Received: by 10.192.165.148 with SMTP id m20csp1221507imm; Sat, 21 Apr 2018 04:02:49 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+zj3wPxCFK8mEnix5hvlTFXrwZD3aJyaF0NMuB8QdK2y0URDE1R6Ee2RtOT3RnmdTRGCon X-Received: by 10.98.211.82 with SMTP id q79mr12831565pfg.45.1524308569699; Sat, 21 Apr 2018 04:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524308569; cv=none; d=google.com; s=arc-20160816; b=T6gMM1Yd/x8KK0KyRVncAJJFqbdYTlPIsQspf4KMHKOeMn2MyGMy1mxVksiCozt1qt YgoeZ7JcGkzmiv18P/dm4tIOezkmurnM2IOIcTNHXonXA6JXIf7VtQ62nxdcMHC4KR7/ 9P0jZgOqkiL8y2qOcmv4dxhQZnjtP55dOoTPaTMRZplh1zu+FyBYoZC+LBFCLYAscJ4E hikEH+bw07Wr5c+5fiJDhQDSH/kZs2TnBxTLL8cArETZt3cLWeUDkokBy1l8qoxVHVx+ 3coTwd5dCj1dy85dGAIx+mvgSoovWtCYP1Ri5nLS2Pn7ZCX1sFRSdoiuFD/BzEIULlIU At1Q== 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=upBGXSZb+zpWFziRffwyP9+S8YGpkrpv1g3qIaoPx5g=; b=SRhUorWNMq7s9sCOgLfRgjVYib7bNiD9hjIMVKx+F5fKl3894axr/RIpi2B0xbTopv e07kXSlJQcXVeVg4ovM3jTFmhLl1Aa4mBC75ZfxK6VQCf0fy8c1rOso3SFy+1GSoplhs F+hhQ+nReg8bbFOFjYQ3ryMakJfca5EdeBE2Oak9S67V9Kgpo4a2ut8oavSu8HK8FnBE xElf2DQuKl5Km6wSSeOWOQNCTvKDWoyraJeQyvIIaUnT8Hik+aLO6yYRq+sN7UvmtQIX +y5qq6FSx5gOvZx0Mai/vs0ppy4YvCk4wzytcxipV0np8CtUDSSg4K7kEGUgUPxdllBV Bp9Q== 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 f12si6278565pgo.64.2018.04.21.04.02.01; Sat, 21 Apr 2018 04:02:49 -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 S1752633AbeDUK6f (ORCPT + 99 others); Sat, 21 Apr 2018 06:58:35 -0400 Received: from vpn-0-22.aquilenet.fr ([185.233.101.22]:59084 "EHLO leonov.paulk.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751436AbeDUK6d (ORCPT ); Sat, 21 Apr 2018 06:58:33 -0400 X-Greylist: delayed 423 seconds by postgrey-1.27 at vger.kernel.org; Sat, 21 Apr 2018 06:58:32 EDT Received: from gagarine.paulk.fr (gagarine [192.168.1.127]) by leonov.paulk.fr (Postfix) with ESMTPS id 4A7C9C070A; Sat, 21 Apr 2018 12:51:28 +0200 (CEST) Received: by gagarine.paulk.fr (Postfix, from userid 114) id 6CEE8C0CB7; Sat, 21 Apr 2018 12:51: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 49EB1C07CD; Sat, 21 Apr 2018 12:51:22 +0200 (CEST) Message-ID: <6fb699194c10db9ff1e9b730435a785b71032840.camel@paulk.fr> Subject: Re: [PATCH] usb: musb: Support gadget mode when the port is set to dual role From: Paul Kocialkowski To: Maxime Ripard , Paul Kocialkowski Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Greg Kroah-Hartman , Bin Liu , Chen-Yu Tsai Date: Sat, 21 Apr 2018 12:51:20 +0200 In-Reply-To: <20180403092910.wcgjn3r4job5y5pb@flea> References: <20180328215213.29538-1-contact@paulk.fr> <20180329092326.dayuccomq5zrywqo@flea> <1522324644.1746.19.camel@bootlin.com> <20180403092910.wcgjn3r4job5y5pb@flea> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-KB68J9My6tN8mRSJFXHf" 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 --=-KB68J9My6tN8mRSJFXHf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Le mardi 03 avril 2018 =C3=A0 11:29 +0200, Maxime Ripard a =C3=A9crit : > Hi, >=20 > On Thu, Mar 29, 2018 at 01:57:24PM +0200, Paul Kocialkowski wrote: > > 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 > > 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 > > 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 > > 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 > I'm not that knowlegdeable about the musb driver, so I can't really > comment on whether what you're saying actually makes sense, but from > what you seem to say, the issue is just happening upon VBUS / ID > notification. >=20 > Have you tested without the role switching? For example, trying to > boot while acting as a gadget? In the end, the issue here was that I did not have a gadget (e.g. g_ether) driver loaded, and this prevented host mode form working (according to my initial explanation). With a gadget loaded, things work normally. Still, I don't think this is the right behavior here: one should definitely be able to use USB OTG in host mode without any gadget loaded. My initial patch fixes this, but I am not confident that it doesn't break other platforms, for which this assumption was added in the first place. 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/ --=-KB68J9My6tN8mRSJFXHf 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/ulQwFAlrbF6gACgkQhP3B6o/u lQyQvw//RbV4GzB2flSTEwVJ3hIKBAgp7MN5mE9fPx4qMAoC/13SZJmaPPmurmxV PCXVVQcLg5pV7knLkUeurj0cBWMNACPppp5YEBxZGm0OgnNf/nvhqkmOW3gcJGxz oOiu+7J2KGX7ZQZ6CUIQWNLjOqC0Sn7pQPnxBX3Hv4eRqLiz236+znahpGWyA+sC xf80kJtFEjd8on5fwB+X5AurU9THlLQFIpPu+uAvPDKlwj/LaUKB7ZrdZM0nOFnh 3qOzmicGGUPzXmGq7espHtbA7h9urqbpBandchBKsuPWt3PewsWzmydOhlr5t2N+ vsAjQ25brQQvn2Pm2jYAMDw/7r8+UJL90h/ugbx2UVY3K51HUaQfLzJ4PQ3txXMH ADHZ4LUZFwDcXEMVMFmh2T6CuhkIusCuNdAAgrXPYeF2N7cGBog7mxfYbjY04p1G xZu0S7VSsLjXsR2wHuSR76p2Z0m2qr+1d8yE66b33XwSLYIHujehrH5EwF2nMKGe Yu5MhJHihmKGRnAk2BAeuxiKEeKjEsIbDz49pZSLBABaj/Ts7+7igF1XJl48ay5H vADrfKG8v+FCeYk9wtXBD+pzE7qbIJ7z7bas0huHuSuV9f9jZqcC97wRmcHr5Kr4 /5MyGRNSN1dGC6FKcWrxmPWqu/fAoY/REBTP/c2LU0GbmjPhwqg= =29pS -----END PGP SIGNATURE----- --=-KB68J9My6tN8mRSJFXHf--