From patchwork Tue Apr 24 06:05:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 141635 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1919775lji; Tue, 24 Apr 2018 00:45:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+KAFsOQxsoIUfMqrU4U91EMsV1/9N2VR93zQvhO38XQtcmJK6BCSRP279PleRoJ4KxgDW7 X-Received: by 10.28.191.27 with SMTP id p27mr11877664wmf.97.1524555948905; Tue, 24 Apr 2018 00:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524555948; cv=none; d=google.com; s=arc-20160816; b=DLU1QBr7lMOAzgh2L5DHqRnS+wW2MOdxTRaM9o3vpuvG/37CPJFZTF+/st2jxo91df ykLh0UpqzyloZC4aTvCvAk88XGv06kl+ReBVnFkShqBcDjR8uN3D94zK3d8A4TxljbB2 cxpGwGsBBiYuH1P0LdrnXehWCb0PJ2oW6xsKyG8/9eK00T1MsmLuvk1cWN5q9z5IHeMg mSuU5tgEf947Ifwv9aCk1V8twH29M+pR9T2NxKGDmGi8voREutMbLgdjphd9LoirA07X AaZURtDephUMjCPt5u0K/wTa6Qzy8PH+hmBZVkcYNRgVQwLK54NOX0rHGs4LdnCALq1Q hbyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:delivered-to:arc-authentication-results; bh=nm2qhvSGMdyage/seQPSPAEwO848hqcZhMgxNY6LLmo=; b=ryfMEpXLGCjBhc4IodgxpRd3tZK1mybhJXKXT++74RLc6ul8Ovi99W2gK0J0M+ZevL MnDdlP7tJXf8SRDRbvHBGfXVU9dXVM7PeaBL9wyFo6HWHGh7iMvCLljnNpCgi8xZCIKi PkQ8pBYcWqDC2vrkVEFk9Cr+Bjispcs3oixJGBjT0xc+z6KVoJHX4guqzsKptcLwWRAk aLj+wG1/TpdH8+jCDV6ByQqvS9ySWicRFjFx84UdefjJQpA8p1Ac7+xcjVmZBEhRN1As jmeolvqmJDjQpdLBd92UQYLQNy5OXyKjQIrWuRP2kg2LBE3f0Iej2RNVl6gPa2tfrY8B hEOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id o16-v6si11333958wrb.366.2018.04.24.00.45.48; Tue, 24 Apr 2018 00:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 5D7FE26769C; Tue, 24 Apr 2018 09:45:27 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9DC2826766D; Tue, 24 Apr 2018 08:01:29 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.4.0 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by alsa0.perex.cz (Postfix) with ESMTP id 85E792675D0 for ; Tue, 24 Apr 2018 08:01:26 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Apr 2018 23:01:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,321,1520924400"; d="scan'208";a="222820724" Received: from vkoul-udesk7.iind.intel.com ([10.223.84.143]) by fmsmga005.fm.intel.com with ESMTP; 23 Apr 2018 23:01:23 -0700 From: Vinod Koul To: alsa-devel@alsa-project.org Date: Tue, 24 Apr 2018 11:35:53 +0530 Message-Id: <1524549954-29144-3-git-send-email-vkoul@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524549954-29144-1-git-send-email-vkoul@kernel.org> References: <1524549954-29144-1-git-send-email-vkoul@kernel.org> X-Mailman-Approved-At: Tue, 24 Apr 2018 09:45:19 +0200 Cc: liam.r.girdwood@linux.intel.com, patches.audio@intel.com, Vinod Koul , broonie@kernel.org, Shreyas NC Subject: [alsa-devel] [PATCH v4 2/3] ASoC: Add multiple CPU DAI support for PCM ops X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org From: Shreyas NC Add support in PCM operations to invoke multiple cpu dais as we do for multiple codec dais. Also the symmetry calculations are updated to reflect multiple cpu dais. Signed-off-by: Shreyas NC Signed-off-by: Vinod Koul --- sound/soc/soc-pcm.c | 483 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 318 insertions(+), 165 deletions(-) -- 2.7.4 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 68d9dc930096..0375432ed9fd 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -64,23 +64,27 @@ static bool snd_soc_dai_stream_valid(struct snd_soc_dai *dai, int stream) */ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) { - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int i; lockdep_assert_held(&rtd->pcm_mutex); if (stream == SNDRV_PCM_STREAM_PLAYBACK) { - cpu_dai->playback_active++; + for (i = 0; i < rtd->num_cpu_dai; i++) + rtd->cpu_dais[i]->playback_active++; for (i = 0; i < rtd->num_codecs; i++) rtd->codec_dais[i]->playback_active++; } else { - cpu_dai->capture_active++; + for (i = 0; i < rtd->num_cpu_dai; i++) + rtd->cpu_dais[i]->capture_active++; for (i = 0; i < rtd->num_codecs; i++) rtd->codec_dais[i]->capture_active++; } - cpu_dai->active++; - cpu_dai->component->active++; + for (i = 0; i < rtd->num_cpu_dai; i++) { + rtd->cpu_dais[i]->component->active++; + rtd->cpu_dais[i]->active++; + } + for (i = 0; i < rtd->num_codecs; i++) { rtd->codec_dais[i]->active++; rtd->codec_dais[i]->component->active++; @@ -99,23 +103,27 @@ void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream) */ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) { - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; int i; lockdep_assert_held(&rtd->pcm_mutex); if (stream == SNDRV_PCM_STREAM_PLAYBACK) { - cpu_dai->playback_active--; + for (i = 0; i < rtd->num_cpu_dai; i++) + rtd->cpu_dais[i]->playback_active--; for (i = 0; i < rtd->num_codecs; i++) rtd->codec_dais[i]->playback_active--; } else { - cpu_dai->capture_active--; + for (i = 0; i < rtd->num_cpu_dai; i++) + rtd->cpu_dais[i]->capture_active--; for (i = 0; i < rtd->num_codecs; i++) rtd->codec_dais[i]->capture_active--; } - cpu_dai->active--; - cpu_dai->component->active--; + for (i = 0; i < rtd->num_cpu_dai; i++) { + rtd->cpu_dais[i]->component->active--; + rtd->cpu_dais[i]->active--; + } + for (i = 0; i < rtd->num_codecs; i++) { rtd->codec_dais[i]->component->active--; rtd->codec_dais[i]->active--; @@ -263,7 +271,6 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; unsigned int rate, channels, sample_bits, symmetry, i; rate = params_rate(params); @@ -271,41 +278,54 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, sample_bits = snd_pcm_format_physical_width(params_format(params)); /* reject unmatched parameters when applying symmetry */ - symmetry = cpu_dai->driver->symmetric_rates || - rtd->dai_link->symmetric_rates; + symmetry = rtd->dai_link->symmetric_rates; + + for (i = 0; i < rtd->num_cpu_dai; i++) + symmetry |= rtd->cpu_dais[i]->driver->symmetric_rates; for (i = 0; i < rtd->num_codecs; i++) symmetry |= rtd->codec_dais[i]->driver->symmetric_rates; - if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) { - dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n", - cpu_dai->rate, rate); - return -EINVAL; - } + for (i = 0; i < rtd->num_cpu_dai; i++) + if (symmetry && rtd->cpu_dais[i]->rate && + rtd->cpu_dais[i]->rate != rate) { + dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n", + rtd->cpu_dais[i]->rate, rate); + return -EINVAL; + } - symmetry = cpu_dai->driver->symmetric_channels || - rtd->dai_link->symmetric_channels; + symmetry = rtd->dai_link->symmetric_channels; + + for (i = 0; i < rtd->num_cpu_dai; i++) + symmetry |= rtd->cpu_dais[i]->driver->symmetric_channels; for (i = 0; i < rtd->num_codecs; i++) symmetry |= rtd->codec_dais[i]->driver->symmetric_channels; - if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) { - dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n", - cpu_dai->channels, channels); - return -EINVAL; - } + for (i = 0; i < rtd->num_cpu_dai; i++) + if (symmetry && rtd->cpu_dais[i]->channels && + rtd->cpu_dais[i]->channels != channels) { + dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n", + rtd->cpu_dais[i]->channels, channels); + return -EINVAL; + } - symmetry = cpu_dai->driver->symmetric_samplebits || - rtd->dai_link->symmetric_samplebits; + symmetry = rtd->dai_link->symmetric_samplebits; + + for (i = 0; i < rtd->num_cpu_dai; i++) + symmetry |= rtd->cpu_dais[i]->driver->symmetric_samplebits; for (i = 0; i < rtd->num_codecs; i++) symmetry |= rtd->codec_dais[i]->driver->symmetric_samplebits; - if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) { - dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n", - cpu_dai->sample_bits, sample_bits); - return -EINVAL; - } + for (i = 0; i < rtd->num_cpu_dai; i++) + if (symmetry && rtd->cpu_dais[i]->sample_bits && + rtd->cpu_dais[i]->sample_bits != sample_bits) { + dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n", + rtd->cpu_dais[i]->sample_bits, + sample_bits); + return -EINVAL; + } return 0; } @@ -313,13 +333,18 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver; struct snd_soc_dai_link *link = rtd->dai_link; - unsigned int symmetry, i; + unsigned int symmetry = 0, i; - symmetry = cpu_driver->symmetric_rates || link->symmetric_rates || - cpu_driver->symmetric_channels || link->symmetric_channels || - cpu_driver->symmetric_samplebits || link->symmetric_samplebits; + symmetry = link->symmetric_rates || link->symmetric_channels || + link->symmetric_samplebits; + + /* Apply symmetery for multiple cpu dais */ + for (i = 0; i < rtd->num_cpu_dai; i++) + symmetry = symmetry || + rtd->cpu_dais[i]->driver->symmetric_rates || + rtd->cpu_dais[i]->driver->symmetric_channels || + rtd->cpu_dais[i]->driver->symmetric_samplebits; for (i = 0; i < rtd->num_codecs; i++) symmetry = symmetry || @@ -347,10 +372,10 @@ static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits) static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i; - unsigned int bits = 0, cpu_bits; + unsigned int bits = 0, cpu_bits = 0; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { for (i = 0; i < rtd->num_codecs; i++) { @@ -361,7 +386,16 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) } bits = max(codec_dai->driver->playback.sig_bits, bits); } - cpu_bits = cpu_dai->driver->playback.sig_bits; + + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->playback.sig_bits == 0) { + cpu_bits = 0; + break; + } + + cpu_bits = max(cpu_dai->driver->playback.sig_bits, bits); + } } else { for (i = 0; i < rtd->num_codecs; i++) { codec_dai = rtd->codec_dais[i]; @@ -371,7 +405,15 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) } bits = max(codec_dai->driver->capture.sig_bits, bits); } - cpu_bits = cpu_dai->driver->capture.sig_bits; + + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->capture.sig_bits == 0) { + cpu_bits = 0; + break; + } + cpu_bits = max(cpu_dai->driver->capture.sig_bits, bits); + } } soc_pcm_set_msb(substream, bits); @@ -383,7 +425,7 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver; + struct snd_soc_dai_driver *cpu_dai_drv; struct snd_soc_dai_driver *codec_dai_drv; struct snd_soc_pcm_stream *codec_stream; struct snd_soc_pcm_stream *cpu_stream; @@ -393,11 +435,6 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) u64 formats = ULLONG_MAX; int i; - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) - cpu_stream = &cpu_dai_drv->playback; - else - cpu_stream = &cpu_dai_drv->capture; - /* first calculate min/max only for CODECs in the DAI link */ for (i = 0; i < rtd->num_codecs; i++) { @@ -427,30 +464,47 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream) rates = snd_pcm_rate_mask_intersect(codec_stream->rates, rates); } - /* - * chan min/max cannot be enforced if there are multiple CODEC DAIs - * connected to a single CPU DAI, use CPU DAI's directly and let - * channel allocation be fixed up later - */ - if (rtd->num_codecs > 1) { - chan_min = cpu_stream->channels_min; - chan_max = cpu_stream->channels_max; - } + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai_drv = rtd->cpu_dais[i]->driver; - hw->channels_min = max(chan_min, cpu_stream->channels_min); - hw->channels_max = min(chan_max, cpu_stream->channels_max); - if (hw->formats) - hw->formats &= formats & cpu_stream->formats; - else - hw->formats = formats & cpu_stream->formats; - hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + cpu_stream = &cpu_dai_drv->playback; + else + cpu_stream = &cpu_dai_drv->capture; - snd_pcm_limit_hw_rates(runtime); + /* + * chan min/max cannot be enforced if there are multiple + * CODEC DAIs connected to a single CPU DAI, use CPU DAI's + * directly and let channel allocation be fixed up later + */ + if (rtd->num_codecs > 1 && rtd->num_cpu_dai == 1) { + chan_min = cpu_stream->channels_min; + chan_max = cpu_stream->channels_max; + } + + hw->channels_min = max(hw->channels_min, chan_min); + hw->channels_min = max(hw->channels_min, + cpu_stream->channels_min); + hw->channels_max = min(hw->channels_max, + cpu_stream->channels_max); + hw->channels_max = min(hw->channels_max, + cpu_stream->channels_max); + + if (hw->formats) + hw->formats &= formats & cpu_stream->formats; + else + hw->formats = formats & cpu_stream->formats; + + hw->rates = snd_pcm_rate_mask_intersect(rates, + cpu_stream->rates); - hw->rate_min = max(hw->rate_min, cpu_stream->rate_min); - hw->rate_min = max(hw->rate_min, rate_min); - hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max); - hw->rate_max = min_not_zero(hw->rate_max, rate_max); + snd_pcm_limit_hw_rates(runtime); + + hw->rate_min = max(hw->rate_min, cpu_stream->rate_min); + hw->rate_min = max(hw->rate_min, rate_min); + hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max); + hw->rate_max = min_not_zero(hw->rate_max, rate_max); + } } /* @@ -465,12 +519,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; const char *codec_dai_name = "multicodec"; - int i, ret = 0, __ret; + const char *cpu_dai_name = "multicpu"; + int i, ret = 0, __ret, j; + + for (i = 0; i < rtd->num_cpu_dai; i++) + pinctrl_pm_select_default_state(rtd->cpu_dais[i]->dev); - pinctrl_pm_select_default_state(cpu_dai->dev); for (i = 0; i < rtd->num_codecs; i++) pinctrl_pm_select_default_state(rtd->codec_dais[i]->dev); @@ -483,12 +540,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); /* startup the audio subsystem */ - if (cpu_dai->driver->ops->startup) { - ret = cpu_dai->driver->ops->startup(substream, cpu_dai); - if (ret < 0) { - dev_err(cpu_dai->dev, "ASoC: can't open interface" - " %s: %d\n", cpu_dai->name, ret); - goto out; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->startup) { + ret = cpu_dai->driver->ops->startup(substream, cpu_dai); + if (ret < 0) { + dev_err(cpu_dai->dev, "ASoC: can't open interface %s: %d\n", + cpu_dai->name, ret); + goto platform_err; + } } } @@ -562,34 +622,40 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) if (rtd->num_codecs == 1) codec_dai_name = rtd->codec_dai->name; + if (rtd->num_cpu_dai == 1) + cpu_dai_name = rtd->cpu_dai->name; + if (soc_pcm_has_symmetry(substream)) runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; ret = -EINVAL; if (!runtime->hw.rates) { printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n", - codec_dai_name, cpu_dai->name); + codec_dai_name, cpu_dai_name); goto config_err; } if (!runtime->hw.formats) { printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n", - codec_dai_name, cpu_dai->name); + codec_dai_name, cpu_dai_name); goto config_err; } if (!runtime->hw.channels_min || !runtime->hw.channels_max || runtime->hw.channels_min > runtime->hw.channels_max) { printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n", - codec_dai_name, cpu_dai->name); + codec_dai_name, cpu_dai_name); goto config_err; } soc_pcm_apply_msb(substream); /* Symmetry only applies if we've already got an active stream. */ - if (cpu_dai->active) { - ret = soc_pcm_apply_symmetry(substream, cpu_dai); - if (ret != 0) - goto config_err; + for (i = 0; i < rtd->num_cpu_dai; i++) { + if (rtd->cpu_dais[i]->active) { + ret = soc_pcm_apply_symmetry(substream, + rtd->cpu_dais[i]); + if (ret != 0) + goto config_err; + } } for (i = 0; i < rtd->num_codecs; i++) { @@ -602,7 +668,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) } pr_debug("ASoC: %s <-> %s info:\n", - codec_dai_name, cpu_dai->name); + codec_dai_name, cpu_dai_name); pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates); pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min, runtime->hw.channels_max); @@ -649,9 +715,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) platform->driver->ops->close(substream); platform_err: - if (cpu_dai->driver->ops->shutdown) - cpu_dai->driver->ops->shutdown(substream, cpu_dai); -out: + j = rtd->num_cpu_dai; + while (--j >= 0) { + cpu_dai = rtd->cpu_dais[j]; + if (cpu_dai->driver->ops->shutdown) + cpu_dai->driver->ops->shutdown(substream, cpu_dai); + } + mutex_unlock(&rtd->pcm_mutex); for_each_rtdcom(rtd, rtdcom) { @@ -665,8 +735,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) if (!rtd->codec_dais[i]->active) pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev); } - if (!cpu_dai->active) - pinctrl_pm_select_sleep_state(cpu_dai->dev); + + for (i = 0; i < rtd->num_cpu_dai; i++) { + if (!rtd->cpu_dais[i]->active) + pinctrl_pm_select_sleep_state(rtd->cpu_dais[i]->dev); + } return ret; } @@ -710,7 +783,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i; @@ -719,8 +792,11 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) snd_soc_runtime_deactivate(rtd, substream->stream); /* clear the corresponding DAIs rate when inactive */ - if (!cpu_dai->active) - cpu_dai->rate = 0; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (!cpu_dai->active) + cpu_dai->rate = 0; + } for (i = 0; i < rtd->num_codecs; i++) { codec_dai = rtd->codec_dais[i]; @@ -728,10 +804,16 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) codec_dai->rate = 0; } - snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream); + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream); + } - if (cpu_dai->driver->ops->shutdown) - cpu_dai->driver->ops->shutdown(substream, cpu_dai); + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->shutdown) + cpu_dai->driver->ops->shutdown(substream, cpu_dai); + } for (i = 0; i < rtd->num_codecs; i++) { codec_dai = rtd->codec_dais[i]; @@ -791,8 +873,11 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) if (!rtd->codec_dais[i]->active) pinctrl_pm_select_sleep_state(rtd->codec_dais[i]->dev); } - if (!cpu_dai->active) - pinctrl_pm_select_sleep_state(cpu_dai->dev); + + for (i = 0; i < rtd->num_cpu_dai; i++) { + if (!rtd->cpu_dais[i]->active) + pinctrl_pm_select_sleep_state(rtd->cpu_dais[i]->dev); + } return 0; } @@ -808,7 +893,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i, ret = 0; @@ -865,12 +950,16 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) } } - if (cpu_dai->driver->ops->prepare) { - ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); - if (ret < 0) { - dev_err(cpu_dai->dev, - "ASoC: cpu DAI prepare error: %d\n", ret); - goto out; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->prepare) { + ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); + if (ret < 0) { + dev_err(cpu_dai->dev, + "ASoC: cpu DAI prepare error: %d\n", + ret); + goto out; + } } } @@ -887,7 +976,10 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) for (i = 0; i < rtd->num_codecs; i++) snd_soc_dai_digital_mute(rtd->codec_dais[i], 0, substream->stream); - snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream); + + for (i = 0; i < rtd->num_cpu_dai; i++) + snd_soc_dai_digital_mute(rtd->cpu_dais[i], 0, + substream->stream); out: mutex_unlock(&rtd->pcm_mutex); @@ -935,8 +1027,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - int i, ret = 0, __ret; + struct snd_soc_dai *cpu_dai; + int i, ret = 0, __ret, j; mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); if (rtd->dai_link->ops->hw_params) { @@ -990,9 +1082,12 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, params_format(&codec_params)); } - ret = soc_dai_hw_params(substream, params, cpu_dai); - if (ret < 0) - goto interface_err; + for (j = 0; j < rtd->num_cpu_dai; j++) { + cpu_dai = rtd->cpu_dais[j]; + ret = soc_dai_hw_params(substream, params, cpu_dai); + if (ret < 0) + goto interface_err; + } if (platform && platform->driver->ops && platform->driver->ops->hw_params) { ret = platform->driver->ops->hw_params(substream, params); @@ -1026,11 +1121,14 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, if (ret < 0) goto component_err; - /* store the parameters for each DAIs */ - cpu_dai->rate = params_rate(params); - cpu_dai->channels = params_channels(params); - cpu_dai->sample_bits = - snd_pcm_format_physical_width(params_format(params)); + for (i = 0; i < rtd->num_cpu_dai; i++) { + /* store the parameters for each DAIs */ + cpu_dai = rtd->cpu_dais[i]; + cpu_dai->rate = params_rate(params); + cpu_dai->channels = params_channels(params); + cpu_dai->sample_bits = + snd_pcm_format_physical_width(params_format(params)); + } ret = soc_pcm_params_symmetry(substream, params); if (ret) @@ -1058,12 +1156,18 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, platform->driver->ops->hw_free(substream); platform_err: - if (cpu_dai->driver->ops->hw_free) - cpu_dai->driver->ops->hw_free(substream, cpu_dai); + j = rtd->num_cpu_dai; interface_err: i = rtd->num_codecs; + while (--j >= 0) { + cpu_dai = rtd->cpu_dais[j]; + + if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free) + cpu_dai->driver->ops->hw_free(substream, cpu_dai); + } + codec_err: while (--i >= 0) { struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; @@ -1088,7 +1192,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; int i; @@ -1096,10 +1200,13 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); /* clear the corresponding DAIs parameters when going to be inactive */ - if (cpu_dai->active == 1) { - cpu_dai->rate = 0; - cpu_dai->channels = 0; - cpu_dai->sample_bits = 0; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->active == 1) { + cpu_dai->rate = 0; + cpu_dai->channels = 0; + cpu_dai->sample_bits = 0; + } } for (i = 0; i < rtd->num_codecs; i++) { @@ -1149,8 +1256,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) codec_dai->driver->ops->hw_free(substream, codec_dai); } - if (cpu_dai->driver->ops->hw_free) - cpu_dai->driver->ops->hw_free(substream, cpu_dai); + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free) + cpu_dai->driver->ops->hw_free(substream, cpu_dai); + } mutex_unlock(&rtd->pcm_mutex); return 0; @@ -1162,7 +1272,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i, ret; @@ -1198,10 +1308,14 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) return ret; } - if (cpu_dai->driver->ops->trigger) { - ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai); - if (ret < 0) - return ret; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->trigger) { + ret = cpu_dai->driver->ops->trigger(substream, + cmd, cpu_dai); + if (ret < 0) + return ret; + } } if (rtd->dai_link->ops->trigger) { @@ -1217,7 +1331,7 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; int i, ret; @@ -1231,10 +1345,14 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream, } } - if (cpu_dai->driver->ops->bespoke_trigger) { - ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); - if (ret < 0) - return ret; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->bespoke_trigger) { + ret = cpu_dai->driver->ops->bespoke_trigger(substream, + cmd, cpu_dai); + if (ret < 0) + return ret; + } } return 0; } @@ -1249,7 +1367,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) struct snd_soc_platform *platform = rtd->platform; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_dai *codec_dai; struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_uframes_t offset = 0; @@ -1276,8 +1394,12 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) break; } - if (cpu_dai->driver->ops->delay) - delay += cpu_dai->driver->ops->delay(substream, cpu_dai); + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->ops->delay) + delay += cpu_dai->driver->ops->delay(substream, + cpu_dai); + } for (i = 0; i < rtd->num_codecs; i++) { codec_dai = rtd->codec_dais[i]; @@ -1400,12 +1522,16 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, if (!be->dai_link->no_pcm) continue; - dev_dbg(card->dev, "ASoC: try BE : %s\n", - be->cpu_dai->playback_widget ? - be->cpu_dai->playback_widget->name : "(not set)"); + for (i = 0; i < be->num_cpu_dai; i++) { + struct snd_soc_dai *cpu_dai = be->cpu_dais[i]; + + dev_dbg(card->dev, "ASoC: try BE : %s\n", + cpu_dai->playback_widget ? + cpu_dai->playback_widget->name : "(not set)"); - if (be->cpu_dai->playback_widget == widget) - return be; + if (cpu_dai->playback_widget == widget) + return be; + } for (i = 0; i < be->num_codecs; i++) { struct snd_soc_dai *dai = be->codec_dais[i]; @@ -1420,12 +1546,16 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, if (!be->dai_link->no_pcm) continue; - dev_dbg(card->dev, "ASoC: try BE %s\n", - be->cpu_dai->capture_widget ? - be->cpu_dai->capture_widget->name : "(not set)"); + for (i = 0; i < be->num_cpu_dai; i++) { + struct snd_soc_dai *cpu_dai = be->cpu_dais[i]; - if (be->cpu_dai->capture_widget == widget) - return be; + dev_dbg(card->dev, "ASoC: try BE %s\n", + cpu_dai->capture_widget ? + cpu_dai->capture_widget->name : "(not set)"); + + if (cpu_dai->capture_widget == widget) + return be; + } for (i = 0; i < be->num_codecs; i++) { struct snd_soc_dai *dai = be->codec_dais[i]; @@ -1475,8 +1605,12 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, if (!rtd->dai_link->no_pcm) continue; - if (rtd->cpu_dai->playback_widget == widget) - return true; + for (i = 0; i < rtd->num_cpu_dai; ++i) { + struct snd_soc_dai *cpu_dai = rtd->cpu_dais[i]; + + if (cpu_dai->playback_widget == widget) + return true; + } for (i = 0; i < rtd->num_codecs; ++i) { struct snd_soc_dai *dai = rtd->codec_dais[i]; @@ -1489,8 +1623,12 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget, if (!rtd->dai_link->no_pcm) continue; - if (rtd->cpu_dai->capture_widget == widget) - return true; + for (i = 0; i < rtd->num_cpu_dai; ++i) { + struct snd_soc_dai *cpu_dai = rtd->cpu_dais[i]; + + if (cpu_dai->capture_widget == widget) + return true; + } for (i = 0; i < rtd->num_codecs; ++i) { struct snd_soc_dai *dai = rtd->codec_dais[i]; @@ -1532,11 +1670,15 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream, unsigned int i; /* is there a valid CPU DAI widget for this BE */ - widget = dai_get_widget(dpcm->be->cpu_dai, stream); + for (i = 0; i < dpcm->be->num_cpu_dai; i++) { + struct snd_soc_dai *dai = dpcm->be->cpu_dais[i]; - /* prune the BE if it's no longer in our active list */ - if (widget && widget_in_list(list, widget)) - continue; + widget = dai_get_widget(dai, stream); + + /* prune the BE if it's no longer in our active list */ + if (widget && widget_in_list(list, widget)) + continue; + } /* is there a valid CODEC DAI widget for this BE */ for (i = 0; i < dpcm->be->num_codecs; i++) { @@ -1877,10 +2019,13 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX; /* Symmetry only applies if we've got an active stream. */ - if (rtd->cpu_dai->active) { - err = soc_pcm_apply_symmetry(be_substream, rtd->cpu_dai); - if (err < 0) - return err; + for (i = 0; i < rtd->num_cpu_dai; i++) { + if (rtd->cpu_dais[i]->active) { + err = soc_pcm_apply_symmetry(be_substream, + rtd->cpu_dais[i]); + if (err < 0) + return err; + } } for (i = 0; i < rtd->num_codecs; i++) { @@ -2989,13 +3134,13 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) { struct snd_soc_platform *platform = rtd->platform; struct snd_soc_dai *codec_dai; - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + struct snd_soc_dai *cpu_dai; struct snd_soc_component *component; struct snd_soc_rtdcom_list *rtdcom; struct snd_pcm *pcm; char new_name[64]; int ret = 0, playback = 0, capture = 0; - int i; + int i, cpu_capture = 0, cpu_playback = 0; if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { playback = rtd->dai_link->dpcm_playback; @@ -3009,8 +3154,16 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) capture = 1; } - capture = capture && cpu_dai->driver->capture.channels_min; - playback = playback && cpu_dai->driver->playback.channels_min; + for (i = 0; i < rtd->num_cpu_dai; i++) { + cpu_dai = rtd->cpu_dais[i]; + if (cpu_dai->driver->playback.channels_min) + cpu_playback = 1; + if (cpu_dai->driver->capture.channels_min) + cpu_capture = 1; + } + + playback = playback && cpu_playback; + capture = capture && cpu_capture; } if (rtd->dai_link->playback_only) { @@ -3141,7 +3294,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) out: dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name, - cpu_dai->name); + (rtd->num_cpu_dai > 1) ? "multicpu" : rtd->cpu_dai->name); return ret; }