Re: [PATCH] USB: serial: fix sysfs-attribute removal deadlock

2014-04-24 Thread Li Zhong
On Wed, 2014-04-23 at 10:19 -0400, Tejun Heo wrote:
> cc'ing Li Zhong who's working on a simliar issue in the following
> thread and quoting whole body.
> 
>   http://thread.gmane.org/gmane.linux.kernel/1680706
> 
> Li, this is another variation of the same problem.  Maybe this can be
> covered by your work too?

It seems to me that it is about write something to driver attribute, and
driver unloading. If so, maybe it's not easy to reuse the help functions
created for device attribute, and device removing.

But I guess the idea to break the active protection could still be
applied here:

Maybe we could try_module_get() here (like the other option suggested by
Johan?), and break active protection if we could get the module,
something like below? 


diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 83e910a..6ce27e0 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -69,9 +69,24 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct 
attribute *attr,
struct driver_attribute *drv_attr = to_drv_attr(attr);
struct driver_private *drv_priv = to_driver(kobj);
ssize_t ret = -EIO;
+   struct kernfs_node *kn;
+
+   if (!try_module_get(drv_priv->driver->owner))
+   return ret;
+
+   kn = kernfs_find_and_get(kobj->sd, attr->name);
+   if (WARN_ON_ONCE(!kn))
+   return ret;
+
+   kernfs_break_active_protection(kn);
 
if (drv_attr->store)
ret = drv_attr->store(drv_priv->driver, buf, count);
+
+   kernfs_unbreak_active_protection(kn);
+   kernfs_put(kn);
+
+   module_put(drv_priv->driver->owner);
return ret;
 }
 


--
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: Deadlock v3.10.35 with FTD_SIO usb-serial adapter

2014-04-24 Thread Matteo Fortini

After some time, we finally had another hangup on kernel 3.14.

@Alan: Here's the info we got in the files you mentioned. At any rate, 
we're keeping the board in the same state so that we can run/produce any 
other needed info.


http://pastebin.com/DZPAqjcd


Thank you,
Matteo



Il 16/04/2014 18:01, Alan Stern ha scritto:

On Wed, 16 Apr 2014, Matteo Fortini wrote:


It's and AMD Geode single board computer, using CS5535 companion chip.

Here's the pertaining lspci -vvv section:

00:0f.4 Class 0c03: Device 1022:2094 (rev 02) (prog-if 10)
  Subsystem: Device 1022:2094
  Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr-
Stepping- SERR- FastB2B- DisINTx-
  Status: Cap+ 66MHz+ UDF- FastB2B- ParErr- DEVSEL=medium >TAbort-
SERR- TAbort-
SERR- 
This doesn't answer my question.  Which controller was the device
attached to when the hang occurred?  Was it the EHCI controller or the
OHCI controller?

If you enable CONFIG_USB_DEBUG, what shows up in the files under the
corresponding directory in /sys/kernel/debug/usb/ehci/ or
/sys/kernel/debug/usb/ohci/ when the hang occurs?

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: [PATCH] usb: musb_dsps: fix the exit routine for debugfs

2014-04-24 Thread Olivier Gayot
Ok, thank you, I didn't notice the existing thread.

On Wed, 23 Apr 2014 10:55:29 -0500
Felipe Balbi  wrote:

> On Wed, Apr 23, 2014 at 05:39:43PM +0200, Olivier Gayot wrote:
> > The following commit introduced the debugfs :
> > 
> > 40f099e32c2a06bad7d75683421e30fcc74924cd
> > Author: Markus Pargmann 
> > Date:   Fri Jan 17 10:22:35 2014 +0100
> > 
> > usb: musb: dsps, debugfs files
> > 
> > Unfortunately, a forgotten call to a cleanup function prevents the
> > probing of musb in case of deferred probe.
> > 
> > Because musb_init_controller() often retries and creates a new
> > debugfs directory each time it is called, we need to remove that
> > directory in case the initialization fails. Otherwise, the
> > debugfs_create_dir() fails at subsequent calls because the
> > directory already exists.
> > 
> > Fixed by calling debugfs_remove_recursive() in the exit function.
> > 
> > Signed-off-by: Olivier Gayot 
> > Cc: Markus Pargmann 
> > ---
> >  drivers/usb/musb/musb_dsps.c |2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/usb/musb/musb_dsps.c
> > b/drivers/usb/musb/musb_dsps.c index 3372ded..c3de0a5 100644
> > --- a/drivers/usb/musb/musb_dsps.c
> > +++ b/drivers/usb/musb/musb_dsps.c
> > @@ -471,6 +471,8 @@ static int dsps_musb_exit(struct musb *musb)
> >  
> > del_timer_sync(&glue->timer);
> >  
> > +   debugfs_remove_recursive(glue->dbgfs_root);
> > +
> > usb_phy_shutdown(musb->xceiv);
> > return 0;
> 
> First of all this commit is wrong, second of all I already have the
> proper commit:
> 
> commit 0fca91b8a446d4a38b8f3d4772c4a8665ebcd7b2
> Author: Daniel Mack 
> Date:   Wed Apr 2 11:46:51 2014 +0200
> 
> usb: musb: dsps: move debugfs_remove_recursive()
> 
> When the platform initialization fails due to missing resources,
> it will return -EPROBE_DEFER after dsps_musb_init() has been called.
> 
> dsps_musb_init() calls dsps_musb_dbg_init() to allocate the
> debugfs nodes. At a later point in time, the probe will be retried,
> and dsps_musb_dbg_init() will be called again. debugfs_create_dir()
> will fail this time, as the node already exists, and so the entire
> device probe will fail with -ENOMEM.
> 
> Fix this by moving debugfs_remove_recursive() from dsps_remove()
> to the plaform's exit function, so it will be cleanly torn down when
> the probe fails. It also feels more natural this way, as .exit is the
> counterpart to .init.
> 
> Signed-off-by: Daniel Mack 
> Signed-off-by: Felipe Balbi 
> 
> diff --git a/drivers/usb/musb/musb_dsps.c
> b/drivers/usb/musb/musb_dsps.c index 3372ded..e2fd263 100644
> --- a/drivers/usb/musb/musb_dsps.c
> +++ b/drivers/usb/musb/musb_dsps.c
> @@ -470,8 +470,9 @@ static int dsps_musb_exit(struct musb *musb)
>   struct dsps_glue *glue = dev_get_drvdata(dev->parent);
>  
>   del_timer_sync(&glue->timer);
> -
>   usb_phy_shutdown(musb->xceiv);
> + debugfs_remove_recursive(glue->dbgfs_root);
> +
>   return 0;
>  }
>  
> @@ -708,8 +709,6 @@ static int dsps_remove(struct platform_device
> *pdev) pm_runtime_put(&pdev->dev);
>   pm_runtime_disable(&pdev->dev);
>  
> - debugfs_remove_recursive(glue->dbgfs_root);
> -
>   return 0;
>  }
>  
> 
> a pull request has already been sent to Greg, should be in v3.15-rc3
> 

--
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


[RFC 3/9] usb: gadget: OS Feature Descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz
There is a custom (non-USB IF) extension to the USB standard:

http://msdn.microsoft.com/library/windows/hardware/gg463182

The said extension is maintained by Microsoft for Microsoft.

Yet it is fairly common for various devices to use it, and a
popular proprietary operating system expects devices to provide
"OS descriptors", so Linux-based USB gadgets whishing to be able
to talk to a variety of operating systems should be able to provide
the "OS descriptors".

This patch adds optional support for gadgets whishing to expose
the so called "OS Feature Descriptors", that is "Extended Compatibility ID"
and "Extended Properties".

Hosts which do request "OS descriptors" from gadgets do so during
the enumeration phase and before the configuration is set with
SET_CONFIGURATION. What is more, those hosts never ask for configurations
at indices other than 0. Therefore, gadgets whishing to provide
"OS descriptors" must designate one configuration to be used with
this kind of hosts - this is what os_desc_config is added for in
struct usb_composite_dev. There is an additional advantage to it:
if a gadget provides "OS descriptors" and designates one configuration
to be used with such non-USB-compliant hosts it can invoke
"usb_add_config" in any order because the designated configuration
will be reported to be at index 0 anyway.

This patch also adds handling vendor-specific requests addressed
at device or interface and related to handling "OS descriptors".

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/composite.c | 315 -
 drivers/usb/gadget/u_os_desc.h |  90 
 include/linux/usb/composite.h  |  58 
 3 files changed, 462 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/gadget/u_os_desc.h

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 0bfdb14..3682d80 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -21,6 +21,8 @@
 #include 
 #include 
 
+#include "u_os_desc.h"
+
 /*
  * The code in this file is utility code, used to build a gadget driver
  * from one or more "function" drivers, one or more "configuration"
@@ -438,8 +440,46 @@ static int config_desc(struct usb_composite_dev *cdev, 
unsigned w_value)
 
}
 
-   /* This is a lookup by config *INDEX* */
w_value &= 0xff;
+   /*
+* This is a lookup to make non-compliant USB hosts happy.
+*
+* By non-compliant USB hosts I mean those which only ask for
+* configuration @index 0.
+* If one configuration is marked "special" by storing
+* its address in cdev->os_desc_config, we try returning
+* exactly this configuration.
+*
+* Otherwise, regular list lookup is performed.
+*
+* If we are connected to a compliant USB host _and_
+* one configuration is "special" we report it @ index 0,
+* but report remaining configurations as well - with adjusted
+* indices.
+*/
+   c = cdev->os_desc_config;
+   if (c) {
+   if (!w_value) {
+   switch (speed) {
+   case USB_SPEED_SUPER:
+   if (!c->superspeed)
+   goto list_lookup;
+   break;
+   case USB_SPEED_HIGH:
+   if (!c->highspeed)
+   goto list_lookup;
+   break;
+   default:
+   if (!c->fullspeed)
+   goto list_lookup;
+   }
+
+   return config_buf(c, speed, cdev->req->buf, type);
+   }
+   --w_value; /* account for conf returned @ index 0 */
+   }
+list_lookup:
+   /* This is a lookup by config *INDEX* */
list_for_each_entry(c, &cdev->configs, list) {
/* ignore configs that won't work at this speed */
switch (speed) {
@@ -455,6 +495,9 @@ static int config_desc(struct usb_composite_dev *cdev, 
unsigned w_value)
if (!c->fullspeed)
continue;
}
+   /* account for conf returned @ index 0 */
+   if (c == cdev->os_desc_config)
+   continue;
 
if (w_value == 0)
return config_buf(c, speed, cdev->req->buf, type);
@@ -1222,6 +1265,158 @@ static void composite_setup_complete(struct usb_ep *ep, 
struct usb_request *req)
req->status, req->actual, req->length);
 }
 
+static int count_ext_compat(struct usb_configuration *c)
+{
+   int i, res;
+
+   res = 0;
+   for (i = 0; i < c->next_interface_id; ++i) {
+   struct usb_function *f;
+   int j;
+
+   f = c->interface[i];
+ 

[RFC 9/9] usb: gadget: ether: example usage of "OS desriptors"

2014-04-24 Thread Andrzej Pietrasiewicz
Example of using OS Descriptors in a legacy gadget.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/ether.c | 58 ++
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index c1c113e..2c06f1f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -24,6 +24,7 @@
 #endif
 
 #include "u_ether.h"
+#include "u_os_desc.h"
 
 
 /*
@@ -316,6 +317,11 @@ static struct usb_configuration eth_config_driver = {
.bmAttributes   = USB_CONFIG_ATT_SELFPOWER,
 };
 
+static struct usb_os_desc_ext_prop icon_prop;
+static struct usb_os_desc_ext_prop label_prop;
+static const char *os_string = "MSFT100";
+static const char *rndis_label = "RNDIS";
+
 /*-*/
 
 static int __init eth_bind(struct usb_composite_dev *cdev)
@@ -324,6 +330,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
struct f_eem_opts   *eem_opts = NULL;
struct f_ecm_opts   *ecm_opts = NULL;
struct f_gether_opts*geth_opts = NULL;
+   struct f_rndis_opts *rndis_opts = NULL;
struct net_device   *net;
int status;
 
@@ -416,18 +423,53 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
 
+   status = usb_add_config(cdev, ð_config_driver, eth_do_config);
+   if (status < 0)
+   goto fail1;
+
/* register our configuration(s); RNDIS first, if it's used */
if (has_rndis()) {
+   rndis_opts = container_of(fi_rndis, struct f_rndis_opts,
+ func_inst);
+   cdev->use_os_string = true;
+   cdev->b_vendor_code = 0xCA;
+   status = utf8s_to_utf16s(os_string, strlen(os_string),
+   UTF16_LITTLE_ENDIAN, (wchar_t *) &cdev->qw_sign[0],
+   OS_STRING_QW_SIGN_LEN);
+   if (status < 0)
+   goto fail1;
+
+   list_add_tail(&icon_prop.entry,
+   &rndis_opts->rndis_os_desc.ext_prop);
+   list_add_tail(&label_prop.entry,
+   &rndis_opts->rndis_os_desc.ext_prop);
+
+   cdev->os_desc_config = &rndis_config_driver;
+   memcpy(&rndis_opts->rndis_os_desc.ext_compat_id[0],
+   rndis_label, 5);
+
+   icon_prop.type = USB_EXT_PROP_UNICODE_ENV;
+   icon_prop.name = "Icons";
+   icon_prop.name_len = 2 * strlen(icon_prop.name) + 2;
+   icon_prop.data = "%SystemRoot%\\system32\\shell32.dll,-233";
+   icon_prop.data_len = 2 * strlen(icon_prop.data) + 2;
+
+   label_prop.type = USB_EXT_PROP_UNICODE;
+   label_prop.name = "Label";
+   label_prop.name_len = 2 * strlen(label_prop.name) + 2;
+   label_prop.data = "XYZ Device";
+   label_prop.data_len = 2 * strlen(label_prop.data) + 2;
+
+   rndis_opts->rndis_os_desc.ext_prop_len =
+   icon_prop.name_len + icon_prop.data_len + 14 +
+   label_prop.name_len + label_prop.data_len + 14;
+   rndis_opts->rndis_os_desc.ext_prop_count = 2;
status = usb_add_config(cdev, &rndis_config_driver,
rndis_do_config);
if (status < 0)
goto fail1;
}
 
-   status = usb_add_config(cdev, ð_config_driver, eth_do_config);
-   if (status < 0)
-   goto fail1;
-
usb_composite_overwrite_options(cdev, &coverwrite);
dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
DRIVER_DESC);
@@ -435,8 +477,11 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
return 0;
 
 fail1:
-   if (has_rndis())
+   if (has_rndis()) {
+   label_prop.data = NULL;
+   icon_prop.data = NULL;
usb_put_function_instance(fi_rndis);
+   }
 fail:
if (use_eem)
usb_put_function_instance(fi_eem);
@@ -449,7 +494,10 @@ fail:
 
 static int __exit eth_unbind(struct usb_composite_dev *cdev)
 {
+
if (has_rndis()) {
+   label_prop.data = NULL;
+   icon_prop.data = NULL;
usb_put_function(f_rndis);
usb_put_function_instance(fi_rndis);
}
-- 
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


[RFC 7/9] usb: gadget: f_rndis: OS Descriptors configfs support

2014-04-24 Thread Andrzej Pietrasiewicz
Added handling of OS Descriptors support for f_rndis.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/f_rndis.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index b781a59..43d15f9 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -27,6 +27,7 @@
 #include "u_ether_configfs.h"
 #include "u_rndis.h"
 #include "rndis.h"
+#include "configfs.h"
 
 /*
  * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
@@ -895,12 +896,15 @@ static void rndis_free_inst(struct usb_function_instance 
*f)
else
free_netdev(opts->net);
}
+
+   kfree(opts->rndis_os_desc.group.default_groups); /* single VLA chunk */
kfree(opts);
 }
 
 static struct usb_function_instance *rndis_alloc_inst(void)
 {
struct f_rndis_opts *opts;
+   struct usb_os_desc *descs[1];
 
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
@@ -917,6 +921,9 @@ static struct usb_function_instance *rndis_alloc_inst(void)
}
INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop);
 
+   descs[0] = &opts->rndis_os_desc;
+   usb_os_desc_prepare_interf_dir(&opts->func_inst.group, 1, descs,
+  THIS_MODULE);
config_group_init_type_name(&opts->func_inst.group, "",
&rndis_func_type);
 
-- 
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


[RFC 0/9] OS Descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz
There is a custom (non-USB IF) extension to the USB standard:

http://msdn.microsoft.com/library/windows/hardware/gg463182

The said extension is maintained by Microsoft for Microsoft.

Yet it is fairly common for various devices to use it, and a
popular proprietary operating system expects devices to provide
"OS descriptors", so Linux-based USB gadgets whishing to be able
to talk to a variety of operating systems should be able to provide
the "OS descriptors".

This patch series adds (optional) support for gadgets whishing to expose
the so-called "OS Descriptors".

The sequence of operations when a gadget is enumerated by an OS which expects
the said descriptors is as following:

1) the host issues a standard "GET_DESCRIPTOR" request of type 0x03 (string)
for a string at index 0xEE in language 0, named "OS String"
2) if the device responds, the hosts interprets the response, and if it is
of expected form the host assumes the device supports "OS Descriptors"
3) the host issues requests to get "Feature Descriptors" it expects

There are two kinds of "Feature Descriptors": "Extended Compatibility"
descriptors and "Extended Properties" descriptors.
They are specified per USB interface or per USB interface group described
by an IAD.

Legacy gadgets (compiled as separate modules, like g_ether, g_serial etc)
can stay as they are and not use this extension; however PATCH 9/9
shows an example of converting g_ether to use "OS Descriptors" with RNDIS.
The intended use of the extension is with configfs interface, though.

This series contains an extension to the f_rndis function; if a function
whishes to support "OS Descriptors" it needs to be patched with a fairly
simple change: PATCH 4/9 contains code for supporting the extension proper,
while PATCH 7/9 contains code for using it with configfs.

Rebased onto Felipe's master as of 23rd April.

It is meant for 3.16.

I kindly ask for comments about this extension. In particular,
FunctionFS needs an extension of the way descriptors are written to ep0.

Regards,

AP

Andrzej Pietrasiewicz (9):
  usb: gadget: FunctionFS: share VLA macros with all usb gadget files
  usb: gadget: OS String support
  usb: gadget: OS Feature Descriptors support
  usb: gadget: f_rndis: OS descriptors support
  usb: gadget: configfs: OS String support
  usb: gadget: configfs: OS Extended Compatibility descriptors support
  usb: gadget: f_rndis: OS Descriptors configfs support
  usb: gadget: configfs: OS Extended Properties descriptors support
  usb: gadget: ether: example usage of "OS desriptors"

 Documentation/ABI/testing/configfs-usb-gadget |  45 +++
 drivers/usb/gadget/composite.c| 331 +++-
 drivers/usb/gadget/configfs.c | 550 +-
 drivers/usb/gadget/configfs.h |  12 +
 drivers/usb/gadget/ether.c|  58 ++-
 drivers/usb/gadget/f_fs.c |  27 +-
 drivers/usb/gadget/f_rndis.c  |  31 +-
 drivers/usb/gadget/u_f.h  |  26 ++
 drivers/usb/gadget/u_os_desc.h|  90 +
 drivers/usb/gadget/u_rndis.h  |   3 +
 include/linux/usb/composite.h |  82 
 11 files changed, 1219 insertions(+), 36 deletions(-)
 create mode 100644 drivers/usb/gadget/u_os_desc.h

-- 
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


[RFC 5/9] usb: gadget: configfs: OS String support

2014-04-24 Thread Andrzej Pietrasiewicz
Add handling of OS String extension from the configfs interface.
A directory "os_desc" is added at the top level of a gadget's
directories hierarchy. In the "os_desc" directory there are
three attributes: "use", "b_vendor_code" and "qw_sign".
If "use" contains "0" the OS string is not reported to the host.
"b_vendor_code" contains a one-byte value which is used
for custom per-device and per-interface requests.
"qw_sign" contains an identifier to be reported as the "OS String"
proper.

Signed-off-by: Andrzej Pietrasiewicz 
---
 Documentation/ABI/testing/configfs-usb-gadget |  11 ++
 drivers/usb/gadget/configfs.c | 159 +-
 2 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget 
b/Documentation/ABI/testing/configfs-usb-gadget
index 37559a0..0e7b786 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget
+++ b/Documentation/ABI/testing/configfs-usb-gadget
@@ -79,3 +79,14 @@ Description:
product - gadget's product description
manufacturer- gadget's manufacturer description
 
+What:  /config/usb-gadget/gadget/os_desc
+Date:  May 2014
+KernelVersion: 3.16
+Description:
+   This group contains "OS String" extension handling attributes.
+
+   use - flag turning "OS Desctiptors" support on/off
+   b_vendor_code   - one-byte value used for custom per-device and
+   per-interface requests
+   qw_sign - an identifier to be reported as "OS String"
+   proper
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 7d1cc01..d37e60f 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -2,6 +2,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "configfs.h"
@@ -43,7 +44,8 @@ struct gadget_info {
struct config_group functions_group;
struct config_group configs_group;
struct config_group strings_group;
-   struct config_group *default_groups[4];
+   struct config_group os_desc_group;
+   struct config_group *default_groups[5];
 
struct mutex lock;
struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
@@ -56,6 +58,9 @@ struct gadget_info {
 #endif
struct usb_composite_driver composite;
struct usb_composite_dev cdev;
+   bool use_os_desc;
+   char b_vendor_code;
+   char qw_sign[OS_STRING_QW_SIGN_LEN];
 };
 
 struct config_usb_cfg {
@@ -79,6 +84,10 @@ struct gadget_strings {
struct list_head list;
 };
 
+struct os_desc {
+   struct config_group group;
+};
+
 struct gadget_config_name {
struct usb_gadget_strings stringtab_dev;
struct usb_string strings;
@@ -736,6 +745,145 @@ static void gadget_strings_attr_release(struct 
config_item *item)
 USB_CONFIG_STRING_RW_OPS(gadget_strings);
 USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info);
 
+static inline struct os_desc *to_os_desc(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct os_desc, group);
+}
+
+CONFIGFS_ATTR_STRUCT(os_desc);
+CONFIGFS_ATTR_OPS(os_desc);
+
+static ssize_t os_desc_use_show(struct os_desc *os_desc, char *page)
+{
+   struct gadget_info *gi;
+
+   gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
+
+   return sprintf(page, "%d", gi->use_os_desc);
+}
+
+static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page,
+size_t len)
+{
+   struct gadget_info *gi;
+   int ret;
+   bool use;
+
+   gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
+
+   mutex_lock(&gi->lock);
+   ret = strtobool(page, &use);
+   if (!ret) {
+   gi->use_os_desc = use;
+   ret = len;
+   }
+   mutex_unlock(&gi->lock);
+
+   return ret;
+}
+
+static struct os_desc_attribute os_desc_use =
+   __CONFIGFS_ATTR(use, S_IRUGO | S_IWUSR,
+   os_desc_use_show,
+   os_desc_use_store);
+
+static ssize_t os_desc_b_vendor_code_show(struct os_desc *os_desc, char *page)
+{
+   struct gadget_info *gi;
+
+   gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
+
+   return sprintf(page, "%d", gi->b_vendor_code);
+}
+
+static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc,
+  const char *page, size_t len)
+{
+   struct gadget_info *gi;
+   int ret;
+   u8 b_vendor_code;
+
+   gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
+
+   mutex_lock(&gi->lock);
+   ret = kstrtou8(page, 0, &b_vendor_code);
+   if (!ret) {
+   gi->b_vendor_code = b_vendor_code;
+   ret = len;
+   }
+   mutex_unlock(&gi->lock);
+
+   return ret;
+}
+
+static struct os_desc_attribute os_desc_b_vendor_code =
+   __C

[RFC 1/9] usb: gadget: FunctionFS: share VLA macros with all usb gadget files

2014-04-24 Thread Andrzej Pietrasiewicz
Variable Length Array macros allow portable (compilable with both gcc
and clang) way of allocating a number of structures using a single
memory chunk. They can be useful for files other than f_fs.c,
so move them to a header file.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/f_fs.c | 27 +--
 drivers/usb/gadget/u_f.h  | 26 ++
 2 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 1e12b3e..be2983a 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -33,36 +33,11 @@
 #include 
 
 #include "u_fs.h"
+#include "u_f.h"
 #include "configfs.h"
 
 #define FUNCTIONFS_MAGIC   0xa647361 /* Chosen by a honest dice roll ;) */
 
-/* Variable Length Array Macros **/
-#define vla_group(groupname) size_t groupname##__next = 0
-#define vla_group_size(groupname) groupname##__next
-
-#define vla_item(groupname, type, name, n) \
-   size_t groupname##_##name##__offset = ({   \
-   size_t align_mask = __alignof__(type) - 1; \
-   size_t offset = (groupname##__next + align_mask) & ~align_mask;\
-   size_t size = (n) * sizeof(type);  \
-   groupname##__next = offset + size; \
-   offset;\
-   })
-
-#define vla_item_with_sz(groupname, type, name, n) \
-   size_t groupname##_##name##__sz = (n) * sizeof(type);  \
-   size_t groupname##_##name##__offset = ({   \
-   size_t align_mask = __alignof__(type) - 1; \
-   size_t offset = (groupname##__next + align_mask) & ~align_mask;\
-   size_t size = groupname##_##name##__sz;\
-   groupname##__next = offset + size; \
-   offset;\
-   })
-
-#define vla_ptr(ptr, groupname, name) \
-   ((void *) ((char *)ptr + groupname##_##name##__offset))
-
 /* Reference counter handling */
 static void ffs_data_get(struct ffs_data *ffs);
 static void ffs_data_put(struct ffs_data *ffs);
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
index 71034c0..1d5f0eb 100644
--- a/drivers/usb/gadget/u_f.h
+++ b/drivers/usb/gadget/u_f.h
@@ -16,6 +16,32 @@
 #ifndef __U_F_H__
 #define __U_F_H__
 
+/* Variable Length Array Macros **/
+#define vla_group(groupname) size_t groupname##__next = 0
+#define vla_group_size(groupname) groupname##__next
+
+#define vla_item(groupname, type, name, n) \
+   size_t groupname##_##name##__offset = ({   \
+   size_t align_mask = __alignof__(type) - 1; \
+   size_t offset = (groupname##__next + align_mask) & ~align_mask;\
+   size_t size = (n) * sizeof(type);  \
+   groupname##__next = offset + size; \
+   offset;\
+   })
+
+#define vla_item_with_sz(groupname, type, name, n) \
+   size_t groupname##_##name##__sz = (n) * sizeof(type);  \
+   size_t groupname##_##name##__offset = ({   \
+   size_t align_mask = __alignof__(type) - 1; \
+   size_t offset = (groupname##__next + align_mask) & ~align_mask;\
+   size_t size = groupname##_##name##__sz;\
+   groupname##__next = offset + size; \
+   offset;\
+   })
+
+#define vla_ptr(ptr, groupname, name) \
+   ((void *) ((char *)ptr + groupname##_##name##__offset))
+
 struct usb_ep;
 struct usb_request;
 
-- 
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


[RFC 6/9] usb: gadget: configfs: OS Extended Compatibility descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz
Add handling of OS Extended Compatibility descriptors from configfs interface.
Hosts which expect the "OS Descriptors" ask only for configurations @ index 0,
but linux-based USB devices can provide more than one configuration.
This patch adds marking one of gadget's configurations the configuration
to be reported at index 0, regardless of the actual sequence of usb_add_config
invocations used for adding the configurations. The configuration is selected
by creating a symbolic link pointing to it from the "os_desc" directory
located at the top of a gadget's directory hierarchy.

One kind of "OS Descriptors" are "Extended Compatibility Descriptors",
which need to be specified per interface. This patch adds interface.
directory in function's configfs directory to represent each interface
defined by the function. Each interface's directory contains two attributes:
"compatible_id" and "sub_compatible_id", which represent 8-byte
strings to be reported to the host as the "Compatible ID" and "Sub Compatible
ID".

Signed-off-by: Andrzej Pietrasiewicz 
---
 Documentation/ABI/testing/configfs-usb-gadget |  13 ++
 drivers/usb/gadget/configfs.c | 190 ++
 drivers/usb/gadget/configfs.h |  12 ++
 include/linux/usb/composite.h |   6 +
 4 files changed, 221 insertions(+)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget 
b/Documentation/ABI/testing/configfs-usb-gadget
index 0e7b786..5c0b3e6 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget
+++ b/Documentation/ABI/testing/configfs-usb-gadget
@@ -62,6 +62,19 @@ KernelVersion:   3.11
 Description:
This group contains functions available to this USB gadget.
 
+What:  /config/usb-gadget/gadget/functions/./interface.
+Date:  May 2014
+KernelVersion: 3.16
+Description:
+   This group contains "Feature Descriptors" specific for one
+   gadget's USB interface or one interface group described
+   by an IAD.
+
+   The attributes:
+
+   compatible_id   - 8-byte string for "Compatible ID"
+   sub_compatible_id   - 8-byte string for "Sub Compatible ID"
+
 What:  /config/usb-gadget/gadget/strings
 Date:  Jun 2013
 KernelVersion: 3.11
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index d37e60f..26c0870 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include "configfs.h"
+#include "u_f.h"
 
 int check_user_usb_string(const char *name,
struct usb_gadget_strings *stringtab_dev)
@@ -872,10 +873,63 @@ static void os_desc_attr_release(struct config_item *item)
kfree(os_desc);
 }
 
+static int os_desc_link(struct config_item *os_desc_ci,
+   struct config_item *usb_cfg_ci)
+{
+   struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
+   struct gadget_info, os_desc_group);
+   struct usb_composite_dev *cdev = &gi->cdev;
+   struct config_usb_cfg *c_target =
+   container_of(to_config_group(usb_cfg_ci),
+struct config_usb_cfg, group);
+   struct usb_configuration *c;
+   int ret;
+
+   mutex_lock(&gi->lock);
+   list_for_each_entry(c, &cdev->configs, list) {
+   if (c == &c_target->c)
+   break;
+   }
+   if (c != &c_target->c) {
+   ret = -EINVAL;
+   goto out;
+   }
+
+   if (cdev->os_desc_config) {
+   ret = -EBUSY;
+   goto out;
+   }
+
+   cdev->os_desc_config = &c_target->c;
+   ret = 0;
+
+out:
+   mutex_unlock(&gi->lock);
+   return ret;
+}
+
+static int os_desc_unlink(struct config_item *os_desc_ci,
+ struct config_item *usb_cfg_ci)
+{
+   struct gadget_info *gi = container_of(to_config_group(os_desc_ci),
+   struct gadget_info, os_desc_group);
+   struct usb_composite_dev *cdev = &gi->cdev;
+
+   mutex_lock(&gi->lock);
+   if (gi->udc_name)
+   unregister_gadget(gi);
+   cdev->os_desc_config = NULL;
+   WARN_ON(gi->udc_name);
+   mutex_unlock(&gi->lock);
+   return 0;
+}
+
 static struct configfs_item_operations os_desc_ops = {
.release= os_desc_attr_release,
.show_attribute = os_desc_attr_show,
.store_attribute= os_desc_attr_store,
+   .allow_link = os_desc_link,
+   .drop_link  = os_desc_unlink,
 };
 
 static struct config_item_type os_desc_type = {
@@ -884,6 +938,133 @@ static struct config_item_type os_desc_type = {
.ct_owner   = THIS_MODULE,
 };
 
+CONFIGFS_ATTR_STRUCT(usb_os_desc);
+CONFIGFS_ATTR_OPS(usb_os_desc);
+
+static struct configfs_item_operations interf_item_ops = {
+   .show_at

[RFC 4/9] usb: gadget: f_rndis: OS descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz
In order for usb functions to expose OS descriptors they
need to be made aware of OS descriptors. This involves
extending the "options" structure and setting up
appropriate associations.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/f_rndis.c | 24 +---
 drivers/usb/gadget/u_rndis.h |  3 +++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index c11761c..b781a59 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -682,6 +682,15 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
 
rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
 
+   if (cdev->use_os_string) {
+   f->os_desc_table = kcalloc(1, sizeof(*f->os_desc_table),
+  GFP_KERNEL);
+   if (!f->os_desc_table)
+   return PTR_ERR(f->os_desc_table);
+   f->os_desc_n = 1;
+   f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc;
+   }
+
/*
 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
 * configurations are bound in sequence with list_for_each_entry,
@@ -693,14 +702,16 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
gether_set_gadget(rndis_opts->net, cdev->gadget);
status = gether_register_netdev(rndis_opts->net);
if (status)
-   return status;
+   goto fail;
rndis_opts->bound = true;
}
 
us = usb_gstrings_attach(cdev, rndis_strings,
 ARRAY_SIZE(rndis_string_defs));
-   if (IS_ERR(us))
-   return PTR_ERR(us);
+   if (IS_ERR(us)) {
+   status = PTR_ERR(us);
+   goto fail;
+   }
rndis_control_intf.iInterface = us[0].id;
rndis_data_intf.iInterface = us[1].id;
rndis_iad_descriptor.iFunction = us[2].id;
@@ -802,6 +813,8 @@ rndis_bind(struct usb_configuration *c, struct usb_function 
*f)
return 0;
 
 fail:
+   kfree(f->os_desc_table);
+   f->os_desc_n = 0;
usb_free_all_descriptors(f);
 
if (rndis->notify_req) {
@@ -892,6 +905,8 @@ static struct usb_function_instance *rndis_alloc_inst(void)
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
return ERR_PTR(-ENOMEM);
+   opts->rndis_os_desc.ext_compat_id = opts->rndis_ext_compat_id;
+
mutex_init(&opts->lock);
opts->func_inst.free_func_inst = rndis_free_inst;
opts->net = gether_setup_default();
@@ -900,6 +915,7 @@ static struct usb_function_instance *rndis_alloc_inst(void)
kfree(opts);
return ERR_CAST(net);
}
+   INIT_LIST_HEAD(&opts->rndis_os_desc.ext_prop);
 
config_group_init_type_name(&opts->func_inst.group, "",
&rndis_func_type);
@@ -925,6 +941,8 @@ static void rndis_unbind(struct usb_configuration *c, 
struct usb_function *f)
 {
struct f_rndis  *rndis = func_to_rndis(f);
 
+   kfree(f->os_desc_table);
+   f->os_desc_n = 0;
usb_free_all_descriptors(f);
 
kfree(rndis->notify_req->buf);
diff --git a/drivers/usb/gadget/u_rndis.h b/drivers/usb/gadget/u_rndis.h
index 7291b15..e902aa4 100644
--- a/drivers/usb/gadget/u_rndis.h
+++ b/drivers/usb/gadget/u_rndis.h
@@ -26,6 +26,9 @@ struct f_rndis_opts {
boolbound;
boolborrowed_net;
 
+   struct usb_os_desc  rndis_os_desc;
+   charrndis_ext_compat_id[16];
+
/*
 * Read/write access to configfs attributes is handled by configfs.
 *
-- 
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


[RFC 2/9] usb: gadget: OS String support

2014-04-24 Thread Andrzej Pietrasiewicz
There is a custom (non-USB IF) extension to the USB standard:

http://msdn.microsoft.com/library/windows/hardware/gg463182

The said extension is maintained by Microsoft for Microsoft.

Yet it is fairly common for various devices to use it, and a
popular proprietary operating system expects devices to provide
"OS descriptors", so Linux-based USB gadgets whishing to be able
to talk to a variety of operating systems should be able to provide
the "OS descriptors".

This patch adds optional support for gadgets whishing to expose
the so called "OS String" under index 0xEE of language 0.
The contents of the string is generated based on the qw_sign
array and b_vendor_code.

Interested gadgets need to set the cdev->use_os_string flag,
fill cdev->qw_sign with appropriate values and fill cdev->b_vendor_code
with a value of their choice.

This patch does not however implement responding to any vendor-specific
USB requests.

Signed-off-by: Andrzej Pietrasiewicz 
---
 drivers/usb/gadget/composite.c | 16 
 include/linux/usb/composite.h  | 14 ++
 2 files changed, 30 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index fab9064..0bfdb14 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -960,6 +960,22 @@ static int get_string(struct usb_composite_dev *cdev,
return s->bLength;
}
 
+   if (cdev->use_os_string && language == 0 && id == OS_STRING_IDX) {
+   /*
+* bLength|bDescriptorType|qwSignature|bMS_VendorCode|bPad
+* -
+* 1 Byte |1 Byte |14 Bytes   |1 Byte|1 Byte
+* -
+*/
+   u8 *b = buf;
+   b[0] = 0x12;
+   b[1] = USB_DT_STRING;
+   memcpy(&b[2], cdev->qw_sign, OS_STRING_QW_SIGN_LEN);
+   b[2 + OS_STRING_QW_SIGN_LEN] = cdev->b_vendor_code;
+   b[3 + OS_STRING_QW_SIGN_LEN] = 0;
+   return 0x12;
+   }
+
list_for_each_entry(uc, &cdev->gstrings, list) {
struct usb_gadget_strings **sp;
 
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index d3ca3b5..28e3b5d 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -335,11 +335,17 @@ static inline struct usb_composite_driver *to_cdriver(
return container_of(gdrv, struct usb_composite_driver, gadget_driver);
 }
 
+#define OS_STRING_QW_SIGN_LEN  14
+#define OS_STRING_IDX  0xEE
+
 /**
  * struct usb_composite_device - represents one composite usb gadget
  * @gadget: read-only, abstracts the gadget's usb peripheral controller
  * @req: used for control responses; buffer is pre-allocated
  * @config: the currently active configuration
+ * @use_os_string: false by default, interested gadgets set it
+ * @qw_sign: qwSignature part of the OS string
+ * @b_vendor_code: bMS_VendorCode part of the OS string
  *
  * One of these devices is allocated and initialized before the
  * associated device driver's bind() is called.
@@ -372,6 +378,14 @@ struct usb_composite_dev {
 
struct usb_configuration*config;
 
+   /*
+* OS String is a custom (yet popular) extension to the USB standard.
+*
+*/
+   unsigned intuse_os_string:1;
+   u8  qw_sign[OS_STRING_QW_SIGN_LEN];
+   u8  b_vendor_code;
+
/* private: */
/* internals */
unsigned intsuspended:1;
-- 
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


[RFC 8/9] usb: gadget: configfs: OS Extended Properties descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz
Add handling of OS Extended Properties descriptors from configfs interface.
One kind of "OS Descriptors" are "Extended Properties" descriptors, which
need to be specified per interface or per group of interfaces described
by an IAD. This patch adds support for creating subdirectories
in interface. directory located in the function's directory.
Names of subdirectories created become names of properties.
Each property contains two attributes: "type" and "data".
The type can be a numeric value 1..7 while data is a blob interpreted
depending on the type specified.
The types are:
1 - unicode string
2 - unicode string with environment variables
3 - binary
4 - little-endian 32-bit
5 - big-endian 32-bit
6 - unicode string with a symbolic link
7 - multiple unicode strings

Signed-off-by: Andrzej Pietrasiewicz 
---
 Documentation/ABI/testing/configfs-usb-gadget |  21 +++
 drivers/usb/gadget/configfs.c | 201 ++
 include/linux/usb/composite.h |   4 +
 3 files changed, 226 insertions(+)

diff --git a/Documentation/ABI/testing/configfs-usb-gadget 
b/Documentation/ABI/testing/configfs-usb-gadget
index 5c0b3e6..95a3658 100644
--- a/Documentation/ABI/testing/configfs-usb-gadget
+++ b/Documentation/ABI/testing/configfs-usb-gadget
@@ -75,6 +75,27 @@ Description:
compatible_id   - 8-byte string for "Compatible ID"
sub_compatible_id   - 8-byte string for "Sub Compatible ID"
 
+What:  
/config/usb-gadget/gadget/functions/./interface./
+Date:  May 2014
+KernelVersion: 3.16
+Description:
+   This group contains "Extended Property Descriptors" specific 
for one
+   gadget's USB interface or one interface group described
+   by an IAD.
+
+   The attributes:
+
+   type- value 1..7 for interpreting the data
+   1: unicode string
+   2: unicode string with environment variable
+   3: binary
+   4: little-endian 32-bit
+   5: big-endian 32-bit
+   6: unicode string with a symbolic link
+   7: multiple unicode strings
+   data- blob of data to be interpreted depending on
+   type
+
 What:  /config/usb-gadget/gadget/strings
 Date:  Jun 2013
 KernelVersion: 3.11
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 26c0870..5fbbe50 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -7,6 +7,7 @@
 #include 
 #include "configfs.h"
 #include "u_f.h"
+#include "u_os_desc.h"
 
 int check_user_usb_string(const char *name,
struct usb_gadget_strings *stringtab_dev)
@@ -941,6 +942,204 @@ static struct config_item_type os_desc_type = {
 CONFIGFS_ATTR_STRUCT(usb_os_desc);
 CONFIGFS_ATTR_OPS(usb_os_desc);
 
+
+static inline struct usb_os_desc_ext_prop
+*to_usb_os_desc_ext_prop(struct config_item *item)
+{
+   return container_of(item, struct usb_os_desc_ext_prop, item);
+}
+
+CONFIGFS_ATTR_STRUCT(usb_os_desc_ext_prop);
+CONFIGFS_ATTR_OPS(usb_os_desc_ext_prop);
+
+static ssize_t ext_prop_type_show(struct usb_os_desc_ext_prop *ext_prop,
+ char *page)
+{
+   return sprintf(page, "%d", ext_prop->type);
+}
+
+static ssize_t ext_prop_type_store(struct usb_os_desc_ext_prop *ext_prop,
+  const char *page, size_t len)
+{
+   struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
+   u8 type;
+   int ret;
+
+   if (desc->opts_mutex)
+   mutex_lock(desc->opts_mutex);
+   ret = kstrtou8(page, 0, &type);
+   if (ret)
+   goto end;
+   if (type < USB_EXT_PROP_UNICODE || type > USB_EXT_PROP_UNICODE_MULTI) {
+   ret = -EINVAL;
+   goto end;
+   }
+
+   if ((ext_prop->type == USB_EXT_PROP_BINARY ||
+   ext_prop->type == USB_EXT_PROP_LE32 ||
+   ext_prop->type == USB_EXT_PROP_BE32) &&
+   (type == USB_EXT_PROP_UNICODE ||
+   type == USB_EXT_PROP_UNICODE_ENV ||
+   type == USB_EXT_PROP_UNICODE_LINK))
+   ext_prop->data_len <<= 1;
+   else if ((ext_prop->type == USB_EXT_PROP_UNICODE ||
+  ext_prop->type == USB_EXT_PROP_UNICODE_ENV ||
+  ext_prop->type == USB_EXT_PROP_UNICODE_LINK) &&
+  (type == USB_EXT_PROP_BINARY ||
+  type == USB_EXT_PROP_LE32 ||
+  type == USB_EXT_PROP_BE32))
+   ext_prop->data_len >>= 1;
+   ext_prop->type = type;
+   ret = len;
+
+end:
+   if (desc->opts_mutex)
+   mutex_unlock(desc->opts_mutex);
+   return ret;
+}
+
+static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop,
+  

RE: [PATCH v2 0/3] Some update for USB OTG

2014-04-24 Thread Peter Chen

 
> >
> > > > >
> > > > > Hi Felipe,
> > > > >
> > > > > Two for fsm, the other one is to delete CONFIG_USB_OTG_FSM since
> > > > > it is duplicated with CONFIG_USB_OTG, thanks.
> > > > >
> > > > > Change on v1:
> > > > > Remove "{}" for a single statement in patch:
> > > > > usb: phy-fsm: update OTG HNP state transition.
> > > > >
> > > > > Li Jun (1):
> > > > >   usb: phy-fsm: update OTG HNP state transition
> > > > >
> > > > > Peter Chen (2):
> > > > >   usb: phy: delete CONFIG_USB_OTG_FSM
> > > > >   usb: phy-fsm: change "|" to "||" for condition
> > > OTG_STATE_A_WAIT_BCON
> > > > > at statemachine
> > > > >
> > > > >  drivers/usb/phy/Kconfig   |   11 +--
> > > > >  drivers/usb/phy/Makefile  |2 +-
> > > > >  drivers/usb/phy/phy-fsm-usb.c |9 +
> > > > >  3 files changed, 7 insertions(+), 15 deletions(-)
> > > > >
> > > > > --
> > > > > 1.7.9.5
> > > > >
> > > > >
> > > >
> > > > Hi Felipe,
> > > >
> > > > Would you give some comments for this patchset please? For the
> > > > patch
> > > > "usb: phy: delete CONFIG_USB_OTG_FSM", I sent it more than two
> > > > months ago, I need to know your comments if it can be accepted or
> > > > not, we are working on OTG FSM patchset for chipidea, and it is
> > > > close to review process, we need to know if we can use
> > > > CONFIG_USB_OTG_FSM to cover OTG
> > > > (fsm) code, or just CONFIG_USB_OTG is ok, thanks.
> > >
> > > I know you've sent this a long time ago and I've been banging my
> > > head ever since trying to decide if we should delete OTG FSM or not.
> > > On the one hand the OTG is pretty generic and aparently everybody
> > > would benefit from it but on the other hand we might have HW which
> > > implements the state machine without much SW control - though I
> > > can't remind of any good examples.
> > >
> > > Also, I think most of that code should be agnostic of the PHY layer
> > > and sit in usb-common.c. Quite frankly, OTG shouldn't depend on the
> > > PHY at all, we could very well have implementations which need/have
> > > no SW control over the PHY and still be fully OTG compliant.
> > >
> >
> > Thanks, I agreed with you too long time ago that otg should not be
> > related to PHY.
> > One more thing, I think we should move out otg staff from phy/, and
> > have a new folder named otg, if you agree with it, I can do it.
> 
> I think we can move code to usb-common/usb-otg.c or usb-otg-fsm.c or
> whatever. Just make sure to build it only if CONFIG_USB_OTG is enabled.
> 

Hi Felipe,

I am trying to move out usb otg things from phy folder, but still have some
concerns for it.

- There is no usb-common folder, only usb-common.c, if I move usb otg things
in usb-common.c, this file looks large (~500 lines), I wonder if we can
create a folder named usb-common, and put usb-common.c and usb-otg.c in it.
- Since the CONFIG_USB_OTG_FSM still exists, when the user goes to configure
kernel, he will see two configurations at menu, one is "USB 2.0 OTG FSM 
implementation"
and the other is "OTG support".

P.S: The two other patches in this patchset are bug fixes, help queue it please.

Thanks,
Peter
--
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: gadget: fsl: check vbus presence on probe

2014-04-24 Thread Paul Fertser
If VBUS is already present during the driver initialisation, the
corresponding IRQ never fires, so there is no way the gadget can get
enumerated.

This patch is real-life tested on an i.MX25 board with VBUS constantly
hooked up.

Signed-off-by: Paul Fertser 
---
 drivers/usb/gadget/fsl_udc_core.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/gadget/fsl_udc_core.c 
b/drivers/usb/gadget/fsl_udc_core.c
index a2f26cd..b4b1516 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2501,6 +2501,11 @@ static int __init fsl_udc_probe(struct platform_device 
*pdev)
if (ret)
goto err_del_udc;
 
+   /* Now let it settle a bit and sense VBUS */
+   msleep_interruptible(1);
+   if (fsl_readl(&dr_regs->otgsc) & OTGSC_STS_B_SESSION_VALID)
+   udc_controller->vbus_active = 1;
+
create_proc_file();
return 0;
 
-- 
1.7.10

--
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: dsps: move debugfs_remove_recursive()

2014-04-24 Thread Ezequiel Garcia
Felipe,

On Apr 22, Greg KH wrote:
> On Tue, Apr 22, 2014 at 10:26:13AM -0500, Felipe Balbi wrote:
> > On Tue, Apr 22, 2014 at 12:19:16PM -0300, Ezequiel Garcia wrote:
> > > 
> > > That way silly grass-hoppers like me won't have to go through the
> > > find-bisect-fix bug cycle, only to discover someone else already fixed
> > > it but the patch is floating around :-)
> > 
> > yeah, maybe.. I don't want to merge my fixes into next though. Maybe
> > Stephen could just merge both my branches on next. Greg, are you merging
> > your usb-linus into linux-next ?
> 
> Yes, both of my branches get merged into linux-next.
> 

Well, if it's not too much trouble, I'd really appreciate that you can find a
way to include these -rc fixes in the branches that get merged in -next.

Thanks!
-- 
Ezequiel García, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com
--
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: [RFC 0/9] OS Descriptors support

2014-04-24 Thread Andrzej Pietrasiewicz

W dniu 24.04.2014 11:17, Andrzej Pietrasiewicz pisze:

There is a custom (non-USB IF) extension to the USB standard:

http://msdn.microsoft.com/library/windows/hardware/gg463182

The said extension is maintained by Microsoft for Microsoft.

Yet it is fairly common for various devices to use it, and a
popular proprietary operating system expects devices to provide
"OS descriptors", so Linux-based USB gadgets whishing to be able
to talk to a variety of operating systems should be able to provide
the "OS descriptors".

This patch series adds (optional) support for gadgets whishing to expose
the so-called "OS Descriptors".

The sequence of operations when a gadget is enumerated by an OS which expects
the said descriptors is as following:

1) the host issues a standard "GET_DESCRIPTOR" request of type 0x03 (string)
for a string at index 0xEE in language 0, named "OS String"
2) if the device responds, the hosts interprets the response, and if it is
of expected form the host assumes the device supports "OS Descriptors"
3) the host issues requests to get "Feature Descriptors" it expects

There are two kinds of "Feature Descriptors": "Extended Compatibility"
descriptors and "Extended Properties" descriptors.
They are specified per USB interface or per USB interface group described
by an IAD.

Legacy gadgets (compiled as separate modules, like g_ether, g_serial etc)
can stay as they are and not use this extension; however PATCH 9/9
shows an example of converting g_ether to use "OS Descriptors" with RNDIS.
The intended use of the extension is with configfs interface, though.

This series contains an extension to the f_rndis function; if a function
whishes to support "OS Descriptors" it needs to be patched with a fairly
simple change: PATCH 4/9 contains code for supporting the extension proper,
while PATCH 7/9 contains code for using it with configfs.



I forgot to add an example of using "OS Descriptors" with configfs,
so here it is (I assume s3c-hsotg is used):

$ #USUAL STUFF
$ #===
$
$ modprobe libcomposite
$ mount none cfg -t configfs
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
$ mkdir configs/c.1
$ mkdir functions/rndis.usb0
$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
$ echo 0x > idProduct
$ echo 0x > idVendor
$ echo 123 > strings/0x409/serialnumber
$ echo manufacturer > strings/0x409/manufacturer
$ echo RNDIS Gadget > strings/0x409/product
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
$ echo 120 > configs/c.1/MaxPower
$
$ #OS DESCRIPTORS
$ #==
$
$ #OS STRING
$ #-
$
$echo 1 > os_desc/use
$ echo 0xcd > os_desc/b_vendor_code
$ echo MSFT100 > os_desc/qw_sign
$
$ #COMPATIBLE ID (SUB COMPATIBLE ID UNUSED)
$ #-
$
$ echo RNDIS > functions/rndis.usb0/os_desc/interface.0/compatible_id
$
$ #MAKE c.1 THE ONE ASSOCIATED WITH OS DESCRIPTORS
$ #---
$
$ ln -s configs/c.1 os_desc
$
$ #MAKE "Icons" EXTENDED PROPERTY
$ #--
$
$ mkdir functions/rndis.usb0/os_desc/interface.0/Icons
$ echo 2 > functions/rndis.usb0/os_desc/interface.0/Icons/type
$ echo "%SystemRoot%\\system32\\shell32.dll,-233" > 
functions/rndis.usb0/os_desc/interface.0/Icons/data
$
$ #MAKE "Label" EXTENDED PROPERTY
$ #--
$
$ mkdir functions/rndis.usb0/os_desc/interface.0/Label
$ echo 1 > functions/rndis.usb0/os_desc/interface.0/Label/type
$ echo "XYZ Device" > functions/rndis.usb0/os_desc/interface.0/Label/data
$
$ #USUAL STUFF, CONTINUED
$ #==
$
$ ln -s functions/rndis.usb0 configs/c.1
$ echo s3c-hsotg > UDC

AP


--
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 v4 0/3] usb: chipidea: msm: Clean and fix glue layer driver

2014-04-24 Thread Ivan T. Ivanov

Hi Peter, 

On Thu, 2014-04-24 at 08:38 +0800, Peter Chen wrote:
> On Wed, Apr 23, 2014 at 03:28:01PM +0300, Ivan T. Ivanov wrote:
> > From: "Ivan T. Ivanov" 
> > 
> > This series intend to fix driver, which was broken for a while.
> > It is used to create peripheral role device, which in coordination
> > with phy-usb-msm driver could provide USB2.0 gadget support for
> > Qualcomm targets.
> > 
> > Changes since version 3.
> > 
> >  - Fix typo in devicetree description file.
> > 
> > Previews version can be found here:
> 
> Since in your phy's patchset, you also access portsc which is in
> chipidea register region, it is not a standard way.
> In case, you will change something at chipidea driver in future
> when you re-work your next revision phy's patchset, I do not
> send this patchset to Greg right now.
> 

Did you see problems with _this_ particular patch set? There is no
direct dependency between PHY patches and these changes. 

Regards,
Ivan

> Once your phy's patchset has accepted, notify me. I will send
> this patchset to Greg.
> 
> Peter
> 
> > 
> > https://lkml.org/lkml/2014/4/22/195
> > 
> > Ivan T. Ivanov (3):
> >   usb: chipidea: msm: Add device tree binding information
> >   usb: chipidea: msm: Add device tree support
> >   usb: chipidea: msm: Initialize offset of the capability registers
> > 
> >  .../devicetree/bindings/usb/ci-hdrc-qcom.txt   | 17 +++
> >  drivers/usb/chipidea/ci_hdrc_msm.c | 24 
> > +-
> >  2 files changed, 40 insertions(+), 1 deletion(-)
> >  create mode 100644 Documentation/devicetree/bindings/usb/ci-hdrc-qcom.txt
> > 
> > --
> > 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: [PATCH] USB: serial: fix sysfs-attribute removal deadlock

2014-04-24 Thread Tejun Heo
On Thu, Apr 24, 2014 at 04:29:15PM +0800, Li Zhong wrote:
> On Wed, 2014-04-23 at 10:19 -0400, Tejun Heo wrote:
> > cc'ing Li Zhong who's working on a simliar issue in the following
> > thread and quoting whole body.
> > 
> >   http://thread.gmane.org/gmane.linux.kernel/1680706
> > 
> > Li, this is another variation of the same problem.  Maybe this can be
> > covered by your work too?
> 
> It seems to me that it is about write something to driver attribute, and
> driver unloading. If so, maybe it's not easy to reuse the help functions
> created for device attribute, and device removing.
> 
> But I guess the idea to break the active protection could still be
> applied here:
> 
> Maybe we could try_module_get() here (like the other option suggested by
> Johan?), and break active protection if we could get the module,
> something like below? 

I don't get why try_module_get() matters here.  We can't call into
->store if the object at hand is already destroyed and the underlying
module can't go away if the target device is still alive.
try_module_get() doesn't actually protect the object.  Why does that
matter?  This is self removal, right?  Can you please take a look at
kernfs_remove_self()?

Thanks.

-- 
tejun
--
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: dsps: move debugfs_remove_recursive()

2014-04-24 Thread Felipe Balbi
On Thu, Apr 24, 2014 at 08:29:17AM -0300, Ezequiel Garcia wrote:
> Felipe,
> 
> On Apr 22, Greg KH wrote:
> > On Tue, Apr 22, 2014 at 10:26:13AM -0500, Felipe Balbi wrote:
> > > On Tue, Apr 22, 2014 at 12:19:16PM -0300, Ezequiel Garcia wrote:
> > > > 
> > > > That way silly grass-hoppers like me won't have to go through the
> > > > find-bisect-fix bug cycle, only to discover someone else already fixed
> > > > it but the patch is floating around :-)
> > > 
> > > yeah, maybe.. I don't want to merge my fixes into next though. Maybe
> > > Stephen could just merge both my branches on next. Greg, are you merging
> > > your usb-linus into linux-next ?
> > 
> > Yes, both of my branches get merged into linux-next.
> > 
> 
> Well, if it's not too much trouble, I'd really appreciate that you can
> find a way to include these -rc fixes in the branches that get merged
> in -next.

done

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 1/4] xhci: A default implementation for Ux timeout calculation and tier policy check

2014-04-24 Thread Mathias Nyman

On 04/22/2014 07:27 AM, Pratyush Anand wrote:

As best case, a host controller should support U0 to U1 switching for
the devices connected below any tier of hub level supported by usb
specification. Therefore xhci_check_tier_policy should always return
success as default implementation.

A host should be able to issue LGO_Ux after the timeout calculated as
per definition of system exit latency defined in C.1.5.2. Therefore
xhci_calculate_ux_timeout returns ux_params.sel as the default
implementation.

Use default calculation in absence of any vendor specific limitations.

Signed-off-by: Pratyush Anand 
Tested-by: Aymen Bouattay 
---
  drivers/usb/host/xhci.c | 66 +++--
  1 file changed, 48 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6cc58fe..f5ac76a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4140,8 +4140,7 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device 
*udev,
return USB3_LPM_DISABLED;
  }

-/* Returns the hub-encoded U1 timeout value.
- * The U1 timeout should be the maximum of the following values:
+/* The U1 timeout should be the maximum of the following values:
   *  - For control endpoints, U1 system exit latency (SEL) * 3
   *  - For bulk endpoints, U1 SEL * 5
   *  - For interrupt endpoints:
@@ -4149,7 +4148,8 @@ static u16 xhci_get_timeout_no_hub_lpm(struct usb_device 
*udev,
   *- Periodic EPs, max(105% of bInterval, U1 SEL * 2)
   *  - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
   */
-static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
+static unsigned long long xhci_calculate_intel_u1_timeout(
+   struct usb_device *udev,
struct usb_endpoint_descriptor *desc)
  {
unsigned long long timeout_ns;
@@ -4181,11 +4181,28 @@ static u16 xhci_calculate_intel_u1_timeout(struct 
usb_device *udev,
return 0;
}

-   /* The U1 timeout is encoded in 1us intervals. */
-   timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);
-   /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */
+   return timeout_ns;
+}
+
+/* Returns the hub-encoded U1 timeout value. */
+static u16 xhci_calculate_u1_timeout(struct xhci_hcd *xhci,
+   struct usb_device *udev,
+   struct usb_endpoint_descriptor *desc)
+{
+   unsigned long long timeout_ns;
+
+   if (xhci->quirks & XHCI_INTEL_HOST)
+   timeout_ns = xhci_calculate_intel_u1_timeout(udev, desc);
+   else
+   timeout_ns = udev->u1_params.sel;
+
+   /* The U1 timeout is encoded in 1us intervals.
+* Don't return a timeout of zero, because that's USB3_LPM_DISABLED.
+*/
if (timeout_ns == USB3_LPM_DISABLED)
-   timeout_ns++;
+   timeout_ns = 1;
+   else
+   timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);

/* If the necessary timeout value is bigger than what we can set in the
 * USB 3.0 hub, we have to disable hub-initiated U1.
@@ -4197,14 +4214,14 @@ static u16 xhci_calculate_intel_u1_timeout(struct 
usb_device *udev,
return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1);
  }

-/* Returns the hub-encoded U2 timeout value.
- * The U2 timeout should be the maximum of:
+/* The U2 timeout should be the maximum of:
   *  - 10 ms (to avoid the bandwidth impact on the scheduler)
   *  - largest bInterval of any active periodic endpoint (to avoid going
   *into lower power link states between intervals).
   *  - the U2 Exit Latency of the device
   */
-static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev,
+static unsigned long long xhci_calculate_intel_u2_timeout(
+   struct usb_device *udev,
struct usb_endpoint_descriptor *desc)
  {
unsigned long long timeout_ns;
@@ -4220,6 +4237,21 @@ static u16 xhci_calculate_intel_u2_timeout(struct 
usb_device *udev,
if (u2_del_ns > timeout_ns)
timeout_ns = u2_del_ns;

+   return timeout_ns;
+}
+
+/* Returns the hub-encoded U2 timeout value. */
+static u16 xhci_calculate_u2_timeout(struct xhci_hcd *xhci,
+   struct usb_device *udev,
+   struct usb_endpoint_descriptor *desc)
+{
+   unsigned long long timeout_ns;
+
+   if (xhci->quirks & XHCI_INTEL_HOST)
+   timeout_ns = xhci_calculate_intel_u2_timeout(udev, desc);
+   else
+   timeout_ns = udev->u2_params.sel;
+
/* The U2 timeout is encoded in 256us intervals */
timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000);
/* If the necessary timeout value is bigger than what we can set in the
@@ -4238,13 +4270,10 @@ static u16 
xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci,
enum usb3_link_state state,
u16 *timeout)
  {
-   if (state == USB3_LPM_U1) {
-   if (xhci

Re: [PATCH] USB: serial: fix sysfs-attribute removal deadlock

2014-04-24 Thread Johan Hovold
On Thu, Apr 24, 2014 at 10:35:17AM -0400, Tejun Heo wrote:
> On Thu, Apr 24, 2014 at 04:29:15PM +0800, Li Zhong wrote:
> > On Wed, 2014-04-23 at 10:19 -0400, Tejun Heo wrote:
> > > cc'ing Li Zhong who's working on a simliar issue in the following
> > > thread and quoting whole body.
> > > 
> > >   http://thread.gmane.org/gmane.linux.kernel/1680706
> > > 
> > > Li, this is another variation of the same problem.  Maybe this can be
> > > covered by your work too?
> > 
> > It seems to me that it is about write something to driver attribute, and
> > driver unloading. If so, maybe it's not easy to reuse the help functions
> > created for device attribute, and device removing.
> > 
> > But I guess the idea to break the active protection could still be
> > applied here:
> > 
> > Maybe we could try_module_get() here (like the other option suggested by
> > Johan?), and break active protection if we could get the module,
> > something like below? 
> 
> I don't get why try_module_get() matters here.  We can't call into
> ->store if the object at hand is already destroyed and the underlying
> module can't go away if the target device is still alive.
> try_module_get() doesn't actually protect the object.  Why does that
> matter?  This is self removal, right?  Can you please take a look at
> kernfs_remove_self()?

No, this isn't self removal. The driver-attribute (not device-attribute)
store operation simply grabs a lock that is also held while the driver
is being deregistered at module unload. Taking a reference to the module
in this case will prevent deregistration while store is running.

But it seems like this can be solved for usb-serial by simply not
holding the lock while deregistering.

Johan
--
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 v2 0/3] Some update for USB OTG

2014-04-24 Thread Felipe Balbi
Hi,

On Thu, Apr 24, 2014 at 09:37:32AM +, Peter Chen wrote:

> > > > Also, I think most of that code should be agnostic of the PHY layer
> > > > and sit in usb-common.c. Quite frankly, OTG shouldn't depend on the
> > > > PHY at all, we could very well have implementations which need/have
> > > > no SW control over the PHY and still be fully OTG compliant.
> > > >
> > >
> > > Thanks, I agreed with you too long time ago that otg should not be
> > > related to PHY.
> > > One more thing, I think we should move out otg staff from phy/, and
> > > have a new folder named otg, if you agree with it, I can do it.
> > 
> > I think we can move code to usb-common/usb-otg.c or usb-otg-fsm.c or
> > whatever. Just make sure to build it only if CONFIG_USB_OTG is enabled.
> > 
> 
> Hi Felipe,
> 
> I am trying to move out usb otg things from phy folder, but still have some
> concerns for it.
> 
> - There is no usb-common folder, only usb-common.c, if I move usb otg
> things in usb-common.c, this file looks large (~500 lines), I wonder
> if we can create a folder named usb-common, and put usb-common.c and
> usb-otg.c in it.

sounds like a good approach to me, but Greg will have the final answer

> - Since the CONFIG_USB_OTG_FSM still exists, when the user goes to
> configure kernel, he will see two configurations at menu, one is "USB
> 2.0 OTG FSM implementation" and the other is "OTG support".

hmm... I see... There might be people who want to use OTG helpers but
not the generic FSM. MUSB, for instance, implements the OTG state
machine completely in HW.

> P.S: The two other patches in this patchset are bug fixes, help queue
> it please.

will do.

-- 
balbi


signature.asc
Description: Digital signature


[PATCH] usb: dwc3: gadget: pretty print link states

2014-04-24 Thread Felipe Balbi
this makes it slightly easier to read link state
change interrupt logs.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 39 ++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f0dc0ee..a8cf87b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -302,6 +302,42 @@ static const char *dwc3_gadget_ep_cmd_string(u8 cmd)
}
 }
 
+static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state)
+{
+   switch (link_state) {
+   case DWC3_LINK_STATE_U0:
+   return "U0";
+   case DWC3_LINK_STATE_U1:
+   return "U1";
+   case DWC3_LINK_STATE_U2:
+   return "U2";
+   case DWC3_LINK_STATE_U3:
+   return "U3";
+   case DWC3_LINK_STATE_SS_DIS:
+   return "SS.Disabled";
+   case DWC3_LINK_STATE_RX_DET:
+   return "RX.Detect";
+   case DWC3_LINK_STATE_SS_INACT:
+   return "SS.Inactive";
+   case DWC3_LINK_STATE_POLL:
+   return "Polling";
+   case DWC3_LINK_STATE_RECOV:
+   return "Recovery";
+   case DWC3_LINK_STATE_HRESET:
+   return "Hot Reset";
+   case DWC3_LINK_STATE_CMPLY:
+   return "Compliance";
+   case DWC3_LINK_STATE_LPBK:
+   return "Loopback";
+   case DWC3_LINK_STATE_RESET:
+   return "Reset";
+   case DWC3_LINK_STATE_RESUME:
+   return "Resume";
+   default:
+   return "UNKNOWN link state\n";
+   }
+}
+
 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, int cmd, u32 param)
 {
u32 timeout = 500;
@@ -2468,7 +2504,8 @@ static void dwc3_gadget_linksts_change_interrupt(struct 
dwc3 *dwc,
break;
}
 
-   dev_vdbg(dwc->dev, "%s link %d\n", __func__, dwc->link_state);
+   dev_vdbg(dwc->dev, "%s link %s\n", __func__,
+   dwc3_gadget_link_string(dwc->link_state));
 }
 
 static void dwc3_gadget_hibernation_interrupt(struct dwc3 *dwc,
-- 
1.9.2.459.g68773ac

--
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_dsps: fix the exit routine for debugfs

2014-04-24 Thread Felipe Balbi
Hi,

On Thu, Apr 24, 2014 at 11:07:34AM +0200, Olivier Gayot wrote:
> Ok, thank you, I didn't notice the existing thread.

no problem, but don't top-post please :-s

-- 
balbi


signature.asc
Description: Digital signature


[PATCH v7 03/20] usb: phy: msm: Move global regulators variables to driver state

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Eliminating global variables allows driver to handle multiple
device instances.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 82 ---
 include/linux/usb/msm_hsusb.h |  3 ++
 2 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 6ae4d2f..6bae936 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -58,47 +58,43 @@
 #define USB_PHY_VDD_DIG_VOL_MIN100 /* uV */
 #define USB_PHY_VDD_DIG_VOL_MAX132 /* uV */

-static struct regulator *hsusb_3p3;
-static struct regulator *hsusb_1p8;
-static struct regulator *hsusb_vddcx;
-
 static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
 {
int ret = 0;

if (init) {
-   hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
-   if (IS_ERR(hsusb_vddcx)) {
+   motg->vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
+   if (IS_ERR(motg->vddcx)) {
dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
-   return PTR_ERR(hsusb_vddcx);
+   return PTR_ERR(motg->vddcx);
}

-   ret = regulator_set_voltage(hsusb_vddcx,
+   ret = regulator_set_voltage(motg->vddcx,
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
return ret;
}

-   ret = regulator_enable(hsusb_vddcx);
+   ret = regulator_enable(motg->vddcx);
if (ret) {
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
}
} else {
-   ret = regulator_set_voltage(hsusb_vddcx, 0,
+   ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret)
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   ret = regulator_disable(hsusb_vddcx);
+   ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");

-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
}

return ret;
@@ -109,38 +105,38 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
int rc = 0;

if (init) {
-   hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
-   if (IS_ERR(hsusb_3p3)) {
+   motg->v3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
+   if (IS_ERR(motg->v3p3)) {
dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
-   return PTR_ERR(hsusb_3p3);
+   return PTR_ERR(motg->v3p3);
}

-   rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN,
+   rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 3p3\n");
goto put_3p3;
}
-   rc = regulator_enable(hsusb_3p3);
+   rc = regulator_enable(motg->v3p3);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
3p3\n");
goto put_3p3;
}
-   hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
-   if (IS_ERR(hsusb_1p8)) {
+   motg->v1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
+   if (IS_ERR(motg->v1p8)) {
dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
-   rc = PTR_ERR(hsusb_1p8);
+   rc = PTR_ERR(motg->v1p8);
goto disable_3p3;
}
-   rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN,
+   rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 1p8\n");
goto put_1p8;
}

[PATCH v7 01/20] usb: phy: msm: Make driver selectable on ARCH_QCOM

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Controller could be found on APQ and MSM platforms,
make configuration description more generic.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 416e0c8..0c668a3 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -171,11 +171,11 @@ config USB_ISP1301
  module will be called phy-isp1301.
 
 config USB_MSM_OTG
-   tristate "OTG support for Qualcomm on-chip USB controller"
-   depends on (USB || USB_GADGET) && ARCH_MSM
+   tristate "Qualcomm on-chip USB OTG controller support"
+   depends on (USB || USB_GADGET) && (ARCH_MSM || ARCH_QCOM)
select USB_PHY
help
- Enable this to support the USB OTG transceiver on MSM chips. It
+ Enable this to support the USB OTG transceiver on Qualcomm chips. It
  handles PHY initialization, clock management, and workarounds
  required after resetting the hardware and power management.
  This driver is required even for peripheral only or host only
-- 
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 v7 19/20] usb: phy: msm: Vote for corner of VDD CX instead of voltage of VDD CX

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

New platform uses RBCPR hardware feature, with that voting for
absolute voltage of VDD CX is not required. Hence vote for corner of
VDD CX which uses nominal corner voltage on VDD CX.

Signed-off-by: Ivan T. Ivanov 
Cc: Mayank Rana 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |  5 
 drivers/usb/phy/phy-msm-usb.c  | 35 +-
 include/linux/usb/msm_hsusb.h  |  1 +
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index 0669667..2826f2a 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -65,6 +65,10 @@ Optional properties:
 Some platforms may have configuration to allow USB
 controller work with any of the two HSPHYs present.

+- qcom,vdd-levels: This property must be a list of three integer values
+(no, min, max) where each value represents either a voltage
+in microvolts or a value corresponding to voltage corner.
+
 Example HSUSB OTG controller device node:

 usb@f9a55000 {
@@ -87,4 +91,5 @@ Example HSUSB OTG controller device node:

 qcom,otg-control = <1>;
 qcom,phy-init-sequence = < -1 0x63 >;
+qcom,vdd-levels = <1 5 7>;
};
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 602e6c8..9240f5b 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -62,6 +62,13 @@

 #define USB_PHY_VDD_DIG_VOL_MIN100 /* uV */
 #define USB_PHY_VDD_DIG_VOL_MAX132 /* uV */
+#define USB_PHY_SUSP_DIG_VOL   50  /* uV */
+
+enum vdd_levels {
+   VDD_LEVEL_NONE = 0,
+   VDD_LEVEL_MIN,
+   VDD_LEVEL_MAX,
+};

 static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
 {
@@ -69,8 +76,8 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)

if (init) {
ret = regulator_set_voltage(motg->vddcx,
-   USB_PHY_VDD_DIG_VOL_MIN,
-   USB_PHY_VDD_DIG_VOL_MAX);
+   motg->vdd_levels[VDD_LEVEL_MIN],
+   motg->vdd_levels[VDD_LEVEL_MAX]);
if (ret) {
dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
return ret;
@@ -81,7 +88,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
} else {
ret = regulator_set_voltage(motg->vddcx, 0,
-   USB_PHY_VDD_DIG_VOL_MAX);
+   motg->vdd_levels[VDD_LEVEL_MAX]);
if (ret)
dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
ret = regulator_disable(motg->vddcx);
@@ -435,17 +442,16 @@ static int msm_phy_init(struct usb_phy *phy)

 #ifdef CONFIG_PM

-#define USB_PHY_SUSP_DIG_VOL  50
 static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high)
 {
-   int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
+   int max_vol = motg->vdd_levels[VDD_LEVEL_MAX];
int min_vol;
int ret;

if (high)
-   min_vol = USB_PHY_VDD_DIG_VOL_MIN;
+   min_vol = motg->vdd_levels[VDD_LEVEL_MIN];
else
-   min_vol = USB_PHY_SUSP_DIG_VOL;
+   min_vol = motg->vdd_levels[VDD_LEVEL_NONE];

ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol);
if (ret) {
@@ -1441,7 +1447,7 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
struct device_node *node = pdev->dev.of_node;
struct property *prop;
int len, ret, words;
-   u32 val;
+   u32 val, tmp[3];

pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
@@ -1472,6 +1478,19 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2)
motg->phy_number = val;

+   motg->vdd_levels[VDD_LEVEL_NONE] = USB_PHY_SUSP_DIG_VOL;
+   motg->vdd_levels[VDD_LEVEL_MIN] = USB_PHY_VDD_DIG_VOL_MIN;
+   motg->vdd_levels[VDD_LEVEL_MAX] = USB_PHY_VDD_DIG_VOL_MAX;
+
+   if (of_get_property(node, "qcom,vdd-levels", &len) &&
+   len == sizeof(tmp)) {
+   of_property_read_u32_array(node, "qcom,vdd-levels",
+  tmp, len / sizeof(*tmp));
+   motg->vdd_levels[VDD_LEVEL_NONE] = tmp[VDD_LEVEL_NONE];
+   motg->vdd_levels[VDD_LEVEL_MIN] = tmp[VDD_LEVEL_MIN];
+   motg->vdd_levels[VDD_LEVEL_MAX] = tmp[VDD_LEVEL_MAX];
+   }
+
prop = of_find_property(node, "qcom,phy-init-sequence", &len);

[PATCH v7 20/20] usb: phy: msm: Use usb_add_phy_dev() to register device

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

They could be more than one USB2.0 PHY's on the platform.
This will allow all of them to be registred successfuly.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 9240f5b..7283005 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1668,6 +1668,7 @@ static int msm_otg_probe(struct platform_device *pdev)
phy->init = msm_phy_init;
phy->set_power = msm_otg_set_power;
phy->notify_disconnect = msm_phy_notify_disconnect;
+   phy->type = USB_PHY_TYPE_USB2;

phy->io_ops = &msm_otg_io_ops;

@@ -1677,7 +1678,7 @@ static int msm_otg_probe(struct platform_device *pdev)

msm_usb_reset(phy);

-   ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2);
+   ret = usb_add_phy_dev(&motg->phy);
if (ret) {
dev_err(&pdev->dev, "usb_add_phy failed\n");
goto disable_ldo;
--
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 v7 04/20] usb: phy: msm: Enable deferred driver probing

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Using platform_driver_probe() prevent driver from requesting
probe deferral. Fix this.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 6bae936..b7d73f2 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1736,6 +1736,7 @@ static const struct dev_pm_ops msm_otg_dev_pm_ops = {
 };

 static struct platform_driver msm_otg_driver = {
+   .probe = msm_otg_probe,
.remove = msm_otg_remove,
.driver = {
.name = DRIVER_NAME,
@@ -1744,7 +1745,7 @@ static struct platform_driver msm_otg_driver = {
},
 };

-module_platform_driver_probe(msm_otg_driver, msm_otg_probe);
+module_platform_driver(msm_otg_driver);

 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("MSM USB transceiver driver");
--
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 v7 18/20] usb: phy: msm: Handle disconnect events

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Put the transceiver in non-driving mode. Otherwise host
may not detect soft-disconnection.

Signed-off-by: Ivan T. Ivanov 
Cc: Pavankumar Kondeti 
---
 drivers/usb/phy/phy-msm-usb.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 1554f69..602e6c8 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -235,6 +235,23 @@ static void ulpi_init(struct msm_otg *motg)
}
 }

+static int msm_phy_notify_disconnect(struct usb_phy *phy,
+  enum usb_device_speed speed)
+{
+   int val;
+
+   /*
+* Put the transceiver in non-driving mode. Otherwise host
+* may not detect soft-disconnection.
+*/
+   val = ulpi_read(phy, ULPI_FUNC_CTRL);
+   val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
+   val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
+   ulpi_write(phy, val, ULPI_FUNC_CTRL);
+
+   return 0;
+}
+
 static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
 {
int ret;
@@ -1631,6 +1648,7 @@ static int msm_otg_probe(struct platform_device *pdev)

phy->init = msm_phy_init;
phy->set_power = msm_otg_set_power;
+   phy->notify_disconnect = msm_phy_notify_disconnect;

phy->io_ops = &msm_otg_io_ops;

--
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 v7 13/20] usb: phy: msm: Use reset framework for LINK and PHY resets

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Using reset framework eliminate need of platform specific
callbacks and enable reset lines to be specified in DT files.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 29 +
 include/linux/usb/msm_hsusb.h |  3 +++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 4ed1ded..6ad1396 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -235,12 +236,15 @@ static void ulpi_init(struct msm_otg *motg)

 static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
 {
-   int ret = 0;
+   int ret;

-   if (!motg->pdata->link_clk_reset)
-   return ret;
+   if (motg->pdata->link_clk_reset)
+   ret = motg->pdata->link_clk_reset(motg->clk, assert);
+   else if (assert)
+   ret = reset_control_assert(motg->link_rst);
+   else
+   ret = reset_control_deassert(motg->link_rst);

-   ret = motg->pdata->link_clk_reset(motg->clk, assert);
if (ret)
dev_err(motg->phy.dev, "usb link clk reset %s failed\n",
assert ? "assert" : "deassert");
@@ -250,12 +254,13 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, 
bool assert)

 static int msm_otg_phy_clk_reset(struct msm_otg *motg)
 {
-   int ret = 0;
+   int ret;

-   if (!motg->pdata->phy_clk_reset)
-   return ret;
+   if (motg->pdata->phy_clk_reset)
+   ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk);
+   else
+   ret = reset_control_reset(motg->phy_rst);

-   ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk);
if (ret)
dev_err(motg->phy.dev, "usb phy clk reset failed\n");

@@ -1377,6 +1382,14 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
id = of_match_device(msm_otg_dt_match, &pdev->dev);
pdata->phy_type = (int) id->data;

+   motg->link_rst = devm_reset_control_get(&pdev->dev, "link");
+   if (IS_ERR(motg->link_rst))
+   return PTR_ERR(motg->link_rst);
+
+   motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy");
+   if (IS_ERR(motg->phy_rst))
+   return PTR_ERR(motg->phy_rst);
+
pdata->mode = of_usb_get_dr_mode(node);
if (pdata->mode == USB_DR_MODE_UNKNOWN)
pdata->mode = USB_DR_MODE_OTG;
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index bd68299..4e5d916 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -165,6 +165,9 @@ struct msm_otg {
struct regulator *v3p3;
struct regulator *v1p8;
struct regulator *vddcx;
+
+   struct reset_control *phy_rst;
+   struct reset_control *link_rst;
 };

 #endif
--
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 v7 15/20] usb: phy: msm: Correct USB PHY Reset sequence for newer platform

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

On few legacy platforms, USB PHY is having dedicated reset clk.
It is used to reset USB PHY after putting USB PHY into low power
mode and for calibration of USB PHY. Putting USB PHY into low
power mode is causing ulpi read/write timeout as expected. USB PHY
reset clk is not available on newer platform.

For 28nm PHY, reset USB PHY after resestting USB LINK.
Also reset USB PHY using USB_PHY_PON bit with USB_OTG_HS_PHY_CTRL
register after programming USB PHY Override registers as suggested
with hardware programming guidelines.

Signed-off-by: Ivan T. Ivanov 
Signed-off-by: Tim Bird 
Cc: Mayank Rana 
---
 drivers/usb/phy/phy-msm-usb.c| 140 ---
 include/linux/usb/msm_hsusb_hw.h |   5 ++
 2 files changed, 93 insertions(+), 52 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index c3877ec..d949018 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -48,6 +48,7 @@
 #define DRIVER_NAME"msm_otg"

 #define ULPI_IO_TIMEOUT_USEC   (10 * 1000)
+#define LINK_RESET_TIMEOUT_USEC(250 * 1000)

 #define USB_PHY_3P3_VOL_MIN305 /* uV */
 #define USB_PHY_3P3_VOL_MAX330 /* uV */
@@ -267,77 +268,35 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg)
return ret;
 }

-static int msm_otg_phy_reset(struct msm_otg *motg)
+static int msm_link_reset(struct msm_otg *motg)
 {
u32 val;
int ret;
-   int retries;

ret = msm_otg_link_clk_reset(motg, 1);
if (ret)
return ret;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   ret = msm_otg_link_clk_reset(motg, 0);
-   if (ret)
-   return ret;

-   val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
-   writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
-
-   for (retries = 3; retries > 0; retries--) {
-   ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM,
-   ULPI_CLR(ULPI_FUNC_CTRL));
-   if (!ret)
-   break;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   }
-   if (!retries)
-   return -ETIMEDOUT;
+   /* wait for 1ms delay as suggested in HPG. */
+   usleep_range(1000, 1200);

-   /* This reset calibrates the phy, if the above write succeeded */
-   ret = msm_otg_phy_clk_reset(motg);
+   ret = msm_otg_link_clk_reset(motg, 0);
if (ret)
return ret;

-   for (retries = 3; retries > 0; retries--) {
-   ret = ulpi_read(&motg->phy, ULPI_DEBUG);
-   if (ret != -ETIMEDOUT)
-   break;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   }
-   if (!retries)
-   return -ETIMEDOUT;
-
if (motg->phy_number)
writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);

-   dev_info(motg->phy.dev, "phy_reset: success\n");
+   val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
+   writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
+
return 0;
 }

-#define LINK_RESET_TIMEOUT_USEC(250 * 1000)
 static int msm_otg_reset(struct usb_phy *phy)
 {
struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
-   struct msm_otg_platform_data *pdata = motg->pdata;
int cnt = 0;
-   int ret;
-   u32 val = 0;
-   u32 ulpi_val = 0;
-
-   ret = msm_otg_phy_reset(motg);
-   if (ret) {
-   dev_err(phy->dev, "phy_reset failed\n");
-   return ret;
-   }
-
-   ulpi_init(motg);

writel(USBCMD_RESET, USB_USBCMD);
while (cnt < LINK_RESET_TIMEOUT_USEC) {
@@ -351,11 +310,86 @@ static int msm_otg_reset(struct usb_phy *phy)

/* select ULPI phy */
writel(0x8000, USB_PORTSC);
+   writel(0x0, USB_AHBBURST);
+   writel(0x08, USB_AHBMODE);
+
+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+   return 0;
+}
+
+static void msm_phy_reset(struct msm_otg *motg)
+{
+   void __iomem *addr;
+
+   if (motg->pdata->phy_type != SNPS_28NM_INTEGRATED_PHY) {
+   msm_otg_phy_clk_reset(motg);
+   return;
+   }
+
+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
+   /* Assert USB PHY_POR */
+   writel(readl(addr) | PHY_POR_ASSERT, addr);
+
+   /*
+* wait for minimum 10 microseconds as suggested in HPG.
+* Use a slightly larger value since the exact value didn't
+* work 100% of the time.
+*/
+   udelay(12);
+
+   /* Deassert USB PHY_POR */
+   writel(readl(addr) & ~PHY_POR_ASSERT, addr);
+}
+
+static int msm_usb_reset(struct usb_phy *phy)
+{
+   struct msm_otg *motg = container_of(phy, struct msm

[PATCH v7 02/20] usb: phy: msm: Remove __init macro from driver probe method

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

This fixes following:

WARNING: drivers/usb/phy/built-in.o(.data+0x68): Section mismatch in reference 
from the variable msm_otg_driver to the function .init.text:msm_otg_probe()
The variable msm_otg_driver references
the function __init msm_otg_probe()

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 5b37b81..6ae4d2f 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1406,7 +1406,7 @@ static void msm_otg_debugfs_cleanup(void)
debugfs_remove(msm_otg_dbg_root);
 }
 
-static int __init msm_otg_probe(struct platform_device *pdev)
+static int msm_otg_probe(struct platform_device *pdev)
 {
int ret = 0;
struct resource *res;
-- 
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 v7 17/20] usb: phy: msm: Select secondary PHY via TCSR

2014-04-24 Thread Ivan T. Ivanov
From: Tim Bird 

Select the secondary PHY using the TCSR register, if phy-num=1
in the DTS (or phy_number is set in the platform data).  The
SOC has 2 PHYs which can be used with the OTG port, and this
code allows configuring the correct one.

Note: This resolves the problem I was seeing where I couldn't
get the USB driver working at all on a dragonboard, from cold
boot.  This patch depends on patch 5/14 from Ivan's msm USB
patch set.  It does not use DT for the register address, as
there's no evidence that this address changes between SoC
versions.

Signed-off-by: Tim Bird 
---
 drivers/usb/phy/phy-msm-usb.c| 14 ++
 include/linux/usb/msm_hsusb_hw.h |  3 +++
 2 files changed, 17 insertions(+)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 06d79c1..1554f69 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1488,6 +1488,7 @@ static int msm_otg_probe(struct platform_device *pdev)
struct resource *res;
struct msm_otg *motg;
struct usb_phy *phy;
+   void __iomem *phy_select;

motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL);
if (!motg) {
@@ -1552,6 +1553,19 @@ static int msm_otg_probe(struct platform_device *pdev)
if (IS_ERR(motg->regs))
return PTR_ERR(motg->regs);

+   /*
+* NOTE: The PHYs can be multiplexed between the chipidea controller
+* and the dwc3 controller, using a single bit. It is important that
+* the dwc3 driver does not set this bit in an incompatible way.
+*/
+   if (motg->phy_number) {
+   phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4);
+   if (IS_ERR(phy_select))
+   return PTR_ERR(phy_select);
+   /* Enable second PHY with the OTG port */
+   writel_relaxed(0x1, phy_select);
+   }
+
dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);

motg->irq = platform_get_irq(pdev, 0);
diff --git a/include/linux/usb/msm_hsusb_hw.h b/include/linux/usb/msm_hsusb_hw.h
index 98d3dd8..a29f603 100644
--- a/include/linux/usb/msm_hsusb_hw.h
+++ b/include/linux/usb/msm_hsusb_hw.h
@@ -16,6 +16,9 @@
 #ifndef __LINUX_USB_GADGET_MSM72K_UDC_H__
 #define __LINUX_USB_GADGET_MSM72K_UDC_H__

+/* USB phy selector - in TCSR address range */
+#define USB2_PHY_SEL 0xfd4ab000
+
 #define USB_AHBBURST (MSM_USB_BASE + 0x0090)
 #define USB_AHBMODE  (MSM_USB_BASE + 0x0098)
 #define USB_CAPLENGTH(MSM_USB_BASE + 0x0100) /* 8 bit */
--
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 v7 16/20] usb: phy: msm: Fix PTS definitions for MSM USB controller

2014-04-24 Thread Ivan T. Ivanov
From: Tim Bird 

Fix the value used for Parallel Transceiver Select (PTS) for the MSM USB
controller.  This is a standard chipidea PORTSC definition, where
a PHY_TYPE of 10b (<<30) is ULPI and 11b (<<30) is SERIAL.
Fix the definitions and use them correctly in the driver code.

Signed-off-by: Tim Bird 
---
 drivers/usb/phy/phy-msm-usb.c| 8 +---
 include/linux/usb/msm_hsusb_hw.h | 5 +++--
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index d949018..06d79c1 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -287,8 +287,9 @@ static int msm_link_reset(struct msm_otg *motg)
if (motg->phy_number)
writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);

+   /* put transceiver in serial mode as part of reset */
val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
-   writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
+   writel(val | PORTSC_PTS_SERIAL, USB_PORTSC);

return 0;
 }
@@ -308,8 +309,9 @@ static int msm_otg_reset(struct usb_phy *phy)
if (cnt >= LINK_RESET_TIMEOUT_USEC)
return -ETIMEDOUT;

-   /* select ULPI phy */
-   writel(0x8000, USB_PORTSC);
+   /* select ULPI phy and clear other status/control bits in PORTSC */
+   writel(PORTSC_PTS_ULPI, USB_PORTSC);
+
writel(0x0, USB_AHBBURST);
writel(0x08, USB_AHBMODE);

diff --git a/include/linux/usb/msm_hsusb_hw.h b/include/linux/usb/msm_hsusb_hw.h
index 575c743..98d3dd8 100644
--- a/include/linux/usb/msm_hsusb_hw.h
+++ b/include/linux/usb/msm_hsusb_hw.h
@@ -31,8 +31,9 @@
 #define USB_USBINTR  (MSM_USB_BASE + 0x0148)

 #define PORTSC_PHCD(1 << 23) /* phy suspend mode */
-#define PORTSC_PTS_MASK (3 << 30)
-#define PORTSC_PTS_ULPI (3 << 30)
+#define PORTSC_PTS_MASK(3 << 30)
+#define PORTSC_PTS_ULPI(2 << 30)
+#define PORTSC_PTS_SERIAL  (3 << 30)

 #define USB_ULPI_VIEWPORT(MSM_USB_BASE + 0x0170)
 #define ULPI_RUN  (1 << 30)
--
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 v7 14/20] usb: phy: msm: Add support for secondary PHY control

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Allow support to use 2nd HSPHY with USB2 Core.
Some platforms may have configuration to allow USB controller
work with any of the two HSPHYs present. By default driver
configures USB core to use primary HSPHY. Add support to allow
user select 2nd HSPHY using DT parameter.

Signed-off-by: Ivan T. Ivanov 
Cc: Manu Gautam 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |  6 ++
 drivers/usb/phy/phy-msm-usb.c  | 24 --
 include/linux/usb/msm_hsusb.h  |  1 +
 include/linux/usb/msm_hsusb_hw.h   |  1 +
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index ee4123d..0669667 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -59,6 +59,12 @@ Optional properties:
 For example: qcom,phy-init-sequence = < -1 0x63 >;
 Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1.

+- qcom,phy-num: Select number of pyco-phy to use, can be one of
+0 - PHY one, default
+1 - Second PHY
+Some platforms may have configuration to allow USB
+controller work with any of the two HSPHYs present.
+
 Example HSUSB OTG controller device node:

 usb@f9a55000 {
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 6ad1396..c3877ec 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -314,6 +314,9 @@ static int msm_otg_phy_reset(struct msm_otg *motg)
if (!retries)
return -ETIMEDOUT;

+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+
dev_info(motg->phy.dev, "phy_reset: success\n");
return 0;
 }
@@ -368,6 +371,9 @@ static int msm_otg_reset(struct usb_phy *phy)
ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL);
}

+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+
return 0;
 }

@@ -404,6 +410,7 @@ static int msm_otg_suspend(struct msm_otg *motg)
struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = phy->otg->host;
struct msm_otg_platform_data *pdata = motg->pdata;
+   void __iomem *addr;
int cnt = 0;

if (atomic_read(&motg->in_lpm))
@@ -463,9 +470,13 @@ static int msm_otg_suspend(struct msm_otg *motg)
 */
writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD);

+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL)
-   writel(readl(USB_PHY_CTRL) | PHY_RETEN, USB_PHY_CTRL);
+   writel(readl(addr) | PHY_RETEN, addr);

clk_disable_unprepare(motg->pclk);
clk_disable_unprepare(motg->clk);
@@ -495,6 +506,7 @@ static int msm_otg_resume(struct msm_otg *motg)
 {
struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = phy->otg->host;
+   void __iomem *addr;
int cnt = 0;
unsigned temp;

@@ -508,9 +520,14 @@ static int msm_otg_resume(struct msm_otg *motg)

if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL) {
+
+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
msm_hsusb_ldo_set_mode(motg, 1);
msm_hsusb_config_vddcx(motg, 1);
-   writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL);
+   writel(readl(addr) & ~PHY_RETEN, addr);
}

temp = readl(USB_USBCMD);
@@ -1399,6 +1416,9 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
if (val == OTG_PMIC_CONTROL)
pdata->otg_control = val;

+   if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2)
+   motg->phy_number = val;
+
prop = of_find_property(node, "qcom,phy-init-sequence", &len);
if (!prop || !len)
return 0;
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 4e5d916..4628f1a 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -158,6 +158,7 @@ struct msm_otg {
atomic_t in_lpm;
int async_int;
unsigned cur_power;
+   int phy_number;
struct delayed_work chg_work;
enum usb_chg_state chg_state;
enum usb_chg_type chg_type;
diff --git a/include/linux/usb/msm_hsusb_hw.h b/include/linux/usb/msm_hsusb_hw.h
index 6e97a2d..e6d7035 100644
--- a/include/linux/usb/msm_hsusb_hw.h
+++ b/include/linux/u

[PATCH v7 11/20] usb: phy: msm: Properly check result from platform_get_irq()

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Function return negative code on error.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 5d64038..8a7a324 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1412,7 +1412,7 @@ static int msm_otg_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);

motg->irq = platform_get_irq(pdev, 0);
-   if (!motg->irq) {
+   if (motg->irq < 0) {
dev_err(&pdev->dev, "platform_get_irq failed\n");
return motg->irq;
}
--
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 v7 08/20] usb: phy: msm: Replace custom enum usb_mode_type with enum usb_dr_mode

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Use enum usb_dr_mode and drop default usb_dr_mode from platform data.

USB DT bindings states: dr_mode: "...In case this attribute isn't
passed via DT, USB DRD controllers should default to OTG...",
so remove redundand field.

Signed-off-by: Ivan T. Ivanov 
Acked-by: David Brown 
---
 arch/arm/mach-msm/board-msm7x30.c |  2 +-
 arch/arm/mach-msm/board-qsd8x50.c |  2 +-
 drivers/usb/phy/phy-msm-usb.c | 41 ---
 include/linux/usb/msm_hsusb.h | 20 +--
 4 files changed, 20 insertions(+), 45 deletions(-)

diff --git a/arch/arm/mach-msm/board-msm7x30.c 
b/arch/arm/mach-msm/board-msm7x30.c
index 46de789..0c4c200 100644
--- a/arch/arm/mach-msm/board-msm7x30.c
+++ b/arch/arm/mach-msm/board-msm7x30.c
@@ -95,7 +95,7 @@ static int hsusb_phy_clk_reset(struct clk *phy_clk)

 static struct msm_otg_platform_data msm_otg_pdata = {
.phy_init_seq   = hsusb_phy_init_seq,
-   .mode   = USB_PERIPHERAL,
+   .mode   = USB_DR_MODE_PERIPHERAL,
.otg_control= OTG_PHY_CONTROL,
.link_clk_reset = hsusb_link_clk_reset,
.phy_clk_reset  = hsusb_phy_clk_reset,
diff --git a/arch/arm/mach-msm/board-qsd8x50.c 
b/arch/arm/mach-msm/board-qsd8x50.c
index 9169ec3..4c74861 100644
--- a/arch/arm/mach-msm/board-qsd8x50.c
+++ b/arch/arm/mach-msm/board-qsd8x50.c
@@ -116,7 +116,7 @@ static int hsusb_phy_clk_reset(struct clk *phy_clk)

 static struct msm_otg_platform_data msm_otg_pdata = {
.phy_init_seq   = hsusb_phy_init_seq,
-   .mode   = USB_PERIPHERAL,
+   .mode   = USB_DR_MODE_PERIPHERAL,
.otg_control= OTG_PHY_CONTROL,
.link_clk_reset = hsusb_link_clk_reset,
.phy_clk_reset  = hsusb_phy_clk_reset,
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 3855217..a67c8a2 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -348,10 +348,10 @@ static int msm_otg_reset(struct usb_phy *phy)

if (pdata->otg_control == OTG_PHY_CONTROL) {
val = readl(USB_OTGSC);
-   if (pdata->mode == USB_OTG) {
+   if (pdata->mode == USB_DR_MODE_OTG) {
ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID;
val |= OTGSC_IDIE | OTGSC_BSVIE;
-   } else if (pdata->mode == USB_PERIPHERAL) {
+   } else if (pdata->mode == USB_DR_MODE_PERIPHERAL) {
ulpi_val = ULPI_INT_SESS_VALID;
val |= OTGSC_BSVIE;
}
@@ -637,7 +637,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct 
usb_bus *host)
 * Fail host registration if this board can support
 * only peripheral configuration.
 */
-   if (motg->pdata->mode == USB_PERIPHERAL) {
+   if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) {
dev_info(otg->phy->dev, "Host mode is not supported\n");
return -ENODEV;
}
@@ -666,7 +666,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct 
usb_bus *host)
 * Kick the state machine work, if peripheral is not supported
 * or peripheral is already registered with us.
 */
-   if (motg->pdata->mode == USB_HOST || otg->gadget) {
+   if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) {
pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work);
}
@@ -710,7 +710,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg,
 * Fail peripheral registration if this board can support
 * only host configuration.
 */
-   if (motg->pdata->mode == USB_HOST) {
+   if (motg->pdata->mode == USB_DR_MODE_HOST) {
dev_info(otg->phy->dev, "Peripheral mode is not supported\n");
return -ENODEV;
}
@@ -735,7 +735,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg,
 * Kick the state machine work, if host is not supported
 * or host is already registered with us.
 */
-   if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
+   if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) {
pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work);
}
@@ -1056,7 +1056,7 @@ static void msm_otg_init_sm(struct msm_otg *motg)
u32 otgsc = readl(USB_OTGSC);

switch (pdata->mode) {
-   case USB_OTG:
+   case USB_DR_MODE_OTG:
if (pdata->otg_control == OTG_PHY_CONTROL) {
if (otgsc & OTGSC_ID)
set_bit(ID, &motg->inputs);
@@ -1068,21 +1068,14 @@ static void msm_otg_init_sm(struct msm_otg *motg)
else
clear_bit(B_SESS_VLD, &motg->inputs);
}

[PATCH v7 09/20] usb: phy: msm: Remove unused pclk_src_name

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

There are no references to 'pclk_src_name' in plaform code,
so it is unused.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 26 +-
 include/linux/usb/msm_hsusb.h |  5 -
 2 files changed, 1 insertion(+), 30 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index a67c8a2..8b84821 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -464,9 +464,6 @@ static int msm_otg_suspend(struct msm_otg *motg)
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);

-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
-
if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL) {
msm_hsusb_ldo_set_mode(motg, 0);
@@ -496,9 +493,6 @@ static int msm_otg_resume(struct msm_otg *motg)
if (!atomic_read(&motg->in_lpm))
return 0;

-   if (!IS_ERR(motg->pclk_src))
-   clk_prepare_enable(motg->pclk_src);
-
clk_prepare_enable(motg->pclk);
clk_prepare_enable(motg->clk);
if (!IS_ERR(motg->core_clk))
@@ -1395,17 +1389,8 @@ static int msm_otg_probe(struct platform_device *pdev)
 * If USB Core is running its protocol engine based on CORE CLK,
 * CORE CLK  must be running at >55Mhz for correct HSUSB
 * operation and USB core cannot tolerate frequency changes on
-* CORE CLK. For such USB cores, vote for maximum clk frequency
-* on pclk source
+* CORE CLK.
 */
-motg->pclk_src = ERR_PTR(-ENOENT);
-if (motg->pdata->pclk_src_name) {
-   motg->pclk_src = devm_clk_get(&pdev->dev,
-   motg->pdata->pclk_src_name);
-   if (IS_ERR(motg->pclk_src))
-   return PTR_ERR(motg->pclk_src);
-   }
-
motg->pclk = devm_clk_get(&pdev->dev, "usb_hs_pclk");
if (IS_ERR(motg->pclk)) {
dev_err(&pdev->dev, "failed to get usb_hs_pclk\n");
@@ -1451,10 +1436,6 @@ static int msm_otg_probe(struct platform_device *pdev)
}

clk_set_rate(motg->clk, 6000);
-   if (!IS_ERR(motg->pclk_src)) {
-   clk_set_rate(motg->pclk_src, INT_MAX);
-   clk_prepare_enable(motg->pclk_src);
-   }

clk_prepare_enable(motg->clk);
clk_prepare_enable(motg->pclk);
@@ -1530,8 +1511,6 @@ disable_clks:
clk_disable_unprepare(motg->clk);
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);
-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
return ret;
 }

@@ -1576,9 +1555,6 @@ static int msm_otg_remove(struct platform_device *pdev)
clk_disable_unprepare(motg->clk);
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);
-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
-
msm_hsusb_ldo_init(motg, 0);

pm_runtime_set_suspended(&pdev->dev);
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 72c5830..262ed80 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -106,8 +106,6 @@ enum usb_chg_type {
  * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
  * @mode: Supported mode (OTG/peripheral/host).
  * @otg_control: OTG switch controlled by user/Id pin
- * @pclk_src_name: pclk is derived from ebi1_usb_clk in case of 7x27 and 8k
- *  dfab_usb_hs_clk in case of 8660 and 8960.
  */
 struct msm_otg_platform_data {
int *phy_init_seq;
@@ -117,7 +115,6 @@ struct msm_otg_platform_data {
enum otg_control_type otg_control;
enum msm_usb_phy_type phy_type;
void (*setup_gpio)(enum usb_otg_state state);
-   char *pclk_src_name;
int (*link_clk_reset)(struct clk *link_clk, bool assert);
int (*phy_clk_reset)(struct clk *phy_clk);
 };
@@ -129,7 +126,6 @@ struct msm_otg_platform_data {
  * @irq: IRQ number assigned for HSUSB controller.
  * @clk: clock struct of usb_hs_clk.
  * @pclk: clock struct of usb_hs_pclk.
- * @pclk_src: pclk source for voting.
  * @phy_reset_clk: clock struct of usb_phy_clk.
  * @core_clk: clock struct of usb_hs_core_clk.
  * @regs: ioremapped register base address.
@@ -150,7 +146,6 @@ struct msm_otg {
int irq;
struct clk *clk;
struct clk *pclk;
-   struct clk *pclk_src;
struct clk *phy_reset_clk;
struct clk *core_clk;
void __iomem *regs;
--
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 v7 12/20] usb: phy: msm: Add device tree support and binding information

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Allows controller to be specified via device tree.

Signed-off-by: Ivan T. Ivanov 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |  67 
 drivers/usb/phy/phy-msm-usb.c  | 113 +
 include/linux/usb/msm_hsusb.h  |   6 +-
 3 files changed, 165 insertions(+), 21 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index 5ea26c6..ee4123d 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -15,3 +15,70 @@ Example EHCI controller device node:
usb-phy = <&usb_otg>;
};

+USB PHY with optional OTG:
+
+Required properties:
+- compatible:   Should contain:
+  "qcom,usb-otg-ci" for chipsets with ChipIdea 45nm PHY
+  "qcom,usb-otg-snps" for chipsets with Synopsys 28nm PHY
+
+- regs: Offset and length of the register set in the memory map
+- interrupts:   interrupt-specifier for the OTG interrupt.
+
+- clocks:   A list of phandle + clock-specifier pairs for the
+clocks listed in clock-names
+- clock-names:  Should contain the following:
+  "phy" USB PHY reference clock
+  "core"Protocol engine clock
+  "iface"   Interface bus clock
+  "alt_core"Protocol engine clock for targets with asynchronous
+reset methodology. (optional)
+
+- vdccx-supply: phandle to the regulator for the vdd supply for
+digital circuit operation.
+- v1p8-supply:  phandle to the regulator for the 1.8V supply
+- v3p3-supply:  phandle to the regulator for the 3.3V supply
+
+- resets:   A list of phandle + reset-specifier pairs for the
+resets listed in reset-names
+- reset-names:  Should contain the following:
+  "phy" USB PHY controller reset
+  "link"USB LINK controller reset
+
+- qcom,otg-control: OTG control (VBUS and ID notifications) can be one of
+1 - PHY control
+2 - PMIC control
+
+Optional properties:
+- dr_mode:  One of "host", "peripheral" or "otg". Defaults to "otg"
+
+- qcom,phy-init-sequence: PHY configuration sequence values. This is related 
to Device
+Mode Eye Diagram test. Start address at which these values 
will be
+written is ULPI_EXT_VENDOR_SPECIFIC. Value of -1 is reserved as
+"do not overwrite default value at this address".
+For example: qcom,phy-init-sequence = < -1 0x63 >;
+Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1.
+
+Example HSUSB OTG controller device node:
+
+usb@f9a55000 {
+compatible = "qcom,usb-otg-snps";
+reg = <0xf9a55000 0x400>;
+interrupts = <0 134 0>;
+dr_mode = "peripheral";
+
+clocks = <&gcc GCC_XO_CLK>, <&gcc GCC_USB_HS_SYSTEM_CLK>,
+<&gcc GCC_USB_HS_AHB_CLK>;
+
+clock-names = "phy", "core", "iface";
+
+vddcx-supply = <&pm8841_s2_corner>;
+v1p8-supply = <&pm8941_l6>;
+v3p3-supply = <&pm8941_l24>;
+
+resets = <&gcc GCC_USB2A_PHY_BCR>, <&gcc GCC_USB_HS_BCR>;
+reset-names = "phy", "link";
+
+qcom,otg-control = <1>;
+qcom,phy-init-sequence = < -1 0x63 >;
+   };
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 8a7a324..4ed1ded 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -30,9 +30,12 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -217,16 +220,16 @@ static struct usb_phy_io_ops msm_otg_io_ops = {
 static void ulpi_init(struct msm_otg *motg)
 {
struct msm_otg_platform_data *pdata = motg->pdata;
-   int *seq = pdata->phy_init_seq;
+   int *seq = pdata->phy_init_seq, idx;
+   u32 addr = ULPI_EXT_VENDOR_SPECIFIC;

-   if (!seq)
-   return;
+   for (idx = 0; idx < pdata->phy_init_sz; idx++) {
+   if (seq[idx] == -1)
+   continue;

-   while (seq[0] >= 0) {
dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n",
-   seq[0], seq[1]);
-   ulpi_write(&motg->phy, seq[0], seq[1]);
-   seq += 2;
+   seq[idx], addr + idx);
+   ulpi_write(&motg->phy, seq[idx], addr + idx);
}
 }

@@ -1343,25 +1346,95 @@ static void msm_otg_debugfs_cleanup(void)
debugfs_remove(msm_otg_dbg_root);
 }

+static struct of_device_id msm_otg_dt_match[] = {
+   {
+   .compatible = "qcom,usb-otg-ci",
+   .data = (void *) CI_45NM_INTEGRATED_PHY
+   },
+   {
+   .compatible = "qcom,usb-otg-snps",
+   .data = (void *) SNPS_28NM_INTEGRATED_PHY
+   },
+   { }
+};
+MODULE_DEVICE_TABLE(of, msm_o

[PATCH v7 05/20] usb: phy: msm: Migrate to Managed Device Resource allocation

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Move memory, regulators, clocks and irq allocation to
devm_* variants. Properly check for valid clk handles.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 192 --
 1 file changed, 73 insertions(+), 119 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index b7d73f2..67cac96 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -63,27 +63,18 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
int ret = 0;

if (init) {
-   motg->vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
-   if (IS_ERR(motg->vddcx)) {
-   dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
-   return PTR_ERR(motg->vddcx);
-   }
-
ret = regulator_set_voltage(motg->vddcx,
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   regulator_put(motg->vddcx);
return ret;
}

ret = regulator_enable(motg->vddcx);
-   if (ret) {
+   if (ret)
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
-   regulator_put(motg->vddcx);
-   }
} else {
ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
@@ -93,8 +84,6 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");
-
-   regulator_put(motg->vddcx);
}

return ret;
@@ -105,53 +94,38 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
int rc = 0;

if (init) {
-   motg->v3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
-   if (IS_ERR(motg->v3p3)) {
-   dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
-   return PTR_ERR(motg->v3p3);
-   }
-
rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 3p3\n");
-   goto put_3p3;
+   goto exit;
}
rc = regulator_enable(motg->v3p3);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
3p3\n");
-   goto put_3p3;
-   }
-   motg->v1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
-   if (IS_ERR(motg->v1p8)) {
-   dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
-   rc = PTR_ERR(motg->v1p8);
-   goto disable_3p3;
+   goto exit;
}
rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 1p8\n");
-   goto put_1p8;
+   goto disable_3p3;
}
rc = regulator_enable(motg->v1p8);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
1p8\n");
-   goto put_1p8;
+   goto disable_3p3;
}

return 0;
}

regulator_disable(motg->v1p8);
-put_1p8:
-   regulator_put(motg->v1p8);
 disable_3p3:
regulator_disable(motg->v3p3);
-put_3p3:
-   regulator_put(motg->v3p3);
+exit:
return rc;
 }

@@ -506,7 +480,7 @@ static int msm_otg_suspend(struct msm_otg *motg)

clk_disable_unprepare(motg->pclk);
clk_disable_unprepare(motg->clk);
-   if (motg->core_clk)
+   if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);

if (!IS_ERR(motg->pclk_src))
@@ -546,7 +520,7 @@ static int msm_otg_resume(struct msm_otg *motg)

clk_prepare_enable(motg->pclk);
clk_prepare_enable(motg->clk);
-   if (motg->core_clk)
+   if (!IS_ERR(motg->core_clk))
clk_prepare_enable(motg->core_clk);

if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
@@ -1415,37 +1389,34 @@ static int msm_otg_probe(struct platform_device *pdev)
re

[PATCH v7 00/20] usb: phy: msm: Fixes, cleanups and DT support

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Hi,

This is a next version of patches posted earlier[1].

Hopefully comments from Felipe, Srinivas and Sergei have been addressed.

Changes since v6

 - New patch "Enable deferred driver probing"
 - Add log to patches wich did not have long description.
 - Revert several changes not related to commit message.

[1] http://www.spinics.net/lists/linux-usb/msg106158.html


Ivan T. Ivanov (18):
  usb: phy: msm: Make driver selectable on ARCH_QCOM
  usb: phy: msm: Remove __init macro from driver probe method
  usb: phy: msm: Move global regulators variables to driver state
  usb: phy: msm: Enable deferred driver probing
  usb: phy: msm: Migrate to Managed Device Resource allocation
  usb: phy: msm: Remove unnecessarily check for valid regulators.
  usb: phy: msm: Fix checkpatch.pl warnings
  usb: phy: msm: Replace custom enum usb_mode_type with enum usb_dr_mode
  usb: phy: msm: Remove unused pclk_src_name
  usb: phy: msm: Remove HSUSB prefix from regulator names
  usb: phy: msm: Properly check result from platform_get_irq()
  usb: phy: msm: Add device tree support and binding information
  usb: phy: msm: Use reset framework for LINK and PHY resets
  usb: phy: msm: Add support for secondary PHY control
  usb: phy: msm: Correct USB PHY Reset sequence for newer platform
  usb: phy: msm: Handle disconnect events
  usb: phy: msm: Vote for corner of VDD CX instead of voltage of VDD CX
  usb: phy: msm: Use usb_add_phy_dev() to register device

Tim Bird (2):
  usb: phy: msm: Fix PTS definitions for MSM USB controller
  usb: phy: msm: Select secondary PHY via TCSR

 .../devicetree/bindings/usb/msm-hsusb.txt  |  78 +++
 arch/arm/mach-msm/board-msm7x30.c  |   2 +-
 arch/arm/mach-msm/board-qsd8x50.c  |   2 +-
 drivers/usb/phy/Kconfig|   6 +-
 drivers/usb/phy/phy-msm-usb.c  | 705 -
 include/linux/usb/msm_hsusb.h  |  39 +-
 include/linux/usb/msm_hsusb_hw.h   |  14 +-
 7 files changed, 509 insertions(+), 337 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


[PATCH v7 07/20] usb: phy: msm: Fix checkpatch.pl warnings

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

This fixes following:

WARNING: quoted string split across lines
WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 39 ++-
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 4045301..3855217 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -67,8 +67,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
-   dev_err(motg->phy.dev, "unable to set the voltage "
-   "for hsusb vddcx\n");
+   dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
return ret;
}

@@ -79,8 +78,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret)
-   dev_err(motg->phy.dev, "unable to set the voltage "
-   "for hsusb vddcx\n");
+   dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");
@@ -97,8 +95,7 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init)
rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
-   dev_err(motg->phy.dev, "unable to set voltage level "
-   "for hsusb 3p3\n");
+   dev_err(motg->phy.dev, "Cannot set v3p3 voltage\n");
goto exit;
}
rc = regulator_enable(motg->v3p3);
@@ -109,8 +106,7 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
-   dev_err(motg->phy.dev, "unable to set voltage level "
-   "for hsusb 1p8\n");
+   dev_err(motg->phy.dev, "Cannot set v1p8 voltage\n");
goto disable_3p3;
}
rc = regulator_enable(motg->v1p8);
@@ -137,15 +133,13 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_HPM_LOAD);
if (ret < 0) {
-   pr_err("%s: Unable to set HPM of the regulator "
-   "HSUSB_1p8\n", __func__);
+   pr_err("Could not set HPM for v1p8\n");
return ret;
}
ret = regulator_set_optimum_mode(motg->v3p3,
USB_PHY_3P3_HPM_LOAD);
if (ret < 0) {
-   pr_err("%s: Unable to set HPM of the regulator "
-   "HSUSB_3p3\n", __func__);
+   pr_err("Could not set HPM for v3p3\n");
regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_LPM_LOAD);
return ret;
@@ -154,13 +148,11 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_LPM_LOAD);
if (ret < 0)
-   pr_err("%s: Unable to set LPM of the regulator "
-   "HSUSB_1p8\n", __func__);
+   pr_err("Could not set LPM for v1p8\n");
ret = regulator_set_optimum_mode(motg->v3p3,
USB_PHY_3P3_LPM_LOAD);
if (ret < 0)
-   pr_err("%s: Unable to set LPM of the regulator "
-   "HSUSB_3p3\n", __func__);
+   pr_err("Could not set LPM for v3p3\n");
}

pr_debug("reg (%s)\n", on ? "HPM" : "LPM");
@@ -390,8 +382,7 @@ static int msm_hsusb_config_vddcx(struct msm_otg *motg, int 
high)

ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol);
if (ret) {
-   pr_err("%s: unable to set the voltage for regulator "
-   "HSUSB_VDDCX\n", __func__);
+   pr_err("Cannot set vddcx voltage\n");
return ret;
}

@@ -546,8 +537,7 @@ static int msm_otg_resume(struct msm_otg *motg)
 * PHY. USB state can not be rest

[PATCH v7 10/20] usb: phy: msm: Remove HSUSB prefix from regulator names

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Prefix did not bring any useful information. Currently none
of the MSM platforms define these regulators, so it is safe
to rename them.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 8b84821..5d64038 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1417,19 +1417,19 @@ static int msm_otg_probe(struct platform_device *pdev)
return motg->irq;
}

-   motg->vddcx = devm_regulator_get(motg->phy.dev, "HSUSB_VDDCX");
+   motg->vddcx = devm_regulator_get(motg->phy.dev, "vddcx");
if (IS_ERR(motg->vddcx)) {
dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
return PTR_ERR(motg->vddcx);
}

-   motg->v3p3 = devm_regulator_get(motg->phy.dev, "HSUSB_3p3");
+   motg->v3p3 = devm_regulator_get(motg->phy.dev, "v3p3");
if (IS_ERR(motg->v3p3)) {
dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
return PTR_ERR(motg->v3p3);
}

-   motg->v1p8 = devm_regulator_get(motg->phy.dev, "HSUSB_1p8");
+   motg->v1p8 = devm_regulator_get(motg->phy.dev, "v1p8");
if (IS_ERR(motg->v1p8)) {
dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
return PTR_ERR(motg->v1p8);
--
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 v7 06/20] usb: phy: msm: Remove unnecessarily check for valid regulators.

2014-04-24 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Whether regulators are available or not is checked at driver
probe. If they are not available driver will refuse to load,
so no need to check them again.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 67cac96..4045301 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -133,16 +133,6 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
 {
int ret = 0;

-   if (!motg->v1p8 || IS_ERR(motg->v1p8)) {
-   pr_err("%s: HSUSB_1p8 is not initialized\n", __func__);
-   return -ENODEV;
-   }
-
-   if (!motg->v3p3 || IS_ERR(motg->v3p3)) {
-   pr_err("%s: HSUSB_3p3 is not initialized\n", __func__);
-   return -ENODEV;
-   }
-
if (on) {
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_HPM_LOAD);
--
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: [PATCH v7 05/20] usb: phy: msm: Migrate to Managed Device Resource allocation

2014-04-24 Thread Fabio Estevam
On Thu, Apr 24, 2014 at 12:48 PM, Ivan T. Ivanov  wrote:

> +   motg->vddcx = devm_regulator_get(motg->phy.dev, "HSUSB_VDDCX");
> +   if (IS_ERR(motg->vddcx)) {
> +   dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
> +   return PTR_ERR(motg->vddcx);
> +   }
> +
> +   motg->v3p3 = devm_regulator_get(motg->phy.dev, "HSUSB_3p3");
> +   if (IS_ERR(motg->v3p3)) {
> +   dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
> +   return PTR_ERR(motg->v3p3);
> +   }
> +
> +   motg->v1p8 = devm_regulator_get(motg->phy.dev, "HSUSB_1p8");
> +   if (IS_ERR(motg->v1p8)) {
> +   dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
> +   return PTR_ERR(motg->v1p8);
> +   }

It seems that calling devm_regulator_bulk_get() here would simplify
the code here.
--
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 20/20] usb: phy: msm: Use usb_add_phy_dev() to register device

2014-04-24 Thread Sergei Shtylyov

Hello.

On 04/24/2014 07:48 PM, Ivan T. Ivanov wrote:


From: "Ivan T. Ivanov" 



They could be more than one USB2.0 PHY's on the platform.


   s/They/There/


This will allow all of them to be registred successfuly.


   s/registred successfuly/registered successfully/


Signed-off-by: Ivan T. Ivanov 


WBR, 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


[PATCH] dt: bindings: dwc2: fix required value for the phy-names property

2014-04-24 Thread Matt Porter
"7408484 usb: gadget: s3c-hsotg: enable generic phy support" introduces
generic phy support to the dwc2.txt binding and the s3c-hsotg driver
which implements support for the binding. The binding documentation
incorrectly states that the phy-names property will be "device". The
binding example, driver, and one dts user all implement the phy-names
property as requiring "usb2-phy".

Fix the dwc2.txt binding documentation to correctly specify "usb2-phy"
as the appropriate value for phy-names.

Reported-by: Tomasz Figa 
Signed-off-by: Matt Porter 
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index b8b6871..467ddd1 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -13,7 +13,7 @@ Refer to clk/clock-bindings.txt for generic clock consumer 
properties
 
 Optional properties:
 - phys: phy provider specifier
-- phy-names: shall be "device"
+- phy-names: shall be "usb2-phy"
 Refer to phy/phy-bindings.txt for generic phy consumer properties
 
 Example:
-- 
1.8.4

--
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


usb: mon: freeing active timer

2014-04-24 Thread Sasha Levin
Hi all,

While fuzzing with trinity inside a KVM tools guest running the latest -next
kernel I've stumbled on the following:

[ 1361.390880] WARNING: CPU: 10 PID: 24274 at lib/debugobjects.c:260 
debug_print_object+0x8c/0xb0()
[ 1361.391203] ODEBUG: free active (active state 0) object type: timer_list 
hint: delayed_work_timer_fn+0x0/0x20
[ 1361.391203] Modules linked in:
[ 1361.391203] CPU: 10 PID: 24274 Comm: trinity-c83 Not tainted 
3.15.0-rc2-next-20140423-sasha-00018-gc4ff6c4 #408
[ 1361.391203]  0009 8801de341c78 b85271f2 
0001
[ 1361.391203]  8801de341cc8 8801de341cb8 b515afcc 
8801eb3ebd98
[ 1361.391203]  8801eb751870 b9e76200 b98dc502 
bc702550
[ 1361.391203] Call Trace:
[ 1361.391203] dump_stack (lib/dump_stack.c:52)
[ 1361.391203] warn_slowpath_common (kernel/panic.c:430)
[ 1361.391203] warn_slowpath_fmt (kernel/panic.c:445)
[ 1361.391203] debug_print_object (lib/debugobjects.c:262)
[ 1361.391203] ? __queue_work (kernel/workqueue.c:1452)
[ 1361.391203] __debug_check_no_obj_freed (lib/debugobjects.c:697)
[ 1361.391203] debug_check_no_obj_freed (lib/debugobjects.c:726)
[ 1361.391203] kmem_cache_free (mm/slub.c:2689 mm/slub.c:2717)
[ 1361.391203] ? kmem_cache_destroy (mm/slab_common.c:363)
[ 1361.391203] kmem_cache_destroy (mm/slab_common.c:363)
[ 1361.391203] mon_text_release (drivers/usb/mon/mon_text.c:643)
[ 1361.391203] __fput (fs/file_table.c:217)
[ 1361.391203] fput (fs/file_table.c:253)
[ 1361.391203] task_work_run (kernel/task_work.c:125 (discriminator 1))
[ 1361.391203] do_notify_resume (include/linux/tracehook.h:196 
arch/x86/kernel/signal.c:751)
[ 1361.391203] int_signal (arch/x86/kernel/entry_64.S:807)


Thanks,
Sasha
--
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: usb: mon: freeing active timer

2014-04-24 Thread Greg KH
On Thu, Apr 24, 2014 at 01:40:14PM -0400, Sasha Levin wrote:
> Hi all,
> 
> While fuzzing with trinity inside a KVM tools guest running the latest -next
> kernel I've stumbled on the following:
> 
> [ 1361.390880] WARNING: CPU: 10 PID: 24274 at lib/debugobjects.c:260 
> debug_print_object+0x8c/0xb0()
> [ 1361.391203] ODEBUG: free active (active state 0) object type: timer_list 
> hint: delayed_work_timer_fn+0x0/0x20
> [ 1361.391203] Modules linked in:
> [ 1361.391203] CPU: 10 PID: 24274 Comm: trinity-c83 Not tainted 
> 3.15.0-rc2-next-20140423-sasha-00018-gc4ff6c4 #408
> [ 1361.391203]  0009 8801de341c78 b85271f2 
> 0001
> [ 1361.391203]  8801de341cc8 8801de341cb8 b515afcc 
> 8801eb3ebd98
> [ 1361.391203]  8801eb751870 b9e76200 b98dc502 
> bc702550
> [ 1361.391203] Call Trace:
> [ 1361.391203] dump_stack (lib/dump_stack.c:52)
> [ 1361.391203] warn_slowpath_common (kernel/panic.c:430)
> [ 1361.391203] warn_slowpath_fmt (kernel/panic.c:445)
> [ 1361.391203] debug_print_object (lib/debugobjects.c:262)
> [ 1361.391203] ? __queue_work (kernel/workqueue.c:1452)
> [ 1361.391203] __debug_check_no_obj_freed (lib/debugobjects.c:697)
> [ 1361.391203] debug_check_no_obj_freed (lib/debugobjects.c:726)
> [ 1361.391203] kmem_cache_free (mm/slub.c:2689 mm/slub.c:2717)
> [ 1361.391203] ? kmem_cache_destroy (mm/slab_common.c:363)
> [ 1361.391203] kmem_cache_destroy (mm/slab_common.c:363)
> [ 1361.391203] mon_text_release (drivers/usb/mon/mon_text.c:643)
> [ 1361.391203] __fput (fs/file_table.c:217)
> [ 1361.391203] fput (fs/file_table.c:253)
> [ 1361.391203] task_work_run (kernel/task_work.c:125 (discriminator 1))
> [ 1361.391203] do_notify_resume (include/linux/tracehook.h:196 
> arch/x86/kernel/signal.c:751)
> [ 1361.391203] int_signal (arch/x86/kernel/entry_64.S:807)

So you were running usbmon at the time?  Were you actually monitoring a
specific USB device/bus, or something else?

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: usb fixes for v3.15-rc3

2014-04-24 Thread Greg KH
On Mon, Apr 21, 2014 at 10:35:17AM -0500, Felipe Balbi wrote:
> Hi Greg,
> 
> Here's my first pull request. All patches soaked for a long time and
> have passed my 300 randconfigs without issues.
> 
> Please consider merging this to your usb-linus branch.
> 
> The following changes since commit c9eaa447e77efe77b7fa4c953bd62de8297fd6c5:
> 
>   Linux 3.15-rc1 (2014-04-13 14:18:35 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
> fixes-for-v3.15-rc3

Pulled and pushed out, 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/1] usb: chipidea: coordinate usb phy initialization for different phy type

2014-04-24 Thread Greg KH
On Wed, Apr 23, 2014 at 01:30:43PM +0800, Peter Chen wrote:
> For internal PHY (like UTMI), the phy clock may from internal pll,
> it is on/off on the fly, the access PORTSC.PTS will hang without
> phy clock. So, the usb_phy_init which will open phy clock needs to
> be called before hw_phymode_configure.
> See: http://marc.info/?l=linux-arm-kernel&m=139350618732108&w=2
> 
> For external PHY (like ulpi), it needs to configure portsc.pts before
> visit viewport, or the viewport can't be visited. so phy_phymode_configure
> needs to be called before usb_phy_init.
> See: cd0b42c2a6d2a74244f0053f8960f5dad5842278
> 
> It may not the best solution, but it can work for all situations.
> 
> Cc: Sascha Hauer 
> Cc: Chris Ruehl 
> Cc: shc_w...@mail.ru
> Cc: de...@eukrea.com
> Cc: feste...@gmail.com
> Signed-off-by: Peter Chen 
> ---
>  drivers/usb/chipidea/core.c |   37 ++---
>  1 files changed, 34 insertions(+), 3 deletions(-)

This should go into 3.14 as well, right?  I've marked it for stable
because of this.

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: usb: mon: freeing active timer

2014-04-24 Thread Sasha Levin
On 04/24/2014 03:24 PM, Greg KH wrote:
> On Thu, Apr 24, 2014 at 01:40:14PM -0400, Sasha Levin wrote:
>> > Hi all,
>> > 
>> > While fuzzing with trinity inside a KVM tools guest running the latest 
>> > -next
>> > kernel I've stumbled on the following:
>> > 
>> > [ 1361.390880] WARNING: CPU: 10 PID: 24274 at lib/debugobjects.c:260 
>> > debug_print_object+0x8c/0xb0()
>> > [ 1361.391203] ODEBUG: free active (active state 0) object type: 
>> > timer_list hint: delayed_work_timer_fn+0x0/0x20
>> > [ 1361.391203] Modules linked in:
>> > [ 1361.391203] CPU: 10 PID: 24274 Comm: trinity-c83 Not tainted 
>> > 3.15.0-rc2-next-20140423-sasha-00018-gc4ff6c4 #408
>> > [ 1361.391203]  0009 8801de341c78 b85271f2 
>> > 0001
>> > [ 1361.391203]  8801de341cc8 8801de341cb8 b515afcc 
>> > 8801eb3ebd98
>> > [ 1361.391203]  8801eb751870 b9e76200 b98dc502 
>> > bc702550
>> > [ 1361.391203] Call Trace:
>> > [ 1361.391203] dump_stack (lib/dump_stack.c:52)
>> > [ 1361.391203] warn_slowpath_common (kernel/panic.c:430)
>> > [ 1361.391203] warn_slowpath_fmt (kernel/panic.c:445)
>> > [ 1361.391203] debug_print_object (lib/debugobjects.c:262)
>> > [ 1361.391203] ? __queue_work (kernel/workqueue.c:1452)
>> > [ 1361.391203] __debug_check_no_obj_freed (lib/debugobjects.c:697)
>> > [ 1361.391203] debug_check_no_obj_freed (lib/debugobjects.c:726)
>> > [ 1361.391203] kmem_cache_free (mm/slub.c:2689 mm/slub.c:2717)
>> > [ 1361.391203] ? kmem_cache_destroy (mm/slab_common.c:363)
>> > [ 1361.391203] kmem_cache_destroy (mm/slab_common.c:363)
>> > [ 1361.391203] mon_text_release (drivers/usb/mon/mon_text.c:643)
>> > [ 1361.391203] __fput (fs/file_table.c:217)
>> > [ 1361.391203] fput (fs/file_table.c:253)
>> > [ 1361.391203] task_work_run (kernel/task_work.c:125 (discriminator 1))
>> > [ 1361.391203] do_notify_resume (include/linux/tracehook.h:196 
>> > arch/x86/kernel/signal.c:751)
>> > [ 1361.391203] int_signal (arch/x86/kernel/entry_64.S:807)
> So you were running usbmon at the time?  Were you actually monitoring a
> specific USB device/bus, or something else?

This was inside a vm with no actual physical USB devices:

# lsusb -t
lsusb: cannot open "/var/lib/usbutils/usb.ids", No such file or directory
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ozwpan/8p, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dummy_hcd/1p, 480M
|__ Port 1: Dev 2, If 0, Class=comm., Driver=cdc_eem, 480M

Since it happened while I was fuzzing, I'm not sure what exactly was getting
monitored at that point.


Thanks,
Sasha
--
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/5] usb: xhci: Prefer endpoint context dequeue pointer over stopped_trb

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:22:58PM +0300, Mathias Nyman wrote:
> From: Julius Werner 
> 
> We have observed a rare cycle state desync bug after Set TR Dequeue
> Pointer commands on Intel LynxPoint xHCs (resulting in an endpoint that
> doesn't fetch new TRBs and thus an unresponsive USB device). It always
> triggers when a previous Set TR Dequeue Pointer command has set the
> pointer to the final Link TRB of a segment, and then another URB gets
> enqueued and cancelled again before it can be completed. Further
> investigation showed that the xHC had returned the Link TRB in the TRB
> Pointer field of the Transfer Event (CC == Stopped -- Length Invalid),
> but when xhci_find_new_dequeue_state() later accesses the Endpoint
> Context's TR Dequeue Pointer field it is set to the first TRB of the
> next segment.
> 
> The driver expects those two values to be the same in this situation,
> and uses the cycle state of the latter together with the address of the
> former. This should be fine according to the XHCI specification, since
> the endpoint ring should be stopped when returning the Transfer Event
> and thus should not advance over the Link TRB before it gets restarted.
> However, real-world XHCI implementations apparently don't really care
> that much about these details, so the driver should follow a more
> defensive approach to try to work around HC spec violations.
> 
> This patch removes the stopped_trb variable that had been used to store
> the TRB Pointer from the last Transfer Event of a stopped TRB. Instead,
> xhci_find_new_dequeue_state() now relies only on the Endpoint Context,
> requiring a small amount of additional processing to find the virtual
> address corresponding to the TR Dequeue Pointer. Some other parts of the
> function were slightly rearranged to better fit into this model.
> 
> This patch should be backported to kernels as old as 2.6.31 that contain
> the commit ae636747146ea97efa18e04576acd3416e2514f5 "USB: xhci: URB
> cancellation support."

Ok, but:

> 
> Signed-off-by: Julius Werner 
> Signed-off-by: Mathias Nyman 

You don't actually add the stable@ tag here, why not?

You have read Documentation/stable_kernel_rules.txt for how stable
kernel trees work, so why not add the label here?

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 2/5] xhci: Use pci_enable_msix_exact() instead of pci_enable_msix()

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:22:59PM +0300, Mathias Nyman wrote:
> From: Alexander Gordeev 
> 
> As result of deprecation of MSI-X/MSI enablement functions
> pci_enable_msix() and pci_enable_msi_block() all drivers
> using these two interfaces need to be updated to use the
> new pci_enable_msi_range()  or pci_enable_msi_exact()
> and pci_enable_msix_range() or pci_enable_msix_exact()
> interfaces.
> 
> Signed-off-by: Alexander Gordeev 
> Cc: Sarah Sharp 
> Cc: Greg Kroah-Hartman 
> Cc: linux-usb@vger.kernel.org
> Cc: linux-...@vger.kernel.org
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index 988ed5f..b0b8399 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -291,7 +291,7 @@ static int xhci_setup_msix(struct xhci_hcd *xhci)
>   xhci->msix_entries[i].vector = 0;
>   }
>  
> - ret = pci_enable_msix(pdev, xhci->msix_entries, xhci->msix_count);
> + ret = pci_enable_msix_exact(pdev, xhci->msix_entries, xhci->msix_count);

Why is this change needed for 3.15-final?

--
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 4/5] xhci: extend quirk for Renesas cards

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:23:01PM +0300, Mathias Nyman wrote:
> From: Igor Gnatenko 
> 
> After suspend another Renesas PCI-X USB 3.0 card doesn't work.
> [root@fedora-20 ~]# lspci -vmnnd 1912:
> Device:   03:00.0
> Class:USB controller [0c03]
> Vendor:   Renesas Technology Corp. [1912]
> Device:   uPD720202 USB 3.0 Host Controller [0015]
> SVendor:  Renesas Technology Corp. [1912]
> SDevice:  uPD720202 USB 3.0 Host Controller [0015]
> Rev:  02
> ProgIf:   30
> 
> Reported-and-tested-by: Anatoly Kharchenko 
> Reference: http://redmine.russianfedora.pro/issues/1315
> Signed-off-by: Igor Gnatenko 
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci-pci.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Again, no stable?

--
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 3/5] xhci: Switch Intel Lynx Point ports to EHCI on shutdown.

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:23:00PM +0300, Mathias Nyman wrote:
> From: Denis Turischev 
> 
> The same issue like with Panther Point chipsets. If the USB ports are
> switched to xHCI on shutdown, the xHCI host will send a spurious interrupt,
> which will wake the system. Some BIOS have work around for this, but not all.
> One example is Compulab's mini-desktop, the Intense-PC2.
> 
> The bug can be avoided if the USB ports are switched back to EHCI on
> shutdown.
> 
> Signed-off-by: Denis Turischev 
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci-pci.c | 2 ++
>  1 file changed, 2 insertions(+)

No stable marking?  Why not?

--
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 0/5] xhci: fixes for 3.15-rc usb-linus

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:22:57PM +0300, Mathias Nyman wrote:
> Hi Greg
> 
> Here are the xhci fixes for 3.15-rc usb-linus.
> Most of them are very small fixes that didn't make
> it to 3.14, sitting and waiting for 3.15-rc1 to come out.
> 
> Only the "Prefer endpoint context.." patch  by Julius has a bit more content.
>  
> These patches are picked together with Sarah, they are tested on top of
> 3.15-rc1, and apply on your current usb-linus branch

Please redo all of these based on my comments.

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 5/5] usb/xhci: fix compilation warning when !CONFIG_PCI && !CONFIG_PM

2014-04-24 Thread Greg KH
On Tue, Apr 22, 2014 at 03:23:02PM +0300, Mathias Nyman wrote:
> From: David Cohen 
> 
> When CONFIG_PCI and CONFIG_PM are not selected, xhci.c gets this
> warning:
> drivers/usb/host/xhci.c:409:13: warning: ‘xhci_msix_sync_irqs’ defined
> but not used [-Wunused-function]
> 
> Instead of creating nested #ifdefs, this patch fixes it by defining the
> xHCI PCI stubs as inline.
> 
> Signed-off-by: David Cohen 
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

What patch caused this problem?  Does it show up in 3.14?  3.10?  2.0?
:)

Please be more specific...

--
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 v2 00/13] extcon: major rework

2014-04-24 Thread Greg KH
On Mon, Apr 14, 2014 at 01:46:11PM +0200, Robert Baldyga wrote:
> This patchset adds many improvements to extcon class driver and extcon
> provider drivers. It changes extcon API to faster and safer by replaceing
> function taking extcon and cable names with functions working with
> structures representing this objects.

What is "faster" exactly?  How did you measure this?  What benchmarks
can be run to test this claim?

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: usb: mon: freeing active timer

2014-04-24 Thread Alan Stern
On Thu, 24 Apr 2014, Sasha Levin wrote:

> On 04/24/2014 03:24 PM, Greg KH wrote:
> > On Thu, Apr 24, 2014 at 01:40:14PM -0400, Sasha Levin wrote:
> >> > Hi all,
> >> > 
> >> > While fuzzing with trinity inside a KVM tools guest running the latest 
> >> > -next
> >> > kernel I've stumbled on the following:
> >> > 
> >> > [ 1361.390880] WARNING: CPU: 10 PID: 24274 at lib/debugobjects.c:260 
> >> > debug_print_object+0x8c/0xb0()
> >> > [ 1361.391203] ODEBUG: free active (active state 0) object type: 
> >> > timer_list hint: delayed_work_timer_fn+0x0/0x20
> >> > [ 1361.391203] Modules linked in:
> >> > [ 1361.391203] CPU: 10 PID: 24274 Comm: trinity-c83 Not tainted 
> >> > 3.15.0-rc2-next-20140423-sasha-00018-gc4ff6c4 #408
> >> > [ 1361.391203]  0009 8801de341c78 b85271f2 
> >> > 0001
> >> > [ 1361.391203]  8801de341cc8 8801de341cb8 b515afcc 
> >> > 8801eb3ebd98
> >> > [ 1361.391203]  8801eb751870 b9e76200 b98dc502 
> >> > bc702550
> >> > [ 1361.391203] Call Trace:
> >> > [ 1361.391203] dump_stack (lib/dump_stack.c:52)
> >> > [ 1361.391203] warn_slowpath_common (kernel/panic.c:430)
> >> > [ 1361.391203] warn_slowpath_fmt (kernel/panic.c:445)
> >> > [ 1361.391203] debug_print_object (lib/debugobjects.c:262)
> >> > [ 1361.391203] ? __queue_work (kernel/workqueue.c:1452)
> >> > [ 1361.391203] __debug_check_no_obj_freed (lib/debugobjects.c:697)
> >> > [ 1361.391203] debug_check_no_obj_freed (lib/debugobjects.c:726)
> >> > [ 1361.391203] kmem_cache_free (mm/slub.c:2689 mm/slub.c:2717)
> >> > [ 1361.391203] ? kmem_cache_destroy (mm/slab_common.c:363)
> >> > [ 1361.391203] kmem_cache_destroy (mm/slab_common.c:363)
> >> > [ 1361.391203] mon_text_release (drivers/usb/mon/mon_text.c:643)
> >> > [ 1361.391203] __fput (fs/file_table.c:217)
> >> > [ 1361.391203] fput (fs/file_table.c:253)
> >> > [ 1361.391203] task_work_run (kernel/task_work.c:125 (discriminator 1))
> >> > [ 1361.391203] do_notify_resume (include/linux/tracehook.h:196 
> >> > arch/x86/kernel/signal.c:751)
> >> > [ 1361.391203] int_signal (arch/x86/kernel/entry_64.S:807)
> > So you were running usbmon at the time?  Were you actually monitoring a
> > specific USB device/bus, or something else?
> 
> This was inside a vm with no actual physical USB devices:
> 
> # lsusb -t
> lsusb: cannot open "/var/lib/usbutils/usb.ids", No such file or directory
> /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ozwpan/8p, 12M
> /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dummy_hcd/1p, 480M
> |__ Port 1: Dev 2, If 0, Class=comm., Driver=cdc_eem, 480M
> 
> Since it happened while I was fuzzing, I'm not sure what exactly was getting
> monitored at that point.

This is odd because the warning message indicates the something 
containing an active timer (a delayed_work structure?) was deallocated.  
But usbmon doesn't use either timers or work queues, and as far as I 
can see, neither does anything involved in kmem_cache management.

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: [PATCH v4] Add support for using a MAX3421E chip as a host driver.

2014-04-24 Thread Greg KH
On Fri, Apr 11, 2014 at 11:55:51PM -0600, David Mosberger wrote:
> This is v4 of the patch.  Compared to v3, the only changes are:
> 
>   - addition of a platform-data header file which allows a platform
> to define which general-purpose output pin controls Vbus (if any)
>   - spi_wr_fifo/spi_rd_fifo got renamed to spi_wr_buf/spi_rd_buf,
> respectively, since that more accurately reflects their function
> (whether or not a FIFO is being written depends on the register
>  number).
> 
> Signed-off-by: David Mosberger 
> ---
>  drivers/usb/Makefile  |1 +
>  drivers/usb/host/Kconfig  |   11 +
>  drivers/usb/host/Makefile |1 +
>  drivers/usb/host/max3421-hcd.c| 1937 
> +
>  include/linux/platform_data/max3421-hcd.h |   23 +
>  5 files changed, 1973 insertions(+)
>  create mode 100644 drivers/usb/host/max3421-hcd.c
>  create mode 100644 include/linux/platform_data/max3421-hcd.h

I get a number of build warnings when building this code:

drivers/usb/host/max3421-hcd.c: In function ‘max3421_transfer_out’:
drivers/usb/host/max3421-hcd.c:570:4: warning: format ‘%zu’ expects argument of 
type ‘size_t’, but argument 5 has type ‘int’ [-Wformat=]
__func__, max_packet, MAX3421_FIFO_SIZE);

In file included from 
/ssd/gregkh-linux/work/usb/arch/x86/include/asm/percpu.h:44:0,
 from 
/ssd/gregkh-linux/work/usb/arch/x86/include/asm/preempt.h:5,
 from include/linux/preempt.h:18,
 from include/linux/spinlock.h:50,
 from include/linux/seqlock.h:35,
 from include/linux/time.h:5,
 from include/linux/stat.h:18,
 from include/linux/module.h:10,
 from drivers/usb/host/max3421-hcd.c:58:
include/linux/kernel.h:713:17: warning: comparison of distinct pointer types 
lacks a cast [enabled by default]
  (void) (&_min1 == &_min2);  \
 ^
drivers/usb/host/max3421-hcd.c:574:26: note: in expansion of macro ‘min’
  max3421_hcd->curr_len = min((urb->transfer_buffer_length -
  ^
drivers/usb/host/max3421-hcd.c: In function ‘max3421_transfer_in_done’:
drivers/usb/host/max3421-hcd.c:977:4: warning: format ‘%zu’ expects argument of 
type ‘size_t’, but argument 5 has type ‘int’ [-Wformat=]
__func__, max_packet, MAX3421_FIFO_SIZE);
^

which I could live with and accept a follow-on patch, but then it breaks the 
build:

ERROR: "spi_register_driver" [drivers/usb/host/max3421-hcd.ko] undefined!
ERROR: "spi_sync" [drivers/usb/host/max3421-hcd.ko] undefined!
ERROR: "spi_setup" [drivers/usb/host/max3421-hcd.ko] undefined!


It looks like the Kconfig dependancies are not correct.

Care to fix that up, and resend this patch?  Also, the changelog text above
needs some work, no one cares what changed from the previous submission once
the code is in the tree, they just want to know what the code does, put the
"this changed" stuff below the cut line.

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 5/5] usb/xhci: fix compilation warning when !CONFIG_PCI && !CONFIG_PM

2014-04-24 Thread David Cohen
Hi Greg,

On Thu, Apr 24, 2014 at 12:50:32PM -0700, Greg KH wrote:
> On Tue, Apr 22, 2014 at 03:23:02PM +0300, Mathias Nyman wrote:
> > From: David Cohen 
> > 
> > When CONFIG_PCI and CONFIG_PM are not selected, xhci.c gets this
> > warning:
> > drivers/usb/host/xhci.c:409:13: warning: ‘xhci_msix_sync_irqs’ defined
> > but not used [-Wunused-function]
> > 
> > Instead of creating nested #ifdefs, this patch fixes it by defining the
> > xHCI PCI stubs as inline.
> > 
> > Signed-off-by: David Cohen 
> > Signed-off-by: Mathias Nyman 
> > ---
> >  drivers/usb/host/xhci.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> What patch caused this problem?  Does it show up in 3.14?  3.10?  2.0?
> :)
> 
> Please be more specific...

I first noticed this warning on 3.13, but I believe it is older :)
You may consider this patch as an extension of this other one:

commit d5c82feb5cf8026cd4af048330fdcd46e861c686
Author: Olof Johansson 
Date:   Tue Jul 23 11:58:20 2013 -0700

usb: xhci: Mark two functions __maybe_unused
--

IMO it makes sense to apply whenever the other patch exists.

Br, David
--
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/5] usb: xhci: Prefer endpoint context dequeue pointer over stopped_trb

2014-04-24 Thread Julius Werner
> You don't actually add the stable@ tag here, why not?
>
> You have read Documentation/stable_kernel_rules.txt for how stable
> kernel trees work, so why not add the label here?

Sorry... I actually didn't know about that file, I just added the
"should be backported" line because I have seen that in other commits.
I will adhere to those rules in the future.

The patch is a little over the line limit (150+ lines with context,
although most of it are scattered single-line changes). The issue it
solves is that a USB device may silently stop working until it is
disconnected, not sure if that's enough to qualify as "oh, that's not
good". I'll let you decide whether it still should be queued up for
stable backports or not.
--
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: dwc3: gadget: pretty print link states

2014-04-24 Thread Paul Zimmerman
> From: linux-usb-ow...@vger.kernel.org 
> [mailto:linux-usb-ow...@vger.kernel.org] On Behalf Of Felipe Balbi
> Sent: Thursday, April 24, 2014 8:10 AM
> 
> this makes it slightly easier to read link state
> change interrupt logs.
> 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/dwc3/gadget.c | 39 ++-
>  1 file changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index f0dc0ee..a8cf87b 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -302,6 +302,42 @@ static const char *dwc3_gadget_ep_cmd_string(u8 cmd)
>   }
>  }
> 
> +static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state)
> +{
> + switch (link_state) {
> + case DWC3_LINK_STATE_U0:
> + return "U0";
> + case DWC3_LINK_STATE_U1:
> + return "U1";
> + case DWC3_LINK_STATE_U2:
> + return "U2";
> + case DWC3_LINK_STATE_U3:
> + return "U3";
> + case DWC3_LINK_STATE_SS_DIS:
> + return "SS.Disabled";
> + case DWC3_LINK_STATE_RX_DET:
> + return "RX.Detect";

Hi Felipe,

For the non-obvious link states, could we have both the name and the
number in the message perhaps? i.e.

case DWC3_LINK_STATE_SS_DIS:
return "SS.Disabled (4)";
case DWC3_LINK_STATE_RX_DET:
return "RX.Detect (5)";

and so on.

If I'm looking at the link state in a register and comparing it to the
log, it helps if I don't have to look up the values in the databook ;)

-- 
Paul

--
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: dwc3: gadget: pretty print link states

2014-04-24 Thread Felipe Balbi
On Thu, Apr 24, 2014 at 09:18:08PM +, Paul Zimmerman wrote:
> > From: linux-usb-ow...@vger.kernel.org 
> > [mailto:linux-usb-ow...@vger.kernel.org] On Behalf Of Felipe Balbi
> > Sent: Thursday, April 24, 2014 8:10 AM
> > 
> > this makes it slightly easier to read link state
> > change interrupt logs.
> > 
> > Signed-off-by: Felipe Balbi 
> > ---
> >  drivers/usb/dwc3/gadget.c | 39 ++-
> >  1 file changed, 38 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > index f0dc0ee..a8cf87b 100644
> > --- a/drivers/usb/dwc3/gadget.c
> > +++ b/drivers/usb/dwc3/gadget.c
> > @@ -302,6 +302,42 @@ static const char *dwc3_gadget_ep_cmd_string(u8 cmd)
> > }
> >  }
> > 
> > +static const char *dwc3_gadget_link_string(enum dwc3_link_state link_state)
> > +{
> > +   switch (link_state) {
> > +   case DWC3_LINK_STATE_U0:
> > +   return "U0";
> > +   case DWC3_LINK_STATE_U1:
> > +   return "U1";
> > +   case DWC3_LINK_STATE_U2:
> > +   return "U2";
> > +   case DWC3_LINK_STATE_U3:
> > +   return "U3";
> > +   case DWC3_LINK_STATE_SS_DIS:
> > +   return "SS.Disabled";
> > +   case DWC3_LINK_STATE_RX_DET:
> > +   return "RX.Detect";
> 
> Hi Felipe,
> 
> For the non-obvious link states, could we have both the name and the
> number in the message perhaps? i.e.
> 
>   case DWC3_LINK_STATE_SS_DIS:
>   return "SS.Disabled (4)";
>   case DWC3_LINK_STATE_RX_DET:
>   return "RX.Detect (5)";
> 
> and so on.
> 
> If I'm looking at the link state in a register and comparing it to the
> log, it helps if I don't have to look up the values in the databook ;)

Sure, makes sense.

ps: funny thing, when I was debugging this I was tired of looking at
numbers because I always had to look at the Databook to figure out what
they were :-p

-- 
balbi


signature.asc
Description: Digital signature


Re: usb audio breaks ohci-pci

2014-04-24 Thread Dennis New
On Thu, 17 Apr 2014 15:36:02 -0400 (EDT), Alan Stern wrote:
> On Tue, 1 Apr 2014, Dennis New wrote:
> 
> > On Tue, 1 Apr 2014 09:30:01 -0400 (EDT), Alan Stern wrote:
> 
> > > I don't know that much can be done to prevent the controller from
> > > crashing, or to recover from such a crash.  Maybe resetting the
> > > controller would work, maybe not.
> > > 
> > > But at least it should be possible to insure that a controller
> > > malfunction doesn't bring down the entire USB stack with it.  I
> > > will work on a patch for this, but I'm going to be quite busy
> > > with other matters for the next few days.  It may take some time
> > > to get the patch ready for you to test.
> 
> Here's a patch for you to test.  Let me know if it doesn't apply 
> properly to the kernel you're using.  I can't tell if it will prevent 
> all your problems, because it's not clear exactly what's going
> wrong. But at least this is a start.
> 
> Alan Stern
> 
> 
> 
> Index: usb-3.14/drivers/usb/host/ohci.h [...]

So, it crashed again after almost a week. But ohci-pci seemed to have
gotten in an infinite loop, constantly repeating about 30 times per
second:

[256283.572813] ohci-pci :00:13.1: OHCI SF watchdog triggered
[256283.572819] ohci-pci :00:13.1: Frame counter has stopped at 6263
[256283.596153] ohci-pci :00:13.1: OHCI SF watchdog triggered
[256283.596163] ohci-pci :00:13.1: Frame counter has stopped at 6263

The frame counter did indeed stop there. Here's a few of the logs I
captured:

http://dennisn.linuxd.org/guest/pubstuff/debug-usbaudio/crash6.log

--
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: [EHCI Debug Port] Linux fails to setup EHCI debug port

2014-04-24 Thread Kyösti Mälkki

Sorry for the late response, as I do not follow linux-usb list very closely.

I have discussed recent Intel chipsets and EHCI debug in some detail on 
the coreboot mailing list [1].


As for the discussion [2] that took place here in February, I noticed 
you tried with early_printk=dbgp which only tries USB bus 1 on EHCI 
0:1a.0. You need to use early_printk=dbgp1 to probe USB bus 2 (EHCI 
0:1d.0), lsusb output suggested that is the controller net20dc was 
plugged in.


Correct USB port would appear as "usb 1-1.2" or "usb 2-1.2" in the 
system log when you connect your USB device. EHCI debug mode will bypass 
the rate matching hubs.


While it does not appear to case on your setup, enabled XHCI can also 
prevent EHCI debug from working. And sometimes you see bad design where 
the USB port you need is either routed to mini-pci-e or ExpressCard slot 
or not connected at all.


Regards,
Kyösti

[1] http://www.coreboot.org/pipermail/coreboot/2014-January/077016.html
[2] http://marc.info/?t=13927060913&r=1&w=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] usb_wwan: some improvement on write and resume

2014-04-24 Thread xiao jin
When enable usb serial for modem data, sometimes the tty is blocked
in tty_wait_until_sent because portdata->out_busy always is set and
have no chance to be cleared.

We have found two scenarios lead to portdata->out_busy problem.
1. usb_wwan_write set portdata->out_busy firstly, then try autopm
async with error. No out urb submit and no usb_wwan_outdat_callback
to this write, portdata->out_busy can't be cleared.
2. usb_wwan_resume run play_delayed() and spin_unlock, but
intfdata->suspended still is not set to zero. At this time
usb_wwan_write is called and anchor the urb to delay list. Then resume
keep running but the delayed urb have no chance to be commit until next
resume. If the time of next resume is far away, tty will be blocked
in tty_wait_until_sent during time.

The patch make some enhancement on write and resume.
1. clear portdata->out_busy if usb_wwan_write try autopm async with
error.
2. put play_Delayed and intfdata->suspended together in the spinlock,
it's to avoid the write race during resume.

Signed-off-by: xiao jin 
Signed-off-by: Zhang, Qi1 
Reviewed-by: David Cohen 
---
 drivers/usb/serial/usb_wwan.c |   12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 640fe01..8e06afc 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -228,8 +228,10 @@ int usb_wwan_write(struct tty_struct *tty, struct 
usb_serial_port *port,
usb_pipeendpoint(this_urb->pipe), i);
 
err = usb_autopm_get_interface_async(port->serial->interface);
-   if (err < 0)
+   if (err < 0) {
+   clear_bit(i, &portdata->out_busy);
break;
+   }
 
/* send the data */
memcpy(this_urb->transfer_buffer, buf, todo);
@@ -661,17 +663,15 @@ int usb_wwan_resume(struct usb_serial *serial)
}
}
 
+   spin_lock_irq(&intfdata->susp_lock);
for (i = 0; i < serial->num_ports; i++) {
/* walk all ports */
port = serial->port[i];
portdata = usb_get_serial_port_data(port);
 
/* skip closed ports */
-   spin_lock_irq(&intfdata->susp_lock);
-   if (!portdata || !portdata->opened) {
-   spin_unlock_irq(&intfdata->susp_lock);
+   if (!portdata || !portdata->opened)
continue;
-   }
 
for (j = 0; j < N_IN_URB; j++) {
urb = portdata->in_urbs[j];
@@ -684,9 +684,7 @@ int usb_wwan_resume(struct usb_serial *serial)
}
}
play_delayed(port);
-   spin_unlock_irq(&intfdata->susp_lock);
}
-   spin_lock_irq(&intfdata->susp_lock);
intfdata->suspended = 0;
spin_unlock_irq(&intfdata->susp_lock);
 err_out:
-- 
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


[PATCH 4/5] appledisplay: Convert /n to \n

2014-04-24 Thread Joe Perches
Use a newline character appropriately.

Signed-off-by: Joe Perches 
---
 drivers/usb/misc/appledisplay.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index ba6a5d6..f37c78d 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -110,7 +110,7 @@ static void appledisplay_complete(struct urb *urb)
__func__, status);
return;
default:
-   dev_dbg(dev, "%s - nonzero urb status received: %d/n",
+   dev_dbg(dev, "%s - nonzero urb status received: %d\n",
__func__, status);
goto exit;
}
-- 
1.8.1.2.459.gbcd45b4.dirty

--
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] treewide: Convert logging message misuses of /n to \n

2014-04-24 Thread Joe Perches
Joe Perches (5):
  qlge: Convert /n to \n
  iwlegacy: Convert /n to \n
  staging: rtl: Convert /n to \n
  appledisplay: Convert /n to \n
  sound: tlv320aic31xx: Convert /n to \n

 drivers/net/ethernet/qlogic/qlge/qlge_main.c  | 2 +-
 drivers/net/wireless/iwlegacy/3945.c  | 2 +-
 drivers/net/wireless/iwlegacy/4965-mac.c  | 2 +-
 drivers/staging/rtl8188eu/hal/usb_ops_linux.c | 2 +-
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   | 2 +-
 drivers/staging/rtl8723au/hal/usb_ops_linux.c | 4 ++--
 drivers/staging/rtl8723au/os_dep/usb_intf.c   | 2 +-
 drivers/usb/misc/appledisplay.c   | 2 +-
 sound/soc/codecs/tlv320aic31xx.c  | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)

-- 
1.8.1.2.459.gbcd45b4.dirty

--
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/1] usb: chipidea: coordinate usb phy initialization for different phy type

2014-04-24 Thread Peter Chen
 
> 
> On Wed, Apr 23, 2014 at 01:30:43PM +0800, Peter Chen wrote:
> > For internal PHY (like UTMI), the phy clock may from internal pll, it
> > is on/off on the fly, the access PORTSC.PTS will hang without phy
> > clock. So, the usb_phy_init which will open phy clock needs to be
> > called before hw_phymode_configure.
> > See: http://marc.info/?l=linux-arm-kernel&m=139350618732108&w=2
> >
> > For external PHY (like ulpi), it needs to configure portsc.pts before
> > visit viewport, or the viewport can't be visited. so
> > phy_phymode_configure needs to be called before usb_phy_init.
> > See: cd0b42c2a6d2a74244f0053f8960f5dad5842278
> >
> > It may not the best solution, but it can work for all situations.
> >
> > Cc: Sascha Hauer 
> > Cc: Chris Ruehl 
> > Cc: shc_w...@mail.ru
> > Cc: de...@eukrea.com
> > Cc: feste...@gmail.com
> > Signed-off-by: Peter Chen 
> > ---
> >  drivers/usb/chipidea/core.c |   37 ++-
> --
> >  1 files changed, 34 insertions(+), 3 deletions(-)
> 
> This should go into 3.14 as well, right?  I've marked it for stable
> because of this.
> 

I have checked v3.14, it can't apply due to this patch is based on 3.15-rc1.
So, do not mark it for stable please.

Peter

--
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: serial: fix sysfs-attribute removal deadlock

2014-04-24 Thread Li Zhong
On Thu, 2014-04-24 at 10:35 -0400, Tejun Heo wrote:
> On Thu, Apr 24, 2014 at 04:29:15PM +0800, Li Zhong wrote:
> > On Wed, 2014-04-23 at 10:19 -0400, Tejun Heo wrote:
> > > cc'ing Li Zhong who's working on a simliar issue in the following
> > > thread and quoting whole body.
> > > 
> > >   http://thread.gmane.org/gmane.linux.kernel/1680706
> > > 
> > > Li, this is another variation of the same problem.  Maybe this can be
> > > covered by your work too?
> > 
> > It seems to me that it is about write something to driver attribute, and
> > driver unloading. If so, maybe it's not easy to reuse the help functions
> > created for device attribute, and device removing.
> > 
> > But I guess the idea to break the active protection could still be
> > applied here:
> > 
> > Maybe we could try_module_get() here (like the other option suggested by
> > Johan?), and break active protection if we could get the module,
> > something like below? 
> 
> I don't get why try_module_get() matters here.  We can't call into
> ->store if the object at hand is already destroyed and the underlying
> module can't go away if the target device is still alive.
> try_module_get() doesn't actually protect the object.  Why does that
> matter?  This is self removal, right?  Can you please take a look at
> kernfs_remove_self()?

This is about one process writing something to driver attributes, and
one process trying to unload this driver. 

I think try_module_get() could detect whether the driver is being
unloaded, and if not, prevent it from being unloaded, so it could
protect the object here by not allow the driver to be unloaded.

And if the driver is being unloaded, we could abort the write operation
directly. 

Thanks, Zhong

> 
> Thanks.
> 


--
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: serial: fix sysfs-attribute removal deadlock

2014-04-24 Thread Li Zhong
On Thu, 2014-04-24 at 16:52 +0200, Johan Hovold wrote:
> On Thu, Apr 24, 2014 at 10:35:17AM -0400, Tejun Heo wrote:
> > On Thu, Apr 24, 2014 at 04:29:15PM +0800, Li Zhong wrote:
> > > On Wed, 2014-04-23 at 10:19 -0400, Tejun Heo wrote:
> > > > cc'ing Li Zhong who's working on a simliar issue in the following
> > > > thread and quoting whole body.
> > > > 
> > > >   http://thread.gmane.org/gmane.linux.kernel/1680706
> > > > 
> > > > Li, this is another variation of the same problem.  Maybe this can be
> > > > covered by your work too?
> > > 
> > > It seems to me that it is about write something to driver attribute, and
> > > driver unloading. If so, maybe it's not easy to reuse the help functions
> > > created for device attribute, and device removing.
> > > 
> > > But I guess the idea to break the active protection could still be
> > > applied here:
> > > 
> > > Maybe we could try_module_get() here (like the other option suggested by
> > > Johan?), and break active protection if we could get the module,
> > > something like below? 
> > 
> > I don't get why try_module_get() matters here.  We can't call into
> > ->store if the object at hand is already destroyed and the underlying
> > module can't go away if the target device is still alive.
> > try_module_get() doesn't actually protect the object.  Why does that
> > matter?  This is self removal, right?  Can you please take a look at
> > kernfs_remove_self()?
> 
> No, this isn't self removal. The driver-attribute (not device-attribute)
> store operation simply grabs a lock that is also held while the driver
> is being deregistered at module unload. Taking a reference to the module
> in this case will prevent deregistration while store is running.
> 
> But it seems like this can be solved for usb-serial by simply not
> holding the lock while deregistering.

I didn't look carefully about this lock. 

But I'm not sure whether there are such requirements for driver
attributes:

some lock needs be grabbed in the driver attributes store callbacks, and
the same lock also needs to be grabbed during driver unregister. 

If we have such requirements currently or in the future, I think they
could all be solved by breaking active protection after get the module
reference.

Thanks, Zhong

> 
> Johan
> 


--
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/1] usb: chipidea: coordinate usb phy initialization for different phy type

2014-04-24 Thread Greg KH
On Fri, Apr 25, 2014 at 02:07:35AM +, Peter Chen wrote:
>  
> > 
> > On Wed, Apr 23, 2014 at 01:30:43PM +0800, Peter Chen wrote:
> > > For internal PHY (like UTMI), the phy clock may from internal pll, it
> > > is on/off on the fly, the access PORTSC.PTS will hang without phy
> > > clock. So, the usb_phy_init which will open phy clock needs to be
> > > called before hw_phymode_configure.
> > > See: http://marc.info/?l=linux-arm-kernel&m=139350618732108&w=2
> > >
> > > For external PHY (like ulpi), it needs to configure portsc.pts before
> > > visit viewport, or the viewport can't be visited. so
> > > phy_phymode_configure needs to be called before usb_phy_init.
> > > See: cd0b42c2a6d2a74244f0053f8960f5dad5842278
> > >
> > > It may not the best solution, but it can work for all situations.
> > >
> > > Cc: Sascha Hauer 
> > > Cc: Chris Ruehl 
> > > Cc: shc_w...@mail.ru
> > > Cc: de...@eukrea.com
> > > Cc: feste...@gmail.com
> > > Signed-off-by: Peter Chen 
> > > ---
> > >  drivers/usb/chipidea/core.c |   37 ++-
> > --
> > >  1 files changed, 34 insertions(+), 3 deletions(-)
> > 
> > This should go into 3.14 as well, right?  I've marked it for stable
> > because of this.
> > 
> 
> I have checked v3.14, it can't apply due to this patch is based on 3.15-rc1.
> So, do not mark it for stable please.

But it fixes a problem in 3.14, right?  Anyway, it's too late, just
ignore the "this does not apply" message you will get when it tries to
go into the stable trees in a few weeks if you don't want it there.

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 v4 0/3] usb: chipidea: msm: Clean and fix glue layer driver

2014-04-24 Thread Peter Chen

 
> 
> On Thu, 2014-04-24 at 08:38 +0800, Peter Chen wrote:
> > On Wed, Apr 23, 2014 at 03:28:01PM +0300, Ivan T. Ivanov wrote:
> > > From: "Ivan T. Ivanov" 
> > >
> > > This series intend to fix driver, which was broken for a while.
> > > It is used to create peripheral role device, which in coordination
> > > with phy-usb-msm driver could provide USB2.0 gadget support for
> > > Qualcomm targets.
> > >
> > > Changes since version 3.
> > >
> > >  - Fix typo in devicetree description file.
> > >
> > > Previews version can be found here:
> >
> > Since in your phy's patchset, you also access portsc which is in
> > chipidea register region, it is not a standard way.
> > In case, you will change something at chipidea driver in future when
> > you re-work your next revision phy's patchset, I do not send this
> > patchset to Greg right now.
> >
> 
> Did you see problems with _this_ particular patch set? There is no direct
> dependency between PHY patches and these changes.
> 
 
I have not seen problems for this patch set, if you make sure the current
phy operation (eg, "phy_type) at chipidea core does not affect you,
I am glad to accept this.

Peter


Re: [PATCH v4] Add support for using a MAX3421E chip as a host driver.

2014-04-24 Thread David Mosberger
Greg,

Thanks for taking a look.  Yes, I'll definitely fix those oversights
and send a new patch next week.

Have a good weekend,

  --david

On Thu, Apr 24, 2014 at 2:09 PM, Greg KH  wrote:
> On Fri, Apr 11, 2014 at 11:55:51PM -0600, David Mosberger wrote:
>> This is v4 of the patch.  Compared to v3, the only changes are:
>>
>>   - addition of a platform-data header file which allows a platform
>> to define which general-purpose output pin controls Vbus (if any)
>>   - spi_wr_fifo/spi_rd_fifo got renamed to spi_wr_buf/spi_rd_buf,
>> respectively, since that more accurately reflects their function
>> (whether or not a FIFO is being written depends on the register
>>  number).
>>
>> Signed-off-by: David Mosberger 
>> ---
>>  drivers/usb/Makefile  |1 +
>>  drivers/usb/host/Kconfig  |   11 +
>>  drivers/usb/host/Makefile |1 +
>>  drivers/usb/host/max3421-hcd.c| 1937 
>> +
>>  include/linux/platform_data/max3421-hcd.h |   23 +
>>  5 files changed, 1973 insertions(+)
>>  create mode 100644 drivers/usb/host/max3421-hcd.c
>>  create mode 100644 include/linux/platform_data/max3421-hcd.h
>
> I get a number of build warnings when building this code:
>
> drivers/usb/host/max3421-hcd.c: In function 'max3421_transfer_out':
> drivers/usb/host/max3421-hcd.c:570:4: warning: format '%zu' expects argument 
> of type 'size_t', but argument 5 has type 'int' [-Wformat=]
> __func__, max_packet, MAX3421_FIFO_SIZE);
>
> In file included from 
> /ssd/gregkh-linux/work/usb/arch/x86/include/asm/percpu.h:44:0,
>  from 
> /ssd/gregkh-linux/work/usb/arch/x86/include/asm/preempt.h:5,
>  from include/linux/preempt.h:18,
>  from include/linux/spinlock.h:50,
>  from include/linux/seqlock.h:35,
>  from include/linux/time.h:5,
>  from include/linux/stat.h:18,
>  from include/linux/module.h:10,
>  from drivers/usb/host/max3421-hcd.c:58:
> include/linux/kernel.h:713:17: warning: comparison of distinct pointer types 
> lacks a cast [enabled by default]
>   (void) (&_min1 == &_min2);  \
>  ^
> drivers/usb/host/max3421-hcd.c:574:26: note: in expansion of macro 'min'
>   max3421_hcd->curr_len = min((urb->transfer_buffer_length -
>   ^
> drivers/usb/host/max3421-hcd.c: In function 'max3421_transfer_in_done':
> drivers/usb/host/max3421-hcd.c:977:4: warning: format '%zu' expects argument 
> of type 'size_t', but argument 5 has type 'int' [-Wformat=]
> __func__, max_packet, MAX3421_FIFO_SIZE);
> ^
>
> which I could live with and accept a follow-on patch, but then it breaks the 
> build:
>
> ERROR: "spi_register_driver" [drivers/usb/host/max3421-hcd.ko] undefined!
> ERROR: "spi_sync" [drivers/usb/host/max3421-hcd.ko] undefined!
> ERROR: "spi_setup" [drivers/usb/host/max3421-hcd.ko] undefined!
>
>
> It looks like the Kconfig dependancies are not correct.
>
> Care to fix that up, and resend this patch?  Also, the changelog text above
> needs some work, no one cares what changed from the previous submission once
> the code is in the tree, they just want to know what the code does, put the
> "this changed" stuff below the cut line.
>
> thanks,
>
> greg k-h



-- 
eGauge Systems LLC, http://egauge.net/, 1.877-EGAUGE1, fax 720.545.9768
--
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


[no subject]

2014-04-24 Thread ADELIA SOARES RIBAS


Claim your 500,000,00 Euros
--
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 v5 1/9] dt: exynos5420: Enable support for USB 3.0 PHY controller

2014-04-24 Thread Tushar Behera
On 04/23/2014 08:00 PM, Vivek Gautam wrote:
> Add device tree nodes for USB 3.0 PHY present alongwith
> USB 3.0 controller Exynos 5420 SoC. This phy driver is
> based on generic phy framework.
> 
> Signed-off-by: Vivek Gautam 
> Reviewed-by: Tomasz Figa 
> ---
>  arch/arm/boot/dts/exynos5420.dtsi |   20 
>  1 file changed, 20 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/exynos5420.dtsi 
> b/arch/arm/boot/dts/exynos5420.dtsi
> index c3a9a66..f69745f 100644
> --- a/arch/arm/boot/dts/exynos5420.dtsi
> +++ b/arch/arm/boot/dts/exynos5420.dtsi
> @@ -732,4 +732,24 @@
>   clock-names = "secss";
>   samsung,power-domain = <&g2d_pd>;
>   };
> +
> + usbdrd_phy0: phy@1210 {
> + compatible = "samsung,exynos5420-usbdrd-phy";
> + reg = <0x1210 0x100>;
> + clocks = <&clock CLK_USBD300>, <&clock CLK_SCLK_USBPHY300>;
> + clock-names = "phy", "ref";
> + samsung,pmu-syscon = <&pmu_system_controller>;

Should the property name be samsung,syscon-phandle as used elsewhere?

samsung,syscon-phandle = <&pmu_system_controller>;

> + samsung,pmu-offset = <0x704>;
> + #phy-cells = <1>;
> + };
> +
> + usbdrd_phy1: phy@1250 {
> + compatible = "samsung,exynos5420-usbdrd-phy";
> + reg = <0x1250 0x100>;
> + clocks = <&clock CLK_USBD301>, <&clock CLK_SCLK_USBPHY301>;
> + clock-names = "phy", "ref";
> + samsung,pmu-syscon = <&pmu_system_controller>;

ditto

> + samsung,pmu-offset = <0x708>;
> + #phy-cells = <1>;
> + };
>  };
> 


-- 
Tushar Behera
--
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 v5 3/9] dt: exynos5250: Enable support for generic USB DRD phy

2014-04-24 Thread Tushar Behera
On 04/23/2014 08:00 PM, Vivek Gautam wrote:
> Add device tree node for new usbdrd-phy driver, which
> is based on generic phy framework.
> 
> Signed-off-by: Vivek Gautam 
> Reviewed-by: Tomasz Figa 
> ---
>  arch/arm/boot/dts/exynos5250.dtsi |   10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/arm/boot/dts/exynos5250.dtsi 
> b/arch/arm/boot/dts/exynos5250.dtsi
> index 3742331..d4254c0 100644
> --- a/arch/arm/boot/dts/exynos5250.dtsi
> +++ b/arch/arm/boot/dts/exynos5250.dtsi
> @@ -551,6 +551,16 @@
>   };
>   };
>  
> + usbdrd_phy: phy@1210 {
> + compatible = "samsung,exynos5250-usbdrd-phy";
> + reg = <0x1210 0x100>;
> + clocks = <&clock CLK_USB3>, <&clock CLK_FIN_PLL>;
> + clock-names = "phy", "ref";
> + samsung,pmu-syscon = <&pmu_system_controller>;

Replace samsung,pmu-syscon by samsung,syscon-phandle ?

> + samsung,pmu-offset = <0x704>;
> + #phy-cells = <1>;
> + };
> +
>   usb@1211 {
>   compatible = "samsung,exynos4210-ehci";
>   reg = <0x1211 0x100>;
> 


-- 
Tushar Behera
--
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