public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Chen <peter.chen@freescale.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Felipe Balbi <balbi@ti.com>, Greg KH <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	<r.baldyga@samsung.com>, <chanho61.park@samsung.com>
Subject: Re: Disable bus's drivers_autoprobe before rootfs has mounted
Date: Mon, 16 Jun 2014 09:36:39 +0800	[thread overview]
Message-ID: <20140616013637.GA6432@shlinux1.ap.freescale.net> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1406130944460.1059-100000@iolanthe.rowland.org>

On Fri, Jun 13, 2014 at 10:19:36AM -0400, Alan Stern wrote:
> On Fri, 13 Jun 2014, Peter Chen wrote:
> 
> > OK, we can keep our g_xxx gadget driver just support the basic feature. But
> > the bug that causes gadget driver load fail due to udc is probed deferral should
> > be fixed, do you think so, we can't wait until configfs has total been ready.
> 
> That problem has always existed.  There never has been a time when a
> gadget driver could be loaded before the UDC driver was ready.  Does it 
> really need to be fixed now?
> 

Yes, otherwise, the device which the udc is probed deferral and the
gadget driver is build-in will never work. If we skip fixing it, this
problem will exist for more than 2 years, it is too long.

I have a support request from android team that usb peripheral function
never works from 3.10.x kernel at one device, I think it is a common problem,
no only I meet it.

Below are links which this problem reports:

http://marc.info/?l=linux-usb&m=139380872501745&w=2
http://marc.info/?l=linux-usb&m=137706435611447&w=2

> If you do want to fix the problem, there's a much easier way than what
> you posted.  See below.
> 
Robert Baldyga posts the similar solution, but seems Felipe doesn't
agree it.
http://www.spinics.net/lists/linux-usb/msg102795.html

Then, you and Felipe has a discussion for this problem:
http://www.spinics.net/lists/linux-usb/msg106760.html

> 
> Index: usb-3.15/include/linux/usb/gadget.h
> ===================================================================
> --- usb-3.15.orig/include/linux/usb/gadget.h
> +++ usb-3.15/include/linux/usb/gadget.h
> @@ -821,6 +821,7 @@ static inline int usb_gadget_disconnect(
>   * @suspend: Invoked on USB suspend.  May be called in_interrupt.
>   * @resume: Invoked on USB resume.  May be called in_interrupt.
>   * @driver: Driver model state for this driver.
> + * @probe_list: List of drivers waiting to be probed.
>   *
>   * Devices are disabled till a gadget driver successfully bind()s, which
>   * means the driver will handle setup() requests needed to enumerate (and
> @@ -881,6 +882,7 @@ struct usb_gadget_driver {
>  
>  	/* FIXME support safe rmmod */
>  	struct device_driver	driver;
> +	struct list_head	probe_list;
>  };
>  
>  
> Index: usb-3.15/drivers/usb/gadget/udc-core.c
> ===================================================================
> --- usb-3.15.orig/drivers/usb/gadget/udc-core.c
> +++ usb-3.15/drivers/usb/gadget/udc-core.c
> @@ -47,8 +47,12 @@ struct usb_udc {
>  
>  static struct class *udc_class;
>  static LIST_HEAD(udc_list);
> +static LIST_HEAD(pending_drivers);
>  static DEFINE_MUTEX(udc_lock);
>  
> +static int udc_bind_to_driver(struct usb_udc *udc,
> +		struct usb_gadget_driver *driver);
> +
>  /* ------------------------------------------------------------------------- */
>  
>  #ifdef	CONFIG_HAS_DMA
> @@ -242,6 +246,15 @@ int usb_add_gadget_udc_release(struct de
>  
>  	usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
>  
> +	while (!list_empty(&pending_drivers)) {
> +		struct usb_gadget_driver *driver;
> +
> +		driver = list_first_entry(&pending_drivers,
> +				struct usb_gadget_driver, probe_list);
> +		if (udc_bind_to_driver(udc, driver) == 0)
> +			break;
> +	}
> +
>  	mutex_unlock(&udc_lock);
>  
>  	return 0;
> @@ -338,6 +351,7 @@ static int udc_bind_to_driver(struct usb
>  
>  	dev_dbg(&udc->dev, "registering UDC driver [%s]\n",
>  			driver->function);
> +	list_del_init(&driver->probe_list);
>  
>  	udc->driver = driver;
>  	udc->dev.driver = &driver->driver;
> @@ -400,6 +414,7 @@ int usb_gadget_probe_driver(struct usb_g
>  		return -EINVAL;
>  
>  	mutex_lock(&udc_lock);
> +	INIT_LIST_HEAD(&driver->probe_list);
>  	list_for_each_entry(udc, &udc_list, list) {
>  		/* For now we take the first one */
>  		if (!udc->driver)
> @@ -407,8 +422,9 @@ int usb_gadget_probe_driver(struct usb_g
>  	}
>  
>  	pr_debug("couldn't find an available UDC\n");
> +	list_add_tail(&driver->probe_list, &pending_drivers);
>  	mutex_unlock(&udc_lock);
> -	return -ENODEV;
> +	return 0;
>  found:
>  	ret = udc_bind_to_driver(udc, driver);
>  	mutex_unlock(&udc_lock);
> @@ -425,6 +441,7 @@ int usb_gadget_unregister_driver(struct
>  		return -EINVAL;
>  
>  	mutex_lock(&udc_lock);
> +	list_del(&driver->probe_list);
>  	list_for_each_entry(udc, &udc_list, list)
>  		if (udc->driver == driver) {
>  			usb_gadget_remove_driver(udc);
> 
> 

-- 

Best Regards,
Peter Chen

  reply	other threads:[~2014-06-16  3:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11  2:14 Disable bus's drivers_autoprobe before rootfs has mounted Peter Chen
2014-06-11  4:10 ` Greg KH
2014-06-11  3:23   ` Peter Chen
2014-06-11 19:10     ` Greg KH
2014-06-11 19:27       ` Alan Stern
2014-06-12  6:31         ` Peter Chen
2014-06-12 14:12           ` Alan Stern
2014-06-13 10:15             ` Peter Chen
2014-06-13 14:19               ` Alan Stern
2014-06-16  1:36                 ` Peter Chen [this message]
2014-06-16 15:00                   ` Alan Stern
2014-06-17  2:04                     ` Peter Chen
2014-06-11  4:35   ` Felipe Balbi
2014-06-11  3:29     ` Peter Chen
2014-06-11 19:36       ` Felipe Balbi
2014-06-12  7:02         ` Peter Chen
2014-06-12 16:53           ` Felipe Balbi
2014-06-13  7:30             ` 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=20140616013637.GA6432@shlinux1.ap.freescale.net \
    --to=peter.chen@freescale.com \
    --cc=balbi@ti.com \
    --cc=chanho61.park@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=r.baldyga@samsung.com \
    --cc=stern@rowland.harvard.edu \
    /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