From patchwork Mon Sep 18 13:39:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cezary Rojewski X-Patchwork-Id: 13389643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AAE8C46CA1 for ; Mon, 18 Sep 2023 13:42:53 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 6C3FEAE8; Mon, 18 Sep 2023 15:42:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6C3FEAE8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1695044571; bh=F7T6jXdTy+Lx+gb27TtxZqZFV4tcYZc+AOLfmGGqWxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=NOkY/uuVmLLhycPo4q/T+hWUA7zyLXeL6QwXOCTiBJQzFWEJd3el5lvS77RALqIzE CmLe6FBwAMWTHvsRyfo/piNKmB0xnYR1OfVyiRdua1DXwb8CyAIDdZE4hFyakw6ZTC NX40cFSf/1yjfK+ZAiM2AE/nW87qr7F22x76eEbk= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 44505F805BD; Mon, 18 Sep 2023 15:40:36 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 5FDF6F805B6; Mon, 18 Sep 2023 15:40:36 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 10540F805B1; Mon, 18 Sep 2023 15:40:33 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id E8B73F8025A for ; Mon, 18 Sep 2023 15:40:29 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E8B73F8025A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JFlMFt4z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695044431; x=1726580431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F7T6jXdTy+Lx+gb27TtxZqZFV4tcYZc+AOLfmGGqWxA=; b=JFlMFt4zvjgstMIUyeJOfaXrQlkhUrS0WOeESBrfgqkXufeKIeluXLqS PF4j2PmRid1AOx+6cjIIWPXPjx/bPt2Fc/WRyq6NH8dbQ3Q1RBbfVPQHW o83M+3sw9tzH0ap98emmN3+60fMmKxVEf6gt/c6Syq+udlqrifuusTH1Q Xbgy03c03nTYW5GfLFYSyeeQ1w5rtI87DtsaAmHnoykw+Ic1ZxmRpPbaw 4kfGqkdJp5txQL6x1JHqC5kYcMsi6CzLJMXUAawxXnGdsT0AjpYfLF8Bb YUkhuvBTqkEMkJEquYMBjY9wXXo/tM+eL9nvwOqh5W1137Q8amy8AawOO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="466003773" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="466003773" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:40:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="745825874" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="745825874" Received: from crojewsk-ctrl.igk.intel.com ([10.102.9.28]) by orsmga002.jf.intel.com with ESMTP; 18 Sep 2023 06:40:10 -0700 From: Cezary Rojewski To: broonie@kernel.org, tiwai@suse.com, perex@perex.cz Cc: alsa-devel@alsa-project.org, amadeuszx.slawinski@linux.intel.com, pierre-louis.bossart@linux.intel.com, hdegoede@redhat.com, Cezary Rojewski Subject: [PATCH v2 04/17] ASoC: pcm: Honor subformat when configuring runtime Date: Mon, 18 Sep 2023 15:39:27 +0200 Message-Id: <20230918133940.3676091-5-cezary.rojewski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230918133940.3676091-1-cezary.rojewski@intel.com> References: <20230918133940.3676091-1-cezary.rojewski@intel.com> MIME-Version: 1.0 Message-ID-Hash: 6RPWWQCUWDW3FNZUKAZE7VVYEVTYEWUR X-Message-ID-Hash: 6RPWWQCUWDW3FNZUKAZE7VVYEVTYEWUR X-MailFrom: cezary.rojewski@intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Subformat options are ignored when setting up hardware parameters and assigning PCM stream capabilities. Account for them to allow for granular format selection. With introduction of subformats, copying hardware parameters becomes a non-trivial operation. Implement a helper function to make things simple. Signed-off-by: Cezary Rojewski Acked-by: Mark Brown --- include/sound/soc.h | 1 + sound/soc/soc-pcm.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index 81ed08c5c67d..0d3158a7715e 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -620,6 +620,7 @@ enum snd_soc_trigger_order { struct snd_soc_pcm_stream { const char *stream_name; u64 formats; /* SNDRV_PCM_FMTBIT_* */ + const struct snd_pcm_subformat *subformats; unsigned int rates; /* SNDRV_PCM_RATE_* */ unsigned int rate_min; /* min rate */ unsigned int rate_max; /* max rate */ diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 54704250c0a2..b57795feb5f8 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -336,9 +336,7 @@ bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, const struct snd_pcm_hardware *hw) { - substream->runtime->hw = *hw; - - return 0; + return snd_pcm_hw_copy(&substream->runtime->hw, hw); } EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams); @@ -554,6 +552,33 @@ static void soc_pcm_hw_update_format(struct snd_pcm_hardware *hw, hw->formats &= p->formats; } +static void soc_pcm_hw_update_subformat(struct snd_pcm_hardware *hw, + struct snd_soc_pcm_stream *p) +{ + const struct snd_pcm_subformat *sf2; + struct snd_pcm_subformat *sf1; + u32 last = 0; + + if (!hw->subformats || !p->subformats) + return; + + for (sf1 = hw->subformats; sf1->mask; sf1++) + last++; + + for (sf1 = hw->subformats; sf1->mask; sf1++) { + for (sf2 = p->subformats; sf2->mask; sf2++) { + if (sf1->format != sf2->format) + continue; + + sf1->mask &= sf2->mask; + if (!sf1->mask) { + swap(*sf1, hw->subformats[last]); + last--; + } + } + } +} + /** * snd_soc_runtime_calc_hw() - Calculate hw limits for a PCM stream * @rtd: ASoC PCM runtime @@ -592,6 +617,7 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd, soc_pcm_hw_update_chan(hw, cpu_stream); soc_pcm_hw_update_rate(hw, cpu_stream); soc_pcm_hw_update_format(hw, cpu_stream); + soc_pcm_hw_update_subformat(hw, cpu_stream); } cpu_chan_min = hw->channels_min; cpu_chan_max = hw->channels_max; @@ -613,6 +639,7 @@ int snd_soc_runtime_calc_hw(struct snd_soc_pcm_runtime *rtd, soc_pcm_hw_update_chan(hw, codec_stream); soc_pcm_hw_update_rate(hw, codec_stream); soc_pcm_hw_update_format(hw, codec_stream); + soc_pcm_hw_update_subformat(hw, codec_stream); } /* Verify both a valid CPU DAI and a valid CODEC DAI were found */ @@ -1698,6 +1725,7 @@ static void dpcm_runtime_setup_fe(struct snd_pcm_substream *substream) soc_pcm_hw_update_rate(hw, cpu_stream); soc_pcm_hw_update_chan(hw, cpu_stream); soc_pcm_hw_update_format(hw, cpu_stream); + soc_pcm_hw_update_subformat(hw, cpu_stream); } } @@ -1735,6 +1763,7 @@ static void dpcm_runtime_setup_be_format(struct snd_pcm_substream *substream) codec_stream = snd_soc_dai_get_pcm_stream(dai, stream); soc_pcm_hw_update_format(hw, codec_stream); + soc_pcm_hw_update_subformat(hw, codec_stream); } } }