diff mbox series

[2/7] usb: onboard-hub: Fix the return values of regulator APIs

Message ID 20240605100221.3571-3-venkatesh.abbarapu@amd.com
State Changes Requested
Delegated to: Marek Vasut
Headers show
Series Add the USB5744 hub driver as per new DT binding | expand

Commit Message

Venkatesh Yadav Abbarapu June 5, 2024, 10:02 a.m. UTC
Use the regulator API's only if the config DM_REGULATOR is enabled.
Don't error out if there is no vdd regulator supply, as these are
optional properties.

Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
---
 common/usb_onboard_hub.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

Comments

Marek Vasut Sept. 2, 2024, 6:45 p.m. UTC | #1
On 6/5/24 12:02 PM, Venkatesh Yadav Abbarapu wrote:
> Use the regulator API's only if the config DM_REGULATOR is enabled.
> Don't error out if there is no vdd regulator supply, as these are
> optional properties.
> 
> Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com>
> ---
>   common/usb_onboard_hub.c | 22 ++++++++++++++--------
>   1 file changed, 14 insertions(+), 8 deletions(-)
> 
> diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c
> index 2f6fb71935d..0cfaa90fce3 100644
> --- a/common/usb_onboard_hub.c
> +++ b/common/usb_onboard_hub.c
> @@ -30,16 +30,22 @@ static int usb_onboard_hub_probe(struct udevice *dev)
>   	struct onboard_hub *hub = dev_get_priv(dev);
>   	int ret;
>   
> -	ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
> -	if (ret) {
> -		dev_err(dev, "can't get vdd-supply: %d\n", ret);
> -		return ret;

Handle -ENOSYS (regulator support not available) return value here and 
you wouldn't need all the ifdeffery.
diff mbox series

Patch

diff --git a/common/usb_onboard_hub.c b/common/usb_onboard_hub.c
index 2f6fb71935d..0cfaa90fce3 100644
--- a/common/usb_onboard_hub.c
+++ b/common/usb_onboard_hub.c
@@ -30,16 +30,22 @@  static int usb_onboard_hub_probe(struct udevice *dev)
 	struct onboard_hub *hub = dev_get_priv(dev);
 	int ret;
 
-	ret = device_get_supply_regulator(dev, "vdd-supply", &hub->vdd);
-	if (ret) {
-		dev_err(dev, "can't get vdd-supply: %d\n", ret);
-		return ret;
+	if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
+		ret = device_get_supply_regulator(dev, "vdd-supply",
+						  &hub->vdd);
+		if (ret && ret != -ENOENT) {
+			dev_err(dev, "Failed to get VDD regulator: %d\n", ret);
+			return ret;
+		}
+		if (hub->vdd) {
+			ret = regulator_set_enable_if_allowed(hub->vdd, true);
+			if (ret && ret != -ENOSYS) {
+				dev_err(dev, "Failed to enable VDD regulator: %d\n", ret);
+				return ret;
+			}
+		}
 	}
 
-	ret = regulator_set_enable_if_allowed(hub->vdd, true);
-	if (ret)
-		dev_err(dev, "can't enable vdd-supply: %d\n", ret);
-
 	hub->reset_gpio = devm_gpiod_get_optional(dev, "reset",
 						  GPIOD_IS_OUT | GPIOD_ACTIVE_LOW);
 	/* property is optional, don't return error! */