Received: by 10.192.165.148 with SMTP id m20csp1401424imm; Sat, 21 Apr 2018 07:38:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49qBUDg8sHlB4XrPyKig2SnvOhdqqGRnitXR6FJx/okYmDogZ6V+yVNxdIxv2g7vGIeEHBB X-Received: by 10.98.113.196 with SMTP id m187mr10225663pfc.216.1524321491728; Sat, 21 Apr 2018 07:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524321491; cv=none; d=google.com; s=arc-20160816; b=k1eJobZHbdjRU3GErOAFvcluKz2T3TGm/GeFHEA25bT02sISafG6sp+Lal1n/tcli3 BHdMDNuQeTuBiG2SNS3vNd6d9EBusp2w5RsrKFFMlH5lXzwu8DtDGWcVr2pRmEItxspv HVhmEmZPIYJoHYUA61B/nGZhUjjSfbaFt1przEbmI1SgoFqeRWNyAHrL84FRExkBEjFg iFlKoHcU8ACjCWQ3yRquqJxxX0y23eQ3lNtD7AnHXK/JzRNccGjZIbyuUNvodsS4Ang9 90eo3WP/UJh4qtzir/u3tWEaOhetnd4lRBdoK342mLKhveaM1LY4gVjWmYnkUv+8ZCXp xo2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=Rq8Co3F0+Xsjo1ssJRDHqyKMQemj+w1Y6Dd4u9N+wBo=; b=taBL5Em8poBS+2pMwD6t0gAuGdk1XaVXc0QP11zTaNCUMmorb7ZlefB1+F9iaqueUO lLuML7MccOVlBQ4kctUSfoZXihJ0Rh3vFOETWxrXl4hn/eHvHShF2FIpoRiOdusEs34a a1GeBdzwuOMydlDrNrQh0TcwZlLVFAVwugneuG7JnASU3Ug1/KLfnjCkpDykN/wqKAbe svioUwq3a7p+PRyqxVrZdptD53tZIwTlzsv3iJOLb42nSSPwDhA0Z3EDUJAeS8lLdiI/ qKCtW1XNRDmtHKpoXp705cTNNfNsXtqrqz8iVF7dqvip8eHb8E8uwWNwgjRC1y3XPSZn a42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=wfW1kFlK; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc11-v6si7502296plb.43.2018.04.21.07.37.34; Sat, 21 Apr 2018 07:38:11 -0700 (PDT) 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=@ti.com header.s=ti-com-17Q1 header.b=wfW1kFlK; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752892AbeDUOep (ORCPT + 99 others); Sat, 21 Apr 2018 10:34:45 -0400 Received: from fllnx209.ext.ti.com ([198.47.19.16]:51404 "EHLO fllnx209.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752762AbeDUOen (ORCPT ); Sat, 21 Apr 2018 10:34:43 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w3LEYR5H006756; Sat, 21 Apr 2018 09:34:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com; s=ti-com-17Q1; t=1524321267; bh=4ef32eIQfxLD+iUFF7RfwwrAUtGXZSnAXsDZG9dllVk=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=wfW1kFlKv4IXwt6e95RwzCp5hm0Fl0LKnt6b1o32lJWKoPgAEWcFkP2ogr2OH4O9G 4qN2CTAjDBn02TR06MyhoG0MiU3bXBMxUF4Fw2sV6DbIPFsoEtaunMlYhnpB6Y1Ite aHjK/dA88PhmR2vQkbIuaofgbMQSDmtQlV88Kuec= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3LEYRu5005984; Sat, 21 Apr 2018 09:34:27 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Sat, 21 Apr 2018 09:34:27 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Sat, 21 Apr 2018 09:34:27 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w3LEYQbW019061; Sat, 21 Apr 2018 09:34:27 -0500 Date: Sat, 21 Apr 2018 09:34:26 -0500 From: Bin Liu To: Paul Kocialkowski CC: Paul Kocialkowski , Maxime Ripard , , , Greg Kroah-Hartman , Chen-Yu Tsai Subject: Re: [PATCH] usb: musb: Support gadget mode when the port is set to dual role Message-ID: <20180421143426.GA10632@LTA0271908.dhcp.ti.com> Mail-Followup-To: Bin Liu , Paul Kocialkowski , Paul Kocialkowski , Maxime Ripard , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Greg Kroah-Hartman , Chen-Yu Tsai References: <20180328215213.29538-1-contact@paulk.fr> <20180329092326.dayuccomq5zrywqo@flea> <1522324644.1746.19.camel@bootlin.com> <20180420142524.GB29011@uda0271908> <2db056d6f65ecbcdc4f31a37fe2e1b1ddfb93c87.camel@paulk.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2db056d6f65ecbcdc4f31a37fe2e1b1ddfb93c87.camel@paulk.fr> User-Agent: Mutt/1.5.21 (2010-09-15) X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 21, 2018 at 12:59:23PM +0200, Paul Kocialkowski wrote: > Hi, > > Le vendredi 20 avril 2018 ? 09:25 -0500, Bin Liu a ?crit : > > On Thu, Mar 29, 2018 at 01:57:24PM +0200, Paul Kocialkowski wrote: > > > Hi, > > > > > > On Thu, 2018-03-29 at 11:23 +0200, Maxime Ripard wrote: > > > > On Wed, Mar 28, 2018 at 11:52:13PM +0200, Paul Kocialkowski wrote: > > > > > This allows dual-role ports to be reported as having gadget mode > > > > > by > > > > > the > > > > > musb_has_gadget helper. This is required to enable MUSB at all > > > > > with > > > > > MUSB > > > > > glue layers that set the port mode to MUSB_PORT_MODE_DUAL_ROLE > > > > > at > > > > > init. > > > > > > > > > > Most notably, this allows calling musb_start when needed in the > > > > > virtual > > > > > MUSB root HUB, regardless of whether the current mode should be > > > > > gadget > > > > > or host. > > > > > > > > > > This fixes USB OTG on Allwinner devices that I could test it > > > > > with, > > > > > mainly A20 devices. > > > > > > > > > > Signed-off-by: Paul Kocialkowski > > > > > > > > Surely there's more to it than that. The gadget mode of A20 boards > > > > have been working in the past, including when compiling with mUSB > > > > setup as dual role. > > > > > > > > Is this a regression since a particular commit? Or is there > > > > another, > > > > deeper issue overlooked in the commit log? > > > > > > The root of the issue here is that musb_start is not called at any > > > point > > > without this patch. My understanding of the flow is the following: > > > when > > > the PHY detects that there was a VBUS/ID change, it will notify its > > > listeners (mainly the musb sunxi glue layer). This will then > > > schedule > > > the driver's work (sunxi_musb_work), which does nothing since the > > > SUNXI_MUSB_FL_ENABLED bit was never set. This bit is only set after > > > calling sunxi_musb_enable, which is called from > > > musb_platform_enable, > > > that originates from musb_start. > > > > > > Currently I see two places where musb_start is called: > > > * musb_virthub > > > * musb_gadget > > > > > > In the latter case, it is in turn called from udc_start, which > > > should > > > probably (correct me if I'm wrong) happen later in the call chain > > > than > > > ID/VBUS change notification time. > > > > I don't think it is correct that udc_start() is triggered by ID/VBUS > > events, but I don't have an Allwinner platform to verify the callflow. > > Yes you're right, I didn't make myself very clear here. I didn't > investigate the udc_start call path much since it was apparently not the > culprit. > > > Have you tried to load with a gadget driver? When a gadget function is > > bound to UDC, udc_start() is triggered, which in turn calls > > musb_start(). > > It does work under that scenario, although my used case here is using > musb with DUAL_ROLE but no gadget driver loaded. That it, I want the > musb_start call to originate from the virtual hub, not from the gadget > side. > > > > In the former case, musb_start is called in the root controller hub > > > control, when setting the USB_PORT_FEAT_POWER feature. This looks > > > perfectly legit and IMO this is where it should be initially calling > > > musb_start in the dual role case. The kernel is indeed setting the > > > > No actually. A dual-role port should be in b_idle state by default, so > > logically all actions should go to the gadget path until the port > > switches to host mode. > > It makes sense that the port should be in b_idle state by default, but > here it fails to switch to host mode when the ID pin detects that it > should. Or does b_idle state entail that a gadget must be loaded (per > the USB spec), and thus nothing should (ever) happen until that happens? > > I find it really odd to need a gadget device to trigger host mode. > This patch does fix the issue, but I am puzzled as to why it is needed > in the first place. The comment above it mentions that "In OTG mode we > have to wait until we loaded a gadget. We don't really need a gadget if > we operate as a host but we should not start a session as a device > without a gadget or else we explode.", which is apparently compatible > with my use case: a gadget is not really needed and I'm not trying to > start a session as a device without a gadget loaded. > > What do you think? Okay, this came down to an argument that whether we should require loading a gadget driver on a dual-role port to work in host mode, which is currently required on musb since a long long time ago. I understand the requirement is kinda unnecessary, but since it already exists on musb stack for a long time, I don't plan to change it. Because I cannot think of a use case in real products that doesn't automatically load a gadget function on the dual-role port. If you can explain a use case in real world (not a engineering lab) that the gadget driver will not be loaded at linux booting up, but later based on user's input, I will reconsider my decision. To remove this requirement from musb stack, the work is more than this patch. Regards, -Bin.