Received: by 10.192.165.148 with SMTP id m20csp1223375imm; Sat, 21 Apr 2018 04:05:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+PnSd7IRExEvmFZ187Zy6gYI32lqSFboGX+ryZ1LzTgGQJyGgmSIV4IgwJm0B2nOqmmYx+ X-Received: by 10.99.97.16 with SMTP id v16mr10968778pgb.292.1524308700470; Sat, 21 Apr 2018 04:05:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524308700; cv=none; d=google.com; s=arc-20160816; b=EOEPGGmeyFkPwyN+gSzxYRhDDfsQ1rs/SwQD28PzA04MCzgqNNoVIlY0kLqgLO94V7 Fk8pTFpfCBiBBljvqRSqDGQYFEixQVQX19a//TBKcgUYwiS+RkKMMp30ldYIh35w2Wk+ rfW2CxrAXjq5lX2Qc/jg3Rn25Ys5JHYQygNh2wW34e1S4FLp4kvs/YKOGM6HXQS3ES+8 eLd+qGpnpK5XMEjHwnptMiK7L2FryPekoUB7+4+Qc6Lg6VDbA68XFnfrDbKuh/1ykRP9 3muyxwiz5ywc6RscCkJsQPICRqsBHiL26yn3SGr+u78FXj16WFiQWp/1tgheN8rrkt+h c+Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to:date :cc:to:from:subject:message-id:arc-authentication-results; bh=9FzMcUoJhXR+U/LbRvhGk++/8fT0HVqZHZkQJoF2czk=; b=yUzJr9TVsPd6hHx4syZpiWBQ1yixNGCxGI3zXYdvIB5ijKPseYX5yNkZ6lGZatDKMa vW54NR4RWZG2LA360IiH+TQ7sEviT+zA50wPSH28n+95YFhdj4/ghkdbtn3XOrS5mPNa BZWXwsKgsgbVQKHFdF6XdZldZUrdhFpuIAHISAVuV6a2T1feDkNLEBhKP/LO7e5xx9oZ YcIfmHzROBGoqPrClhhOCHa/i+slWMnasXfnOoc052S64xlsSO7p4r1BASnP94Pk/8hV Iq6jAqqcH41UwVFgbt5X2HmDrpDko79rgl4SxZMt1XvqYoGMywMo6Vj7ZrpLWqEvKqLt 5YzA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m6si6278675pgc.234.2018.04.21.04.04.23; Sat, 21 Apr 2018 04:05:00 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752778AbeDUK7b (ORCPT + 99 others); Sat, 21 Apr 2018 06:59:31 -0400 Received: from vpn-0-22.aquilenet.fr ([185.233.101.22]:59130 "EHLO leonov.paulk.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752738AbeDUK73 (ORCPT ); Sat, 21 Apr 2018 06:59:29 -0400 Received: from gagarine.paulk.fr (gagarine [192.168.1.127]) by leonov.paulk.fr (Postfix) with ESMTPS id 0A277C0701; Sat, 21 Apr 2018 12:59:28 +0200 (CEST) Received: by gagarine.paulk.fr (Postfix, from userid 114) id 5CA22C0CB1; Sat, 21 Apr 2018 12:59:27 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on gagarine.paulk.fr X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT autolearn=disabled version=3.4.1 Received: from collins (unknown [192.168.1.1]) by gagarine.paulk.fr (Postfix) with ESMTPSA id F363BC0C38; Sat, 21 Apr 2018 12:59:23 +0200 (CEST) Message-ID: <2db056d6f65ecbcdc4f31a37fe2e1b1ddfb93c87.camel@paulk.fr> Subject: Re: [PATCH] usb: musb: Support gadget mode when the port is set to dual role From: Paul Kocialkowski To: Bin Liu , Paul Kocialkowski Cc: Maxime Ripard , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Greg Kroah-Hartman , Chen-Yu Tsai Date: Sat, 21 Apr 2018 12:59:23 +0200 In-Reply-To: <20180420142524.GB29011@uda0271908> References: <20180328215213.29538-1-contact@paulk.fr> <20180329092326.dayuccomq5zrywqo@flea> <1522324644.1746.19.camel@bootlin.com> <20180420142524.GB29011@uda0271908> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-8DiKZ71yBmb+gr2Xl35R" X-Mailer: Evolution 3.28.1 Mime-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-8DiKZ71yBmb+gr2Xl35R Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Le vendredi 20 avril 2018 =C3=A0 09:25 -0500, Bin Liu a =C3=A9crit : > On Thu, Mar 29, 2018 at 01:57:24PM +0200, Paul Kocialkowski wrote: > > Hi, > >=20 > > 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. > > > >=20 > > > > 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. > > > >=20 > > > > This fixes USB OTG on Allwinner devices that I could test it > > > > with, > > > > mainly A20 devices. > > > >=20 > > > > Signed-off-by: Paul Kocialkowski > > >=20 > > > 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. > > >=20 > > > Is this a regression since a particular commit? Or is there > > > another, > > > deeper issue overlooked in the commit log? > >=20 > > 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. > >=20 > > Currently I see two places where musb_start is called: > > * musb_virthub > > * musb_gadget > >=20 > > 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. >=20 > 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 >=20 > 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? > > feature, only that it fails to enable musb without this patch. > >=20 > > First, I'd like to make sure that this understanding of the flow is > > correct as I may have missed something here. Does it make sense? >=20 > I am guessing you didn't load a gadget driver when testing? Correct. > > Then, it seems that the offending commit is: be9d39881fc4f > > ("usb: musb: host: rely on port_mode to call musb_start()") > >=20 > > That itself fixed: ae44df2e21b5 > > ("usb: musb: call musb_start() only once in OTG mode") > >=20 > > Still, this commit was authored in June 2015, so almost 3 years ago. > > In the meantime, the sunxi driver has received feature improvements, > > so > > it seems hard to believe that it was broken all this time... > >=20 > > Cheers, >=20 > Regards, > -Bin. Cheers, --=20 Paul Kocialkowski, developer of free digital technology and hardware support. Website: https://www.paulk.fr/ Coding blog: https://code.paulk.fr/ Git repositories: https://git.paulk.fr/ https://git.code.paulk.fr/ --=-8DiKZ71yBmb+gr2Xl35R Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEAbcMXZQMtj1fphLChP3B6o/ulQwFAlrbGYsACgkQhP3B6o/u lQxbbQ/5AYON/svk2ym7lwLpAUn6EVpIRT+ZG7JxLKvCD4BfdQAiRNYaYnVKcxPQ NuF3jYP8gACdtOnZrskMmSS+Zw0tlW/w1fWSrEONypy1ZryZSPrPugDqk0O6YKjr /1Q/tdCO4uK+10Zv771JLHAXD+rC38bHzjVMm7d4yheb+jY4WMVwoEhJP/oKw34W 9iWX9KEg7SdnevJynwe/QGNnj4kRstsROvrs1CugdBiX33kG8vOXRvDVpuuODDSD 6tImTk60kX9OU2G1G6ILdPnOYrf+qd7jfqbebpI+HkKuFA5S+xDUMK2PEeag6Ajn czi97IhijombUZLsK4IRw9WLAcZ8vaf61BcDyS3wzPuFJMKAJ7yt1PzqndNqwbUA LFnsOdWIfyuNQSQk0YAHrGTd7pt5wauzqV6iHXZvoNvBPCS7/PthgrKcKYsFvUsw wIIHVfXPP4o1dguRgR01q3cjauY9N9poRrI82b0UjsUN2BFoSLsiBmqFfEZLXUh+ IIf0BjVntb/PVBkd44qOqFVcYR2+MC1Mk96seeiViKiNmAVfrRHLR0O3GBiLL4IT sOyOAFdIWPKjLgial/qTNqwNaGkgIffBep9xf5fZ7l5Lug7pN/T09yqfxaCTBXH6 17OMeoKHgsJiD5UWUOT/YipgLiRyJqFB63bJOmV5MyUSdKr7nc0= =2jtG -----END PGP SIGNATURE----- --=-8DiKZ71yBmb+gr2Xl35R--