public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Eugen Hristev <eugen.hristev@collabora.com>
To: kever.yang@rock-chips.com, jonas@kwiboo.se,
	eugen.hristev@collabora.com, u-boot@lists.denx.de
Cc: u-boot-amlogic@groups.io, xdrudis@tinet.cat, jagan@edgeble.ai,
	neil.armstrong@linaro.org, anarsoul@gmail.com
Subject: [PATCH v5 6/6] phy: Keep balance of counts when ops is missing
Date: Wed, 19 Apr 2023 16:40:14 +0300	[thread overview]
Message-ID: <20230419134014.128461-6-eugen.hristev@collabora.com> (raw)
In-Reply-To: <20230419134014.128461-1-eugen.hristev@collabora.com>

From: Jonas Karlman <jonas@kwiboo.se>

Fixes: 226fce6108fe ("phy: Track power-on and init counts in uclass")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 drivers/phy/phy-uclass.c | 80 ++++++++++++++++++++--------------------
 1 file changed, 39 insertions(+), 41 deletions(-)

diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index 45ec1471d0ae..2a672549f268 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -228,24 +228,24 @@ int generic_phy_init(struct phy *phy)
 
 	if (!generic_phy_valid(phy))
 		return 0;
-	ops = phy_dev_ops(phy->dev);
-	if (!ops->init)
-		return 0;
-
 	counts = phy_get_counts(phy);
 	if (counts->init_count > 0) {
 		counts->init_count++;
 		return 0;
 	}
 
-	ret = ops->init(phy);
-	if (ret)
-		dev_err(phy->dev, "PHY: Failed to init %s: %d.\n",
-			phy->dev->name, ret);
-	else
-		counts->init_count = 1;
+	ops = phy_dev_ops(phy->dev);
+	if (ops->init) {
+		ret = ops->init(phy);
+		if (ret) {
+			dev_err(phy->dev, "PHY: Failed to init %s: %d.\n",
+				phy->dev->name, ret);
+			return ret;
+		}
+	}
+	counts->init_count = 1;
 
-	return ret;
+	return 0;
 }
 
 int generic_phy_reset(struct phy *phy)
@@ -274,10 +274,6 @@ int generic_phy_exit(struct phy *phy)
 
 	if (!generic_phy_valid(phy))
 		return 0;
-	ops = phy_dev_ops(phy->dev);
-	if (!ops->exit)
-		return 0;
-
 	counts = phy_get_counts(phy);
 	if (counts->init_count == 0)
 		return 0;
@@ -286,14 +282,18 @@ int generic_phy_exit(struct phy *phy)
 		return 0;
 	}
 
-	ret = ops->exit(phy);
-	if (ret)
-		dev_err(phy->dev, "PHY: Failed to exit %s: %d.\n",
-			phy->dev->name, ret);
-	else
-		counts->init_count = 0;
+	ops = phy_dev_ops(phy->dev);
+	if (ops->exit) {
+		ret = ops->exit(phy);
+		if (ret) {
+			dev_err(phy->dev, "PHY: Failed to exit %s: %d.\n",
+				phy->dev->name, ret);
+			return ret;
+		}
+	}
+	counts->init_count = 0;
 
-	return ret;
+	return 0;
 }
 
 int generic_phy_power_on(struct phy *phy)
@@ -304,10 +304,6 @@ int generic_phy_power_on(struct phy *phy)
 
 	if (!generic_phy_valid(phy))
 		return 0;
-	ops = phy_dev_ops(phy->dev);
-	if (!ops->power_on)
-		return 0;
-
 	counts = phy_get_counts(phy);
 	if (counts->power_on_count > 0) {
 		counts->power_on_count++;
@@ -321,12 +317,15 @@ int generic_phy_power_on(struct phy *phy)
 		return ret;
 	}
 
-	ret = ops->power_on(phy);
-	if (ret) {
-		dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n",
-			phy->dev->name, ret);
-		regulator_set_enable_if_allowed(counts->supply, false);
-		return ret;
+	ops = phy_dev_ops(phy->dev);
+	if (ops->power_on) {
+		ret = ops->power_on(phy);
+		if (ret) {
+			dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n",
+				phy->dev->name, ret);
+			regulator_set_enable_if_allowed(counts->supply, false);
+			return ret;
+		}
 	}
 	counts->power_on_count = 1;
 
@@ -341,10 +340,6 @@ int generic_phy_power_off(struct phy *phy)
 
 	if (!generic_phy_valid(phy))
 		return 0;
-	ops = phy_dev_ops(phy->dev);
-	if (!ops->power_off)
-		return 0;
-
 	counts = phy_get_counts(phy);
 	if (counts->power_on_count == 0)
 		return 0;
@@ -353,11 +348,14 @@ int generic_phy_power_off(struct phy *phy)
 		return 0;
 	}
 
-	ret = ops->power_off(phy);
-	if (ret) {
-		dev_err(phy->dev, "PHY: Failed to power off %s: %d.\n",
-			phy->dev->name, ret);
-		return ret;
+	ops = phy_dev_ops(phy->dev);
+	if (ops->power_off) {
+		ret = ops->power_off(phy);
+		if (ret) {
+			dev_err(phy->dev, "PHY: Failed to power off %s: %d.\n",
+				phy->dev->name, ret);
+			return ret;
+		}
 	}
 	counts->power_on_count = 0;
 
-- 
2.34.1


  parent reply	other threads:[~2023-04-19 13:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-19 13:40 [PATCH v5 1/6] ARM: dts: rockchip: rk3588-rock-5b-u-boot: add USB 2.0 host Eugen Hristev
2023-04-19 13:40 ` [PATCH v5 2/6] configs: rockchip: rock5b-rk3588: enable USB and regulators Eugen Hristev
2023-05-06  9:33   ` Kever Yang
2023-04-19 13:40 ` [PATCH v5 3/6] phy: add support for phy-supply Eugen Hristev
2023-05-06  9:34   ` Kever Yang
2023-04-19 13:40 ` [PATCH v5 4/6] phy: remove phy-supply related code Eugen Hristev
2023-05-06  9:36   ` Kever Yang
2023-05-09  7:53   ` neil.armstrong
2023-04-19 13:40 ` [PATCH v5 5/6] phy: rockchip-inno-usb2: add initial support for rk3588 PHY Eugen Hristev
2023-05-06  9:35   ` Kever Yang
2023-04-19 13:40 ` Eugen Hristev [this message]
2023-05-06  9:35   ` [PATCH v5 6/6] phy: Keep balance of counts when ops is missing Kever Yang
2023-05-06  9:58 ` [PATCH v5 1/6] ARM: dts: rockchip: rk3588-rock-5b-u-boot: add USB 2.0 host Kever Yang
2023-05-06 10:07 ` Kever Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230419134014.128461-6-eugen.hristev@collabora.com \
    --to=eugen.hristev@collabora.com \
    --cc=anarsoul@gmail.com \
    --cc=jagan@edgeble.ai \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=neil.armstrong@linaro.org \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    --cc=xdrudis@tinet.cat \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox