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 B17F6EB64D9 for ; Mon, 10 Jul 2023 17:27:00 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C06158466A; Mon, 10 Jul 2023 19:26:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se 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=kwiboo.se header.i=@kwiboo.se header.b="iRIp0qvH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B49A784660; Mon, 10 Jul 2023 19:26:56 +0200 (CEST) Received: from s.wrqvtzvf.outbound-mail.sendgrid.net (s.wrqvtzvf.outbound-mail.sendgrid.net [149.72.126.143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5237E8676A for ; Mon, 10 Jul 2023 19:26:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bounces+31435339-7456-u-boot=lists.denx.de@em2124.kwiboo.se DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=mime-version:subject:references:from:in-reply-to:to:cc:content-type: content-transfer-encoding:cc:content-type:from:subject:to; s=s1; bh=vcN8Z4xFNoLc4tiUaLK/MpFQYmNG1Y7tHlHdpuOoLLY=; b=iRIp0qvHzJqeIeg0K/hPefGn41mXzOKOKk9iyJkmRuqPTGGkqaORcI7mF8Gaum7VuVnv v8YNGaotDFr/Mdej4GZAZPfb1GwNzs2wI6IiRD1HloVw35J22jL9+2/41XKUb1MXX8JLcc Jl+p7o9CjI4Bi7rHy+W8vht6A4D2B+1cuf3JSD2i8xp9Qts83rMSoSnVqnFFqNSNA8HP2h 6lsPfaoIKANLJphrhzyiENYDE7pd0cgGrqxfI4DPSTxPFGLwtRiMdG8Q87RXWYp/j8t9Dp HbFla9ANgYn7S7wbYc0GpF5Sv4r2mLzpwKUlsqQoLJfVfmJbSlaQBl+uvRZY64qQ== Received: by filterdrecv-65f68489c8-zw5h4 with SMTP id filterdrecv-65f68489c8-zw5h4-1-64AC3F5A-15 2023-07-10 17:26:50.456803587 +0000 UTC m=+5248234.875713342 Received: from [192.168.1.50] (unknown) by geopod-ismtpd-11 (SG) with ESMTP id ZyGRcJE_RHGWMBePljJFlA Mon, 10 Jul 2023 17:26:50.073 +0000 (UTC) Message-ID: Date: Mon, 10 Jul 2023 17:26:50 +0000 (UTC) MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v3] phy: phy-imx8mq-usb: add vbus regulator support Content-Language: en-US References: <20230710171427.1742575-1-tharvey@gateworks.com> From: Jonas Karlman In-Reply-To: <20230710171427.1742575-1-tharvey@gateworks.com> X-SG-EID: =?us-ascii?Q?TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxA?= =?us-ascii?Q?fZekEeQsTe+RrMu3cja6a0h26JuH6smffr34br7?= =?us-ascii?Q?bpmH+prWhYiPpQQ5pAhvhciuQPRhmyMa=2F5xhigu?= =?us-ascii?Q?HIAD6Xx3DVmYa5+60cGphd7bLcrX885bMxColQh?= =?us-ascii?Q?JDLBhXpfuEIk2F32Es6KC0X1rKG+stNnVtdQn=2Fc?= =?us-ascii?Q?mCxRFb7CqKwNnxVzIYtF6pFaje6dJzY5xQpQLb?= To: Tim Harvey , Fabio Estevam , Marek Vasut , Adam Ford , Martyn Welch , Marcel Ziswiler Cc: "NXP i . MX U-Boot Team" , Stefano Babic , u-boot@lists.denx.de X-Entity-ID: P7KYpSJvGCELWjBME/J5tg== Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Hi Tim, On 2023-07-10 19:14, 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 > --- > 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..cbd96a0bd4df 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(imx_phy->vbus_supply, true); I would recommend you to use regulator_set_enable_if_allowed and (ret && ret != -ENOSYS) if the regulator may be a fixed/gpio regulator. The fixed/gpio regulator reference counter patches has been merged into next. The basic regulator_set_enable may now return -EBUSY or -EALREADY when a fixed/gpio regulator is already enabled/disabled. > + if (ret) { > + 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(imx_phy->vbus_supply, false); Same here. Regards, Jonas > + if (ret) { > + 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; > > /* Assigned clock already set clock */ > ret = clk_get_by_name(dev, "phy", &priv->phy_clk); > @@ -242,6 +268,15 @@ int imx8mq_usb_phy_probe(struct udevice *dev) > } > #endif > > + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { > + ret = device_get_supply_regulator(dev, "vbus-supply", > + &priv->vbus_supply); > + if (ret && ret != -ENOENT) { > + dev_err(dev, "Failed to get VBUS regulator: %d\n", ret); > + return ret; > + } > + } > + > return 0; > } >