Re: BUG Report: USB Storage is not working when connecting on a Thunderbolt 3.0 port

2017-03-28 Thread Mathias Nyman

Hi

On 28.03.2017 05:35, Olivier Langlois wrote:

Hardware:
HP Spectre 13
http://h10032.www1.hp.com/ctg/Manual/c05228576.pdf

Kernel version:
4.10.6 SMP PREEMPT x86_64


Is this a new issue? was it working on some other kernel?



When I plug my usb storage on the USB 3.1 Gen1 port, the storage is
working:
[  498.070841] usb 2-3: new SuperSpeed USB device number 2 using
xhci_hcd
[  498.114368] usb-storage 2-3:1.0: USB Mass Storage device detected

...

but when I plug it on one of the 2 Thunderbolt port, I get:



[  352.851123] xhci_hcd :37:00.0: xHCI Host Controller
[  352.851129] xhci_hcd :37:00.0: new USB bus registered, assigned
bus number 3
[  352.852299] xhci_hcd :37:00.0: hcc params 0x200077c1 hci version
0x110 quirks 0x9810
[  352.852566] hub 3-0:1.0: USB hub found
[  352.852575] hub 3-0:1.0: 2 ports detected
[  352.852749] xhci_hcd :37:00.0: xHCI Host Controller
[  352.852753] xhci_hcd :37:00.0: new USB bus registered, assigned
bus number 4
[  352.852915] hub 4-0:1.0: USB hub found
[  352.852923] hub 4-0:1.0: 2 ports detected
[  353.211414] usb 3-2: new high-speed USB device number 2 using
xhci_hcd
[  353.351482] usb 3-2: device descriptor read/64, error -71
[  353.611477] usb 3-2: device descriptor read/64, error -71
[  353.871617] usb 3-2: new high-speed USB device number 3 using
xhci_hcd


Odd that it tries to enumerate as high-speed.

Might be because xHC controller is being hotplug added at device connect,
and xhci driver adds USB2 hcd first, and usb3 hcd second.

What happens if you first connect a high-speed USB device to the first
Thunderbolt type-C Gen2 port, and then after a while when xhci driver is
properly loaded plug in the SuperSpeed device to the second TB type-C gen2 port?

Thomas Reifferscheid reported a similar issue recently. His device got
detected as both high and superspeed at the same time if it was connected
during boot
http://marc.info/?l=linux-usb&m=148897296702314&w=2

He listed 3 workarounds, but I haven't yet had time to get into this
issue in detail.

-Mathias

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


Re: [PATCHv2] net: usbnet: support 64bit stats in qmi_wwan driver

2017-03-28 Thread Oliver Neukum
Am Freitag, den 24.03.2017, 07:17 -0700 schrieb Eric Dumazet:
> On Fri, 2017-03-24 at 15:42 +1000, Greg Ungerer wrote:
> 
> > 
> > The usbnet core is used by a number of drivers. This patch only
> > updates the qmi-wwan driver to use stats64. If you remove the
> > dev->stats.rx_* updates all those other driver users will have
> > no counts.
> 
> I see. Then I guess the u64 stuff could be done only if running 32bit
> kernels. (The existing stats are using 'unsigned long' so are already
> 64bit wide on 64bit kernels)

We want every driver to use u64 if possible. If something
is exported we want a defined size.

Regards
Oliver

--
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 1/4] cdc-acm: reassemble fragmented notifications

2017-03-28 Thread Oliver Neukum
Am Freitag, den 24.03.2017, 22:50 +0100 schrieb Tobias Herzog:
> Hi Oliver,
> 
> thank you for your patience... :) I have a question to one of your
> comments (see below).
> 
> Best regards,
> Tobias
> 
> > 
> > Am Samstag, den 18.03.2017, 19:52 +0100 schrieb Tobias Herzog:
> > > 
> > > 
> > > USB devices may have very limitited endpoint packet sizes, so that
> > > notifications can not be transferred within one single usb packet.
> > > Reassembling of multiple packages may be necessary.
> > Hi,
> > 
> > almost perfect.
> > A few new issue. Comments inline.
> > 
> > > 
> > > 
> > > 
> > > + struct usb_cdc_notification *dr = (struct
> > > usb_cdc_notification *)buf;
> > > + unsigned char *data = (unsigned char *)(dr + 1);
> > This is border line incorrect. It depends on the compiler not
> > adding padding. Please make it
> > 
> > buf + sizeof(struct usb_cdc_notification)
> > 
> > > 
> > > 
> > > - usb_mark_last_busy(acm->dev);
> > > -
> > > - data = (unsigned char *)(dr + 1);
> > >   switch (dr->bNotificationType) {
> > >   case USB_CDC_NOTIFY_NETWORK_CONNECTION:
> > >   dev_dbg(&acm->control->dev,
> > > @@ -363,8 +337,77 @@ static void acm_ctrl_irq(struct urb *urb)
> > >   __func__,
> > >   dr->bNotificationType, dr->wIndex,
> > >   dr->wLength, data[0], data[1]);
> > > + }
> > > +}
> > > +
> > > +/* control interface reports status changes with "interrupt"
> > > transfers */
> > > +static void acm_ctrl_irq(struct urb *urb)
> > > +{
> > > + struct acm *acm = urb->context;
> > > + struct usb_cdc_notification *dr = urb->transfer_buffer;
> > > + unsigned int current_size = urb->actual_length;
> > > + unsigned int expected_size, copy_size;
> > > + int retval;
> > > + int status = urb->status;
> > > +
> > > + switch (status) {
> > > + case 0:
> > > + /* success */
> > >   break;
> > > + case -ECONNRESET:
> > > + case -ENOENT:
> > > + case -ESHUTDOWN:
> > > + /* this urb is terminated, clean up */
> > > + acm->nb_index = 0;
> > > + dev_dbg(&acm->control->dev,
> > > + "%s - urb shutting down with status:
> > > %d\n",
> > > + __func__, status);
> > > + return;
> > > + default:
> > > + dev_dbg(&acm->control->dev,
> > > + "%s - nonzero urb status received: %d\n",
> > > + __func__, status);
> > > + goto exit;
> > >   }
> > > +
> > > + usb_mark_last_busy(acm->dev);
> > > +
> > > + if (acm->nb_index)
> > > + dr = (struct usb_cdc_notification *)acm-
> > > > 
> > > > notification_buffer;
> > > +
> > > + /* size = notification-header + (optional) data */
> > > + expected_size = sizeof(struct usb_cdc_notification) +
> > > + le16_to_cpu(dr->wLength);
> > > +
> > > + if (current_size < expected_size) {
> > > + /* notification is transmitted fragmented,
> > > reassemble */
> > > + if (acm->nb_size < expected_size) {
> > > + if (acm->nb_size) {
> > > + kfree(acm->notification_buffer);
> > > + acm->nb_size = 0;
> > > + }
> > > + acm->notification_buffer =
> > > + kmalloc(expected_size,
> > > GFP_ATOMIC);
> > Given how kmalloc works you'd better round this up to a power of two.
> > 
> > > 
> > > 
> > > + if (!acm->notification_buffer)
> > > + goto exit;
> > This is most subtle. Please add a comment that this prevents a double
> > free if we get a disconnect()
> I'm unsure if I got this right: Are you talking about the fact, that
> the use of 'kmalloc' will make 'acm->notification_buffer' valid again
> (i.e. NULL or pointing to a correctly allocated block), after it was

yes

> "invalidated" by 'kfree' (in case the previously allocated buffer was
> too small)?
> The 'goto exit'-thing for me is just not to use the buffer if
> allocation fails. Or am I missing anything here?

You need to consider the hot unplug case.

Regards
Oliver

--
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 v3 0/2] USB: refactor endpoint retrieval

2017-03-28 Thread Johan Hovold
Many USB drivers iterate over the available endpoints to find required
endpoints of a specific type and direction. Typically the endpoints are
required for proper function and a missing endpoint should abort probe.

To facilitate code reuse, this series adds a helper to retrieve common
endpoints (bulk or interrupt, in or out) and four wrappers to find a
single endpoint (which should cover the vast majority of drivers).

This typically saves about 10-15 lines of code per driver, so even if
this series result in a net gain in terms of lines due to the helpers
being added to core, there will be further reductions when applied to
other subsystems.

Note that the helpers are marked as __must_check to serve as a reminder
to always verify that all expected endpoints are indeed present.

Also note that some drivers have implemented their endpoint look-up
loops in such a way that they have picked the last endpoint descriptor
of the specified type should more than one such descriptor exist. To
avoid any regressions, the second patch therefore adds corresponding
helpers to lookup endpoints by searching the endpoint descriptors in
reverse order. In almost all cases, I expect it would be safe to simply
pick the first matching descriptor instead (i.e. there is only one
endpoint descriptor per type).

Johan


Changes in v3
 - drop patches already applied, and resend the two patces which had
   dependencies on usb-linus which have now been merged to usb-next

Changes in v2
 - use the new helpers also in cdc-acm, usb-storage and usblp (last
   three patches)
 - s/lookup/look up/ in kerneldoc comments
 - simplify match_endpoint helper (Bjørn Mork)
 - add the chaoskey and legousbtower maintainers on CC
 - add temporary variables to avoid reinitialising return-value
   variables where approporiate

Johan Hovold (2):
  USB: lvstest: tighten endpoint sanity check
  USB: usbtmc: refactor endpoint retrieval

 drivers/usb/class/usbtmc.c | 56 +++---
 drivers/usb/misc/lvstest.c |  7 +++---
 2 files changed, 21 insertions(+), 42 deletions(-)

-- 
2.12.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 v3 2/2] USB: usbtmc: refactor endpoint retrieval

2017-03-28 Thread Johan Hovold
Use the new endpoint helpers to lookup the required bulk-in and bulk-out
endpoints, and the optional interrupt-in endpoint.

Signed-off-by: Johan Hovold 
---
 drivers/usb/class/usbtmc.c | 56 +++---
 1 file changed, 18 insertions(+), 38 deletions(-)

diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 8fb309a0ff6b..578f424decc2 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1375,7 +1375,7 @@ static int usbtmc_probe(struct usb_interface *intf,
 {
struct usbtmc_device_data *data;
struct usb_host_interface *iface_desc;
-   struct usb_endpoint_descriptor *endpoint;
+   struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in;
int n;
int retcode;
 
@@ -1421,49 +1421,29 @@ static int usbtmc_probe(struct usb_interface *intf,
iface_desc = data->intf->cur_altsetting;
data->ifnum = iface_desc->desc.bInterfaceNumber;
 
-   /* Find bulk in endpoint */
-   for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) {
-   endpoint = &iface_desc->endpoint[n].desc;
-
-   if (usb_endpoint_is_bulk_in(endpoint)) {
-   data->bulk_in = endpoint->bEndpointAddress;
-   dev_dbg(&intf->dev, "Found bulk in endpoint at %u\n",
-   data->bulk_in);
-   break;
-   }
-   }
-
-   /* Find bulk out endpoint */
-   for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) {
-   endpoint = &iface_desc->endpoint[n].desc;
-
-   if (usb_endpoint_is_bulk_out(endpoint)) {
-   data->bulk_out = endpoint->bEndpointAddress;
-   dev_dbg(&intf->dev, "Found Bulk out endpoint at %u\n",
-   data->bulk_out);
-   break;
-   }
-   }
-
-   if (!data->bulk_out || !data->bulk_in) {
+   /* Find bulk endpoints */
+   retcode = usb_find_common_endpoints(iface_desc,
+   &bulk_in, &bulk_out, NULL, NULL);
+   if (retcode) {
dev_err(&intf->dev, "bulk endpoints not found\n");
-   retcode = -ENODEV;
goto err_put;
}
 
+   data->bulk_in = bulk_in->bEndpointAddress;
+   dev_dbg(&intf->dev, "Found bulk in endpoint at %u\n", data->bulk_in);
+
+   data->bulk_out = bulk_out->bEndpointAddress;
+   dev_dbg(&intf->dev, "Found Bulk out endpoint at %u\n", data->bulk_out);
+
/* Find int endpoint */
-   for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) {
-   endpoint = &iface_desc->endpoint[n].desc;
-
-   if (usb_endpoint_is_int_in(endpoint)) {
-   data->iin_ep_present = 1;
-   data->iin_ep = endpoint->bEndpointAddress;
-   data->iin_wMaxPacketSize = usb_endpoint_maxp(endpoint);
-   data->iin_interval = endpoint->bInterval;
-   dev_dbg(&intf->dev, "Found Int in endpoint at %u\n",
+   retcode = usb_find_int_in_endpoint(iface_desc, &int_in);
+   if (!retcode) {
+   data->iin_ep_present = 1;
+   data->iin_ep = int_in->bEndpointAddress;
+   data->iin_wMaxPacketSize = usb_endpoint_maxp(int_in);
+   data->iin_interval = int_in->bInterval;
+   dev_dbg(&intf->dev, "Found Int in endpoint at %u\n",
data->iin_ep);
-   break;
-   }
}
 
retcode = get_capabilities(data);
-- 
2.12.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 v3 1/2] USB: lvstest: tighten endpoint sanity check

2017-03-28 Thread Johan Hovold
Use the new endpoint helpers to lookup the required interrupt-in
endpoint.

Note that this in fact both loosens and tightens the endpoint sanity
check by accepting any interface with an interrupt-in endpoint rather
than always using the first endpoint without verifying its type.

Signed-off-by: Johan Hovold 
---
 drivers/usb/misc/lvstest.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c
index 6d075cdb6ed1..2142132a1f82 100644
--- a/drivers/usb/misc/lvstest.c
+++ b/drivers/usb/misc/lvstest.c
@@ -367,10 +367,9 @@ static int lvs_rh_probe(struct usb_interface *intf,
hdev = interface_to_usbdev(intf);
desc = intf->cur_altsetting;
 
-   if (desc->desc.bNumEndpoints < 1)
-   return -ENODEV;
-
-   endpoint = &desc->endpoint[0].desc;
+   ret = usb_find_int_in_endpoint(desc, &endpoint);
+   if (ret)
+   return ret;
 
/* valid only for SS root hub */
if (hdev->descriptor.bDeviceProtocol != USB_HUB_PR_SS || hdev->parent) {
-- 
2.12.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 RFC] dwc2: Don't assume URB transfer_buffer are dword-aligned

2017-03-28 Thread Mauro Carvalho Chehab
Em Fri, 17 Mar 2017 10:24:15 +0900
Greg Kroah-Hartman  escreveu:

> On Thu, Mar 16, 2017 at 09:08:40PM -0300, Mauro Carvalho Chehab wrote:
> > The dwc2 hardware doesn't like to do DMA transfers without
> > aligning data in DWORD. The driver also assumes that, even
> > when there's no DMA, at dwc2_read_packet().
> > 
> > That cause buffer overflows, preventing some drivers to work.  
> 
> Why aren't the drivers being fixed?  This is a well-known (hopefully)
> restriction on USB data buffers, can't the uvc_driver be fixed?

I talked to Laurent about on IRC. He told that he is willing to consider
that option, if the USB API explicitly states that all buffers must be
dword-aligned (and/or buffer sizes).

IMHO, he has a point: if this is a restriction of for usb transfer
buffers, it should be documented somewhere.

Yet, a quick check with:
$ git grep -i dword Documentation/usb/
$ git grep -i align Documentation/usb/

Didn't hit anything related to it. 

> > In the specific case of uvc_driver, it uses an array where
> > it caches the content of video controls, passing it to the
> > USB stack via usb_control_msg(). Typical controls use 1 or 2
> > bytes. The net result is that other values of the buffer
> > gets overriden when this function is called.  
> 
> Not good, it should be fixed, otherwise you are going to have to try to
> fix up all host controllers :(
> 
> thanks,
> 
> greg k-h



Thanks,
Mauro
--
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: serial: drop termios-flag debugging

2017-03-28 Thread Johan Hovold
Drop some unnecessary termios-flag debugging that have been faithfully
reproduced in a few old drivers, including the "clfag" typo and all.

This also addresses a compiler warning on sparc where tcflag_t is
unsigned long and would have required an explicit cast.

Reported-by: Geert Uytterhoeven 
Signed-off-by: Johan Hovold 
---
 drivers/usb/serial/io_edgeport.c  |  5 -
 drivers/usb/serial/io_ti.c|  8 
 drivers/usb/serial/mos7720.c  | 11 ---
 drivers/usb/serial/mos7840.c  | 10 --
 drivers/usb/serial/ti_usb_3410_5052.c |  8 
 5 files changed, 42 deletions(-)

diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 751e7454c37b..e5d6265eac6e 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -1544,11 +1544,6 @@ static void edge_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios)
 {
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-   unsigned int cflag;
-
-   cflag = tty->termios.c_cflag;
-   dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, 
tty->termios.c_cflag, tty->termios.c_iflag);
-   dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, 
old_termios->c_cflag, old_termios->c_iflag);
 
if (edge_port == NULL)
return;
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index f3ed131d14bf..87798e625d6c 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2372,14 +2372,6 @@ static void edge_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios)
 {
struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-   unsigned int cflag;
-
-   cflag = tty->termios.c_cflag;
-
-   dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
-   tty->termios.c_cflag, tty->termios.c_iflag);
-   dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
-   old_termios->c_cflag, old_termios->c_iflag);
 
if (edge_port == NULL)
return;
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index b1f6b275e7c1..c3a314d5bdc6 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -1688,7 +1688,6 @@ static void mos7720_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios)
 {
int status;
-   unsigned int cflag;
struct usb_serial *serial;
struct moschip_port *mos7720_port;
 
@@ -1704,16 +1703,6 @@ static void mos7720_set_termios(struct tty_struct *tty,
return;
}
 
-   dev_dbg(&port->dev, "setting termios - ASPIRE\n");
-
-   cflag = tty->termios.c_cflag;
-
-   dev_dbg(&port->dev, "%s - cflag %08x iflag %08x\n", __func__,
-   tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag));
-
-   dev_dbg(&port->dev, "%s - old cflag %08x old iflag %08x\n", __func__,
-   old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
-
/* change the port settings to the new ones specified */
change_port_settings(tty, mos7720_port, old_termios);
 
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 770b3a470232..e8669aae14b3 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1868,7 +1868,6 @@ static void mos7840_set_termios(struct tty_struct *tty,
struct ktermios *old_termios)
 {
int status;
-   unsigned int cflag;
struct usb_serial *serial;
struct moschip_port *mos7840_port;
 
@@ -1890,15 +1889,6 @@ static void mos7840_set_termios(struct tty_struct *tty,
return;
}
 
-   dev_dbg(&port->dev, "%s", "setting termios - \n");
-
-   cflag = tty->termios.c_cflag;
-
-   dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__,
-   tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag));
-   dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__,
-   old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag));
-
/* change the port settings to the new ones specified */
 
mos7840_change_port_settings(tty, mos7840_port, old_termios);
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c 
b/drivers/usb/serial/ti_usb_3410_5052.c
index e16558b63fcc..8fc3854e5e69 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -929,7 +929,6 @@ static void ti_set_termios(struct tty_struct *tty,
 {
struct ti_port *tport = usb_get_serial_port_data(port);
struct ti_uart_config *config;
-   tcflag_t cflag, iflag;
int baud;
int status;
int port_number = port->port_number;
@@ -937,13 +936,6 @@ static void ti_set_

Re: [PATCH] usb: gadget: udc: remove redundant initial assignments to the pointer 's'

2017-03-28 Thread Sergei Shtylyov

Hello!

On 3/28/2017 1:34 AM, Colin King wrote:


From: Colin Ian King 

The initial setting of pointer s to the driver name or to the literal
string "(none)" is redundant as later it is always set to point to
a different literal string before it is printed log.  Remove this


   Printed to log, perhaps?


redundant code.

Detected with CoverityScan, CID#1227032, CID#1227033 ("Unused Value")

Signed-off-by: Colin Ian King 

[...]

MBR, Sergei

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


[PATCH 1/3] usb: dwc3: trace: change format for string to cmd trace

2017-03-28 Thread Felipe Balbi
a %x is much easier for a human to parse when reading tracepoint
output. Let's change it.

Signed-off-by: Felipe Balbi 
---

tested with Intel Edison (DWC3) and "g_ether use_eem=1"

 drivers/usb/dwc3/trace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index 69671e4589b9..fd5fc91fa9a0 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -173,7 +173,7 @@ DECLARE_EVENT_CLASS(dwc3_log_generic_cmd,
__entry->param = param;
__entry->status = status;
),
-   TP_printk("cmd '%s' [%d] param %08x --> status: %s",
+   TP_printk("cmd '%s' [%x] param %08x --> status: %s",
dwc3_gadget_generic_cmd_string(__entry->cmd),
__entry->cmd, __entry->param,
dwc3_gadget_generic_cmd_status_string(__entry->status)
-- 
2.11.0.295.gd7dffce1ce

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


[PATCH 2/3] usb: gadget: u_ether: use better list accessors

2017-03-28 Thread Felipe Balbi
We have helpers for some of these, let's rely on them instead of open
coding what they do in u_ether.c

Signed-off-by: Felipe Balbi 
---

tested with Intel Edison (DWC3) and "g_ether use_eem=1"

 drivers/usb/gadget/function/u_ether.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index c3cab77181d4..cba6ff683f2c 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -401,13 +401,12 @@ static int alloc_requests(struct eth_dev *dev, struct 
gether *link, unsigned n)
 static void rx_fill(struct eth_dev *dev, gfp_t gfp_flags)
 {
struct usb_request  *req;
+   struct usb_request  *tmp;
unsigned long   flags;
 
/* fill unused rxq slots with some skb */
spin_lock_irqsave(&dev->req_lock, flags);
-   while (!list_empty(&dev->rx_reqs)) {
-   req = container_of(dev->rx_reqs.next,
-   struct usb_request, list);
+   list_for_each_entry_safe(req, tmp, &dev->rx_reqs, list) {
list_del_init(&req->list);
spin_unlock_irqrestore(&dev->req_lock, flags);
 
@@ -527,7 +526,7 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
return NETDEV_TX_BUSY;
}
 
-   req = container_of(dev->tx_reqs.next, struct usb_request, list);
+   req = list_first_entry(&dev->tx_reqs, struct usb_request, list);
list_del(&req->list);
 
/* temporarily stop TX queue when the freelist empties */
@@ -1122,6 +1121,7 @@ void gether_disconnect(struct gether *link)
 {
struct eth_dev  *dev = link->ioport;
struct usb_request  *req;
+   struct usb_request  *tmp;
 
WARN_ON(!dev);
if (!dev)
@@ -1138,9 +1138,7 @@ void gether_disconnect(struct gether *link)
 */
usb_ep_disable(link->in_ep);
spin_lock(&dev->req_lock);
-   while (!list_empty(&dev->tx_reqs)) {
-   req = container_of(dev->tx_reqs.next,
-   struct usb_request, list);
+   list_for_each_entry_safe(req, tmp, &dev->tx_reqs, list) {
list_del(&req->list);
 
spin_unlock(&dev->req_lock);
@@ -1152,9 +1150,7 @@ void gether_disconnect(struct gether *link)
 
usb_ep_disable(link->out_ep);
spin_lock(&dev->req_lock);
-   while (!list_empty(&dev->rx_reqs)) {
-   req = container_of(dev->rx_reqs.next,
-   struct usb_request, list);
+   list_for_each_entry_safe(req, tmp, &dev->rx_reqs, list) {
list_del(&req->list);
 
spin_unlock(&dev->req_lock);
-- 
2.11.0.295.gd7dffce1ce

--
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 3/3] usb: gadget: u_ether: conditionally align transfer size

2017-03-28 Thread Felipe Balbi
Unless HW sets quirk_ep_out_aligned_size, gadget driver shouldn't make
any efforts towards aligning transfers. If the UDC needs, it *must*
set the quirk flag.

Signed-off-by: Felipe Balbi 
---

tested with Intel Edison (DWC3) and "g_ether use_eem=1"

 drivers/usb/gadget/function/u_ether.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index cba6ff683f2c..a8b40d07e927 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -178,6 +178,7 @@ static void rx_complete(struct usb_ep *ep, struct 
usb_request *req);
 static int
 rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags)
 {
+   struct usb_gadget *g = dev->gadget;
struct sk_buff  *skb;
int retval = -ENOMEM;
size_t  size = 0;
@@ -209,8 +210,11 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, 
gfp_t gfp_flags)
 */
size += sizeof(struct ethhdr) + dev->net->mtu + RX_EXTRA;
size += dev->port_usb->header_len;
-   size += out->maxpacket - 1;
-   size -= size % out->maxpacket;
+
+   if (g->quirk_ep_out_aligned_size) {
+   size += out->maxpacket - 1;
+   size -= size % out->maxpacket;
+   }
 
if (dev->port_usb->is_fixed)
size = max_t(size_t, size, dev->port_usb->fixed_out_len);
-- 
2.11.0.295.gd7dffce1ce

--
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/4] usb: dwc3: dual-role support

2017-03-28 Thread Felipe Balbi
Roger Quadros  writes:

> Hi,
>
> We rely on the OTG controller block or Extcon to provide us with
> VBUS and ID line status via an interrupt.
>
> This is then used to switch the controller between host, peripheral
> and idle roles based on the following table.
>
> ID  VBUSdual-role state
> --  ---
> 0   x   A_HOST - Host controller active
> 1   0   B_IDLE - Both Host and Gadget controllers inactive
> 1   1   B_PERIPHERAL - Gadget controller active
>
> Series depends on
> [1] dwc3 trivial fixes - https://lkml.org/lkml/2017/2/15/204

right, you never sent v2 of that though, did you? :-s -ECONFUSED

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] xhci: Manually give back cancelled URB if queuing it for cancel fails

2017-03-28 Thread Mathias Nyman

On 28.03.2017 09:49, Felipe Balbi wrote:


Hi,

Mathias Nyman  writes:

On 27.03.2017 17:54, Felipe Balbi wrote:


Hi,

Mathias Nyman  writes:

Manually give back URB if we are can not add it to the cancel queue, and
stop the endpoint normally.


this sentence doesn't parse very well ;-)


This can happen if device just reset before URB timed out and dequeued,
leading to missing endpoint ring.


seems like this could be extended a bit too.



I'll clean up those commit messages, and modify patch 2/3 a bit to only touch
the error message and URB actual_length for endpoint stopped at status stage.

This way there is as little change going to usb-linus and stable as possible,
saving the reset for usb-next

-Mathias   


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


[PATCH v3 4/7] UDC: Provide correct arguments for 'dma_pool_create'

2017-03-28 Thread Raviteja Garimella
Change the argument from NULL to a struct device for the
dma_pool_create call during dma init.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/snps_udc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index c778d51..5f95a65 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -3101,7 +3101,7 @@ int init_dma_pools(struct udc *dev)
}
 
/* DMA setup */
-   dev->data_requests = dma_pool_create("data_requests", NULL,
+   dev->data_requests = dma_pool_create("data_requests", dev->dev,
sizeof(struct udc_data_dma), 0, 0);
if (!dev->data_requests) {
DBG(dev, "can't get request data pool\n");
@@ -3112,7 +3112,7 @@ int init_dma_pools(struct udc *dev)
dev->ep[UDC_EP0IN_IX].dma = &dev->regs->ctl;
 
/* dma desc for setup data */
-   dev->stp_requests = dma_pool_create("setup requests", NULL,
+   dev->stp_requests = dma_pool_create("setup requests", dev->dev,
sizeof(struct udc_stp_dma), 0, 0);
if (!dev->stp_requests) {
DBG(dev, "can't get stp request pool\n");
-- 
2.1.0

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


[PATCH v3 5/7] UDC: Use struct dma_pool instead of pci_pool

2017-03-28 Thread Raviteja Garimella
Using dma_pool instead of pci_pool will make snps_udc_core driver
to be compatible with non-pci platforms.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/amd5536udc.h| 4 ++--
 drivers/usb/gadget/udc/snps_udc_core.c | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index c252457..91aae23 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -551,8 +551,8 @@ struct udc {
u32 __iomem *txfifo;
 
/* DMA desc pools */
-   struct pci_pool *data_requests;
-   struct pci_pool *stp_requests;
+   struct dma_pool *data_requests;
+   struct dma_pool *stp_requests;
 
/* device data */
unsigned long   phys_addr;
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 5f95a65..9d3861b 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -543,7 +543,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
 
if (ep->dma) {
/* ep0 in requests are allocated from data pool here */
-   dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
+   dma_desc = dma_pool_alloc(ep->dev->data_requests, gfp,
&req->td_phys);
if (!dma_desc) {
kfree(req);
@@ -582,7 +582,7 @@ static int udc_free_dma_chain(struct udc *dev, struct 
udc_request *req)
td = phys_to_virt(td_last->next);
 
for (i = 1; i < req->chain_len; i++) {
-   pci_pool_free(dev->data_requests, td,
+   dma_pool_free(dev->data_requests, td,
  (dma_addr_t)td_last->next);
td_last = td;
td = phys_to_virt(td_last->next);
@@ -612,7 +612,7 @@ udc_free_request(struct usb_ep *usbep, struct usb_request 
*usbreq)
if (req->chain_len > 1)
udc_free_dma_chain(ep->dev, req);
 
-   pci_pool_free(ep->dev->data_requests, req->td_data,
+   dma_pool_free(ep->dev->data_requests, req->td_data,
req->td_phys);
}
kfree(req);
@@ -807,7 +807,7 @@ static int udc_create_dma_chain(
for (i = buf_len; i < bytes; i += buf_len) {
/* create or determine next desc. */
if (create_new_chain) {
-   td = pci_pool_alloc(ep->dev->data_requests,
+   td = dma_pool_alloc(ep->dev->data_requests,
gfp_flags, &dma_addr);
if (!td)
return -ENOMEM;
-- 
2.1.0

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


[PATCH v3 1/7] UDC: Split the driver into amd (pci) and Synopsys core IP driver

2017-03-28 Thread Raviteja Garimella
This patch splits the amd5536udc driver into two -- one that does
pci device registration and the other file that does the rest of
the driver tasks like the gadget/ep ops etc for Synopsys UDC.

This way of splitting helps in exporting core driver symbols which
can be used by any other platform/pci driver that is written for
the same Synopsys USB device controller.

The current patch also includes a change in the Kconfig and Makefile.
A new config option USB_SNP_CORE will be selected automatically when
any one of the platform or pci driver for the same UDC is selected.

Main changes:
- amd5536udc_pci.c: PCI device registration is moved to this file.

- amd5536udc.c:
  This file does rest of the core UDC fucntionality.
  9 symbols are exported so as to be used by amd5536udc_pci.c.
  Module parameter definitions are moved to header file.

- amd5536udc.h:
  Function declarations, module parameters definitions and few common
  header file includes are added to this file

- Kconfig:
  New USB_SNP_CORE option is added which will be auto selected when
  any pci or platform driver config option for the UDC is chosen.

- Makefile:
  Compiles the core and pci files separately.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/Kconfig  |  18 +++
 drivers/usb/gadget/udc/Makefile |   3 +-
 drivers/usb/gadget/udc/amd5536udc.c | 238 
 drivers/usb/gadget/udc/amd5536udc.h |  36 +
 drivers/usb/gadget/udc/amd5536udc_pci.c | 217 +
 5 files changed, 297 insertions(+), 215 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 4b69f28..2cee076 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -253,6 +253,20 @@ config USB_MV_U3D
  MARVELL PXA2128 Processor series include a super speed USB3.0 device
  controller, which support super speed USB peripheral.
 
+config USB_SNP_CORE
+   depends on USB_AMD5536UDC
+   tristate
+   help
+ This enables core driver support for Synopsys USB 2.0 Device
+ controller.
+
+ This will be enabled when PCI or Platform driver for this UDC is
+ selected. Currently, this will be enabled by USB_SNP_UDC_PLAT or
+ USB_AMD5536UDC options.
+
+ This IP is different to the High Speed OTG IP that can be enabled
+ by selecting USB_DWC2 or USB_DWC3 options.
+
 #
 # Controllers available in both integrated and discrete versions
 #
@@ -278,6 +292,7 @@ source "drivers/usb/gadget/udc/bdc/Kconfig"
 config USB_AMD5536UDC
tristate "AMD5536 UDC"
depends on PCI
+   select USB_SNP_CORE
help
   The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
   It is a USB Highspeed DMA capable USB device controller. Beside ep0
@@ -285,6 +300,9 @@ config USB_AMD5536UDC
   The UDC port supports OTG operation, and may be used as a host port
   if it's not being used to implement peripheral or OTG roles.
 
+  This UDC is based on Synopsys USB device controller IP and selects
+  CONFIG_USB_SNP_CORE option to build the core driver.
+
   Say "y" to link the driver statically, or "m" to build a
   dynamically linked module called "amd5536udc" and force all
   gadget drivers to also be dynamically linked.
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 98e74ed..626e1f1 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -10,7 +10,8 @@ obj-$(CONFIG_USB_GADGET)  += udc-core.o
 obj-$(CONFIG_USB_DUMMY_HCD)+= dummy_hcd.o
 obj-$(CONFIG_USB_NET2272)  += net2272.o
 obj-$(CONFIG_USB_NET2280)  += net2280.o
-obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc.o
+obj-$(CONFIG_USB_SNP_CORE) += amd5536udc.o
+obj-$(CONFIG_USB_AMD5536UDC)   += amd5536udc_pci.o
 obj-$(CONFIG_USB_PXA25X)   += pxa25x_udc.o
 obj-$(CONFIG_USB_PXA27X)   += pxa27x_udc.o
 obj-$(CONFIG_USB_GOKU) += goku_udc.o
diff --git a/drivers/usb/gadget/udc/amd5536udc.c 
b/drivers/usb/gadget/udc/amd5536udc.c
index ea03ca7..72f3c8f 100644
--- a/drivers/usb/gadget/udc/amd5536udc.c
+++ b/drivers/usb/gadget/udc/amd5536udc.c
@@ -11,27 +11,15 @@
  */
 
 /*
- * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
- * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
- * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
- *
- * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
- * be used as host port) and UOC bits PAD_EN and APU are set (should be done
- * by BIOS init).
- *
- * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
- * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
- * can be used with gadget ether.
+ * This file does the core driver implementation

[PATCH v3 0/7] Platform driver support for 'amd5536udc' driver

2017-03-28 Thread Raviteja Garimella
Changes in PATCH v3:
===
1. Updated bindings documentation and platform driver to add
   "brcm,iproc-udc" compatibility string.

2. Added a patch to replace references of struct pci_pool with
   struct dma_pool so that it is compatibile with non-pci drivers.

Changes in PATCH v2:
===
1. Updated bindings documentation:
   -- compatibility string for each supported SoC
   -- removed extcon node
   -- rename the file name to just iproc-udc.txt

2. Modified comptability strings in platform driver file
   to reflect the change made in 1.

3 Kconfig
   -- Resolved warnings shown by kbuild-test-robot  

The changes are being submitted as PATCH this time. Below are the
details of main changes with respect to previous RFC versions.

Changes in PATCH v1:
===
Patch 1/6 now splits the driver into amd5536udc_pci_.c (which
contains only the PCI device registration part), and amd5536udc.c
will still be driver that does the rest of UDC driver functionality.

Patch 2/6 renames amd5536udc.c to snps_udc_core.c.

The DT compatibilty string is changed to "brcm,iproc-snps-udc"
as per review comments for RFCv2. The driver and bindings
documentation is modified to reflect this.

This is RFC for the changes made as per the review comments made for
the previous version. I would like to know  if this approach (the way
the driver is split and the naming and all)looks good to be submitted.


Changes in RFC v2:
=
1. Split the driver into platform/pci specific drivers with a core driver
   file that handles the common driver routines that are exported.

2. Split the driver into number of patches as suggested in previous
   review comments.

3. Added the devicetree bindings documentation for Synopsys platform
   driver.

Introduction (RFC v1):
=
This patch adds platform device support to the existing 'amd5536udc'
driver.

The UDC is based on Synopsys Designware core USB (2.0) Device controller
IP.

The driver so far supports UDCs that are a part of AMD southbridge
and is connected through PCI bus.

The same driver can be used with UDCs that are integrated into SoCs
like Broadcom's Northstar2/Cygnus platforms by adding platform device
suooprt.

This patch contains all the changes that were required to get the driver
functional on Broadcom's Northstar2 platform. 

This is a request for comments from maintainers/others regarding approach
on whether to have 2 different drivers (one each for AMD and Broadcom)
with a common library (3 files in total), or have a single driver like
it's done in this patch and have the driver filename changed to some
common name based on ther underlying IP, like snps_udc.c.

Below are the main changes done:

1. Added OF based platform device registration -- so that the driver gets
   probed based on the device tree entry. Like wise, remove routine and
   platform PM ops are supported.

2. Modified debug prints to be compatible with both pci and platform
   devices.

3. Added members to 'struct udc' in header file for extcon and phy support.
   This is required if the UDC is connected to a Dual Role Device Phy
   where the Phy can be configured to be in Device mode or Host mode based
   on the type of external cable that is connected to the port.
 
4. Added checks in udc connect/disconnect routines so as to return if the
   routine is already called.

5. Modified the arguments passed to dma_pool_create routine -- which
   expects struct device, whereas NULL is passed in the existing version.
 
6. Kconfig changes are done so that the driver now depends on either of
   CONFIG_OF or CONFIG_PCI. More description about the Synopsys IP is
   provided.

Repo: https://github.com/Broadcom/arm64-linux.git
Branch: udc_snps_v3

Raviteja Garimella (7):
  UDC: Split the driver into amd (pci) and Synopsys core IP driver
  UDC: Rename amd5536udc driver file based on IP
  UDC: make debug prints compatible with both pci and platform devices
  UDC: Provide correct arguments for 'dma_pool_create'
  UDC: Use struct dma_pool instead of pci_pool
  DT bindings documentation for Broadcom IPROC USB Device controller.
  UDC: Add Synopsys UDC Platform driver

 .../devicetree/bindings/usb/iproc-udc.txt  |   21 +
 drivers/usb/gadget/udc/Kconfig |   32 +
 drivers/usb/gadget/udc/Makefile|4 +-
 drivers/usb/gadget/udc/amd5536udc.c| 3413 
 drivers/usb/gadget/udc/amd5536udc.h|   58 +-
 drivers/usb/gadget/udc/amd5536udc_pci.c|  218 ++
 drivers/usb/gadget/udc/snps_udc_core.c | 3239 +++
 drivers/usb/gadget/udc/snps_udc_plat.c |  344 ++
 8 files changed, 3912 insertions(+), 3417 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt
 delete mode 100644 drivers/usb/gadget/udc/amd5536udc.c
 create mode 100644 drivers/usb/gadget/udc/amd5536udc_pci.c
 create mode 100644 drivers/usb/gadget/udc

[PATCH v3 3/7] UDC: make debug prints compatible with both pci and platform devices

2017-03-28 Thread Raviteja Garimella
This patch adds a struct device member to UDC data structure and
makes changes to the arguments of dev_err and dev_dbg calls so that
the debug prints work for both pci and platform devices.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/amd5536udc.h |  4 +++-
 drivers/usb/gadget/udc/amd5536udc_pci.c |  1 +
 drivers/usb/gadget/udc/snps_udc_core.c  | 28 ++--
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index bd2a18e..c252457 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -563,6 +563,8 @@ struct udc {
u16 cur_config;
u16 cur_intf;
u16 cur_alt;
+
+   struct device   *dev;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -639,7 +641,7 @@ MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
 
 /* debug macros */
 
-#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
+#define DBG(udc , args...) dev_dbg(udc->dev, args)
 
 #ifdef UDC_VERBOSE
 #define VDBG   DBG
diff --git a/drivers/usb/gadget/udc/amd5536udc_pci.c 
b/drivers/usb/gadget/udc/amd5536udc_pci.c
index 2a2d0a9..57a13f0 100644
--- a/drivers/usb/gadget/udc/amd5536udc_pci.c
+++ b/drivers/usb/gadget/udc/amd5536udc_pci.c
@@ -168,6 +168,7 @@ static int udc_pci_probe(
dev->phys_addr = resource;
dev->irq = pdev->irq;
dev->pdev = pdev;
+   dev->dev = &pdev->dev;
 
/* general probing */
if (udc_probe(dev)) {
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 72f3c8f..c778d51 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -209,18 +209,18 @@ static void print_regs(struct udc *dev)
if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBNDU (packet per buffer "
"WITHOUT desc. update)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBNDU");
} else if (use_dma && use_dma_ppb && use_dma_ppb_du) {
DBG(dev, "DMA mode   = PPBDU (packet per buffer "
"WITH desc. update)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU");
+   dev_info(dev->dev, "DMA mode (%s)\n", "PPBDU");
}
if (use_dma && use_dma_bufferfill_mode) {
DBG(dev, "DMA mode   = BF (buffer fill mode)\n");
-   dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF");
+   dev_info(dev->dev, "DMA mode (%s)\n", "BF");
}
if (!use_dma)
-   dev_info(&dev->pdev->dev, "FIFO mode\n");
+   dev_info(dev->dev, "FIFO mode\n");
DBG(dev, "---\n");
 }
 
@@ -1628,7 +1628,7 @@ static void udc_setup_endpoints(struct udc *dev)
 static void usb_connect(struct udc *dev)
 {
 
-   dev_info(&dev->pdev->dev, "USB Connect\n");
+   dev_info(dev->dev, "USB Connect\n");
 
dev->connected = 1;
 
@@ -1646,7 +1646,7 @@ static void usb_connect(struct udc *dev)
 static void usb_disconnect(struct udc *dev)
 {
 
-   dev_info(&dev->pdev->dev, "USB Disconnect\n");
+   dev_info(dev->dev, "USB Disconnect\n");
 
dev->connected = 0;
 
@@ -2110,7 +2110,7 @@ static irqreturn_t udc_data_out_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(&dev->pdev->dev, "HE ep%dout occurred\n", ep->num);
+   dev_err(dev->dev, "HE ep%dout occurred\n", ep->num);
 
/* clear HE */
writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts);
@@ -2309,7 +2309,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
if (use_dma) {
/* BNA ? */
if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
-   dev_err(&dev->pdev->dev,
+   dev_err(dev->dev,
"BNA ep%din occurred - DESPTR = %08lx\n",
ep->num,
(unsigned long) readl(&ep->regs->desptr));
@@ -2322,7 +2322,7 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int 
ep_ix)
}
/* HE event ? */
if (epsts & AMD_BIT(UDC_EPSTS_HE)) {
-   dev_err(&dev->pdev->dev,
+   dev_err(dev->dev,
"HE ep%dn occurred - DESPTR = %08lx\n",
ep->num, (unsigned long) readl(&ep->regs->desptr));
 
@@ -2960,7 +2960,7 @@ __acquires(dev->lock)
 
/* link up all endpoi

[PATCH v3 7/7] UDC: Add Synopsys UDC Platform driver

2017-03-28 Thread Raviteja Garimella
This patch adds platform driver support for Synopsys UDC.

A new driver file (snps_udc_plat.c) is created for this purpose
where the platform driver registration is done based on OF
node.

Currently, UDC integrated into Broadcom's iProc SoCs (Northstar2
and Cygnus) work with this driver.

New members are added to the UDC data structure for having platform
device support along with extcon and phy support.

Kconfig and Makefiles are modified to select platform driver for
compilation.

Signed-off-by: Raviteja Garimella 
---
 drivers/usb/gadget/udc/Kconfig |  16 +-
 drivers/usb/gadget/udc/Makefile|   1 +
 drivers/usb/gadget/udc/amd5536udc.h|  14 ++
 drivers/usb/gadget/udc/snps_udc_core.c |  54 --
 drivers/usb/gadget/udc/snps_udc_plat.c | 344 +
 5 files changed, 409 insertions(+), 20 deletions(-)
 create mode 100644 drivers/usb/gadget/udc/snps_udc_plat.c

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 2cee076..fe87523 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -254,7 +254,7 @@ config USB_MV_U3D
  controller, which support super speed USB peripheral.
 
 config USB_SNP_CORE
-   depends on USB_AMD5536UDC
+   depends on (USB_AMD5536UDC || USB_SNP_UDC_PLAT)
tristate
help
  This enables core driver support for Synopsys USB 2.0 Device
@@ -267,6 +267,20 @@ config USB_SNP_CORE
  This IP is different to the High Speed OTG IP that can be enabled
  by selecting USB_DWC2 or USB_DWC3 options.
 
+config USB_SNP_UDC_PLAT
+   tristate "Synopsys USB 2.0 Device controller"
+   depends on (USB_GADGET && OF)
+   select USB_GADGET_DUALSPEED
+   select USB_SNP_CORE
+   default ARCH_BCM_IPROC
+   help
+ This adds Platform Device support for Synopsys Designware core
+ AHB subsystem USB2.0 Device Controller (UDC).
+
+ This driver works with UDCs integrated into Broadcom's Northstar2
+ and Cygnus SoCs.
+
+ If unsure, say N.
 #
 # Controllers available in both integrated and discrete versions
 #
diff --git a/drivers/usb/gadget/udc/Makefile b/drivers/usb/gadget/udc/Makefile
index 4f4fd62..ea9e1c7 100644
--- a/drivers/usb/gadget/udc/Makefile
+++ b/drivers/usb/gadget/udc/Makefile
@@ -37,4 +37,5 @@ obj-$(CONFIG_USB_FOTG210_UDC) += fotg210-udc.o
 obj-$(CONFIG_USB_MV_U3D)   += mv_u3d_core.o
 obj-$(CONFIG_USB_GR_UDC)   += gr_udc.o
 obj-$(CONFIG_USB_GADGET_XILINX)+= udc-xilinx.o
+obj-$(CONFIG_USB_SNP_UDC_PLAT) += snps_udc_plat.o
 obj-$(CONFIG_USB_BDC_UDC)  += bdc/
diff --git a/drivers/usb/gadget/udc/amd5536udc.h 
b/drivers/usb/gadget/udc/amd5536udc.h
index 91aae23..4fe22d4 100644
--- a/drivers/usb/gadget/udc/amd5536udc.h
+++ b/drivers/usb/gadget/udc/amd5536udc.h
@@ -16,6 +16,7 @@
 /* debug control */
 /* #define UDC_VERBOSE */
 
+#include 
 #include 
 #include 
 
@@ -28,6 +29,9 @@
 #define UDC_HSA0_REV 1
 #define UDC_HSB1_REV 2
 
+/* Broadcom chip rev. */
+#define UDC_BCM_REV 10
+
 /*
  * SETUP usb commands
  * needed, because some SETUP's are handled in hw, but must be passed to
@@ -112,6 +116,7 @@
 #define UDC_DEVCTL_BRLEN_MASK  0x00ff
 #define UDC_DEVCTL_BRLEN_OFS   16
 
+#define UDC_DEVCTL_SRX_FLUSH   14
 #define UDC_DEVCTL_CSR_DONE13
 #define UDC_DEVCTL_DEVNAK  12
 #define UDC_DEVCTL_SD  10
@@ -564,7 +569,15 @@ struct udc {
u16 cur_intf;
u16 cur_alt;
 
+   /* for platform device and extcon support */
struct device   *dev;
+   struct phy  *udc_phy;
+   struct extcon_dev   *edev;
+   struct extcon_specific_cable_nb extcon_nb;
+   struct notifier_block   nb;
+   struct delayed_work drd_work;
+   struct workqueue_struct *drd_wq;
+   u32 conn_type;
 };
 
 #define to_amd5536_udc(g)  (container_of((g), struct udc, gadget))
@@ -580,6 +593,7 @@ int udc_enable_dev_setup_interrupts(struct udc *dev);
 int udc_mask_unused_interrupts(struct udc *dev);
 irqreturn_t udc_irq(int irq, void *pdev);
 void gadget_release(struct device *pdev);
+void empty_req_queue(struct udc_ep *ep);
 void udc_basic_init(struct udc *dev);
 void free_dma_pools(struct udc *dev);
 int init_dma_pools(struct udc *dev);
diff --git a/drivers/usb/gadget/udc/snps_udc_core.c 
b/drivers/usb/gadget/udc/snps_udc_core.c
index 9d3861b..b5f772e 100644
--- a/drivers/usb/gadget/udc/snps_udc_core.c
+++ b/drivers/usb/gadget/udc/snps_udc_core.c
@@ -41,7 +41,6 @@
 #include "amd5536udc.h"
 
 static void udc_tasklet_disconnect(unsigned long);
-static void empty_req_queue(struct udc_ep *);
 static void udc_setup_endpoints(struct udc *dev);
 static void udc_soft_reset(struct udc *dev);
 static struct udc_re

Re: [PATCH v2 3/4] usb: dwc3: add dual-role support

2017-03-28 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
> If dr_mode is "otg" then support dual role mode of operation.
>
> Get ID and VBUS information from the OTG controller
> and put the controller in the appropriate state.
>
> This is our dual-role state table.
>
> IDVBUSdual-role state
> -----
> 0 x   A_HOST - Host controller active
> 1 0   B_IDLE - Both Host and Gadget controllers inactive
> 1 1   B_PERIPHERAL - Gadget controller active
>
> Calling dwc3_otg_fsm_sync() directly from dwc3_complete() can
> lock up the system at xHCI add/remove so we use a work queue for it.
>
> Signed-off-by: Roger Quadros 

it still seems to me that you're adding too much code for something that
should be darn simple. Please, read on.

> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 369bab1..619fa7c 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -27,6 +27,7 @@
>  #include 
>  #include 
>  #include 
> +#include 

as a cosmetic change, it would be nicer to have a drd.c or otg.c which
exposes dwc3_otg_start()/stop() like we do for gadget.c and host.c

> @@ -107,6 +108,7 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
>   reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
>   reg |= DWC3_GCTL_PRTCAPDIR(mode);
> + dwc->current_mode = mode;
>   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>  }
>  
> @@ -839,6 +841,505 @@ static int dwc3_core_get_phy(struct dwc3 *dwc)
>   return 0;
>  }
>  
> +static int dwc3_drd_start_host(struct dwc3 *dwc, int on, bool skip);
> +static int dwc3_drd_start_gadget(struct dwc3 *dwc, int on);
> +
> +/* dwc->lock must be held */
> +static void dwc3_drd_statemachine(struct dwc3 *dwc, int id, int vbus)
> +{
> + enum usb_otg_state new_state;
> + int protocol;
> +
> + if (id == dwc->otg_fsm.id && vbus == dwc->otg_fsm.b_sess_vld)
> + return;
> +
> + dwc->otg_fsm.id = id;
> + dwc->otg_fsm.b_sess_vld = vbus;
> +
> + if (!id) {
> + new_state = OTG_STATE_A_HOST;
> + } else{
> + if (vbus)
> + new_state = OTG_STATE_B_PERIPHERAL;
> + else
> + new_state = OTG_STATE_B_IDLE;
> + }
> +
> + if (dwc->otg.state == new_state)
> + return;
> +
> + protocol = dwc->otg_fsm.protocol;
> + switch (new_state) {
> + case OTG_STATE_B_IDLE:
> + if (protocol == PROTO_GADGET)
> + dwc3_drd_start_gadget(dwc, 0);
> + else if (protocol == PROTO_HOST)
> + dwc3_drd_start_host(dwc, 0, 0);
> + dwc->otg_fsm.protocol = PROTO_UNDEF;
> + break;
> + case OTG_STATE_B_PERIPHERAL:
> + if (protocol == PROTO_HOST)
> + dwc3_drd_start_host(dwc, 0, 0);
> +
> + if (protocol != PROTO_GADGET) {
> + dwc->otg_fsm.protocol = PROTO_GADGET;
> + dwc3_drd_start_gadget(dwc, 1);
> + }
> + break;
> + case OTG_STATE_A_HOST:
> + if (protocol == PROTO_GADGET)
> + dwc3_drd_start_gadget(dwc, 0);
> +
> + if (protocol != PROTO_HOST) {
> + dwc->otg_fsm.protocol = PROTO_HOST;
> + dwc3_drd_start_host(dwc, 1, 0);
> + }
> + break;
> + default:
> + dev_err(dwc->dev, "drd: invalid usb-drd state: %s\n",
> + usb_otg_state_string(new_state));
> + return;
> + }
> +
> + dwc->otg.state = new_state;
> +}

I think I've mentioned this before. Why don't we start with the simplest
possible implementation? Something that *just* allows us to get ID pin
value and set the mode. After that's stable, then we add more pieces to
the mix.

For something that simple, we wouldn't even need to use OTG FSM layer
because that brings no benefit for such a simple requirement.

Once there's a *real* need for OTG FSM, then we can add support for it,
but then we add support to something we know to be working.

> +/* dwc->lock must be held */
> +static void dwc3_otg_fsm_sync(struct dwc3 *dwc)
> +{
> + u32 reg;
> + int id, vbus;
> +
> + /*
> +  * calling dwc3_otg_fsm_sync() during resume breaks host
> +  * if adapter was removed during suspend as xhci driver
> +  * is not prepared to see hcd removal before xhci_resume.
> +  */
> + if (dwc->otg_prevent_sync)
> + return;
> +
> + reg = dwc3_readl(dwc->regs, DWC3_OSTS);
> + id = !!(reg & DWC3_OSTS_CONIDSTS);
> + vbus = !!(reg & DWC3_OSTS_BSESVLD);
> + dwc3_drd_statemachine(dwc, id, vbus);
> +}

Just consider this for a moment. Consider the steps taken to get here.

- User plugs cable
- Hardirq handler run
- read register
- if (reg) return IRQ_WAKE_THREAD;
- schedule bottom half handler to sometime in the futur

[PATCH v3 6/7] DT bindings documentation for Broadcom IPROC USB Device controller.

2017-03-28 Thread Raviteja Garimella
The device node is used for UDCs integrated into Broadcom's
iProc family of SoCs'. The UDC is based on Synopsys Designware
Cores AHB Subsystem USB Device Controller IP.

Signed-off-by: Raviteja Garimella 
---
 Documentation/devicetree/bindings/usb/iproc-udc.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/iproc-udc.txt

diff --git a/Documentation/devicetree/bindings/usb/iproc-udc.txt 
b/Documentation/devicetree/bindings/usb/iproc-udc.txt
new file mode 100644
index 000..272d7fa
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/iproc-udc.txt
@@ -0,0 +1,21 @@
+Broadcom IPROC USB Device controller.
+
+The device node is used for UDCs integrated into Broadcom's
+iProc family (Northstar2, Cygnus) of SoCs'. The UDC is based
+on Synopsys Designware Cores AHB Subsystem Device Controller
+IP.
+
+Required properties:
+ - compatible: Add the compatibility strings for supported platforms.
+   For Broadcom NS2 platform, add "brcm,ns2-udc","brcm,iproc-udc".
+   For Broadcom Cygnus platform, add "brcm,cygnus-udc", "brcm,iproc-udc".
+ - reg: Offset and length of UDC register set
+ - interrupts: description of interrupt line
+ - phys: phandle to phy node.
+
+Example:
+   udc_dwc: usb@664e {
+   compatible = "brcm,ns2-udc", "brcm,iproc-udc";
+   reg = <0x664e 0x2000>;
+   interrupts = ;
+   phys = <&usbdrd_phy>;
-- 
2.1.0

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


Re: [PATCH] usb: mtu3: Replace the extcon API

2017-03-28 Thread Chunfeng Yun
Hi,

On Tue, 2017-03-28 at 13:42 +0900, Chanwoo Choi wrote:
> This patch uses the resource-managed extcon API for extcon_register_notifier()
> and replaces the deprecated extcon API as following:
> - extcon_get_cable_state_() -> extcon_get_state()
> 
> Cc: Greg Kroah-Hartman 
> Cc: Chunfeng Yun 
> Cc: linux-usb@vger.kernel.org
> Signed-off-by: Chanwoo Choi 
> ---
>  drivers/usb/mtu3/mtu3_dr.c | 19 ++-
>  1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c
> index 1a8987e7c5b0..11a0d3b84c5e 100644
> --- a/drivers/usb/mtu3/mtu3_dr.c
> +++ b/drivers/usb/mtu3/mtu3_dr.c
> @@ -223,25 +223,25 @@ static int ssusb_extcon_register(struct otg_switch_mtk 
> *otg_sx)
>   return 0;
>  
>   otg_sx->vbus_nb.notifier_call = ssusb_vbus_notifier;
> - ret = extcon_register_notifier(edev, EXTCON_USB,
> + ret = devm_extcon_register_notifier(ssusb->dev, edev, EXTCON_USB,
>   &otg_sx->vbus_nb);
>   if (ret < 0)
>   dev_err(ssusb->dev, "failed to register notifier for USB\n");
>  
>   otg_sx->id_nb.notifier_call = ssusb_id_notifier;
> - ret = extcon_register_notifier(edev, EXTCON_USB_HOST,
> + ret = devm_extcon_register_notifier(ssusb->dev, edev, EXTCON_USB_HOST,
>   &otg_sx->id_nb);
>   if (ret < 0)
>   dev_err(ssusb->dev, "failed to register notifier for 
> USB-HOST\n");
>  
>   dev_dbg(ssusb->dev, "EXTCON_USB: %d, EXTCON_USB_HOST: %d\n",
> - extcon_get_cable_state_(edev, EXTCON_USB),
> - extcon_get_cable_state_(edev, EXTCON_USB_HOST));
> + extcon_get_state(edev, EXTCON_USB),
> + extcon_get_state(edev, EXTCON_USB_HOST));
>  
>   /* default as host, switch to device mode if needed */
> - if (extcon_get_cable_state_(edev, EXTCON_USB_HOST) == false)
> + if (extcon_get_state(edev, EXTCON_USB_HOST) == false)
>   ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT);
> - if (extcon_get_cable_state_(edev, EXTCON_USB) == true)
> + if (extcon_get_state(edev, EXTCON_USB) == true)
>   ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID);
>  
>   return 0;
> @@ -367,13 +367,6 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb)
>  
>   cancel_delayed_work(&otg_sx->extcon_reg_dwork);
>  
> - if (otg_sx->edev) {
> - extcon_unregister_notifier(otg_sx->edev,
> - EXTCON_USB, &otg_sx->vbus_nb);
> - extcon_unregister_notifier(otg_sx->edev,
> - EXTCON_USB_HOST, &otg_sx->id_nb);
> - }
> -
>   if (otg_sx->manual_drd_enabled)
>   ssusb_debugfs_exit(ssusb);
>  }

Tested-by: Chunfeng Yun 
Acked-by: Chunfeng Yun 

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 v2 4/4] usb: dwc3: Workaround for super-speed host on dra7 in dual-role mode

2017-03-28 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
> dra7 OTG core limits the host controller to USB2.0 (high-speed) mode
> when we're operating in dual-role.

yeah, that's not a quirk. DRA7 supports OTGv2, not OTGv3. There was no
USB3 when OTGv2 was written.

DRA7 just shouldn't use OTG core altogether. In fact, this is the very
thing I've been saying for a long time. Make the simplest implementation
possible. The dead simple, does-one-thing-only sort of implementation.

All we need for Dual-Role (without OTG extras) is some input for ID and
VBUS, then we add/remove HCD/UDC conditionally and set PRTCAPDIR.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH 2/4] usb: gadget: udc: add USB ID signal monitoring

2017-03-28 Thread Yoshihiro Shimoda
This usb 3.0 peripheral controller has a register (USB_OTG_STA) to monitor
the USB ID signal. So, this patch adds the ID signal monitoring to change
the mode to host (A-Device) or peripheral (B-Device).

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 47 +++
 1 file changed, 47 insertions(+)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 4029593..d81953b 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -37,6 +37,9 @@
 #define USB3_USB_INT_ENA_2 0x22c
 #define USB3_STUP_DAT_00x230
 #define USB3_STUP_DAT_10x234
+#define USB3_USB_OTG_STA   0x268
+#define USB3_USB_OTG_INT_STA   0x26c
+#define USB3_USB_OTG_INT_ENA   0x270
 #define USB3_P0_MOD0x280
 #define USB3_P0_CON0x288
 #define USB3_P0_STA0x28c
@@ -124,6 +127,9 @@
 /* USB_INT_ENA_2 and USB_INT_STA_2 */
 #define USB_INT_2_PIPE(n)  BIT(n)
 
+/* USB_OTG_STA, USB_OTG_INT_STA and USB_OTG_INT_ENA */
+#define USB_OTG_IDMON  BIT(4)
+
 /* P0_MOD */
 #define P0_MOD_DIR BIT(6)
 
@@ -540,17 +546,39 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
}
 }
 
+static void usb3_mode_a_host(struct renesas_usb3 *usb3)
+{
+   usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+   usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
+}
+
 static void usb3_mode_b_peri(struct renesas_usb3 *usb3)
 {
usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
 }
 
+static bool usb3_is_a_device(struct renesas_usb3 *usb3)
+{
+   return !(usb3_read(usb3, USB3_USB_OTG_STA) & USB_OTG_IDMON);
+}
+
+static void usb3_check_id(struct renesas_usb3 *usb3)
+{
+   if (usb3_is_a_device(usb3) && !usb3->forced_b_device)
+   usb3_mode_a_host(usb3);
+   else
+   usb3_mode_b_peri(usb3);
+}
+
 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3)
 {
usb3_init_axi_bridge(usb3);
usb3_init_epc_registers(usb3);
+   usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_STA);
+   usb3_write(usb3, USB_OTG_IDMON, USB3_USB_OTG_INT_ENA);
 
+   usb3_check_id(usb3);
usb3_check_vbus(usb3);
 }
 
@@ -559,6 +587,7 @@ static void renesas_usb3_stop_controller(struct 
renesas_usb3 *usb3)
usb3_disconnect(usb3);
usb3_write(usb3, 0, USB3_P0_INT_ENA);
usb3_write(usb3, 0, USB3_PN_INT_ENA);
+   usb3_write(usb3, 0, USB3_USB_OTG_INT_ENA);
usb3_write(usb3, 0, USB3_USB_INT_ENA_1);
usb3_write(usb3, 0, USB3_USB_INT_ENA_2);
usb3_write(usb3, 0, USB3_AXI_INT_ENA);
@@ -1492,10 +1521,22 @@ static void usb3_irq_epc_int_2(struct renesas_usb3 
*usb3, u32 int_sta_2)
}
 }
 
+static void usb3_irq_idmon_change(struct renesas_usb3 *usb3)
+{
+   usb3_check_id(usb3);
+}
+
+static void usb3_irq_otg_int(struct renesas_usb3 *usb3, u32 otg_int_sta)
+{
+   if (otg_int_sta & USB_OTG_IDMON)
+   usb3_irq_idmon_change(usb3);
+}
+
 static void usb3_irq_epc(struct renesas_usb3 *usb3)
 {
u32 int_sta_1 = usb3_read(usb3, USB3_USB_INT_STA_1);
u32 int_sta_2 = usb3_read(usb3, USB3_USB_INT_STA_2);
+   u32 otg_int_sta = usb3_read(usb3, USB3_USB_OTG_INT_STA);
 
int_sta_1 &= usb3_read(usb3, USB3_USB_INT_ENA_1);
if (int_sta_1) {
@@ -1506,6 +1547,12 @@ static void usb3_irq_epc(struct renesas_usb3 *usb3)
int_sta_2 &= usb3_read(usb3, USB3_USB_INT_ENA_2);
if (int_sta_2)
usb3_irq_epc_int_2(usb3, int_sta_2);
+
+   otg_int_sta &= usb3_read(usb3, USB3_USB_OTG_INT_ENA);
+   if (otg_int_sta) {
+   usb3_write(usb3, otg_int_sta, USB3_USB_OTG_INT_STA);
+   usb3_irq_otg_int(usb3, otg_int_sta);
+   }
 }
 
 static irqreturn_t renesas_usb3_irq(int irq, void *_usb3)
-- 
1.9.1

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


[PATCH 4/4] usb: gadget: udc: renesas_usb3: add support for usb role swap

2017-03-28 Thread Yoshihiro Shimoda
This patch adds support for usb role swap via sysfs "role".

For example:
 1) Connect a usb cable using 2 Salvator-X boards.
  - For A-Device, the cable is connected to CN11 (USB3.0 ch0).
  - For B-Device, the cable is connected to CN9 (USB2.0 ch0).
 2) On A-Device, you input the following command:
  # echo peripheral > /sys/devices/platform/soc/ee02.usb/role
 3) On B-Device, you input the following command:
  # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Then, the A-Device acts as a peripheral and the B-Device acts as
a host. Please note that A-Device must input the following command
if you want the board to act as a host again.
 # echo host > /sys/devices/platform/soc/ee02.usb/role

Signed-off-by: Yoshihiro Shimoda 
---
 .../ABI/testing/sysfs-platform-renesas_usb3|  2 ++
 drivers/usb/gadget/udc/renesas_usb3.c  | 41 +-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-platform-renesas_usb3 
b/Documentation/ABI/testing/sysfs-platform-renesas_usb3
index f5dace7..1ab919c 100644
--- a/Documentation/ABI/testing/sysfs-platform-renesas_usb3
+++ b/Documentation/ABI/testing/sysfs-platform-renesas_usb3
@@ -7,6 +7,8 @@ Description:
The file can show/change the drd mode of usb.
 
Write the following string to change the mode:
+"host" - switching mode from peripheral to host.
+"peripheral" - switching mode from host to peripheral.
 "b-device" - switching mode as forced b-device mode.
 
Read the file, then it shows the following strings:
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 34ac03c..b552243 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -570,12 +570,29 @@ static void usb3_mode_a_host(struct renesas_usb3 *usb3)
usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
 }
 
+static void usb3_mode_a_peri(struct renesas_usb3 *usb3)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&usb3->lock, flags);
+   usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+   usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
+   usb3_check_vbus(usb3);
+   spin_unlock_irqrestore(&usb3->lock, flags);
+}
+
 static void usb3_mode_b_peri(struct renesas_usb3 *usb3)
 {
usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
 }
 
+static void usb3_mode_b_host(struct renesas_usb3 *usb3)
+{
+   usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+   usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
+}
+
 static bool usb3_is_a_device(struct renesas_usb3 *usb3)
 {
return !(usb3_read(usb3, USB3_USB_OTG_STA) & USB_OTG_IDMON);
@@ -1865,8 +1882,30 @@ static ssize_t role_store(struct device *dev, struct 
device_attribute *attr,
usb3->forced_b_device = true;
renesas_usb3_init_forced_b_device(usb3);
} else {
+   bool new_mode_is_host;
+
usb3->forced_b_device = false;
-   return -EINVAL;
+   if (!strncmp(buf, "host", strlen("host")))
+   new_mode_is_host = true;
+   else if (!strncmp(buf, "peripheral", strlen("peripheral")))
+   new_mode_is_host = false;
+   else
+   return -EINVAL;
+
+   if (new_mode_is_host == usb3_is_host(usb3))
+   return -EINVAL;
+
+   if (new_mode_is_host) {
+   if (usb3_is_a_device(usb3))
+   usb3_mode_a_host(usb3);
+   else
+   usb3_mode_b_host(usb3);
+   } else {
+   if (usb3_is_a_device(usb3))
+   usb3_mode_a_peri(usb3);
+   else
+   usb3_mode_b_peri(usb3);
+   }
}
 
return count;
-- 
1.9.1

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


[PATCH 0/4] usb: gadget: udc: renesas_usb3: add USB3.0 DRD support

2017-03-28 Thread Yoshihiro Shimoda
This patch set is based on the latest Felipe's usb.bit / testing/next branch
(commit id = 29986993f67341493988b6c5d68e0653061975b2).

The USB3.0 DRD controller on R-Car Gen3 can change the role via DRD_CON
register in the periperal side sadly, so this patch adds support
for usb role swap feature in this udc driver.
Furtunately, the default setting of the DRD is host side, if a user want
to use host side only, we can handle it easily just to disable the udc driver.

Yoshihiro Shimoda (4):
  usb: gadget: udc: renesas_usb3: add sysfs "role" to set "b-device"
mode
  usb: gadget: udc: add USB ID signal monitoring
  usb: gadget: udc: renesas_usb3: add extcon support
  usb: gadget: udc: renesas_usb3: add support for usb role swap

 .../ABI/testing/sysfs-platform-renesas_usb3|  17 ++
 drivers/usb/gadget/udc/Kconfig |   1 +
 drivers/usb/gadget/udc/renesas_usb3.c  | 201 -
 3 files changed, 214 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-renesas_usb3

-- 
1.9.1

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


[PATCH 3/4] usb: gadget: udc: renesas_usb3: add extcon support

2017-03-28 Thread Yoshihiro Shimoda
This patch adds extcon support to see VBUS/ID signal states.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/Kconfig|  1 +
 drivers/usb/gadget/udc/renesas_usb3.c | 43 +--
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 4b69f28..66cb00b 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -191,6 +191,7 @@ config USB_RENESAS_USBHS_UDC
 config USB_RENESAS_USB3
tristate 'Renesas USB3.0 Peripheral controller'
depends on ARCH_RENESAS || COMPILE_TEST
+   depends on EXTCON
help
   Renesas USB3.0 Peripheral controller is a USB peripheral controller
   that supports super, high, and full speed USB 3.0 data transfers.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index d81953b..34ac03c 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -263,6 +264,8 @@ struct renesas_usb3 {
 
struct usb_gadget gadget;
struct usb_gadget_driver *driver;
+   struct extcon_dev *extcon;
+   struct work_struct extcon_work;
 
struct renesas_usb3_ep *usb3_ep;
int num_usb3_eps;
@@ -276,6 +279,8 @@ struct renesas_usb3 {
bool softconnect;
bool workaround_for_vbus;
bool forced_b_device;
+   bool extcon_host;   /* check id  and set EXTCON_USB_HOST */
+   bool extcon_usb;/* check vbus and set EXTCON_USB */
 };
 
 #define gadget_to_renesas_usb3(_gadget)\
@@ -339,6 +344,15 @@ static int usb3_wait(struct renesas_usb3 *usb3, u32 reg, 
u32 mask,
return -EBUSY;
 }
 
+static void renesas_usb3_extcon_work(struct work_struct *work)
+{
+   struct renesas_usb3 *usb3 = container_of(work, struct renesas_usb3,
+extcon_work);
+
+   extcon_set_state_sync(usb3->extcon, EXTCON_USB_HOST, usb3->extcon_host);
+   extcon_set_state_sync(usb3->extcon, EXTCON_USB, usb3->extcon_usb);
+}
+
 static void usb3_enable_irq_1(struct renesas_usb3 *usb3, u32 bits)
 {
usb3_set_bit(usb3, bits, USB3_USB_INT_ENA_1);
@@ -539,10 +553,14 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
if (usb3->workaround_for_vbus) {
usb3_connect(usb3);
} else {
-   if (usb3_read(usb3, USB3_USB_STA) & USB_STA_VBUS_STA)
+   usb3->extcon_usb = !!(usb3_read(usb3, USB3_USB_STA) &
+   USB_STA_VBUS_STA);
+   if (usb3->extcon_usb)
usb3_connect(usb3);
else
usb3_disconnect(usb3);
+
+   schedule_work(&usb3->extcon_work);
}
 }
 
@@ -565,10 +583,14 @@ static bool usb3_is_a_device(struct renesas_usb3 *usb3)
 
 static void usb3_check_id(struct renesas_usb3 *usb3)
 {
-   if (usb3_is_a_device(usb3) && !usb3->forced_b_device)
+   usb3->extcon_host = usb3_is_a_device(usb3);
+
+   if (usb3->extcon_host && !usb3->forced_b_device)
usb3_mode_a_host(usb3);
else
usb3_mode_b_peri(usb3);
+
+   schedule_work(&usb3->extcon_work);
 }
 
 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3)
@@ -2000,6 +2022,12 @@ static void renesas_usb3_init_ram(struct renesas_usb3 
*usb3, struct device *dev,
 };
 MODULE_DEVICE_TABLE(of, usb3_of_match);
 
+static const unsigned int renesas_usb3_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
 static int renesas_usb3_probe(struct platform_device *pdev)
 {
struct renesas_usb3 *usb3;
@@ -2043,6 +2071,17 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
if (ret < 0)
return ret;
 
+   INIT_WORK(&usb3->extcon_work, renesas_usb3_extcon_work);
+   usb3->extcon = devm_extcon_dev_allocate(&pdev->dev, renesas_usb3_cable);
+   if (IS_ERR(usb3->extcon))
+   return PTR_ERR(usb3->extcon);
+
+   ret = devm_extcon_dev_register(&pdev->dev, usb3->extcon);
+   if (ret < 0) {
+   dev_err(&pdev->dev, "Failed to register extcon\n");
+   return ret;
+   }
+
/* for ep0 handling */
usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL);
if (!usb3->ep0_req)
-- 
1.9.1

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


[PATCH 1/4] usb: gadget: udc: renesas_usb3: add sysfs "role" to set "b-device" mode

2017-03-28 Thread Yoshihiro Shimoda
Sadly, to change the role ("host" and "peripheral") of USB3.0 DRD
controller on R-Car Gen3, software has to set the DRD_CON register
which is included in a usb3.0 peripheral controler's register.
To simply implementation, the previous code always set peripheral mode
as hardcoded. However, to support usb role swap in the future,
the hardcoded is not good. So, this patch adds sysfs "role" to set
the mode by a user.
After applied this patch, since the DRD controller will act as host
mode after probed, a user needs to change the mode via the sysfs.

Signed-off-by: Yoshihiro Shimoda 
---
 .../ABI/testing/sysfs-platform-renesas_usb3| 15 +
 drivers/usb/gadget/udc/renesas_usb3.c  | 74 --
 2 files changed, 85 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-renesas_usb3

diff --git a/Documentation/ABI/testing/sysfs-platform-renesas_usb3 
b/Documentation/ABI/testing/sysfs-platform-renesas_usb3
new file mode 100644
index 000..f5dace7
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-renesas_usb3
@@ -0,0 +1,15 @@
+What:  /sys/devices/platform//role
+Date:  March 2017
+KernelVersion: 4.13
+Contact:   Yoshihiro Shimoda 
+Description:
+   This file can be read and write.
+   The file can show/change the drd mode of usb.
+
+   Write the following string to change the mode:
+"b-device" - switching mode as forced b-device mode.
+
+   Read the file, then it shows the following strings:
+"host" - The mode is host now.
+"peripheral" - The mode is peripheral now.
+"b-device" - The mode is forced b-device (b-peripheral) now.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 2218f91..4029593 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -269,6 +269,7 @@ struct renesas_usb3 {
u8 ep0_buf[USB3_EP0_BUF_SIZE];
bool softconnect;
bool workaround_for_vbus;
+   bool forced_b_device;
 };
 
 #define gadget_to_renesas_usb3(_gadget)\
@@ -352,6 +353,11 @@ static void usb3_disable_pipe_irq(struct renesas_usb3 
*usb3, int num)
usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2);
 }
 
+static bool usb3_is_host(struct renesas_usb3 *usb3)
+{
+   return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON);
+}
+
 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
 {
/* Set AXI_INT */
@@ -362,10 +368,6 @@ static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
 
 static void usb3_init_epc_registers(struct renesas_usb3 *usb3)
 {
-   /* FIXME: How to change host / peripheral mode as well? */
-   usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
-   usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
-
usb3_write(usb3, ~0, USB3_USB_INT_STA_1);
usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG);
 }
@@ -538,6 +540,12 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
}
 }
 
+static void usb3_mode_b_peri(struct renesas_usb3 *usb3)
+{
+   usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+   usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON);
+}
+
 static void renesas_usb3_init_controller(struct renesas_usb3 *usb3)
 {
usb3_init_axi_bridge(usb3);
@@ -556,6 +564,16 @@ static void renesas_usb3_stop_controller(struct 
renesas_usb3 *usb3)
usb3_write(usb3, 0, USB3_AXI_INT_ENA);
 }
 
+static void renesas_usb3_init_forced_b_device(struct renesas_usb3 *usb3)
+{
+   unsigned long flags;
+
+   spin_lock_irqsave(&usb3->lock, flags);
+   usb3_mode_b_peri(usb3);
+   renesas_usb3_init_controller(usb3);
+   spin_unlock_irqrestore(&usb3->lock, flags);
+}
+
 static void usb3_irq_epc_int_1_pll_wakeup(struct renesas_usb3 *usb3)
 {
usb3_disable_irq_1(usb3, USB_INT_1_B3_PLLWKUP);
@@ -1756,6 +1774,47 @@ static int renesas_usb3_set_selfpowered(struct 
usb_gadget *gadget, int is_self)
.set_selfpowered= renesas_usb3_set_selfpowered,
 };
 
+static const char *usb3_get_role_string(struct renesas_usb3 *usb3)
+{
+   if (usb3->forced_b_device)
+   return "b-device";
+   else if (usb3_is_host(usb3))
+   return "host";
+   else
+   return "peripheral";
+}
+
+static ssize_t role_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+   struct renesas_usb3 *usb3 = dev_get_drvdata(dev);
+
+   if (!usb3->driver)
+   return -ENODEV;
+
+   if (!strncmp(buf, "b-device", strlen("b-device"))) {
+   usb3->forced_b_device = true;
+   renesas_usb3_init_forced_b_device(usb3);
+   } else {
+   usb3->forced_b_device = false;
+   return -EINVAL;
+   }
+
+   return count;
+}
+
+static ssize_t role_show(struct

Re: [PATCH 1/4] usb: gadget: udc: renesas_usb3: add sysfs "role" to set "b-device" mode

2017-03-28 Thread Felipe Balbi

Hi,

Yoshihiro Shimoda  writes:
> Sadly, to change the role ("host" and "peripheral") of USB3.0 DRD
> controller on R-Car Gen3, software has to set the DRD_CON register
> which is included in a usb3.0 peripheral controler's register.
> To simply implementation, the previous code always set peripheral mode
> as hardcoded. However, to support usb role swap in the future,
> the hardcoded is not good. So, this patch adds sysfs "role" to set
> the mode by a user.
> After applied this patch, since the DRD controller will act as host
> mode after probed, a user needs to change the mode via the sysfs.
>
> Signed-off-by: Yoshihiro Shimoda 

in patch 3, you add extcon to monitor ID and VBUS pins. Do you really
need this sysfs file at all?

-- 
balbi
--
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 v4] USB: Proper handling of Race Condition when two USB class drivers try to call init_usb_class simultaneously

2017-03-28 Thread Ajay Kaher
Greg, sending patch again using git send-email, please apply.
Let me know if still any issue.

There is race condition when two USB class drivers try to call
init_usb_class at the same time and leads to crash.
code path: probe->usb_register_dev->init_usb_class

To solve this, mutex locking has been added in init_usb_class() and
destroy_usb_class().

As pointed by Alan, removed "if (usb_class)" test from destroy_usb_class()
because usb_class can never be NULL there.

Signed-off-by: Ajay Kaher 
Acked-by: Alan Stern 
---
 drivers/usb/core/file.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 822ced9..422ce7b 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -27,6 +27,7 @@
 #define MAX_USB_MINORS 256
 static const struct file_operations *usb_minors[MAX_USB_MINORS];
 static DECLARE_RWSEM(minor_rwsem);
+static DEFINE_MUTEX(init_usb_class_mutex);
 
 static int usb_open(struct inode *inode, struct file *file)
 {
@@ -109,8 +110,9 @@ static void release_usb_class(struct kref *kref)
 
 static void destroy_usb_class(void)
 {
-   if (usb_class)
-   kref_put(&usb_class->kref, release_usb_class);
+   mutex_lock(&init_usb_class_mutex);
+   kref_put(&usb_class->kref, release_usb_class);
+   mutex_unlock(&init_usb_class_mutex);
 }
 
 int usb_major_init(void)
@@ -171,7 +173,10 @@ int usb_register_dev(struct usb_interface *intf,
if (intf->minor >= 0)
return -EADDRINUSE;
 
+   mutex_lock(&init_usb_class_mutex);
retval = init_usb_class();
+   mutex_unlock(&init_usb_class_mutex);
+
if (retval)
return retval;
 
-- 
2.7.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


[PATCH] usb: gadget: pch_udc: don't update td->next after it has been released to the pool

2017-03-28 Thread Colin King
From: Colin Ian King 

Writing to td->next should be avoided after td has been freed using
dma_pool_free. The intent was to nullify the next pointer, but this
is potentially dangerous once it is back in the pool. Remove it.

Detected by CoverityScan, CID#1091173 ("Write tp pointer after free")

Signed-off-by: Colin Ian King 
---
 drivers/usb/gadget/udc/pch_udc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/pch_udc.c b/drivers/usb/gadget/udc/pch_udc.c
index 84dcbcd756f0..08bbe2c24134 100644
--- a/drivers/usb/gadget/udc/pch_udc.c
+++ b/drivers/usb/gadget/udc/pch_udc.c
@@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev 
*dev,
td = phys_to_virt(addr);
addr2 = (dma_addr_t)td->next;
dma_pool_free(dev->data_requests, td, addr);
-   td->next = 0x00;
addr = addr2;
}
req->chain_len = 1;
-- 
2.11.0

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


Re: [PATCH] usb: gadget: pch_udc: don't update td->next after it has been released to the pool

2017-03-28 Thread Colin Ian King
On 28/03/17 13:51, Felipe Balbi wrote:
> 
> Hi,
> 
> Colin King  writes:
>> From: Colin Ian King 
>>
>> Writing to td->next should be avoided after td has been freed using
>> dma_pool_free. The intent was to nullify the next pointer, but this
>> is potentially dangerous once it is back in the pool. Remove it.
>>
>> Detected by CoverityScan, CID#1091173 ("Write tp pointer after free")
>>
>> Signed-off-by: Colin Ian King 
>> ---
>>  drivers/usb/gadget/udc/pch_udc.c | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/drivers/usb/gadget/udc/pch_udc.c 
>> b/drivers/usb/gadget/udc/pch_udc.c
>> index 84dcbcd756f0..08bbe2c24134 100644
>> --- a/drivers/usb/gadget/udc/pch_udc.c
>> +++ b/drivers/usb/gadget/udc/pch_udc.c
>> @@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev 
>> *dev,
>>  td = phys_to_virt(addr);
>>  addr2 = (dma_addr_t)td->next;
>>  dma_pool_free(dev->data_requests, td, addr);
>> -td->next = 0x00;
> 
> I already have a patch for this, thanks

Ah, I somehow overlooked that. Good to see it is fixed.

Colin

> 
> 1f459262b0e1649a1e5ad12fa4c66eb76c2220ce
> Author: Gustavo A. R. Silva 
> AuthorDate: Fri Mar 10 15:39:32 2017 -0600
> Commit: Felipe Balbi 
> CommitDate: Wed Mar 22 11:21:10 2017 +0200
> 
> usb: gadget: udc: remove pointer dereference after free
> 
> Remove pointer dereference after free.
> 
> Addresses-Coverity-ID: 1091173
> Acked-by: Michal Nazarewicz 
> Signed-off-by: Gustavo A. R. Silva 
> Signed-off-by: Felipe Balbi 
> 
> 1 file changed, 1 deletion(-)
> drivers/usb/gadget/udc/pch_udc.c | 1 -
> 
> modified   drivers/usb/gadget/udc/pch_udc.c
> @@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev 
> *dev,
>   td = phys_to_virt(addr);
>   addr2 = (dma_addr_t)td->next;
>   pci_pool_free(dev->data_requests, td, addr);
> - td->next = 0x00;
>   addr = addr2;
>   }
>   req->chain_len = 1;
> 

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


[PATCH v3 0/3] xhci fixes for usb-linus

2017-03-28 Thread Mathias Nyman
Hi Greg

Third version
A few more xhci fixes for usb-linus 4.11-rc

Most important is the URB dequeue fix that resolves a hang on resume
reported by Diego Viola on his DELL Inspiron 5558.

v3:
 - make patch 2/3 very targeted and only fix the missing case of how we
   handle  control transfers stopped at status stage.
 - Clean up commit messages

v2:
 -  Don't add extra blank line, and Fix tranfer -> transfer typos

Adam Wallis (1):
  xhci: plat: Register shutdown for xhci_plat

Mathias Nyman (2):
  xhci: Set URB actual length for stopped control transfers
  xhci: Manually give back cancelled URB if we can't queue it for cancel

 drivers/usb/host/xhci-plat.c |  1 +
 drivers/usb/host/xhci-ring.c |  3 +++
 drivers/usb/host/xhci.c  | 43 +--
 3 files changed, 29 insertions(+), 18 deletions(-)

-- 
1.9.1

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


Re: [PATCH] usb: gadget: pch_udc: don't update td->next after it has been released to the pool

2017-03-28 Thread Felipe Balbi

Hi,

Colin King  writes:
> From: Colin Ian King 
>
> Writing to td->next should be avoided after td has been freed using
> dma_pool_free. The intent was to nullify the next pointer, but this
> is potentially dangerous once it is back in the pool. Remove it.
>
> Detected by CoverityScan, CID#1091173 ("Write tp pointer after free")
>
> Signed-off-by: Colin Ian King 
> ---
>  drivers/usb/gadget/udc/pch_udc.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/udc/pch_udc.c 
> b/drivers/usb/gadget/udc/pch_udc.c
> index 84dcbcd756f0..08bbe2c24134 100644
> --- a/drivers/usb/gadget/udc/pch_udc.c
> +++ b/drivers/usb/gadget/udc/pch_udc.c
> @@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev 
> *dev,
>   td = phys_to_virt(addr);
>   addr2 = (dma_addr_t)td->next;
>   dma_pool_free(dev->data_requests, td, addr);
> - td->next = 0x00;

I already have a patch for this, thanks

1f459262b0e1649a1e5ad12fa4c66eb76c2220ce
Author: Gustavo A. R. Silva 
AuthorDate: Fri Mar 10 15:39:32 2017 -0600
Commit: Felipe Balbi 
CommitDate: Wed Mar 22 11:21:10 2017 +0200

usb: gadget: udc: remove pointer dereference after free

Remove pointer dereference after free.

Addresses-Coverity-ID: 1091173
Acked-by: Michal Nazarewicz 
Signed-off-by: Gustavo A. R. Silva 
Signed-off-by: Felipe Balbi 

1 file changed, 1 deletion(-)
drivers/usb/gadget/udc/pch_udc.c | 1 -

modified   drivers/usb/gadget/udc/pch_udc.c
@@ -1523,7 +1523,6 @@ static void pch_udc_free_dma_chain(struct pch_udc_dev 
*dev,
td = phys_to_virt(addr);
addr2 = (dma_addr_t)td->next;
pci_pool_free(dev->data_requests, td, addr);
-   td->next = 0x00;
addr = addr2;
}
req->chain_len = 1;

-- 
balbi
--
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 v3 2/3] xhci: Set URB actual length for stopped control transfers

2017-03-28 Thread Mathias Nyman
A control transfer that stopped at the status stage incorrectly
warned about a "unexpected TRB Type 4", and did not set the
transferred actual_length for the URB.

The URB actual_length for control transfers should contain the
bytes transferred in the data stage.

Bytes of a partially sent setup stage and missing bytes from
status stage should be left out.

Cc: 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-ring.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index d9936c7..a3309aa 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1989,6 +1989,9 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct 
xhci_td *td,
case TRB_NORMAL:
td->urb->actual_length = requested - remaining;
goto finish_td;
+   case TRB_STATUS:
+   td->urb->actual_length = requested;
+   goto finish_td;
default:
xhci_warn(xhci, "WARN: unexpected TRB Type %d\n",
  trb_type);
-- 
1.9.1

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


[PATCH v3 1/3] xhci: plat: Register shutdown for xhci_plat

2017-03-28 Thread Mathias Nyman
From: Adam Wallis 

Shutdown should be called for xhci_plat devices especially for
situations where kexec might be used by stopping DMA
transactions.

Signed-off-by: Adam Wallis 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-plat.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index bd02a6c..6ed468f 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -344,6 +344,7 @@ static int xhci_plat_resume(struct device *dev)
 static struct platform_driver usb_xhci_driver = {
.probe  = xhci_plat_probe,
.remove = xhci_plat_remove,
+   .shutdown   = usb_hcd_platform_shutdown,
.driver = {
.name = "xhci-hcd",
.pm = DEV_PM_OPS,
-- 
1.9.1

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


[PATCH v3 3/3] xhci: Manually give back cancelled URB if we can't queue it for cancel

2017-03-28 Thread Mathias Nyman
xhci needs to take care of four scenarios when asked to cancel a URB.

1 URB is not queued or already given back.
  usb_hcd_check_unlink_urb() will return an error, we pass the error on

2 We fail to find xhci internal structures from urb private data such as
  virtual device and endpoint ring.
  Give back URB immediately, can't do anything about internal structures.

3 URB private data has valid pointers to xhci internal data, but host is
  not  responding.
  give back URB immedately and remove the URB from the endpoint lists.

4 Everyting is working
  add URB to cancel list, queue a command to stop the endpoint, after
  which the URB can be turned to no-op or skipped, removed from lists,
  and given back.

We failed to give back the urb in case 2 where the correct device and
endpoint pointers could not be retrieved from URB private data.

This caused a hang on Dell Inspiron 5558/0VNM2T at resume from suspend
as urb was never returned.

[  245.270505] INFO: task rtsx_usb_ms_1:254 blocked for more than 120 seconds.
[  245.272244]   Tainted: GW   4.11.0-rc3-ARCH #2
[  245.273983] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this 
message.
[  245.275737] rtsx_usb_ms_1   D0   254  2 0x
[  245.277524] Call Trace:
[  245.279278]  __schedule+0x2d3/0x8a0
[  245.281077]  schedule+0x3d/0x90
[  245.281961]  usb_kill_urb.part.3+0x6c/0xa0 [usbcore]
[  245.282861]  ? wake_atomic_t_function+0x60/0x60
[  245.283760]  usb_kill_urb+0x21/0x30 [usbcore]
[  245.284649]  usb_start_wait_urb+0xe5/0x170 [usbcore]
[  245.285541]  ? try_to_del_timer_sync+0x53/0x80
[  245.286434]  usb_bulk_msg+0xbd/0x160 [usbcore]
[  245.287326]  rtsx_usb_send_cmd+0x63/0x90 [rtsx_usb]

Reported-by: diego.vi...@gmail.com
Tested-by: diego.vi...@gmail.com
Cc: sta...@vger.kernel.org
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci.c | 43 +--
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 50aee8b..953fd8f 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1477,6 +1477,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb 
*urb, int status)
struct xhci_ring *ep_ring;
struct xhci_virt_ep *ep;
struct xhci_command *command;
+   struct xhci_virt_device *vdev;
 
xhci = hcd_to_xhci(hcd);
spin_lock_irqsave(&xhci->lock, flags);
@@ -1485,15 +1486,27 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb 
*urb, int status)
 
/* Make sure the URB hasn't completed or been unlinked already */
ret = usb_hcd_check_unlink_urb(hcd, urb, status);
-   if (ret || !urb->hcpriv)
+   if (ret)
goto done;
+
+   /* give back URB now if we can't queue it for cancel */
+   vdev = xhci->devs[urb->dev->slot_id];
+   urb_priv = urb->hcpriv;
+   if (!vdev || !urb_priv)
+   goto err_giveback;
+
+   ep_index = xhci_get_endpoint_index(&urb->ep->desc);
+   ep = &vdev->eps[ep_index];
+   ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
+   if (!ep || !ep_ring)
+   goto err_giveback;
+
temp = readl(&xhci->op_regs->status);
if (temp == 0x || (xhci->xhc_state & XHCI_STATE_HALTED)) {
xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
"HW died, freeing TD.");
-   urb_priv = urb->hcpriv;
for (i = urb_priv->num_tds_done;
-i < urb_priv->num_tds && xhci->devs[urb->dev->slot_id];
+i < urb_priv->num_tds;
 i++) {
td = &urb_priv->td[i];
if (!list_empty(&td->td_list))
@@ -1501,23 +1514,9 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb 
*urb, int status)
if (!list_empty(&td->cancelled_td_list))
list_del_init(&td->cancelled_td_list);
}
-
-   usb_hcd_unlink_urb_from_ep(hcd, urb);
-   spin_unlock_irqrestore(&xhci->lock, flags);
-   usb_hcd_giveback_urb(hcd, urb, -ESHUTDOWN);
-   xhci_urb_free_priv(urb_priv);
-   return ret;
+   goto err_giveback;
}
 
-   ep_index = xhci_get_endpoint_index(&urb->ep->desc);
-   ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index];
-   ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
-   if (!ep_ring) {
-   ret = -EINVAL;
-   goto done;
-   }
-
-   urb_priv = urb->hcpriv;
i = urb_priv->num_tds_done;
if (i < urb_priv->num_tds)
xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
@@ -1554,6 +1553,14 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb 
*urb, int status)
 done:
spin_unlock_irqrestore(&xhci->lock, flags);
return ret;
+
+err_giveback:
+   if (urb_priv)
+   xhci_urb_free_priv(ur

Re: USB device disconnect after suspend/resume

2017-03-28 Thread Stephan Müller
Am Dienstag, 28. März 2017, 03:12:44 CEST schrieb Peter Chen:

Hi Peter,

> Do you have debug information from USB core (not only USB storage)? It
> may show why it is disconnected from low level.

The device is question is at port 2-3.

usb core dyndbg:

[   72.546341] Restarting tasks ... 
[   72.546465] hub 1-0:1.0: state 7 ports 11 chg  evt 0028
[   72.546595] hub 2-0:1.0: state 7 ports 4 chg 0008 evt 
[   72.546662] usb usb2-port3: status 0263, change , 5.0 Gb/s
[   72.546670] usb 2-3: USB disconnect, device number 2
[   72.546675] usb 2-3: unregistering device
[   72.546682] usb 2-3: unregistering interface 2-3:1.0
[   72.552689] done.
[   72.553977] brcmfmac :03:00.0: Direct firmware load for brcm/
brcmfmac43602-pcie.txt failed with error -2
[   72.676148] usb 2-3: usb_disable_device nuking all URBs
[   72.727915] usb usb2-port3: not reset yet, waiting 50ms
[   72.780009] usb usb2-port3: not reset yet, waiting 200ms
[   72.985875] usb usb2-port3: not reset yet, waiting 200ms
[   73.063770] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Nov 10 
2015 06:38:10 version 7.35.177.61 (r598657) FWID 01-ea662a8c
[   73.096915] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code (0x30 
0x30)
[   73.122551] brcmfmac :03:00.0 wlp3s0: renamed from wlan0
[   73.140131] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
[   73.193919] usb usb2-port3: not reset yet, waiting 200ms
[   73.402026] usb usb2-port3: hot reset failed, warm reset
[   73.402028] usb usb2-port3: not enabled, trying warm reset again...
[   73.609968] usb usb2-port3: not warm reset yet, waiting 200ms
[   73.817946] usb usb2-port3: not warm reset yet, waiting 200ms
[   74.026100] usb usb2-port3: not warm reset yet, waiting 200ms
[   74.234126] usb usb2-port3: not warm reset yet, waiting 200ms
[   74.234167] usb usb2-port3: not enabled, trying warm reset again...
[   74.441910] usb usb2-port3: not warm reset yet, waiting 200ms
[   74.649894] usb usb2-port3: not warm reset yet, waiting 200ms
[   74.857981] usb usb2-port3: not warm reset yet, waiting 200ms
[   75.066006] usb usb2-port3: not warm reset yet, waiting 200ms
[   75.066040] xhci_hcd :00:14.0: Cannot set link state.
[   75.066045] usb usb2-port3: cannot disable (err = -32)
[   75.066065] xhci_hcd :00:14.0: Cannot set link state.
[   75.066069] usb usb2-port3: cannot disable (err = -32)
[   75.066079] hub 2-0:1.0: state 7 ports 4 chg  evt 0008
[   75.066130] hub 2-0:1.0: hub_suspend
[   75.066140] usb usb2: bus auto-suspend, wakeup 1


xhci dyndbg (I hope I have copied the right logs):

[  219.110425] xhci_hcd :00:14.0: Cancel URB 8c1678bf7a80, dev 3, ep 
0x0, starting at offset 0x44f3eb390
[  219.110438] xhci_hcd :00:14.0: // Ding dong!
[  219.110519] xhci_hcd :00:14.0: Stopped on Transfer TRB
[  219.110525] xhci_hcd :00:14.0: WARN: unexpected TRB Type 4
[  219.110532] xhci_hcd :00:14.0: Removing canceled TD starting at 
0x44f3eb390 (dma).
[  219.110534] xhci_hcd :00:14.0: Finding endpoint context
[  219.110537] xhci_hcd :00:14.0: Cycle state = 0x1
[  219.110540] xhci_hcd :00:14.0: New dequeue segment = 8c16cec66a40 
(virtual)
[  219.110542] xhci_hcd :00:14.0: New dequeue pointer = 0x44f3eb3b0 (DMA)
[  219.110547] xhci_hcd :00:14.0: Set TR Deq Ptr cmd, new deq seg = 
8c16cec66a40 (0x44f3eb000 dma), new deq ptr = 8c16cf3eb3b0 
(0x44f3eb3b0 dma), new cycle = 1
[  219.110550] xhci_hcd :00:14.0: // Ding dong!
[  219.110570] xhci_hcd :00:14.0: Successful Set TR Deq Ptr cmd, deq = 
@44f3eb3b0
[  219.110613] xhci_hcd :00:14.0: disable port 3 USB2 hardware LPM
[  219.110620] xhci_hcd :00:14.0: Set up evaluate context for LPM MEL 
change.
[  219.110623] xhci_hcd :00:14.0: Slot 2 Input Context:
...
[  219.110698] xhci_hcd :00:14.0: // Ding dong!
[  219.110851] xhci_hcd :00:14.0: Successful evaluate context command
[  219.110855] xhci_hcd :00:14.0: Slot 2 Output Context:
...
[  219.113759] xhci_hcd :00:14.0: Port Status Change Event for port 3
[  219.113767] xhci_hcd :00:14.0: handle_port_status: starting port 
polling.
[  219.113779] xhci_hcd :00:14.0: xhci_hub_status_data: stopping port 
polling.
[  219.122345] xhci_hcd :00:14.0: // Ding dong!
[  219.122436] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
[  219.122441] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
[  219.122444] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
[  219.122448] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
[  219.146522] xhci_hcd :00:14.0: xhci_suspend: stopping port polling.

--- suspended ---

[  228.110972] Restarting tasks ...
[  228.129044] xhci_hcd :00:14.0: ep 0x81 - asked for 16 bytes, 10 bytes 
untransferred
[  228.129949] xhci_hcd :00:14.0: get port status, actual port 2 status  = 
0x603
[  228.129951] xhci_hcd :00:14.0: Get port status returned 0x103
[  228.129962] xhci_hcd :00:14.0: get port status, actual port 2 

Re: [PATCH v5 1/5] usb: dwc2: Add support for STM32F429/439/469 USB OTG HS/FS in FS mode (internal PHY)

2017-03-28 Thread Felipe Balbi

Hi,

Alexandre Torgue  writes:
> Hi John,
>
> On 02/01/2017 04:37 AM, John Youn wrote:
>> On 1/31/2017 5:26 PM, Bruno Herrera wrote:
>>> This patch introduces a new parameter to activate USB OTG HS/FS core
>>> embedded phy transceiver. The STM32F4x9 SoC uses the GGPIO register
>>> to enable the transceiver.
>>> Also add the dwc2_set_params function for stm32f4 otg fs.
>>>
>>> Signed-off-by: Bruno Herrera 
>>
>> Acked-by: John Youn 
>>
> Do you plan to take those patches on your pull-request for 4.12?
> I was wondering if I take machine parts (DT) in my pull request for 4.12 
> or if I wait an official version with driver part merged.

patches already in my queue for v4.12

-- 
balbi
--
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 1/2] usb: phy: Introduce one extcon device into usb phy

2017-03-28 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> Usually usb phy need register one extcon device to get the connection
> notifications. It will remove some duplicate code if the extcon device
> is registered using common code instead of each phy driver having its
> own related extcon APIs. So we add one pointer of extcon device into
> usb phy structure, and some other helper functions to register extcon.
>
> Suggested-by: NeilBrown 
> Signed-off-by: Baolin Wang 

will this work with devices which have ID and VBUS from separate EXTCON
devices?

-- 
balbi
--
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 2/2] usb: phy: phy-qcom-8x16-usb: Remove redundant extcon register/unregister

2017-03-28 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> Since usb phy core has added common code to register or unregister
> extcon device, then phy-qcom-8x16-usb driver does not need its own
> code to register/unregister extcon device, then remove them.
>
> Signed-off-by: Baolin Wang 

so previous patch helped *ONE* single user? Was it really beneficial if
it's all for a single user? Which duplicated code did it remove?

-- 
balbi
--
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: musb: fix possible spinlock deadlock

2017-03-28 Thread Bin Liu
commit bc1e2154542071e3cfe1734b143af9b8bdacf8bd upstream.

The DSPS glue calls del_timer_sync() in its musb_platform_disable()
implementation, which requires the caller to not hold a lock. But
musb_remove() calls musb_platform_disable() will musb->lock held. This
could causes spinlock deadlock.

So change musb_remove() to call musb_platform_disable() without holds
musb->lock. This doesn't impact the musb_platform_disable implementation
in other glue drivers.

root@am335x-evm:~# modprobe -r musb-dsps
[  126.134879] musb-hdrc musb-hdrc.1: remove, state 1
[  126.140465] usb usb2: USB disconnect, device number 1
[  126.146178] usb 2-1: USB disconnect, device number 2
[  126.416985] musb-hdrc musb-hdrc.1: USB bus 2 deregistered
[  126.423943]
[  126.425525] ==
[  126.431997] [ INFO: possible circular locking dependency detected ]
[  126.438564] 4.11.0-rc1-3-g1557f13bca04-dirty #77 Not tainted
[  126.444852] ---
[  126.451414] modprobe/778 is trying to acquire lock:
[  126.456523]  (((&glue->timer))){+.-...}, at: [] 
del_timer_sync+0x0/0xd0
[  126.464403]
[  126.464403] but task is already holding lock:
[  126.470511]  (&(&musb->lock)->rlock){-.-...}, at: [] 
musb_remove+0x50/0x1
30 [musb_hdrc]
[  126.479965]
[  126.479965] which lock already depends on the new lock.
[  126.479965]
[  126.488531]
[  126.488531] the existing dependency chain (in reverse order) is:
[  126.496368]
[  126.496368] -> #1 (&(&musb->lock)->rlock){-.-...}:
[  126.502968]otg_timer+0x80/0xec [musb_dsps]
[  126.507990]call_timer_fn+0xb4/0x390
[  126.512372]expire_timers+0xf0/0x1fc
[  126.516754]run_timer_softirq+0x80/0x178
[  126.521511]__do_softirq+0xc4/0x554
[  126.525802]irq_exit+0xe8/0x158
[  126.529735]__handle_domain_irq+0x58/0xb8
[  126.534583]__irq_usr+0x54/0x80
[  126.538507]
[  126.538507] -> #0 (((&glue->timer))){+.-...}:
[  126.544636]del_timer_sync+0x40/0xd0
[  126.549066]musb_remove+0x6c/0x130 [musb_hdrc]
[  126.554370]platform_drv_remove+0x24/0x3c
[  126.559206]device_release_driver_internal+0x14c/0x1e0
[  126.565225]bus_remove_device+0xd8/0x108
[  126.569970]device_del+0x1e4/0x308
[  126.574170]platform_device_del+0x24/0x8c
[  126.579006]platform_device_unregister+0xc/0x20
[  126.584394]dsps_remove+0x14/0x30 [musb_dsps]
[  126.589595]platform_drv_remove+0x24/0x3c
[  126.594432]device_release_driver_internal+0x14c/0x1e0
[  126.600450]driver_detach+0x38/0x6c
[  126.604740]bus_remove_driver+0x4c/0xa0
[  126.609407]SyS_delete_module+0x11c/0x1e4
[  126.614252]__sys_trace_return+0x0/0x10

Fixes: ea2f35c01d5ea ("usb: musb: Fix sleeping function called from invalid 
context for hdrc glue")
Cc:  #4.9+
Acked-by: Tony Lindgren 
Signed-off-by: Bin Liu 
Signed-off-by: Greg Kroah-Hartman 

Conflicts:
drivers/usb/musb/musb_core.c
---
 drivers/usb/musb/musb_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 1ffd8f89d59d..a3f3ff71b353 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2497,8 +2497,8 @@ static int musb_remove(struct platform_device *pdev)
pm_runtime_get_sync(musb->controller);
musb_host_cleanup(musb);
musb_gadget_cleanup(musb);
-   spin_lock_irqsave(&musb->lock, flags);
musb_platform_disable(musb);
+   spin_lock_irqsave(&musb->lock, flags);
musb_generic_disable(musb);
spin_unlock_irqrestore(&musb->lock, flags);
musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
-- 
1.9.1

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


Re: [PATCH v3 2/2] usb: gadget: reword configuration choices

2017-03-28 Thread Felipe Balbi

Hi,

Randy Dunlap  writes:
>> @@ -477,6 +477,12 @@ choice
>>not be able work with that controller, or might need to implement
>>a less common variant of a device class protocol.
>>  
>> +  The available choices each represent a single precomposed USB
>> +  gadget configuration. In the device model, each option contains
>> +  both the device instanciation as a child for a USB gadget
>
> instantiation

fixed locally, thanks

-- 
balbi
--
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/5] usb: dwc2: Add support for STM32F429/439/469 USB OTG HS/FS in FS mode (internal PHY)

2017-03-28 Thread Alexandre Torgue



On 03/28/2017 03:36 PM, Felipe Balbi wrote:


Hi,

Alexandre Torgue  writes:

Hi John,

On 02/01/2017 04:37 AM, John Youn wrote:

On 1/31/2017 5:26 PM, Bruno Herrera wrote:

This patch introduces a new parameter to activate USB OTG HS/FS core
embedded phy transceiver. The STM32F4x9 SoC uses the GGPIO register
to enable the transceiver.
Also add the dwc2_set_params function for stm32f4 otg fs.

Signed-off-by: Bruno Herrera 


Acked-by: John Youn 


Do you plan to take those patches on your pull-request for 4.12?
I was wondering if I take machine parts (DT) in my pull request for 4.12
or if I wait an official version with driver part merged.


patches already in my queue for v4.12


Thanks for info.

Regards
Alex




--
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 2/2] usb: dwc2: add multiple clocks handling

2017-03-28 Thread Felipe Balbi

Hi,

Heiko Stübner  writes:
> Am Donnerstag, 9. Februar 2017, 10:44:39 CET schrieb Frank Wang:
>> Since dwc2 may have one or more input clocks need to manage for some
>> platform, so this adds change clk to clk's array of struct dwc2_hsotg
>> to handle more clocks operation.
>> 
>> Signed-off-by: Frank Wang 
>
> for the simple clock handling the dwc2-driver does right now, this looks 
> adquate and honoring EPROBE_DEFER is a nice touch ;-), so
>
> Reviewed-by: Heiko Stuebner 

John, care to look at this series?

-- 
balbi
--
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] usb: phy: isp1301: Add OF device ID table

2017-03-28 Thread Felipe Balbi

Hi,

Javier Martinez Canillas  writes:
> The driver doesn't have a struct of_device_id table but supported devices
> are registered via Device Trees. This is working on the assumption that a
> I2C device registered via OF will always match a legacy I2C device ID and
> that the MODALIAS reported will always be of the form i2c:.
>
> But this could change in the future so the correct approach is to have an
> OF device ID table if the devices are registered via OF.
>
> Signed-off-by: Javier Martinez Canillas 

this is already upstream. Care to send an incremental diff in case we
need this fixed further?

-- 
balbi
--
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: gadget: uvc: Missing files for configfs interface

2017-03-28 Thread Felipe Balbi

Hi,

Petr Cvek  writes:
> Dne 7.3.2017 v 06:58 Laurent Pinchart napsal(a):
>> Hi Petr,
>> 
>> Thank you for the patch.
>> 
>> On Tuesday 07 Mar 2017 00:57:20 Petr Cvek wrote:
>>> Commit 76e0da34c7ce ("usb-gadget/uvc: use per-attribute show and store
>>> methods") caused a stringification of an undefined macro argument "aname",
>>> so three UVC parameters (streaming_interval, streaming_maxpacket and
>>> streaming_maxburst) were named "aname".
>>>
>>> Add the definition of "aname" to the main macro and name the filenames as
>>> originaly intended.
>> 
>> Why don't you just 
>> 
>> - UVC_ATTR(f_uvc_opts_, cname, aname)
>> + UVC_ATTR(f_uvc_opts_, cname, cname)
>> 
>> in the definition of the UVCG_OPTS_ATTR() macro ?
>
> Hi,
>
> In a fact I did it for my first testing version. But then I realized
> two things. First one is that someone may want to rename these three
> files (now or in the future). The second one is that this bug was
> caused by original author, who probably assumed the UVCG_OPTS_ATTR
> macro had "aname" argument as others UVCG_* macros and didn't check. I
> assumed that too and only after I saw three "aname" files with the
> same path I realized where is the problem.
>
> So it's more like a human error prone type of a code. But if you think
> "cname" is enough I can send PATCH v2.

Laurent, any comments?

-- 
balbi
--
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] usb: phy: isp1301: Add OF device ID table

2017-03-28 Thread Javier Martinez Canillas
Hello Felipe,

On 03/28/2017 09:45 AM, Felipe Balbi wrote:
> 
> Hi,
> 
> Javier Martinez Canillas  writes:
>> The driver doesn't have a struct of_device_id table but supported devices
>> are registered via Device Trees. This is working on the assumption that a
>> I2C device registered via OF will always match a legacy I2C device ID and
>> that the MODALIAS reported will always be of the form i2c:.
>>
>> But this could change in the future so the correct approach is to have an
>> OF device ID table if the devices are registered via OF.
>>
>> Signed-off-by: Javier Martinez Canillas 
> 
> this is already upstream. Care to send an incremental diff in case we
> need this fixed further?
> 

Ah, sorry. I missed that was already picked. Sure, I'll post an incremental
diff on top of v1. Thanks!

Best regards,
-- 
Javier Martinez Canillas
Open Source Group
Samsung Research America
--
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] dwc2: gadget: Fix in control write transfers

2017-03-28 Thread Minas Harutyunyan
After data out stage gadget driver should not initate ZLP on control EP,
because it is up to function driver.

Signed-off-by: Minas Harutyunyan 
---
 drivers/usb/dwc2/gadget.c | 20 ++--
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 98a4a79e7f6e..b7520fa3725b 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1369,6 +1369,11 @@ static int dwc2_hsotg_ep_queue(struct usb_ep *ep, struct 
usb_request *req,
return 0;
}
 
+   /* Change EP direction if status phase request is after data out */
+   if (!hs_ep->index && !req->length && !hs_ep->dir_in &&
+   (hs->ep0_state == DWC2_EP0_DATA_OUT))
+   hs_ep->dir_in = 1;
+
if (first) {
if (!hs_ep->isochronous) {
dwc2_hsotg_start_req(hs, hs_ep, hs_req, false);
@@ -2327,14 +2332,6 @@ static void dwc2_hsotg_handle_outdone(struct dwc2_hsotg 
*hsotg, int epnum)
 */
}
 
-   /* DDMA IN status phase will start from StsPhseRcvd interrupt */
-   if (!using_desc_dma(hsotg) && epnum == 0 &&
-   hsotg->ep0_state == DWC2_EP0_DATA_OUT) {
-   /* Move to STATUS IN */
-   dwc2_hsotg_ep0_zlp(hsotg, true);
-   return;
-   }
-
/*
 * Slave mode OUT transfers do not go through XferComplete so
 * adjust the ISOC parity here.
@@ -2997,14 +2994,9 @@ static void dwc2_hsotg_epint(struct dwc2_hsotg *hsotg, 
unsigned int idx,
}
}
 
-   if (ints & DXEPINT_STSPHSERCVD) {
+   if (ints & DXEPINT_STSPHSERCVD)
dev_dbg(hsotg->dev, "%s: StsPhseRcvd\n", __func__);
 
-   /* Move to STATUS IN for DDMA */
-   if (using_desc_dma(hsotg))
-   dwc2_hsotg_ep0_zlp(hsotg, true);
-   }
-
if (ints & DXEPINT_BACK2BACKSETUP)
dev_dbg(hsotg->dev, "%s: B2BSetup/INEPNakEff\n", __func__);
 
-- 
2.11.0

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


INVESTITIONSPLÄNE

2017-03-28 Thread Joanna Diane Christopher
Hallo

Mein Name ist Joanna Diane Christopher, ich bin 20 Jahre alte Waise von Abidjan 
Elfenbeinküste in Westafrika, ich habe die Summe von (7,5 Millionen Euro), die 
mein verstorbener Vater in einer der Prime Bank hier mit meinem Namen als 
nächster Verwandter niedergelegt hat Weil ich sein einziges überlebender kind 
bin

Ich möchte, dass Sie mir helfen, dieses Geld auf Ihr Bankkonto in Ihrem Land zu 
übertragen und mich auch in Ihr Land zu bringen, um meine Ausbildung 
fortzusetzen. Meine Onkel und Verwandten sind verzweifelt versucht, mich um 
jeden Preis zu töten, weil dieses Geld mein verstorbener Vater in der Bank in 
meinem Namen hinterlegt hat.

Ich würde mich sehr verjüngen, wenn du auf mich antworten könntest, nachdem du 
diese E-Mail gelesen hast, damit ich dir mehr Informationen darüber geben 
kannst, wie du mit der Bank meines Vaters verkehren kannst, um die Übertragung 
des Fonds auf dein Bankkonto zu erleichtern.

Ich biete Ihnen 20% der Gesamtsumme als Entschädigung für Ihre Hilfe und 
Bemühungen an.

Vielen Dank für Ihre Zeit und Rücksicht.


Freundliche Grüße,

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


INVESTITIONSPLÄNE

2017-03-28 Thread Joanna Diane Christopher
Hallo

Mein Name ist Joanna Diane Christopher, ich bin 20 Jahre alte Waise von Abidjan 
Elfenbeinküste in Westafrika, ich habe die Summe von (7,5 Millionen Euro), die 
mein verstorbener Vater in einer der Prime Bank hier mit meinem Namen als 
nächster Verwandter niedergelegt hat Weil ich sein einziges überlebender kind 
bin

Ich möchte, dass Sie mir helfen, dieses Geld auf Ihr Bankkonto in Ihrem Land zu 
übertragen und mich auch in Ihr Land zu bringen, um meine Ausbildung 
fortzusetzen. Meine Onkel und Verwandten sind verzweifelt versucht, mich um 
jeden Preis zu töten, weil dieses Geld mein verstorbener Vater in der Bank in 
meinem Namen hinterlegt hat.

Ich würde mich sehr verjüngen, wenn du auf mich antworten könntest, nachdem du 
diese E-Mail gelesen hast, damit ich dir mehr Informationen darüber geben 
kannst, wie du mit der Bank meines Vaters verkehren kannst, um die Übertragung 
des Fonds auf dein Bankkonto zu erleichtern.

Ich biete Ihnen 20% der Gesamtsumme als Entschädigung für Ihre Hilfe und 
Bemühungen an.

Vielen Dank für Ihre Zeit und Rücksicht.


Freundliche Grüße,

Joanna
--
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: keep VBUS on when device is disconnected

2017-03-28 Thread Tony Lindgren
* Moreno Bartalucci  [170327 23:12]:
> > Il giorno 27 mar 2017, alle ore 19:15, Bin Liu  ha scritto:
> > 
> > […]
> > 
> > The MUSB otg state machine has been changed in many place since the last
> > time I looked at it, and I am not sure how exactly it works now.
> > 
> > If the $subject patch can correctly keep the VBUS on for host-only mode,
> > we can somehow use dr_modei value to distinguish the mode. We don't have
> > to create a new vbus-always-on-in-host-mode flag. VBUS has to be always
> > on in host-only mode anyway, until some error condition happens.
> > 
> 
> During my research, I used this patch to try to print the status of the usb 
> port:
> 
> --- a/drivers/usb/musb/musb_dsps.c2017-03-13 09:34:31.0 +0100
> +++ b/drivers/usb/musb/musb_dsps.c2017-03-13 09:36:02.0 +0100
> @@ -245,6 +245,8 @@ static void otg_timer(unsigned long _mus
>   dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
>   usb_otg_state_string(musb->xceiv->otg->state));
> 
> + dev_emerg(musb->controller, "musb->xceiv->otg->state=%s, 
> musb->port_mode=%d\n", 
> usb_otg_state_string(musb->xceiv->otg->state),(int)musb->port_mode);
> +
>   spin_lock_irqsave(&musb->lock, flags);
>   switch (musb->xceiv->otg->state) {
>   case OTG_STATE_A_WAIT_BCON:
> 
> Unless I did something wrong, maybe it’s worth to notice that before the 
> patch that apparently introduced this bug 
> (2f3fd2c5bde1f94513c3dc311ae64494085ec371) I got nothing printed anywhere.
> With that patch applied, instead, I got the line printed in dmesg.
> I might be wrong but my assumption is that without that patch otg_timer was 
> never called.
> If this is true, it would explain why writing 0 on DEVCTL didn’t bother 
> anything: it never happened.

OK yeah that makes sense.

Thanks,

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


[PATCH linux-next v2 0/4] usb: gadget: udc: atmel: Endpoint allocation scheme fixes

2017-03-28 Thread cristian.birsan
From: Cristian Birsan 

This patch series provides fixes, based on the feedback received on the mailing 
list, for
the following:
- fifo table parameters validation against device tree values
- coding style
- message display for EP configuration error
- Kconfig comments for fifo_mode=0

Changes since v1:
- Removed static for usba_config_fifo_table() function from "Check fifo
configuration values against device tree" patch

Cristian Birsan (4):
  usb: gadget: udc: atmel: Check fifo configuration values against
device tree
  usb: gadget: udc: atmel: Minor code cleanup
  usb: gadget: udc: atmel: Use dev_warn() to display EP configuration
error
  usb: gadget: udc: atmel: Update Kconfig help for fifo_mode = 0

 drivers/usb/gadget/udc/Kconfig  |  5 ++--
 drivers/usb/gadget/udc/atmel_usba_udc.c | 47 ++---
 2 files changed, 35 insertions(+), 17 deletions(-)

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


[PATCH linux-next v2 1/4] usb: gadget: udc: atmel: Check fifo configuration values against device tree

2017-03-28 Thread cristian.birsan
From: Cristian Birsan 

Check fifo configuration values against device tree values for endpoint fifo
in auto configuration mode (fifo_mode=0).

Signed-off-by: Cristian Birsan 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 24 ++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 2035906b..3fd43fb 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -2118,14 +2118,34 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
dev_err(&pdev->dev, "of_probe: fifo-size error(%d)\n", 
ret);
goto err;
}
-   ep->fifo_size = fifo_mode ? udc->fifo_cfg[i].fifo_size : val;
+   if (fifo_mode) {
+   if (val < udc->fifo_cfg[i].fifo_size) {
+   dev_warn(&pdev->dev,
+"of_probe: fifo-size table value not 
supported by HW, using DT value\n");
+   ep->fifo_size = val;
+   } else {
+   ep->fifo_size = udc->fifo_cfg[i].fifo_size;
+   }
+   } else {
+   ep->fifo_size = val;
+   }
 
ret = of_property_read_u32(pp, "atmel,nb-banks", &val);
if (ret) {
dev_err(&pdev->dev, "of_probe: nb-banks error(%d)\n", 
ret);
goto err;
}
-   ep->nr_banks = fifo_mode ? udc->fifo_cfg[i].nr_banks : val;
+   if (fifo_mode) {
+   if (val < udc->fifo_cfg[i].nr_banks) {
+   dev_warn(&pdev->dev,
+"of_probe: nb-banks table value not 
supported by HW, using DT value\n");
+   ep->nr_banks = val;
+   } else {
+   ep->nr_banks = udc->fifo_cfg[i].nr_banks;
+   }
+   } else {
+   ep->nr_banks = val;
+   }
 
ep->can_dma = of_property_read_bool(pp, "atmel,can-dma");
ep->can_isoc = of_property_read_bool(pp, "atmel,can-isoc");
-- 
2.7.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


[PATCH linux-next v2 2/4] usb: gadget: udc: atmel: Minor code cleanup

2017-03-28 Thread cristian.birsan
From: Cristian Birsan 

Minor code cleanup based on feedback received on mailinglist.

Signed-off-by: Cristian Birsan 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 3fd43fb..2bd8410 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -321,7 +321,6 @@ static inline void usba_cleanup_debugfs(struct usba_udc 
*udc)
 
 static ushort fifo_mode;
 
-/* "modprobe ... fifo_mode=1" etc */
 module_param(fifo_mode, ushort, 0x0);
 MODULE_PARM_DESC(fifo_mode, "Endpoint configuration mode");
 
@@ -371,7 +370,7 @@ static struct usba_fifo_cfg mode_4_cfg[] = {
 };
 /* Add additional configurations here */
 
-int usba_config_fifo_table(struct usba_udc *udc)
+static int usba_config_fifo_table(struct usba_udc *udc)
 {
int n;
 
@@ -1076,11 +1075,9 @@ static int atmel_usba_start(struct usb_gadget *gadget,
struct usb_gadget_driver *driver);
 static int atmel_usba_stop(struct usb_gadget *gadget);
 
-static struct usb_ep *atmel_usba_match_ep(
-   struct usb_gadget   *gadget,
-   struct usb_endpoint_descriptor  *desc,
-   struct usb_ss_ep_comp_descriptor *ep_comp
-)
+static struct usb_ep *atmel_usba_match_ep(struct usb_gadget *gadget,
+   struct usb_endpoint_descriptor  *desc,
+   struct usb_ss_ep_comp_descriptor *ep_comp)
 {
struct usb_ep   *_ep;
struct usba_ep *ep;
@@ -1100,7 +1097,6 @@ static struct usb_ep *atmel_usba_match_ep(
ep = to_usba_ep(_ep);
 
switch (usb_endpoint_type(desc)) {
-
case USB_ENDPOINT_XFER_CONTROL:
break;
 
@@ -1141,7 +1137,7 @@ static struct usb_ep *atmel_usba_match_ep(
ep->udc->configured_ep++;
}
 
-return _ep;
+   return _ep;
 }
 
 static const struct usb_gadget_ops usba_udc_ops = {
@@ -2089,8 +2085,9 @@ static struct usba_ep * atmel_udc_of_init(struct 
platform_device *pdev,
while ((pp = of_get_next_child(np, pp)))
udc->num_ep++;
udc->configured_ep = 1;
-   } else
+   } else {
udc->num_ep = usba_config_fifo_table(udc);
+   }
 
eps = devm_kzalloc(&pdev->dev, sizeof(struct usba_ep) * udc->num_ep,
   GFP_KERNEL);
-- 
2.7.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


[PATCH linux-next v2 3/4] usb: gadget: udc: atmel: Use dev_warn() to display EP configuration error

2017-03-28 Thread cristian.birsan
From: Cristian Birsan 

Use dev_warn() to display EP configuration error to avoid silent failure.

Signed-off-by: Cristian Birsan 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 2bd8410..942c9c9 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1851,7 +1851,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 * but it's clearly harmless...
 */
if (!(usba_ep_readl(ep0, CFG) & USBA_EPT_MAPPED))
-   dev_dbg(&udc->pdev->dev,
+   dev_warn(&udc->pdev->dev,
 "ODD: EP0 configuration is invalid!\n");
 
/* Preallocate other endpoints */
@@ -1860,8 +1860,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
ep = &udc->usba_ep[i];
usba_ep_writel(ep, CFG, ep->ept_cfg);
if (!(usba_ep_readl(ep, CFG) & USBA_EPT_MAPPED))
-   dev_dbg(&udc->pdev->dev,
-"ODD: EP%d configuration is invalid!\n", i);
+   dev_warn(&udc->pdev->dev,
+"ODD: EP%d configuration is 
invalid!\n", i);
}
}
 
-- 
2.7.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


[PATCH linux-next v2 4/4] usb: gadget: udc: atmel: Update Kconfig help for fifo_mode = 0

2017-03-28 Thread cristian.birsan
From: Cristian Birsan 

Update Kconfig help for fifo_mode = 0 to explain the behavior better.

Signed-off-by: Cristian Birsan 
---
 drivers/usb/gadget/udc/Kconfig | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index c6cc9d3..1fd3fe9 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -62,8 +62,9 @@ config USB_ATMEL_USBA
 
  The fifo_mode parameter is used to select endpoint allocation mode.
  fifo_mode = 0 is used to let the driver autoconfigure the endpoints.
- In this case 2 banks are allocated for isochronous endpoints and
- only one bank is allocated for the rest of the endpoints.
+ In this case, for ep1 2 banks are allocated if it works in isochronous
+ mode and only 1 bank otherwise. For the rest of the endpoints
+ only 1 bank is allocated.
 
  fifo_mode = 1 is a generic maximum fifo size (1024 bytes) 
configuration
  allowing the usage of ep1 - ep6
-- 
2.7.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


Re: [PATCH] usb: musb: fix possible spinlock deadlock

2017-03-28 Thread Greg KH
On Tue, Mar 28, 2017 at 08:45:31AM -0500, Bin Liu wrote:
> commit bc1e2154542071e3cfe1734b143af9b8bdacf8bd upstream.
> 
> The DSPS glue calls del_timer_sync() in its musb_platform_disable()
> implementation, which requires the caller to not hold a lock. But
> musb_remove() calls musb_platform_disable() will musb->lock held. This
> could causes spinlock deadlock.
> 
> So change musb_remove() to call musb_platform_disable() without holds
> musb->lock. This doesn't impact the musb_platform_disable implementation
> in other glue drivers.
> 
> root@am335x-evm:~# modprobe -r musb-dsps
> [  126.134879] musb-hdrc musb-hdrc.1: remove, state 1
> [  126.140465] usb usb2: USB disconnect, device number 1
> [  126.146178] usb 2-1: USB disconnect, device number 2
> [  126.416985] musb-hdrc musb-hdrc.1: USB bus 2 deregistered
> [  126.423943]
> [  126.425525] ==
> [  126.431997] [ INFO: possible circular locking dependency detected ]
> [  126.438564] 4.11.0-rc1-3-g1557f13bca04-dirty #77 Not tainted
> [  126.444852] ---
> [  126.451414] modprobe/778 is trying to acquire lock:
> [  126.456523]  (((&glue->timer))){+.-...}, at: [] 
> del_timer_sync+0x0/0xd0
> [  126.464403]
> [  126.464403] but task is already holding lock:
> [  126.470511]  (&(&musb->lock)->rlock){-.-...}, at: [] 
> musb_remove+0x50/0x1
> 30 [musb_hdrc]
> [  126.479965]
> [  126.479965] which lock already depends on the new lock.
> [  126.479965]
> [  126.488531]
> [  126.488531] the existing dependency chain (in reverse order) is:
> [  126.496368]
> [  126.496368] -> #1 (&(&musb->lock)->rlock){-.-...}:
> [  126.502968]otg_timer+0x80/0xec [musb_dsps]
> [  126.507990]call_timer_fn+0xb4/0x390
> [  126.512372]expire_timers+0xf0/0x1fc
> [  126.516754]run_timer_softirq+0x80/0x178
> [  126.521511]__do_softirq+0xc4/0x554
> [  126.525802]irq_exit+0xe8/0x158
> [  126.529735]__handle_domain_irq+0x58/0xb8
> [  126.534583]__irq_usr+0x54/0x80
> [  126.538507]
> [  126.538507] -> #0 (((&glue->timer))){+.-...}:
> [  126.544636]del_timer_sync+0x40/0xd0
> [  126.549066]musb_remove+0x6c/0x130 [musb_hdrc]
> [  126.554370]platform_drv_remove+0x24/0x3c
> [  126.559206]device_release_driver_internal+0x14c/0x1e0
> [  126.565225]bus_remove_device+0xd8/0x108
> [  126.569970]device_del+0x1e4/0x308
> [  126.574170]platform_device_del+0x24/0x8c
> [  126.579006]platform_device_unregister+0xc/0x20
> [  126.584394]dsps_remove+0x14/0x30 [musb_dsps]
> [  126.589595]platform_drv_remove+0x24/0x3c
> [  126.594432]device_release_driver_internal+0x14c/0x1e0
> [  126.600450]driver_detach+0x38/0x6c
> [  126.604740]bus_remove_driver+0x4c/0xa0
> [  126.609407]SyS_delete_module+0x11c/0x1e4
> [  126.614252]__sys_trace_return+0x0/0x10
> 
> Fixes: ea2f35c01d5ea ("usb: musb: Fix sleeping function called from invalid 
> context for hdrc glue")
> Cc:  #4.9+
> Acked-by: Tony Lindgren 
> Signed-off-by: Bin Liu 
> Signed-off-by: Greg Kroah-Hartman 
> 
> Conflicts:
>   drivers/usb/musb/musb_core.c

What is this "Conflicts:" line for?

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] usb: musb: fix possible spinlock deadlock

2017-03-28 Thread Bin Liu
On Tue, Mar 28, 2017 at 07:15:58PM +0200, Greg KH wrote:
> On Tue, Mar 28, 2017 at 08:45:31AM -0500, Bin Liu wrote:
> > commit bc1e2154542071e3cfe1734b143af9b8bdacf8bd upstream.
> > 
> > The DSPS glue calls del_timer_sync() in its musb_platform_disable()
> > implementation, which requires the caller to not hold a lock. But
> > musb_remove() calls musb_platform_disable() will musb->lock held. This
> > could causes spinlock deadlock.
> > 
> > So change musb_remove() to call musb_platform_disable() without holds
> > musb->lock. This doesn't impact the musb_platform_disable implementation
> > in other glue drivers.
> > 
> > root@am335x-evm:~# modprobe -r musb-dsps
> > [  126.134879] musb-hdrc musb-hdrc.1: remove, state 1
> > [  126.140465] usb usb2: USB disconnect, device number 1
> > [  126.146178] usb 2-1: USB disconnect, device number 2
> > [  126.416985] musb-hdrc musb-hdrc.1: USB bus 2 deregistered
> > [  126.423943]
> > [  126.425525] ==
> > [  126.431997] [ INFO: possible circular locking dependency detected ]
> > [  126.438564] 4.11.0-rc1-3-g1557f13bca04-dirty #77 Not tainted
> > [  126.444852] ---
> > [  126.451414] modprobe/778 is trying to acquire lock:
> > [  126.456523]  (((&glue->timer))){+.-...}, at: [] 
> > del_timer_sync+0x0/0xd0
> > [  126.464403]
> > [  126.464403] but task is already holding lock:
> > [  126.470511]  (&(&musb->lock)->rlock){-.-...}, at: [] 
> > musb_remove+0x50/0x1
> > 30 [musb_hdrc]
> > [  126.479965]
> > [  126.479965] which lock already depends on the new lock.
> > [  126.479965]
> > [  126.488531]
> > [  126.488531] the existing dependency chain (in reverse order) is:
> > [  126.496368]
> > [  126.496368] -> #1 (&(&musb->lock)->rlock){-.-...}:
> > [  126.502968]otg_timer+0x80/0xec [musb_dsps]
> > [  126.507990]call_timer_fn+0xb4/0x390
> > [  126.512372]expire_timers+0xf0/0x1fc
> > [  126.516754]run_timer_softirq+0x80/0x178
> > [  126.521511]__do_softirq+0xc4/0x554
> > [  126.525802]irq_exit+0xe8/0x158
> > [  126.529735]__handle_domain_irq+0x58/0xb8
> > [  126.534583]__irq_usr+0x54/0x80
> > [  126.538507]
> > [  126.538507] -> #0 (((&glue->timer))){+.-...}:
> > [  126.544636]del_timer_sync+0x40/0xd0
> > [  126.549066]musb_remove+0x6c/0x130 [musb_hdrc]
> > [  126.554370]platform_drv_remove+0x24/0x3c
> > [  126.559206]device_release_driver_internal+0x14c/0x1e0
> > [  126.565225]bus_remove_device+0xd8/0x108
> > [  126.569970]device_del+0x1e4/0x308
> > [  126.574170]platform_device_del+0x24/0x8c
> > [  126.579006]platform_device_unregister+0xc/0x20
> > [  126.584394]dsps_remove+0x14/0x30 [musb_dsps]
> > [  126.589595]platform_drv_remove+0x24/0x3c
> > [  126.594432]device_release_driver_internal+0x14c/0x1e0
> > [  126.600450]driver_detach+0x38/0x6c
> > [  126.604740]bus_remove_driver+0x4c/0xa0
> > [  126.609407]SyS_delete_module+0x11c/0x1e4
> > [  126.614252]__sys_trace_return+0x0/0x10
> > 
> > Fixes: ea2f35c01d5ea ("usb: musb: Fix sleeping function called from invalid 
> > context for hdrc glue")
> > Cc:  #4.9+
> > Acked-by: Tony Lindgren 
> > Signed-off-by: Bin Liu 
> > Signed-off-by: Greg Kroah-Hartman 
> > 
> > Conflicts:
> > drivers/usb/musb/musb_core.c
> 
> What is this "Conflicts:" line for?

That was the reason the uptream commit failed to apply to stable
automatically.

I am not sure if we want to track it or not, so I leave it here for
comment.

Should I remove it?

Regards,
-Bin.
--
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: phy: isp1301: Fix build warning when CONFIG_OF is disabled

2017-03-28 Thread Javier Martinez Canillas
Commit fd567653bdb9 ("usb: phy: isp1301: Add OF device ID table")
added an OF device ID table, but used the of_match_ptr() macro
that will lead to a build warning if CONFIG_OF symbol is disabled:

drivers/usb/phy//phy-isp1301.c:36:34: warning: ‘isp1301_of_match’ defined but 
not used [-Wunused-const-variable=]
 static const struct of_device_id isp1301_of_match[] = {
  ^~~~

Fixes: fd567653bdb9 ("usb: phy: isp1301: Add OF device ID table")
Reported-by: Arnd Bergmann 
Signed-off-by: Javier Martinez Canillas 

---

 drivers/usb/phy/phy-isp1301.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c
index b3b33cf7ddf6..f333024660b4 100644
--- a/drivers/usb/phy/phy-isp1301.c
+++ b/drivers/usb/phy/phy-isp1301.c
@@ -136,7 +136,7 @@ static int isp1301_remove(struct i2c_client *client)
 static struct i2c_driver isp1301_driver = {
.driver = {
.name = DRV_NAME,
-   .of_match_table = of_match_ptr(isp1301_of_match),
+   .of_match_table = isp1301_of_match,
},
.probe = isp1301_probe,
.remove = isp1301_remove,
-- 
2.9.3

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


Fast Loans

2017-03-28 Thread Service Loans
Do you need a loan to pay up bill or to start a business? Email Us
--
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 1/2] usb: phy: Introduce one extcon device into usb phy

2017-03-28 Thread NeilBrown
On Thu, Mar 23 2017, Baolin Wang wrote:

> Usually usb phy need register one extcon device to get the connection
> notifications. It will remove some duplicate code if the extcon device
> is registered using common code instead of each phy driver having its
> own related extcon APIs. So we add one pointer of extcon device into
> usb phy structure, and some other helper functions to register extcon.
>
> Suggested-by: NeilBrown 
> Signed-off-by: Baolin Wang 
> ---
> Changes since v1:
>  - Fix build errors with random config.
> ---
>  drivers/usb/phy/Kconfig |6 +++---
>  drivers/usb/phy/phy.c   |   44 
>  include/linux/usb/phy.h |6 ++
>  3 files changed, 53 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
> index 61cef75..c9c61a8 100644
> --- a/drivers/usb/phy/Kconfig
> +++ b/drivers/usb/phy/Kconfig
> @@ -4,6 +4,7 @@
>  menu "USB Physical Layer drivers"
>  
>  config USB_PHY
> + select EXTCON
>   def_bool n
>  
>  #
> @@ -116,7 +117,7 @@ config OMAP_OTG
>  
>  config TAHVO_USB
>   tristate "Tahvo USB transceiver driver"
> - depends on MFD_RETU && EXTCON
> + depends on MFD_RETU
>   depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 
> 'y'
>   select USB_PHY
>   help
> @@ -148,7 +149,6 @@ config USB_MSM_OTG
>   depends on (USB || USB_GADGET) && (ARCH_QCOM || COMPILE_TEST)
>   depends on USB_GADGET || !USB_GADGET # if USB_GADGET=m, this can't be 
> 'y'
>   depends on RESET_CONTROLLER
> - depends on EXTCON
>   select USB_PHY
>   help
> Enable this to support the USB OTG transceiver on Qualcomm chips. It
> @@ -162,7 +162,7 @@ config USB_MSM_OTG
>  config USB_QCOM_8X16_PHY
>   tristate "Qualcomm APQ8016/MSM8916 on-chip USB PHY controller support"
>   depends on ARCH_QCOM || COMPILE_TEST
> - depends on RESET_CONTROLLER && EXTCON
> + depends on RESET_CONTROLLER
>   select USB_PHY
>   select USB_ULPI_VIEWPORT
>   help
> diff --git a/drivers/usb/phy/phy.c b/drivers/usb/phy/phy.c
> index 98f75d2..baa8b18 100644
> --- a/drivers/usb/phy/phy.c
> +++ b/drivers/usb/phy/phy.c
> @@ -100,6 +100,41 @@ static int devm_usb_phy_match(struct device *dev, void 
> *res, void *match_data)
>   return *phy == match_data;
>  }
>  
> +static int usb_add_extcon(struct usb_phy *x)
> +{
> + int ret;
> +
> + if (of_property_read_bool(x->dev->of_node, "extcon")) {
> + x->edev = extcon_get_edev_by_phandle(x->dev, 0);

This is not what I meant to suggest.
This provides an extcon only for some phy devices.  I meant that every
single usb_phy should always have an extcon.
So phy.c should probably call extcon_dev_allocate() and
extcon_dev_register() - or similar.

The driver then calls extcon_set_state() or similar on this extcon
device in whatever way might be appropriate.
For a phy driver like phy-qcom-8x16-usb it might just pass on
events from some separate extcon device.

For the (hypothetical?) device that Felipe suggests with separate
ID and VBUS extcons, it would pass on events from multiple different
extcons.  i.e. it would act like a multiplexer.

Other drivers would do things from interrupt handlers, based on values
read from registers.

The important point is that each usb_phy doesn't get a pointer to some
separate extcon.  Rather it has an extcon that it completely owns.  The
name of the extcon is the same of the phy.  The extcon should be seen as
a part of the phy, not a separate thing which provides service to the
phy.

Thanks,
NeilBrown


signature.asc
Description: PGP signature


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

2017-03-28 Thread NeilBrown
On Tue, Mar 07 2017, Baolin Wang wrote:

> On 3 March 2017 at 10:23, NeilBrown  wrote:
>
>>
>> I understand your reluctance to change drivers that you cannot test.
>> An alternative it do change all the
>>   atomic_notifier_call_chain(.*notifier,
>> calls that don't pass a pointer to vbus_draw to pass NULL, and to
>> declare the passing of NULL to be deprecated (so hopefully people won't
>> use it in new code).
>> Then any notification callback that expects a current can just ignore
>> calls where the pointer is NULL.
>
> I am afraid if it is enough to send out vbus draw information from USB
> phy driver, for example you will miss super speed (900mA), which need
> get the speed information from gadget driver.

When the gadget driver determines that 900mA is available, it calls
usb_phy_set_power() which calls the ->set_power() method on the usb_phy.
The usb_phy the uses the notifier to inform all interested parties
that 900mA is available.

NeilBrown


signature.asc
Description: PGP signature


RE: [PATCH 1/4] usb: gadget: udc: renesas_usb3: add sysfs "role" to set "b-device" mode

2017-03-28 Thread Yoshihiro Shimoda
Hi Felipe-san,

> From: Felipe Balbi, Sent: Tuesday, March 28, 2017 9:06 PM
> 
> Hi,
> 
> Yoshihiro Shimoda  writes:
> > Sadly, to change the role ("host" and "peripheral") of USB3.0 DRD
> > controller on R-Car Gen3, software has to set the DRD_CON register
> > which is included in a usb3.0 peripheral controler's register.
> > To simply implementation, the previous code always set peripheral mode
> > as hardcoded. However, to support usb role swap in the future,
> > the hardcoded is not good. So, this patch adds sysfs "role" to set
> > the mode by a user.
> > After applied this patch, since the DRD controller will act as host
> > mode after probed, a user needs to change the mode via the sysfs.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> 
> in patch 3, you add extcon to monitor ID and VBUS pins. Do you really
> need this sysfs file at all?

Yes. This is because this "role" sysfs file cannot monitor the ID and VBUS pins.
The "role" only monitors the mode which is "host" or "peripheral".

Best regards,
Yoshihiro Shimoda

> --
> balbi
--
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: [PATCHv2] phy: cpcap-usb: Add CPCAP PMIC USB support

2017-03-28 Thread Rob Herring
On Wed, Mar 22, 2017 at 04:46:02PM -0700, Tony Lindgren wrote:
> Some Motorola phones like droid 4 use a custom CPCAP PMIC that has a
> multiplexing USB PHY.
> 
> This USB PHY can operate at least in four modes using pin multiplexing
> and two control GPIOS:
> 
> - Pass through companion PHY for the SoC USB PHY
> - ULPI PHY for the SoC
> - Pass through USB for the modem
> - UART debug console for the SoC
> 
> This patch adds support for droid 4 USB PHY and debug UART modes,
> support for other modes can be added later on as needed.
> 
> Both peripheral and host mode are working for the USB. The
> host mode depends on the cpcap-charger driver for VBUS.
> 
> VBUS and ID pin detection are done using cpcap-adc IIO ADC
> driver.
> 
> Cc: devicet...@vger.kernel.org
> Cc: Marcel Partap 
> Cc: Michael Scott 
> Tested-by: Sebastian Reichel 
> Signed-off-by: Tony Lindgren 
> ---
> 
> Changes since v1:
> 
> - Use iio_read_channel_processed() instead of iio_read_channel_scaled()
>   as changed in the v2 of the ADC driver 
> 
> - Keep Tested-by from Sebastian Reichel  as the change
>   from v1 is trivial
> 
> ---
>  .../devicetree/bindings/phy/phy-cpcap-usb.txt  |  40 ++

Acked-by: Rob Herring 

>  drivers/phy/Kconfig|   8 +
>  drivers/phy/Makefile   |   1 +
>  drivers/phy/phy-cpcap-usb.c| 695 
> +
>  4 files changed, 744 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/phy-cpcap-usb.txt
>  create mode 100644 drivers/phy/phy-cpcap-usb.c
--
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 device disconnect after suspend/resume

2017-03-28 Thread Peter Chen
On Tue, Mar 28, 2017 at 03:25:34PM +0200, Stephan Müller wrote:
> Am Dienstag, 28. März 2017, 03:12:44 CEST schrieb Peter Chen:
> 
> Hi Peter,
> 
> > Do you have debug information from USB core (not only USB storage)? It
> > may show why it is disconnected from low level.
> 
> The device is question is at port 2-3.
> 
> usb core dyndbg:
> 
> [   72.546341] Restarting tasks ... 
> [   72.546465] hub 1-0:1.0: state 7 ports 11 chg  evt 0028
> [   72.546595] hub 2-0:1.0: state 7 ports 4 chg 0008 evt 
> [   72.546662] usb usb2-port3: status 0263, change , 5.0 Gb/s
> [   72.546670] usb 2-3: USB disconnect, device number 2
> [   72.546675] usb 2-3: unregistering device
> [   72.546682] usb 2-3: unregistering interface 2-3:1.0
> [   72.552689] done.
> [   72.553977] brcmfmac :03:00.0: Direct firmware load for brcm/
> brcmfmac43602-pcie.txt failed with error -2
> [   72.676148] usb 2-3: usb_disable_device nuking all URBs
> [   72.727915] usb usb2-port3: not reset yet, waiting 50ms
> [   72.780009] usb usb2-port3: not reset yet, waiting 200ms
> [   72.985875] usb usb2-port3: not reset yet, waiting 200ms
> [   73.063770] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Nov 
> 10 
> 2015 06:38:10 version 7.35.177.61 (r598657) FWID 01-ea662a8c
> [   73.096915] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code 
> (0x30 
> 0x30)
> [   73.122551] brcmfmac :03:00.0 wlp3s0: renamed from wlan0
> [   73.140131] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
> [   73.193919] usb usb2-port3: not reset yet, waiting 200ms
> [   73.402026] usb usb2-port3: hot reset failed, warm reset
> [   73.402028] usb usb2-port3: not enabled, trying warm reset again...
> [   73.609968] usb usb2-port3: not warm reset yet, waiting 200ms
> [   73.817946] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.026100] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.234126] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.234167] usb usb2-port3: not enabled, trying warm reset again...
> [   74.441910] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.649894] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.857981] usb usb2-port3: not warm reset yet, waiting 200ms
> [   75.066006] usb usb2-port3: not warm reset yet, waiting 200ms
> [   75.066040] xhci_hcd :00:14.0: Cannot set link state.
> [   75.066045] usb usb2-port3: cannot disable (err = -32)
> [   75.066065] xhci_hcd :00:14.0: Cannot set link state.
> [   75.066069] usb usb2-port3: cannot disable (err = -32)
> [   75.066079] hub 2-0:1.0: state 7 ports 4 chg  evt 0008
> [   75.066130] hub 2-0:1.0: hub_suspend
> [   75.066140] usb usb2: bus auto-suspend, wakeup 1
> 
> 
> xhci dyndbg (I hope I have copied the right logs):
> 
> [  219.110425] xhci_hcd :00:14.0: Cancel URB 8c1678bf7a80, dev 3, ep 
> 0x0, starting at offset 0x44f3eb390
> [  219.110438] xhci_hcd :00:14.0: // Ding dong!
> [  219.110519] xhci_hcd :00:14.0: Stopped on Transfer TRB
> [  219.110525] xhci_hcd :00:14.0: WARN: unexpected TRB Type 4
> [  219.110532] xhci_hcd :00:14.0: Removing canceled TD starting at 
> 0x44f3eb390 (dma).
> [  219.110534] xhci_hcd :00:14.0: Finding endpoint context
> [  219.110537] xhci_hcd :00:14.0: Cycle state = 0x1
> [  219.110540] xhci_hcd :00:14.0: New dequeue segment = 8c16cec66a40 
> (virtual)
> [  219.110542] xhci_hcd :00:14.0: New dequeue pointer = 0x44f3eb3b0 (DMA)
> [  219.110547] xhci_hcd :00:14.0: Set TR Deq Ptr cmd, new deq seg = 
> 8c16cec66a40 (0x44f3eb000 dma), new deq ptr = 8c16cf3eb3b0 
> (0x44f3eb3b0 dma), new cycle = 1
> [  219.110550] xhci_hcd :00:14.0: // Ding dong!
> [  219.110570] xhci_hcd :00:14.0: Successful Set TR Deq Ptr cmd, deq = 
> @44f3eb3b0
> [  219.110613] xhci_hcd :00:14.0: disable port 3 USB2 hardware LPM
> [  219.110620] xhci_hcd :00:14.0: Set up evaluate context for LPM MEL 
> change.
> [  219.110623] xhci_hcd :00:14.0: Slot 2 Input Context:
> ...
> [  219.110698] xhci_hcd :00:14.0: // Ding dong!
> [  219.110851] xhci_hcd :00:14.0: Successful evaluate context command
> [  219.110855] xhci_hcd :00:14.0: Slot 2 Output Context:
> ...
> [  219.113759] xhci_hcd :00:14.0: Port Status Change Event for port 3
> [  219.113767] xhci_hcd :00:14.0: handle_port_status: starting port 
> polling.
> [  219.113779] xhci_hcd :00:14.0: xhci_hub_status_data: stopping port 
> polling.
> [  219.122345] xhci_hcd :00:14.0: // Ding dong!
> [  219.122436] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122441] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122444] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122448] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.146522] xhci_hcd :00:14.0: xhci_suspend: stopping port polling.
> 
> --- suspended ---
> 
> [  228.110972] Restarting tasks ...
> [  228.129044] xhci_hcd :00:14.0: ep 0x81 - aske

Re: USB device disconnect after suspend/resume

2017-03-28 Thread Peter Chen
On Tue, Mar 28, 2017 at 03:25:34PM +0200, Stephan Müller wrote:
> Am Dienstag, 28. März 2017, 03:12:44 CEST schrieb Peter Chen:
> 
> Hi Peter,
> 
> > Do you have debug information from USB core (not only USB storage)? It
> > may show why it is disconnected from low level.
> 
> The device is question is at port 2-3.
> 
> usb core dyndbg:
> 
> [   72.546341] Restarting tasks ... 
> [   72.546465] hub 1-0:1.0: state 7 ports 11 chg  evt 0028
> [   72.546595] hub 2-0:1.0: state 7 ports 4 chg 0008 evt 
> [   72.546662] usb usb2-port3: status 0263, change , 5.0 Gb/s
> [   72.546670] usb 2-3: USB disconnect, device number 2
> [   72.546675] usb 2-3: unregistering device
> [   72.546682] usb 2-3: unregistering interface 2-3:1.0
> [   72.552689] done.
> [   72.553977] brcmfmac :03:00.0: Direct firmware load for brcm/
> brcmfmac43602-pcie.txt failed with error -2
> [   72.676148] usb 2-3: usb_disable_device nuking all URBs
> [   72.727915] usb usb2-port3: not reset yet, waiting 50ms
> [   72.780009] usb usb2-port3: not reset yet, waiting 200ms
> [   72.985875] usb usb2-port3: not reset yet, waiting 200ms
> [   73.063770] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Nov 
> 10 
> 2015 06:38:10 version 7.35.177.61 (r598657) FWID 01-ea662a8c
> [   73.096915] brcmfmac: brcmf_cfg80211_reg_notifier: not a ISO3166 code 
> (0x30 
> 0x30)
> [   73.122551] brcmfmac :03:00.0 wlp3s0: renamed from wlan0
> [   73.140131] IPv6: ADDRCONF(NETDEV_UP): wlp3s0: link is not ready
> [   73.193919] usb usb2-port3: not reset yet, waiting 200ms
> [   73.402026] usb usb2-port3: hot reset failed, warm reset
> [   73.402028] usb usb2-port3: not enabled, trying warm reset again...
> [   73.609968] usb usb2-port3: not warm reset yet, waiting 200ms
> [   73.817946] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.026100] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.234126] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.234167] usb usb2-port3: not enabled, trying warm reset again...
> [   74.441910] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.649894] usb usb2-port3: not warm reset yet, waiting 200ms
> [   74.857981] usb usb2-port3: not warm reset yet, waiting 200ms
> [   75.066006] usb usb2-port3: not warm reset yet, waiting 200ms
> [   75.066040] xhci_hcd :00:14.0: Cannot set link state.
> [   75.066045] usb usb2-port3: cannot disable (err = -32)
> [   75.066065] xhci_hcd :00:14.0: Cannot set link state.
> [   75.066069] usb usb2-port3: cannot disable (err = -32)
> [   75.066079] hub 2-0:1.0: state 7 ports 4 chg  evt 0008
> [   75.066130] hub 2-0:1.0: hub_suspend
> [   75.066140] usb usb2: bus auto-suspend, wakeup 1
> 
> 
> xhci dyndbg (I hope I have copied the right logs):
> 
> [  219.110425] xhci_hcd :00:14.0: Cancel URB 8c1678bf7a80, dev 3, ep 
> 0x0, starting at offset 0x44f3eb390
> [  219.110438] xhci_hcd :00:14.0: // Ding dong!
> [  219.110519] xhci_hcd :00:14.0: Stopped on Transfer TRB
> [  219.110525] xhci_hcd :00:14.0: WARN: unexpected TRB Type 4
> [  219.110532] xhci_hcd :00:14.0: Removing canceled TD starting at 
> 0x44f3eb390 (dma).
> [  219.110534] xhci_hcd :00:14.0: Finding endpoint context
> [  219.110537] xhci_hcd :00:14.0: Cycle state = 0x1
> [  219.110540] xhci_hcd :00:14.0: New dequeue segment = 8c16cec66a40 
> (virtual)
> [  219.110542] xhci_hcd :00:14.0: New dequeue pointer = 0x44f3eb3b0 (DMA)
> [  219.110547] xhci_hcd :00:14.0: Set TR Deq Ptr cmd, new deq seg = 
> 8c16cec66a40 (0x44f3eb000 dma), new deq ptr = 8c16cf3eb3b0 
> (0x44f3eb3b0 dma), new cycle = 1
> [  219.110550] xhci_hcd :00:14.0: // Ding dong!
> [  219.110570] xhci_hcd :00:14.0: Successful Set TR Deq Ptr cmd, deq = 
> @44f3eb3b0
> [  219.110613] xhci_hcd :00:14.0: disable port 3 USB2 hardware LPM
> [  219.110620] xhci_hcd :00:14.0: Set up evaluate context for LPM MEL 
> change.
> [  219.110623] xhci_hcd :00:14.0: Slot 2 Input Context:
> ...
> [  219.110698] xhci_hcd :00:14.0: // Ding dong!
> [  219.110851] xhci_hcd :00:14.0: Successful evaluate context command
> [  219.110855] xhci_hcd :00:14.0: Slot 2 Output Context:
> ...
> [  219.113759] xhci_hcd :00:14.0: Port Status Change Event for port 3
> [  219.113767] xhci_hcd :00:14.0: handle_port_status: starting port 
> polling.
> [  219.113779] xhci_hcd :00:14.0: xhci_hub_status_data: stopping port 
> polling.
> [  219.122345] xhci_hcd :00:14.0: // Ding dong!
> [  219.122436] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122441] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122444] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.122448] xhci_hcd :00:14.0: Stopped on No-op or Link TRB
> [  219.146522] xhci_hcd :00:14.0: xhci_suspend: stopping port polling.
> 
> --- suspended ---
> 
> [  228.110972] Restarting tasks ...
> [  228.129044] xhci_hcd :00:14.0: ep 0x81 - aske

[PATCH 1/2] usb: host: xhci: delete sp_dma_buffers for scratchpad

2017-03-28 Thread Peter Chen
We already have sp_array to store each scratch buffer address for xHC,
it doesn't need another sp_dma_buffers array to store it.

Signed-off-by: Peter Chen 
---
 drivers/usb/host/xhci-mem.c | 18 --
 drivers/usb/host/xhci.h |  1 -
 2 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 032a702..22a03b7 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1709,36 +1709,27 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, 
gfp_t flags)
if (!xhci->scratchpad->sp_buffers)
goto fail_sp3;
 
-   xhci->scratchpad->sp_dma_buffers =
-   kzalloc(sizeof(dma_addr_t) * num_sp, flags);
-
-   if (!xhci->scratchpad->sp_dma_buffers)
-   goto fail_sp4;
-
xhci->dcbaa->dev_context_ptrs[0] = 
cpu_to_le64(xhci->scratchpad->sp_dma);
for (i = 0; i < num_sp; i++) {
dma_addr_t dma;
void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma,
flags);
if (!buf)
-   goto fail_sp5;
+   goto fail_sp4;
 
xhci->scratchpad->sp_array[i] = dma;
xhci->scratchpad->sp_buffers[i] = buf;
-   xhci->scratchpad->sp_dma_buffers[i] = dma;
}
 
return 0;
 
- fail_sp5:
+ fail_sp4:
for (i = i - 1; i >= 0; i--) {
dma_free_coherent(dev, xhci->page_size,
xhci->scratchpad->sp_buffers[i],
-   xhci->scratchpad->sp_dma_buffers[i]);
+   xhci->scratchpad->sp_array[i]);
}
-   kfree(xhci->scratchpad->sp_dma_buffers);
 
- fail_sp4:
kfree(xhci->scratchpad->sp_buffers);
 
  fail_sp3:
@@ -1768,9 +1759,8 @@ static void scratchpad_free(struct xhci_hcd *xhci)
for (i = 0; i < num_sp; i++) {
dma_free_coherent(dev, xhci->page_size,
xhci->scratchpad->sp_buffers[i],
-   xhci->scratchpad->sp_dma_buffers[i]);
+   xhci->scratchpad->sp_array[i]);
}
-   kfree(xhci->scratchpad->sp_dma_buffers);
kfree(xhci->scratchpad->sp_buffers);
dma_free_coherent(dev, num_sp * sizeof(u64),
xhci->scratchpad->sp_array,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index da3eb69..00d2578 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1604,7 +1604,6 @@ struct xhci_scratchpad {
u64 *sp_array;
dma_addr_t sp_dma;
void **sp_buffers;
-   dma_addr_t *sp_dma_buffers;
 };
 
 struct urb_priv {
-- 
2.7.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


[PATCH 2/2] usb: host: xhci: using dma pool for scratchpad buffer

2017-03-28 Thread Peter Chen
According to xHCI ch4.20 Scratchpad Buffers
A Scratchpad Buffer is a PAGESIZE block of system memory
located on a PAGESIZE boundary
...
Software clears the Scratchpad Buffer to ‘0’

So, we need to use dma pool for PAGESIZE boundary buffer, and zeroed
its region using dma_pool_zalloc.

Signed-off-by: Peter Chen 
---
 drivers/usb/host/xhci-mem.c | 21 +++--
 drivers/usb/host/xhci.h |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 22a03b7..56aa0a6 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1710,12 +1710,18 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, 
gfp_t flags)
goto fail_sp3;
 
xhci->dcbaa->dev_context_ptrs[0] = 
cpu_to_le64(xhci->scratchpad->sp_dma);
+
+   xhci->scratchpad_pool = dma_pool_create("xhci scratchpad buffer pool",
+   dev, xhci->page_size,
+   xhci->page_size, xhci->page_size);
+   if (!xhci->scratchpad_pool)
+   goto fail_sp4;
+
for (i = 0; i < num_sp; i++) {
dma_addr_t dma;
-   void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma,
-   flags);
+   void *buf = dma_pool_zalloc(xhci->scratchpad_pool, flags, &dma);
if (!buf)
-   goto fail_sp4;
+   goto fail_sp5;
 
xhci->scratchpad->sp_array[i] = dma;
xhci->scratchpad->sp_buffers[i] = buf;
@@ -1723,13 +1729,15 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, 
gfp_t flags)
 
return 0;
 
- fail_sp4:
+ fail_sp5:
for (i = i - 1; i >= 0; i--) {
-   dma_free_coherent(dev, xhci->page_size,
+   dma_pool_free(xhci->scratchpad_pool,
xhci->scratchpad->sp_buffers[i],
xhci->scratchpad->sp_array[i]);
}
+   dma_pool_destroy(xhci->scratchpad_pool);
 
+ fail_sp4:
kfree(xhci->scratchpad->sp_buffers);
 
  fail_sp3:
@@ -1757,10 +1765,11 @@ static void scratchpad_free(struct xhci_hcd *xhci)
num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
 
for (i = 0; i < num_sp; i++) {
-   dma_free_coherent(dev, xhci->page_size,
+   dma_pool_free(xhci->scratchpad_pool,
xhci->scratchpad->sp_buffers[i],
xhci->scratchpad->sp_array[i]);
}
+   dma_pool_destroy(xhci->scratchpad_pool);
kfree(xhci->scratchpad->sp_buffers);
dma_free_coherent(dev, num_sp * sizeof(u64),
xhci->scratchpad->sp_array,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 00d2578..d029398 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1758,6 +1758,7 @@ struct xhci_hcd {
struct dma_pool *segment_pool;
struct dma_pool *small_streams_pool;
struct dma_pool *medium_streams_pool;
+   struct dma_pool *scratchpad_pool;
 
/* Host controller watchdog timer structures */
unsigned intxhc_state;
-- 
2.7.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


Re: [PATCH] usb: musb: fix possible spinlock deadlock

2017-03-28 Thread Greg KH
On Tue, Mar 28, 2017 at 12:56:34PM -0500, Bin Liu wrote:
> On Tue, Mar 28, 2017 at 07:15:58PM +0200, Greg KH wrote:
> > On Tue, Mar 28, 2017 at 08:45:31AM -0500, Bin Liu wrote:
> > > commit bc1e2154542071e3cfe1734b143af9b8bdacf8bd upstream.
> > > 
> > > The DSPS glue calls del_timer_sync() in its musb_platform_disable()
> > > implementation, which requires the caller to not hold a lock. But
> > > musb_remove() calls musb_platform_disable() will musb->lock held. This
> > > could causes spinlock deadlock.
> > > 
> > > So change musb_remove() to call musb_platform_disable() without holds
> > > musb->lock. This doesn't impact the musb_platform_disable implementation
> > > in other glue drivers.
> > > 
> > > root@am335x-evm:~# modprobe -r musb-dsps
> > > [  126.134879] musb-hdrc musb-hdrc.1: remove, state 1
> > > [  126.140465] usb usb2: USB disconnect, device number 1
> > > [  126.146178] usb 2-1: USB disconnect, device number 2
> > > [  126.416985] musb-hdrc musb-hdrc.1: USB bus 2 deregistered
> > > [  126.423943]
> > > [  126.425525] ==
> > > [  126.431997] [ INFO: possible circular locking dependency detected ]
> > > [  126.438564] 4.11.0-rc1-3-g1557f13bca04-dirty #77 Not tainted
> > > [  126.444852] ---
> > > [  126.451414] modprobe/778 is trying to acquire lock:
> > > [  126.456523]  (((&glue->timer))){+.-...}, at: [] 
> > > del_timer_sync+0x0/0xd0
> > > [  126.464403]
> > > [  126.464403] but task is already holding lock:
> > > [  126.470511]  (&(&musb->lock)->rlock){-.-...}, at: [] 
> > > musb_remove+0x50/0x1
> > > 30 [musb_hdrc]
> > > [  126.479965]
> > > [  126.479965] which lock already depends on the new lock.
> > > [  126.479965]
> > > [  126.488531]
> > > [  126.488531] the existing dependency chain (in reverse order) is:
> > > [  126.496368]
> > > [  126.496368] -> #1 (&(&musb->lock)->rlock){-.-...}:
> > > [  126.502968]otg_timer+0x80/0xec [musb_dsps]
> > > [  126.507990]call_timer_fn+0xb4/0x390
> > > [  126.512372]expire_timers+0xf0/0x1fc
> > > [  126.516754]run_timer_softirq+0x80/0x178
> > > [  126.521511]__do_softirq+0xc4/0x554
> > > [  126.525802]irq_exit+0xe8/0x158
> > > [  126.529735]__handle_domain_irq+0x58/0xb8
> > > [  126.534583]__irq_usr+0x54/0x80
> > > [  126.538507]
> > > [  126.538507] -> #0 (((&glue->timer))){+.-...}:
> > > [  126.544636]del_timer_sync+0x40/0xd0
> > > [  126.549066]musb_remove+0x6c/0x130 [musb_hdrc]
> > > [  126.554370]platform_drv_remove+0x24/0x3c
> > > [  126.559206]device_release_driver_internal+0x14c/0x1e0
> > > [  126.565225]bus_remove_device+0xd8/0x108
> > > [  126.569970]device_del+0x1e4/0x308
> > > [  126.574170]platform_device_del+0x24/0x8c
> > > [  126.579006]platform_device_unregister+0xc/0x20
> > > [  126.584394]dsps_remove+0x14/0x30 [musb_dsps]
> > > [  126.589595]platform_drv_remove+0x24/0x3c
> > > [  126.594432]device_release_driver_internal+0x14c/0x1e0
> > > [  126.600450]driver_detach+0x38/0x6c
> > > [  126.604740]bus_remove_driver+0x4c/0xa0
> > > [  126.609407]SyS_delete_module+0x11c/0x1e4
> > > [  126.614252]__sys_trace_return+0x0/0x10
> > > 
> > > Fixes: ea2f35c01d5ea ("usb: musb: Fix sleeping function called from 
> > > invalid context for hdrc glue")
> > > Cc:  #4.9+
> > > Acked-by: Tony Lindgren 
> > > Signed-off-by: Bin Liu 
> > > Signed-off-by: Greg Kroah-Hartman 
> > > 
> > > Conflicts:
> > >   drivers/usb/musb/musb_core.c
> > 
> > What is this "Conflicts:" line for?
> 
> That was the reason the uptream commit failed to apply to stable
> automatically.
> 
> I am not sure if we want to track it or not, so I leave it here for
> comment.
> 
> Should I remove it?

Yes, please do.  They do not belong in the changelog at all...

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/2] usb: host: xhci: using dma pool for scratchpad buffer

2017-03-28 Thread Felipe Balbi

Hi,

Peter Chen  writes:
> According to xHCI ch4.20 Scratchpad Buffers
>   A Scratchpad Buffer is a PAGESIZE block of system memory
>   located on a PAGESIZE boundary
>   ...
>   Software clears the Scratchpad Buffer to ‘0’
>
> So, we need to use dma pool for PAGESIZE boundary buffer, and zeroed
> its region using dma_pool_zalloc.

you're doing two separate things here...

> Signed-off-by: Peter Chen 
> ---
>  drivers/usb/host/xhci-mem.c | 21 +++--
>  drivers/usb/host/xhci.h |  1 +
>  2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
> index 22a03b7..56aa0a6 100644
> --- a/drivers/usb/host/xhci-mem.c
> +++ b/drivers/usb/host/xhci-mem.c
> @@ -1710,12 +1710,18 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, 
> gfp_t flags)
>   goto fail_sp3;
>  
>   xhci->dcbaa->dev_context_ptrs[0] = 
> cpu_to_le64(xhci->scratchpad->sp_dma);
> +
> + xhci->scratchpad_pool = dma_pool_create("xhci scratchpad buffer pool",
> + dev, xhci->page_size,
> + xhci->page_size, xhci->page_size);

adding a DMA pool here, and ...

> + if (!xhci->scratchpad_pool)
> + goto fail_sp4;
> +
>   for (i = 0; i < num_sp; i++) {
>   dma_addr_t dma;
> - void *buf = dma_alloc_coherent(dev, xhci->page_size, &dma,
> - flags);
> + void *buf = dma_pool_zalloc(xhci->scratchpad_pool, flags, &dma);

... fixing a possible bug here.

-- 
balbi
--
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/4] usb: gadget: udc: renesas_usb3: add sysfs "role" to set "b-device" mode

2017-03-28 Thread Felipe Balbi


Hi,

Yoshihiro Shimoda  writes:
> Hi Felipe-san,
>
>> From: Felipe Balbi, Sent: Tuesday, March 28, 2017 9:06 PM
>> 
>> Hi,
>> 
>> Yoshihiro Shimoda  writes:
>> > Sadly, to change the role ("host" and "peripheral") of USB3.0 DRD
>> > controller on R-Car Gen3, software has to set the DRD_CON register
>> > which is included in a usb3.0 peripheral controler's register.
>> > To simply implementation, the previous code always set peripheral mode
>> > as hardcoded. However, to support usb role swap in the future,
>> > the hardcoded is not good. So, this patch adds sysfs "role" to set
>> > the mode by a user.
>> > After applied this patch, since the DRD controller will act as host
>> > mode after probed, a user needs to change the mode via the sysfs.
>> >
>> > Signed-off-by: Yoshihiro Shimoda 
>> 
>> in patch 3, you add extcon to monitor ID and VBUS pins. Do you really
>> need this sysfs file at all?
>
> Yes. This is because this "role" sysfs file cannot monitor the ID and VBUS 
> pins.
> The "role" only monitors the mode which is "host" or "peripheral".

Right, I understand it can't monitor the state of ID/VBUS, but do you
have a usecase for that file that's not covered by the other patches in
the series? :-)

If you want to force renesas controller to peripheral mode, then
shouldn't you use dr-mode device_property() instead?

-- 
balbi
--
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: [RESEND PATCH v6 4/4] usb: musb: da8xx: Add a primary support of PM runtime

2017-03-28 Thread Sekhar Nori
On Tuesday 28 March 2017 06:09 AM, Kevin Hilman wrote:
> Alexandre Bailon  writes:
> 
>> Currently, MUSB DA8xx glue driver doesn't have PM runtime support.
>> Because the CPPI 4.1 is using the same clock as MUSB DA8xx and
>> CPPI 4.1 is a child of MUSB DA8xx glue, add support of PM runtime
>> to the DA8xx glue driver in order to let the CPPI 4.1 driver manage
>> the clock by using PM runtime.
>>
>> Signed-off-by: Alexandre Bailon 
> 
> Dumb question: even if the clock is shared with cppi4, doesn't the
> use-couting in the clock API handle it so that things should function
> fine even without this patch?
> 
> Some other comments/questions below...
> 
>> ---
>>  drivers/usb/musb/da8xx.c | 27 ---
>>  1 file changed, 8 insertions(+), 19 deletions(-)
>>
>> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
>> index ed28afd..89e12f6 100644
>> --- a/drivers/usb/musb/da8xx.c
>> +++ b/drivers/usb/musb/da8xx.c
>> @@ -30,7 +30,6 @@
>>   */
>>  
>>  #include 
>> -#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -86,7 +85,6 @@ struct da8xx_glue {
>>  struct device   *dev;
>>  struct platform_device  *musb;
>>  struct platform_device  *usb_phy;
>> -struct clk  *clk;
>>  struct phy  *phy;
>>  };
>>  
>> @@ -376,11 +374,7 @@ static int da8xx_musb_init(struct musb *musb)
>>  
>>  musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
>>  
>> -ret = clk_prepare_enable(glue->clk);
>> -if (ret) {
>> -dev_err(glue->dev, "failed to enable clock\n");
>> -return ret;
>> -}
>> +pm_runtime_get_sync(musb->controller->parent);
>>  
>>  /* Returns zero if e.g. not clocked */
>>  rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
>> @@ -423,7 +417,7 @@ static int da8xx_musb_init(struct musb *musb)
>>  err_phy_power_on:
>>  phy_exit(glue->phy);
>>  fail:
>> -clk_disable_unprepare(glue->clk);
>> +pm_runtime_put(musb->controller->parent);
>>  return ret;
>>  }
>>  
>> @@ -435,7 +429,7 @@ static int da8xx_musb_exit(struct musb *musb)
>>  
>>  phy_power_off(glue->phy);
>>  phy_exit(glue->phy);
>> -clk_disable_unprepare(glue->clk);
>> +pm_runtime_put(musb->controller->parent);
>>  
>>  usb_put_phy(musb->xceiv);
>>  
>> @@ -519,7 +513,6 @@ static int da8xx_probe(struct platform_device *pdev)
>>  struct musb_hdrc_platform_data  *pdata = dev_get_platdata(&pdev->dev);
>>  struct da8xx_glue   *glue;
>>  struct platform_device_info pinfo;
>> -struct clk  *clk;
>>  struct device_node  *np = pdev->dev.of_node;
>>  int ret;
>>  
>> @@ -527,12 +520,6 @@ static int da8xx_probe(struct platform_device *pdev)
>>  if (!glue)
>>  return -ENOMEM;
>>  
>> -clk = devm_clk_get(&pdev->dev, "usb20");
>> -if (IS_ERR(clk)) {
>> -dev_err(&pdev->dev, "failed to get clock\n");
>> -return PTR_ERR(clk);
>> -}
> 
> Something isn't quite right here.
> 
> This clk_get uses a con_id "usb20", but when converting to runtime PM,
> we rely on the pm_clk layer (used on davinci for runtime PM) to do clock
> lookups by the default con_ids.  I guess this still probably works
> because we fallback to the NULL con_id.

Right, since DaVinci uses pm_clk layer for runtime PM, we support
runtime PM on only two types of clocks. Those with con_id in the list of
con_ids recognized by pm_clk layer or those with NULL con_id. For
devices which use a single clock, NULL con_id is preferred.

Thanks,
Sekhar
--
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