lkml.org 
[lkml]   [2018]   [Apr]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] usb: musb: Support gadget mode when the port is set to dual role
From
Date
Hi,

Le mardi 03 avril 2018 à 11:29 +0200, Maxime Ripard a écrit :
> Hi,
>
> 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.
> > > >
> > > > 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 <contact@paulk.fr>
> > >
> > > 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.
> >
> > 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.
> >
> > 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?
> >
> > Then, it seems that the offending commit is: be9d39881fc4f
> > ("usb: musb: host: rely on port_mode to call musb_start()")
> >
> > That itself fixed: ae44df2e21b5
> > ("usb: musb: call musb_start() only once in OTG mode")
> >
> > 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...
>
> 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.
>
> 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!

--
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/[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2018-04-21 12:58    [W:0.089 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site