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: 13383264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 08D37EDEC71 for ; Wed, 13 Sep 2023 15:01:42 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E2456DED; Wed, 13 Sep 2023 17:00:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E2456DED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1694617300; bh=xXYKBXYPDdvaUKvMy2WO8Yj7n+AOFyjl6Bq83aaDQ8I=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=hcdcXD6nWrjpD+nlwweuielHK3HBx5anT7szfAWRUsNT9nsmFM48gGkFtOcUCBGW0 x7iQNNROiJXaP9nfeIhmEodGZW5oaGrmVnwhWNapqS1R9XXSsPNt83y8rJ1G/PU47r 74PedFzyv2osSSQkcVl5rJdd65Hsocesu06xGZ2Y= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4CD38F80567; Wed, 13 Sep 2023 17:00:32 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id B0FCAF8055A; Wed, 13 Sep 2023 17:00:31 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A6AE0F80563; Wed, 13 Sep 2023 17:00:28 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 84403F80425 for ; Wed, 13 Sep 2023 17:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 84403F80425 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=cirrus.com header.i=@cirrus.com header.a=rsa-sha256 header.s=PODMain02222019 header.b=qvciHAJn 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 Message-ID-Hash: LUAMPTA7AY5DT7GWB6KDC3SVNXQNVBM5 X-Message-ID-Hash: LUAMPTA7AY5DT7GWB6KDC3SVNXQNVBM5 X-MailFrom: prvs=4620b17109=sbinding@opensource.cirrus.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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: 13383267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA910EDEC70 for ; Wed, 13 Sep 2023 15:03:56 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 92B4AAE9; Wed, 13 Sep 2023 17:03:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 92B4AAE9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1694617434; bh=GRpMO30E92zwarLbyCP64eutvKgo8RQKyTQV6G2CBT4=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=rWlrAyWqjwLXJofESF9o/YApRNx+m4n2OnpaaTri8XBId+pdyl21XWV17C2c2n5hK mqdknQkcPZXL/G5LsjFhTKKbRyHc2YM+pM2KHqkahERPt327mocicYbR3u1oiaJHf0 xsVtv3I2ycJwFMt3wV0kRXV4IhSEktoF+NB1hEHE= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E04B6F80551; Wed, 13 Sep 2023 17:02:36 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id A5533F80425; Wed, 13 Sep 2023 17:02:36 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 061E9F8047D; Wed, 13 Sep 2023 17:02:33 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 893F0F80551 for ; Wed, 13 Sep 2023 17:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 893F0F80551 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=cirrus.com header.i=@cirrus.com header.a=rsa-sha256 header.s=PODMain02222019 header.b=ZVX2QHyE 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 Message-ID-Hash: D6KKK3RS3SKOICDVWZY774NOVCRJJXG5 X-Message-ID-Hash: D6KKK3RS3SKOICDVWZY774NOVCRJJXG5 X-MailFrom: prvs=4620b17109=sbinding@opensource.cirrus.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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: 13383265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCA8EEDEC70 for ; Wed, 13 Sep 2023 15:01:49 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B5036A4B; Wed, 13 Sep 2023 17:00:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B5036A4B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1694617307; bh=PeW8y6YFb5yxGaiJND1GUSoamUa3Gb2wXIbsHHpC0D8=; h=From:To:CC:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=pcxQ5GcrhzDflqTLtWzulCXuvTR74rHuoWgBemufJRqWO4T7XBFa/1vLvlQtTTQ6p h5Q1G8dCasqS/oyS8Jine6SKEqYZUf6GipwQYs3rXvX2dfyG1xxCwTgQEjwONm/Vka jnzPCtpRf8lJvxZNcjsE+dkc25GpScwHE8z9Lelc= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 87801F80571; Wed, 13 Sep 2023 17:00:35 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 9BA15F80571; Wed, 13 Sep 2023 17:00:34 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 315FFF8055A; Wed, 13 Sep 2023 17:00:30 +0200 (CEST) Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 012D6F8055B for ; Wed, 13 Sep 2023 17:00:25 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 012D6F8055B Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=cirrus.com header.i=@cirrus.com header.a=rsa-sha256 header.s=PODMain02222019 header.b=SrDA4BfB 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 Message-ID-Hash: NQR5ET7R72UIIPDBIB7V2PV2LDEHMCYY X-Message-ID-Hash: NQR5ET7R72UIIPDBIB7V2PV2LDEHMCYY X-MailFrom: prvs=4620b17109=sbinding@opensource.cirrus.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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; };