diff mbox series

phy: stm32: usbphyc: manage optional vbus regulator on phy_power_on/off

Message ID 20201015125057.8037-1-patrick.delaunay@st.com
State Accepted
Commit c4801389588c9ed49222e6f0615de9879d445f9c
Delegated to: Patrick Delaunay
Headers show
Series phy: stm32: usbphyc: manage optional vbus regulator on phy_power_on/off | expand

Commit Message

Patrick DELAUNAY Oct. 15, 2020, 12:50 p.m. UTC
This patch adds support for optional vbus regulator.
It is managed on phy_power_on/off calls and may be needed for host mode.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 .../phy/phy-stm32-usbphyc.txt                 |  2 ++
 drivers/phy/phy-stm32-usbphyc.c               | 33 +++++++++++++------
 2 files changed, 25 insertions(+), 10 deletions(-)

Comments

Patrice CHOTARD Oct. 21, 2020, 11:45 a.m. UTC | #1
Hi Patrick

On 10/15/20 2:50 PM, Patrick Delaunay wrote:
> This patch adds support for optional vbus regulator.
> It is managed on phy_power_on/off calls and may be needed for host mode.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  .../phy/phy-stm32-usbphyc.txt                 |  2 ++
>  drivers/phy/phy-stm32-usbphyc.c               | 33 +++++++++++++------
>  2 files changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt b/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
> index da98407403..edfe4b426c 100644
> --- a/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
> +++ b/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
> @@ -45,6 +45,8 @@ Required properties:
>  - #phy-cells: see phy-bindings.txt in the same directory, must be <0> for PHY
>    port#1 and must be <1> for PHY port#2, to select USB controller
>  
> +Optional properties:
> +- vbus-supply: phandle to the regulator providing 5V vbus to the USB connector
>  
>  Example:
>  		usbphyc: usb-phy@5a006000 {
> diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
> index 9d4296d649..ab4a913c93 100644
> --- a/drivers/phy/phy-stm32-usbphyc.c
> +++ b/drivers/phy/phy-stm32-usbphyc.c
> @@ -59,6 +59,7 @@ struct stm32_usbphyc {
>  	struct udevice *vdda1v8;
>  	struct stm32_usbphyc_phy {
>  		struct udevice *vdd;
> +		struct udevice *vbus;
>  		bool init;
>  		bool powered;
>  	} phys[MAX_PHYS];
> @@ -244,6 +245,11 @@ static int stm32_usbphyc_phy_power_on(struct phy *phy)
>  		if (ret)
>  			return ret;
>  	}
> +	if (usbphyc_phy->vbus) {
> +		ret = regulator_set_enable(usbphyc_phy->vbus, true);
> +		if (ret)
> +			return ret;
> +	}
>  
>  	usbphyc_phy->powered = true;
>  
> @@ -262,6 +268,11 @@ static int stm32_usbphyc_phy_power_off(struct phy *phy)
>  	if (stm32_usbphyc_is_powered(usbphyc))
>  		return 0;
>  
> +	if (usbphyc_phy->vbus) {
> +		ret = regulator_set_enable(usbphyc_phy->vbus, false);
> +		if (ret)
> +			return ret;
> +	}
>  	if (usbphyc_phy->vdd) {
>  		ret = regulator_set_enable_if_allowed(usbphyc_phy->vdd, false);
>  		if (ret)
> @@ -271,7 +282,7 @@ static int stm32_usbphyc_phy_power_off(struct phy *phy)
>  	return 0;
>  }
>  
> -static int stm32_usbphyc_get_regulator(struct udevice *dev, ofnode node,
> +static int stm32_usbphyc_get_regulator(ofnode node,
>  				       char *supply_name,
>  				       struct udevice **regulator)
>  {
> @@ -281,19 +292,14 @@ static int stm32_usbphyc_get_regulator(struct udevice *dev, ofnode node,
>  	ret = ofnode_parse_phandle_with_args(node, supply_name,
>  					     NULL, 0, 0,
>  					     &regulator_phandle);
> -	if (ret) {
> -		dev_err(dev, "Can't find %s property (%d)\n", supply_name, ret);
> +	if (ret)
>  		return ret;
> -	}
>  
>  	ret = uclass_get_device_by_ofnode(UCLASS_REGULATOR,
>  					  regulator_phandle.node,
>  					  regulator);
> -
> -	if (ret) {
> -		dev_err(dev, "Can't get %s regulator (%d)\n", supply_name, ret);
> +	if (ret)
>  		return ret;
> -	}
>  
>  	return 0;
>  }
> @@ -380,10 +386,17 @@ static int stm32_usbphyc_probe(struct udevice *dev)
>  
>  		usbphyc_phy->init = false;
>  		usbphyc_phy->powered = false;
> -		ret = stm32_usbphyc_get_regulator(dev, node, "phy-supply",
> +		ret = stm32_usbphyc_get_regulator(node, "phy-supply",
>  						  &usbphyc_phy->vdd);
> -		if (ret)
> +		if (ret) {
> +			dev_err(dev, "Can't get phy-supply regulator\n");
>  			return ret;
> +		}
> +
> +		ret = stm32_usbphyc_get_regulator(node, "vbus-supply",
> +						  &usbphyc_phy->vbus);
> +		if (ret)
> +			usbphyc_phy->vbus = NULL;
>  
>  		node = dev_read_next_subnode(node);
>  	}

Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks
Patrick DELAUNAY Nov. 25, 2020, 11:04 a.m. UTC | #2
Hi,

> From: Patrick DELAUNAY <patrick.delaunay@st.com>
> Sent: jeudi 15 octobre 2020 14:51
> 
> This patch adds support for optional vbus regulator.
> It is managed on phy_power_on/off calls and may be needed for host mode.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
> 
>  .../phy/phy-stm32-usbphyc.txt                 |  2 ++
>  drivers/phy/phy-stm32-usbphyc.c               | 33 +++++++++++++------
>  2 files changed, 25 insertions(+), 10 deletions(-)
> 

Applied to u-boot-stm/master, thanks!

Regards

Patrick
diff mbox series

Patch

diff --git a/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt b/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
index da98407403..edfe4b426c 100644
--- a/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
+++ b/doc/device-tree-bindings/phy/phy-stm32-usbphyc.txt
@@ -45,6 +45,8 @@  Required properties:
 - #phy-cells: see phy-bindings.txt in the same directory, must be <0> for PHY
   port#1 and must be <1> for PHY port#2, to select USB controller
 
+Optional properties:
+- vbus-supply: phandle to the regulator providing 5V vbus to the USB connector
 
 Example:
 		usbphyc: usb-phy@5a006000 {
diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
index 9d4296d649..ab4a913c93 100644
--- a/drivers/phy/phy-stm32-usbphyc.c
+++ b/drivers/phy/phy-stm32-usbphyc.c
@@ -59,6 +59,7 @@  struct stm32_usbphyc {
 	struct udevice *vdda1v8;
 	struct stm32_usbphyc_phy {
 		struct udevice *vdd;
+		struct udevice *vbus;
 		bool init;
 		bool powered;
 	} phys[MAX_PHYS];
@@ -244,6 +245,11 @@  static int stm32_usbphyc_phy_power_on(struct phy *phy)
 		if (ret)
 			return ret;
 	}
+	if (usbphyc_phy->vbus) {
+		ret = regulator_set_enable(usbphyc_phy->vbus, true);
+		if (ret)
+			return ret;
+	}
 
 	usbphyc_phy->powered = true;
 
@@ -262,6 +268,11 @@  static int stm32_usbphyc_phy_power_off(struct phy *phy)
 	if (stm32_usbphyc_is_powered(usbphyc))
 		return 0;
 
+	if (usbphyc_phy->vbus) {
+		ret = regulator_set_enable(usbphyc_phy->vbus, false);
+		if (ret)
+			return ret;
+	}
 	if (usbphyc_phy->vdd) {
 		ret = regulator_set_enable_if_allowed(usbphyc_phy->vdd, false);
 		if (ret)
@@ -271,7 +282,7 @@  static int stm32_usbphyc_phy_power_off(struct phy *phy)
 	return 0;
 }
 
-static int stm32_usbphyc_get_regulator(struct udevice *dev, ofnode node,
+static int stm32_usbphyc_get_regulator(ofnode node,
 				       char *supply_name,
 				       struct udevice **regulator)
 {
@@ -281,19 +292,14 @@  static int stm32_usbphyc_get_regulator(struct udevice *dev, ofnode node,
 	ret = ofnode_parse_phandle_with_args(node, supply_name,
 					     NULL, 0, 0,
 					     &regulator_phandle);
-	if (ret) {
-		dev_err(dev, "Can't find %s property (%d)\n", supply_name, ret);
+	if (ret)
 		return ret;
-	}
 
 	ret = uclass_get_device_by_ofnode(UCLASS_REGULATOR,
 					  regulator_phandle.node,
 					  regulator);
-
-	if (ret) {
-		dev_err(dev, "Can't get %s regulator (%d)\n", supply_name, ret);
+	if (ret)
 		return ret;
-	}
 
 	return 0;
 }
@@ -380,10 +386,17 @@  static int stm32_usbphyc_probe(struct udevice *dev)
 
 		usbphyc_phy->init = false;
 		usbphyc_phy->powered = false;
-		ret = stm32_usbphyc_get_regulator(dev, node, "phy-supply",
+		ret = stm32_usbphyc_get_regulator(node, "phy-supply",
 						  &usbphyc_phy->vdd);
-		if (ret)
+		if (ret) {
+			dev_err(dev, "Can't get phy-supply regulator\n");
 			return ret;
+		}
+
+		ret = stm32_usbphyc_get_regulator(node, "vbus-supply",
+						  &usbphyc_phy->vbus);
+		if (ret)
+			usbphyc_phy->vbus = NULL;
 
 		node = dev_read_next_subnode(node);
 	}