Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5100399imu; Tue, 8 Jan 2019 11:30:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN651yalP/Ix+g46AG+Ek/UQYY23X2CdfPkAmusKV6cPjHuc4yh7pSIiRgagqibEzJGI6MOk X-Received: by 2002:a62:7042:: with SMTP id l63mr3108258pfc.89.1546975812241; Tue, 08 Jan 2019 11:30:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546975812; cv=none; d=google.com; s=arc-20160816; b=RFSfkBpUdTZeRDzKtm5V/B5vxZPneezv2b/DiNDz9zk/W3DTLWZRwWzjdp6sTFhGFS Vr87D7c1dSFQOFUU+s0aq8GI0WMwTFpCDOdq1wrXimb4RZ7YIro1KDoeP5BVr/Wq2d5R gcHqnTSO1P7j//2x8/6ZLB+Jil1NjNFJ1zqWYD/txWFDTw1/8REykwYxefJORps/PuIB I/t8sExoKo/2xWrxMfSsbNAcfRtT3YNgqIemrD/1T09irVsx/xWcdrfNztU144BYwgsD q8pAQNF+Op1XLI7N0eT8BBjht0PhGx9YOSmAyPGSO23tRhD+shLKgbSbyNP2Ug9K4xsc yu5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7Mre0/i0p0IwaFuQPt4qzYQj2u9ID2g2llJVAMr5GLQ=; b=or5/MCmx0008Po1PBmE82cCeX8a0ZCvx5+FCvvmYcFCZRRkkv9Yh+i+UF4M82KQjqU hkPGgTesVzG/TBkdx6NDlY2/RiVEWSIw/4s5usxPgVMIQmPVmCot+ZvBfNvYkYQjA9Kk sRoeyC8eVYQuqCpiLe7bRO8414HcnInwfECCDeoZIhbE17R71vGn6wKowGe/Zqlt4mDD vwa9qsI/G+btecqtllpUh+71p9KY7NxQAiUij8jEE1nvw/WlMAcGKr0RpQn5hyqVq8ta siEy/l2cJ56ZPxDAhGXv+wzfIEUrTxQCYof90AtSw2h/9jSp6Fdbojm6hcgmUpI2+L1W GsrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VxVnB2bJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si67783184pfe.203.2019.01.08.11.29.57; Tue, 08 Jan 2019 11:30:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VxVnB2bJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729714AbfAHT1c (ORCPT + 99 others); Tue, 8 Jan 2019 14:27:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:33646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbfAHT10 (ORCPT ); Tue, 8 Jan 2019 14:27:26 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07FD020883; Tue, 8 Jan 2019 19:27:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975645; bh=vViSs6Xpq7LPIGKTAhZ6Hhj484SUf+9UMhIaTpU090E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VxVnB2bJbcs7uAGbXv5SjWlEMkXh9YuMGuGVqr5kLIsRKjFLWCiPfC3lV57GRr2IB S7j2NPhY+DLc7ycDxzzNjLqsJjodF6bSqgF2NEJs1suWrvgBxbI7YOR8SEWMOMQvPT gaQtrfcTKaIgrfb0Nq94c1pGto8vT6EE5FdODxUA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yoshihiro Shimoda , Felipe Balbi , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 030/117] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device Date: Tue, 8 Jan 2019 14:24:58 -0500 Message-Id: <20190108192628.121270-30-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yoshihiro Shimoda [ Upstream commit ceb94bc52c437463f0903e61060a94a2226fb672 ] This patch adds a safety connection way for "forced_b_device" with "workaround_for_vbus" like below: < Example for R-Car E3 Ebisu > # modprobe # 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 Signed-off-by: Yoshihiro Shimoda Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- 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 cdffbd1e0316..6e34f9594159 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.19.1