All of lore.kernel.org
 help / color / mirror / Atom feed
From: fabrizio.castro@bp.renesas.com (Fabrizio Castro)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 4.19.y 13/17] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device
Date: Wed, 24 Apr 2019 18:20:36 +0100	[thread overview]
Message-ID: <1556126440-27978-14-git-send-email-fabrizio.castro@bp.renesas.com> (raw)
In-Reply-To: <1556126440-27978-1-git-send-email-fabrizio.castro@bp.renesas.com>

From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>

commit ceb94bc52c437463f0903e61060a94a2226fb672 upstream.

This patch adds a safety connection way for "forced_b_device" with
"workaround_for_vbus" like below:

< Example for R-Car E3 Ebisu >
 # modprobe <any usb gadget driver>
 # echo 1 > /sys/kernel/debug/ee020000.usb/b_device
 (connect a usb cable to host side.)
 # echo 2 > /sys/kernel/debug/ee020000.usb/b_device

Previous code should have connected a usb cable before the "b_device"
is set to 1 on the Ebisu board. However, if xHCI driver on the board
is probed, it causes some troubles:
 - Conflicts USB VBUS/signals between the board and another host.
 - "Cannot enable. Maybe the USB cable is bad?" might happen on
   both the board and another host with a usb hub.
 - Cannot enumerate a usb gadget correctly because an interruption
   of VBUS change happens unexpectedly.

Reported-by: Kazuya Mizuguchi <kazuya.mizuguchi.ks@renesas.com>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
 drivers/usb/gadget/udc/renesas_usb3.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index cdffbd1..6e34f95 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -358,6 +358,7 @@ struct renesas_usb3 {
 	bool extcon_host;		/* check id and set EXTCON_USB_HOST */
 	bool extcon_usb;		/* check vbus and set EXTCON_USB */
 	bool forced_b_device;
+	bool start_to_connect;
 };
 
 #define gadget_to_renesas_usb3(_gadget)	\
@@ -476,7 +477,8 @@ static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
 static void usb3_init_epc_registers(struct renesas_usb3 *usb3)
 {
 	usb3_write(usb3, ~0, USB3_USB_INT_STA_1);
-	usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG);
+	if (!usb3->workaround_for_vbus)
+		usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG);
 }
 
 static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3)
@@ -700,8 +702,7 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev)
 	usb3_set_mode_by_role_sw(usb3, host);
 	usb3_vbus_out(usb3, a_dev);
 	/* for A-Peripheral or forced B-device mode */
-	if ((!host && a_dev) ||
-	    (usb3->workaround_for_vbus && usb3->forced_b_device))
+	if ((!host && a_dev) || usb3->start_to_connect)
 		usb3_connect(usb3);
 	spin_unlock_irqrestore(&usb3->lock, flags);
 }
@@ -2432,7 +2433,11 @@ static ssize_t renesas_usb3_b_device_write(struct file *file,
 	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
 		return -EFAULT;
 
-	if (!strncmp(buf, "1", 1))
+	usb3->start_to_connect = false;
+	if (usb3->workaround_for_vbus && usb3->forced_b_device &&
+	    !strncmp(buf, "2", 1))
+		usb3->start_to_connect = true;
+	else if (!strncmp(buf, "1", 1))
 		usb3->forced_b_device = true;
 	else
 		usb3->forced_b_device = false;
@@ -2440,7 +2445,7 @@ static ssize_t renesas_usb3_b_device_write(struct file *file,
 	if (usb3->workaround_for_vbus)
 		usb3_disconnect(usb3);
 
-	/* Let this driver call usb3_connect() anyway */
+	/* Let this driver call usb3_connect() if needed */
 	usb3_check_id(usb3);
 
 	return count;
-- 
2.7.4

  parent reply	other threads:[~2019-04-24 17:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 17:20 [cip-dev] [PATCH 4.19.y 00/17] Backport USB support for RZ/G2E Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 01/17] dt-bindings: rcar-gen3-phy-usb2: Add r8a774a1 support Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 02/17] dt-bindings: rcar-gen3-phy-usb2: Add r8a774c0 support Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 03/17] arm64: dts: renesas: r8a774c0: Add USB2.0 phy and host device nodes Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 04/17] usb: renesas_usbhs: add support for RZ/G2E Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 05/17] usb: renesas_usbhs: Add reset_control Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 06/17] usb: renesas_usbhs: Add multiple clocks management Fabrizio Castro
2019-04-25  8:26   ` Pavel Machek
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 07/17] Revert "usb: renesas_usbhs: add extcon notifier to set mode for non-otg channel" Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 08/17] dt-bindings: usb: renesas_usbhs: add clock-names property Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 09/17] dt-bindings: usb: renesas_usbhs: Add r8a774c0 support Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 10/17] dt-bindings: dmaengine: usb-dmac: Add binding for r8a774c0 Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 11/17] arm64: dts: renesas: r8a774c0: Add USB-DMAC and HSUSB device nodes Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 12/17] usb: gadget: udc: renesas_usb3: add support for r8a77990 Fabrizio Castro
2019-04-24 17:20 ` Fabrizio Castro [this message]
2019-04-25  8:40   ` [cip-dev] [PATCH 4.19.y 13/17] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device Pavel Machek
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 14/17] usb: gadget: udc: renesas_usb3: add support for r8a774c0 Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 15/17] usb: gadget: udc: renesas_usb3: Add r8a774a1 support Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 16/17] usb: gadget: udc: renesas_usb3: Add bindings for r8a774c0 Fabrizio Castro
2019-04-24 17:20 ` [cip-dev] [PATCH 4.19.y 17/17] arm64: dts: renesas: r8a774c0: Add USB3.0 device nodes Fabrizio Castro
2019-04-25  0:54 ` [cip-dev] [PATCH 4.19.y 00/17] Backport USB support for RZ/G2E nobuhiro1.iwamatsu at toshiba.co.jp
2019-04-25  8:11   ` Pavel Machek
2019-04-25 10:00 ` Pavel Machek

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=1556126440-27978-14-git-send-email-fabrizio.castro@bp.renesas.com \
    --to=fabrizio.castro@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.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.