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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D7DF9EB64D9 for ; Wed, 12 Jul 2023 09:15:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 32FF0869BA; Wed, 12 Jul 2023 11:15:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689153332; bh=pFqBu1p/MRrLswIkfbshEZjH9o6ffpYf23n1wM04uJI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BdxPO6/cZ/u8gnmQF/5s5Ogly6gojpCVR0kaZWpgwYTn3NApInAAiWM5GKU7AXvmH IFzxVxVegOHruo8x+QD3oDFOR6Ej1nH088bi62SG6nJjbPhIiciPxx1eI1NdeW54pu a932DkHUMHxqlAXH1c9AGHMiTvgrdIPinLcTfDcQJyCP9q26gocMg8zn0rqDu6kXFR I3eqC75n19mXSCyV+9lzgRTa/lSk2yiIGJVZ+EZSaREoht4Kee940H280urvmuwL5N KDNrSVsk/ZEMQCBME4sSfvpVRuSy/1aAmvV0fxZ5im/IdJzcoki3MHWoXZR5tBomZu 2sy4CybOc02Kg== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id C496E868EC; Wed, 12 Jul 2023 11:15:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1689153330; bh=pFqBu1p/MRrLswIkfbshEZjH9o6ffpYf23n1wM04uJI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=P8g9YoMhNrNciTKSsaliVbWCCteBAE11sf3ZpamO3uTljEAO4EPk+SEzZgiH7PJ9J 5JLOneOaEuF0ymW1EmGNZaQPeyUfzOQxo9XZuIqp34pKelv8bsqPMsNz6VECr5Hv5s uLa3hUBqjVsU7XqtT2XpE8UlMrcZKEsUoV3fDvzGlOgb+60ckBp0nX/Sd2g+M88OdG FohrCNP4aUUCUe9v2fxNwykErmpsbFTmxrLRGjosw5MS0AHzlSUJNrOud1L0b5WCAE 9ysieJpvEyjdYoyniPznX33UyykrPxEahUk1pfd9xQUEyJL1jKywM8Hy5GsxtkaZ5a nVYclaloGF1OA== Message-ID: Date: Wed, 12 Jul 2023 11:15:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v4] phy: phy-imx8mq-usb: add vbus regulator support Content-Language: en-US To: Tim Harvey Cc: u-boot@lists.denx.de, Fabio Estevam , Adam Ford , Martyn Welch , Marcel Ziswiler , "NXP i . MX U-Boot Team" , Stefano Babic References: <20230710224932.1996810-1-tharvey@gateworks.com> <5528fd1b-22f8-efef-f05a-56da34601a64@denx.de> From: Marek Vasut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.8 at phobos.denx.de X-Virus-Status: Clean On 7/11/23 22:13, Tim Harvey wrote: > On Mon, Jul 10, 2023 at 4:18 PM Marek Vasut wrote: >> >> On 7/11/23 00:49, Tim Harvey wrote: >>> Add support for enabling and disabling vbus-supply regulator found >>> on several imx8mp boards in the usb3_phy0 and usb3_phy1 nodes. >>> >>> Signed-off-by: Tim Harvey >>> Reviewed-by: Adam Ford >>> Reviewed-by: Marek Vasut >>> --- >>> v4: >>> - use regulator_set_enable_if_allowed to handle regulator reference counting >>> errors >>> - added Marek's rb tag >>> >>> v3: >>> - change pr_err to dev_err >>> - add #if CONFIG_IS_ENABLED around vbus_supply in struct >>> - add fail path to disable clock if regulator enable failed >>> >>> v2: >>> - protect ret with __maybe_unused in case CONFIG_CLK and >>> CONFIG_DM_REGULATOR not defined >>> - add error prints on failures >>> - add Adam's rb tag >>> --- >>> drivers/phy/phy-imx8mq-usb.c | 39 ++++++++++++++++++++++++++++++++++-- >>> 1 file changed, 37 insertions(+), 2 deletions(-) >>> >>> diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/phy-imx8mq-usb.c >>> index 69f01de55538..6cbcb2338cfe 100644 >>> --- a/drivers/phy/phy-imx8mq-usb.c >>> +++ b/drivers/phy/phy-imx8mq-usb.c >>> @@ -14,6 +14,8 @@ >>> #include >>> #include >>> #include >>> +#include >>> +#include >>> >>> #define PHY_CTRL0 0x0 >>> #define PHY_CTRL0_REF_SSP_EN BIT(2) >>> @@ -81,6 +83,9 @@ struct imx8mq_usb_phy { >>> #endif >>> void __iomem *base; >>> enum imx8mpq_phy_type type; >>> +#if CONFIG_IS_ENABLED(DM_REGULATOR) >>> + struct udevice *vbus_supply; >>> +#endif >>> }; >>> >>> static const struct udevice_id imx8mq_usb_phy_of_match[] = { >>> @@ -172,10 +177,10 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy) >>> { >>> struct udevice *dev = usb_phy->dev; >>> struct imx8mq_usb_phy *imx_phy = dev_get_priv(dev); >>> + __maybe_unused int ret; >>> u32 value; >>> >>> #if CONFIG_IS_ENABLED(CLK) >>> - int ret; >>> ret = clk_enable(&imx_phy->phy_clk); >>> if (ret) { >>> printf("Failed to enable usb phy clock\n"); >>> @@ -183,18 +188,31 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy) >>> } >>> #endif >>> >>> + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supply) { >>> + ret = regulator_set_enable_if_allowed(imx_phy->vbus_supply, true); >>> + if (ret && ret != -ENOSYS) { >>> + dev_err(dev, "Failed to enable VBUS regulator: %d\n", ret); >>> + goto err; >>> + } >>> + } >>> + >>> /* Disable rx term override */ >>> value = readl(imx_phy->base + PHY_CTRL6); >>> value &= ~PHY_CTRL6_RXTERM_OVERRIDE_SEL; >>> writel(value, imx_phy->base + PHY_CTRL6); >>> >>> return 0; >>> + >>> +err: >>> + clk_disable(&imx_phy->phy_clk); >>> + return ret; >>> } >>> >>> static int imx8mq_usb_phy_power_off(struct phy *usb_phy) >>> { >>> struct udevice *dev = usb_phy->dev; >>> struct imx8mq_usb_phy *imx_phy = dev_get_priv(dev); >>> + __maybe_unused int ret; >>> u32 value; >>> >>> /* Override rx term to be 0 */ >>> @@ -206,6 +224,14 @@ static int imx8mq_usb_phy_power_off(struct phy *usb_phy) >>> clk_disable(&imx_phy->phy_clk); >>> #endif >>> >>> + if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supply) { >>> + ret = regulator_set_enable_if_allowed(imx_phy->vbus_supply, false); >>> + if (ret && ret != -ENOSYS) { >>> + dev_err(dev, "Failed to disable VBUS regulator: %d\n", ret); >>> + return ret; >>> + } >>> + } >>> + >>> return 0; >>> } >>> >>> @@ -224,6 +250,7 @@ struct phy_ops imx8mq_usb_phy_ops = { >>> int imx8mq_usb_phy_probe(struct udevice *dev) >>> { >>> struct imx8mq_usb_phy *priv = dev_get_priv(dev); >>> + __maybe_unused int ret; >>> >>> priv->type = dev_get_driver_data(dev); >>> priv->base = dev_read_addr_ptr(dev); >>> @@ -232,7 +259,6 @@ int imx8mq_usb_phy_probe(struct udevice *dev) >>> return -EINVAL; >>> >>> #if CONFIG_IS_ENABLED(CLK) >>> - int ret; >> >> I _think_ if you were to convert this #if CONFIG...() to if >> (CONFIG...()), you would be able to drop the __maybe_unused . Separate >> conversion patch would be better though. > > Hi Marek, Hi, > Yes, I thought about that as well and felt it should be a separate > followup cleanup patch. Can you please send such a follow up patch ? Thanks