Re: [PATCH 2/2] gadget: Support for the usb charger framework

2015-08-06 Thread Peter Chen
On Thu, Aug 06, 2015 at 03:03:49PM +0800, Baolin Wang wrote:
> The usb charger framework is based on usb gadget, and each usb gadget
> can be one usb charger to set the current limitation.
> 
> This patch adds a notifier mechanism for usb charger to report to usb
> charger when the usb gadget state is changed.
> 
> Also we introduce a callback 'get_charger_type' which will implemented
> by user for usb gadget operations to get the usb charger type.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/usb/gadget/udc/udc-core.c |   41 
> +
>  include/linux/usb/gadget.h|   20 ++
>  2 files changed, 61 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/udc-core.c 
> b/drivers/usb/gadget/udc/udc-core.c
> index d69c355..d5368088 100644
> --- a/drivers/usb/gadget/udc/udc-core.c
> +++ b/drivers/usb/gadget/udc/udc-core.c
> @@ -28,6 +28,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  /**
>   * struct usb_udc - describes one usb device controller
> @@ -127,12 +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
>  }
>  EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
>  
> +int usb_gadget_register_notify(struct usb_gadget *gadget,
> +struct notifier_block *nb)
> +{
> + unsigned long flags;
> + int ret;
> +
> + spin_lock_irqsave(&gadget->lock, flags);

I find you use so many spin_lock_irqsave, any reasons for that?
Why mutex_lock can't be used?

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] gadget: Introduce the usb charger framework

2015-08-06 Thread Peter Chen
On Thu, Aug 06, 2015 at 03:03:48PM +0800, Baolin Wang wrote:
> This patch introduces the usb charger driver based on usb gadget that
> makes an enhancement to a power driver. It works well in practice but
> that requires a system with suitable hardware.
> 
> The basic conception of the usb charger is that, when one usb charger
> is added or removed by reporting from the usb gadget state change or
> the extcon device state change, the usb charger will report to power
> user to set the current limitation.
> 
> The usb charger will register notifiees on the usb gadget or the extcon
> device to get notified the usb charger state.
> 
> Power user will register a notifiee on the usb charger to get notified
> by status changes from the usb charger. It will report to power user
> to set the current limitation when detecting the usb charger is added
> or removed from extcon device state or usb gadget state.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/usb/gadget/charger.c|  547 
> +++
>  include/linux/usb/usb_charger.h |  101 
>  2 files changed, 648 insertions(+)
>  create mode 100644 drivers/usb/gadget/charger.c
>  create mode 100644 include/linux/usb/usb_charger.h
> 
> diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
> new file mode 100644
> index 000..3ca0180
> --- /dev/null
> +++ b/drivers/usb/gadget/charger.c
> @@ -0,0 +1,547 @@
> +/*
> + * usb charger.c -- USB charger driver
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DEFAULT_CUR_PROTECT  (50)
> +#define DEFAULT_SDP_CUR_LIMIT(500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_DCP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_CDP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_ACA_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +
> +static LIST_HEAD(usb_charger_list);
> +static DEFINE_MUTEX(usb_charger_list_lock);
> +
> +/*
> + * usb_charger_find_by_name - Get the usb charger device by name.
> + * @name - usb charger device name.
> + *
> + * notes: when this function walks the list and returns a charger
> + * it's dropped the lock which means that something else could come
> + * along and delete the charger before we dereference the pointer.
> + * It's very unlikely but it's a possibility so you should take care
> + * of it.
> + * Thus when you get the usb charger by name, you should call
> + * put_usb_charger() to derease the reference count of the usb charger.
> + *
> + * return the instance of usb charger device.
> + */
> +struct usb_charger *usb_charger_find_by_name(char *name)
> +{
> + struct usb_charger *uchger;
> +
> + if (!name)
> + return ERR_PTR(-EINVAL);
> +
> + mutex_lock(&usb_charger_list_lock);
> + list_for_each_entry(uchger, &usb_charger_list, entry) {
> + if (!strcmp(uchger->name, name)) {
> + get_usb_charger(uchger);
> + mutex_unlock(&usb_charger_list_lock);
> + return uchger;
> + }
> + }
> + mutex_unlock(&usb_charger_list_lock);
> +
> + return NULL;
> +}
> +
> +/*
> + * usb_charger_register_notify() - Register a notifiee to get notified by
> + *   any attach status changes from the usb charger type detection.
> + * @uchger - the usb charger device which is monitored.
> + * @nb - a notifier block to be registered.
> + */
> +void usb_charger_register_notify(struct usb_charger *uchger,
> +  struct notifier_block *nb)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&uchger->lock, flags);
> + raw_notifier_chain_register(&uchger->uchger_nh, nb);
> + spin_unlock_irqrestore(&uchger->lock, flags);
> +}
> +
> +/*
> + * usb_charger_unregister_notify() - Unregister a notifiee from the usb 
> charger.
> + * @uchger - the usb charger device which is monitored.
> + * @nb - a notifier block to be unregistered.
> + */
> +void usb_charger_unregister_notify(struct usb_charger *uchger,
> +struct notifier_block *nb)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&uchger->lock, flags);
> + raw_notifier_chain_unregister(&uchger->uchger_nh, nb);
> + spin_unlock_irqrestore(&uchger->lock, flags);
> +}
> +
> +/*
> + * usb_charger_register_extcon_notifier() - Register a notifiee of the usb
> + *   charger to get notified by any attach status changes from
> + *   the extcon device.
> + * @uchger - the usb charger device.
> + * @edev - the extcon device.
> + * @e

Re: [PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation

2015-08-06 Thread Peter Chen
On Thu, Aug 06, 2015 at 03:03:47PM +0800, Baolin Wang wrote:
> Currently the Linux kernel does not provide any standard integration of this
> feature that integrates the USB subsystem with the system power regulation
> provided by PMICs meaning that either vendors must add this in their kernels
> or USB gadget devices based on Linux (such as mobile phones) may not behave
> as they should.
> 
> Providing a standard framework for doing this in the kernel.

Baolin, thanks for introducing a framework for doing it, we do support
USB Charger for chipidea driver at internal tree, but it is specific 
for imx, and still have some problems to upstream due to need to
change some common code.

One suggestion, would you add your user next time? In that case, we can
know better for this framework.

> 
> Baolin Wang (2):
>   gadget: Introduce the usb charger framework
>   gadget: Support for the usb charger framework
> 
>  drivers/usb/gadget/charger.c  |  547 
> +
>  drivers/usb/gadget/udc/udc-core.c |   41 +++
>  include/linux/usb/gadget.h|   20 ++
>  include/linux/usb/usb_charger.h   |  101 +++
>  4 files changed, 709 insertions(+)
>  create mode 100644 drivers/usb/gadget/charger.c
>  create mode 100644 include/linux/usb/usb_charger.h
> 
> -- 
> 1.7.9.5
> 

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: chipidea: imx: properly check for usbmisc

2015-08-06 Thread Peter Chen
On Fri, Aug 07, 2015 at 10:11:47AM +0800, Peter Chen wrote:
> On Thu, Aug 06, 2015 at 03:09:54PM +0200, Tomeu Vizoso wrote:
> > If usbmisc hasn't probed yet, defer the probe.
> > 
> > It's not enough to check if the platform device for the OF node of the
> > usbmisc has been registered, but it also needs to have been probed
> > already before we can call imx_usbmisc_init().
> > 
> > This can happen if the order in which devices are probed change due to
> > async probing or on-demand probing of dependencies.
> > 
> > Signed-off-by: Tomeu Vizoso 
> > ---
> >  drivers/usb/chipidea/ci_hdrc_imx.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
> > b/drivers/usb/chipidea/ci_hdrc_imx.c
> > index 504554e41922..e3c61d5e9270 100644
> > --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> > +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> > @@ -104,7 +104,7 @@ static struct imx_usbmisc_data 
> > *usbmisc_get_init_data(struct device *dev)
> > misc_pdev = of_find_device_by_node(args.np);
> > of_node_put(args.np);
> >  
> > -   if (!misc_pdev)
> > +   if (!misc_pdev || !platform_get_drvdata(misc_pdev))
> > return ERR_PTR(-EPROBE_DEFER);
> 
> "||"? or "&&"? You want usbmisc has already been probed.

Oh, oops. The patch is right, I will queue it.

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] gadget: Introduce the usb charger framework

2015-08-06 Thread Baolin Wang
On 7 August 2015 at 00:39, Greg KH  wrote:
> On Thu, Aug 06, 2015 at 03:03:48PM +0800, Baolin Wang wrote:
>> This patch introduces the usb charger driver based on usb gadget that
>> makes an enhancement to a power driver. It works well in practice but
>> that requires a system with suitable hardware.
>>
>> The basic conception of the usb charger is that, when one usb charger
>> is added or removed by reporting from the usb gadget state change or
>> the extcon device state change, the usb charger will report to power
>> user to set the current limitation.
>>
>> The usb charger will register notifiees on the usb gadget or the extcon
>> device to get notified the usb charger state.
>>
>> Power user will register a notifiee on the usb charger to get notified
>> by status changes from the usb charger. It will report to power user
>> to set the current limitation when detecting the usb charger is added
>> or removed from extcon device state or usb gadget state.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>>  drivers/usb/gadget/charger.c|  547 
>> +++
>>  include/linux/usb/usb_charger.h |  101 
>>  2 files changed, 648 insertions(+)
>>  create mode 100644 drivers/usb/gadget/charger.c
>>  create mode 100644 include/linux/usb/usb_charger.h
>>
>> diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
>> new file mode 100644
>> index 000..3ca0180
>> --- /dev/null
>> +++ b/drivers/usb/gadget/charger.c
>> @@ -0,0 +1,547 @@
>> +/*
>> + * usb charger.c -- USB charger driver
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>
> I have to ask, do you really mean "any later version"?
>

I'll think about this and modify it.

>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define DEFAULT_CUR_PROTECT  (50)
>> +#define DEFAULT_SDP_CUR_LIMIT(500 - DEFAULT_CUR_PROTECT)
>> +#define DEFAULT_DCP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
>> +#define DEFAULT_CDP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
>> +#define DEFAULT_ACA_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
>> +
>> +static LIST_HEAD(usb_charger_list);
>> +static DEFINE_MUTEX(usb_charger_list_lock);
>> +
>> +/*
>> + * usb_charger_find_by_name - Get the usb charger device by name.
>> + * @name - usb charger device name.
>> + *
>> + * notes: when this function walks the list and returns a charger
>> + * it's dropped the lock which means that something else could come
>> + * along and delete the charger before we dereference the pointer.
>> + * It's very unlikely but it's a possibility so you should take care
>> + * of it.
>> + * Thus when you get the usb charger by name, you should call
>> + * put_usb_charger() to derease the reference count of the usb charger.
>> + *
>> + * return the instance of usb charger device.
>> + */
>> +struct usb_charger *usb_charger_find_by_name(char *name)
>> +{
>> + struct usb_charger *uchger;
>> +
>> + if (!name)
>> + return ERR_PTR(-EINVAL);
>> +
>> + mutex_lock(&usb_charger_list_lock);
>> + list_for_each_entry(uchger, &usb_charger_list, entry) {
>> + if (!strcmp(uchger->name, name)) {
>> + get_usb_charger(uchger);
>> + mutex_unlock(&usb_charger_list_lock);
>> + return uchger;
>> + }
>> + }
>> + mutex_unlock(&usb_charger_list_lock);
>> +
>> + return NULL;
>> +}
>> +
>> +/*
>> + * usb_charger_register_notify() - Register a notifiee to get notified by
>> + *   any attach status changes from the usb charger type detection.
>> + * @uchger - the usb charger device which is monitored.
>> + * @nb - a notifier block to be registered.
>> + */
>> +void usb_charger_register_notify(struct usb_charger *uchger,
>> +  struct notifier_block *nb)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&uchger->lock, flags);
>> + raw_notifier_chain_register(&uchger->uchger_nh, nb);
>> + spin_unlock_irqrestore(&uchger->lock, flags);
>> +}
>> +
>> +/*
>> + * usb_charger_unregister_notify() - Unregister a notifiee from the usb 
>> charger.
>> + * @uchger - the usb charger device which is monitored.
>> + * @nb - a notifier block to be unregistered.
>> + */
>> +void usb_charger_unregister_notify(struct usb_charger *uchger,
>> +struct notifier_block *nb)
>> +{
>> + unsigned long flags;
>> +
>> + spin_lock_irqsave(&uchger->lock, flags);
>> + raw_notifier_chain_unregister(&uchger->uchger_nh, nb);
>> + spin_unlock_irqrestore(&uchger->lock, flags);
>> +}
>> +
>>

Re: [PATCH] usb: chipidea: imx: properly check for usbmisc

2015-08-06 Thread Peter Chen
On Thu, Aug 06, 2015 at 03:09:54PM +0200, Tomeu Vizoso wrote:
> If usbmisc hasn't probed yet, defer the probe.
> 
> It's not enough to check if the platform device for the OF node of the
> usbmisc has been registered, but it also needs to have been probed
> already before we can call imx_usbmisc_init().
> 
> This can happen if the order in which devices are probed change due to
> async probing or on-demand probing of dependencies.
> 
> Signed-off-by: Tomeu Vizoso 
> ---
>  drivers/usb/chipidea/ci_hdrc_imx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
> b/drivers/usb/chipidea/ci_hdrc_imx.c
> index 504554e41922..e3c61d5e9270 100644
> --- a/drivers/usb/chipidea/ci_hdrc_imx.c
> +++ b/drivers/usb/chipidea/ci_hdrc_imx.c
> @@ -104,7 +104,7 @@ static struct imx_usbmisc_data 
> *usbmisc_get_init_data(struct device *dev)
>   misc_pdev = of_find_device_by_node(args.np);
>   of_node_put(args.np);
>  
> - if (!misc_pdev)
> + if (!misc_pdev || !platform_get_drvdata(misc_pdev))
>   return ERR_PTR(-EPROBE_DEFER);

"||"? or "&&"? You want usbmisc has already been probed.


>  
>   data->dev = &misc_pdev->dev;
> -- 
> 2.4.3
> 

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] gadget: Introduce the usb charger framework

2015-08-06 Thread Mark Brown
On Thu, Aug 06, 2015 at 09:39:05AM -0700, Greg KH wrote:
> On Thu, Aug 06, 2015 at 03:03:48PM +0800, Baolin Wang wrote:

> > +static void usb_charger_release(struct device *dev)
> > +{
> > +   struct usb_charger *uchger = dev_get_drvdata(dev);

> > +   if (!atomic_dec_and_test(&uchger->count)) {
> > +   dev_err(dev, "The usb charger is still in use\n");

> Why is the "count" different from the reference count?  You shouldn't be
> in this function if the reference count is not 0, so tie your "user"
> count to this one.  Having two different reference counts is a nightmare
> and almost impossible to get right.  And a huge red flag that the design
> is incorrect.

> > +   return;

> You can't "fail" a release call, so you just leaked memory all over the
> floor here :(

Indeed.  I did discuss this with Baolin off list but I'd missed the
dynamic allocation of devices for some reason.

> > +   mutex_lock(&usb_charger_list_lock);
> > +   list_for_each_entry(tmp, &usb_charger_list, entry) {
> > +   if (!(strcmp(tmp->name, uchger->name))) {
> > +   mutex_unlock(&usb_charger_list_lock);
> > +   ret = -EEXIST;
> > +   goto out;
> > +   }
> > +   }
> > +   list_add_tail(&uchger->entry, &usb_charger_list);

> Why do you need a separate list?  This subsystem's bus structure should
> own that list of devices, no need for a separate one (again, a huge red
> flag that the design is not correct.)

Right, if we dynamically allocate a device per charger then the lifetime
issues should go away and we get a list for free.


signature.asc
Description: Digital signature


[ANNOUNCE] tree closed for v4.3 merge window

2015-08-06 Thread Felipe Balbi
Hi folks,

if your patches aren't in my tree yet, it's too late, sorry.

We have a total of 145 non-merge commits, here's dirstat:

$ git diff --dirstat next ^cbfe8fa6cd67 | sort -rn
  21.0% drivers/usb/gadget/udc/
  19.9% drivers/usb/musb/
  12.9% drivers/usb/phy/
  11.7% drivers/usb/gadget/legacy/
   7.8% drivers/usb/gadget/
   6.1% drivers/usb/gadget/function/
   5.7% drivers/usb/dwc3/
   5.0% include/linux/usb/
   4.0% drivers/usb/
   3.1% Documentation/devicetree/bindings/usb/

My tree will soak a bit on linux-next to catch any further build
regressions (I couldn't find anything missing after the recent 4 patches
I sent) and next week a pull request will be sent to Greg.

Please, avoid sending patches until v4.3-rc1 is tagged as that goes a
long way towards keeping my sanity ;-)

cheers

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation

2015-08-06 Thread Greg KH
On Thu, Aug 06, 2015 at 11:21:22AM -0500, Felipe Balbi wrote:
> Hi,
> 
> On Thu, Aug 06, 2015 at 03:03:47PM +0800, Baolin Wang wrote:
> > Currently the Linux kernel does not provide any standard integration of this
> > feature that integrates the USB subsystem with the system power regulation
> > provided by PMICs meaning that either vendors must add this in their kernels
> > or USB gadget devices based on Linux (such as mobile phones) may not behave
> > as they should.
> > 
> > Providing a standard framework for doing this in the kernel.
> 
> it's too late in this cycle to even start discussing this. i'll drop
> from my queue, please resend rebase on v4.3-rc1 once that's out.

Why should that matter?  Can't they just rebase on linux-next and we can
work it out from there?  the merge cycle is just for us maintainers to
worry about, people can submit code whenever they want to, it's up to us
as to what tree we merge it to (now or next).

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] gadget: Introduce the usb charger framework

2015-08-06 Thread Greg KH
On Thu, Aug 06, 2015 at 03:03:48PM +0800, Baolin Wang wrote:
> This patch introduces the usb charger driver based on usb gadget that
> makes an enhancement to a power driver. It works well in practice but
> that requires a system with suitable hardware.
> 
> The basic conception of the usb charger is that, when one usb charger
> is added or removed by reporting from the usb gadget state change or
> the extcon device state change, the usb charger will report to power
> user to set the current limitation.
> 
> The usb charger will register notifiees on the usb gadget or the extcon
> device to get notified the usb charger state.
> 
> Power user will register a notifiee on the usb charger to get notified
> by status changes from the usb charger. It will report to power user
> to set the current limitation when detecting the usb charger is added
> or removed from extcon device state or usb gadget state.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/usb/gadget/charger.c|  547 
> +++
>  include/linux/usb/usb_charger.h |  101 
>  2 files changed, 648 insertions(+)
>  create mode 100644 drivers/usb/gadget/charger.c
>  create mode 100644 include/linux/usb/usb_charger.h
> 
> diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
> new file mode 100644
> index 000..3ca0180
> --- /dev/null
> +++ b/drivers/usb/gadget/charger.c
> @@ -0,0 +1,547 @@
> +/*
> + * usb charger.c -- USB charger driver
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.

I have to ask, do you really mean "any later version"?

> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DEFAULT_CUR_PROTECT  (50)
> +#define DEFAULT_SDP_CUR_LIMIT(500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_DCP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_CDP_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +#define DEFAULT_ACA_CUR_LIMIT(1500 - DEFAULT_CUR_PROTECT)
> +
> +static LIST_HEAD(usb_charger_list);
> +static DEFINE_MUTEX(usb_charger_list_lock);
> +
> +/*
> + * usb_charger_find_by_name - Get the usb charger device by name.
> + * @name - usb charger device name.
> + *
> + * notes: when this function walks the list and returns a charger
> + * it's dropped the lock which means that something else could come
> + * along and delete the charger before we dereference the pointer.
> + * It's very unlikely but it's a possibility so you should take care
> + * of it.
> + * Thus when you get the usb charger by name, you should call
> + * put_usb_charger() to derease the reference count of the usb charger.
> + *
> + * return the instance of usb charger device.
> + */
> +struct usb_charger *usb_charger_find_by_name(char *name)
> +{
> + struct usb_charger *uchger;
> +
> + if (!name)
> + return ERR_PTR(-EINVAL);
> +
> + mutex_lock(&usb_charger_list_lock);
> + list_for_each_entry(uchger, &usb_charger_list, entry) {
> + if (!strcmp(uchger->name, name)) {
> + get_usb_charger(uchger);
> + mutex_unlock(&usb_charger_list_lock);
> + return uchger;
> + }
> + }
> + mutex_unlock(&usb_charger_list_lock);
> +
> + return NULL;
> +}
> +
> +/*
> + * usb_charger_register_notify() - Register a notifiee to get notified by
> + *   any attach status changes from the usb charger type detection.
> + * @uchger - the usb charger device which is monitored.
> + * @nb - a notifier block to be registered.
> + */
> +void usb_charger_register_notify(struct usb_charger *uchger,
> +  struct notifier_block *nb)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&uchger->lock, flags);
> + raw_notifier_chain_register(&uchger->uchger_nh, nb);
> + spin_unlock_irqrestore(&uchger->lock, flags);
> +}
> +
> +/*
> + * usb_charger_unregister_notify() - Unregister a notifiee from the usb 
> charger.
> + * @uchger - the usb charger device which is monitored.
> + * @nb - a notifier block to be unregistered.
> + */
> +void usb_charger_unregister_notify(struct usb_charger *uchger,
> +struct notifier_block *nb)
> +{
> + unsigned long flags;
> +
> + spin_lock_irqsave(&uchger->lock, flags);
> + raw_notifier_chain_unregister(&uchger->uchger_nh, nb);
> + spin_unlock_irqrestore(&uchger->lock, flags);
> +}
> +
> +/*
> + * usb_charger_register_extcon_notifier() - Register a notifiee of the usb
> + *   charger to get notified by any attach status changes from
> + *   the extcon device.
> + * @uchger - the usb 

[PATCH 2/2] usb: gadget: legacy: nokia: add CONFIG_BLOCK dependency

2015-08-06 Thread Felipe Balbi
g_nokia now has mass_storage function, so it should
depend on CONFIG_BLOCK.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/legacy/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/legacy/Kconfig 
b/drivers/usb/gadget/legacy/Kconfig
index ddef41f6df3e..4d682ad7bf23 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -339,6 +339,7 @@ config USB_CDC_COMPOSITE
 config USB_G_NOKIA
tristate "Nokia composite gadget"
depends on PHONET
+   depends on BLOCK
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_U_ETHER
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] usb: gadget: f_mass_storage: add mising

2015-08-06 Thread Felipe Balbi
 was originally being pulled
indirectly through some other header, however
it's not anymore, so we need to include it
directly

Reported-by: Jim Davis 
Suggested-by: Alan Stern 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/f_mass_storage.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c 
b/drivers/usb/gadget/function/f_mass_storage.c
index 11a7f5aa955b..a6eb537d7768 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -214,6 +214,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/5] usb: xhci: Add support for URB_ZERO_PACKET to bulk/sg transfers

2015-08-06 Thread Mathias Nyman
From: Reyad Attiyat 

This commit checks for the URB_ZERO_PACKET flag and creates an extra
zero-length td if the urb transfer length is a multiple of the endpoint's
max packet length.

Signed-off-by: Reyad Attiyat 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-ring.c | 66 ++--
 drivers/usb/host/xhci.c  |  5 
 2 files changed, 57 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 94416ff..fb877d6 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3038,9 +3038,11 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
struct xhci_td *td;
struct scatterlist *sg;
int num_sgs;
-   int trb_buff_len, this_sg_len, running_total;
+   int trb_buff_len, this_sg_len, running_total, ret;
unsigned int total_packet_count;
+   bool zero_length_needed;
bool first_trb;
+   int last_trb_num;
u64 addr;
bool more_trbs_coming;
 
@@ -3056,13 +3058,27 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, 
gfp_t mem_flags,
total_packet_count = DIV_ROUND_UP(urb->transfer_buffer_length,
usb_endpoint_maxp(&urb->ep->desc));
 
-   trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
+   ret = prepare_transfer(xhci, xhci->devs[slot_id],
ep_index, urb->stream_id,
num_trbs, urb, 0, mem_flags);
-   if (trb_buff_len < 0)
-   return trb_buff_len;
+   if (ret < 0)
+   return ret;
 
urb_priv = urb->hcpriv;
+
+   /* Deal with URB_ZERO_PACKET - need one more td/trb */
+   zero_length_needed = urb->transfer_flags & URB_ZERO_PACKET &&
+   urb_priv->length == 2;
+   if (zero_length_needed) {
+   num_trbs++;
+   xhci_dbg(xhci, "Creating zero length td.\n");
+   ret = prepare_transfer(xhci, xhci->devs[slot_id],
+   ep_index, urb->stream_id,
+   1, urb, 1, mem_flags);
+   if (ret < 0)
+   return ret;
+   }
+
td = urb_priv->td[0];
 
/*
@@ -3092,6 +3108,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
trb_buff_len = urb->transfer_buffer_length;
 
first_trb = true;
+   last_trb_num = zero_length_needed ? 2 : 1;
/* Queue the first TRB, even if it's zero-length */
do {
u32 field = 0;
@@ -3109,12 +3126,15 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, 
gfp_t mem_flags,
/* Chain all the TRBs together; clear the chain bit in the last
 * TRB to indicate it's the last TRB in the chain.
 */
-   if (num_trbs > 1) {
+   if (num_trbs > last_trb_num) {
field |= TRB_CHAIN;
-   } else {
-   /* FIXME - add check for ZERO_PACKET flag before this */
+   } else if (num_trbs == last_trb_num) {
td->last_trb = ep_ring->enqueue;
field |= TRB_IOC;
+   } else if (zero_length_needed && num_trbs == 1) {
+   trb_buff_len = 0;
+   urb_priv->td[1]->last_trb = ep_ring->enqueue;
+   field |= TRB_IOC;
}
 
/* Only set interrupt on short packet for IN endpoints */
@@ -3176,7 +3196,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
if (running_total + trb_buff_len > urb->transfer_buffer_length)
trb_buff_len =
urb->transfer_buffer_length - running_total;
-   } while (running_total < urb->transfer_buffer_length);
+   } while (num_trbs > 0);
 
check_trb_math(urb, num_trbs, running_total);
giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
@@ -3194,7 +3214,9 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
int num_trbs;
struct xhci_generic_trb *start_trb;
bool first_trb;
+   int last_trb_num;
bool more_trbs_coming;
+   bool zero_length_needed;
int start_cycle;
u32 field, length_field;
 
@@ -3225,7 +3247,6 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
num_trbs++;
running_total += TRB_MAX_BUFF_SIZE;
}
-   /* FIXME: this doesn't deal with URB_ZERO_PACKET - need one more */
 
ret = prepare_transfer(xhci, xhci->devs[slot_id],
ep_index, urb->stream_id,
@@ -3234,6 +3255,20 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
return ret;
 
urb_priv = urb->hcpriv;
+
+   /* Deal with URB_ZERO_PACKET - need one more td/trb */
+   zero_length_needed = urb->tran

[PATCH 4/5] xhci: xHCI 1.1: Contiguous Frame ID Capability (CFC)

2015-08-06 Thread Mathias Nyman
From: Lu Baolu 

If the Contiguous Frame ID Capability is supported (CFC = 1),
then the xHC shall match the Frame ID in every Isoch TD with
SIA = 0 against the Frame Index of the MFINDEX register. This
rule ensures resynchronization of Isoch TDs even if some are
dropped due to Missed Service Errors or Stopping the endpoint.

This patch enables xHCI driver to support CFC by calculating
and setting the Frame ID field of an Isoch TRB.

[made some dbg messages checkpatch friendly -Mathias]
Signed-off-by: Lu Baolu 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-dbg.c  |   2 +
 drivers/usb/host/xhci-ring.c | 191 ---
 drivers/usb/host/xhci.h  |   7 ++
 3 files changed, 187 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 745717e..c867ecb 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -99,6 +99,8 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci)
xhci_dbg(xhci, "HCC PARAMS 0x%x:\n", (unsigned int) temp);
xhci_dbg(xhci, "  HC generates %s bit addresses\n",
HCC_64BIT_ADDR(temp) ? "64" : "32");
+   xhci_dbg(xhci, "  HC %s Contiguous Frame ID Capability\n",
+   HCC_CFC(temp) ? "has" : "hasn't");
/* FIXME */
xhci_dbg(xhci, "  FIXME: more HCCPARAMS debugging\n");
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index fb877d6..b54901f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3552,6 +3552,97 @@ static unsigned int 
xhci_get_last_burst_packet_count(struct xhci_hcd *xhci,
}
 }
 
+/*
+ * Calculates Frame ID field of the isochronous TRB identifies the
+ * target frame that the Interval associated with this Isochronous
+ * Transfer Descriptor will start on. Refer to 4.11.2.5 in 1.1 spec.
+ *
+ * Returns actual frame id on success, negative value on error.
+ */
+static int xhci_get_isoc_frame_id(struct xhci_hcd *xhci,
+   struct urb *urb, int index)
+{
+   int start_frame, ist, ret = 0;
+   int start_frame_id, end_frame_id, current_frame_id;
+
+   if (urb->dev->speed == USB_SPEED_LOW ||
+   urb->dev->speed == USB_SPEED_FULL)
+   start_frame = urb->start_frame + index * urb->interval;
+   else
+   start_frame = (urb->start_frame + index * urb->interval) >> 3;
+
+   /* Isochronous Scheduling Threshold (IST, bits 0~3 in HCSPARAMS2):
+*
+* If bit [3] of IST is cleared to '0', software can add a TRB no
+* later than IST[2:0] Microframes before that TRB is scheduled to
+* be executed.
+* If bit [3] of IST is set to '1', software can add a TRB no later
+* than IST[2:0] Frames before that TRB is scheduled to be executed.
+*/
+   ist = HCS_IST(xhci->hcs_params2) & 0x7;
+   if (HCS_IST(xhci->hcs_params2) & (1 << 3))
+   ist <<= 3;
+
+   /* Software shall not schedule an Isoch TD with a Frame ID value that
+* is less than the Start Frame ID or greater than the End Frame ID,
+* where:
+*
+* End Frame ID = (Current MFINDEX register value + 895 ms.) MOD 2048
+* Start Frame ID = (Current MFINDEX register value + IST + 1) MOD 2048
+*
+* Both the End Frame ID and Start Frame ID values are calculated
+* in microframes. When software determines the valid Frame ID value;
+* The End Frame ID value should be rounded down to the nearest Frame
+* boundary, and the Start Frame ID value should be rounded up to the
+* nearest Frame boundary.
+*/
+   current_frame_id = readl(&xhci->run_regs->microframe_index);
+   start_frame_id = roundup(current_frame_id + ist + 1, 8);
+   end_frame_id = rounddown(current_frame_id + 895 * 8, 8);
+
+   start_frame &= 0x7ff;
+   start_frame_id = (start_frame_id >> 3) & 0x7ff;
+   end_frame_id = (end_frame_id >> 3) & 0x7ff;
+
+   xhci_dbg(xhci, "%s: index %d, reg 0x%x start_frame_id 0x%x, 
end_frame_id 0x%x, start_frame 0x%x\n",
+__func__, index, readl(&xhci->run_regs->microframe_index),
+start_frame_id, end_frame_id, start_frame);
+
+   if (start_frame_id < end_frame_id) {
+   if (start_frame > end_frame_id ||
+   start_frame < start_frame_id)
+   ret = -EINVAL;
+   } else if (start_frame_id > end_frame_id) {
+   if ((start_frame > end_frame_id &&
+   start_frame < start_frame_id))
+   ret = -EINVAL;
+   } else {
+   ret = -EINVAL;
+   }
+
+   if (index == 0) {
+   if (ret == -EINVAL || start_frame == start_frame_id) {
+   start_frame = start_frame_id + 1;
+   if (urb->dev->speed == USB_SPEED_LOW ||
+

[PATCH 5/5] xhci: xHCI 1.1: Stopped - Short Packet Capability (SPC)

2015-08-06 Thread Mathias Nyman
From: Lu Baolu 

This patch enables xhci driver to support SPC by handling
Stopped - Short Packet event in transfer event path.

If SPC = '1' and the stop endpoint command is executed, after a Short
Packet condition has been detected, but before the end of the TD has been
reached, (i.e. the TD is in progress for pipe), then a Transfer Event TRB
with its Completion Code set to Stopped - Short Packet and its TRB
Transfer Length set to value of the EDTLA shall be forced for the
interrupted TRB, irrespective of whether its IOC or ISP flags are set.
This Transfer Event TRB will precede the Command Completion Event TRB for
the command, and is referred to as a Stopped Transfer Event.

Signed-off-by: Lu Baolu 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-dbg.c  |  2 ++
 drivers/usb/host/xhci-ring.c | 44 +---
 drivers/usb/host/xhci.h  |  6 --
 3 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index c867ecb..2d16fae 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -101,6 +101,8 @@ static void xhci_print_cap_regs(struct xhci_hcd *xhci)
HCC_64BIT_ADDR(temp) ? "64" : "32");
xhci_dbg(xhci, "  HC %s Contiguous Frame ID Capability\n",
HCC_CFC(temp) ? "has" : "hasn't");
+   xhci_dbg(xhci, "  HC %s generate Stopped - Short Package event\n",
+   HCC_SPC(temp) ? "can" : "can't");
/* FIXME */
xhci_dbg(xhci, "  FIXME: more HCCPARAMS debugging\n");
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index b54901f..9c9d629 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1809,7 +1809,9 @@ static int finish_td(struct xhci_hcd *xhci, struct 
xhci_td *td,
if (skip)
goto td_cleanup;
 
-   if (trb_comp_code == COMP_STOP_INVAL || trb_comp_code == COMP_STOP) {
+   if (trb_comp_code == COMP_STOP_INVAL ||
+   trb_comp_code == COMP_STOP ||
+   trb_comp_code == COMP_STOP_SHORT) {
/* The Endpoint Stop Command completion will take care of any
 * stopped TDs.  A stopped TD may be restarted, so don't update
 * the ring dequeue pointer or take this TD off any lists yet.
@@ -1916,8 +1918,22 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct 
xhci_td *td,
else
*status = 0;
break;
-   case COMP_STOP_INVAL:
+   case COMP_STOP_SHORT:
+   if (event_trb == ep_ring->dequeue || event_trb == td->last_trb)
+   xhci_warn(xhci, "WARN: Stopped Short Packet on ctrl 
setup or status TRB\n");
+   else
+   td->urb->actual_length =
+   EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
+
+   return finish_td(xhci, td, event_trb, event, ep, status, false);
case COMP_STOP:
+   /* Did we stop at data stage? */
+   if (event_trb != ep_ring->dequeue && event_trb != td->last_trb)
+   td->urb->actual_length =
+   td->urb->transfer_buffer_length -
+   EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
+   /* fall through */
+   case COMP_STOP_INVAL:
return finish_td(xhci, td, event_trb, event, ep, status, false);
default:
if (!xhci_requires_manual_halt_cleanup(xhci,
@@ -2011,6 +2027,8 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct 
xhci_td *td,
}
if ((xhci->quirks & XHCI_TRUST_TX_LENGTH))
trb_comp_code = COMP_SHORT_TX;
+   /* fallthrough */
+   case COMP_STOP_SHORT:
case COMP_SHORT_TX:
frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
-EREMOTEIO : 0;
@@ -2046,6 +2064,10 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct 
xhci_td *td,
if (trb_comp_code == COMP_SUCCESS || skip_td) {
frame->actual_length = frame->length;
td->urb->actual_length += frame->length;
+   } else if (trb_comp_code == COMP_STOP_SHORT) {
+   frame->actual_length =
+   EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));
+   td->urb->actual_length += frame->actual_length;
} else {
for (cur_trb = ep_ring->dequeue,
 cur_seg = ep_ring->deq_seg; cur_trb != event_trb;
@@ -2126,6 +2148,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, 
struct xhci_td *td,
*status = 0;
}
break;
+   case COMP_STOP_SHORT:
case COMP_SHORT_TX:
if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
 

Re: [PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation

2015-08-06 Thread Felipe Balbi
Hi,

On Thu, Aug 06, 2015 at 03:03:47PM +0800, Baolin Wang wrote:
> Currently the Linux kernel does not provide any standard integration of this
> feature that integrates the USB subsystem with the system power regulation
> provided by PMICs meaning that either vendors must add this in their kernels
> or USB gadget devices based on Linux (such as mobile phones) may not behave
> as they should.
> 
> Providing a standard framework for doing this in the kernel.

it's too late in this cycle to even start discussing this. i'll drop
from my queue, please resend rebase on v4.3-rc1 once that's out.

-- 
balbi


signature.asc
Description: Digital signature


[PATCH 3/5] usb: host: xhci: Simplify return statement

2015-08-06 Thread Mathias Nyman
From: Saurabh Karajgaonkar 

Replace redundant variable use in return statement.

Signed-off-by: Saurabh Karajgaonkar 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index cdf5dfb..0e32bfe 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4680,7 +4680,6 @@ int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
 {
struct xhci_hcd *xhci;
u16 mel;
-   int ret;
 
xhci = hcd_to_xhci(hcd);
if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) ||
@@ -4688,10 +4687,7 @@ int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
return 0;
 
mel = calculate_max_exit_latency(udev, state, USB3_LPM_DISABLED);
-   ret = xhci_change_max_exit_latency(xhci, udev, mel);
-   if (ret)
-   return ret;
-   return 0;
+   return xhci_change_max_exit_latency(xhci, udev, mel);
 }
 #else /* CONFIG_PM */
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] usb: xhci: make USB_XHCI_PLATFORM selectable

2015-08-06 Thread Mathias Nyman
From: Rafał Miłecki 

Right now xhci-plat-hcd can be built when using one of platform specific
drivers only (mvebu/rcar). There shouldn't be such limitation as some
platforms may not require any quirks and may want to just use a generic
driver ("generic-xhci" / "xhci-hcd").

Signed-off-by: Rafał Miłecki 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/Kconfig | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 8afc3c1..5f05679 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -32,7 +32,14 @@ config USB_XHCI_PCI
default y
 
 config USB_XHCI_PLATFORM
-   tristate
+   tristate "Generic xHCI driver for a platform device"
+   ---help---
+ Adds an xHCI host driver for a generic platform device, which
+ provides a memory space and an irq.
+ It is also a prerequisite for platform specific drivers that
+ implement some extra quirks.
+
+ If unsure, say N.
 
 config USB_XHCI_MVEBU
tristate "xHCI support for Marvell Armada 375/38x"
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/5] xhci features for usb-next

2015-08-06 Thread Mathias Nyman
Hi Greg

There xhci patches for usb-next include support for a couple new xhci 1.1
features, support for zero packet bulk transfers and some other minor
changes

-Mathias

Lu Baolu (2):
  xhci: xHCI 1.1: Contiguous Frame ID Capability (CFC)
  xhci: xHCI 1.1: Stopped - Short Packet Capability (SPC)

Rafał Miłecki (1):
  usb: xhci: make USB_XHCI_PLATFORM selectable

Reyad Attiyat (1):
  usb: xhci: Add support for URB_ZERO_PACKET to bulk/sg transfers

Saurabh Karajgaonkar (1):
  usb: host: xhci: Simplify return statement

 drivers/usb/host/Kconfig |   9 +-
 drivers/usb/host/xhci-dbg.c  |   4 +
 drivers/usb/host/xhci-ring.c | 301 ++-
 drivers/usb/host/xhci.c  |  11 +-
 drivers/usb/host/xhci.h  |  13 +-
 5 files changed, 300 insertions(+), 38 deletions(-)

-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: g_serial hangs on write when the cable is disconnected

2015-08-06 Thread Laszlo Papp
On Thu, Aug 6, 2015 at 4:16 PM, Peter Hurley  wrote:
> [ +cc Felipe ]
>
> Hi Laszlo,
>
> On 08/06/2015 10:03 AM, Laszlo Papp wrote:
>> On Thu, Aug 6, 2015 at 2:52 PM, Alan Stern  wrote:
>>> On Thu, 6 Aug 2015, Laszlo Papp wrote:
 On Wed, Aug 5, 2015 at 7:15 PM, Alan Stern  
 wrote:
> On Wed, 5 Aug 2015, Greg KH wrote:
>
>> hm, wait, is this really the n_gsm line discipline?  Or is it something
>> else?
>>
>> g_serial is the device side of a serial connection, there is no "cable
>> removed" notification that it even knows about, that has to come from
>> the gadget driver somehow, which you should listen for and then kick
>> your userspace program.
>
> There is the gserial_disconnect() callback, which gets invoked when the
> Vbus power (provided by the host) is removed.  It's a pretty good
> indicator that the USB cable has been unplugged.
>
> I don't understand all the stuff that gserial_disconnect() does, but it
> ought to be more or less equivalent to a "hangup" -- as the kerneldoc
> says.  If it doesn't do what users expect, there's probably a bug
> somewhere.
>
> Of course, it's possible that the callback does not get invoked in
> Laszlo's case.  Then the question would be: Why not?

 Hmm, that is a good question. I wonder if there had been any recent
 fixes for that lately... I suppose that I will need to skim through
 the git log. Thank you for the hints!
>>>
>>> You should also add a printk statement to the disconnect callback so
>>> that you can verify whether it really is getting called.
>>
>> Thanks. Should that also be called if I just boot up the board with
>> Linux on it while the cable is not attached. In other words, the
>> problem that I am also experiencing is that it blocks even when no
>> cable is attached to the board and there has been no cable ever
>> attached for the last boot.
>
> You have everyone hopelessly confused about what your problem actually is.
>
> Your $subject says that "g_serial hangs on write" and for a reproducer
> you provide:
>
> #include 
> #include 
> #include 
>
> int main()
> {
> const char buf[] = "Hello World!\n";
> int fd = open("/dev/ttyGS0", O_RDWR | O_NONBLOCK);
> int sent = write(fd, buf, sizeof(buf)-1);
> close(fd);
> return 0;
> }
>
> Only a careful reader would have caught this in your subsequent reply:
>
> On Wed, Aug 05, 2015 at 04:40:21PM +0100, Laszlo Papp wrote:
>> Wow, I managed to mess it up in my original email! So, this code above
>> made it working, but without O_NONBLOCK, it was not working. Using
>> O_NONBLOCK is my current nasty workaround.

Yes, of course. I made a mistake with that and I apologise.

> To answer your original question, yes, the write() is behaving as expected.
> If you open a tty without O_NONBLOCK, then both read() and write() to that
> tty will _block_ until the operation is successful or the tty is hung up.
>
> Your comparison with how ttyS* ports behave when a cable is not connected
> is based on incorrect assumptions. When a ttyS port is in CLOCAL mode
> (the default), the cable state is ignored when _opening_. On write(),
> without hardware flow control (CRTSCTS), the serial port is successfully
> writing the data out without knowing that nothing is listening.

Yes, you are right with that. There is no way to detect errors without
some handshaking on the serial port.

For now, O_NONBLOCK, it is, until I find a better example to work with.

> I don't see a bug here.

It is very likely just a missing example in the documentation. I do
not think that there is a bug in here.

> Regards,
> Peter Hurley
>
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] usb: musb: gadget: remove remaining DMA ifdeferry

2015-08-06 Thread Felipe Balbi
Commit fb91cddc54e7 ("usb: musb: Remove DMA
ifdef for musb_gadget.c short_packet") tried
to remove DMA ifdeferry from musb_gadget.c
but ended up leaving some around.

Remove them so that when building kernels with
all DMA engines enabled, we don't end up trying
to allocte channels twice.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/musb/musb_gadget.c | 39 ++-
 1 file changed, 18 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 5f52bcb4bf78..cc503591b634 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -313,8 +313,7 @@ static void txstate(struct musb *musb, struct musb_request 
*req)
 
/* MUSB_TXCSR_P_ISO is still set correctly */
 
-#if defined(CONFIG_USB_INVENTRA_DMA) || defined(CONFIG_USB_UX500_DMA)
-   {
+   if (musb_dma_inventra(musb) || musb_dma_ux500(musb)) {
if (request_size < musb_ep->packet_sz)
musb_ep->dma->desired_mode = 0;
else
@@ -365,7 +364,6 @@ static void txstate(struct musb *musb, struct musb_request 
*req)
}
}
 
-#endif
if (is_cppi_enabled(musb)) {
/* program endpoint CSR first, then setup DMA */
csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
@@ -641,8 +639,10 @@ static void rxstate(struct musb *musb, struct musb_request 
*req)
use_mode_1 = 0;
 
if (request->actual < request->length) {
-#ifdef CONFIG_USB_INVENTRA_DMA
-   if (is_buffer_mapped(req)) {
+   if (!is_buffer_mapped(req))
+   goto buffer_aint_mapped;
+
+   if (musb_dma_inventra(musb)) {
struct dma_controller   *c;
struct dma_channel  *channel;
int use_dma = 0;
@@ -716,8 +716,8 @@ static void rxstate(struct musb *musb, struct musb_request 
*req)
if (use_dma)
return;
}
-#elif defined(CONFIG_USB_UX500_DMA)
-   if ((is_buffer_mapped(req)) &&
+
+   if ((musb_dma_ux500(musb)) &&
(request->actual < request->length)) {
 
struct dma_controller *c;
@@ -765,7 +765,6 @@ static void rxstate(struct musb *musb, struct musb_request 
*req)
 
return;
}
-#endif /* Mentor's DMA */
 
len = request->length - request->actual;
dev_dbg(musb->controller, "%s OUT/RX pio fifo %d/%d, 
maxpacket %d\n",
@@ -775,8 +774,7 @@ static void rxstate(struct musb *musb, struct musb_request 
*req)
 
fifo_count = min_t(unsigned, len, fifo_count);
 
-#ifdef CONFIG_USB_TUSB_OMAP_DMA
-   if (tusb_dma_omap(musb) && is_buffer_mapped(req)) {
+   if (tusb_dma_omap(musb)) {
struct dma_controller *c = musb->dma_controller;
struct dma_channel *channel = musb_ep->dma;
u32 dma_addr = request->dma + request->actual;
@@ -790,23 +788,22 @@ static void rxstate(struct musb *musb, struct 
musb_request *req)
if (ret)
return;
}
-#endif
+
/*
 * Unmap the dma buffer back to cpu if dma channel
 * programming fails. This buffer is mapped if the
 * channel allocation is successful
 */
-if (is_buffer_mapped(req)) {
-   unmap_dma_buffer(req, musb);
-
-   /*
-* Clear DMAENAB and AUTOCLEAR for the
-* PIO mode transfer
-*/
-   csr &= ~(MUSB_RXCSR_DMAENAB | 
MUSB_RXCSR_AUTOCLEAR);
-   musb_writew(epio, MUSB_RXCSR, csr);
-   }
+   unmap_dma_buffer(req, musb);
+
+   /*
+* Clear DMAENAB and AUTOCLEAR for the
+* PIO mode transfer
+*/
+   csr &= ~(MUSB_RXCSR_DMAENAB | MUSB_RXCSR_AUTOCLEAR);
+   musb_writew(epio, MUSB_RXCSR, csr);
 
+buffer_aint_mapped:
musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *)
(request->buf + request->actual));
reques

[PATCH 2/2] usb: musb: cppi41: allow it to work again

2015-08-06 Thread Felipe Balbi
since commit 33c300cb90a6 ("usb: musb: dsps:
don't fake of_node to musb core") we have been
preventing CPPI 4.1 from probing due to NULL
of_node. We can't revert said commit otherwise
a different regression would show up, so the fix
is to look for the parent device's (glue layer's)
of_node instead, since that's the thing which
is actually described in DTS.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/musb/musb_cppi41.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/musb/musb_cppi41.c b/drivers/usb/musb/musb_cppi41.c
index 4d1b44c232ee..d07cafb7d5f5 100644
--- a/drivers/usb/musb/musb_cppi41.c
+++ b/drivers/usb/musb/musb_cppi41.c
@@ -614,7 +614,7 @@ static int cppi41_dma_controller_start(struct 
cppi41_dma_controller *controller)
 {
struct musb *musb = controller->musb;
struct device *dev = musb->controller;
-   struct device_node *np = dev->of_node;
+   struct device_node *np = dev->parent->of_node;
struct cppi41_dma_channel *cppi41_channel;
int count;
int i;
@@ -664,7 +664,7 @@ static int cppi41_dma_controller_start(struct 
cppi41_dma_controller *controller)
musb_dma->status = MUSB_DMA_STATUS_FREE;
musb_dma->max_len = SZ_4M;
 
-   dc = dma_request_slave_channel(dev, str);
+   dc = dma_request_slave_channel(dev->parent, str);
if (!dc) {
dev_err(dev, "Failed to request %s.\n", str);
ret = -EPROBE_DEFER;
@@ -695,7 +695,7 @@ cppi41_dma_controller_create(struct musb *musb, void 
__iomem *base)
struct cppi41_dma_controller *controller;
int ret = 0;
 
-   if (!musb->controller->of_node) {
+   if (!musb->controller->parent->of_node) {
dev_err(musb->controller, "Need DT for the DMA engine.\n");
return NULL;
}
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [linux-sunxi] [PATCH] musb: sunxi: Ignore VBus errors in host-only mode

2015-08-06 Thread Hans de Goede

Hi,

On 06-08-15 10:22, Olliver Schinagl wrote:

Hey Hans,

I've tried getting your musb stuff working on a cubietruck, but i don't seem to 
see this patch on your linux-sunxi/sunxi-wip branch on github? Is your github 
branch fully functional at the moment?

What I have done so far, is build the kernel using sunxi_defconfig and enabled USB_MUSB_SUNXI with its dependancies (musb isn't 
enabled there by default): USB_SUPPORT [=y] && USB_MUSB_HDRC [=y] && ARCH_SUNXI [=y] && NOP_USB_XCEIV 
[=y] && PHY_SUN4I_USB [=y] && EXTCON [=y] && GENERIC_PHY [=y]  Selects: SUNXI_SRAM [=y]

I changed the dts from dr_mode='otg' to dr_mode='host', a) we only need host 
mode anyway (the id pin isn't properly connected)


If you change the dr_mode to host then you _must_ also remove any id_det and 
vbus_det
gpio settings from the usb_phy node in the dts, as the sun4i phy code detects
host vs otg mode by checking for the presence of these.

> and b) I got an error about an known dr_mode before and this was the quick 
and easy way.


Dmesg produces the following related to musb.

[1.691062] usb_phy_generic.0.auto supply vcc not found, using dummy 
regulator
[1.691445] musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk combine, 
bulk split, HB-ISO Rx, HB-ISO Tx, SoftConn)
[1.691453] musb-hdrc: MHDRC RTL version 0.0
[1.691467] musb-hdrc: 11/11 max ep, 5184/8192 memory
[1.691543] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[1.691553] musb-hdrc musb-hdrc.1.auto: new USB bus registered, assigned bus 
number 5
[1.692470] hub 5-0:1.0: USB hub found
[1.692529] hub 5-0:1.0: 1 port detected
[1.699956] sunxi-rtc 1c20d00.rtc: setting system clock to 2015-08-06 
07:59:08 UTC (1438847948)
[1.704733] usb0-vbus: disabling
[1.765695] ldo4: disabling
[1.808351] ldo3: disabling
[1.848769] vcc5v0: disabling
[1.848774] vcc3v0: disabling

The usb_phy_generic missing shouldn't be too bad? But the usb0-vbus being 
disabled obviously might be related to the musb port not working?


Correct.

For starters I would try the dts changes I suggested above.

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: randconfig build error with next-20150806, in drivers/usb/gadget/function/f_mass_storage.c

2015-08-06 Thread Alan Stern
On Thu, 6 Aug 2015, Jim Davis wrote:

> Building with the attached random configuration file,
> 
> drivers/usb/gadget/function/f_mass_storage.c: In function ‘fsg_main_thread’:
> drivers/usb/gadget/function/f_mass_storage.c:2520:2: error: implicit
> declaration of function ‘set_fs’
> [-Werror=implicit-function-declaration]
>   set_fs(get_ds());
>   ^
> drivers/usb/gadget/function/f_mass_storage.c:2520:2: error: implicit
> declaration of function ‘get_ds’
> [-Werror=implicit-function-declaration]

Looks like the source file needs to #include .  
Apparently it got brought in indirectly from some other header file in
4.1, but not in current linux-next.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: g_serial hangs on write when the cable is disconnected

2015-08-06 Thread Peter Hurley
[ +cc Felipe ]

Hi Laszlo,

On 08/06/2015 10:03 AM, Laszlo Papp wrote:
> On Thu, Aug 6, 2015 at 2:52 PM, Alan Stern  wrote:
>> On Thu, 6 Aug 2015, Laszlo Papp wrote:
>>> On Wed, Aug 5, 2015 at 7:15 PM, Alan Stern  
>>> wrote:
 On Wed, 5 Aug 2015, Greg KH wrote:

> hm, wait, is this really the n_gsm line discipline?  Or is it something
> else?
>
> g_serial is the device side of a serial connection, there is no "cable
> removed" notification that it even knows about, that has to come from
> the gadget driver somehow, which you should listen for and then kick
> your userspace program.

 There is the gserial_disconnect() callback, which gets invoked when the
 Vbus power (provided by the host) is removed.  It's a pretty good
 indicator that the USB cable has been unplugged.

 I don't understand all the stuff that gserial_disconnect() does, but it
 ought to be more or less equivalent to a "hangup" -- as the kerneldoc
 says.  If it doesn't do what users expect, there's probably a bug
 somewhere.

 Of course, it's possible that the callback does not get invoked in
 Laszlo's case.  Then the question would be: Why not?
>>>
>>> Hmm, that is a good question. I wonder if there had been any recent
>>> fixes for that lately... I suppose that I will need to skim through
>>> the git log. Thank you for the hints!
>>
>> You should also add a printk statement to the disconnect callback so
>> that you can verify whether it really is getting called.
> 
> Thanks. Should that also be called if I just boot up the board with
> Linux on it while the cable is not attached. In other words, the
> problem that I am also experiencing is that it blocks even when no
> cable is attached to the board and there has been no cable ever
> attached for the last boot.

You have everyone hopelessly confused about what your problem actually is.

Your $subject says that "g_serial hangs on write" and for a reproducer
you provide:

#include 
#include 
#include 

int main()
{
const char buf[] = "Hello World!\n";
int fd = open("/dev/ttyGS0", O_RDWR | O_NONBLOCK);
int sent = write(fd, buf, sizeof(buf)-1);
close(fd);
return 0;
}

Only a careful reader would have caught this in your subsequent reply:

On Wed, Aug 05, 2015 at 04:40:21PM +0100, Laszlo Papp wrote:
> Wow, I managed to mess it up in my original email! So, this code above
> made it working, but without O_NONBLOCK, it was not working. Using
> O_NONBLOCK is my current nasty workaround.

To answer your original question, yes, the write() is behaving as expected.
If you open a tty without O_NONBLOCK, then both read() and write() to that
tty will _block_ until the operation is successful or the tty is hung up.

Your comparison with how ttyS* ports behave when a cable is not connected
is based on incorrect assumptions. When a ttyS port is in CLOCAL mode
(the default), the cable state is ignored when _opening_. On write(),
without hardware flow control (CRTSCTS), the serial port is successfully
writing the data out without knowing that nothing is listening.

I don't see a bug here.

Regards,
Peter Hurley




--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


randconfig build error with next-20150806, in drivers/usb/gadget/function/f_mass_storage.c

2015-08-06 Thread Jim Davis
Building with the attached random configuration file,

drivers/usb/gadget/function/f_mass_storage.c: In function ‘fsg_main_thread’:
drivers/usb/gadget/function/f_mass_storage.c:2520:2: error: implicit
declaration of function ‘set_fs’
[-Werror=implicit-function-declaration]
  set_fs(get_ds());
  ^
drivers/usb/gadget/function/f_mass_storage.c:2520:2: error: implicit
declaration of function ‘get_ds’
[-Werror=implicit-function-declaration]

-- 
Jim
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 4.2.0-rc5 Kernel Configuration
#
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_PERF_EVENTS_INTEL_UNCORE=y
CONFIG_OUTPUT_FORMAT="elf64-x86-64"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_HAVE_LATENCYTOP_SUPPORT=y
CONFIG_MMU=y
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_GENERIC_ISA_DMA=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_ARCH_MAY_HAVE_PC_FDC=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_ARCH_HAS_CPU_RELAX=y
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
CONFIG_HAVE_SETUP_PER_CPU_AREA=y
CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK=y
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
CONFIG_ARCH_SUSPEND_POSSIBLE=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
CONFIG_ARCH_WANT_GENERAL_HUGETLB=y
CONFIG_ZONE_DMA32=y
CONFIG_AUDIT_ARCH=y
CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
CONFIG_ARCH_HWEIGHT_CFLAGS="-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx 
-fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 
-fcall-saved-r11"
CONFIG_ARCH_SUPPORTS_UPROBES=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_PGTABLE_LEVELS=4
CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
CONFIG_CONSTRUCTORS=y
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_EXTABLE_SORT=y

#
# General setup
#
CONFIG_BROKEN_ON_SMP=y
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE=""
# CONFIG_COMPILE_TEST is not set
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION_AUTO=y
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_HAVE_KERNEL_BZIP2=y
CONFIG_HAVE_KERNEL_LZMA=y
CONFIG_HAVE_KERNEL_XZ=y
CONFIG_HAVE_KERNEL_LZO=y
CONFIG_HAVE_KERNEL_LZ4=y
CONFIG_KERNEL_GZIP=y
# CONFIG_KERNEL_BZIP2 is not set
# CONFIG_KERNEL_LZMA is not set
# CONFIG_KERNEL_XZ is not set
# CONFIG_KERNEL_LZO is not set
# CONFIG_KERNEL_LZ4 is not set
CONFIG_DEFAULT_HOSTNAME="(none)"
CONFIG_SYSVIPC=y
CONFIG_POSIX_MQUEUE=y
CONFIG_CROSS_MEMORY_ATTACH=y
# CONFIG_FHANDLE is not set
CONFIG_USELIB=y
CONFIG_AUDIT=y
CONFIG_HAVE_ARCH_AUDITSYSCALL=y
# CONFIG_AUDITSYSCALL is not set

#
# IRQ subsystem
#
CONFIG_GENERIC_IRQ_PROBE=y
CONFIG_GENERIC_IRQ_SHOW=y
CONFIG_GENERIC_IRQ_CHIP=y
CONFIG_IRQ_DOMAIN=y
CONFIG_IRQ_DOMAIN_HIERARCHY=y
CONFIG_IRQ_DOMAIN_DEBUG=y
CONFIG_IRQ_FORCED_THREADING=y
CONFIG_SPARSE_IRQ=y
CONFIG_CLOCKSOURCE_WATCHDOG=y
CONFIG_ARCH_CLOCKSOURCE_DATA=y
CONFIG_CLOCKSOURCE_VALIDATE_LAST_CYCLE=y
CONFIG_GENERIC_TIME_VSYSCALL=y
CONFIG_GENERIC_CLOCKEVENTS=y
CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
CONFIG_GENERIC_CLOCKEVENTS_MIN_ADJUST=y
CONFIG_GENERIC_CMOS_UPDATE=y

#
# Timers subsystem
#
CONFIG_HZ_PERIODIC=y
# CONFIG_NO_HZ_IDLE is not set
# CONFIG_NO_HZ is not set
# CONFIG_HIGH_RES_TIMERS is not set

#
# CPU/Task time and stats accounting
#
CONFIG_TICK_CPU_ACCOUNTING=y
# CONFIG_VIRT_CPU_ACCOUNTING_GEN is not set
# CONFIG_IRQ_TIME_ACCOUNTING is not set
# CONFIG_BSD_PROCESS_ACCT is not set
CONFIG_TASKSTATS=y
# CONFIG_TASK_DELAY_ACCT is not set
# CONFIG_TASK_XACCT is not set

#
# RCU Subsystem
#
CONFIG_TINY_RCU=y
CONFIG_RCU_EXPERT=y
CONFIG_SRCU=y
CONFIG_TASKS_RCU=y
# CONFIG_RCU_STALL_COMMON is not set
# CONFIG_TREE_RCU_TRACE is not set
CONFIG_RCU_KTHREAD_PRIO=0
# CONFIG_RCU_EXPEDITE_BOOT is not set
CONFIG_BUILD_BIN2C=y
CONFIG_IKCONFIG=y
CONFIG_LOG_BUF_SHIFT=17
CONFIG_HAVE_UNSTABLE_SCHED_CLOCK=y
CONFIG_ARCH_SUPPORTS_NUMA_BALANCING=y
CONFIG_ARCH_SUPPORTS_INT128=y
# CONFIG_CGROUPS is not set
CONFIG_CHECKPOINT_RESTORE=y
CONFIG_NAMESPACES=y
CONFIG_UTS_NS=y
# CONFIG_IPC_NS is not set
# CONFIG_USER_NS is not set
# CONFIG_PID_NS is not set
CONFIG_NET_NS=y
# CONFIG_SCHED_AUTOGROUP is not set
CONFIG_SYSFS_DEPRECATED=y
# CONFIG_SYSFS_DEPRECATED_V2 is not set
CONFIG_RELAY=y
# CONFIG_BLK_DEV_INITRD is not set
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
# CONFIG_LTO_MENU is not set
CONFIG_ANON_INODES=y
CONFIG_HAVE_UID16=y
CONFIG_SYSCTL_EXCEPTION_TRACE=y
CONFIG_HAVE_PCSPKR_PLATFORM=y
CONFIG_BPF=y
CONFIG_EXPERT=y
CONFIG_UID16=y
CONFIG_MULTIUSER=y
# CONFIG_SGETMASK_SYSCALL is not set
CONFIG_SYSFS_SYSCALL=y
CONFIG_KALLSYMS=y
CONFIG_KALLSYMS_ALL=y
CONFIG_PRINTK=y
CONFIG_BUG=y
# CONFIG_ELF_CORE is not set
# CONFIG_PCSPKR_PLATFORM is not set
CONFIG_BASE_FULL=y
CONFIG_FUTEX=y
CONFIG_EPOLL=y
# CONFIG_SIGNALFD is not set
# CONFIG_TIMERFD is not set
CONFIG_EVENTFD=y
# CONFIG_BPF_SYSCALL is not set
# CONFIG_SHMEM is not set
# CONFIG_AIO is not set
# CONFIG_ADVISE_SYSCALLS is not set
CONFIG_USERFAULTFD=y
# CONFIG_PCI_QUIRKS is 

Re: PROBLEM: ch341 module fails with EPROTO when I plug-in Arduino board)

2015-08-06 Thread Evgen Druzhynin
2015-07-07 14:28 GMT+03:00 Evgen Druzhynin :
> 2015-07-07 14:06 GMT+03:00 Johan Hovold :
> I'll try to find exact kernel version where issue was introduced ASAP.

Hi all,

Root cause is chinese Arduino board (ID 1a86:7523 QinHeng Electronics
HL-340 USB-Serial adapter). The board sometimes works and sometimes
doesn't on the same version of kernel.

=
y = works
n = not works
=

I tested in next sequence:
- 4.1 - n
- 4.0 - n
- 3.19 - n
- 3.15 - n
- 3.13 - y
- 3.14 - y
- 3.15 - y
- 3.17 - y
- 3.18 - y
- 3.19 - y
- 4.0 - y
- 4.1 - y

But on the next morning the board didn't work again with 4.1 kernel.
Original Arduino board works perfect on any version of kernel.

Thank in advance for the answer.
Best regards,
Evgen.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: g_serial hangs on write when the cable is disconnected

2015-08-06 Thread Alan Stern
On Thu, 6 Aug 2015, Laszlo Papp wrote:

> > You should also add a printk statement to the disconnect callback so
> > that you can verify whether it really is getting called.
> 
> Thanks. Should that also be called if I just boot up the board with
> Linux on it while the cable is not attached.

No.  It gets called only at the time you unplug the cable.

> In other words, the
> problem that I am also experiencing is that it blocks even when no
> cable is attached to the board and there has been no cable ever
> attached for the last boot.

You didn't mention this before.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Renesas upd7202 (xhci): can't setup

2015-08-06 Thread Jean-Francois SIMON
Mathias,

> Does changing the delay time in the busyloop make a difference?

We have found that this was a hardware problem in our design.
-jfs
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: g_serial hangs on write when the cable is disconnected

2015-08-06 Thread Laszlo Papp
On Thu, Aug 6, 2015 at 2:52 PM, Alan Stern  wrote:
> On Thu, 6 Aug 2015, Laszlo Papp wrote:
>
>> Hi Alan,
>>
>> On Wed, Aug 5, 2015 at 7:15 PM, Alan Stern  wrote:
>> > On Wed, 5 Aug 2015, Greg KH wrote:
>> >
>> >> hm, wait, is this really the n_gsm line discipline?  Or is it something
>> >> else?
>> >>
>> >> g_serial is the device side of a serial connection, there is no "cable
>> >> removed" notification that it even knows about, that has to come from
>> >> the gadget driver somehow, which you should listen for and then kick
>> >> your userspace program.
>> >
>> > There is the gserial_disconnect() callback, which gets invoked when the
>> > Vbus power (provided by the host) is removed.  It's a pretty good
>> > indicator that the USB cable has been unplugged.
>> >
>> > I don't understand all the stuff that gserial_disconnect() does, but it
>> > ought to be more or less equivalent to a "hangup" -- as the kerneldoc
>> > says.  If it doesn't do what users expect, there's probably a bug
>> > somewhere.
>> >
>> > Of course, it's possible that the callback does not get invoked in
>> > Laszlo's case.  Then the question would be: Why not?
>>
>> Hmm, that is a good question. I wonder if there had been any recent
>> fixes for that lately... I suppose that I will need to skim through
>> the git log. Thank you for the hints!
>
> You should also add a printk statement to the disconnect callback so
> that you can verify whether it really is getting called.

Thanks. Should that also be called if I just boot up the board with
Linux on it while the cable is not attached. In other words, the
problem that I am also experiencing is that it blocks even when no
cable is attached to the board and there has been no cable ever
attached for the last boot.

>
> Alan Stern
>
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: g_serial hangs on write when the cable is disconnected

2015-08-06 Thread Alan Stern
On Thu, 6 Aug 2015, Laszlo Papp wrote:

> Hi Alan,
> 
> On Wed, Aug 5, 2015 at 7:15 PM, Alan Stern  wrote:
> > On Wed, 5 Aug 2015, Greg KH wrote:
> >
> >> hm, wait, is this really the n_gsm line discipline?  Or is it something
> >> else?
> >>
> >> g_serial is the device side of a serial connection, there is no "cable
> >> removed" notification that it even knows about, that has to come from
> >> the gadget driver somehow, which you should listen for and then kick
> >> your userspace program.
> >
> > There is the gserial_disconnect() callback, which gets invoked when the
> > Vbus power (provided by the host) is removed.  It's a pretty good
> > indicator that the USB cable has been unplugged.
> >
> > I don't understand all the stuff that gserial_disconnect() does, but it
> > ought to be more or less equivalent to a "hangup" -- as the kerneldoc
> > says.  If it doesn't do what users expect, there's probably a bug
> > somewhere.
> >
> > Of course, it's possible that the callback does not get invoked in
> > Laszlo's case.  Then the question would be: Why not?
> 
> Hmm, that is a good question. I wonder if there had been any recent
> fixes for that lately... I suppose that I will need to skim through
> the git log. Thank you for the hints!

You should also add a printk statement to the disconnect callback so 
that you can verify whether it really is getting called.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: chipidea: imx: properly check for usbmisc

2015-08-06 Thread Tomeu Vizoso
If usbmisc hasn't probed yet, defer the probe.

It's not enough to check if the platform device for the OF node of the
usbmisc has been registered, but it also needs to have been probed
already before we can call imx_usbmisc_init().

This can happen if the order in which devices are probed change due to
async probing or on-demand probing of dependencies.

Signed-off-by: Tomeu Vizoso 
---
 drivers/usb/chipidea/ci_hdrc_imx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c 
b/drivers/usb/chipidea/ci_hdrc_imx.c
index 504554e41922..e3c61d5e9270 100644
--- a/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -104,7 +104,7 @@ static struct imx_usbmisc_data 
*usbmisc_get_init_data(struct device *dev)
misc_pdev = of_find_device_by_node(args.np);
of_node_put(args.np);
 
-   if (!misc_pdev)
+   if (!misc_pdev || !platform_get_drvdata(misc_pdev))
return ERR_PTR(-EPROBE_DEFER);
 
data->dev = &misc_pdev->dev;
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 3/8] usb: gadget: move ep_matches() from epautoconf to udc-core

2015-08-06 Thread Robert Baldyga
Move ep_matches() function to udc-core and rename it to
usb_gadget_ep_match_desc(). This function can be used by UDC drivers
in 'match_ep' callback to avoid writing lots of repetitive code.

Replace all calls of ep_matches() with usb_gadget_ep_match_desc().

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 95 +--
 drivers/usb/gadget/udc/udc-core.c | 69 
 include/linux/usb/gadget.h|  8 
 3 files changed, 88 insertions(+), 84 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index f000c73..d49af4f 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -22,82 +22,6 @@
 
 #include "gadget_chips.h"
 
-static int
-ep_matches (
-   struct usb_gadget   *gadget,
-   struct usb_ep   *ep,
-   struct usb_endpoint_descriptor  *desc,
-   struct usb_ss_ep_comp_descriptor *ep_comp
-)
-{
-   u8  type;
-   u16 max;
-   int num_req_streams = 0;
-
-   /* endpoint already claimed? */
-   if (ep->claimed)
-   return 0;
-
-   type = usb_endpoint_type(desc);
-   max = 0x7ff & usb_endpoint_maxp(desc);
-
-   if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
-   return 0;
-   if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
-   return 0;
-
-   if (max > ep->maxpacket_limit)
-   return 0;
-
-   /* "high bandwidth" works only at high speed */
-   if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
-   return 0;
-
-   switch (type) {
-   case USB_ENDPOINT_XFER_CONTROL:
-   /* only support ep0 for portable CONTROL traffic */
-   return 0;
-   case USB_ENDPOINT_XFER_ISOC:
-   if (!ep->caps.type_iso)
-   return 0;
-   /* ISO:  limit 1023 bytes full speed,
-* 1024 high/super speed
-*/
-   if (!gadget_is_dualspeed(gadget) && max > 1023)
-   return 0;
-   break;
-   case USB_ENDPOINT_XFER_BULK:
-   if (!ep->caps.type_bulk)
-   return 0;
-   if (ep_comp && gadget_is_superspeed(gadget)) {
-   /* Get the number of required streams from the
-* EP companion descriptor and see if the EP
-* matches it
-*/
-   num_req_streams = ep_comp->bmAttributes & 0x1f;
-   if (num_req_streams > ep->max_streams)
-   return 0;
-   }
-   break;
-   case USB_ENDPOINT_XFER_INT:
-   /* Bulk endpoints handle interrupt transfers,
-* except the toggle-quirky iso-synch kind
-*/
-   if (!ep->caps.type_int && !ep->caps.type_bulk)
-   return 0;
-   /* INT:  limit 64 bytes full speed,
-* 1024 high/super speed
-*/
-   if (!gadget_is_dualspeed(gadget) && max > 64)
-   return 0;
-   break;
-   }
-
-   /* MATCH!! */
-
-   return 1;
-}
-
 static struct usb_ep *
 find_ep (struct usb_gadget *gadget, const char *name)
 {
@@ -180,10 +104,12 @@ struct usb_ep *usb_ep_autoconfig_ss(
if (type == USB_ENDPOINT_XFER_INT) {
/* ep-e, ep-f are PIO with only 64 byte fifos */
ep = find_ep(gadget, "ep-e");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget,
+   ep, desc, ep_comp))
goto found_ep;
ep = find_ep(gadget, "ep-f");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget,
+   ep, desc, ep_comp))
goto found_ep;
}
 
@@ -191,20 +117,21 @@ struct usb_ep *usb_ep_autoconfig_ss(
snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
usb_endpoint_dir_in(desc) ? "in" : "out");
ep = find_ep(gadget, name);
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
} else if (gadget_is_goku (gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
ep = find_ep(gadget, "ep3-bulk");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+  

[PATCH v8 4/8] usb: gadget: move find_ep() from epautoconf to udc-core

2015-08-06 Thread Robert Baldyga
Move find_ep() to udc-core and rename it to gadget_find_ep_by_name().
It can be used in UDC drivers, especially in 'match_ep' callback after
moving chip-specific endpoint matching logic from epautoconf to UDC
drivers.

Replace all calls of find_ep() function with gadget_find_ep_by_name().

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 30 +-
 drivers/usb/gadget/udc/udc-core.c | 21 +
 include/linux/usb/gadget.h|  8 +++-
 3 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index d49af4f..a39ca03 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -22,18 +22,6 @@
 
 #include "gadget_chips.h"
 
-static struct usb_ep *
-find_ep (struct usb_gadget *gadget, const char *name)
-{
-   struct usb_ep   *ep;
-
-   list_for_each_entry (ep, &gadget->ep_list, ep_list) {
-   if (0 == strcmp (ep->name, name))
-   return ep;
-   }
-   return NULL;
-}
-
 /**
  * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
  * descriptor and ep companion descriptor
@@ -103,11 +91,11 @@ struct usb_ep *usb_ep_autoconfig_ss(
 
if (type == USB_ENDPOINT_XFER_INT) {
/* ep-e, ep-f are PIO with only 64 byte fifos */
-   ep = find_ep(gadget, "ep-e");
+   ep = gadget_find_ep_by_name(gadget, "ep-e");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
-   ep = find_ep(gadget, "ep-f");
+   ep = gadget_find_ep_by_name(gadget, "ep-f");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
@@ -116,20 +104,20 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* USB3380: use same address for usb and hardware endpoints */
snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
usb_endpoint_dir_in(desc) ? "in" : "out");
-   ep = find_ep(gadget, name);
+   ep = gadget_find_ep_by_name(gadget, name);
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
} else if (gadget_is_goku (gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
-   ep = find_ep(gadget, "ep3-bulk");
+   ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
} else if (USB_ENDPOINT_XFER_BULK == type
&& (USB_DIR_IN & desc->bEndpointAddress)) {
/* DMA may be available */
-   ep = find_ep(gadget, "ep2-bulk");
+   ep = gadget_find_ep_by_name(gadget, "ep2-bulk");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
@@ -140,14 +128,14 @@ struct usb_ep *usb_ep_autoconfig_ss(
if ((USB_ENDPOINT_XFER_BULK == type) ||
(USB_ENDPOINT_XFER_ISOC == type)) {
if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = find_ep (gadget, "ep5in");
+   ep = gadget_find_ep_by_name(gadget, "ep5in");
else
-   ep = find_ep (gadget, "ep6out");
+   ep = gadget_find_ep_by_name(gadget, "ep6out");
} else if (USB_ENDPOINT_XFER_INT == type) {
if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = find_ep(gadget, "ep1in");
+   ep = gadget_find_ep_by_name(gadget, "ep1in");
else
-   ep = find_ep(gadget, "ep2out");
+   ep = gadget_find_ep_by_name(gadget, "ep2out");
} else
ep = NULL;
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b6427d1..3c954b5 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -131,6 +131,27 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
 /* - */
 
+/**
+ * gadget_find_ep_by_name - returns ep whose name is the same as sting 

[PATCH v8 7/8] usb: musb: gadget: add musb_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 23 ---
 drivers/usb/musb/musb_gadget.c  | 34 ++
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 574b6a4..16c1cc9 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -83,29 +83,6 @@ struct usb_ep *usb_ep_autoconfig_ss(
goto found_ep;
}
 
-   /* First, apply chip-specific "best usage" knowledge.
-* This might make a good usb_gadget_ops hook ...
-*/
-#ifdef CONFIG_BLACKFIN
-   if (gadget_is_musbhdrc(gadget)) {
-   if ((USB_ENDPOINT_XFER_BULK == type) ||
-   (USB_ENDPOINT_XFER_ISOC == type)) {
-   if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = gadget_find_ep_by_name(gadget, "ep5in");
-   else
-   ep = gadget_find_ep_by_name(gadget, "ep6out");
-   } else if (USB_ENDPOINT_XFER_INT == type) {
-   if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = gadget_find_ep_by_name(gadget, "ep1in");
-   else
-   ep = gadget_find_ep_by_name(gadget, "ep2out");
-   } else
-   ep = NULL;
-   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
-   goto found_ep;
-   }
-#endif
-
/* Second, look at endpoints until an unclaimed one looks usable */
list_for_each_entry (ep, &gadget->ep_list, ep_list) {
if (usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4150baf..5f52bcb 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1684,6 +1684,39 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, 
int is_on)
return 0;
 }
 
+#ifdef CONFIG_BLACKFIN
+static struct usb_ep *musb_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct usb_ep *ep = NULL;
+
+   switch (usb_endpoint_type(desc)) {
+   case USB_ENDPOINT_XFER_ISOC:
+   case USB_ENDPOINT_XFER_BULK:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep5in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep6out");
+   break;
+   case USB_ENDPOINT_XFER_INT:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep1in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep2out");
+   break;
+   default:
+   }
+
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+
+   return NULL;
+}
+#else
+#define musb_match_ep NULL
+#endif
+
 static int musb_gadget_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
 static int musb_gadget_stop(struct usb_gadget *g);
@@ -1697,6 +1730,7 @@ static const struct usb_gadget_ops musb_gadget_operations 
= {
.pullup = musb_gadget_pullup,
.udc_start  = musb_gadget_start,
.udc_stop   = musb_gadget_stop,
+   .match_ep   = musb_match_ep,
 };
 
 /* --- */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 6/8] usb: gadget: goku_udc: add goku_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 20 ++--
 drivers/usb/gadget/udc/goku_udc.c | 29 +
 2 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 0ff5134..574b6a4 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,24 +86,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
-   if (gadget_is_goku(gadget)) {
-   if (USB_ENDPOINT_XFER_INT == type) {
-   /* single buffering is enough */
-   ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   } else if (USB_ENDPOINT_XFER_BULK == type
-   && (USB_DIR_IN & desc->bEndpointAddress)) {
-   /* DMA may be available */
-   ep = gadget_find_ep_by_name(gadget, "ep2-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   }
-
 #ifdef CONFIG_BLACKFIN
-   } else if (gadget_is_musbhdrc(gadget)) {
+   if (gadget_is_musbhdrc(gadget)) {
if ((USB_ENDPOINT_XFER_BULK == type) ||
(USB_ENDPOINT_XFER_ISOC == type)) {
if (USB_DIR_IN & desc->bEndpointAddress)
@@ -119,8 +103,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
ep = NULL;
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
-#endif
}
+#endif
 
/* Second, look at endpoints until an unclaimed one looks usable */
list_for_each_entry (ep, &gadget->ep_list, ep_list) {
diff --git a/drivers/usb/gadget/udc/goku_udc.c 
b/drivers/usb/gadget/udc/goku_udc.c
index 46b8d14..2b628b3 100644
--- a/drivers/usb/gadget/udc/goku_udc.c
+++ b/drivers/usb/gadget/udc/goku_udc.c
@@ -990,6 +990,34 @@ static int goku_get_frame(struct usb_gadget *_gadget)
return -EOPNOTSUPP;
 }
 
+static struct usb_ep *goku_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct goku_udc *dev = to_goku_udc(g);
+   struct usb_ep *ep;
+
+   switch (usb_endpoint_type(desc)) {
+   case USB_ENDPOINT_XFER_INT:
+   /* single buffering is enough */
+   ep = &dev->ep[3].ep;
+   if (usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+   break;
+   case USB_ENDPOINT_XFER_BULK:
+   if (usb_endpoint_dir_in(desc)) {
+   /* DMA may be available */
+   ep = &dev->ep[2].ep;
+   if (usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+   }
+   break;
+   default:
+   }
+
+   return NULL;
+}
+
 static int goku_udc_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
 static int goku_udc_stop(struct usb_gadget *g);
@@ -998,6 +1026,7 @@ static const struct usb_gadget_ops goku_ops = {
.get_frame  = goku_get_frame,
.udc_start  = goku_udc_start,
.udc_stop   = goku_udc_stop,
+   .match_ep   = goku_match_ep,
// no remote wakeup
// not selfpowered
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 8/8] usb: gadget: remove gadget_chips.h

2015-08-06 Thread Robert Baldyga
This header file contains helpers for quirks based on UDC controller name.
Since we have generic quirk bitfields in usb_gadget structure for all of
these quirks we don't need to have this header any longer.

This patch removes gadget_chips.h file and makes sure that it's no longer
included anywhere in kernel sources.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c  |  2 -
 drivers/usb/gadget/function/f_acm.c  |  1 -
 drivers/usb/gadget/function/f_mass_storage.c |  1 -
 drivers/usb/gadget/function/f_obex.c |  1 -
 drivers/usb/gadget/function/f_serial.c   |  1 -
 drivers/usb/gadget/function/f_sourcesink.c   |  1 -
 drivers/usb/gadget/function/u_ether.h|  2 -
 drivers/usb/gadget/function/u_uac1.h |  2 -
 drivers/usb/gadget/legacy/audio.c|  1 -
 drivers/usb/gadget/legacy/gmidi.c|  2 -
 drivers/usb/gadget/legacy/hid.c  |  1 -
 drivers/usb/gadget/legacy/nokia.c|  1 -
 drivers/usb/gadget/legacy/printer.c  |  2 -
 drivers/usb/gadget/legacy/serial.c   |  1 -
 drivers/usb/gadget/udc/gadget_chips.h| 55 
 15 files changed, 74 deletions(-)
 delete mode 100644 drivers/usb/gadget/udc/gadget_chips.h

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 16c1cc9..978435a 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 /**
  * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
  * descriptor and ep companion descriptor
diff --git a/drivers/usb/gadget/function/f_acm.c 
b/drivers/usb/gadget/function/f_acm.c
index aad8165..be9df09 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -21,7 +21,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_mass_storage.c 
b/drivers/usb/gadget/function/f_mass_storage.c
index 04c3bb6..11a7f5a 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -219,7 +219,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #include "configfs.h"
 
 
diff --git a/drivers/usb/gadget/function/f_obex.c 
b/drivers/usb/gadget/function/f_obex.c
index 2682d59..5460426 100644
--- a/drivers/usb/gadget/function/f_obex.c
+++ b/drivers/usb/gadget/function/f_obex.c
@@ -20,7 +20,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_serial.c 
b/drivers/usb/gadget/function/f_serial.c
index 2e02dfa..1d162e2 100644
--- a/drivers/usb/gadget/function/f_serial.c
+++ b/drivers/usb/gadget/function/f_serial.c
@@ -16,7 +16,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_sourcesink.c 
b/drivers/usb/gadget/function/f_sourcesink.c
index e6af171..cbfaf86 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -20,7 +20,6 @@
 #include 
 
 #include "g_zero.h"
-#include "gadget_chips.h"
 #include "u_f.h"
 
 /*
diff --git a/drivers/usb/gadget/function/u_ether.h 
b/drivers/usb/gadget/function/u_ether.h
index 1384f00..c77145b 100644
--- a/drivers/usb/gadget/function/u_ether.h
+++ b/drivers/usb/gadget/function/u_ether.h
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #define QMULT_DEFAULT 5
 
 /*
diff --git a/drivers/usb/gadget/function/u_uac1.h 
b/drivers/usb/gadget/function/u_uac1.h
index fe386df..5c2ac8e 100644
--- a/drivers/usb/gadget/function/u_uac1.h
+++ b/drivers/usb/gadget/function/u_uac1.h
@@ -21,8 +21,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #define FILE_PCM_PLAYBACK  "/dev/snd/pcmC0D0p"
 #define FILE_PCM_CAPTURE   "/dev/snd/pcmC0D0c"
 #define FILE_CONTROL   "/dev/snd/controlC0"
diff --git a/drivers/usb/gadget/legacy/audio.c 
b/drivers/usb/gadget/legacy/audio.c
index 9b2c1c6..685cf3b 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #define DRIVER_DESC"Linux USB Audio Gadget"
 #define DRIVER_VERSION "Feb 2, 2012"
 
diff --git a/drivers/usb/gadget/legacy/gmidi.c 
b/drivers/usb/gadget/legacy/gmidi.c
index 650568d..8a18348 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -35,8 +35,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #include "u_midi.h"
 
 /*-*/
diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index e4874d3..7e5d2c4 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #define DRIVER_DESC"HID Gadget"
 #define DRIVER_VERSIO

[PATCH v8 5/8] usb: gadget: net2280: add net2280_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c  | 23 +--
 drivers/usb/gadget/udc/net2280.c | 28 
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index a39ca03..0ff5134 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,28 +86,7 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
-   if (gadget_is_net2280(gadget)) {
-   char name[8];
-
-   if (type == USB_ENDPOINT_XFER_INT) {
-   /* ep-e, ep-f are PIO with only 64 byte fifos */
-   ep = gadget_find_ep_by_name(gadget, "ep-e");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   ep = gadget_find_ep_by_name(gadget, "ep-f");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   }
-
-   /* USB3380: use same address for usb and hardware endpoints */
-   snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
-   usb_endpoint_dir_in(desc) ? "in" : "out");
-   ep = gadget_find_ep_by_name(gadget, name);
-   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
-   goto found_ep;
-   } else if (gadget_is_goku (gadget)) {
+   if (gadget_is_goku(gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 872ca25..cf0ed42 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -1550,6 +1550,33 @@ static int net2280_pullup(struct usb_gadget *_gadget, 
int is_on)
return 0;
 }
 
+static struct usb_ep *net2280_match_ep(struct usb_gadget *_gadget,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   char name[8];
+   struct usb_ep *ep;
+
+   if (usb_endpoint_type(desc) == USB_ENDPOINT_XFER_INT) {
+   /* ep-e, ep-f are PIO with only 64 byte fifos */
+   ep = gadget_find_ep_by_name(_gadget, "ep-e");
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+   ep = gadget_find_ep_by_name(_gadget, "ep-f");
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+   }
+
+   /* USB3380: use same address for usb and hardware endpoints */
+   snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
+   usb_endpoint_dir_in(desc) ? "in" : "out");
+   ep = gadget_find_ep_by_name(_gadget, name);
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+
+   return NULL;
+}
+
 static int net2280_start(struct usb_gadget *_gadget,
struct usb_gadget_driver *driver);
 static int net2280_stop(struct usb_gadget *_gadget);
@@ -1561,6 +1588,7 @@ static const struct usb_gadget_ops net2280_ops = {
.pullup = net2280_pullup,
.udc_start  = net2280_start,
.udc_stop   = net2280_stop,
+   .match_ep   = net2280_match_ep,
 };
 
 /*-*/
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 1/8] usb: gadget: epautoconf: rework ep_matches() function

2015-08-06 Thread Robert Baldyga
Rework ep_matches() function to make it shorter and more readable.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 81 -
 1 file changed, 32 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 52658fe..95e1275 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -32,7 +32,6 @@ ep_matches (
 {
u8  type;
u16 max;
-
int num_req_streams = 0;
 
/* endpoint already claimed? */
@@ -40,6 +39,20 @@ ep_matches (
return 0;
 
type = usb_endpoint_type(desc);
+   max = 0x7ff & usb_endpoint_maxp(desc);
+
+   if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
+   return 0;
+   if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
+   return 0;
+
+   if (max > ep->maxpacket_limit)
+   return 0;
+
+   /* "high bandwidth" works only at high speed */
+   if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
+   return 0;
+
switch (type) {
case USB_ENDPOINT_XFER_CONTROL:
/* only support ep0 for portable CONTROL traffic */
@@ -47,66 +60,36 @@ ep_matches (
case USB_ENDPOINT_XFER_ISOC:
if (!ep->caps.type_iso)
return 0;
+   /* ISO:  limit 1023 bytes full speed,
+* 1024 high/super speed
+*/
+   if (!gadget_is_dualspeed(gadget) && max > 1023)
+   return 0;
break;
case USB_ENDPOINT_XFER_BULK:
if (!ep->caps.type_bulk)
return 0;
+   if (ep_comp && gadget_is_superspeed(gadget)) {
+   /* Get the number of required streams from the
+* EP companion descriptor and see if the EP
+* matches it
+*/
+   num_req_streams = ep_comp->bmAttributes & 0x1f;
+   if (num_req_streams > ep->max_streams)
+   return 0;
+   }
break;
case USB_ENDPOINT_XFER_INT:
-   /* bulk endpoints handle interrupt transfers,
+   /* Bulk endpoints handle interrupt transfers,
 * except the toggle-quirky iso-synch kind
 */
if (!ep->caps.type_int && !ep->caps.type_bulk)
return 0;
-   break;
-   }
-
-   if (usb_endpoint_dir_in(desc)) {
-   if (!ep->caps.dir_in)
-   return 0;
-   } else {
-   if (!ep->caps.dir_out)
-   return 0;
-   }
-
-   /*
-* Get the number of required streams from the EP companion
-* descriptor and see if the EP matches it
-*/
-   if (usb_endpoint_xfer_bulk(desc)) {
-   if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) {
-   num_req_streams = ep_comp->bmAttributes & 0x1f;
-   if (num_req_streams > ep->max_streams)
-   return 0;
-   }
-
-   }
-
-   /* endpoint maxpacket size is an input parameter, except for bulk
-* where it's an output parameter representing the full speed limit.
-* the usb spec fixes high speed bulk maxpacket at 512 bytes.
-*/
-   max = 0x7ff & usb_endpoint_maxp(desc);
-   switch (type) {
-   case USB_ENDPOINT_XFER_INT:
-   /* INT:  limit 64 bytes full speed, 1024 high/super speed */
+   /* INT:  limit 64 bytes full speed,
+* 1024 high/super speed
+*/
if (!gadget_is_dualspeed(gadget) && max > 64)
return 0;
-   /* FALLTHROUGH */
-
-   case USB_ENDPOINT_XFER_ISOC:
-   /* ISO:  limit 1023 bytes full speed, 1024 high/super speed */
-   if (ep->maxpacket_limit < max)
-   return 0;
-   if (!gadget_is_dualspeed(gadget) && max > 1023)
-   return 0;
-
-   /* BOTH:  "high bandwidth" works only at high speed */
-   if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
-   if (!gadget_is_dualspeed(gadget))
-   return 0;
-   /* configure your hardware with enough buffering!! */
-   }
break;
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 2/8] usb: gadget: add 'ep_match' callback to usb_gadget_ops

2015-08-06 Thread Robert Baldyga
Add callback that is called by epautoconf to allow UDC driver match the
best endpoint for specific descriptor. It's intended to supply mechanism
which allows to get rid of chip-specific endpoint matching code from
epautoconf.

If gadget has set 'ep_match' callback we prefer to call it first, and
if it fails to find matching endpoint, then we try to use default matching
algorithm.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 6 ++
 include/linux/usb/gadget.h  | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 95e1275..f000c73 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -165,6 +165,12 @@ struct usb_ep *usb_ep_autoconfig_ss(
 
type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 
+   if (gadget->ops->match_ep) {
+   ep = gadget->ops->match_ep(gadget, desc, ep_comp);
+   if (ep)
+   goto found_ep;
+   }
+
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 82b5bcb..303214b 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -534,6 +534,9 @@ struct usb_gadget_ops {
int (*udc_start)(struct usb_gadget *,
struct usb_gadget_driver *);
int (*udc_stop)(struct usb_gadget *);
+   struct usb_ep *(*match_ep)(struct usb_gadget *,
+   struct usb_endpoint_descriptor *,
+   struct usb_ss_ep_comp_descriptor *);
 };
 
 /**
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 0/8] usb: gadget: rework ep matching and claiming mechanism

2015-08-06 Thread Robert Baldyga
Hi Felipe,

These are remaining patches of my series plus one which remained from
series [1].

[1] usb: gadget: get rid of UDC name-based quirks
https://lkml.org/lkml/2015/7/28/29

Best regards,
Robert Baldyga

Changelog:

v8:
- addressed comments from Sergei Shtylyov

v7: https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg949593.html
- make gadget_find_ep_by_name() exported symbol instead of static inline
  as Alan Stern suggested

v6: https://lkml.org/lkml/2015/8/5/312
- fix regression in ep_matches() function

v5: https://lkml.org/lkml/2015/7/31/402
- made code more grepable according to Felipe's suggestion

v4: https://lkml.org/lkml/2015/7/27/181
- addressed comments from Krzysztof Opasiak and Felipe Balbi

v3: https://lkml.org/lkml/2015/7/15/68
- addressed comments from Sergei Shtylyov

v2: https://lkml.org/lkml/2015/7/14/172
- remove PXA quirk from ep_matches() function without behaviour change
  using ep capabilities flags
- separate ep and desc configuration code from ep_match() function
- add 'ep_match' to usb_gadget_ops and move chip-specific endpoint
  matching algorithms from generic code to UDC controller drivers

v1: https://lkml.org/lkml/2015/7/8/436

Robert Baldyga (8):
  usb: gadget: epautoconf: rework ep_matches() function
  usb: gadget: add 'ep_match' callback to usb_gadget_ops
  usb: gadget: move ep_matches() from epautoconf to udc-core
  usb: gadget: move find_ep() from epautoconf to udc-core
  usb: gadget: net2280: add net2280_match_ep() function
  usb: gadget: goku_udc: add goku_match_ep() function
  usb: musb: gadget: add musb_match_ep() function
  usb: gadget: remove gadget_chips.h

 drivers/usb/gadget/epautoconf.c  | 166 +--
 drivers/usb/gadget/function/f_acm.c  |   1 -
 drivers/usb/gadget/function/f_mass_storage.c |   1 -
 drivers/usb/gadget/function/f_obex.c |   1 -
 drivers/usb/gadget/function/f_serial.c   |   1 -
 drivers/usb/gadget/function/f_sourcesink.c   |   1 -
 drivers/usb/gadget/function/u_ether.h|   2 -
 drivers/usb/gadget/function/u_uac1.h |   2 -
 drivers/usb/gadget/legacy/audio.c|   1 -
 drivers/usb/gadget/legacy/gmidi.c|   2 -
 drivers/usb/gadget/legacy/hid.c  |   1 -
 drivers/usb/gadget/legacy/nokia.c|   1 -
 drivers/usb/gadget/legacy/printer.c  |   2 -
 drivers/usb/gadget/legacy/serial.c   |   1 -
 drivers/usb/gadget/udc/gadget_chips.h|  55 -
 drivers/usb/gadget/udc/goku_udc.c|  29 +
 drivers/usb/gadget/udc/net2280.c |  28 +
 drivers/usb/gadget/udc/udc-core.c|  90 +++
 drivers/usb/musb/musb_gadget.c   |  34 ++
 include/linux/usb/gadget.h   |  19 ++-
 20 files changed, 203 insertions(+), 235 deletions(-)
 delete mode 100644 drivers/usb/gadget/udc/gadget_chips.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 7/8] usb: musb: gadget: add musb_match_ep() function

2015-08-06 Thread Sergei Shtylyov

On 8/6/2015 10:58 AM, Robert Baldyga wrote:


Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.



Signed-off-by: Robert Baldyga 
---
  drivers/usb/gadget/epautoconf.c | 23 ---
  drivers/usb/musb/musb_gadget.c  | 34 ++
  2 files changed, 34 insertions(+), 23 deletions(-)


[...]

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4150baf..ac2f188 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1684,6 +1684,39 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, 
int is_on)
return 0;
  }

+#ifdef CONFIG_BLACKFIN
+static struct usb_ep *musb_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct usb_ep *ep = NULL;
+   u8 type = usb_endpoint_type(desc);


   You hardly need this variable.


+
+   switch (type) {
+   case USB_ENDPOINT_XFER_ISOC:
+   case USB_ENDPOINT_XFER_BULK:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep5in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep6out");
+   break;
+   case USB_ENDPOINT_XFER_INT:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep1in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep2out");
+   default:
+   }
+
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+
+   return NULL;
+}
+#else
+#define musb_match_ep NULL
+#endif
+
  static int musb_gadget_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
  static int musb_gadget_stop(struct usb_gadget *g);

[...]

MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v7 6/8] usb: gadget: goku_udc: add goku_match_ep() function

2015-08-06 Thread Sergei Shtylyov

Hello.

On 8/6/2015 10:58 AM, Robert Baldyga wrote:


Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.



Signed-off-by: Robert Baldyga 
---
  drivers/usb/gadget/epautoconf.c   | 20 ++--
  drivers/usb/gadget/udc/goku_udc.c | 25 +
  2 files changed, 27 insertions(+), 18 deletions(-)



diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 0ff5134..574b6a4 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,24 +86,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
-   if (gadget_is_goku(gadget)) {
-   if (USB_ENDPOINT_XFER_INT == type) {
-   /* single buffering is enough */
-   ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   } else if (USB_ENDPOINT_XFER_BULK == type
-   && (USB_DIR_IN & desc->bEndpointAddress)) {
-   /* DMA may be available */
-   ep = gadget_find_ep_by_name(gadget, "ep2-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   }
-
  #ifdef CONFIG_BLACKFIN
-   } else if (gadget_is_musbhdrc(gadget)) {
+   if (gadget_is_musbhdrc(gadget)) {
if ((USB_ENDPOINT_XFER_BULK == type) ||
(USB_ENDPOINT_XFER_ISOC == type)) {
if (USB_DIR_IN & desc->bEndpointAddress)
@@ -119,8 +103,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
ep = NULL;
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
-#endif
}
+#endif

/* Second, look at endpoints until an unclaimed one looks usable */
list_for_each_entry (ep, &gadget->ep_list, ep_list) {
diff --git a/drivers/usb/gadget/udc/goku_udc.c 
b/drivers/usb/gadget/udc/goku_udc.c
index 46b8d14..d5a93ea 100644
--- a/drivers/usb/gadget/udc/goku_udc.c
+++ b/drivers/usb/gadget/udc/goku_udc.c
@@ -990,6 +990,30 @@ static int goku_get_frame(struct usb_gadget *_gadget)
return -EOPNOTSUPP;
  }

+static struct usb_ep *goku_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct goku_udc *dev = to_goku_udc(g);
+   struct usb_ep *ep;
+   u8 type = usb_endpoint_type(desc);
+
+   if (type == USB_ENDPOINT_XFER_INT) {
+   /* single buffering is enough */
+   ep = &dev->ep[3].ep;
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+   } else if (type == USB_ENDPOINT_XFER_BULK
+   && usb_endpoint_dir_in(desc)) {
+   /* DMA may be available */
+   ep = &dev->ep[2].ep;
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;


   You used *switch* in the MUSB driver but not here, despite the above is 
also asking for *switch*. Why? :-)



+   }
+
+   return NULL;
+}
+


MBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Re: [PATCH v3]USB:OHCI: BugFix:Proper handling of ed_rm_list to handle race condition between usb_kill_urb() and finish_unlinks()

2015-08-06 Thread AMAN DEEP
Dear Alan

sorry for late reply.

>This patch has been difficult to coordinate because it affects exactly
>the same code as another recent fix (I really goofed when writing the
>977dcfdc6031 commit).  Here's my version of it, based on Greg's
>usb-linus branch as of about a week ago; the topmost commit was
>1209544d8a2a.
>
>Aman, if this matches what you've got then you can resubmit it to Greg.
>
Actually i am out of station till 9th August for some urgent work.
I will be able to check the patch on 10th August.
i will re-submit the patch on 10th August.


Thanks & Regards,
Aman Deep

--- Original Message ---
Sender : Alan Stern
Date : Aug 04, 2015 20:15 (GMT+06:00)
Title : Re: [PATCH v3]USB:OHCI: BugFix:Proper handling of ed_rm_list to handle 
race condition between usb_kill_urb() and finish_unlinks()

On Mon, 3 Aug 2015, Greg KH wrote:

> On Thu, Jul 23, 2015 at 12:50:26PM +, AMAN DEEP wrote:
> > There is a race condition between 
> >  finish_unlinks->finish_urb() function and 
> >  usb_kill_urb() in ohci controller case. The finish_urb 
> >  calls spin_unlock(&ohci->lock) before 
> >  usb_hcd_giveback_urb() function call, then if during 
> >  this time, usb_kill_urb is called for another endpoint,
> >   then new ed will be added to ed_rm_list at beginning 
> >  for unlink. and ed_rm_list will point to newly added 
> >  ed.
> > 
> > When finish_urb() is completed in finish_unlinks() and
> > ed->td_list becomes empty as in below code (in finish_unlinks() function)
> > if (list_empty(&ed->td_list)) {
> > *last = ed->ed_next;
> > ed->ed_next = NULL;
> > } else if (ohci->rh_state == OHCI_RH_RUNNING) {
> > *last = ed->ed_next;
> > ed->ed_next = NULL;
> > ed_schedule(ohci, ed);
> > }
> > *last = ed->ed_next will make ed_rm_list to point to ed->ed_next and
> > previously added ed by usb_kill_urb will be left unreferenced by
> > ed_rm_list. This causes usb_kill_urb() hang forever waiting for
> > finish_unlink to remove added ed from ed_rm_list.
> > 
> > The main reason for hang in this race condtion is addition and removal
> > of ed from ed_rm_list in the beginning during usb_kill_urb and later last*
> > is modified in finish_unlinks().
> > As suggested by Alan Stern, the solution for proper handling of
> > ohci->ed_rm_list is to remove ed from the ed_rm_list before finishing
> > any URBs. Then at the end, we can add ed back to the list if necessary.
> > This properly handle the updated ohci->ed_rm_list in
> > usb_kill_urb().
> > 
> > Fixes:977dcfdc6031("USB:OHCI:don't lose track of EDs when a 
> > controller dies")
> > 
> > Acked-by: Alan Stern 
> > 
> > Signed-off-by: Aman Deep 
> > CC: 
> > ---
> >  drivers/usb/host/ohci-q.c |   17 ++---
> >  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> This patch isn't applying at all.  What kernel version are you making it
> against?

This patch has been difficult to coordinate because it affects exactly
the same code as another recent fix (I really goofed when writing the
977dcfdc6031 commit).  Here's my version of it, based on Greg's
usb-linus branch as of about a week ago; the topmost commit was
1209544d8a2a.

Aman, if this matches what you've got then you can resubmit it to Greg.

Alan Stern



Index: usb-4.2/drivers/usb/host/ohci-q.c
===
--- usb-4.2.orig/drivers/usb/host/ohci-q.c
+++ usb-4.2/drivers/usb/host/ohci-q.c
@@ -1017,6 +1017,8 @@ skip_ed:
* have modified this list.  normally it's just prepending
* entries (which we'd ignore), but paranoia won't hurt.
*/
+ *last = ed->ed_next;
+ ed->ed_next = NULL;
modified = 0;

/* unlink urbs as requested, but rescan the list after
@@ -1075,21 +1077,22 @@ rescan_this:
goto rescan_this;

/*
- * If no TDs are queued, take ED off the ed_rm_list.
+ * If no TDs are queued, ED is now idle.
* Otherwise, if the HC is running, reschedule.
- * If not, leave it on the list for further dequeues.
+ * If the HC isn't running, add ED back to the
+ * start of the list for later processing.
*/
if (list_empty(&ed->td_list)) {
- *last = ed->ed_next;
- ed->ed_next = NULL;
ed->state = ED_IDLE;
list_del(&ed->in_use_list);
} else if (ohci->rh_state == OHCI_RH_RUNNING) {
- *last = ed->ed_next;
- ed->ed_next = NULL;
ed_schedule(ohci, ed);
} else {
- last = &ed->ed_next;
+ ed->ed_next = ohci->ed_rm_list;
+ ohci->ed_rm_list = ed;
+ /* Don't loop on the same ED */
+ if (last == &ohci->ed_rm_list)
+ last = &ed->ed_next;
}

if (modified)




Re: [PATCH] drivers/usb: Delete XHCI command timer if necessary

2015-08-06 Thread Gavin Shan
On Thu, Aug 06, 2015 at 10:37:11AM +0300, Mathias Nyman wrote:
>On 06.08.2015 02:29, Greg KH wrote:
>> On Thu, Aug 06, 2015 at 09:13:12AM +1000, Gavin Shan wrote:
>>> On Mon, Jul 27, 2015 at 12:08:05PM +1000, Gavin Shan wrote:
 When xhci_mem_cleanup() is called, it's possible that the command
 timer isn't initialized and scheduled. For those cases, to delete
 the command timer causes soft-lockup as below stack dump shows.

 The patch avoids deleting the command timer if it's not scheduled
 with the help of timer_pending().

 NMI watchdog: BUG: soft lockup - CPU#40 stuck for 23s! [kworker/40:1:8140]
  :
 NIP [c0150b30] lock_timer_base.isra.34+0x90/0xa0
 LR [c0150c24] try_to_del_timer_sync+0x34/0xa0
 Call Trace:
 [c00f67c975e0] [c15b84f8] mon_ops+0x0/0x8 (unreliable)
 [c00f67c97620] [c0150c24] try_to_del_timer_sync+0x34/0xa0
 [c00f67c97660] [c0150cf0] del_timer_sync+0x60/0x80
 [c00f67c97690] [c070ac0c] xhci_mem_cleanup+0x5c/0x5e0
 [c00f67c97740] [c070c2e8] xhci_mem_init+0x1158/0x13b0
 [c00f67c97860] [c0700978] xhci_init+0x88/0x110
 [c00f67c978e0] [c0701644] xhci_gen_setup+0x2b4/0x590
 [c00f67c97970] [c06d4410] xhci_pci_setup+0x40/0x190
 [c00f67c979f0] [c06b1af8] usb_add_hcd+0x418/0xba0
 [c00f67c97ab0] [c06cb15c] usb_hcd_pci_probe+0x1dc/0x5c0
 [c00f67c97b50] [c06d3ba4] xhci_pci_probe+0x64/0x1f0
 [c00f67c97ba0] [c04fe9ac] local_pci_probe+0x6c/0x130
 [c00f67c97c30] [c00e5ce8] work_for_cpu_fn+0x38/0x60
 [c00f67c97c60] [c00eacb8] process_one_work+0x198/0x470
 [c00f67c97cf0] [c00eb6ac] worker_thread+0x37c/0x5a0
 [c00f67c97d80] [c00f2730] kthread+0x110/0x130
 [c00f67c97e30] [c0009660] ret_from_kernel_thread+0x5c/0x7c

 Reported-by: Priya M. A 
 Signed-off-by: Gavin Shan 
>>>
>>> ping?
>> 
>> The driver maintainer is on vacation, please give him a chance to get
>> back and catch up.
>> 
>
>This one is already applied, but author wasn't notified about it. 
>In Greg's usb-linus:
>
>commit ffe5adcb7661d94e952d6b5ed7f493cb4ef0c7bc
>Author: Gavin Shan 
>Date:   Mon Aug 3 16:07:49 2015 +0300
>drivers/usb: Delete XHCI command timer if necessary
>

Thanks, Mathias and Greg.

Gavin

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH][v2] drivers: usb: fsl: Workaround for USB erratum-A005275

2015-08-06 Thread Nikhil Badola
Incoming packets in high speed are randomly corrupted by h/w
resulting in multiple errors. This workaround makes FS as
default mode in all affected socs by disabling HS chirp
signalling.This errata does not affect FS and LS mode.

Forces all HS devices to connect in FS mode for all socs
affected by this erratum:
P3041 and P2041 rev 1.0 and 1.1
P5020 and P5010 rev 1.0 and 2.0
P5040, P1010 and T4240 rev 1.0

Signed-off-by: Ramneek Mehresh 
Signed-off-by: Nikhil Badola 
---
changes for v2: 
- Changed PFSC bit writing hunk position
- Changed ehci_has_fsl_hs_errata(e) definition hunk position

 drivers/usb/host/ehci-fsl.c  |  4 
 drivers/usb/host/ehci-hub.c  |  7 +++
 drivers/usb/host/ehci.h  | 12 
 drivers/usb/host/fsl-mph-dr-of.c |  4 
 include/linux/fsl_devices.h  |  1 +
 5 files changed, 28 insertions(+)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 202dafb..3b6eb21 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -278,6 +278,10 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x8000 | 
SNOOP_SIZE_2GB);
}
 
+   /* Deal with USB erratum A-005275 */
+   if (pdata->has_fsl_erratum_a005275 == 1)
+   ehci->has_fsl_hs_errata = 1;
+
if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
(pdata->operating_mode == FSL_USB2_DR_OTG))
if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 22abb68..086a711 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -1221,6 +1221,13 @@ int ehci_hub_control(
 */
ehci->reset_done [wIndex] = jiffies
+ msecs_to_jiffies (50);
+
+   /*
+* Force full-speed connect for FSL high-speed
+* erratum; disable HS Chirp by setting PFSC bit
+*/
+   if (ehci_has_fsl_hs_errata(ehci))
+   temp |= (1 << PORTSC_FSL_PFSC);
}
ehci_writel(ehci, temp, status_reg);
break;
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index f700157..46f62e4 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -215,6 +215,7 @@ struct ehci_hcd {   /* one per controller */
/* SILICON QUIRKS */
unsignedno_selective_suspend:1;
unsignedhas_fsl_port_bug:1; /* FreeScale */
+   unsignedhas_fsl_hs_errata:1;/* Freescale HS quirk */
unsignedbig_endian_mmio:1;
unsignedbig_endian_desc:1;
unsignedbig_endian_capbase:1;
@@ -686,6 +687,17 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
 #defineehci_has_fsl_portno_bug(e)  (0)
 #endif
 
+#define PORTSC_FSL_PFSC24  /* Port Force Full-Speed Connect */
+
+#if defined(CONFIG_PPC_85xx)
+/* Some Freescale processors have an erratum (USB A-005275) in which
+ * incoming packets get corrupted in HS mode
+ */
+#define ehci_has_fsl_hs_errata(e)  ((e)->has_fsl_hs_errata)
+#else
+#define ehci_has_fsl_hs_errata(e)  (0)
+#endif
+
 /*
  * While most USB host controllers implement their registers in
  * little-endian format, a minority (celleb companion chip) implement
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index 9f73141..534c4c5 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -221,6 +221,10 @@ static int fsl_usb2_mph_dr_of_probe(struct platform_device 
*ofdev)
pdata->has_fsl_erratum_a007792 = 1;
else
pdata->has_fsl_erratum_a007792 = 0;
+   if (of_get_property(np, "fsl,usb-erratum-a005275", NULL))
+   pdata->has_fsl_erratum_a005275 = 1;
+   else
+   pdata->has_fsl_erratum_a005275 = 0;
 
/*
 * Determine whether phy_clk_valid needs to be checked
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index cebdbbb..f291291 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -99,6 +99,7 @@ struct fsl_usb2_platform_data {
unsignedsuspended:1;
unsignedalready_suspended:1;
unsignedhas_fsl_erratum_a007792:1;
+   unsignedhas_fsl_erratum_a005275:1;
unsignedcheck_phy_clk_valid:1;
 
/* register save area for suspend/resume */
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
Mor

Re: [PATCH 10/10] ARM: dts: omap4: Use "syscon-otghs" instead of "ctrl-module" in USB node

2015-08-06 Thread Tony Lindgren
* Kishon Vijay Abraham I  [150805 07:28]:
> Hi Roger,
> 
> On Wednesday 05 August 2015 01:38 PM, Roger Quadros wrote:
> > On 05/08/15 11:02, Roger Quadros wrote:
> >> Kishon,
> >>
> >> On 04/08/15 18:30, Kishon Vijay Abraham I wrote:
> >>> Add "syscon-otghs" property and remove the deprecated "ctrl-module"
> >>> property from MUSB devicetree node.
> >>>
> >>> Since "omap_control_usbotg" devicetree node is no longer used, remove
> >>> it.
> >>>
> >>> Signed-off-by: Kishon Vijay Abraham I 
> >>> ---
> >>>  arch/arm/boot/dts/omap4.dtsi |8 +---
> >>>  1 file changed, 1 insertion(+), 7 deletions(-)
> >>>
> >>> diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
> >>> index b27634d..2fb49a5 100644
> >>> --- a/arch/arm/boot/dts/omap4.dtsi
> >>> +++ b/arch/arm/boot/dts/omap4.dtsi
> >>> @@ -854,12 +854,6 @@
> >>>   };
> >>>   };
> >>>  
> >>> - omap_control_usbotg: control-phy@4a00233c {
> >>> - compatible = "ti,control-phy-otghs";
> >>> - reg = <0x4a00233c 0x4>;
> >>> - reg-names = "otghs_control";
> >>> - };
> >>> -
> >>>   usb_otg_hs: usb_otg_hs@4a0ab000 {
> >>>   compatible = "ti,omap4-musb";
> >>>   reg = <0x4a0ab000 0x7ff>;
> >>> @@ -872,7 +866,7 @@
> >>>   multipoint = <1>;
> >>>   num-eps = <16>;
> >>>   ram-bits = <12>;
> >>> - ctrl-module = <&omap_control_usbotg>;
> >>> + syscon-otghs = <&scm_conf 0x33c>;
> >>
> >> All other properties were of the format "syscon-phy-foo".
> >> Why use a different format here?
> >>
> > 
> > Ah, looks like we don't have a dedicated phy driver for this?
> > We will need to add a PHY driver I guess then and handle this register
> > in that driver rather than in the musb driver.
> 
> I was explaining in the other thread to Tony on why this shouldn't be done in 
> a
> PHY driver [1].

And I just suggested thhere that it should be in the drivers/phy/phy-omap-usb2.c
PHY driver instead of the MUSB driver.

Regards,

Tony 
 
> [1] -> https://lkml.org/lkml/2015/8/5/455
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: musb: omap2430: use *syscon* framework API to write to mailbox register

2015-08-06 Thread Tony Lindgren
* Kishon Vijay Abraham I  [150805 07:10]:
> On Wednesday 05 August 2015 01:31 PM, Tony Lindgren wrote:
> > 
> > We don't have syscon-otghs and to me it seems we need a PHY driver
> > as I pointed out at:
> 
> If *syscon-otghs* is not present, then it'll fall-back to using the 
> *ctrl-module*.

OK great.

> > 
> > https://lkml.org/lkml/2015/6/24/231
> 
> Maybe I should have explained this in the previous thread. The *otghs* 
> register
> that we are trying to access here does _not_ belong to the PHY. It acts as
> mailbox register from MUSB glue (TI integration layer) to MUSB core. That's 
> why
> it's programmed in the TI glue layer (omap2430.c).
> 
> Even when we were using the older API [omap_control_usb_set_mode()], we first
> call omap_musb_mailbox from the PHY drivers (phy-twl4030-usb.c,
> phy-twl6030-usb.c) and then omap_musb_mailbox in the TI glue writes to the
> control module instead of PHY drivers directly calling 
> omap_control_usb_set_mode().

Hmm looking at "Table 18-204. CONTROL_USBOTGHS_CONTROL" it seems to mention
"transceiver" for quite a few bitfields :) Probably what that register does
is control a PHY over ULPI.

So from Linux kernel point of view we're best off treating it as a PHY.
It seems it should have a minimal PHY driver similar to what we have for
dm816x control module in drivers/phy/phy-dm816x-usb.c.

For reference, here is the register bitfields pasted from 4460 TRM:

Table 18-204. CONTROL_USBOTGHS_CONTROL, p3972
Physical Address 0x4A00 233C

BIT NAMEDESCIPTION
8   DISCHRGVBUS ... OTG transceiver does (not) discharge VBUS ...
7   CHRGVBUS... OTG transceiver does (not) charge VBUS ...
6   IDPULLUP... OTG transceiver does (not) drive VBUS ...
4   IDDIG   ... OTG transceiver does (not) apply a pullup to ID ...
3   SESSEND ... VBUS voltage is above/below VB_SESS_END ... 
2   VBUSVALID   ... VBUS is above the threshold ...
1   BVALID  ... VBUS voltage is above/below VB_SESS_VLD ...
0   AVALID  ... BUS voltage is above/below VA_SESS_VLD ...

So how about just adding ONTROL_USBOTGHS_CONTROL support to the existing
drivers/phy/phy-omap-usb2.c instead? It seems that it should allow us
to completely get rid of the custom mailbox stuff for MUSB 2430 support?

> > So let's sort that issue first. It also seems this just completely
> > breaks the MUSB support?
> 
> Why do you think so? If *syscon-otghs* is not present in dt, then it'll
> fall-back to using the *ctrl-module* and everything should work seamlessly.

OK that's good to hear. IMO drivers/phy/phy-omap4.c or similar should
manage the syscon-otghs syscon register, not MUSB driver.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [linux-sunxi] [PATCH] musb: sunxi: Ignore VBus errors in host-only mode

2015-08-06 Thread Olliver Schinagl

Hey Hans,

I've tried getting your musb stuff working on a cubietruck, but i don't 
seem to see this patch on your linux-sunxi/sunxi-wip branch on github? 
Is your github branch fully functional at the moment?


What I have done so far, is build the kernel using sunxi_defconfig and 
enabled USB_MUSB_SUNXI with its dependancies (musb isn't enabled there 
by default): USB_SUPPORT [=y] && USB_MUSB_HDRC [=y] && ARCH_SUNXI [=y] 
&& NOP_USB_XCEIV [=y] && PHY_SUN4I_USB [=y] && EXTCON [=y] && 
GENERIC_PHY [=y]  Selects: SUNXI_SRAM [=y]


I changed the dts from dr_mode='otg' to dr_mode='host', a) we only need 
host mode anyway (the id pin isn't properly connected) and b) I got an 
error about an known dr_mode before and this was the quick and easy way.


Dmesg produces the following related to musb.

[1.691062] usb_phy_generic.0.auto supply vcc not found, using dummy 
regulator
[1.691445] musb-hdrc: ConfigData=0xde (UTMI-8, dyn FIFOs, bulk 
combine, bulk split, HB-ISO Rx, HB-ISO Tx, SoftConn)

[1.691453] musb-hdrc: MHDRC RTL version 0.0
[1.691467] musb-hdrc: 11/11 max ep, 5184/8192 memory
[1.691543] musb-hdrc musb-hdrc.1.auto: MUSB HDRC host driver
[1.691553] musb-hdrc musb-hdrc.1.auto: new USB bus registered, 
assigned bus number 5

[1.692470] hub 5-0:1.0: USB hub found
[1.692529] hub 5-0:1.0: 1 port detected
[1.699956] sunxi-rtc 1c20d00.rtc: setting system clock to 2015-08-06 
07:59:08 UTC (1438847948)

[1.704733] usb0-vbus: disabling
[1.765695] ldo4: disabling
[1.808351] ldo3: disabling
[1.848769] vcc5v0: disabling
[1.848774] vcc3v0: disabling

The usb_phy_generic missing shouldn't be too bad? But the usb0-vbus 
being disabled obviously might be related to the musb port not working? 
What causes this though? I went through all the musb patch series mails 
but don't recall seing anything special being needed.


If there are fixes missing in the sunxi-next stuff that could explain 
this, could you be so kind and push your latest work so I can try it? 
Thanks Hans!


Olliver

On 04-08-15 23:25, Hans de Goede wrote:

For some unclear reason sometimes we get VBus errors in host-only mode,
even though we do not have any vbus-detection then. Ignore these.

Signed-off-by: Hans de Goede 
---
  drivers/usb/musb/sunxi.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index f9f6304..34ce5df 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -194,6 +194,10 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void 
*__hci)
musb_writeb(musb->mregs, MUSB_FADDR, 0);
}
  
+	/*  Ignore Vbus errors when in host only mode */

+   if (musb->port_mode == MUSB_PORT_MODE_HOST)
+   musb->int_usb &= ~MUSB_INTR_VBUSERROR;
+
musb->int_tx = readw(musb->mregs + SUNXI_MUSB_INTRTX);
if (musb->int_tx)
writew(musb->int_tx, musb->mregs + SUNXI_MUSB_INTRTX);


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 0/8] usb: gadget: rework ep matching and claiming mechanism

2015-08-06 Thread Robert Baldyga
Hi Felipe,

These are remaining patches of my series plus one which remained from
series [1].

In this version of this patch set I have changed gadget_find_ep_by_name()
to exported symbol, as Alan suggested.

[1] usb: gadget: get rid of UDC name-based quirks
https://lkml.org/lkml/2015/7/28/29

Best regards,
Robert Baldyga

Changelog:

v7:
- make gadget_find_ep_by_name() exported symbol instead of static inline
  as Alan Stern suggested

v6: https://lkml.org/lkml/2015/8/5/312
- fix regression in ep_matches() function

v5: https://lkml.org/lkml/2015/7/31/402
- made code more grepable according to Felipe's suggestion

v4: https://lkml.org/lkml/2015/7/27/181
- addressed comments from Krzysztof Opasiak and Felipe Balbi

v3: https://lkml.org/lkml/2015/7/15/68
- addressed comments from Sergei Shtylyov

v2: https://lkml.org/lkml/2015/7/14/172
- remove PXA quirk from ep_matches() function without behaviour change
  using ep capabilities flags
- separate ep and desc configuration code from ep_match() function
- add 'ep_match' to usb_gadget_ops and move chip-specific endpoint
  matching algorithms from generic code to UDC controller drivers

v1: https://lkml.org/lkml/2015/7/8/436

Robert Baldyga (8):
  usb: gadget: epautoconf: rework ep_matches() function
  usb: gadget: add 'ep_match' callback to usb_gadget_ops
  usb: gadget: move ep_matches() from epautoconf to udc-core
  usb: gadget: move find_ep() from epautoconf to udc-core
  usb: gadget: net2280: add net2280_match_ep() function
  usb: gadget: goku_udc: add goku_match_ep() function
  usb: musb: gadget: add musb_match_ep() function
  usb: gadget: remove gadget_chips.h

 drivers/usb/gadget/epautoconf.c  | 166 +--
 drivers/usb/gadget/function/f_acm.c  |   1 -
 drivers/usb/gadget/function/f_mass_storage.c |   1 -
 drivers/usb/gadget/function/f_obex.c |   1 -
 drivers/usb/gadget/function/f_serial.c   |   1 -
 drivers/usb/gadget/function/f_sourcesink.c   |   1 -
 drivers/usb/gadget/function/u_ether.h|   2 -
 drivers/usb/gadget/function/u_uac1.h |   2 -
 drivers/usb/gadget/legacy/audio.c|   1 -
 drivers/usb/gadget/legacy/gmidi.c|   2 -
 drivers/usb/gadget/legacy/hid.c  |   1 -
 drivers/usb/gadget/legacy/nokia.c|   1 -
 drivers/usb/gadget/legacy/printer.c  |   2 -
 drivers/usb/gadget/legacy/serial.c   |   1 -
 drivers/usb/gadget/udc/gadget_chips.h|  55 -
 drivers/usb/gadget/udc/goku_udc.c|  25 
 drivers/usb/gadget/udc/net2280.c |  31 +
 drivers/usb/gadget/udc/udc-core.c|  90 +++
 drivers/usb/musb/musb_gadget.c   |  34 ++
 include/linux/usb/gadget.h   |  19 ++-
 20 files changed, 202 insertions(+), 235 deletions(-)
 delete mode 100644 drivers/usb/gadget/udc/gadget_chips.h

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/8] usb: gadget: epautoconf: rework ep_matches() function

2015-08-06 Thread Robert Baldyga
Rework ep_matches() function to make it shorter and more readable.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 81 -
 1 file changed, 32 insertions(+), 49 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 52658fe..95e1275 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -32,7 +32,6 @@ ep_matches (
 {
u8  type;
u16 max;
-
int num_req_streams = 0;
 
/* endpoint already claimed? */
@@ -40,6 +39,20 @@ ep_matches (
return 0;
 
type = usb_endpoint_type(desc);
+   max = 0x7ff & usb_endpoint_maxp(desc);
+
+   if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
+   return 0;
+   if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
+   return 0;
+
+   if (max > ep->maxpacket_limit)
+   return 0;
+
+   /* "high bandwidth" works only at high speed */
+   if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
+   return 0;
+
switch (type) {
case USB_ENDPOINT_XFER_CONTROL:
/* only support ep0 for portable CONTROL traffic */
@@ -47,66 +60,36 @@ ep_matches (
case USB_ENDPOINT_XFER_ISOC:
if (!ep->caps.type_iso)
return 0;
+   /* ISO:  limit 1023 bytes full speed,
+* 1024 high/super speed
+*/
+   if (!gadget_is_dualspeed(gadget) && max > 1023)
+   return 0;
break;
case USB_ENDPOINT_XFER_BULK:
if (!ep->caps.type_bulk)
return 0;
+   if (ep_comp && gadget_is_superspeed(gadget)) {
+   /* Get the number of required streams from the
+* EP companion descriptor and see if the EP
+* matches it
+*/
+   num_req_streams = ep_comp->bmAttributes & 0x1f;
+   if (num_req_streams > ep->max_streams)
+   return 0;
+   }
break;
case USB_ENDPOINT_XFER_INT:
-   /* bulk endpoints handle interrupt transfers,
+   /* Bulk endpoints handle interrupt transfers,
 * except the toggle-quirky iso-synch kind
 */
if (!ep->caps.type_int && !ep->caps.type_bulk)
return 0;
-   break;
-   }
-
-   if (usb_endpoint_dir_in(desc)) {
-   if (!ep->caps.dir_in)
-   return 0;
-   } else {
-   if (!ep->caps.dir_out)
-   return 0;
-   }
-
-   /*
-* Get the number of required streams from the EP companion
-* descriptor and see if the EP matches it
-*/
-   if (usb_endpoint_xfer_bulk(desc)) {
-   if (ep_comp && gadget->max_speed >= USB_SPEED_SUPER) {
-   num_req_streams = ep_comp->bmAttributes & 0x1f;
-   if (num_req_streams > ep->max_streams)
-   return 0;
-   }
-
-   }
-
-   /* endpoint maxpacket size is an input parameter, except for bulk
-* where it's an output parameter representing the full speed limit.
-* the usb spec fixes high speed bulk maxpacket at 512 bytes.
-*/
-   max = 0x7ff & usb_endpoint_maxp(desc);
-   switch (type) {
-   case USB_ENDPOINT_XFER_INT:
-   /* INT:  limit 64 bytes full speed, 1024 high/super speed */
+   /* INT:  limit 64 bytes full speed,
+* 1024 high/super speed
+*/
if (!gadget_is_dualspeed(gadget) && max > 64)
return 0;
-   /* FALLTHROUGH */
-
-   case USB_ENDPOINT_XFER_ISOC:
-   /* ISO:  limit 1023 bytes full speed, 1024 high/super speed */
-   if (ep->maxpacket_limit < max)
-   return 0;
-   if (!gadget_is_dualspeed(gadget) && max > 1023)
-   return 0;
-
-   /* BOTH:  "high bandwidth" works only at high speed */
-   if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
-   if (!gadget_is_dualspeed(gadget))
-   return 0;
-   /* configure your hardware with enough buffering!! */
-   }
break;
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 5/8] usb: gadget: net2280: add net2280_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c  | 23 +--
 drivers/usb/gadget/udc/net2280.c | 31 +++
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index a39ca03..0ff5134 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,28 +86,7 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
-   if (gadget_is_net2280(gadget)) {
-   char name[8];
-
-   if (type == USB_ENDPOINT_XFER_INT) {
-   /* ep-e, ep-f are PIO with only 64 byte fifos */
-   ep = gadget_find_ep_by_name(gadget, "ep-e");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   ep = gadget_find_ep_by_name(gadget, "ep-f");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   }
-
-   /* USB3380: use same address for usb and hardware endpoints */
-   snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
-   usb_endpoint_dir_in(desc) ? "in" : "out");
-   ep = gadget_find_ep_by_name(gadget, name);
-   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
-   goto found_ep;
-   } else if (gadget_is_goku (gadget)) {
+   if (gadget_is_goku(gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 872ca25..9d7eac1 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -1550,6 +1550,36 @@ static int net2280_pullup(struct usb_gadget *_gadget, 
int is_on)
return 0;
 }
 
+static struct usb_ep *net2280_match_ep(struct usb_gadget *_gadget,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   char name[8];
+   struct usb_ep *ep;
+   u8 type;
+
+   type = usb_endpoint_type(desc);
+
+   if (type == USB_ENDPOINT_XFER_INT) {
+   /* ep-e, ep-f are PIO with only 64 byte fifos */
+   ep = gadget_find_ep_by_name(_gadget, "ep-e");
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+   ep = gadget_find_ep_by_name(_gadget, "ep-f");
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+   }
+
+   /* USB3380: use same address for usb and hardware endpoints */
+   snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
+   usb_endpoint_dir_in(desc) ? "in" : "out");
+   ep = gadget_find_ep_by_name(_gadget, name);
+   if (ep && usb_gadget_ep_match_desc(_gadget, ep, desc, ep_comp))
+   return ep;
+
+   return NULL;
+}
+
 static int net2280_start(struct usb_gadget *_gadget,
struct usb_gadget_driver *driver);
 static int net2280_stop(struct usb_gadget *_gadget);
@@ -1561,6 +1591,7 @@ static const struct usb_gadget_ops net2280_ops = {
.pullup = net2280_pullup,
.udc_start  = net2280_start,
.udc_stop   = net2280_stop,
+   .match_ep   = net2280_match_ep,
 };
 
 /*-*/
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 2/8] usb: gadget: add 'ep_match' callback to usb_gadget_ops

2015-08-06 Thread Robert Baldyga
Add callback that is called by epautoconf to allow UDC driver match the
best endpoint for specific descriptor. It's intended to supply mechanism
which allows to get rid of chip-specific endpoint matching code from
epautoconf.

If gadget has set 'ep_match' callback we prefer to call it first, and
if it fails to find matching endpoint, then we try to use default matching
algorithm.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 6 ++
 include/linux/usb/gadget.h  | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 95e1275..f000c73 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -165,6 +165,12 @@ struct usb_ep *usb_ep_autoconfig_ss(
 
type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 
+   if (gadget->ops->match_ep) {
+   ep = gadget->ops->match_ep(gadget, desc, ep_comp);
+   if (ep)
+   goto found_ep;
+   }
+
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 82b5bcb..303214b 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -534,6 +534,9 @@ struct usb_gadget_ops {
int (*udc_start)(struct usb_gadget *,
struct usb_gadget_driver *);
int (*udc_stop)(struct usb_gadget *);
+   struct usb_ep *(*match_ep)(struct usb_gadget *,
+   struct usb_endpoint_descriptor *,
+   struct usb_ss_ep_comp_descriptor *);
 };
 
 /**
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 3/8] usb: gadget: move ep_matches() from epautoconf to udc-core

2015-08-06 Thread Robert Baldyga
Move ep_matches() function to udc-core and rename it to
usb_gadget_ep_match_desc(). This function can be used by UDC drivers
in 'match_ep' callback to avoid writing lots of repetitive code.

Replace all calls of ep_matches() with usb_gadget_ep_match_desc().

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 95 +--
 drivers/usb/gadget/udc/udc-core.c | 69 
 include/linux/usb/gadget.h|  8 
 3 files changed, 88 insertions(+), 84 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index f000c73..d49af4f 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -22,82 +22,6 @@
 
 #include "gadget_chips.h"
 
-static int
-ep_matches (
-   struct usb_gadget   *gadget,
-   struct usb_ep   *ep,
-   struct usb_endpoint_descriptor  *desc,
-   struct usb_ss_ep_comp_descriptor *ep_comp
-)
-{
-   u8  type;
-   u16 max;
-   int num_req_streams = 0;
-
-   /* endpoint already claimed? */
-   if (ep->claimed)
-   return 0;
-
-   type = usb_endpoint_type(desc);
-   max = 0x7ff & usb_endpoint_maxp(desc);
-
-   if (usb_endpoint_dir_in(desc) && !ep->caps.dir_in)
-   return 0;
-   if (usb_endpoint_dir_out(desc) && !ep->caps.dir_out)
-   return 0;
-
-   if (max > ep->maxpacket_limit)
-   return 0;
-
-   /* "high bandwidth" works only at high speed */
-   if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp(desc) & (3<<11))
-   return 0;
-
-   switch (type) {
-   case USB_ENDPOINT_XFER_CONTROL:
-   /* only support ep0 for portable CONTROL traffic */
-   return 0;
-   case USB_ENDPOINT_XFER_ISOC:
-   if (!ep->caps.type_iso)
-   return 0;
-   /* ISO:  limit 1023 bytes full speed,
-* 1024 high/super speed
-*/
-   if (!gadget_is_dualspeed(gadget) && max > 1023)
-   return 0;
-   break;
-   case USB_ENDPOINT_XFER_BULK:
-   if (!ep->caps.type_bulk)
-   return 0;
-   if (ep_comp && gadget_is_superspeed(gadget)) {
-   /* Get the number of required streams from the
-* EP companion descriptor and see if the EP
-* matches it
-*/
-   num_req_streams = ep_comp->bmAttributes & 0x1f;
-   if (num_req_streams > ep->max_streams)
-   return 0;
-   }
-   break;
-   case USB_ENDPOINT_XFER_INT:
-   /* Bulk endpoints handle interrupt transfers,
-* except the toggle-quirky iso-synch kind
-*/
-   if (!ep->caps.type_int && !ep->caps.type_bulk)
-   return 0;
-   /* INT:  limit 64 bytes full speed,
-* 1024 high/super speed
-*/
-   if (!gadget_is_dualspeed(gadget) && max > 64)
-   return 0;
-   break;
-   }
-
-   /* MATCH!! */
-
-   return 1;
-}
-
 static struct usb_ep *
 find_ep (struct usb_gadget *gadget, const char *name)
 {
@@ -180,10 +104,12 @@ struct usb_ep *usb_ep_autoconfig_ss(
if (type == USB_ENDPOINT_XFER_INT) {
/* ep-e, ep-f are PIO with only 64 byte fifos */
ep = find_ep(gadget, "ep-e");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget,
+   ep, desc, ep_comp))
goto found_ep;
ep = find_ep(gadget, "ep-f");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget,
+   ep, desc, ep_comp))
goto found_ep;
}
 
@@ -191,20 +117,21 @@ struct usb_ep *usb_ep_autoconfig_ss(
snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
usb_endpoint_dir_in(desc) ? "in" : "out");
ep = find_ep(gadget, name);
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
} else if (gadget_is_goku (gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
ep = find_ep(gadget, "ep3-bulk");
-   if (ep && ep_matches(gadget, ep, desc, ep_comp))
+  

[PATCH v7 6/8] usb: gadget: goku_udc: add goku_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 20 ++--
 drivers/usb/gadget/udc/goku_udc.c | 25 +
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 0ff5134..574b6a4 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -86,24 +86,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* First, apply chip-specific "best usage" knowledge.
 * This might make a good usb_gadget_ops hook ...
 */
-   if (gadget_is_goku(gadget)) {
-   if (USB_ENDPOINT_XFER_INT == type) {
-   /* single buffering is enough */
-   ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   } else if (USB_ENDPOINT_XFER_BULK == type
-   && (USB_DIR_IN & desc->bEndpointAddress)) {
-   /* DMA may be available */
-   ep = gadget_find_ep_by_name(gadget, "ep2-bulk");
-   if (ep && usb_gadget_ep_match_desc(gadget,
-   ep, desc, ep_comp))
-   goto found_ep;
-   }
-
 #ifdef CONFIG_BLACKFIN
-   } else if (gadget_is_musbhdrc(gadget)) {
+   if (gadget_is_musbhdrc(gadget)) {
if ((USB_ENDPOINT_XFER_BULK == type) ||
(USB_ENDPOINT_XFER_ISOC == type)) {
if (USB_DIR_IN & desc->bEndpointAddress)
@@ -119,8 +103,8 @@ struct usb_ep *usb_ep_autoconfig_ss(
ep = NULL;
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
-#endif
}
+#endif
 
/* Second, look at endpoints until an unclaimed one looks usable */
list_for_each_entry (ep, &gadget->ep_list, ep_list) {
diff --git a/drivers/usb/gadget/udc/goku_udc.c 
b/drivers/usb/gadget/udc/goku_udc.c
index 46b8d14..d5a93ea 100644
--- a/drivers/usb/gadget/udc/goku_udc.c
+++ b/drivers/usb/gadget/udc/goku_udc.c
@@ -990,6 +990,30 @@ static int goku_get_frame(struct usb_gadget *_gadget)
return -EOPNOTSUPP;
 }
 
+static struct usb_ep *goku_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct goku_udc *dev = to_goku_udc(g);
+   struct usb_ep *ep;
+   u8 type = usb_endpoint_type(desc);
+
+   if (type == USB_ENDPOINT_XFER_INT) {
+   /* single buffering is enough */
+   ep = &dev->ep[3].ep;
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+   } else if (type == USB_ENDPOINT_XFER_BULK
+   && usb_endpoint_dir_in(desc)) {
+   /* DMA may be available */
+   ep = &dev->ep[2].ep;
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+   }
+
+   return NULL;
+}
+
 static int goku_udc_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
 static int goku_udc_stop(struct usb_gadget *g);
@@ -998,6 +1022,7 @@ static const struct usb_gadget_ops goku_ops = {
.get_frame  = goku_get_frame,
.udc_start  = goku_udc_start,
.udc_stop   = goku_udc_stop,
+   .match_ep   = goku_match_ep,
// no remote wakeup
// not selfpowered
 };
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 4/8] usb: gadget: move find_ep() from epautoconf to udc-core

2015-08-06 Thread Robert Baldyga
Move find_ep() to udc-core and rename it to gadget_find_ep_by_name().
It can be used in UDC drivers, especially in 'match_ep' callback after
moving chip-specific endpoint matching logic from epautoconf to UDC
drivers.

Replace all calls of find_ep() function with gadget_find_ep_by_name().

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c   | 30 +-
 drivers/usb/gadget/udc/udc-core.c | 21 +
 include/linux/usb/gadget.h|  8 +++-
 3 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index d49af4f..a39ca03 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -22,18 +22,6 @@
 
 #include "gadget_chips.h"
 
-static struct usb_ep *
-find_ep (struct usb_gadget *gadget, const char *name)
-{
-   struct usb_ep   *ep;
-
-   list_for_each_entry (ep, &gadget->ep_list, ep_list) {
-   if (0 == strcmp (ep->name, name))
-   return ep;
-   }
-   return NULL;
-}
-
 /**
  * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
  * descriptor and ep companion descriptor
@@ -103,11 +91,11 @@ struct usb_ep *usb_ep_autoconfig_ss(
 
if (type == USB_ENDPOINT_XFER_INT) {
/* ep-e, ep-f are PIO with only 64 byte fifos */
-   ep = find_ep(gadget, "ep-e");
+   ep = gadget_find_ep_by_name(gadget, "ep-e");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
-   ep = find_ep(gadget, "ep-f");
+   ep = gadget_find_ep_by_name(gadget, "ep-f");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
@@ -116,20 +104,20 @@ struct usb_ep *usb_ep_autoconfig_ss(
/* USB3380: use same address for usb and hardware endpoints */
snprintf(name, sizeof(name), "ep%d%s", usb_endpoint_num(desc),
usb_endpoint_dir_in(desc) ? "in" : "out");
-   ep = find_ep(gadget, name);
+   ep = gadget_find_ep_by_name(gadget, name);
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
goto found_ep;
} else if (gadget_is_goku (gadget)) {
if (USB_ENDPOINT_XFER_INT == type) {
/* single buffering is enough */
-   ep = find_ep(gadget, "ep3-bulk");
+   ep = gadget_find_ep_by_name(gadget, "ep3-bulk");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
} else if (USB_ENDPOINT_XFER_BULK == type
&& (USB_DIR_IN & desc->bEndpointAddress)) {
/* DMA may be available */
-   ep = find_ep(gadget, "ep2-bulk");
+   ep = gadget_find_ep_by_name(gadget, "ep2-bulk");
if (ep && usb_gadget_ep_match_desc(gadget,
ep, desc, ep_comp))
goto found_ep;
@@ -140,14 +128,14 @@ struct usb_ep *usb_ep_autoconfig_ss(
if ((USB_ENDPOINT_XFER_BULK == type) ||
(USB_ENDPOINT_XFER_ISOC == type)) {
if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = find_ep (gadget, "ep5in");
+   ep = gadget_find_ep_by_name(gadget, "ep5in");
else
-   ep = find_ep (gadget, "ep6out");
+   ep = gadget_find_ep_by_name(gadget, "ep6out");
} else if (USB_ENDPOINT_XFER_INT == type) {
if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = find_ep(gadget, "ep1in");
+   ep = gadget_find_ep_by_name(gadget, "ep1in");
else
-   ep = find_ep(gadget, "ep2out");
+   ep = gadget_find_ep_by_name(gadget, "ep2out");
} else
ep = NULL;
if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index b6427d1..3c954b5 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -131,6 +131,27 @@ EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
 /* - */
 
+/**
+ * gadget_find_ep_by_name - returns ep whose name is the same as sting 

[PATCH v7 7/8] usb: musb: gadget: add musb_match_ep() function

2015-08-06 Thread Robert Baldyga
Add 'match_ep' callback to utilize chip-specific knowledge in endpoint matching
process. Function does the same that was done by chip-specific code inside
of epautoconf. Now this code can be removed from there to separate generic code
from platform specific logic.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c | 23 ---
 drivers/usb/musb/musb_gadget.c  | 34 ++
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 574b6a4..16c1cc9 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -83,29 +83,6 @@ struct usb_ep *usb_ep_autoconfig_ss(
goto found_ep;
}
 
-   /* First, apply chip-specific "best usage" knowledge.
-* This might make a good usb_gadget_ops hook ...
-*/
-#ifdef CONFIG_BLACKFIN
-   if (gadget_is_musbhdrc(gadget)) {
-   if ((USB_ENDPOINT_XFER_BULK == type) ||
-   (USB_ENDPOINT_XFER_ISOC == type)) {
-   if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = gadget_find_ep_by_name(gadget, "ep5in");
-   else
-   ep = gadget_find_ep_by_name(gadget, "ep6out");
-   } else if (USB_ENDPOINT_XFER_INT == type) {
-   if (USB_DIR_IN & desc->bEndpointAddress)
-   ep = gadget_find_ep_by_name(gadget, "ep1in");
-   else
-   ep = gadget_find_ep_by_name(gadget, "ep2out");
-   } else
-   ep = NULL;
-   if (ep && usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
-   goto found_ep;
-   }
-#endif
-
/* Second, look at endpoints until an unclaimed one looks usable */
list_for_each_entry (ep, &gadget->ep_list, ep_list) {
if (usb_gadget_ep_match_desc(gadget, ep, desc, ep_comp))
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4150baf..ac2f188 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1684,6 +1684,39 @@ static int musb_gadget_pullup(struct usb_gadget *gadget, 
int is_on)
return 0;
 }
 
+#ifdef CONFIG_BLACKFIN
+static struct usb_ep *musb_match_ep(struct usb_gadget *g,
+   struct usb_endpoint_descriptor *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
+{
+   struct usb_ep *ep = NULL;
+   u8 type = usb_endpoint_type(desc);
+
+   switch (type) {
+   case USB_ENDPOINT_XFER_ISOC:
+   case USB_ENDPOINT_XFER_BULK:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep5in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep6out");
+   break;
+   case USB_ENDPOINT_XFER_INT:
+   if (usb_endpoint_dir_in(desc))
+   ep = gadget_find_ep_by_name(g, "ep1in");
+   else
+   ep = gadget_find_ep_by_name(g, "ep2out");
+   default:
+   }
+
+   if (ep && usb_gadget_ep_match_desc(g, ep, desc, ep_comp))
+   return ep;
+
+   return NULL;
+}
+#else
+#define musb_match_ep NULL
+#endif
+
 static int musb_gadget_start(struct usb_gadget *g,
struct usb_gadget_driver *driver);
 static int musb_gadget_stop(struct usb_gadget *g);
@@ -1697,6 +1730,7 @@ static const struct usb_gadget_ops musb_gadget_operations 
= {
.pullup = musb_gadget_pullup,
.udc_start  = musb_gadget_start,
.udc_stop   = musb_gadget_stop,
+   .match_ep   = musb_match_ep,
 };
 
 /* --- */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 8/8] usb: gadget: remove gadget_chips.h

2015-08-06 Thread Robert Baldyga
This header file contains helpers for quirks based on UDC controller name.
Since we have generic quirk bitfields in usb_gadget structure for all of
these quirks we don't need to have this header any longer.

This patch removes gadget_chips.h file and makes sure that it's no longer
included anywhere in kernel sources.

Signed-off-by: Robert Baldyga 
---
 drivers/usb/gadget/epautoconf.c  |  2 -
 drivers/usb/gadget/function/f_acm.c  |  1 -
 drivers/usb/gadget/function/f_mass_storage.c |  1 -
 drivers/usb/gadget/function/f_obex.c |  1 -
 drivers/usb/gadget/function/f_serial.c   |  1 -
 drivers/usb/gadget/function/f_sourcesink.c   |  1 -
 drivers/usb/gadget/function/u_ether.h|  2 -
 drivers/usb/gadget/function/u_uac1.h |  2 -
 drivers/usb/gadget/legacy/audio.c|  1 -
 drivers/usb/gadget/legacy/gmidi.c|  2 -
 drivers/usb/gadget/legacy/hid.c  |  1 -
 drivers/usb/gadget/legacy/nokia.c|  1 -
 drivers/usb/gadget/legacy/printer.c  |  2 -
 drivers/usb/gadget/legacy/serial.c   |  1 -
 drivers/usb/gadget/udc/gadget_chips.h| 55 
 15 files changed, 74 deletions(-)
 delete mode 100644 drivers/usb/gadget/udc/gadget_chips.h

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 16c1cc9..978435a 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 /**
  * usb_ep_autoconfig_ss() - choose an endpoint matching the ep
  * descriptor and ep companion descriptor
diff --git a/drivers/usb/gadget/function/f_acm.c 
b/drivers/usb/gadget/function/f_acm.c
index aad8165..be9df09 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -21,7 +21,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_mass_storage.c 
b/drivers/usb/gadget/function/f_mass_storage.c
index 04c3bb6..11a7f5a 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -219,7 +219,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #include "configfs.h"
 
 
diff --git a/drivers/usb/gadget/function/f_obex.c 
b/drivers/usb/gadget/function/f_obex.c
index 2682d59..5460426 100644
--- a/drivers/usb/gadget/function/f_obex.c
+++ b/drivers/usb/gadget/function/f_obex.c
@@ -20,7 +20,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_serial.c 
b/drivers/usb/gadget/function/f_serial.c
index 2e02dfa..1d162e2 100644
--- a/drivers/usb/gadget/function/f_serial.c
+++ b/drivers/usb/gadget/function/f_serial.c
@@ -16,7 +16,6 @@
 #include 
 
 #include "u_serial.h"
-#include "gadget_chips.h"
 
 
 /*
diff --git a/drivers/usb/gadget/function/f_sourcesink.c 
b/drivers/usb/gadget/function/f_sourcesink.c
index e6af171..cbfaf86 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -20,7 +20,6 @@
 #include 
 
 #include "g_zero.h"
-#include "gadget_chips.h"
 #include "u_f.h"
 
 /*
diff --git a/drivers/usb/gadget/function/u_ether.h 
b/drivers/usb/gadget/function/u_ether.h
index 1384f00..c77145b 100644
--- a/drivers/usb/gadget/function/u_ether.h
+++ b/drivers/usb/gadget/function/u_ether.h
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #define QMULT_DEFAULT 5
 
 /*
diff --git a/drivers/usb/gadget/function/u_uac1.h 
b/drivers/usb/gadget/function/u_uac1.h
index fe386df..5c2ac8e 100644
--- a/drivers/usb/gadget/function/u_uac1.h
+++ b/drivers/usb/gadget/function/u_uac1.h
@@ -21,8 +21,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #define FILE_PCM_PLAYBACK  "/dev/snd/pcmC0D0p"
 #define FILE_PCM_CAPTURE   "/dev/snd/pcmC0D0c"
 #define FILE_CONTROL   "/dev/snd/controlC0"
diff --git a/drivers/usb/gadget/legacy/audio.c 
b/drivers/usb/gadget/legacy/audio.c
index 9b2c1c6..685cf3b 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -15,7 +15,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #define DRIVER_DESC"Linux USB Audio Gadget"
 #define DRIVER_VERSION "Feb 2, 2012"
 
diff --git a/drivers/usb/gadget/legacy/gmidi.c 
b/drivers/usb/gadget/legacy/gmidi.c
index 650568d..8a18348 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -35,8 +35,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
-
 #include "u_midi.h"
 
 /*-*/
diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c
index e4874d3..7e5d2c4 100644
--- a/drivers/usb/gadget/legacy/hid.c
+++ b/drivers/usb/gadget/legacy/hid.c
@@ -19,7 +19,6 @@
 #include 
 #include 
 
-#include "gadget_chips.h"
 #define DRIVER_DESC"HID Gadget"
 #define DRIVER_VERSIO

Re: [PATCH] drivers/usb: Delete XHCI command timer if necessary

2015-08-06 Thread Mathias Nyman
On 06.08.2015 02:29, Greg KH wrote:
> On Thu, Aug 06, 2015 at 09:13:12AM +1000, Gavin Shan wrote:
>> On Mon, Jul 27, 2015 at 12:08:05PM +1000, Gavin Shan wrote:
>>> When xhci_mem_cleanup() is called, it's possible that the command
>>> timer isn't initialized and scheduled. For those cases, to delete
>>> the command timer causes soft-lockup as below stack dump shows.
>>>
>>> The patch avoids deleting the command timer if it's not scheduled
>>> with the help of timer_pending().
>>>
>>> NMI watchdog: BUG: soft lockup - CPU#40 stuck for 23s! [kworker/40:1:8140]
>>>  :
>>> NIP [c0150b30] lock_timer_base.isra.34+0x90/0xa0
>>> LR [c0150c24] try_to_del_timer_sync+0x34/0xa0
>>> Call Trace:
>>> [c00f67c975e0] [c15b84f8] mon_ops+0x0/0x8 (unreliable)
>>> [c00f67c97620] [c0150c24] try_to_del_timer_sync+0x34/0xa0
>>> [c00f67c97660] [c0150cf0] del_timer_sync+0x60/0x80
>>> [c00f67c97690] [c070ac0c] xhci_mem_cleanup+0x5c/0x5e0
>>> [c00f67c97740] [c070c2e8] xhci_mem_init+0x1158/0x13b0
>>> [c00f67c97860] [c0700978] xhci_init+0x88/0x110
>>> [c00f67c978e0] [c0701644] xhci_gen_setup+0x2b4/0x590
>>> [c00f67c97970] [c06d4410] xhci_pci_setup+0x40/0x190
>>> [c00f67c979f0] [c06b1af8] usb_add_hcd+0x418/0xba0
>>> [c00f67c97ab0] [c06cb15c] usb_hcd_pci_probe+0x1dc/0x5c0
>>> [c00f67c97b50] [c06d3ba4] xhci_pci_probe+0x64/0x1f0
>>> [c00f67c97ba0] [c04fe9ac] local_pci_probe+0x6c/0x130
>>> [c00f67c97c30] [c00e5ce8] work_for_cpu_fn+0x38/0x60
>>> [c00f67c97c60] [c00eacb8] process_one_work+0x198/0x470
>>> [c00f67c97cf0] [c00eb6ac] worker_thread+0x37c/0x5a0
>>> [c00f67c97d80] [c00f2730] kthread+0x110/0x130
>>> [c00f67c97e30] [c0009660] ret_from_kernel_thread+0x5c/0x7c
>>>
>>> Reported-by: Priya M. A 
>>> Signed-off-by: Gavin Shan 
>>
>> ping?
> 
> The driver maintainer is on vacation, please give him a chance to get
> back and catch up.
> 

This one is already applied, but author wasn't notified about it. 
In Greg's usb-linus:

commit ffe5adcb7661d94e952d6b5ed7f493cb4ef0c7bc
Author: Gavin Shan 
Date:   Mon Aug 3 16:07:49 2015 +0300
drivers/usb: Delete XHCI command timer if necessary

-Mathias

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] gadget: Support for the usb charger framework

2015-08-06 Thread Baolin Wang
The usb charger framework is based on usb gadget, and each usb gadget
can be one usb charger to set the current limitation.

This patch adds a notifier mechanism for usb charger to report to usb
charger when the usb gadget state is changed.

Also we introduce a callback 'get_charger_type' which will implemented
by user for usb gadget operations to get the usb charger type.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/udc/udc-core.c |   41 +
 include/linux/usb/gadget.h|   20 ++
 2 files changed, 61 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c 
b/drivers/usb/gadget/udc/udc-core.c
index d69c355..d5368088 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * struct usb_udc - describes one usb device controller
@@ -127,12 +128,45 @@ void usb_gadget_giveback_request(struct usb_ep *ep,
 }
 EXPORT_SYMBOL_GPL(usb_gadget_giveback_request);
 
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb)
+{
+   unsigned long flags;
+   int ret;
+
+   spin_lock_irqsave(&gadget->lock, flags);
+   ret = raw_notifier_chain_register(&gadget->nh, nb);
+   spin_unlock_irqrestore(&gadget->lock, flags);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_register_notify);
+
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb)
+{
+   unsigned long flags;
+   int ret;
+
+   spin_lock_irqsave(&gadget->lock, flags);
+   ret = raw_notifier_chain_unregister(&gadget->nh, nb);
+   spin_unlock_irqrestore(&gadget->lock, flags);
+
+   return ret;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_unregister_notify);
+
 /* - */
 
 static void usb_gadget_state_work(struct work_struct *work)
 {
struct usb_gadget *gadget = work_to_gadget(work);
struct usb_udc *udc = gadget->udc;
+   unsigned long flags;
+
+   spin_lock_irqsave(&gadget->lock, flags);
+   raw_notifier_call_chain(&gadget->nh, gadget->state, gadget);
+   spin_unlock_irqrestore(&gadget->lock, flags);
 
if (udc)
sysfs_notify(&udc->dev.kobj, NULL, "state");
@@ -272,6 +306,8 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
dev_set_name(&gadget->dev, "gadget");
INIT_WORK(&gadget->work, usb_gadget_state_work);
+   RAW_INIT_NOTIFIER_HEAD(&gadget->nh);
+   spin_lock_init(&gadget->lock);
gadget->dev.parent = parent;
 
 #ifdef CONFIG_HAS_DMA
@@ -313,6 +349,10 @@ int usb_add_gadget_udc_release(struct device *parent, 
struct usb_gadget *gadget,
 
mutex_unlock(&udc_lock);
 
+   ret = usb_charger_init(gadget);
+   if (ret)
+   goto err4;
+
return 0;
 
 err4:
@@ -388,6 +428,7 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
flush_work(&gadget->work);
device_unregister(&udc->dev);
+   usb_charger_exit(gadget);
device_unregister(&gadget->dev);
 }
 EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 4f3dfb7..f24d6ac 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -492,6 +492,7 @@ struct usb_gadget_ops {
int (*udc_start)(struct usb_gadget *,
struct usb_gadget_driver *);
int (*udc_stop)(struct usb_gadget *);
+   enum usb_charger_type   (*get_charger_type)(struct usb_gadget *);
 };
 
 /**
@@ -559,6 +560,9 @@ struct usb_gadget {
struct device   dev;
unsignedout_epnum;
unsignedin_epnum;
+   struct raw_notifier_headnh;
+   struct usb_charger  *uchger;
+   spinlock_t  lock;
 
unsignedsg_supported:1;
unsignedis_otg:1;
@@ -1014,6 +1018,22 @@ extern void usb_gadget_unmap_request(struct usb_gadget 
*gadget,
 
 /*-*/
 
+/**
+ * Register a notifiee to get notified by any attach status changes from
+ * the usb gadget
+ */
+int usb_gadget_register_notify(struct usb_gadget *gadget,
+  struct notifier_block *nb);
+
+/*-*/
+
+
+/* Unregister a notifiee from the usb gadget */
+int usb_gadget_unregister_notify(struct usb_gadget *gadget,
+struct notifier_block *nb);
+
+/*-*/
+
 /* utility to set gadget state properly */
 
 extern void usb_gadget_set_state(s

[PATCH 1/2] gadget: Introduce the usb charger framework

2015-08-06 Thread Baolin Wang
This patch introduces the usb charger driver based on usb gadget that
makes an enhancement to a power driver. It works well in practice but
that requires a system with suitable hardware.

The basic conception of the usb charger is that, when one usb charger
is added or removed by reporting from the usb gadget state change or
the extcon device state change, the usb charger will report to power
user to set the current limitation.

The usb charger will register notifiees on the usb gadget or the extcon
device to get notified the usb charger state.

Power user will register a notifiee on the usb charger to get notified
by status changes from the usb charger. It will report to power user
to set the current limitation when detecting the usb charger is added
or removed from extcon device state or usb gadget state.

Signed-off-by: Baolin Wang 
---
 drivers/usb/gadget/charger.c|  547 +++
 include/linux/usb/usb_charger.h |  101 
 2 files changed, 648 insertions(+)
 create mode 100644 drivers/usb/gadget/charger.c
 create mode 100644 include/linux/usb/usb_charger.h

diff --git a/drivers/usb/gadget/charger.c b/drivers/usb/gadget/charger.c
new file mode 100644
index 000..3ca0180
--- /dev/null
+++ b/drivers/usb/gadget/charger.c
@@ -0,0 +1,547 @@
+/*
+ * usb charger.c -- USB charger driver
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_CUR_PROTECT(50)
+#define DEFAULT_SDP_CUR_LIMIT  (500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_DCP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_CDP_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+#define DEFAULT_ACA_CUR_LIMIT  (1500 - DEFAULT_CUR_PROTECT)
+
+static LIST_HEAD(usb_charger_list);
+static DEFINE_MUTEX(usb_charger_list_lock);
+
+/*
+ * usb_charger_find_by_name - Get the usb charger device by name.
+ * @name - usb charger device name.
+ *
+ * notes: when this function walks the list and returns a charger
+ * it's dropped the lock which means that something else could come
+ * along and delete the charger before we dereference the pointer.
+ * It's very unlikely but it's a possibility so you should take care
+ * of it.
+ * Thus when you get the usb charger by name, you should call
+ * put_usb_charger() to derease the reference count of the usb charger.
+ *
+ * return the instance of usb charger device.
+ */
+struct usb_charger *usb_charger_find_by_name(char *name)
+{
+   struct usb_charger *uchger;
+
+   if (!name)
+   return ERR_PTR(-EINVAL);
+
+   mutex_lock(&usb_charger_list_lock);
+   list_for_each_entry(uchger, &usb_charger_list, entry) {
+   if (!strcmp(uchger->name, name)) {
+   get_usb_charger(uchger);
+   mutex_unlock(&usb_charger_list_lock);
+   return uchger;
+   }
+   }
+   mutex_unlock(&usb_charger_list_lock);
+
+   return NULL;
+}
+
+/*
+ * usb_charger_register_notify() - Register a notifiee to get notified by
+ * any attach status changes from the usb charger type detection.
+ * @uchger - the usb charger device which is monitored.
+ * @nb - a notifier block to be registered.
+ */
+void usb_charger_register_notify(struct usb_charger *uchger,
+struct notifier_block *nb)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&uchger->lock, flags);
+   raw_notifier_chain_register(&uchger->uchger_nh, nb);
+   spin_unlock_irqrestore(&uchger->lock, flags);
+}
+
+/*
+ * usb_charger_unregister_notify() - Unregister a notifiee from the usb 
charger.
+ * @uchger - the usb charger device which is monitored.
+ * @nb - a notifier block to be unregistered.
+ */
+void usb_charger_unregister_notify(struct usb_charger *uchger,
+  struct notifier_block *nb)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&uchger->lock, flags);
+   raw_notifier_chain_unregister(&uchger->uchger_nh, nb);
+   spin_unlock_irqrestore(&uchger->lock, flags);
+}
+
+/*
+ * usb_charger_register_extcon_notifier() - Register a notifiee of the usb
+ * charger to get notified by any attach status changes from
+ * the extcon device.
+ * @uchger - the usb charger device.
+ * @edev - the extcon device.
+ * @extcon_id - extcon id.
+ */
+int usb_charger_register_extcon_notifier(struct usb_charger *uchger,
+struct extcon_dev *edev,
+unsigned int extcon_id)
+{
+   if (!uchger || !edev)
+   return -EINVAL;
+
+   return 

[PATCH 0/2] Introduce usb charger framework to deal with the usb gadget power negotation

2015-08-06 Thread Baolin Wang
Currently the Linux kernel does not provide any standard integration of this
feature that integrates the USB subsystem with the system power regulation
provided by PMICs meaning that either vendors must add this in their kernels
or USB gadget devices based on Linux (such as mobile phones) may not behave
as they should.

Providing a standard framework for doing this in the kernel.

Baolin Wang (2):
  gadget: Introduce the usb charger framework
  gadget: Support for the usb charger framework

 drivers/usb/gadget/charger.c  |  547 +
 drivers/usb/gadget/udc/udc-core.c |   41 +++
 include/linux/usb/gadget.h|   20 ++
 include/linux/usb/usb_charger.h   |  101 +++
 4 files changed, 709 insertions(+)
 create mode 100644 drivers/usb/gadget/charger.c
 create mode 100644 include/linux/usb/usb_charger.h

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html