From patchwork Wed Jul 24 16:24:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 169614 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10464717ilk; Wed, 24 Jul 2019 09:24:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXiWnIi5HkurlkFfmoLge+Bg2WdDKIyW5nXD7S0mkTY7SKRYpVAvg4Ig1gqjOu0a9uvyGz X-Received: by 2002:aa7:8acb:: with SMTP id b11mr11753258pfd.109.1563985456181; Wed, 24 Jul 2019 09:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563985456; cv=none; d=google.com; s=arc-20160816; b=k6BUwnqWA9s+q1HyNS/spj5WWk3a4eR8bIrH8VyPMR5LCAAHv2Mh7kRv4iyBRO6qGR cwY1xO29xXYvKTlNTkbU16tAH97kj6dUgeaIhx+42+qlzFY1vb0D8oNx2onRq7asRHts MYwZQa0azbOsDAjc9bDySmsRGFSTbK3sBCrdVa1a1/f6KtUftdfDK4Al5I5+45s9rgS1 p3dH4VW9CBzKXyF7ByCrY+9kJB7rrNfaMLjL5sgQ2bFRCBREQtmD2c1nsnjuxwlJPTmX 3pGfIfQrO7tdgA5492Y4nZ8NjcVkZL+Y3EJxogtQH1dUdRj1pvn7xVN51Ykq2tGRryGK 7c7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NYbwqma1m9jqmdyH3lyO6cWket2bF1VkY/YuX/cmnIM=; b=DYctn7i4lm+sx8UPhm6DnQ5JH3ult/bFX3T+iRkCq0MUvwIy3uNu7q1k5OVybUbkuC vlfXhBHzxhMOzANvWqvl6p40aNXzlaXwzHIRFy6ajTVU7ea0RNBFnG4D3nrvySXpM5M3 hOGKXGr82LK/LQFp0FMHUu5F5I27mvZfVaRpbmAik8bRB2mjPbUrMg4qmEhCEuCrj9Nb k5CASBIT6PQZNFQPsHNy5YfIvMTvT16xVuoUdyhPsRqSbz0K8wiJpjJLkCP4vFsNdnU0 Cefuh83KSXK2dj3WgRPdm86rx9pqrbxvyEOS7W+3elApil2zT35ZFnj/j5LgOACXw/gT 0Bww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=kumEAPUx; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k198si15002712pga.313.2019.07.24.09.24.15; Wed, 24 Jul 2019 09:24:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=kumEAPUx; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728771AbfGXQYP (ORCPT + 8 others); Wed, 24 Jul 2019 12:24:15 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44023 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728768AbfGXQYO (ORCPT ); Wed, 24 Jul 2019 12:24:14 -0400 Received: by mail-wr1-f68.google.com with SMTP id p13so47623674wru.10 for ; Wed, 24 Jul 2019 09:24:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NYbwqma1m9jqmdyH3lyO6cWket2bF1VkY/YuX/cmnIM=; b=kumEAPUx7B49kM8BuP59c5fzHEqI89ld6/bXZ9wclNMrmminy+PGmddOmTANEISf/U mW0bJLHMrDbnth3oX9Og7HTFcbiDi73QRyYxCu5r3QHVKXc53nxgAOudarnTjjJs2fHe LnUt1GR8wHA/aaEGQb7Xvx28Jb352PPcZUBhKcnLBjo+BugP50E+I7aZg75y7y3YJyHS BzzvfZpaGurdnxhCp0AcFvLMZIBBI8ob8aIK4KJ/+FlZ8p8tKSovSjTzBcIJVDPlhLEj c/fx/W6do9q7Q9UCgrxOqIArBTbdLqubwtgGlXXROGKKX7WjiL64SsHP+XlVPkrML96X dLJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NYbwqma1m9jqmdyH3lyO6cWket2bF1VkY/YuX/cmnIM=; b=bAolAcWo7C17JWTEI+HjlCDkM0WycWGJQjRThewKuYAjZQfh869L8/xBSNOLmHFaS5 fz9FVTjwmbgihApFJ8a9ivfoo+J1on1P6hIuZg826WpgaYJXNfUNom8OUryUOJ4gnhUY xLmZwH6P+GsRWb1Cd+dHmCR4Pv76YjUkZK3JlAghQ4go57ar0P3rgAzXBAZt3RZRCkUP 4MNCPURIagjTWfnsf/tlRqqahFfLWrgNuhO7d83YjCOwNBkIJ3qiU+zs7UuVHr/qvvoy wfAuRzTEPYnxgx5RU8YLwFtVzki1jKw6qnFd4CgOHOYXQgm7nXZKopWoMZQ5ORw6VMoE jqfQ== X-Gm-Message-State: APjAAAUxDDZxxMBmnYXHKYbHZOvccbUxVZ7iaeDXwdnfx5oT0Y4gxO54 bCiMubJ1iU/ZYwUfgb5pLkszBg== X-Received: by 2002:adf:edd1:: with SMTP id v17mr4837090wro.348.1563985452644; Wed, 24 Jul 2019 09:24:12 -0700 (PDT) Received: from starbuck.baylibre.local (lmontsouris-657-1-212-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id f70sm55688960wme.22.2019.07.24.09.24.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 09:24:12 -0700 (PDT) From: Jerome Brunet To: Mark Brown , Liam Girdwood , Kevin Hilman Cc: Jerome Brunet , alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org Subject: [PATCH 3/6] ASoC: codec2codec: deal with params when necessary Date: Wed, 24 Jul 2019 18:24:02 +0200 Message-Id: <20190724162405.6574-4-jbrunet@baylibre.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190724162405.6574-1-jbrunet@baylibre.com> References: <20190724162405.6574-1-jbrunet@baylibre.com> MIME-Version: 1.0 X-Patchwork-Bot: notify Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org When there is an event on codec to codec dai_link, we only need to deal with params if the event is SND_SOC_DAPM_PRE_PMU, when .hw_params() is called. For the other events, it is useless. Also, params does not need to be dynamically allocated as it does not need to survive the event. Last, dealing with the codec to codec params just before calling .hw_params() callbacks give change to either party on the link to alter params content in .startup(), which might be useful in some cases Signed-off-by: Jerome Brunet --- sound/soc/soc-dapm.c | 81 ++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 30 deletions(-) -- 2.21.0 diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index d20cd89513a4..aa6e47beaec3 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3764,25 +3764,12 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, } EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); -static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *kcontrol, int event) +static int +snd_soc_dai_link_prepare_params(struct snd_soc_dapm_widget *w, + struct snd_pcm_hw_params *params, + const struct snd_soc_pcm_stream *config) { - struct snd_soc_dapm_path *path; - struct snd_soc_dai *source, *sink; - struct snd_soc_pcm_runtime *rtd = w->priv; - const struct snd_soc_pcm_stream *config; - struct snd_pcm_substream substream; - struct snd_pcm_hw_params *params = NULL; - struct snd_pcm_runtime *runtime = NULL; unsigned int fmt; - int ret = 0; - - config = rtd->dai_link->params + rtd->params_select; - - if (WARN_ON(!config) || - WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || - list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) - return -EINVAL; /* Be a little careful as we don't want to overflow the mask array */ if (config->formats) { @@ -3791,26 +3778,41 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n", config->formats); fmt = 0; - } - /* Currently very limited parameter selection */ - params = kzalloc(sizeof(*params), GFP_KERNEL); - if (!params) { - ret = -ENOMEM; - goto out; + return -EINVAL; } - snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt); + memset(params, 0, sizeof(*params)); + + snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt); hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = config->rate_min; hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = config->rate_max; - hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min = config->channels_min; hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max = config->channels_max; + return 0; +} + +static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_dapm_path *path; + struct snd_soc_dai *source, *sink; + struct snd_soc_pcm_runtime *rtd = w->priv; + const struct snd_soc_pcm_stream *config; + struct snd_pcm_substream substream; + struct snd_pcm_hw_params params; + struct snd_pcm_runtime *runtime = NULL; + int ret = 0; + + if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || + list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) + return -EINVAL; + memset(&substream, 0, sizeof(substream)); /* Allocate a dummy snd_pcm_runtime for startup() and other ops() */ @@ -3850,27 +3852,47 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, sink->active++; } + /* + * Note: getting the config after .startup() gives a chance to + * either party on the link to alter the configuration if + * necessary + */ + config = rtd->dai_link->params + rtd->params_select; + if (WARN_ON(!config)) { + dev_err(w->dapm->dev, "ASoC: link config missing\n"); + ret = -EINVAL; + goto out; + } + + ret = snd_soc_dai_link_prepare_params(w, ¶ms, config); + if (ret < 0) { + dev_err(w->dapm->dev, "ASoC: link params prepare failed: %d\n", + ret); + goto out; + } + substream.stream = SNDRV_PCM_STREAM_CAPTURE; snd_soc_dapm_widget_for_each_source_path(w, path) { source = path->source->priv; - ret = soc_dai_hw_params(&substream, params, source); + ret = soc_dai_hw_params(&substream, ¶ms, source); if (ret < 0) goto out; - dapm_update_dai_unlocked(&substream, params, source); + dapm_update_dai_unlocked(&substream, ¶ms, source); } substream.stream = SNDRV_PCM_STREAM_PLAYBACK; snd_soc_dapm_widget_for_each_sink_path(w, path) { sink = path->sink->priv; - ret = soc_dai_hw_params(&substream, params, sink); + ret = soc_dai_hw_params(&substream, ¶ms, sink); if (ret < 0) goto out; - dapm_update_dai_unlocked(&substream, params, sink); + dapm_update_dai_unlocked(&substream, ¶ms, sink); } + break; case SND_SOC_DAPM_POST_PMU: @@ -3932,7 +3954,6 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, out: kfree(runtime); - kfree(params); return ret; }