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 56EBFC678D5 for ; Wed, 8 Mar 2023 00:47:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5F3CB83CB4; Wed, 8 Mar 2023 01:47:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=rock-chips.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 AA9EA83AA4; Wed, 8 Mar 2023 01:47:23 +0100 (CET) Received: from mail-m11874.qiye.163.com (mail-m11874.qiye.163.com [115.236.118.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7664A85BCF for ; Wed, 8 Mar 2023 01:47:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kever.yang@rock-chips.com Received: from [172.16.12.93] (unknown [58.22.7.114]) by mail-m11874.qiye.163.com (Hmail) with ESMTPA id 05B813C017D; Wed, 8 Mar 2023 08:47:04 +0800 (CST) Message-ID: <0d2f07d8-4e89-2995-6754-2ca462e7b77a@rock-chips.com> Date: Wed, 8 Mar 2023 08:47:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PATCH v2 1/3] phy: rockchip-inno-usb2: add support for phy-supply Content-Language: en-US To: Vasily Khoruzhick , Simon Glass , Philipp Tomsich , Lukasz Majewski , Sean Anderson , Jagan Teki , Manoj Sai , John Keeping , Mark Kettenis , u-boot@lists.denx.de References: <20230307220827.68520-1-anarsoul@gmail.com> From: Kever Yang In-Reply-To: <20230307220827.68520-1-anarsoul@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZGUxLGFYYQklOQxpOGksdQ09VEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLSEpMVUpLS1VLWQ Y+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6ND46Djo5DT0OHzAiEhEKNgoU EhkaChpVSlVKTUxDSUhNT0lPTU1NVTMWGhIXVRAeDR4JVQIaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFOTU1KNwY+ X-HM-Tid: 0a86beaf98282eb0kusn05b813c017d X-HM-MType: 1 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 2023/3/8 06:08, Vasily Khoruzhick wrote: > PHY driver needs to enable PHY supply, otherwise port will > remain unpowered. > > Signed-off-by: Vasily Khoruzhick Reviewed-by: Kever Yang Thanks, - Kever > --- > v2: address check_patch.pl issues > > drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 64 ++++++++++++++++++- > 1 file changed, 61 insertions(+), 3 deletions(-) > > diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c > index 55e1dbcfef..a859cd6f18 100644 > --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c > +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > > DECLARE_GLOBAL_DATA_PTR; > > @@ -62,6 +63,10 @@ struct rockchip_usb2phy { > void *reg_base; > struct clk phyclk; > const struct rockchip_usb2phy_cfg *phy_cfg; > +#if IS_ENABLED(CONFIG_DM_REGULATOR) > + struct udevice *host_supply; > + struct udevice *otg_supply; > +#endif > }; > > static inline int property_enable(void *reg_base, > @@ -86,12 +91,42 @@ struct rockchip_usb2phy_port_cfg *us2phy_get_port(struct phy *phy) > return &phy_cfg->port_cfgs[phy->id]; > } > > +#if IS_ENABLED(CONFIG_DM_REGULATOR) > +static int rockchip_usb2phy_regulator_set_enable(struct phy *phy, bool enable) > +{ > + struct udevice *parent = dev_get_parent(phy->dev); > + struct rockchip_usb2phy *priv = dev_get_priv(parent); > + struct udevice *supply; > + int ret = 0; > + > + if (phy->id == USB2PHY_PORT_HOST) > + supply = priv->host_supply; > + else > + supply = priv->otg_supply; > + > + if (supply) > + ret = regulator_set_enable(supply, enable); > + > + return ret; > +} > +#else > +static int rockchip_usb2phy_regulator_set_enable(struct phy *phy, bool enable) > +{ > + return 0; > +} > +#endif > + > static int rockchip_usb2phy_power_on(struct phy *phy) > { > struct udevice *parent = dev_get_parent(phy->dev); > struct rockchip_usb2phy *priv = dev_get_priv(parent); > const struct rockchip_usb2phy_port_cfg *port_cfg = us2phy_get_port(phy); > > + int ret = rockchip_usb2phy_regulator_set_enable(phy, true); > + > + if (ret) > + return ret; > + > property_enable(priv->reg_base, &port_cfg->phy_sus, false); > > /* waiting for the utmi_clk to become stable */ > @@ -108,6 +143,11 @@ static int rockchip_usb2phy_power_off(struct phy *phy) > > property_enable(priv->reg_base, &port_cfg->phy_sus, true); > > + int ret = rockchip_usb2phy_regulator_set_enable(phy, false); > + > + if (ret) > + return ret; > + > return 0; > } > > @@ -149,13 +189,31 @@ static int rockchip_usb2phy_of_xlate(struct phy *phy, > struct ofnode_phandle_args *args) > { > const char *name = phy->dev->name; > + struct udevice *parent = dev_get_parent(phy->dev); > + struct rockchip_usb2phy *priv = dev_get_priv(parent); > +#if IS_ENABLED(CONFIG_DM_REGULATOR) > + struct udevice *supply; > + int ret = device_get_supply_regulator(phy->dev, "phy-supply", &supply); > + > + if (ret && ret != -ENOENT) { > + pr_err("Failed to get PHY regulator\n"); > + return ret; > + } > +#endif > > - if (!strcasecmp(name, "host-port")) > + if (!strcasecmp(name, "host-port")) { > phy->id = USB2PHY_PORT_HOST; > - else if (!strcasecmp(name, "otg-port")) > +#if IS_ENABLED(CONFIG_DM_REGULATOR) > + priv->host_supply = supply; > +#endif > + } else if (!strcasecmp(name, "otg-port")) { > phy->id = USB2PHY_PORT_OTG; > - else > +#if IS_ENABLED(CONFIG_DM_REGULATOR) > + priv->otg_supply = supply; > +#endif > + } else { > dev_err(phy->dev, "improper %s device\n", name); > + } > > return 0; > }