All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
To: Rob Herring <robh+dt@kernel.org>, Andy Gross <agross@kernel.org>,
	"Bjorn Andersson" <bjorn.andersson@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@kernel.org>,
	Stephen Boyd <swboyd@chromium.org>,
	Doug Anderson <dianders@chromium.org>,
	"Matthias Kaehlcke" <mka@chromium.org>
Cc: <devicetree@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<quic_pkondeti@quicinc.com>, <quic_ppratap@quicinc.com>,
	Sandeep Maheswaram <quic_c_sanm@quicinc.com>
Subject: [PATCH v2 2/3] usb: dwc3: qcom: Add multi-pd support
Date: Mon, 25 Oct 2021 14:37:30 +0530	[thread overview]
Message-ID: <1635152851-23660-3-git-send-email-quic_c_sanm@quicinc.com> (raw)
In-Reply-To: <1635152851-23660-1-git-send-email-quic_c_sanm@quicinc.com>

Add multi pd support to set performance state for cx domain
to maintain minimum corner voltage for USB clocks.

Signed-off-by: Sandeep Maheswaram <quic_c_sanm@quicinc.com>
---
v2:
Added error handling and detach function.Used attach_by_id function.

 drivers/usb/dwc3/dwc3-qcom.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 9abbd01..efbd34a 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -17,6 +17,7 @@
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/phy/phy.h>
+#include <linux/pm_domain.h>
 #include <linux/usb/of.h>
 #include <linux/reset.h>
 #include <linux/iopoll.h>
@@ -89,6 +90,14 @@ struct dwc3_qcom {
 	bool			pm_suspended;
 	struct icc_path		*icc_path_ddr;
 	struct icc_path		*icc_path_apps;
+
+	/* power domain for cx */
+	struct device		*pd_cx;
+	struct device_link	*pd_link_cx;
+
+	/* power domain for usb gdsc */
+	struct device		*pd_usb_gdsc;
+	struct device_link	*pd_link_usb_gdsc;
 };
 
 static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
@@ -521,6 +530,79 @@ static int dwc3_qcom_setup_irq(struct platform_device *pdev)
 	return 0;
 }
 
+static int dwc3_qcom_attach_pd(struct device *dev)
+{
+	struct dwc3_qcom *qcom = dev_get_drvdata(dev);
+	int ret;
+
+	/* Do nothing when in a single power domain */
+	if (dev->pm_domain)
+		return 0;
+
+	qcom->pd_cx = dev_pm_domain_attach_by_id(dev, 0);
+	if (IS_ERR_OR_NULL(qcom->pd_cx)) {
+		dev_err(dev, "Failed to attach cx pd.\n");
+
+		if (!qcom->pd_cx)
+			return -EINVAL;
+		else
+			return PTR_ERR(qcom->pd_cx);
+	}
+
+	qcom->pd_link_cx = device_link_add(dev, qcom->pd_cx,
+			DL_FLAG_STATELESS |
+			DL_FLAG_PM_RUNTIME |
+			DL_FLAG_RPM_ACTIVE);
+	if (!qcom->pd_link_cx) {
+		dev_err(dev, "Failed to add device_link to cx pd.\n");
+		ret = -EINVAL;
+		goto detach_cx_pd;
+	}
+
+	qcom->pd_usb_gdsc = dev_pm_domain_attach_by_id(dev, 1);
+	if (IS_ERR_OR_NULL(qcom->pd_usb_gdsc)) {
+		dev_err(dev, "Failed to attach usb gdsc pd.\n");
+		if (!qcom->pd_usb_gdsc)
+			ret = -EINVAL;
+		else
+			ret = PTR_ERR(qcom->pd_usb_gdsc);
+		goto del_cx_link;
+	}
+
+	qcom->pd_link_usb_gdsc = device_link_add(dev, qcom->pd_usb_gdsc,
+			DL_FLAG_STATELESS |
+			DL_FLAG_PM_RUNTIME |
+			DL_FLAG_RPM_ACTIVE);
+	if (!qcom->pd_link_usb_gdsc) {
+		dev_err(dev, "Failed to add device_link to usb gdsc pd.\n");
+		ret = -EINVAL;
+		goto detach_gdsc_pd;
+	}
+
+	return 0;
+
+detach_gdsc_pd:
+	dev_pm_domain_detach(qcom->pd_usb_gdsc, true);
+del_cx_link:
+	device_link_del(qcom->pd_link_cx);
+detach_cx_pd:
+	dev_pm_domain_detach(qcom->pd_cx, true);
+	return ret;
+}
+
+static void dwc3_qcom_detach_pd(struct device *dev)
+{
+	struct dwc3_qcom *qcom = dev_get_drvdata(dev);
+
+	if (dev->pm_domain)
+		return;
+
+	device_link_del(qcom->pd_link_usb_gdsc);
+	dev_pm_domain_detach(qcom->pd_usb_gdsc, true);
+	device_link_del(qcom->pd_link_cx);
+	dev_pm_domain_detach(qcom->pd_cx, true);
+}
+
 static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count)
 {
 	struct device		*dev = qcom->dev;
@@ -837,6 +919,10 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 	if (ret)
 		goto interconnect_exit;
 
+	ret = dwc3_qcom_attach_pd(dev);
+	if (ret)
+		goto interconnect_exit;
+
 	device_init_wakeup(&pdev->dev, 1);
 	qcom->is_suspended = false;
 	pm_runtime_set_active(dev);
@@ -878,6 +964,7 @@ static int dwc3_qcom_remove(struct platform_device *pdev)
 	}
 	qcom->num_clocks = 0;
 
+	dwc3_qcom_detach_pd(dev);
 	dwc3_qcom_interconnect_exit(qcom);
 	reset_control_assert(qcom->resets);
 
-- 
2.7.4


  parent reply	other threads:[~2021-10-25  9:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25  9:07 [PATCH v2 0/3] USB DWC3 QCOM Multi power domain support Sandeep Maheswaram
2021-10-25  9:07 ` [PATCH v2 1/3] dt-bindings: usb: qcom,dwc3: Add multi-pd bindings for dwc3 qcom Sandeep Maheswaram
2021-10-25 18:16   ` Rob Herring
2021-10-25 19:10   ` Bjorn Andersson
2021-10-25 20:17     ` Stephen Boyd
2021-10-25 21:43       ` Bjorn Andersson
2021-10-25 22:41         ` Stephen Boyd
2021-10-26  2:48           ` Bjorn Andersson
2021-10-27  0:48             ` Stephen Boyd
2021-10-27  4:55               ` Bjorn Andersson
2021-10-27 14:24                 ` Ulf Hansson
2021-10-27 15:11                   ` Bjorn Andersson
2021-10-28 10:31                     ` Ulf Hansson
2021-10-28 16:42                       ` Bjorn Andersson
2021-10-28  3:56                   ` Rajendra Nayak
2021-10-28 10:35                     ` Ulf Hansson
2021-10-28 10:46                       ` Rajendra Nayak
2021-10-28 16:53                         ` Bjorn Andersson
2021-10-28 20:04                           ` Stephen Boyd
2021-10-29  0:21                             ` Bjorn Andersson
2021-10-29  9:48                               ` Rajendra Nayak
2022-01-17  6:03                     ` Sandeep Maheswaram
2022-01-19 11:01                       ` Rajendra Nayak
2022-01-31  5:04                         ` Sandeep Maheswaram
2022-02-04  9:09                           ` Rajendra Nayak
2021-10-25  9:07 ` Sandeep Maheswaram [this message]
2021-10-25  9:07 ` [PATCH v2 3/3] arm64: dts: qcom: sc7280: Add cx power domain support Sandeep Maheswaram
2021-10-25 22:25   ` Stephen Boyd

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=1635152851-23660-3-git-send-email-quic_c_sanm@quicinc.com \
    --to=quic_c_sanm@quicinc.com \
    --cc=agross@kernel.org \
    --cc=balbi@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_ppratap@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=swboyd@chromium.org \
    /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 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.