From patchwork Tue Jul 21 11:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11675529 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CB5F618 for ; Tue, 21 Jul 2020 11:43:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22AB42073A for ; Tue, 21 Jul 2020 11:43:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tXvN4rnt"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="l/HF4aQ5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22AB42073A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=2cIQZcgPrfLBLW2DH3tyHWKlA9DZ+ABme1agQdWqvGw=; b=tXvN4rntUOmq0JNncnFERchSvE ebQzB50TTk8B7rCmvzj6psihM+YVbHOkt/92bF2Ypegy/TopuNwb/V6qM9nOKH1R9+Yrbx7OEna85 kdaVGHCo4QWEQ+gzDg24v7iruLnGI+2keONf3hHjz8+EoX8k+LKlXBiAYzNSeFoc4Uakhd2qHicwH GZQczU4RlGaIHJSw9xkgfA/pS5ufdpAtQb98u15sTscG9cEYukx6watkGGaxEg226yFMyqRVBJEn9 Fd4K9lsnS89nuxDrvEN1Fzfoo5sH995BTJMEamVayVlwpOTzjJ52jcvz9mhNYpLQzJm7jDQFwAeL+ B7Fo9ECQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxqff-0004o5-2D; Tue, 21 Jul 2020 11:42:55 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jxqfd-0004nj-AN for linux-rockchip@lists.infradead.org; Tue, 21 Jul 2020 11:42:54 +0000 Received: by mail-yb1-xb49.google.com with SMTP id l17so4869986ybe.18 for ; Tue, 21 Jul 2020 04:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=pUWmRTBLEYRizskyMOfMCe5Obk/Y8AGE+aUZJdC32sg=; b=l/HF4aQ5fNmZm4GESxfFtw4LVaeYuPe/3oJyGtRScaxV0iYCBxNY08NUhoekd8lHPD jIiMqysHDPw126uGY66NT9TmOOwzF5+49L7/rLSpsYUiMHM7vWAFk7bjaKZPkxFSU/S0 MLK8wt1HJGdtb7zJWMO7ahQ4TCEahXAE1hXZuD3Jq2K0Vbg0F2eGhQ6yDLX9YsFx5DvH RAIdn4Jk++d1hwipDZiHiwxNe5d51fJRAdPKJJlu3jNgrWxKmQroa1K8WmCNW1QfAW9u B00tWt4zOkKay9PIIOZVyFobuprBvch01LfN7FKjUxzPXOeJe9R0+XPBnGvbbaZdBJdM 2zSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=pUWmRTBLEYRizskyMOfMCe5Obk/Y8AGE+aUZJdC32sg=; b=aZMZjy2VAx4YBGdufpigIp9ltk5R17fOrddGOz48oDW+Q+jezEq7TeVCPfKf/nSgWc mTtcY5JVaa47jObTcHjd8K+709YKuI3VjfnukMFzkwZkSz1vYnxJHfIqnlTu8NORJQ7J AG8YWNtFe5Cia7s23yfYo+qLGSz7Zh6P+9OW9oA8FI1FBT6RVqTK+OMATKrQ32vM2+1x LAYWUul36Q3N27jvvKdU4PNd0yOq9PIG4/gYlWB37sJXbZCjVIqLyVsDgE8WWFbEze2u W3lz1qamZcTaVSlC8vC4MzJaowWWGqMXswY+B+bwUh3fYqnTd2k6Yat/ONWd9mx49QbJ wbHQ== X-Gm-Message-State: AOAM530jk81NBQrv45j/KgdDiUx1bkmTa4cNRBgNAwoOVnCR859ocp41 MWf8q2054mqKiWYtoD0B3f1QMBcxDYKw X-Google-Smtp-Source: ABdhPJxOVTW+qU+7x9pffdJYq1aJhi17fw4kRMdHq5/8/hmX03tjuhwXL+fYj8cnBgdZ4GLFPI7WD0kscMEy X-Received: by 2002:a25:73ce:: with SMTP id o197mr40510611ybc.13.1595331769688; Tue, 21 Jul 2020 04:42:49 -0700 (PDT) Date: Tue, 21 Jul 2020 19:42:32 +0800 Message-Id: <20200721114232.2812254-1-tzungbi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog Subject: [PATCH] ASoC: max98357a: move control of SD_MODE back to DAI ops From: Tzung-Bi Shih To: broonie@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200721_074253_391728_89A0AF49 X-CRM114-Status: GOOD ( 16.32 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b49 listed in] [list.dnswl.org] -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 DKIMWL_WL_MED DKIMwl.org - Medium sender X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tzungbi@google.com, alsa-devel@alsa-project.org, alpernebiyasak@gmail.com, cychiang@google.com, linux-rockchip@lists.infradead.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org Partially reverts commit 128f825aeab7 ("ASoC: max98357a: move control of SD_MODE to DAPM"). In order to have mute control of max98357 from machine drivers, commit 128f825aeab7 ("ASoC: max98357a: move control of SD_MODE to DAPM") moves the control of SD_MODE from DAI ops to DAPM events. However, pop noise has been observed on rk3399-gru-kevin boards due to this commit. The commit 128f825aeab7 caused sequence of DAI clocks and SD_MODE changed on rk3399-gru-kevin boards. With the commit 128f825aeab7: - SD_MODE will be set to 1 before DAI clocks start. - SD_MODE will be set to 0 after DAI clocks stop. As a result, pop noise. Moves the control of SD_MODE back to DAI ops. In the meantime, uses an additional flag in DAPM event to provide chance of mute control for machine drivers. Signed-off-by: Tzung-Bi Shih Tested-By: Alper Nebi Yasak --- This patch addresses the reported issue in the thread https://lkml.org/lkml/2020/7/16/427 sound/soc/codecs/max98357a.c | 50 ++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c index 4f431133d0bb..918812763884 100644 --- a/sound/soc/codecs/max98357a.c +++ b/sound/soc/codecs/max98357a.c @@ -23,36 +23,61 @@ struct max98357a_priv { struct gpio_desc *sdmode; unsigned int sdmode_delay; + int sdmode_switch; }; -static int max98357a_sdmode_event(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *kcontrol, int event) +static int max98357a_daiops_trigger(struct snd_pcm_substream *substream, + int cmd, struct snd_soc_dai *dai) { - struct snd_soc_component *component = - snd_soc_dapm_to_component(w->dapm); + struct snd_soc_component *component = dai->component; struct max98357a_priv *max98357a = snd_soc_component_get_drvdata(component); if (!max98357a->sdmode) return 0; - if (event & SND_SOC_DAPM_POST_PMU) { - msleep(max98357a->sdmode_delay); - gpiod_set_value(max98357a->sdmode, 1); - dev_dbg(component->dev, "set sdmode to 1"); - } else if (event & SND_SOC_DAPM_PRE_PMD) { + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + mdelay(max98357a->sdmode_delay); + if (max98357a->sdmode_switch) { + gpiod_set_value(max98357a->sdmode, 1); + dev_dbg(component->dev, "set sdmode to 1"); + } + break; + case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: + case SNDRV_PCM_TRIGGER_PAUSE_PUSH: gpiod_set_value(max98357a->sdmode, 0); dev_dbg(component->dev, "set sdmode to 0"); + break; } return 0; } +static int max98357a_sdmode_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, int event) +{ + struct snd_soc_component *component = + snd_soc_dapm_to_component(w->dapm); + struct max98357a_priv *max98357a = + snd_soc_component_get_drvdata(component); + + if (event & SND_SOC_DAPM_POST_PMU) + max98357a->sdmode_switch = 1; + else if (event & SND_SOC_DAPM_POST_PMD) + max98357a->sdmode_switch = 0; + + return 0; +} + static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = { SND_SOC_DAPM_OUTPUT("Speaker"), SND_SOC_DAPM_OUT_DRV_E("SD_MODE", SND_SOC_NOPM, 0, 0, NULL, 0, max98357a_sdmode_event, - SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), + SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD), }; static const struct snd_soc_dapm_route max98357a_dapm_routes[] = { @@ -71,6 +96,10 @@ static const struct snd_soc_component_driver max98357a_component_driver = { .non_legacy_dai_naming = 1, }; +static const struct snd_soc_dai_ops max98357a_dai_ops = { + .trigger = max98357a_daiops_trigger, +}; + static struct snd_soc_dai_driver max98357a_dai_driver = { .name = "HiFi", .playback = { @@ -90,6 +119,7 @@ static struct snd_soc_dai_driver max98357a_dai_driver = { .channels_min = 1, .channels_max = 2, }, + .ops = &max98357a_dai_ops, }; static int max98357a_platform_probe(struct platform_device *pdev)