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 3/6] phy: add support for phy-supply
Date: Wed, 19 Apr 2023 16:40:11 +0300 [thread overview]
Message-ID: <20230419134014.128461-3-eugen.hristev@collabora.com> (raw)
In-Reply-To: <20230419134014.128461-1-eugen.hristev@collabora.com>
Some phys require a phy-supply property that is a phandle to a regulator
that needs to be enabled for phy operations.
Implement basic supply lookup, enable and disabling, if DM_REGULATOR is
available.
[jonas@kwiboo.se:
use regulator_set_enable_if_allowed and disable if power_on ops fails]
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Eugen Hristev <eugen.hristev@collabora.com>
---
Changes in v5:
- add changes done by Jonas
drivers/phy/phy-uclass.c | 51 +++++++++++++++++++++++++++++++---------
1 file changed, 40 insertions(+), 11 deletions(-)
diff --git a/drivers/phy/phy-uclass.c b/drivers/phy/phy-uclass.c
index 3fef5135a9cb..45ec1471d0ae 100644
--- a/drivers/phy/phy-uclass.c
+++ b/drivers/phy/phy-uclass.c
@@ -12,6 +12,7 @@
#include <dm/devres.h>
#include <generic-phy.h>
#include <linux/list.h>
+#include <power/regulator.h>
/**
* struct phy_counts - Init and power-on counts of a single PHY port
@@ -29,12 +30,14 @@
* without a matching generic_phy_exit() afterwards
* @list: Handle for a linked list of these structures corresponding to
* ports of the same PHY provider
+ * @supply: Handle to a phy-supply device
*/
struct phy_counts {
unsigned long id;
int power_on_count;
int init_count;
struct list_head list;
+ struct udevice *supply;
};
static inline struct phy_ops *phy_dev_ops(struct udevice *dev)
@@ -58,7 +61,7 @@ static struct phy_counts *phy_get_counts(struct phy *phy)
return NULL;
}
-static int phy_alloc_counts(struct phy *phy)
+static int phy_alloc_counts(struct phy *phy, struct udevice *supply)
{
struct list_head *uc_priv;
struct phy_counts *counts;
@@ -76,6 +79,7 @@ static int phy_alloc_counts(struct phy *phy)
counts->id = phy->id;
counts->power_on_count = 0;
counts->init_count = 0;
+ counts->supply = supply;
list_add(&counts->list, uc_priv);
return 0;
@@ -123,7 +127,7 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy)
{
struct ofnode_phandle_args args;
struct phy_ops *ops;
- struct udevice *phydev;
+ struct udevice *phydev, *supply = NULL;
int i, ret;
debug("%s(node=%s, index=%d, phy=%p)\n",
@@ -172,7 +176,17 @@ int generic_phy_get_by_index_nodev(ofnode node, int index, struct phy *phy)
goto err;
}
- ret = phy_alloc_counts(phy);
+ if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
+ ret = device_get_supply_regulator(phydev, "phy-supply",
+ &supply);
+ if (ret && ret != -ENOENT) {
+ debug("%s: device_get_supply_regulator failed: %d\n",
+ __func__, ret);
+ goto err;
+ }
+ }
+
+ ret = phy_alloc_counts(phy, supply);
if (ret) {
debug("phy_alloc_counts() failed: %d\n", ret);
goto err;
@@ -300,14 +314,23 @@ int generic_phy_power_on(struct phy *phy)
return 0;
}
+ ret = regulator_set_enable_if_allowed(counts->supply, true);
+ if (ret && ret != -ENOSYS) {
+ dev_err(phy->dev, "PHY: Failed to enable regulator %s: %d.\n",
+ counts->supply->name, ret);
+ return ret;
+ }
+
ret = ops->power_on(phy);
- if (ret)
+ if (ret) {
dev_err(phy->dev, "PHY: Failed to power on %s: %d.\n",
phy->dev->name, ret);
- else
- counts->power_on_count = 1;
+ regulator_set_enable_if_allowed(counts->supply, false);
+ return ret;
+ }
+ counts->power_on_count = 1;
- return ret;
+ return 0;
}
int generic_phy_power_off(struct phy *phy)
@@ -331,13 +354,19 @@ int generic_phy_power_off(struct phy *phy)
}
ret = ops->power_off(phy);
- if (ret)
+ if (ret) {
dev_err(phy->dev, "PHY: Failed to power off %s: %d.\n",
phy->dev->name, ret);
- else
- counts->power_on_count = 0;
+ return ret;
+ }
+ counts->power_on_count = 0;
- return ret;
+ ret = regulator_set_enable_if_allowed(counts->supply, false);
+ if (ret && ret != -ENOSYS)
+ dev_err(phy->dev, "PHY: Failed to disable regulator %s: %d.\n",
+ counts->supply->name, ret);
+
+ return 0;
}
int generic_phy_configure(struct phy *phy, void *params)
--
2.34.1
next prev 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 ` Eugen Hristev [this message]
2023-05-06 9:34 ` [PATCH v5 3/6] phy: add support for phy-supply 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 ` [PATCH v5 6/6] phy: Keep balance of counts when ops is missing Eugen Hristev
2023-05-06 9:35 ` 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-3-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