Re: [PATCH v8 2/4] i2c: add support for Diolan DLN-2 USB-I2C adapter

2014-10-16 Thread Wolfram Sang
On Wed, Oct 15, 2014 at 05:48:09PM +0300, Octavian Purdila wrote:
 From: Laurentiu Palcu laurentiu.pa...@intel.com
 
 This patch adds support for the Diolan DLN-2 I2C master module. Due
 to hardware limitations it does not support SMBUS quick commands.
 
 Information about the USB protocol interface can be found in the
 Programmer's Reference Manual [1], see section 6.2.2 for the I2C
 master module commands and responses.
 
 [1] https://www.diolan.com/downloads/dln-api-manual.pdf
 
 Signed-off-by: Laurentiu Palcu laurentiu.pa...@intel.com
 Signed-off-by: Octavian Purdila octavian.purd...@intel.com

For the I2C part:

Acked-by: Wolfram Sang w...@the-dreams.de

I assume this goes together with the other patches. If I should pick it,
let me know.



signature.asc
Description: Digital signature


Re: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Naveen Kumar Parna
 It's entirely possible that the stall packets are created by the hub.
 When a full-speed device is connected to a USB-2 hub, and the device
 fails to respond to a packet sent by the host, the hub reports this
 failure as a stall.

Here I don’t think device fails to respond to a packet sent by the
host. I verified this by connecting Ellisys USB analyser in between
host and devices.

For example Look at the attached(Sample_HciEvt.png) HCI event captured
by Ellisys USB analyser. It is a valid HCI event from device to Host.
IN transaction 96 1 ACK FS 16 bytes (FF 2F C2 01 00 17 00 DF 00 01 10
00 00 A9 EE 0F)
IN transaction 96 1 ACK FS 16 bytes (00 00 00 5A 06 9D 39 00 00 66 00
00 00 00 00 00)
IN transaction 96 1 ACK FS 16 bytes (00 00 00 00 00 00 00 00 00 00 00
8E 05 28 00 01)
IN transaction 96 1 ACK FS 1 byte (00)

Due to spurious stall packets , sometimes btusb driver is not
receiving this full event , instead it got STALL packet instead of
first 16 bytes plus rest of other 33 bytes.



 When the device is connected to an OHCI controller, such failures would
 be reported in a different way, such as a -EPROTO or -EILSEQ status.


I did not observed -EPROTO or -EILSEQ status in OHCI controller scenario.

Thanks,
Naveen


[PATCH v2 1/2] usb: dwc2: gadget: modify return statement

2014-10-16 Thread Sudip Mukherjee
modified the function to have a single return statement at the end
instead of multiple return statement in the middle of the function
to improve the readability of the code.

Signed-off-by: Sudip Mukherjee su...@vectorindia.org
---
 drivers/usb/dwc2/gadget.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7b5856f..af5517f 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
dir_in = (desc-bEndpointAddress  USB_ENDPOINT_DIR_MASK) ? 1 : 0;
if (dir_in != hs_ep-dir_in) {
dev_err(hsotg-dev, %s: direction mismatch!\n, __func__);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto error1;
}
 
mps = usb_endpoint_maxp(desc);
@@ -2561,8 +2562,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
hs_ep-fifo_size = val;
break;
}
-   if (i == 8)
-   return -ENOMEM;
+   if (i == 8) {
+   ret = -ENOMEM;
+   goto error1;
+   }
}
 
/* for non control endpoints, set PID to D0 */
@@ -2580,6 +2583,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
 
spin_unlock_irqrestore(hsotg-lock, flags);
+
+error1:
return ret;
 }
 
-- 
1.8.1.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 v2 2/2] usb: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Sudip Mukherjee
sparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic block

we were returning ENOMEM while still holding the spinlock.
The sparse warning was fixed by releasing the spinlock before return.

This patch depends on the previous patch of the series.

Signed-off-by: Sudip Mukherjee su...@vectorindia.org
---
 drivers/usb/dwc2/gadget.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index af5517f..05a9a23 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2564,7 +2564,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
}
if (i == 8) {
ret = -ENOMEM;
-   goto error1;
+   goto error2;
}
}
 
@@ -2582,6 +2582,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
/* enable the endpoint interrupt */
s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
 
+error2:
spin_unlock_irqrestore(hsotg-lock, flags);
 
 error1:
-- 
1.8.1.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 00/25] cleanup unnecessary 'out of memory' messages for usb

2014-10-16 Thread Greg KH
On Tue, Oct 14, 2014 at 09:27:40AM -0500, Felipe Balbi wrote:
 On Tue, Oct 14, 2014 at 10:08:39AM +0200, Greg KH wrote:
  On Tue, Oct 14, 2014 at 03:55:54PM +0800, Peter Chen wrote:
   Hi Greg,
   
   Fabio Estevam posted the similar patches for chipidea, I think the cleanup
   may also be benefix for the whole usb driver, the idea of this cleanup
   is from:
   
   commit ebfdc40969f24fc0cdd1349835d36e8ebae05374
   Author: Joe Perches j...@perches.com
   Date:   Wed Aug 6 16:10:27 2014 -0700
   
   checkpatch: attempt to find unnecessary 'out of memory' messages
   
   Logging messages that show some type of out of memory error are
   generally unnecessary as there is a generic message and a stack dump
   done by the memory subsystem.
 
   These messages generally increase kernel size without much added 
   value.
   
  
  I have no objection to them, but can't add them to my tree until after
  3.18-rc1 is out, so it will have to wait a week or so.
 
 If you don't mind, I'll take gadget, musb, dwc3, dwc2 and phy.

I don't mind at all.
--
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: XHCI max scratchpad buffers seem to differ from specification

2014-10-16 Thread Daniel Karling

 That must be a relatively recent addition to the spec. In the original
 v1.0 spec, only bits 31:27 are specified for this.

 --
 Paul


That explains it, thanks. I could only find v1.1 when I noticed this.
--
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: FTDI driver in Linux

2014-10-16 Thread Victor Ashik

Please check below

15.10.2014 18:00, Johan Hovold пишет:

[ Adding linux-usb to CC. ]

On Wed, Oct 15, 2014 at 03:55:15PM +0400, Victor Ashik wrote:

Hello Johan,

Sorry for asking you directly, I found your address in the top comment of
ftdi_sio.c in Linux sources.  I think that you know a short answer to my
question. Sorry for a long explanation below, I am trying to be as specific
as possible.

I am trying to get my decade-old FTDI 8U100AX-based USB-serial converter
working with Linux. I checked that it works with NetBSD and does not work
with Linux.

On Linux I see error messages in dmesg:
[53627.263480] ftdi_sio ttyUSB0: Unable to read latency timer: -32
[53627.264295] ftdi_sio ttyUSB0: Unable to write latency timer: -32


The driver should still work even if the device doesn't support setting
the latency timer.


RX/DX leds on connected via USB-Serial analog modem are blinking very fast
and I do not get correct response from the modem to AT commands.

I am trying to realize what is going on by looking at the code. I found
that my defice may require the extra byte transmitted with the data:

https://github.com/juanfra684/netbsd-src/blob/b00c2cff78f467ead9e6468be4379e23bfc8c33f/sys/dev/usb/uftdi.c#L221

  Was that this support dropped from the code? Or was it there at all?

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/serial/ftdi_sio.c?id=refs/tags/v3.17#n1915


No, we're still supposed to support the legacy SIO type of devices,
although that code doesn't get much testing I'm afraid.

But let's start with verifying that the type is actually detected.

Could you post the kernel log from when plugging the device in along
with the lsusb -v output for it?

[83986.455025] usb 1-1.2: New USB device found, idVendor=0403, 
idProduct=8372
[83986.455029] usb 1-1.2: New USB device strings: Mfr=1, Product=2, 
SerialNumber=3

[83986.455031] usb 1-1.2: Product: USB Serial Converter
[83986.455032] usb 1-1.2: Manufacturer: FTDI
[83986.455033] usb 1-1.2: SerialNumber: FT00026B
[83986.472948] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[83986.472972] usb 1-1.2: Detected SIO
[83986.472974] usb 1-1.2: Number of endpoints 2
[83986.472975] usb 1-1.2: Endpoint 1 MaxPacketSize 64
[83986.472976] usb 1-1.2: Endpoint 2 MaxPacketSize 64
[83986.472977] usb 1-1.2: Setting MaxPacketSize 64
[83986.473150] ftdi_sio ttyUSB0: Unable to read latency timer: -32
[83986.473626] ftdi_sio ttyUSB0: Unable to write latency timer: -32
[83986.473673] usb 1-1.2: FTDI USB Serial Device converter now attached 
to ttyUSB0


 Bus 001 Device 010: ID 0403:8372 Future Technology Devices 
International, Ltd FT8U100AX Serial Port

Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   1.10
  bDeviceClass0 (Defined at Interface level)
  bDeviceSubClass 0
  bDeviceProtocol 0
  bMaxPacketSize0 8
  idVendor   0x0403 Future Technology Devices International, Ltd
  idProduct  0x8372 FT8U100AX Serial Port
  bcdDevice0.01
  iManufacturer   1
  iProduct2
  iSerial 3
  bNumConfigurations  1
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   32
bNumInterfaces  1
bConfigurationValue 1
iConfiguration  2
bmAttributes 0x20
  (Missing must-be-set bit!)
  (Bus Powered)
  Remote Wakeup
MaxPower   60mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   2
  bInterfaceClass   255 Vendor Specific Class
  bInterfaceSubClass255 Vendor Specific Subclass
  bInterfaceProtocol255 Vendor Specific Protocol
  iInterface  2
  iInterface  2
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82  EP 2 IN
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0040  1x 64 bytes
bInterval   0
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02  EP 2 OUT
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0040  1x 64 bytes
bInterval   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: FTDI driver in Linux

2014-10-16 Thread Johan Hovold
On Thu, Oct 16, 2014 at 12:47:05PM +0400, Victor Ashik wrote:
  Wed, Oct 15, 2014 at 6:00 PM, Johan Hovold jo...@kernel.org wrote:

  No, we're still supposed to support the legacy SIO type of devices,
  although that code doesn't get much testing I'm afraid.
 
  But let's start with verifying that the type is actually detected.
 
  Could you post the kernel log from when plugging the device in along
  with the lsusb -v output for it?
 
 [83986.455025] usb 1-1.2: New USB device found, idVendor=0403,
 idProduct=8372
 [83986.455029] usb 1-1.2: New USB device strings: Mfr=1, Product=2,
 SerialNumber=3
 [83986.455031] usb 1-1.2: Product: USB Serial Converter
 [83986.455032] usb 1-1.2: Manufacturer: FTDI
 [83986.455033] usb 1-1.2: SerialNumber: FT00026B
 [83986.472948] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
 [83986.472972] usb 1-1.2: Detected SIO

So the type is indeed detected correctly.

 [83986.472974] usb 1-1.2: Number of endpoints 2
 [83986.472975] usb 1-1.2: Endpoint 1 MaxPacketSize 64
 [83986.472976] usb 1-1.2: Endpoint 2 MaxPacketSize 64
 [83986.472977] usb 1-1.2: Setting MaxPacketSize 64
 [83986.473150] ftdi_sio ttyUSB0: Unable to read latency timer: -32
 [83986.473626] ftdi_sio ttyUSB0: Unable to write latency timer: -32
 [83986.473673] usb 1-1.2: FTDI USB Serial Device converter now attached to
 ttyUSB0

Are you able to verify if rx or tx works separately, e.g. by connecting
to a working serial port and setting up two terminal sessions? Remember
to try with flow control disabled on both ends as well.

Also could you post a log from when opening, reading/writing and closing
the device? Make sure to enable debugging in usb-serial core as well.
Using echo and cat (e.g. echo hello /dev/ttyUSB0) can suffice as
long the port has been properly set up.

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


Re: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Oliver Neukum
On Wed, 2014-10-15 at 12:11 -0400, Alan Stern wrote:
  If the hub is the problem… what will be the better solution? Is it
  possible to change internal hub?
 
 No, it is not possible.

Indeed. However, it is possible to use an additional in between your
devices and the internal hub.

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 0/7] Equivalent of g_midi with configfs

2014-10-16 Thread Andrzej Pietrasiewicz
This series aims at integrating configfs into hid, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,
mass_storage, FunctionFS, loopback, sourcesink, uac1, uac2, uvc and hid.
It concludes converting functions explicitly available as f_xyz.c files
to configfs.

Rebased onto Felipe's testing/next.

Since Felipe has closed his tree for 3.18, this is meant for 3.19.

BACKWARD COMPATIBILITY
==

Please note that the old g_midi.ko is still available and works.

USING THE NEW GADGET
==

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based
gadgets (*).

With configfs the procedure is as follows, compared to the information
mentioned above (*):

instead of mkdir functions/acm.ttyS1 do

mkdir functions/hid.instance name

e.g. mkdir functions/midi.usb0.

In the midi.usb0 directory there will be the following attributes:

buflen  - MIDI buffer length
id  - ID string for the USB MIDI adapter
in_ports- number of MIDI input ports
index   - index value for the USB MIDI adapter
out_ports   - number of MIDI output ports
qlen- USB read request queue length

Below is a script which creates a midi gadget:

# modprobe libcomposite
# mount none cfg -t configfs
# mkdir cfg/usb_gadget/g1
# cd cfg/usb_gadget/g1
# mkdir configs/c.1
# mkdir functions/midi.usb0
# mkdir strings/0x409
# mkdir configs/c.1/strings/0x409
# echo 0x0004  idProduct
# echo 0x17b3  idVendor
# echo serial  strings/0x409/serialnumber
# echo manufacturer  strings/0x409/manufacturer
# echo MIDI Gadget  strings/0x409/product
# echo Conf 1  configs/c.1/strings/0x409/configuration
# echo 120  configs/c.1/MaxPower
# ln -s functions/midi.usb0 configs/c.1
# echo 1248.hsotg  UDC

TESTING THE FUNCTION


Run the gadget as above. There are two cases: playing a mid from the gadget to
the host and playing a mid from the host to the gadget.

1) Playing a mid from the gadget to the host
host)

$ arecordmidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1
$ arecordmidi -p 24:0 from_gadget.mid

gadget)

$ aplaymidi -l
 PortClient name  Port name
 20:0f_midi   f_midi

$ aplaymidi -p 20:0 to_host.mid

2) Playing a mid from the host to the gadget
gadget)

$ arecordmidi -l
 PortClient name  Port name
 20:0f_midi   f_midi

$ arecordmidi -p 20:0 from_host.mid

host)

$ aplaymidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1

$ aplaymidi -p24:0 to_gadget.mid

The from_gadget.mid should sound identical to the to_host.mid.
The from_host.id should sound identical to the to_gadget.mid.

MIDI files can be played to speakers/headphones with e.g. timidity installed

$ aplaymidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1
128:0TiMidity TiMidity port 0
128:1TiMidity TiMidity port 1
128:2TiMidity TiMidity port 2
128:3TiMidity TiMidity port 3

$ aplaymidi -p 128:0 file.mid

MIDI ports can be logically connected using the aconnect utility, e.g.:

$ aconnect 24:0 128:0 # try it on the host

After the gadget's MIDI port is connected to timidity's MIDI port,
whatever is played at the gadget side with aplaymidi -l is audible
in host's speakers/headphones.

Andrzej Pietrasiewicz (7):
  usb: gadget: f_midi: enable use of the index parameter
  usb: gadget: f_midi: check kstrdup() return value
  usb: gadget: f_midi: convert to new function interface with backward
compatibility
  usb: gadget: midi: convert to new interface of f_midi
  usb: gadget: f_midi: remove compatibility layer
  usb: gadget: f_midi: use usb_gstrings_attach
  usb: gadget: f_midi: add configfs support

 Documentation/ABI/testing/configfs-usb-gadget-midi |  12 +
 drivers/usb/gadget/Kconfig |  16 +
 drivers/usb/gadget/function/Makefile   |   2 +
 drivers/usb/gadget/function/f_midi.c   | 364 -
 drivers/usb/gadget/function/u_midi.h   |  40 +++
 drivers/usb/gadget/legacy/Kconfig  |   1 +
 drivers/usb/gadget/legacy/gmidi.c  |  43 ++-
 7 files changed, 382 insertions(+), 96 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi
 create mode 100644 drivers/usb/gadget/function/u_midi.h

-- 
1.9.1

--
To unsubscribe 

[PATCH 3/7] usb: gadget: f_midi: convert to new function interface with backward compatibility

2014-10-16 Thread Andrzej Pietrasiewicz
Converting midi to the new function interface requires converting
the USB midi's function code and its users.

This patch converts the f_midi.c to the new function interface.
The file can now be compiled into a separate usb_f_midi.ko module.

The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/Kconfig   |   3 +
 drivers/usb/gadget/function/Makefile |   2 +
 drivers/usb/gadget/function/f_midi.c | 147 +--
 drivers/usb/gadget/function/u_midi.h |  32 
 drivers/usb/gadget/legacy/gmidi.c|   1 +
 5 files changed, 179 insertions(+), 6 deletions(-)
 create mode 100644 drivers/usb/gadget/function/u_midi.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index c4880fc..9815237 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -190,6 +190,9 @@ config USB_F_UAC2
 config USB_F_UVC
tristate
 
+config USB_F_MIDI
+   tristate
+
 choice
tristate USB Gadget Drivers
default USB_ETH
diff --git a/drivers/usb/gadget/function/Makefile 
b/drivers/usb/gadget/function/Makefile
index 90701aa..576eea5 100644
--- a/drivers/usb/gadget/function/Makefile
+++ b/drivers/usb/gadget/function/Makefile
@@ -38,3 +38,5 @@ usb_f_uac2-y  := f_uac2.o
 obj-$(CONFIG_USB_F_UAC2)   += usb_f_uac2.o
 usb_f_uvc-y:= f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o
 obj-$(CONFIG_USB_F_UVC)+= usb_f_uvc.o
+usb_f_midi-y   := f_midi.o
+obj-$(CONFIG_USB_F_MIDI)   += usb_f_midi.o
diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index a920eee..f3e7d95 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -20,6 +20,7 @@
  */
 
 #include linux/kernel.h
+#include linux/module.h
 #include linux/slab.h
 #include linux/device.h
 
@@ -33,6 +34,7 @@
 #include linux/usb/midi.h
 
 #include u_f.h
+#include u_midi.h
 
 MODULE_AUTHOR(Ben Williamson);
 MODULE_LICENSE(GPL v2);
@@ -99,7 +101,7 @@ DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
 DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16);
 
 /* B.3.1  Standard AC Interface Descriptor */
-static struct usb_interface_descriptor ac_interface_desc __initdata = {
+static struct usb_interface_descriptor ac_interface_desc = {
.bLength =  USB_DT_INTERFACE_SIZE,
.bDescriptorType =  USB_DT_INTERFACE,
/* .bInterfaceNumber =  DYNAMIC */
@@ -110,7 +112,7 @@ static struct usb_interface_descriptor ac_interface_desc 
__initdata = {
 };
 
 /* B.3.2  Class-Specific AC Interface Descriptor */
-static struct uac1_ac_header_descriptor_1 ac_header_desc __initdata = {
+static struct uac1_ac_header_descriptor_1 ac_header_desc = {
.bLength =  UAC_DT_AC_HEADER_SIZE(1),
.bDescriptorType =  USB_DT_CS_INTERFACE,
.bDescriptorSubtype =   USB_MS_HEADER,
@@ -121,7 +123,7 @@ static struct uac1_ac_header_descriptor_1 ac_header_desc 
__initdata = {
 };
 
 /* B.4.1  Standard MS Interface Descriptor */
-static struct usb_interface_descriptor ms_interface_desc __initdata = {
+static struct usb_interface_descriptor ms_interface_desc = {
.bLength =  USB_DT_INTERFACE_SIZE,
.bDescriptorType =  USB_DT_INTERFACE,
/* .bInterfaceNumber =  DYNAMIC */
@@ -132,7 +134,7 @@ static struct usb_interface_descriptor ms_interface_desc 
__initdata = {
 };
 
 /* B.4.2  Class-Specific MS Interface Descriptor */
-static struct usb_ms_header_descriptor ms_header_desc __initdata = {
+static struct usb_ms_header_descriptor ms_header_desc = {
.bLength =  USB_DT_MS_HEADER_SIZE,
.bDescriptorType =  USB_DT_CS_INTERFACE,
.bDescriptorSubtype =   USB_MS_HEADER,
@@ -387,6 +389,7 @@ static void f_midi_disable(struct usb_function *f)
usb_ep_disable(midi-out_ep);
 }
 
+#ifdef USBF_MIDI_INCLUDED
 static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
 {
struct usb_composite_dev *cdev = f-config-cdev;
@@ -409,6 +412,7 @@ static void f_midi_unbind(struct usb_configuration *c, 
struct usb_function *f)
usb_free_all_descriptors(f);
kfree(midi);
 }
+#endif
 
 static int f_midi_snd_free(struct snd_device *device)
 {
@@ -729,8 +733,7 @@ fail:
 
 /* MIDI function driver setup/binding */
 
-static int __init
-f_midi_bind(struct usb_configuration *c, struct usb_function *f)
+static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
 {
struct usb_descriptor_header **midi_function;
struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS];
@@ -741,6 +744,14 @@ f_midi_bind(struct usb_configuration *c, struct 
usb_function *f)
struct f_midi *midi = func_to_midi(f);
int status, n, jack = 1, i = 0;
 
+#ifndef 

[PATCH 5/7] usb: gadget: f_midi: remove compatibility layer

2014-10-16 Thread Andrzej Pietrasiewicz
There are no old f_midi interface users left, so remove it.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 122 ---
 1 file changed, 122 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index f3e7d95..5cd77be 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -389,31 +389,6 @@ static void f_midi_disable(struct usb_function *f)
usb_ep_disable(midi-out_ep);
 }
 
-#ifdef USBF_MIDI_INCLUDED
-static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-   struct usb_composite_dev *cdev = f-config-cdev;
-   struct f_midi *midi = func_to_midi(f);
-   struct snd_card *card;
-
-   DBG(cdev, unbind\n);
-
-   /* just to be sure */
-   f_midi_disable(f);
-
-   card = midi-card;
-   midi-card = NULL;
-   if (card)
-   snd_card_free(card);
-
-   kfree(midi-id);
-   midi-id = NULL;
-
-   usb_free_all_descriptors(f);
-   kfree(midi);
-}
-#endif
-
 static int f_midi_snd_free(struct snd_device *device)
 {
return 0;
@@ -744,14 +719,12 @@ static int f_midi_bind(struct usb_configuration *c, 
struct usb_function *f)
struct f_midi *midi = func_to_midi(f);
int status, n, jack = 1, i = 0;
 
-#ifndef USBF_MIDI_INCLUDED
midi-gadget = cdev-gadget;
tasklet_init(midi-tasklet, f_midi_in_tasklet, (unsigned long) midi);
status = f_midi_register_card(midi);
if (status  0)
goto fail_register;
 
-#endif
/* maybe allocate device-global string ID */
if (midi_string_defs[0].id == 0) {
status = usb_string_id(c-cdev);
@@ -908,10 +881,8 @@ fail_f_midi:
kfree(midi_function);
usb_free_descriptors(f-hs_descriptors);
 fail:
-#ifndef USBF_MIDI_INCLUDED
f_midi_unregister_card(midi);
 fail_register:
-#endif
/* we might as well release our claims on endpoints */
if (midi-out_ep)
midi-out_ep-driver_data = NULL;
@@ -923,98 +894,6 @@ fail_register:
return status;
 }
 
-#ifdef USBF_MIDI_INCLUDED
-/**
- * f_midi_bind_config - add USB MIDI function to a configuration
- * @c: the configuration to supcard the USB audio function
- * @index: the soundcard index to use for the ALSA device creation
- * @id: the soundcard id to use for the ALSA device creation
- * @buflen: the buffer length to use
- * @qlen the number of read requests to pre-allocate
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- */
-int __init f_midi_bind_config(struct usb_configuration *c,
- int index, char *id,
- unsigned int in_ports,
- unsigned int out_ports,
- unsigned int buflen,
- unsigned int qlen)
-{
-   struct f_midi *midi;
-   int status, i;
-
-   /* sanity check */
-   if (in_ports  MAX_PORTS || out_ports  MAX_PORTS)
-   return -EINVAL;
-
-   /* allocate and initialize one new instance */
-   midi = kzalloc(sizeof *midi, GFP_KERNEL);
-   if (!midi) {
-   status = -ENOMEM;
-   goto fail;
-   }
-
-   for (i = 0; i  in_ports; i++) {
-   struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL);
-   if (!port) {
-   status = -ENOMEM;
-   goto setup_fail;
-   }
-
-   port-midi = midi;
-   port-active = 0;
-   port-cable = i;
-   midi-in_port[i] = port;
-   }
-
-   midi-gadget = c-cdev-gadget;
-   tasklet_init(midi-tasklet, f_midi_in_tasklet, (unsigned long) midi);
-
-   /* set up ALSA midi devices */
-   midi-in_ports = in_ports;
-   midi-out_ports = out_ports;
-   midi-index = index;
-   status = f_midi_register_card(midi);
-   if (status  0)
-   goto setup_fail;
-
-   midi-func.name= gmidi function;
-   midi-func.strings = midi_strings;
-   midi-func.bind= f_midi_bind;
-   midi-func.unbind  = f_midi_unbind;
-   midi-func.set_alt = f_midi_set_alt;
-   midi-func.disable = f_midi_disable;
-
-   midi-id = kstrdup(id, GFP_KERNEL);
-   if (id  !midi-id) {
-   status = -ENOMEM;
-   goto kstrdup_fail;
-   }
-   midi-buflen = buflen;
-   midi-qlen = qlen;
-
-   status = usb_add_function(c, midi-func);
-   if (status)
-   goto add_fail;
-
-   return 0;
-
-add_fail:
-   kfree(midi-id);
-kstrdup_fail:
-   f_midi_unregister_card(midi);
-setup_fail:
-   for (--i; i = 0; i--)
-   kfree(midi-in_port[i]);
-   kfree(midi);
-fail:
-   return status;
-}
-
-#else
-
 static void 

[PATCH 4/7] usb: gadget: midi: convert to new interface of f_midi

2014-10-16 Thread Andrzej Pietrasiewicz
Use the new f_midi interface so that the old can be removed.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/legacy/Kconfig |  1 +
 drivers/usb/gadget/legacy/gmidi.c | 44 ---
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/legacy/Kconfig 
b/drivers/usb/gadget/legacy/Kconfig
index 24392d2..8011b19 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -287,6 +287,7 @@ config USB_MIDI_GADGET
depends on SND
select USB_LIBCOMPOSITE
select SND_RAWMIDI
+   select USB_F_MIDI
help
  The MIDI Gadget acts as a USB Audio device, with one MIDI
  input and one MIDI output. These MIDI jacks appear as
diff --git a/drivers/usb/gadget/legacy/gmidi.c 
b/drivers/usb/gadget/legacy/gmidi.c
index f704c55..0d01e46 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -37,8 +37,7 @@
 
 #include gadget_chips.h
 
-#define USBF_MIDI_INCLUDED
-#include f_midi.c
+#include u_midi.h
 
 /*-*/
 
@@ -116,8 +115,13 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
+struct usb_function_instance *fi_midi;
+struct usb_function *f_midi;
+
 static int __exit midi_unbind(struct usb_composite_dev *dev)
 {
+   usb_put_function(f_midi);
+   usb_put_function_instance(fi_midi);
return 0;
 }
 
@@ -131,28 +135,54 @@ static struct usb_configuration midi_config = {
 
 static int __init midi_bind_config(struct usb_configuration *c)
 {
-   return f_midi_bind_config(c, index, id,
- in_ports, out_ports,
- buflen, qlen);
+   int status;
+
+   f_midi = usb_get_function(fi_midi);
+   if (IS_ERR(f_midi))
+   return PTR_ERR(f_midi);
+
+   status = usb_add_function(c, f_midi);
+   if (status  0) {
+   usb_put_function(f_midi);
+   return status;
+   }
+
+   return 0;
 }
 
 static int __init midi_bind(struct usb_composite_dev *cdev)
 {
+   struct f_midi_opts *midi_opts;
int status;
 
+   fi_midi = usb_get_function_instance(midi);
+   if (IS_ERR(fi_midi))
+   return PTR_ERR(fi_midi);
+
+   midi_opts = container_of(fi_midi, struct f_midi_opts, func_inst);
+   midi_opts-index = index;
+   midi_opts-id = id;
+   midi_opts-in_ports = in_ports;
+   midi_opts-out_ports = out_ports;
+   midi_opts-buflen = buflen;
+   midi_opts-qlen = qlen;
+
status = usb_string_ids_tab(cdev, strings_dev);
if (status  0)
-   return status;
+   goto put;
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
 
status = usb_add_config(cdev, midi_config, midi_bind_config);
if (status  0)
-   return status;
+   goto put;
usb_composite_overwrite_options(cdev, coverwrite);
pr_info(%s\n, longname);
return 0;
+put:
+   usb_put_function_instance(fi_midi);
+   return status;
 }
 
 static __refdata struct usb_composite_driver midi_driver = {
-- 
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 2/7] usb: gadget: f_midi: check kstrdup() return value

2014-10-16 Thread Andrzej Pietrasiewicz
kstrdup() might fail, so check its return value and react appropriately.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index bf32957..a920eee 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -654,6 +654,14 @@ static struct snd_rawmidi_ops gmidi_out_ops = {
.trigger = f_midi_out_trigger
 };
 
+static inline void f_midi_unregister_card(struct f_midi *midi)
+{
+   if (midi-card) {
+   snd_card_free(midi-card);
+   midi-card = NULL;
+   }
+}
+
 /* register as a sound card */
 static int f_midi_register_card(struct f_midi *midi)
 {
@@ -715,10 +723,7 @@ static int f_midi_register_card(struct f_midi *midi)
return 0;
 
 fail:
-   if (midi-card) {
-   snd_card_free(midi-card);
-   midi-card = NULL;
-   }
+   f_midi_unregister_card(midi);
return err;
 }
 
@@ -967,15 +972,23 @@ int __init f_midi_bind_config(struct usb_configuration *c,
midi-func.disable = f_midi_disable;
 
midi-id = kstrdup(id, GFP_KERNEL);
+   if (id  !midi-id) {
+   status = -ENOMEM;
+   goto kstrdup_fail;
+   }
midi-buflen = buflen;
midi-qlen = qlen;
 
status = usb_add_function(c, midi-func);
if (status)
-   goto setup_fail;
+   goto add_fail;
 
return 0;
 
+add_fail:
+   kfree(midi-id);
+kstrdup_fail:
+   f_midi_unregister_card(midi);
 setup_fail:
for (--i; i = 0; i--)
kfree(midi-in_port[i]);
-- 
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 6/7] usb: gadget: f_midi: use usb_gstrings_attach

2014-10-16 Thread Andrzej Pietrasiewicz
In order to add configfs support the usb_gstrings_attach must be used.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index 5cd77be..ec2a9ce 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -717,6 +717,7 @@ static int f_midi_bind(struct usb_configuration *c, struct 
usb_function *f)
struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc[MAX_PORTS];
struct usb_composite_dev *cdev = c-cdev;
struct f_midi *midi = func_to_midi(f);
+   struct usb_string *us;
int status, n, jack = 1, i = 0;
 
midi-gadget = cdev-gadget;
@@ -726,12 +727,13 @@ static int f_midi_bind(struct usb_configuration *c, 
struct usb_function *f)
goto fail_register;
 
/* maybe allocate device-global string ID */
-   if (midi_string_defs[0].id == 0) {
-   status = usb_string_id(c-cdev);
-   if (status  0)
-   goto fail;
-   midi_string_defs[0].id = status;
+   us = usb_gstrings_attach(c-cdev, midi_strings,
+ARRAY_SIZE(midi_string_defs));
+   if (IS_ERR(us)) {
+   status = PTR_ERR(us);
+   goto fail;
}
+   ac_interface_desc.iInterface = us[STRING_FUNC_IDX].id;
 
/* We have two interfaces, AudioControl and MIDIStreaming */
status = usb_interface_id(c, f);
@@ -991,7 +993,6 @@ struct usb_function *f_midi_alloc(struct 
usb_function_instance *fi)
midi-qlen = opts-qlen;
 
midi-func.name = gmidi function;
-   midi-func.strings  = midi_strings;
midi-func.bind = f_midi_bind;
midi-func.unbind   = f_midi_unbind;
midi-func.set_alt  = f_midi_set_alt;
-- 
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/7] usb: gadget: f_midi: enable use of the index parameter

2014-10-16 Thread Andrzej Pietrasiewicz
The soundcard index to use for the ALSA device creation is passed as a
parameter to f_midi_bind_config(), but is assigned to midi-index only
after the call to f_midi_register_card(midi). So no matter what is passed
to f_midi_bind_config(), the actual index for snd_card_new() is always 0.
This probably works ok if at the moment of f_midi's bind there are no
other snd_cards, but if there are, it is not possible to bind f_midi.

This patch moves the assignment to a place before the call to
f_midi_register_card(midi).

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index 807b31c..bf32957 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -954,6 +954,7 @@ int __init f_midi_bind_config(struct usb_configuration *c,
/* set up ALSA midi devices */
midi-in_ports = in_ports;
midi-out_ports = out_ports;
+   midi-index = index;
status = f_midi_register_card(midi);
if (status  0)
goto setup_fail;
@@ -966,7 +967,6 @@ int __init f_midi_bind_config(struct usb_configuration *c,
midi-func.disable = f_midi_disable;
 
midi-id = kstrdup(id, GFP_KERNEL);
-   midi-index = index;
midi-buflen = buflen;
midi-qlen = qlen;
 
-- 
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 7/7] usb: gadget: f_midi: add configfs support

2014-10-16 Thread Andrzej Pietrasiewicz
Make the midi function available for gadgets composed with configfs.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 Documentation/ABI/testing/configfs-usb-gadget-midi |  12 ++
 drivers/usb/gadget/Kconfig |  13 ++
 drivers/usb/gadget/function/f_midi.c   | 161 -
 drivers/usb/gadget/function/u_midi.h   |   8 +
 4 files changed, 192 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-midi 
b/Documentation/ABI/testing/configfs-usb-gadget-midi
new file mode 100644
index 000..6b341df
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-midi
@@ -0,0 +1,12 @@
+What:  /config/usb-gadget/gadget/functions/midi.name
+Date:  Nov 2014
+KernelVersion: 3.19
+Description:
+   The attributes:
+
+   index   - index value for the USB MIDI adapter
+   id  - ID string for the USB MIDI adapter
+   buflen  - MIDI buffer length
+   qlen- USB read request queue length
+   in_ports- number of MIDI input ports
+   out_ports   - number of MIDI output ports
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 9815237..e283046 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -365,6 +365,19 @@ config USB_CONFIGFS_F_FS
  implemented in kernel space (for instance Ethernet, serial or
  mass storage) and other are implemented in user space.
 
+config USB_CONFIGFS_F_MIDI
+   boolean MIDI function
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_RAWMIDI
+   select USB_F_MIDI
+   help
+ The MIDI Function acts as a USB Audio device, with one MIDI
+ input and one MIDI output. These MIDI jacks appear as
+ a sound card in the ALSA sound system. Other MIDI
+ connections can then be made on the gadget system, using
+ ALSA's aconnect utility etc.
+
 source drivers/usb/gadget/legacy/Kconfig
 
 endchoice
diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index ec2a9ce..1f94dad 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -896,12 +896,145 @@ fail_register:
return status;
 }
 
+static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct f_midi_opts,
+   func_inst.group);
+}
+
+CONFIGFS_ATTR_STRUCT(f_midi_opts);
+CONFIGFS_ATTR_OPS(f_midi_opts);
+
+static void midi_attr_release(struct config_item *item)
+{
+   struct f_midi_opts *opts = to_f_midi_opts(item);
+
+   usb_put_function_instance(opts-func_inst);
+}
+
+static struct configfs_item_operations midi_item_ops = {
+   .release= midi_attr_release,
+   .show_attribute = f_midi_opts_attr_show,
+   .store_attribute = f_midi_opts_attr_store,
+};
+
+#define F_MIDI_OPT(name, test_limit, limit)\
+static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) 
\
+{  \
+   int result; \
+   \
+   mutex_lock(opts-lock);\
+   result = sprintf(page, %d\n, opts-name); \
+   mutex_unlock(opts-lock);  \
+   \
+   return result;  \
+}  \
+   \
+static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts,\
+const char *page, size_t len)  \
+{  \
+   int ret;\
+   u32 num;\
+   \
+   mutex_lock(opts-lock);\
+   if (opts-refcnt) { \
+   ret = -EBUSY;   \
+   goto end;   \
+   }   \
+   \
+   ret = kstrtou32(page, 0, num); \
+   if (ret)

Re: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Naveen Kumar Parna
On Thu, Oct 16, 2014 at 2:45 PM, Oliver Neukum oneu...@suse.de wrote:

 On Wed, 2014-10-15 at 12:11 -0400, Alan Stern wrote:
   If the hub is the problem… what will be the better solution? Is it
   possible to change internal hub?
 
  No, it is not possible.

 Indeed. However, it is possible to use an additional in between your
 devices and the internal hub.

 Regards
 Oliver




Tested with this configuration(external hubs Dev 3, Dev 4, Dev 17, Dev
10) and got the same result.

/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M

/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M

|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M

|__ Port 5: Dev 3, If 0, Class=hub, Driver=hub/7p, 12M

|__ Port 1: Dev 4, If 0, Class=hub, Driver=hub/7p, 12M

|__ Port 1: Dev 11, If 0, Class=vend., Driver=, 12M

|__ Port 2: Dev 12, If 0, Class=vend., Driver=, 12M

|__ Port 3: Dev 13, If 0, Class=vend., Driver=, 12M

|__ Port 4: Dev 14, If 0, Class=vend., Driver=, 12M

|__ Port 5: Dev 15, If 0, Class=vend., Driver=, 12M

|__ Port 6: Dev 16, If 0, Class=vend., Driver=, 12M

|__ Port 7: Dev 17, If 0, Class=hub, Driver=hub/2p, 12M

|__ Port 1: Dev 21, If 0, Class=vend., Driver=, 12M

|__ Port 2: Dev 22, If 0, Class=vend., Driver=, 12M

|__ Port 2: Dev 5, If 0, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 2: Dev 5, If 1, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 2: Dev 5, If 2, Class=app., Driver=, 12M

|__ Port 3: Dev 6, If 0, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 3: Dev 6, If 1, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 3: Dev 6, If 2, Class=app., Driver=, 12M

|__ Port 4: Dev 7, If 0, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 4: Dev 7, If 1, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 4: Dev 7, If 2, Class=app., Driver=, 12M

|__ Port 5: Dev 8, If 0, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 5: Dev 8, If 1, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 5: Dev 8, If 2, Class=app., Driver=, 12M

|__ Port 6: Dev 9, If 0, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 6: Dev 9, If 1, Class='bInterfaceClass 0xe0 not
yet handled', Driver=btusb, 12M

|__ Port 6: Dev 9, If 2, Class=app., Driver=, 12M

|__ Port 7: Dev 10, If 0, Class=hub, Driver=hub/3p, 12M

|__ Port 1: Dev 18, If 0, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 1: Dev 18, If 1, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 1: Dev 18, If 2, Class=app., Driver=, 12M

|__ Port 2: Dev 19, If 0, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 2: Dev 19, If 1, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 2: Dev 19, If 2, Class=app., Driver=, 12M

|__ Port 3: Dev 20, If 0, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 3: Dev 20, If 1, Class='bInterfaceClass 0xe0
not yet handled', Driver=btusb, 12M

|__ Port 3: Dev 20, If 2, Class=app., Driver=, 12M
--
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: FTDI driver in Linux

2014-10-16 Thread Victor Ashik

16.10.2014 14:02, Johan Hovold пишет:

On Thu, Oct 16, 2014 at 12:47:05PM +0400, Victor Ashik wrote:

  Wed, Oct 15, 2014 at 6:00 PM, Johan Hovold jo...@kernel.org wrote:



No, we're still supposed to support the legacy SIO type of devices,
although that code doesn't get much testing I'm afraid.

But let's start with verifying that the type is actually detected.

Could you post the kernel log from when plugging the device in along
with the lsusb -v output for it?


[83986.455025] usb 1-1.2: New USB device found, idVendor=0403,
idProduct=8372
[83986.455029] usb 1-1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
[83986.455031] usb 1-1.2: Product: USB Serial Converter
[83986.455032] usb 1-1.2: Manufacturer: FTDI
[83986.455033] usb 1-1.2: SerialNumber: FT00026B
[83986.472948] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[83986.472972] usb 1-1.2: Detected SIO


So the type is indeed detected correctly.


[83986.472974] usb 1-1.2: Number of endpoints 2
[83986.472975] usb 1-1.2: Endpoint 1 MaxPacketSize 64
[83986.472976] usb 1-1.2: Endpoint 2 MaxPacketSize 64
[83986.472977] usb 1-1.2: Setting MaxPacketSize 64
[83986.473150] ftdi_sio ttyUSB0: Unable to read latency timer: -32
[83986.473626] ftdi_sio ttyUSB0: Unable to write latency timer: -32
[83986.473673] usb 1-1.2: FTDI USB Serial Device converter now attached to
ttyUSB0


Are you able to verify if rx or tx works separately, e.g. by connecting
to a working serial port and setting up two terminal sessions? Remember
to try with flow control disabled on both ends as well.

Also could you post a log from when opening, reading/writing and closing
the device? Make sure to enable debugging in usb-serial core as well.
Using echo and cat (e.g. echo hello /dev/ttyUSB0) can suffice as
long the port has been properly set up.


[91798.346109] usbserial: unknown parameter 'debug' ignored
[91798.346489] usbcore: registered new interface driver usbserial
[91798.346512] usbcore: registered new interface driver usbserial_generic
[91798.346531] usbserial: USB Serial support registered for generic
[91803.034148] ftdi_sio: unknown parameter 'debug' ignored
[91803.034572] usbcore: registered new interface driver ftdi_sio
[91803.034695] usbserial: USB Serial support registered for FTDI USB 
Serial Device

[91803.034757] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[91803.034898] usb 1-1.2: Detected SIO
[91803.034901] usb 1-1.2: Number of endpoints 2
[91803.034902] usb 1-1.2: Endpoint 1 MaxPacketSize 64
[91803.034904] usb 1-1.2: Endpoint 2 MaxPacketSize 64
[91803.034906] usb 1-1.2: Setting MaxPacketSize 64
[91803.035940] ftdi_sio ttyUSB0: Unable to read latency timer: -32
[91803.036435] ftdi_sio ttyUSB0: Unable to write latency timer: -32
[91803.036711] usb 1-1.2: FTDI USB Serial Device converter now attached 
to ttyUSB0
[91806.063117] ftdi_sio ttyUSB0: ftdi_set_termios FAILED to set 
databits/stopbits/parity

[91806.063467] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
[91806.063806] ftdi_sio ttyUSB0: urb failed to clear flow control
[91806.064545] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
[91806.064914] ftdi_sio ttyUSB0: urb failed to clear flow control
[91806.065289] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
[91806.065662] ftdi_sio ttyUSB0: urb failed to set to rts/cts flow control
[91806.066036] ftdi_sio ttyUSB0: failed to get modem status: -32
[91806.066414] ftdi_sio ttyUSB0: urb failed to set to rts/cts flow control
[91812.841711] ftdi_sio ttyUSB0: failed to get modem status: -32
[91812.842077] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
[91812.842437] ftdi_sio ttyUSB0: urb failed to clear flow control
[91812.842788] ftdi_sio ttyUSB0: failed to get modem status: -32
[91812.843160] ftdi_sio ttyUSB0: error from flowcontrol urb

--
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: FTDI driver in Linux

2014-10-16 Thread Victor Ashik

16.10.2014 14:02, Johan Hovold пишет:

On Thu, Oct 16, 2014 at 12:47:05PM +0400, Victor Ashik wrote:

  Wed, Oct 15, 2014 at 6:00 PM, Johan Hovold jo...@kernel.org wrote:



No, we're still supposed to support the legacy SIO type of devices,
although that code doesn't get much testing I'm afraid.

But let's start with verifying that the type is actually detected.

Could you post the kernel log from when plugging the device in along
with the lsusb -v output for it?


[83986.455025] usb 1-1.2: New USB device found, idVendor=0403,
idProduct=8372
[83986.455029] usb 1-1.2: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
[83986.455031] usb 1-1.2: Product: USB Serial Converter
[83986.455032] usb 1-1.2: Manufacturer: FTDI
[83986.455033] usb 1-1.2: SerialNumber: FT00026B
[83986.472948] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[83986.472972] usb 1-1.2: Detected SIO


So the type is indeed detected correctly.


[83986.472974] usb 1-1.2: Number of endpoints 2
[83986.472975] usb 1-1.2: Endpoint 1 MaxPacketSize 64
[83986.472976] usb 1-1.2: Endpoint 2 MaxPacketSize 64
[83986.472977] usb 1-1.2: Setting MaxPacketSize 64
[83986.473150] ftdi_sio ttyUSB0: Unable to read latency timer: -32
[83986.473626] ftdi_sio ttyUSB0: Unable to write latency timer: -32
[83986.473673] usb 1-1.2: FTDI USB Serial Device converter now attached to
ttyUSB0


Are you able to verify if rx or tx works separately, e.g. by connecting
to a working serial port and setting up two terminal sessions? Remember
to try with flow control disabled on both ends as well.

Also could you post a log from when opening, reading/writing and closing
the device? Make sure to enable debugging in usb-serial core as well.
Using echo and cat (e.g. echo hello /dev/ttyUSB0) can suffice as
long the port has been properly set up.

I captured a data exchange between NetBSD and a modem via USB, on NetBSD 
I issued commands:


cu -l /dev/ttyUSB0 -s 38400
AT+FCLASS?

and got a resonse:

0

OK

Here is a hex dump of a packet with letter A from host to a device:

   c0 03 12 06 01 88 ff ff 53 03 02 0c 01 00 2d 00  S.-.
0010   95 a1 3f 54 00 00 00 00 2a f4 0d 00 8d ff ff ff  ..?T*...
0020   02 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00  
0030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
0040   05 41.A

This is an echoed A back from the modem:

   c0 03 12 06 01 88 ff ff 43 03 82 0c 01 00 2d 00  C.-.
0010   95 a1 3f 54 00 00 00 00 2a 91 0e 00 00 00 00 00  ..?T*...
0020   03 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00  
0030   00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00  
0040   31 60 41 1`A

Please check the capture file attached.
Hope this helps.


netbsd-modem-AT+FCLASS.pcapng
Description: application/pcapng


[PATCH] usb: gadget: Kconfig: enable separate compilation of uac1/uac2 functions

2014-10-16 Thread Andrzej Pietrasiewicz
uac1 and uac2 functions are available through the configfs interface
and it should be possible to build them without building their legacy
gadgets.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/Kconfig | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index c4880fc..c8a0784 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -362,6 +362,37 @@ config USB_CONFIGFS_F_FS
  implemented in kernel space (for instance Ethernet, serial or
  mass storage) and other are implemented in user space.
 
+config USB_CONFIGFS_F_UAC1
+   boolean Audio Class 1.0
+   depends on USB_CONFIGFS
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_PCM
+   select USB_F_UAC1
+   help
+ This Audio function implements 1 AudioControl interface,
+ 1 AudioStreaming Interface each for USB-OUT and USB-IN.
+ This driver requires a real Audio codec to be present
+ on the device.
+
+config USB_CONFIGFS_F_UAC2
+   boolean Audio Class 2.0
+   depends on USB_CONFIGFS
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_PCM
+   select USB_F_UAC2
+   help
+ This Audio function is compatible with USB Audio Class
+ specification 2.0. It implements 1 AudioControl interface,
+ 1 AudioStreaming Interface each for USB-OUT and USB-IN.
+ This driver doesn't expect any real Audio codec to be present
+ on the device - the audio streams are simply sinked to and
+ sourced from a virtual ALSA sound card created. The user-space
+ application may choose to do whatever it wants with the data
+ received from the USB Host and choose to provide whatever it
+ wants as audio data to the USB Host.
+
 source drivers/usb/gadget/legacy/Kconfig
 
 endchoice
-- 
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


[PATCHv2 1/7] usb: gadget: f_midi: enable use of the index parameter

2014-10-16 Thread Andrzej Pietrasiewicz
The soundcard index to use for the ALSA device creation is passed as a
parameter to f_midi_bind_config(), but is assigned to midi-index only
after the call to f_midi_register_card(midi). So no matter what is passed
to f_midi_bind_config(), the actual index for snd_card_new() is always 0.
This probably works ok if at the moment of f_midi's bind there are no
other snd_cards, but if there are, it is not possible to bind f_midi.

This patch moves the assignment to a place before the call to
f_midi_register_card(midi).

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index 807b31c..bf32957 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -954,6 +954,7 @@ int __init f_midi_bind_config(struct usb_configuration *c,
/* set up ALSA midi devices */
midi-in_ports = in_ports;
midi-out_ports = out_ports;
+   midi-index = index;
status = f_midi_register_card(midi);
if (status  0)
goto setup_fail;
@@ -966,7 +967,6 @@ int __init f_midi_bind_config(struct usb_configuration *c,
midi-func.disable = f_midi_disable;
 
midi-id = kstrdup(id, GFP_KERNEL);
-   midi-index = index;
midi-buflen = buflen;
midi-qlen = qlen;
 
-- 
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


[PATCHv2 0/7] Equivalent of g_midi with configfs

2014-10-16 Thread Andrzej Pietrasiewicz
This series aims at integrating configfs into hid, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,
mass_storage, FunctionFS, loopback, sourcesink, uac1, uac2, uvc and hid.
It concludes converting functions explicitly available as f_xyz.c files
to configfs.

Rebased onto Felipe's testing/next.

Since Felipe has closed his tree for 3.18, this is meant for 3.19.

v1..v2:
-fixed Kconfig entry for standalone function module building

BACKWARD COMPATIBILITY
==

Please note that the old g_midi.ko is still available and works.

USING THE NEW GADGET
==

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based
gadgets (*).

With configfs the procedure is as follows, compared to the information
mentioned above (*):

instead of mkdir functions/acm.ttyS1 do

mkdir functions/hid.instance name

e.g. mkdir functions/midi.usb0.

In the midi.usb0 directory there will be the following attributes:

buflen  - MIDI buffer length
id  - ID string for the USB MIDI adapter
in_ports- number of MIDI input ports
index   - index value for the USB MIDI adapter
out_ports   - number of MIDI output ports
qlen- USB read request queue length

Below is a script which creates a midi gadget:

# modprobe libcomposite
# mount none cfg -t configfs
# mkdir cfg/usb_gadget/g1
# cd cfg/usb_gadget/g1
# mkdir configs/c.1
# mkdir functions/midi.usb0
# mkdir strings/0x409
# mkdir configs/c.1/strings/0x409
# echo 0x0004  idProduct
# echo 0x17b3  idVendor
# echo serial  strings/0x409/serialnumber
# echo manufacturer  strings/0x409/manufacturer
# echo MIDI Gadget  strings/0x409/product
# echo Conf 1  configs/c.1/strings/0x409/configuration
# echo 120  configs/c.1/MaxPower
# ln -s functions/midi.usb0 configs/c.1
# echo 1248.hsotg  UDC

TESTING THE FUNCTION


Run the gadget as above. There are two cases: playing a mid from the gadget to
the host and playing a mid from the host to the gadget.

1) Playing a mid from the gadget to the host
host)

$ arecordmidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1
$ arecordmidi -p 24:0 from_gadget.mid

gadget)

$ aplaymidi -l
 PortClient name  Port name
 20:0f_midi   f_midi

$ aplaymidi -p 20:0 to_host.mid

2) Playing a mid from the host to the gadget
gadget)

$ arecordmidi -l
 PortClient name  Port name
 20:0f_midi   f_midi

$ arecordmidi -p 20:0 from_host.mid

host)

$ aplaymidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1

$ aplaymidi -p24:0 to_gadget.mid

The from_gadget.mid should sound identical to the to_host.mid.
The from_host.id should sound identical to the to_gadget.mid.

MIDI files can be played to speakers/headphones with e.g. timidity installed

$ aplaymidi -l
 PortClient name  Port name
 14:0Midi Through Midi Through Port-0
 24:0MIDI Gadget  MIDI Gadget MIDI 1
128:0TiMidity TiMidity port 0
128:1TiMidity TiMidity port 1
128:2TiMidity TiMidity port 2
128:3TiMidity TiMidity port 3

$ aplaymidi -p 128:0 file.mid

MIDI ports can be logically connected using the aconnect utility, e.g.:

$ aconnect 24:0 128:0 # try it on the host

After the gadget's MIDI port is connected to timidity's MIDI port,
whatever is played at the gadget side with aplaymidi -l is audible
in host's speakers/headphones.

Andrzej Pietrasiewicz (7):
  usb: gadget: f_midi: enable use of the index parameter
  usb: gadget: f_midi: check kstrdup() return value
  usb: gadget: f_midi: convert to new function interface with backward
compatibility
  usb: gadget: midi: convert to new interface of f_midi
  usb: gadget: f_midi: remove compatibility layer
  usb: gadget: f_midi: use usb_gstrings_attach
  usb: gadget: f_midi: add configfs support

 Documentation/ABI/testing/configfs-usb-gadget-midi |  12 +
 drivers/usb/gadget/Kconfig |  17 +
 drivers/usb/gadget/function/Makefile   |   2 +
 drivers/usb/gadget/function/f_midi.c   | 364 -
 drivers/usb/gadget/function/u_midi.h   |  40 +++
 drivers/usb/gadget/legacy/Kconfig  |   1 +
 drivers/usb/gadget/legacy/gmidi.c  |  43 ++-
 7 files changed, 383 insertions(+), 96 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi
 create mode 100644 

[PATCHv2 3/7] usb: gadget: f_midi: convert to new function interface with backward compatibility

2014-10-16 Thread Andrzej Pietrasiewicz
Converting midi to the new function interface requires converting
the USB midi's function code and its users.

This patch converts the f_midi.c to the new function interface.
The file can now be compiled into a separate usb_f_midi.ko module.

The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/Kconfig   |   3 +
 drivers/usb/gadget/function/Makefile |   2 +
 drivers/usb/gadget/function/f_midi.c | 147 +--
 drivers/usb/gadget/function/u_midi.h |  32 
 drivers/usb/gadget/legacy/gmidi.c|   1 +
 5 files changed, 179 insertions(+), 6 deletions(-)
 create mode 100644 drivers/usb/gadget/function/u_midi.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index c4880fc..9815237 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -190,6 +190,9 @@ config USB_F_UAC2
 config USB_F_UVC
tristate
 
+config USB_F_MIDI
+   tristate
+
 choice
tristate USB Gadget Drivers
default USB_ETH
diff --git a/drivers/usb/gadget/function/Makefile 
b/drivers/usb/gadget/function/Makefile
index 90701aa..576eea5 100644
--- a/drivers/usb/gadget/function/Makefile
+++ b/drivers/usb/gadget/function/Makefile
@@ -38,3 +38,5 @@ usb_f_uac2-y  := f_uac2.o
 obj-$(CONFIG_USB_F_UAC2)   += usb_f_uac2.o
 usb_f_uvc-y:= f_uvc.o uvc_queue.o uvc_v4l2.o uvc_video.o
 obj-$(CONFIG_USB_F_UVC)+= usb_f_uvc.o
+usb_f_midi-y   := f_midi.o
+obj-$(CONFIG_USB_F_MIDI)   += usb_f_midi.o
diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index a920eee..f3e7d95 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -20,6 +20,7 @@
  */
 
 #include linux/kernel.h
+#include linux/module.h
 #include linux/slab.h
 #include linux/device.h
 
@@ -33,6 +34,7 @@
 #include linux/usb/midi.h
 
 #include u_f.h
+#include u_midi.h
 
 MODULE_AUTHOR(Ben Williamson);
 MODULE_LICENSE(GPL v2);
@@ -99,7 +101,7 @@ DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
 DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(16);
 
 /* B.3.1  Standard AC Interface Descriptor */
-static struct usb_interface_descriptor ac_interface_desc __initdata = {
+static struct usb_interface_descriptor ac_interface_desc = {
.bLength =  USB_DT_INTERFACE_SIZE,
.bDescriptorType =  USB_DT_INTERFACE,
/* .bInterfaceNumber =  DYNAMIC */
@@ -110,7 +112,7 @@ static struct usb_interface_descriptor ac_interface_desc 
__initdata = {
 };
 
 /* B.3.2  Class-Specific AC Interface Descriptor */
-static struct uac1_ac_header_descriptor_1 ac_header_desc __initdata = {
+static struct uac1_ac_header_descriptor_1 ac_header_desc = {
.bLength =  UAC_DT_AC_HEADER_SIZE(1),
.bDescriptorType =  USB_DT_CS_INTERFACE,
.bDescriptorSubtype =   USB_MS_HEADER,
@@ -121,7 +123,7 @@ static struct uac1_ac_header_descriptor_1 ac_header_desc 
__initdata = {
 };
 
 /* B.4.1  Standard MS Interface Descriptor */
-static struct usb_interface_descriptor ms_interface_desc __initdata = {
+static struct usb_interface_descriptor ms_interface_desc = {
.bLength =  USB_DT_INTERFACE_SIZE,
.bDescriptorType =  USB_DT_INTERFACE,
/* .bInterfaceNumber =  DYNAMIC */
@@ -132,7 +134,7 @@ static struct usb_interface_descriptor ms_interface_desc 
__initdata = {
 };
 
 /* B.4.2  Class-Specific MS Interface Descriptor */
-static struct usb_ms_header_descriptor ms_header_desc __initdata = {
+static struct usb_ms_header_descriptor ms_header_desc = {
.bLength =  USB_DT_MS_HEADER_SIZE,
.bDescriptorType =  USB_DT_CS_INTERFACE,
.bDescriptorSubtype =   USB_MS_HEADER,
@@ -387,6 +389,7 @@ static void f_midi_disable(struct usb_function *f)
usb_ep_disable(midi-out_ep);
 }
 
+#ifdef USBF_MIDI_INCLUDED
 static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
 {
struct usb_composite_dev *cdev = f-config-cdev;
@@ -409,6 +412,7 @@ static void f_midi_unbind(struct usb_configuration *c, 
struct usb_function *f)
usb_free_all_descriptors(f);
kfree(midi);
 }
+#endif
 
 static int f_midi_snd_free(struct snd_device *device)
 {
@@ -729,8 +733,7 @@ fail:
 
 /* MIDI function driver setup/binding */
 
-static int __init
-f_midi_bind(struct usb_configuration *c, struct usb_function *f)
+static int f_midi_bind(struct usb_configuration *c, struct usb_function *f)
 {
struct usb_descriptor_header **midi_function;
struct usb_midi_in_jack_descriptor jack_in_ext_desc[MAX_PORTS];
@@ -741,6 +744,14 @@ f_midi_bind(struct usb_configuration *c, struct 
usb_function *f)
struct f_midi *midi = func_to_midi(f);
int status, n, jack = 1, i = 0;
 
+#ifndef 

[PATCHv2 7/7] usb: gadget: f_midi: add configfs support

2014-10-16 Thread Andrzej Pietrasiewicz
Make the midi function available for gadgets composed with configfs.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 Documentation/ABI/testing/configfs-usb-gadget-midi |  12 ++
 drivers/usb/gadget/Kconfig |  14 ++
 drivers/usb/gadget/function/f_midi.c   | 161 -
 drivers/usb/gadget/function/u_midi.h   |   8 +
 4 files changed, 193 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-midi 
b/Documentation/ABI/testing/configfs-usb-gadget-midi
new file mode 100644
index 000..6b341df
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-midi
@@ -0,0 +1,12 @@
+What:  /config/usb-gadget/gadget/functions/midi.name
+Date:  Nov 2014
+KernelVersion: 3.19
+Description:
+   The attributes:
+
+   index   - index value for the USB MIDI adapter
+   id  - ID string for the USB MIDI adapter
+   buflen  - MIDI buffer length
+   qlen- USB read request queue length
+   in_ports- number of MIDI input ports
+   out_ports   - number of MIDI output ports
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 9815237..9004fcc 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -365,6 +365,20 @@ config USB_CONFIGFS_F_FS
  implemented in kernel space (for instance Ethernet, serial or
  mass storage) and other are implemented in user space.
 
+config USB_CONFIGFS_F_MIDI
+   boolean MIDI function
+   depends on USB_CONFIGFS
+   depends on SND
+   select USB_LIBCOMPOSITE
+   select SND_RAWMIDI
+   select USB_F_MIDI
+   help
+ The MIDI Function acts as a USB Audio device, with one MIDI
+ input and one MIDI output. These MIDI jacks appear as
+ a sound card in the ALSA sound system. Other MIDI
+ connections can then be made on the gadget system, using
+ ALSA's aconnect utility etc.
+
 source drivers/usb/gadget/legacy/Kconfig
 
 endchoice
diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index ec2a9ce..1f94dad 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -896,12 +896,145 @@ fail_register:
return status;
 }
 
+static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct f_midi_opts,
+   func_inst.group);
+}
+
+CONFIGFS_ATTR_STRUCT(f_midi_opts);
+CONFIGFS_ATTR_OPS(f_midi_opts);
+
+static void midi_attr_release(struct config_item *item)
+{
+   struct f_midi_opts *opts = to_f_midi_opts(item);
+
+   usb_put_function_instance(opts-func_inst);
+}
+
+static struct configfs_item_operations midi_item_ops = {
+   .release= midi_attr_release,
+   .show_attribute = f_midi_opts_attr_show,
+   .store_attribute = f_midi_opts_attr_store,
+};
+
+#define F_MIDI_OPT(name, test_limit, limit)\
+static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) 
\
+{  \
+   int result; \
+   \
+   mutex_lock(opts-lock);\
+   result = sprintf(page, %d\n, opts-name); \
+   mutex_unlock(opts-lock);  \
+   \
+   return result;  \
+}  \
+   \
+static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts,\
+const char *page, size_t len)  \
+{  \
+   int ret;\
+   u32 num;\
+   \
+   mutex_lock(opts-lock);\
+   if (opts-refcnt) { \
+   ret = -EBUSY;   \
+   goto end;   \
+   }   \
+   \
+   ret = kstrtou32(page, 0, num); \

[PATCHv2 4/7] usb: gadget: midi: convert to new interface of f_midi

2014-10-16 Thread Andrzej Pietrasiewicz
Use the new f_midi interface so that the old can be removed.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/legacy/Kconfig |  1 +
 drivers/usb/gadget/legacy/gmidi.c | 44 ---
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/legacy/Kconfig 
b/drivers/usb/gadget/legacy/Kconfig
index 24392d2..8011b19 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -287,6 +287,7 @@ config USB_MIDI_GADGET
depends on SND
select USB_LIBCOMPOSITE
select SND_RAWMIDI
+   select USB_F_MIDI
help
  The MIDI Gadget acts as a USB Audio device, with one MIDI
  input and one MIDI output. These MIDI jacks appear as
diff --git a/drivers/usb/gadget/legacy/gmidi.c 
b/drivers/usb/gadget/legacy/gmidi.c
index f704c55..0d01e46 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -37,8 +37,7 @@
 
 #include gadget_chips.h
 
-#define USBF_MIDI_INCLUDED
-#include f_midi.c
+#include u_midi.h
 
 /*-*/
 
@@ -116,8 +115,13 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
+struct usb_function_instance *fi_midi;
+struct usb_function *f_midi;
+
 static int __exit midi_unbind(struct usb_composite_dev *dev)
 {
+   usb_put_function(f_midi);
+   usb_put_function_instance(fi_midi);
return 0;
 }
 
@@ -131,28 +135,54 @@ static struct usb_configuration midi_config = {
 
 static int __init midi_bind_config(struct usb_configuration *c)
 {
-   return f_midi_bind_config(c, index, id,
- in_ports, out_ports,
- buflen, qlen);
+   int status;
+
+   f_midi = usb_get_function(fi_midi);
+   if (IS_ERR(f_midi))
+   return PTR_ERR(f_midi);
+
+   status = usb_add_function(c, f_midi);
+   if (status  0) {
+   usb_put_function(f_midi);
+   return status;
+   }
+
+   return 0;
 }
 
 static int __init midi_bind(struct usb_composite_dev *cdev)
 {
+   struct f_midi_opts *midi_opts;
int status;
 
+   fi_midi = usb_get_function_instance(midi);
+   if (IS_ERR(fi_midi))
+   return PTR_ERR(fi_midi);
+
+   midi_opts = container_of(fi_midi, struct f_midi_opts, func_inst);
+   midi_opts-index = index;
+   midi_opts-id = id;
+   midi_opts-in_ports = in_ports;
+   midi_opts-out_ports = out_ports;
+   midi_opts-buflen = buflen;
+   midi_opts-qlen = qlen;
+
status = usb_string_ids_tab(cdev, strings_dev);
if (status  0)
-   return status;
+   goto put;
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
midi_config.iConfiguration = strings_dev[STRING_DESCRIPTION_IDX].id;
 
status = usb_add_config(cdev, midi_config, midi_bind_config);
if (status  0)
-   return status;
+   goto put;
usb_composite_overwrite_options(cdev, coverwrite);
pr_info(%s\n, longname);
return 0;
+put:
+   usb_put_function_instance(fi_midi);
+   return status;
 }
 
 static __refdata struct usb_composite_driver midi_driver = {
-- 
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


[PATCHv2 5/7] usb: gadget: f_midi: remove compatibility layer

2014-10-16 Thread Andrzej Pietrasiewicz
There are no old f_midi interface users left, so remove it.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 122 ---
 1 file changed, 122 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index f3e7d95..5cd77be 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -389,31 +389,6 @@ static void f_midi_disable(struct usb_function *f)
usb_ep_disable(midi-out_ep);
 }
 
-#ifdef USBF_MIDI_INCLUDED
-static void f_midi_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-   struct usb_composite_dev *cdev = f-config-cdev;
-   struct f_midi *midi = func_to_midi(f);
-   struct snd_card *card;
-
-   DBG(cdev, unbind\n);
-
-   /* just to be sure */
-   f_midi_disable(f);
-
-   card = midi-card;
-   midi-card = NULL;
-   if (card)
-   snd_card_free(card);
-
-   kfree(midi-id);
-   midi-id = NULL;
-
-   usb_free_all_descriptors(f);
-   kfree(midi);
-}
-#endif
-
 static int f_midi_snd_free(struct snd_device *device)
 {
return 0;
@@ -744,14 +719,12 @@ static int f_midi_bind(struct usb_configuration *c, 
struct usb_function *f)
struct f_midi *midi = func_to_midi(f);
int status, n, jack = 1, i = 0;
 
-#ifndef USBF_MIDI_INCLUDED
midi-gadget = cdev-gadget;
tasklet_init(midi-tasklet, f_midi_in_tasklet, (unsigned long) midi);
status = f_midi_register_card(midi);
if (status  0)
goto fail_register;
 
-#endif
/* maybe allocate device-global string ID */
if (midi_string_defs[0].id == 0) {
status = usb_string_id(c-cdev);
@@ -908,10 +881,8 @@ fail_f_midi:
kfree(midi_function);
usb_free_descriptors(f-hs_descriptors);
 fail:
-#ifndef USBF_MIDI_INCLUDED
f_midi_unregister_card(midi);
 fail_register:
-#endif
/* we might as well release our claims on endpoints */
if (midi-out_ep)
midi-out_ep-driver_data = NULL;
@@ -923,98 +894,6 @@ fail_register:
return status;
 }
 
-#ifdef USBF_MIDI_INCLUDED
-/**
- * f_midi_bind_config - add USB MIDI function to a configuration
- * @c: the configuration to supcard the USB audio function
- * @index: the soundcard index to use for the ALSA device creation
- * @id: the soundcard id to use for the ALSA device creation
- * @buflen: the buffer length to use
- * @qlen the number of read requests to pre-allocate
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- */
-int __init f_midi_bind_config(struct usb_configuration *c,
- int index, char *id,
- unsigned int in_ports,
- unsigned int out_ports,
- unsigned int buflen,
- unsigned int qlen)
-{
-   struct f_midi *midi;
-   int status, i;
-
-   /* sanity check */
-   if (in_ports  MAX_PORTS || out_ports  MAX_PORTS)
-   return -EINVAL;
-
-   /* allocate and initialize one new instance */
-   midi = kzalloc(sizeof *midi, GFP_KERNEL);
-   if (!midi) {
-   status = -ENOMEM;
-   goto fail;
-   }
-
-   for (i = 0; i  in_ports; i++) {
-   struct gmidi_in_port *port = kzalloc(sizeof(*port), GFP_KERNEL);
-   if (!port) {
-   status = -ENOMEM;
-   goto setup_fail;
-   }
-
-   port-midi = midi;
-   port-active = 0;
-   port-cable = i;
-   midi-in_port[i] = port;
-   }
-
-   midi-gadget = c-cdev-gadget;
-   tasklet_init(midi-tasklet, f_midi_in_tasklet, (unsigned long) midi);
-
-   /* set up ALSA midi devices */
-   midi-in_ports = in_ports;
-   midi-out_ports = out_ports;
-   midi-index = index;
-   status = f_midi_register_card(midi);
-   if (status  0)
-   goto setup_fail;
-
-   midi-func.name= gmidi function;
-   midi-func.strings = midi_strings;
-   midi-func.bind= f_midi_bind;
-   midi-func.unbind  = f_midi_unbind;
-   midi-func.set_alt = f_midi_set_alt;
-   midi-func.disable = f_midi_disable;
-
-   midi-id = kstrdup(id, GFP_KERNEL);
-   if (id  !midi-id) {
-   status = -ENOMEM;
-   goto kstrdup_fail;
-   }
-   midi-buflen = buflen;
-   midi-qlen = qlen;
-
-   status = usb_add_function(c, midi-func);
-   if (status)
-   goto add_fail;
-
-   return 0;
-
-add_fail:
-   kfree(midi-id);
-kstrdup_fail:
-   f_midi_unregister_card(midi);
-setup_fail:
-   for (--i; i = 0; i--)
-   kfree(midi-in_port[i]);
-   kfree(midi);
-fail:
-   return status;
-}
-
-#else
-
 static void 

[PATCHv2 2/7] usb: gadget: f_midi: check kstrdup() return value

2014-10-16 Thread Andrzej Pietrasiewicz
kstrdup() might fail, so check its return value and react appropriately.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index bf32957..a920eee 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -654,6 +654,14 @@ static struct snd_rawmidi_ops gmidi_out_ops = {
.trigger = f_midi_out_trigger
 };
 
+static inline void f_midi_unregister_card(struct f_midi *midi)
+{
+   if (midi-card) {
+   snd_card_free(midi-card);
+   midi-card = NULL;
+   }
+}
+
 /* register as a sound card */
 static int f_midi_register_card(struct f_midi *midi)
 {
@@ -715,10 +723,7 @@ static int f_midi_register_card(struct f_midi *midi)
return 0;
 
 fail:
-   if (midi-card) {
-   snd_card_free(midi-card);
-   midi-card = NULL;
-   }
+   f_midi_unregister_card(midi);
return err;
 }
 
@@ -967,15 +972,23 @@ int __init f_midi_bind_config(struct usb_configuration *c,
midi-func.disable = f_midi_disable;
 
midi-id = kstrdup(id, GFP_KERNEL);
+   if (id  !midi-id) {
+   status = -ENOMEM;
+   goto kstrdup_fail;
+   }
midi-buflen = buflen;
midi-qlen = qlen;
 
status = usb_add_function(c, midi-func);
if (status)
-   goto setup_fail;
+   goto add_fail;
 
return 0;
 
+add_fail:
+   kfree(midi-id);
+kstrdup_fail:
+   f_midi_unregister_card(midi);
 setup_fail:
for (--i; i = 0; i--)
kfree(midi-in_port[i]);
-- 
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


[PATCHv2 6/7] usb: gadget: f_midi: use usb_gstrings_attach

2014-10-16 Thread Andrzej Pietrasiewicz
In order to add configfs support the usb_gstrings_attach must be used.

Signed-off-by: Andrzej Pietrasiewicz andrze...@samsung.com
---
 drivers/usb/gadget/function/f_midi.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index 5cd77be..ec2a9ce 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -717,6 +717,7 @@ static int f_midi_bind(struct usb_configuration *c, struct 
usb_function *f)
struct usb_midi_out_jack_descriptor_1 jack_out_emb_desc[MAX_PORTS];
struct usb_composite_dev *cdev = c-cdev;
struct f_midi *midi = func_to_midi(f);
+   struct usb_string *us;
int status, n, jack = 1, i = 0;
 
midi-gadget = cdev-gadget;
@@ -726,12 +727,13 @@ static int f_midi_bind(struct usb_configuration *c, 
struct usb_function *f)
goto fail_register;
 
/* maybe allocate device-global string ID */
-   if (midi_string_defs[0].id == 0) {
-   status = usb_string_id(c-cdev);
-   if (status  0)
-   goto fail;
-   midi_string_defs[0].id = status;
+   us = usb_gstrings_attach(c-cdev, midi_strings,
+ARRAY_SIZE(midi_string_defs));
+   if (IS_ERR(us)) {
+   status = PTR_ERR(us);
+   goto fail;
}
+   ac_interface_desc.iInterface = us[STRING_FUNC_IDX].id;
 
/* We have two interfaces, AudioControl and MIDIStreaming */
status = usb_interface_id(c, f);
@@ -991,7 +993,6 @@ struct usb_function *f_midi_alloc(struct 
usb_function_instance *fi)
midi-qlen = opts-qlen;
 
midi-func.name = gmidi function;
-   midi-func.strings  = midi_strings;
midi-func.bind = f_midi_bind;
midi-func.unbind   = f_midi_unbind;
midi-func.set_alt  = f_midi_set_alt;
-- 
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 v2] storage: Reject bogus max LUN values

2014-10-16 Thread Mark Knibbs
Hi,

v2: Minor change as suggested

Some mass storage devices return a bogus value in response to a Get Max LUN
request. The Iomega Jaz USB Adapter responds with 0x10, hence my recent
patch to use the US_FL_SINGLE_LUN quirk for it.

The USB MSC Bulk Only Transport document says The device shall return one
byte of data that contains the maximum LUN supported by the device.

Since the LUN field in the command block wrapper is only 4 bits wide, it
might be helpful to report too-large LUN values in the kernel log, and
assume max LUN is actually 0. That could get some devices which currently
need the US_FL_SINGLE_LUN quirk to work.


Signed-off-by: Mark Knibbs ma...@clara.co.uk
Acked-by: Alan Stern st...@rowland.harvard.edu

---
diff -upN linux-3.17/drivers/usb/storage/transport.c.orig 
linux-3.17/drivers/usb/storage/transport.c
--- linux-3.17/drivers/usb/storage/transport.c.orig 2014-10-05 
20:12:36.0 +0100
+++ linux-3.17/drivers/usb/storage/transport.c  2014-10-12 13:11:38.0 
+0100
@@ -1035,9 +1035,20 @@ int usb_stor_Bulk_max_lun(struct us_data
usb_stor_dbg(us, GetMaxLUN command result is %d, data is %d\n,
 result, us-iobuf[0]);
 
-   /* if we have a successful request, return the result */
-   if (result  0)
-   return us-iobuf[0];
+   /*
+* If we have a successful request, return the result if valid. The
+* CBW LUN field is 4 bits wide, so the value reported by the device
+* should fit into that.
+*/
+   if (result  0) {
+   if (us-iobuf[0]  16) {
+   return us-iobuf[0];
+   } else {
+   dev_info(us-pusb_intf-dev,
+Max LUN %d is not valid, using 0 instead,
+us-iobuf[0]);
+   }
+   }
 
/*
 * Some devices don't like GetMaxLUN.  They may STALL the control
--
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: FTDI driver in Linux

2014-10-16 Thread Johan Hovold
On Thu, Oct 16, 2014 at 02:55:22PM +0400, Victor Ashik wrote:
 16.10.2014 14:02, Johan Hovold пишет:
  On Thu, Oct 16, 2014 at 12:47:05PM +0400, Victor Ashik wrote:
Wed, Oct 15, 2014 at 6:00 PM, Johan Hovold jo...@kernel.org wrote:
 
  No, we're still supposed to support the legacy SIO type of devices,
  although that code doesn't get much testing I'm afraid.
 
  But let's start with verifying that the type is actually detected.
 
  Could you post the kernel log from when plugging the device in along
  with the lsusb -v output for it?
 
  [83986.455025] usb 1-1.2: New USB device found, idVendor=0403,
  idProduct=8372
  [83986.455029] usb 1-1.2: New USB device strings: Mfr=1, Product=2,
  SerialNumber=3
  [83986.455031] usb 1-1.2: Product: USB Serial Converter
  [83986.455032] usb 1-1.2: Manufacturer: FTDI
  [83986.455033] usb 1-1.2: SerialNumber: FT00026B
  [83986.472948] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter 
  detected
  [83986.472972] usb 1-1.2: Detected SIO
 
  So the type is indeed detected correctly.
 
  [83986.472974] usb 1-1.2: Number of endpoints 2
  [83986.472975] usb 1-1.2: Endpoint 1 MaxPacketSize 64
  [83986.472976] usb 1-1.2: Endpoint 2 MaxPacketSize 64
  [83986.472977] usb 1-1.2: Setting MaxPacketSize 64
  [83986.473150] ftdi_sio ttyUSB0: Unable to read latency timer: -32
  [83986.473626] ftdi_sio ttyUSB0: Unable to write latency timer: -32
  [83986.473673] usb 1-1.2: FTDI USB Serial Device converter now attached to
  ttyUSB0
 
  Are you able to verify if rx or tx works separately, e.g. by connecting
  to a working serial port and setting up two terminal sessions? Remember
  to try with flow control disabled on both ends as well.
 
  Also could you post a log from when opening, reading/writing and closing
  the device? Make sure to enable debugging in usb-serial core as well.
  Using echo and cat (e.g. echo hello /dev/ttyUSB0) can suffice as
  long the port has been properly set up.
 
 [91798.346109] usbserial: unknown parameter 'debug' ignored

The debug module parameter has been removed. You need to enable it using
dynamic debugging (e.g. through debugfs).

 [91798.346489] usbcore: registered new interface driver usbserial
 [91798.346512] usbcore: registered new interface driver usbserial_generic
 [91798.346531] usbserial: USB Serial support registered for generic
 [91803.034148] ftdi_sio: unknown parameter 'debug' ignored

Same here (although it seems you enabled it in the driver directly).

 [91803.034572] usbcore: registered new interface driver ftdi_sio
 [91803.034695] usbserial: USB Serial support registered for FTDI USB 
 Serial Device
 [91803.034757] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
 [91803.034898] usb 1-1.2: Detected SIO
 [91803.034901] usb 1-1.2: Number of endpoints 2
 [91803.034902] usb 1-1.2: Endpoint 1 MaxPacketSize 64
 [91803.034904] usb 1-1.2: Endpoint 2 MaxPacketSize 64
 [91803.034906] usb 1-1.2: Setting MaxPacketSize 64
 [91803.035940] ftdi_sio ttyUSB0: Unable to read latency timer: -32
 [91803.036435] ftdi_sio ttyUSB0: Unable to write latency timer: -32
 [91803.036711] usb 1-1.2: FTDI USB Serial Device converter now attached 
 to ttyUSB0
 [91806.063117] ftdi_sio ttyUSB0: ftdi_set_termios FAILED to set 
 databits/stopbits/parity
 [91806.063467] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
 [91806.063806] ftdi_sio ttyUSB0: urb failed to clear flow control
 [91806.064545] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
 [91806.064914] ftdi_sio ttyUSB0: urb failed to clear flow control
 [91806.065289] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
 [91806.065662] ftdi_sio ttyUSB0: urb failed to set to rts/cts flow control
 [91806.066036] ftdi_sio ttyUSB0: failed to get modem status: -32
 [91806.066414] ftdi_sio ttyUSB0: urb failed to set to rts/cts flow control
 [91812.841711] ftdi_sio ttyUSB0: failed to get modem status: -32
 [91812.842077] ftdi_sio ttyUSB0: ftdi_set_termios urb failed to set baudrate
 [91812.842437] ftdi_sio ttyUSB0: urb failed to clear flow control
 [91812.842788] ftdi_sio ttyUSB0: failed to get modem status: -32
 [91812.843160] ftdi_sio ttyUSB0: error from flowcontrol urb

So basically all control transfers are failing. (This should really have
been logged at error log level -- I'll fix that up.)

I'll try to have a look at the bsd logs you sent soon. Meanwhile you
could test if the device works at 115200 8N1, which could be the default
baud rate.

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


[PATCH 2/9] usb: dwc2/gadget: fix enumeration issues

2014-10-16 Thread Marek Szyprowski
Excessive debug messages might cause timing issues that prevent correct
usb enumeration. This patch hides information about USB bus reset to let
driver enumerate fast enough to avoid making host angry. This fixes
endless enumeration and usb reset loop observed with some Linux hosts.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 119c8a3effc2..8870e38c1d82 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2333,7 +2333,7 @@ irq_retry:
 
u32 usb_status = readl(hsotg-regs + GOTGCTL);
 
-   dev_info(hsotg-dev, %s: USBRst\n, __func__);
+   dev_dbg(hsotg-dev, %s: USBRst\n, __func__);
dev_dbg(hsotg-dev, GNPTXSTS=%08x\n,
readl(hsotg-regs + GNPTXSTS));
 
-- 
1.9.2

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


[PATCH 0/9] more dwc2/gadget fixes

2014-10-16 Thread Marek Szyprowski
Hi!

This patchset contains a set of fixes to solve vaious minor issues
related to cable connect/disconnect events, pull-up control,
soft-disconnect mode, proper usb phy operation and restoring gadget
state after suspend/resume cycle.

Best regards
Marek Szyprowski, PhD
Samsung RD Institute Poland

Marek Szyprowski (9):
  usb: dwc2/gadget: report disconnect event from 'end session' irq
  usb: dwc2/gadget: fix enumeration issues
  usb: dwc2/gadget: fix support for soft_connect udc framework feature
  usb: dwc2/gadget: disable phy before turning off power regulators
  usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init
  usb: dwc2/gadget: decouple setting soft disconnect from
s3c_hsotg_core_init
  usb: dwc2/gadget: use soft disconnect mode for implementing pullup
control
  usb: dwc2/gadget: fix calls to phy control functions in suspend/resume
code
  usb: dwc2/gadget: rework suspend/resume code to correctly restore
gadget state

 drivers/usb/dwc2/core.h   |  4 +-
 drivers/usb/dwc2/gadget.c | 93 +--
 2 files changed, 69 insertions(+), 28 deletions(-)

-- 
1.9.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 7/9] usb: dwc2/gadget: use soft disconnect mode for implementing pullup control

2014-10-16 Thread Marek Szyprowski
This patch moves PHY enable and disable calls from pullup method to
udc_start/stop functions and adds calls to recently introduces soft
disconnect mode in pullup method. This improves dwc2 gadget driver
compatibility with gadget API requirements (now pullup method really
forces soft disconnect mode instead of shutting down the whole hardware)
and as a side effect also solves the issue related to limited caller
context for PHY related functions (they cannot be called from
non-sleeping context).

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 16 +---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index d039334967d7..cdf417a7ae63 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2883,6 +2883,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
   struct usb_gadget_driver *driver)
 {
struct s3c_hsotg *hsotg = to_hsotg(gadget);
+   unsigned long flags;
int ret;
 
if (!hsotg) {
@@ -2919,7 +2920,15 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
goto err;
}
 
+   s3c_hsotg_phy_enable(hsotg);
+
+   spin_lock_irqsave(hsotg-lock, flags);
+   s3c_hsotg_init(hsotg);
+   s3c_hsotg_core_init_disconnected(hsotg);
+   spin_unlock_irqrestore(hsotg-lock, flags);
+
dev_info(hsotg-dev, bound driver %s\n, driver-driver.name);
+
return 0;
 
 err:
@@ -2957,6 +2966,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
 
spin_unlock_irqrestore(hsotg-lock, flags);
 
+   s3c_hsotg_phy_disable(hsotg);
+
regulator_bulk_disable(ARRAY_SIZE(hsotg-supplies), hsotg-supplies);
 
clk_disable(hsotg-clk);
@@ -2990,14 +3001,13 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
int is_on)
dev_dbg(hsotg-dev, %s: is_on: %d\n, __func__, is_on);
 
spin_lock_irqsave(hsotg-lock, flags);
+
if (is_on) {
-   s3c_hsotg_phy_enable(hsotg);
clk_enable(hsotg-clk);
-   s3c_hsotg_core_init_disconnected(hsotg);
s3c_hsotg_core_connect(hsotg);
} else {
+   s3c_hsotg_core_disconnect(hsotg);
clk_disable(hsotg-clk);
-   s3c_hsotg_phy_disable(hsotg);
}
 
hsotg-gadget.speed = USB_SPEED_UNKNOWN;
-- 
1.9.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 6/9] usb: dwc2/gadget: decouple setting soft disconnect from s3c_hsotg_core_init

2014-10-16 Thread Marek Szyprowski
This patch changes s3c_hsotg_core_init function to leave hardware in
soft disconnect mode, so the actual moment of coupling the hardware to
the usb bus can be later controlled by the driver in the more accurate
way. For this purpose, separate functions for enabling and disabling
soft disconnect mode have been added.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 22 +-
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 1ba0682fb252..d039334967d7 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2124,7 +2124,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
  *
  * Issue a soft reset to the core, and await the core finishing it.
  */
-static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
+static void s3c_hsotg_core_init_disconnected(struct s3c_hsotg *hsotg)
 {
s3c_hsotg_corereset(hsotg);
 
@@ -2241,14 +2241,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
readl(hsotg-regs + DOEPCTL0));
 
/* clear global NAKs */
-   writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK,
+   writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK | DCTL_SFTDISCON,
   hsotg-regs + DCTL);
 
/* must be at-least 3ms to allow bus to see disconnect */
mdelay(3);
 
hsotg-last_rst = jiffies;
+}
+
+static void s3c_hsotg_core_disconnect(struct s3c_hsotg *hsotg)
+{
+   /* set the soft-disconnect bit */
+   __orr32(hsotg-regs + DCTL, DCTL_SFTDISCON);
+}
 
+static void s3c_hsotg_core_connect(struct s3c_hsotg *hsotg)
+{
/* remove the soft-disconnect and let's go */
__bic32(hsotg-regs + DCTL, DCTL_SFTDISCON);
 }
@@ -2348,7 +2357,8 @@ irq_retry:
kill_all_requests(hsotg, hsotg-eps[0],
  -ECONNRESET, true);
 
-   s3c_hsotg_core_init(hsotg);
+   s3c_hsotg_core_init_disconnected(hsotg);
+   s3c_hsotg_core_connect(hsotg);
}
}
}
@@ -2983,7 +2993,8 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
int is_on)
if (is_on) {
s3c_hsotg_phy_enable(hsotg);
clk_enable(hsotg-clk);
-   s3c_hsotg_core_init(hsotg);
+   s3c_hsotg_core_init_disconnected(hsotg);
+   s3c_hsotg_core_connect(hsotg);
} else {
clk_disable(hsotg-clk);
s3c_hsotg_phy_disable(hsotg);
@@ -3670,7 +3681,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev)
 
spin_lock_irqsave(hsotg-lock, flags);
s3c_hsotg_phy_enable(hsotg);
-   s3c_hsotg_core_init(hsotg);
+   s3c_hsotg_core_init_disconnect(hsotg);
+   s3c_hsotg_core_connect(hsotg);
spin_unlock_irqrestore(hsotg-lock, flags);
 
return ret;
-- 
1.9.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 3/9] usb: dwc2/gadget: fix support for soft_connect udc framework feature

2014-10-16 Thread Marek Szyprowski
Enabling and disabling usb gadget by writing to
/sys/class/udc/*hsotg/soft_connect results in calling udc_start/udc_stop
functions with the same usb gadget driver, so the driver should not WARN
about such case.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 8870e38c1d82..37fda4c03397 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2892,7 +2892,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
return -EINVAL;
}
 
-   WARN_ON(hsotg-driver);
+   WARN_ON(hsotg-driver  hsotg-driver != driver);
 
driver-driver.bus = NULL;
hsotg-driver = driver;
-- 
1.9.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 4/9] usb: dwc2/gadget: disable phy before turning off power regulators

2014-10-16 Thread Marek Szyprowski
This patch fixes probe function to match the pattern used elsewhere in
the driver, where power regulators are turned off as the last element in
the device shutdown procedure.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 37fda4c03397..178a6ea5eef8 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3573,6 +3573,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
s3c_hsotg_initep(hsotg, hsotg-eps[epnum], epnum);
 
/* disable power and clock */
+   s3c_hsotg_phy_disable(hsotg);
 
ret = regulator_bulk_disable(ARRAY_SIZE(hsotg-supplies),
hsotg-supplies);
@@ -3581,8 +3582,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
goto err_ep_mem;
}
 
-   s3c_hsotg_phy_disable(hsotg);
-
ret = usb_add_gadget_udc(pdev-dev, hsotg-gadget);
if (ret)
goto err_ep_mem;
-- 
1.9.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 9/9] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state

2014-10-16 Thread Marek Szyprowski
Suspend/resume code assumed that the gadget was always enabled and
connected to usb bus. This means that the actual state of the gadget
(soft-enabled/disabled or connected/disconnected) was not correctly
preserved on suspend/resume cycle. This patch fixes this issue.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/core.h   |  4 +++-
 drivers/usb/dwc2/gadget.c | 42 ++
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index bf015ab3b44c..3648b76a18b4 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -210,7 +210,9 @@ struct s3c_hsotg {
u8  ctrl_buff[8];
 
struct usb_gadget   gadget;
-   unsigned intsetup;
+   unsigned intsetup:1;
+   unsigned intconnected:1;
+   unsigned intenabled:1;
unsigned long   last_rst;
struct s3c_hsotg_ep *eps;
 };
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 052b1a857291..83fe123ede05 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2925,6 +2925,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
spin_lock_irqsave(hsotg-lock, flags);
s3c_hsotg_init(hsotg);
s3c_hsotg_core_init_disconnected(hsotg);
+   hsotg-enabled = 1;
+   hsotg-connected = 0;
spin_unlock_irqrestore(hsotg-lock, flags);
 
dev_info(hsotg-dev, bound driver %s\n, driver-driver.name);
@@ -2963,6 +2965,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
hsotg-driver = NULL;
 
hsotg-gadget.speed = USB_SPEED_UNKNOWN;
+   hsotg-enabled = 0;
+   hsotg-connected = 0;
 
spin_unlock_irqrestore(hsotg-lock, flags);
 
@@ -3004,9 +3008,11 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
int is_on)
 
if (is_on) {
clk_enable(hsotg-clk);
+   hsotg-connected = 1;
s3c_hsotg_core_connect(hsotg);
} else {
s3c_hsotg_core_disconnect(hsotg);
+   hsotg-connected = 0;
clk_disable(hsotg-clk);
}
 
@@ -3655,16 +3661,18 @@ static int s3c_hsotg_suspend(struct platform_device 
*pdev, pm_message_t state)
dev_info(hsotg-dev, suspending usb gadget %s\n,
 hsotg-driver-driver.name);
 
-   spin_lock_irqsave(hsotg-lock, flags);
-   s3c_hsotg_core_disconnect(hsotg);
-   s3c_hsotg_disconnect(hsotg);
-   hsotg-gadget.speed = USB_SPEED_UNKNOWN;
-   spin_unlock_irqrestore(hsotg-lock, flags);
+   if (hsotg-enabled) {
+   int ep;
 
-   s3c_hsotg_phy_disable(hsotg);
+   spin_lock_irqsave(hsotg-lock, flags);
+   if (hsotg-connected)
+   s3c_hsotg_core_disconnect(hsotg);
+   s3c_hsotg_disconnect(hsotg);
+   hsotg-gadget.speed = USB_SPEED_UNKNOWN;
+   spin_unlock_irqrestore(hsotg-lock, flags);
+
+   s3c_hsotg_phy_disable(hsotg);
 
-   if (hsotg-driver) {
-   int ep;
for (ep = 0; ep  hsotg-num_of_eps; ep++)
s3c_hsotg_ep_disable(hsotg-eps[ep].ep);
 
@@ -3682,21 +3690,23 @@ static int s3c_hsotg_resume(struct platform_device 
*pdev)
unsigned long flags;
int ret = 0;
 
-   if (hsotg-driver) {
+   if (hsotg-driver)
dev_info(hsotg-dev, resuming usb gadget %s\n,
 hsotg-driver-driver.name);
 
+   if (hsotg-enabled) {
clk_enable(hsotg-clk);
ret = regulator_bulk_enable(ARRAY_SIZE(hsotg-supplies),
- hsotg-supplies);
-   }
+   hsotg-supplies);
 
-   s3c_hsotg_phy_enable(hsotg);
+   s3c_hsotg_phy_enable(hsotg);
 
-   spin_lock_irqsave(hsotg-lock, flags);
-   s3c_hsotg_core_init_disconnected(hsotg);
-   s3c_hsotg_core_connect(hsotg);
-   spin_unlock_irqrestore(hsotg-lock, flags);
+   spin_lock_irqsave(hsotg-lock, flags);
+   s3c_hsotg_core_init_disconnected(hsotg);
+   if (hsotg-connected)
+   s3c_hsotg_core_connect(hsotg);
+   spin_unlock_irqrestore(hsotg-lock, flags);
+   }
 
return ret;
 }
-- 
1.9.2

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


[PATCH 1/9] usb: dwc2/gadget: report disconnect event from 'end session' irq

2014-10-16 Thread Marek Szyprowski
This patch adds a call to s3c_hsotg_disconnect() from 'end session'
interrupt to correctly notify gadget subsystem about unplugged usb
cable.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7b5856fadd93..119c8a3effc2 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2279,6 +2279,12 @@ irq_retry:
dev_info(hsotg-dev, OTGInt: %08x\n, otgint);
 
writel(otgint, hsotg-regs + GOTGINT);
+
+   if (otgint  GOTGINT_SES_END_DET) {
+   if (hsotg-gadget.speed != USB_SPEED_UNKNOWN)
+   s3c_hsotg_disconnect(hsotg);
+   hsotg-gadget.speed = USB_SPEED_UNKNOWN;
+   }
}
 
if (gintsts  GINTSTS_SESSREQINT) {
-- 
1.9.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 8/9] usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code

2014-10-16 Thread Marek Szyprowski
This patch moves calls to phy enable/disable out of spinlock protected
blocks in device suspend/resume to fix incorrect caller context. Phy
related functions must not be called from atomic context.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index cdf417a7ae63..052b1a857291 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3656,11 +3656,13 @@ static int s3c_hsotg_suspend(struct platform_device 
*pdev, pm_message_t state)
 hsotg-driver-driver.name);
 
spin_lock_irqsave(hsotg-lock, flags);
+   s3c_hsotg_core_disconnect(hsotg);
s3c_hsotg_disconnect(hsotg);
-   s3c_hsotg_phy_disable(hsotg);
hsotg-gadget.speed = USB_SPEED_UNKNOWN;
spin_unlock_irqrestore(hsotg-lock, flags);
 
+   s3c_hsotg_phy_disable(hsotg);
+
if (hsotg-driver) {
int ep;
for (ep = 0; ep  hsotg-num_of_eps; ep++)
@@ -3689,9 +3691,10 @@ static int s3c_hsotg_resume(struct platform_device *pdev)
  hsotg-supplies);
}
 
-   spin_lock_irqsave(hsotg-lock, flags);
s3c_hsotg_phy_enable(hsotg);
-   s3c_hsotg_core_init_disconnect(hsotg);
+
+   spin_lock_irqsave(hsotg-lock, flags);
+   s3c_hsotg_core_init_disconnected(hsotg);
s3c_hsotg_core_connect(hsotg);
spin_unlock_irqrestore(hsotg-lock, flags);
 
-- 
1.9.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 5/9] usb: dwc2/gadget: move setting last reset time to s3c_hsotg_core_init

2014-10-16 Thread Marek Szyprowski
This patch removes duplicated code and sets last_rst variable in the
function which does the hardware reset.

Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
---
 drivers/usb/dwc2/gadget.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 178a6ea5eef8..1ba0682fb252 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2247,6 +2247,8 @@ static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
/* must be at-least 3ms to allow bus to see disconnect */
mdelay(3);
 
+   hsotg-last_rst = jiffies;
+
/* remove the soft-disconnect and let's go */
__bic32(hsotg-regs + DCTL, DCTL_SFTDISCON);
 }
@@ -2347,7 +2349,6 @@ irq_retry:
  -ECONNRESET, true);
 
s3c_hsotg_core_init(hsotg);
-   hsotg-last_rst = jiffies;
}
}
}
@@ -2908,7 +2909,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
goto err;
}
 
-   hsotg-last_rst = jiffies;
dev_info(hsotg-dev, bound driver %s\n, driver-driver.name);
return 0;
 
@@ -3669,7 +3669,6 @@ static int s3c_hsotg_resume(struct platform_device *pdev)
}
 
spin_lock_irqsave(hsotg-lock, flags);
-   hsotg-last_rst = jiffies;
s3c_hsotg_phy_enable(hsotg);
s3c_hsotg_core_init(hsotg);
spin_unlock_irqrestore(hsotg-lock, flags);
-- 
1.9.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 v2 2/2] usb: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Felipe Balbi
HI,

On Thu, Oct 16, 2014 at 01:11:10PM +0530, Sudip Mukherjee wrote:
 sparse was giving the following warning:
 warning: context imbalance in 's3c_hsotg_ep_enable'
   - different lock contexts for basic block
 
 we were returning ENOMEM while still holding the spinlock.
 The sparse warning was fixed by releasing the spinlock before return.
 
 This patch depends on the previous patch of the series.
 
 Signed-off-by: Sudip Mukherjee su...@vectorindia.org

this should be patch one so it can be backported to stable kernels.

-- 
balbi


signature.asc
Description: Digital signature


Re: [RFC PATCH 1/2] usb: dwc2: add clock manage for hcd

2014-10-16 Thread Felipe Balbi
Hi,

On Wed, Oct 15, 2014 at 10:46:17PM -0700, Kever Yang wrote:
 This patch move clock init out of gadget into platform,
 make both hcd and gadget can use the clock
 
 Signed-off-by: Kever Yang kever.y...@rock-chips.com
 ---
 
  drivers/usb/dwc2/gadget.c   | 16 ++--
  drivers/usb/dwc2/hcd.c  |  3 +++
  drivers/usb/dwc2/platform.c | 30 ++
  3 files changed, 23 insertions(+), 26 deletions(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 6ffbfc2..1943e52 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -3408,20 +3408,12 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int 
 irq)
   hsotg-phyif = GUSBCFG_PHYIF8;
   }
  
 - hsotg-clk = devm_clk_get(dev, otg);
 - if (IS_ERR(hsotg-clk)) {
 - dev_err(dev, cannot get otg clock\n);
 - return PTR_ERR(hsotg-clk);
 - }
 -
   hsotg-gadget.max_speed = USB_SPEED_HIGH;
   hsotg-gadget.ops = s3c_hsotg_gadget_ops;
   hsotg-gadget.name = dev_name(dev);
  
   /* reset the system */
  
 - clk_prepare_enable(hsotg-clk);
 -
   /* regulators */
  
   for (i = 0; i  ARRAY_SIZE(hsotg-supplies); i++)
 @@ -3431,7 +3423,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
hsotg-supplies);
   if (ret) {
   dev_err(dev, failed to request supplies: %d\n, ret);
 - goto err_clk;
 + goto out;
   }
  
   ret = regulator_bulk_enable(ARRAY_SIZE(hsotg-supplies),
 @@ -3510,9 +3502,7 @@ err_ep_mem:
   kfree(eps);
  err_supplies:
   s3c_hsotg_phy_disable(hsotg);
 -err_clk:
 - clk_disable_unprepare(hsotg-clk);
 -
 +out:
   return ret;
  }
  EXPORT_SYMBOL_GPL(dwc2_gadget_init);
 @@ -3532,8 +3522,6 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
   usb_gadget_unregister_driver(hsotg-driver);
   }
  
 - clk_disable_unprepare(hsotg-clk);
 -
   return 0;
  }
  EXPORT_SYMBOL_GPL(s3c_hsotg_remove);
 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
 index fa49c72..fddd923 100644
 --- a/drivers/usb/dwc2/hcd.c
 +++ b/drivers/usb/dwc2/hcd.c
 @@ -46,6 +46,7 @@
  #include linux/delay.h
  #include linux/io.h
  #include linux/slab.h
 +#include linux/clk.h
  #include linux/usb.h
  
  #include linux/usb/hcd.h
 @@ -2266,6 +2267,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
   spin_lock_irqsave(hsotg-lock, flags);
  
   hcd-state = HC_STATE_RUNNING;
 + clk_enable(hsotg-clk);

with this you're moving clk_enable() from gadget to HCD. You might want
to leave this completely to the glue; at least for now.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 1/9] usb: dwc2/gadget: report disconnect event from 'end session' irq

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 02:57:57PM +0200, Marek Szyprowski wrote:
 This patch adds a call to s3c_hsotg_disconnect() from 'end session'
 interrupt to correctly notify gadget subsystem about unplugged usb
 cable.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 6 ++
  1 file changed, 6 insertions(+)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 7b5856fadd93..119c8a3effc2 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2279,6 +2279,12 @@ irq_retry:
   dev_info(hsotg-dev, OTGInt: %08x\n, otgint);
  
   writel(otgint, hsotg-regs + GOTGINT);
 +
 + if (otgint  GOTGINT_SES_END_DET) {

looks like this should be done for GINTSTS_DISCONNINT.

-- 
balbi


signature.asc
Description: Digital signature


Re: [RFC PATCH 2/2] usb: dwc2: add bus suspend/resume for dwc2

2014-10-16 Thread Felipe Balbi
On Wed, Oct 15, 2014 at 10:46:18PM -0700, Kever Yang wrote:
 This patch add suspend/resume for dwc2 hcd controller.

adds

 Signed-off-by: Kever Yang kever.y...@rock-chips.com
 ---
 
  drivers/usb/dwc2/hcd.c | 71 
 ++
  1 file changed, 60 insertions(+), 11 deletions(-)
 
 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
 index fddd923..c1801d8 100644
 --- a/drivers/usb/dwc2/hcd.c
 +++ b/drivers/usb/dwc2/hcd.c
 @@ -1474,6 +1474,23 @@ static void dwc2_port_suspend(struct dwc2_hsotg 
 *hsotg, u16 windex)
   }
  }
  
 +static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
 +{
 + u32 hprt0;
 +
 + writel(0, hsotg-regs + PCGCTL);
 + usleep_range(2, 4);

why this usleep_range() ? Is it documented somewhere ? How about adding
a comment explaining why you need to wait at least 20ms ?

 + hprt0 = dwc2_read_hprt0(hsotg);
 + hprt0 |= HPRT0_RES;
 + writel(hprt0, hsotg-regs + HPRT0);
 + hprt0 = ~HPRT0_SUSP;
 + usleep_range(10, 15);

and another one here, why ?

 + hprt0 = ~HPRT0_RES;
 + writel(hprt0, hsotg-regs + HPRT0);
 +}
 +
  /* Handles hub class-specific requests */
  static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
   u16 wvalue, u16 windex, char *buf, u16 wlength)
 @@ -1519,17 +1536,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg 
 *hsotg, u16 typereq,
   case USB_PORT_FEAT_SUSPEND:
   dev_dbg(hsotg-dev,
   ClearPortFeature USB_PORT_FEAT_SUSPEND\n);
 - writel(0, hsotg-regs + PCGCTL);
 - usleep_range(2, 4);
 -
 - hprt0 = dwc2_read_hprt0(hsotg);
 - hprt0 |= HPRT0_RES;
 - writel(hprt0, hsotg-regs + HPRT0);
 - hprt0 = ~HPRT0_SUSP;
 - usleep_range(10, 15);
 -
 - hprt0 = ~HPRT0_RES;
 - writel(hprt0, hsotg-regs + HPRT0);
 + dwc2_port_resume(hsotg);
   break;
  
   case USB_PORT_FEAT_POWER:
 @@ -2304,6 +2311,45 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd)
   usleep_range(1000, 3000);
  }
  
 +static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
 +{
 + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
 + u32 hprt0;
 +
 + if (hsotg-op_state != OTG_STATE_B_HOST)
 + return 0;
 +
 + if (hsotg-lx_state != DWC2_L0)
 + return 0;
 +
 + hprt0 = dwc2_read_hprt0(hsotg);
 + if (hprt0 | HPRT0_CONNSTS)

did you mean:

if (hprt0  HPRT0_CONNSTS) ??

 + dwc2_port_suspend(hsotg, 1);

always 1 ?

 + clk_disable(hsotg-clk);

this I keep getting wrong, but if -bus_suspend() is really the one used
for actual system sleep, then you might want to fiddle with the clocks
only from the parent platform glue. I haven't really read the code to
make sure, however, so this might be a completely bogus comment :-)

 + return 0;
 +}
 +
 +static int _dwc2_hcd_resume(struct usb_hcd *hcd)
 +{
 + struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
 + u32 hprt0;
 +
 + if (hsotg-op_state != OTG_STATE_B_HOST)
 + return 0;
 +
 + if (hsotg-lx_state != DWC2_L2)
 + return 0;
 +
 + clk_enable(hsotg-clk);
 +
 + hprt0 = dwc2_read_hprt0(hsotg);
 + if (hprt0 | HPRT0_CONNSTS | HPRT0_SUSP)

and here:

if ((hprt0  HPRT0_CONNSTS) 
(hprt0  HPRT0_SUSP))  ???

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 2/9] usb: dwc2/gadget: fix enumeration issues

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 02:57:58PM +0200, Marek Szyprowski wrote:
 Excessive debug messages might cause timing issues that prevent correct
 usb enumeration. This patch hides information about USB bus reset to let
 driver enumerate fast enough to avoid making host angry. This fixes
 endless enumeration and usb reset loop observed with some Linux hosts.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 119c8a3effc2..8870e38c1d82 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2333,7 +2333,7 @@ irq_retry:
  
   u32 usb_status = readl(hsotg-regs + GOTGCTL);
  
 - dev_info(hsotg-dev, %s: USBRst\n, __func__);
 + dev_dbg(hsotg-dev, %s: USBRst\n, __func__);

considering this is inside an IRQ handler, I'd rather use dev_vdbg() but
no strong feelings:

Reviewed-by: Felipe Balbi ba...@ti.com

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 3/9] usb: dwc2/gadget: fix support for soft_connect udc framework feature

2014-10-16 Thread Felipe Balbi
Hi,

On Thu, Oct 16, 2014 at 02:57:59PM +0200, Marek Szyprowski wrote:
 Enabling and disabling usb gadget by writing to
 /sys/class/udc/*hsotg/soft_connect results in calling udc_start/udc_stop
 functions with the same usb gadget driver, so the driver should not WARN
 about such case.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 8870e38c1d82..37fda4c03397 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2892,7 +2892,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget 
 *gadget,
   return -EINVAL;
   }
  
 - WARN_ON(hsotg-driver);
 + WARN_ON(hsotg-driver  hsotg-driver != driver);

the bug is in your -udc_stop(). You should clear hsotg-driver to NULL
there.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 6/9] usb: dwc2/gadget: decouple setting soft disconnect from s3c_hsotg_core_init

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 02:58:02PM +0200, Marek Szyprowski wrote:
 This patch changes s3c_hsotg_core_init function to leave hardware in
 soft disconnect mode, so the actual moment of coupling the hardware to
 the usb bus can be later controlled by the driver in the more accurate

what is this more accurate way you talk about ? Why is it more
accurate ? Perhaps you have failed some USB Certification test ? Which
test id was that ? Why did it fail ? and why does this patch solve the
issue ?

 way. For this purpose, separate functions for enabling and disabling
 soft disconnect mode have been added.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 22 +-
  1 file changed, 17 insertions(+), 5 deletions(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 1ba0682fb252..d039334967d7 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2124,7 +2124,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
   *
   * Issue a soft reset to the core, and await the core finishing it.
   */
 -static void s3c_hsotg_core_init(struct s3c_hsotg *hsotg)
 +static void s3c_hsotg_core_init_disconnected(struct s3c_hsotg *hsotg)
  {
   s3c_hsotg_corereset(hsotg);
  
 @@ -2241,14 +2241,23 @@ static void s3c_hsotg_core_init(struct s3c_hsotg 
 *hsotg)
   readl(hsotg-regs + DOEPCTL0));
  
   /* clear global NAKs */
 - writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK,
 + writel(DCTL_CGOUTNAK | DCTL_CGNPINNAK | DCTL_SFTDISCON,
  hsotg-regs + DCTL);
  
   /* must be at-least 3ms to allow bus to see disconnect */
   mdelay(3);
  
   hsotg-last_rst = jiffies;
 +}
 +
 +static void s3c_hsotg_core_disconnect(struct s3c_hsotg *hsotg)
 +{
 + /* set the soft-disconnect bit */
 + __orr32(hsotg-regs + DCTL, DCTL_SFTDISCON);
 +}
  
 +static void s3c_hsotg_core_connect(struct s3c_hsotg *hsotg)
 +{
   /* remove the soft-disconnect and let's go */
   __bic32(hsotg-regs + DCTL, DCTL_SFTDISCON);
  }
 @@ -2348,7 +2357,8 @@ irq_retry:
   kill_all_requests(hsotg, hsotg-eps[0],
 -ECONNRESET, true);
  
 - s3c_hsotg_core_init(hsotg);
 + s3c_hsotg_core_init_disconnected(hsotg);
 + s3c_hsotg_core_connect(hsotg);
   }
   }
   }
 @@ -2983,7 +2993,8 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, 
 int is_on)
   if (is_on) {
   s3c_hsotg_phy_enable(hsotg);
   clk_enable(hsotg-clk);
 - s3c_hsotg_core_init(hsotg);
 + s3c_hsotg_core_init_disconnected(hsotg);
 + s3c_hsotg_core_connect(hsotg);
   } else {
   clk_disable(hsotg-clk);
   s3c_hsotg_phy_disable(hsotg);
 @@ -3670,7 +3681,8 @@ static int s3c_hsotg_resume(struct platform_device 
 *pdev)
  
   spin_lock_irqsave(hsotg-lock, flags);
   s3c_hsotg_phy_enable(hsotg);
 - s3c_hsotg_core_init(hsotg);
 + s3c_hsotg_core_init_disconnect(hsotg);
 + s3c_hsotg_core_connect(hsotg);
   spin_unlock_irqrestore(hsotg-lock, flags);
  
   return ret;
 -- 
 1.9.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

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 7/9] usb: dwc2/gadget: use soft disconnect mode for implementing pullup control

2014-10-16 Thread Felipe Balbi
Hi,

your subject line is wrong. -pullup() is already implemented, you're
moving unnecessary code from -pullup() to other places.

On Thu, Oct 16, 2014 at 02:58:03PM +0200, Marek Szyprowski wrote:
 This patch moves PHY enable and disable calls from pullup method to
 udc_start/stop functions and adds calls to recently introduces soft
 disconnect mode in pullup method. This improves dwc2 gadget driver
 compatibility with gadget API requirements (now pullup method really
 forces soft disconnect mode instead of shutting down the whole hardware)
 and as a side effect also solves the issue related to limited caller
 context for PHY related functions (they cannot be called from
 non-sleeping context).

you're doing two things in one patch. See below

 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 16 +---
  1 file changed, 13 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index d039334967d7..cdf417a7ae63 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2883,6 +2883,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget 
 *gadget,
  struct usb_gadget_driver *driver)
  {
   struct s3c_hsotg *hsotg = to_hsotg(gadget);
 + unsigned long flags;
   int ret;
  
   if (!hsotg) {
 @@ -2919,7 +2920,15 @@ static int s3c_hsotg_udc_start(struct usb_gadget 
 *gadget,
   goto err;
   }
  
 + s3c_hsotg_phy_enable(hsotg);

you moved phy_enable to udc_start/udc_stop (one patch)

 +
 + spin_lock_irqsave(hsotg-lock, flags);
 + s3c_hsotg_init(hsotg);
 + s3c_hsotg_core_init_disconnected(hsotg);

you moved core init here (another patch).

 + spin_unlock_irqrestore(hsotg-lock, flags);
 +
   dev_info(hsotg-dev, bound driver %s\n, driver-driver.name);
 +
   return 0;
  
  err:
 @@ -2957,6 +2966,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
  
   spin_unlock_irqrestore(hsotg-lock, flags);
  
 + s3c_hsotg_phy_disable(hsotg);
 +
   regulator_bulk_disable(ARRAY_SIZE(hsotg-supplies), hsotg-supplies);
  
   clk_disable(hsotg-clk);
 @@ -2990,14 +3001,13 @@ static int s3c_hsotg_pullup(struct usb_gadget 
 *gadget, int is_on)
   dev_dbg(hsotg-dev, %s: is_on: %d\n, __func__, is_on);
  
   spin_lock_irqsave(hsotg-lock, flags);
 +
   if (is_on) {
 - s3c_hsotg_phy_enable(hsotg);
   clk_enable(hsotg-clk);
 - s3c_hsotg_core_init_disconnected(hsotg);
   s3c_hsotg_core_connect(hsotg);
   } else {
 + s3c_hsotg_core_disconnect(hsotg);
   clk_disable(hsotg-clk);
 - s3c_hsotg_phy_disable(hsotg);
   }
  
   hsotg-gadget.speed = USB_SPEED_UNKNOWN;
 -- 
 1.9.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

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 8/9] usb: dwc2/gadget: fix calls to phy control functions in suspend/resume code

2014-10-16 Thread Felipe Balbi
Hi,

On Thu, Oct 16, 2014 at 02:58:04PM +0200, Marek Szyprowski wrote:
 This patch moves calls to phy enable/disable out of spinlock protected
 blocks in device suspend/resume to fix incorrect caller context. Phy
 related functions must not be called from atomic context.
 
 Signed-off-by: Marek Szyprowski m.szyprow...@samsung.com
 ---
  drivers/usb/dwc2/gadget.c | 9 ++---
  1 file changed, 6 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index cdf417a7ae63..052b1a857291 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -3656,11 +3656,13 @@ static int s3c_hsotg_suspend(struct platform_device 
 *pdev, pm_message_t state)
hsotg-driver-driver.name);
  
   spin_lock_irqsave(hsotg-lock, flags);
 + s3c_hsotg_core_disconnect(hsotg);
   s3c_hsotg_disconnect(hsotg);
 - s3c_hsotg_phy_disable(hsotg);
   hsotg-gadget.speed = USB_SPEED_UNKNOWN;
   spin_unlock_irqrestore(hsotg-lock, flags);
  
 + s3c_hsotg_phy_disable(hsotg);

this is aching to have a locked version as well as an unlocked version.
Look at what you do here. There's a minor race when you release that
spinlock. By the time -suspend() is called, IRQs are not yet disabled.

-- 
balbi


signature.asc
Description: Digital signature


External USB3 hard drive fails to connect (JMicron bridge 152d:0569)

2014-10-16 Thread Matej Kenda
Dear USB Linux developers,

I found a problem with external USB 3 enclosure.

I hope that enough information is provided to start analysis of the
problem. I can provide more details if necessary or try patches.

Regards,

Matej


Dear usb-linux developers,

I found a problem with an external USB 3 disk enclosure.

I hope that all relevant information is collected in this report. More
information can be provided if necessary.

Regards,

Matej

[1.] One line summary of the problem: External USB3 hard drive fails
to connect (JMicron bridge 152d:0569)

[2.] Full description of the problem/report:

A Hitachi 2.5 disk in USB 3 disk enclosure IcyBox IB-273StU3 with JMicron
bridge 152d:0569 fails to be connected on Ubuntu Utopic with Linux kernel 3.17.

Disk was connected to

* HP EliteBook 8770W (BIOS was upgraded to latest: F.50)
  * USB 3 ports on laptop
  * USB 2 ports on laptop
  * USB 3 ports on dock
  * external USB 2 HUB with own power supply

* Dell PowerEdge 2900 (USB 2) (Linux kernel 3.13)
* Intel Desktop Board D510MO (USB 2) (Linux kernel 3.13)

The disk is sometimes properly recognised only the first time it is attached
after starting the computer:

[ 346.790756] usb 4-4: new SuperSpeed USB device number 3 using xhci_hcd
[ 346.807293] usb 4-4: New USB device found, idVendor=152d, idProduct=0569
[ 346.807301] usb 4-4: New USB device strings: Mfr=1, Product=2, SerialNumber=5
[ 346.807304] usb 4-4: Product: USB to ATA/ATAPI Bridge
[ 346.807307] usb 4-4: Manufacturer: JMicron
[ 346.807310] usb 4-4: SerialNumber: 4A3337343030383448584B595845
[ 348.477947] usb-storage 4-4:1.0: USB Mass Storage device detected
[ 348.478225] scsi7 : usb-storage 4-4:1.0
[ 348.478395] usbcore: registered new interface driver usb-storage
[ 348.588835] usbcore: registered new interface driver uas
[ 349.475655] scsi 7:0:0:0: Direct-Access Hitachi HTS727575A9E364 PQ: 0 ANSI: 5
[ 349.476095] sd 7:0:0:0: Attached scsi generic sg2 type 0
[ 349.476243] sd 7:0:0:0: [sdb] 1465149168 512-byte logical blocks:
(750 GB/698 GiB)
[ 349.476734] sd 7:0:0:0: [sdb] Test WP failed, assume Write Enabled
[ 349.477219] sd 7:0:0:0: [sdb] Asking for cache data failed
[ 349.477224] sd 7:0:0:0: [sdb] Assuming drive cache: write through
[ 349.760792] sdb: sdb1
[ 349.762218] sd 7:0:0:0: [sdb] Attached SCSI disk
[ 350.097878] EXT4-fs (sdb1): recovery complete
[ 350.098248] EXT4-fs (sdb1): mounted filesystem with ordered data
mode. Opts: (null)
[ 396.016083] usb 4-4: USB disconnect, device number 3

Further attempts fail, regardless of how the disk is attached:

* directly to powered USB 3 port on the laptop
* to USB 3 port in laptop dock
* via USB 2 hub with external power

[  190.748200] usb 3-4: new high-speed USB device number 5 using xhci_hcd
[  190.877017] usb 3-4: New USB device found, idVendor=152d, idProduct=0569
[  190.877025] usb 3-4: New USB device strings: Mfr=1, Product=2, SerialNumber=5
[  190.877029] usb 3-4: Product: USB to ATA/ATAPI Bridge
[  190.877032] usb 3-4: Manufacturer: JMicron
[  190.877035] usb 3-4: SerialNumber: 4A3337343030383448584B595845
[  190.877693] usb-storage 3-4:1.0: USB Mass Storage device detected
[  190.880663] scsi host8: usb-storage 3-4:1.0
[  191.881078] scsi 8:0:0:0: Direct-Access Hitachi
HTS727575A9E364   PQ: 0 ANSI: 5
[  191.881792] sd 8:0:0:0: Attached scsi generic sg2 type 0
[  191.881846] sd 8:0:0:0: [sdb] 1465149168 512-byte logical blocks:
(750 GB/698 GiB)
[  191.882427] sd 8:0:0:0: [sdb] Test WP failed, assume Write Enabled
[  191.882888] sd 8:0:0:0: [sdb] Asking for cache data failed
[  191.882894] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[  192.577075] usb 3-4: reset high-speed USB device number 5 using xhci_hcd
[  192.577154] xhci_hcd :00:14.0: Setup ERROR: setup context
command for slot 5.
[  192.577163] usb 3-4: hub failed to enable device, error -22
[  192.689018] usb 3-4: reset high-speed USB device number 5 using xhci_hcd
[  192.689089] xhci_hcd :00:14.0: Setup ERROR: setup context
command for slot 5.
[  192.689099] usb 3-4: hub failed to enable device, error -22
[  192.800977] usb 3-4: reset high-speed USB device number 5 using xhci_hcd
[  192.817405] xhci_hcd :00:14.0: xHCI xhci_drop_endpoint called
with disabled ep 8800b8556000
[  192.817414] xhci_hcd :00:14.0: xHCI xhci_drop_endpoint called
with disabled ep 8800b8556048
[  192.937305] usb 3-4: reset high-speed USB device number 5 using xhci_hcd
[  192.937384] xhci_hcd :00:14.0: Setup ERROR: setup context
command for slot 5.
[  192.937394] usb 3-4: hub failed to enable device, error -22
[  193.049091] usb 3-4: reset high-speed USB device number 5 using xhci_hcd
[  193.049161] xhci_hcd :00:14.0: Setup ERROR: setup context
command for slot 5.


[3.] Keywords (i.e., modules, networking, kernel):

[4.] Kernel version (from /proc/version):

Linux version 3.17.0-031700-generic (apw@gomeisa) (gcc version 4.6.3
(Ubuntu/Linaro 4.6.3-1ubuntu5) ) #201410060605 SMP Mon Oct 6 10:07:09
UTC 2014

[5.] Output 

Re: xhci_hcd can't detect new devices after enabling runtime PM and disabling S3 wake (bug #85701)

2014-10-16 Thread Alan Stern
On Thu, 16 Oct 2014, Lu, Baolu wrote:

 
 On 10/15/2014 6:07 PM, Dmitry Nezhevenko wrote:
  On Sat, Oct 11, 2014 at 03:51:47PM +0800, Lu, Baolu wrote:
  Hi Dmitry,
 
  Can you please try to disable wakeup of root hub instead of host 
  controller?
 
  Hi,
 
  Sorry for delay. Can you please suggest how to do this?
 
 I always do this with below steps. lsusb -t on my machine prints
 
 allen@allen-ivb:/sys/bus/pci/devices/:00:14.0/usb3$ lsusb -t
 /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
 /:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M
  |__ Port 3: Dev 2, If 0, Class=Hub, Driver=hub/3p, 12M
  |__ Port 1: Dev 3, If 0, Class=Human Interface Device, 
 Driver=usbhid, 12M
  |__ Port 1: Dev 3, If 1, Class=Human Interface Device, 
 Driver=usbhid, 12M
 /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
  |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
  |__ Port 5: Dev 3, If 0, Class=Human Interface Device, 
 Driver=usbhid, 1.5M
  |__ Port 6: Dev 4, If 0, Class=Human Interface Device, 
 Driver=usbhid, 1.5M
  |__ Port 6: Dev 4, If 1, Class=Human Interface Device, 
 Driver=usbhid, 1.5M
 /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
  |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
 
 I want to disable remote wake up of xHC USB2 root hub (/:  Bus 03.Port 
 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 480M).
 
 Find the sys device path of the host controller. (You might need to use 
 lspci to get the bus/dev/fun of your xHC).
 
 On my machine, it's /sys/bus/pci/devices/:00:14.0.
 
 root@allen-ivb:/sys/devices/pci:00/:00:14.0# echo disabled  
 usb3/power/wakeup

It doesn't have to be so complicated.  You can simply do:

echo disabled /sys/bus/usb/devices/usb3/power/wakeup

However that file contains disabled by default, so doing this may not 
accomplish anything.

Alan Stern

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


Re: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Alan Stern
On Thu, 16 Oct 2014, Naveen Kumar Parna wrote:

  Indeed. However, it is possible to use an additional in between your
  devices and the internal hub.
 
  Regards
  Oliver
 
 
 
 
 Tested with this configuration(external hubs Dev 3, Dev 4, Dev 17, Dev
 10) and got the same result.
 
 /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
 
 /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
 
 |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M
 
 |__ Port 5: Dev 3, If 0, Class=hub, Driver=hub/7p, 12M
 
 |__ Port 1: Dev 4, If 0, Class=hub, Driver=hub/7p, 12M

This is not what Oliver meant.  You have to use a USB-2 hub.  And 
having one of them is enough; you don't need two.

Alan Stern

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


Re: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Alan Stern
On Thu, 16 Oct 2014, Naveen Kumar Parna wrote:

  It's entirely possible that the stall packets are created by the hub.
  When a full-speed device is connected to a USB-2 hub, and the device
  fails to respond to a packet sent by the host, the hub reports this
  failure as a stall.
 
 Here I don’t think device fails to respond to a packet sent by the
 host. I verified this by connecting Ellisys USB analyser in between
 host and devices.
 
 For example Look at the attached(Sample_HciEvt.png) HCI event captured
 by Ellisys USB analyser. It is a valid HCI event from device to Host.
 IN transaction 96 1 ACK FS 16 bytes (FF 2F C2 01 00 17 00 DF 00 01 10
 00 00 A9 EE 0F)
 IN transaction 96 1 ACK FS 16 bytes (00 00 00 5A 06 9D 39 00 00 66 00
 00 00 00 00 00)
 IN transaction 96 1 ACK FS 16 bytes (00 00 00 00 00 00 00 00 00 00 00
 8E 05 28 00 01)
 IN transaction 96 1 ACK FS 1 byte (00)

This doesn't prove anything.  All it means is that the device responded 
properly on these four occasions.  What if the device failed to respond 
on some other occasion?  You have to compare the output of the analyzer 
with the output from usbmon.  If usbmon shows a STALL and the analyzer 
shows a valid reply for the very same packet, then you'll know the 
device isn't at fault.

You should also run a similar test when you connect the device through
a USB-2 hub.  In fact, you should run two tests.  In one test, connect
the analyzer to the cable segment between the computer and the hub; in 
the other test, connect the analyzer to the cable segment between the 
hub and the device.

Alan Stern

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


Re: [PATCH v2 2/2] usb: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Sudip Mukherjee
On Thu, Oct 16, 2014 at 08:21:55AM -0500, Felipe Balbi wrote:
 HI,
 
 On Thu, Oct 16, 2014 at 01:11:10PM +0530, Sudip Mukherjee wrote:
  sparse was giving the following warning:
  warning: context imbalance in 's3c_hsotg_ep_enable'
  - different lock contexts for basic block
  
  we were returning ENOMEM while still holding the spinlock.
  The sparse warning was fixed by releasing the spinlock before return.
  
  This patch depends on the previous patch of the series.
  
  Signed-off-by: Sudip Mukherjee su...@vectorindia.org
 
 this should be patch one so it can be backported to stable kernels.
 
my v1 patch fixed only this , while reviewing that one Paul Zimmerman suggested 
to rewrite the return statements.
so this v2 series had the rewrite and the spinlock error fix.
now if this is to be made the patch one then it will be a duplicate of my v1 
followed by another patch for return statements. 
should i do that ?

thanks
sudip

 -- 
 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: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 08:22:08PM +0530, Sudip Mukherjee wrote:
 On Thu, Oct 16, 2014 at 08:21:55AM -0500, Felipe Balbi wrote:
  HI,
  
  On Thu, Oct 16, 2014 at 01:11:10PM +0530, Sudip Mukherjee wrote:
   sparse was giving the following warning:
   warning: context imbalance in 's3c_hsotg_ep_enable'
 - different lock contexts for basic block
   
   we were returning ENOMEM while still holding the spinlock.
   The sparse warning was fixed by releasing the spinlock before return.
   
   This patch depends on the previous patch of the series.
   
   Signed-off-by: Sudip Mukherjee su...@vectorindia.org
  
  this should be patch one so it can be backported to stable kernels.
  
 my v1 patch fixed only this , while reviewing that one Paul Zimmerman
 suggested to rewrite the return statements.
 so this v2 series had the rewrite and the spinlock error fix.
 now if this is to be made the patch one then it will be a duplicate of
 my v1 followed by another patch for return statements. 
 should i do that ?

Paul has the final word on this driver, if he already asked you to
change, I withdraw my comment ;-)

cheers

-- 
balbi


signature.asc
Description: Digital signature


Re: External USB3 hard drive fails to connect (JMicron bridge 152d:0569)

2014-10-16 Thread Oliver Neukum
On Thu, 2014-10-16 at 15:58 +0200, Matej Kenda wrote:
 Dear USB Linux developers,
 
 I found a problem with external USB 3 enclosure.
 
 I hope that enough information is provided to start analysis of the
 problem. I can provide more details if necessary or try patches.

Is this a regression? Did you test any (older) other kernel?

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: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Naveen Kumar Parna
Ok, I will do this and update you.
But Currently I am on long leave and I can update you on 27th Oct.

Thanks,
Naveen

On Thu, Oct 16, 2014 at 7:39 PM, Alan Stern st...@rowland.harvard.edu wrote:
 On Thu, 16 Oct 2014, Naveen Kumar Parna wrote:

  Indeed. However, it is possible to use an additional in between your
  devices and the internal hub.
 
  Regards
  Oliver
 
 


 Tested with this configuration(external hubs Dev 3, Dev 4, Dev 17, Dev
 10) and got the same result.

 /:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M

 /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M

 |__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M

 |__ Port 5: Dev 3, If 0, Class=hub, Driver=hub/7p, 12M

 |__ Port 1: Dev 4, If 0, Class=hub, Driver=hub/7p, 12M

 This is not what Oliver meant.  You have to use a USB-2 hub.  And
 having one of them is enough; you don't need two.

 Alan Stern

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


[PATCH] storage: Enable multi-target mode as vendor driver does for SCM eUSCSI bridge

2014-10-16 Thread Mark Knibbs
Hi,

usb_stor_euscsi_init() enables multi-target mode for SCM eUSB SCSI bridge
devices. The control message it sends has wLength = 1 and the byte sent is
0x01. While that works, the SCM driver does it with wLength = 0. We may as
well match what the SCM driver does.

This also includes the change from
 [PATCH] storage: Replace magic number with define in usb_stor_euscsi_init()


Signed-off-by: Mark Knibbs ma...@clara.co.uk

---
diff -up linux-3.17/drivers/usb/storage/initializers.c.orig 
linux-3.17/drivers/usb/storage/initializers.c  
--- linux-3.17/drivers/usb/storage/initializers.c.orig  2014-10-05 
20:23:04.0 +0100
+++ linux-3.17/drivers/usb/storage/initializers.c   2014-10-16 
13:39:04.497910732 +0100
@@ -49,10 +49,9 @@ int usb_stor_euscsi_init(struct us_data
int result;
 
usb_stor_dbg(us, Attempting to init eUSCSI bridge...\n);
-   us-iobuf[0] = 0x1;
result = usb_stor_control_msg(us, us-send_ctrl_pipe,
0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
-   0x01, 0x0, us-iobuf, 0x1, 5000);
+   0x01, 0x0, NULL, 0x0, USB_CTRL_SET_TIMEOUT);
usb_stor_dbg(us, -- result is %d\n, result);
 
return 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: External USB3 hard drive fails to connect (JMicron bridge 152d:0569)

2014-10-16 Thread Matej Kenda
Hi Oliver,

 On 16. okt. 2014, at 17:02, Oliver Neukum oneu...@suse.de wrote:
 
 On Thu, 2014-10-16 at 15:58 +0200, Matej Kenda wrote:
 Dear USB Linux developers,
 
 I found a problem with external USB 3 enclosure.
 
 Is this a regression? Did you test any (older) other kernel?

The problem was originaly discovered on 3.13, then I tested on 3.14, 3.16 and 
3.17. 

It did work on any of these kernels. 

Regards,

Matej

--
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: btusb_intr_complete returns -EPIPE

2014-10-16 Thread Naveen Kumar Parna
On Thu, Oct 16, 2014 at 7:46 PM, Alan Stern st...@rowland.harvard.edu wrote:
 On Thu, 16 Oct 2014, Naveen Kumar Parna wrote:

  It's entirely possible that the stall packets are created by the hub.
  When a full-speed device is connected to a USB-2 hub, and the device
  fails to respond to a packet sent by the host, the hub reports this
  failure as a stall.

 Here I don’t think device fails to respond to a packet sent by the
 host. I verified this by connecting Ellisys USB analyser in between
 host and devices.

 For example Look at the attached(Sample_HciEvt.png) HCI event captured
 by Ellisys USB analyser. It is a valid HCI event from device to Host.
 IN transaction 96 1 ACK FS 16 bytes (FF 2F C2 01 00 17 00 DF 00 01 10
 00 00 A9 EE 0F)
 IN transaction 96 1 ACK FS 16 bytes (00 00 00 5A 06 9D 39 00 00 66 00
 00 00 00 00 00)
 IN transaction 96 1 ACK FS 16 bytes (00 00 00 00 00 00 00 00 00 00 00
 8E 05 28 00 01)
 IN transaction 96 1 ACK FS 1 byte (00)

 This doesn't prove anything.  All it means is that the device responded
 properly on these four occasions.  What if the device failed to respond
 on some other occasion?  You have to compare the output of the analyzer
 with the output from usbmon.  If usbmon shows a STALL and the analyzer
 shows a valid reply for the very same packet, then you'll know the
 device isn't at fault.



I forgot to post usbmon log, but usbmon shows a STALL and the analyser
shows a valid reply for the very same packet.

I tried this many number of times and always got same result.

But did not get STALL on OHCI-USB host controller on PCI card with
internal USB 1.1 hub. In both the scenario’s I used same devices.




 You should also run a similar test when you connect the device through
 a USB-2 hub.  In fact, you should run two tests.  In one test, connect
 the analyzer to the cable segment between the computer and the hub; in
 the other test, connect the analyzer to the cable segment between the
 hub and the device.



Ok, I will try and update you on this.




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


IPD in xHCI vs. EHCI

2014-10-16 Thread Bin Liu
Hi,

While investigating a USB performance problem, I observed the same
issue as described in [1], which is that xHCI takes 10-15 times longer
than EHCI to send the IN packet after received NAK - 20-30us vs. 2us.

Does anyone have any comment? I am wondering if the xHCI IPD is sw
configurable? Might depend on the xHCI IP revision or vendor?

Thanks,
-Bin.

[1] https://communities.intel.com/message/228140
--
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: OHCI: ohci-at91: remove unnecessary headers

2014-10-16 Thread Alexandre Belloni
Remove unnecessary mach/* headers to be able to converge to a multiplatform
kernel.

Signed-off-by: Alexandre Belloni alexandre.bell...@free-electrons.com
---
 drivers/usb/host/ohci-at91.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index e49eb4f90f5d..6181549883af 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -24,12 +24,8 @@
 #include linux/usb.h
 #include linux/usb/hcd.h
 
-#include mach/hardware.h
 #include asm/gpio.h
 
-#include mach/cpu.h
-
-
 #include ohci.h
 
 #define valid_port(index)  ((index) = 0  (index)  AT91_MAX_USBH_PORTS)
-- 
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: External USB3 hard drive fails to connect (JMicron bridge 152d:0569)

2014-10-16 Thread Matej Kenda
Hi,

I apologise for a typo.

On 16. okt. 2014, at 17:15, Matej Kenda matej...@gmail.com wrote:

 The problem was originaly discovered on 3.13, then I tested on 3.14, 3.16 and 
 3.17. 
 
 It did work on any of these kernels. 

Correction:

It did *not work* on any of these kernels.

Regards,

Matej

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


Re: [RFC PATCH 1/2] usb: dwc2: add clock manage for hcd

2014-10-16 Thread Kever Yang

Hi Felipe,

Thank for comment.

On 10/16/2014 06:23 AM, Felipe Balbi wrote:

Hi,

On Wed, Oct 15, 2014 at 10:46:17PM -0700, Kever Yang wrote:

This patch move clock init out of gadget into platform,
make both hcd and gadget can use the clock

Signed-off-by: Kever Yang kever.y...@rock-chips.com
---

  drivers/usb/dwc2/gadget.c   | 16 ++--
  drivers/usb/dwc2/hcd.c  |  3 +++
  drivers/usb/dwc2/platform.c | 30 ++
  3 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index fa49c72..fddd923 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -46,6 +46,7 @@
  #include linux/delay.h
  #include linux/io.h
  #include linux/slab.h
+#include linux/clk.h
  #include linux/usb.h
  
  #include linux/usb/hcd.h

@@ -2266,6 +2267,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
spin_lock_irqsave(hsotg-lock, flags);
  
  	hcd-state = HC_STATE_RUNNING;

+   clk_enable(hsotg-clk);

with this you're moving clk_enable() from gadget to HCD. You might want
to leave this completely to the glue; at least for now.

No, I moving devm_clk_get/clk_prerare_enable/clk_disable_unprepare
to platform, but not effect clk_enable/disable in the gadget.

I send this patch for comments if we can do it in this way.
If not, how should we manage clock in hcd and gadget?

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


Re: [RFC PATCH 2/2] usb: dwc2: add bus suspend/resume for dwc2

2014-10-16 Thread Kever Yang

Hi Felipe,

On 10/16/2014 06:30 AM, Felipe Balbi wrote:

On Wed, Oct 15, 2014 at 10:46:18PM -0700, Kever Yang wrote:

This patch add suspend/resume for dwc2 hcd controller.

adds


Signed-off-by: Kever Yang kever.y...@rock-chips.com
---

  drivers/usb/dwc2/hcd.c | 71 ++
  1 file changed, 60 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index fddd923..c1801d8 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -1474,6 +1474,23 @@ static void dwc2_port_suspend(struct dwc2_hsotg *hsotg, 
u16 windex)
}
  }
  
+static void dwc2_port_resume(struct dwc2_hsotg *hsotg)

+{
+   u32 hprt0;
+
+   writel(0, hsotg-regs + PCGCTL);
+   usleep_range(2, 4);

why this usleep_range() ? Is it documented somewhere ? How about adding
a comment explaining why you need to wait at least 20ms ?

This is a straight copy of CLEAR_FEATURE(PORT_SUSPEND) code
in dwc2_hcd_hub_control(), maybe Paul knows the detail?

I will check with USB2.0 spec and DWC databook to figure out
how long the delay it should be.




+   hprt0 = dwc2_read_hprt0(hsotg);
+   hprt0 |= HPRT0_RES;
+   writel(hprt0, hsotg-regs + HPRT0);
+   hprt0 = ~HPRT0_SUSP;
+   usleep_range(10, 15);

and another one here, why ?


+   hprt0 = ~HPRT0_RES;
+   writel(hprt0, hsotg-regs + HPRT0);
+}
+
  /* Handles hub class-specific requests */
  static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, u16 typereq,
u16 wvalue, u16 windex, char *buf, u16 wlength)
@@ -1519,17 +1536,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg 
*hsotg, u16 typereq,
case USB_PORT_FEAT_SUSPEND:
dev_dbg(hsotg-dev,
ClearPortFeature USB_PORT_FEAT_SUSPEND\n);
-   writel(0, hsotg-regs + PCGCTL);
-   usleep_range(2, 4);
-
-   hprt0 = dwc2_read_hprt0(hsotg);
-   hprt0 |= HPRT0_RES;
-   writel(hprt0, hsotg-regs + HPRT0);
-   hprt0 = ~HPRT0_SUSP;
-   usleep_range(10, 15);
-
-   hprt0 = ~HPRT0_RES;
-   writel(hprt0, hsotg-regs + HPRT0);
+   dwc2_port_resume(hsotg);
break;
  
  		case USB_PORT_FEAT_POWER:

@@ -2304,6 +2311,45 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd)
usleep_range(1000, 3000);
  }
  
+static int _dwc2_hcd_suspend(struct usb_hcd *hcd)

+{
+   struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+   u32 hprt0;
+
+   if (hsotg-op_state != OTG_STATE_B_HOST)
+   return 0;
+
+   if (hsotg-lx_state != DWC2_L0)
+   return 0;
+
+   hprt0 = dwc2_read_hprt0(hsotg);
+   if (hprt0 | HPRT0_CONNSTS)

did you mean:

if (hprt0  HPRT0_CONNSTS) ??


+   dwc2_port_suspend(hsotg, 1);

always 1 ?


+   clk_disable(hsotg-clk);

this I keep getting wrong, but if -bus_suspend() is really the one used
for actual system sleep, then you might want to fiddle with the clocks
only from the parent platform glue. I haven't really read the code to
make sure, however, so this might be a completely bogus comment :-)


+   return 0;
+}
+
+static int _dwc2_hcd_resume(struct usb_hcd *hcd)
+{
+   struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+   u32 hprt0;
+
+   if (hsotg-op_state != OTG_STATE_B_HOST)
+   return 0;
+
+   if (hsotg-lx_state != DWC2_L2)
+   return 0;
+
+   clk_enable(hsotg-clk);
+
+   hprt0 = dwc2_read_hprt0(hsotg);
+   if (hprt0 | HPRT0_CONNSTS | HPRT0_SUSP)

and here:

if ((hprt0  HPRT0_CONNSTS) 
(hprt0  HPRT0_SUSP))  ???



--
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: OHCI: ohci-at91: remove unnecessary headers

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 05:52:38PM +0200, Alexandre Belloni wrote:
 Remove unnecessary mach/* headers to be able to converge to a multiplatform
 kernel.
 
 Signed-off-by: Alexandre Belloni alexandre.bell...@free-electrons.com

Very nice

Reviewed-by: Felipe Balbi ba...@ti.com

 ---
  drivers/usb/host/ohci-at91.c | 4 
  1 file changed, 4 deletions(-)
 
 diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
 index e49eb4f90f5d..6181549883af 100644
 --- a/drivers/usb/host/ohci-at91.c
 +++ b/drivers/usb/host/ohci-at91.c
 @@ -24,12 +24,8 @@
  #include linux/usb.h
  #include linux/usb/hcd.h
  
 -#include mach/hardware.h
  #include asm/gpio.h
  
 -#include mach/cpu.h
 -
 -
  #include ohci.h
  
  #define valid_port(index)((index) = 0  (index)  AT91_MAX_USBH_PORTS)
 -- 
 1.9.1
 

-- 
balbi


signature.asc
Description: Digital signature


Re: [RFC PATCH 1/2] usb: dwc2: add clock manage for hcd

2014-10-16 Thread Felipe Balbi
On Thu, Oct 16, 2014 at 09:41:27AM -0700, Kever Yang wrote:
 Hi Felipe,
 
 Thank for comment.
 
 On 10/16/2014 06:23 AM, Felipe Balbi wrote:
 Hi,
 
 On Wed, Oct 15, 2014 at 10:46:17PM -0700, Kever Yang wrote:
 This patch move clock init out of gadget into platform,
 make both hcd and gadget can use the clock
 
 Signed-off-by: Kever Yang kever.y...@rock-chips.com
 ---
 
   drivers/usb/dwc2/gadget.c   | 16 ++--
   drivers/usb/dwc2/hcd.c  |  3 +++
   drivers/usb/dwc2/platform.c | 30 ++
   3 files changed, 23 insertions(+), 26 deletions(-)
 
 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
 index fa49c72..fddd923 100644
 --- a/drivers/usb/dwc2/hcd.c
 +++ b/drivers/usb/dwc2/hcd.c
 @@ -46,6 +46,7 @@
   #include linux/delay.h
   #include linux/io.h
   #include linux/slab.h
 +#include linux/clk.h
   #include linux/usb.h
   #include linux/usb/hcd.h
 @@ -2266,6 +2267,7 @@ static int _dwc2_hcd_start(struct usb_hcd *hcd)
 spin_lock_irqsave(hsotg-lock, flags);
 hcd-state = HC_STATE_RUNNING;
 +   clk_enable(hsotg-clk);
 with this you're moving clk_enable() from gadget to HCD. You might want
 to leave this completely to the glue; at least for now.
 No, I moving devm_clk_get/clk_prerare_enable/clk_disable_unprepare
 to platform, but not effect clk_enable/disable in the gadget.
 
 I send this patch for comments if we can do it in this way.
 If not, how should we manage clock in hcd and gadget?

As a first cut, I'd say only platform glue manages it. You can, anyway,
hide clk_enable()/disable() under
-runtime_resume()/-runtime_suspend() and linux driver model will
guarantee that will be called in the correct order. E.g.:

-runtime_resume(parent);
for_each_child(parent)
-runtime_resume(child);

conversely on suspend:

for_each_child(parent)
-runtime_suspend(child);
-runtime_suspend(parent);

-- 
balbi


signature.asc
Description: Digital signature


Re: [RFC PATCH 2/2] usb: dwc2: add bus suspend/resume for dwc2

2014-10-16 Thread Felipe Balbi
Hi,

On Thu, Oct 16, 2014 at 09:51:38AM -0700, Kever Yang wrote:
 This patch add suspend/resume for dwc2 hcd controller.
 adds
 
 Signed-off-by: Kever Yang kever.y...@rock-chips.com
 ---
 
   drivers/usb/dwc2/hcd.c | 71 
  ++
   1 file changed, 60 insertions(+), 11 deletions(-)
 
 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
 index fddd923..c1801d8 100644
 --- a/drivers/usb/dwc2/hcd.c
 +++ b/drivers/usb/dwc2/hcd.c
 @@ -1474,6 +1474,23 @@ static void dwc2_port_suspend(struct dwc2_hsotg 
 *hsotg, u16 windex)
 }
   }
 +static void dwc2_port_resume(struct dwc2_hsotg *hsotg)
 +{
 +   u32 hprt0;
 +
 +   writel(0, hsotg-regs + PCGCTL);
 +   usleep_range(2, 4);
 why this usleep_range() ? Is it documented somewhere ? How about adding
 a comment explaining why you need to wait at least 20ms ?
 This is a straight copy of CLEAR_FEATURE(PORT_SUSPEND) code
 in dwc2_hcd_hub_control(), maybe Paul knows the detail?

Probably :-)

 I will check with USB2.0 spec and DWC databook to figure out
 how long the delay it should be.

Thank you, that helps.

-- 
balbi


signature.asc
Description: Digital signature


[PATCH] USB: kobil_sct: Remove unused transfer buffer allocs

2014-10-16 Thread Peter Hurley
Commit 90419cfcb5d9c889b10dc51363c56a4d394d670e,
USB: kobil_sct: fix control requests without data stage, removed
the bogus data buffer arguments, but still allocate transfer
buffers which are not used.

Cc: Johan Hovold jhov...@gmail.com
Signed-off-by: Peter Hurley pe...@hurleysoftware.com
---
 drivers/usb/serial/kobil_sct.c | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 078f9ed..3d2bd65 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -414,8 +414,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
int result;
int dtr = 0;
int rts = 0;
-   unsigned char *transfer_buffer;
-   int transfer_buffer_length = 8;
 
/* FIXME: locking ? */
priv = usb_get_serial_port_data(port);
@@ -425,11 +423,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
return -EINVAL;
}
 
-   /* allocate memory for transfer buffer */
-   transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
-   if (!transfer_buffer)
-   return -ENOMEM;
-
if (set  TIOCM_RTS)
rts = 1;
if (set  TIOCM_DTR)
@@ -469,7 +462,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
KOBIL_TIMEOUT);
}
dev_dbg(dev, %s - Send set_status_line URB returns: %i\n, __func__, 
result);
-   kfree(transfer_buffer);
return (result  0) ? result : 0;
 }
 
@@ -530,8 +522,6 @@ static int kobil_ioctl(struct tty_struct *tty,
 {
struct usb_serial_port *port = tty-driver_data;
struct kobil_private *priv = usb_get_serial_port_data(port);
-   unsigned char *transfer_buffer;
-   int transfer_buffer_length = 8;
int result;
 
if (priv-device_type == KOBIL_USBTWIN_PRODUCT_ID ||
@@ -541,10 +531,6 @@ static int kobil_ioctl(struct tty_struct *tty,
 
switch (cmd) {
case TCFLSH:
-   transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
-   if (!transfer_buffer)
-   return -ENOBUFS;
-
result = usb_control_msg(port-serial-dev,
  usb_sndctrlpipe(port-serial-dev, 0),
  SUSBCRequest_Misc,
@@ -559,7 +545,6 @@ static int kobil_ioctl(struct tty_struct *tty,
dev_dbg(port-dev,
%s - Send reset_all_queues (FLUSH) URB returns: %i\n,
__func__, result);
-   kfree(transfer_buffer);
return (result  0) ? -EIO: 0;
default:
return -ENOIOCTLCMD;
-- 
2.1.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: kobil_sct: Remove unused transfer buffer allocs

2014-10-16 Thread Peter Hurley
On 10/16/2014 01:59 PM, Peter Hurley wrote:
 Commit 90419cfcb5d9c889b10dc51363c56a4d394d670e,
 USB: kobil_sct: fix control requests without data stage, removed
 the bogus data buffer arguments, but still allocate transfer
 buffers which are not used.
 
 Cc: Johan Hovold jhov...@gmail.com
 Signed-off-by: Peter Hurley pe...@hurleysoftware.com
 ---
  drivers/usb/serial/kobil_sct.c | 15 ---
  1 file changed, 15 deletions(-)
 
 diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
 index 078f9ed..3d2bd65 100644
 --- a/drivers/usb/serial/kobil_sct.c
 +++ b/drivers/usb/serial/kobil_sct.c
 @@ -414,8 +414,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
   int result;
   int dtr = 0;
   int rts = 0;
 - unsigned char *transfer_buffer;
 - int transfer_buffer_length = 8;
  
   /* FIXME: locking ? */
   priv = usb_get_serial_port_data(port);
 @@ -425,11 +423,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
   return -EINVAL;
   }
  
 - /* allocate memory for transfer buffer */
 - transfer_buffer = kzalloc(transfer_buffer_length, GFP_KERNEL);
 - if (!transfer_buffer)
 - return -ENOMEM;
 -
   if (set  TIOCM_RTS)
   rts = 1;
   if (set  TIOCM_DTR)
 @@ -469,7 +462,6 @@ static int kobil_tiocmset(struct tty_struct *tty,
   KOBIL_TIMEOUT);
   }
   dev_dbg(dev, %s - Send set_status_line URB returns: %i\n, __func__, 
 result);
 - kfree(transfer_buffer);
   return (result  0) ? result : 0;
  }
  
 @@ -530,8 +522,6 @@ static int kobil_ioctl(struct tty_struct *tty,
  {
   struct usb_serial_port *port = tty-driver_data;
   struct kobil_private *priv = usb_get_serial_port_data(port);
 - unsigned char *transfer_buffer;
 - int transfer_buffer_length = 8;
   int result;
  
   if (priv-device_type == KOBIL_USBTWIN_PRODUCT_ID ||
 @@ -541,10 +531,6 @@ static int kobil_ioctl(struct tty_struct *tty,
  
   switch (cmd) {
   case TCFLSH:
 - transfer_buffer = kmalloc(transfer_buffer_length, GFP_KERNEL);
 - if (!transfer_buffer)
 - return -ENOBUFS;
 -
   result = usb_control_msg(port-serial-dev,
 usb_sndctrlpipe(port-serial-dev, 0),
 SUSBCRequest_Misc,
 @@ -559,7 +545,6 @@ static int kobil_ioctl(struct tty_struct *tty,
   dev_dbg(port-dev,
   %s - Send reset_all_queues (FLUSH) URB returns: %i\n,
   __func__, result);
 - kfree(transfer_buffer);
   return (result  0) ? -EIO: 0;
   ^^^
Returning 0 is almost certainly wrong; no further processing for
TCFLSH is performed.

Only this driver returns 0 (of all the tty drivers in mainline).

Returning -ENOIOCTLCMD allows further processing to continue;
especially the line discipline's input flushing, if TCIFLUSH/TCIOFLUSH.

Is it trying to avoid the tty_driver_flush_buffer() because it doesn't
have an output buffer?

   default:
   return -ENOIOCTLCMD;
 

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


RE: [PATCH v2 2/2] usb: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Paul Zimmerman
 From: Sudip Mukherjee [mailto:sudipm.mukher...@gmail.com]
 Sent: Thursday, October 16, 2014 7:52 AM
 
 On Thu, Oct 16, 2014 at 08:21:55AM -0500, Felipe Balbi wrote:
  HI,
 
  On Thu, Oct 16, 2014 at 01:11:10PM +0530, Sudip Mukherjee wrote:
   sparse was giving the following warning:
   warning: context imbalance in 's3c_hsotg_ep_enable'
 - different lock contexts for basic block
  
   we were returning ENOMEM while still holding the spinlock.
   The sparse warning was fixed by releasing the spinlock before return.
  
   This patch depends on the previous patch of the series.
  
   Signed-off-by: Sudip Mukherjee su...@vectorindia.org
 
  this should be patch one so it can be backported to stable kernels.
 
 my v1 patch fixed only this , while reviewing that one Paul Zimmerman 
 suggested to rewrite the return
 statements.
 so this v2 series had the rewrite and the spinlock error fix.
 now if this is to be made the patch one then it will be a duplicate of my v1 
 followed by another patch
 for return statements.
 should i do that ?

Hi Sudip,

Please make the first patch like I showed in my previous reply. Then we
can mark that one for stable to fix the bug. Then make a second patch to
change the other error path.

-- 
Paul

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


[PATCH V2] USB: dwc2: add support for the reset_controller api

2014-10-16 Thread John Crispin
We need this for dwc2 to work on older ralink SoC like the rt3052. Without, we
see the following when loading the driver:

[0.76] dwc2 101c.usb: Bad value for GSNPSID: 0x

Signed-off-by: John Crispin blo...@openwrt.org
---
Changes since V1
* move the OF lookup call into the platform code
* add code to the cleanup path that puts the core back into reset

 drivers/usb/dwc2/core.h |3 +++
 drivers/usb/dwc2/hcd.c  |   11 +++
 drivers/usb/dwc2/platform.c |5 +
 3 files changed, 19 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 1efd10c..8dfd16a 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -42,6 +42,7 @@
 #include linux/usb/gadget.h
 #include linux/usb/otg.h
 #include linux/usb/phy.h
+#include linux/reset.h
 #include hw.h
 
 #ifdef DWC2_LOG_WRITES
@@ -596,6 +597,8 @@ struct dwc2_hsotg {
unsigned int queuing_high_bandwidth:1;
unsigned int srp_success:1;
 
+   struct reset_control *reset_control;
+
struct workqueue_struct *wq_otg;
struct work_struct wf_otg;
struct timer_list wkp_timer;
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 4d918ed..ff2ca4b 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2764,6 +2764,14 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
 
dev_dbg(hsotg-dev, DWC OTG HCD INIT\n);
 
+   /* bring the device out of reset */
+   if (hsotg-reset_control) {
+   int retval = reset_control_deassert(hsotg-reset_control);
+
+   if (retval)
+   return retval;
+   }
+
/* Detect config values from hardware */
retval = dwc2_get_hwparams(hsotg);
 
@@ -2973,6 +2981,9 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
dwc2_hcd_release(hsotg);
usb_put_hcd(hcd);
 
+   if (hsotg-reset_control)
+   reset_control_assert(hsotg-reset_control);
+
 #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
kfree(hsotg-last_frame_num_array);
kfree(hsotg-frame_num_array);
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index a10e7a3..6d74583 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -120,6 +120,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
const struct dwc2_core_params *params;
struct dwc2_core_params defparams;
struct dwc2_hsotg *hsotg;
+   struct reset_control *reset_control;
struct resource *res;
int retval;
int irq;
@@ -171,6 +172,10 @@ static int dwc2_driver_probe(struct platform_device *dev)
dev_dbg(dev-dev, mapped PA %08lx to VA %p\n,
(unsigned long)res-start, hsotg-regs);
 
+   reset_control = devm_reset_control_get(dev-dev, NULL);
+   if (!IS_ERR(reset_control))
+   hsotg-reset_control = reset_control;
+
retval = dwc2_hcd_init(hsotg, irq, params);
if (retval)
return retval;
-- 
1.7.10.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 V2] USB: dwc2: add support for the reset_controller api

2014-10-16 Thread Paul Zimmerman
 From: linux-usb-ow...@vger.kernel.org 
 [mailto:linux-usb-ow...@vger.kernel.org] On Behalf Of John Crispin
 Sent: Thursday, October 16, 2014 1:34 PM
 
 We need this for dwc2 to work on older ralink SoC like the rt3052. Without, we
 see the following when loading the driver:
 
 [0.76] dwc2 101c.usb: Bad value for GSNPSID: 0x
 
 Signed-off-by: John Crispin blo...@openwrt.org
 ---
 Changes since V1
 * move the OF lookup call into the platform code
 * add code to the cleanup path that puts the core back into reset
 
  drivers/usb/dwc2/core.h |3 +++
  drivers/usb/dwc2/hcd.c  |   11 +++
  drivers/usb/dwc2/platform.c |5 +
  3 files changed, 19 insertions(+)
 
 diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
 index 1efd10c..8dfd16a 100644
 --- a/drivers/usb/dwc2/core.h
 +++ b/drivers/usb/dwc2/core.h
 @@ -42,6 +42,7 @@
  #include linux/usb/gadget.h
  #include linux/usb/otg.h
  #include linux/usb/phy.h
 +#include linux/reset.h
  #include hw.h
 
  #ifdef DWC2_LOG_WRITES
 @@ -596,6 +597,8 @@ struct dwc2_hsotg {
   unsigned int queuing_high_bandwidth:1;
   unsigned int srp_success:1;
 
 + struct reset_control *reset_control;
 +

Please also add a kerneldoc header for this to the comment block.

   struct workqueue_struct *wq_otg;
   struct work_struct wf_otg;
   struct timer_list wkp_timer;
 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
 index 4d918ed..ff2ca4b 100644
 --- a/drivers/usb/dwc2/hcd.c
 +++ b/drivers/usb/dwc2/hcd.c
 @@ -2764,6 +2764,14 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
 
   dev_dbg(hsotg-dev, DWC OTG HCD INIT\n);
 
 + /* bring the device out of reset */
 + if (hsotg-reset_control) {
 + int retval = reset_control_deassert(hsotg-reset_control);
 +
 + if (retval)
 + return retval;
 + }
 +
   /* Detect config values from hardware */
   retval = dwc2_get_hwparams(hsotg);
 
 @@ -2973,6 +2981,9 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
   dwc2_hcd_release(hsotg);
   usb_put_hcd(hcd);
 
 + if (hsotg-reset_control)
 + reset_control_assert(hsotg-reset_control);
 +
  #ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
   kfree(hsotg-last_frame_num_array);
   kfree(hsotg-frame_num_array);
 diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
 index a10e7a3..6d74583 100644
 --- a/drivers/usb/dwc2/platform.c
 +++ b/drivers/usb/dwc2/platform.c
 @@ -120,6 +120,7 @@ static int dwc2_driver_probe(struct platform_device *dev)
   const struct dwc2_core_params *params;
   struct dwc2_core_params defparams;
   struct dwc2_hsotg *hsotg;
 + struct reset_control *reset_control;
   struct resource *res;
   int retval;
   int irq;
 @@ -171,6 +172,10 @@ static int dwc2_driver_probe(struct platform_device *dev)
   dev_dbg(dev-dev, mapped PA %08lx to VA %p\n,
   (unsigned long)res-start, hsotg-regs);
 
 + reset_control = devm_reset_control_get(dev-dev, NULL);
 + if (!IS_ERR(reset_control))
 + hsotg-reset_control = reset_control;
 +

I guess you also need a patch to the platform code / dt bindings, to
enable this? Or is it already there?

Also, please CC Felipe (ba...@ti.com) on all dwc2 patches, since they
are now going through his tree.

-- 
Paul

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


[PATCH] storage: Fix bus scan and multi-LUN support for SCM eUSCSI devices

2014-10-16 Thread Mark Knibbs
Hi,

This patch does two things for SCM eUSCSI USB-SCSI converters:

1. SCM eUSCSI bridge devices are hard-wired to use SCSI ID 7. On connecting
the converter, access to that ID is attempted during the bus scan. Asking
the converter to issue INQUIRY commands to itself isn't very polite and
wastes time. Set this_id to 7 so __scsi_scan_target() skips it in the scan.
(This replaces my previously-posted patch
  [PATCH v2] storage: Don't scan target 7 for SCM USB-SCSI converters.)


2. Enable multi-LUN support. eUSCSI devices don't support Get Max LUN
requests, returning an error (-32). [Different targets could have different
numbers of LUNs, so it wouldn't make sense to return a particular value in
response to Get Max LUN.]

usb_stor_scan_dwork() does this:
/* For bulk-only devices, determine the max LUN value */
if (us-protocol == USB_PR_BULK  !(us-fflags  US_FL_SINGLE_LUN)) {
mutex_lock(us-dev_mutex);
us-max_lun = usb_stor_Bulk_max_lun(us);
mutex_unlock(us-dev_mutex);

It avoids calling usb_stor_Bulk_max_lun() if US_FL_SINGLE_LUN, but not for
US_FL_SCM_MULT_TARG. Since usb_stor_Bulk_max_lun() returns 0 in the error
case, us-max_lun was always set to 0.

[If the user doesn't want multi-LUN support (perhaps there are SCSI devices
which respond to commands on all LUNs?), the US_FL_SINGLE_LUN quirk can be
specified on the kernel command line.]


Signed-off-by: Mark Knibbs ma...@clara.co.uk

---
diff -up linux-3.17/drivers/usb/storage/usb.c.orig 
linux-3.17/drivers/usb/storage/usb.c
--- linux-3.17/drivers/usb/storage/usb.c.orig   2014-10-05 20:23:04.0 
+0100
+++ linux-3.17/drivers/usb/storage/usb.c2014-10-16 22:11:31.0 
+0100
@@ -877,7 +877,9 @@ static void usb_stor_scan_dwork(struct w
dev_dbg(dev, starting scan\n);
 
/* For bulk-only devices, determine the max LUN value */
-   if (us-protocol == USB_PR_BULK  !(us-fflags  US_FL_SINGLE_LUN)) {
+   if (us-protocol == USB_PR_BULK 
+   !(us-fflags  US_FL_SINGLE_LUN) 
+   !(us-fflags  US_FL_SCM_MULT_TARG)) {
mutex_lock(us-dev_mutex);
us-max_lun = usb_stor_Bulk_max_lun(us);
mutex_unlock(us-dev_mutex);
@@ -976,13 +978,24 @@ int usb_stor_probe2(struct us_data *us)
usb_stor_dbg(us, Transport: %s\n, us-transport_name);
usb_stor_dbg(us, Protocol: %s\n, us-protocol_name);
 
+   if (us-fflags  US_FL_SCM_MULT_TARG) {
+   /*
+* SCM eUSCSI bridge devices can have different numbers
+* of LUNs on different targets; allow all to be probed.
+*/
+   us-max_lun = 7;
+   /* The eUSCSI itself has ID 7, so avoid scanning that */
+   us_to_host(us)-this_id = 7;
+   /* max_id is 8 initially, so no need to set it here */
+   } else {
+   /* In the normal case there is only a single target */
+   us_to_host(us)-max_id = 1;
+   }
+
/* fix for single-lun devices */
if (us-fflags  US_FL_SINGLE_LUN)
us-max_lun = 0;
 
-   if (!(us-fflags  US_FL_SCM_MULT_TARG))
-   us_to_host(us)-max_id = 1;
-
/* Find the endpoints and calculate pipe values */
result = get_pipes(us);
if (result)
--
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


unfixable usb porthole

2014-10-16 Thread Gene Heskett
Is there a move afoot to write a checker utility that determines if the 
usb device its pointed at is vulnerable, and can therefore be reliably 
blacklisted?

From what I've read, the real fix will be a standards rewrite, and once 
fixed units are in the supply chains, replace what we have. The makers 
like Prolific  FDTI are licking their chops at that prospect.  But with 
my weeping willow tree usb setup here, thats not a very appetizing choice 
as I have well north of $2500 dollars in stuff with usb sockets on them.

Thanks for any encouraging news.

Cheers, Gene Heskett
-- 
There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order.
-Ed Howdershelt (Author)
Genes Web page http://geneslinuxbox.net:6309/gene
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
--
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: unfixable usb porthole

2014-10-16 Thread Greg KH
On Thu, Oct 16, 2014 at 06:12:48PM -0400, Gene Heskett wrote:
 Is there a move afoot to write a checker utility that determines if the 
 usb device its pointed at is vulnerable, and can therefore be reliably 
 blacklisted?

What do you mean by a vulnerable USB device?

--
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: unfixable usb porthole

2014-10-16 Thread Gene Heskett
On Thursday 16 October 2014 18:28:16 Greg KH did opine
And Gene did reply:
 On Thu, Oct 16, 2014 at 06:12:48PM -0400, Gene Heskett wrote:
  Is there a move afoot to write a checker utility that determines if
  the usb device its pointed at is vulnerable, and can therefore be
  reliably blacklisted?
 
 What do you mean by a vulnerable USB device?

Thanks for the reply, Greg.

There is an exploitable error in the usb hardware/firmware, one that 
nearly 100% of the devices have.

No one ever gave security a seconds thought when writing the usb std.  As 
described it is both hardware and firmware that will need to be addressed 
for an effective fix.

See:

http://www.wired.com/2014/10/code-published-for-unfixable-usb-attack/

for an explanation much better than I seem to be doing.  It went live 
yesterday.

Cheers, Gene Heskett
-- 
There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order.
-Ed Howdershelt (Author)
Genes Web page http://geneslinuxbox.net:6309/gene
US V Castleman, SCOTUS, Mar 2014 is grounds for Impeaching SCOTUS
--
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: dwc2: gadget: sparse warning of context imbalance

2014-10-16 Thread Sudip Mukherjee
sparse was giving the following warning:
warning: context imbalance in 's3c_hsotg_ep_enable'
- different lock contexts for basic block

we were returning ENOMEM while still holding the spinlock.
The sparse warning was fixed by releasing the spinlock before return.

Signed-off-by: Sudip Mukherjee su...@vectorindia.org
---
 drivers/usb/dwc2/gadget.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7b5856f..7f25527 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2561,8 +2561,10 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
hs_ep-fifo_size = val;
break;
}
-   if (i == 8)
-   return -ENOMEM;
+   if (i == 8) {
+   ret = -ENOMEM;
+   goto error;
+   }
}
 
/* for non control endpoints, set PID to D0 */
@@ -2579,6 +2581,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
/* enable the endpoint interrupt */
s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
 
+error:
spin_unlock_irqrestore(hsotg-lock, flags);
return ret;
 }
-- 
1.8.1.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: dwc2: gadget: modify return statement

2014-10-16 Thread Sudip Mukherjee
modified the function to have a single return statement at the end
instead of multiple return statement in the middle of the function
to improve the readability of the code.

This patch depends on the previous patch of the series.

Signed-off-by: Sudip Mukherjee su...@vectorindia.org
---
 drivers/usb/dwc2/gadget.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 7f25527..e8a8fc7 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2471,7 +2471,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
dir_in = (desc-bEndpointAddress  USB_ENDPOINT_DIR_MASK) ? 1 : 0;
if (dir_in != hs_ep-dir_in) {
dev_err(hsotg-dev, %s: direction mismatch!\n, __func__);
-   return -EINVAL;
+   ret = -EINVAL;
+   goto error1;
}
 
mps = usb_endpoint_maxp(desc);
@@ -2583,6 +2584,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
 
 error:
spin_unlock_irqrestore(hsotg-lock, flags);
+error1:
return ret;
 }
 
-- 
1.8.1.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 net] r8152: use cancel_delayed_work for runtime suspend

2014-10-16 Thread Hayes Wang
It would cause dead lock for runtime suspend, when the workqueue
is running and runtime suspend occurs before the workqueue wakes
up the device. The rtl8152_suspend() waits the workqueue to finish
because of calling cancel_delayed_work_sync(). The workqueue waits
the suspend function to finish for waking up the device because of
calling usb_autopm_get_interface().

Signed-off-by: Hayes Wang hayesw...@realtek.com
---
 drivers/net/usb/r8152.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 864159e..7d4e55a 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -3200,12 +3200,13 @@ static int rtl8152_suspend(struct usb_interface *intf, 
pm_message_t message)
if (netif_running(tp-netdev)) {
clear_bit(WORK_ENABLE, tp-flags);
usb_kill_urb(tp-intr_urb);
-   cancel_delayed_work_sync(tp-schedule);
tasklet_disable(tp-tl);
if (test_bit(SELECTIVE_SUSPEND, tp-flags)) {
+   cancel_delayed_work(tp-schedule);
rtl_stop_rx(tp);
rtl_runtime_suspend_enable(tp, true);
} else {
+   cancel_delayed_work_sync(tp-schedule);
tp-rtl_ops.down(tp);
}
tasklet_enable(tp-tl);
-- 
1.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