Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3292918rwa; Tue, 23 Aug 2022 02:08:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR4LTLqW7JxDSW/MboNCl/O/BLdg53zvpMk57lsTEz8mFHUrDZ0z8Oy+3rwat/3ok6gjvHQy X-Received: by 2002:a05:6402:35d4:b0:446:88da:9bd5 with SMTP id z20-20020a05640235d400b0044688da9bd5mr2860951edc.415.1661245702367; Tue, 23 Aug 2022 02:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661245702; cv=none; d=google.com; s=arc-20160816; b=A60xlTM0sGICb0zm2Zq2Um9eHKFSAoMxE3wN66VGyRvuEKEJMm1wdA3gzbXY0BIz+I 0pITfM+RQABHqCwy4zdHun04RdcS5wQK+91JJEugNYKraF/naN7WtCvhnSoQvlBKiySB kZEpkbc/jenhcUwO3JTo/ODfwb3SfChtquwmcMtRkw4eUOppiqcMyce6tLbFGZk5yO1T dHlAevWcHvSQZQ0+ns+KBU0KZJ9sSX58q3VeSVitWNihTvUxPXuz1nKw2OyR6Phj+XiQ FVlgZK1ijiFm4P8Bby6qF9+SAAo+nPsuBEl1LbTcWLNy8vFvLRvUVnw4pMneu4v4Tu7O bG1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+DWoGrFfOWno5k1LaOc07c/Tkn1aqtFu03ekn56Qh2M=; b=bbMl9pAhd9xy+ewiw5m6QcdrLNpj+9epsM6JFBT79/Q0QYs6Otf8IQ+nuWXZTbLs37 hPtMcc+cBFvEUh2MnqzvIxK8afYEw4i3hbAqrgkaYm1Sz/mJX26iUHzqetAhtQnNymC2 K7Jkkbe+55ibvSQpOxr5+C3bI4Lx734927nYjGo6sVZRSCbN0xBnoIBiINjRg7LkJkhd 53xuXnqicQ39x0p+osuHEQGHXwKHr3drfe//vi44+ZPKvB9s7SaKvrU6pPdmCNObO7f+ WYXxSgCBbJNdPEufq+HncVCB3UHRbgj4sFjAr+j7haUw013lkGNz3sKbH40BA2E57Qtd ehwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UCKQ13Pl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc18-20020a170907169200b0073d9ea386d4si1331490ejc.983.2022.08.23.02.07.54; Tue, 23 Aug 2022 02:08:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UCKQ13Pl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240770AbiHWIoJ (ORCPT + 99 others); Tue, 23 Aug 2022 04:44:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347385AbiHWIky (ORCPT ); Tue, 23 Aug 2022 04:40:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2CE24AD4B; Tue, 23 Aug 2022 01:18:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 24B02B81C4E; Tue, 23 Aug 2022 08:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 896EFC433C1; Tue, 23 Aug 2022 08:18:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242733; bh=4jrCeDH5htUTAKRPY4r395KdKhET1ApCrWau5EWtYyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UCKQ13PlR9/DsTvyZMdgmQbLQXlyWD47kAuj5Lxgf6kaN8ZM+3cmzMdj56ltFCZN5 zQj2kTVA1wKAAYCxKoQIQTRFB6UhWaASf/0zniEZ8oL69V0dCQepP83hXCBnNdjVYt IZ/sLfcH9sImkgqjS6Mkr2h6SSOZUz02QQqXXCQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Martin=20Povi=C5=A1er?= , Mark Brown Subject: [PATCH 5.19 183/365] ASoC: tas2770: Fix handling of mute/unmute Date: Tue, 23 Aug 2022 10:01:24 +0200 Message-Id: <20220823080125.881354758@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Povišer commit 1e5907bcb3a3b569be0a03ebe668bba2ed320a50 upstream. Because the PWR_CTRL field is modeled as the power state of the DAC widget, and at the same time it is used to implement mute/unmute, we need some additional book-keeping to have the right end result no matter the sequence of calls. Without this fix, one can mute an ongoing stream by toggling a speaker pin control. Fixes: 1a476abc723e ("tas2770: add tas2770 smart PA kernel driver") Signed-off-by: Martin Povišer Link: https://lore.kernel.org/r/20220808141246.5749-5-povik+lin@cutebit.org Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- sound/soc/codecs/tas2770.c | 57 +++++++++++++++++++++++---------------------- sound/soc/codecs/tas2770.h | 2 + 2 files changed, 32 insertions(+), 27 deletions(-) --- a/sound/soc/codecs/tas2770.c +++ b/sound/soc/codecs/tas2770.c @@ -46,6 +46,26 @@ static void tas2770_reset(struct tas2770 usleep_range(1000, 2000); } +static int tas2770_update_pwr_ctrl(struct tas2770_priv *tas2770) +{ + struct snd_soc_component *component = tas2770->component; + unsigned int val; + int ret; + + if (tas2770->dac_powered) + val = tas2770->unmuted ? + TAS2770_PWR_CTRL_ACTIVE : TAS2770_PWR_CTRL_MUTE; + else + val = TAS2770_PWR_CTRL_SHUTDOWN; + + ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, + TAS2770_PWR_CTRL_MASK, val); + if (ret < 0) + return ret; + + return 0; +} + #ifdef CONFIG_PM static int tas2770_codec_suspend(struct snd_soc_component *component) { @@ -82,9 +102,7 @@ static int tas2770_codec_resume(struct s gpiod_set_value_cansleep(tas2770->sdz_gpio, 1); usleep_range(1000, 2000); } else { - ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, - TAS2770_PWR_CTRL_MASK, - TAS2770_PWR_CTRL_ACTIVE); + ret = tas2770_update_pwr_ctrl(tas2770); if (ret < 0) return ret; } @@ -120,24 +138,19 @@ static int tas2770_dac_event(struct snd_ switch (event) { case SND_SOC_DAPM_POST_PMU: - ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, - TAS2770_PWR_CTRL_MASK, - TAS2770_PWR_CTRL_MUTE); + tas2770->dac_powered = 1; + ret = tas2770_update_pwr_ctrl(tas2770); break; case SND_SOC_DAPM_PRE_PMD: - ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, - TAS2770_PWR_CTRL_MASK, - TAS2770_PWR_CTRL_SHUTDOWN); + tas2770->dac_powered = 0; + ret = tas2770_update_pwr_ctrl(tas2770); break; default: dev_err(tas2770->dev, "Not supported evevt\n"); return -EINVAL; } - if (ret < 0) - return ret; - - return 0; + return ret; } static const struct snd_kcontrol_new isense_switch = @@ -171,21 +184,11 @@ static const struct snd_soc_dapm_route t static int tas2770_mute(struct snd_soc_dai *dai, int mute, int direction) { struct snd_soc_component *component = dai->component; - int ret; - - if (mute) - ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, - TAS2770_PWR_CTRL_MASK, - TAS2770_PWR_CTRL_MUTE); - else - ret = snd_soc_component_update_bits(component, TAS2770_PWR_CTRL, - TAS2770_PWR_CTRL_MASK, - TAS2770_PWR_CTRL_ACTIVE); - - if (ret < 0) - return ret; + struct tas2770_priv *tas2770 = + snd_soc_component_get_drvdata(component); - return 0; + tas2770->unmuted = !mute; + return tas2770_update_pwr_ctrl(tas2770); } static int tas2770_set_bitwidth(struct tas2770_priv *tas2770, int bitwidth) --- a/sound/soc/codecs/tas2770.h +++ b/sound/soc/codecs/tas2770.h @@ -138,6 +138,8 @@ struct tas2770_priv { struct device *dev; int v_sense_slot; int i_sense_slot; + bool dac_powered; + bool unmuted; }; #endif /* __TAS2770__ */