mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kever Yang <kever.yang@rock-chips.com>
To: heiko@sntech.de, robh+dt@kernel.org, pawel.moll@arm.com,
	mark.rutland@arm.com, ijc+devicetree@hellion.org.uk,
	galak@codeaurora.org, rdunlap@infradead.org,
	linux@arm.linux.org.uk, paulz@synopsys.com,
	gregkh@linuxfoundation.org, mporter@linaro.org, kishon@ti.com,
	balbi@ti.com
Cc: swarren@wwwdotorg.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-usb@vger.kernel.org,
	kever.yang@rock-chips.com, addy.ke@rock-chips.com,
	xjq@rock-chips.com, cf@rock-chips.com, lyz@rock-chips.com,
	wulf@rock-chips.com, dianders@chromium.org, olof@lixom.net,
	sonnyrao@chromium.org
Subject: [PATCH 4/4] usb: dwc2: add dr_mode support for dwc2
Date: Tue, 29 Jul 2014 18:35:29 -0700	[thread overview]
Message-ID: <1406684129-18352-1-git-send-email-kever.yang@rock-chips.com> (raw)
In-Reply-To: <1406683873-18194-1-git-send-email-kever.yang@rock-chips.com>

Some devices with A female host port and without use of usb_id pin
will need this for the otg controller works as device role
during firmware period and works as host role in rich os.

Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
---
 drivers/usb/dwc2/core.c     |   13 +++++++++++++
 drivers/usb/dwc2/core.h     |    2 ++
 drivers/usb/dwc2/platform.c |    4 ++++
 3 files changed, 19 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 27d2c9b..6688951 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -118,6 +118,7 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
 {
 	u32 greset;
 	int count = 0;
+	u32 gusbcfg;
 
 	dev_vdbg(hsotg->dev, "%s()\n", __func__);
 
@@ -148,6 +149,18 @@ static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
 		}
 	} while (greset & GRSTCTL_CSFTRST);
 
+	if (hsotg->dr_mode == USB_DR_MODE_HOST) {
+		gusbcfg = readl(hsotg->regs+GUSBCFG);
+		gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
+		gusbcfg |= GUSBCFG_FORCEHOSTMODE;
+		writel(gusbcfg, hsotg->regs+GUSBCFG);
+	} else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) {
+		gusbcfg = readl(hsotg->regs+GUSBCFG);
+		gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
+		gusbcfg |= GUSBCFG_FORCEDEVMODE;
+		writel(gusbcfg, hsotg->regs+GUSBCFG);
+	}
+
 	/*
 	 * NOTE: This long sleep is _very_ important, otherwise the core will
 	 * not stay in host mode after a connector ID change!
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 1efd10c..9fe960b 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -501,6 +501,7 @@ struct dwc2_hw_params {
  *                      a_peripheral and b_device=>b_host) this may not match
  *                      the core, but allows the software to determine
  *                      transitions
+ * @dr_mode:            requested mode of operation
  * @queuing_high_bandwidth: True if multiple packets of a high-bandwidth
  *                      transfer are in process of being queued
  * @srp_success:        Stores status of SRP request in the case of a FS PHY
@@ -592,6 +593,7 @@ struct dwc2_hsotg {
 	/** Params to actually use */
 	struct dwc2_core_params *core_params;
 	enum usb_otg_state op_state;
+	enum usb_dr_mode        dr_mode;
 
 	unsigned int queuing_high_bandwidth:1;
 	unsigned int srp_success:1;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index cc5983c..a2ac1ea 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -42,6 +42,8 @@
 #include <linux/of_device.h>
 #include <linux/platform_device.h>
 
+#include <linux/usb/of.h>
+
 #include "core.h"
 #include "hcd.h"
 
@@ -200,6 +202,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
 	dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
 		(unsigned long)res->start, hsotg->regs);
 
+	hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node);
+
 	retval = dwc2_hcd_init(hsotg, irq, params);
 	if (retval)
 		return retval;
-- 
1.7.9.5



  parent reply	other threads:[~2014-07-30  1:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <963258>
2014-07-30  1:31 ` [PATCH 0/4] usb: dwc2: add suport for Rockchip dwc2 controller Kever Yang
2014-07-30  1:31   ` [PATCH 1/4] Documentation: dt-bindings: add dt binding info for Rockchip dwc2 Kever Yang
2014-07-30 18:53     ` Paul Zimmerman
2014-07-30  1:34   ` [PATCH 2/4] ARM: dts: add rk3288 dwc2 controller support Kever Yang
2014-07-30 15:18     ` Sergei Shtylyov
2014-07-30 17:55       ` Sergei Shtylyov
2014-07-30  1:35   ` [PATCH 3/4] usb: dwc2: add compatible data for rockchip soc Kever Yang
2014-07-30 19:00     ` Paul Zimmerman
2014-07-30  1:35   ` Kever Yang [this message]
2014-07-30 19:05     ` [PATCH 4/4] usb: dwc2: add dr_mode support for dwc2 Paul Zimmerman
2014-07-31  0:29 ` [PATCH v2 0/2] Patches to add dr_mode " Kever Yang
2014-07-31  0:29   ` [PATCH v2 1/2] Documentation: dt-bindings: add dt binding info for dwc2 dr_mode Kever Yang
2014-07-31  4:00     ` Doug Anderson
2014-07-31  1:06   ` [PATCH v2 2/2] usb: dwc2: add dr_mode support for dwc2 Kever Yang
2014-07-31  7:07     ` Jingoo Han
2014-07-31 18:47     ` Paul Zimmerman

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=1406684129-18352-1-git-send-email-kever.yang@rock-chips.com \
    --to=kever.yang@rock-chips.com \
    --cc=addy.ke@rock-chips.com \
    --cc=balbi@ti.com \
    --cc=cf@rock-chips.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=galak@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=heiko@sntech.de \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=kishon@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=lyz@rock-chips.com \
    --cc=mark.rutland@arm.com \
    --cc=mporter@linaro.org \
    --cc=olof@lixom.net \
    --cc=paulz@synopsys.com \
    --cc=pawel.moll@arm.com \
    --cc=rdunlap@infradead.org \
    --cc=robh+dt@kernel.org \
    --cc=sonnyrao@chromium.org \
    --cc=swarren@wwwdotorg.org \
    --cc=wulf@rock-chips.com \
    --cc=xjq@rock-chips.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®