From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796407324; b=KpQSa4H79o+Sf/MHpmyNH5iaSIK7ooD2gWfajvOJZTyZf8nW8xRMhcopSR82CXlHKyif trObktFWKRkD1cKYhH8pUfb2dV8hDvPUzv2E+yDUbNEvnDbGA3y6sg8+Jec+7e0zFtumK sNKQegx05DXAiC58pN3qBVRNTwRaVq2R8/Eg6sFmzyTW/w9WE76R2gPkoExqO/AtQiJUi 9NB3UzNQxwNHqWgAa7/KZ9LLgl3b8dGnmawgDkFz9/Yz+G1xC66lGLsnwgWAQFpi+yBvV dcq5n7OJgCmLAUpbYE7IAkoYW/3dLXQUQ8dT5hCt5s5wAmZdoH1mWAcQYrW3fZDzEQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407324; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jA61fIZXxnEsqzzHuip6MaVOXgkFoMRKZ6mWjybkBfU=; b=BmuNrXUdiTeTaNMBJ2+SwTsLUsZroOdafC71p1YpjI66C1tIeEhYF4oPkBqPxhmZHqIP /oGYsZQFFASKD4KXuPL3xdhAzjsyVQ4E0BoZMbQNVNcgDKIBH+aQnA8rSeNgyAwPjoqPq 65KCouaRGIhrLGhwwelRcn8rtFtOOv84/Bg+cAXj/NsFvjUFJT9ulzbpVUTVY4761jtDL koqYQHbz5sHGe50sX3od1s0PK407SLyYB6/TD0kpiCt3P7GFOlVj4Ia+pPz9VlvG2daUx +ds3HrMoIwTiRJJ0HDIhPzrcdnVAnPTKv7HwpBojtnVJxSxJafZP+NVyLO4737vzekw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SucQoa9O; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 492C7606A336 for ; Fri, 4 Dec 2026 18:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SucQoa9O Received: by smtp.kernel.org (Postfix) with ESMTPSA id B84F11F00A11; Fri, 4 Dec 2026 18:02:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796407323; bh=jA61fIZXxnEsqzzHuip6MaVOXgkFoMRKZ6mWjybkBfU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SucQoa9OEny0CR3QOhw+yCUOhX5jRpK0rDxSDEvxRQC9rN8Nhw/82DqFAbxbOFKhC CfaN+/wgSor6saFAJzUlC8zIsSsXSIUtxsQboYJTyjkVyJUk7Pq1odWb0HhskOFAa/ V5Ww4K2aeYdI0C8VnZsckWQSmt+JbEvXriqRTHU2SyfRFxvZJTKGZGxISqstHLI1HQ 0vIjeBN6Gq99gCpTsuJ5dGabSbQ7ThaMbMrHG1cq38t7Qo25orl3cdIo0BVVgowXU8 X+fHN9devXsSIMn8Zv4fA1r2wcBeUph0XXxg5c31c5T2+/qjj0Lz41fJHhDwdotnEY /uIHwTfBUtA/w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ASoC: pcm1681: Establish contact with the DAC lazily Reply-To: sashiko-reviews@lists.linux.dev To: "Mohammad Rafi Shaik" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261204173012.3644350-1-mohammad.rafi.shaik@oss.qualcomm.com> References: <20261204173012.3644350-1-mohammad.rafi.shaik@oss.qualcomm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 18:02:03 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [High] ASoC: pcm1681: resume skips wait and leaves active stream in cache-only mode - [Medium] ASoC: pcm1681: pcm1681_ensure_ready() clears cache_only before DAC is ready - [Medium] ASoC: pcm1681: pcm1681_soft_reset() toggles cache_bypass without locking - [Medium] ASoC: pcm1681: ready and cache-only only reset in pcm1681_runtime_suspend() - [Medium] ASoC: pcm1681: probe and hw_params stall via pcm1681_ensure_ready() -- commit 75104116faab40978c73eecd5c4a280bc41e56fd Author: Mohammad Rafi Shaik ASoC: pcm1681: Establish contact with the DAC lazily This commit keeps the pcm1681 regmap in cache-only mode until the DAC control port responds, probing and soft-resetting it lazily from pcm1681_ensure_ready() in probe, runtime resume, and hw_params. > diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c > index 2aae372389ad6..3ad0582cb6f0d 100644 > --- a/sound/soc/codecs/pcm1681.c > +++ b/sound/soc/codecs/pcm1681.c [ ... ] > +static int pcm1681_soft_reset(struct pcm1681_private *priv) > +{ > + int ret; > + > + /* > + * SRST is cleared by the reset it triggers, so it must not end up in > + * the cache, where it would be replayed on every resume. > + */ > + regcache_cache_bypass(priv->regmap, true); > + ret =3D regmap_write(priv->regmap, PCM1681_DEEMPH_CONTROL, PCM1681_SRST= ); > + regcache_cache_bypass(priv->regmap, false); [Severity: Medium] Can toggling regcache_cache_bypass() across separate regmap calls silently drop a concurrent ALSA mixer update? regcache_cache_bypass() releases the regmap lock as soon as it returns, and ALSA kcontrol writes only hold card->controls_rwsem while pcm1681_hw_params() holds card->pcm_mutex: CPU0 CPU1 pcm1681_hw_params() snd_ctl_elem_write() pcm1681_ensure_ready() soc_put_volsw() pcm1681_soft_reset() regcache_cache_bypass(..., true) regmap_update_bits() <-- skips regcache_write() regmap_write(..., PCM1681_SRST) regcache_cache_bypass(..., false) regcache_sync() <-- overwrites with stale cache The kcontrol write returns success to userspace, bypasses the cache, is wiped by PCM1681_SRST, and is then overwritten with the old cached value. Using regmap_multi_reg_write_bypassed() (or a codec mutex) would keep the bypassed write atomic with respect to other regmap callers. [ ... ] > +static int pcm1681_ensure_ready(struct pcm1681_private *priv, struct dev= ice *dev, > + bool wait) > +{ > + unsigned int val; > + int err =3D 0, ret; > + > + if (priv->ready) > + return 0; > + > + regcache_cache_only(priv->regmap, false); > + > + /* The status register is volatile, so a read of it reaches the device = */ > + if (wait) { > + pcm1681_sck_delay(priv, PCM1681_SCK_SETTLE_CYCLES); > + > + ret =3D read_poll_timeout(regmap_read, err, !err, > + PCM1681_READY_POLL_US, > + PCM1681_READY_TIMEOUT_US, false, > + priv->regmap, PCM1681_ZERO_DETECT_STATUS, > + &val); [Severity: Medium] Does clearing cache_only before the settle delay and polling loop expose concurrent ALSA mixer writes to the same failed-write cache eviction? Clearing regcache_cache_only() opens an up to ~115 ms window across pcm1681_sck_delay(), read_poll_timeout(), and the post-SRST delay in pcm1681_soft_reset() while the DAC is still unresponsive or resetting: CPU0 CPU1 pcm1681_hw_params() snd_ctl_elem_write() pcm1681_ensure_ready() soc_put_volsw() regcache_cache_only(..., false) pcm1681_sck_delay(...) regmap_update_bits() _regmap_raw_write_impl() <-- I2C NACK, drops cache entry When that write fails on I2C, _regmap_raw_write_impl() calls map->cache_ops->drop() on [reg, reg + 1]. Even if pcm1681_ensure_ready() later succeeds, regcache_sync() skips the evicted registers and leaves the DAC at its 0xff (0 dB) reset defaults; if readiness fails and restores cache-only mode, later reads of those registers fail with -EBUSY. Probing while still in cache-only mode (for example via regmap_read_bypassed()) and serializing the reset/sync sequence against control writes would close this window. [ ... ] > @@ -378,7 +504,12 @@ static int pcm1681_i2c_probe(struct i2c_client *clie= nt) > if (ret) > return dev_err_probe(dev, ret, "Failed to enable sck\n"); > =20 > - pcm1681_sck_settle(priv); > + /* > + * Take the first chance to set the DAC up. Not being able to is not > + * fatal, it only means sck is not running yet and the first stream has > + * to wait out the reset instead. > + */ > + pcm1681_ensure_ready(priv, dev, true); [Severity: Medium] Should pcm1681_i2c_probe() pass wait =3D false, or avoid polling here, to prevent a synchronous boot-probe stall? On Qualcomm q6prm boards where sck is initialized to 19.2 MHz but not driven at probe, calling pcm1681_ensure_ready(..., true) sleeps 3.4 ms and then polls for the full 50 ms timeout, generating roughly 50 to 200 NACKed I2C reads before discarding the error (where probe previously slept 3.4 ms with no I2C traffic). On boards without an sck DT clock, falling back to PCM1681_SCK_MIN_RATE in pcm1681_sck_delay() also adds a 65 ms delay to probe even when the DAC is already ready (114 ms if unclocked). Contrary to the comment on PCM1681_SCK_MIN_RATE, that 65 ms delay also applies in pcm1681_hw_params() on every stream start after runtime autosuspend whenever clk_get_rate() returns 0. [ ... ] > @@ -430,6 +561,7 @@ static int pcm1681_runtime_suspend(struct device *dev) > */ > regcache_cache_only(priv->regmap, true); > regcache_mark_dirty(priv->regmap); > + priv->ready =3D false; > =20 > clk_disable_unprepare(priv->sck); [Severity: Medium] Can priv->ready stay true and regmap stay out of cache-only mode after the host CPU DAI has already gated sck? When a stream closes, soc_pcm_clean() calls snd_soc_dai_shutdown() on the CPU DAI (tearing down the audio interface and stopping sck in q6i2s_lpass_dai_shutdown()) before dropping the codec's runtime PM reference via pm_runtime_put_autosuspend(). Because pcm1681_i2c_probe() uses a 100 ms autosuspend delay (and .use_pmdown_time =3D 1 can extend this to 5.1 s on non-DPCM links), pcm1681_runtime_suspend() does not run right away. During that window, a mixer write hits the unclocked DAC and fails with -ENXIO, dropping the register from the cache. A back-to-back stream opened before autosuspend fires hits if (priv->ready) return 0 in pcm1681_ensure_ready(), skipping settling, pcm1681_soft_reset(), and regcache_sync(), so lost DAC registers remain at reset defaults. Re-entering cache-only mode and clearing priv->ready in a DAI .shutdown callback would cover the gap. [ ... ] > @@ -447,16 +579,13 @@ static int pcm1681_runtime_resume(struct device *de= v) > return ret; > } > =20 > - pcm1681_sck_settle(priv); > - > - regcache_cache_only(priv->regmap, false); > - ret =3D regcache_sync(priv->regmap); > - if (ret) { > - dev_err(dev, "Failed to sync regcache: %d\n", ret); > - regcache_cache_only(priv->regmap, true); > - clk_disable_unprepare(priv->sck); > - return ret; > - } > + /* > + * Gating sck does not put the DAC back into reset, so if sck is running > + * the control port answers right away and the cache can be replayed > + * here. If it is not, hw_params is left to wait out the reset, resuming > + * is not a reason to fail and not a reason to stall either. > + */ > + pcm1681_ensure_ready(priv, dev, false); > =20 > return 0; > } [Severity: High] Does skipping the wait here leave an active playback stream stuck in cache-only mode across system suspend and resume? pcm1681_pm_ops uses DEFINE_RUNTIME_DEV_PM_OPS(), so system suspend runs pcm1681_runtime_suspend() (setting cache_only and priv->ready =3D false) and system resume runs pcm1681_runtime_resume(). If sck is not running yet on resume, or the DAC needs reset settling after sleep, pcm1681_ensure_ready(..., false) fails and leaves the regmap in cache-only mode. On resume, snd_soc_card_resume_deferred() unmutes active DACs and userspace recovers SNDRV_PCM_STATE_SUSPENDED via snd_pcm_prepare() -> __soc_pcm_prepare() without calling pcm1681_hw_params(). Because pcm1681_dai_ops has no .prepare callback and pcm1681_mute() does not call pcm1681_ensure_ready(), the resumed stream never leaves cache-only mode and never syncs format, attenuation, or unmute writes to the DAC until the stream is closed and reopened. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204173012.3644= 350-1-mohammad.rafi.shaik@oss.qualcomm.com?part=3D1