All of lore.kernel.org
 help / color / mirror / Atom feed
From: "周琰杰 (Zhou Yanjie)" <zhouyanjie@wanyeetech.com>
To: hminas@synopsys.com, gregkh@linuxfoundation.org, paul@crapouillou.net
Cc: linux-mips@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, dongsheng.qiu@ingenic.com,
	aric.pzqi@ingenic.com, sernia.zhou@foxmail.com,
	"Dragan Čečavac" <dragancecavac@yahoo.com>
Subject: [PATCH] USB: DWC2: Add VBUS overcurrent detection control.
Date: Tue, 23 Mar 2021 23:24:26 +0800	[thread overview]
Message-ID: <1616513066-62025-1-git-send-email-zhouyanjie@wanyeetech.com> (raw)

Introduce configurable option for enabling GOTGCTL register
bits VbvalidOvEn and VbvalidOvVal. Once selected it disables
VBUS overcurrent detection.

This patch is derived from Dragan Čečavac (in the kernel 3.18
tree of CI20). It is very useful for the MIPS Creator CI20(r1).
Without this patch, CI20's OTG port has a great probability to
face overcurrent warning, which breaks the OTG functionality.

Signed-off-by: 周琰杰 (Zhou Yanjie) <zhouyanjie@wanyeetech.com>
Signed-off-by: Dragan Čečavac <dragancecavac@yahoo.com>
---
 drivers/usb/dwc2/Kconfig | 6 ++++++
 drivers/usb/dwc2/core.c  | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig
index c131719..e40d187 100644
--- a/drivers/usb/dwc2/Kconfig
+++ b/drivers/usb/dwc2/Kconfig
@@ -94,4 +94,10 @@ config USB_DWC2_DEBUG_PERIODIC
 	  non-periodic transfers, but of course the debug logs will be
 	  incomplete. Note that this also disables some debug messages
 	  for which the transfer type cannot be deduced.
+
+config USB_DWC2_DISABLE_VOD
+	bool "Disable VBUS overcurrent detection"
+	help
+	  Say Y here to switch off VBUS overcurrent detection. It enables USB
+	  functionality blocked by overcurrent detection.
 endif
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index fec17a2..c629dc97 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -1200,6 +1200,7 @@ static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
 int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
 {
 	u32 usbcfg;
+	u32 otgctl;
 	int retval = 0;
 
 	if ((hsotg->params.speed == DWC2_SPEED_PARAM_FULL ||
@@ -1231,6 +1232,14 @@ int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
 		dwc2_writel(hsotg, usbcfg, GUSBCFG);
 	}
 
+	if (IS_ENABLED(CONFIG_USB_DWC2_DISABLE_VOD)) {
+		if (dwc2_is_host_mode(hsotg)) {
+			otgctl = readl(hsotg->regs + GOTGCTL);
+			otgctl |= GOTGCTL_VBVALOEN | GOTGCTL_VBVALOVAL;
+			writel(otgctl, hsotg->regs + GOTGCTL);
+		}
+	}
+
 	return retval;
 }
 
-- 
2.7.4


             reply	other threads:[~2021-03-23 15:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 15:24 周琰杰 (Zhou Yanjie) [this message]
2021-03-23 15:31 ` [PATCH] USB: DWC2: Add VBUS overcurrent detection control Greg KH
2021-06-15  8:16   ` 周琰杰
2021-06-15  8:52     ` Paul Cercueil
2021-06-15  9:14       ` 周琰杰
2021-06-15  9:48       ` Greg KH
2021-06-15 10:06         ` Paul Cercueil
2021-06-15  9:46     ` Greg KH

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=1616513066-62025-1-git-send-email-zhouyanjie@wanyeetech.com \
    --to=zhouyanjie@wanyeetech.com \
    --cc=aric.pzqi@ingenic.com \
    --cc=dongsheng.qiu@ingenic.com \
    --cc=dragancecavac@yahoo.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hminas@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=sernia.zhou@foxmail.com \
    /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.