[PATCH v6 1/2] phy: phy-imx8mq-usb: add vbus regulator support
Marek Vasut
marex at denx.de
Thu Jul 13 19:55:06 CEST 2023
On 7/13/23 19:11, 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 <tharvey at gateworks.com>
> Reviewed-by: Adam Ford <aford173 at gmail.com>
> Reviewed-by: Marek Vasut <marex at denx.de>
> ---
> 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 <linux/delay.h>
> #include <linux/err.h>
> #include <clk.h>
> +#include <dm/device_compat.h>
> +#include <power/regulator.h>
>
> #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);
This would fail if CLK is not enabled , or cause clock imbalance.
(you would avoid this issue if you were to swap the two patches, or add
+if CONFIG_IS_ENABLED(CLK)
clk_disable(...);
[...]
More information about the U-Boot
mailing list