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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6826C433F5 for ; Mon, 25 Oct 2021 14:08:44 +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 2C77A60F9B for ; Mon, 25 Oct 2021 14:08:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C77A60F9B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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 365D6834B9; Mon, 25 Oct 2021 16:08:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id C9FBB83458; Mon, 25 Oct 2021 16:08:39 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id ED6C58352D for ; Mon, 25 Oct 2021 16:08:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5E9D21FB; Mon, 25 Oct 2021 07:08:34 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AE0FB3F5A1; Mon, 25 Oct 2021 07:08:33 -0700 (PDT) Date: Mon, 25 Oct 2021 15:08:29 +0100 From: Andre Przywara To: Samuel Holland Cc: u-boot@lists.denx.de, Jagan Teki , Joe Hershberger Subject: Re: [PATCH 2/3] phy: sun4i-usb: Refactor VBUS detection to match Linux Message-ID: <20211025150829.7cbd946d@slackpad.fritz.box> In-Reply-To: <20210912142243.9912-3-samuel@sholland.org> References: <20210912142243.9912-1-samuel@sholland.org> <20210912142243.9912-3-samuel@sholland.org> Organization: Arm Ltd. X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.31; x86_64-slackware-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 On Sun, 12 Sep 2021 09:22:41 -0500 Samuel Holland wrote: Hi, > 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 Let's see if testing reveals any subtle issues ;-) Acked-by: Andre Przywara Cheers, Andre > --- > > 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;