Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2073039rwb; Fri, 2 Dec 2022 05:15:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf69JSqA75oizacxiQPTm6vB3PBwGCBsZV3PqwmT8OsqcAVhPAVgNQziC6od7cxwWR8qgGlC X-Received: by 2002:a17:906:658:b0:7ae:df97:9ff4 with SMTP id t24-20020a170906065800b007aedf979ff4mr10864063ejb.762.1669986916292; Fri, 02 Dec 2022 05:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669986916; cv=none; d=google.com; s=arc-20160816; b=lKq4PjzX/BBrHAfqtG2HozqQ12OUYXaLgl68hBxWR4PhvoHpaH3N2q5mtsXAhghB5a 6u0vA9gxrveICs+3Qj2jLTFGcRybNi7kCY3yKL3kjuU2m6l5izenrzOzRa3u4RfEQywG KlzaLvlSSu9JrzVatp3YoAsQQTBGGaslTcYFgQ5ktfx5qfHPN5EyIjGAeArGtgGEdtKj OemvLfrhe/7doheZcwew+gnn9vsHNz3u72EYHFLgjq52s4i6aeHi9sxtHvV/pHc5Q4Qa iV1svXQ2PWovsAF6NcaZOxvM9aSwukPP0vAPW9rE0xOZrscaCbP9FyWPD7I2Z2tG5m3q ig1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=DhGdxpJEkjYywcSuSWVbyLC7MtBW/7xgB641h9cKPo4=; b=JA+CguNspu/poQGlmZXS82OhZl643wkBLIT9yhQdBDkqGAMS7TpNGNQry2bgBU8FXN 1egowWq4Jwn3SVnuewREIkX3yuAautSPSIByE/KQjZo2d+jyu4lcRU2GW+Lth0SlC1dF aBlx7tXBaEjghCRukV8agyB/XElTwT1Vv8zmirMralZ4Q0g0rU4vGlAV6SkJWuJ6ojHK VjFdMTGFVICczT0WTi0U3uI09rI3aUxaph45WG8IYlssN/cqkMordE1AZgsDZLwoCOup yPX4IXgWZbuPqMCbFMR7+Mnql4aPdq4AVfH1xeSL3ECO4JFPHS0h4Y8UZ2E1PyDy3ypS YADw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=IL4kNpSF; 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 e6-20020a056402190600b00468cd2ab847si6389528edz.172.2022.12.02.05.14.54; Fri, 02 Dec 2022 05:15:16 -0800 (PST) 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=IL4kNpSF; 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 S233485AbiLBMat (ORCPT + 83 others); Fri, 2 Dec 2022 07:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbiLBMar (ORCPT ); Fri, 2 Dec 2022 07:30:47 -0500 X-Greylist: delayed 359 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 02 Dec 2022 04:30:44 PST Received: from hutie.ust.cz (hutie.ust.cz [185.8.165.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E846C8D648 for ; Fri, 2 Dec 2022 04:30:44 -0800 (PST) Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1669983879; bh=DhGdxpJEkjYywcSuSWVbyLC7MtBW/7xgB641h9cKPo4=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=IL4kNpSFC8k/yBhtt9cknfsI2E6UirQsg42bUDsGBfK8kpkUktkO+W+rP+2ILv1fB XmTr7UuDGZXD1uNc5DmvPyPPHCTujbiM1DfbpzmH3SLsrsFhG1ydwVW1Y1Wy2BorM8 RhKQFoGpme26jd+CHWig9w1cloA39sPCcuwkqT04= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH] ASoC: tas27{64,70}: fix PM ops ordering From: =?utf-8?Q?Martin_Povi=C5=A1er?= In-Reply-To: <20221202115855.16483-1-jcalligeros99@gmail.com> Date: Fri, 2 Dec 2022 13:24:38 +0100 Cc: Linux-ALSA , Jaroslav Kysela , Takashi Iwai , Linux Kernel Mailing List , shenghao-ding@ti.com, kevin-lu@ti.com Content-Transfer-Encoding: quoted-printable Message-Id: <642B09FF-E7CC-481A-9EC7-88B74FA830CB@cutebit.org> References: <20221202115855.16483-1-jcalligeros99@gmail.com> To: James Calligeros 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 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 (Copying in some TI addresses which may be interested.) > On 2. 12. 2022, at 12:58, James Calligeros = wrote: >=20 > On both tas2764 and tas2770, a write to PWR_CTRL is attempted > on resume before syncing the regcache to the chip, potentially leaving > it in an undefined state that causes resume to fail. The codec > is then unavailable until the next system reset. I think we need to split this into separate tas2764 and tas2770 changes. So, concentrating on tas2764 first: The issue here isn=E2=80=99t that a write is attempted before the device = is synced and while the regcache is in cache-only state. That=E2=80=99s on its own = OK. The issue here is that all registers including PWR_CTRL are restored in one go, and that can cause issues since we need the device properly configured before raising its power state. > On tas2770 specifically, both suspend and resume ops attempt useless > register writes on unrestored registers. This causes its state to be > desynchronised from what ASoC expects it to be in. >=20 > These two codecs are almost identical, so unify their behaviour > and reorder the ops so that the codec is always suspended and > resumed in a known/expected state. I suggest we make the first commit fix up tas2764 suspend/resume code to a state that=E2=80=99s OK, then second commit copies that over to tas2770 to replace what=E2=80=99s there now. (Pointing out some of = the things that=E2=80=99s wrong with the old code.) > Suggested-by: Martin Povi=C5=A1er > Signed-off-by: James Calligeros > --- > sound/soc/codecs/tas2764.c | 11 +++++++---- > sound/soc/codecs/tas2770.c | 40 ++++++++++++++++++++------------------ > 2 files changed, 28 insertions(+), 23 deletions(-) >=20 > diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c > index 2e0ed3e68fa5..51c6b3a940c4 100644 > --- a/sound/soc/codecs/tas2764.c > +++ b/sound/soc/codecs/tas2764.c > @@ -32,7 +32,7 @@ struct tas2764_priv { > struct regmap *regmap; > struct device *dev; > int irq; > -=09 > + Stray whiteline change here > int v_sense_slot; > int i_sense_slot; >=20 > @@ -157,14 +157,17 @@ static int tas2764_codec_resume(struct = snd_soc_component *component) > usleep_range(1000, 2000); > } >=20 > - ret =3D tas2764_update_pwr_ctrl(tas2764); > + regcache_cache_only(tas2764->regmap, false); >=20 > + ret =3D regcache_sync(tas2764->regmap); > if (ret < 0) > return ret; >=20 > - regcache_cache_only(tas2764->regmap, false); > + ret =3D tas2764_update_pwr_ctrl(tas2764); > + if (ret < 0) > + return ret; >=20 > - return regcache_sync(tas2764->regmap); > + return 0; > } > #else > #define tas2764_codec_suspend NULL > diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c > index 8557759acb1f..5c9e8419b387 100644 > --- a/sound/soc/codecs/tas2770.c > +++ b/sound/soc/codecs/tas2770.c > @@ -72,25 +72,21 @@ static int tas2770_codec_suspend(struct = snd_soc_component *component) > struct tas2770_priv *tas2770 =3D = snd_soc_component_get_drvdata(component); > int ret =3D 0; >=20 > + ret =3D snd_soc_component_update_bits(component, = TAS2770_PWR_CTRL, > + TAS2770_PWR_CTRL_MASK, > + = TAS2770_PWR_CTRL_SHUTDOWN); > + > + if (ret < 0) > + return ret; > + > regcache_cache_only(tas2770->regmap, true); > - regcache_mark_dirty(tas2770->regmap); > + regcache_sync(tas2770->regmap); >=20 > - if (tas2770->sdz_gpio) { > + if (tas2770->sdz_gpio) > gpiod_set_value_cansleep(tas2770->sdz_gpio, 0); > - } else { > - ret =3D snd_soc_component_update_bits(component, = TAS2770_PWR_CTRL, > - = TAS2770_PWR_CTRL_MASK, > - = TAS2770_PWR_CTRL_SHUTDOWN); > - if (ret < 0) { > - regcache_cache_only(tas2770->regmap, false); > - regcache_sync(tas2770->regmap); > - return ret; > - } >=20 > - ret =3D 0; > - } >=20 > - return ret; > + return 0; > } >=20 > static int tas2770_codec_resume(struct snd_soc_component *component) > @@ -98,18 +94,24 @@ static int tas2770_codec_resume(struct = snd_soc_component *component) > struct tas2770_priv *tas2770 =3D = snd_soc_component_get_drvdata(component); > int ret; >=20 > + > if (tas2770->sdz_gpio) { > gpiod_set_value_cansleep(tas2770->sdz_gpio, 1); > usleep_range(1000, 2000); > - } else { > - ret =3D tas2770_update_pwr_ctrl(tas2770); > - if (ret < 0) > - return ret; > } >=20 > regcache_cache_only(tas2770->regmap, false); >=20 > - return regcache_sync(tas2770->regmap); > + ret =3D regcache_sync(tas2770->regmap); > + if (ret < 0) > + return ret; > + > + ret =3D tas2770_update_pwr_ctrl(tas2770); > + if (ret < 0) > + return ret; > + > + > + return 0; > } > #else > #define tas2770_codec_suspend NULL > --=20 > 2.38.1 >=20