From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32691C433F5 for ; Sun, 12 Sep 2021 14:23:25 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 877B46108C for ; Sun, 12 Sep 2021 14:23:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 877B46108C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9D3B18391C; Sun, 12 Sep 2021 16:23:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=sholland.org header.i=@sholland.org header.b="BXa+55BF"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="IdoWNRx5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 72AB78390F; Sun, 12 Sep 2021 16:22:56 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5FD6483910 for ; Sun, 12 Sep 2021 16:22:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@sholland.org Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id A5FBC5C008C; Sun, 12 Sep 2021 10:22:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 12 Sep 2021 10:22:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=tThLH8ngV/G2A ov3M3yDL0QiDDFCYEu4JHmrK8Xfz64=; b=BXa+55BFUypsiJJGMnRNg5hKfGkpW okLQDXq4BVzQHIkgjr5pPkDpc86L+4oTfQouqoP095MKh0DIG78wpxuJ1DCR/GEN AmcWn67npoBgaog6sM3/3sUA651W00FbP9hF56QM7mW6Vjn2l8ue4yObB/Mc7gpF uLTk+bOLUoAT+PAs4g3mPxlGL5kHk9T3jBF1PoeEitBmK/bWLhft57IMMo8kOek+ Ldr8DJdla4zn9epBt8DL5JZL9lrujc60gAMKDE/GMBVDsv/l/pH85m0vqAn3krVx iMiJGQHTBM/UuJGJcOPUo43S9oHvZVIBV27FkjIEUZedIBukGfYNSWVsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=tThLH8ngV/G2Aov3M3yDL0QiDDFCYEu4JHmrK8Xfz64=; b=IdoWNRx5 +GHAFL8AYuTEeLa/lv59usrQzKViqlXilbTS0Cqa1nZRRa5mI5gHrWzHebqy3i37 /+WAcGc6JAMX5MPYE2m86xK/Jx1PZV8k9hg691lTU0v412Qr/Y3bVUFtwIQJ/p3V LZheOLvOdS+kDr0gFMqo9/GN9A3nbq+zt+Y1buFkawbn0z7YoMjEpK4eQilwlFss 79O1QLDIW8+wr/hJ+pnFupSAXJWaiEVJxVmEg+vKLO5+oJit6fhzJV1kcD5S5Lvc eKoDPjXqudUqmnCKa5eoMSFOvT1Hq2pXKaHXRXK0GXLhSPYbdZDdE9jaXwOri5vh y+fI28egqru0ng== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudeghedgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 12 Sep 2021 10:22:48 -0400 (EDT) From: Samuel Holland To: u-boot@lists.denx.de, Jagan Teki , Andre Przywara Cc: Samuel Holland , Joe Hershberger Subject: [PATCH 2/3] phy: sun4i-usb: Refactor VBUS detection to match Linux Date: Sun, 12 Sep 2021 09:22:41 -0500 Message-Id: <20210912142243.9912-3-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210912142243.9912-1-samuel@sholland.org> References: <20210912142243.9912-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The Linux driver checks the VBUS detection GPIO first; then VBUS power supply; then finally assumes VBUS is present. When adding VBUS power supply support, we want to match that order, so we get the same behavior in case both a GPIO and a power supply are provided in the device tree. So refactor the function a bit to remove the early return, and use the same "assume VBUS is present" final fallback. Signed-off-by: Samuel Holland --- drivers/phy/allwinner/phy-sun4i-usb.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/phy/allwinner/phy-sun4i-usb.c b/drivers/phy/allwinner/phy-sun4i-usb.c index 5302b809ee6..827ecd70f27 100644 --- a/drivers/phy/allwinner/phy-sun4i-usb.c +++ b/drivers/phy/allwinner/phy-sun4i-usb.c @@ -391,20 +391,19 @@ int sun4i_usb_phy_vbus_detect(struct phy *phy) { struct sun4i_usb_phy_data *data = dev_get_priv(phy->dev); struct sun4i_usb_phy_plat *usb_phy = &data->usb_phy[phy->id]; - int err, retries = 3; - - if (usb_phy->gpio_vbus_det < 0) - return usb_phy->gpio_vbus_det; - - err = gpio_get_value(usb_phy->gpio_vbus_det); - /* - * Vbus may have been provided by the board and just been turned of - * some milliseconds ago on reset, what we're measuring then is a - * residual charge on Vbus, sleep a bit and try again. - */ - while (err > 0 && retries--) { - mdelay(100); + int err = 1, retries = 3; + + if (usb_phy->gpio_vbus_det >= 0) { err = gpio_get_value(usb_phy->gpio_vbus_det); + /* + * Vbus may have been provided by the board and just turned off + * some milliseconds ago on reset. What we're measuring then is + * a residual charge on Vbus. Sleep a bit and try again. + */ + while (err > 0 && retries--) { + mdelay(100); + err = gpio_get_value(usb_phy->gpio_vbus_det); + } } return err; -- 2.31.1