All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers
@ 2020-06-25 19:54 Wesley Cheng
  2020-06-25 19:54 ` [PATCH v3 1/2] " Wesley Cheng
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Wesley Cheng @ 2020-06-25 19:54 UTC (permalink / raw
  To: kishon, vkoul, agross, bjorn.andersson
  Cc: linux-arm-msm, linux-kernel, jackp, Wesley Cheng

Changes in v3:
 - Fixed strict checkpatch warnings due to alignment
 - Remove debug artifacts from prints
 - Split the set mode callback addition to another patch
 - Removed suspended parameter

Changes in v2:
 - Addressed checkpatch alignment/line length warnings.
 - Removed superfluous init in qcom_snps_hsphy_resume().

Adds a set mode callback and runtime suspend/resume handlers to the
phy-qcom-snps-femto-v2 driver.  The set mode is used to enable certain
power management features in the PHY during suspend/resume.

Wesley Cheng (2):
  phy: qcom-snps: Add runtime suspend and resume handlers
  phy: qcom-snps: Add a set mode callback

 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 85 +++++++++++++++++++
 1 file changed, 85 insertions(+)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] phy: qcom-snps: Add runtime suspend and resume handlers
  2020-06-25 19:54 [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Wesley Cheng
@ 2020-06-25 19:54 ` Wesley Cheng
  2020-06-29  9:44   ` Vinod Koul
  2020-06-25 19:54 ` [PATCH v3 2/2] phy: qcom-snps: Add a set mode callback Wesley Cheng
  2020-06-29  9:46 ` [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Vinod Koul
  2 siblings, 1 reply; 5+ messages in thread
From: Wesley Cheng @ 2020-06-25 19:54 UTC (permalink / raw
  To: kishon, vkoul, agross, bjorn.andersson
  Cc: linux-arm-msm, linux-kernel, jackp, Wesley Cheng

Allow for the PHY to be put into a powered down state when possible.
Add the required suspend and resume callbacks, which will determine
what resources can be turned off depending on the cable status.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Reviewed-by: Vinod Koul <vkoul@kernel.org>
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 73 +++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
index 4d74045271eb..152d8633f4ea 100644
--- a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
+++ b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
@@ -104,6 +104,63 @@ static inline void qcom_snps_hsphy_write_mask(void __iomem *base, u32 offset,
 	readl_relaxed(base + offset);
 }
 
+static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
+{
+	dev_dbg(&hsphy->phy->dev, "Suspend QCOM SNPS PHY\n");
+
+	if (hsphy->mode == PHY_MODE_USB_HOST) {
+		/* Enable auto-resume to meet remote wakeup timing */
+		qcom_snps_hsphy_write_mask(hsphy->base,
+					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
+					   USB2_AUTO_RESUME,
+					   USB2_AUTO_RESUME);
+		usleep_range(500, 1000);
+		qcom_snps_hsphy_write_mask(hsphy->base,
+					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
+					   0, USB2_AUTO_RESUME);
+	}
+
+	clk_disable_unprepare(hsphy->cfg_ahb_clk);
+	return 0;
+}
+
+static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
+{
+	int ret;
+
+	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
+
+	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
+	if (ret) {
+		dev_err(&hsphy->phy->dev, "failed to enable cfg ahb clock\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static int __maybe_unused qcom_snps_hsphy_runtime_suspend(struct device *dev)
+{
+	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
+
+	if (!hsphy->phy_initialized)
+		return 0;
+
+	qcom_snps_hsphy_suspend(hsphy);
+	return 0;
+}
+
+static int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)
+{
+	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
+
+	if (!hsphy->phy_initialized)
+		return 0;
+
+	qcom_snps_hsphy_resume(hsphy);
+	return 0;
+}
+
 static int qcom_snps_hsphy_init(struct phy *phy)
 {
 	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
@@ -212,6 +269,11 @@ static const struct of_device_id qcom_snps_hsphy_of_match_table[] = {
 };
 MODULE_DEVICE_TABLE(of, qcom_snps_hsphy_of_match_table);
 
+static const struct dev_pm_ops qcom_snps_hsphy_pm_ops = {
+	SET_RUNTIME_PM_OPS(qcom_snps_hsphy_runtime_suspend,
+			   qcom_snps_hsphy_runtime_resume, NULL)
+};
+
 static int qcom_snps_hsphy_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -255,6 +317,14 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+	/*
+	 * Prevent runtime pm from being ON by default. Users can enable
+	 * it using power/control in sysfs.
+	 */
+	pm_runtime_forbid(dev);
+
 	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_hsphy_gen_ops);
 	if (IS_ERR(generic_phy)) {
 		ret = PTR_ERR(generic_phy);
@@ -269,6 +339,8 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
 	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
 	if (!IS_ERR(phy_provider))
 		dev_dbg(dev, "Registered Qcom-SNPS HS phy\n");
+	else
+		pm_runtime_disable(dev);
 
 	return PTR_ERR_OR_ZERO(phy_provider);
 }
@@ -277,6 +349,7 @@ static struct platform_driver qcom_snps_hsphy_driver = {
 	.probe		= qcom_snps_hsphy_probe,
 	.driver = {
 		.name	= "qcom-snps-hs-femto-v2-phy",
+		.pm = &qcom_snps_hsphy_pm_ops,
 		.of_match_table = qcom_snps_hsphy_of_match_table,
 	},
 };
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] phy: qcom-snps: Add a set mode callback
  2020-06-25 19:54 [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Wesley Cheng
  2020-06-25 19:54 ` [PATCH v3 1/2] " Wesley Cheng
@ 2020-06-25 19:54 ` Wesley Cheng
  2020-06-29  9:46 ` [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Wesley Cheng @ 2020-06-25 19:54 UTC (permalink / raw
  To: kishon, vkoul, agross, bjorn.andersson
  Cc: linux-arm-msm, linux-kernel, jackp, Wesley Cheng

The set mode handler is used to keep track of the current role of the
device.  This is used for enabling certain resources within the PHY
depending on if the device is behaving as a host or device.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
---
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
index 152d8633f4ea..ae4bac024c7b 100644
--- a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
+++ b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
@@ -77,6 +77,7 @@ static const char * const qcom_snps_hsphy_vreg_names[] = {
  * @phy_reset: phy reset control
  * @vregs: regulator supplies bulk data
  * @phy_initialized: if PHY has been initialized correctly
+ * @mode: contains the current mode the PHY is in
  */
 struct qcom_snps_hsphy {
 	struct phy *phy;
@@ -88,6 +89,7 @@ struct qcom_snps_hsphy {
 	struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
 
 	bool phy_initialized;
+	enum phy_mode mode;
 };
 
 static inline void qcom_snps_hsphy_write_mask(void __iomem *base, u32 offset,
@@ -161,6 +163,15 @@ static int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)
 	return 0;
 }
 
+static int qcom_snps_hsphy_set_mode(struct phy *phy, enum phy_mode mode,
+				    int submode)
+{
+	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
+
+	hsphy->mode = mode;
+	return 0;
+}
+
 static int qcom_snps_hsphy_init(struct phy *phy)
 {
 	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
@@ -258,6 +269,7 @@ static int qcom_snps_hsphy_exit(struct phy *phy)
 static const struct phy_ops qcom_snps_hsphy_gen_ops = {
 	.init		= qcom_snps_hsphy_init,
 	.exit		= qcom_snps_hsphy_exit,
+	.set_mode	= qcom_snps_hsphy_set_mode,
 	.owner		= THIS_MODULE,
 };
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] phy: qcom-snps: Add runtime suspend and resume handlers
  2020-06-25 19:54 ` [PATCH v3 1/2] " Wesley Cheng
@ 2020-06-29  9:44   ` Vinod Koul
  0 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2020-06-29  9:44 UTC (permalink / raw
  To: Wesley Cheng
  Cc: kishon, agross, bjorn.andersson, linux-arm-msm, linux-kernel,
	jackp

Hi Wesley,

On 25-06-20, 12:54, Wesley Cheng wrote:
> Allow for the PHY to be put into a powered down state when possible.
> Add the required suspend and resume callbacks, which will determine
> what resources can be turned off depending on the cable status.
> 
> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
> Reviewed-by: Vinod Koul <vkoul@kernel.org>

Please do not add this tag unless someone send it explictly over the
email.. I do not recall sending a review tag

> ---
>  drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 73 +++++++++++++++++++
>  1 file changed, 73 insertions(+)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
> index 4d74045271eb..152d8633f4ea 100644
> --- a/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c
> @@ -104,6 +104,63 @@ static inline void qcom_snps_hsphy_write_mask(void __iomem *base, u32 offset,
>  	readl_relaxed(base + offset);
>  }
>  
> +static int qcom_snps_hsphy_suspend(struct qcom_snps_hsphy *hsphy)
> +{
> +	dev_dbg(&hsphy->phy->dev, "Suspend QCOM SNPS PHY\n");
> +
> +	if (hsphy->mode == PHY_MODE_USB_HOST) {
> +		/* Enable auto-resume to meet remote wakeup timing */
> +		qcom_snps_hsphy_write_mask(hsphy->base,
> +					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
> +					   USB2_AUTO_RESUME,
> +					   USB2_AUTO_RESUME);
> +		usleep_range(500, 1000);
> +		qcom_snps_hsphy_write_mask(hsphy->base,
> +					   USB2_PHY_USB_PHY_HS_PHY_CTRL2,
> +					   0, USB2_AUTO_RESUME);
> +	}
> +
> +	clk_disable_unprepare(hsphy->cfg_ahb_clk);
> +	return 0;
> +}
> +
> +static int qcom_snps_hsphy_resume(struct qcom_snps_hsphy *hsphy)
> +{
> +	int ret;
> +
> +	dev_dbg(&hsphy->phy->dev, "Resume QCOM SNPS PHY, mode\n");
> +
> +	ret = clk_prepare_enable(hsphy->cfg_ahb_clk);
> +	if (ret) {
> +		dev_err(&hsphy->phy->dev, "failed to enable cfg ahb clock\n");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused qcom_snps_hsphy_runtime_suspend(struct device *dev)
> +{
> +	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
> +
> +	if (!hsphy->phy_initialized)
> +		return 0;
> +
> +	qcom_snps_hsphy_suspend(hsphy);
> +	return 0;
> +}
> +
> +static int __maybe_unused qcom_snps_hsphy_runtime_resume(struct device *dev)
> +{
> +	struct qcom_snps_hsphy *hsphy = dev_get_drvdata(dev);
> +
> +	if (!hsphy->phy_initialized)
> +		return 0;
> +
> +	qcom_snps_hsphy_resume(hsphy);
> +	return 0;
> +}
> +
>  static int qcom_snps_hsphy_init(struct phy *phy)
>  {
>  	struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
> @@ -212,6 +269,11 @@ static const struct of_device_id qcom_snps_hsphy_of_match_table[] = {
>  };
>  MODULE_DEVICE_TABLE(of, qcom_snps_hsphy_of_match_table);
>  
> +static const struct dev_pm_ops qcom_snps_hsphy_pm_ops = {
> +	SET_RUNTIME_PM_OPS(qcom_snps_hsphy_runtime_suspend,
> +			   qcom_snps_hsphy_runtime_resume, NULL)
> +};
> +
>  static int qcom_snps_hsphy_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -255,6 +317,14 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	pm_runtime_set_active(dev);
> +	pm_runtime_enable(dev);
> +	/*
> +	 * Prevent runtime pm from being ON by default. Users can enable
> +	 * it using power/control in sysfs.
> +	 */
> +	pm_runtime_forbid(dev);
> +
>  	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_hsphy_gen_ops);
>  	if (IS_ERR(generic_phy)) {
>  		ret = PTR_ERR(generic_phy);
> @@ -269,6 +339,8 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
>  	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
>  	if (!IS_ERR(phy_provider))
>  		dev_dbg(dev, "Registered Qcom-SNPS HS phy\n");
> +	else
> +		pm_runtime_disable(dev);
>  
>  	return PTR_ERR_OR_ZERO(phy_provider);
>  }
> @@ -277,6 +349,7 @@ static struct platform_driver qcom_snps_hsphy_driver = {
>  	.probe		= qcom_snps_hsphy_probe,
>  	.driver = {
>  		.name	= "qcom-snps-hs-femto-v2-phy",
> +		.pm = &qcom_snps_hsphy_pm_ops,
>  		.of_match_table = qcom_snps_hsphy_of_match_table,
>  	},
>  };
> -- 
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project

-- 
~Vinod

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers
  2020-06-25 19:54 [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Wesley Cheng
  2020-06-25 19:54 ` [PATCH v3 1/2] " Wesley Cheng
  2020-06-25 19:54 ` [PATCH v3 2/2] phy: qcom-snps: Add a set mode callback Wesley Cheng
@ 2020-06-29  9:46 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2020-06-29  9:46 UTC (permalink / raw
  To: Wesley Cheng
  Cc: kishon, agross, bjorn.andersson, linux-arm-msm, linux-kernel,
	jackp

On 25-06-20, 12:54, Wesley Cheng wrote:
> Changes in v3:
>  - Fixed strict checkpatch warnings due to alignment
>  - Remove debug artifacts from prints
>  - Split the set mode callback addition to another patch
>  - Removed suspended parameter
> 
> Changes in v2:
>  - Addressed checkpatch alignment/line length warnings.
>  - Removed superfluous init in qcom_snps_hsphy_resume().
> 
> Adds a set mode callback and runtime suspend/resume handlers to the
> phy-qcom-snps-femto-v2 driver.  The set mode is used to enable certain
> power management features in the PHY during suspend/resume.

Applied after dropping the wrong review tag, thanks
-- 
~Vinod

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-29 21:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-25 19:54 [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Wesley Cheng
2020-06-25 19:54 ` [PATCH v3 1/2] " Wesley Cheng
2020-06-29  9:44   ` Vinod Koul
2020-06-25 19:54 ` [PATCH v3 2/2] phy: qcom-snps: Add a set mode callback Wesley Cheng
2020-06-29  9:46 ` [PATCH v3 0/2] phy: qcom-snps: Add runtime suspend and resume handlers Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.