From: peter.chen@freescale.com (Peter Chen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 14/14] usb: udc-core: add judgement logic for usb_gadget_connect
Date: Fri, 15 Mar 2013 14:06:16 +0800 [thread overview]
Message-ID: <20130315060615.GB28361@nchen-desktop> (raw)
In-Reply-To: <20130314101904.GD32369@arwen.pp.htv.fi>
On Thu, Mar 14, 2013 at 12:19:04PM +0200, Felipe Balbi wrote:
> Hi,
>
> On Thu, Mar 14, 2013 at 05:24:39PM +0800, Peter Chen wrote:
> > > > @@ -278,7 +278,10 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
> > > > driver->unbind(gadget);
> > > > goto err1;
> > > > }
> > > > - usb_gadget_connect(gadget);
> > > > + if (!gadget->ops->vbus_session ||
> > > > + (gadget->ops->vbus_session
> > > > + && gadget->vbus_active))
> > > > + usb_gadget_connect(gadget);
> > > >
> > > > kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE);
> > > > return 0;
> > > > @@ -384,7 +387,10 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
> > > >
> > > > if (sysfs_streq(buf, "connect")) {
> > > > usb_gadget_udc_start(gadget, udc->driver);
> > > > - usb_gadget_connect(gadget);
> > > > + if (!gadget->ops->vbus_session ||
> > > > + (gadget->ops->vbus_session
> > > > + && gadget->vbus_active))
> > > > + usb_gadget_connect(gadget);
> > >
> > > this patch is incomplete. What happens if this test fails ? Who will
> > > connect pullup then ?
> >
> > gadget->ops->vbus_session will handle it when the vbus interrupt comes
>
> for your driver, what about all the others ?
All drivers have .vbus_session will try to pullup, but some still check
if .pullup (using .softconnect) is called beforehand, it is duplicated
with this patch. Sorry, my careless.
If you have a look with these drivers, even usb_gadget_connect is called
at udc_bind_to_driver, they will NOT pull up if vbus is not there.
The most strict condition is :
gadget_is_loaded && vbus_session_is_called && pullup_is_called
In fact, calling usb_gadget_connect(gadget) unconditionally at udc-core
may hang system if low power is enabled as udc will enter low
power mode after udc_start if no vbus is there.
> Also, we shouldn't allow
> this ping-pong between who handles pullup and who handles vbus_session.
>
> It should all be managed by udc-core with UDC drivers just providing
> enough hooks. If we allow the UDC driver to connect pullups when VBUS
> IRQ comes, we could fall into all sorts of traps:
>
> a) we could connect cable with no gadget driver loaded
In that case, the pullup will not be called, it will check if gadget module
is loaded.
> b) there will be code duplication among all UDC drivers to call
> usb_gadge_connect() from vbus_session
Yes
> c) we might screw up the usb_function_activate()/deactivate() counter
>
why?
> Need to be very careful with all these details, there are many, many
> users to udc-core with different requirements. So unless we can come up
> with a way which wouldn't cause code duplication or regressions, I don't
> think we can solve the real problem.
Yes, udc has vendor specific, no uniform spec like host.
>
> I guess the best solution to all problems is to start deferring
> pullup to when gadget driver says it's ok to connect them. It's far more
> likely that we will already have connection to a host and VBUS will be
> alive.
I still think (gadget_is_loaded && vbus_is_there) is enough.
>
> Also, I'm not sure what does this all mean for SRP. Should we connect
> pullup before or after SRP ?
I am not familiar with SRP, but I think vbus is pre-condition.
--
Best Regards,
Peter Chen
next prev parent reply other threads:[~2013-03-15 6:06 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-14 5:50 [PATCH 00/14] Add vbus status to udc-core Peter Chen
2013-03-14 5:50 ` [PATCH 01/14] usb: udc-core: introduce vbus_active for struct usb_gadget Peter Chen
2013-03-14 5:50 ` [PATCH 02/14] usb: chipidea: using common vbus_active Peter Chen
2013-03-14 5:50 ` [PATCH 03/14] usb: at91_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 04/14] usb: fsl_udc_core: " Peter Chen
2013-03-14 5:50 ` [PATCH 05/14] usb: lpc32xx_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 06/14] usb: mv_u3d_core: " Peter Chen
2013-03-14 5:50 ` [PATCH 07/14] usb: mv_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 08/14] usb: omap_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 09/14] usb: pch_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 10/14] usb: pxa25x_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 11/14] usb: pxa27x_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 12/14] usb: s3c2410_udc: " Peter Chen
2013-03-14 5:50 ` [PATCH 13/14] usb: udc-core: small cleanup for udc->gadget Peter Chen
2013-03-14 5:50 ` [PATCH 14/14] usb: udc-core: add judgement logic for usb_gadget_connect Peter Chen
2013-03-14 9:00 ` Felipe Balbi
2013-03-14 9:24 ` Peter Chen
2013-03-14 10:19 ` Felipe Balbi
2013-03-15 6:06 ` Peter Chen [this message]
2013-03-15 7:51 ` Felipe Balbi
2013-03-15 10:04 ` Peter Chen
2013-03-15 10:37 ` Felipe Balbi
2013-03-15 12:26 ` Peter Chen
2013-03-18 6:52 ` Peter Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130315060615.GB28361@nchen-desktop \
--to=peter.chen@freescale.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox