public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: chunfeng.yun@mediatek.com (Chunfeng Yun)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/7] usb: xhci-mtk: use APIs of mtu_wakeup to support remote wakeup
Date: Sat, 9 Dec 2017 16:45:32 +0800	[thread overview]
Message-ID: <1512809136-2779-4-git-send-email-chunfeng.yun@mediatek.com> (raw)
In-Reply-To: <1512809136-2779-1-git-send-email-chunfeng.yun@mediatek.com>

On some platforms, there are two xHCI IPs, but the old way of
usb wakeup doesn't support it, so use the new APIs of mtu_wakeup
to support it.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
 drivers/usb/host/xhci-mtk.c | 39 +++++++++++++++++++++++----------------
 drivers/usb/host/xhci-mtk.h |  2 ++
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index b62a1d2..3176a10 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -19,6 +19,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/soc/mediatek/usb-wakeup.h>
 
 #include "xhci.h"
 #include "xhci-mtk.h"
@@ -366,7 +367,9 @@ static void usb_wakeup_line_state_dis(struct xhci_hcd_mtk *mtk)
 
 static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 {
-	if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+	if (mtk->wakeup)
+		mtu_wakeup_enable(mtk->uwk);
+	else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
 		usb_wakeup_ip_sleep_en(mtk);
 	else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
 		usb_wakeup_line_state_en(mtk);
@@ -374,7 +377,9 @@ static void usb_wakeup_enable(struct xhci_hcd_mtk *mtk)
 
 static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 {
-	if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
+	if (mtk->wakeup)
+		mtu_wakeup_disable(mtk->uwk);
+	else if (mtk->wakeup_src == SSUSB_WK_IP_SLEEP)
 		usb_wakeup_ip_sleep_dis(mtk);
 	else if (mtk->wakeup_src == SSUSB_WK_LINE_STATE)
 		usb_wakeup_line_state_dis(mtk);
@@ -383,24 +388,26 @@ static void usb_wakeup_disable(struct xhci_hcd_mtk *mtk)
 static int usb_wakeup_of_property_parse(struct xhci_hcd_mtk *mtk,
 				struct device_node *dn)
 {
-	struct device *dev = mtk->dev;
+	/* try the new way first */
+	mtk->wakeup = of_property_read_bool(dn, "wakeup-source");
+	if (mtk->wakeup) {
+		mtk->uwk = devm_of_uwk_get_by_index(mtk->dev, dn, 0);
+		if (IS_ERR(mtk->uwk))
+			dev_err(mtk->dev, "fail to get uwk\n");
+
+		return PTR_ERR_OR_ZERO(mtk->uwk);
+	}
 
-	/*
-	* wakeup function is optional, so it is not an error if this property
-	* does not exist, and in such case, no need to get relative
-	* properties anymore.
-	*/
+	/* wakeup function is optional (deprecated, use the new way instead) */
 	of_property_read_u32(dn, "mediatek,wakeup-src", &mtk->wakeup_src);
-	if (!mtk->wakeup_src)
-		return 0;
-
-	mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
+	if (mtk->wakeup_src) {
+		mtk->pericfg = syscon_regmap_lookup_by_phandle(dn,
 						"mediatek,syscon-wakeup");
-	if (IS_ERR(mtk->pericfg)) {
-		dev_err(dev, "fail to get pericfg regs\n");
-		return PTR_ERR(mtk->pericfg);
+		if (IS_ERR(mtk->pericfg)) {
+			dev_err(mtk->dev, "fail to get pericfg regs\n");
+			return PTR_ERR(mtk->pericfg);
+		}
 	}
-
 	return 0;
 }
 
diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
index 6b74ce5..95bd6ca 100644
--- a/drivers/usb/host/xhci-mtk.h
+++ b/drivers/usb/host/xhci-mtk.h
@@ -124,6 +124,8 @@ struct xhci_hcd_mtk {
 	int num_phys;
 	int wakeup_src;
 	bool lpm_support;
+	struct mtu_wakeup *uwk;
+	bool wakeup;
 };
 
 static inline struct xhci_hcd_mtk *hcd_to_mtk(struct usb_hcd *hcd)
-- 
1.9.1

  parent reply	other threads:[~2017-12-09  8:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09  8:45 [PATCH 0/7] Add USB remote wakeup driver Chunfeng Yun
2017-12-09  8:45 ` [PATCH 1/7] soc: mediatek: Add USB " Chunfeng Yun
2017-12-15 20:55   ` Rob Herring
2017-12-21  6:50     ` Chunfeng Yun
2017-12-09  8:45 ` [PATCH 2/7] dt-bindings: soc: mediatek: add bindings document for USB wakeup Chunfeng Yun
2017-12-09  8:45 ` Chunfeng Yun [this message]
2017-12-09  8:45 ` [PATCH 4/7] usb: mtu3: use APIs of mtu_wakeup to support remote wakeup Chunfeng Yun
2017-12-09  8:45 ` [PATCH 5/7] dt-bindings: usb: mtk-xhci: add USB wakeup properties Chunfeng Yun
2017-12-09  8:45 ` [PATCH 6/7] dt-bindings: usb: mtu3: " Chunfeng Yun
2017-12-09  8:45 ` [PATCH 7/7] arm64: dts: mt8173: add uwk node and remove unused usb property Chunfeng Yun
2017-12-15 20:55 ` [PATCH 0/7] Add USB remote wakeup driver Rob Herring
2017-12-21  6:48   ` Chunfeng Yun

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=1512809136-2779-4-git-send-email-chunfeng.yun@mediatek.com \
    --to=chunfeng.yun@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox