phy: phy-imx8mq-usb: add vbus regulator support
Subsystems (2)
PATCH v7 1/2 phy: phy-imx8mq-usb: add vbus regulator support
Add support for enabling and disabling vbus-supply regulator found on several imx8mp boards in the usb3_phy0 and usb3_phy1 nodes.
---
v7:
- add #ifdef protection around clk_disable error path
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 | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-)
drivers/phy/phy-imx8mq-usb.c +36 -3
@@ -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,26 @@ 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: +#if CONFIG_IS_ENABLED (CLK ) +clk_disable (&imx_phy->phy_clk); +#endif +return ret; }static int imx8mq_usb_phy_power_off (struct phy *usb_phy)
@@ -196,6 +213,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 +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); +int ret; priv->type =dev_get_driver_data (dev); priv->base =dev_read_addr_ptr (dev);
@@ -232,8 +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);if (ret) {
@@ -241,6 +266,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 ; }
Signature · 1 line
2.25.1
PATCH v7 2/2 phy: phy-imx8mq-usb: clean up clock code
use CONFIG_IS_ENABLED for clock enable/disable and change printf's to dev_err. Additionlly remove the comment that does not make sense.
---
v7: protect against CLK being undefined in error path
v6: new patch
--- drivers/phy/phy-imx8mq-usb.c | 38 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
drivers/phy/phy-imx8mq-usb.c +17 -21
@@ -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);
@@ -202,9 +200,8 @@ static int imx8mq_usb_phy_power_on(struct phy *usb_phy)return 0 ; err: -#if CONFIG_IS_ENABLED (CLK ) -clk_disable (&imx_phy->phy_clk); -#endif +if (CONFIG_IS_ENABLED (CLK )) +clk_disable (&imx_phy->phy_clk);return ret; }
@@ -220,9 +217,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);
@@ -258,14 +254,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);
Signature · 1 line
2.25.1
Re: [PATCH v7 2/2] phy: phy-imx8mq-usb: clean up clock code
Quoted 4 lines · Tim Harvey
use
CONFIG_IS_ENABLEDfor clock enable/disable and change printf's todev_err. Additionlly remove the comment that does not make sense.Signed-off-by Tim Harvey <[email protected]>
Thanks!
Re: [PATCH v7 2/2] phy: phy-imx8mq-usb: clean up clock code
Quoted 10 lines · Marek Vasut
Quoted 4 lines · Tim Harvey
use
CONFIG_IS_ENABLEDfor clock enable/disable and change printf's todev_err. Additionlly remove the comment that does not make sense.Signed-off-by Tim Harvey <[email protected]>Reviewed-by Marek Vasut <[email protected]>Thanks!
Hi Marek,
Who's tree do the phy patches go through?
Best regards,
Tim
Re: [PATCH v7 2/2] phy: phy-imx8mq-usb: clean up clock code
Quoted 8 lines · Tim Harvey
Quoted 7 lines · Marek Vasut
Quoted 4 lines · Tim Harvey
use
CONFIG_IS_ENABLEDfor clock enable/disable and change printf's todev_err. Additionlly remove the comment that does not make sense.Signed-off-by Tim Harvey <[email protected]>
Quoted 7 lines
Quoted 3 lines
Reviewed-by Marek Vasut <[email protected]>Thanks!
Hi Marek,
Who's tree do the phy patches go through?
It is assigned to me in PW, so I'll pick it up via usb/master , applied , thanks.
That said, if you see something stuck for a month, that's too long, just let me know sooner please.
Hi Tim
Thanks!
Quoted 6 lines · Tim Harvey
Add support for enabling and disabling vbus-supply regulator found on several imx8mp boards in the
usb3_phy0andusb3_phy1nodes.Signed-off-by Tim Harvey <[email protected]>Reviewed-by Adam Ford <[email protected]>Reviewed-by Marek Vasut <[email protected]>
Quoted 148 lines
---
v7:
- add #ifdef protection aroundclk_disableerror pathv6:
- move changes to clk to separate patch
- sort new vars in reverse christmas tree stylev5:
- remove #ifCONFIG_IS_ENABLEDaround struct members
(you can not conditionally include if using if (CONFIG_IS_ENABLED(foo)) )
- replace clk '#ifCONFIG_IS_ENABLED(CLK)' with 'if (CONFIG_IS_ENABLED(CLK))'v4:
- useregulator_set_enable_if_allowedto handle regulator reference counting
errors
- added Marek's rb tagv3:
- changepr_errtodev_err
- add #ifCONFIG_IS_ENABLEDaroundvbus_supplyin struct
- add fail path to disable clock if regulator enable failedv2:
- protect ret with__maybe_unusedin caseCONFIG_CLKandCONFIG_DM_REGULATORnot defined
- add error prints on failures
- add Adam's rb tagSigned-off-by Tim Harvey <[email protected]>---
drivers/phy/phy-imx8mq-usb.c | 39 +++++++++++++++++++++++++++++++++---1 file changed, 36 insertions(+), 3 deletions(-)drivers/phy/phy-imx8mq-usb.c +2
-0@@ -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)drivers/phy/phy-imx8mq-usb.c +1
-0@@ -81,6 +83,7 @@ struct imx8mq_usb_phy { #endif void __iomem *base; enum imx8mpq_phy_type type; + struct udevice *vbus_supply; };
static const structudevice_idimx8mq_usb_phy_of_match[] = {drivers/phy/phy-imx8mq-usb.c +1
-0@@ -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;
#ifCONFIG_IS_ENABLED(CLK)
- int ret;
ret =clk_enable(&imx_phy->phy_clk);
if (ret) {
printf("Failed to enable usb phy clock\n");drivers/phy/phy-imx8mq-usb.c +0
-0@@ -183,12 +186,26 @@ 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;drivers/phy/phy-imx8mq-usb.c +6
-0+ +err: +#if CONFIG_IS_ENABLED (CLK ) + clk_disable(&imx_phy->phy_clk); +#endif + return ret;}
static intimx8mq_usb_phy_power_off(struct phy *usb_phy)drivers/phy/phy-imx8mq-usb.c +1
-0@@ -196,6 +213,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);drivers/phy/phy-imx8mq-usb.c +0
-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;
}drivers/phy/phy-imx8mq-usb.c +1
-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); + int ret;
priv->type =dev_get_driver_data(dev);
priv->base =dev_read_addr_ptr(dev);drivers/phy/phy-imx8mq-usb.c +0
-0@@ -232,8 +259,6 @@ int imx8mq_usb_phy_probe(struct udevice *dev) return -EINVAL;
#ifCONFIG_IS_ENABLED(CLK)
- int ret;
-
/* Assigned clock already set clock */ ret =clk_get_by_name(dev, "phy", &priv->phy_clk); if (ret) {drivers/phy/phy-imx8mq-usb.c +8
-0@@ -241,6 +266,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;
}