From patchwork Wed Sep 13 15:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 138923 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1195951vqx; Wed, 13 Sep 2023 09:13:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFI4MgnsxtSXl4I86tUUYVEsBqP6+rMob6QAaatPmB9fi8Y+0D/fEX49f6ZMY2rQ1ln8vWh X-Received: by 2002:aca:1b18:0:b0:3a7:cccd:33e9 with SMTP id b24-20020aca1b18000000b003a7cccd33e9mr3435790oib.41.1694621631360; Wed, 13 Sep 2023 09:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694621631; cv=none; d=google.com; s=arc-20160816; b=Qrb2l/w27lmb1L9TZDULgNhERth9eJuowfGBVwYE6ZfGTaHUJGBIR7ycDdVbOSVqyt C9OxyDMKTU/YCKS5X0NKozd58esexLum+JfzfrQdMoRPg+yUC7Nmp7GTSvFiRJzNrVsw JLG/bKJQct+tk0a3PgljPJtKZts9r14XFozUKP87m09g6dBoj9sRBKYnBKbI3jTsrHql qKk6pZKViQLC5/NNgXfzAofRyEtPa4xzsm4aqkCDm2r5EZXFn5BXFYgMYV1I//OmqKo5 7S2h8uhfHMexzTWClH87zemDTvPf4JV8SLjdIgTo6EL4z/wbizlNOj85rBtye6H8knco BY7g== 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:from :dkim-signature; bh=Dh+rm8/z+C93/OT9V7lVmPaM5s4LmDAFqoJT9hkB4GU=; fh=nLTNXObJ5oqFazCRfk6NCsjnmxCjZ5yWeCYqqRZCVhM=; b=r+j5ry1LR+EBVlvrXbW/HP7VZ+Wqm3dqznPlTuXMB9CD9Ira26YDY1J1ccfXW22uAG UU+PHKPSKMf2aE5xqzI9wO5W/OggpG2kmO64QgMZntrgSfliJHjRQsSMOAIrVQZAN1dH UxcYd/V2SQCE2sF+kdPgcEdR7atp3tHeKMI1hwdRNclGqsvaei4UqL82cdjXOaQMjDTf ilEx1fLsE+bP7XdKdTb/eHd0TNs1TI61fwS+gboR7Ko3Mahhvp8UN8KPh/4aTQMXzucM kBAi1+N4wT7S/tsTwlb2km2A9CbYGB+1nm22ZvxcKT9ndjf6ai3qzIFYmgIiYm79bP3+ Ya2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=qvciHAJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w24-20020a637b18000000b00565550ba905si7653242pgc.622.2023.09.13.09.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 09:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=qvciHAJn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 1E80680E6C89; Wed, 13 Sep 2023 08:01:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240971AbjIMPAl (ORCPT + 36 others); Wed, 13 Sep 2023 11:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234329AbjIMPAh (ORCPT ); Wed, 13 Sep 2023 11:00:37 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31F6AB3 for ; Wed, 13 Sep 2023 08:00:33 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38CMxBYs012824; Wed, 13 Sep 2023 10:00:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=Dh+rm8/z+C93/OT9V7lVmPaM5s4LmDAFqoJT9hkB4GU=; b= qvciHAJn7z2vKVWeICmAqeZ/0vJ4Tu44gm11e1i5y2Iy3QN9L3Aa0/dSTinHheUw ns7jln0/ET8PAgrT6rGUj9ROC4NPQ6HTWVn24N6YqnNuplaKFw+TdToWlUbG9J6z 4PdDiNBtZXWixvbIBQ0jTQPjoE9SRlF6kCF9XpaUQn9XB6E6NqTCWioojDJurgGL vuCqbkX9g9MDH7TpsOZsHrBJmcyxN6X2Xppz5CBun23CFjsDitOlu7nWuWDT4eQB hAF/XxYm5szXcdfHhgRRt1W4tU66DBAShSlQdiMaKOK3VxZW+j1NFYqwKMQXfKdu ND45i4zVjCZ9bSh/mvnL8A== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3t2y7u125n-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Sep 2023 10:00:23 -0500 (CDT) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 13 Sep 2023 16:00:20 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.37 via Frontend Transport; Wed, 13 Sep 2023 16:00:20 +0100 Received: from sbinding-cirrus-dsktp2.ad.cirrus.com (unknown [198.90.238.120]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 21DCB11AA; Wed, 13 Sep 2023 15:00:20 +0000 (UTC) From: Stefan Binding To: Mark Brown , Uday M Bhat , Pierre-Louis Bossart CC: , , , Richard Fitzgerald , Stefan Binding Subject: [PATCH v1 1/3] ASoC: cs42l42: Ensure a reset pulse meets minimum pulse width. Date: Wed, 13 Sep 2023 16:00:10 +0100 Message-ID: <20230913150012.604775-2-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230913150012.604775-1-sbinding@opensource.cirrus.com> References: <20230913150012.604775-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: oQb8ia575QRFzeNOv0q-cj2ulpxtpl8e X-Proofpoint-ORIG-GUID: oQb8ia575QRFzeNOv0q-cj2ulpxtpl8e X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 08:01:04 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776939571688026792 X-GMAIL-MSGID: 1776939571688026792 From: Richard Fitzgerald The CS42L42 can accept very short reset pulses of a few microseconds but there's no reason to force a very short pulse. Allow a wide range for the usleep_range() so it can be relaxed about the choice of timing source. Signed-off-by: Richard Fitzgerald Signed-off-by: Stefan Binding --- sound/soc/codecs/cs42l42.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c index a0de0329406a..56d2857a4f01 100644 --- a/sound/soc/codecs/cs42l42.c +++ b/sound/soc/codecs/cs42l42.c @@ -2320,6 +2320,10 @@ int cs42l42_common_probe(struct cs42l42_private *cs42l42, if (cs42l42->reset_gpio) { dev_dbg(cs42l42->dev, "Found reset GPIO\n"); + + /* Ensure minimum reset pulse width */ + usleep_range(10, 500); + gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); } usleep_range(CS42L42_BOOT_TIME_US, CS42L42_BOOT_TIME_US * 2); From patchwork Wed Sep 13 15:00:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 139067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp59515vqb; Wed, 13 Sep 2023 13:10:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbQbdAHaUqMDMFENPpaQ9ocYGIMxBNLrGNcWEEunJ1Ra4X4LLQwDq9Cd3cl3ZSy41r+d30 X-Received: by 2002:a17:903:11d1:b0:1bf:7d3b:4405 with SMTP id q17-20020a17090311d100b001bf7d3b4405mr4040545plh.14.1694635807177; Wed, 13 Sep 2023 13:10:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694635807; cv=none; d=google.com; s=arc-20160816; b=02RIGuxj8cGriMCnfRAZVXJ3RAFbxGAIt2vX3DcW2/sVlro6geVidrLMuQhNasFPrn w0M1dloeUjNaGCNkHQb0A8xD51iahUnI0oGgvjrYtVOPXL32RU22x50sGcBPbEb68prG 4sK7HT1m7xwr9pUHD6ABbhRgBmCVSqUbXcYgQwL+F8gOA/8Y3YlE5fqUzMF0aUzNdPhW mvrPEhocq6rYjCz0BtcvwBQ6I+iYXbR/ZC34PukphBLjU0G0uODwW1+2WBuU804kTw6e 1pkFgVZ+p4OjevFHV/36W8aVZF7pTMQp7kMf7JjlM/t6/pWkxfpYTfBJawY8iLUkHYk1 F3nA== 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:from :dkim-signature; bh=PVaReH5xb95hJSWXKB1ZU+tI/szUdn6DXOR932aBpIg=; fh=nLTNXObJ5oqFazCRfk6NCsjnmxCjZ5yWeCYqqRZCVhM=; b=o3CjGqdkMikIcSr1SaVCqEHu0Ml2e9Ju4jNj9fYJ4KafHKNTH/JAYj2jDYkd4c9OSQ /3Km7fU/gAi8b4v61oJYUdVNwHJ7CedhR9863JAQv7gf4o9KHb936sKsskAMKwsazGw8 AkHIQzp+usllfOMhLuHSPCh9pqONyVRSbwu+QaCnLQjpJdyVluxRmRpp5wRGZIP+9C0s RkpetsJTPLCOL4nrkDPpCC3QWqcJXkS1epdx/3jX/GNvIl+qArHwHPWHTPbF0eAeoaRK ePAEe0QBp/736EmqeoAfSyg8KHQct4CL4JXP72AkopeoOGorfpKw1AMQj7GPRbJ0NQcp MHeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ZVX2QHyE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id e5-20020a17090301c500b001bbc7ed95efsi51774plh.44.2023.09.13.13.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 13:10:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=ZVX2QHyE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 60EEB80B5A0C; Wed, 13 Sep 2023 08:00:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240895AbjIMPAi (ORCPT + 36 others); Wed, 13 Sep 2023 11:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233101AbjIMPAg (ORCPT ); Wed, 13 Sep 2023 11:00:36 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C9FBB3 for ; Wed, 13 Sep 2023 08:00:32 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38CMxBYu012824; Wed, 13 Sep 2023 10:00:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=PVaReH5xb95hJSWXKB1ZU+tI/szUdn6DXOR932aBpIg=; b= ZVX2QHyELoWnF6ZoDjt2cH8BufZ2Dq6Issq3cu3yfcHwBgxgmSPXaPMNAU26Iqjg oWq7YHopmwhz01H6B3+OKSbC2yyXrbC4CK4a32u/g+chTsdfbgdJBdv9aCi80sLu 7zajfAr+fdu/YeJyIwhUYL7/i0kHIetATNUujdUA2PGZv5MpxNTkg8aqQfZm0Wvm cm/yRu5zv0bviXs0bgYoIY4wNrAFGOM/wM9hGKMrACERIB8tFUBZH0Q0apudQjs8 Idst/X2UQm9PH3LLH/aXRp6NHa7cQFOH8t5KXGFInwL6pspOnXxl7nvSV8rA5AxB OcG23m7O4rS9NEuSfrjHVQ== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3t2y7u125n-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Sep 2023 10:00:23 -0500 (CDT) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 13 Sep 2023 16:00:20 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.37 via Frontend Transport; Wed, 13 Sep 2023 16:00:20 +0100 Received: from sbinding-cirrus-dsktp2.ad.cirrus.com (unknown [198.90.238.120]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 6982F15B9; Wed, 13 Sep 2023 15:00:20 +0000 (UTC) From: Stefan Binding To: Mark Brown , Uday M Bhat , Pierre-Louis Bossart CC: , , , Richard Fitzgerald , Stefan Binding Subject: [PATCH v1 2/3] ASoC: cs42l42: Don't rely on GPIOD_OUT_LOW to set RESET initially low Date: Wed, 13 Sep 2023 16:00:11 +0100 Message-ID: <20230913150012.604775-3-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230913150012.604775-1-sbinding@opensource.cirrus.com> References: <20230913150012.604775-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: lca0U4S-IG95BKgtvo7CRGe-1JouNJCD X-Proofpoint-ORIG-GUID: lca0U4S-IG95BKgtvo7CRGe-1JouNJCD X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 08:00:54 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776954435884829231 X-GMAIL-MSGID: 1776954435884829231 From: Richard Fitzgerald The ACPI setting for a GPIO default state has higher priority than the flag passed to devm_gpiod_get_optional() so ACPI can override the GPIOD_OUT_LOW. Explicitly set the GPIO low when hard resetting. Although GPIOD_OUT_LOW can't be relied on this doesn't seem like a reason to stop passing it to devm_gpiod_get_optional(). So we still pass it to state our intent, but can deal with it having no effect. Signed-off-by: Richard Fitzgerald Signed-off-by: Stefan Binding --- sound/soc/codecs/cs42l42.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c index 56d2857a4f01..dc93861ddfb0 100644 --- a/sound/soc/codecs/cs42l42.c +++ b/sound/soc/codecs/cs42l42.c @@ -2321,6 +2321,12 @@ int cs42l42_common_probe(struct cs42l42_private *cs42l42, if (cs42l42->reset_gpio) { dev_dbg(cs42l42->dev, "Found reset GPIO\n"); + /* + * ACPI can override the default GPIO state we requested + * so ensure that we start with RESET low. + */ + gpiod_set_value_cansleep(cs42l42->reset_gpio, 0); + /* Ensure minimum reset pulse width */ usleep_range(10, 500); From patchwork Wed Sep 13 15:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Binding X-Patchwork-Id: 138880 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1148117vqx; Wed, 13 Sep 2023 08:03:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFz7EiWPVaGVjx5cJba4hu24NSf/CPhFLntqGmqDdO/GQCXigNI59quvbcy0v/Z3UUahbY/ X-Received: by 2002:a05:6a21:a597:b0:13e:e053:1050 with SMTP id gd23-20020a056a21a59700b0013ee0531050mr2912449pzc.56.1694617411217; Wed, 13 Sep 2023 08:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694617411; cv=none; d=google.com; s=arc-20160816; b=CfqhPgvlbgG4cccbCbMwzRJz2qyfbFEHDnMymLLq6Ko5fUdYpGvxifamWBwbaKMqzq /rPB3guVzNzJej3ikv14n08/B1RycqlaPM/h7PqmirgOx5fkHxv6vSDkqv4YfPCM0gBl T86WfyF7DSVQTarlTKw0w6aV0CByMyi24J6kJF51CgwmuN65CDYPtbIeB7qtL447nnjb I2D1Kt5dQkXXNfVwyIxxDsJT9kJrSkCxHUm+Lnx5Z8pvupStLeH16JRTGWR9QaCf5nnV R+kTVSYczRtXefj/hYIE7ks5ITJV/1oRfyGrt1ji1TWHESs5/qKejZfuL3iFud01ESO1 Y8CQ== 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:from :dkim-signature; bh=+LN7H2ZDQ/GaX+MwOCAMgy5391uuwKBA1IrMvUwY3qs=; fh=nLTNXObJ5oqFazCRfk6NCsjnmxCjZ5yWeCYqqRZCVhM=; b=RdxRUd+aUadpOKYRuR9tpEIj2uKBcXhdimQmYdaX6CkH5HFlqLeRWPdnqyvbLi1tXv U/fKR4xhqcXdZCp4NSJWZugFMBvF39mXokOeOAPfGCUKoUlb92jXBdjCWu+ujSqyCDRd b+EjkLFVOn+borgAB9baYgQ4Xex3QLX+P7SfUl8O/PjGAWpPgNRMUQBuH7OTnwYFIy8/ 05/JdAy2nVDA/jFjaoZv+RZn5W5aB11EXIpB3K7yki5T0XP70Ngb8zxsC3JI8xGzq5vE D9wCB4b5swwIWDGRBwFpnKeNEG7Q1gPOWHGhKYzQhvCC4vAwFBc0HWuFqEKqeF1Izfj4 TvrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=SrDA4BfB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id u18-20020a056a00159200b0069024057c60si213595pfk.42.2023.09.13.08.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:03:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=SrDA4BfB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 171278020BE6; Wed, 13 Sep 2023 08:00:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240964AbjIMPAj (ORCPT + 36 others); Wed, 13 Sep 2023 11:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234100AbjIMPAg (ORCPT ); Wed, 13 Sep 2023 11:00:36 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CABAB7 for ; Wed, 13 Sep 2023 08:00:32 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38CMxBYt012824; Wed, 13 Sep 2023 10:00:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=+LN7H2ZDQ/GaX+MwOCAMgy5391uuwKBA1IrMvUwY3qs=; b= SrDA4BfB2uV8qNacwofFkUbvvaLLLcc4YLfurmkb44JHzZs93ie6W8cnjT/9K2sc hv3WwgJUoPwaJnmtnNXOI0DNhOrBKmBFA/5l3fAaDhH6SE3gDBRxIKRgmzeoWZ5k 7aLZZ7XErk44HU7qIf5dnnKdwb9U9JVeGkLIOGCwIyUxH5MLkhNFMFOv/q80g98B 13zLM9dN73TF2JSkVvoyVLuhtTRp9dv+yMquDBPuBwdC7UU02U3DR0rzpQN2M/oG wWKXg7Jicu13QPaOAdMk3fGXJoAukl7iUnrVUZUPm4+pyVmGmEXbwVOY/9zqTT/5 dVsl+3aA9QxN1GrLzfNH4g== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3t2y7u125q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Sep 2023 10:00:23 -0500 (CDT) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Wed, 13 Sep 2023 16:00:21 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.37 via Frontend Transport; Wed, 13 Sep 2023 16:00:21 +0100 Received: from sbinding-cirrus-dsktp2.ad.cirrus.com (unknown [198.90.238.120]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id B965711AA; Wed, 13 Sep 2023 15:00:20 +0000 (UTC) From: Stefan Binding To: Mark Brown , Uday M Bhat , Pierre-Louis Bossart CC: , , , Richard Fitzgerald , Stefan Binding Subject: [PATCH v1 3/3] ASoC: cs42l42: Avoid stale SoundWire ATTACH after hard reset Date: Wed, 13 Sep 2023 16:00:12 +0100 Message-ID: <20230913150012.604775-4-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230913150012.604775-1-sbinding@opensource.cirrus.com> References: <20230913150012.604775-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: br98W4FxGg-rapGOWLx5CksctckCik3G X-Proofpoint-ORIG-GUID: br98W4FxGg-rapGOWLx5CksctckCik3G X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 08:00:51 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776935146600005927 X-GMAIL-MSGID: 1776935146600005927 From: Richard Fitzgerald In SoundWire mode leave hard RESET asserted when exiting probe, and wait for an UNATTACHED notification before deasserting RESET. If the boot state of the reset GPIO was deasserted it is possible that the SoundWire core had already enumerated the CS42L42 before cs42l42_sdw_probe() is called. When cs42l42_common_probe() hard resets the CS42L42 it triggers a race condition: 1) After cs42l42_sdw_probe() returns the thread that called it will call cs42l42_sdw_update_status() to report the last status recorded by the SoundWire core. 2) The SoundWire bus master will see a PING with the CS42L42 now reporting as unenumerated and will trigger the core SoundWire code to start enumerating CS42L42. These two threads are racing against each other. If (1) happens before (2) a stale ATTACHED notification will be reported to the cs42l42 driver when in fact the status of cs42l42 is now unattached. To avoid this race condition: - Leave RESET asserted on exit from cs42l42_sdw_probe(). This ensures that an UNATTACHED notification must be sent to the cs42l42 driver. If cs42l42 was already enumerated it will be seen to drop off the bus, causing an UNATTACH notification. If it was never enumerated the status is already UNATTACHED and this will be reported by thread (1). - When the UNATTACH notification is received, release RESET. This will cause CS42L42 to be enumerated and eventually report an ATTACHED notification. - The ATTACHED notification is now valid. Signed-off-by: Richard Fitzgerald Signed-off-by: Stefan Binding --- sound/soc/codecs/cs42l42-sdw.c | 20 ++++++++++++++++++++ sound/soc/codecs/cs42l42.c | 11 ++++++++++- sound/soc/codecs/cs42l42.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/cs42l42-sdw.c b/sound/soc/codecs/cs42l42-sdw.c index eeab07c850f9..974bae4abfad 100644 --- a/sound/soc/codecs/cs42l42-sdw.c +++ b/sound/soc/codecs/cs42l42-sdw.c @@ -344,6 +344,16 @@ static int cs42l42_sdw_update_status(struct sdw_slave *peripheral, switch (status) { case SDW_SLAVE_ATTACHED: dev_dbg(cs42l42->dev, "ATTACHED\n"); + + /* + * The SoundWire core can report stale ATTACH notifications + * if we hard-reset CS42L42 in probe() but it had already been + * enumerated. Reject the ATTACH if we haven't yet seen an + * UNATTACH report for the device being in reset. + */ + if (cs42l42->sdw_waiting_first_unattach) + break; + /* * Initialise codec, this only needs to be done once. * When resuming from suspend, resume callback will handle re-init of codec, @@ -354,6 +364,16 @@ static int cs42l42_sdw_update_status(struct sdw_slave *peripheral, break; case SDW_SLAVE_UNATTACHED: dev_dbg(cs42l42->dev, "UNATTACHED\n"); + + if (cs42l42->sdw_waiting_first_unattach) { + /* + * SoundWire core has seen that CS42L42 is not on + * the bus so release RESET and wait for ATTACH. + */ + cs42l42->sdw_waiting_first_unattach = false; + gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); + } + break; default: break; diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c index dc93861ddfb0..2961340f15e2 100644 --- a/sound/soc/codecs/cs42l42.c +++ b/sound/soc/codecs/cs42l42.c @@ -2330,7 +2330,16 @@ int cs42l42_common_probe(struct cs42l42_private *cs42l42, /* Ensure minimum reset pulse width */ usleep_range(10, 500); - gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); + /* + * On SoundWire keep the chip in reset until we get an UNATTACH + * notification from the SoundWire core. This acts as a + * synchronization point to reject stale ATTACH notifications + * if the chip was already enumerated before we reset it. + */ + if (cs42l42->sdw_peripheral) + cs42l42->sdw_waiting_first_unattach = true; + else + gpiod_set_value_cansleep(cs42l42->reset_gpio, 1); } usleep_range(CS42L42_BOOT_TIME_US, CS42L42_BOOT_TIME_US * 2); diff --git a/sound/soc/codecs/cs42l42.h b/sound/soc/codecs/cs42l42.h index 4bd7b85a5747..7785125b73ab 100644 --- a/sound/soc/codecs/cs42l42.h +++ b/sound/soc/codecs/cs42l42.h @@ -53,6 +53,7 @@ struct cs42l42_private { u8 stream_use; bool hp_adc_up_pending; bool suspended; + bool sdw_waiting_first_unattach; bool init_done; };