[PATCH v7 3/5] phy: core: Add support for phy suspend & resume

From: Krishna chaitanya chundru
Date: Tue Sep 20 2022 - 06:23:23 EST


Introducing phy power suspend and resume callbacks for allowing to
park the link-state in L1ss without holding any PCIe resources during
system suspend.

If we use phy_suspend & phy_resume API's we are getting compilation
issue as same function is present in drivers/net/phy/phy_device.c.

So creating phy_pm_suspend & phy_pm_resume API's.

Signed-off-by: Krishna chaitanya chundru <quic_krichai@xxxxxxxxxxx>
---
changes since v6:
- change names from power_down, power_up to suspend & resume
respectively.
---
drivers/phy/phy-core.c | 30 ++++++++++++++++++++++++++++++
include/linux/phy/phy.h | 20 ++++++++++++++++++++
2 files changed, 50 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index d93ddf1..ca3e423 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -441,6 +441,36 @@ int phy_set_speed(struct phy *phy, int speed)
}
EXPORT_SYMBOL_GPL(phy_set_speed);

+int phy_pm_suspend(struct phy *phy)
+{
+ int ret;
+
+ if (!phy || !phy->ops->suspend)
+ return 0;
+
+ mutex_lock(&phy->mutex);
+ ret = phy->ops->suspend(phy);
+ mutex_unlock(&phy->mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(phy_pm_suspend);
+
+int phy_pm_resume(struct phy *phy)
+{
+ int ret;
+
+ if (!phy || !phy->ops->resume)
+ return 0;
+
+ mutex_lock(&phy->mutex);
+ ret = phy->ops->resume(phy);
+ mutex_unlock(&phy->mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(phy_pm_resume);
+
int phy_reset(struct phy *phy)
{
int ret;
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index b141375..e312028 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -76,6 +76,8 @@ union phy_configure_opts {
* @set_mode: set the mode of the phy
* @set_media: set the media type of the phy (optional)
* @set_speed: set the speed of the phy (optional)
+ * @suspend: suspending the phy
+ * @resume: resuming the phy
* @reset: resetting the phy
* @calibrate: calibrate the phy
* @release: ops to be performed while the consumer relinquishes the PHY
@@ -89,6 +91,8 @@ struct phy_ops {
int (*set_mode)(struct phy *phy, enum phy_mode mode, int submode);
int (*set_media)(struct phy *phy, enum phy_media media);
int (*set_speed)(struct phy *phy, int speed);
+ int (*suspend)(struct phy *phy);
+ int (*resume)(struct phy *phy);

/**
* @configure:
@@ -226,6 +230,8 @@ int phy_init(struct phy *phy);
int phy_exit(struct phy *phy);
int phy_power_on(struct phy *phy);
int phy_power_off(struct phy *phy);
+int phy_pm_suspend(struct phy *phy);
+int phy_pm_resume(struct phy *phy);
int phy_set_mode_ext(struct phy *phy, enum phy_mode mode, int submode);
#define phy_set_mode(phy, mode) \
phy_set_mode_ext(phy, mode, 0)
@@ -349,6 +355,20 @@ static inline int phy_power_off(struct phy *phy)
return -ENOSYS;
}

+static inline int phy_pm_suspend(struct phy *phy)
+{
+ if (!phy)
+ return 0;
+ return -ENOSYS;
+}
+
+static inline int phy_pm_resume(struct phy *phy)
+{
+ if (!phy)
+ return 0;
+ return -ENOSYS;
+}
+
static inline int phy_set_mode_ext(struct phy *phy, enum phy_mode mode,
int submode)
{
--
2.7.4