From patchwork Thu Jul 13 17:11:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 1807386 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R21Ng2FDdz20bh for ; Fri, 14 Jul 2023 03:11:29 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2E9A686C9F; Thu, 13 Jul 2023 19:11:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.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 79C6A86C67; Thu, 13 Jul 2023 19:11:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (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 CD37686C10 for ; Thu, 13 Jul 2023 19:11:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tharvey@gateworks.com Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.93) (envelope-from ) id 1qJzqV-0077Cb-Rp; Thu, 13 Jul 2023 17:11:15 +0000 From: Tim Harvey To: u-boot@lists.denx.de, Fabio Estevam , Marek Vasut , Adam Ford , Martyn Welch , Marcel Ziswiler Cc: "NXP i . MX U-Boot Team" , Stefano Babic , Tim Harvey Subject: [PATCH v6 1/2] phy: phy-imx8mq-usb: add vbus regulator support Date: Thu, 13 Jul 2023 10:11:12 -0700 Message-Id: <20230713171113.3642177-1-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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 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 --- v6: - move changes to clk to separate patch - sort new vars in reverse christmas tree style v5: - remove #if CONFIG_IS_ENABLED around struct members (you can not conditionally include if using if (CONFIG_IS_ENABLED(foo)) ) - replace clk '#if CONFIG_IS_ENABLED(CLK)' with 'if (CONFIG_IS_ENABLED(CLK))' 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 | 37 +++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/phy-imx8mq-usb.c index 69f01de55538..0ab7965df2ff 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,7 @@ struct imx8mq_usb_phy { #endif void __iomem *base; enum imx8mpq_phy_type type; + struct udevice *vbus_supply; }; static const struct udevice_id imx8mq_usb_phy_of_match[] = { @@ -173,9 +176,9 @@ 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); u32 value; + int ret; #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,12 +186,24 @@ 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) @@ -196,6 +211,7 @@ 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); u32 value; + int ret; /* Override rx term to be 0 */ value = readl(imx_phy->base + PHY_CTRL6); @@ -206,6 +222,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 +248,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); + int ret; priv->type = dev_get_driver_data(dev); priv->base = dev_read_addr_ptr(dev); @@ -232,8 +257,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); if (ret) { @@ -241,6 +264,14 @@ int imx8mq_usb_phy_probe(struct udevice *dev) return ret; } #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; } From patchwork Thu Jul 13 17:11:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Harvey X-Patchwork-Id: 1807387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R21Np6p0xz20bh for ; Fri, 14 Jul 2023 03:11:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 718E086CA5; Thu, 13 Jul 2023 19:11:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.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 A453686C10; Thu, 13 Jul 2023 19:11:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from finn.localdomain (finn.gateworks.com [108.161.129.64]) (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 2715F86C17 for ; Thu, 13 Jul 2023 19:11:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=gateworks.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=tharvey@gateworks.com Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by finn.localdomain with esmtp (Exim 4.93) (envelope-from ) id 1qJzqW-0077Cb-HA; Thu, 13 Jul 2023 17:11:16 +0000 From: Tim Harvey To: u-boot@lists.denx.de, Fabio Estevam , Marek Vasut , Adam Ford , Martyn Welch , Marcel Ziswiler Cc: "NXP i . MX U-Boot Team" , Stefano Babic , Tim Harvey Subject: [PATCH v6 2/2] phy: phy-imx8mq-usb: clean up clock code Date: Thu, 13 Jul 2023 10:11:13 -0700 Message-Id: <20230713171113.3642177-2-tharvey@gateworks.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230713171113.3642177-1-tharvey@gateworks.com> References: <20230713171113.3642177-1-tharvey@gateworks.com> MIME-Version: 1.0 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 use CONFIG_IS_ENABLED for clock enable/disable and change printf's to dev_err. Additionlly remove the comment that does not make sense. Signed-off-by: Tim Harvey --- v6: new patch drivers/phy/phy-imx8mq-usb.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/phy/phy-imx8mq-usb.c b/drivers/phy/phy-imx8mq-usb.c index 0ab7965df2ff..bf9b0b6f3450 100644 --- a/drivers/phy/phy-imx8mq-usb.c +++ b/drivers/phy/phy-imx8mq-usb.c @@ -78,9 +78,7 @@ enum imx8mpq_phy_type { }; struct imx8mq_usb_phy { -#if CONFIG_IS_ENABLED(CLK) struct clk phy_clk; -#endif void __iomem *base; enum imx8mpq_phy_type type; struct udevice *vbus_supply; @@ -178,13 +176,13 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy) u32 value; int ret; -#if CONFIG_IS_ENABLED(CLK) - ret = clk_enable(&imx_phy->phy_clk); - if (ret) { - printf("Failed to enable usb phy clock\n"); - return ret; + if (CONFIG_IS_ENABLED(CLK)) { + ret = clk_enable(&imx_phy->phy_clk); + if (ret) { + dev_err(dev, "Failed to enable usb phy clock: %d\n", ret); + return ret; + } } -#endif if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supply) { ret = regulator_set_enable_if_allowed(imx_phy->vbus_supply, true); @@ -218,9 +216,8 @@ static int imx8mq_usb_phy_power_off(struct phy *usb_phy) value |= PHY_CTRL6_RXTERM_OVERRIDE_SEL; writel(value, imx_phy->base + PHY_CTRL6); -#if CONFIG_IS_ENABLED(CLK) - clk_disable(&imx_phy->phy_clk); -#endif + if (CONFIG_IS_ENABLED(CLK)) + clk_disable(&imx_phy->phy_clk); if (CONFIG_IS_ENABLED(DM_REGULATOR) && imx_phy->vbus_supply) { ret = regulator_set_enable_if_allowed(imx_phy->vbus_supply, false); @@ -256,14 +253,14 @@ int imx8mq_usb_phy_probe(struct udevice *dev) if (!priv->base) return -EINVAL; -#if CONFIG_IS_ENABLED(CLK) - /* Assigned clock already set clock */ - ret = clk_get_by_name(dev, "phy", &priv->phy_clk); - if (ret) { - printf("Failed to get usb phy clock\n"); - return ret; + if (CONFIG_IS_ENABLED(CLK)) { + ret = clk_get_by_name(dev, "phy", &priv->phy_clk); + if (ret) { + dev_err(dev, "Failed to get usb phy clock %d\n", ret); + return ret; + } } -#endif + if (CONFIG_IS_ENABLED(DM_REGULATOR)) { ret = device_get_supply_regulator(dev, "vbus-supply", &priv->vbus_supply);