From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F38B81DF269; Mon, 4 Aug 2025 00:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754268039; cv=none; b=JB9zphcNqg9WbMRWX1h5Kdsv1jURCNw2BHa8NQd2nNw544eAXBtDlOfR//pUK4Yb1MEYO2j3UULC0rUCFxdYm1ivOisOKoS/+SYOQClgtQBw4e8USRAHu0gqhDKzOdj7OJ22FHCfV/gjFX3Pncdfpx8DNqumZskQCsglIjy8oGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754268039; c=relaxed/simple; bh=GrZMN1ctYClu+Qt27newfYtAy9wGy5zkAcrdofZY1HQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PnSM4HjIDRNp1cXuXrla0jP5l1tnwhxL248OVJdwpCIyRS0r9pTKJrujI6XRCDLcEeS9W/OyND307m6ENsZcsMlCKwcBP3JIitfsJHLQ0o5zmRB/5cwPCxac7giRjSwy7HmM5lv5U9Mq7hdarsZtdllqL8osSXBktxQd2wsic30= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cg5JGiEm; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cg5JGiEm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78755C4CEEB; Mon, 4 Aug 2025 00:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1754268038; bh=GrZMN1ctYClu+Qt27newfYtAy9wGy5zkAcrdofZY1HQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cg5JGiEmEsz1YMTXL18r0YKaaekFoHwmp5m3LhR5vJH2uovKECxRUQ7TxxDLgiD5a 3UhBWktXmeRo7O/FMyfQkcC8H5NrneZ6Znbo98QV1F1icbJycRi/RXvMetoDsicdWW Bc8TxViYqNDBRW2TSufVHZ4gOeF9C6SRr2CX+yIjS3OkFmRAM5ItsIpJpHd+DKLuFc C+atvKLP7hY5psj8AeZ6OAieuW61Dzy2DLsHgSFFuWTIzf/kdHfSn9YGyMobYlrSPR nCNbe4UPPBYyYHLDnJJ1+xtCx7c/fATZWUF8PCi7pmLkujv5u0dQ6+9pU/6tLx0sdX P39zE9SfGUAiw== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Xinxin Wan , =?UTF-8?q?Amadeusz=20S=C5=82awi=C5=84ski?= , Cezary Rojewski , Mark Brown , Sasha Levin , oder_chiou@realtek.com Subject: [PATCH AUTOSEL 5.15 44/44] ASoC: codecs: rt5640: Retry DEVICE_ID verification Date: Sun, 3 Aug 2025 20:38:49 -0400 Message-Id: <20250804003849.3627024-44-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250804003849.3627024-1-sashal@kernel.org> References: <20250804003849.3627024-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.189 Content-Transfer-Encoding: 8bit From: Xinxin Wan [ Upstream commit 19f971057b2d7b99c80530ec1052b45de236a8da ] To be more resilient to codec-detection failures when the hardware powers on slowly, add retry mechanism to the device verification check. Similar pattern is found throughout a number of Realtek codecs. Our tests show that 60ms delay is sufficient to address readiness issues on rt5640 chip. Reviewed-by: Amadeusz Sławiński Reviewed-by: Cezary Rojewski Signed-off-by: Xinxin Wan Signed-off-by: Cezary Rojewski Link: https://patch.msgid.link/20250530142120.2944095-3-cezary.rojewski@intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- LLM Generated explanations, may be completely bogus: **Backport Status: YES** This commit should be backported to stable kernel trees. Here's my detailed analysis: ## Analysis of the Commit ### 1. Bug Fix Nature This commit fixes a real-world hardware detection issue where the RT5640 codec device ID verification fails on systems where the hardware powers on slowly. The failure results in the driver returning `-ENODEV` and the audio codec not being initialized, causing complete audio failure. ### 2. Small and Contained Change The fix is minimal and highly contained: - Only adds 3 lines of code - The change is isolated to the probe function's device ID verification logic - No architectural changes or new features introduced - The retry logic is simple: if initial ID read doesn't match, wait 60-100ms and retry once ### 3. Clear Purpose with No Major Side Effects The code change: ```c regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); +if (val != RT5640_DEVICE_ID) { + usleep_range(60000, 100000); + regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); +} ``` - Only adds a single retry with delay if the first read fails - The delay (60-100ms) is reasonable for probe-time initialization - No impact on normal operation when hardware is ready ### 4. Follows Established Pattern The commit message mentions "Similar pattern is found throughout a number of Realtek codecs," and the probe function already contains a 400ms delay after enabling LDO1 (line 3004), showing that power-on delays are expected for this hardware. ### 5. Minimal Risk of Regression - The retry only occurs when device ID verification would have failed anyway - In the worst case, it adds a 60-100ms delay to failed probe attempts - Systems where the codec is ready immediately continue to work without delay - The pattern is conservative: only one retry attempt ### 6. Important User Impact Without this fix, affected systems experience: - Complete audio failure on boot - No audio codec detection - Requires manual intervention or multiple reboots to get audio working ### 7. Stable Tree Suitability This fix meets all stable kernel criteria: - Fixes a real bug affecting users - Minimal change with clear purpose - No new features or APIs - Low risk of introducing new issues - Self-contained within a single driver The commit represents a classic hardware quirk fix that improves reliability without adding complexity, making it an ideal candidate for stable backport. sound/soc/codecs/rt5640.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c index cd1db5caabad..9998bdb954ba 100644 --- a/sound/soc/codecs/rt5640.c +++ b/sound/soc/codecs/rt5640.c @@ -2837,6 +2837,11 @@ static int rt5640_i2c_probe(struct i2c_client *i2c, } regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); + if (val != RT5640_DEVICE_ID) { + usleep_range(60000, 100000); + regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); + } + if (val != RT5640_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %#x is not rt5640/39\n", val); -- 2.39.5