[PATCH resend v5 6/6] phy: Keep balance of counts when ops is missing
Eugen Hristev
eugen.hristev at collabora.com
Mon May 15 11:59:50 CEST 2023
From: Jonas Karlman <jonas at kwiboo.se>
Reviewed-by: Kever Yang <kever.yang at rock-chips.com>
Fixes: 226fce6108fe ("phy: Track power-on and init counts in uclass")
Signed-off-by: Jonas Karlman <jonas at 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 28cc0e6f2b80..629ef3aa3de5 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
More information about the U-Boot
mailing list