Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp717260rwe; Thu, 25 Aug 2022 08:04:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR6uRY4h9/wOD3i9dIlqHumoymqc9nRcqxlAij8s3iG02JHioM/eRbXLpJ9VZEF/0L6PXYAd X-Received: by 2002:a05:6a00:228c:b0:536:cd2c:c9f3 with SMTP id f12-20020a056a00228c00b00536cd2cc9f3mr4438059pfe.62.1661439875422; Thu, 25 Aug 2022 08:04:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661439875; cv=none; d=google.com; s=arc-20160816; b=tslampqlMcXerYmd0ceN+TFf+UQngDx06u8ksYGA0nivNKGpwTaE9VuhwY/h83wpXJ 2erryS/wIJyKgk3OEJm2R+kZqS36gIUM/icJ3w/Qu2zvee9vTRPFsZdjOHgYCokYkKFD rwHL9OTWM7VF3q8iWxsaUPff+pYzERJNR8aNOmuDZLeLlfK9WZnP7Vhs5TbRrU4tBKDh o3KWiDwHPGpGZFUNORPA0PAna8p7E/8xnOfm/RzNVBKmt7oK3Wco2Px99xyjRqa2FavR 5CtI9KAa7L+2UjiYW9GxmiJzdVlgZqhH8dsN2ZA3uO9ce9sE2ovyzkwL4eln4zYVinrR bjiQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :from; bh=5RGgH1AcjF5BtsgHx+ZoU5Me0+YKLfaL9/ywuzhYSio=; b=BrSU0+69AYkXNLS6eQrQHIQmgQwDrSVJwL/DM6k/iedF57qdZjzzXaLPp11A6RwXxJ kOnkXkVeeL216M8QalhKiPsIj3PaEsKFSqQQhZpj0AHqTK/IYKQS2v/TKqh/yyVKIFy5 aYmpZDGIDLzAvm12DkRlJpR3LgZr7rYzrGjSDUm8NasDgCTufv+N2WOYhw0ZnO3dcsaS TKmYtlhntF+ZpGohd53Ef6RF6du+NPHm9Yvv61jaIExw/GZIa8SbPHNDyFyHoc2/HOvv vUd41k6GliHbwdkDkK3aItgCzWmWp79uGDZtiAb+vPUW8Dc3pale90v92mJhuAwl+yK8 zC6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=SYyOmV2P; 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=cutebit.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d2-20020a170902cec200b0016bfdcb6f11si22666594plg.194.2022.08.25.08.04.23; Thu, 25 Aug 2022 08:04:35 -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=@cutebit.org header.s=mail header.b=SYyOmV2P; 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=cutebit.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240821AbiHYOXD (ORCPT + 99 others); Thu, 25 Aug 2022 10:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238113AbiHYOWp (ORCPT ); Thu, 25 Aug 2022 10:22:45 -0400 Received: from hutie.ust.cz (hutie.ust.cz [185.8.165.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157C2B5156 for ; Thu, 25 Aug 2022 07:22:43 -0700 (PDT) From: =?UTF-8?q?Martin=20Povi=C5=A1er?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1661437362; bh=5RGgH1AcjF5BtsgHx+ZoU5Me0+YKLfaL9/ywuzhYSio=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SYyOmV2P5l7WMaWO/z5fBxhZuxZpcmFDcNLB/3Vj+yLexFc/x98roK9dYw4NbNWIk xxyWH6utfs7iE0IF6RTOGYSJiRlkcdXdhbRAibmKNDYsAPYZ+i+HNgBwvVGubkmCv7 koH8M+uW3wkHWwmy55xkqXtbs/dHDBE6JV2hOPRM= To: Liam Girdwood , Mark Brown Cc: navada@ti.com, shenghao-ding@ti.com, asyrus@ti.com, raphael-xu@ti.com, =?UTF-8?q?Martin=20Povi=C5=A1er?= , Stephen Kitt , Charles Keepax , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] ASoC: tas2562: Fix mute/unmute Date: Thu, 25 Aug 2022 16:22:26 +0200 Message-Id: <20220825142226.80929-3-povik+lin@cutebit.org> In-Reply-To: <20220825142226.80929-1-povik+lin@cutebit.org> References: <20220825142226.80929-1-povik+lin@cutebit.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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 permanently mutes an ongoing stream by toggling the associated speaker pin control. (This mirrors commit 1e5907bcb3a3 ("ASoC: tas2770: Fix handling of mute/unmute") which was a fix to the tas2770 driver.) Signed-off-by: Martin PoviĊĦer --- sound/soc/codecs/tas2562.c | 55 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/sound/soc/codecs/tas2562.c b/sound/soc/codecs/tas2562.c index 2b0cdb6d1600..66149055aba9 100644 --- a/sound/soc/codecs/tas2562.c +++ b/sound/soc/codecs/tas2562.c @@ -54,6 +54,8 @@ struct tas2562_data { int i_sense_slot; int volume_lvl; int model_id; + bool dac_powered; + bool unmuted; }; enum tas256x_model { @@ -351,30 +353,43 @@ static int tas2562_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) return 0; } +static int tas2562_update_pwr_ctrl(struct tas2562_data *tas2562) +{ + struct snd_soc_component *component = tas2562->component; + unsigned int val; + int ret; + + if (tas2562->dac_powered) + val = tas2562->unmuted ? + TAS2562_ACTIVE : TAS2562_MUTE; + else + val = TAS2562_SHUTDOWN; + + ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL, + TAS2562_MODE_MASK, val); + if (ret < 0) + return ret; + + return 0; +} + static int tas2562_mute(struct snd_soc_dai *dai, int mute, int direction) { - struct snd_soc_component *component = dai->component; + struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(dai->component); - return snd_soc_component_update_bits(component, TAS2562_PWR_CTRL, - TAS2562_MODE_MASK, - mute ? TAS2562_MUTE : 0); + tas2562->unmuted = !mute; + return tas2562_update_pwr_ctrl(tas2562); } static int tas2562_codec_probe(struct snd_soc_component *component) { struct tas2562_data *tas2562 = snd_soc_component_get_drvdata(component); - int ret; tas2562->component = component; if (tas2562->sdz_gpio) gpiod_set_value_cansleep(tas2562->sdz_gpio, 1); - ret = snd_soc_component_update_bits(component, TAS2562_PWR_CTRL, - TAS2562_MODE_MASK, TAS2562_MUTE); - if (ret < 0) - return ret; - return 0; } @@ -428,30 +443,18 @@ static int tas2562_dac_event(struct snd_soc_dapm_widget *w, switch (event) { case SND_SOC_DAPM_POST_PMU: - ret = snd_soc_component_update_bits(component, - TAS2562_PWR_CTRL, - TAS2562_MODE_MASK, - TAS2562_MUTE); - if (ret) - goto end; + tas2562->dac_powered = true; + ret = tas2562_update_pwr_ctrl(tas2562); break; case SND_SOC_DAPM_PRE_PMD: - ret = snd_soc_component_update_bits(component, - TAS2562_PWR_CTRL, - TAS2562_MODE_MASK, - TAS2562_SHUTDOWN); - if (ret) - goto end; + tas2562->dac_powered = false; + ret = tas2562_update_pwr_ctrl(tas2562); break; default: dev_err(tas2562->dev, "Not supported evevt\n"); return -EINVAL; } -end: - if (ret < 0) - return ret; - return 0; } -- 2.33.0