aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/kernel-parameters.txt2
-rw-r--r--Documentation/usb/authorization.txt10
-rw-r--r--Documentation/usb/usbmon.txt8
-rw-r--r--Documentation/x86/earlyprintk.txt39
-rw-r--r--MAINTAINERS4
-rw-r--r--arch/x86/kernel/early_printk.c780
-rw-r--r--drivers/net/usb/cdc_eem.c17
-rw-r--r--drivers/usb/Kconfig3
-rw-r--r--drivers/usb/Makefile2
-rw-r--r--drivers/usb/class/cdc-acm.c2
-rw-r--r--drivers/usb/class/cdc-wdm.c30
-rw-r--r--drivers/usb/class/usbtmc.c84
-rw-r--r--drivers/usb/core/config.c2
-rw-r--r--drivers/usb/core/devio.c247
-rw-r--r--drivers/usb/core/driver.c75
-rw-r--r--drivers/usb/core/generic.c4
-rw-r--r--drivers/usb/core/hcd.c111
-rw-r--r--drivers/usb/core/hcd.h5
-rw-r--r--drivers/usb/core/hub.c126
-rw-r--r--drivers/usb/core/message.c32
-rw-r--r--drivers/usb/core/usb.c13
-rw-r--r--drivers/usb/core/usb.h7
-rw-r--r--drivers/usb/early/Makefile5
-rw-r--r--drivers/usb/early/ehci-dbgp.c996
-rw-r--r--drivers/usb/gadget/Kconfig31
-rw-r--r--drivers/usb/gadget/amd5536udc.c56
-rw-r--r--drivers/usb/gadget/at91_udc.c1
-rw-r--r--drivers/usb/gadget/audio.c24
-rw-r--r--drivers/usb/gadget/composite.c2
-rw-r--r--drivers/usb/gadget/dummy_hcd.c5
-rw-r--r--drivers/usb/gadget/ether.c31
-rw-r--r--drivers/usb/gadget/f_audio.c97
-rw-r--r--drivers/usb/gadget/f_eem.c562
-rw-r--r--drivers/usb/gadget/f_rndis.c15
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c4
-rw-r--r--drivers/usb/gadget/gmidi.c8
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c49
-rw-r--r--drivers/usb/gadget/pxa25x_udc.h1
-rw-r--r--drivers/usb/gadget/rndis.c13
-rw-r--r--drivers/usb/gadget/rndis.h3
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c6
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c3
-rw-r--r--drivers/usb/gadget/u_audio.c10
-rw-r--r--drivers/usb/gadget/u_ether.c85
-rw-r--r--drivers/usb/gadget/u_ether.h12
-rw-r--r--drivers/usb/gadget/u_serial.c1
-rw-r--r--drivers/usb/host/Kconfig18
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/ehci-atmel.c230
-rw-r--r--drivers/usb/host/ehci-au1xxx.c29
-rw-r--r--drivers/usb/host/ehci-dbg.c46
-rw-r--r--drivers/usb/host/ehci-hcd.c89
-rw-r--r--drivers/usb/host/ehci-hub.c84
-rw-r--r--drivers/usb/host/ehci-mem.c26
-rw-r--r--drivers/usb/host/ehci-pci.c42
-rw-r--r--drivers/usb/host/ehci-q.c95
-rw-r--r--drivers/usb/host/ehci-sched.c100
-rw-r--r--drivers/usb/host/ehci-w90x900.c181
-rw-r--r--drivers/usb/host/ehci.h14
-rw-r--r--drivers/usb/host/isp1362-hcd.c2909
-rw-r--r--drivers/usb/host/isp1362.h1079
-rw-r--r--drivers/usb/host/isp1760-hcd.c4
-rw-r--r--drivers/usb/host/isp1760-hcd.h2
-rw-r--r--drivers/usb/host/isp1760-if.c21
-rw-r--r--drivers/usb/host/ohci-at91.c2
-rw-r--r--drivers/usb/host/ohci-au1xxx.c27
-rw-r--r--drivers/usb/host/ohci-ep93xx.c1
-rw-r--r--drivers/usb/host/ohci-hcd.c1
-rw-r--r--drivers/usb/host/ohci-pxa27x.c4
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c1
-rw-r--r--drivers/usb/host/pci-quirks.c2
-rw-r--r--drivers/usb/host/sl811-hcd.c8
-rw-r--r--drivers/usb/host/uhci-q.c1
-rw-r--r--drivers/usb/host/whci/asl.c12
-rw-r--r--drivers/usb/host/whci/hcd.c8
-rw-r--r--drivers/usb/host/whci/pzl.c12
-rw-r--r--drivers/usb/host/whci/qset.c4
-rw-r--r--drivers/usb/host/whci/whci-hc.h1
-rw-r--r--drivers/usb/host/xhci-dbg.c5
-rw-r--r--drivers/usb/host/xhci-hcd.c530
-rw-r--r--drivers/usb/host/xhci-mem.c140
-rw-r--r--drivers/usb/host/xhci-pci.c16
-rw-r--r--drivers/usb/host/xhci-ring.c377
-rw-r--r--drivers/usb/host/xhci.h111
-rw-r--r--drivers/usb/image/microtek.c37
-rw-r--r--drivers/usb/misc/idmouse.c21
-rw-r--r--drivers/usb/misc/ldusb.c6
-rw-r--r--drivers/usb/misc/legousbtower.c6
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c53
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.h2
-rw-r--r--drivers/usb/misc/usbsevseg.c69
-rw-r--r--drivers/usb/mon/Kconfig4
-rw-r--r--drivers/usb/mon/Makefile2
-rw-r--r--drivers/usb/mon/mon_bin.c12
-rw-r--r--drivers/usb/mon/mon_dma.c95
-rw-r--r--drivers/usb/mon/mon_main.c1
-rw-r--r--drivers/usb/mon/mon_text.c14
-rw-r--r--drivers/usb/mon/usb_mon.h14
-rw-r--r--drivers/usb/musb/musb_core.c8
-rw-r--r--drivers/usb/otg/isp1301_omap.c23
-rw-r--r--drivers/usb/serial/ark3116.c24
-rw-r--r--drivers/usb/serial/ch341.c52
-rw-r--r--drivers/usb/serial/ftdi_sio.c7
-rw-r--r--drivers/usb/serial/ftdi_sio.h10
-rw-r--r--drivers/usb/serial/generic.c206
-rw-r--r--drivers/usb/serial/iuu_phoenix.c115
-rw-r--r--drivers/usb/serial/moto_modem.c2
-rw-r--r--drivers/usb/serial/option.c138
-rw-r--r--drivers/usb/serial/pl2303.c71
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/sierra.c157
-rw-r--r--drivers/usb/serial/usb-serial.c23
-rw-r--r--drivers/usb/storage/datafab.c4
-rw-r--r--drivers/usb/storage/initializers.c2
-rw-r--r--drivers/usb/storage/jumpshot.c2
-rw-r--r--drivers/usb/storage/onetouch.c2
-rw-r--r--drivers/usb/storage/unusual_devs.h22
-rw-r--r--drivers/usb/usb-skeleton.c252
-rw-r--r--include/linux/usb.h25
-rw-r--r--include/linux/usb/audio.h287
-rw-r--r--include/linux/usb/ch9.h8
-rw-r--r--include/linux/usb/ehci_def.h35
-rw-r--r--include/linux/usb/isp1362.h46
-rw-r--r--include/linux/usb/isp1760.h18
-rw-r--r--include/linux/usb/serial.h2
-rw-r--r--include/linux/usbdevice_fs.h3
126 files changed, 9603 insertions, 2137 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c363840cdcea..6fa7292947e5 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -671,7 +671,7 @@ and is between 256 and 4096 characters. It is defined in the file
671 earlyprintk= [X86,SH,BLACKFIN] 671 earlyprintk= [X86,SH,BLACKFIN]
672 earlyprintk=vga 672 earlyprintk=vga
673 earlyprintk=serial[,ttySn[,baudrate]] 673 earlyprintk=serial[,ttySn[,baudrate]]
674 earlyprintk=dbgp 674 earlyprintk=dbgp[debugController#]
675 675
676 Append ",keep" to not disable it when the real console 676 Append ",keep" to not disable it when the real console
677 takes over. 677 takes over.
diff --git a/Documentation/usb/authorization.txt b/Documentation/usb/authorization.txt
index 381b22ee7834..c069b6884c77 100644
--- a/Documentation/usb/authorization.txt
+++ b/Documentation/usb/authorization.txt
@@ -16,20 +16,20 @@ Usage:
16 16
17Authorize a device to connect: 17Authorize a device to connect:
18 18
19$ echo 1 > /sys/usb/devices/DEVICE/authorized 19$ echo 1 > /sys/bus/usb/devices/DEVICE/authorized
20 20
21Deauthorize a device: 21Deauthorize a device:
22 22
23$ echo 0 > /sys/usb/devices/DEVICE/authorized 23$ echo 0 > /sys/bus/usb/devices/DEVICE/authorized
24 24
25Set new devices connected to hostX to be deauthorized by default (ie: 25Set new devices connected to hostX to be deauthorized by default (ie:
26lock down): 26lock down):
27 27
28$ echo 0 > /sys/bus/devices/usbX/authorized_default 28$ echo 0 > /sys/bus/usb/devices/usbX/authorized_default
29 29
30Remove the lock down: 30Remove the lock down:
31 31
32$ echo 1 > /sys/bus/devices/usbX/authorized_default 32$ echo 1 > /sys/bus/usb/devices/usbX/authorized_default
33 33
34By default, Wired USB devices are authorized by default to 34By default, Wired USB devices are authorized by default to
35connect. Wireless USB hosts deauthorize by default all new connected 35connect. Wireless USB hosts deauthorize by default all new connected
@@ -47,7 +47,7 @@ USB port):
47boot up 47boot up
48rc.local -> 48rc.local ->
49 49
50 for host in /sys/bus/devices/usb* 50 for host in /sys/bus/usb/devices/usb*
51 do 51 do
52 echo 0 > $host/authorized_default 52 echo 0 > $host/authorized_default
53 done 53 done
diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt
index 6c3c625b7f30..66f92d1194c1 100644
--- a/Documentation/usb/usbmon.txt
+++ b/Documentation/usb/usbmon.txt
@@ -33,7 +33,7 @@ if usbmon is built into the kernel.
33 33
34Verify that bus sockets are present. 34Verify that bus sockets are present.
35 35
36# ls /sys/kernel/debug/usbmon 36# ls /sys/kernel/debug/usb/usbmon
370s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u 370s 0u 1s 1t 1u 2s 2t 2u 3s 3t 3u 4s 4t 4u
38# 38#
39 39
@@ -58,11 +58,11 @@ Bus=03 means it's bus 3.
58 58
593. Start 'cat' 593. Start 'cat'
60 60
61# cat /sys/kernel/debug/usbmon/3u > /tmp/1.mon.out 61# cat /sys/kernel/debug/usb/usbmon/3u > /tmp/1.mon.out
62 62
63to listen on a single bus, otherwise, to listen on all buses, type: 63to listen on a single bus, otherwise, to listen on all buses, type:
64 64
65# cat /sys/kernel/debug/usbmon/0u > /tmp/1.mon.out 65# cat /sys/kernel/debug/usb/usbmon/0u > /tmp/1.mon.out
66 66
67This process will be reading until killed. Naturally, the output can be 67This process will be reading until killed. Naturally, the output can be
68redirected to a desirable location. This is preferred, because it is going 68redirected to a desirable location. This is preferred, because it is going
@@ -305,7 +305,7 @@ Before the call, hdr, data, and alloc should be filled. Upon return, the area
305pointed by hdr contains the next event structure, and the data buffer contains 305pointed by hdr contains the next event structure, and the data buffer contains
306the data, if any. The event is removed from the kernel buffer. 306the data, if any. The event is removed from the kernel buffer.
307 307
308The MON_IOCX_GET copies 48 bytes, MON_IOCX_GETX copies 64 bytes. 308The MON_IOCX_GET copies 48 bytes to hdr area, MON_IOCX_GETX copies 64 bytes.
309 309
310 MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg) 310 MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg)
311 311
diff --git a/Documentation/x86/earlyprintk.txt b/Documentation/x86/earlyprintk.txt
index 607b1a016064..f19802c0f485 100644
--- a/Documentation/x86/earlyprintk.txt
+++ b/Documentation/x86/earlyprintk.txt
@@ -7,7 +7,7 @@ and two USB cables, connected like this:
7 7
8 [host/target] <-------> [USB debug key] <-------> [client/console] 8 [host/target] <-------> [USB debug key] <-------> [client/console]
9 9
101. There are three specific hardware requirements: 101. There are a number of specific hardware requirements:
11 11
12 a.) Host/target system needs to have USB debug port capability. 12 a.) Host/target system needs to have USB debug port capability.
13 13
@@ -42,7 +42,35 @@ and two USB cables, connected like this:
42 This is a small blue plastic connector with two USB connections, 42 This is a small blue plastic connector with two USB connections,
43 it draws power from its USB connections. 43 it draws power from its USB connections.
44 44
45 c.) Thirdly, you need a second client/console system with a regular USB port. 45 c.) You need a second client/console system with a high speed USB 2.0
46 port.
47
48 d.) The Netchip device must be plugged directly into the physical
49 debug port on the "host/target" system. You cannot use a USB hub in
50 between the physical debug port and the "host/target" system.
51
52 The EHCI debug controller is bound to a specific physical USB
53 port and the Netchip device will only work as an early printk
54 device in this port. The EHCI host controllers are electrically
55 wired such that the EHCI debug controller is hooked up to the
56 first physical and there is no way to change this via software.
57 You can find the physical port through experimentation by trying
58 each physical port on the system and rebooting. Or you can try
59 and use lsusb or look at the kernel info messages emitted by the
60 usb stack when you plug a usb device into various ports on the
61 "host/target" system.
62
63 Some hardware vendors do not expose the usb debug port with a
64 physical connector and if you find such a device send a complaint
65 to the hardware vendor, because there is no reason not to wire
66 this port into one of the physically accessible ports.
67
68 e.) It is also important to note, that many versions of the Netchip
69 device require the "client/console" system to be plugged into the
70 right and side of the device (with the product logo facing up and
71 readable left to right). The reason being is that the 5 volt
72 power supply is taken from only one side of the device and it
73 must be the side that does not get rebooted.
46 74
472. Software requirements: 752. Software requirements:
48 76
@@ -56,6 +84,13 @@ and two USB cables, connected like this:
56 (If you are using Grub, append it to the 'kernel' line in 84 (If you are using Grub, append it to the 'kernel' line in
57 /etc/grub.conf) 85 /etc/grub.conf)
58 86
87 On systems with more than one EHCI debug controller you must
88 specify the correct EHCI debug controller number. The ordering
89 comes from the PCI bus enumeration of the EHCI controllers. The
90 default with no number argument is "0" the first EHCI debug
91 controller. To use the second EHCI debug controller, you would
92 use the command line: "earlyprintk=dbgp1"
93
59 NOTE: normally earlyprintk console gets turned off once the 94 NOTE: normally earlyprintk console gets turned off once the
60 regular console is alive - use "earlyprintk=dbgp,keep" to keep 95 regular console is alive - use "earlyprintk=dbgp,keep" to keep
61 this channel open beyond early bootup. This can be useful for 96 this channel open beyond early bootup. This can be useful for
diff --git a/MAINTAINERS b/MAINTAINERS
index ed6cd99a57ba..e1fc32e394aa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2107,12 +2107,12 @@ S: Supported
2107F: arch/powerpc/sysdev/qe_lib/ 2107F: arch/powerpc/sysdev/qe_lib/
2108F: arch/powerpc/include/asm/*qe.h 2108F: arch/powerpc/include/asm/*qe.h
2109 2109
2110FREESCALE HIGHSPEED USB DEVICE DRIVER 2110FREESCALE USB PERIPHERIAL DRIVERS
2111M: Li Yang <leoli@freescale.com> 2111M: Li Yang <leoli@freescale.com>
2112L: linux-usb@vger.kernel.org 2112L: linux-usb@vger.kernel.org
2113L: linuxppc-dev@ozlabs.org 2113L: linuxppc-dev@ozlabs.org
2114S: Maintained 2114S: Maintained
2115F: drivers/usb/gadget/fsl_usb2_udc.c 2115F: drivers/usb/gadget/fsl*
2116 2116
2117FREESCALE QUICC ENGINE UCC ETHERNET DRIVER 2117FREESCALE QUICC ENGINE UCC ETHERNET DRIVER
2118M: Li Yang <leoli@freescale.com> 2118M: Li Yang <leoli@freescale.com>
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index b11cab3c323a..2acfd3fdc0cc 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -160,721 +160,6 @@ static struct console early_serial_console = {
160 .index = -1, 160 .index = -1,
161}; 161};
162 162
163#ifdef CONFIG_EARLY_PRINTK_DBGP
164
165static struct ehci_caps __iomem *ehci_caps;
166static struct ehci_regs __iomem *ehci_regs;
167static struct ehci_dbg_port __iomem *ehci_debug;
168static unsigned int dbgp_endpoint_out;
169
170struct ehci_dev {
171 u32 bus;
172 u32 slot;
173 u32 func;
174};
175
176static struct ehci_dev ehci_dev;
177
178#define USB_DEBUG_DEVNUM 127
179
180#define DBGP_DATA_TOGGLE 0x8800
181
182static inline u32 dbgp_pid_update(u32 x, u32 tok)
183{
184 return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff);
185}
186
187static inline u32 dbgp_len_update(u32 x, u32 len)
188{
189 return (x & ~0x0f) | (len & 0x0f);
190}
191
192/*
193 * USB Packet IDs (PIDs)
194 */
195
196/* token */
197#define USB_PID_OUT 0xe1
198#define USB_PID_IN 0x69
199#define USB_PID_SOF 0xa5
200#define USB_PID_SETUP 0x2d
201/* handshake */
202#define USB_PID_ACK 0xd2
203#define USB_PID_NAK 0x5a
204#define USB_PID_STALL 0x1e
205#define USB_PID_NYET 0x96
206/* data */
207#define USB_PID_DATA0 0xc3
208#define USB_PID_DATA1 0x4b
209#define USB_PID_DATA2 0x87
210#define USB_PID_MDATA 0x0f
211/* Special */
212#define USB_PID_PREAMBLE 0x3c
213#define USB_PID_ERR 0x3c
214#define USB_PID_SPLIT 0x78
215#define USB_PID_PING 0xb4
216#define USB_PID_UNDEF_0 0xf0
217
218#define USB_PID_DATA_TOGGLE 0x88
219#define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE)
220
221#define PCI_CAP_ID_EHCI_DEBUG 0xa
222
223#define HUB_ROOT_RESET_TIME 50 /* times are in msec */
224#define HUB_SHORT_RESET_TIME 10
225#define HUB_LONG_RESET_TIME 200
226#define HUB_RESET_TIMEOUT 500
227
228#define DBGP_MAX_PACKET 8
229
230static int dbgp_wait_until_complete(void)
231{
232 u32 ctrl;
233 int loop = 0x100000;
234
235 do {
236 ctrl = readl(&ehci_debug->control);
237 /* Stop when the transaction is finished */
238 if (ctrl & DBGP_DONE)
239 break;
240 } while (--loop > 0);
241
242 if (!loop)
243 return -1;
244
245 /*
246 * Now that we have observed the completed transaction,
247 * clear the done bit.
248 */
249 writel(ctrl | DBGP_DONE, &ehci_debug->control);
250 return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl);
251}
252
253static void __init dbgp_mdelay(int ms)
254{
255 int i;
256
257 while (ms--) {
258 for (i = 0; i < 1000; i++)
259 outb(0x1, 0x80);
260 }
261}
262
263static void dbgp_breath(void)
264{
265 /* Sleep to give the debug port a chance to breathe */
266}
267
268static int dbgp_wait_until_done(unsigned ctrl)
269{
270 u32 pids, lpid;
271 int ret;
272 int loop = 3;
273
274retry:
275 writel(ctrl | DBGP_GO, &ehci_debug->control);
276 ret = dbgp_wait_until_complete();
277 pids = readl(&ehci_debug->pids);
278 lpid = DBGP_PID_GET(pids);
279
280 if (ret < 0)
281 return ret;
282
283 /*
284 * If the port is getting full or it has dropped data
285 * start pacing ourselves, not necessary but it's friendly.
286 */
287 if ((lpid == USB_PID_NAK) || (lpid == USB_PID_NYET))
288 dbgp_breath();
289
290 /* If I get a NACK reissue the transmission */
291 if (lpid == USB_PID_NAK) {
292 if (--loop > 0)
293 goto retry;
294 }
295
296 return ret;
297}
298
299static void dbgp_set_data(const void *buf, int size)
300{
301 const unsigned char *bytes = buf;
302 u32 lo, hi;
303 int i;
304
305 lo = hi = 0;
306 for (i = 0; i < 4 && i < size; i++)
307 lo |= bytes[i] << (8*i);
308 for (; i < 8 && i < size; i++)
309 hi |= bytes[i] << (8*(i - 4));
310 writel(lo, &ehci_debug->data03);
311 writel(hi, &ehci_debug->data47);
312}
313
314static void __init dbgp_get_data(void *buf, int size)
315{
316 unsigned char *bytes = buf;
317 u32 lo, hi;
318 int i;
319
320 lo = readl(&ehci_debug->data03);
321 hi = readl(&ehci_debug->data47);
322 for (i = 0; i < 4 && i < size; i++)
323 bytes[i] = (lo >> (8*i)) & 0xff;
324 for (; i < 8 && i < size; i++)
325 bytes[i] = (hi >> (8*(i - 4))) & 0xff;
326}
327
328static int dbgp_bulk_write(unsigned devnum, unsigned endpoint,
329 const char *bytes, int size)
330{
331 u32 pids, addr, ctrl;
332 int ret;
333
334 if (size > DBGP_MAX_PACKET)
335 return -1;
336
337 addr = DBGP_EPADDR(devnum, endpoint);
338
339 pids = readl(&ehci_debug->pids);
340 pids = dbgp_pid_update(pids, USB_PID_OUT);
341
342 ctrl = readl(&ehci_debug->control);
343 ctrl = dbgp_len_update(ctrl, size);
344 ctrl |= DBGP_OUT;
345 ctrl |= DBGP_GO;
346
347 dbgp_set_data(bytes, size);
348 writel(addr, &ehci_debug->address);
349 writel(pids, &ehci_debug->pids);
350
351 ret = dbgp_wait_until_done(ctrl);
352 if (ret < 0)
353 return ret;
354
355 return ret;
356}
357
358static int __init dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data,
359 int size)
360{
361 u32 pids, addr, ctrl;
362 int ret;
363
364 if (size > DBGP_MAX_PACKET)
365 return -1;
366
367 addr = DBGP_EPADDR(devnum, endpoint);
368
369 pids = readl(&ehci_debug->pids);
370 pids = dbgp_pid_update(pids, USB_PID_IN);
371
372 ctrl = readl(&ehci_debug->control);
373 ctrl = dbgp_len_update(ctrl, size);
374 ctrl &= ~DBGP_OUT;
375 ctrl |= DBGP_GO;
376
377 writel(addr, &ehci_debug->address);
378 writel(pids, &ehci_debug->pids);
379 ret = dbgp_wait_until_done(ctrl);
380 if (ret < 0)
381 return ret;
382
383 if (size > ret)
384 size = ret;
385 dbgp_get_data(data, size);
386 return ret;
387}
388
389static int __init dbgp_control_msg(unsigned devnum, int requesttype,
390 int request, int value, int index, void *data, int size)
391{
392 u32 pids, addr, ctrl;
393 struct usb_ctrlrequest req;
394 int read;
395 int ret;
396
397 read = (requesttype & USB_DIR_IN) != 0;
398 if (size > (read ? DBGP_MAX_PACKET:0))
399 return -1;
400
401 /* Compute the control message */
402 req.bRequestType = requesttype;
403 req.bRequest = request;
404 req.wValue = cpu_to_le16(value);
405 req.wIndex = cpu_to_le16(index);
406 req.wLength = cpu_to_le16(size);
407
408 pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP);
409 addr = DBGP_EPADDR(devnum, 0);
410
411 ctrl = readl(&ehci_debug->control);
412 ctrl = dbgp_len_update(ctrl, sizeof(req));
413 ctrl |= DBGP_OUT;
414 ctrl |= DBGP_GO;
415
416 /* Send the setup message */
417 dbgp_set_data(&req, sizeof(req));
418 writel(addr, &ehci_debug->address);
419 writel(pids, &ehci_debug->pids);
420 ret = dbgp_wait_until_done(ctrl);
421 if (ret < 0)
422 return ret;
423
424 /* Read the result */
425 return dbgp_bulk_read(devnum, 0, data, size);
426}
427
428
429/* Find a PCI capability */
430static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap)
431{
432 u8 pos;
433 int bytes;
434
435 if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
436 PCI_STATUS_CAP_LIST))
437 return 0;
438
439 pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST);
440 for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
441 u8 id;
442
443 pos &= ~3;
444 id = read_pci_config_byte(num, slot, func, pos+PCI_CAP_LIST_ID);
445 if (id == 0xff)
446 break;
447 if (id == cap)
448 return pos;
449
450 pos = read_pci_config_byte(num, slot, func,
451 pos+PCI_CAP_LIST_NEXT);
452 }
453 return 0;
454}
455
456static u32 __init __find_dbgp(u32 bus, u32 slot, u32 func)
457{
458 u32 class;
459
460 class = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
461 if ((class >> 8) != PCI_CLASS_SERIAL_USB_EHCI)
462 return 0;
463
464 return find_cap(bus, slot, func, PCI_CAP_ID_EHCI_DEBUG);
465}
466
467static u32 __init find_dbgp(int ehci_num, u32 *rbus, u32 *rslot, u32 *rfunc)
468{
469 u32 bus, slot, func;
470
471 for (bus = 0; bus < 256; bus++) {
472 for (slot = 0; slot < 32; slot++) {
473 for (func = 0; func < 8; func++) {
474 unsigned cap;
475
476 cap = __find_dbgp(bus, slot, func);
477
478 if (!cap)
479 continue;
480 if (ehci_num-- != 0)
481 continue;
482 *rbus = bus;
483 *rslot = slot;
484 *rfunc = func;
485 return cap;
486 }
487 }
488 }
489 return 0;
490}
491
492static int __init ehci_reset_port(int port)
493{
494 u32 portsc;
495 u32 delay_time, delay;
496 int loop;
497
498 /* Reset the usb debug port */
499 portsc = readl(&ehci_regs->port_status[port - 1]);
500 portsc &= ~PORT_PE;
501 portsc |= PORT_RESET;
502 writel(portsc, &ehci_regs->port_status[port - 1]);
503
504 delay = HUB_ROOT_RESET_TIME;
505 for (delay_time = 0; delay_time < HUB_RESET_TIMEOUT;
506 delay_time += delay) {
507 dbgp_mdelay(delay);
508
509 portsc = readl(&ehci_regs->port_status[port - 1]);
510 if (portsc & PORT_RESET) {
511 /* force reset to complete */
512 loop = 2;
513 writel(portsc & ~(PORT_RWC_BITS | PORT_RESET),
514 &ehci_regs->port_status[port - 1]);
515 do {
516 portsc = readl(&ehci_regs->port_status[port-1]);
517 } while ((portsc & PORT_RESET) && (--loop > 0));
518 }
519
520 /* Device went away? */
521 if (!(portsc & PORT_CONNECT))
522 return -ENOTCONN;
523
524 /* bomb out completely if something weird happend */
525 if ((portsc & PORT_CSC))
526 return -EINVAL;
527
528 /* If we've finished resetting, then break out of the loop */
529 if (!(portsc & PORT_RESET) && (portsc & PORT_PE))
530 return 0;
531 }
532 return -EBUSY;
533}
534
535static int __init ehci_wait_for_port(int port)
536{
537 u32 status;
538 int ret, reps;
539
540 for (reps = 0; reps < 3; reps++) {
541 dbgp_mdelay(100);
542 status = readl(&ehci_regs->status);
543 if (status & STS_PCD) {
544 ret = ehci_reset_port(port);
545 if (ret == 0)
546 return 0;
547 }
548 }
549 return -ENOTCONN;
550}
551
552#ifdef DBGP_DEBUG
553# define dbgp_printk early_printk
554#else
555static inline void dbgp_printk(const char *fmt, ...) { }
556#endif
557
558typedef void (*set_debug_port_t)(int port);
559
560static void __init default_set_debug_port(int port)
561{
562}
563
564static set_debug_port_t __initdata set_debug_port = default_set_debug_port;
565
566static void __init nvidia_set_debug_port(int port)
567{
568 u32 dword;
569 dword = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func,
570 0x74);
571 dword &= ~(0x0f<<12);
572 dword |= ((port & 0x0f)<<12);
573 write_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 0x74,
574 dword);
575 dbgp_printk("set debug port to %d\n", port);
576}
577
578static void __init detect_set_debug_port(void)
579{
580 u32 vendorid;
581
582 vendorid = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func,
583 0x00);
584
585 if ((vendorid & 0xffff) == 0x10de) {
586 dbgp_printk("using nvidia set_debug_port\n");
587 set_debug_port = nvidia_set_debug_port;
588 }
589}
590
591static int __init ehci_setup(void)
592{
593 struct usb_debug_descriptor dbgp_desc;
594 u32 cmd, ctrl, status, portsc, hcs_params;
595 u32 debug_port, new_debug_port = 0, n_ports;
596 u32 devnum;
597 int ret, i;
598 int loop;
599 int port_map_tried;
600 int playtimes = 3;
601
602try_next_time:
603 port_map_tried = 0;
604
605try_next_port:
606
607 hcs_params = readl(&ehci_caps->hcs_params);
608 debug_port = HCS_DEBUG_PORT(hcs_params);
609 n_ports = HCS_N_PORTS(hcs_params);
610
611 dbgp_printk("debug_port: %d\n", debug_port);
612 dbgp_printk("n_ports: %d\n", n_ports);
613
614 for (i = 1; i <= n_ports; i++) {
615 portsc = readl(&ehci_regs->port_status[i-1]);
616 dbgp_printk("portstatus%d: %08x\n", i, portsc);
617 }
618
619 if (port_map_tried && (new_debug_port != debug_port)) {
620 if (--playtimes) {
621 set_debug_port(new_debug_port);
622 goto try_next_time;
623 }
624 return -1;
625 }
626
627 loop = 100000;
628 /* Reset the EHCI controller */
629 cmd = readl(&ehci_regs->command);
630 cmd |= CMD_RESET;
631 writel(cmd, &ehci_regs->command);
632 do {
633 cmd = readl(&ehci_regs->command);
634 } while ((cmd & CMD_RESET) && (--loop > 0));
635
636 if (!loop) {
637 dbgp_printk("can not reset ehci\n");
638 return -1;
639 }
640 dbgp_printk("ehci reset done\n");
641
642 /* Claim ownership, but do not enable yet */
643 ctrl = readl(&ehci_debug->control);
644 ctrl |= DBGP_OWNER;
645 ctrl &= ~(DBGP_ENABLED | DBGP_INUSE);
646 writel(ctrl, &ehci_debug->control);
647
648 /* Start the ehci running */
649 cmd = readl(&ehci_regs->command);
650 cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET);
651 cmd |= CMD_RUN;
652 writel(cmd, &ehci_regs->command);
653
654 /* Ensure everything is routed to the EHCI */
655 writel(FLAG_CF, &ehci_regs->configured_flag);
656
657 /* Wait until the controller is no longer halted */
658 loop = 10;
659 do {
660 status = readl(&ehci_regs->status);
661 } while ((status & STS_HALT) && (--loop > 0));
662
663 if (!loop) {
664 dbgp_printk("ehci can be started\n");
665 return -1;
666 }
667 dbgp_printk("ehci started\n");
668
669 /* Wait for a device to show up in the debug port */
670 ret = ehci_wait_for_port(debug_port);
671 if (ret < 0) {
672 dbgp_printk("No device found in debug port\n");
673 goto next_debug_port;
674 }
675 dbgp_printk("ehci wait for port done\n");
676
677 /* Enable the debug port */
678 ctrl = readl(&ehci_debug->control);
679 ctrl |= DBGP_CLAIM;
680 writel(ctrl, &ehci_debug->control);
681 ctrl = readl(&ehci_debug->control);
682 if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) {
683 dbgp_printk("No device in debug port\n");
684 writel(ctrl & ~DBGP_CLAIM, &ehci_debug->control);
685 goto err;
686 }
687 dbgp_printk("debug ported enabled\n");
688
689 /* Completely transfer the debug device to the debug controller */
690 portsc = readl(&ehci_regs->port_status[debug_port - 1]);
691 portsc &= ~PORT_PE;
692 writel(portsc, &ehci_regs->port_status[debug_port - 1]);
693
694 dbgp_mdelay(100);
695
696 /* Find the debug device and make it device number 127 */
697 for (devnum = 0; devnum <= 127; devnum++) {
698 ret = dbgp_control_msg(devnum,
699 USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
700 USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0,
701 &dbgp_desc, sizeof(dbgp_desc));
702 if (ret > 0)
703 break;
704 }
705 if (devnum > 127) {
706 dbgp_printk("Could not find attached debug device\n");
707 goto err;
708 }
709 if (ret < 0) {
710 dbgp_printk("Attached device is not a debug device\n");
711 goto err;
712 }
713 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint;
714
715 /* Move the device to 127 if it isn't already there */
716 if (devnum != USB_DEBUG_DEVNUM) {
717 ret = dbgp_control_msg(devnum,
718 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
719 USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0);
720 if (ret < 0) {
721 dbgp_printk("Could not move attached device to %d\n",
722 USB_DEBUG_DEVNUM);
723 goto err;
724 }
725 devnum = USB_DEBUG_DEVNUM;
726 dbgp_printk("debug device renamed to 127\n");
727 }
728
729 /* Enable the debug interface */
730 ret = dbgp_control_msg(USB_DEBUG_DEVNUM,
731 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
732 USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0);
733 if (ret < 0) {
734 dbgp_printk(" Could not enable the debug device\n");
735 goto err;
736 }
737 dbgp_printk("debug interface enabled\n");
738
739 /* Perform a small write to get the even/odd data state in sync
740 */
741 ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, dbgp_endpoint_out, " ", 1);
742 if (ret < 0) {
743 dbgp_printk("dbgp_bulk_write failed: %d\n", ret);
744 goto err;
745 }
746 dbgp_printk("small write doned\n");
747
748 return 0;
749err:
750 /* Things didn't work so remove my claim */
751 ctrl = readl(&ehci_debug->control);
752 ctrl &= ~(DBGP_CLAIM | DBGP_OUT);
753 writel(ctrl, &ehci_debug->control);
754 return -1;
755
756next_debug_port:
757 port_map_tried |= (1<<(debug_port - 1));
758 new_debug_port = ((debug_port-1+1)%n_ports) + 1;
759 if (port_map_tried != ((1<<n_ports) - 1)) {
760 set_debug_port(new_debug_port);
761 goto try_next_port;
762 }
763 if (--playtimes) {
764 set_debug_port(new_debug_port);
765 goto try_next_time;
766 }
767
768 return -1;
769}
770
771static int __init early_dbgp_init(char *s)
772{
773 u32 debug_port, bar, offset;
774 u32 bus, slot, func, cap;
775 void __iomem *ehci_bar;
776 u32 dbgp_num;
777 u32 bar_val;
778 char *e;
779 int ret;
780 u8 byte;
781
782 if (!early_pci_allowed())
783 return -1;
784
785 dbgp_num = 0;
786 if (*s)
787 dbgp_num = simple_strtoul(s, &e, 10);
788 dbgp_printk("dbgp_num: %d\n", dbgp_num);
789
790 cap = find_dbgp(dbgp_num, &bus, &slot, &func);
791 if (!cap)
792 return -1;
793
794 dbgp_printk("Found EHCI debug port on %02x:%02x.%1x\n", bus, slot,
795 func);
796
797 debug_port = read_pci_config(bus, slot, func, cap);
798 bar = (debug_port >> 29) & 0x7;
799 bar = (bar * 4) + 0xc;
800 offset = (debug_port >> 16) & 0xfff;
801 dbgp_printk("bar: %02x offset: %03x\n", bar, offset);
802 if (bar != PCI_BASE_ADDRESS_0) {
803 dbgp_printk("only debug ports on bar 1 handled.\n");
804
805 return -1;
806 }
807
808 bar_val = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0);
809 dbgp_printk("bar_val: %02x offset: %03x\n", bar_val, offset);
810 if (bar_val & ~PCI_BASE_ADDRESS_MEM_MASK) {
811 dbgp_printk("only simple 32bit mmio bars supported\n");
812
813 return -1;
814 }
815
816 /* double check if the mem space is enabled */
817 byte = read_pci_config_byte(bus, slot, func, 0x04);
818 if (!(byte & 0x2)) {
819 byte |= 0x02;
820 write_pci_config_byte(bus, slot, func, 0x04, byte);
821 dbgp_printk("mmio for ehci enabled\n");
822 }
823
824 /*
825 * FIXME I don't have the bar size so just guess PAGE_SIZE is more
826 * than enough. 1K is the biggest I have seen.
827 */
828 set_fixmap_nocache(FIX_DBGP_BASE, bar_val & PAGE_MASK);
829 ehci_bar = (void __iomem *)__fix_to_virt(FIX_DBGP_BASE);
830 ehci_bar += bar_val & ~PAGE_MASK;
831 dbgp_printk("ehci_bar: %p\n", ehci_bar);
832
833 ehci_caps = ehci_bar;
834 ehci_regs = ehci_bar + HC_LENGTH(readl(&ehci_caps->hc_capbase));
835 ehci_debug = ehci_bar + offset;
836 ehci_dev.bus = bus;
837 ehci_dev.slot = slot;
838 ehci_dev.func = func;
839
840 detect_set_debug_port();
841
842 ret = ehci_setup();
843 if (ret < 0) {
844 dbgp_printk("ehci_setup failed\n");
845 ehci_debug = NULL;
846
847 return -1;
848 }
849
850 return 0;
851}
852
853static void early_dbgp_write(struct console *con, const char *str, u32 n)
854{
855 int chunk, ret;
856
857 if (!ehci_debug)
858 return;
859 while (n > 0) {
860 chunk = n;
861 if (chunk > DBGP_MAX_PACKET)
862 chunk = DBGP_MAX_PACKET;
863 ret = dbgp_bulk_write(USB_DEBUG_DEVNUM,
864 dbgp_endpoint_out, str, chunk);
865 str += chunk;
866 n -= chunk;
867 }
868}
869
870static struct console early_dbgp_console = {
871 .name = "earlydbg",
872 .write = early_dbgp_write,
873 .flags = CON_PRINTBUFFER,
874 .index = -1,
875};
876#endif
877
878/* Direct interface for emergencies */ 163/* Direct interface for emergencies */
879static struct console *early_console = &early_vga_console; 164static struct console *early_console = &early_vga_console;
880static int __initdata early_console_initialized; 165static int __initdata early_console_initialized;
@@ -891,10 +176,19 @@ asmlinkage void early_printk(const char *fmt, ...)
891 va_end(ap); 176 va_end(ap);
892} 177}
893 178
179static inline void early_console_register(struct console *con, int keep_early)
180{
181 early_console = con;
182 if (keep_early)
183 early_console->flags &= ~CON_BOOT;
184 else
185 early_console->flags |= CON_BOOT;
186 register_console(early_console);
187}
894 188
895static int __init setup_early_printk(char *buf) 189static int __init setup_early_printk(char *buf)
896{ 190{
897 int keep_early; 191 int keep;
898 192
899 if (!buf) 193 if (!buf)
900 return 0; 194 return 0;
@@ -903,42 +197,34 @@ static int __init setup_early_printk(char *buf)
903 return 0; 197 return 0;
904 early_console_initialized = 1; 198 early_console_initialized = 1;
905 199
906 keep_early = (strstr(buf, "keep") != NULL); 200 keep = (strstr(buf, "keep") != NULL);
907 201
908 if (!strncmp(buf, "serial", 6)) { 202 while (*buf != '\0') {
909 early_serial_init(buf + 6); 203 if (!strncmp(buf, "serial", 6)) {
910 early_console = &early_serial_console; 204 early_serial_init(buf + 6);
911 } else if (!strncmp(buf, "ttyS", 4)) { 205 early_console_register(&early_serial_console, keep);
912 early_serial_init(buf); 206 }
913 early_console = &early_serial_console; 207 if (!strncmp(buf, "ttyS", 4)) {
914 } else if (!strncmp(buf, "vga", 3) 208 early_serial_init(buf + 4);
915 && boot_params.screen_info.orig_video_isVGA == 1) { 209 early_console_register(&early_serial_console, keep);
916 max_xpos = boot_params.screen_info.orig_video_cols; 210 }
917 max_ypos = boot_params.screen_info.orig_video_lines; 211 if (!strncmp(buf, "vga", 3) &&
918 current_ypos = boot_params.screen_info.orig_y; 212 boot_params.screen_info.orig_video_isVGA == 1) {
919 early_console = &early_vga_console; 213 max_xpos = boot_params.screen_info.orig_video_cols;
214 max_ypos = boot_params.screen_info.orig_video_lines;
215 current_ypos = boot_params.screen_info.orig_y;
216 early_console_register(&early_vga_console, keep);
217 }
920#ifdef CONFIG_EARLY_PRINTK_DBGP 218#ifdef CONFIG_EARLY_PRINTK_DBGP
921 } else if (!strncmp(buf, "dbgp", 4)) { 219 if (!strncmp(buf, "dbgp", 4) && !early_dbgp_init(buf + 4))
922 if (early_dbgp_init(buf+4) < 0) 220 early_console_register(&early_dbgp_console, keep);
923 return 0;
924 early_console = &early_dbgp_console;
925 /*
926 * usb subsys will reset ehci controller, so don't keep
927 * that early console
928 */
929 keep_early = 0;
930#endif 221#endif
931#ifdef CONFIG_HVC_XEN 222#ifdef CONFIG_HVC_XEN
932 } else if (!strncmp(buf, "xen", 3)) { 223 if (!strncmp(buf, "xen", 3))
933 early_console = &xenboot_console; 224 early_console_register(&xenboot_console, keep);
934#endif 225#endif
226 buf++;
935 } 227 }
936
937 if (keep_early)
938 early_console->flags &= ~CON_BOOT;
939 else
940 early_console->flags |= CON_BOOT;
941 register_console(early_console);
942 return 0; 228 return 0;
943} 229}
944 230
diff --git a/drivers/net/usb/cdc_eem.c b/drivers/net/usb/cdc_eem.c
index 45cebfb302cf..23300656c266 100644
--- a/drivers/net/usb/cdc_eem.c
+++ b/drivers/net/usb/cdc_eem.c
@@ -300,20 +300,23 @@ static int eem_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
300 return 0; 300 return 0;
301 } 301 }
302 302
303 crc = get_unaligned_le32(skb2->data
304 + len - ETH_FCS_LEN);
305 skb_trim(skb2, len - ETH_FCS_LEN);
306
307 /* 303 /*
308 * The bmCRC helps to denote when the CRC field in 304 * The bmCRC helps to denote when the CRC field in
309 * the Ethernet frame contains a calculated CRC: 305 * the Ethernet frame contains a calculated CRC:
310 * bmCRC = 1 : CRC is calculated 306 * bmCRC = 1 : CRC is calculated
311 * bmCRC = 0 : CRC = 0xDEADBEEF 307 * bmCRC = 0 : CRC = 0xDEADBEEF
312 */ 308 */
313 if (header & BIT(14)) 309 if (header & BIT(14)) {
314 crc2 = ~crc32_le(~0, skb2->data, skb2->len); 310 crc = get_unaligned_le32(skb2->data
315 else 311 + len - ETH_FCS_LEN);
312 crc2 = ~crc32_le(~0, skb2->data, skb2->len
313 - ETH_FCS_LEN);
314 } else {
315 crc = get_unaligned_be32(skb2->data
316 + len - ETH_FCS_LEN);
316 crc2 = 0xdeadbeef; 317 crc2 = 0xdeadbeef;
318 }
319 skb_trim(skb2, len - ETH_FCS_LEN);
317 320
318 if (is_last) 321 if (is_last)
319 return crc == crc2; 322 return crc == crc2;
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index dcd49f1e96d0..ebd7237230e3 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -39,6 +39,7 @@ config USB_ARCH_HAS_OHCI
39 default y if ARCH_AT91 39 default y if ARCH_AT91
40 default y if ARCH_PNX4008 && I2C 40 default y if ARCH_PNX4008 && I2C
41 default y if MFD_TC6393XB 41 default y if MFD_TC6393XB
42 default y if ARCH_W90X900
42 # PPC: 43 # PPC:
43 default y if STB03xxx 44 default y if STB03xxx
44 default y if PPC_MPC52xx 45 default y if PPC_MPC52xx
@@ -58,6 +59,8 @@ config USB_ARCH_HAS_EHCI
58 default y if PPC_83xx 59 default y if PPC_83xx
59 default y if SOC_AU1200 60 default y if SOC_AU1200
60 default y if ARCH_IXP4XX 61 default y if ARCH_IXP4XX
62 default y if ARCH_W90X900
63 default y if ARCH_AT91SAM9G45
61 default PCI 64 default PCI
62 65
63# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. 66# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 19cb7d5480d7..be3c9b80bc9f 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_USB_UHCI_HCD) += host/
16obj-$(CONFIG_USB_FHCI_HCD) += host/ 16obj-$(CONFIG_USB_FHCI_HCD) += host/
17obj-$(CONFIG_USB_XHCI_HCD) += host/ 17obj-$(CONFIG_USB_XHCI_HCD) += host/
18obj-$(CONFIG_USB_SL811_HCD) += host/ 18obj-$(CONFIG_USB_SL811_HCD) += host/
19obj-$(CONFIG_USB_ISP1362_HCD) += host/
19obj-$(CONFIG_USB_U132_HCD) += host/ 20obj-$(CONFIG_USB_U132_HCD) += host/
20obj-$(CONFIG_USB_R8A66597_HCD) += host/ 21obj-$(CONFIG_USB_R8A66597_HCD) += host/
21obj-$(CONFIG_USB_HWA_HCD) += host/ 22obj-$(CONFIG_USB_HWA_HCD) += host/
@@ -39,6 +40,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
39obj-$(CONFIG_USB_SERIAL) += serial/ 40obj-$(CONFIG_USB_SERIAL) += serial/
40 41
41obj-$(CONFIG_USB) += misc/ 42obj-$(CONFIG_USB) += misc/
43obj-y += early/
42 44
43obj-$(CONFIG_USB_ATM) += atm/ 45obj-$(CONFIG_USB_ATM) += atm/
44obj-$(CONFIG_USB_SPEEDTOUCH) += atm/ 46obj-$(CONFIG_USB_SPEEDTOUCH) += atm/
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 85a1a55815cf..e3861b21e776 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -59,6 +59,7 @@
59#include <linux/init.h> 59#include <linux/init.h>
60#include <linux/slab.h> 60#include <linux/slab.h>
61#include <linux/tty.h> 61#include <linux/tty.h>
62#include <linux/serial.h>
62#include <linux/tty_driver.h> 63#include <linux/tty_driver.h>
63#include <linux/tty_flip.h> 64#include <linux/tty_flip.h>
64#include <linux/module.h> 65#include <linux/module.h>
@@ -609,6 +610,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
609 acm->throttle = 0; 610 acm->throttle = 0;
610 611
611 tasklet_schedule(&acm->urb_task); 612 tasklet_schedule(&acm->urb_task);
613 set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
612 rv = tty_port_block_til_ready(&acm->port, tty, filp); 614 rv = tty_port_block_til_ready(&acm->port, tty, filp);
613done: 615done:
614 mutex_unlock(&acm->mutex); 616 mutex_unlock(&acm->mutex);
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 8c64c018b676..3e564bfe17d1 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -313,8 +313,13 @@ static ssize_t wdm_write
313 r = usb_autopm_get_interface(desc->intf); 313 r = usb_autopm_get_interface(desc->intf);
314 if (r < 0) 314 if (r < 0)
315 goto outnp; 315 goto outnp;
316 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, 316
317 &desc->flags)); 317 if (!file->f_flags && O_NONBLOCK)
318 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
319 &desc->flags));
320 else
321 if (test_bit(WDM_IN_USE, &desc->flags))
322 r = -EAGAIN;
318 if (r < 0) 323 if (r < 0)
319 goto out; 324 goto out;
320 325
@@ -377,7 +382,7 @@ outnl:
377static ssize_t wdm_read 382static ssize_t wdm_read
378(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 383(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
379{ 384{
380 int rv, cntr; 385 int rv, cntr = 0;
381 int i = 0; 386 int i = 0;
382 struct wdm_device *desc = file->private_data; 387 struct wdm_device *desc = file->private_data;
383 388
@@ -389,10 +394,23 @@ static ssize_t wdm_read
389 if (desc->length == 0) { 394 if (desc->length == 0) {
390 desc->read = 0; 395 desc->read = 0;
391retry: 396retry:
397 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
398 rv = -ENODEV;
399 goto err;
400 }
392 i++; 401 i++;
393 rv = wait_event_interruptible(desc->wait, 402 if (file->f_flags & O_NONBLOCK) {
394 test_bit(WDM_READ, &desc->flags)); 403 if (!test_bit(WDM_READ, &desc->flags)) {
404 rv = cntr ? cntr : -EAGAIN;
405 goto err;
406 }
407 rv = 0;
408 } else {
409 rv = wait_event_interruptible(desc->wait,
410 test_bit(WDM_READ, &desc->flags));
411 }
395 412
413 /* may have happened while we slept */
396 if (test_bit(WDM_DISCONNECTING, &desc->flags)) { 414 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
397 rv = -ENODEV; 415 rv = -ENODEV;
398 goto err; 416 goto err;
@@ -448,7 +466,7 @@ retry:
448 466
449err: 467err:
450 mutex_unlock(&desc->rlock); 468 mutex_unlock(&desc->rlock);
451 if (rv < 0) 469 if (rv < 0 && rv != -EAGAIN)
452 dev_err(&desc->intf->dev, "wdm_read: exit error\n"); 470 dev_err(&desc->intf->dev, "wdm_read: exit error\n");
453 return rv; 471 return rv;
454} 472}
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index b09a527f7341..333ee02e7b2b 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -57,7 +57,9 @@ MODULE_DEVICE_TABLE(usb, usbtmc_devices);
57 57
58/* 58/*
59 * This structure is the capabilities for the device 59 * This structure is the capabilities for the device
60 * See section 4.2.1.8 of the USBTMC specification for details. 60 * See section 4.2.1.8 of the USBTMC specification,
61 * and section 4.2.2 of the USBTMC usb488 subclass
62 * specification for details.
61 */ 63 */
62struct usbtmc_dev_capabilities { 64struct usbtmc_dev_capabilities {
63 __u8 interface_capabilities; 65 __u8 interface_capabilities;
@@ -86,6 +88,8 @@ struct usbtmc_device_data {
86 bool TermCharEnabled; 88 bool TermCharEnabled;
87 bool auto_abort; 89 bool auto_abort;
88 90
91 bool zombie; /* fd of disconnected device */
92
89 struct usbtmc_dev_capabilities capabilities; 93 struct usbtmc_dev_capabilities capabilities;
90 struct kref kref; 94 struct kref kref;
91 struct mutex io_mutex; /* only one i/o function running at a time */ 95 struct mutex io_mutex; /* only one i/o function running at a time */
@@ -367,13 +371,13 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
367{ 371{
368 struct usbtmc_device_data *data; 372 struct usbtmc_device_data *data;
369 struct device *dev; 373 struct device *dev;
370 unsigned long int n_characters; 374 u32 n_characters;
371 u8 *buffer; 375 u8 *buffer;
372 int actual; 376 int actual;
373 int done; 377 size_t done;
374 int remaining; 378 size_t remaining;
375 int retval; 379 int retval;
376 int this_part; 380 size_t this_part;
377 381
378 /* Get pointer to private data structure */ 382 /* Get pointer to private data structure */
379 data = filp->private_data; 383 data = filp->private_data;
@@ -384,6 +388,10 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
384 return -ENOMEM; 388 return -ENOMEM;
385 389
386 mutex_lock(&data->io_mutex); 390 mutex_lock(&data->io_mutex);
391 if (data->zombie) {
392 retval = -ENODEV;
393 goto exit;
394 }
387 395
388 remaining = count; 396 remaining = count;
389 done = 0; 397 done = 0;
@@ -401,10 +409,10 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
401 buffer[1] = data->bTag; 409 buffer[1] = data->bTag;
402 buffer[2] = ~(data->bTag); 410 buffer[2] = ~(data->bTag);
403 buffer[3] = 0; /* Reserved */ 411 buffer[3] = 0; /* Reserved */
404 buffer[4] = (this_part - 12 - 3) & 255; 412 buffer[4] = (this_part) & 255;
405 buffer[5] = ((this_part - 12 - 3) >> 8) & 255; 413 buffer[5] = ((this_part) >> 8) & 255;
406 buffer[6] = ((this_part - 12 - 3) >> 16) & 255; 414 buffer[6] = ((this_part) >> 16) & 255;
407 buffer[7] = ((this_part - 12 - 3) >> 24) & 255; 415 buffer[7] = ((this_part) >> 24) & 255;
408 buffer[8] = data->TermCharEnabled * 2; 416 buffer[8] = data->TermCharEnabled * 2;
409 /* Use term character? */ 417 /* Use term character? */
410 buffer[9] = data->TermChar; 418 buffer[9] = data->TermChar;
@@ -455,6 +463,22 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
455 (buffer[6] << 16) + 463 (buffer[6] << 16) +
456 (buffer[7] << 24); 464 (buffer[7] << 24);
457 465
466 /* Ensure the instrument doesn't lie about it */
467 if(n_characters > actual - 12) {
468 dev_err(dev, "Device lies about message size: %u > %d\n", n_characters, actual - 12);
469 n_characters = actual - 12;
470 }
471
472 /* Ensure the instrument doesn't send more back than requested */
473 if(n_characters > this_part) {
474 dev_err(dev, "Device returns more than requested: %zu > %zu\n", done + n_characters, done + this_part);
475 n_characters = this_part;
476 }
477
478 /* Bound amount of data received by amount of data requested */
479 if (n_characters > this_part)
480 n_characters = this_part;
481
458 /* Copy buffer to user space */ 482 /* Copy buffer to user space */
459 if (copy_to_user(buf + done, &buffer[12], n_characters)) { 483 if (copy_to_user(buf + done, &buffer[12], n_characters)) {
460 /* There must have been an addressing problem */ 484 /* There must have been an addressing problem */
@@ -463,8 +487,11 @@ static ssize_t usbtmc_read(struct file *filp, char __user *buf,
463 } 487 }
464 488
465 done += n_characters; 489 done += n_characters;
466 if (n_characters < USBTMC_SIZE_IOBUFFER) 490 /* Terminate if end-of-message bit recieved from device */
491 if ((buffer[8] & 0x01) && (actual >= n_characters + 12))
467 remaining = 0; 492 remaining = 0;
493 else
494 remaining -= n_characters;
468 } 495 }
469 496
470 /* Update file position value */ 497 /* Update file position value */
@@ -496,6 +523,10 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
496 return -ENOMEM; 523 return -ENOMEM;
497 524
498 mutex_lock(&data->io_mutex); 525 mutex_lock(&data->io_mutex);
526 if (data->zombie) {
527 retval = -ENODEV;
528 goto exit;
529 }
499 530
500 remaining = count; 531 remaining = count;
501 done = 0; 532 done = 0;
@@ -767,20 +798,21 @@ static int get_capabilities(struct usbtmc_device_data *data)
767 } 798 }
768 799
769 dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); 800 dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]);
770 dev_dbg(dev, "Interface capabilities are %x\n", buffer[4]);
771 dev_dbg(dev, "Device capabilities are %x\n", buffer[5]);
772 dev_dbg(dev, "USB488 interface capabilities are %x\n", buffer[14]);
773 dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]);
774 if (buffer[0] != USBTMC_STATUS_SUCCESS) { 801 if (buffer[0] != USBTMC_STATUS_SUCCESS) {
775 dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); 802 dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]);
776 rv = -EPERM; 803 rv = -EPERM;
777 goto err_out; 804 goto err_out;
778 } 805 }
806 dev_dbg(dev, "Interface capabilities are %x\n", buffer[4]);
807 dev_dbg(dev, "Device capabilities are %x\n", buffer[5]);
808 dev_dbg(dev, "USB488 interface capabilities are %x\n", buffer[14]);
809 dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]);
779 810
780 data->capabilities.interface_capabilities = buffer[4]; 811 data->capabilities.interface_capabilities = buffer[4];
781 data->capabilities.device_capabilities = buffer[5]; 812 data->capabilities.device_capabilities = buffer[5];
782 data->capabilities.usb488_interface_capabilities = buffer[14]; 813 data->capabilities.usb488_interface_capabilities = buffer[14];
783 data->capabilities.usb488_device_capabilities = buffer[15]; 814 data->capabilities.usb488_device_capabilities = buffer[15];
815 rv = 0;
784 816
785err_out: 817err_out:
786 kfree(buffer); 818 kfree(buffer);
@@ -925,6 +957,10 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
925 957
926 data = file->private_data; 958 data = file->private_data;
927 mutex_lock(&data->io_mutex); 959 mutex_lock(&data->io_mutex);
960 if (data->zombie) {
961 retval = -ENODEV;
962 goto skip_io_on_zombie;
963 }
928 964
929 switch (cmd) { 965 switch (cmd) {
930 case USBTMC_IOCTL_CLEAR_OUT_HALT: 966 case USBTMC_IOCTL_CLEAR_OUT_HALT:
@@ -952,6 +988,7 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
952 break; 988 break;
953 } 989 }
954 990
991skip_io_on_zombie:
955 mutex_unlock(&data->io_mutex); 992 mutex_unlock(&data->io_mutex);
956 return retval; 993 return retval;
957} 994}
@@ -995,6 +1032,7 @@ static int usbtmc_probe(struct usb_interface *intf,
995 usb_set_intfdata(intf, data); 1032 usb_set_intfdata(intf, data);
996 kref_init(&data->kref); 1033 kref_init(&data->kref);
997 mutex_init(&data->io_mutex); 1034 mutex_init(&data->io_mutex);
1035 data->zombie = 0;
998 1036
999 /* Initialize USBTMC bTag and other fields */ 1037 /* Initialize USBTMC bTag and other fields */
1000 data->bTag = 1; 1038 data->bTag = 1;
@@ -1065,14 +1103,30 @@ static void usbtmc_disconnect(struct usb_interface *intf)
1065 usb_deregister_dev(intf, &usbtmc_class); 1103 usb_deregister_dev(intf, &usbtmc_class);
1066 sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp); 1104 sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp);
1067 sysfs_remove_group(&intf->dev.kobj, &data_attr_grp); 1105 sysfs_remove_group(&intf->dev.kobj, &data_attr_grp);
1106 mutex_lock(&data->io_mutex);
1107 data->zombie = 1;
1108 mutex_unlock(&data->io_mutex);
1068 kref_put(&data->kref, usbtmc_delete); 1109 kref_put(&data->kref, usbtmc_delete);
1069} 1110}
1070 1111
1112static int usbtmc_suspend (struct usb_interface *intf, pm_message_t message)
1113{
1114 /* this driver does not have pending URBs */
1115 return 0;
1116}
1117
1118static int usbtmc_resume (struct usb_interface *intf)
1119{
1120 return 0;
1121}
1122
1071static struct usb_driver usbtmc_driver = { 1123static struct usb_driver usbtmc_driver = {
1072 .name = "usbtmc", 1124 .name = "usbtmc",
1073 .id_table = usbtmc_devices, 1125 .id_table = usbtmc_devices,
1074 .probe = usbtmc_probe, 1126 .probe = usbtmc_probe,
1075 .disconnect = usbtmc_disconnect 1127 .disconnect = usbtmc_disconnect,
1128 .suspend = usbtmc_suspend,
1129 .resume = usbtmc_resume,
1076}; 1130};
1077 1131
1078static int __init usbtmc_init(void) 1132static int __init usbtmc_init(void)
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index a16c538d0132..0d3af6a6ee49 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -105,7 +105,7 @@ static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
105 ep->ss_ep_comp->extralen = i; 105 ep->ss_ep_comp->extralen = i;
106 buffer += i; 106 buffer += i;
107 size -= i; 107 size -= i;
108 retval = buffer - buffer_start + i; 108 retval = buffer - buffer_start;
109 if (num_skipped > 0) 109 if (num_skipped > 0)
110 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 110 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
111 num_skipped, plural(num_skipped), 111 num_skipped, plural(num_skipped),
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 4247eccf858c..181f78c84105 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -52,6 +52,7 @@
52 52
53#include "hcd.h" /* for usbcore internals */ 53#include "hcd.h" /* for usbcore internals */
54#include "usb.h" 54#include "usb.h"
55#include "hub.h"
55 56
56#define USB_MAXBUS 64 57#define USB_MAXBUS 64
57#define USB_DEVICE_MAX USB_MAXBUS * 128 58#define USB_DEVICE_MAX USB_MAXBUS * 128
@@ -73,6 +74,7 @@ struct dev_state {
73 void __user *disccontext; 74 void __user *disccontext;
74 unsigned long ifclaimed; 75 unsigned long ifclaimed;
75 u32 secid; 76 u32 secid;
77 u32 disabled_bulk_eps;
76}; 78};
77 79
78struct async { 80struct async {
@@ -87,6 +89,8 @@ struct async {
87 struct urb *urb; 89 struct urb *urb;
88 int status; 90 int status;
89 u32 secid; 91 u32 secid;
92 u8 bulk_addr;
93 u8 bulk_status;
90}; 94};
91 95
92static int usbfs_snoop; 96static int usbfs_snoop;
@@ -99,11 +103,15 @@ MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
99 dev_info(dev , format , ## arg); \ 103 dev_info(dev , format , ## arg); \
100 } while (0) 104 } while (0)
101 105
102#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0) 106enum snoop_when {
107 SUBMIT, COMPLETE
108};
103 109
110#define USB_DEVICE_DEV MKDEV(USB_DEVICE_MAJOR, 0)
104 111
105#define MAX_USBFS_BUFFER_SIZE 16384 112#define MAX_USBFS_BUFFER_SIZE 16384
106 113
114
107static int connected(struct dev_state *ps) 115static int connected(struct dev_state *ps)
108{ 116{
109 return (!list_empty(&ps->list) && 117 return (!list_empty(&ps->list) &&
@@ -300,24 +308,79 @@ static struct async *async_getpending(struct dev_state *ps,
300 return NULL; 308 return NULL;
301} 309}
302 310
303static void snoop_urb(struct urb *urb, void __user *userurb) 311static void snoop_urb(struct usb_device *udev,
312 void __user *userurb, int pipe, unsigned length,
313 int timeout_or_status, enum snoop_when when)
304{ 314{
305 unsigned j; 315 static const char *types[] = {"isoc", "int", "ctrl", "bulk"};
306 unsigned char *data = urb->transfer_buffer; 316 static const char *dirs[] = {"out", "in"};
317 int ep;
318 const char *t, *d;
307 319
308 if (!usbfs_snoop) 320 if (!usbfs_snoop)
309 return; 321 return;
310 322
311 dev_info(&urb->dev->dev, "direction=%s\n", 323 ep = usb_pipeendpoint(pipe);
312 usb_urb_dir_in(urb) ? "IN" : "OUT"); 324 t = types[usb_pipetype(pipe)];
313 dev_info(&urb->dev->dev, "userurb=%p\n", userurb); 325 d = dirs[!!usb_pipein(pipe)];
314 dev_info(&urb->dev->dev, "transfer_buffer_length=%u\n", 326
315 urb->transfer_buffer_length); 327 if (userurb) { /* Async */
316 dev_info(&urb->dev->dev, "actual_length=%u\n", urb->actual_length); 328 if (when == SUBMIT)
317 dev_info(&urb->dev->dev, "data: "); 329 dev_info(&udev->dev, "userurb %p, ep%d %s-%s, "
318 for (j = 0; j < urb->transfer_buffer_length; ++j) 330 "length %u\n",
319 printk("%02x ", data[j]); 331 userurb, ep, t, d, length);
320 printk("\n"); 332 else
333 dev_info(&udev->dev, "userurb %p, ep%d %s-%s, "
334 "actual_length %u status %d\n",
335 userurb, ep, t, d, length,
336 timeout_or_status);
337 } else {
338 if (when == SUBMIT)
339 dev_info(&udev->dev, "ep%d %s-%s, length %u, "
340 "timeout %d\n",
341 ep, t, d, length, timeout_or_status);
342 else
343 dev_info(&udev->dev, "ep%d %s-%s, actual_length %u, "
344 "status %d\n",
345 ep, t, d, length, timeout_or_status);
346 }
347}
348
349#define AS_CONTINUATION 1
350#define AS_UNLINK 2
351
352static void cancel_bulk_urbs(struct dev_state *ps, unsigned bulk_addr)
353__releases(ps->lock)
354__acquires(ps->lock)
355{
356 struct async *as;
357
358 /* Mark all the pending URBs that match bulk_addr, up to but not
359 * including the first one without AS_CONTINUATION. If such an
360 * URB is encountered then a new transfer has already started so
361 * the endpoint doesn't need to be disabled; otherwise it does.
362 */
363 list_for_each_entry(as, &ps->async_pending, asynclist) {
364 if (as->bulk_addr == bulk_addr) {
365 if (as->bulk_status != AS_CONTINUATION)
366 goto rescan;
367 as->bulk_status = AS_UNLINK;
368 as->bulk_addr = 0;
369 }
370 }
371 ps->disabled_bulk_eps |= (1 << bulk_addr);
372
373 /* Now carefully unlink all the marked pending URBs */
374 rescan:
375 list_for_each_entry(as, &ps->async_pending, asynclist) {
376 if (as->bulk_status == AS_UNLINK) {
377 as->bulk_status = 0; /* Only once */
378 spin_unlock(&ps->lock); /* Allow completions */
379 usb_unlink_urb(as->urb);
380 spin_lock(&ps->lock);
381 goto rescan;
382 }
383 }
321} 384}
322 385
323static void async_completed(struct urb *urb) 386static void async_completed(struct urb *urb)
@@ -346,7 +409,11 @@ static void async_completed(struct urb *urb)
346 secid = as->secid; 409 secid = as->secid;
347 } 410 }
348 snoop(&urb->dev->dev, "urb complete\n"); 411 snoop(&urb->dev->dev, "urb complete\n");
349 snoop_urb(urb, as->userurb); 412 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
413 as->status, COMPLETE);
414 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET &&
415 as->status != -ENOENT)
416 cancel_bulk_urbs(ps, as->bulk_addr);
350 spin_unlock(&ps->lock); 417 spin_unlock(&ps->lock);
351 418
352 if (signr) 419 if (signr)
@@ -655,6 +722,7 @@ static int usbdev_release(struct inode *inode, struct file *file)
655 struct async *as; 722 struct async *as;
656 723
657 usb_lock_device(dev); 724 usb_lock_device(dev);
725 usb_hub_release_all_ports(dev, ps);
658 726
659 /* Protect against simultaneous open */ 727 /* Protect against simultaneous open */
660 mutex_lock(&usbfs_mutex); 728 mutex_lock(&usbfs_mutex);
@@ -688,7 +756,7 @@ static int proc_control(struct dev_state *ps, void __user *arg)
688 unsigned int tmo; 756 unsigned int tmo;
689 unsigned char *tbuf; 757 unsigned char *tbuf;
690 unsigned wLength; 758 unsigned wLength;
691 int i, j, ret; 759 int i, pipe, ret;
692 760
693 if (copy_from_user(&ctrl, arg, sizeof(ctrl))) 761 if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
694 return -EFAULT; 762 return -EFAULT;
@@ -708,24 +776,17 @@ static int proc_control(struct dev_state *ps, void __user *arg)
708 free_page((unsigned long)tbuf); 776 free_page((unsigned long)tbuf);
709 return -EINVAL; 777 return -EINVAL;
710 } 778 }
711 snoop(&dev->dev, "control read: bRequest=%02x " 779 pipe = usb_rcvctrlpipe(dev, 0);
712 "bRrequestType=%02x wValue=%04x " 780 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT);
713 "wIndex=%04x wLength=%04x\n",
714 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
715 ctrl.wIndex, ctrl.wLength);
716 781
717 usb_unlock_device(dev); 782 usb_unlock_device(dev);
718 i = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), ctrl.bRequest, 783 i = usb_control_msg(dev, pipe, ctrl.bRequest,
719 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 784 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
720 tbuf, ctrl.wLength, tmo); 785 tbuf, ctrl.wLength, tmo);
721 usb_lock_device(dev); 786 usb_lock_device(dev);
787 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE);
788
722 if ((i > 0) && ctrl.wLength) { 789 if ((i > 0) && ctrl.wLength) {
723 if (usbfs_snoop) {
724 dev_info(&dev->dev, "control read: data ");
725 for (j = 0; j < i; ++j)
726 printk("%02x ", (u8)(tbuf)[j]);
727 printk("\n");
728 }
729 if (copy_to_user(ctrl.data, tbuf, i)) { 790 if (copy_to_user(ctrl.data, tbuf, i)) {
730 free_page((unsigned long)tbuf); 791 free_page((unsigned long)tbuf);
731 return -EFAULT; 792 return -EFAULT;
@@ -738,22 +799,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
738 return -EFAULT; 799 return -EFAULT;
739 } 800 }
740 } 801 }
741 snoop(&dev->dev, "control write: bRequest=%02x " 802 pipe = usb_sndctrlpipe(dev, 0);
742 "bRrequestType=%02x wValue=%04x " 803 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT);
743 "wIndex=%04x wLength=%04x\n", 804
744 ctrl.bRequest, ctrl.bRequestType, ctrl.wValue,
745 ctrl.wIndex, ctrl.wLength);
746 if (usbfs_snoop) {
747 dev_info(&dev->dev, "control write: data: ");
748 for (j = 0; j < ctrl.wLength; ++j)
749 printk("%02x ", (unsigned char)(tbuf)[j]);
750 printk("\n");
751 }
752 usb_unlock_device(dev); 805 usb_unlock_device(dev);
753 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, 806 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest,
754 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 807 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
755 tbuf, ctrl.wLength, tmo); 808 tbuf, ctrl.wLength, tmo);
756 usb_lock_device(dev); 809 usb_lock_device(dev);
810 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE);
757 } 811 }
758 free_page((unsigned long)tbuf); 812 free_page((unsigned long)tbuf);
759 if (i < 0 && i != -EPIPE) { 813 if (i < 0 && i != -EPIPE) {
@@ -772,7 +826,7 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
772 unsigned int tmo, len1, pipe; 826 unsigned int tmo, len1, pipe;
773 int len2; 827 int len2;
774 unsigned char *tbuf; 828 unsigned char *tbuf;
775 int i, j, ret; 829 int i, ret;
776 830
777 if (copy_from_user(&bulk, arg, sizeof(bulk))) 831 if (copy_from_user(&bulk, arg, sizeof(bulk)))
778 return -EFAULT; 832 return -EFAULT;
@@ -799,18 +853,14 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
799 kfree(tbuf); 853 kfree(tbuf);
800 return -EINVAL; 854 return -EINVAL;
801 } 855 }
802 snoop(&dev->dev, "bulk read: len=0x%02x timeout=%04d\n", 856 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT);
803 bulk.len, bulk.timeout); 857
804 usb_unlock_device(dev); 858 usb_unlock_device(dev);
805 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 859 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
806 usb_lock_device(dev); 860 usb_lock_device(dev);
861 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE);
862
807 if (!i && len2) { 863 if (!i && len2) {
808 if (usbfs_snoop) {
809 dev_info(&dev->dev, "bulk read: data ");
810 for (j = 0; j < len2; ++j)
811 printk("%02x ", (u8)(tbuf)[j]);
812 printk("\n");
813 }
814 if (copy_to_user(bulk.data, tbuf, len2)) { 864 if (copy_to_user(bulk.data, tbuf, len2)) {
815 kfree(tbuf); 865 kfree(tbuf);
816 return -EFAULT; 866 return -EFAULT;
@@ -823,17 +873,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
823 return -EFAULT; 873 return -EFAULT;
824 } 874 }
825 } 875 }
826 snoop(&dev->dev, "bulk write: len=0x%02x timeout=%04d\n", 876 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT);
827 bulk.len, bulk.timeout); 877
828 if (usbfs_snoop) {
829 dev_info(&dev->dev, "bulk write: data: ");
830 for (j = 0; j < len1; ++j)
831 printk("%02x ", (unsigned char)(tbuf)[j]);
832 printk("\n");
833 }
834 usb_unlock_device(dev); 878 usb_unlock_device(dev);
835 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 879 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
836 usb_lock_device(dev); 880 usb_lock_device(dev);
881 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE);
837 } 882 }
838 kfree(tbuf); 883 kfree(tbuf);
839 if (i < 0) 884 if (i < 0)
@@ -991,6 +1036,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
991 1036
992 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP | 1037 if (uurb->flags & ~(USBDEVFS_URB_ISO_ASAP |
993 USBDEVFS_URB_SHORT_NOT_OK | 1038 USBDEVFS_URB_SHORT_NOT_OK |
1039 USBDEVFS_URB_BULK_CONTINUATION |
994 USBDEVFS_URB_NO_FSBR | 1040 USBDEVFS_URB_NO_FSBR |
995 USBDEVFS_URB_ZERO_PACKET | 1041 USBDEVFS_URB_ZERO_PACKET |
996 USBDEVFS_URB_NO_INTERRUPT)) 1042 USBDEVFS_URB_NO_INTERRUPT))
@@ -1051,13 +1097,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1051 is_in = 0; 1097 is_in = 0;
1052 uurb->endpoint &= ~USB_DIR_IN; 1098 uurb->endpoint &= ~USB_DIR_IN;
1053 } 1099 }
1054 snoop(&ps->dev->dev, "control urb: bRequest=%02x "
1055 "bRrequestType=%02x wValue=%04x "
1056 "wIndex=%04x wLength=%04x\n",
1057 dr->bRequest, dr->bRequestType,
1058 __le16_to_cpup(&dr->wValue),
1059 __le16_to_cpup(&dr->wIndex),
1060 __le16_to_cpup(&dr->wLength));
1061 break; 1100 break;
1062 1101
1063 case USBDEVFS_URB_TYPE_BULK: 1102 case USBDEVFS_URB_TYPE_BULK:
@@ -1070,7 +1109,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1070 uurb->number_of_packets = 0; 1109 uurb->number_of_packets = 0;
1071 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) 1110 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1072 return -EINVAL; 1111 return -EINVAL;
1073 snoop(&ps->dev->dev, "bulk urb\n");
1074 break; 1112 break;
1075 1113
1076 case USBDEVFS_URB_TYPE_ISO: 1114 case USBDEVFS_URB_TYPE_ISO:
@@ -1097,12 +1135,12 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1097 } 1135 }
1098 totlen += isopkt[u].length; 1136 totlen += isopkt[u].length;
1099 } 1137 }
1100 if (totlen > 32768) { 1138 /* 3072 * 64 microframes */
1139 if (totlen > 196608) {
1101 kfree(isopkt); 1140 kfree(isopkt);
1102 return -EINVAL; 1141 return -EINVAL;
1103 } 1142 }
1104 uurb->buffer_length = totlen; 1143 uurb->buffer_length = totlen;
1105 snoop(&ps->dev->dev, "iso urb\n");
1106 break; 1144 break;
1107 1145
1108 case USBDEVFS_URB_TYPE_INTERRUPT: 1146 case USBDEVFS_URB_TYPE_INTERRUPT:
@@ -1111,7 +1149,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1111 return -EINVAL; 1149 return -EINVAL;
1112 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) 1150 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1113 return -EINVAL; 1151 return -EINVAL;
1114 snoop(&ps->dev->dev, "interrupt urb\n");
1115 break; 1152 break;
1116 1153
1117 default: 1154 default:
@@ -1198,11 +1235,46 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1198 return -EFAULT; 1235 return -EFAULT;
1199 } 1236 }
1200 } 1237 }
1201 snoop_urb(as->urb, as->userurb); 1238 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1239 as->urb->transfer_buffer_length, 0, SUBMIT);
1202 async_newpending(as); 1240 async_newpending(as);
1203 if ((ret = usb_submit_urb(as->urb, GFP_KERNEL))) { 1241
1242 if (usb_endpoint_xfer_bulk(&ep->desc)) {
1243 spin_lock_irq(&ps->lock);
1244
1245 /* Not exactly the endpoint address; the direction bit is
1246 * shifted to the 0x10 position so that the value will be
1247 * between 0 and 31.
1248 */
1249 as->bulk_addr = usb_endpoint_num(&ep->desc) |
1250 ((ep->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK)
1251 >> 3);
1252
1253 /* If this bulk URB is the start of a new transfer, re-enable
1254 * the endpoint. Otherwise mark it as a continuation URB.
1255 */
1256 if (uurb->flags & USBDEVFS_URB_BULK_CONTINUATION)
1257 as->bulk_status = AS_CONTINUATION;
1258 else
1259 ps->disabled_bulk_eps &= ~(1 << as->bulk_addr);
1260
1261 /* Don't accept continuation URBs if the endpoint is
1262 * disabled because of an earlier error.
1263 */
1264 if (ps->disabled_bulk_eps & (1 << as->bulk_addr))
1265 ret = -EREMOTEIO;
1266 else
1267 ret = usb_submit_urb(as->urb, GFP_ATOMIC);
1268 spin_unlock_irq(&ps->lock);
1269 } else {
1270 ret = usb_submit_urb(as->urb, GFP_KERNEL);
1271 }
1272
1273 if (ret) {
1204 dev_printk(KERN_DEBUG, &ps->dev->dev, 1274 dev_printk(KERN_DEBUG, &ps->dev->dev,
1205 "usbfs: usb_submit_urb returned %d\n", ret); 1275 "usbfs: usb_submit_urb returned %d\n", ret);
1276 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1277 0, ret, COMPLETE);
1206 async_removepending(as); 1278 async_removepending(as);
1207 free_async(as); 1279 free_async(as);
1208 return ret; 1280 return ret;
@@ -1548,6 +1620,29 @@ static int proc_ioctl_compat(struct dev_state *ps, compat_uptr_t arg)
1548} 1620}
1549#endif 1621#endif
1550 1622
1623static int proc_claim_port(struct dev_state *ps, void __user *arg)
1624{
1625 unsigned portnum;
1626 int rc;
1627
1628 if (get_user(portnum, (unsigned __user *) arg))
1629 return -EFAULT;
1630 rc = usb_hub_claim_port(ps->dev, portnum, ps);
1631 if (rc == 0)
1632 snoop(&ps->dev->dev, "port %d claimed by process %d: %s\n",
1633 portnum, task_pid_nr(current), current->comm);
1634 return rc;
1635}
1636
1637static int proc_release_port(struct dev_state *ps, void __user *arg)
1638{
1639 unsigned portnum;
1640
1641 if (get_user(portnum, (unsigned __user *) arg))
1642 return -EFAULT;
1643 return usb_hub_release_port(ps->dev, portnum, ps);
1644}
1645
1551/* 1646/*
1552 * NOTE: All requests here that have interface numbers as parameters 1647 * NOTE: All requests here that have interface numbers as parameters
1553 * are assuming that somehow the configuration has been prevented from 1648 * are assuming that somehow the configuration has been prevented from
@@ -1645,7 +1740,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1645 break; 1740 break;
1646 1741
1647 case USBDEVFS_REAPURBNDELAY32: 1742 case USBDEVFS_REAPURBNDELAY32:
1648 snoop(&dev->dev, "%s: REAPURBDELAY32\n", __func__); 1743 snoop(&dev->dev, "%s: REAPURBNDELAY32\n", __func__);
1649 ret = proc_reapurbnonblock_compat(ps, p); 1744 ret = proc_reapurbnonblock_compat(ps, p);
1650 break; 1745 break;
1651 1746
@@ -1666,7 +1761,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1666 break; 1761 break;
1667 1762
1668 case USBDEVFS_REAPURBNDELAY: 1763 case USBDEVFS_REAPURBNDELAY:
1669 snoop(&dev->dev, "%s: REAPURBDELAY\n", __func__); 1764 snoop(&dev->dev, "%s: REAPURBNDELAY\n", __func__);
1670 ret = proc_reapurbnonblock(ps, p); 1765 ret = proc_reapurbnonblock(ps, p);
1671 break; 1766 break;
1672 1767
@@ -1689,6 +1784,16 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1689 snoop(&dev->dev, "%s: IOCTL\n", __func__); 1784 snoop(&dev->dev, "%s: IOCTL\n", __func__);
1690 ret = proc_ioctl_default(ps, p); 1785 ret = proc_ioctl_default(ps, p);
1691 break; 1786 break;
1787
1788 case USBDEVFS_CLAIM_PORT:
1789 snoop(&dev->dev, "%s: CLAIM_PORT\n", __func__);
1790 ret = proc_claim_port(ps, p);
1791 break;
1792
1793 case USBDEVFS_RELEASE_PORT:
1794 snoop(&dev->dev, "%s: RELEASE_PORT\n", __func__);
1795 ret = proc_release_port(ps, p);
1796 break;
1692 } 1797 }
1693 usb_unlock_device(dev); 1798 usb_unlock_device(dev);
1694 if (ret >= 0) 1799 if (ret >= 0)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 69e5773abfce..4f864472c5c4 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -207,6 +207,9 @@ static int usb_probe_interface(struct device *dev)
207 207
208 intf->needs_binding = 0; 208 intf->needs_binding = 0;
209 209
210 if (usb_device_is_owned(udev))
211 return -ENODEV;
212
210 if (udev->authorized == 0) { 213 if (udev->authorized == 0) {
211 dev_err(&intf->dev, "Device is not authorized for usage\n"); 214 dev_err(&intf->dev, "Device is not authorized for usage\n");
212 return -ENODEV; 215 return -ENODEV;
@@ -232,28 +235,35 @@ static int usb_probe_interface(struct device *dev)
232 /* The interface should always appear to be in use 235 /* The interface should always appear to be in use
233 * unless the driver suports autosuspend. 236 * unless the driver suports autosuspend.
234 */ 237 */
235 intf->pm_usage_cnt = !(driver->supports_autosuspend); 238 atomic_set(&intf->pm_usage_cnt, !driver->supports_autosuspend);
236 239
237 /* Carry out a deferred switch to altsetting 0 */ 240 /* Carry out a deferred switch to altsetting 0 */
238 if (intf->needs_altsetting0) { 241 if (intf->needs_altsetting0) {
239 usb_set_interface(udev, intf->altsetting[0]. 242 error = usb_set_interface(udev, intf->altsetting[0].
240 desc.bInterfaceNumber, 0); 243 desc.bInterfaceNumber, 0);
244 if (error < 0)
245 goto err;
246
241 intf->needs_altsetting0 = 0; 247 intf->needs_altsetting0 = 0;
242 } 248 }
243 249
244 error = driver->probe(intf, id); 250 error = driver->probe(intf, id);
245 if (error) { 251 if (error)
246 mark_quiesced(intf); 252 goto err;
247 intf->needs_remote_wakeup = 0;
248 intf->condition = USB_INTERFACE_UNBOUND;
249 usb_cancel_queued_reset(intf);
250 } else
251 intf->condition = USB_INTERFACE_BOUND;
252 253
254 intf->condition = USB_INTERFACE_BOUND;
253 usb_autosuspend_device(udev); 255 usb_autosuspend_device(udev);
254 } 256 }
255 257
256 return error; 258 return error;
259
260err:
261 mark_quiesced(intf);
262 intf->needs_remote_wakeup = 0;
263 intf->condition = USB_INTERFACE_UNBOUND;
264 usb_cancel_queued_reset(intf);
265 usb_autosuspend_device(udev);
266 return error;
257} 267}
258 268
259/* called from driver core with dev locked */ 269/* called from driver core with dev locked */
@@ -262,7 +272,7 @@ static int usb_unbind_interface(struct device *dev)
262 struct usb_driver *driver = to_usb_driver(dev->driver); 272 struct usb_driver *driver = to_usb_driver(dev->driver);
263 struct usb_interface *intf = to_usb_interface(dev); 273 struct usb_interface *intf = to_usb_interface(dev);
264 struct usb_device *udev; 274 struct usb_device *udev;
265 int error; 275 int error, r;
266 276
267 intf->condition = USB_INTERFACE_UNBINDING; 277 intf->condition = USB_INTERFACE_UNBINDING;
268 278
@@ -290,11 +300,14 @@ static int usb_unbind_interface(struct device *dev)
290 * Just re-enable it without affecting the endpoint toggles. 300 * Just re-enable it without affecting the endpoint toggles.
291 */ 301 */
292 usb_enable_interface(udev, intf, false); 302 usb_enable_interface(udev, intf, false);
293 } else if (!error && intf->dev.power.status == DPM_ON) 303 } else if (!error && intf->dev.power.status == DPM_ON) {
294 usb_set_interface(udev, intf->altsetting[0]. 304 r = usb_set_interface(udev, intf->altsetting[0].
295 desc.bInterfaceNumber, 0); 305 desc.bInterfaceNumber, 0);
296 else 306 if (r < 0)
307 intf->needs_altsetting0 = 1;
308 } else {
297 intf->needs_altsetting0 = 1; 309 intf->needs_altsetting0 = 1;
310 }
298 usb_set_intfdata(intf, NULL); 311 usb_set_intfdata(intf, NULL);
299 312
300 intf->condition = USB_INTERFACE_UNBOUND; 313 intf->condition = USB_INTERFACE_UNBOUND;
@@ -344,7 +357,7 @@ int usb_driver_claim_interface(struct usb_driver *driver,
344 usb_pm_lock(udev); 357 usb_pm_lock(udev);
345 iface->condition = USB_INTERFACE_BOUND; 358 iface->condition = USB_INTERFACE_BOUND;
346 mark_active(iface); 359 mark_active(iface);
347 iface->pm_usage_cnt = !(driver->supports_autosuspend); 360 atomic_set(&iface->pm_usage_cnt, !driver->supports_autosuspend);
348 usb_pm_unlock(udev); 361 usb_pm_unlock(udev);
349 362
350 /* if interface was already added, bind now; else let 363 /* if interface was already added, bind now; else let
@@ -1065,7 +1078,7 @@ static int autosuspend_check(struct usb_device *udev, int reschedule)
1065 intf = udev->actconfig->interface[i]; 1078 intf = udev->actconfig->interface[i];
1066 if (!is_active(intf)) 1079 if (!is_active(intf))
1067 continue; 1080 continue;
1068 if (intf->pm_usage_cnt > 0) 1081 if (atomic_read(&intf->pm_usage_cnt) > 0)
1069 return -EBUSY; 1082 return -EBUSY;
1070 if (intf->needs_remote_wakeup && 1083 if (intf->needs_remote_wakeup &&
1071 !udev->do_remote_wakeup) { 1084 !udev->do_remote_wakeup) {
@@ -1461,17 +1474,19 @@ static int usb_autopm_do_interface(struct usb_interface *intf,
1461 status = -ENODEV; 1474 status = -ENODEV;
1462 else { 1475 else {
1463 udev->auto_pm = 1; 1476 udev->auto_pm = 1;
1464 intf->pm_usage_cnt += inc_usage_cnt; 1477 atomic_add(inc_usage_cnt, &intf->pm_usage_cnt);
1465 udev->last_busy = jiffies; 1478 udev->last_busy = jiffies;
1466 if (inc_usage_cnt >= 0 && intf->pm_usage_cnt > 0) { 1479 if (inc_usage_cnt >= 0 &&
1480 atomic_read(&intf->pm_usage_cnt) > 0) {
1467 if (udev->state == USB_STATE_SUSPENDED) 1481 if (udev->state == USB_STATE_SUSPENDED)
1468 status = usb_resume_both(udev, 1482 status = usb_resume_both(udev,
1469 PMSG_AUTO_RESUME); 1483 PMSG_AUTO_RESUME);
1470 if (status != 0) 1484 if (status != 0)
1471 intf->pm_usage_cnt -= inc_usage_cnt; 1485 atomic_sub(inc_usage_cnt, &intf->pm_usage_cnt);
1472 else 1486 else
1473 udev->last_busy = jiffies; 1487 udev->last_busy = jiffies;
1474 } else if (inc_usage_cnt <= 0 && intf->pm_usage_cnt <= 0) { 1488 } else if (inc_usage_cnt <= 0 &&
1489 atomic_read(&intf->pm_usage_cnt) <= 0) {
1475 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); 1490 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1476 } 1491 }
1477 } 1492 }
@@ -1516,7 +1531,7 @@ void usb_autopm_put_interface(struct usb_interface *intf)
1516 1531
1517 status = usb_autopm_do_interface(intf, -1); 1532 status = usb_autopm_do_interface(intf, -1);
1518 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1533 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1519 __func__, status, intf->pm_usage_cnt); 1534 __func__, status, atomic_read(&intf->pm_usage_cnt));
1520} 1535}
1521EXPORT_SYMBOL_GPL(usb_autopm_put_interface); 1536EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1522 1537
@@ -1544,10 +1559,10 @@ void usb_autopm_put_interface_async(struct usb_interface *intf)
1544 status = -ENODEV; 1559 status = -ENODEV;
1545 } else { 1560 } else {
1546 udev->last_busy = jiffies; 1561 udev->last_busy = jiffies;
1547 --intf->pm_usage_cnt; 1562 atomic_dec(&intf->pm_usage_cnt);
1548 if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) 1563 if (udev->autosuspend_disabled || udev->autosuspend_delay < 0)
1549 status = -EPERM; 1564 status = -EPERM;
1550 else if (intf->pm_usage_cnt <= 0 && 1565 else if (atomic_read(&intf->pm_usage_cnt) <= 0 &&
1551 !timer_pending(&udev->autosuspend.timer)) { 1566 !timer_pending(&udev->autosuspend.timer)) {
1552 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, 1567 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1553 round_jiffies_up_relative( 1568 round_jiffies_up_relative(
@@ -1555,7 +1570,7 @@ void usb_autopm_put_interface_async(struct usb_interface *intf)
1555 } 1570 }
1556 } 1571 }
1557 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1572 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1558 __func__, status, intf->pm_usage_cnt); 1573 __func__, status, atomic_read(&intf->pm_usage_cnt));
1559} 1574}
1560EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); 1575EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async);
1561 1576
@@ -1599,7 +1614,7 @@ int usb_autopm_get_interface(struct usb_interface *intf)
1599 1614
1600 status = usb_autopm_do_interface(intf, 1); 1615 status = usb_autopm_do_interface(intf, 1);
1601 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1616 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1602 __func__, status, intf->pm_usage_cnt); 1617 __func__, status, atomic_read(&intf->pm_usage_cnt));
1603 return status; 1618 return status;
1604} 1619}
1605EXPORT_SYMBOL_GPL(usb_autopm_get_interface); 1620EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
@@ -1627,10 +1642,14 @@ int usb_autopm_get_interface_async(struct usb_interface *intf)
1627 status = -ENODEV; 1642 status = -ENODEV;
1628 else if (udev->autoresume_disabled) 1643 else if (udev->autoresume_disabled)
1629 status = -EPERM; 1644 status = -EPERM;
1630 else if (++intf->pm_usage_cnt > 0 && udev->state == USB_STATE_SUSPENDED) 1645 else {
1631 queue_work(ksuspend_usb_wq, &udev->autoresume); 1646 atomic_inc(&intf->pm_usage_cnt);
1647 if (atomic_read(&intf->pm_usage_cnt) > 0 &&
1648 udev->state == USB_STATE_SUSPENDED)
1649 queue_work(ksuspend_usb_wq, &udev->autoresume);
1650 }
1632 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1651 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1633 __func__, status, intf->pm_usage_cnt); 1652 __func__, status, atomic_read(&intf->pm_usage_cnt));
1634 return status; 1653 return status;
1635} 1654}
1636EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); 1655EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async);
@@ -1652,7 +1671,7 @@ int usb_autopm_set_interface(struct usb_interface *intf)
1652 1671
1653 status = usb_autopm_do_interface(intf, 0); 1672 status = usb_autopm_do_interface(intf, 0);
1654 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1673 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n",
1655 __func__, status, intf->pm_usage_cnt); 1674 __func__, status, atomic_read(&intf->pm_usage_cnt));
1656 return status; 1675 return status;
1657} 1676}
1658EXPORT_SYMBOL_GPL(usb_autopm_set_interface); 1677EXPORT_SYMBOL_GPL(usb_autopm_set_interface);
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 30ecac3af15a..05e6d313961e 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -158,7 +158,9 @@ static int generic_probe(struct usb_device *udev)
158 /* Choose and set the configuration. This registers the interfaces 158 /* Choose and set the configuration. This registers the interfaces
159 * with the driver core and lets interface drivers bind to them. 159 * with the driver core and lets interface drivers bind to them.
160 */ 160 */
161 if (udev->authorized == 0) 161 if (usb_device_is_owned(udev))
162 ; /* Don't configure if the device is owned */
163 else if (udev->authorized == 0)
162 dev_err(&udev->dev, "Device is not authorized for usage\n"); 164 dev_err(&udev->dev, "Device is not authorized for usage\n");
163 else { 165 else {
164 c = usb_choose_configuration(udev); 166 c = usb_choose_configuration(udev);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 95ccfa0b9fc5..34de475f016e 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -337,72 +337,89 @@ static const u8 ss_rh_config_descriptor[] = {
337 337
338/*-------------------------------------------------------------------------*/ 338/*-------------------------------------------------------------------------*/
339 339
340/* 340/**
341 * helper routine for returning string descriptors in UTF-16LE 341 * ascii2desc() - Helper routine for producing UTF-16LE string descriptors
342 * input can actually be ISO-8859-1; ASCII is its 7-bit subset 342 * @s: Null-terminated ASCII (actually ISO-8859-1) string
343 * @buf: Buffer for USB string descriptor (header + UTF-16LE)
344 * @len: Length (in bytes; may be odd) of descriptor buffer.
345 *
346 * The return value is the number of bytes filled in: 2 + 2*strlen(s) or
347 * buflen, whichever is less.
348 *
349 * USB String descriptors can contain at most 126 characters; input
350 * strings longer than that are truncated.
343 */ 351 */
344static unsigned ascii2utf(char *s, u8 *utf, int utfmax) 352static unsigned
353ascii2desc(char const *s, u8 *buf, unsigned len)
345{ 354{
346 unsigned retval; 355 unsigned n, t = 2 + 2*strlen(s);
347 356
348 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) { 357 if (t > 254)
349 *utf++ = *s++; 358 t = 254; /* Longest possible UTF string descriptor */
350 *utf++ = 0; 359 if (len > t)
351 } 360 len = t;
352 if (utfmax > 0) { 361
353 *utf = *s; 362 t += USB_DT_STRING << 8; /* Now t is first 16 bits to store */
354 ++retval; 363
364 n = len;
365 while (n--) {
366 *buf++ = t;
367 if (!n--)
368 break;
369 *buf++ = t >> 8;
370 t = (unsigned char)*s++;
355 } 371 }
356 return retval; 372 return len;
357} 373}
358 374
359/* 375/**
360 * rh_string - provides manufacturer, product and serial strings for root hub 376 * rh_string() - provides string descriptors for root hub
361 * @id: the string ID number (1: serial number, 2: product, 3: vendor) 377 * @id: the string ID number (0: langids, 1: serial #, 2: product, 3: vendor)
362 * @hcd: the host controller for this root hub 378 * @hcd: the host controller for this root hub
363 * @data: return packet in UTF-16 LE 379 * @data: buffer for output packet
364 * @len: length of the return packet 380 * @len: length of the provided buffer
365 * 381 *
366 * Produces either a manufacturer, product or serial number string for the 382 * Produces either a manufacturer, product or serial number string for the
367 * virtual root hub device. 383 * virtual root hub device.
384 * Returns the number of bytes filled in: the length of the descriptor or
385 * of the provided buffer, whichever is less.
368 */ 386 */
369static unsigned rh_string(int id, struct usb_hcd *hcd, u8 *data, unsigned len) 387static unsigned
388rh_string(int id, struct usb_hcd const *hcd, u8 *data, unsigned len)
370{ 389{
371 char buf [100]; 390 char buf[100];
391 char const *s;
392 static char const langids[4] = {4, USB_DT_STRING, 0x09, 0x04};
372 393
373 // language ids 394 // language ids
374 if (id == 0) { 395 switch (id) {
375 buf[0] = 4; buf[1] = 3; /* 4 bytes string data */ 396 case 0:
376 buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */ 397 /* Array of LANGID codes (0x0409 is MSFT-speak for "en-us") */
377 len = min_t(unsigned, len, 4); 398 /* See http://www.usb.org/developers/docs/USB_LANGIDs.pdf */
378 memcpy (data, buf, len); 399 if (len > 4)
400 len = 4;
401 memcpy(data, langids, len);
379 return len; 402 return len;
380 403 case 1:
381 // serial number 404 /* Serial number */
382 } else if (id == 1) { 405 s = hcd->self.bus_name;
383 strlcpy (buf, hcd->self.bus_name, sizeof buf); 406 break;
384 407 case 2:
385 // product description 408 /* Product name */
386 } else if (id == 2) { 409 s = hcd->product_desc;
387 strlcpy (buf, hcd->product_desc, sizeof buf); 410 break;
388 411 case 3:
389 // id 3 == vendor description 412 /* Manufacturer */
390 } else if (id == 3) {
391 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, 413 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
392 init_utsname()->release, hcd->driver->description); 414 init_utsname()->release, hcd->driver->description);
393 } 415 s = buf;
394 416 break;
395 switch (len) { /* All cases fall through */
396 default: 417 default:
397 len = 2 + ascii2utf (buf, data + 2, len - 2); 418 /* Can't happen; caller guarantees it */
398 case 2: 419 return 0;
399 data [1] = 3; /* type == string */
400 case 1:
401 data [0] = 2 * (strlen (buf) + 1);
402 case 0:
403 ; /* Compiler wants a statement here */
404 } 420 }
405 return len; 421
422 return ascii2desc(s, data, len);
406} 423}
407 424
408 425
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index ec5c67ea07b7..79782a1c43f6 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -267,6 +267,11 @@ struct hc_driver {
267 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); 267 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
268 /* Returns the hardware-chosen device address */ 268 /* Returns the hardware-chosen device address */
269 int (*address_device)(struct usb_hcd *, struct usb_device *udev); 269 int (*address_device)(struct usb_hcd *, struct usb_device *udev);
270 /* Notifies the HCD after a hub descriptor is fetched.
271 * Will block.
272 */
273 int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev,
274 struct usb_tt *tt, gfp_t mem_flags);
270}; 275};
271 276
272extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 277extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 71f86c60d83c..5ce839137ad6 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -78,6 +78,7 @@ struct usb_hub {
78 u8 indicator[USB_MAXCHILDREN]; 78 u8 indicator[USB_MAXCHILDREN];
79 struct delayed_work leds; 79 struct delayed_work leds;
80 struct delayed_work init_work; 80 struct delayed_work init_work;
81 void **port_owners;
81}; 82};
82 83
83 84
@@ -162,8 +163,10 @@ static inline char *portspeed(int portstatus)
162} 163}
163 164
164/* Note that hdev or one of its children must be locked! */ 165/* Note that hdev or one of its children must be locked! */
165static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev) 166static struct usb_hub *hdev_to_hub(struct usb_device *hdev)
166{ 167{
168 if (!hdev || !hdev->actconfig)
169 return NULL;
167 return usb_get_intfdata(hdev->actconfig->interface[0]); 170 return usb_get_intfdata(hdev->actconfig->interface[0]);
168} 171}
169 172
@@ -372,7 +375,7 @@ static void kick_khubd(struct usb_hub *hub)
372 unsigned long flags; 375 unsigned long flags;
373 376
374 /* Suppress autosuspend until khubd runs */ 377 /* Suppress autosuspend until khubd runs */
375 to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; 378 atomic_set(&to_usb_interface(hub->intfdev)->pm_usage_cnt, 1);
376 379
377 spin_lock_irqsave(&hub_event_lock, flags); 380 spin_lock_irqsave(&hub_event_lock, flags);
378 if (!hub->disconnected && list_empty(&hub->event_list)) { 381 if (!hub->disconnected && list_empty(&hub->event_list)) {
@@ -384,8 +387,10 @@ static void kick_khubd(struct usb_hub *hub)
384 387
385void usb_kick_khubd(struct usb_device *hdev) 388void usb_kick_khubd(struct usb_device *hdev)
386{ 389{
387 /* FIXME: What if hdev isn't bound to the hub driver? */ 390 struct usb_hub *hub = hdev_to_hub(hdev);
388 kick_khubd(hdev_to_hub(hdev)); 391
392 if (hub)
393 kick_khubd(hub);
389} 394}
390 395
391 396
@@ -677,7 +682,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
677 msecs_to_jiffies(delay)); 682 msecs_to_jiffies(delay));
678 683
679 /* Suppress autosuspend until init is done */ 684 /* Suppress autosuspend until init is done */
680 to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; 685 atomic_set(&to_usb_interface(hub->intfdev)->
686 pm_usage_cnt, 1);
681 return; /* Continues at init2: below */ 687 return; /* Continues at init2: below */
682 } else { 688 } else {
683 hub_power_on(hub, true); 689 hub_power_on(hub, true);
@@ -854,25 +860,24 @@ static int hub_post_reset(struct usb_interface *intf)
854static int hub_configure(struct usb_hub *hub, 860static int hub_configure(struct usb_hub *hub,
855 struct usb_endpoint_descriptor *endpoint) 861 struct usb_endpoint_descriptor *endpoint)
856{ 862{
863 struct usb_hcd *hcd;
857 struct usb_device *hdev = hub->hdev; 864 struct usb_device *hdev = hub->hdev;
858 struct device *hub_dev = hub->intfdev; 865 struct device *hub_dev = hub->intfdev;
859 u16 hubstatus, hubchange; 866 u16 hubstatus, hubchange;
860 u16 wHubCharacteristics; 867 u16 wHubCharacteristics;
861 unsigned int pipe; 868 unsigned int pipe;
862 int maxp, ret; 869 int maxp, ret;
863 char *message; 870 char *message = "out of memory";
864 871
865 hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL, 872 hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL,
866 &hub->buffer_dma); 873 &hub->buffer_dma);
867 if (!hub->buffer) { 874 if (!hub->buffer) {
868 message = "can't allocate hub irq buffer";
869 ret = -ENOMEM; 875 ret = -ENOMEM;
870 goto fail; 876 goto fail;
871 } 877 }
872 878
873 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL); 879 hub->status = kmalloc(sizeof(*hub->status), GFP_KERNEL);
874 if (!hub->status) { 880 if (!hub->status) {
875 message = "can't kmalloc hub status buffer";
876 ret = -ENOMEM; 881 ret = -ENOMEM;
877 goto fail; 882 goto fail;
878 } 883 }
@@ -880,7 +885,6 @@ static int hub_configure(struct usb_hub *hub,
880 885
881 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL); 886 hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);
882 if (!hub->descriptor) { 887 if (!hub->descriptor) {
883 message = "can't kmalloc hub descriptor";
884 ret = -ENOMEM; 888 ret = -ENOMEM;
885 goto fail; 889 goto fail;
886 } 890 }
@@ -904,6 +908,12 @@ static int hub_configure(struct usb_hub *hub,
904 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild, 908 dev_info (hub_dev, "%d port%s detected\n", hdev->maxchild,
905 (hdev->maxchild == 1) ? "" : "s"); 909 (hdev->maxchild == 1) ? "" : "s");
906 910
911 hub->port_owners = kzalloc(hdev->maxchild * sizeof(void *), GFP_KERNEL);
912 if (!hub->port_owners) {
913 ret = -ENOMEM;
914 goto fail;
915 }
916
907 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics); 917 wHubCharacteristics = le16_to_cpu(hub->descriptor->wHubCharacteristics);
908 918
909 if (wHubCharacteristics & HUB_CHAR_COMPOUND) { 919 if (wHubCharacteristics & HUB_CHAR_COMPOUND) {
@@ -1052,6 +1062,19 @@ static int hub_configure(struct usb_hub *hub,
1052 dev_dbg(hub_dev, "%umA bus power budget for each child\n", 1062 dev_dbg(hub_dev, "%umA bus power budget for each child\n",
1053 hub->mA_per_port); 1063 hub->mA_per_port);
1054 1064
1065 /* Update the HCD's internal representation of this hub before khubd
1066 * starts getting port status changes for devices under the hub.
1067 */
1068 hcd = bus_to_hcd(hdev->bus);
1069 if (hcd->driver->update_hub_device) {
1070 ret = hcd->driver->update_hub_device(hcd, hdev,
1071 &hub->tt, GFP_KERNEL);
1072 if (ret < 0) {
1073 message = "can't update HCD hub info";
1074 goto fail;
1075 }
1076 }
1077
1055 ret = hub_hub_status(hub, &hubstatus, &hubchange); 1078 ret = hub_hub_status(hub, &hubstatus, &hubchange);
1056 if (ret < 0) { 1079 if (ret < 0) {
1057 message = "can't get hub status"; 1080 message = "can't get hub status";
@@ -1082,7 +1105,6 @@ static int hub_configure(struct usb_hub *hub,
1082 1105
1083 hub->urb = usb_alloc_urb(0, GFP_KERNEL); 1106 hub->urb = usb_alloc_urb(0, GFP_KERNEL);
1084 if (!hub->urb) { 1107 if (!hub->urb) {
1085 message = "couldn't allocate interrupt urb";
1086 ret = -ENOMEM; 1108 ret = -ENOMEM;
1087 goto fail; 1109 goto fail;
1088 } 1110 }
@@ -1131,11 +1153,13 @@ static void hub_disconnect(struct usb_interface *intf)
1131 hub_quiesce(hub, HUB_DISCONNECT); 1153 hub_quiesce(hub, HUB_DISCONNECT);
1132 1154
1133 usb_set_intfdata (intf, NULL); 1155 usb_set_intfdata (intf, NULL);
1156 hub->hdev->maxchild = 0;
1134 1157
1135 if (hub->hdev->speed == USB_SPEED_HIGH) 1158 if (hub->hdev->speed == USB_SPEED_HIGH)
1136 highspeed_hubs--; 1159 highspeed_hubs--;
1137 1160
1138 usb_free_urb(hub->urb); 1161 usb_free_urb(hub->urb);
1162 kfree(hub->port_owners);
1139 kfree(hub->descriptor); 1163 kfree(hub->descriptor);
1140 kfree(hub->status); 1164 kfree(hub->status);
1141 usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer, 1165 usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer,
@@ -1250,6 +1274,79 @@ hub_ioctl(struct usb_interface *intf, unsigned int code, void *user_data)
1250 } 1274 }
1251} 1275}
1252 1276
1277/*
1278 * Allow user programs to claim ports on a hub. When a device is attached
1279 * to one of these "claimed" ports, the program will "own" the device.
1280 */
1281static int find_port_owner(struct usb_device *hdev, unsigned port1,
1282 void ***ppowner)
1283{
1284 if (hdev->state == USB_STATE_NOTATTACHED)
1285 return -ENODEV;
1286 if (port1 == 0 || port1 > hdev->maxchild)
1287 return -EINVAL;
1288
1289 /* This assumes that devices not managed by the hub driver
1290 * will always have maxchild equal to 0.
1291 */
1292 *ppowner = &(hdev_to_hub(hdev)->port_owners[port1 - 1]);
1293 return 0;
1294}
1295
1296/* In the following three functions, the caller must hold hdev's lock */
1297int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, void *owner)
1298{
1299 int rc;
1300 void **powner;
1301
1302 rc = find_port_owner(hdev, port1, &powner);
1303 if (rc)
1304 return rc;
1305 if (*powner)
1306 return -EBUSY;
1307 *powner = owner;
1308 return rc;
1309}
1310
1311int usb_hub_release_port(struct usb_device *hdev, unsigned port1, void *owner)
1312{
1313 int rc;
1314 void **powner;
1315
1316 rc = find_port_owner(hdev, port1, &powner);
1317 if (rc)
1318 return rc;
1319 if (*powner != owner)
1320 return -ENOENT;
1321 *powner = NULL;
1322 return rc;
1323}
1324
1325void usb_hub_release_all_ports(struct usb_device *hdev, void *owner)
1326{
1327 int n;
1328 void **powner;
1329
1330 n = find_port_owner(hdev, 1, &powner);
1331 if (n == 0) {
1332 for (; n < hdev->maxchild; (++n, ++powner)) {
1333 if (*powner == owner)
1334 *powner = NULL;
1335 }
1336 }
1337}
1338
1339/* The caller must hold udev's lock */
1340bool usb_device_is_owned(struct usb_device *udev)
1341{
1342 struct usb_hub *hub;
1343
1344 if (udev->state == USB_STATE_NOTATTACHED || !udev->parent)
1345 return false;
1346 hub = hdev_to_hub(udev->parent);
1347 return !!hub->port_owners[udev->portnum - 1];
1348}
1349
1253 1350
1254static void recursively_mark_NOTATTACHED(struct usb_device *udev) 1351static void recursively_mark_NOTATTACHED(struct usb_device *udev)
1255{ 1352{
@@ -2849,14 +2946,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2849 /* For a suspended device, treat this as a 2946 /* For a suspended device, treat this as a
2850 * remote wakeup event. 2947 * remote wakeup event.
2851 */ 2948 */
2852 if (udev->do_remote_wakeup) 2949 status = remote_wakeup(udev);
2853 status = remote_wakeup(udev);
2854
2855 /* Otherwise leave it be; devices can't tell the
2856 * difference between suspended and disabled.
2857 */
2858 else
2859 status = 0;
2860#endif 2950#endif
2861 2951
2862 } else { 2952 } else {
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 9720e699f472..da718e84d58d 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -459,35 +459,23 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
459 io->urbs[i]->context = io; 459 io->urbs[i]->context = io;
460 460
461 /* 461 /*
462 * Some systems need to revert to PIO when DMA is 462 * Some systems need to revert to PIO when DMA is temporarily
463 * temporarily unavailable. For their sakes, both 463 * unavailable. For their sakes, both transfer_buffer and
464 * transfer_buffer and transfer_dma are set when 464 * transfer_dma are set when possible.
465 * possible. However this can only work on systems
466 * without:
467 * 465 *
468 * - HIGHMEM, since DMA buffers located in high memory 466 * Note that if IOMMU coalescing occurred, we cannot
469 * are not directly addressable by the CPU for PIO; 467 * trust sg_page anymore, so check if S/G list shrunk.
470 *
471 * - IOMMU, since dma_map_sg() is allowed to use an
472 * IOMMU to make virtually discontiguous buffers be
473 * "dma-contiguous" so that PIO and DMA need diferent
474 * numbers of URBs.
475 *
476 * So when HIGHMEM or IOMMU are in use, transfer_buffer
477 * is NULL to prevent stale pointers and to help spot
478 * bugs.
479 */ 468 */
469 if (io->nents == io->entries && !PageHighMem(sg_page(sg)))
470 io->urbs[i]->transfer_buffer = sg_virt(sg);
471 else
472 io->urbs[i]->transfer_buffer = NULL;
473
480 if (dma) { 474 if (dma) {
481 io->urbs[i]->transfer_dma = sg_dma_address(sg); 475 io->urbs[i]->transfer_dma = sg_dma_address(sg);
482 len = sg_dma_len(sg); 476 len = sg_dma_len(sg);
483#if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
484 io->urbs[i]->transfer_buffer = NULL;
485#else
486 io->urbs[i]->transfer_buffer = sg_virt(sg);
487#endif
488 } else { 477 } else {
489 /* hc may use _only_ transfer_buffer */ 478 /* hc may use _only_ transfer_buffer */
490 io->urbs[i]->transfer_buffer = sg_virt(sg);
491 len = sg->length; 479 len = sg->length;
492 } 480 }
493 481
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 43ee943d757a..b1b85abb9a2d 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -413,8 +413,13 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
413 } else { 413 } else {
414 snprintf(dev->devpath, sizeof dev->devpath, 414 snprintf(dev->devpath, sizeof dev->devpath,
415 "%s.%d", parent->devpath, port1); 415 "%s.%d", parent->devpath, port1);
416 dev->route = parent->route + 416 /* Route string assumes hubs have less than 16 ports */
417 (port1 << ((parent->level - 1)*4)); 417 if (port1 < 15)
418 dev->route = parent->route +
419 (port1 << ((parent->level - 1)*4));
420 else
421 dev->route = parent->route +
422 (15 << ((parent->level - 1)*4));
418 } 423 }
419 424
420 dev->dev.parent = &parent->dev; 425 dev->dev.parent = &parent->dev;
@@ -914,11 +919,11 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
914 || !(bus = dev->bus) 919 || !(bus = dev->bus)
915 || !(controller = bus->controller) 920 || !(controller = bus->controller)
916 || !controller->dma_mask) 921 || !controller->dma_mask)
917 return -1; 922 return -EINVAL;
918 923
919 /* FIXME generic api broken like pci, can't report errors */ 924 /* FIXME generic api broken like pci, can't report errors */
920 return dma_map_sg(controller, sg, nents, 925 return dma_map_sg(controller, sg, nents,
921 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 926 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE) ? : -ENOMEM;
922} 927}
923EXPORT_SYMBOL_GPL(usb_buffer_map_sg); 928EXPORT_SYMBOL_GPL(usb_buffer_map_sg);
924 929
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index c0e0ae2bb8e7..9a8b15e6377a 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -37,6 +37,13 @@ extern int usb_match_device(struct usb_device *dev,
37extern void usb_forced_unbind_intf(struct usb_interface *intf); 37extern void usb_forced_unbind_intf(struct usb_interface *intf);
38extern void usb_rebind_intf(struct usb_interface *intf); 38extern void usb_rebind_intf(struct usb_interface *intf);
39 39
40extern int usb_hub_claim_port(struct usb_device *hdev, unsigned port,
41 void *owner);
42extern int usb_hub_release_port(struct usb_device *hdev, unsigned port,
43 void *owner);
44extern void usb_hub_release_all_ports(struct usb_device *hdev, void *owner);
45extern bool usb_device_is_owned(struct usb_device *udev);
46
40extern int usb_hub_init(void); 47extern int usb_hub_init(void);
41extern void usb_hub_cleanup(void); 48extern void usb_hub_cleanup(void);
42extern int usb_major_init(void); 49extern int usb_major_init(void);
diff --git a/drivers/usb/early/Makefile b/drivers/usb/early/Makefile
new file mode 100644
index 000000000000..dfedee8c45b6
--- /dev/null
+++ b/drivers/usb/early/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for early USB devices
3#
4
5obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
new file mode 100644
index 000000000000..1206a26ef893
--- /dev/null
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -0,0 +1,996 @@
1/*
2 * Standalone EHCI usb debug driver
3 *
4 * Originally written by:
5 * Eric W. Biederman" <ebiederm@xmission.com> and
6 * Yinghai Lu <yhlu.kernel@gmail.com>
7 *
8 * Changes for early/late printk and HW errata:
9 * Jason Wessel <jason.wessel@windriver.com>
10 * Copyright (C) 2009 Wind River Systems, Inc.
11 *
12 */
13
14#include <linux/console.h>
15#include <linux/errno.h>
16#include <linux/module.h>
17#include <linux/pci_regs.h>
18#include <linux/pci_ids.h>
19#include <linux/usb/ch9.h>
20#include <linux/usb/ehci_def.h>
21#include <linux/delay.h>
22#include <asm/io.h>
23#include <asm/pci-direct.h>
24#include <asm/fixmap.h>
25
26/* The code here is intended to talk directly to the EHCI debug port
27 * and does not require that you have any kind of USB host controller
28 * drivers or USB device drivers compiled into the kernel.
29 *
30 * If you make a change to anything in here, the following test cases
31 * need to pass where a USB debug device works in the following
32 * configurations.
33 *
34 * 1. boot args: earlyprintk=dbgp
35 * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set
36 * o kernel compiled with CONFIG_USB_EHCI_HCD=y
37 * 2. boot args: earlyprintk=dbgp,keep
38 * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set
39 * o kernel compiled with CONFIG_USB_EHCI_HCD=y
40 * 3. boot args: earlyprintk=dbgp console=ttyUSB0
41 * o kernel has CONFIG_USB_EHCI_HCD=y and
42 * CONFIG_USB_SERIAL_DEBUG=y
43 * 4. boot args: earlyprintk=vga,dbgp
44 * o kernel compiled with # CONFIG_USB_EHCI_HCD is not set
45 * o kernel compiled with CONFIG_USB_EHCI_HCD=y
46 *
47 * For the 4th configuration you can turn on or off the DBGP_DEBUG
48 * such that you can debug the dbgp device's driver code.
49 */
50
51static int dbgp_phys_port = 1;
52
53static struct ehci_caps __iomem *ehci_caps;
54static struct ehci_regs __iomem *ehci_regs;
55static struct ehci_dbg_port __iomem *ehci_debug;
56static int dbgp_not_safe; /* Cannot use debug device during ehci reset */
57static unsigned int dbgp_endpoint_out;
58
59struct ehci_dev {
60 u32 bus;
61 u32 slot;
62 u32 func;
63};
64
65static struct ehci_dev ehci_dev;
66
67#define USB_DEBUG_DEVNUM 127
68
69#define DBGP_DATA_TOGGLE 0x8800
70
71#ifdef DBGP_DEBUG
72#define dbgp_printk printk
73static void dbgp_ehci_status(char *str)
74{
75 if (!ehci_debug)
76 return;
77 dbgp_printk("dbgp: %s\n", str);
78 dbgp_printk(" Debug control: %08x", readl(&ehci_debug->control));
79 dbgp_printk(" ehci cmd : %08x", readl(&ehci_regs->command));
80 dbgp_printk(" ehci conf flg: %08x\n",
81 readl(&ehci_regs->configured_flag));
82 dbgp_printk(" ehci status : %08x", readl(&ehci_regs->status));
83 dbgp_printk(" ehci portsc : %08x\n",
84 readl(&ehci_regs->port_status[dbgp_phys_port - 1]));
85}
86#else
87static inline void dbgp_ehci_status(char *str) { }
88static inline void dbgp_printk(const char *fmt, ...) { }
89#endif
90
91static inline u32 dbgp_pid_update(u32 x, u32 tok)
92{
93 return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff);
94}
95
96static inline u32 dbgp_len_update(u32 x, u32 len)
97{
98 return (x & ~0x0f) | (len & 0x0f);
99}
100
101/*
102 * USB Packet IDs (PIDs)
103 */
104
105/* token */
106#define USB_PID_OUT 0xe1
107#define USB_PID_IN 0x69
108#define USB_PID_SOF 0xa5
109#define USB_PID_SETUP 0x2d
110/* handshake */
111#define USB_PID_ACK 0xd2
112#define USB_PID_NAK 0x5a
113#define USB_PID_STALL 0x1e
114#define USB_PID_NYET 0x96
115/* data */
116#define USB_PID_DATA0 0xc3
117#define USB_PID_DATA1 0x4b
118#define USB_PID_DATA2 0x87
119#define USB_PID_MDATA 0x0f
120/* Special */
121#define USB_PID_PREAMBLE 0x3c
122#define USB_PID_ERR 0x3c
123#define USB_PID_SPLIT 0x78
124#define USB_PID_PING 0xb4
125#define USB_PID_UNDEF_0 0xf0
126
127#define USB_PID_DATA_TOGGLE 0x88
128#define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE)
129
130#define PCI_CAP_ID_EHCI_DEBUG 0xa
131
132#define HUB_ROOT_RESET_TIME 50 /* times are in msec */
133#define HUB_SHORT_RESET_TIME 10
134#define HUB_LONG_RESET_TIME 200
135#define HUB_RESET_TIMEOUT 500
136
137#define DBGP_MAX_PACKET 8
138#define DBGP_TIMEOUT (250 * 1000)
139
140static int dbgp_wait_until_complete(void)
141{
142 u32 ctrl;
143 int loop = DBGP_TIMEOUT;
144
145 do {
146 ctrl = readl(&ehci_debug->control);
147 /* Stop when the transaction is finished */
148 if (ctrl & DBGP_DONE)
149 break;
150 udelay(1);
151 } while (--loop > 0);
152
153 if (!loop)
154 return -DBGP_TIMEOUT;
155
156 /*
157 * Now that we have observed the completed transaction,
158 * clear the done bit.
159 */
160 writel(ctrl | DBGP_DONE, &ehci_debug->control);
161 return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl);
162}
163
164static inline void dbgp_mdelay(int ms)
165{
166 int i;
167
168 while (ms--) {
169 for (i = 0; i < 1000; i++)
170 outb(0x1, 0x80);
171 }
172}
173
174static void dbgp_breath(void)
175{
176 /* Sleep to give the debug port a chance to breathe */
177}
178
179static int dbgp_wait_until_done(unsigned ctrl)
180{
181 u32 pids, lpid;
182 int ret;
183 int loop = 3;
184
185retry:
186 writel(ctrl | DBGP_GO, &ehci_debug->control);
187 ret = dbgp_wait_until_complete();
188 pids = readl(&ehci_debug->pids);
189 lpid = DBGP_PID_GET(pids);
190
191 if (ret < 0) {
192 /* A -DBGP_TIMEOUT failure here means the device has
193 * failed, perhaps because it was unplugged, in which
194 * case we do not want to hang the system so the dbgp
195 * will be marked as unsafe to use. EHCI reset is the
196 * only way to recover if you unplug the dbgp device.
197 */
198 if (ret == -DBGP_TIMEOUT && !dbgp_not_safe)
199 dbgp_not_safe = 1;
200 return ret;
201 }
202
203 /*
204 * If the port is getting full or it has dropped data
205 * start pacing ourselves, not necessary but it's friendly.
206 */
207 if ((lpid == USB_PID_NAK) || (lpid == USB_PID_NYET))
208 dbgp_breath();
209
210 /* If I get a NACK reissue the transmission */
211 if (lpid == USB_PID_NAK) {
212 if (--loop > 0)
213 goto retry;
214 }
215
216 return ret;
217}
218
219static inline void dbgp_set_data(const void *buf, int size)
220{
221 const unsigned char *bytes = buf;
222 u32 lo, hi;
223 int i;
224
225 lo = hi = 0;
226 for (i = 0; i < 4 && i < size; i++)
227 lo |= bytes[i] << (8*i);
228 for (; i < 8 && i < size; i++)
229 hi |= bytes[i] << (8*(i - 4));
230 writel(lo, &ehci_debug->data03);
231 writel(hi, &ehci_debug->data47);
232}
233
234static inline void dbgp_get_data(void *buf, int size)
235{
236 unsigned char *bytes = buf;
237 u32 lo, hi;
238 int i;
239
240 lo = readl(&ehci_debug->data03);
241 hi = readl(&ehci_debug->data47);
242 for (i = 0; i < 4 && i < size; i++)
243 bytes[i] = (lo >> (8*i)) & 0xff;
244 for (; i < 8 && i < size; i++)
245 bytes[i] = (hi >> (8*(i - 4))) & 0xff;
246}
247
248static int dbgp_out(u32 addr, const char *bytes, int size)
249{
250 u32 pids, ctrl;
251
252 pids = readl(&ehci_debug->pids);
253 pids = dbgp_pid_update(pids, USB_PID_OUT);
254
255 ctrl = readl(&ehci_debug->control);
256 ctrl = dbgp_len_update(ctrl, size);
257 ctrl |= DBGP_OUT;
258 ctrl |= DBGP_GO;
259
260 dbgp_set_data(bytes, size);
261 writel(addr, &ehci_debug->address);
262 writel(pids, &ehci_debug->pids);
263 return dbgp_wait_until_done(ctrl);
264}
265
266static int dbgp_bulk_write(unsigned devnum, unsigned endpoint,
267 const char *bytes, int size)
268{
269 int ret;
270 int loops = 5;
271 u32 addr;
272 if (size > DBGP_MAX_PACKET)
273 return -1;
274
275 addr = DBGP_EPADDR(devnum, endpoint);
276try_again:
277 if (loops--) {
278 ret = dbgp_out(addr, bytes, size);
279 if (ret == -DBGP_ERR_BAD) {
280 int try_loops = 3;
281 do {
282 /* Emit a dummy packet to re-sync communication
283 * with the debug device */
284 if (dbgp_out(addr, "12345678", 8) >= 0) {
285 udelay(2);
286 goto try_again;
287 }
288 } while (try_loops--);
289 }
290 }
291
292 return ret;
293}
294
295static int dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data,
296 int size)
297{
298 u32 pids, addr, ctrl;
299 int ret;
300
301 if (size > DBGP_MAX_PACKET)
302 return -1;
303
304 addr = DBGP_EPADDR(devnum, endpoint);
305
306 pids = readl(&ehci_debug->pids);
307 pids = dbgp_pid_update(pids, USB_PID_IN);
308
309 ctrl = readl(&ehci_debug->control);
310 ctrl = dbgp_len_update(ctrl, size);
311 ctrl &= ~DBGP_OUT;
312 ctrl |= DBGP_GO;
313
314 writel(addr, &ehci_debug->address);
315 writel(pids, &ehci_debug->pids);
316 ret = dbgp_wait_until_done(ctrl);
317 if (ret < 0)
318 return ret;
319
320 if (size > ret)
321 size = ret;
322 dbgp_get_data(data, size);
323 return ret;
324}
325
326static int dbgp_control_msg(unsigned devnum, int requesttype,
327 int request, int value, int index, void *data, int size)
328{
329 u32 pids, addr, ctrl;
330 struct usb_ctrlrequest req;
331 int read;
332 int ret;
333
334 read = (requesttype & USB_DIR_IN) != 0;
335 if (size > (read ? DBGP_MAX_PACKET:0))
336 return -1;
337
338 /* Compute the control message */
339 req.bRequestType = requesttype;
340 req.bRequest = request;
341 req.wValue = cpu_to_le16(value);
342 req.wIndex = cpu_to_le16(index);
343 req.wLength = cpu_to_le16(size);
344
345 pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP);
346 addr = DBGP_EPADDR(devnum, 0);
347
348 ctrl = readl(&ehci_debug->control);
349 ctrl = dbgp_len_update(ctrl, sizeof(req));
350 ctrl |= DBGP_OUT;
351 ctrl |= DBGP_GO;
352
353 /* Send the setup message */
354 dbgp_set_data(&req, sizeof(req));
355 writel(addr, &ehci_debug->address);
356 writel(pids, &ehci_debug->pids);
357 ret = dbgp_wait_until_done(ctrl);
358 if (ret < 0)
359 return ret;
360
361 /* Read the result */
362 return dbgp_bulk_read(devnum, 0, data, size);
363}
364
365
366/* Find a PCI capability */
367static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap)
368{
369 u8 pos;
370 int bytes;
371
372 if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
373 PCI_STATUS_CAP_LIST))
374 return 0;
375
376 pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST);
377 for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
378 u8 id;
379
380 pos &= ~3;
381 id = read_pci_config_byte(num, slot, func, pos+PCI_CAP_LIST_ID);
382 if (id == 0xff)
383 break;
384 if (id == cap)
385 return pos;
386
387 pos = read_pci_config_byte(num, slot, func,
388 pos+PCI_CAP_LIST_NEXT);
389 }
390 return 0;
391}
392
393static u32 __init __find_dbgp(u32 bus, u32 slot, u32 func)
394{
395 u32 class;
396
397 class = read_pci_config(bus, slot, func, PCI_CLASS_REVISION);
398 if ((class >> 8) != PCI_CLASS_SERIAL_USB_EHCI)
399 return 0;
400
401 return find_cap(bus, slot, func, PCI_CAP_ID_EHCI_DEBUG);
402}
403
404static u32 __init find_dbgp(int ehci_num, u32 *rbus, u32 *rslot, u32 *rfunc)
405{
406 u32 bus, slot, func;
407
408 for (bus = 0; bus < 256; bus++) {
409 for (slot = 0; slot < 32; slot++) {
410 for (func = 0; func < 8; func++) {
411 unsigned cap;
412
413 cap = __find_dbgp(bus, slot, func);
414
415 if (!cap)
416 continue;
417 if (ehci_num-- != 0)
418 continue;
419 *rbus = bus;
420 *rslot = slot;
421 *rfunc = func;
422 return cap;
423 }
424 }
425 }
426 return 0;
427}
428
429static int dbgp_ehci_startup(void)
430{
431 u32 ctrl, cmd, status;
432 int loop;
433
434 /* Claim ownership, but do not enable yet */
435 ctrl = readl(&ehci_debug->control);
436 ctrl |= DBGP_OWNER;
437 ctrl &= ~(DBGP_ENABLED | DBGP_INUSE);
438 writel(ctrl, &ehci_debug->control);
439 udelay(1);
440
441 dbgp_ehci_status("EHCI startup");
442 /* Start the ehci running */
443 cmd = readl(&ehci_regs->command);
444 cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET);
445 cmd |= CMD_RUN;
446 writel(cmd, &ehci_regs->command);
447
448 /* Ensure everything is routed to the EHCI */
449 writel(FLAG_CF, &ehci_regs->configured_flag);
450
451 /* Wait until the controller is no longer halted */
452 loop = 10;
453 do {
454 status = readl(&ehci_regs->status);
455 if (!(status & STS_HALT))
456 break;
457 udelay(1);
458 } while (--loop > 0);
459
460 if (!loop) {
461 dbgp_printk("ehci can not be started\n");
462 return -ENODEV;
463 }
464 dbgp_printk("ehci started\n");
465 return 0;
466}
467
468static int dbgp_ehci_controller_reset(void)
469{
470 int loop = 250 * 1000;
471 u32 cmd;
472
473 /* Reset the EHCI controller */
474 cmd = readl(&ehci_regs->command);
475 cmd |= CMD_RESET;
476 writel(cmd, &ehci_regs->command);
477 do {
478 cmd = readl(&ehci_regs->command);
479 } while ((cmd & CMD_RESET) && (--loop > 0));
480
481 if (!loop) {
482 dbgp_printk("can not reset ehci\n");
483 return -1;
484 }
485 dbgp_ehci_status("ehci reset done");
486 return 0;
487}
488static int ehci_wait_for_port(int port);
489/* Return 0 on success
490 * Return -ENODEV for any general failure
491 * Return -EIO if wait for port fails
492 */
493int dbgp_external_startup(void)
494{
495 int devnum;
496 struct usb_debug_descriptor dbgp_desc;
497 int ret;
498 u32 ctrl, portsc, cmd;
499 int dbg_port = dbgp_phys_port;
500 int tries = 3;
501 int reset_port_tries = 1;
502 int try_hard_once = 1;
503
504try_port_reset_again:
505 ret = dbgp_ehci_startup();
506 if (ret)
507 return ret;
508
509 /* Wait for a device to show up in the debug port */
510 ret = ehci_wait_for_port(dbg_port);
511 if (ret < 0) {
512 portsc = readl(&ehci_regs->port_status[dbg_port - 1]);
513 if (!(portsc & PORT_CONNECT) && try_hard_once) {
514 /* Last ditch effort to try to force enable
515 * the debug device by using the packet test
516 * ehci command to try and wake it up. */
517 try_hard_once = 0;
518 cmd = readl(&ehci_regs->command);
519 cmd &= ~CMD_RUN;
520 writel(cmd, &ehci_regs->command);
521 portsc = readl(&ehci_regs->port_status[dbg_port - 1]);
522 portsc |= PORT_TEST_PKT;
523 writel(portsc, &ehci_regs->port_status[dbg_port - 1]);
524 dbgp_ehci_status("Trying to force debug port online");
525 mdelay(50);
526 dbgp_ehci_controller_reset();
527 goto try_port_reset_again;
528 } else if (reset_port_tries--) {
529 goto try_port_reset_again;
530 }
531 dbgp_printk("No device found in debug port\n");
532 return -EIO;
533 }
534 dbgp_ehci_status("wait for port done");
535
536 /* Enable the debug port */
537 ctrl = readl(&ehci_debug->control);
538 ctrl |= DBGP_CLAIM;
539 writel(ctrl, &ehci_debug->control);
540 ctrl = readl(&ehci_debug->control);
541 if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) {
542 dbgp_printk("No device in debug port\n");
543 writel(ctrl & ~DBGP_CLAIM, &ehci_debug->control);
544 return -ENODEV;
545 }
546 dbgp_ehci_status("debug ported enabled");
547
548 /* Completely transfer the debug device to the debug controller */
549 portsc = readl(&ehci_regs->port_status[dbg_port - 1]);
550 portsc &= ~PORT_PE;
551 writel(portsc, &ehci_regs->port_status[dbg_port - 1]);
552
553 dbgp_mdelay(100);
554
555try_again:
556 /* Find the debug device and make it device number 127 */
557 for (devnum = 0; devnum <= 127; devnum++) {
558 ret = dbgp_control_msg(devnum,
559 USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
560 USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0,
561 &dbgp_desc, sizeof(dbgp_desc));
562 if (ret > 0)
563 break;
564 }
565 if (devnum > 127) {
566 dbgp_printk("Could not find attached debug device\n");
567 goto err;
568 }
569 if (ret < 0) {
570 dbgp_printk("Attached device is not a debug device\n");
571 goto err;
572 }
573 dbgp_endpoint_out = dbgp_desc.bDebugOutEndpoint;
574
575 /* Move the device to 127 if it isn't already there */
576 if (devnum != USB_DEBUG_DEVNUM) {
577 ret = dbgp_control_msg(devnum,
578 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
579 USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0);
580 if (ret < 0) {
581 dbgp_printk("Could not move attached device to %d\n",
582 USB_DEBUG_DEVNUM);
583 goto err;
584 }
585 devnum = USB_DEBUG_DEVNUM;
586 dbgp_printk("debug device renamed to 127\n");
587 }
588
589 /* Enable the debug interface */
590 ret = dbgp_control_msg(USB_DEBUG_DEVNUM,
591 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
592 USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0);
593 if (ret < 0) {
594 dbgp_printk(" Could not enable the debug device\n");
595 goto err;
596 }
597 dbgp_printk("debug interface enabled\n");
598 /* Perform a small write to get the even/odd data state in sync
599 */
600 ret = dbgp_bulk_write(USB_DEBUG_DEVNUM, dbgp_endpoint_out, " ", 1);
601 if (ret < 0) {
602 dbgp_printk("dbgp_bulk_write failed: %d\n", ret);
603 goto err;
604 }
605 dbgp_printk("small write doned\n");
606 dbgp_not_safe = 0;
607
608 return 0;
609err:
610 if (tries--)
611 goto try_again;
612 return -ENODEV;
613}
614EXPORT_SYMBOL_GPL(dbgp_external_startup);
615
616static int __init ehci_reset_port(int port)
617{
618 u32 portsc;
619 u32 delay_time, delay;
620 int loop;
621
622 dbgp_ehci_status("reset port");
623 /* Reset the usb debug port */
624 portsc = readl(&ehci_regs->port_status[port - 1]);
625 portsc &= ~PORT_PE;
626 portsc |= PORT_RESET;
627 writel(portsc, &ehci_regs->port_status[port - 1]);
628
629 delay = HUB_ROOT_RESET_TIME;
630 for (delay_time = 0; delay_time < HUB_RESET_TIMEOUT;
631 delay_time += delay) {
632 dbgp_mdelay(delay);
633 portsc = readl(&ehci_regs->port_status[port - 1]);
634 if (!(portsc & PORT_RESET))
635 break;
636 }
637 if (portsc & PORT_RESET) {
638 /* force reset to complete */
639 loop = 100 * 1000;
640 writel(portsc & ~(PORT_RWC_BITS | PORT_RESET),
641 &ehci_regs->port_status[port - 1]);
642 do {
643 udelay(1);
644 portsc = readl(&ehci_regs->port_status[port-1]);
645 } while ((portsc & PORT_RESET) && (--loop > 0));
646 }
647
648 /* Device went away? */
649 if (!(portsc & PORT_CONNECT))
650 return -ENOTCONN;
651
652 /* bomb out completely if something weird happend */
653 if ((portsc & PORT_CSC))
654 return -EINVAL;
655
656 /* If we've finished resetting, then break out of the loop */
657 if (!(portsc & PORT_RESET) && (portsc & PORT_PE))
658 return 0;
659 return -EBUSY;
660}
661
662static int ehci_wait_for_port(int port)
663{
664 u32 status;
665 int ret, reps;
666
667 for (reps = 0; reps < 300; reps++) {
668 status = readl(&ehci_regs->status);
669 if (status & STS_PCD)
670 break;
671 dbgp_mdelay(1);
672 }
673 ret = ehci_reset_port(port);
674 if (ret == 0)
675 return 0;
676 return -ENOTCONN;
677}
678
679typedef void (*set_debug_port_t)(int port);
680
681static void __init default_set_debug_port(int port)
682{
683}
684
685static set_debug_port_t __initdata set_debug_port = default_set_debug_port;
686
687static void __init nvidia_set_debug_port(int port)
688{
689 u32 dword;
690 dword = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func,
691 0x74);
692 dword &= ~(0x0f<<12);
693 dword |= ((port & 0x0f)<<12);
694 write_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func, 0x74,
695 dword);
696 dbgp_printk("set debug port to %d\n", port);
697}
698
699static void __init detect_set_debug_port(void)
700{
701 u32 vendorid;
702
703 vendorid = read_pci_config(ehci_dev.bus, ehci_dev.slot, ehci_dev.func,
704 0x00);
705
706 if ((vendorid & 0xffff) == 0x10de) {
707 dbgp_printk("using nvidia set_debug_port\n");
708 set_debug_port = nvidia_set_debug_port;
709 }
710}
711
712/* The code in early_ehci_bios_handoff() is derived from the usb pci
713 * quirk initialization, but altered so as to use the early PCI
714 * routines. */
715#define EHCI_USBLEGSUP_BIOS (1 << 16) /* BIOS semaphore */
716#define EHCI_USBLEGCTLSTS 4 /* legacy control/status */
717static void __init early_ehci_bios_handoff(void)
718{
719 u32 hcc_params = readl(&ehci_caps->hcc_params);
720 int offset = (hcc_params >> 8) & 0xff;
721 u32 cap;
722 int msec;
723
724 if (!offset)
725 return;
726
727 cap = read_pci_config(ehci_dev.bus, ehci_dev.slot,
728 ehci_dev.func, offset);
729 dbgp_printk("dbgp: ehci BIOS state %08x\n", cap);
730
731 if ((cap & 0xff) == 1 && (cap & EHCI_USBLEGSUP_BIOS)) {
732 dbgp_printk("dbgp: BIOS handoff\n");
733 write_pci_config_byte(ehci_dev.bus, ehci_dev.slot,
734 ehci_dev.func, offset + 3, 1);
735 }
736
737 /* if boot firmware now owns EHCI, spin till it hands it over. */
738 msec = 1000;
739 while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) {
740 mdelay(10);
741 msec -= 10;
742 cap = read_pci_config(ehci_dev.bus, ehci_dev.slot,
743 ehci_dev.func, offset);
744 }
745
746 if (cap & EHCI_USBLEGSUP_BIOS) {
747 /* well, possibly buggy BIOS... try to shut it down,
748 * and hope nothing goes too wrong */
749 dbgp_printk("dbgp: BIOS handoff failed: %08x\n", cap);
750 write_pci_config_byte(ehci_dev.bus, ehci_dev.slot,
751 ehci_dev.func, offset + 2, 0);
752 }
753
754 /* just in case, always disable EHCI SMIs */
755 write_pci_config_byte(ehci_dev.bus, ehci_dev.slot, ehci_dev.func,
756 offset + EHCI_USBLEGCTLSTS, 0);
757}
758
759static int __init ehci_setup(void)
760{
761 u32 ctrl, portsc, hcs_params;
762 u32 debug_port, new_debug_port = 0, n_ports;
763 int ret, i;
764 int port_map_tried;
765 int playtimes = 3;
766
767 early_ehci_bios_handoff();
768
769try_next_time:
770 port_map_tried = 0;
771
772try_next_port:
773
774 hcs_params = readl(&ehci_caps->hcs_params);
775 debug_port = HCS_DEBUG_PORT(hcs_params);
776 dbgp_phys_port = debug_port;
777 n_ports = HCS_N_PORTS(hcs_params);
778
779 dbgp_printk("debug_port: %d\n", debug_port);
780 dbgp_printk("n_ports: %d\n", n_ports);
781 dbgp_ehci_status("");
782
783 for (i = 1; i <= n_ports; i++) {
784 portsc = readl(&ehci_regs->port_status[i-1]);
785 dbgp_printk("portstatus%d: %08x\n", i, portsc);
786 }
787
788 if (port_map_tried && (new_debug_port != debug_port)) {
789 if (--playtimes) {
790 set_debug_port(new_debug_port);
791 goto try_next_time;
792 }
793 return -1;
794 }
795
796 /* Only reset the controller if it is not already in the
797 * configured state */
798 if (!(readl(&ehci_regs->configured_flag) & FLAG_CF)) {
799 if (dbgp_ehci_controller_reset() != 0)
800 return -1;
801 } else {
802 dbgp_ehci_status("ehci skip - already configured");
803 }
804
805 ret = dbgp_external_startup();
806 if (ret == -EIO)
807 goto next_debug_port;
808
809 if (ret < 0) {
810 /* Things didn't work so remove my claim */
811 ctrl = readl(&ehci_debug->control);
812 ctrl &= ~(DBGP_CLAIM | DBGP_OUT);
813 writel(ctrl, &ehci_debug->control);
814 return -1;
815 }
816 return 0;
817
818next_debug_port:
819 port_map_tried |= (1<<(debug_port - 1));
820 new_debug_port = ((debug_port-1+1)%n_ports) + 1;
821 if (port_map_tried != ((1<<n_ports) - 1)) {
822 set_debug_port(new_debug_port);
823 goto try_next_port;
824 }
825 if (--playtimes) {
826 set_debug_port(new_debug_port);
827 goto try_next_time;
828 }
829
830 return -1;
831}
832
833int __init early_dbgp_init(char *s)
834{
835 u32 debug_port, bar, offset;
836 u32 bus, slot, func, cap;
837 void __iomem *ehci_bar;
838 u32 dbgp_num;
839 u32 bar_val;
840 char *e;
841 int ret;
842 u8 byte;
843
844 if (!early_pci_allowed())
845 return -1;
846
847 dbgp_num = 0;
848 if (*s)
849 dbgp_num = simple_strtoul(s, &e, 10);
850 dbgp_printk("dbgp_num: %d\n", dbgp_num);
851
852 cap = find_dbgp(dbgp_num, &bus, &slot, &func);
853 if (!cap)
854 return -1;
855
856 dbgp_printk("Found EHCI debug port on %02x:%02x.%1x\n", bus, slot,
857 func);
858
859 debug_port = read_pci_config(bus, slot, func, cap);
860 bar = (debug_port >> 29) & 0x7;
861 bar = (bar * 4) + 0xc;
862 offset = (debug_port >> 16) & 0xfff;
863 dbgp_printk("bar: %02x offset: %03x\n", bar, offset);
864 if (bar != PCI_BASE_ADDRESS_0) {
865 dbgp_printk("only debug ports on bar 1 handled.\n");
866
867 return -1;
868 }
869
870 bar_val = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0);
871 dbgp_printk("bar_val: %02x offset: %03x\n", bar_val, offset);
872 if (bar_val & ~PCI_BASE_ADDRESS_MEM_MASK) {
873 dbgp_printk("only simple 32bit mmio bars supported\n");
874
875 return -1;
876 }
877
878 /* double check if the mem space is enabled */
879 byte = read_pci_config_byte(bus, slot, func, 0x04);
880 if (!(byte & 0x2)) {
881 byte |= 0x02;
882 write_pci_config_byte(bus, slot, func, 0x04, byte);
883 dbgp_printk("mmio for ehci enabled\n");
884 }
885
886 /*
887 * FIXME I don't have the bar size so just guess PAGE_SIZE is more
888 * than enough. 1K is the biggest I have seen.
889 */
890 set_fixmap_nocache(FIX_DBGP_BASE, bar_val & PAGE_MASK);
891 ehci_bar = (void __iomem *)__fix_to_virt(FIX_DBGP_BASE);
892 ehci_bar += bar_val & ~PAGE_MASK;
893 dbgp_printk("ehci_bar: %p\n", ehci_bar);
894
895 ehci_caps = ehci_bar;
896 ehci_regs = ehci_bar + HC_LENGTH(readl(&ehci_caps->hc_capbase));
897 ehci_debug = ehci_bar + offset;
898 ehci_dev.bus = bus;
899 ehci_dev.slot = slot;
900 ehci_dev.func = func;
901
902 detect_set_debug_port();
903
904 ret = ehci_setup();
905 if (ret < 0) {
906 dbgp_printk("ehci_setup failed\n");
907 ehci_debug = NULL;
908
909 return -1;
910 }
911 dbgp_ehci_status("early_init_complete");
912
913 return 0;
914}
915
916static void early_dbgp_write(struct console *con, const char *str, u32 n)
917{
918 int chunk, ret;
919 char buf[DBGP_MAX_PACKET];
920 int use_cr = 0;
921 u32 cmd, ctrl;
922 int reset_run = 0;
923
924 if (!ehci_debug || dbgp_not_safe)
925 return;
926
927 cmd = readl(&ehci_regs->command);
928 if (unlikely(!(cmd & CMD_RUN))) {
929 /* If the ehci controller is not in the run state do extended
930 * checks to see if the acpi or some other initialization also
931 * reset the ehci debug port */
932 ctrl = readl(&ehci_debug->control);
933 if (!(ctrl & DBGP_ENABLED)) {
934 dbgp_not_safe = 1;
935 dbgp_external_startup();
936 } else {
937 cmd |= CMD_RUN;
938 writel(cmd, &ehci_regs->command);
939 reset_run = 1;
940 }
941 }
942 while (n > 0) {
943 for (chunk = 0; chunk < DBGP_MAX_PACKET && n > 0;
944 str++, chunk++, n--) {
945 if (!use_cr && *str == '\n') {
946 use_cr = 1;
947 buf[chunk] = '\r';
948 str--;
949 n++;
950 continue;
951 }
952 if (use_cr)
953 use_cr = 0;
954 buf[chunk] = *str;
955 }
956 if (chunk > 0) {
957 ret = dbgp_bulk_write(USB_DEBUG_DEVNUM,
958 dbgp_endpoint_out, buf, chunk);
959 }
960 }
961 if (unlikely(reset_run)) {
962 cmd = readl(&ehci_regs->command);
963 cmd &= ~CMD_RUN;
964 writel(cmd, &ehci_regs->command);
965 }
966}
967
968struct console early_dbgp_console = {
969 .name = "earlydbg",
970 .write = early_dbgp_write,
971 .flags = CON_PRINTBUFFER,
972 .index = -1,
973};
974
975int dbgp_reset_prep(void)
976{
977 u32 ctrl;
978
979 dbgp_not_safe = 1;
980 if (!ehci_debug)
981 return 0;
982
983 if (early_dbgp_console.index != -1 &&
984 !(early_dbgp_console.flags & CON_BOOT))
985 return 1;
986 /* This means the console is not initialized, or should get
987 * shutdown so as to allow for reuse of the usb device, which
988 * means it is time to shutdown the usb debug port. */
989 ctrl = readl(&ehci_debug->control);
990 if (ctrl & DBGP_ENABLED) {
991 ctrl &= ~(DBGP_CLAIM);
992 writel(ctrl, &ehci_debug->control);
993 }
994 return 0;
995}
996EXPORT_SYMBOL_GPL(dbgp_reset_prep);
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 9f986b417c5b..33351312327f 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -124,7 +124,7 @@ choice
124 124
125config USB_GADGET_AT91 125config USB_GADGET_AT91
126 boolean "Atmel AT91 USB Device Port" 126 boolean "Atmel AT91 USB Device Port"
127 depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 127 depends on ARCH_AT91 && !ARCH_AT91SAM9RL && !ARCH_AT91CAP9 && !ARCH_AT91SAM9G45
128 select USB_GADGET_SELECTED 128 select USB_GADGET_SELECTED
129 help 129 help
130 Many Atmel AT91 processors (such as the AT91RM2000) have a 130 Many Atmel AT91 processors (such as the AT91RM2000) have a
@@ -143,7 +143,7 @@ config USB_AT91
143config USB_GADGET_ATMEL_USBA 143config USB_GADGET_ATMEL_USBA
144 boolean "Atmel USBA" 144 boolean "Atmel USBA"
145 select USB_GADGET_DUALSPEED 145 select USB_GADGET_DUALSPEED
146 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL 146 depends on AVR32 || ARCH_AT91CAP9 || ARCH_AT91SAM9RL || ARCH_AT91SAM9G45
147 help 147 help
148 USBA is the integrated high-speed USB Device controller on 148 USBA is the integrated high-speed USB Device controller on
149 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. 149 the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel.
@@ -627,9 +627,10 @@ config USB_AUDIO
627config USB_ETH 627config USB_ETH
628 tristate "Ethernet Gadget (with CDC Ethernet support)" 628 tristate "Ethernet Gadget (with CDC Ethernet support)"
629 depends on NET 629 depends on NET
630 select CRC32
630 help 631 help
631 This driver implements Ethernet style communication, in either 632 This driver implements Ethernet style communication, in one of
632 of two ways: 633 several ways:
633 634
634 - The "Communication Device Class" (CDC) Ethernet Control Model. 635 - The "Communication Device Class" (CDC) Ethernet Control Model.
635 That protocol is often avoided with pure Ethernet adapters, in 636 That protocol is often avoided with pure Ethernet adapters, in
@@ -639,7 +640,11 @@ config USB_ETH
639 - On hardware can't implement that protocol, a simple CDC subset 640 - On hardware can't implement that protocol, a simple CDC subset
640 is used, placing fewer demands on USB. 641 is used, placing fewer demands on USB.
641 642
642 RNDIS support is a third option, more demanding than that subset. 643 - CDC Ethernet Emulation Model (EEM) is a newer standard that has
644 a simpler interface that can be used by more USB hardware.
645
646 RNDIS support is an additional option, more demanding than than
647 subset.
643 648
644 Within the USB device, this gadget driver exposes a network device 649 Within the USB device, this gadget driver exposes a network device
645 "usbX", where X depends on what other networking devices you have. 650 "usbX", where X depends on what other networking devices you have.
@@ -672,6 +677,22 @@ config USB_ETH_RNDIS
672 XP, you'll need to download drivers from Microsoft's website; a URL 677 XP, you'll need to download drivers from Microsoft's website; a URL
673 is given in comments found in that info file. 678 is given in comments found in that info file.
674 679
680config USB_ETH_EEM
681 bool "Ethernet Emulation Model (EEM) support"
682 depends on USB_ETH
683 default n
684 help
685 CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM
686 and therefore can be supported by more hardware. Technically ECM and
687 EEM are designed for different applications. The ECM model extends
688 the network interface to the target (e.g. a USB cable modem), and the
689 EEM model is for mobile devices to communicate with hosts using
690 ethernet over USB. For Linux gadgets, however, the interface with
691 the host is the same (a usbX device), so the differences are minimal.
692
693 If you say "y" here, the Ethernet gadget driver will use the EEM
694 protocol rather than ECM. If unsure, say "n".
695
675config USB_GADGETFS 696config USB_GADGETFS
676 tristate "Gadget Filesystem (EXPERIMENTAL)" 697 tristate "Gadget Filesystem (EXPERIMENTAL)"
677 depends on EXPERIMENTAL 698 depends on EXPERIMENTAL
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 77352ccc245e..d5b65962dd36 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -2378,40 +2378,34 @@ static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2378 if (!ep->cancel_transfer && !list_empty(&ep->queue)) { 2378 if (!ep->cancel_transfer && !list_empty(&ep->queue)) {
2379 req = list_entry(ep->queue.next, 2379 req = list_entry(ep->queue.next,
2380 struct udc_request, queue); 2380 struct udc_request, queue);
2381 if (req) { 2381 /*
2382 /* 2382 * length bytes transfered
2383 * length bytes transfered 2383 * check dma done of last desc. in PPBDU mode
2384 * check dma done of last desc. in PPBDU mode 2384 */
2385 */ 2385 if (use_dma_ppb_du) {
2386 if (use_dma_ppb_du) { 2386 td = udc_get_last_dma_desc(req);
2387 td = udc_get_last_dma_desc(req); 2387 if (td) {
2388 if (td) { 2388 dma_done =
2389 dma_done = 2389 AMD_GETBITS(td->status,
2390 AMD_GETBITS(td->status, 2390 UDC_DMA_IN_STS_BS);
2391 UDC_DMA_IN_STS_BS); 2391 /* don't care DMA done */
2392 /* don't care DMA done */
2393 req->req.actual =
2394 req->req.length;
2395 }
2396 } else {
2397 /* assume all bytes transferred */
2398 req->req.actual = req->req.length; 2392 req->req.actual = req->req.length;
2399 } 2393 }
2394 } else {
2395 /* assume all bytes transferred */
2396 req->req.actual = req->req.length;
2397 }
2400 2398
2401 if (req->req.actual == req->req.length) { 2399 if (req->req.actual == req->req.length) {
2402 /* complete req */ 2400 /* complete req */
2403 complete_req(ep, req, 0); 2401 complete_req(ep, req, 0);
2404 req->dma_going = 0; 2402 req->dma_going = 0;
2405 /* further request available ? */ 2403 /* further request available ? */
2406 if (list_empty(&ep->queue)) { 2404 if (list_empty(&ep->queue)) {
2407 /* disable interrupt */ 2405 /* disable interrupt */
2408 tmp = readl( 2406 tmp = readl(&dev->regs->ep_irqmsk);
2409 &dev->regs->ep_irqmsk); 2407 tmp |= AMD_BIT(ep->num);
2410 tmp |= AMD_BIT(ep->num); 2408 writel(tmp, &dev->regs->ep_irqmsk);
2411 writel(tmp,
2412 &dev->regs->ep_irqmsk);
2413 }
2414
2415 } 2409 }
2416 } 2410 }
2417 } 2411 }
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 72bae8f39d81..66450a1abc22 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1754,7 +1754,6 @@ static int __init at91udc_probe(struct platform_device *pdev)
1754 IRQF_DISABLED, driver_name, udc)) { 1754 IRQF_DISABLED, driver_name, udc)) {
1755 DBG("request vbus irq %d failed\n", 1755 DBG("request vbus irq %d failed\n",
1756 udc->board.vbus_pin); 1756 udc->board.vbus_pin);
1757 free_irq(udc->udp_irq, udc);
1758 retval = -EBUSY; 1757 retval = -EBUSY;
1759 goto fail3; 1758 goto fail3;
1760 } 1759 }
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index 9f80f4e970bd..a3a0f4a27ef0 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -106,20 +106,20 @@ static int audio_set_endpoint_req(struct usb_configuration *c,
106 ctrl->bRequest, w_value, len, ep); 106 ctrl->bRequest, w_value, len, ep);
107 107
108 switch (ctrl->bRequest) { 108 switch (ctrl->bRequest) {
109 case SET_CUR: 109 case UAC_SET_CUR:
110 value = 0; 110 value = 0;
111 break; 111 break;
112 112
113 case SET_MIN: 113 case UAC_SET_MIN:
114 break; 114 break;
115 115
116 case SET_MAX: 116 case UAC_SET_MAX:
117 break; 117 break;
118 118
119 case SET_RES: 119 case UAC_SET_RES:
120 break; 120 break;
121 121
122 case SET_MEM: 122 case UAC_SET_MEM:
123 break; 123 break;
124 124
125 default: 125 default:
@@ -142,13 +142,13 @@ static int audio_get_endpoint_req(struct usb_configuration *c,
142 ctrl->bRequest, w_value, len, ep); 142 ctrl->bRequest, w_value, len, ep);
143 143
144 switch (ctrl->bRequest) { 144 switch (ctrl->bRequest) {
145 case GET_CUR: 145 case UAC_GET_CUR:
146 case GET_MIN: 146 case UAC_GET_MIN:
147 case GET_MAX: 147 case UAC_GET_MAX:
148 case GET_RES: 148 case UAC_GET_RES:
149 value = 3; 149 value = 3;
150 break; 150 break;
151 case GET_MEM: 151 case UAC_GET_MEM:
152 break; 152 break;
153 default: 153 default:
154 break; 154 break;
@@ -171,11 +171,11 @@ audio_setup(struct usb_configuration *c, const struct usb_ctrlrequest *ctrl)
171 * Audio class messages; interface activation uses set_alt(). 171 * Audio class messages; interface activation uses set_alt().
172 */ 172 */
173 switch (ctrl->bRequestType) { 173 switch (ctrl->bRequestType) {
174 case USB_AUDIO_SET_ENDPOINT: 174 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
175 value = audio_set_endpoint_req(c, ctrl); 175 value = audio_set_endpoint_req(c, ctrl);
176 break; 176 break;
177 177
178 case USB_AUDIO_GET_ENDPOINT: 178 case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
179 value = audio_get_endpoint_req(c, ctrl); 179 value = audio_get_endpoint_req(c, ctrl);
180 break; 180 break;
181 181
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 59e85234fa0a..d05397ec8a18 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -602,7 +602,7 @@ static int get_string(struct usb_composite_dev *cdev,
602 } 602 }
603 } 603 }
604 604
605 for (len = 0; s->wData[len] && len <= 126; len++) 605 for (len = 0; len <= 126 && s->wData[len]; len++)
606 continue; 606 continue;
607 if (!len) 607 if (!len)
608 return -EINVAL; 608 return -EINVAL;
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index a56b24d305f8..5e0966485188 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1306,11 +1306,6 @@ restart:
1306 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1306 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1307 w_index = le16_to_cpu(setup.wIndex); 1307 w_index = le16_to_cpu(setup.wIndex);
1308 w_value = le16_to_cpu(setup.wValue); 1308 w_value = le16_to_cpu(setup.wValue);
1309 if (le16_to_cpu(setup.wLength) !=
1310 urb->transfer_buffer_length) {
1311 status = -EOVERFLOW;
1312 goto return_urb;
1313 }
1314 1309
1315 /* paranoia, in case of stale queued data */ 1310 /* paranoia, in case of stale queued data */
1316 list_for_each_entry (req, &ep->queue, queue) { 1311 list_for_each_entry (req, &ep->queue, queue) {
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index bd102f5052ba..f37de283d0ab 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -61,6 +61,11 @@
61 * simpler, Microsoft pushes their own approach: RNDIS. The published 61 * simpler, Microsoft pushes their own approach: RNDIS. The published
62 * RNDIS specs are ambiguous and appear to be incomplete, and are also 62 * RNDIS specs are ambiguous and appear to be incomplete, and are also
63 * needlessly complex. They borrow more from CDC ACM than CDC ECM. 63 * needlessly complex. They borrow more from CDC ACM than CDC ECM.
64 *
65 * While CDC ECM, CDC Subset, and RNDIS are designed to extend the ethernet
66 * interface to the target, CDC EEM was designed to use ethernet over the USB
67 * link between the host and target. CDC EEM is implemented as an alternative
68 * to those other protocols when that communication model is more appropriate
64 */ 69 */
65 70
66#define DRIVER_DESC "Ethernet Gadget" 71#define DRIVER_DESC "Ethernet Gadget"
@@ -114,6 +119,7 @@ static inline bool has_rndis(void)
114#include "f_rndis.c" 119#include "f_rndis.c"
115#include "rndis.c" 120#include "rndis.c"
116#endif 121#endif
122#include "f_eem.c"
117#include "u_ether.c" 123#include "u_ether.c"
118 124
119/*-------------------------------------------------------------------------*/ 125/*-------------------------------------------------------------------------*/
@@ -150,6 +156,10 @@ static inline bool has_rndis(void)
150#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ 156#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
151#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ 157#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
152 158
159/* For EEM gadgets */
160#define EEM_VENDOR_NUM 0x0525 /* INVALID - NEEDS TO BE ALLOCATED */
161#define EEM_PRODUCT_NUM 0xa4a1 /* INVALID - NEEDS TO BE ALLOCATED */
162
153/*-------------------------------------------------------------------------*/ 163/*-------------------------------------------------------------------------*/
154 164
155static struct usb_device_descriptor device_desc = { 165static struct usb_device_descriptor device_desc = {
@@ -246,8 +256,16 @@ static struct usb_configuration rndis_config_driver = {
246 256
247/*-------------------------------------------------------------------------*/ 257/*-------------------------------------------------------------------------*/
248 258
259#ifdef CONFIG_USB_ETH_EEM
260static int use_eem = 1;
261#else
262static int use_eem;
263#endif
264module_param(use_eem, bool, 0);
265MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
266
249/* 267/*
250 * We _always_ have an ECM or CDC Subset configuration. 268 * We _always_ have an ECM, CDC Subset, or EEM configuration.
251 */ 269 */
252static int __init eth_do_config(struct usb_configuration *c) 270static int __init eth_do_config(struct usb_configuration *c)
253{ 271{
@@ -258,7 +276,9 @@ static int __init eth_do_config(struct usb_configuration *c)
258 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 276 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
259 } 277 }
260 278
261 if (can_support_ecm(c->cdev->gadget)) 279 if (use_eem)
280 return eem_bind_config(c);
281 else if (can_support_ecm(c->cdev->gadget))
262 return ecm_bind_config(c, hostaddr); 282 return ecm_bind_config(c, hostaddr);
263 else 283 else
264 return geth_bind_config(c, hostaddr); 284 return geth_bind_config(c, hostaddr);
@@ -286,7 +306,12 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
286 return status; 306 return status;
287 307
288 /* set up main config label and device descriptor */ 308 /* set up main config label and device descriptor */
289 if (can_support_ecm(cdev->gadget)) { 309 if (use_eem) {
310 /* EEM */
311 eth_config_driver.label = "CDC Ethernet (EEM)";
312 device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
313 device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
314 } else if (can_support_ecm(cdev->gadget)) {
290 /* ECM */ 315 /* ECM */
291 eth_config_driver.label = "CDC Ethernet (ECM)"; 316 eth_config_driver.label = "CDC Ethernet (ECM)";
292 } else { 317 } else {
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
index 66527ba2d2ea..98e9bb977291 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_audio.c
@@ -28,6 +28,9 @@ static int audio_buf_size = 48000;
28module_param(audio_buf_size, int, S_IRUGO); 28module_param(audio_buf_size, int, S_IRUGO);
29MODULE_PARM_DESC(audio_buf_size, "Audio buffer size"); 29MODULE_PARM_DESC(audio_buf_size, "Audio buffer size");
30 30
31static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value);
32static int generic_get_cmd(struct usb_audio_control *con, u8 cmd);
33
31/* 34/*
32 * DESCRIPTORS ... most are static, but strings and full 35 * DESCRIPTORS ... most are static, but strings and full
33 * configuration descriptors are built on demand. 36 * configuration descriptors are built on demand.
@@ -50,16 +53,16 @@ static struct usb_interface_descriptor ac_interface_desc __initdata = {
50 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, 53 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
51}; 54};
52 55
53DECLARE_USB_AC_HEADER_DESCRIPTOR(2); 56DECLARE_UAC_AC_HEADER_DESCRIPTOR(2);
54 57
55#define USB_DT_AC_HEADER_LENGH USB_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) 58#define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES)
56/* B.3.2 Class-Specific AC Interface Descriptor */ 59/* B.3.2 Class-Specific AC Interface Descriptor */
57static struct usb_ac_header_descriptor_2 ac_header_desc = { 60static struct uac_ac_header_descriptor_2 ac_header_desc = {
58 .bLength = USB_DT_AC_HEADER_LENGH, 61 .bLength = UAC_DT_AC_HEADER_LENGTH,
59 .bDescriptorType = USB_DT_CS_INTERFACE, 62 .bDescriptorType = USB_DT_CS_INTERFACE,
60 .bDescriptorSubtype = HEADER, 63 .bDescriptorSubtype = UAC_HEADER,
61 .bcdADC = __constant_cpu_to_le16(0x0100), 64 .bcdADC = __constant_cpu_to_le16(0x0100),
62 .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_LENGH), 65 .wTotalLength = __constant_cpu_to_le16(UAC_DT_AC_HEADER_LENGTH),
63 .bInCollection = F_AUDIO_NUM_INTERFACES, 66 .bInCollection = F_AUDIO_NUM_INTERFACES,
64 .baInterfaceNr = { 67 .baInterfaceNr = {
65 [0] = F_AUDIO_AC_INTERFACE, 68 [0] = F_AUDIO_AC_INTERFACE,
@@ -68,33 +71,33 @@ static struct usb_ac_header_descriptor_2 ac_header_desc = {
68}; 71};
69 72
70#define INPUT_TERMINAL_ID 1 73#define INPUT_TERMINAL_ID 1
71static struct usb_input_terminal_descriptor input_terminal_desc = { 74static struct uac_input_terminal_descriptor input_terminal_desc = {
72 .bLength = USB_DT_AC_INPUT_TERMINAL_SIZE, 75 .bLength = UAC_DT_INPUT_TERMINAL_SIZE,
73 .bDescriptorType = USB_DT_CS_INTERFACE, 76 .bDescriptorType = USB_DT_CS_INTERFACE,
74 .bDescriptorSubtype = INPUT_TERMINAL, 77 .bDescriptorSubtype = UAC_INPUT_TERMINAL,
75 .bTerminalID = INPUT_TERMINAL_ID, 78 .bTerminalID = INPUT_TERMINAL_ID,
76 .wTerminalType = USB_AC_TERMINAL_STREAMING, 79 .wTerminalType = UAC_TERMINAL_STREAMING,
77 .bAssocTerminal = 0, 80 .bAssocTerminal = 0,
78 .wChannelConfig = 0x3, 81 .wChannelConfig = 0x3,
79}; 82};
80 83
81DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(0); 84DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(0);
82 85
83#define FEATURE_UNIT_ID 2 86#define FEATURE_UNIT_ID 2
84static struct usb_ac_feature_unit_descriptor_0 feature_unit_desc = { 87static struct uac_feature_unit_descriptor_0 feature_unit_desc = {
85 .bLength = USB_DT_AC_FEATURE_UNIT_SIZE(0), 88 .bLength = UAC_DT_FEATURE_UNIT_SIZE(0),
86 .bDescriptorType = USB_DT_CS_INTERFACE, 89 .bDescriptorType = USB_DT_CS_INTERFACE,
87 .bDescriptorSubtype = FEATURE_UNIT, 90 .bDescriptorSubtype = UAC_FEATURE_UNIT,
88 .bUnitID = FEATURE_UNIT_ID, 91 .bUnitID = FEATURE_UNIT_ID,
89 .bSourceID = INPUT_TERMINAL_ID, 92 .bSourceID = INPUT_TERMINAL_ID,
90 .bControlSize = 2, 93 .bControlSize = 2,
91 .bmaControls[0] = (FU_MUTE | FU_VOLUME), 94 .bmaControls[0] = (UAC_FU_MUTE | UAC_FU_VOLUME),
92}; 95};
93 96
94static struct usb_audio_control mute_control = { 97static struct usb_audio_control mute_control = {
95 .list = LIST_HEAD_INIT(mute_control.list), 98 .list = LIST_HEAD_INIT(mute_control.list),
96 .name = "Mute Control", 99 .name = "Mute Control",
97 .type = MUTE_CONTROL, 100 .type = UAC_MUTE_CONTROL,
98 /* Todo: add real Mute control code */ 101 /* Todo: add real Mute control code */
99 .set = generic_set_cmd, 102 .set = generic_set_cmd,
100 .get = generic_get_cmd, 103 .get = generic_get_cmd,
@@ -103,7 +106,7 @@ static struct usb_audio_control mute_control = {
103static struct usb_audio_control volume_control = { 106static struct usb_audio_control volume_control = {
104 .list = LIST_HEAD_INIT(volume_control.list), 107 .list = LIST_HEAD_INIT(volume_control.list),
105 .name = "Volume Control", 108 .name = "Volume Control",
106 .type = VOLUME_CONTROL, 109 .type = UAC_VOLUME_CONTROL,
107 /* Todo: add real Volume control code */ 110 /* Todo: add real Volume control code */
108 .set = generic_set_cmd, 111 .set = generic_set_cmd,
109 .get = generic_get_cmd, 112 .get = generic_get_cmd,
@@ -113,17 +116,17 @@ static struct usb_audio_control_selector feature_unit = {
113 .list = LIST_HEAD_INIT(feature_unit.list), 116 .list = LIST_HEAD_INIT(feature_unit.list),
114 .id = FEATURE_UNIT_ID, 117 .id = FEATURE_UNIT_ID,
115 .name = "Mute & Volume Control", 118 .name = "Mute & Volume Control",
116 .type = FEATURE_UNIT, 119 .type = UAC_FEATURE_UNIT,
117 .desc = (struct usb_descriptor_header *)&feature_unit_desc, 120 .desc = (struct usb_descriptor_header *)&feature_unit_desc,
118}; 121};
119 122
120#define OUTPUT_TERMINAL_ID 3 123#define OUTPUT_TERMINAL_ID 3
121static struct usb_output_terminal_descriptor output_terminal_desc = { 124static struct uac_output_terminal_descriptor output_terminal_desc = {
122 .bLength = USB_DT_AC_OUTPUT_TERMINAL_SIZE, 125 .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE,
123 .bDescriptorType = USB_DT_CS_INTERFACE, 126 .bDescriptorType = USB_DT_CS_INTERFACE,
124 .bDescriptorSubtype = OUTPUT_TERMINAL, 127 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
125 .bTerminalID = OUTPUT_TERMINAL_ID, 128 .bTerminalID = OUTPUT_TERMINAL_ID,
126 .wTerminalType = USB_AC_OUTPUT_TERMINAL_SPEAKER, 129 .wTerminalType = UAC_OUTPUT_TERMINAL_SPEAKER,
127 .bAssocTerminal = FEATURE_UNIT_ID, 130 .bAssocTerminal = FEATURE_UNIT_ID,
128 .bSourceID = FEATURE_UNIT_ID, 131 .bSourceID = FEATURE_UNIT_ID,
129}; 132};
@@ -148,22 +151,22 @@ static struct usb_interface_descriptor as_interface_alt_1_desc = {
148}; 151};
149 152
150/* B.4.2 Class-Specific AS Interface Descriptor */ 153/* B.4.2 Class-Specific AS Interface Descriptor */
151static struct usb_as_header_descriptor as_header_desc = { 154static struct uac_as_header_descriptor as_header_desc = {
152 .bLength = USB_DT_AS_HEADER_SIZE, 155 .bLength = UAC_DT_AS_HEADER_SIZE,
153 .bDescriptorType = USB_DT_CS_INTERFACE, 156 .bDescriptorType = USB_DT_CS_INTERFACE,
154 .bDescriptorSubtype = AS_GENERAL, 157 .bDescriptorSubtype = UAC_AS_GENERAL,
155 .bTerminalLink = INPUT_TERMINAL_ID, 158 .bTerminalLink = INPUT_TERMINAL_ID,
156 .bDelay = 1, 159 .bDelay = 1,
157 .wFormatTag = USB_AS_AUDIO_FORMAT_TYPE_I_PCM, 160 .wFormatTag = UAC_FORMAT_TYPE_I_PCM,
158}; 161};
159 162
160DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(1); 163DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(1);
161 164
162static struct usb_as_formate_type_i_discrete_descriptor_1 as_type_i_desc = { 165static struct uac_format_type_i_discrete_descriptor_1 as_type_i_desc = {
163 .bLength = USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1), 166 .bLength = UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1),
164 .bDescriptorType = USB_DT_CS_INTERFACE, 167 .bDescriptorType = USB_DT_CS_INTERFACE,
165 .bDescriptorSubtype = FORMAT_TYPE, 168 .bDescriptorSubtype = UAC_FORMAT_TYPE,
166 .bFormatType = USB_AS_FORMAT_TYPE_I, 169 .bFormatType = UAC_FORMAT_TYPE_I,
167 .bSubframeSize = 2, 170 .bSubframeSize = 2,
168 .bBitResolution = 16, 171 .bBitResolution = 16,
169 .bSamFreqType = 1, 172 .bSamFreqType = 1,
@@ -174,17 +177,17 @@ static struct usb_endpoint_descriptor as_out_ep_desc __initdata = {
174 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE, 177 .bLength = USB_DT_ENDPOINT_AUDIO_SIZE,
175 .bDescriptorType = USB_DT_ENDPOINT, 178 .bDescriptorType = USB_DT_ENDPOINT,
176 .bEndpointAddress = USB_DIR_OUT, 179 .bEndpointAddress = USB_DIR_OUT,
177 .bmAttributes = USB_AS_ENDPOINT_ADAPTIVE 180 .bmAttributes = USB_ENDPOINT_SYNC_ADAPTIVE
178 | USB_ENDPOINT_XFER_ISOC, 181 | USB_ENDPOINT_XFER_ISOC,
179 .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE), 182 .wMaxPacketSize = __constant_cpu_to_le16(OUT_EP_MAX_PACKET_SIZE),
180 .bInterval = 4, 183 .bInterval = 4,
181}; 184};
182 185
183/* Class-specific AS ISO OUT Endpoint Descriptor */ 186/* Class-specific AS ISO OUT Endpoint Descriptor */
184static struct usb_as_iso_endpoint_descriptor as_iso_out_desc __initdata = { 187static struct uac_iso_endpoint_descriptor as_iso_out_desc __initdata = {
185 .bLength = USB_AS_ISO_ENDPOINT_DESC_SIZE, 188 .bLength = UAC_ISO_ENDPOINT_DESC_SIZE,
186 .bDescriptorType = USB_DT_CS_ENDPOINT, 189 .bDescriptorType = USB_DT_CS_ENDPOINT,
187 .bDescriptorSubtype = EP_GENERAL, 190 .bDescriptorSubtype = UAC_EP_GENERAL,
188 .bmAttributes = 1, 191 .bmAttributes = 1,
189 .bLockDelayUnits = 1, 192 .bLockDelayUnits = 1,
190 .wLockDelay = __constant_cpu_to_le16(1), 193 .wLockDelay = __constant_cpu_to_le16(1),
@@ -456,11 +459,11 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
456 * Audio class messages; interface activation uses set_alt(). 459 * Audio class messages; interface activation uses set_alt().
457 */ 460 */
458 switch (ctrl->bRequestType) { 461 switch (ctrl->bRequestType) {
459 case USB_AUDIO_SET_INTF: 462 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE:
460 value = audio_set_intf_req(f, ctrl); 463 value = audio_set_intf_req(f, ctrl);
461 break; 464 break;
462 465
463 case USB_AUDIO_GET_INTF: 466 case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE:
464 value = audio_get_intf_req(f, ctrl); 467 value = audio_get_intf_req(f, ctrl);
465 break; 468 break;
466 469
@@ -632,6 +635,18 @@ f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
632 635
633/*-------------------------------------------------------------------------*/ 636/*-------------------------------------------------------------------------*/
634 637
638static int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
639{
640 con->data[cmd] = value;
641
642 return 0;
643}
644
645static int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
646{
647 return con->data[cmd];
648}
649
635/* Todo: add more control selecotor dynamically */ 650/* Todo: add more control selecotor dynamically */
636int __init control_selector_init(struct f_audio *audio) 651int __init control_selector_init(struct f_audio *audio)
637{ 652{
@@ -642,10 +657,10 @@ int __init control_selector_init(struct f_audio *audio)
642 list_add(&mute_control.list, &feature_unit.control); 657 list_add(&mute_control.list, &feature_unit.control);
643 list_add(&volume_control.list, &feature_unit.control); 658 list_add(&volume_control.list, &feature_unit.control);
644 659
645 volume_control.data[_CUR] = 0xffc0; 660 volume_control.data[UAC__CUR] = 0xffc0;
646 volume_control.data[_MIN] = 0xe3a0; 661 volume_control.data[UAC__MIN] = 0xe3a0;
647 volume_control.data[_MAX] = 0xfff0; 662 volume_control.data[UAC__MAX] = 0xfff0;
648 volume_control.data[_RES] = 0x0030; 663 volume_control.data[UAC__RES] = 0x0030;
649 664
650 return 0; 665 return 0;
651} 666}
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
new file mode 100644
index 000000000000..0a577d5694fd
--- /dev/null
+++ b/drivers/usb/gadget/f_eem.c
@@ -0,0 +1,562 @@
1/*
2 * f_eem.c -- USB CDC Ethernet (EEM) link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 * Copyright (C) 2009 EF Johnson Technologies
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/kernel.h>
24#include <linux/device.h>
25#include <linux/etherdevice.h>
26#include <linux/crc32.h>
27
28#include "u_ether.h"
29
30#define EEM_HLEN 2
31
32/*
33 * This function is a "CDC Ethernet Emulation Model" (CDC EEM)
34 * Ethernet link.
35 */
36
37struct eem_ep_descs {
38 struct usb_endpoint_descriptor *in;
39 struct usb_endpoint_descriptor *out;
40};
41
42struct f_eem {
43 struct gether port;
44 u8 ctrl_id;
45
46 struct eem_ep_descs fs;
47 struct eem_ep_descs hs;
48};
49
50static inline struct f_eem *func_to_eem(struct usb_function *f)
51{
52 return container_of(f, struct f_eem, port.func);
53}
54
55/*-------------------------------------------------------------------------*/
56
57/* interface descriptor: */
58
59static struct usb_interface_descriptor eem_intf __initdata = {
60 .bLength = sizeof eem_intf,
61 .bDescriptorType = USB_DT_INTERFACE,
62
63 /* .bInterfaceNumber = DYNAMIC */
64 .bNumEndpoints = 2,
65 .bInterfaceClass = USB_CLASS_COMM,
66 .bInterfaceSubClass = USB_CDC_SUBCLASS_EEM,
67 .bInterfaceProtocol = USB_CDC_PROTO_EEM,
68 /* .iInterface = DYNAMIC */
69};
70
71/* full speed support: */
72
73static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = {
74 .bLength = USB_DT_ENDPOINT_SIZE,
75 .bDescriptorType = USB_DT_ENDPOINT,
76
77 .bEndpointAddress = USB_DIR_IN,
78 .bmAttributes = USB_ENDPOINT_XFER_BULK,
79};
80
81static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = {
82 .bLength = USB_DT_ENDPOINT_SIZE,
83 .bDescriptorType = USB_DT_ENDPOINT,
84
85 .bEndpointAddress = USB_DIR_OUT,
86 .bmAttributes = USB_ENDPOINT_XFER_BULK,
87};
88
89static struct usb_descriptor_header *eem_fs_function[] __initdata = {
90 /* CDC EEM control descriptors */
91 (struct usb_descriptor_header *) &eem_intf,
92 (struct usb_descriptor_header *) &eem_fs_in_desc,
93 (struct usb_descriptor_header *) &eem_fs_out_desc,
94 NULL,
95};
96
97/* high speed support: */
98
99static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = {
100 .bLength = USB_DT_ENDPOINT_SIZE,
101 .bDescriptorType = USB_DT_ENDPOINT,
102
103 .bEndpointAddress = USB_DIR_IN,
104 .bmAttributes = USB_ENDPOINT_XFER_BULK,
105 .wMaxPacketSize = cpu_to_le16(512),
106};
107
108static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = {
109 .bLength = USB_DT_ENDPOINT_SIZE,
110 .bDescriptorType = USB_DT_ENDPOINT,
111
112 .bEndpointAddress = USB_DIR_OUT,
113 .bmAttributes = USB_ENDPOINT_XFER_BULK,
114 .wMaxPacketSize = cpu_to_le16(512),
115};
116
117static struct usb_descriptor_header *eem_hs_function[] __initdata = {
118 /* CDC EEM control descriptors */
119 (struct usb_descriptor_header *) &eem_intf,
120 (struct usb_descriptor_header *) &eem_hs_in_desc,
121 (struct usb_descriptor_header *) &eem_hs_out_desc,
122 NULL,
123};
124
125/* string descriptors: */
126
127static struct usb_string eem_string_defs[] = {
128 [0].s = "CDC Ethernet Emulation Model (EEM)",
129 { } /* end of list */
130};
131
132static struct usb_gadget_strings eem_string_table = {
133 .language = 0x0409, /* en-us */
134 .strings = eem_string_defs,
135};
136
137static struct usb_gadget_strings *eem_strings[] = {
138 &eem_string_table,
139 NULL,
140};
141
142/*-------------------------------------------------------------------------*/
143
144static int eem_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
145{
146 struct usb_composite_dev *cdev = f->config->cdev;
147 int value = -EOPNOTSUPP;
148 u16 w_index = le16_to_cpu(ctrl->wIndex);
149 u16 w_value = le16_to_cpu(ctrl->wValue);
150 u16 w_length = le16_to_cpu(ctrl->wLength);
151
152 DBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
153 ctrl->bRequestType, ctrl->bRequest,
154 w_value, w_index, w_length);
155
156 /* device either stalls (value < 0) or reports success */
157 return value;
158}
159
160
161static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
162{
163 struct f_eem *eem = func_to_eem(f);
164 struct usb_composite_dev *cdev = f->config->cdev;
165 struct net_device *net;
166
167 /* we know alt == 0, so this is an activation or a reset */
168 if (alt != 0)
169 goto fail;
170
171 if (intf == eem->ctrl_id) {
172
173 if (eem->port.in_ep->driver_data) {
174 DBG(cdev, "reset eem\n");
175 gether_disconnect(&eem->port);
176 }
177
178 if (!eem->port.in) {
179 DBG(cdev, "init eem\n");
180 eem->port.in = ep_choose(cdev->gadget,
181 eem->hs.in, eem->fs.in);
182 eem->port.out = ep_choose(cdev->gadget,
183 eem->hs.out, eem->fs.out);
184 }
185
186 /* zlps should not occur because zero-length EEM packets
187 * will be inserted in those cases where they would occur
188 */
189 eem->port.is_zlp_ok = 1;
190 eem->port.cdc_filter = DEFAULT_FILTER;
191 DBG(cdev, "activate eem\n");
192 net = gether_connect(&eem->port);
193 if (IS_ERR(net))
194 return PTR_ERR(net);
195 } else
196 goto fail;
197
198 return 0;
199fail:
200 return -EINVAL;
201}
202
203static void eem_disable(struct usb_function *f)
204{
205 struct f_eem *eem = func_to_eem(f);
206 struct usb_composite_dev *cdev = f->config->cdev;
207
208 DBG(cdev, "eem deactivated\n");
209
210 if (eem->port.in_ep->driver_data)
211 gether_disconnect(&eem->port);
212}
213
214/*-------------------------------------------------------------------------*/
215
216/* EEM function driver setup/binding */
217
218static int __init
219eem_bind(struct usb_configuration *c, struct usb_function *f)
220{
221 struct usb_composite_dev *cdev = c->cdev;
222 struct f_eem *eem = func_to_eem(f);
223 int status;
224 struct usb_ep *ep;
225
226 /* allocate instance-specific interface IDs */
227 status = usb_interface_id(c, f);
228 if (status < 0)
229 goto fail;
230 eem->ctrl_id = status;
231 eem_intf.bInterfaceNumber = status;
232
233 status = -ENODEV;
234
235 /* allocate instance-specific endpoints */
236 ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_in_desc);
237 if (!ep)
238 goto fail;
239 eem->port.in_ep = ep;
240 ep->driver_data = cdev; /* claim */
241
242 ep = usb_ep_autoconfig(cdev->gadget, &eem_fs_out_desc);
243 if (!ep)
244 goto fail;
245 eem->port.out_ep = ep;
246 ep->driver_data = cdev; /* claim */
247
248 status = -ENOMEM;
249
250 /* copy descriptors, and track endpoint copies */
251 f->descriptors = usb_copy_descriptors(eem_fs_function);
252 if (!f->descriptors)
253 goto fail;
254
255 eem->fs.in = usb_find_endpoint(eem_fs_function,
256 f->descriptors, &eem_fs_in_desc);
257 eem->fs.out = usb_find_endpoint(eem_fs_function,
258 f->descriptors, &eem_fs_out_desc);
259
260 /* support all relevant hardware speeds... we expect that when
261 * hardware is dual speed, all bulk-capable endpoints work at
262 * both speeds
263 */
264 if (gadget_is_dualspeed(c->cdev->gadget)) {
265 eem_hs_in_desc.bEndpointAddress =
266 eem_fs_in_desc.bEndpointAddress;
267 eem_hs_out_desc.bEndpointAddress =
268 eem_fs_out_desc.bEndpointAddress;
269
270 /* copy descriptors, and track endpoint copies */
271 f->hs_descriptors = usb_copy_descriptors(eem_hs_function);
272 if (!f->hs_descriptors)
273 goto fail;
274
275 eem->hs.in = usb_find_endpoint(eem_hs_function,
276 f->hs_descriptors, &eem_hs_in_desc);
277 eem->hs.out = usb_find_endpoint(eem_hs_function,
278 f->hs_descriptors, &eem_hs_out_desc);
279 }
280
281 DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n",
282 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
283 eem->port.in_ep->name, eem->port.out_ep->name);
284 return 0;
285
286fail:
287 if (f->descriptors)
288 usb_free_descriptors(f->descriptors);
289
290 /* we might as well release our claims on endpoints */
291 if (eem->port.out)
292 eem->port.out_ep->driver_data = NULL;
293 if (eem->port.in)
294 eem->port.in_ep->driver_data = NULL;
295
296 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
297
298 return status;
299}
300
301static void
302eem_unbind(struct usb_configuration *c, struct usb_function *f)
303{
304 struct f_eem *eem = func_to_eem(f);
305
306 DBG(c->cdev, "eem unbind\n");
307
308 if (gadget_is_dualspeed(c->cdev->gadget))
309 usb_free_descriptors(f->hs_descriptors);
310 usb_free_descriptors(f->descriptors);
311 kfree(eem);
312}
313
314static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req)
315{
316}
317
318/*
319 * Add the EEM header and ethernet checksum.
320 * We currently do not attempt to put multiple ethernet frames
321 * into a single USB transfer
322 */
323static struct sk_buff *eem_wrap(struct gether *port, struct sk_buff *skb)
324{
325 struct sk_buff *skb2 = NULL;
326 struct usb_ep *in = port->in_ep;
327 int padlen = 0;
328 u16 len = skb->len;
329
330 if (!skb_cloned(skb)) {
331 int headroom = skb_headroom(skb);
332 int tailroom = skb_tailroom(skb);
333
334 /* When (len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) is 0,
335 * stick two bytes of zero-length EEM packet on the end.
336 */
337 if (((len + EEM_HLEN + ETH_FCS_LEN) % in->maxpacket) == 0)
338 padlen += 2;
339
340 if ((tailroom >= (ETH_FCS_LEN + padlen)) &&
341 (headroom >= EEM_HLEN))
342 goto done;
343 }
344
345 skb2 = skb_copy_expand(skb, EEM_HLEN, ETH_FCS_LEN + padlen, GFP_ATOMIC);
346 dev_kfree_skb_any(skb);
347 skb = skb2;
348 if (!skb)
349 return skb;
350
351done:
352 /* use the "no CRC" option */
353 put_unaligned_be32(0xdeadbeef, skb_put(skb, 4));
354
355 /* EEM packet header format:
356 * b0..13: length of ethernet frame
357 * b14: bmCRC (0 == sentinel CRC)
358 * b15: bmType (0 == data)
359 */
360 len = skb->len;
361 put_unaligned_le16((len & 0x3FFF) | BIT(14), skb_push(skb, 2));
362
363 /* add a zero-length EEM packet, if needed */
364 if (padlen)
365 put_unaligned_le16(0, skb_put(skb, 2));
366
367 return skb;
368}
369
370/*
371 * Remove the EEM header. Note that there can be many EEM packets in a single
372 * USB transfer, so we need to break them out and handle them independently.
373 */
374static int eem_unwrap(struct gether *port,
375 struct sk_buff *skb,
376 struct sk_buff_head *list)
377{
378 struct usb_composite_dev *cdev = port->func.config->cdev;
379 int status = 0;
380
381 do {
382 struct sk_buff *skb2;
383 u16 header;
384 u16 len = 0;
385
386 if (skb->len < EEM_HLEN) {
387 status = -EINVAL;
388 DBG(cdev, "invalid EEM header\n");
389 goto error;
390 }
391
392 /* remove the EEM header */
393 header = get_unaligned_le16(skb->data);
394 skb_pull(skb, EEM_HLEN);
395
396 /* EEM packet header format:
397 * b0..14: EEM type dependent (data or command)
398 * b15: bmType (0 == data, 1 == command)
399 */
400 if (header & BIT(15)) {
401 struct usb_request *req = cdev->req;
402 u16 bmEEMCmd;
403
404 /* EEM command packet format:
405 * b0..10: bmEEMCmdParam
406 * b11..13: bmEEMCmd
407 * b14: reserved (must be zero)
408 * b15: bmType (1 == command)
409 */
410 if (header & BIT(14))
411 continue;
412
413 bmEEMCmd = (header >> 11) & 0x7;
414 switch (bmEEMCmd) {
415 case 0: /* echo */
416 len = header & 0x7FF;
417 if (skb->len < len) {
418 status = -EOVERFLOW;
419 goto error;
420 }
421
422 skb2 = skb_clone(skb, GFP_ATOMIC);
423 if (unlikely(!skb2)) {
424 DBG(cdev, "EEM echo response error\n");
425 goto next;
426 }
427 skb_trim(skb2, len);
428 put_unaligned_le16(BIT(15) | BIT(11) | len,
429 skb_push(skb2, 2));
430 skb_copy_bits(skb, 0, req->buf, skb->len);
431 req->length = skb->len;
432 req->complete = eem_cmd_complete;
433 req->zero = 1;
434 if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC))
435 DBG(cdev, "echo response queue fail\n");
436 break;
437
438 case 1: /* echo response */
439 case 2: /* suspend hint */
440 case 3: /* response hint */
441 case 4: /* response complete hint */
442 case 5: /* tickle */
443 default: /* reserved */
444 continue;
445 }
446 } else {
447 u32 crc, crc2;
448 struct sk_buff *skb3;
449
450 /* check for zero-length EEM packet */
451 if (header == 0)
452 continue;
453
454 /* EEM data packet format:
455 * b0..13: length of ethernet frame
456 * b14: bmCRC (0 == sentinel, 1 == calculated)
457 * b15: bmType (0 == data)
458 */
459 len = header & 0x3FFF;
460 if ((skb->len < len)
461 || (len < (ETH_HLEN + ETH_FCS_LEN))) {
462 status = -EINVAL;
463 goto error;
464 }
465
466 /* validate CRC */
467 crc = get_unaligned_le32(skb->data + len - ETH_FCS_LEN);
468 if (header & BIT(14)) {
469 crc = get_unaligned_le32(skb->data + len
470 - ETH_FCS_LEN);
471 crc2 = ~crc32_le(~0,
472 skb->data,
473 skb->len - ETH_FCS_LEN);
474 } else {
475 crc = get_unaligned_be32(skb->data + len
476 - ETH_FCS_LEN);
477 crc2 = 0xdeadbeef;
478 }
479 if (crc != crc2) {
480 DBG(cdev, "invalid EEM CRC\n");
481 goto next;
482 }
483
484 skb2 = skb_clone(skb, GFP_ATOMIC);
485 if (unlikely(!skb2)) {
486 DBG(cdev, "unable to unframe EEM packet\n");
487 continue;
488 }
489 skb_trim(skb2, len - ETH_FCS_LEN);
490
491 skb3 = skb_copy_expand(skb2,
492 NET_IP_ALIGN,
493 0,
494 GFP_ATOMIC);
495 if (unlikely(!skb3)) {
496 DBG(cdev, "unable to realign EEM packet\n");
497 dev_kfree_skb_any(skb2);
498 continue;
499 }
500 dev_kfree_skb_any(skb2);
501 skb_queue_tail(list, skb3);
502 }
503next:
504 skb_pull(skb, len);
505 } while (skb->len);
506
507error:
508 dev_kfree_skb_any(skb);
509 return status;
510}
511
512/**
513 * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration
514 * @c: the configuration to support the network link
515 * Context: single threaded during gadget setup
516 *
517 * Returns zero on success, else negative errno.
518 *
519 * Caller must have called @gether_setup(). Caller is also responsible
520 * for calling @gether_cleanup() before module unload.
521 */
522int __init eem_bind_config(struct usb_configuration *c)
523{
524 struct f_eem *eem;
525 int status;
526
527 /* maybe allocate device-global string IDs */
528 if (eem_string_defs[0].id == 0) {
529
530 /* control interface label */
531 status = usb_string_id(c->cdev);
532 if (status < 0)
533 return status;
534 eem_string_defs[0].id = status;
535 eem_intf.iInterface = status;
536 }
537
538 /* allocate and initialize one new instance */
539 eem = kzalloc(sizeof *eem, GFP_KERNEL);
540 if (!eem)
541 return -ENOMEM;
542
543 eem->port.cdc_filter = DEFAULT_FILTER;
544
545 eem->port.func.name = "cdc_eem";
546 eem->port.func.strings = eem_strings;
547 /* descriptors are per-instance copies */
548 eem->port.func.bind = eem_bind;
549 eem->port.func.unbind = eem_unbind;
550 eem->port.func.set_alt = eem_set_alt;
551 eem->port.func.setup = eem_setup;
552 eem->port.func.disable = eem_disable;
553 eem->port.wrap = eem_wrap;
554 eem->port.unwrap = eem_unwrap;
555 eem->port.header_len = EEM_HLEN;
556
557 status = usb_add_function(c, &eem->port.func);
558 if (status)
559 kfree(eem);
560 return status;
561}
562
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 424a37c5773f..c9966cc07d3a 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -286,12 +286,17 @@ static struct usb_gadget_strings *rndis_strings[] = {
286 286
287/*-------------------------------------------------------------------------*/ 287/*-------------------------------------------------------------------------*/
288 288
289static struct sk_buff *rndis_add_header(struct sk_buff *skb) 289static struct sk_buff *rndis_add_header(struct gether *port,
290 struct sk_buff *skb)
290{ 291{
291 skb = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type)); 292 struct sk_buff *skb2;
292 if (skb) 293
293 rndis_add_hdr(skb); 294 skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
294 return skb; 295 if (skb2)
296 rndis_add_hdr(skb2);
297
298 dev_kfree_skb_any(skb);
299 return skb2;
295} 300}
296 301
297static void rndis_response_available(void *_rndis) 302static void rndis_response_available(void *_rndis)
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index d701bf4698d2..7881f12413c4 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2751,6 +2751,10 @@ static int __devexit qe_udc_remove(struct of_device *ofdev)
2751/*-------------------------------------------------------------------------*/ 2751/*-------------------------------------------------------------------------*/
2752static struct of_device_id __devinitdata qe_udc_match[] = { 2752static struct of_device_id __devinitdata qe_udc_match[] = {
2753 { 2753 {
2754 .compatible = "fsl,mpc8323-qe-usb",
2755 .data = (void *)PORT_QE,
2756 },
2757 {
2754 .compatible = "fsl,mpc8360-qe-usb", 2758 .compatible = "fsl,mpc8360-qe-usb",
2755 .data = (void *)PORT_QE, 2759 .data = (void *)PORT_QE,
2756 }, 2760 },
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index b9312dc6e041..d0b1e836f0e0 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -191,7 +191,7 @@ module_param(qlen, uint, S_IRUGO);
191#define GMIDI_MS_INTERFACE 1 191#define GMIDI_MS_INTERFACE 1
192#define GMIDI_NUM_INTERFACES 2 192#define GMIDI_NUM_INTERFACES 2
193 193
194DECLARE_USB_AC_HEADER_DESCRIPTOR(1); 194DECLARE_UAC_AC_HEADER_DESCRIPTOR(1);
195DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1); 195DECLARE_USB_MIDI_OUT_JACK_DESCRIPTOR(1);
196DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1); 196DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1);
197 197
@@ -237,12 +237,12 @@ static const struct usb_interface_descriptor ac_interface_desc = {
237}; 237};
238 238
239/* B.3.2 Class-Specific AC Interface Descriptor */ 239/* B.3.2 Class-Specific AC Interface Descriptor */
240static const struct usb_ac_header_descriptor_1 ac_header_desc = { 240static const struct uac_ac_header_descriptor_1 ac_header_desc = {
241 .bLength = USB_DT_AC_HEADER_SIZE(1), 241 .bLength = UAC_DT_AC_HEADER_SIZE(1),
242 .bDescriptorType = USB_DT_CS_INTERFACE, 242 .bDescriptorType = USB_DT_CS_INTERFACE,
243 .bDescriptorSubtype = USB_MS_HEADER, 243 .bDescriptorSubtype = USB_MS_HEADER,
244 .bcdADC = cpu_to_le16(0x0100), 244 .bcdADC = cpu_to_le16(0x0100),
245 .wTotalLength = cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)), 245 .wTotalLength = cpu_to_le16(UAC_DT_AC_HEADER_SIZE(1)),
246 .bInCollection = 1, 246 .bInCollection = 1,
247 .baInterfaceNr = { 247 .baInterfaceNr = {
248 [0] = GMIDI_MS_INTERFACE, 248 [0] = GMIDI_MS_INTERFACE,
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index ed21e263f832..e6fedbd5a654 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -56,6 +56,7 @@
56 56
57#include <linux/usb/ch9.h> 57#include <linux/usb/ch9.h>
58#include <linux/usb/gadget.h> 58#include <linux/usb/gadget.h>
59#include <linux/usb/otg.h>
59 60
60/* 61/*
61 * This driver is PXA25x only. Grab the right register definitions. 62 * This driver is PXA25x only. Grab the right register definitions.
@@ -1008,15 +1009,27 @@ static int pxa25x_udc_pullup(struct usb_gadget *_gadget, int is_active)
1008 return 0; 1009 return 0;
1009} 1010}
1010 1011
1012/* boards may consume current from VBUS, up to 100-500mA based on config.
1013 * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs
1014 * violate USB specs.
1015 */
1016static int pxa25x_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1017{
1018 struct pxa25x_udc *udc;
1019
1020 udc = container_of(_gadget, struct pxa25x_udc, gadget);
1021
1022 if (udc->transceiver)
1023 return otg_set_power(udc->transceiver, mA);
1024 return -EOPNOTSUPP;
1025}
1026
1011static const struct usb_gadget_ops pxa25x_udc_ops = { 1027static const struct usb_gadget_ops pxa25x_udc_ops = {
1012 .get_frame = pxa25x_udc_get_frame, 1028 .get_frame = pxa25x_udc_get_frame,
1013 .wakeup = pxa25x_udc_wakeup, 1029 .wakeup = pxa25x_udc_wakeup,
1014 .vbus_session = pxa25x_udc_vbus_session, 1030 .vbus_session = pxa25x_udc_vbus_session,
1015 .pullup = pxa25x_udc_pullup, 1031 .pullup = pxa25x_udc_pullup,
1016 1032 .vbus_draw = pxa25x_udc_vbus_draw,
1017 // .vbus_draw ... boards may consume current from VBUS, up to
1018 // 100-500mA based on config. the 500uA suspend ceiling means
1019 // that exclusively vbus-powered PXA designs violate USB specs.
1020}; 1033};
1021 1034
1022/*-------------------------------------------------------------------------*/ 1035/*-------------------------------------------------------------------------*/
@@ -1303,9 +1316,23 @@ fail:
1303 * for set_configuration as well as eventual disconnect. 1316 * for set_configuration as well as eventual disconnect.
1304 */ 1317 */
1305 DMSG("registered gadget driver '%s'\n", driver->driver.name); 1318 DMSG("registered gadget driver '%s'\n", driver->driver.name);
1319
1320 /* connect to bus through transceiver */
1321 if (dev->transceiver) {
1322 retval = otg_set_peripheral(dev->transceiver, &dev->gadget);
1323 if (retval) {
1324 DMSG("can't bind to transceiver\n");
1325 if (driver->unbind)
1326 driver->unbind(&dev->gadget);
1327 goto bind_fail;
1328 }
1329 }
1330
1306 pullup(dev); 1331 pullup(dev);
1307 dump_state(dev); 1332 dump_state(dev);
1308 return 0; 1333 return 0;
1334bind_fail:
1335 return retval;
1309} 1336}
1310EXPORT_SYMBOL(usb_gadget_register_driver); 1337EXPORT_SYMBOL(usb_gadget_register_driver);
1311 1338
@@ -1351,6 +1378,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1351 stop_activity(dev, driver); 1378 stop_activity(dev, driver);
1352 local_irq_enable(); 1379 local_irq_enable();
1353 1380
1381 if (dev->transceiver)
1382 (void) otg_set_peripheral(dev->transceiver, NULL);
1383
1354 driver->unbind(&dev->gadget); 1384 driver->unbind(&dev->gadget);
1355 dev->gadget.dev.driver = NULL; 1385 dev->gadget.dev.driver = NULL;
1356 dev->driver = NULL; 1386 dev->driver = NULL;
@@ -2162,6 +2192,8 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2162 dev->dev = &pdev->dev; 2192 dev->dev = &pdev->dev;
2163 dev->mach = pdev->dev.platform_data; 2193 dev->mach = pdev->dev.platform_data;
2164 2194
2195 dev->transceiver = otg_get_transceiver();
2196
2165 if (gpio_is_valid(dev->mach->gpio_vbus)) { 2197 if (gpio_is_valid(dev->mach->gpio_vbus)) {
2166 if ((retval = gpio_request(dev->mach->gpio_vbus, 2198 if ((retval = gpio_request(dev->mach->gpio_vbus,
2167 "pxa25x_udc GPIO VBUS"))) { 2199 "pxa25x_udc GPIO VBUS"))) {
@@ -2264,6 +2296,10 @@ lubbock_fail0:
2264 if (gpio_is_valid(dev->mach->gpio_vbus)) 2296 if (gpio_is_valid(dev->mach->gpio_vbus))
2265 gpio_free(dev->mach->gpio_vbus); 2297 gpio_free(dev->mach->gpio_vbus);
2266 err_gpio_vbus: 2298 err_gpio_vbus:
2299 if (dev->transceiver) {
2300 otg_put_transceiver(dev->transceiver);
2301 dev->transceiver = NULL;
2302 }
2267 clk_put(dev->clk); 2303 clk_put(dev->clk);
2268 err_clk: 2304 err_clk:
2269 return retval; 2305 return retval;
@@ -2305,6 +2341,11 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2305 2341
2306 clk_put(dev->clk); 2342 clk_put(dev->clk);
2307 2343
2344 if (dev->transceiver) {
2345 otg_put_transceiver(dev->transceiver);
2346 dev->transceiver = NULL;
2347 }
2348
2308 platform_set_drvdata(pdev, NULL); 2349 platform_set_drvdata(pdev, NULL);
2309 the_controller = NULL; 2350 the_controller = NULL;
2310 return 0; 2351 return 0;
diff --git a/drivers/usb/gadget/pxa25x_udc.h b/drivers/usb/gadget/pxa25x_udc.h
index 1d51aa21e6eb..f572c5617462 100644
--- a/drivers/usb/gadget/pxa25x_udc.h
+++ b/drivers/usb/gadget/pxa25x_udc.h
@@ -128,6 +128,7 @@ struct pxa25x_udc {
128 struct device *dev; 128 struct device *dev;
129 struct clk *clk; 129 struct clk *clk;
130 struct pxa2xx_udc_mach_info *mach; 130 struct pxa2xx_udc_mach_info *mach;
131 struct otg_transceiver *transceiver;
131 u64 dma_mask; 132 u64 dma_mask;
132 struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS]; 133 struct pxa25x_ep ep [PXA_UDC_NUM_ENDPOINTS];
133 134
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index ca41b0b5afb3..48267bc0b2e0 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1022,22 +1022,29 @@ static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1022 return r; 1022 return r;
1023} 1023}
1024 1024
1025int rndis_rm_hdr(struct sk_buff *skb) 1025int rndis_rm_hdr(struct gether *port,
1026 struct sk_buff *skb,
1027 struct sk_buff_head *list)
1026{ 1028{
1027 /* tmp points to a struct rndis_packet_msg_type */ 1029 /* tmp points to a struct rndis_packet_msg_type */
1028 __le32 *tmp = (void *) skb->data; 1030 __le32 *tmp = (void *) skb->data;
1029 1031
1030 /* MessageType, MessageLength */ 1032 /* MessageType, MessageLength */
1031 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) 1033 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1032 != get_unaligned(tmp++)) 1034 != get_unaligned(tmp++)) {
1035 dev_kfree_skb_any(skb);
1033 return -EINVAL; 1036 return -EINVAL;
1037 }
1034 tmp++; 1038 tmp++;
1035 1039
1036 /* DataOffset, DataLength */ 1040 /* DataOffset, DataLength */
1037 if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) 1041 if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) {
1042 dev_kfree_skb_any(skb);
1038 return -EOVERFLOW; 1043 return -EOVERFLOW;
1044 }
1039 skb_trim(skb, get_unaligned_le32(tmp++)); 1045 skb_trim(skb, get_unaligned_le32(tmp++));
1040 1046
1047 skb_queue_tail(list, skb);
1041 return 0; 1048 return 0;
1042} 1049}
1043 1050
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index aac61dfe0f03..c236aaa9dcd1 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -251,7 +251,8 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID,
251 const char *vendorDescr); 251 const char *vendorDescr);
252int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); 252int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed);
253void rndis_add_hdr (struct sk_buff *skb); 253void rndis_add_hdr (struct sk_buff *skb);
254int rndis_rm_hdr (struct sk_buff *skb); 254int rndis_rm_hdr(struct gether *port, struct sk_buff *skb,
255 struct sk_buff_head *list);
255u8 *rndis_get_next_response (int configNr, u32 *length); 256u8 *rndis_get_next_response (int configNr, u32 *length);
256void rndis_free_response (int configNr, u8 *buf); 257void rndis_free_response (int configNr, u8 *buf);
257 258
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 50c71aae2cc2..4b5dbd0127f5 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -2392,7 +2392,7 @@ static int s3c_hsotg_corereset(struct s3c_hsotg *hsotg)
2392 grstctl = readl(hsotg->regs + S3C_GRSTCTL); 2392 grstctl = readl(hsotg->regs + S3C_GRSTCTL);
2393 } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0); 2393 } while (!(grstctl & S3C_GRSTCTL_CSftRst) && timeout-- > 0);
2394 2394
2395 if (!grstctl & S3C_GRSTCTL_CSftRst) { 2395 if (!(grstctl & S3C_GRSTCTL_CSftRst)) {
2396 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n"); 2396 dev_err(hsotg->dev, "Failed to get CSftRst asserted\n");
2397 return -EINVAL; 2397 return -EINVAL;
2398 } 2398 }
@@ -2514,8 +2514,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
2514 * DMA mode we may need this. */ 2514 * DMA mode we may need this. */
2515 writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk | 2515 writel(S3C_DOEPMSK_SetupMsk | S3C_DOEPMSK_AHBErrMsk |
2516 S3C_DOEPMSK_EPDisbldMsk | 2516 S3C_DOEPMSK_EPDisbldMsk |
2517 using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk | 2517 (using_dma(hsotg) ? (S3C_DIEPMSK_XferComplMsk |
2518 S3C_DIEPMSK_TimeOUTMsk) : 0, 2518 S3C_DIEPMSK_TimeOUTMsk) : 0),
2519 hsotg->regs + S3C_DOEPMSK); 2519 hsotg->regs + S3C_DOEPMSK);
2520 2520
2521 writel(0, hsotg->regs + S3C_DAINTMSK); 2521 writel(0, hsotg->regs + S3C_DAINTMSK);
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index a9b452fe6221..d5f4c1d45c97 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1703,8 +1703,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1703 dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n", 1703 dprintk(DEBUG_NORMAL,"usb_gadget_register_driver() '%s'\n",
1704 driver->driver.name); 1704 driver->driver.name);
1705 1705
1706 if (driver->disconnect) 1706 driver->unbind(&udc->gadget);
1707 driver->disconnect(&udc->gadget);
1708 1707
1709 device_del(&udc->gadget.dev); 1708 device_del(&udc->gadget.dev);
1710 udc->driver = NULL; 1709 udc->driver = NULL;
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_audio.c
index 0f3d22fc030e..b5200d551458 100644
--- a/drivers/usb/gadget/u_audio.c
+++ b/drivers/usb/gadget/u_audio.c
@@ -253,11 +253,13 @@ static int gaudio_open_snd_dev(struct gaudio *card)
253 snd->filp = filp_open(fn_cap, O_RDONLY, 0); 253 snd->filp = filp_open(fn_cap, O_RDONLY, 0);
254 if (IS_ERR(snd->filp)) { 254 if (IS_ERR(snd->filp)) {
255 ERROR(card, "No such PCM capture device: %s\n", fn_cap); 255 ERROR(card, "No such PCM capture device: %s\n", fn_cap);
256 snd->filp = NULL; 256 snd->substream = NULL;
257 snd->card = NULL;
258 } else {
259 pcm_file = snd->filp->private_data;
260 snd->substream = pcm_file->substream;
261 snd->card = card;
257 } 262 }
258 pcm_file = snd->filp->private_data;
259 snd->substream = pcm_file->substream;
260 snd->card = card;
261 263
262 return 0; 264 return 0;
263} 265}
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index c66521953917..f8751ff863cd 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -37,8 +37,9 @@
37 * one (!) network link through the USB gadget stack, normally "usb0". 37 * one (!) network link through the USB gadget stack, normally "usb0".
38 * 38 *
39 * The control and data models are handled by the function driver which 39 * The control and data models are handled by the function driver which
40 * connects to this code; such as CDC Ethernet, "CDC Subset", or RNDIS. 40 * connects to this code; such as CDC Ethernet (ECM or EEM),
41 * That includes all descriptor and endpoint management. 41 * "CDC Subset", or RNDIS. That includes all descriptor and endpoint
42 * management.
42 * 43 *
43 * Link level addressing is handled by this component using module 44 * Link level addressing is handled by this component using module
44 * parameters; if no such parameters are provided, random link level 45 * parameters; if no such parameters are provided, random link level
@@ -68,9 +69,13 @@ struct eth_dev {
68 struct list_head tx_reqs, rx_reqs; 69 struct list_head tx_reqs, rx_reqs;
69 atomic_t tx_qlen; 70 atomic_t tx_qlen;
70 71
72 struct sk_buff_head rx_frames;
73
71 unsigned header_len; 74 unsigned header_len;
72 struct sk_buff *(*wrap)(struct sk_buff *skb); 75 struct sk_buff *(*wrap)(struct gether *, struct sk_buff *skb);
73 int (*unwrap)(struct sk_buff *skb); 76 int (*unwrap)(struct gether *,
77 struct sk_buff *skb,
78 struct sk_buff_head *list);
74 79
75 struct work_struct work; 80 struct work_struct work;
76 81
@@ -269,7 +274,7 @@ enomem:
269 274
270static void rx_complete(struct usb_ep *ep, struct usb_request *req) 275static void rx_complete(struct usb_ep *ep, struct usb_request *req)
271{ 276{
272 struct sk_buff *skb = req->context; 277 struct sk_buff *skb = req->context, *skb2;
273 struct eth_dev *dev = ep->driver_data; 278 struct eth_dev *dev = ep->driver_data;
274 int status = req->status; 279 int status = req->status;
275 280
@@ -278,26 +283,47 @@ static void rx_complete(struct usb_ep *ep, struct usb_request *req)
278 /* normal completion */ 283 /* normal completion */
279 case 0: 284 case 0:
280 skb_put(skb, req->actual); 285 skb_put(skb, req->actual);
281 if (dev->unwrap)
282 status = dev->unwrap(skb);
283 if (status < 0
284 || ETH_HLEN > skb->len
285 || skb->len > ETH_FRAME_LEN) {
286 dev->net->stats.rx_errors++;
287 dev->net->stats.rx_length_errors++;
288 DBG(dev, "rx length %d\n", skb->len);
289 break;
290 }
291 286
292 skb->protocol = eth_type_trans(skb, dev->net); 287 if (dev->unwrap) {
293 dev->net->stats.rx_packets++; 288 unsigned long flags;
294 dev->net->stats.rx_bytes += skb->len;
295 289
296 /* no buffer copies needed, unless hardware can't 290 spin_lock_irqsave(&dev->lock, flags);
297 * use skb buffers. 291 if (dev->port_usb) {
298 */ 292 status = dev->unwrap(dev->port_usb,
299 status = netif_rx(skb); 293 skb,
294 &dev->rx_frames);
295 } else {
296 dev_kfree_skb_any(skb);
297 status = -ENOTCONN;
298 }
299 spin_unlock_irqrestore(&dev->lock, flags);
300 } else {
301 skb_queue_tail(&dev->rx_frames, skb);
302 }
300 skb = NULL; 303 skb = NULL;
304
305 skb2 = skb_dequeue(&dev->rx_frames);
306 while (skb2) {
307 if (status < 0
308 || ETH_HLEN > skb2->len
309 || skb2->len > ETH_FRAME_LEN) {
310 dev->net->stats.rx_errors++;
311 dev->net->stats.rx_length_errors++;
312 DBG(dev, "rx length %d\n", skb2->len);
313 dev_kfree_skb_any(skb2);
314 goto next_frame;
315 }
316 skb2->protocol = eth_type_trans(skb2, dev->net);
317 dev->net->stats.rx_packets++;
318 dev->net->stats.rx_bytes += skb2->len;
319
320 /* no buffer copies needed, unless hardware can't
321 * use skb buffers.
322 */
323 status = netif_rx(skb2);
324next_frame:
325 skb2 = skb_dequeue(&dev->rx_frames);
326 }
301 break; 327 break;
302 328
303 /* software-driven interface shutdown */ 329 /* software-driven interface shutdown */
@@ -537,14 +563,15 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
537 * or there's not enough space for extra headers we need 563 * or there's not enough space for extra headers we need
538 */ 564 */
539 if (dev->wrap) { 565 if (dev->wrap) {
540 struct sk_buff *skb_new; 566 unsigned long flags;
541 567
542 skb_new = dev->wrap(skb); 568 spin_lock_irqsave(&dev->lock, flags);
543 if (!skb_new) 569 if (dev->port_usb)
570 skb = dev->wrap(dev->port_usb, skb);
571 spin_unlock_irqrestore(&dev->lock, flags);
572 if (!skb)
544 goto drop; 573 goto drop;
545 574
546 dev_kfree_skb_any(skb);
547 skb = skb_new;
548 length = skb->len; 575 length = skb->len;
549 } 576 }
550 req->buf = skb->data; 577 req->buf = skb->data;
@@ -578,9 +605,9 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
578 } 605 }
579 606
580 if (retval) { 607 if (retval) {
608 dev_kfree_skb_any(skb);
581drop: 609drop:
582 dev->net->stats.tx_dropped++; 610 dev->net->stats.tx_dropped++;
583 dev_kfree_skb_any(skb);
584 spin_lock_irqsave(&dev->req_lock, flags); 611 spin_lock_irqsave(&dev->req_lock, flags);
585 if (list_empty(&dev->tx_reqs)) 612 if (list_empty(&dev->tx_reqs))
586 netif_start_queue(net); 613 netif_start_queue(net);
@@ -753,6 +780,8 @@ int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
753 INIT_LIST_HEAD(&dev->tx_reqs); 780 INIT_LIST_HEAD(&dev->tx_reqs);
754 INIT_LIST_HEAD(&dev->rx_reqs); 781 INIT_LIST_HEAD(&dev->rx_reqs);
755 782
783 skb_queue_head_init(&dev->rx_frames);
784
756 /* network device setup */ 785 /* network device setup */
757 dev->net = net; 786 dev->net = net;
758 strcpy(net->name, "usb%d"); 787 strcpy(net->name, "usb%d");
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 0d1f7ae3b071..91b39ffdf6ea 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -60,12 +60,13 @@ struct gether {
60 60
61 u16 cdc_filter; 61 u16 cdc_filter;
62 62
63 /* hooks for added framing, as needed for RNDIS and EEM. 63 /* hooks for added framing, as needed for RNDIS and EEM. */
64 * we currently don't support multiple frames per SKB.
65 */
66 u32 header_len; 64 u32 header_len;
67 struct sk_buff *(*wrap)(struct sk_buff *skb); 65 struct sk_buff *(*wrap)(struct gether *port,
68 int (*unwrap)(struct sk_buff *skb); 66 struct sk_buff *skb);
67 int (*unwrap)(struct gether *port,
68 struct sk_buff *skb,
69 struct sk_buff_head *list);
69 70
70 /* called on network open/close */ 71 /* called on network open/close */
71 void (*open)(struct gether *); 72 void (*open)(struct gether *);
@@ -109,6 +110,7 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
109/* each configuration may bind one instance of an ethernet link */ 110/* each configuration may bind one instance of an ethernet link */
110int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 111int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
111int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 112int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
113int eem_bind_config(struct usb_configuration *c);
112 114
113#ifdef CONFIG_USB_ETH_RNDIS 115#ifdef CONFIG_USB_ETH_RNDIS
114 116
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index fc6e709f45b1..adf8260c3a6a 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -1114,7 +1114,6 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count)
1114 /* export the driver ... */ 1114 /* export the driver ... */
1115 status = tty_register_driver(gs_tty_driver); 1115 status = tty_register_driver(gs_tty_driver);
1116 if (status) { 1116 if (status) {
1117 put_tty_driver(gs_tty_driver);
1118 pr_err("%s: cannot register, err %d\n", 1117 pr_err("%s: cannot register, err %d\n",
1119 __func__, status); 1118 __func__, status);
1120 goto fail; 1119 goto fail;
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f21ca7d27a43..9b43b226817f 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -113,6 +113,12 @@ config USB_EHCI_HCD_PPC_OF
113 Enables support for the USB controller present on the PowerPC 113 Enables support for the USB controller present on the PowerPC
114 OpenFirmware platform bus. 114 OpenFirmware platform bus.
115 115
116config USB_W90X900_EHCI
117 bool "W90X900(W90P910) EHCI support"
118 depends on USB_EHCI_HCD && ARCH_W90X900
119 ---help---
120 Enables support for the W90X900 USB controller
121
116config USB_OXU210HP_HCD 122config USB_OXU210HP_HCD
117 tristate "OXU210HP HCD support" 123 tristate "OXU210HP HCD support"
118 depends on USB 124 depends on USB
@@ -153,6 +159,18 @@ config USB_ISP1760_HCD
153 To compile this driver as a module, choose M here: the 159 To compile this driver as a module, choose M here: the
154 module will be called isp1760. 160 module will be called isp1760.
155 161
162config USB_ISP1362_HCD
163 tristate "ISP1362 HCD support"
164 depends on USB
165 default N
166 ---help---
167 Supports the Philips ISP1362 chip as a host controller
168
169 This driver does not support isochronous transfers.
170
171 To compile this driver as a module, choose M here: the
172 module will be called isp1362-hcd.
173
156config USB_OHCI_HCD 174config USB_OHCI_HCD
157 tristate "OHCI HCD support" 175 tristate "OHCI HCD support"
158 depends on USB && USB_ARCH_HAS_OHCI 176 depends on USB && USB_ARCH_HAS_OHCI
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 289d748bb414..f58b2494c44a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_PCI) += pci-quirks.o
21obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o 21obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
22obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o 22obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
23obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 23obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
24obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o
24obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 25obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
25obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 26obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
26obj-$(CONFIG_USB_FHCI_HCD) += fhci.o 27obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
new file mode 100644
index 000000000000..87c1b7c34c0e
--- /dev/null
+++ b/drivers/usb/host/ehci-atmel.c
@@ -0,0 +1,230 @@
1/*
2 * Driver for EHCI UHP on Atmel chips
3 *
4 * Copyright (C) 2009 Atmel Corporation,
5 * Nicolas Ferre <nicolas.ferre@atmel.com>
6 *
7 * Based on various ehci-*.c drivers
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
13
14#include <linux/clk.h>
15#include <linux/platform_device.h>
16
17/* interface and function clocks */
18static struct clk *iclk, *fclk;
19static int clocked;
20
21/*-------------------------------------------------------------------------*/
22
23static void atmel_start_clock(void)
24{
25 clk_enable(iclk);
26 clk_enable(fclk);
27 clocked = 1;
28}
29
30static void atmel_stop_clock(void)
31{
32 clk_disable(fclk);
33 clk_disable(iclk);
34 clocked = 0;
35}
36
37static void atmel_start_ehci(struct platform_device *pdev)
38{
39 dev_dbg(&pdev->dev, "start\n");
40 atmel_start_clock();
41}
42
43static void atmel_stop_ehci(struct platform_device *pdev)
44{
45 dev_dbg(&pdev->dev, "stop\n");
46 atmel_stop_clock();
47}
48
49/*-------------------------------------------------------------------------*/
50
51static int ehci_atmel_setup(struct usb_hcd *hcd)
52{
53 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
54 int retval = 0;
55
56 /* registers start at offset 0x0 */
57 ehci->caps = hcd->regs;
58 ehci->regs = hcd->regs +
59 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
60 dbg_hcs_params(ehci, "reset");
61 dbg_hcc_params(ehci, "reset");
62
63 /* cache this readonly data; minimize chip reads */
64 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
65
66 retval = ehci_halt(ehci);
67 if (retval)
68 return retval;
69
70 /* data structure init */
71 retval = ehci_init(hcd);
72 if (retval)
73 return retval;
74
75 ehci->sbrn = 0x20;
76
77 ehci_reset(ehci);
78 ehci_port_power(ehci, 0);
79
80 return retval;
81}
82
83static const struct hc_driver ehci_atmel_hc_driver = {
84 .description = hcd_name,
85 .product_desc = "Atmel EHCI UHP HS",
86 .hcd_priv_size = sizeof(struct ehci_hcd),
87
88 /* generic hardware linkage */
89 .irq = ehci_irq,
90 .flags = HCD_MEMORY | HCD_USB2,
91
92 /* basic lifecycle operations */
93 .reset = ehci_atmel_setup,
94 .start = ehci_run,
95 .stop = ehci_stop,
96 .shutdown = ehci_shutdown,
97
98 /* managing i/o requests and associated device resources */
99 .urb_enqueue = ehci_urb_enqueue,
100 .urb_dequeue = ehci_urb_dequeue,
101 .endpoint_disable = ehci_endpoint_disable,
102
103 /* scheduling support */
104 .get_frame_number = ehci_get_frame,
105
106 /* root hub support */
107 .hub_status_data = ehci_hub_status_data,
108 .hub_control = ehci_hub_control,
109 .bus_suspend = ehci_bus_suspend,
110 .bus_resume = ehci_bus_resume,
111 .relinquish_port = ehci_relinquish_port,
112 .port_handed_over = ehci_port_handed_over,
113};
114
115static int __init ehci_atmel_drv_probe(struct platform_device *pdev)
116{
117 struct usb_hcd *hcd;
118 const struct hc_driver *driver = &ehci_atmel_hc_driver;
119 struct resource *res;
120 int irq;
121 int retval;
122
123 if (usb_disabled())
124 return -ENODEV;
125
126 pr_debug("Initializing Atmel-SoC USB Host Controller\n");
127
128 irq = platform_get_irq(pdev, 0);
129 if (irq <= 0) {
130 dev_err(&pdev->dev,
131 "Found HC with no IRQ. Check %s setup!\n",
132 dev_name(&pdev->dev));
133 retval = -ENODEV;
134 goto fail_create_hcd;
135 }
136
137 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
138 if (!hcd) {
139 retval = -ENOMEM;
140 goto fail_create_hcd;
141 }
142
143 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
144 if (!res) {
145 dev_err(&pdev->dev,
146 "Found HC with no register addr. Check %s setup!\n",
147 dev_name(&pdev->dev));
148 retval = -ENODEV;
149 goto fail_request_resource;
150 }
151 hcd->rsrc_start = res->start;
152 hcd->rsrc_len = res->end - res->start + 1;
153
154 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
155 driver->description)) {
156 dev_dbg(&pdev->dev, "controller already in use\n");
157 retval = -EBUSY;
158 goto fail_request_resource;
159 }
160
161 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
162 if (hcd->regs == NULL) {
163 dev_dbg(&pdev->dev, "error mapping memory\n");
164 retval = -EFAULT;
165 goto fail_ioremap;
166 }
167
168 iclk = clk_get(&pdev->dev, "ehci_clk");
169 if (IS_ERR(iclk)) {
170 dev_err(&pdev->dev, "Error getting interface clock\n");
171 retval = -ENOENT;
172 goto fail_get_iclk;
173 }
174 fclk = clk_get(&pdev->dev, "uhpck");
175 if (IS_ERR(fclk)) {
176 dev_err(&pdev->dev, "Error getting function clock\n");
177 retval = -ENOENT;
178 goto fail_get_fclk;
179 }
180
181 atmel_start_ehci(pdev);
182
183 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
184 if (retval)
185 goto fail_add_hcd;
186
187 return retval;
188
189fail_add_hcd:
190 atmel_stop_ehci(pdev);
191 clk_put(fclk);
192fail_get_fclk:
193 clk_put(iclk);
194fail_get_iclk:
195 iounmap(hcd->regs);
196fail_ioremap:
197 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
198fail_request_resource:
199 usb_put_hcd(hcd);
200fail_create_hcd:
201 dev_err(&pdev->dev, "init %s fail, %d\n",
202 dev_name(&pdev->dev), retval);
203
204 return retval;
205}
206
207static int __exit ehci_atmel_drv_remove(struct platform_device *pdev)
208{
209 struct usb_hcd *hcd = platform_get_drvdata(pdev);
210
211 ehci_shutdown(hcd);
212 usb_remove_hcd(hcd);
213 iounmap(hcd->regs);
214 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
215 usb_put_hcd(hcd);
216
217 atmel_stop_ehci(pdev);
218 clk_put(fclk);
219 clk_put(iclk);
220 fclk = iclk = NULL;
221
222 return 0;
223}
224
225static struct platform_driver ehci_atmel_driver = {
226 .probe = ehci_atmel_drv_probe,
227 .remove = __exit_p(ehci_atmel_drv_remove),
228 .shutdown = usb_hcd_platform_shutdown,
229 .driver.name = "atmel-ehci",
230};
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 59d208d94d4e..ed77be76d6bb 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -199,10 +199,9 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
199} 199}
200 200
201#ifdef CONFIG_PM 201#ifdef CONFIG_PM
202static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, 202static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
203 pm_message_t message)
204{ 203{
205 struct usb_hcd *hcd = platform_get_drvdata(pdev); 204 struct usb_hcd *hcd = dev_get_drvdata(dev);
206 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 205 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
207 unsigned long flags; 206 unsigned long flags;
208 int rc; 207 int rc;
@@ -229,12 +228,6 @@ static int ehci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
229 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 228 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
230 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 229 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
231 230
232 /* make sure snapshot being resumed re-enumerates everything */
233 if (message.event == PM_EVENT_PRETHAW) {
234 ehci_halt(ehci);
235 ehci_reset(ehci);
236 }
237
238 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 231 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
239 232
240 au1xxx_stop_ehc(); 233 au1xxx_stop_ehc();
@@ -248,10 +241,9 @@ bail:
248 return rc; 241 return rc;
249} 242}
250 243
251 244static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
252static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
253{ 245{
254 struct usb_hcd *hcd = platform_get_drvdata(pdev); 246 struct usb_hcd *hcd = dev_get_drvdata(dev);
255 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 247 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
256 248
257 au1xxx_start_ehc(); 249 au1xxx_start_ehc();
@@ -305,20 +297,25 @@ static int ehci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
305 return 0; 297 return 0;
306} 298}
307 299
300static struct dev_pm_ops au1xxx_ehci_pmops = {
301 .suspend = ehci_hcd_au1xxx_drv_suspend,
302 .resume = ehci_hcd_au1xxx_drv_resume,
303};
304
305#define AU1XXX_EHCI_PMOPS &au1xxx_ehci_pmops
306
308#else 307#else
309#define ehci_hcd_au1xxx_drv_suspend NULL 308#define AU1XXX_EHCI_PMOPS NULL
310#define ehci_hcd_au1xxx_drv_resume NULL
311#endif 309#endif
312 310
313static struct platform_driver ehci_hcd_au1xxx_driver = { 311static struct platform_driver ehci_hcd_au1xxx_driver = {
314 .probe = ehci_hcd_au1xxx_drv_probe, 312 .probe = ehci_hcd_au1xxx_drv_probe,
315 .remove = ehci_hcd_au1xxx_drv_remove, 313 .remove = ehci_hcd_au1xxx_drv_remove,
316 .shutdown = usb_hcd_platform_shutdown, 314 .shutdown = usb_hcd_platform_shutdown,
317 .suspend = ehci_hcd_au1xxx_drv_suspend,
318 .resume = ehci_hcd_au1xxx_drv_resume,
319 .driver = { 315 .driver = {
320 .name = "au1xxx-ehci", 316 .name = "au1xxx-ehci",
321 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
318 .pm = AU1XXX_EHCI_PMOPS,
322 } 319 }
323}; 320};
324 321
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 7f4ace73d44a..874d2000bf92 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -134,10 +134,11 @@ dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
134static void __maybe_unused 134static void __maybe_unused
135dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) 135dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
136{ 136{
137 struct ehci_qh_hw *hw = qh->hw;
138
137 ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label, 139 ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
138 qh, qh->hw_next, qh->hw_info1, qh->hw_info2, 140 qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
139 qh->hw_current); 141 dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
140 dbg_qtd ("overlay", ehci, (struct ehci_qtd *) &qh->hw_qtd_next);
141} 142}
142 143
143static void __maybe_unused 144static void __maybe_unused
@@ -400,31 +401,32 @@ static void qh_lines (
400 char *next = *nextp; 401 char *next = *nextp;
401 char mark; 402 char mark;
402 __le32 list_end = EHCI_LIST_END(ehci); 403 __le32 list_end = EHCI_LIST_END(ehci);
404 struct ehci_qh_hw *hw = qh->hw;
403 405
404 if (qh->hw_qtd_next == list_end) /* NEC does this */ 406 if (hw->hw_qtd_next == list_end) /* NEC does this */
405 mark = '@'; 407 mark = '@';
406 else 408 else
407 mark = token_mark(ehci, qh->hw_token); 409 mark = token_mark(ehci, hw->hw_token);
408 if (mark == '/') { /* qh_alt_next controls qh advance? */ 410 if (mark == '/') { /* qh_alt_next controls qh advance? */
409 if ((qh->hw_alt_next & QTD_MASK(ehci)) 411 if ((hw->hw_alt_next & QTD_MASK(ehci))
410 == ehci->async->hw_alt_next) 412 == ehci->async->hw->hw_alt_next)
411 mark = '#'; /* blocked */ 413 mark = '#'; /* blocked */
412 else if (qh->hw_alt_next == list_end) 414 else if (hw->hw_alt_next == list_end)
413 mark = '.'; /* use hw_qtd_next */ 415 mark = '.'; /* use hw_qtd_next */
414 /* else alt_next points to some other qtd */ 416 /* else alt_next points to some other qtd */
415 } 417 }
416 scratch = hc32_to_cpup(ehci, &qh->hw_info1); 418 scratch = hc32_to_cpup(ehci, &hw->hw_info1);
417 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &qh->hw_current) : 0; 419 hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
418 temp = scnprintf (next, size, 420 temp = scnprintf (next, size,
419 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)", 421 "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)",
420 qh, scratch & 0x007f, 422 qh, scratch & 0x007f,
421 speed_char (scratch), 423 speed_char (scratch),
422 (scratch >> 8) & 0x000f, 424 (scratch >> 8) & 0x000f,
423 scratch, hc32_to_cpup(ehci, &qh->hw_info2), 425 scratch, hc32_to_cpup(ehci, &hw->hw_info2),
424 hc32_to_cpup(ehci, &qh->hw_token), mark, 426 hc32_to_cpup(ehci, &hw->hw_token), mark,
425 (cpu_to_hc32(ehci, QTD_TOGGLE) & qh->hw_token) 427 (cpu_to_hc32(ehci, QTD_TOGGLE) & hw->hw_token)
426 ? "data1" : "data0", 428 ? "data1" : "data0",
427 (hc32_to_cpup(ehci, &qh->hw_alt_next) >> 1) & 0x0f); 429 (hc32_to_cpup(ehci, &hw->hw_alt_next) >> 1) & 0x0f);
428 size -= temp; 430 size -= temp;
429 next += temp; 431 next += temp;
430 432
@@ -435,10 +437,10 @@ static void qh_lines (
435 mark = ' '; 437 mark = ' ';
436 if (hw_curr == td->qtd_dma) 438 if (hw_curr == td->qtd_dma)
437 mark = '*'; 439 mark = '*';
438 else if (qh->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) 440 else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
439 mark = '+'; 441 mark = '+';
440 else if (QTD_LENGTH (scratch)) { 442 else if (QTD_LENGTH (scratch)) {
441 if (td->hw_alt_next == ehci->async->hw_alt_next) 443 if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
442 mark = '#'; 444 mark = '#';
443 else if (td->hw_alt_next != list_end) 445 else if (td->hw_alt_next != list_end)
444 mark = '/'; 446 mark = '/';
@@ -550,12 +552,15 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
550 next += temp; 552 next += temp;
551 553
552 do { 554 do {
555 struct ehci_qh_hw *hw;
556
553 switch (hc32_to_cpu(ehci, tag)) { 557 switch (hc32_to_cpu(ehci, tag)) {
554 case Q_TYPE_QH: 558 case Q_TYPE_QH:
559 hw = p.qh->hw;
555 temp = scnprintf (next, size, " qh%d-%04x/%p", 560 temp = scnprintf (next, size, " qh%d-%04x/%p",
556 p.qh->period, 561 p.qh->period,
557 hc32_to_cpup(ehci, 562 hc32_to_cpup(ehci,
558 &p.qh->hw_info2) 563 &hw->hw_info2)
559 /* uframe masks */ 564 /* uframe masks */
560 & (QH_CMASK | QH_SMASK), 565 & (QH_CMASK | QH_SMASK),
561 p.qh); 566 p.qh);
@@ -576,7 +581,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
576 /* show more info the first time around */ 581 /* show more info the first time around */
577 if (temp == seen_count) { 582 if (temp == seen_count) {
578 u32 scratch = hc32_to_cpup(ehci, 583 u32 scratch = hc32_to_cpup(ehci,
579 &p.qh->hw_info1); 584 &hw->hw_info1);
580 struct ehci_qtd *qtd; 585 struct ehci_qtd *qtd;
581 char *type = ""; 586 char *type = "";
582 587
@@ -609,7 +614,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
609 } else 614 } else
610 temp = 0; 615 temp = 0;
611 if (p.qh) { 616 if (p.qh) {
612 tag = Q_NEXT_TYPE(ehci, p.qh->hw_next); 617 tag = Q_NEXT_TYPE(ehci, hw->hw_next);
613 p = p.qh->qh_next; 618 p = p.qh->qh_next;
614 } 619 }
615 break; 620 break;
@@ -879,8 +884,7 @@ static int debug_close(struct inode *inode, struct file *file)
879 struct debug_buffer *buf = file->private_data; 884 struct debug_buffer *buf = file->private_data;
880 885
881 if (buf) { 886 if (buf) {
882 if (buf->output_buf) 887 vfree(buf->output_buf);
883 vfree(buf->output_buf);
884 kfree(buf); 888 kfree(buf);
885 } 889 }
886 890
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 11c627ce6022..9835e0713943 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -30,7 +30,6 @@
30#include <linux/timer.h> 30#include <linux/timer.h>
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/reboot.h>
34#include <linux/usb.h> 33#include <linux/usb.h>
35#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
36#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -127,6 +126,8 @@ timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
127 126
128 switch (action) { 127 switch (action) {
129 case TIMER_IO_WATCHDOG: 128 case TIMER_IO_WATCHDOG:
129 if (!ehci->need_io_watchdog)
130 return;
130 t = EHCI_IO_JIFFIES; 131 t = EHCI_IO_JIFFIES;
131 break; 132 break;
132 case TIMER_ASYNC_OFF: 133 case TIMER_ASYNC_OFF:
@@ -239,6 +240,11 @@ static int ehci_reset (struct ehci_hcd *ehci)
239 int retval; 240 int retval;
240 u32 command = ehci_readl(ehci, &ehci->regs->command); 241 u32 command = ehci_readl(ehci, &ehci->regs->command);
241 242
243 /* If the EHCI debug controller is active, special care must be
244 * taken before and after a host controller reset */
245 if (ehci->debug && !dbgp_reset_prep())
246 ehci->debug = NULL;
247
242 command |= CMD_RESET; 248 command |= CMD_RESET;
243 dbg_cmd (ehci, "reset", command); 249 dbg_cmd (ehci, "reset", command);
244 ehci_writel(ehci, command, &ehci->regs->command); 250 ehci_writel(ehci, command, &ehci->regs->command);
@@ -247,12 +253,21 @@ static int ehci_reset (struct ehci_hcd *ehci)
247 retval = handshake (ehci, &ehci->regs->command, 253 retval = handshake (ehci, &ehci->regs->command,
248 CMD_RESET, 0, 250 * 1000); 254 CMD_RESET, 0, 250 * 1000);
249 255
256 if (ehci->has_hostpc) {
257 ehci_writel(ehci, USBMODE_EX_HC | USBMODE_EX_VBPS,
258 (u32 __iomem *)(((u8 *)ehci->regs) + USBMODE_EX));
259 ehci_writel(ehci, TXFIFO_DEFAULT,
260 (u32 __iomem *)(((u8 *)ehci->regs) + TXFILLTUNING));
261 }
250 if (retval) 262 if (retval)
251 return retval; 263 return retval;
252 264
253 if (ehci_is_TDI(ehci)) 265 if (ehci_is_TDI(ehci))
254 tdi_reset (ehci); 266 tdi_reset (ehci);
255 267
268 if (ehci->debug)
269 dbgp_external_startup();
270
256 return retval; 271 return retval;
257} 272}
258 273
@@ -505,9 +520,14 @@ static int ehci_init(struct usb_hcd *hcd)
505 u32 temp; 520 u32 temp;
506 int retval; 521 int retval;
507 u32 hcc_params; 522 u32 hcc_params;
523 struct ehci_qh_hw *hw;
508 524
509 spin_lock_init(&ehci->lock); 525 spin_lock_init(&ehci->lock);
510 526
527 /*
528 * keep io watchdog by default, those good HCDs could turn off it later
529 */
530 ehci->need_io_watchdog = 1;
511 init_timer(&ehci->watchdog); 531 init_timer(&ehci->watchdog);
512 ehci->watchdog.function = ehci_watchdog; 532 ehci->watchdog.function = ehci_watchdog;
513 ehci->watchdog.data = (unsigned long) ehci; 533 ehci->watchdog.data = (unsigned long) ehci;
@@ -544,12 +564,13 @@ static int ehci_init(struct usb_hcd *hcd)
544 * from automatically advancing to the next td after short reads. 564 * from automatically advancing to the next td after short reads.
545 */ 565 */
546 ehci->async->qh_next.qh = NULL; 566 ehci->async->qh_next.qh = NULL;
547 ehci->async->hw_next = QH_NEXT(ehci, ehci->async->qh_dma); 567 hw = ehci->async->hw;
548 ehci->async->hw_info1 = cpu_to_hc32(ehci, QH_HEAD); 568 hw->hw_next = QH_NEXT(ehci, ehci->async->qh_dma);
549 ehci->async->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); 569 hw->hw_info1 = cpu_to_hc32(ehci, QH_HEAD);
550 ehci->async->hw_qtd_next = EHCI_LIST_END(ehci); 570 hw->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT);
571 hw->hw_qtd_next = EHCI_LIST_END(ehci);
551 ehci->async->qh_state = QH_STATE_LINKED; 572 ehci->async->qh_state = QH_STATE_LINKED;
552 ehci->async->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma); 573 hw->hw_alt_next = QTD_NEXT(ehci, ehci->async->dummy->qtd_dma);
553 574
554 /* clear interrupt enables, set irq latency */ 575 /* clear interrupt enables, set irq latency */
555 if (log2_irq_thresh < 0 || log2_irq_thresh > 6) 576 if (log2_irq_thresh < 0 || log2_irq_thresh > 6)
@@ -850,12 +871,18 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
850 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim) 871 if (!HC_IS_RUNNING(ehci_to_hcd(ehci)->state) && ehci->reclaim)
851 end_unlink_async(ehci); 872 end_unlink_async(ehci);
852 873
853 /* if it's not linked then there's nothing to do */ 874 /* If the QH isn't linked then there's nothing we can do
854 if (qh->qh_state != QH_STATE_LINKED) 875 * unless we were called during a giveback, in which case
855 ; 876 * qh_completions() has to deal with it.
877 */
878 if (qh->qh_state != QH_STATE_LINKED) {
879 if (qh->qh_state == QH_STATE_COMPLETING)
880 qh->needs_rescan = 1;
881 return;
882 }
856 883
857 /* defer till later if busy */ 884 /* defer till later if busy */
858 else if (ehci->reclaim) { 885 if (ehci->reclaim) {
859 struct ehci_qh *last; 886 struct ehci_qh *last;
860 887
861 for (last = ehci->reclaim; 888 for (last = ehci->reclaim;
@@ -915,8 +942,9 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
915 break; 942 break;
916 switch (qh->qh_state) { 943 switch (qh->qh_state) {
917 case QH_STATE_LINKED: 944 case QH_STATE_LINKED:
945 case QH_STATE_COMPLETING:
918 intr_deschedule (ehci, qh); 946 intr_deschedule (ehci, qh);
919 /* FALL THROUGH */ 947 break;
920 case QH_STATE_IDLE: 948 case QH_STATE_IDLE:
921 qh_completions (ehci, qh); 949 qh_completions (ehci, qh);
922 break; 950 break;
@@ -925,23 +953,6 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
925 qh, qh->qh_state); 953 qh, qh->qh_state);
926 goto done; 954 goto done;
927 } 955 }
928
929 /* reschedule QH iff another request is queued */
930 if (!list_empty (&qh->qtd_list)
931 && HC_IS_RUNNING (hcd->state)) {
932 rc = qh_schedule(ehci, qh);
933
934 /* An error here likely indicates handshake failure
935 * or no space left in the schedule. Neither fault
936 * should happen often ...
937 *
938 * FIXME kill the now-dysfunctional queued urbs
939 */
940 if (rc != 0)
941 ehci_err(ehci,
942 "can't reschedule qh %p, err %d",
943 qh, rc);
944 }
945 break; 956 break;
946 957
947 case PIPE_ISOCHRONOUS: 958 case PIPE_ISOCHRONOUS:
@@ -979,7 +990,7 @@ rescan:
979 /* endpoints can be iso streams. for now, we don't 990 /* endpoints can be iso streams. for now, we don't
980 * accelerate iso completions ... so spin a while. 991 * accelerate iso completions ... so spin a while.
981 */ 992 */
982 if (qh->hw_info1 == 0) { 993 if (qh->hw->hw_info1 == 0) {
983 ehci_vdbg (ehci, "iso delay\n"); 994 ehci_vdbg (ehci, "iso delay\n");
984 goto idle_timeout; 995 goto idle_timeout;
985 } 996 }
@@ -988,6 +999,7 @@ rescan:
988 qh->qh_state = QH_STATE_IDLE; 999 qh->qh_state = QH_STATE_IDLE;
989 switch (qh->qh_state) { 1000 switch (qh->qh_state) {
990 case QH_STATE_LINKED: 1001 case QH_STATE_LINKED:
1002 case QH_STATE_COMPLETING:
991 for (tmp = ehci->async->qh_next.qh; 1003 for (tmp = ehci->async->qh_next.qh;
992 tmp && tmp != qh; 1004 tmp && tmp != qh;
993 tmp = tmp->qh_next.qh) 1005 tmp = tmp->qh_next.qh)
@@ -1052,18 +1064,17 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1052 usb_settoggle(qh->dev, epnum, is_out, 0); 1064 usb_settoggle(qh->dev, epnum, is_out, 0);
1053 if (!list_empty(&qh->qtd_list)) { 1065 if (!list_empty(&qh->qtd_list)) {
1054 WARN_ONCE(1, "clear_halt for a busy endpoint\n"); 1066 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
1055 } else if (qh->qh_state == QH_STATE_LINKED) { 1067 } else if (qh->qh_state == QH_STATE_LINKED ||
1068 qh->qh_state == QH_STATE_COMPLETING) {
1056 1069
1057 /* The toggle value in the QH can't be updated 1070 /* The toggle value in the QH can't be updated
1058 * while the QH is active. Unlink it now; 1071 * while the QH is active. Unlink it now;
1059 * re-linking will call qh_refresh(). 1072 * re-linking will call qh_refresh().
1060 */ 1073 */
1061 if (eptype == USB_ENDPOINT_XFER_BULK) { 1074 if (eptype == USB_ENDPOINT_XFER_BULK)
1062 unlink_async(ehci, qh); 1075 unlink_async(ehci, qh);
1063 } else { 1076 else
1064 intr_deschedule(ehci, qh); 1077 intr_deschedule(ehci, qh);
1065 (void) qh_schedule(ehci, qh);
1066 }
1067 } 1078 }
1068 } 1079 }
1069 spin_unlock_irqrestore(&ehci->lock, flags); 1080 spin_unlock_irqrestore(&ehci->lock, flags);
@@ -1117,6 +1128,16 @@ MODULE_LICENSE ("GPL");
1117#define PLATFORM_DRIVER ixp4xx_ehci_driver 1128#define PLATFORM_DRIVER ixp4xx_ehci_driver
1118#endif 1129#endif
1119 1130
1131#ifdef CONFIG_USB_W90X900_EHCI
1132#include "ehci-w90x900.c"
1133#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1134#endif
1135
1136#ifdef CONFIG_ARCH_AT91
1137#include "ehci-atmel.c"
1138#define PLATFORM_DRIVER ehci_atmel_driver
1139#endif
1140
1120#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \ 1141#if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
1121 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) 1142 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER)
1122#error "missing bus glue for ehci-hcd" 1143#error "missing bus glue for ehci-hcd"
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index f46ad27c9a90..1b6f1c0e5cee 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -111,6 +111,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
111 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 111 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
112 int port; 112 int port;
113 int mask; 113 int mask;
114 u32 __iomem *hostpc_reg = NULL;
114 115
115 ehci_dbg(ehci, "suspend root hub\n"); 116 ehci_dbg(ehci, "suspend root hub\n");
116 117
@@ -142,6 +143,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
142 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; 143 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
143 u32 t2 = t1; 144 u32 t2 = t1;
144 145
146 if (ehci->has_hostpc)
147 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
148 + HOSTPC0 + 4 * (port & 0xff));
145 /* keep track of which ports we suspend */ 149 /* keep track of which ports we suspend */
146 if (t1 & PORT_OWNER) 150 if (t1 & PORT_OWNER)
147 set_bit(port, &ehci->owned_ports); 151 set_bit(port, &ehci->owned_ports);
@@ -151,15 +155,37 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
151 } 155 }
152 156
153 /* enable remote wakeup on all ports */ 157 /* enable remote wakeup on all ports */
154 if (hcd->self.root_hub->do_remote_wakeup) 158 if (hcd->self.root_hub->do_remote_wakeup) {
155 t2 |= PORT_WAKE_BITS; 159 /* only enable appropriate wake bits, otherwise the
156 else 160 * hardware can not go phy low power mode. If a race
161 * condition happens here(connection change during bits
162 * set), the port change detection will finally fix it.
163 */
164 if (t1 & PORT_CONNECT) {
165 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
166 t2 &= ~PORT_WKCONN_E;
167 } else {
168 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
169 t2 &= ~PORT_WKDISC_E;
170 }
171 } else
157 t2 &= ~PORT_WAKE_BITS; 172 t2 &= ~PORT_WAKE_BITS;
158 173
159 if (t1 != t2) { 174 if (t1 != t2) {
160 ehci_vdbg (ehci, "port %d, %08x -> %08x\n", 175 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
161 port + 1, t1, t2); 176 port + 1, t1, t2);
162 ehci_writel(ehci, t2, reg); 177 ehci_writel(ehci, t2, reg);
178 if (hostpc_reg) {
179 u32 t3;
180
181 msleep(5);/* 5ms for HCD enter low pwr mode */
182 t3 = ehci_readl(ehci, hostpc_reg);
183 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
184 t3 = ehci_readl(ehci, hostpc_reg);
185 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
186 port, (t3 & HOSTPC_PHCD) ?
187 "succeeded" : "failed");
188 }
163 } 189 }
164 } 190 }
165 191
@@ -183,6 +209,11 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
183 209
184 ehci->next_statechange = jiffies + msecs_to_jiffies(10); 210 ehci->next_statechange = jiffies + msecs_to_jiffies(10);
185 spin_unlock_irq (&ehci->lock); 211 spin_unlock_irq (&ehci->lock);
212
213 /* ehci_work() may have re-enabled the watchdog timer, which we do not
214 * want, and so we must delete any pending watchdog timer events.
215 */
216 del_timer_sync(&ehci->watchdog);
186 return 0; 217 return 0;
187} 218}
188 219
@@ -204,6 +235,13 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
204 return -ESHUTDOWN; 235 return -ESHUTDOWN;
205 } 236 }
206 237
238 if (unlikely(ehci->debug)) {
239 if (ehci->debug && !dbgp_reset_prep())
240 ehci->debug = NULL;
241 else
242 dbgp_external_startup();
243 }
244
207 /* Ideally and we've got a real resume here, and no port's power 245 /* Ideally and we've got a real resume here, and no port's power
208 * was lost. (For PCI, that means Vaux was maintained.) But we 246 * was lost. (For PCI, that means Vaux was maintained.) But we
209 * could instead be restoring a swsusp snapshot -- so that BIOS was 247 * could instead be restoring a swsusp snapshot -- so that BIOS was
@@ -563,7 +601,8 @@ static int ehci_hub_control (
563 int ports = HCS_N_PORTS (ehci->hcs_params); 601 int ports = HCS_N_PORTS (ehci->hcs_params);
564 u32 __iomem *status_reg = &ehci->regs->port_status[ 602 u32 __iomem *status_reg = &ehci->regs->port_status[
565 (wIndex & 0xff) - 1]; 603 (wIndex & 0xff) - 1];
566 u32 temp, status; 604 u32 __iomem *hostpc_reg = NULL;
605 u32 temp, temp1, status;
567 unsigned long flags; 606 unsigned long flags;
568 int retval = 0; 607 int retval = 0;
569 unsigned selector; 608 unsigned selector;
@@ -575,6 +614,9 @@ static int ehci_hub_control (
575 * power, "this is the one", etc. EHCI spec supports this. 614 * power, "this is the one", etc. EHCI spec supports this.
576 */ 615 */
577 616
617 if (ehci->has_hostpc)
618 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
619 + HOSTPC0 + 4 * ((wIndex & 0xff) - 1));
578 spin_lock_irqsave (&ehci->lock, flags); 620 spin_lock_irqsave (&ehci->lock, flags);
579 switch (typeReq) { 621 switch (typeReq) {
580 case ClearHubFeature: 622 case ClearHubFeature:
@@ -773,7 +815,11 @@ static int ehci_hub_control (
773 if (temp & PORT_CONNECT) { 815 if (temp & PORT_CONNECT) {
774 status |= 1 << USB_PORT_FEAT_CONNECTION; 816 status |= 1 << USB_PORT_FEAT_CONNECTION;
775 // status may be from integrated TT 817 // status may be from integrated TT
776 status |= ehci_port_speed(ehci, temp); 818 if (ehci->has_hostpc) {
819 temp1 = ehci_readl(ehci, hostpc_reg);
820 status |= ehci_port_speed(ehci, temp1);
821 } else
822 status |= ehci_port_speed(ehci, temp);
777 } 823 }
778 if (temp & PORT_PE) 824 if (temp & PORT_PE)
779 status |= 1 << USB_PORT_FEAT_ENABLE; 825 status |= 1 << USB_PORT_FEAT_ENABLE;
@@ -816,6 +862,15 @@ static int ehci_hub_control (
816 case SetPortFeature: 862 case SetPortFeature:
817 selector = wIndex >> 8; 863 selector = wIndex >> 8;
818 wIndex &= 0xff; 864 wIndex &= 0xff;
865 if (unlikely(ehci->debug)) {
866 /* If the debug port is active any port
867 * feature requests should get denied */
868 if (wIndex == HCS_DEBUG_PORT(ehci->hcs_params) &&
869 (readl(&ehci->debug->control) & DBGP_ENABLED)) {
870 retval = -ENODEV;
871 goto error_exit;
872 }
873 }
819 if (!wIndex || wIndex > ports) 874 if (!wIndex || wIndex > ports)
820 goto error; 875 goto error;
821 wIndex--; 876 wIndex--;
@@ -832,6 +887,24 @@ static int ehci_hub_control (
832 || (temp & PORT_RESET) != 0) 887 || (temp & PORT_RESET) != 0)
833 goto error; 888 goto error;
834 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 889 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
890 /* After above check the port must be connected.
891 * Set appropriate bit thus could put phy into low power
892 * mode if we have hostpc feature
893 */
894 if (hostpc_reg) {
895 temp &= ~PORT_WKCONN_E;
896 temp |= (PORT_WKDISC_E | PORT_WKOC_E);
897 ehci_writel(ehci, temp | PORT_SUSPEND,
898 status_reg);
899 msleep(5);/* 5ms for HCD enter low pwr mode */
900 temp1 = ehci_readl(ehci, hostpc_reg);
901 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
902 hostpc_reg);
903 temp1 = ehci_readl(ehci, hostpc_reg);
904 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n",
905 wIndex, (temp1 & HOSTPC_PHCD) ?
906 "succeeded" : "failed");
907 }
835 set_bit(wIndex, &ehci->suspended_ports); 908 set_bit(wIndex, &ehci->suspended_ports);
836 break; 909 break;
837 case USB_PORT_FEAT_POWER: 910 case USB_PORT_FEAT_POWER:
@@ -894,6 +967,7 @@ error:
894 /* "stall" on error */ 967 /* "stall" on error */
895 retval = -EPIPE; 968 retval = -EPIPE;
896 } 969 }
970error_exit:
897 spin_unlock_irqrestore (&ehci->lock, flags); 971 spin_unlock_irqrestore (&ehci->lock, flags);
898 return retval; 972 return retval;
899} 973}
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index 10d52919abbb..aeda96e0af67 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -75,7 +75,8 @@ static void qh_destroy(struct ehci_qh *qh)
75 } 75 }
76 if (qh->dummy) 76 if (qh->dummy)
77 ehci_qtd_free (ehci, qh->dummy); 77 ehci_qtd_free (ehci, qh->dummy);
78 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); 78 dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma);
79 kfree(qh);
79} 80}
80 81
81static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) 82static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
@@ -83,12 +84,14 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
83 struct ehci_qh *qh; 84 struct ehci_qh *qh;
84 dma_addr_t dma; 85 dma_addr_t dma;
85 86
86 qh = (struct ehci_qh *) 87 qh = kzalloc(sizeof *qh, GFP_ATOMIC);
87 dma_pool_alloc (ehci->qh_pool, flags, &dma);
88 if (!qh) 88 if (!qh)
89 return qh; 89 goto done;
90 90 qh->hw = (struct ehci_qh_hw *)
91 memset (qh, 0, sizeof *qh); 91 dma_pool_alloc(ehci->qh_pool, flags, &dma);
92 if (!qh->hw)
93 goto fail;
94 memset(qh->hw, 0, sizeof *qh->hw);
92 qh->refcount = 1; 95 qh->refcount = 1;
93 qh->ehci = ehci; 96 qh->ehci = ehci;
94 qh->qh_dma = dma; 97 qh->qh_dma = dma;
@@ -99,10 +102,15 @@ static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags)
99 qh->dummy = ehci_qtd_alloc (ehci, flags); 102 qh->dummy = ehci_qtd_alloc (ehci, flags);
100 if (qh->dummy == NULL) { 103 if (qh->dummy == NULL) {
101 ehci_dbg (ehci, "no dummy td\n"); 104 ehci_dbg (ehci, "no dummy td\n");
102 dma_pool_free (ehci->qh_pool, qh, qh->qh_dma); 105 goto fail1;
103 qh = NULL;
104 } 106 }
107done:
105 return qh; 108 return qh;
109fail1:
110 dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma);
111fail:
112 kfree(qh);
113 return NULL;
106} 114}
107 115
108/* to share a qh (cpu threads, or hc) */ 116/* to share a qh (cpu threads, or hc) */
@@ -180,7 +188,7 @@ static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags)
180 /* QHs for control/bulk/intr transfers */ 188 /* QHs for control/bulk/intr transfers */
181 ehci->qh_pool = dma_pool_create ("ehci_qh", 189 ehci->qh_pool = dma_pool_create ("ehci_qh",
182 ehci_to_hcd(ehci)->self.controller, 190 ehci_to_hcd(ehci)->self.controller,
183 sizeof (struct ehci_qh), 191 sizeof(struct ehci_qh_hw),
184 32 /* byte alignment (for hw parts) */, 192 32 /* byte alignment (for hw parts) */,
185 4096 /* can't cross 4K */); 193 4096 /* can't cross 4K */);
186 if (!ehci->qh_pool) { 194 if (!ehci->qh_pool) {
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index b5b83c43898a..378861b9d79a 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -27,28 +27,8 @@
27/* called after powerup, by probe or system-pm "wakeup" */ 27/* called after powerup, by probe or system-pm "wakeup" */
28static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev) 28static int ehci_pci_reinit(struct ehci_hcd *ehci, struct pci_dev *pdev)
29{ 29{
30 u32 temp;
31 int retval; 30 int retval;
32 31
33 /* optional debug port, normally in the first BAR */
34 temp = pci_find_capability(pdev, 0x0a);
35 if (temp) {
36 pci_read_config_dword(pdev, temp, &temp);
37 temp >>= 16;
38 if ((temp & (3 << 13)) == (1 << 13)) {
39 temp &= 0x1fff;
40 ehci->debug = ehci_to_hcd(ehci)->regs + temp;
41 temp = ehci_readl(ehci, &ehci->debug->control);
42 ehci_info(ehci, "debug port %d%s\n",
43 HCS_DEBUG_PORT(ehci->hcs_params),
44 (temp & DBGP_ENABLED)
45 ? " IN USE"
46 : "");
47 if (!(temp & DBGP_ENABLED))
48 ehci->debug = NULL;
49 }
50 }
51
52 /* we expect static quirk code to handle the "extended capabilities" 32 /* we expect static quirk code to handle the "extended capabilities"
53 * (currently just BIOS handoff) allowed starting with EHCI 0.96 33 * (currently just BIOS handoff) allowed starting with EHCI 0.96
54 */ 34 */
@@ -129,6 +109,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
129 return retval; 109 return retval;
130 110
131 switch (pdev->vendor) { 111 switch (pdev->vendor) {
112 case PCI_VENDOR_ID_INTEL:
113 ehci->need_io_watchdog = 0;
114 break;
132 case PCI_VENDOR_ID_TDI: 115 case PCI_VENDOR_ID_TDI:
133 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 116 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
134 hcd->has_tt = 1; 117 hcd->has_tt = 1;
@@ -192,6 +175,25 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
192 break; 175 break;
193 } 176 }
194 177
178 /* optional debug port, normally in the first BAR */
179 temp = pci_find_capability(pdev, 0x0a);
180 if (temp) {
181 pci_read_config_dword(pdev, temp, &temp);
182 temp >>= 16;
183 if ((temp & (3 << 13)) == (1 << 13)) {
184 temp &= 0x1fff;
185 ehci->debug = ehci_to_hcd(ehci)->regs + temp;
186 temp = ehci_readl(ehci, &ehci->debug->control);
187 ehci_info(ehci, "debug port %d%s\n",
188 HCS_DEBUG_PORT(ehci->hcs_params),
189 (temp & DBGP_ENABLED)
190 ? " IN USE"
191 : "");
192 if (!(temp & DBGP_ENABLED))
193 ehci->debug = NULL;
194 }
195 }
196
195 ehci_reset(ehci); 197 ehci_reset(ehci);
196 198
197 /* at least the Genesys GL880S needs fixup here */ 199 /* at least the Genesys GL880S needs fixup here */
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 7673554fa64d..00ad9ce392ed 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -87,31 +87,33 @@ qtd_fill(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t buf,
87static inline void 87static inline void
88qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd) 88qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
89{ 89{
90 struct ehci_qh_hw *hw = qh->hw;
91
90 /* writes to an active overlay are unsafe */ 92 /* writes to an active overlay are unsafe */
91 BUG_ON(qh->qh_state != QH_STATE_IDLE); 93 BUG_ON(qh->qh_state != QH_STATE_IDLE);
92 94
93 qh->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); 95 hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma);
94 qh->hw_alt_next = EHCI_LIST_END(ehci); 96 hw->hw_alt_next = EHCI_LIST_END(ehci);
95 97
96 /* Except for control endpoints, we make hardware maintain data 98 /* Except for control endpoints, we make hardware maintain data
97 * toggle (like OHCI) ... here (re)initialize the toggle in the QH, 99 * toggle (like OHCI) ... here (re)initialize the toggle in the QH,
98 * and set the pseudo-toggle in udev. Only usb_clear_halt() will 100 * and set the pseudo-toggle in udev. Only usb_clear_halt() will
99 * ever clear it. 101 * ever clear it.
100 */ 102 */
101 if (!(qh->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) { 103 if (!(hw->hw_info1 & cpu_to_hc32(ehci, 1 << 14))) {
102 unsigned is_out, epnum; 104 unsigned is_out, epnum;
103 105
104 is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8)); 106 is_out = !(qtd->hw_token & cpu_to_hc32(ehci, 1 << 8));
105 epnum = (hc32_to_cpup(ehci, &qh->hw_info1) >> 8) & 0x0f; 107 epnum = (hc32_to_cpup(ehci, &hw->hw_info1) >> 8) & 0x0f;
106 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) { 108 if (unlikely (!usb_gettoggle (qh->dev, epnum, is_out))) {
107 qh->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE); 109 hw->hw_token &= ~cpu_to_hc32(ehci, QTD_TOGGLE);
108 usb_settoggle (qh->dev, epnum, is_out, 1); 110 usb_settoggle (qh->dev, epnum, is_out, 1);
109 } 111 }
110 } 112 }
111 113
112 /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ 114 /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */
113 wmb (); 115 wmb ();
114 qh->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING); 116 hw->hw_token &= cpu_to_hc32(ehci, QTD_TOGGLE | QTD_STS_PING);
115} 117}
116 118
117/* if it weren't for a common silicon quirk (writing the dummy into the qh 119/* if it weren't for a common silicon quirk (writing the dummy into the qh
@@ -129,7 +131,7 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
129 qtd = list_entry (qh->qtd_list.next, 131 qtd = list_entry (qh->qtd_list.next,
130 struct ehci_qtd, qtd_list); 132 struct ehci_qtd, qtd_list);
131 /* first qtd may already be partially processed */ 133 /* first qtd may already be partially processed */
132 if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw_current) 134 if (cpu_to_hc32(ehci, qtd->qtd_dma) == qh->hw->hw_current)
133 qtd = NULL; 135 qtd = NULL;
134 } 136 }
135 137
@@ -260,7 +262,7 @@ __acquires(ehci->lock)
260 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; 262 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv;
261 263
262 /* S-mask in a QH means it's an interrupt urb */ 264 /* S-mask in a QH means it's an interrupt urb */
263 if ((qh->hw_info2 & cpu_to_hc32(ehci, QH_SMASK)) != 0) { 265 if ((qh->hw->hw_info2 & cpu_to_hc32(ehci, QH_SMASK)) != 0) {
264 266
265 /* ... update hc-wide periodic stats (for usbfs) */ 267 /* ... update hc-wide periodic stats (for usbfs) */
266 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--; 268 ehci_to_hcd(ehci)->self.bandwidth_int_reqs--;
@@ -297,7 +299,6 @@ __acquires(ehci->lock)
297static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); 299static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh);
298static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh); 300static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh);
299 301
300static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
301static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh); 302static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
302 303
303/* 304/*
@@ -308,13 +309,14 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
308static unsigned 309static unsigned
309qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) 310qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
310{ 311{
311 struct ehci_qtd *last = NULL, *end = qh->dummy; 312 struct ehci_qtd *last, *end = qh->dummy;
312 struct list_head *entry, *tmp; 313 struct list_head *entry, *tmp;
313 int last_status = -EINPROGRESS; 314 int last_status;
314 int stopped; 315 int stopped;
315 unsigned count = 0; 316 unsigned count = 0;
316 u8 state; 317 u8 state;
317 __le32 halt = HALT_BIT(ehci); 318 const __le32 halt = HALT_BIT(ehci);
319 struct ehci_qh_hw *hw = qh->hw;
318 320
319 if (unlikely (list_empty (&qh->qtd_list))) 321 if (unlikely (list_empty (&qh->qtd_list)))
320 return count; 322 return count;
@@ -324,11 +326,20 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
324 * they add urbs to this qh's queue or mark them for unlinking. 326 * they add urbs to this qh's queue or mark them for unlinking.
325 * 327 *
326 * NOTE: unlinking expects to be done in queue order. 328 * NOTE: unlinking expects to be done in queue order.
329 *
330 * It's a bug for qh->qh_state to be anything other than
331 * QH_STATE_IDLE, unless our caller is scan_async() or
332 * scan_periodic().
327 */ 333 */
328 state = qh->qh_state; 334 state = qh->qh_state;
329 qh->qh_state = QH_STATE_COMPLETING; 335 qh->qh_state = QH_STATE_COMPLETING;
330 stopped = (state == QH_STATE_IDLE); 336 stopped = (state == QH_STATE_IDLE);
331 337
338 rescan:
339 last = NULL;
340 last_status = -EINPROGRESS;
341 qh->needs_rescan = 0;
342
332 /* remove de-activated QTDs from front of queue. 343 /* remove de-activated QTDs from front of queue.
333 * after faults (including short reads), cleanup this urb 344 * after faults (including short reads), cleanup this urb
334 * then let the queue advance. 345 * then let the queue advance.
@@ -392,7 +403,8 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
392 qtd->hw_token = cpu_to_hc32(ehci, 403 qtd->hw_token = cpu_to_hc32(ehci,
393 token); 404 token);
394 wmb(); 405 wmb();
395 qh->hw_token = cpu_to_hc32(ehci, token); 406 hw->hw_token = cpu_to_hc32(ehci,
407 token);
396 goto retry_xacterr; 408 goto retry_xacterr;
397 } 409 }
398 stopped = 1; 410 stopped = 1;
@@ -435,8 +447,8 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
435 /* qh unlinked; token in overlay may be most current */ 447 /* qh unlinked; token in overlay may be most current */
436 if (state == QH_STATE_IDLE 448 if (state == QH_STATE_IDLE
437 && cpu_to_hc32(ehci, qtd->qtd_dma) 449 && cpu_to_hc32(ehci, qtd->qtd_dma)
438 == qh->hw_current) { 450 == hw->hw_current) {
439 token = hc32_to_cpu(ehci, qh->hw_token); 451 token = hc32_to_cpu(ehci, hw->hw_token);
440 452
441 /* An unlink may leave an incomplete 453 /* An unlink may leave an incomplete
442 * async transaction in the TT buffer. 454 * async transaction in the TT buffer.
@@ -449,9 +461,9 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
449 * patch the qh later and so that completions can't 461 * patch the qh later and so that completions can't
450 * activate it while we "know" it's stopped. 462 * activate it while we "know" it's stopped.
451 */ 463 */
452 if ((halt & qh->hw_token) == 0) { 464 if ((halt & hw->hw_token) == 0) {
453halt: 465halt:
454 qh->hw_token |= halt; 466 hw->hw_token |= halt;
455 wmb (); 467 wmb ();
456 } 468 }
457 } 469 }
@@ -503,6 +515,21 @@ halt:
503 ehci_qtd_free (ehci, last); 515 ehci_qtd_free (ehci, last);
504 } 516 }
505 517
518 /* Do we need to rescan for URBs dequeued during a giveback? */
519 if (unlikely(qh->needs_rescan)) {
520 /* If the QH is already unlinked, do the rescan now. */
521 if (state == QH_STATE_IDLE)
522 goto rescan;
523
524 /* Otherwise we have to wait until the QH is fully unlinked.
525 * Our caller will start an unlink if qh->needs_rescan is
526 * set. But if an unlink has already started, nothing needs
527 * to be done.
528 */
529 if (state != QH_STATE_LINKED)
530 qh->needs_rescan = 0;
531 }
532
506 /* restore original state; caller must unlink or relink */ 533 /* restore original state; caller must unlink or relink */
507 qh->qh_state = state; 534 qh->qh_state = state;
508 535
@@ -510,7 +537,7 @@ halt:
510 * it after fault cleanup, or recovering from silicon wrongly 537 * it after fault cleanup, or recovering from silicon wrongly
511 * overlaying the dummy qtd (which reduces DMA chatter). 538 * overlaying the dummy qtd (which reduces DMA chatter).
512 */ 539 */
513 if (stopped != 0 || qh->hw_qtd_next == EHCI_LIST_END(ehci)) { 540 if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci)) {
514 switch (state) { 541 switch (state) {
515 case QH_STATE_IDLE: 542 case QH_STATE_IDLE:
516 qh_refresh(ehci, qh); 543 qh_refresh(ehci, qh);
@@ -527,12 +554,9 @@ halt:
527 * That should be rare for interrupt transfers, 554 * That should be rare for interrupt transfers,
528 * except maybe high bandwidth ... 555 * except maybe high bandwidth ...
529 */ 556 */
530 if ((cpu_to_hc32(ehci, QH_SMASK) 557
531 & qh->hw_info2) != 0) { 558 /* Tell the caller to start an unlink */
532 intr_deschedule (ehci, qh); 559 qh->needs_rescan = 1;
533 (void) qh_schedule (ehci, qh);
534 } else
535 unlink_async (ehci, qh);
536 break; 560 break;
537 /* otherwise, unlink already started */ 561 /* otherwise, unlink already started */
538 } 562 }
@@ -649,7 +673,7 @@ qh_urb_transaction (
649 * (this will usually be overridden later.) 673 * (this will usually be overridden later.)
650 */ 674 */
651 if (is_input) 675 if (is_input)
652 qtd->hw_alt_next = ehci->async->hw_alt_next; 676 qtd->hw_alt_next = ehci->async->hw->hw_alt_next;
653 677
654 /* qh makes control packets use qtd toggle; maybe switch it */ 678 /* qh makes control packets use qtd toggle; maybe switch it */
655 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) 679 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
@@ -744,6 +768,7 @@ qh_make (
744 int is_input, type; 768 int is_input, type;
745 int maxp = 0; 769 int maxp = 0;
746 struct usb_tt *tt = urb->dev->tt; 770 struct usb_tt *tt = urb->dev->tt;
771 struct ehci_qh_hw *hw;
747 772
748 if (!qh) 773 if (!qh)
749 return qh; 774 return qh;
@@ -890,8 +915,9 @@ done:
890 915
891 /* init as live, toggle clear, advance to dummy */ 916 /* init as live, toggle clear, advance to dummy */
892 qh->qh_state = QH_STATE_IDLE; 917 qh->qh_state = QH_STATE_IDLE;
893 qh->hw_info1 = cpu_to_hc32(ehci, info1); 918 hw = qh->hw;
894 qh->hw_info2 = cpu_to_hc32(ehci, info2); 919 hw->hw_info1 = cpu_to_hc32(ehci, info1);
920 hw->hw_info2 = cpu_to_hc32(ehci, info2);
895 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); 921 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
896 qh_refresh (ehci, qh); 922 qh_refresh (ehci, qh);
897 return qh; 923 return qh;
@@ -910,6 +936,8 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
910 if (unlikely(qh->clearing_tt)) 936 if (unlikely(qh->clearing_tt))
911 return; 937 return;
912 938
939 WARN_ON(qh->qh_state != QH_STATE_IDLE);
940
913 /* (re)start the async schedule? */ 941 /* (re)start the async schedule? */
914 head = ehci->async; 942 head = ehci->async;
915 timer_action_done (ehci, TIMER_ASYNC_OFF); 943 timer_action_done (ehci, TIMER_ASYNC_OFF);
@@ -928,16 +956,15 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
928 } 956 }
929 957
930 /* clear halt and/or toggle; and maybe recover from silicon quirk */ 958 /* clear halt and/or toggle; and maybe recover from silicon quirk */
931 if (qh->qh_state == QH_STATE_IDLE) 959 qh_refresh(ehci, qh);
932 qh_refresh (ehci, qh);
933 960
934 /* splice right after start */ 961 /* splice right after start */
935 qh->qh_next = head->qh_next; 962 qh->qh_next = head->qh_next;
936 qh->hw_next = head->hw_next; 963 qh->hw->hw_next = head->hw->hw_next;
937 wmb (); 964 wmb ();
938 965
939 head->qh_next.qh = qh; 966 head->qh_next.qh = qh;
940 head->hw_next = dma; 967 head->hw->hw_next = dma;
941 968
942 qh_get(qh); 969 qh_get(qh);
943 qh->xacterrs = 0; 970 qh->xacterrs = 0;
@@ -984,7 +1011,7 @@ static struct ehci_qh *qh_append_tds (
984 1011
985 /* usb_reset_device() briefly reverts to address 0 */ 1012 /* usb_reset_device() briefly reverts to address 0 */
986 if (usb_pipedevice (urb->pipe) == 0) 1013 if (usb_pipedevice (urb->pipe) == 0)
987 qh->hw_info1 &= ~qh_addr_mask; 1014 qh->hw->hw_info1 &= ~qh_addr_mask;
988 } 1015 }
989 1016
990 /* just one way to queue requests: swap with the dummy qtd. 1017 /* just one way to queue requests: swap with the dummy qtd.
@@ -1169,7 +1196,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1169 while (prev->qh_next.qh != qh) 1196 while (prev->qh_next.qh != qh)
1170 prev = prev->qh_next.qh; 1197 prev = prev->qh_next.qh;
1171 1198
1172 prev->hw_next = qh->hw_next; 1199 prev->hw->hw_next = qh->hw->hw_next;
1173 prev->qh_next = qh->qh_next; 1200 prev->qh_next = qh->qh_next;
1174 wmb (); 1201 wmb ();
1175 1202
@@ -1214,6 +1241,8 @@ rescan:
1214 qh = qh_get (qh); 1241 qh = qh_get (qh);
1215 qh->stamp = ehci->stamp; 1242 qh->stamp = ehci->stamp;
1216 temp = qh_completions (ehci, qh); 1243 temp = qh_completions (ehci, qh);
1244 if (qh->needs_rescan)
1245 unlink_async(ehci, qh);
1217 qh_put (qh); 1246 qh_put (qh);
1218 if (temp != 0) { 1247 if (temp != 0) {
1219 goto rescan; 1248 goto rescan;
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index edd61ee90323..3ea05936851f 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -60,6 +60,20 @@ periodic_next_shadow(struct ehci_hcd *ehci, union ehci_shadow *periodic,
60 } 60 }
61} 61}
62 62
63static __hc32 *
64shadow_next_periodic(struct ehci_hcd *ehci, union ehci_shadow *periodic,
65 __hc32 tag)
66{
67 switch (hc32_to_cpu(ehci, tag)) {
68 /* our ehci_shadow.qh is actually software part */
69 case Q_TYPE_QH:
70 return &periodic->qh->hw->hw_next;
71 /* others are hw parts */
72 default:
73 return periodic->hw_next;
74 }
75}
76
63/* caller must hold ehci->lock */ 77/* caller must hold ehci->lock */
64static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr) 78static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
65{ 79{
@@ -71,7 +85,8 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
71 while (here.ptr && here.ptr != ptr) { 85 while (here.ptr && here.ptr != ptr) {
72 prev_p = periodic_next_shadow(ehci, prev_p, 86 prev_p = periodic_next_shadow(ehci, prev_p,
73 Q_NEXT_TYPE(ehci, *hw_p)); 87 Q_NEXT_TYPE(ehci, *hw_p));
74 hw_p = here.hw_next; 88 hw_p = shadow_next_periodic(ehci, &here,
89 Q_NEXT_TYPE(ehci, *hw_p));
75 here = *prev_p; 90 here = *prev_p;
76 } 91 }
77 /* an interrupt entry (at list end) could have been shared */ 92 /* an interrupt entry (at list end) could have been shared */
@@ -83,7 +98,7 @@ static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
83 */ 98 */
84 *prev_p = *periodic_next_shadow(ehci, &here, 99 *prev_p = *periodic_next_shadow(ehci, &here,
85 Q_NEXT_TYPE(ehci, *hw_p)); 100 Q_NEXT_TYPE(ehci, *hw_p));
86 *hw_p = *here.hw_next; 101 *hw_p = *shadow_next_periodic(ehci, &here, Q_NEXT_TYPE(ehci, *hw_p));
87} 102}
88 103
89/* how many of the uframe's 125 usecs are allocated? */ 104/* how many of the uframe's 125 usecs are allocated? */
@@ -93,18 +108,20 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
93 __hc32 *hw_p = &ehci->periodic [frame]; 108 __hc32 *hw_p = &ehci->periodic [frame];
94 union ehci_shadow *q = &ehci->pshadow [frame]; 109 union ehci_shadow *q = &ehci->pshadow [frame];
95 unsigned usecs = 0; 110 unsigned usecs = 0;
111 struct ehci_qh_hw *hw;
96 112
97 while (q->ptr) { 113 while (q->ptr) {
98 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) { 114 switch (hc32_to_cpu(ehci, Q_NEXT_TYPE(ehci, *hw_p))) {
99 case Q_TYPE_QH: 115 case Q_TYPE_QH:
116 hw = q->qh->hw;
100 /* is it in the S-mask? */ 117 /* is it in the S-mask? */
101 if (q->qh->hw_info2 & cpu_to_hc32(ehci, 1 << uframe)) 118 if (hw->hw_info2 & cpu_to_hc32(ehci, 1 << uframe))
102 usecs += q->qh->usecs; 119 usecs += q->qh->usecs;
103 /* ... or C-mask? */ 120 /* ... or C-mask? */
104 if (q->qh->hw_info2 & cpu_to_hc32(ehci, 121 if (hw->hw_info2 & cpu_to_hc32(ehci,
105 1 << (8 + uframe))) 122 1 << (8 + uframe)))
106 usecs += q->qh->c_usecs; 123 usecs += q->qh->c_usecs;
107 hw_p = &q->qh->hw_next; 124 hw_p = &hw->hw_next;
108 q = &q->qh->qh_next; 125 q = &q->qh->qh_next;
109 break; 126 break;
110 // case Q_TYPE_FSTN: 127 // case Q_TYPE_FSTN:
@@ -237,10 +254,10 @@ periodic_tt_usecs (
237 continue; 254 continue;
238 case Q_TYPE_QH: 255 case Q_TYPE_QH:
239 if (same_tt(dev, q->qh->dev)) { 256 if (same_tt(dev, q->qh->dev)) {
240 uf = tt_start_uframe(ehci, q->qh->hw_info2); 257 uf = tt_start_uframe(ehci, q->qh->hw->hw_info2);
241 tt_usecs[uf] += q->qh->tt_usecs; 258 tt_usecs[uf] += q->qh->tt_usecs;
242 } 259 }
243 hw_p = &q->qh->hw_next; 260 hw_p = &q->qh->hw->hw_next;
244 q = &q->qh->qh_next; 261 q = &q->qh->qh_next;
245 continue; 262 continue;
246 case Q_TYPE_SITD: 263 case Q_TYPE_SITD:
@@ -375,6 +392,7 @@ static int tt_no_collision (
375 for (; frame < ehci->periodic_size; frame += period) { 392 for (; frame < ehci->periodic_size; frame += period) {
376 union ehci_shadow here; 393 union ehci_shadow here;
377 __hc32 type; 394 __hc32 type;
395 struct ehci_qh_hw *hw;
378 396
379 here = ehci->pshadow [frame]; 397 here = ehci->pshadow [frame];
380 type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]); 398 type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]);
@@ -385,17 +403,18 @@ static int tt_no_collision (
385 here = here.itd->itd_next; 403 here = here.itd->itd_next;
386 continue; 404 continue;
387 case Q_TYPE_QH: 405 case Q_TYPE_QH:
406 hw = here.qh->hw;
388 if (same_tt (dev, here.qh->dev)) { 407 if (same_tt (dev, here.qh->dev)) {
389 u32 mask; 408 u32 mask;
390 409
391 mask = hc32_to_cpu(ehci, 410 mask = hc32_to_cpu(ehci,
392 here.qh->hw_info2); 411 hw->hw_info2);
393 /* "knows" no gap is needed */ 412 /* "knows" no gap is needed */
394 mask |= mask >> 8; 413 mask |= mask >> 8;
395 if (mask & uf_mask) 414 if (mask & uf_mask)
396 break; 415 break;
397 } 416 }
398 type = Q_NEXT_TYPE(ehci, here.qh->hw_next); 417 type = Q_NEXT_TYPE(ehci, hw->hw_next);
399 here = here.qh->qh_next; 418 here = here.qh->qh_next;
400 continue; 419 continue;
401 case Q_TYPE_SITD: 420 case Q_TYPE_SITD:
@@ -498,7 +517,8 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
498 517
499 dev_dbg (&qh->dev->dev, 518 dev_dbg (&qh->dev->dev,
500 "link qh%d-%04x/%p start %d [%d/%d us]\n", 519 "link qh%d-%04x/%p start %d [%d/%d us]\n",
501 period, hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), 520 period, hc32_to_cpup(ehci, &qh->hw->hw_info2)
521 & (QH_CMASK | QH_SMASK),
502 qh, qh->start, qh->usecs, qh->c_usecs); 522 qh, qh->start, qh->usecs, qh->c_usecs);
503 523
504 /* high bandwidth, or otherwise every microframe */ 524 /* high bandwidth, or otherwise every microframe */
@@ -517,7 +537,7 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
517 if (type == cpu_to_hc32(ehci, Q_TYPE_QH)) 537 if (type == cpu_to_hc32(ehci, Q_TYPE_QH))
518 break; 538 break;
519 prev = periodic_next_shadow(ehci, prev, type); 539 prev = periodic_next_shadow(ehci, prev, type);
520 hw_p = &here.qh->hw_next; 540 hw_p = shadow_next_periodic(ehci, &here, type);
521 here = *prev; 541 here = *prev;
522 } 542 }
523 543
@@ -528,14 +548,14 @@ static int qh_link_periodic (struct ehci_hcd *ehci, struct ehci_qh *qh)
528 if (qh->period > here.qh->period) 548 if (qh->period > here.qh->period)
529 break; 549 break;
530 prev = &here.qh->qh_next; 550 prev = &here.qh->qh_next;
531 hw_p = &here.qh->hw_next; 551 hw_p = &here.qh->hw->hw_next;
532 here = *prev; 552 here = *prev;
533 } 553 }
534 /* link in this qh, unless some earlier pass did that */ 554 /* link in this qh, unless some earlier pass did that */
535 if (qh != here.qh) { 555 if (qh != here.qh) {
536 qh->qh_next = here; 556 qh->qh_next = here;
537 if (here.qh) 557 if (here.qh)
538 qh->hw_next = *hw_p; 558 qh->hw->hw_next = *hw_p;
539 wmb (); 559 wmb ();
540 prev->qh = qh; 560 prev->qh = qh;
541 *hw_p = QH_NEXT (ehci, qh->qh_dma); 561 *hw_p = QH_NEXT (ehci, qh->qh_dma);
@@ -581,7 +601,7 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
581 dev_dbg (&qh->dev->dev, 601 dev_dbg (&qh->dev->dev,
582 "unlink qh%d-%04x/%p start %d [%d/%d us]\n", 602 "unlink qh%d-%04x/%p start %d [%d/%d us]\n",
583 qh->period, 603 qh->period,
584 hc32_to_cpup(ehci, &qh->hw_info2) & (QH_CMASK | QH_SMASK), 604 hc32_to_cpup(ehci, &qh->hw->hw_info2) & (QH_CMASK | QH_SMASK),
585 qh, qh->start, qh->usecs, qh->c_usecs); 605 qh, qh->start, qh->usecs, qh->c_usecs);
586 606
587 /* qh->qh_next still "live" to HC */ 607 /* qh->qh_next still "live" to HC */
@@ -595,7 +615,19 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
595 615
596static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh) 616static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
597{ 617{
598 unsigned wait; 618 unsigned wait;
619 struct ehci_qh_hw *hw = qh->hw;
620 int rc;
621
622 /* If the QH isn't linked then there's nothing we can do
623 * unless we were called during a giveback, in which case
624 * qh_completions() has to deal with it.
625 */
626 if (qh->qh_state != QH_STATE_LINKED) {
627 if (qh->qh_state == QH_STATE_COMPLETING)
628 qh->needs_rescan = 1;
629 return;
630 }
599 631
600 qh_unlink_periodic (ehci, qh); 632 qh_unlink_periodic (ehci, qh);
601 633
@@ -606,15 +638,33 @@ static void intr_deschedule (struct ehci_hcd *ehci, struct ehci_qh *qh)
606 */ 638 */
607 if (list_empty (&qh->qtd_list) 639 if (list_empty (&qh->qtd_list)
608 || (cpu_to_hc32(ehci, QH_CMASK) 640 || (cpu_to_hc32(ehci, QH_CMASK)
609 & qh->hw_info2) != 0) 641 & hw->hw_info2) != 0)
610 wait = 2; 642 wait = 2;
611 else 643 else
612 wait = 55; /* worst case: 3 * 1024 */ 644 wait = 55; /* worst case: 3 * 1024 */
613 645
614 udelay (wait); 646 udelay (wait);
615 qh->qh_state = QH_STATE_IDLE; 647 qh->qh_state = QH_STATE_IDLE;
616 qh->hw_next = EHCI_LIST_END(ehci); 648 hw->hw_next = EHCI_LIST_END(ehci);
617 wmb (); 649 wmb ();
650
651 qh_completions(ehci, qh);
652
653 /* reschedule QH iff another request is queued */
654 if (!list_empty(&qh->qtd_list) &&
655 HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
656 rc = qh_schedule(ehci, qh);
657
658 /* An error here likely indicates handshake failure
659 * or no space left in the schedule. Neither fault
660 * should happen often ...
661 *
662 * FIXME kill the now-dysfunctional queued urbs
663 */
664 if (rc != 0)
665 ehci_err(ehci, "can't reschedule qh %p, err %d\n",
666 qh, rc);
667 }
618} 668}
619 669
620/*-------------------------------------------------------------------------*/ 670/*-------------------------------------------------------------------------*/
@@ -739,14 +789,15 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
739 unsigned uframe; 789 unsigned uframe;
740 __hc32 c_mask; 790 __hc32 c_mask;
741 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ 791 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
792 struct ehci_qh_hw *hw = qh->hw;
742 793
743 qh_refresh(ehci, qh); 794 qh_refresh(ehci, qh);
744 qh->hw_next = EHCI_LIST_END(ehci); 795 hw->hw_next = EHCI_LIST_END(ehci);
745 frame = qh->start; 796 frame = qh->start;
746 797
747 /* reuse the previous schedule slots, if we can */ 798 /* reuse the previous schedule slots, if we can */
748 if (frame < qh->period) { 799 if (frame < qh->period) {
749 uframe = ffs(hc32_to_cpup(ehci, &qh->hw_info2) & QH_SMASK); 800 uframe = ffs(hc32_to_cpup(ehci, &hw->hw_info2) & QH_SMASK);
750 status = check_intr_schedule (ehci, frame, --uframe, 801 status = check_intr_schedule (ehci, frame, --uframe,
751 qh, &c_mask); 802 qh, &c_mask);
752 } else { 803 } else {
@@ -784,11 +835,11 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
784 qh->start = frame; 835 qh->start = frame;
785 836
786 /* reset S-frame and (maybe) C-frame masks */ 837 /* reset S-frame and (maybe) C-frame masks */
787 qh->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK)); 838 hw->hw_info2 &= cpu_to_hc32(ehci, ~(QH_CMASK | QH_SMASK));
788 qh->hw_info2 |= qh->period 839 hw->hw_info2 |= qh->period
789 ? cpu_to_hc32(ehci, 1 << uframe) 840 ? cpu_to_hc32(ehci, 1 << uframe)
790 : cpu_to_hc32(ehci, QH_SMASK); 841 : cpu_to_hc32(ehci, QH_SMASK);
791 qh->hw_info2 |= c_mask; 842 hw->hw_info2 |= c_mask;
792 } else 843 } else
793 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 844 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
794 845
@@ -2188,10 +2239,11 @@ restart:
2188 case Q_TYPE_QH: 2239 case Q_TYPE_QH:
2189 /* handle any completions */ 2240 /* handle any completions */
2190 temp.qh = qh_get (q.qh); 2241 temp.qh = qh_get (q.qh);
2191 type = Q_NEXT_TYPE(ehci, q.qh->hw_next); 2242 type = Q_NEXT_TYPE(ehci, q.qh->hw->hw_next);
2192 q = q.qh->qh_next; 2243 q = q.qh->qh_next;
2193 modified = qh_completions (ehci, temp.qh); 2244 modified = qh_completions (ehci, temp.qh);
2194 if (unlikely (list_empty (&temp.qh->qtd_list))) 2245 if (unlikely(list_empty(&temp.qh->qtd_list) ||
2246 temp.qh->needs_rescan))
2195 intr_deschedule (ehci, temp.qh); 2247 intr_deschedule (ehci, temp.qh);
2196 qh_put (temp.qh); 2248 qh_put (temp.qh);
2197 break; 2249 break;
diff --git a/drivers/usb/host/ehci-w90x900.c b/drivers/usb/host/ehci-w90x900.c
new file mode 100644
index 000000000000..cfa21ea20f82
--- /dev/null
+++ b/drivers/usb/host/ehci-w90x900.c
@@ -0,0 +1,181 @@
1/*
2 * linux/driver/usb/host/ehci-w90x900.c
3 *
4 * Copyright (c) 2008 Nuvoton technology corporation.
5 *
6 * Wan ZongShun <mcuos.com@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation;version 2 of the License.
11 *
12 */
13
14#include <linux/platform_device.h>
15
16/*ebable phy0 and phy1 for w90p910*/
17#define ENPHY (0x01<<8)
18#define PHY0_CTR (0xA4)
19#define PHY1_CTR (0xA8)
20
21static int __devinit usb_w90x900_probe(const struct hc_driver *driver,
22 struct platform_device *pdev)
23{
24 struct usb_hcd *hcd;
25 struct ehci_hcd *ehci;
26 struct resource *res;
27 int retval = 0, irq;
28 unsigned long val;
29
30
31 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
32 if (!res) {
33 retval = -ENXIO;
34 goto err1;
35 }
36
37 hcd = usb_create_hcd(driver, &pdev->dev, "w90x900 EHCI");
38 if (!hcd) {
39 retval = -ENOMEM;
40 goto err1;
41 }
42
43 hcd->rsrc_start = res->start;
44 hcd->rsrc_len = res->end - res->start + 1;
45
46 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
47 retval = -EBUSY;
48 goto err2;
49 }
50
51 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
52 if (hcd->regs == NULL) {
53 retval = -EFAULT;
54 goto err3;
55 }
56
57 ehci = hcd_to_ehci(hcd);
58 ehci->caps = hcd->regs;
59 ehci->regs = hcd->regs +
60 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
61
62 /* enable PHY 0,1,the regs only apply to w90p910
63 * 0xA4,0xA8 were offsets of PHY0 and PHY1 controller of
64 * w90p910 IC relative to ehci->regs.
65 */
66 val = __raw_readl(ehci->regs+PHY0_CTR);
67 val |= ENPHY;
68 __raw_writel(val, ehci->regs+PHY0_CTR);
69
70 val = __raw_readl(ehci->regs+PHY1_CTR);
71 val |= ENPHY;
72 __raw_writel(val, ehci->regs+PHY1_CTR);
73
74 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
75 ehci->sbrn = 0x20;
76
77 irq = platform_get_irq(pdev, 0);
78 if (irq < 0)
79 goto err4;
80
81 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
82 if (retval != 0)
83 goto err4;
84
85 ehci_writel(ehci, 1, &ehci->regs->configured_flag);
86
87 return retval;
88err4:
89 iounmap(hcd->regs);
90err3:
91 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
92err2:
93 usb_put_hcd(hcd);
94err1:
95 return retval;
96}
97
98static
99void usb_w90x900_remove(struct usb_hcd *hcd, struct platform_device *pdev)
100{
101 usb_remove_hcd(hcd);
102 iounmap(hcd->regs);
103 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
104 usb_put_hcd(hcd);
105}
106
107static const struct hc_driver ehci_w90x900_hc_driver = {
108 .description = hcd_name,
109 .product_desc = "Nuvoton w90x900 EHCI Host Controller",
110 .hcd_priv_size = sizeof(struct ehci_hcd),
111
112 /*
113 * generic hardware linkage
114 */
115 .irq = ehci_irq,
116 .flags = HCD_USB2|HCD_MEMORY,
117
118 /*
119 * basic lifecycle operations
120 */
121 .reset = ehci_init,
122 .start = ehci_run,
123
124 .stop = ehci_stop,
125 .shutdown = ehci_shutdown,
126
127 /*
128 * managing i/o requests and associated device resources
129 */
130 .urb_enqueue = ehci_urb_enqueue,
131 .urb_dequeue = ehci_urb_dequeue,
132 .endpoint_disable = ehci_endpoint_disable,
133
134 /*
135 * scheduling support
136 */
137 .get_frame_number = ehci_get_frame,
138
139 /*
140 * root hub support
141 */
142 .hub_status_data = ehci_hub_status_data,
143 .hub_control = ehci_hub_control,
144#ifdef CONFIG_PM
145 .bus_suspend = ehci_bus_suspend,
146 .bus_resume = ehci_bus_resume,
147#endif
148 .relinquish_port = ehci_relinquish_port,
149 .port_handed_over = ehci_port_handed_over,
150};
151
152static int __devinit ehci_w90x900_probe(struct platform_device *pdev)
153{
154 if (usb_disabled())
155 return -ENODEV;
156
157 return usb_w90x900_probe(&ehci_w90x900_hc_driver, pdev);
158}
159
160static int __devexit ehci_w90x900_remove(struct platform_device *pdev)
161{
162 struct usb_hcd *hcd = platform_get_drvdata(pdev);
163
164 usb_w90x900_remove(hcd, pdev);
165
166 return 0;
167}
168
169static struct platform_driver ehci_hcd_w90x900_driver = {
170 .probe = ehci_w90x900_probe,
171 .remove = __devexit_p(ehci_w90x900_remove),
172 .driver = {
173 .name = "w90x900-ehci",
174 .owner = THIS_MODULE,
175 },
176};
177
178MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
179MODULE_DESCRIPTION("w90p910 usb ehci driver!");
180MODULE_LICENSE("GPL");
181MODULE_ALIAS("platform:w90p910-ehci");
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 48b9e889a18b..064e76821ff5 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -126,6 +126,7 @@ struct ehci_hcd { /* one per controller */
126 unsigned big_endian_mmio:1; 126 unsigned big_endian_mmio:1;
127 unsigned big_endian_desc:1; 127 unsigned big_endian_desc:1;
128 unsigned has_amcc_usb23:1; 128 unsigned has_amcc_usb23:1;
129 unsigned need_io_watchdog:1;
129 130
130 /* required for usb32 quirk */ 131 /* required for usb32 quirk */
131 #define OHCI_CTRL_HCFS (3 << 6) 132 #define OHCI_CTRL_HCFS (3 << 6)
@@ -135,6 +136,7 @@ struct ehci_hcd { /* one per controller */
135 #define OHCI_HCCTRL_OFFSET 0x4 136 #define OHCI_HCCTRL_OFFSET 0x4
136 #define OHCI_HCCTRL_LEN 0x4 137 #define OHCI_HCCTRL_LEN 0x4
137 __hc32 *ohci_hcctrl_reg; 138 __hc32 *ohci_hcctrl_reg;
139 unsigned has_hostpc:1;
138 140
139 u8 sbrn; /* packed release number */ 141 u8 sbrn; /* packed release number */
140 142
@@ -298,8 +300,8 @@ union ehci_shadow {
298 * These appear in both the async and (for interrupt) periodic schedules. 300 * These appear in both the async and (for interrupt) periodic schedules.
299 */ 301 */
300 302
301struct ehci_qh { 303/* first part defined by EHCI spec */
302 /* first part defined by EHCI spec */ 304struct ehci_qh_hw {
303 __hc32 hw_next; /* see EHCI 3.6.1 */ 305 __hc32 hw_next; /* see EHCI 3.6.1 */
304 __hc32 hw_info1; /* see EHCI 3.6.2 */ 306 __hc32 hw_info1; /* see EHCI 3.6.2 */
305#define QH_HEAD 0x00008000 307#define QH_HEAD 0x00008000
@@ -317,7 +319,10 @@ struct ehci_qh {
317 __hc32 hw_token; 319 __hc32 hw_token;
318 __hc32 hw_buf [5]; 320 __hc32 hw_buf [5];
319 __hc32 hw_buf_hi [5]; 321 __hc32 hw_buf_hi [5];
322} __attribute__ ((aligned(32)));
320 323
324struct ehci_qh {
325 struct ehci_qh_hw *hw;
321 /* the rest is HCD-private */ 326 /* the rest is HCD-private */
322 dma_addr_t qh_dma; /* address of qh */ 327 dma_addr_t qh_dma; /* address of qh */
323 union ehci_shadow qh_next; /* ptr to qh; or periodic */ 328 union ehci_shadow qh_next; /* ptr to qh; or periodic */
@@ -336,6 +341,7 @@ struct ehci_qh {
336 u32 refcount; 341 u32 refcount;
337 unsigned stamp; 342 unsigned stamp;
338 343
344 u8 needs_rescan; /* Dequeue during giveback */
339 u8 qh_state; 345 u8 qh_state;
340#define QH_STATE_LINKED 1 /* HC sees this */ 346#define QH_STATE_LINKED 1 /* HC sees this */
341#define QH_STATE_UNLINK 2 /* HC may still see this */ 347#define QH_STATE_UNLINK 2 /* HC may still see this */
@@ -357,7 +363,7 @@ struct ehci_qh {
357 363
358 struct usb_device *dev; /* access to TT */ 364 struct usb_device *dev; /* access to TT */
359 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 365 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
360} __attribute__ ((aligned (32))); 366};
361 367
362/*-------------------------------------------------------------------------*/ 368/*-------------------------------------------------------------------------*/
363 369
@@ -544,7 +550,7 @@ static inline unsigned int
544ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc) 550ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
545{ 551{
546 if (ehci_is_TDI(ehci)) { 552 if (ehci_is_TDI(ehci)) {
547 switch ((portsc>>26)&3) { 553 switch ((portsc >> (ehci->has_hostpc ? 25 : 26)) & 3) {
548 case 0: 554 case 0:
549 return 0; 555 return 0;
550 case 1: 556 case 1:
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
new file mode 100644
index 000000000000..e35d82808bab
--- /dev/null
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -0,0 +1,2909 @@
1/*
2 * ISP1362 HCD (Host Controller Driver) for USB.
3 *
4 * Copyright (C) 2005 Lothar Wassmann <LW@KARO-electronics.de>
5 *
6 * Derived from the SL811 HCD, rewritten for ISP116x.
7 * Copyright (C) 2005 Olav Kongas <ok@artecdesign.ee>
8 *
9 * Portions:
10 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
11 * Copyright (C) 2004 David Brownell
12 */
13
14/*
15 * The ISP1362 chip requires a large delay (300ns and 462ns) between
16 * accesses to the address and data register.
17 * The following timing options exist:
18 *
19 * 1. Configure your memory controller to add such delays if it can (the best)
20 * 2. Implement platform-specific delay function possibly
21 * combined with configuring the memory controller; see
22 * include/linux/usb_isp1362.h for more info.
23 * 3. Use ndelay (easiest, poorest).
24 *
25 * Use the corresponding macros USE_PLATFORM_DELAY and USE_NDELAY in the
26 * platform specific section of isp1362.h to select the appropriate variant.
27 *
28 * Also note that according to the Philips "ISP1362 Errata" document
29 * Rev 1.00 from 27 May data corruption may occur when the #WR signal
30 * is reasserted (even with #CS deasserted) within 132ns after a
31 * write cycle to any controller register. If the hardware doesn't
32 * implement the recommended fix (gating the #WR with #CS) software
33 * must ensure that no further write cycle (not necessarily to the chip!)
34 * is issued by the CPU within this interval.
35
36 * For PXA25x this can be ensured by using VLIO with the maximum
37 * recovery time (MSCx = 0x7f8c) with a memory clock of 99.53 MHz.
38 */
39
40#ifdef CONFIG_USB_DEBUG
41# define ISP1362_DEBUG
42#else
43# undef ISP1362_DEBUG
44#endif
45
46/*
47 * The PXA255 UDC apparently doesn't handle GET_STATUS, GET_CONFIG and
48 * GET_INTERFACE requests correctly when the SETUP and DATA stages of the
49 * requests are carried out in separate frames. This will delay any SETUP
50 * packets until the start of the next frame so that this situation is
51 * unlikely to occur (and makes usbtest happy running with a PXA255 target
52 * device).
53 */
54#undef BUGGY_PXA2XX_UDC_USBTEST
55
56#undef PTD_TRACE
57#undef URB_TRACE
58#undef VERBOSE
59#undef REGISTERS
60
61/* This enables a memory test on the ISP1362 chip memory to make sure the
62 * chip access timing is correct.
63 */
64#undef CHIP_BUFFER_TEST
65
66#include <linux/module.h>
67#include <linux/moduleparam.h>
68#include <linux/kernel.h>
69#include <linux/delay.h>
70#include <linux/ioport.h>
71#include <linux/sched.h>
72#include <linux/slab.h>
73#include <linux/smp_lock.h>
74#include <linux/errno.h>
75#include <linux/init.h>
76#include <linux/list.h>
77#include <linux/interrupt.h>
78#include <linux/usb.h>
79#include <linux/usb/isp1362.h>
80#include <linux/platform_device.h>
81#include <linux/pm.h>
82#include <linux/io.h>
83#include <linux/bitops.h>
84
85#include <asm/irq.h>
86#include <asm/system.h>
87#include <asm/byteorder.h>
88#include <asm/unaligned.h>
89
90static int dbg_level;
91#ifdef ISP1362_DEBUG
92module_param(dbg_level, int, 0644);
93#else
94module_param(dbg_level, int, 0);
95#define STUB_DEBUG_FILE
96#endif
97
98#include "../core/hcd.h"
99#include "../core/usb.h"
100#include "isp1362.h"
101
102
103#define DRIVER_VERSION "2005-04-04"
104#define DRIVER_DESC "ISP1362 USB Host Controller Driver"
105
106MODULE_DESCRIPTION(DRIVER_DESC);
107MODULE_LICENSE("GPL");
108
109static const char hcd_name[] = "isp1362-hcd";
110
111static void isp1362_hc_stop(struct usb_hcd *hcd);
112static int isp1362_hc_start(struct usb_hcd *hcd);
113
114/*-------------------------------------------------------------------------*/
115
116/*
117 * When called from the interrupthandler only isp1362_hcd->irqenb is modified,
118 * since the interrupt handler will write isp1362_hcd->irqenb to HCuPINT upon
119 * completion.
120 * We don't need a 'disable' counterpart, since interrupts will be disabled
121 * only by the interrupt handler.
122 */
123static inline void isp1362_enable_int(struct isp1362_hcd *isp1362_hcd, u16 mask)
124{
125 if ((isp1362_hcd->irqenb | mask) == isp1362_hcd->irqenb)
126 return;
127 if (mask & ~isp1362_hcd->irqenb)
128 isp1362_write_reg16(isp1362_hcd, HCuPINT, mask & ~isp1362_hcd->irqenb);
129 isp1362_hcd->irqenb |= mask;
130 if (isp1362_hcd->irq_active)
131 return;
132 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
133}
134
135/*-------------------------------------------------------------------------*/
136
137static inline struct isp1362_ep_queue *get_ptd_queue(struct isp1362_hcd *isp1362_hcd,
138 u16 offset)
139{
140 struct isp1362_ep_queue *epq = NULL;
141
142 if (offset < isp1362_hcd->istl_queue[1].buf_start)
143 epq = &isp1362_hcd->istl_queue[0];
144 else if (offset < isp1362_hcd->intl_queue.buf_start)
145 epq = &isp1362_hcd->istl_queue[1];
146 else if (offset < isp1362_hcd->atl_queue.buf_start)
147 epq = &isp1362_hcd->intl_queue;
148 else if (offset < isp1362_hcd->atl_queue.buf_start +
149 isp1362_hcd->atl_queue.buf_size)
150 epq = &isp1362_hcd->atl_queue;
151
152 if (epq)
153 DBG(1, "%s: PTD $%04x is on %s queue\n", __func__, offset, epq->name);
154 else
155 pr_warning("%s: invalid PTD $%04x\n", __func__, offset);
156
157 return epq;
158}
159
160static inline int get_ptd_offset(struct isp1362_ep_queue *epq, u8 index)
161{
162 int offset;
163
164 if (index * epq->blk_size > epq->buf_size) {
165 pr_warning("%s: Bad %s index %d(%d)\n", __func__, epq->name, index,
166 epq->buf_size / epq->blk_size);
167 return -EINVAL;
168 }
169 offset = epq->buf_start + index * epq->blk_size;
170 DBG(3, "%s: %s PTD[%02x] # %04x\n", __func__, epq->name, index, offset);
171
172 return offset;
173}
174
175/*-------------------------------------------------------------------------*/
176
177static inline u16 max_transfer_size(struct isp1362_ep_queue *epq, size_t size,
178 int mps)
179{
180 u16 xfer_size = min_t(size_t, MAX_XFER_SIZE, size);
181
182 xfer_size = min_t(size_t, xfer_size, epq->buf_avail * epq->blk_size - PTD_HEADER_SIZE);
183 if (xfer_size < size && xfer_size % mps)
184 xfer_size -= xfer_size % mps;
185
186 return xfer_size;
187}
188
189static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
190 struct isp1362_ep *ep, u16 len)
191{
192 int ptd_offset = -EINVAL;
193 int index;
194 int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1;
195 int found = -1;
196 int last = -1;
197
198 BUG_ON(len > epq->buf_size);
199
200 if (!epq->buf_avail)
201 return -ENOMEM;
202
203 if (ep->num_ptds)
204 pr_err("%s: %s len %d/%d num_ptds %d buf_map %08lx skip_map %08lx\n", __func__,
205 epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map);
206 BUG_ON(ep->num_ptds != 0);
207
208 for (index = 0; index <= epq->buf_count - num_ptds; index++) {
209 if (test_bit(index, &epq->buf_map))
210 continue;
211 found = index;
212 for (last = index + 1; last < index + num_ptds; last++) {
213 if (test_bit(last, &epq->buf_map)) {
214 found = -1;
215 break;
216 }
217 }
218 if (found >= 0)
219 break;
220 }
221 if (found < 0)
222 return -EOVERFLOW;
223
224 DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__,
225 num_ptds, found, len, (int)(epq->blk_size - PTD_HEADER_SIZE));
226 ptd_offset = get_ptd_offset(epq, found);
227 WARN_ON(ptd_offset < 0);
228 ep->ptd_offset = ptd_offset;
229 ep->num_ptds += num_ptds;
230 epq->buf_avail -= num_ptds;
231 BUG_ON(epq->buf_avail > epq->buf_count);
232 ep->ptd_index = found;
233 for (index = found; index < last; index++)
234 __set_bit(index, &epq->buf_map);
235 DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
236 __func__, epq->name, ep->ptd_index, ep->ptd_offset,
237 epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map);
238
239 return found;
240}
241
242static inline void release_ptd_buffers(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
243{
244 int index = ep->ptd_index;
245 int last = ep->ptd_index + ep->num_ptds;
246
247 if (last > epq->buf_count)
248 pr_err("%s: ep %p req %d len %d %s PTD[%d] $%04x num_ptds %d buf_count %d buf_avail %d buf_map %08lx skip_map %08lx\n",
249 __func__, ep, ep->num_req, ep->length, epq->name, ep->ptd_index,
250 ep->ptd_offset, ep->num_ptds, epq->buf_count, epq->buf_avail,
251 epq->buf_map, epq->skip_map);
252 BUG_ON(last > epq->buf_count);
253
254 for (; index < last; index++) {
255 __clear_bit(index, &epq->buf_map);
256 __set_bit(index, &epq->skip_map);
257 }
258 epq->buf_avail += ep->num_ptds;
259 epq->ptd_count--;
260
261 BUG_ON(epq->buf_avail > epq->buf_count);
262 BUG_ON(epq->ptd_count > epq->buf_count);
263
264 DBG(1, "%s: Done %s PTDs $%04x released %d avail %d count %d\n",
265 __func__, epq->name,
266 ep->ptd_offset, ep->num_ptds, epq->buf_avail, epq->buf_count);
267 DBG(1, "%s: buf_map %08lx skip_map %08lx\n", __func__,
268 epq->buf_map, epq->skip_map);
269
270 ep->num_ptds = 0;
271 ep->ptd_offset = -EINVAL;
272 ep->ptd_index = -EINVAL;
273}
274
275/*-------------------------------------------------------------------------*/
276
277/*
278 Set up PTD's.
279*/
280static void prepare_ptd(struct isp1362_hcd *isp1362_hcd, struct urb *urb,
281 struct isp1362_ep *ep, struct isp1362_ep_queue *epq,
282 u16 fno)
283{
284 struct ptd *ptd;
285 int toggle;
286 int dir;
287 u16 len;
288 size_t buf_len = urb->transfer_buffer_length - urb->actual_length;
289
290 DBG(3, "%s: %s ep %p\n", __func__, epq->name, ep);
291
292 ptd = &ep->ptd;
293
294 ep->data = (unsigned char *)urb->transfer_buffer + urb->actual_length;
295
296 switch (ep->nextpid) {
297 case USB_PID_IN:
298 toggle = usb_gettoggle(urb->dev, ep->epnum, 0);
299 dir = PTD_DIR_IN;
300 if (usb_pipecontrol(urb->pipe)) {
301 len = min_t(size_t, ep->maxpacket, buf_len);
302 } else if (usb_pipeisoc(urb->pipe)) {
303 len = min_t(size_t, urb->iso_frame_desc[fno].length, MAX_XFER_SIZE);
304 ep->data = urb->transfer_buffer + urb->iso_frame_desc[fno].offset;
305 } else
306 len = max_transfer_size(epq, buf_len, ep->maxpacket);
307 DBG(1, "%s: IN len %d/%d/%d from URB\n", __func__, len, ep->maxpacket,
308 (int)buf_len);
309 break;
310 case USB_PID_OUT:
311 toggle = usb_gettoggle(urb->dev, ep->epnum, 1);
312 dir = PTD_DIR_OUT;
313 if (usb_pipecontrol(urb->pipe))
314 len = min_t(size_t, ep->maxpacket, buf_len);
315 else if (usb_pipeisoc(urb->pipe))
316 len = min_t(size_t, urb->iso_frame_desc[0].length, MAX_XFER_SIZE);
317 else
318 len = max_transfer_size(epq, buf_len, ep->maxpacket);
319 if (len == 0)
320 pr_info("%s: Sending ZERO packet: %d\n", __func__,
321 urb->transfer_flags & URB_ZERO_PACKET);
322 DBG(1, "%s: OUT len %d/%d/%d from URB\n", __func__, len, ep->maxpacket,
323 (int)buf_len);
324 break;
325 case USB_PID_SETUP:
326 toggle = 0;
327 dir = PTD_DIR_SETUP;
328 len = sizeof(struct usb_ctrlrequest);
329 DBG(1, "%s: SETUP len %d\n", __func__, len);
330 ep->data = urb->setup_packet;
331 break;
332 case USB_PID_ACK:
333 toggle = 1;
334 len = 0;
335 dir = (urb->transfer_buffer_length && usb_pipein(urb->pipe)) ?
336 PTD_DIR_OUT : PTD_DIR_IN;
337 DBG(1, "%s: ACK len %d\n", __func__, len);
338 break;
339 default:
340 toggle = dir = len = 0;
341 pr_err("%s@%d: ep->nextpid %02x\n", __func__, __LINE__, ep->nextpid);
342 BUG_ON(1);
343 }
344
345 ep->length = len;
346 if (!len)
347 ep->data = NULL;
348
349 ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK | PTD_TOGGLE(toggle);
350 ptd->mps = PTD_MPS(ep->maxpacket) | PTD_SPD(urb->dev->speed == USB_SPEED_LOW) |
351 PTD_EP(ep->epnum);
352 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
353 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
354
355 if (usb_pipeint(urb->pipe)) {
356 ptd->faddr |= PTD_SF_INT(ep->branch);
357 ptd->faddr |= PTD_PR(ep->interval ? __ffs(ep->interval) : 0);
358 }
359 if (usb_pipeisoc(urb->pipe))
360 ptd->faddr |= PTD_SF_ISO(fno);
361
362 DBG(1, "%s: Finished\n", __func__);
363}
364
365static void isp1362_write_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
366 struct isp1362_ep_queue *epq)
367{
368 struct ptd *ptd = &ep->ptd;
369 int len = PTD_GET_DIR(ptd) == PTD_DIR_IN ? 0 : ep->length;
370
371 _BUG_ON(ep->ptd_offset < 0);
372
373 prefetch(ptd);
374 isp1362_write_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE);
375 if (len)
376 isp1362_write_buffer(isp1362_hcd, ep->data,
377 ep->ptd_offset + PTD_HEADER_SIZE, len);
378
379 dump_ptd(ptd);
380 dump_ptd_out_data(ptd, ep->data);
381}
382
383static void isp1362_read_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
384 struct isp1362_ep_queue *epq)
385{
386 struct ptd *ptd = &ep->ptd;
387 int act_len;
388
389 WARN_ON(list_empty(&ep->active));
390 BUG_ON(ep->ptd_offset < 0);
391
392 list_del_init(&ep->active);
393 DBG(1, "%s: ep %p removed from active list %p\n", __func__, ep, &epq->active);
394
395 prefetchw(ptd);
396 isp1362_read_buffer(isp1362_hcd, ptd, ep->ptd_offset, PTD_HEADER_SIZE);
397 dump_ptd(ptd);
398 act_len = PTD_GET_COUNT(ptd);
399 if (PTD_GET_DIR(ptd) != PTD_DIR_IN || act_len == 0)
400 return;
401 if (act_len > ep->length)
402 pr_err("%s: ep %p PTD $%04x act_len %d ep->length %d\n", __func__, ep,
403 ep->ptd_offset, act_len, ep->length);
404 BUG_ON(act_len > ep->length);
405 /* Only transfer the amount of data that has actually been overwritten
406 * in the chip buffer. We don't want any data that doesn't belong to the
407 * transfer to leak out of the chip to the callers transfer buffer!
408 */
409 prefetchw(ep->data);
410 isp1362_read_buffer(isp1362_hcd, ep->data,
411 ep->ptd_offset + PTD_HEADER_SIZE, act_len);
412 dump_ptd_in_data(ptd, ep->data);
413}
414
415/*
416 * INT PTDs will stay in the chip until data is available.
417 * This function will remove a PTD from the chip when the URB is dequeued.
418 * Must be called with the spinlock held and IRQs disabled
419 */
420static void remove_ptd(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep)
421
422{
423 int index;
424 struct isp1362_ep_queue *epq;
425
426 DBG(1, "%s: ep %p PTD[%d] $%04x\n", __func__, ep, ep->ptd_index, ep->ptd_offset);
427 BUG_ON(ep->ptd_offset < 0);
428
429 epq = get_ptd_queue(isp1362_hcd, ep->ptd_offset);
430 BUG_ON(!epq);
431
432 /* put ep in remove_list for cleanup */
433 WARN_ON(!list_empty(&ep->remove_list));
434 list_add_tail(&ep->remove_list, &isp1362_hcd->remove_list);
435 /* let SOF interrupt handle the cleanup */
436 isp1362_enable_int(isp1362_hcd, HCuPINT_SOF);
437
438 index = ep->ptd_index;
439 if (index < 0)
440 /* ISO queues don't have SKIP registers */
441 return;
442
443 DBG(1, "%s: Disabling PTD[%02x] $%04x %08lx|%08x\n", __func__,
444 index, ep->ptd_offset, epq->skip_map, 1 << index);
445
446 /* prevent further processing of PTD (will be effective after next SOF) */
447 epq->skip_map |= 1 << index;
448 if (epq == &isp1362_hcd->atl_queue) {
449 DBG(2, "%s: ATLSKIP = %08x -> %08lx\n", __func__,
450 isp1362_read_reg32(isp1362_hcd, HCATLSKIP), epq->skip_map);
451 isp1362_write_reg32(isp1362_hcd, HCATLSKIP, epq->skip_map);
452 if (~epq->skip_map == 0)
453 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
454 } else if (epq == &isp1362_hcd->intl_queue) {
455 DBG(2, "%s: INTLSKIP = %08x -> %08lx\n", __func__,
456 isp1362_read_reg32(isp1362_hcd, HCINTLSKIP), epq->skip_map);
457 isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, epq->skip_map);
458 if (~epq->skip_map == 0)
459 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
460 }
461}
462
463/*
464 Take done or failed requests out of schedule. Give back
465 processed urbs.
466*/
467static void finish_request(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep,
468 struct urb *urb, int status)
469 __releases(isp1362_hcd->lock)
470 __acquires(isp1362_hcd->lock)
471{
472 urb->hcpriv = NULL;
473 ep->error_count = 0;
474
475 if (usb_pipecontrol(urb->pipe))
476 ep->nextpid = USB_PID_SETUP;
477
478 URB_DBG("%s: req %d FA %d ep%d%s %s: len %d/%d %s stat %d\n", __func__,
479 ep->num_req, usb_pipedevice(urb->pipe),
480 usb_pipeendpoint(urb->pipe),
481 !usb_pipein(urb->pipe) ? "out" : "in",
482 usb_pipecontrol(urb->pipe) ? "ctrl" :
483 usb_pipeint(urb->pipe) ? "int" :
484 usb_pipebulk(urb->pipe) ? "bulk" :
485 "iso",
486 urb->actual_length, urb->transfer_buffer_length,
487 !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
488 "short_ok" : "", urb->status);
489
490
491 usb_hcd_unlink_urb_from_ep(isp1362_hcd_to_hcd(isp1362_hcd), urb);
492 spin_unlock(&isp1362_hcd->lock);
493 usb_hcd_giveback_urb(isp1362_hcd_to_hcd(isp1362_hcd), urb, status);
494 spin_lock(&isp1362_hcd->lock);
495
496 /* take idle endpoints out of the schedule right away */
497 if (!list_empty(&ep->hep->urb_list))
498 return;
499
500 /* async deschedule */
501 if (!list_empty(&ep->schedule)) {
502 list_del_init(&ep->schedule);
503 return;
504 }
505
506
507 if (ep->interval) {
508 /* periodic deschedule */
509 DBG(1, "deschedule qh%d/%p branch %d load %d bandwidth %d -> %d\n", ep->interval,
510 ep, ep->branch, ep->load,
511 isp1362_hcd->load[ep->branch],
512 isp1362_hcd->load[ep->branch] - ep->load);
513 isp1362_hcd->load[ep->branch] -= ep->load;
514 ep->branch = PERIODIC_SIZE;
515 }
516}
517
518/*
519 * Analyze transfer results, handle partial transfers and errors
520*/
521static void postproc_ep(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep *ep)
522{
523 struct urb *urb = get_urb(ep);
524 struct usb_device *udev;
525 struct ptd *ptd;
526 int short_ok;
527 u16 len;
528 int urbstat = -EINPROGRESS;
529 u8 cc;
530
531 DBG(2, "%s: ep %p req %d\n", __func__, ep, ep->num_req);
532
533 udev = urb->dev;
534 ptd = &ep->ptd;
535 cc = PTD_GET_CC(ptd);
536 if (cc == PTD_NOTACCESSED) {
537 pr_err("%s: req %d PTD %p Untouched by ISP1362\n", __func__,
538 ep->num_req, ptd);
539 cc = PTD_DEVNOTRESP;
540 }
541
542 short_ok = !(urb->transfer_flags & URB_SHORT_NOT_OK);
543 len = urb->transfer_buffer_length - urb->actual_length;
544
545 /* Data underrun is special. For allowed underrun
546 we clear the error and continue as normal. For
547 forbidden underrun we finish the DATA stage
548 immediately while for control transfer,
549 we do a STATUS stage.
550 */
551 if (cc == PTD_DATAUNDERRUN) {
552 if (short_ok) {
553 DBG(1, "%s: req %d Allowed data underrun short_%sok %d/%d/%d byte\n",
554 __func__, ep->num_req, short_ok ? "" : "not_",
555 PTD_GET_COUNT(ptd), ep->maxpacket, len);
556 cc = PTD_CC_NOERROR;
557 urbstat = 0;
558 } else {
559 DBG(1, "%s: req %d Data Underrun %s nextpid %02x short_%sok %d/%d/%d byte\n",
560 __func__, ep->num_req,
561 usb_pipein(urb->pipe) ? "IN" : "OUT", ep->nextpid,
562 short_ok ? "" : "not_",
563 PTD_GET_COUNT(ptd), ep->maxpacket, len);
564 if (usb_pipecontrol(urb->pipe)) {
565 ep->nextpid = USB_PID_ACK;
566 /* save the data underrun error code for later and
567 * procede with the status stage
568 */
569 urb->actual_length += PTD_GET_COUNT(ptd);
570 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
571
572 if (urb->status == -EINPROGRESS)
573 urb->status = cc_to_error[PTD_DATAUNDERRUN];
574 } else {
575 usb_settoggle(udev, ep->epnum, ep->nextpid == USB_PID_OUT,
576 PTD_GET_TOGGLE(ptd));
577 urbstat = cc_to_error[PTD_DATAUNDERRUN];
578 }
579 goto out;
580 }
581 }
582
583 if (cc != PTD_CC_NOERROR) {
584 if (++ep->error_count >= 3 || cc == PTD_CC_STALL || cc == PTD_DATAOVERRUN) {
585 urbstat = cc_to_error[cc];
586 DBG(1, "%s: req %d nextpid %02x, status %d, error %d, error_count %d\n",
587 __func__, ep->num_req, ep->nextpid, urbstat, cc,
588 ep->error_count);
589 }
590 goto out;
591 }
592
593 switch (ep->nextpid) {
594 case USB_PID_OUT:
595 if (PTD_GET_COUNT(ptd) != ep->length)
596 pr_err("%s: count=%d len=%d\n", __func__,
597 PTD_GET_COUNT(ptd), ep->length);
598 BUG_ON(PTD_GET_COUNT(ptd) != ep->length);
599 urb->actual_length += ep->length;
600 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
601 usb_settoggle(udev, ep->epnum, 1, PTD_GET_TOGGLE(ptd));
602 if (urb->actual_length == urb->transfer_buffer_length) {
603 DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
604 ep->num_req, len, ep->maxpacket, urbstat);
605 if (usb_pipecontrol(urb->pipe)) {
606 DBG(3, "%s: req %d %s Wait for ACK\n", __func__,
607 ep->num_req,
608 usb_pipein(urb->pipe) ? "IN" : "OUT");
609 ep->nextpid = USB_PID_ACK;
610 } else {
611 if (len % ep->maxpacket ||
612 !(urb->transfer_flags & URB_ZERO_PACKET)) {
613 urbstat = 0;
614 DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
615 __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT",
616 urbstat, len, ep->maxpacket, urb->actual_length);
617 }
618 }
619 }
620 break;
621 case USB_PID_IN:
622 len = PTD_GET_COUNT(ptd);
623 BUG_ON(len > ep->length);
624 urb->actual_length += len;
625 BUG_ON(urb->actual_length > urb->transfer_buffer_length);
626 usb_settoggle(udev, ep->epnum, 0, PTD_GET_TOGGLE(ptd));
627 /* if transfer completed or (allowed) data underrun */
628 if ((urb->transfer_buffer_length == urb->actual_length) ||
629 len % ep->maxpacket) {
630 DBG(3, "%s: req %d xfer complete %d/%d status %d -> 0\n", __func__,
631 ep->num_req, len, ep->maxpacket, urbstat);
632 if (usb_pipecontrol(urb->pipe)) {
633 DBG(3, "%s: req %d %s Wait for ACK\n", __func__,
634 ep->num_req,
635 usb_pipein(urb->pipe) ? "IN" : "OUT");
636 ep->nextpid = USB_PID_ACK;
637 } else {
638 urbstat = 0;
639 DBG(3, "%s: req %d URB %s status %d count %d/%d/%d\n",
640 __func__, ep->num_req, usb_pipein(urb->pipe) ? "IN" : "OUT",
641 urbstat, len, ep->maxpacket, urb->actual_length);
642 }
643 }
644 break;
645 case USB_PID_SETUP:
646 if (urb->transfer_buffer_length == urb->actual_length) {
647 ep->nextpid = USB_PID_ACK;
648 } else if (usb_pipeout(urb->pipe)) {
649 usb_settoggle(udev, 0, 1, 1);
650 ep->nextpid = USB_PID_OUT;
651 } else {
652 usb_settoggle(udev, 0, 0, 1);
653 ep->nextpid = USB_PID_IN;
654 }
655 break;
656 case USB_PID_ACK:
657 DBG(3, "%s: req %d got ACK %d -> 0\n", __func__, ep->num_req,
658 urbstat);
659 WARN_ON(urbstat != -EINPROGRESS);
660 urbstat = 0;
661 ep->nextpid = 0;
662 break;
663 default:
664 BUG_ON(1);
665 }
666
667 out:
668 if (urbstat != -EINPROGRESS) {
669 DBG(2, "%s: Finishing ep %p req %d urb %p status %d\n", __func__,
670 ep, ep->num_req, urb, urbstat);
671 finish_request(isp1362_hcd, ep, urb, urbstat);
672 }
673}
674
675static void finish_unlinks(struct isp1362_hcd *isp1362_hcd)
676{
677 struct isp1362_ep *ep;
678 struct isp1362_ep *tmp;
679
680 list_for_each_entry_safe(ep, tmp, &isp1362_hcd->remove_list, remove_list) {
681 struct isp1362_ep_queue *epq =
682 get_ptd_queue(isp1362_hcd, ep->ptd_offset);
683 int index = ep->ptd_index;
684
685 BUG_ON(epq == NULL);
686 if (index >= 0) {
687 DBG(1, "%s: remove PTD[%d] $%04x\n", __func__, index, ep->ptd_offset);
688 BUG_ON(ep->num_ptds == 0);
689 release_ptd_buffers(epq, ep);
690 }
691 if (!list_empty(&ep->hep->urb_list)) {
692 struct urb *urb = get_urb(ep);
693
694 DBG(1, "%s: Finishing req %d ep %p from remove_list\n", __func__,
695 ep->num_req, ep);
696 finish_request(isp1362_hcd, ep, urb, -ESHUTDOWN);
697 }
698 WARN_ON(list_empty(&ep->active));
699 if (!list_empty(&ep->active)) {
700 list_del_init(&ep->active);
701 DBG(1, "%s: ep %p removed from active list\n", __func__, ep);
702 }
703 list_del_init(&ep->remove_list);
704 DBG(1, "%s: ep %p removed from remove_list\n", __func__, ep);
705 }
706 DBG(1, "%s: Done\n", __func__);
707}
708
709static inline void enable_atl_transfers(struct isp1362_hcd *isp1362_hcd, int count)
710{
711 if (count > 0) {
712 if (count < isp1362_hcd->atl_queue.ptd_count)
713 isp1362_write_reg16(isp1362_hcd, HCATLDTC, count);
714 isp1362_enable_int(isp1362_hcd, HCuPINT_ATL);
715 isp1362_write_reg32(isp1362_hcd, HCATLSKIP, isp1362_hcd->atl_queue.skip_map);
716 isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
717 } else
718 isp1362_enable_int(isp1362_hcd, HCuPINT_SOF);
719}
720
721static inline void enable_intl_transfers(struct isp1362_hcd *isp1362_hcd)
722{
723 isp1362_enable_int(isp1362_hcd, HCuPINT_INTL);
724 isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
725 isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, isp1362_hcd->intl_queue.skip_map);
726}
727
728static inline void enable_istl_transfers(struct isp1362_hcd *isp1362_hcd, int flip)
729{
730 isp1362_enable_int(isp1362_hcd, flip ? HCuPINT_ISTL1 : HCuPINT_ISTL0);
731 isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, flip ?
732 HCBUFSTAT_ISTL1_FULL : HCBUFSTAT_ISTL0_FULL);
733}
734
735static int submit_req(struct isp1362_hcd *isp1362_hcd, struct urb *urb,
736 struct isp1362_ep *ep, struct isp1362_ep_queue *epq)
737{
738 int index = epq->free_ptd;
739
740 prepare_ptd(isp1362_hcd, urb, ep, epq, 0);
741 index = claim_ptd_buffers(epq, ep, ep->length);
742 if (index == -ENOMEM) {
743 DBG(1, "%s: req %d No free %s PTD available: %d, %08lx:%08lx\n", __func__,
744 ep->num_req, epq->name, ep->num_ptds, epq->buf_map, epq->skip_map);
745 return index;
746 } else if (index == -EOVERFLOW) {
747 DBG(1, "%s: req %d Not enough space for %d byte %s PTD %d %08lx:%08lx\n",
748 __func__, ep->num_req, ep->length, epq->name, ep->num_ptds,
749 epq->buf_map, epq->skip_map);
750 return index;
751 } else
752 BUG_ON(index < 0);
753 list_add_tail(&ep->active, &epq->active);
754 DBG(1, "%s: ep %p req %d len %d added to active list %p\n", __func__,
755 ep, ep->num_req, ep->length, &epq->active);
756 DBG(1, "%s: Submitting %s PTD $%04x for ep %p req %d\n", __func__, epq->name,
757 ep->ptd_offset, ep, ep->num_req);
758 isp1362_write_ptd(isp1362_hcd, ep, epq);
759 __clear_bit(ep->ptd_index, &epq->skip_map);
760
761 return 0;
762}
763
764static void start_atl_transfers(struct isp1362_hcd *isp1362_hcd)
765{
766 int ptd_count = 0;
767 struct isp1362_ep_queue *epq = &isp1362_hcd->atl_queue;
768 struct isp1362_ep *ep;
769 int defer = 0;
770
771 if (atomic_read(&epq->finishing)) {
772 DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
773 return;
774 }
775
776 list_for_each_entry(ep, &isp1362_hcd->async, schedule) {
777 struct urb *urb = get_urb(ep);
778 int ret;
779
780 if (!list_empty(&ep->active)) {
781 DBG(2, "%s: Skipping active %s ep %p\n", __func__, epq->name, ep);
782 continue;
783 }
784
785 DBG(1, "%s: Processing %s ep %p req %d\n", __func__, epq->name,
786 ep, ep->num_req);
787
788 ret = submit_req(isp1362_hcd, urb, ep, epq);
789 if (ret == -ENOMEM) {
790 defer = 1;
791 break;
792 } else if (ret == -EOVERFLOW) {
793 defer = 1;
794 continue;
795 }
796#ifdef BUGGY_PXA2XX_UDC_USBTEST
797 defer = ep->nextpid == USB_PID_SETUP;
798#endif
799 ptd_count++;
800 }
801
802 /* Avoid starving of endpoints */
803 if (isp1362_hcd->async.next != isp1362_hcd->async.prev) {
804 DBG(2, "%s: Cycling ASYNC schedule %d\n", __func__, ptd_count);
805 list_move(&isp1362_hcd->async, isp1362_hcd->async.next);
806 }
807 if (ptd_count || defer)
808 enable_atl_transfers(isp1362_hcd, defer ? 0 : ptd_count);
809
810 epq->ptd_count += ptd_count;
811 if (epq->ptd_count > epq->stat_maxptds) {
812 epq->stat_maxptds = epq->ptd_count;
813 DBG(0, "%s: max_ptds: %d\n", __func__, epq->stat_maxptds);
814 }
815}
816
817static void start_intl_transfers(struct isp1362_hcd *isp1362_hcd)
818{
819 int ptd_count = 0;
820 struct isp1362_ep_queue *epq = &isp1362_hcd->intl_queue;
821 struct isp1362_ep *ep;
822
823 if (atomic_read(&epq->finishing)) {
824 DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
825 return;
826 }
827
828 list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) {
829 struct urb *urb = get_urb(ep);
830 int ret;
831
832 if (!list_empty(&ep->active)) {
833 DBG(1, "%s: Skipping active %s ep %p\n", __func__,
834 epq->name, ep);
835 continue;
836 }
837
838 DBG(1, "%s: Processing %s ep %p req %d\n", __func__,
839 epq->name, ep, ep->num_req);
840 ret = submit_req(isp1362_hcd, urb, ep, epq);
841 if (ret == -ENOMEM)
842 break;
843 else if (ret == -EOVERFLOW)
844 continue;
845 ptd_count++;
846 }
847
848 if (ptd_count) {
849 static int last_count;
850
851 if (ptd_count != last_count) {
852 DBG(0, "%s: ptd_count: %d\n", __func__, ptd_count);
853 last_count = ptd_count;
854 }
855 enable_intl_transfers(isp1362_hcd);
856 }
857
858 epq->ptd_count += ptd_count;
859 if (epq->ptd_count > epq->stat_maxptds)
860 epq->stat_maxptds = epq->ptd_count;
861}
862
863static inline int next_ptd(struct isp1362_ep_queue *epq, struct isp1362_ep *ep)
864{
865 u16 ptd_offset = ep->ptd_offset;
866 int num_ptds = (ep->length + PTD_HEADER_SIZE + (epq->blk_size - 1)) / epq->blk_size;
867
868 DBG(2, "%s: PTD offset $%04x + %04x => %d * %04x -> $%04x\n", __func__, ptd_offset,
869 ep->length, num_ptds, epq->blk_size, ptd_offset + num_ptds * epq->blk_size);
870
871 ptd_offset += num_ptds * epq->blk_size;
872 if (ptd_offset < epq->buf_start + epq->buf_size)
873 return ptd_offset;
874 else
875 return -ENOMEM;
876}
877
878static void start_iso_transfers(struct isp1362_hcd *isp1362_hcd)
879{
880 int ptd_count = 0;
881 int flip = isp1362_hcd->istl_flip;
882 struct isp1362_ep_queue *epq;
883 int ptd_offset;
884 struct isp1362_ep *ep;
885 struct isp1362_ep *tmp;
886 u16 fno = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
887
888 fill2:
889 epq = &isp1362_hcd->istl_queue[flip];
890 if (atomic_read(&epq->finishing)) {
891 DBG(1, "%s: finish_transfers is active for %s\n", __func__, epq->name);
892 return;
893 }
894
895 if (!list_empty(&epq->active))
896 return;
897
898 ptd_offset = epq->buf_start;
899 list_for_each_entry_safe(ep, tmp, &isp1362_hcd->isoc, schedule) {
900 struct urb *urb = get_urb(ep);
901 s16 diff = fno - (u16)urb->start_frame;
902
903 DBG(1, "%s: Processing %s ep %p\n", __func__, epq->name, ep);
904
905 if (diff > urb->number_of_packets) {
906 /* time frame for this URB has elapsed */
907 finish_request(isp1362_hcd, ep, urb, -EOVERFLOW);
908 continue;
909 } else if (diff < -1) {
910 /* URB is not due in this frame or the next one.
911 * Comparing with '-1' instead of '0' accounts for double
912 * buffering in the ISP1362 which enables us to queue the PTD
913 * one frame ahead of time
914 */
915 } else if (diff == -1) {
916 /* submit PTD's that are due in the next frame */
917 prepare_ptd(isp1362_hcd, urb, ep, epq, fno);
918 if (ptd_offset + PTD_HEADER_SIZE + ep->length >
919 epq->buf_start + epq->buf_size) {
920 pr_err("%s: Not enough ISO buffer space for %d byte PTD\n",
921 __func__, ep->length);
922 continue;
923 }
924 ep->ptd_offset = ptd_offset;
925 list_add_tail(&ep->active, &epq->active);
926
927 ptd_offset = next_ptd(epq, ep);
928 if (ptd_offset < 0) {
929 pr_warning("%s: req %d No more %s PTD buffers available\n", __func__,
930 ep->num_req, epq->name);
931 break;
932 }
933 }
934 }
935 list_for_each_entry(ep, &epq->active, active) {
936 if (epq->active.next == &ep->active)
937 ep->ptd.mps |= PTD_LAST_MSK;
938 isp1362_write_ptd(isp1362_hcd, ep, epq);
939 ptd_count++;
940 }
941
942 if (ptd_count)
943 enable_istl_transfers(isp1362_hcd, flip);
944
945 epq->ptd_count += ptd_count;
946 if (epq->ptd_count > epq->stat_maxptds)
947 epq->stat_maxptds = epq->ptd_count;
948
949 /* check, whether the second ISTL buffer may also be filled */
950 if (!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
951 (flip ? HCBUFSTAT_ISTL0_FULL : HCBUFSTAT_ISTL1_FULL))) {
952 fno++;
953 ptd_count = 0;
954 flip = 1 - flip;
955 goto fill2;
956 }
957}
958
959static void finish_transfers(struct isp1362_hcd *isp1362_hcd, unsigned long done_map,
960 struct isp1362_ep_queue *epq)
961{
962 struct isp1362_ep *ep;
963 struct isp1362_ep *tmp;
964
965 if (list_empty(&epq->active)) {
966 DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name);
967 return;
968 }
969
970 DBG(1, "%s: Finishing %s transfers %08lx\n", __func__, epq->name, done_map);
971
972 atomic_inc(&epq->finishing);
973 list_for_each_entry_safe(ep, tmp, &epq->active, active) {
974 int index = ep->ptd_index;
975
976 DBG(1, "%s: Checking %s PTD[%02x] $%04x\n", __func__, epq->name,
977 index, ep->ptd_offset);
978
979 BUG_ON(index < 0);
980 if (__test_and_clear_bit(index, &done_map)) {
981 isp1362_read_ptd(isp1362_hcd, ep, epq);
982 epq->free_ptd = index;
983 BUG_ON(ep->num_ptds == 0);
984 release_ptd_buffers(epq, ep);
985
986 DBG(1, "%s: ep %p req %d removed from active list\n", __func__,
987 ep, ep->num_req);
988 if (!list_empty(&ep->remove_list)) {
989 list_del_init(&ep->remove_list);
990 DBG(1, "%s: ep %p removed from remove list\n", __func__, ep);
991 }
992 DBG(1, "%s: Postprocessing %s ep %p req %d\n", __func__, epq->name,
993 ep, ep->num_req);
994 postproc_ep(isp1362_hcd, ep);
995 }
996 if (!done_map)
997 break;
998 }
999 if (done_map)
1000 pr_warning("%s: done_map not clear: %08lx:%08lx\n", __func__, done_map,
1001 epq->skip_map);
1002 atomic_dec(&epq->finishing);
1003}
1004
1005static void finish_iso_transfers(struct isp1362_hcd *isp1362_hcd, struct isp1362_ep_queue *epq)
1006{
1007 struct isp1362_ep *ep;
1008 struct isp1362_ep *tmp;
1009
1010 if (list_empty(&epq->active)) {
1011 DBG(1, "%s: Nothing to do for %s queue\n", __func__, epq->name);
1012 return;
1013 }
1014
1015 DBG(1, "%s: Finishing %s transfers\n", __func__, epq->name);
1016
1017 atomic_inc(&epq->finishing);
1018 list_for_each_entry_safe(ep, tmp, &epq->active, active) {
1019 DBG(1, "%s: Checking PTD $%04x\n", __func__, ep->ptd_offset);
1020
1021 isp1362_read_ptd(isp1362_hcd, ep, epq);
1022 DBG(1, "%s: Postprocessing %s ep %p\n", __func__, epq->name, ep);
1023 postproc_ep(isp1362_hcd, ep);
1024 }
1025 WARN_ON(epq->blk_size != 0);
1026 atomic_dec(&epq->finishing);
1027}
1028
1029static irqreturn_t isp1362_irq(struct usb_hcd *hcd)
1030{
1031 int handled = 0;
1032 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1033 u16 irqstat;
1034 u16 svc_mask;
1035
1036 spin_lock(&isp1362_hcd->lock);
1037
1038 BUG_ON(isp1362_hcd->irq_active++);
1039
1040 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
1041
1042 irqstat = isp1362_read_reg16(isp1362_hcd, HCuPINT);
1043 DBG(3, "%s: got IRQ %04x:%04x\n", __func__, irqstat, isp1362_hcd->irqenb);
1044
1045 /* only handle interrupts that are currently enabled */
1046 irqstat &= isp1362_hcd->irqenb;
1047 isp1362_write_reg16(isp1362_hcd, HCuPINT, irqstat);
1048 svc_mask = irqstat;
1049
1050 if (irqstat & HCuPINT_SOF) {
1051 isp1362_hcd->irqenb &= ~HCuPINT_SOF;
1052 isp1362_hcd->irq_stat[ISP1362_INT_SOF]++;
1053 handled = 1;
1054 svc_mask &= ~HCuPINT_SOF;
1055 DBG(3, "%s: SOF\n", __func__);
1056 isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
1057 if (!list_empty(&isp1362_hcd->remove_list))
1058 finish_unlinks(isp1362_hcd);
1059 if (!list_empty(&isp1362_hcd->async) && !(irqstat & HCuPINT_ATL)) {
1060 if (list_empty(&isp1362_hcd->atl_queue.active)) {
1061 start_atl_transfers(isp1362_hcd);
1062 } else {
1063 isp1362_enable_int(isp1362_hcd, HCuPINT_ATL);
1064 isp1362_write_reg32(isp1362_hcd, HCATLSKIP,
1065 isp1362_hcd->atl_queue.skip_map);
1066 isp1362_set_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
1067 }
1068 }
1069 }
1070
1071 if (irqstat & HCuPINT_ISTL0) {
1072 isp1362_hcd->irq_stat[ISP1362_INT_ISTL0]++;
1073 handled = 1;
1074 svc_mask &= ~HCuPINT_ISTL0;
1075 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL0_FULL);
1076 DBG(1, "%s: ISTL0\n", __func__);
1077 WARN_ON((int)!!isp1362_hcd->istl_flip);
1078 WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
1079 HCBUFSTAT_ISTL0_ACTIVE);
1080 WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
1081 HCBUFSTAT_ISTL0_DONE));
1082 isp1362_hcd->irqenb &= ~HCuPINT_ISTL0;
1083 }
1084
1085 if (irqstat & HCuPINT_ISTL1) {
1086 isp1362_hcd->irq_stat[ISP1362_INT_ISTL1]++;
1087 handled = 1;
1088 svc_mask &= ~HCuPINT_ISTL1;
1089 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ISTL1_FULL);
1090 DBG(1, "%s: ISTL1\n", __func__);
1091 WARN_ON(!(int)isp1362_hcd->istl_flip);
1092 WARN_ON(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
1093 HCBUFSTAT_ISTL1_ACTIVE);
1094 WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCBUFSTAT) &
1095 HCBUFSTAT_ISTL1_DONE));
1096 isp1362_hcd->irqenb &= ~HCuPINT_ISTL1;
1097 }
1098
1099 if (irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) {
1100 WARN_ON((irqstat & (HCuPINT_ISTL0 | HCuPINT_ISTL1)) ==
1101 (HCuPINT_ISTL0 | HCuPINT_ISTL1));
1102 finish_iso_transfers(isp1362_hcd,
1103 &isp1362_hcd->istl_queue[isp1362_hcd->istl_flip]);
1104 start_iso_transfers(isp1362_hcd);
1105 isp1362_hcd->istl_flip = 1 - isp1362_hcd->istl_flip;
1106 }
1107
1108 if (irqstat & HCuPINT_INTL) {
1109 u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE);
1110 u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCINTLSKIP);
1111 isp1362_hcd->irq_stat[ISP1362_INT_INTL]++;
1112
1113 DBG(2, "%s: INTL\n", __func__);
1114
1115 svc_mask &= ~HCuPINT_INTL;
1116
1117 isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, skip_map | done_map);
1118 if (~(done_map | skip_map) == 0)
1119 /* All PTDs are finished, disable INTL processing entirely */
1120 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_INTL_ACTIVE);
1121
1122 handled = 1;
1123 WARN_ON(!done_map);
1124 if (done_map) {
1125 DBG(3, "%s: INTL done_map %08x\n", __func__, done_map);
1126 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue);
1127 start_intl_transfers(isp1362_hcd);
1128 }
1129 }
1130
1131 if (irqstat & HCuPINT_ATL) {
1132 u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE);
1133 u32 skip_map = isp1362_read_reg32(isp1362_hcd, HCATLSKIP);
1134 isp1362_hcd->irq_stat[ISP1362_INT_ATL]++;
1135
1136 DBG(2, "%s: ATL\n", __func__);
1137
1138 svc_mask &= ~HCuPINT_ATL;
1139
1140 isp1362_write_reg32(isp1362_hcd, HCATLSKIP, skip_map | done_map);
1141 if (~(done_map | skip_map) == 0)
1142 isp1362_clr_mask16(isp1362_hcd, HCBUFSTAT, HCBUFSTAT_ATL_ACTIVE);
1143 if (done_map) {
1144 DBG(3, "%s: ATL done_map %08x\n", __func__, done_map);
1145 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue);
1146 start_atl_transfers(isp1362_hcd);
1147 }
1148 handled = 1;
1149 }
1150
1151 if (irqstat & HCuPINT_OPR) {
1152 u32 intstat = isp1362_read_reg32(isp1362_hcd, HCINTSTAT);
1153 isp1362_hcd->irq_stat[ISP1362_INT_OPR]++;
1154
1155 svc_mask &= ~HCuPINT_OPR;
1156 DBG(2, "%s: OPR %08x:%08x\n", __func__, intstat, isp1362_hcd->intenb);
1157 intstat &= isp1362_hcd->intenb;
1158 if (intstat & OHCI_INTR_UE) {
1159 pr_err("Unrecoverable error\n");
1160 /* FIXME: do here reset or cleanup or whatever */
1161 }
1162 if (intstat & OHCI_INTR_RHSC) {
1163 isp1362_hcd->rhstatus = isp1362_read_reg32(isp1362_hcd, HCRHSTATUS);
1164 isp1362_hcd->rhport[0] = isp1362_read_reg32(isp1362_hcd, HCRHPORT1);
1165 isp1362_hcd->rhport[1] = isp1362_read_reg32(isp1362_hcd, HCRHPORT2);
1166 }
1167 if (intstat & OHCI_INTR_RD) {
1168 pr_info("%s: RESUME DETECTED\n", __func__);
1169 isp1362_show_reg(isp1362_hcd, HCCONTROL);
1170 usb_hcd_resume_root_hub(hcd);
1171 }
1172 isp1362_write_reg32(isp1362_hcd, HCINTSTAT, intstat);
1173 irqstat &= ~HCuPINT_OPR;
1174 handled = 1;
1175 }
1176
1177 if (irqstat & HCuPINT_SUSP) {
1178 isp1362_hcd->irq_stat[ISP1362_INT_SUSP]++;
1179 handled = 1;
1180 svc_mask &= ~HCuPINT_SUSP;
1181
1182 pr_info("%s: SUSPEND IRQ\n", __func__);
1183 }
1184
1185 if (irqstat & HCuPINT_CLKRDY) {
1186 isp1362_hcd->irq_stat[ISP1362_INT_CLKRDY]++;
1187 handled = 1;
1188 isp1362_hcd->irqenb &= ~HCuPINT_CLKRDY;
1189 svc_mask &= ~HCuPINT_CLKRDY;
1190 pr_info("%s: CLKRDY IRQ\n", __func__);
1191 }
1192
1193 if (svc_mask)
1194 pr_err("%s: Unserviced interrupt(s) %04x\n", __func__, svc_mask);
1195
1196 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
1197 isp1362_hcd->irq_active--;
1198 spin_unlock(&isp1362_hcd->lock);
1199
1200 return IRQ_RETVAL(handled);
1201}
1202
1203/*-------------------------------------------------------------------------*/
1204
1205#define MAX_PERIODIC_LOAD 900 /* out of 1000 usec */
1206static int balance(struct isp1362_hcd *isp1362_hcd, u16 interval, u16 load)
1207{
1208 int i, branch = -ENOSPC;
1209
1210 /* search for the least loaded schedule branch of that interval
1211 * which has enough bandwidth left unreserved.
1212 */
1213 for (i = 0; i < interval; i++) {
1214 if (branch < 0 || isp1362_hcd->load[branch] > isp1362_hcd->load[i]) {
1215 int j;
1216
1217 for (j = i; j < PERIODIC_SIZE; j += interval) {
1218 if ((isp1362_hcd->load[j] + load) > MAX_PERIODIC_LOAD) {
1219 pr_err("%s: new load %d load[%02x] %d max %d\n", __func__,
1220 load, j, isp1362_hcd->load[j], MAX_PERIODIC_LOAD);
1221 break;
1222 }
1223 }
1224 if (j < PERIODIC_SIZE)
1225 continue;
1226 branch = i;
1227 }
1228 }
1229 return branch;
1230}
1231
1232/* NB! ALL the code above this point runs with isp1362_hcd->lock
1233 held, irqs off
1234*/
1235
1236/*-------------------------------------------------------------------------*/
1237
1238static int isp1362_urb_enqueue(struct usb_hcd *hcd,
1239 struct urb *urb,
1240 gfp_t mem_flags)
1241{
1242 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1243 struct usb_device *udev = urb->dev;
1244 unsigned int pipe = urb->pipe;
1245 int is_out = !usb_pipein(pipe);
1246 int type = usb_pipetype(pipe);
1247 int epnum = usb_pipeendpoint(pipe);
1248 struct usb_host_endpoint *hep = urb->ep;
1249 struct isp1362_ep *ep = NULL;
1250 unsigned long flags;
1251 int retval = 0;
1252
1253 DBG(3, "%s: urb %p\n", __func__, urb);
1254
1255 if (type == PIPE_ISOCHRONOUS) {
1256 pr_err("Isochronous transfers not supported\n");
1257 return -ENOSPC;
1258 }
1259
1260 URB_DBG("%s: FA %d ep%d%s %s: len %d %s%s\n", __func__,
1261 usb_pipedevice(pipe), epnum,
1262 is_out ? "out" : "in",
1263 usb_pipecontrol(pipe) ? "ctrl" :
1264 usb_pipeint(pipe) ? "int" :
1265 usb_pipebulk(pipe) ? "bulk" :
1266 "iso",
1267 urb->transfer_buffer_length,
1268 (urb->transfer_flags & URB_ZERO_PACKET) ? "ZERO_PACKET " : "",
1269 !(urb->transfer_flags & URB_SHORT_NOT_OK) ?
1270 "short_ok" : "");
1271
1272 /* avoid all allocations within spinlocks: request or endpoint */
1273 if (!hep->hcpriv) {
1274 ep = kcalloc(1, sizeof *ep, mem_flags);
1275 if (!ep)
1276 return -ENOMEM;
1277 }
1278 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1279
1280 /* don't submit to a dead or disabled port */
1281 if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) &
1282 (1 << USB_PORT_FEAT_ENABLE)) ||
1283 !HC_IS_RUNNING(hcd->state)) {
1284 kfree(ep);
1285 retval = -ENODEV;
1286 goto fail_not_linked;
1287 }
1288
1289 retval = usb_hcd_link_urb_to_ep(hcd, urb);
1290 if (retval) {
1291 kfree(ep);
1292 goto fail_not_linked;
1293 }
1294
1295 if (hep->hcpriv) {
1296 ep = hep->hcpriv;
1297 } else {
1298 INIT_LIST_HEAD(&ep->schedule);
1299 INIT_LIST_HEAD(&ep->active);
1300 INIT_LIST_HEAD(&ep->remove_list);
1301 ep->udev = usb_get_dev(udev);
1302 ep->hep = hep;
1303 ep->epnum = epnum;
1304 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
1305 ep->ptd_offset = -EINVAL;
1306 ep->ptd_index = -EINVAL;
1307 usb_settoggle(udev, epnum, is_out, 0);
1308
1309 if (type == PIPE_CONTROL)
1310 ep->nextpid = USB_PID_SETUP;
1311 else if (is_out)
1312 ep->nextpid = USB_PID_OUT;
1313 else
1314 ep->nextpid = USB_PID_IN;
1315
1316 switch (type) {
1317 case PIPE_ISOCHRONOUS:
1318 case PIPE_INTERRUPT:
1319 if (urb->interval > PERIODIC_SIZE)
1320 urb->interval = PERIODIC_SIZE;
1321 ep->interval = urb->interval;
1322 ep->branch = PERIODIC_SIZE;
1323 ep->load = usb_calc_bus_time(udev->speed, !is_out,
1324 (type == PIPE_ISOCHRONOUS),
1325 usb_maxpacket(udev, pipe, is_out)) / 1000;
1326 break;
1327 }
1328 hep->hcpriv = ep;
1329 }
1330 ep->num_req = isp1362_hcd->req_serial++;
1331
1332 /* maybe put endpoint into schedule */
1333 switch (type) {
1334 case PIPE_CONTROL:
1335 case PIPE_BULK:
1336 if (list_empty(&ep->schedule)) {
1337 DBG(1, "%s: Adding ep %p req %d to async schedule\n",
1338 __func__, ep, ep->num_req);
1339 list_add_tail(&ep->schedule, &isp1362_hcd->async);
1340 }
1341 break;
1342 case PIPE_ISOCHRONOUS:
1343 case PIPE_INTERRUPT:
1344 urb->interval = ep->interval;
1345
1346 /* urb submitted for already existing EP */
1347 if (ep->branch < PERIODIC_SIZE)
1348 break;
1349
1350 retval = balance(isp1362_hcd, ep->interval, ep->load);
1351 if (retval < 0) {
1352 pr_err("%s: balance returned %d\n", __func__, retval);
1353 goto fail;
1354 }
1355 ep->branch = retval;
1356 retval = 0;
1357 isp1362_hcd->fmindex = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
1358 DBG(1, "%s: Current frame %04x branch %02x start_frame %04x(%04x)\n",
1359 __func__, isp1362_hcd->fmindex, ep->branch,
1360 ((isp1362_hcd->fmindex + PERIODIC_SIZE - 1) &
1361 ~(PERIODIC_SIZE - 1)) + ep->branch,
1362 (isp1362_hcd->fmindex & (PERIODIC_SIZE - 1)) + ep->branch);
1363
1364 if (list_empty(&ep->schedule)) {
1365 if (type == PIPE_ISOCHRONOUS) {
1366 u16 frame = isp1362_hcd->fmindex;
1367
1368 frame += max_t(u16, 8, ep->interval);
1369 frame &= ~(ep->interval - 1);
1370 frame |= ep->branch;
1371 if (frame_before(frame, isp1362_hcd->fmindex))
1372 frame += ep->interval;
1373 urb->start_frame = frame;
1374
1375 DBG(1, "%s: Adding ep %p to isoc schedule\n", __func__, ep);
1376 list_add_tail(&ep->schedule, &isp1362_hcd->isoc);
1377 } else {
1378 DBG(1, "%s: Adding ep %p to periodic schedule\n", __func__, ep);
1379 list_add_tail(&ep->schedule, &isp1362_hcd->periodic);
1380 }
1381 } else
1382 DBG(1, "%s: ep %p already scheduled\n", __func__, ep);
1383
1384 DBG(2, "%s: load %d bandwidth %d -> %d\n", __func__,
1385 ep->load / ep->interval, isp1362_hcd->load[ep->branch],
1386 isp1362_hcd->load[ep->branch] + ep->load);
1387 isp1362_hcd->load[ep->branch] += ep->load;
1388 }
1389
1390 urb->hcpriv = hep;
1391 ALIGNSTAT(isp1362_hcd, urb->transfer_buffer);
1392
1393 switch (type) {
1394 case PIPE_CONTROL:
1395 case PIPE_BULK:
1396 start_atl_transfers(isp1362_hcd);
1397 break;
1398 case PIPE_INTERRUPT:
1399 start_intl_transfers(isp1362_hcd);
1400 break;
1401 case PIPE_ISOCHRONOUS:
1402 start_iso_transfers(isp1362_hcd);
1403 break;
1404 default:
1405 BUG();
1406 }
1407 fail:
1408 if (retval)
1409 usb_hcd_unlink_urb_from_ep(hcd, urb);
1410
1411
1412 fail_not_linked:
1413 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1414 if (retval)
1415 DBG(0, "%s: urb %p failed with %d\n", __func__, urb, retval);
1416 return retval;
1417}
1418
1419static int isp1362_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1420{
1421 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1422 struct usb_host_endpoint *hep;
1423 unsigned long flags;
1424 struct isp1362_ep *ep;
1425 int retval = 0;
1426
1427 DBG(3, "%s: urb %p\n", __func__, urb);
1428
1429 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1430 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
1431 if (retval)
1432 goto done;
1433
1434 hep = urb->hcpriv;
1435
1436 if (!hep) {
1437 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1438 return -EIDRM;
1439 }
1440
1441 ep = hep->hcpriv;
1442 if (ep) {
1443 /* In front of queue? */
1444 if (ep->hep->urb_list.next == &urb->urb_list) {
1445 if (!list_empty(&ep->active)) {
1446 DBG(1, "%s: urb %p ep %p req %d active PTD[%d] $%04x\n", __func__,
1447 urb, ep, ep->num_req, ep->ptd_index, ep->ptd_offset);
1448 /* disable processing and queue PTD for removal */
1449 remove_ptd(isp1362_hcd, ep);
1450 urb = NULL;
1451 }
1452 }
1453 if (urb) {
1454 DBG(1, "%s: Finishing ep %p req %d\n", __func__, ep,
1455 ep->num_req);
1456 finish_request(isp1362_hcd, ep, urb, status);
1457 } else
1458 DBG(1, "%s: urb %p active; wait4irq\n", __func__, urb);
1459 } else {
1460 pr_warning("%s: No EP in URB %p\n", __func__, urb);
1461 retval = -EINVAL;
1462 }
1463done:
1464 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1465
1466 DBG(3, "%s: exit\n", __func__);
1467
1468 return retval;
1469}
1470
1471static void isp1362_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1472{
1473 struct isp1362_ep *ep = hep->hcpriv;
1474 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1475 unsigned long flags;
1476
1477 DBG(1, "%s: ep %p\n", __func__, ep);
1478 if (!ep)
1479 return;
1480 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1481 if (!list_empty(&hep->urb_list)) {
1482 if (!list_empty(&ep->active) && list_empty(&ep->remove_list)) {
1483 DBG(1, "%s: Removing ep %p req %d PTD[%d] $%04x\n", __func__,
1484 ep, ep->num_req, ep->ptd_index, ep->ptd_offset);
1485 remove_ptd(isp1362_hcd, ep);
1486 pr_info("%s: Waiting for Interrupt to clean up\n", __func__);
1487 }
1488 }
1489 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1490 /* Wait for interrupt to clear out active list */
1491 while (!list_empty(&ep->active))
1492 msleep(1);
1493
1494 DBG(1, "%s: Freeing EP %p\n", __func__, ep);
1495
1496 usb_put_dev(ep->udev);
1497 kfree(ep);
1498 hep->hcpriv = NULL;
1499}
1500
1501static int isp1362_get_frame(struct usb_hcd *hcd)
1502{
1503 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1504 u32 fmnum;
1505 unsigned long flags;
1506
1507 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1508 fmnum = isp1362_read_reg32(isp1362_hcd, HCFMNUM);
1509 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1510
1511 return (int)fmnum;
1512}
1513
1514/*-------------------------------------------------------------------------*/
1515
1516/* Adapted from ohci-hub.c */
1517static int isp1362_hub_status_data(struct usb_hcd *hcd, char *buf)
1518{
1519 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1520 int ports, i, changed = 0;
1521 unsigned long flags;
1522
1523 if (!HC_IS_RUNNING(hcd->state))
1524 return -ESHUTDOWN;
1525
1526 /* Report no status change now, if we are scheduled to be
1527 called later */
1528 if (timer_pending(&hcd->rh_timer))
1529 return 0;
1530
1531 ports = isp1362_hcd->rhdesca & RH_A_NDP;
1532 BUG_ON(ports > 2);
1533
1534 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1535 /* init status */
1536 if (isp1362_hcd->rhstatus & (RH_HS_LPSC | RH_HS_OCIC))
1537 buf[0] = changed = 1;
1538 else
1539 buf[0] = 0;
1540
1541 for (i = 0; i < ports; i++) {
1542 u32 status = isp1362_hcd->rhport[i];
1543
1544 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC |
1545 RH_PS_OCIC | RH_PS_PRSC)) {
1546 changed = 1;
1547 buf[0] |= 1 << (i + 1);
1548 continue;
1549 }
1550
1551 if (!(status & RH_PS_CCS))
1552 continue;
1553 }
1554 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1555 return changed;
1556}
1557
1558static void isp1362_hub_descriptor(struct isp1362_hcd *isp1362_hcd,
1559 struct usb_hub_descriptor *desc)
1560{
1561 u32 reg = isp1362_hcd->rhdesca;
1562
1563 DBG(3, "%s: enter\n", __func__);
1564
1565 desc->bDescriptorType = 0x29;
1566 desc->bDescLength = 9;
1567 desc->bHubContrCurrent = 0;
1568 desc->bNbrPorts = reg & 0x3;
1569 /* Power switching, device type, overcurrent. */
1570 desc->wHubCharacteristics = cpu_to_le16((reg >> 8) & 0x1f);
1571 DBG(0, "%s: hubcharacteristics = %02x\n", __func__, cpu_to_le16((reg >> 8) & 0x1f));
1572 desc->bPwrOn2PwrGood = (reg >> 24) & 0xff;
1573 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1574 desc->bitmap[0] = desc->bNbrPorts == 1 ? 1 << 1 : 3 << 1;
1575 desc->bitmap[1] = ~0;
1576
1577 DBG(3, "%s: exit\n", __func__);
1578}
1579
1580/* Adapted from ohci-hub.c */
1581static int isp1362_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
1582 u16 wIndex, char *buf, u16 wLength)
1583{
1584 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1585 int retval = 0;
1586 unsigned long flags;
1587 unsigned long t1;
1588 int ports = isp1362_hcd->rhdesca & RH_A_NDP;
1589 u32 tmp = 0;
1590
1591 switch (typeReq) {
1592 case ClearHubFeature:
1593 DBG(0, "ClearHubFeature: ");
1594 switch (wValue) {
1595 case C_HUB_OVER_CURRENT:
1596 _DBG(0, "C_HUB_OVER_CURRENT\n");
1597 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1598 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_OCIC);
1599 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1600 case C_HUB_LOCAL_POWER:
1601 _DBG(0, "C_HUB_LOCAL_POWER\n");
1602 break;
1603 default:
1604 goto error;
1605 }
1606 break;
1607 case SetHubFeature:
1608 DBG(0, "SetHubFeature: ");
1609 switch (wValue) {
1610 case C_HUB_OVER_CURRENT:
1611 case C_HUB_LOCAL_POWER:
1612 _DBG(0, "C_HUB_OVER_CURRENT or C_HUB_LOCAL_POWER\n");
1613 break;
1614 default:
1615 goto error;
1616 }
1617 break;
1618 case GetHubDescriptor:
1619 DBG(0, "GetHubDescriptor\n");
1620 isp1362_hub_descriptor(isp1362_hcd, (struct usb_hub_descriptor *)buf);
1621 break;
1622 case GetHubStatus:
1623 DBG(0, "GetHubStatus\n");
1624 put_unaligned(cpu_to_le32(0), (__le32 *) buf);
1625 break;
1626 case GetPortStatus:
1627#ifndef VERBOSE
1628 DBG(0, "GetPortStatus\n");
1629#endif
1630 if (!wIndex || wIndex > ports)
1631 goto error;
1632 tmp = isp1362_hcd->rhport[--wIndex];
1633 put_unaligned(cpu_to_le32(tmp), (__le32 *) buf);
1634 break;
1635 case ClearPortFeature:
1636 DBG(0, "ClearPortFeature: ");
1637 if (!wIndex || wIndex > ports)
1638 goto error;
1639 wIndex--;
1640
1641 switch (wValue) {
1642 case USB_PORT_FEAT_ENABLE:
1643 _DBG(0, "USB_PORT_FEAT_ENABLE\n");
1644 tmp = RH_PS_CCS;
1645 break;
1646 case USB_PORT_FEAT_C_ENABLE:
1647 _DBG(0, "USB_PORT_FEAT_C_ENABLE\n");
1648 tmp = RH_PS_PESC;
1649 break;
1650 case USB_PORT_FEAT_SUSPEND:
1651 _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1652 tmp = RH_PS_POCI;
1653 break;
1654 case USB_PORT_FEAT_C_SUSPEND:
1655 _DBG(0, "USB_PORT_FEAT_C_SUSPEND\n");
1656 tmp = RH_PS_PSSC;
1657 break;
1658 case USB_PORT_FEAT_POWER:
1659 _DBG(0, "USB_PORT_FEAT_POWER\n");
1660 tmp = RH_PS_LSDA;
1661
1662 break;
1663 case USB_PORT_FEAT_C_CONNECTION:
1664 _DBG(0, "USB_PORT_FEAT_C_CONNECTION\n");
1665 tmp = RH_PS_CSC;
1666 break;
1667 case USB_PORT_FEAT_C_OVER_CURRENT:
1668 _DBG(0, "USB_PORT_FEAT_C_OVER_CURRENT\n");
1669 tmp = RH_PS_OCIC;
1670 break;
1671 case USB_PORT_FEAT_C_RESET:
1672 _DBG(0, "USB_PORT_FEAT_C_RESET\n");
1673 tmp = RH_PS_PRSC;
1674 break;
1675 default:
1676 goto error;
1677 }
1678
1679 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1680 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, tmp);
1681 isp1362_hcd->rhport[wIndex] =
1682 isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
1683 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1684 break;
1685 case SetPortFeature:
1686 DBG(0, "SetPortFeature: ");
1687 if (!wIndex || wIndex > ports)
1688 goto error;
1689 wIndex--;
1690 switch (wValue) {
1691 case USB_PORT_FEAT_SUSPEND:
1692 _DBG(0, "USB_PORT_FEAT_SUSPEND\n");
1693#ifdef CONFIG_USB_OTG
1694 if (ohci->hcd.self.otg_port == (wIndex + 1) &&
1695 ohci->hcd.self.b_hnp_enable) {
1696 start_hnp(ohci);
1697 break;
1698 }
1699#endif
1700 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1701 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PSS);
1702 isp1362_hcd->rhport[wIndex] =
1703 isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
1704 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1705 break;
1706 case USB_PORT_FEAT_POWER:
1707 _DBG(0, "USB_PORT_FEAT_POWER\n");
1708 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1709 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, RH_PS_PPS);
1710 isp1362_hcd->rhport[wIndex] =
1711 isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
1712 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1713 break;
1714 case USB_PORT_FEAT_RESET:
1715 _DBG(0, "USB_PORT_FEAT_RESET\n");
1716 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1717
1718 t1 = jiffies + msecs_to_jiffies(USB_RESET_WIDTH);
1719 while (time_before(jiffies, t1)) {
1720 /* spin until any current reset finishes */
1721 for (;;) {
1722 tmp = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + wIndex);
1723 if (!(tmp & RH_PS_PRS))
1724 break;
1725 udelay(500);
1726 }
1727 if (!(tmp & RH_PS_CCS))
1728 break;
1729 /* Reset lasts 10ms (claims datasheet) */
1730 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + wIndex, (RH_PS_PRS));
1731
1732 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1733 msleep(10);
1734 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1735 }
1736
1737 isp1362_hcd->rhport[wIndex] = isp1362_read_reg32(isp1362_hcd,
1738 HCRHPORT1 + wIndex);
1739 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1740 break;
1741 default:
1742 goto error;
1743 }
1744 break;
1745
1746 default:
1747 error:
1748 /* "protocol stall" on error */
1749 _DBG(0, "PROTOCOL STALL\n");
1750 retval = -EPIPE;
1751 }
1752
1753 return retval;
1754}
1755
1756#ifdef CONFIG_PM
1757static int isp1362_bus_suspend(struct usb_hcd *hcd)
1758{
1759 int status = 0;
1760 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1761 unsigned long flags;
1762
1763 if (time_before(jiffies, isp1362_hcd->next_statechange))
1764 msleep(5);
1765
1766 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1767
1768 isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
1769 switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) {
1770 case OHCI_USB_RESUME:
1771 DBG(0, "%s: resume/suspend?\n", __func__);
1772 isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS;
1773 isp1362_hcd->hc_control |= OHCI_USB_RESET;
1774 isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
1775 /* FALL THROUGH */
1776 case OHCI_USB_RESET:
1777 status = -EBUSY;
1778 pr_warning("%s: needs reinit!\n", __func__);
1779 goto done;
1780 case OHCI_USB_SUSPEND:
1781 pr_warning("%s: already suspended?\n", __func__);
1782 goto done;
1783 }
1784 DBG(0, "%s: suspend root hub\n", __func__);
1785
1786 /* First stop any processing */
1787 hcd->state = HC_STATE_QUIESCING;
1788 if (!list_empty(&isp1362_hcd->atl_queue.active) ||
1789 !list_empty(&isp1362_hcd->intl_queue.active) ||
1790 !list_empty(&isp1362_hcd->istl_queue[0] .active) ||
1791 !list_empty(&isp1362_hcd->istl_queue[1] .active)) {
1792 int limit;
1793
1794 isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0);
1795 isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0);
1796 isp1362_write_reg16(isp1362_hcd, HCBUFSTAT, 0);
1797 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
1798 isp1362_write_reg32(isp1362_hcd, HCINTSTAT, OHCI_INTR_SF);
1799
1800 DBG(0, "%s: stopping schedules ...\n", __func__);
1801 limit = 2000;
1802 while (limit > 0) {
1803 udelay(250);
1804 limit -= 250;
1805 if (isp1362_read_reg32(isp1362_hcd, HCINTSTAT) & OHCI_INTR_SF)
1806 break;
1807 }
1808 mdelay(7);
1809 if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ATL) {
1810 u32 done_map = isp1362_read_reg32(isp1362_hcd, HCATLDONE);
1811 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->atl_queue);
1812 }
1813 if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_INTL) {
1814 u32 done_map = isp1362_read_reg32(isp1362_hcd, HCINTLDONE);
1815 finish_transfers(isp1362_hcd, done_map, &isp1362_hcd->intl_queue);
1816 }
1817 if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL0)
1818 finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[0]);
1819 if (isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_ISTL1)
1820 finish_iso_transfers(isp1362_hcd, &isp1362_hcd->istl_queue[1]);
1821 }
1822 DBG(0, "%s: HCINTSTAT: %08x\n", __func__,
1823 isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
1824 isp1362_write_reg32(isp1362_hcd, HCINTSTAT,
1825 isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
1826
1827 /* Suspend hub */
1828 isp1362_hcd->hc_control = OHCI_USB_SUSPEND;
1829 isp1362_show_reg(isp1362_hcd, HCCONTROL);
1830 isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
1831 isp1362_show_reg(isp1362_hcd, HCCONTROL);
1832
1833#if 1
1834 isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
1835 if ((isp1362_hcd->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_SUSPEND) {
1836 pr_err("%s: controller won't suspend %08x\n", __func__,
1837 isp1362_hcd->hc_control);
1838 status = -EBUSY;
1839 } else
1840#endif
1841 {
1842 /* no resumes until devices finish suspending */
1843 isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(5);
1844 }
1845done:
1846 if (status == 0) {
1847 hcd->state = HC_STATE_SUSPENDED;
1848 DBG(0, "%s: HCD suspended: %08x\n", __func__,
1849 isp1362_read_reg32(isp1362_hcd, HCCONTROL));
1850 }
1851 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1852 return status;
1853}
1854
1855static int isp1362_bus_resume(struct usb_hcd *hcd)
1856{
1857 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
1858 u32 port;
1859 unsigned long flags;
1860 int status = -EINPROGRESS;
1861
1862 if (time_before(jiffies, isp1362_hcd->next_statechange))
1863 msleep(5);
1864
1865 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1866 isp1362_hcd->hc_control = isp1362_read_reg32(isp1362_hcd, HCCONTROL);
1867 pr_info("%s: HCCONTROL: %08x\n", __func__, isp1362_hcd->hc_control);
1868 if (hcd->state == HC_STATE_RESUMING) {
1869 pr_warning("%s: duplicate resume\n", __func__);
1870 status = 0;
1871 } else
1872 switch (isp1362_hcd->hc_control & OHCI_CTRL_HCFS) {
1873 case OHCI_USB_SUSPEND:
1874 DBG(0, "%s: resume root hub\n", __func__);
1875 isp1362_hcd->hc_control &= ~OHCI_CTRL_HCFS;
1876 isp1362_hcd->hc_control |= OHCI_USB_RESUME;
1877 isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
1878 break;
1879 case OHCI_USB_RESUME:
1880 /* HCFS changes sometime after INTR_RD */
1881 DBG(0, "%s: remote wakeup\n", __func__);
1882 break;
1883 case OHCI_USB_OPER:
1884 DBG(0, "%s: odd resume\n", __func__);
1885 status = 0;
1886 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1887 break;
1888 default: /* RESET, we lost power */
1889 DBG(0, "%s: root hub hardware reset\n", __func__);
1890 status = -EBUSY;
1891 }
1892 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1893 if (status == -EBUSY) {
1894 DBG(0, "%s: Restarting HC\n", __func__);
1895 isp1362_hc_stop(hcd);
1896 return isp1362_hc_start(hcd);
1897 }
1898 if (status != -EINPROGRESS)
1899 return status;
1900 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1901 port = isp1362_read_reg32(isp1362_hcd, HCRHDESCA) & RH_A_NDP;
1902 while (port--) {
1903 u32 stat = isp1362_read_reg32(isp1362_hcd, HCRHPORT1 + port);
1904
1905 /* force global, not selective, resume */
1906 if (!(stat & RH_PS_PSS)) {
1907 DBG(0, "%s: Not Resuming RH port %d\n", __func__, port);
1908 continue;
1909 }
1910 DBG(0, "%s: Resuming RH port %d\n", __func__, port);
1911 isp1362_write_reg32(isp1362_hcd, HCRHPORT1 + port, RH_PS_POCI);
1912 }
1913 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1914
1915 /* Some controllers (lucent) need extra-long delays */
1916 hcd->state = HC_STATE_RESUMING;
1917 mdelay(20 /* usb 11.5.1.10 */ + 15);
1918
1919 isp1362_hcd->hc_control = OHCI_USB_OPER;
1920 spin_lock_irqsave(&isp1362_hcd->lock, flags);
1921 isp1362_show_reg(isp1362_hcd, HCCONTROL);
1922 isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
1923 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
1924 /* TRSMRCY */
1925 msleep(10);
1926
1927 /* keep it alive for ~5x suspend + resume costs */
1928 isp1362_hcd->next_statechange = jiffies + msecs_to_jiffies(250);
1929
1930 hcd->self.root_hub->dev.power.power_state = PMSG_ON;
1931 hcd->state = HC_STATE_RUNNING;
1932 return 0;
1933}
1934#else
1935#define isp1362_bus_suspend NULL
1936#define isp1362_bus_resume NULL
1937#endif
1938
1939/*-------------------------------------------------------------------------*/
1940
1941#ifdef STUB_DEBUG_FILE
1942
1943static inline void create_debug_file(struct isp1362_hcd *isp1362_hcd)
1944{
1945}
1946static inline void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
1947{
1948}
1949
1950#else
1951
1952#include <linux/proc_fs.h>
1953#include <linux/seq_file.h>
1954
1955static void dump_irq(struct seq_file *s, char *label, u16 mask)
1956{
1957 seq_printf(s, "%-15s %04x%s%s%s%s%s%s\n", label, mask,
1958 mask & HCuPINT_CLKRDY ? " clkrdy" : "",
1959 mask & HCuPINT_SUSP ? " susp" : "",
1960 mask & HCuPINT_OPR ? " opr" : "",
1961 mask & HCuPINT_EOT ? " eot" : "",
1962 mask & HCuPINT_ATL ? " atl" : "",
1963 mask & HCuPINT_SOF ? " sof" : "");
1964}
1965
1966static void dump_int(struct seq_file *s, char *label, u32 mask)
1967{
1968 seq_printf(s, "%-15s %08x%s%s%s%s%s%s%s\n", label, mask,
1969 mask & OHCI_INTR_MIE ? " MIE" : "",
1970 mask & OHCI_INTR_RHSC ? " rhsc" : "",
1971 mask & OHCI_INTR_FNO ? " fno" : "",
1972 mask & OHCI_INTR_UE ? " ue" : "",
1973 mask & OHCI_INTR_RD ? " rd" : "",
1974 mask & OHCI_INTR_SF ? " sof" : "",
1975 mask & OHCI_INTR_SO ? " so" : "");
1976}
1977
1978static void dump_ctrl(struct seq_file *s, char *label, u32 mask)
1979{
1980 seq_printf(s, "%-15s %08x%s%s%s\n", label, mask,
1981 mask & OHCI_CTRL_RWC ? " rwc" : "",
1982 mask & OHCI_CTRL_RWE ? " rwe" : "",
1983 ({
1984 char *hcfs;
1985 switch (mask & OHCI_CTRL_HCFS) {
1986 case OHCI_USB_OPER:
1987 hcfs = " oper";
1988 break;
1989 case OHCI_USB_RESET:
1990 hcfs = " reset";
1991 break;
1992 case OHCI_USB_RESUME:
1993 hcfs = " resume";
1994 break;
1995 case OHCI_USB_SUSPEND:
1996 hcfs = " suspend";
1997 break;
1998 default:
1999 hcfs = " ?";
2000 }
2001 hcfs;
2002 }));
2003}
2004
2005static void dump_regs(struct seq_file *s, struct isp1362_hcd *isp1362_hcd)
2006{
2007 seq_printf(s, "HCREVISION [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCREVISION),
2008 isp1362_read_reg32(isp1362_hcd, HCREVISION));
2009 seq_printf(s, "HCCONTROL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCONTROL),
2010 isp1362_read_reg32(isp1362_hcd, HCCONTROL));
2011 seq_printf(s, "HCCMDSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCCMDSTAT),
2012 isp1362_read_reg32(isp1362_hcd, HCCMDSTAT));
2013 seq_printf(s, "HCINTSTAT [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTSTAT),
2014 isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
2015 seq_printf(s, "HCINTENB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTENB),
2016 isp1362_read_reg32(isp1362_hcd, HCINTENB));
2017 seq_printf(s, "HCFMINTVL [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMINTVL),
2018 isp1362_read_reg32(isp1362_hcd, HCFMINTVL));
2019 seq_printf(s, "HCFMREM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMREM),
2020 isp1362_read_reg32(isp1362_hcd, HCFMREM));
2021 seq_printf(s, "HCFMNUM [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCFMNUM),
2022 isp1362_read_reg32(isp1362_hcd, HCFMNUM));
2023 seq_printf(s, "HCLSTHRESH [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCLSTHRESH),
2024 isp1362_read_reg32(isp1362_hcd, HCLSTHRESH));
2025 seq_printf(s, "HCRHDESCA [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCA),
2026 isp1362_read_reg32(isp1362_hcd, HCRHDESCA));
2027 seq_printf(s, "HCRHDESCB [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHDESCB),
2028 isp1362_read_reg32(isp1362_hcd, HCRHDESCB));
2029 seq_printf(s, "HCRHSTATUS [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHSTATUS),
2030 isp1362_read_reg32(isp1362_hcd, HCRHSTATUS));
2031 seq_printf(s, "HCRHPORT1 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT1),
2032 isp1362_read_reg32(isp1362_hcd, HCRHPORT1));
2033 seq_printf(s, "HCRHPORT2 [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCRHPORT2),
2034 isp1362_read_reg32(isp1362_hcd, HCRHPORT2));
2035 seq_printf(s, "\n");
2036 seq_printf(s, "HCHWCFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCHWCFG),
2037 isp1362_read_reg16(isp1362_hcd, HCHWCFG));
2038 seq_printf(s, "HCDMACFG [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCDMACFG),
2039 isp1362_read_reg16(isp1362_hcd, HCDMACFG));
2040 seq_printf(s, "HCXFERCTR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCXFERCTR),
2041 isp1362_read_reg16(isp1362_hcd, HCXFERCTR));
2042 seq_printf(s, "HCuPINT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINT),
2043 isp1362_read_reg16(isp1362_hcd, HCuPINT));
2044 seq_printf(s, "HCuPINTENB [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCuPINTENB),
2045 isp1362_read_reg16(isp1362_hcd, HCuPINTENB));
2046 seq_printf(s, "HCCHIPID [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCCHIPID),
2047 isp1362_read_reg16(isp1362_hcd, HCCHIPID));
2048 seq_printf(s, "HCSCRATCH [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCSCRATCH),
2049 isp1362_read_reg16(isp1362_hcd, HCSCRATCH));
2050 seq_printf(s, "HCBUFSTAT [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCBUFSTAT),
2051 isp1362_read_reg16(isp1362_hcd, HCBUFSTAT));
2052 seq_printf(s, "HCDIRADDR [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCDIRADDR),
2053 isp1362_read_reg32(isp1362_hcd, HCDIRADDR));
2054#if 0
2055 seq_printf(s, "HCDIRDATA [%02x] %04x\n", ISP1362_REG_NO(HCDIRDATA),
2056 isp1362_read_reg16(isp1362_hcd, HCDIRDATA));
2057#endif
2058 seq_printf(s, "HCISTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLBUFSZ),
2059 isp1362_read_reg16(isp1362_hcd, HCISTLBUFSZ));
2060 seq_printf(s, "HCISTLRATE [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCISTLRATE),
2061 isp1362_read_reg16(isp1362_hcd, HCISTLRATE));
2062 seq_printf(s, "\n");
2063 seq_printf(s, "HCINTLBUFSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBUFSZ),
2064 isp1362_read_reg16(isp1362_hcd, HCINTLBUFSZ));
2065 seq_printf(s, "HCINTLBLKSZ[%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLBLKSZ),
2066 isp1362_read_reg16(isp1362_hcd, HCINTLBLKSZ));
2067 seq_printf(s, "HCINTLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLDONE),
2068 isp1362_read_reg32(isp1362_hcd, HCINTLDONE));
2069 seq_printf(s, "HCINTLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLSKIP),
2070 isp1362_read_reg32(isp1362_hcd, HCINTLSKIP));
2071 seq_printf(s, "HCINTLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLLAST),
2072 isp1362_read_reg32(isp1362_hcd, HCINTLLAST));
2073 seq_printf(s, "HCINTLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCINTLCURR),
2074 isp1362_read_reg16(isp1362_hcd, HCINTLCURR));
2075 seq_printf(s, "\n");
2076 seq_printf(s, "HCATLBUFSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBUFSZ),
2077 isp1362_read_reg16(isp1362_hcd, HCATLBUFSZ));
2078 seq_printf(s, "HCATLBLKSZ [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLBLKSZ),
2079 isp1362_read_reg16(isp1362_hcd, HCATLBLKSZ));
2080#if 0
2081 seq_printf(s, "HCATLDONE [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDONE),
2082 isp1362_read_reg32(isp1362_hcd, HCATLDONE));
2083#endif
2084 seq_printf(s, "HCATLSKIP [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLSKIP),
2085 isp1362_read_reg32(isp1362_hcd, HCATLSKIP));
2086 seq_printf(s, "HCATLLAST [%02x] %08x\n", ISP1362_REG_NO(ISP1362_REG_HCATLLAST),
2087 isp1362_read_reg32(isp1362_hcd, HCATLLAST));
2088 seq_printf(s, "HCATLCURR [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLCURR),
2089 isp1362_read_reg16(isp1362_hcd, HCATLCURR));
2090 seq_printf(s, "\n");
2091 seq_printf(s, "HCATLDTC [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTC),
2092 isp1362_read_reg16(isp1362_hcd, HCATLDTC));
2093 seq_printf(s, "HCATLDTCTO [%02x] %04x\n", ISP1362_REG_NO(ISP1362_REG_HCATLDTCTO),
2094 isp1362_read_reg16(isp1362_hcd, HCATLDTCTO));
2095}
2096
2097static int proc_isp1362_show(struct seq_file *s, void *unused)
2098{
2099 struct isp1362_hcd *isp1362_hcd = s->private;
2100 struct isp1362_ep *ep;
2101 int i;
2102
2103 seq_printf(s, "%s\n%s version %s\n",
2104 isp1362_hcd_to_hcd(isp1362_hcd)->product_desc, hcd_name, DRIVER_VERSION);
2105
2106 /* collect statistics to help estimate potential win for
2107 * DMA engines that care about alignment (PXA)
2108 */
2109 seq_printf(s, "alignment: 16b/%ld 8b/%ld 4b/%ld 2b/%ld 1b/%ld\n",
2110 isp1362_hcd->stat16, isp1362_hcd->stat8, isp1362_hcd->stat4,
2111 isp1362_hcd->stat2, isp1362_hcd->stat1);
2112 seq_printf(s, "max # ptds in ATL fifo: %d\n", isp1362_hcd->atl_queue.stat_maxptds);
2113 seq_printf(s, "max # ptds in INTL fifo: %d\n", isp1362_hcd->intl_queue.stat_maxptds);
2114 seq_printf(s, "max # ptds in ISTL fifo: %d\n",
2115 max(isp1362_hcd->istl_queue[0] .stat_maxptds,
2116 isp1362_hcd->istl_queue[1] .stat_maxptds));
2117
2118 /* FIXME: don't show the following in suspended state */
2119 spin_lock_irq(&isp1362_hcd->lock);
2120
2121 dump_irq(s, "hc_irq_enable", isp1362_read_reg16(isp1362_hcd, HCuPINTENB));
2122 dump_irq(s, "hc_irq_status", isp1362_read_reg16(isp1362_hcd, HCuPINT));
2123 dump_int(s, "ohci_int_enable", isp1362_read_reg32(isp1362_hcd, HCINTENB));
2124 dump_int(s, "ohci_int_status", isp1362_read_reg32(isp1362_hcd, HCINTSTAT));
2125 dump_ctrl(s, "ohci_control", isp1362_read_reg32(isp1362_hcd, HCCONTROL));
2126
2127 for (i = 0; i < NUM_ISP1362_IRQS; i++)
2128 if (isp1362_hcd->irq_stat[i])
2129 seq_printf(s, "%-15s: %d\n",
2130 ISP1362_INT_NAME(i), isp1362_hcd->irq_stat[i]);
2131
2132 dump_regs(s, isp1362_hcd);
2133 list_for_each_entry(ep, &isp1362_hcd->async, schedule) {
2134 struct urb *urb;
2135
2136 seq_printf(s, "%p, ep%d%s, maxpacket %d:\n", ep, ep->epnum,
2137 ({
2138 char *s;
2139 switch (ep->nextpid) {
2140 case USB_PID_IN:
2141 s = "in";
2142 break;
2143 case USB_PID_OUT:
2144 s = "out";
2145 break;
2146 case USB_PID_SETUP:
2147 s = "setup";
2148 break;
2149 case USB_PID_ACK:
2150 s = "status";
2151 break;
2152 default:
2153 s = "?";
2154 break;
2155 };
2156 s;}), ep->maxpacket) ;
2157 list_for_each_entry(urb, &ep->hep->urb_list, urb_list) {
2158 seq_printf(s, " urb%p, %d/%d\n", urb,
2159 urb->actual_length,
2160 urb->transfer_buffer_length);
2161 }
2162 }
2163 if (!list_empty(&isp1362_hcd->async))
2164 seq_printf(s, "\n");
2165 dump_ptd_queue(&isp1362_hcd->atl_queue);
2166
2167 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
2168
2169 list_for_each_entry(ep, &isp1362_hcd->periodic, schedule) {
2170 seq_printf(s, "branch:%2d load:%3d PTD[%d] $%04x:\n", ep->branch,
2171 isp1362_hcd->load[ep->branch], ep->ptd_index, ep->ptd_offset);
2172
2173 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
2174 ep->interval, ep,
2175 (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ",
2176 ep->udev->devnum, ep->epnum,
2177 (ep->epnum == 0) ? "" :
2178 ((ep->nextpid == USB_PID_IN) ?
2179 "in" : "out"), ep->maxpacket);
2180 }
2181 dump_ptd_queue(&isp1362_hcd->intl_queue);
2182
2183 seq_printf(s, "ISO:\n");
2184
2185 list_for_each_entry(ep, &isp1362_hcd->isoc, schedule) {
2186 seq_printf(s, " %d/%p (%sdev%d ep%d%s max %d)\n",
2187 ep->interval, ep,
2188 (ep->udev->speed == USB_SPEED_FULL) ? "" : "ls ",
2189 ep->udev->devnum, ep->epnum,
2190 (ep->epnum == 0) ? "" :
2191 ((ep->nextpid == USB_PID_IN) ?
2192 "in" : "out"), ep->maxpacket);
2193 }
2194
2195 spin_unlock_irq(&isp1362_hcd->lock);
2196 seq_printf(s, "\n");
2197
2198 return 0;
2199}
2200
2201static int proc_isp1362_open(struct inode *inode, struct file *file)
2202{
2203 return single_open(file, proc_isp1362_show, PDE(inode)->data);
2204}
2205
2206static const struct file_operations proc_ops = {
2207 .open = proc_isp1362_open,
2208 .read = seq_read,
2209 .llseek = seq_lseek,
2210 .release = single_release,
2211};
2212
2213/* expect just one isp1362_hcd per system */
2214static const char proc_filename[] = "driver/isp1362";
2215
2216static void create_debug_file(struct isp1362_hcd *isp1362_hcd)
2217{
2218 struct proc_dir_entry *pde;
2219
2220 pde = create_proc_entry(proc_filename, 0, NULL);
2221 if (pde == NULL) {
2222 pr_warning("%s: Failed to create debug file '%s'\n", __func__, proc_filename);
2223 return;
2224 }
2225
2226 pde->proc_fops = &proc_ops;
2227 pde->data = isp1362_hcd;
2228 isp1362_hcd->pde = pde;
2229}
2230
2231static void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
2232{
2233 if (isp1362_hcd->pde)
2234 remove_proc_entry(proc_filename, 0);
2235}
2236
2237#endif
2238
2239/*-------------------------------------------------------------------------*/
2240
2241static void isp1362_sw_reset(struct isp1362_hcd *isp1362_hcd)
2242{
2243 int tmp = 20;
2244 unsigned long flags;
2245
2246 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2247
2248 isp1362_write_reg16(isp1362_hcd, HCSWRES, HCSWRES_MAGIC);
2249 isp1362_write_reg32(isp1362_hcd, HCCMDSTAT, OHCI_HCR);
2250 while (--tmp) {
2251 mdelay(1);
2252 if (!(isp1362_read_reg32(isp1362_hcd, HCCMDSTAT) & OHCI_HCR))
2253 break;
2254 }
2255 if (!tmp)
2256 pr_err("Software reset timeout\n");
2257 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2258}
2259
2260static int isp1362_mem_config(struct usb_hcd *hcd)
2261{
2262 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2263 unsigned long flags;
2264 u32 total;
2265 u16 istl_size = ISP1362_ISTL_BUFSIZE;
2266 u16 intl_blksize = ISP1362_INTL_BLKSIZE + PTD_HEADER_SIZE;
2267 u16 intl_size = ISP1362_INTL_BUFFERS * intl_blksize;
2268 u16 atl_blksize = ISP1362_ATL_BLKSIZE + PTD_HEADER_SIZE;
2269 u16 atl_buffers = (ISP1362_BUF_SIZE - (istl_size + intl_size)) / atl_blksize;
2270 u16 atl_size;
2271 int i;
2272
2273 WARN_ON(istl_size & 3);
2274 WARN_ON(atl_blksize & 3);
2275 WARN_ON(intl_blksize & 3);
2276 WARN_ON(atl_blksize < PTD_HEADER_SIZE);
2277 WARN_ON(intl_blksize < PTD_HEADER_SIZE);
2278
2279 BUG_ON((unsigned)ISP1362_INTL_BUFFERS > 32);
2280 if (atl_buffers > 32)
2281 atl_buffers = 32;
2282 atl_size = atl_buffers * atl_blksize;
2283 total = atl_size + intl_size + istl_size;
2284 dev_info(hcd->self.controller, "ISP1362 Memory usage:\n");
2285 dev_info(hcd->self.controller, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n",
2286 istl_size / 2, istl_size, 0, istl_size / 2);
2287 dev_info(hcd->self.controller, " INTL: %4d * (%3u+8): %4d @ $%04x\n",
2288 ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE,
2289 intl_size, istl_size);
2290 dev_info(hcd->self.controller, " ATL : %4d * (%3u+8): %4d @ $%04x\n",
2291 atl_buffers, atl_blksize - PTD_HEADER_SIZE,
2292 atl_size, istl_size + intl_size);
2293 dev_info(hcd->self.controller, " USED/FREE: %4d %4d\n", total,
2294 ISP1362_BUF_SIZE - total);
2295
2296 if (total > ISP1362_BUF_SIZE) {
2297 dev_err(hcd->self.controller, "%s: Memory requested: %d, available %d\n",
2298 __func__, total, ISP1362_BUF_SIZE);
2299 return -ENOMEM;
2300 }
2301
2302 total = istl_size + intl_size + atl_size;
2303 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2304
2305 for (i = 0; i < 2; i++) {
2306 isp1362_hcd->istl_queue[i].buf_start = i * istl_size / 2,
2307 isp1362_hcd->istl_queue[i].buf_size = istl_size / 2;
2308 isp1362_hcd->istl_queue[i].blk_size = 4;
2309 INIT_LIST_HEAD(&isp1362_hcd->istl_queue[i].active);
2310 snprintf(isp1362_hcd->istl_queue[i].name,
2311 sizeof(isp1362_hcd->istl_queue[i].name), "ISTL%d", i);
2312 DBG(3, "%s: %5s buf $%04x %d\n", __func__,
2313 isp1362_hcd->istl_queue[i].name,
2314 isp1362_hcd->istl_queue[i].buf_start,
2315 isp1362_hcd->istl_queue[i].buf_size);
2316 }
2317 isp1362_write_reg16(isp1362_hcd, HCISTLBUFSZ, istl_size / 2);
2318
2319 isp1362_hcd->intl_queue.buf_start = istl_size;
2320 isp1362_hcd->intl_queue.buf_size = intl_size;
2321 isp1362_hcd->intl_queue.buf_count = ISP1362_INTL_BUFFERS;
2322 isp1362_hcd->intl_queue.blk_size = intl_blksize;
2323 isp1362_hcd->intl_queue.buf_avail = isp1362_hcd->intl_queue.buf_count;
2324 isp1362_hcd->intl_queue.skip_map = ~0;
2325 INIT_LIST_HEAD(&isp1362_hcd->intl_queue.active);
2326
2327 isp1362_write_reg16(isp1362_hcd, HCINTLBUFSZ,
2328 isp1362_hcd->intl_queue.buf_size);
2329 isp1362_write_reg16(isp1362_hcd, HCINTLBLKSZ,
2330 isp1362_hcd->intl_queue.blk_size - PTD_HEADER_SIZE);
2331 isp1362_write_reg32(isp1362_hcd, HCINTLSKIP, ~0);
2332 isp1362_write_reg32(isp1362_hcd, HCINTLLAST,
2333 1 << (ISP1362_INTL_BUFFERS - 1));
2334
2335 isp1362_hcd->atl_queue.buf_start = istl_size + intl_size;
2336 isp1362_hcd->atl_queue.buf_size = atl_size;
2337 isp1362_hcd->atl_queue.buf_count = atl_buffers;
2338 isp1362_hcd->atl_queue.blk_size = atl_blksize;
2339 isp1362_hcd->atl_queue.buf_avail = isp1362_hcd->atl_queue.buf_count;
2340 isp1362_hcd->atl_queue.skip_map = ~0;
2341 INIT_LIST_HEAD(&isp1362_hcd->atl_queue.active);
2342
2343 isp1362_write_reg16(isp1362_hcd, HCATLBUFSZ,
2344 isp1362_hcd->atl_queue.buf_size);
2345 isp1362_write_reg16(isp1362_hcd, HCATLBLKSZ,
2346 isp1362_hcd->atl_queue.blk_size - PTD_HEADER_SIZE);
2347 isp1362_write_reg32(isp1362_hcd, HCATLSKIP, ~0);
2348 isp1362_write_reg32(isp1362_hcd, HCATLLAST,
2349 1 << (atl_buffers - 1));
2350
2351 snprintf(isp1362_hcd->atl_queue.name,
2352 sizeof(isp1362_hcd->atl_queue.name), "ATL");
2353 snprintf(isp1362_hcd->intl_queue.name,
2354 sizeof(isp1362_hcd->intl_queue.name), "INTL");
2355 DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
2356 isp1362_hcd->intl_queue.name,
2357 isp1362_hcd->intl_queue.buf_start,
2358 ISP1362_INTL_BUFFERS, isp1362_hcd->intl_queue.blk_size,
2359 isp1362_hcd->intl_queue.buf_size);
2360 DBG(3, "%s: %5s buf $%04x %2d * %4d = %4d\n", __func__,
2361 isp1362_hcd->atl_queue.name,
2362 isp1362_hcd->atl_queue.buf_start,
2363 atl_buffers, isp1362_hcd->atl_queue.blk_size,
2364 isp1362_hcd->atl_queue.buf_size);
2365
2366 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2367
2368 return 0;
2369}
2370
2371static int isp1362_hc_reset(struct usb_hcd *hcd)
2372{
2373 int ret = 0;
2374 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2375 unsigned long t;
2376 unsigned long timeout = 100;
2377 unsigned long flags;
2378 int clkrdy = 0;
2379
2380 pr_info("%s:\n", __func__);
2381
2382 if (isp1362_hcd->board && isp1362_hcd->board->reset) {
2383 isp1362_hcd->board->reset(hcd->self.controller, 1);
2384 msleep(20);
2385 if (isp1362_hcd->board->clock)
2386 isp1362_hcd->board->clock(hcd->self.controller, 1);
2387 isp1362_hcd->board->reset(hcd->self.controller, 0);
2388 } else
2389 isp1362_sw_reset(isp1362_hcd);
2390
2391 /* chip has been reset. First we need to see a clock */
2392 t = jiffies + msecs_to_jiffies(timeout);
2393 while (!clkrdy && time_before_eq(jiffies, t)) {
2394 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2395 clkrdy = isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_CLKRDY;
2396 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2397 if (!clkrdy)
2398 msleep(4);
2399 }
2400
2401 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2402 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_CLKRDY);
2403 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2404 if (!clkrdy) {
2405 pr_err("Clock not ready after %lums\n", timeout);
2406 ret = -ENODEV;
2407 }
2408 return ret;
2409}
2410
2411static void isp1362_hc_stop(struct usb_hcd *hcd)
2412{
2413 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2414 unsigned long flags;
2415 u32 tmp;
2416
2417 pr_info("%s:\n", __func__);
2418
2419 del_timer_sync(&hcd->rh_timer);
2420
2421 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2422
2423 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
2424
2425 /* Switch off power for all ports */
2426 tmp = isp1362_read_reg32(isp1362_hcd, HCRHDESCA);
2427 tmp &= ~(RH_A_NPS | RH_A_PSM);
2428 isp1362_write_reg32(isp1362_hcd, HCRHDESCA, tmp);
2429 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS);
2430
2431 /* Reset the chip */
2432 if (isp1362_hcd->board && isp1362_hcd->board->reset)
2433 isp1362_hcd->board->reset(hcd->self.controller, 1);
2434 else
2435 isp1362_sw_reset(isp1362_hcd);
2436
2437 if (isp1362_hcd->board && isp1362_hcd->board->clock)
2438 isp1362_hcd->board->clock(hcd->self.controller, 0);
2439
2440 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2441}
2442
2443#ifdef CHIP_BUFFER_TEST
2444static int isp1362_chip_test(struct isp1362_hcd *isp1362_hcd)
2445{
2446 int ret = 0;
2447 u16 *ref;
2448 unsigned long flags;
2449
2450 ref = kmalloc(2 * ISP1362_BUF_SIZE, GFP_KERNEL);
2451 if (ref) {
2452 int offset;
2453 u16 *tst = &ref[ISP1362_BUF_SIZE / 2];
2454
2455 for (offset = 0; offset < ISP1362_BUF_SIZE / 2; offset++) {
2456 ref[offset] = ~offset;
2457 tst[offset] = offset;
2458 }
2459
2460 for (offset = 0; offset < 4; offset++) {
2461 int j;
2462
2463 for (j = 0; j < 8; j++) {
2464 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2465 isp1362_write_buffer(isp1362_hcd, (u8 *)ref + offset, 0, j);
2466 isp1362_read_buffer(isp1362_hcd, (u8 *)tst + offset, 0, j);
2467 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2468
2469 if (memcmp(ref, tst, j)) {
2470 ret = -ENODEV;
2471 pr_err("%s: memory check with %d byte offset %d failed\n",
2472 __func__, j, offset);
2473 dump_data((u8 *)ref + offset, j);
2474 dump_data((u8 *)tst + offset, j);
2475 }
2476 }
2477 }
2478
2479 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2480 isp1362_write_buffer(isp1362_hcd, ref, 0, ISP1362_BUF_SIZE);
2481 isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
2482 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2483
2484 if (memcmp(ref, tst, ISP1362_BUF_SIZE)) {
2485 ret = -ENODEV;
2486 pr_err("%s: memory check failed\n", __func__);
2487 dump_data((u8 *)tst, ISP1362_BUF_SIZE / 2);
2488 }
2489
2490 for (offset = 0; offset < 256; offset++) {
2491 int test_size = 0;
2492
2493 yield();
2494
2495 memset(tst, 0, ISP1362_BUF_SIZE);
2496 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2497 isp1362_write_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
2498 isp1362_read_buffer(isp1362_hcd, tst, 0, ISP1362_BUF_SIZE);
2499 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2500 if (memcmp(tst, tst + (ISP1362_BUF_SIZE / (2 * sizeof(*tst))),
2501 ISP1362_BUF_SIZE / 2)) {
2502 pr_err("%s: Failed to clear buffer\n", __func__);
2503 dump_data((u8 *)tst, ISP1362_BUF_SIZE);
2504 break;
2505 }
2506 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2507 isp1362_write_buffer(isp1362_hcd, ref, offset * 2, PTD_HEADER_SIZE);
2508 isp1362_write_buffer(isp1362_hcd, ref + PTD_HEADER_SIZE / sizeof(*ref),
2509 offset * 2 + PTD_HEADER_SIZE, test_size);
2510 isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
2511 PTD_HEADER_SIZE + test_size);
2512 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2513 if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
2514 dump_data(((u8 *)ref) + offset, PTD_HEADER_SIZE + test_size);
2515 dump_data((u8 *)tst, PTD_HEADER_SIZE + test_size);
2516 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2517 isp1362_read_buffer(isp1362_hcd, tst, offset * 2,
2518 PTD_HEADER_SIZE + test_size);
2519 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2520 if (memcmp(ref, tst, PTD_HEADER_SIZE + test_size)) {
2521 ret = -ENODEV;
2522 pr_err("%s: memory check with offset %02x failed\n",
2523 __func__, offset);
2524 break;
2525 }
2526 pr_warning("%s: memory check with offset %02x ok after second read\n",
2527 __func__, offset);
2528 }
2529 }
2530 kfree(ref);
2531 }
2532 return ret;
2533}
2534#endif
2535
2536static int isp1362_hc_start(struct usb_hcd *hcd)
2537{
2538 int ret;
2539 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2540 struct isp1362_platform_data *board = isp1362_hcd->board;
2541 u16 hwcfg;
2542 u16 chipid;
2543 unsigned long flags;
2544
2545 pr_info("%s:\n", __func__);
2546
2547 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2548 chipid = isp1362_read_reg16(isp1362_hcd, HCCHIPID);
2549 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2550
2551 if ((chipid & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
2552 pr_err("%s: Invalid chip ID %04x\n", __func__, chipid);
2553 return -ENODEV;
2554 }
2555
2556#ifdef CHIP_BUFFER_TEST
2557 ret = isp1362_chip_test(isp1362_hcd);
2558 if (ret)
2559 return -ENODEV;
2560#endif
2561 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2562 /* clear interrupt status and disable all interrupt sources */
2563 isp1362_write_reg16(isp1362_hcd, HCuPINT, 0xff);
2564 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, 0);
2565
2566 /* HW conf */
2567 hwcfg = HCHWCFG_INT_ENABLE | HCHWCFG_DBWIDTH(1);
2568 if (board->sel15Kres)
2569 hwcfg |= HCHWCFG_PULLDOWN_DS2 |
2570 ((MAX_ROOT_PORTS > 1) ? HCHWCFG_PULLDOWN_DS1 : 0);
2571 if (board->clknotstop)
2572 hwcfg |= HCHWCFG_CLKNOTSTOP;
2573 if (board->oc_enable)
2574 hwcfg |= HCHWCFG_ANALOG_OC;
2575 if (board->int_act_high)
2576 hwcfg |= HCHWCFG_INT_POL;
2577 if (board->int_edge_triggered)
2578 hwcfg |= HCHWCFG_INT_TRIGGER;
2579 if (board->dreq_act_high)
2580 hwcfg |= HCHWCFG_DREQ_POL;
2581 if (board->dack_act_high)
2582 hwcfg |= HCHWCFG_DACK_POL;
2583 isp1362_write_reg16(isp1362_hcd, HCHWCFG, hwcfg);
2584 isp1362_show_reg(isp1362_hcd, HCHWCFG);
2585 isp1362_write_reg16(isp1362_hcd, HCDMACFG, 0);
2586 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2587
2588 ret = isp1362_mem_config(hcd);
2589 if (ret)
2590 return ret;
2591
2592 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2593
2594 /* Root hub conf */
2595 isp1362_hcd->rhdesca = 0;
2596 if (board->no_power_switching)
2597 isp1362_hcd->rhdesca |= RH_A_NPS;
2598 if (board->power_switching_mode)
2599 isp1362_hcd->rhdesca |= RH_A_PSM;
2600 if (board->potpg)
2601 isp1362_hcd->rhdesca |= (board->potpg << 24) & RH_A_POTPGT;
2602 else
2603 isp1362_hcd->rhdesca |= (25 << 24) & RH_A_POTPGT;
2604
2605 isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca & ~RH_A_OCPM);
2606 isp1362_write_reg32(isp1362_hcd, HCRHDESCA, isp1362_hcd->rhdesca | RH_A_OCPM);
2607 isp1362_hcd->rhdesca = isp1362_read_reg32(isp1362_hcd, HCRHDESCA);
2608
2609 isp1362_hcd->rhdescb = RH_B_PPCM;
2610 isp1362_write_reg32(isp1362_hcd, HCRHDESCB, isp1362_hcd->rhdescb);
2611 isp1362_hcd->rhdescb = isp1362_read_reg32(isp1362_hcd, HCRHDESCB);
2612
2613 isp1362_read_reg32(isp1362_hcd, HCFMINTVL);
2614 isp1362_write_reg32(isp1362_hcd, HCFMINTVL, (FSMP(FI) << 16) | FI);
2615 isp1362_write_reg32(isp1362_hcd, HCLSTHRESH, LSTHRESH);
2616
2617 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2618
2619 isp1362_hcd->hc_control = OHCI_USB_OPER;
2620 hcd->state = HC_STATE_RUNNING;
2621
2622 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2623 /* Set up interrupts */
2624 isp1362_hcd->intenb = OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE;
2625 isp1362_hcd->intenb |= OHCI_INTR_RD;
2626 isp1362_hcd->irqenb = HCuPINT_OPR | HCuPINT_SUSP;
2627 isp1362_write_reg32(isp1362_hcd, HCINTENB, isp1362_hcd->intenb);
2628 isp1362_write_reg16(isp1362_hcd, HCuPINTENB, isp1362_hcd->irqenb);
2629
2630 /* Go operational */
2631 isp1362_write_reg32(isp1362_hcd, HCCONTROL, isp1362_hcd->hc_control);
2632 /* enable global power */
2633 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC | RH_HS_DRWE);
2634
2635 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2636
2637 return 0;
2638}
2639
2640/*-------------------------------------------------------------------------*/
2641
2642static struct hc_driver isp1362_hc_driver = {
2643 .description = hcd_name,
2644 .product_desc = "ISP1362 Host Controller",
2645 .hcd_priv_size = sizeof(struct isp1362_hcd),
2646
2647 .irq = isp1362_irq,
2648 .flags = HCD_USB11 | HCD_MEMORY,
2649
2650 .reset = isp1362_hc_reset,
2651 .start = isp1362_hc_start,
2652 .stop = isp1362_hc_stop,
2653
2654 .urb_enqueue = isp1362_urb_enqueue,
2655 .urb_dequeue = isp1362_urb_dequeue,
2656 .endpoint_disable = isp1362_endpoint_disable,
2657
2658 .get_frame_number = isp1362_get_frame,
2659
2660 .hub_status_data = isp1362_hub_status_data,
2661 .hub_control = isp1362_hub_control,
2662 .bus_suspend = isp1362_bus_suspend,
2663 .bus_resume = isp1362_bus_resume,
2664};
2665
2666/*-------------------------------------------------------------------------*/
2667
2668#define resource_len(r) (((r)->end - (r)->start) + 1)
2669
2670static int __devexit isp1362_remove(struct platform_device *pdev)
2671{
2672 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2673 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2674 struct resource *res;
2675
2676 remove_debug_file(isp1362_hcd);
2677 DBG(0, "%s: Removing HCD\n", __func__);
2678 usb_remove_hcd(hcd);
2679
2680 DBG(0, "%s: Unmapping data_reg @ %08x\n", __func__,
2681 (u32)isp1362_hcd->data_reg);
2682 iounmap(isp1362_hcd->data_reg);
2683
2684 DBG(0, "%s: Unmapping addr_reg @ %08x\n", __func__,
2685 (u32)isp1362_hcd->addr_reg);
2686 iounmap(isp1362_hcd->addr_reg);
2687
2688 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2689 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
2690 if (res)
2691 release_mem_region(res->start, resource_len(res));
2692
2693 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2694 DBG(0, "%s: release mem_region: %08lx\n", __func__, (long unsigned int)res->start);
2695 if (res)
2696 release_mem_region(res->start, resource_len(res));
2697
2698 DBG(0, "%s: put_hcd\n", __func__);
2699 usb_put_hcd(hcd);
2700 DBG(0, "%s: Done\n", __func__);
2701
2702 return 0;
2703}
2704
2705static int __init isp1362_probe(struct platform_device *pdev)
2706{
2707 struct usb_hcd *hcd;
2708 struct isp1362_hcd *isp1362_hcd;
2709 struct resource *addr, *data;
2710 void __iomem *addr_reg;
2711 void __iomem *data_reg;
2712 int irq;
2713 int retval = 0;
2714
2715 /* basic sanity checks first. board-specific init logic should
2716 * have initialized this the three resources and probably board
2717 * specific platform_data. we don't probe for IRQs, and do only
2718 * minimal sanity checking.
2719 */
2720 if (pdev->num_resources < 3) {
2721 retval = -ENODEV;
2722 goto err1;
2723 }
2724
2725 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2726 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2727 irq = platform_get_irq(pdev, 0);
2728 if (!addr || !data || irq < 0) {
2729 retval = -ENODEV;
2730 goto err1;
2731 }
2732
2733#ifdef CONFIG_USB_HCD_DMA
2734 if (pdev->dev.dma_mask) {
2735 struct resource *dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
2736
2737 if (!dma_res) {
2738 retval = -ENODEV;
2739 goto err1;
2740 }
2741 isp1362_hcd->data_dma = dma_res->start;
2742 isp1362_hcd->max_dma_size = resource_len(dma_res);
2743 }
2744#else
2745 if (pdev->dev.dma_mask) {
2746 DBG(1, "won't do DMA");
2747 retval = -ENODEV;
2748 goto err1;
2749 }
2750#endif
2751
2752 if (!request_mem_region(addr->start, resource_len(addr), hcd_name)) {
2753 retval = -EBUSY;
2754 goto err1;
2755 }
2756 addr_reg = ioremap(addr->start, resource_len(addr));
2757 if (addr_reg == NULL) {
2758 retval = -ENOMEM;
2759 goto err2;
2760 }
2761
2762 if (!request_mem_region(data->start, resource_len(data), hcd_name)) {
2763 retval = -EBUSY;
2764 goto err3;
2765 }
2766 data_reg = ioremap(data->start, resource_len(data));
2767 if (data_reg == NULL) {
2768 retval = -ENOMEM;
2769 goto err4;
2770 }
2771
2772 /* allocate and initialize hcd */
2773 hcd = usb_create_hcd(&isp1362_hc_driver, &pdev->dev, dev_name(&pdev->dev));
2774 if (!hcd) {
2775 retval = -ENOMEM;
2776 goto err5;
2777 }
2778 hcd->rsrc_start = data->start;
2779 isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2780 isp1362_hcd->data_reg = data_reg;
2781 isp1362_hcd->addr_reg = addr_reg;
2782
2783 isp1362_hcd->next_statechange = jiffies;
2784 spin_lock_init(&isp1362_hcd->lock);
2785 INIT_LIST_HEAD(&isp1362_hcd->async);
2786 INIT_LIST_HEAD(&isp1362_hcd->periodic);
2787 INIT_LIST_HEAD(&isp1362_hcd->isoc);
2788 INIT_LIST_HEAD(&isp1362_hcd->remove_list);
2789 isp1362_hcd->board = pdev->dev.platform_data;
2790#if USE_PLATFORM_DELAY
2791 if (!isp1362_hcd->board->delay) {
2792 dev_err(hcd->self.controller, "No platform delay function given\n");
2793 retval = -ENODEV;
2794 goto err6;
2795 }
2796#endif
2797
2798#ifdef CONFIG_ARM
2799 if (isp1362_hcd->board)
2800 set_irq_type(irq, isp1362_hcd->board->int_act_high ? IRQT_RISING : IRQT_FALLING);
2801#endif
2802
2803 retval = usb_add_hcd(hcd, irq, IRQF_TRIGGER_LOW | IRQF_DISABLED | IRQF_SHARED);
2804 if (retval != 0)
2805 goto err6;
2806 pr_info("%s, irq %d\n", hcd->product_desc, irq);
2807
2808 create_debug_file(isp1362_hcd);
2809
2810 return 0;
2811
2812 err6:
2813 DBG(0, "%s: Freeing dev %08x\n", __func__, (u32)isp1362_hcd);
2814 usb_put_hcd(hcd);
2815 err5:
2816 DBG(0, "%s: Unmapping data_reg @ %08x\n", __func__, (u32)data_reg);
2817 iounmap(data_reg);
2818 err4:
2819 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)data->start);
2820 release_mem_region(data->start, resource_len(data));
2821 err3:
2822 DBG(0, "%s: Unmapping addr_reg @ %08x\n", __func__, (u32)addr_reg);
2823 iounmap(addr_reg);
2824 err2:
2825 DBG(0, "%s: Releasing mem region %08lx\n", __func__, (long unsigned int)addr->start);
2826 release_mem_region(addr->start, resource_len(addr));
2827 err1:
2828 pr_err("%s: init error, %d\n", __func__, retval);
2829
2830 return retval;
2831}
2832
2833#ifdef CONFIG_PM
2834static int isp1362_suspend(struct platform_device *pdev, pm_message_t state)
2835{
2836 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2837 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2838 unsigned long flags;
2839 int retval = 0;
2840
2841 DBG(0, "%s: Suspending device\n", __func__);
2842
2843 if (state.event == PM_EVENT_FREEZE) {
2844 DBG(0, "%s: Suspending root hub\n", __func__);
2845 retval = isp1362_bus_suspend(hcd);
2846 } else {
2847 DBG(0, "%s: Suspending RH ports\n", __func__);
2848 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2849 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPS);
2850 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2851 }
2852 if (retval == 0)
2853 pdev->dev.power.power_state = state;
2854 return retval;
2855}
2856
2857static int isp1362_resume(struct platform_device *pdev)
2858{
2859 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2860 struct isp1362_hcd *isp1362_hcd = hcd_to_isp1362_hcd(hcd);
2861 unsigned long flags;
2862
2863 DBG(0, "%s: Resuming\n", __func__);
2864
2865 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
2866 DBG(0, "%s: Resume RH ports\n", __func__);
2867 spin_lock_irqsave(&isp1362_hcd->lock, flags);
2868 isp1362_write_reg32(isp1362_hcd, HCRHSTATUS, RH_HS_LPSC);
2869 spin_unlock_irqrestore(&isp1362_hcd->lock, flags);
2870 return 0;
2871 }
2872
2873 pdev->dev.power.power_state = PMSG_ON;
2874
2875 return isp1362_bus_resume(isp1362_hcd_to_hcd(isp1362_hcd));
2876}
2877#else
2878#define isp1362_suspend NULL
2879#define isp1362_resume NULL
2880#endif
2881
2882static struct platform_driver isp1362_driver = {
2883 .probe = isp1362_probe,
2884 .remove = __devexit_p(isp1362_remove),
2885
2886 .suspend = isp1362_suspend,
2887 .resume = isp1362_resume,
2888 .driver = {
2889 .name = (char *)hcd_name,
2890 .owner = THIS_MODULE,
2891 },
2892};
2893
2894/*-------------------------------------------------------------------------*/
2895
2896static int __init isp1362_init(void)
2897{
2898 if (usb_disabled())
2899 return -ENODEV;
2900 pr_info("driver %s, %s\n", hcd_name, DRIVER_VERSION);
2901 return platform_driver_register(&isp1362_driver);
2902}
2903module_init(isp1362_init);
2904
2905static void __exit isp1362_cleanup(void)
2906{
2907 platform_driver_unregister(&isp1362_driver);
2908}
2909module_exit(isp1362_cleanup);
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h
new file mode 100644
index 000000000000..fe60f62a32f3
--- /dev/null
+++ b/drivers/usb/host/isp1362.h
@@ -0,0 +1,1079 @@
1/*
2 * ISP1362 HCD (Host Controller Driver) for USB.
3 *
4 * COPYRIGHT (C) by L. Wassmann <LW@KARO-electronics.de>
5 */
6
7/* ------------------------------------------------------------------------- */
8/*
9 * Platform specific compile time options
10 */
11#if defined(CONFIG_ARCH_KARO)
12#include <asm/arch/hardware.h>
13#include <asm/arch/pxa-regs.h>
14#include <asm/arch/karo.h>
15
16#define USE_32BIT 1
17
18
19/* These options are mutually eclusive */
20#define USE_PLATFORM_DELAY 1
21#define USE_NDELAY 0
22/*
23 * MAX_ROOT_PORTS: Number of downstream ports
24 *
25 * The chip has two USB ports, one of which can be configured as
26 * an USB device port, so the value of this constant is implementation
27 * specific.
28 */
29#define MAX_ROOT_PORTS 2
30#define DUMMY_DELAY_ACCESS do {} while (0)
31
32/* insert platform specific definitions for other machines here */
33#elif defined(CONFIG_BLACKFIN)
34
35#include <linux/io.h>
36#define USE_32BIT 0
37#define MAX_ROOT_PORTS 2
38#define USE_PLATFORM_DELAY 0
39#define USE_NDELAY 1
40
41#define DUMMY_DELAY_ACCESS \
42 do { \
43 bfin_read16(ASYNC_BANK0_BASE); \
44 bfin_read16(ASYNC_BANK0_BASE); \
45 bfin_read16(ASYNC_BANK0_BASE); \
46 } while (0)
47
48#undef insw
49#undef outsw
50
51#define insw delayed_insw
52#define outsw delayed_outsw
53
54static inline void delayed_outsw(unsigned int addr, void *buf, int len)
55{
56 unsigned short *bp = (unsigned short *)buf;
57 while (len--) {
58 DUMMY_DELAY_ACCESS;
59 outw(*bp++, addr);
60 }
61}
62
63static inline void delayed_insw(unsigned int addr, void *buf, int len)
64{
65 unsigned short *bp = (unsigned short *)buf;
66 while (len--) {
67 DUMMY_DELAY_ACCESS;
68 *bp++ = inw((void *)addr);
69 }
70}
71
72#else
73
74#define MAX_ROOT_PORTS 2
75
76#define USE_32BIT 0
77
78/* These options are mutually eclusive */
79#define USE_PLATFORM_DELAY 0
80#define USE_NDELAY 0
81
82#define DUMMY_DELAY_ACCESS do {} while (0)
83
84#endif
85
86
87/* ------------------------------------------------------------------------- */
88
89#define USB_RESET_WIDTH 50
90#define MAX_XFER_SIZE 1023
91
92/* Buffer sizes */
93#define ISP1362_BUF_SIZE 4096
94#define ISP1362_ISTL_BUFSIZE 512
95#define ISP1362_INTL_BLKSIZE 64
96#define ISP1362_INTL_BUFFERS 16
97#define ISP1362_ATL_BLKSIZE 64
98
99#define ISP1362_REG_WRITE_OFFSET 0x80
100
101#ifdef ISP1362_DEBUG
102typedef const unsigned int isp1362_reg_t;
103
104#define REG_WIDTH_16 0x000
105#define REG_WIDTH_32 0x100
106#define REG_WIDTH_MASK 0x100
107#define REG_NO_MASK 0x0ff
108
109#define REG_ACCESS_R 0x200
110#define REG_ACCESS_W 0x400
111#define REG_ACCESS_RW 0x600
112#define REG_ACCESS_MASK 0x600
113
114#define ISP1362_REG_NO(r) ((r) & REG_NO_MASK)
115
116#define _BUG_ON(x) BUG_ON(x)
117#define _WARN_ON(x) WARN_ON(x)
118
119#define ISP1362_REG(name, addr, width, rw) \
120static isp1362_reg_t ISP1362_REG_##name = ((addr) | (width) | (rw))
121
122#define REG_ACCESS_TEST(r) BUG_ON(((r) & ISP1362_REG_WRITE_OFFSET) && !((r) & REG_ACCESS_W))
123#define REG_WIDTH_TEST(r, w) BUG_ON(((r) & REG_WIDTH_MASK) != (w))
124#else
125typedef const unsigned char isp1362_reg_t;
126#define ISP1362_REG_NO(r) (r)
127#define _BUG_ON(x) do {} while (0)
128#define _WARN_ON(x) do {} while (0)
129
130#define ISP1362_REG(name, addr, width, rw) \
131static isp1362_reg_t ISP1362_REG_##name = addr
132
133#define REG_ACCESS_TEST(r) do {} while (0)
134#define REG_WIDTH_TEST(r, w) do {} while (0)
135#endif
136
137/* OHCI compatible registers */
138/*
139 * Note: Some of the ISP1362 'OHCI' registers implement only
140 * a subset of the bits defined in the OHCI spec.
141 *
142 * Bitmasks for the individual bits of these registers are defined in "ohci.h"
143 */
144ISP1362_REG(HCREVISION, 0x00, REG_WIDTH_32, REG_ACCESS_R);
145ISP1362_REG(HCCONTROL, 0x01, REG_WIDTH_32, REG_ACCESS_RW);
146ISP1362_REG(HCCMDSTAT, 0x02, REG_WIDTH_32, REG_ACCESS_RW);
147ISP1362_REG(HCINTSTAT, 0x03, REG_WIDTH_32, REG_ACCESS_RW);
148ISP1362_REG(HCINTENB, 0x04, REG_WIDTH_32, REG_ACCESS_RW);
149ISP1362_REG(HCINTDIS, 0x05, REG_WIDTH_32, REG_ACCESS_RW);
150ISP1362_REG(HCFMINTVL, 0x0d, REG_WIDTH_32, REG_ACCESS_RW);
151ISP1362_REG(HCFMREM, 0x0e, REG_WIDTH_32, REG_ACCESS_RW);
152ISP1362_REG(HCFMNUM, 0x0f, REG_WIDTH_32, REG_ACCESS_RW);
153ISP1362_REG(HCLSTHRESH, 0x11, REG_WIDTH_32, REG_ACCESS_RW);
154ISP1362_REG(HCRHDESCA, 0x12, REG_WIDTH_32, REG_ACCESS_RW);
155ISP1362_REG(HCRHDESCB, 0x13, REG_WIDTH_32, REG_ACCESS_RW);
156ISP1362_REG(HCRHSTATUS, 0x14, REG_WIDTH_32, REG_ACCESS_RW);
157ISP1362_REG(HCRHPORT1, 0x15, REG_WIDTH_32, REG_ACCESS_RW);
158ISP1362_REG(HCRHPORT2, 0x16, REG_WIDTH_32, REG_ACCESS_RW);
159
160/* Philips ISP1362 specific registers */
161ISP1362_REG(HCHWCFG, 0x20, REG_WIDTH_16, REG_ACCESS_RW);
162#define HCHWCFG_DISABLE_SUSPEND (1 << 15)
163#define HCHWCFG_GLOBAL_PWRDOWN (1 << 14)
164#define HCHWCFG_PULLDOWN_DS2 (1 << 13)
165#define HCHWCFG_PULLDOWN_DS1 (1 << 12)
166#define HCHWCFG_CLKNOTSTOP (1 << 11)
167#define HCHWCFG_ANALOG_OC (1 << 10)
168#define HCHWCFG_ONEINT (1 << 9)
169#define HCHWCFG_DACK_MODE (1 << 8)
170#define HCHWCFG_ONEDMA (1 << 7)
171#define HCHWCFG_DACK_POL (1 << 6)
172#define HCHWCFG_DREQ_POL (1 << 5)
173#define HCHWCFG_DBWIDTH_MASK (0x03 << 3)
174#define HCHWCFG_DBWIDTH(n) (((n) << 3) & HCHWCFG_DBWIDTH_MASK)
175#define HCHWCFG_INT_POL (1 << 2)
176#define HCHWCFG_INT_TRIGGER (1 << 1)
177#define HCHWCFG_INT_ENABLE (1 << 0)
178
179ISP1362_REG(HCDMACFG, 0x21, REG_WIDTH_16, REG_ACCESS_RW);
180#define HCDMACFG_CTR_ENABLE (1 << 7)
181#define HCDMACFG_BURST_LEN_MASK (0x03 << 5)
182#define HCDMACFG_BURST_LEN(n) (((n) << 5) & HCDMACFG_BURST_LEN_MASK)
183#define HCDMACFG_BURST_LEN_1 HCDMACFG_BURST_LEN(0)
184#define HCDMACFG_BURST_LEN_4 HCDMACFG_BURST_LEN(1)
185#define HCDMACFG_BURST_LEN_8 HCDMACFG_BURST_LEN(2)
186#define HCDMACFG_DMA_ENABLE (1 << 4)
187#define HCDMACFG_BUF_TYPE_MASK (0x07 << 1)
188#define HCDMACFG_BUF_TYPE(n) (((n) << 1) & HCDMACFG_BUF_TYPE_MASK)
189#define HCDMACFG_BUF_ISTL0 HCDMACFG_BUF_TYPE(0)
190#define HCDMACFG_BUF_ISTL1 HCDMACFG_BUF_TYPE(1)
191#define HCDMACFG_BUF_INTL HCDMACFG_BUF_TYPE(2)
192#define HCDMACFG_BUF_ATL HCDMACFG_BUF_TYPE(3)
193#define HCDMACFG_BUF_DIRECT HCDMACFG_BUF_TYPE(4)
194#define HCDMACFG_DMA_RW_SELECT (1 << 0)
195
196ISP1362_REG(HCXFERCTR, 0x22, REG_WIDTH_16, REG_ACCESS_RW);
197
198ISP1362_REG(HCuPINT, 0x24, REG_WIDTH_16, REG_ACCESS_RW);
199#define HCuPINT_SOF (1 << 0)
200#define HCuPINT_ISTL0 (1 << 1)
201#define HCuPINT_ISTL1 (1 << 2)
202#define HCuPINT_EOT (1 << 3)
203#define HCuPINT_OPR (1 << 4)
204#define HCuPINT_SUSP (1 << 5)
205#define HCuPINT_CLKRDY (1 << 6)
206#define HCuPINT_INTL (1 << 7)
207#define HCuPINT_ATL (1 << 8)
208#define HCuPINT_OTG (1 << 9)
209
210ISP1362_REG(HCuPINTENB, 0x25, REG_WIDTH_16, REG_ACCESS_RW);
211/* same bit definitions apply as for HCuPINT */
212
213ISP1362_REG(HCCHIPID, 0x27, REG_WIDTH_16, REG_ACCESS_R);
214#define HCCHIPID_MASK 0xff00
215#define HCCHIPID_MAGIC 0x3600
216
217ISP1362_REG(HCSCRATCH, 0x28, REG_WIDTH_16, REG_ACCESS_RW);
218
219ISP1362_REG(HCSWRES, 0x29, REG_WIDTH_16, REG_ACCESS_W);
220#define HCSWRES_MAGIC 0x00f6
221
222ISP1362_REG(HCBUFSTAT, 0x2c, REG_WIDTH_16, REG_ACCESS_RW);
223#define HCBUFSTAT_ISTL0_FULL (1 << 0)
224#define HCBUFSTAT_ISTL1_FULL (1 << 1)
225#define HCBUFSTAT_INTL_ACTIVE (1 << 2)
226#define HCBUFSTAT_ATL_ACTIVE (1 << 3)
227#define HCBUFSTAT_RESET_HWPP (1 << 4)
228#define HCBUFSTAT_ISTL0_ACTIVE (1 << 5)
229#define HCBUFSTAT_ISTL1_ACTIVE (1 << 6)
230#define HCBUFSTAT_ISTL0_DONE (1 << 8)
231#define HCBUFSTAT_ISTL1_DONE (1 << 9)
232#define HCBUFSTAT_PAIRED_PTDPP (1 << 10)
233
234ISP1362_REG(HCDIRADDR, 0x32, REG_WIDTH_32, REG_ACCESS_RW);
235#define HCDIRADDR_ADDR_MASK 0x0000ffff
236#define HCDIRADDR_ADDR(n) (((n) << 0) & HCDIRADDR_ADDR_MASK)
237#define HCDIRADDR_COUNT_MASK 0xffff0000
238#define HCDIRADDR_COUNT(n) (((n) << 16) & HCDIRADDR_COUNT_MASK)
239ISP1362_REG(HCDIRDATA, 0x45, REG_WIDTH_16, REG_ACCESS_RW);
240
241ISP1362_REG(HCISTLBUFSZ, 0x30, REG_WIDTH_16, REG_ACCESS_RW);
242ISP1362_REG(HCISTL0PORT, 0x40, REG_WIDTH_16, REG_ACCESS_RW);
243ISP1362_REG(HCISTL1PORT, 0x42, REG_WIDTH_16, REG_ACCESS_RW);
244ISP1362_REG(HCISTLRATE, 0x47, REG_WIDTH_16, REG_ACCESS_RW);
245
246ISP1362_REG(HCINTLBUFSZ, 0x33, REG_WIDTH_16, REG_ACCESS_RW);
247ISP1362_REG(HCINTLPORT, 0x43, REG_WIDTH_16, REG_ACCESS_RW);
248ISP1362_REG(HCINTLBLKSZ, 0x53, REG_WIDTH_16, REG_ACCESS_RW);
249ISP1362_REG(HCINTLDONE, 0x17, REG_WIDTH_32, REG_ACCESS_R);
250ISP1362_REG(HCINTLSKIP, 0x18, REG_WIDTH_32, REG_ACCESS_RW);
251ISP1362_REG(HCINTLLAST, 0x19, REG_WIDTH_32, REG_ACCESS_RW);
252ISP1362_REG(HCINTLCURR, 0x1a, REG_WIDTH_16, REG_ACCESS_R);
253
254ISP1362_REG(HCATLBUFSZ, 0x34, REG_WIDTH_16, REG_ACCESS_RW);
255ISP1362_REG(HCATLPORT, 0x44, REG_WIDTH_16, REG_ACCESS_RW);
256ISP1362_REG(HCATLBLKSZ, 0x54, REG_WIDTH_16, REG_ACCESS_RW);
257ISP1362_REG(HCATLDONE, 0x1b, REG_WIDTH_32, REG_ACCESS_R);
258ISP1362_REG(HCATLSKIP, 0x1c, REG_WIDTH_32, REG_ACCESS_RW);
259ISP1362_REG(HCATLLAST, 0x1d, REG_WIDTH_32, REG_ACCESS_RW);
260ISP1362_REG(HCATLCURR, 0x1e, REG_WIDTH_16, REG_ACCESS_R);
261
262ISP1362_REG(HCATLDTC, 0x51, REG_WIDTH_16, REG_ACCESS_RW);
263ISP1362_REG(HCATLDTCTO, 0x52, REG_WIDTH_16, REG_ACCESS_RW);
264
265
266ISP1362_REG(OTGCONTROL, 0x62, REG_WIDTH_16, REG_ACCESS_RW);
267ISP1362_REG(OTGSTATUS, 0x67, REG_WIDTH_16, REG_ACCESS_R);
268ISP1362_REG(OTGINT, 0x68, REG_WIDTH_16, REG_ACCESS_RW);
269ISP1362_REG(OTGINTENB, 0x69, REG_WIDTH_16, REG_ACCESS_RW);
270ISP1362_REG(OTGTIMER, 0x6A, REG_WIDTH_16, REG_ACCESS_RW);
271ISP1362_REG(OTGALTTMR, 0x6C, REG_WIDTH_16, REG_ACCESS_RW);
272
273/* Philips transfer descriptor, cpu-endian */
274struct ptd {
275 u16 count;
276#define PTD_COUNT_MSK (0x3ff << 0)
277#define PTD_TOGGLE_MSK (1 << 10)
278#define PTD_ACTIVE_MSK (1 << 11)
279#define PTD_CC_MSK (0xf << 12)
280 u16 mps;
281#define PTD_MPS_MSK (0x3ff << 0)
282#define PTD_SPD_MSK (1 << 10)
283#define PTD_LAST_MSK (1 << 11)
284#define PTD_EP_MSK (0xf << 12)
285 u16 len;
286#define PTD_LEN_MSK (0x3ff << 0)
287#define PTD_DIR_MSK (3 << 10)
288#define PTD_DIR_SETUP (0)
289#define PTD_DIR_OUT (1)
290#define PTD_DIR_IN (2)
291 u16 faddr;
292#define PTD_FA_MSK (0x7f << 0)
293/* PTD Byte 7: [StartingFrame (if ISO PTD) | StartingFrame[0..4], PollingRate[0..2] (if INT PTD)] */
294#define PTD_SF_ISO_MSK (0xff << 8)
295#define PTD_SF_INT_MSK (0x1f << 8)
296#define PTD_PR_MSK (0x07 << 13)
297} __attribute__ ((packed, aligned(2)));
298#define PTD_HEADER_SIZE sizeof(struct ptd)
299
300/* ------------------------------------------------------------------------- */
301/* Copied from ohci.h: */
302/*
303 * Hardware transfer status codes -- CC from PTD
304 */
305#define PTD_CC_NOERROR 0x00
306#define PTD_CC_CRC 0x01
307#define PTD_CC_BITSTUFFING 0x02
308#define PTD_CC_DATATOGGLEM 0x03
309#define PTD_CC_STALL 0x04
310#define PTD_DEVNOTRESP 0x05
311#define PTD_PIDCHECKFAIL 0x06
312#define PTD_UNEXPECTEDPID 0x07
313#define PTD_DATAOVERRUN 0x08
314#define PTD_DATAUNDERRUN 0x09
315 /* 0x0A, 0x0B reserved for hardware */
316#define PTD_BUFFEROVERRUN 0x0C
317#define PTD_BUFFERUNDERRUN 0x0D
318 /* 0x0E, 0x0F reserved for HCD */
319#define PTD_NOTACCESSED 0x0F
320
321
322/* map OHCI TD status codes (CC) to errno values */
323static const int cc_to_error[16] = {
324 /* No Error */ 0,
325 /* CRC Error */ -EILSEQ,
326 /* Bit Stuff */ -EPROTO,
327 /* Data Togg */ -EILSEQ,
328 /* Stall */ -EPIPE,
329 /* DevNotResp */ -ETIMEDOUT,
330 /* PIDCheck */ -EPROTO,
331 /* UnExpPID */ -EPROTO,
332 /* DataOver */ -EOVERFLOW,
333 /* DataUnder */ -EREMOTEIO,
334 /* (for hw) */ -EIO,
335 /* (for hw) */ -EIO,
336 /* BufferOver */ -ECOMM,
337 /* BuffUnder */ -ENOSR,
338 /* (for HCD) */ -EALREADY,
339 /* (for HCD) */ -EALREADY
340};
341
342
343/*
344 * HcControl (control) register masks
345 */
346#define OHCI_CTRL_HCFS (3 << 6) /* host controller functional state */
347#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
348#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
349
350/* pre-shifted values for HCFS */
351# define OHCI_USB_RESET (0 << 6)
352# define OHCI_USB_RESUME (1 << 6)
353# define OHCI_USB_OPER (2 << 6)
354# define OHCI_USB_SUSPEND (3 << 6)
355
356/*
357 * HcCommandStatus (cmdstatus) register masks
358 */
359#define OHCI_HCR (1 << 0) /* host controller reset */
360#define OHCI_SOC (3 << 16) /* scheduling overrun count */
361
362/*
363 * masks used with interrupt registers:
364 * HcInterruptStatus (intrstatus)
365 * HcInterruptEnable (intrenable)
366 * HcInterruptDisable (intrdisable)
367 */
368#define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
369#define OHCI_INTR_WDH (1 << 1) /* writeback of done_head */
370#define OHCI_INTR_SF (1 << 2) /* start frame */
371#define OHCI_INTR_RD (1 << 3) /* resume detect */
372#define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
373#define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
374#define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
375#define OHCI_INTR_OC (1 << 30) /* ownership change */
376#define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
377
378/* roothub.portstatus [i] bits */
379#define RH_PS_CCS 0x00000001 /* current connect status */
380#define RH_PS_PES 0x00000002 /* port enable status*/
381#define RH_PS_PSS 0x00000004 /* port suspend status */
382#define RH_PS_POCI 0x00000008 /* port over current indicator */
383#define RH_PS_PRS 0x00000010 /* port reset status */
384#define RH_PS_PPS 0x00000100 /* port power status */
385#define RH_PS_LSDA 0x00000200 /* low speed device attached */
386#define RH_PS_CSC 0x00010000 /* connect status change */
387#define RH_PS_PESC 0x00020000 /* port enable status change */
388#define RH_PS_PSSC 0x00040000 /* port suspend status change */
389#define RH_PS_OCIC 0x00080000 /* over current indicator change */
390#define RH_PS_PRSC 0x00100000 /* port reset status change */
391
392/* roothub.status bits */
393#define RH_HS_LPS 0x00000001 /* local power status */
394#define RH_HS_OCI 0x00000002 /* over current indicator */
395#define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
396#define RH_HS_LPSC 0x00010000 /* local power status change */
397#define RH_HS_OCIC 0x00020000 /* over current indicator change */
398#define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
399
400/* roothub.b masks */
401#define RH_B_DR 0x0000ffff /* device removable flags */
402#define RH_B_PPCM 0xffff0000 /* port power control mask */
403
404/* roothub.a masks */
405#define RH_A_NDP (0xff << 0) /* number of downstream ports */
406#define RH_A_PSM (1 << 8) /* power switching mode */
407#define RH_A_NPS (1 << 9) /* no power switching */
408#define RH_A_DT (1 << 10) /* device type (mbz) */
409#define RH_A_OCPM (1 << 11) /* over current protection mode */
410#define RH_A_NOCP (1 << 12) /* no over current protection */
411#define RH_A_POTPGT (0xff << 24) /* power on to power good time */
412
413#define FI 0x2edf /* 12000 bits per frame (-1) */
414#define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
415#define LSTHRESH 0x628 /* lowspeed bit threshold */
416
417/* ------------------------------------------------------------------------- */
418
419/* PTD accessor macros. */
420#define PTD_GET_COUNT(p) (((p)->count & PTD_COUNT_MSK) >> 0)
421#define PTD_COUNT(v) (((v) << 0) & PTD_COUNT_MSK)
422#define PTD_GET_TOGGLE(p) (((p)->count & PTD_TOGGLE_MSK) >> 10)
423#define PTD_TOGGLE(v) (((v) << 10) & PTD_TOGGLE_MSK)
424#define PTD_GET_ACTIVE(p) (((p)->count & PTD_ACTIVE_MSK) >> 11)
425#define PTD_ACTIVE(v) (((v) << 11) & PTD_ACTIVE_MSK)
426#define PTD_GET_CC(p) (((p)->count & PTD_CC_MSK) >> 12)
427#define PTD_CC(v) (((v) << 12) & PTD_CC_MSK)
428#define PTD_GET_MPS(p) (((p)->mps & PTD_MPS_MSK) >> 0)
429#define PTD_MPS(v) (((v) << 0) & PTD_MPS_MSK)
430#define PTD_GET_SPD(p) (((p)->mps & PTD_SPD_MSK) >> 10)
431#define PTD_SPD(v) (((v) << 10) & PTD_SPD_MSK)
432#define PTD_GET_LAST(p) (((p)->mps & PTD_LAST_MSK) >> 11)
433#define PTD_LAST(v) (((v) << 11) & PTD_LAST_MSK)
434#define PTD_GET_EP(p) (((p)->mps & PTD_EP_MSK) >> 12)
435#define PTD_EP(v) (((v) << 12) & PTD_EP_MSK)
436#define PTD_GET_LEN(p) (((p)->len & PTD_LEN_MSK) >> 0)
437#define PTD_LEN(v) (((v) << 0) & PTD_LEN_MSK)
438#define PTD_GET_DIR(p) (((p)->len & PTD_DIR_MSK) >> 10)
439#define PTD_DIR(v) (((v) << 10) & PTD_DIR_MSK)
440#define PTD_GET_FA(p) (((p)->faddr & PTD_FA_MSK) >> 0)
441#define PTD_FA(v) (((v) << 0) & PTD_FA_MSK)
442#define PTD_GET_SF_INT(p) (((p)->faddr & PTD_SF_INT_MSK) >> 8)
443#define PTD_SF_INT(v) (((v) << 8) & PTD_SF_INT_MSK)
444#define PTD_GET_SF_ISO(p) (((p)->faddr & PTD_SF_ISO_MSK) >> 8)
445#define PTD_SF_ISO(v) (((v) << 8) & PTD_SF_ISO_MSK)
446#define PTD_GET_PR(p) (((p)->faddr & PTD_PR_MSK) >> 13)
447#define PTD_PR(v) (((v) << 13) & PTD_PR_MSK)
448
449#define LOG2_PERIODIC_SIZE 5 /* arbitrary; this matches OHCI */
450#define PERIODIC_SIZE (1 << LOG2_PERIODIC_SIZE)
451
452struct isp1362_ep {
453 struct usb_host_endpoint *hep;
454 struct usb_device *udev;
455
456 /* philips transfer descriptor */
457 struct ptd ptd;
458
459 u8 maxpacket;
460 u8 epnum;
461 u8 nextpid;
462 u16 error_count;
463 u16 length; /* of current packet */
464 s16 ptd_offset; /* buffer offset in ISP1362 where
465 PTD has been stored
466 (for access thru HCDIRDATA) */
467 int ptd_index;
468 int num_ptds;
469 void *data; /* to databuf */
470 /* queue of active EPs (the ones transmitted to the chip) */
471 struct list_head active;
472
473 /* periodic schedule */
474 u8 branch;
475 u16 interval;
476 u16 load;
477 u16 last_iso;
478
479 /* async schedule */
480 struct list_head schedule; /* list of all EPs that need processing */
481 struct list_head remove_list;
482 int num_req;
483};
484
485struct isp1362_ep_queue {
486 struct list_head active; /* list of PTDs currently processed by HC */
487 atomic_t finishing;
488 unsigned long buf_map;
489 unsigned long skip_map;
490 int free_ptd;
491 u16 buf_start;
492 u16 buf_size;
493 u16 blk_size; /* PTD buffer block size for ATL and INTL */
494 u8 buf_count;
495 u8 buf_avail;
496 char name[16];
497
498 /* for statistical tracking */
499 u8 stat_maxptds; /* Max # of ptds seen simultaneously in fifo */
500 u8 ptd_count; /* number of ptds submitted to this queue */
501};
502
503struct isp1362_hcd {
504 spinlock_t lock;
505 void __iomem *addr_reg;
506 void __iomem *data_reg;
507
508 struct isp1362_platform_data *board;
509
510 struct proc_dir_entry *pde;
511 unsigned long stat1, stat2, stat4, stat8, stat16;
512
513 /* HC registers */
514 u32 intenb; /* "OHCI" interrupts */
515 u16 irqenb; /* uP interrupts */
516
517 /* Root hub registers */
518 u32 rhdesca;
519 u32 rhdescb;
520 u32 rhstatus;
521 u32 rhport[MAX_ROOT_PORTS];
522 unsigned long next_statechange;
523
524 /* HC control reg shadow copy */
525 u32 hc_control;
526
527 /* async schedule: control, bulk */
528 struct list_head async;
529
530 /* periodic schedule: int */
531 u16 load[PERIODIC_SIZE];
532 struct list_head periodic;
533 u16 fmindex;
534
535 /* periodic schedule: isochronous */
536 struct list_head isoc;
537 int istl_flip:1;
538 int irq_active:1;
539
540 /* Schedules for the current frame */
541 struct isp1362_ep_queue atl_queue;
542 struct isp1362_ep_queue intl_queue;
543 struct isp1362_ep_queue istl_queue[2];
544
545 /* list of PTDs retrieved from HC */
546 struct list_head remove_list;
547 enum {
548 ISP1362_INT_SOF,
549 ISP1362_INT_ISTL0,
550 ISP1362_INT_ISTL1,
551 ISP1362_INT_EOT,
552 ISP1362_INT_OPR,
553 ISP1362_INT_SUSP,
554 ISP1362_INT_CLKRDY,
555 ISP1362_INT_INTL,
556 ISP1362_INT_ATL,
557 ISP1362_INT_OTG,
558 NUM_ISP1362_IRQS
559 } IRQ_NAMES;
560 unsigned int irq_stat[NUM_ISP1362_IRQS];
561 int req_serial;
562};
563
564static inline const char *ISP1362_INT_NAME(int n)
565{
566 switch (n) {
567 case ISP1362_INT_SOF: return "SOF";
568 case ISP1362_INT_ISTL0: return "ISTL0";
569 case ISP1362_INT_ISTL1: return "ISTL1";
570 case ISP1362_INT_EOT: return "EOT";
571 case ISP1362_INT_OPR: return "OPR";
572 case ISP1362_INT_SUSP: return "SUSP";
573 case ISP1362_INT_CLKRDY: return "CLKRDY";
574 case ISP1362_INT_INTL: return "INTL";
575 case ISP1362_INT_ATL: return "ATL";
576 case ISP1362_INT_OTG: return "OTG";
577 default: return "unknown";
578 }
579}
580
581static inline void ALIGNSTAT(struct isp1362_hcd *isp1362_hcd, void *ptr)
582{
583 unsigned p = (unsigned)ptr;
584 if (!(p & 0xf))
585 isp1362_hcd->stat16++;
586 else if (!(p & 0x7))
587 isp1362_hcd->stat8++;
588 else if (!(p & 0x3))
589 isp1362_hcd->stat4++;
590 else if (!(p & 0x1))
591 isp1362_hcd->stat2++;
592 else
593 isp1362_hcd->stat1++;
594}
595
596static inline struct isp1362_hcd *hcd_to_isp1362_hcd(struct usb_hcd *hcd)
597{
598 return (struct isp1362_hcd *) (hcd->hcd_priv);
599}
600
601static inline struct usb_hcd *isp1362_hcd_to_hcd(struct isp1362_hcd *isp1362_hcd)
602{
603 return container_of((void *)isp1362_hcd, struct usb_hcd, hcd_priv);
604}
605
606#define frame_before(f1, f2) ((s16)((u16)f1 - (u16)f2) < 0)
607
608/*
609 * ISP1362 HW Interface
610 */
611
612#ifdef ISP1362_DEBUG
613#define DBG(level, fmt...) \
614 do { \
615 if (dbg_level > level) \
616 pr_debug(fmt); \
617 } while (0)
618#define _DBG(level, fmt...) \
619 do { \
620 if (dbg_level > level) \
621 printk(fmt); \
622 } while (0)
623#else
624#define DBG(fmt...) do {} while (0)
625#define _DBG DBG
626#endif
627
628#ifdef VERBOSE
629# define VDBG(fmt...) DBG(3, fmt)
630#else
631# define VDBG(fmt...) do {} while (0)
632#endif
633
634#ifdef REGISTERS
635# define RDBG(fmt...) DBG(1, fmt)
636#else
637# define RDBG(fmt...) do {} while (0)
638#endif
639
640#ifdef URB_TRACE
641#define URB_DBG(fmt...) DBG(0, fmt)
642#else
643#define URB_DBG(fmt...) do {} while (0)
644#endif
645
646
647#if USE_PLATFORM_DELAY
648#if USE_NDELAY
649#error USE_PLATFORM_DELAY and USE_NDELAY defined simultaneously.
650#endif
651#define isp1362_delay(h, d) (h)->board->delay(isp1362_hcd_to_hcd(h)->self.controller, d)
652#elif USE_NDELAY
653#define isp1362_delay(h, d) ndelay(d)
654#else
655#define isp1362_delay(h, d) do {} while (0)
656#endif
657
658#define get_urb(ep) ({ \
659 BUG_ON(list_empty(&ep->hep->urb_list)); \
660 container_of(ep->hep->urb_list.next, struct urb, urb_list); \
661})
662
663/* basic access functions for ISP1362 chip registers */
664/* NOTE: The contents of the address pointer register cannot be read back! The driver must ensure,
665 * that all register accesses are performed with interrupts disabled, since the interrupt
666 * handler has no way of restoring the previous state.
667 */
668static void isp1362_write_addr(struct isp1362_hcd *isp1362_hcd, isp1362_reg_t reg)
669{
670 /*_BUG_ON((reg & ISP1362_REG_WRITE_OFFSET) && !(reg & REG_ACCESS_W));*/
671 REG_ACCESS_TEST(reg);
672 _BUG_ON(!irqs_disabled());
673 DUMMY_DELAY_ACCESS;
674 writew(ISP1362_REG_NO(reg), isp1362_hcd->addr_reg);
675 DUMMY_DELAY_ACCESS;
676 isp1362_delay(isp1362_hcd, 1);
677}
678
679static void isp1362_write_data16(struct isp1362_hcd *isp1362_hcd, u16 val)
680{
681 _BUG_ON(!irqs_disabled());
682 DUMMY_DELAY_ACCESS;
683 writew(val, isp1362_hcd->data_reg);
684}
685
686static u16 isp1362_read_data16(struct isp1362_hcd *isp1362_hcd)
687{
688 u16 val;
689
690 _BUG_ON(!irqs_disabled());
691 DUMMY_DELAY_ACCESS;
692 val = readw(isp1362_hcd->data_reg);
693
694 return val;
695}
696
697static void isp1362_write_data32(struct isp1362_hcd *isp1362_hcd, u32 val)
698{
699 _BUG_ON(!irqs_disabled());
700#if USE_32BIT
701 DUMMY_DELAY_ACCESS;
702 writel(val, isp1362_hcd->data_reg);
703#else
704 DUMMY_DELAY_ACCESS;
705 writew((u16)val, isp1362_hcd->data_reg);
706 DUMMY_DELAY_ACCESS;
707 writew(val >> 16, isp1362_hcd->data_reg);
708#endif
709}
710
711static u32 isp1362_read_data32(struct isp1362_hcd *isp1362_hcd)
712{
713 u32 val;
714
715 _BUG_ON(!irqs_disabled());
716#if USE_32BIT
717 DUMMY_DELAY_ACCESS;
718 val = readl(isp1362_hcd->data_reg);
719#else
720 DUMMY_DELAY_ACCESS;
721 val = (u32)readw(isp1362_hcd->data_reg);
722 DUMMY_DELAY_ACCESS;
723 val |= (u32)readw(isp1362_hcd->data_reg) << 16;
724#endif
725 return val;
726}
727
728/* use readsw/writesw to access the fifo whenever possible */
729/* assume HCDIRDATA or XFERCTR & addr_reg have been set up */
730static void isp1362_read_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
731{
732 u8 *dp = buf;
733 u16 data;
734
735 if (!len)
736 return;
737
738 _BUG_ON(!irqs_disabled());
739
740 RDBG("%s: Reading %d byte from fifo to mem @ %p\n", __func__, len, buf);
741#if USE_32BIT
742 if (len >= 4) {
743 RDBG("%s: Using readsl for %d dwords\n", __func__, len >> 2);
744 readsl(isp1362_hcd->data_reg, dp, len >> 2);
745 dp += len & ~3;
746 len &= 3;
747 }
748#endif
749 if (len >= 2) {
750 RDBG("%s: Using readsw for %d words\n", __func__, len >> 1);
751 insw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
752 dp += len & ~1;
753 len &= 1;
754 }
755
756 BUG_ON(len & ~1);
757 if (len > 0) {
758 data = isp1362_read_data16(isp1362_hcd);
759 RDBG("%s: Reading trailing byte %02x to mem @ %08x\n", __func__,
760 (u8)data, (u32)dp);
761 *dp = (u8)data;
762 }
763}
764
765static void isp1362_write_fifo(struct isp1362_hcd *isp1362_hcd, void *buf, u16 len)
766{
767 u8 *dp = buf;
768 u16 data;
769
770 if (!len)
771 return;
772
773 if ((unsigned)dp & 0x1) {
774 /* not aligned */
775 for (; len > 1; len -= 2) {
776 data = *dp++;
777 data |= *dp++ << 8;
778 isp1362_write_data16(isp1362_hcd, data);
779 }
780 if (len)
781 isp1362_write_data16(isp1362_hcd, *dp);
782 return;
783 }
784
785 _BUG_ON(!irqs_disabled());
786
787 RDBG("%s: Writing %d byte to fifo from memory @%p\n", __func__, len, buf);
788#if USE_32BIT
789 if (len >= 4) {
790 RDBG("%s: Using writesl for %d dwords\n", __func__, len >> 2);
791 writesl(isp1362_hcd->data_reg, dp, len >> 2);
792 dp += len & ~3;
793 len &= 3;
794 }
795#endif
796 if (len >= 2) {
797 RDBG("%s: Using writesw for %d words\n", __func__, len >> 1);
798 outsw((unsigned long)isp1362_hcd->data_reg, dp, len >> 1);
799 dp += len & ~1;
800 len &= 1;
801 }
802
803 BUG_ON(len & ~1);
804 if (len > 0) {
805 /* finally write any trailing byte; we don't need to care
806 * about the high byte of the last word written
807 */
808 data = (u16)*dp;
809 RDBG("%s: Sending trailing byte %02x from mem @ %08x\n", __func__,
810 data, (u32)dp);
811 isp1362_write_data16(isp1362_hcd, data);
812 }
813}
814
815#define isp1362_read_reg16(d, r) ({ \
816 u16 __v; \
817 REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
818 isp1362_write_addr(d, ISP1362_REG_##r); \
819 __v = isp1362_read_data16(d); \
820 RDBG("%s: Read %04x from %s[%02x]\n", __func__, __v, #r, \
821 ISP1362_REG_NO(ISP1362_REG_##r)); \
822 __v; \
823})
824
825#define isp1362_read_reg32(d, r) ({ \
826 u32 __v; \
827 REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
828 isp1362_write_addr(d, ISP1362_REG_##r); \
829 __v = isp1362_read_data32(d); \
830 RDBG("%s: Read %08x from %s[%02x]\n", __func__, __v, #r, \
831 ISP1362_REG_NO(ISP1362_REG_##r)); \
832 __v; \
833})
834
835#define isp1362_write_reg16(d, r, v) { \
836 REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_16); \
837 isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
838 isp1362_write_data16(d, (u16)(v)); \
839 RDBG("%s: Wrote %04x to %s[%02x]\n", __func__, (u16)(v), #r, \
840 ISP1362_REG_NO(ISP1362_REG_##r)); \
841}
842
843#define isp1362_write_reg32(d, r, v) { \
844 REG_WIDTH_TEST(ISP1362_REG_##r, REG_WIDTH_32); \
845 isp1362_write_addr(d, (ISP1362_REG_##r) | ISP1362_REG_WRITE_OFFSET); \
846 isp1362_write_data32(d, (u32)(v)); \
847 RDBG("%s: Wrote %08x to %s[%02x]\n", __func__, (u32)(v), #r, \
848 ISP1362_REG_NO(ISP1362_REG_##r)); \
849}
850
851#define isp1362_set_mask16(d, r, m) { \
852 u16 __v; \
853 __v = isp1362_read_reg16(d, r); \
854 if ((__v | m) != __v) \
855 isp1362_write_reg16(d, r, __v | m); \
856}
857
858#define isp1362_clr_mask16(d, r, m) { \
859 u16 __v; \
860 __v = isp1362_read_reg16(d, r); \
861 if ((__v & ~m) != __v) \
862 isp1362_write_reg16(d, r, __v & ~m); \
863}
864
865#define isp1362_set_mask32(d, r, m) { \
866 u32 __v; \
867 __v = isp1362_read_reg32(d, r); \
868 if ((__v | m) != __v) \
869 isp1362_write_reg32(d, r, __v | m); \
870}
871
872#define isp1362_clr_mask32(d, r, m) { \
873 u32 __v; \
874 __v = isp1362_read_reg32(d, r); \
875 if ((__v & ~m) != __v) \
876 isp1362_write_reg32(d, r, __v & ~m); \
877}
878
879#ifdef ISP1362_DEBUG
880#define isp1362_show_reg(d, r) { \
881 if ((ISP1362_REG_##r & REG_WIDTH_MASK) == REG_WIDTH_32) \
882 DBG(0, "%-12s[%02x]: %08x\n", #r, \
883 ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg32(d, r)); \
884 else \
885 DBG(0, "%-12s[%02x]: %04x\n", #r, \
886 ISP1362_REG_NO(ISP1362_REG_##r), isp1362_read_reg16(d, r)); \
887}
888#else
889#define isp1362_show_reg(d, r) do {} while (0)
890#endif
891
892static void __attribute__((__unused__)) isp1362_show_regs(struct isp1362_hcd *isp1362_hcd)
893{
894 isp1362_show_reg(isp1362_hcd, HCREVISION);
895 isp1362_show_reg(isp1362_hcd, HCCONTROL);
896 isp1362_show_reg(isp1362_hcd, HCCMDSTAT);
897 isp1362_show_reg(isp1362_hcd, HCINTSTAT);
898 isp1362_show_reg(isp1362_hcd, HCINTENB);
899 isp1362_show_reg(isp1362_hcd, HCFMINTVL);
900 isp1362_show_reg(isp1362_hcd, HCFMREM);
901 isp1362_show_reg(isp1362_hcd, HCFMNUM);
902 isp1362_show_reg(isp1362_hcd, HCLSTHRESH);
903 isp1362_show_reg(isp1362_hcd, HCRHDESCA);
904 isp1362_show_reg(isp1362_hcd, HCRHDESCB);
905 isp1362_show_reg(isp1362_hcd, HCRHSTATUS);
906 isp1362_show_reg(isp1362_hcd, HCRHPORT1);
907 isp1362_show_reg(isp1362_hcd, HCRHPORT2);
908
909 isp1362_show_reg(isp1362_hcd, HCHWCFG);
910 isp1362_show_reg(isp1362_hcd, HCDMACFG);
911 isp1362_show_reg(isp1362_hcd, HCXFERCTR);
912 isp1362_show_reg(isp1362_hcd, HCuPINT);
913
914 if (in_interrupt())
915 DBG(0, "%-12s[%02x]: %04x\n", "HCuPINTENB",
916 ISP1362_REG_NO(ISP1362_REG_HCuPINTENB), isp1362_hcd->irqenb);
917 else
918 isp1362_show_reg(isp1362_hcd, HCuPINTENB);
919 isp1362_show_reg(isp1362_hcd, HCCHIPID);
920 isp1362_show_reg(isp1362_hcd, HCSCRATCH);
921 isp1362_show_reg(isp1362_hcd, HCBUFSTAT);
922 isp1362_show_reg(isp1362_hcd, HCDIRADDR);
923 /* Access would advance fifo
924 * isp1362_show_reg(isp1362_hcd, HCDIRDATA);
925 */
926 isp1362_show_reg(isp1362_hcd, HCISTLBUFSZ);
927 isp1362_show_reg(isp1362_hcd, HCISTLRATE);
928 isp1362_show_reg(isp1362_hcd, HCINTLBUFSZ);
929 isp1362_show_reg(isp1362_hcd, HCINTLBLKSZ);
930 isp1362_show_reg(isp1362_hcd, HCINTLDONE);
931 isp1362_show_reg(isp1362_hcd, HCINTLSKIP);
932 isp1362_show_reg(isp1362_hcd, HCINTLLAST);
933 isp1362_show_reg(isp1362_hcd, HCINTLCURR);
934 isp1362_show_reg(isp1362_hcd, HCATLBUFSZ);
935 isp1362_show_reg(isp1362_hcd, HCATLBLKSZ);
936 /* only valid after ATL_DONE interrupt
937 * isp1362_show_reg(isp1362_hcd, HCATLDONE);
938 */
939 isp1362_show_reg(isp1362_hcd, HCATLSKIP);
940 isp1362_show_reg(isp1362_hcd, HCATLLAST);
941 isp1362_show_reg(isp1362_hcd, HCATLCURR);
942 isp1362_show_reg(isp1362_hcd, HCATLDTC);
943 isp1362_show_reg(isp1362_hcd, HCATLDTCTO);
944}
945
946static void isp1362_write_diraddr(struct isp1362_hcd *isp1362_hcd, u16 offset, u16 len)
947{
948 _BUG_ON(offset & 1);
949 _BUG_ON(offset >= ISP1362_BUF_SIZE);
950 _BUG_ON(len > ISP1362_BUF_SIZE);
951 _BUG_ON(offset + len > ISP1362_BUF_SIZE);
952 len = (len + 1) & ~1;
953
954 isp1362_clr_mask16(isp1362_hcd, HCDMACFG, HCDMACFG_CTR_ENABLE);
955 isp1362_write_reg32(isp1362_hcd, HCDIRADDR,
956 HCDIRADDR_ADDR(offset) | HCDIRADDR_COUNT(len));
957}
958
959static void isp1362_read_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
960{
961 _BUG_ON(offset & 1);
962
963 isp1362_write_diraddr(isp1362_hcd, offset, len);
964
965 DBG(3, "%s: Reading %d byte from buffer @%04x to memory @ %08x\n", __func__,
966 len, offset, (u32)buf);
967
968 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
969 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
970
971 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA);
972
973 isp1362_read_fifo(isp1362_hcd, buf, len);
974 _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
975 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
976 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
977}
978
979static void isp1362_write_buffer(struct isp1362_hcd *isp1362_hcd, void *buf, u16 offset, int len)
980{
981 _BUG_ON(offset & 1);
982
983 isp1362_write_diraddr(isp1362_hcd, offset, len);
984
985 DBG(3, "%s: Writing %d byte to buffer @%04x from memory @ %08x\n", __func__,
986 len, offset, (u32)buf);
987
988 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
989 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
990
991 isp1362_write_addr(isp1362_hcd, ISP1362_REG_HCDIRDATA | ISP1362_REG_WRITE_OFFSET);
992 isp1362_write_fifo(isp1362_hcd, buf, len);
993
994 _WARN_ON(!(isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
995 isp1362_write_reg16(isp1362_hcd, HCuPINT, HCuPINT_EOT);
996 _WARN_ON((isp1362_read_reg16(isp1362_hcd, HCuPINT) & HCuPINT_EOT));
997}
998
999static void __attribute__((unused)) dump_data(char *buf, int len)
1000{
1001 if (dbg_level > 0) {
1002 int k;
1003 int lf = 0;
1004
1005 for (k = 0; k < len; ++k) {
1006 if (!lf)
1007 DBG(0, "%04x:", k);
1008 printk(" %02x", ((u8 *) buf)[k]);
1009 lf = 1;
1010 if (!k)
1011 continue;
1012 if (k % 16 == 15) {
1013 printk("\n");
1014 lf = 0;
1015 continue;
1016 }
1017 if (k % 8 == 7)
1018 printk(" ");
1019 if (k % 4 == 3)
1020 printk(" ");
1021 }
1022 if (lf)
1023 printk("\n");
1024 }
1025}
1026
1027#if defined(ISP1362_DEBUG) && defined(PTD_TRACE)
1028
1029static void dump_ptd(struct ptd *ptd)
1030{
1031 DBG(0, "EP %p: CC=%x EP=%d DIR=%x CNT=%d LEN=%d MPS=%d TGL=%x ACT=%x FA=%d SPD=%x SF=%x PR=%x LST=%x\n",
1032 container_of(ptd, struct isp1362_ep, ptd),
1033 PTD_GET_CC(ptd), PTD_GET_EP(ptd), PTD_GET_DIR(ptd),
1034 PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
1035 PTD_GET_TOGGLE(ptd), PTD_GET_ACTIVE(ptd), PTD_GET_FA(ptd),
1036 PTD_GET_SPD(ptd), PTD_GET_SF_INT(ptd), PTD_GET_PR(ptd), PTD_GET_LAST(ptd));
1037 DBG(0, " %04x %04x %04x %04x\n", ptd->count, ptd->mps, ptd->len, ptd->faddr);
1038}
1039
1040static void dump_ptd_out_data(struct ptd *ptd, u8 *buf)
1041{
1042 if (dbg_level > 0) {
1043 if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
1044 DBG(0, "--out->\n");
1045 dump_data(buf, PTD_GET_LEN(ptd));
1046 }
1047 }
1048}
1049
1050static void dump_ptd_in_data(struct ptd *ptd, u8 *buf)
1051{
1052 if (dbg_level > 0) {
1053 if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
1054 DBG(0, "<--in--\n");
1055 dump_data(buf, PTD_GET_COUNT(ptd));
1056 }
1057 DBG(0, "-----\n");
1058 }
1059}
1060
1061static void dump_ptd_queue(struct isp1362_ep_queue *epq)
1062{
1063 struct isp1362_ep *ep;
1064 int dbg = dbg_level;
1065
1066 dbg_level = 1;
1067 list_for_each_entry(ep, &epq->active, active) {
1068 dump_ptd(&ep->ptd);
1069 dump_data(ep->data, ep->length);
1070 }
1071 dbg_level = dbg;
1072}
1073#else
1074#define dump_ptd(ptd) do {} while (0)
1075#define dump_ptd_in_data(ptd, buf) do {} while (0)
1076#define dump_ptd_out_data(ptd, buf) do {} while (0)
1077#define dump_ptd_data(ptd, buf) do {} while (0)
1078#define dump_ptd_queue(epq) do {} while (0)
1079#endif
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 15438469f21a..9600a58299db 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -386,6 +386,10 @@ static int isp1760_hc_setup(struct usb_hcd *hcd)
386 hwmode |= HW_DACK_POL_HIGH; 386 hwmode |= HW_DACK_POL_HIGH;
387 if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH) 387 if (priv->devflags & ISP1760_FLAG_DREQ_POL_HIGH)
388 hwmode |= HW_DREQ_POL_HIGH; 388 hwmode |= HW_DREQ_POL_HIGH;
389 if (priv->devflags & ISP1760_FLAG_INTR_POL_HIGH)
390 hwmode |= HW_INTR_HIGH_ACT;
391 if (priv->devflags & ISP1760_FLAG_INTR_EDGE_TRIG)
392 hwmode |= HW_INTR_EDGE_TRIG;
389 393
390 /* 394 /*
391 * We have to set this first in case we're in 16-bit mode. 395 * We have to set this first in case we're in 16-bit mode.
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index 462f4943cb1b..6931ef5c9650 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -142,6 +142,8 @@ typedef void (packet_enqueue)(struct usb_hcd *hcd, struct isp1760_qh *qh,
142#define ISP1760_FLAG_DACK_POL_HIGH 0x00000010 /* DACK active high */ 142#define ISP1760_FLAG_DACK_POL_HIGH 0x00000010 /* DACK active high */
143#define ISP1760_FLAG_DREQ_POL_HIGH 0x00000020 /* DREQ active high */ 143#define ISP1760_FLAG_DREQ_POL_HIGH 0x00000020 /* DREQ active high */
144#define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */ 144#define ISP1760_FLAG_ISP1761 0x00000040 /* Chip is ISP1761 */
145#define ISP1760_FLAG_INTR_POL_HIGH 0x00000080 /* Interrupt polarity active high */
146#define ISP1760_FLAG_INTR_EDGE_TRIG 0x00000100 /* Interrupt edge triggered */
145 147
146/* chip memory management */ 148/* chip memory management */
147struct memory_chunk { 149struct memory_chunk {
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index d4feebfc63bd..1c9f977a5c9c 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -3,6 +3,7 @@
3 * Currently there is support for 3 * Currently there is support for
4 * - OpenFirmware 4 * - OpenFirmware
5 * - PCI 5 * - PCI
6 * - PDEV (generic platform device centralized driver model)
6 * 7 *
7 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de> 8 * (c) 2007 Sebastian Siewior <bigeasy@linutronix.de>
8 * 9 *
@@ -11,6 +12,7 @@
11#include <linux/usb.h> 12#include <linux/usb.h>
12#include <linux/io.h> 13#include <linux/io.h>
13#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/usb/isp1760.h>
14 16
15#include "../core/hcd.h" 17#include "../core/hcd.h"
16#include "isp1760-hcd.h" 18#include "isp1760-hcd.h"
@@ -308,6 +310,8 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev)
308 struct resource *mem_res; 310 struct resource *mem_res;
309 struct resource *irq_res; 311 struct resource *irq_res;
310 resource_size_t mem_size; 312 resource_size_t mem_size;
313 struct isp1760_platform_data *priv = pdev->dev.platform_data;
314 unsigned int devflags = 0;
311 unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED; 315 unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED;
312 316
313 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 317 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -330,8 +334,23 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev)
330 } 334 }
331 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK; 335 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
332 336
337 if (priv) {
338 if (priv->is_isp1761)
339 devflags |= ISP1760_FLAG_ISP1761;
340 if (priv->bus_width_16)
341 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
342 if (priv->port1_otg)
343 devflags |= ISP1760_FLAG_OTG_EN;
344 if (priv->analog_oc)
345 devflags |= ISP1760_FLAG_ANALOG_OC;
346 if (priv->dack_polarity_high)
347 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
348 if (priv->dreq_polarity_high)
349 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
350 }
351
333 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, 352 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
334 irqflags, &pdev->dev, dev_name(&pdev->dev), 0); 353 irqflags, &pdev->dev, dev_name(&pdev->dev), devflags);
335 if (IS_ERR(hcd)) { 354 if (IS_ERR(hcd)) {
336 pr_warning("isp1760: Failed to register the HCD device\n"); 355 pr_warning("isp1760: Failed to register the HCD device\n");
337 ret = -ENODEV; 356 ret = -ENODEV;
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index bb5e6f671578..7ccffcbe7b6f 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -148,7 +148,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
148 at91_start_hc(pdev); 148 at91_start_hc(pdev);
149 ohci_hcd_init(hcd_to_ohci(hcd)); 149 ohci_hcd_init(hcd_to_ohci(hcd));
150 150
151 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_DISABLED); 151 retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
152 if (retval == 0) 152 if (retval == 0)
153 return retval; 153 return retval;
154 154
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 2ac4e022a13f..e4380082ebb1 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -248,10 +248,9 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
248} 248}
249 249
250#ifdef CONFIG_PM 250#ifdef CONFIG_PM
251static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev, 251static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
252 pm_message_t message)
253{ 252{
254 struct usb_hcd *hcd = platform_get_drvdata(pdev); 253 struct usb_hcd *hcd = dev_get_drvdata(dev);
255 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 254 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
256 unsigned long flags; 255 unsigned long flags;
257 int rc; 256 int rc;
@@ -274,10 +273,6 @@ static int ohci_hcd_au1xxx_drv_suspend(struct platform_device *pdev,
274 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); 273 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
275 (void)ohci_readl(ohci, &ohci->regs->intrdisable); 274 (void)ohci_readl(ohci, &ohci->regs->intrdisable);
276 275
277 /* make sure snapshot being resumed re-enumerates everything */
278 if (message.event == PM_EVENT_PRETHAW)
279 ohci_usb_reset(ohci);
280
281 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 276 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
282 277
283 au1xxx_stop_ohc(); 278 au1xxx_stop_ohc();
@@ -287,9 +282,9 @@ bail:
287 return rc; 282 return rc;
288} 283}
289 284
290static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev) 285static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
291{ 286{
292 struct usb_hcd *hcd = platform_get_drvdata(pdev); 287 struct usb_hcd *hcd = dev_get_drvdata(dev);
293 288
294 au1xxx_start_ohc(); 289 au1xxx_start_ohc();
295 290
@@ -298,20 +293,26 @@ static int ohci_hcd_au1xxx_drv_resume(struct platform_device *pdev)
298 293
299 return 0; 294 return 0;
300} 295}
296
297static struct dev_pm_ops au1xxx_ohci_pmops = {
298 .suspend = ohci_hcd_au1xxx_drv_suspend,
299 .resume = ohci_hcd_au1xxx_drv_resume,
300};
301
302#define AU1XXX_OHCI_PMOPS &au1xxx_ohci_pmops
303
301#else 304#else
302#define ohci_hcd_au1xxx_drv_suspend NULL 305#define AU1XXX_OHCI_PMOPS NULL
303#define ohci_hcd_au1xxx_drv_resume NULL
304#endif 306#endif
305 307
306static struct platform_driver ohci_hcd_au1xxx_driver = { 308static struct platform_driver ohci_hcd_au1xxx_driver = {
307 .probe = ohci_hcd_au1xxx_drv_probe, 309 .probe = ohci_hcd_au1xxx_drv_probe,
308 .remove = ohci_hcd_au1xxx_drv_remove, 310 .remove = ohci_hcd_au1xxx_drv_remove,
309 .shutdown = usb_hcd_platform_shutdown, 311 .shutdown = usb_hcd_platform_shutdown,
310 .suspend = ohci_hcd_au1xxx_drv_suspend,
311 .resume = ohci_hcd_au1xxx_drv_resume,
312 .driver = { 312 .driver = {
313 .name = "au1xxx-ohci", 313 .name = "au1xxx-ohci",
314 .owner = THIS_MODULE, 314 .owner = THIS_MODULE,
315 .pm = AU1XXX_OHCI_PMOPS,
315 }, 316 },
316}; 317};
317 318
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index b0dbf4157d29..4e681613e7ae 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -188,7 +188,6 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
188{ 188{
189 struct usb_hcd *hcd = platform_get_drvdata(pdev); 189 struct usb_hcd *hcd = platform_get_drvdata(pdev);
190 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 190 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
191 int status;
192 191
193 if (time_before(jiffies, ohci->next_statechange)) 192 if (time_before(jiffies, ohci->next_statechange))
194 msleep(5); 193 msleep(5);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 58151687d351..78bb7710f36d 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -34,7 +34,6 @@
34#include <linux/usb/otg.h> 34#include <linux/usb/otg.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/dmapool.h> 36#include <linux/dmapool.h>
37#include <linux/reboot.h>
38#include <linux/workqueue.h> 37#include <linux/workqueue.h>
39#include <linux/debugfs.h> 38#include <linux/debugfs.h>
40 39
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index e44dc2cbca24..b5294a9344de 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -177,9 +177,13 @@ static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci,
177 177
178 if (inf->flags & NO_OC_PROTECTION) 178 if (inf->flags & NO_OC_PROTECTION)
179 uhcrhda |= UHCRHDA_NOCP; 179 uhcrhda |= UHCRHDA_NOCP;
180 else
181 uhcrhda &= ~UHCRHDA_NOCP;
180 182
181 if (inf->flags & OC_MODE_PERPORT) 183 if (inf->flags & OC_MODE_PERPORT)
182 uhcrhda |= UHCRHDA_OCPM; 184 uhcrhda |= UHCRHDA_OCPM;
185 else
186 uhcrhda &= ~UHCRHDA_OCPM;
183 187
184 if (inf->power_on_delay) { 188 if (inf->power_on_delay) {
185 uhcrhda &= ~UHCRHDA_POTPGT(0xff); 189 uhcrhda &= ~UHCRHDA_POTPGT(0xff);
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index 5ac489ee3dab..50f57f468836 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -33,7 +33,6 @@
33#include <linux/timer.h> 33#include <linux/timer.h>
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/reboot.h>
37#include <linux/usb.h> 36#include <linux/usb.h>
38#include <linux/moduleparam.h> 37#include <linux/moduleparam.h>
39#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 83b5f9cea85a..23cf3bde4762 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -475,4 +475,4 @@ static void __devinit quirk_usb_early_handoff(struct pci_dev *pdev)
475 else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI) 475 else if (pdev->class == PCI_CLASS_SERIAL_USB_XHCI)
476 quirk_usb_handoff_xhci(pdev); 476 quirk_usb_handoff_xhci(pdev);
477} 477}
478DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff); 478DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, quirk_usb_early_handoff);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index a949259f18b9..5b22a4d1c9e4 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -719,8 +719,12 @@ retry:
719 /* port status seems weird until after reset, so 719 /* port status seems weird until after reset, so
720 * force the reset and make khubd clean up later. 720 * force the reset and make khubd clean up later.
721 */ 721 */
722 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION) 722 if (sl811->stat_insrmv & 1)
723 | (1 << USB_PORT_FEAT_CONNECTION); 723 sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION;
724 else
725 sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION);
726
727 sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION;
724 728
725 } else if (irqstat & SL11H_INTMASK_RD) { 729 } else if (irqstat & SL11H_INTMASK_RD) {
726 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) { 730 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 64e57bfe236b..acd582c02802 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -1422,7 +1422,6 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1422 goto err_submit_failed; 1422 goto err_submit_failed;
1423 1423
1424 /* Add this URB to the QH */ 1424 /* Add this URB to the QH */
1425 urbp->qh = qh;
1426 list_add_tail(&urbp->node, &qh->queue); 1425 list_add_tail(&urbp->node, &qh->queue);
1427 1426
1428 /* If the new URB is the first and only one on this QH then either 1427 /* If the new URB is the first and only one on this QH then either
diff --git a/drivers/usb/host/whci/asl.c b/drivers/usb/host/whci/asl.c
index c2050785a819..c632437c7649 100644
--- a/drivers/usb/host/whci/asl.c
+++ b/drivers/usb/host/whci/asl.c
@@ -227,11 +227,21 @@ void scan_async_work(struct work_struct *work)
227 /* 227 /*
228 * Now that the ASL is updated, complete the removal of any 228 * Now that the ASL is updated, complete the removal of any
229 * removed qsets. 229 * removed qsets.
230 *
231 * If the qset was to be reset, do so and reinsert it into the
232 * ASL if it has pending transfers.
230 */ 233 */
231 spin_lock_irq(&whc->lock); 234 spin_lock_irq(&whc->lock);
232 235
233 list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) { 236 list_for_each_entry_safe(qset, t, &whc->async_removed_list, list_node) {
234 qset_remove_complete(whc, qset); 237 qset_remove_complete(whc, qset);
238 if (qset->reset) {
239 qset_reset(whc, qset);
240 if (!list_empty(&qset->stds)) {
241 asl_qset_insert_begin(whc, qset);
242 queue_work(whc->workqueue, &whc->async_work);
243 }
244 }
235 } 245 }
236 246
237 spin_unlock_irq(&whc->lock); 247 spin_unlock_irq(&whc->lock);
@@ -267,7 +277,7 @@ int asl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags)
267 else 277 else
268 err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); 278 err = qset_add_urb(whc, qset, urb, GFP_ATOMIC);
269 if (!err) { 279 if (!err) {
270 if (!qset->in_sw_list) 280 if (!qset->in_sw_list && !qset->remove)
271 asl_qset_insert_begin(whc, qset); 281 asl_qset_insert_begin(whc, qset);
272 } else 282 } else
273 usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); 283 usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb);
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index e019a5058ab8..687b622a1612 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -192,19 +192,23 @@ static void whc_endpoint_reset(struct usb_hcd *usb_hcd,
192 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd); 192 struct wusbhc *wusbhc = usb_hcd_to_wusbhc(usb_hcd);
193 struct whc *whc = wusbhc_to_whc(wusbhc); 193 struct whc *whc = wusbhc_to_whc(wusbhc);
194 struct whc_qset *qset; 194 struct whc_qset *qset;
195 unsigned long flags;
196
197 spin_lock_irqsave(&whc->lock, flags);
195 198
196 qset = ep->hcpriv; 199 qset = ep->hcpriv;
197 if (qset) { 200 if (qset) {
198 qset->remove = 1; 201 qset->remove = 1;
202 qset->reset = 1;
199 203
200 if (usb_endpoint_xfer_bulk(&ep->desc) 204 if (usb_endpoint_xfer_bulk(&ep->desc)
201 || usb_endpoint_xfer_control(&ep->desc)) 205 || usb_endpoint_xfer_control(&ep->desc))
202 queue_work(whc->workqueue, &whc->async_work); 206 queue_work(whc->workqueue, &whc->async_work);
203 else 207 else
204 queue_work(whc->workqueue, &whc->periodic_work); 208 queue_work(whc->workqueue, &whc->periodic_work);
205
206 qset_reset(whc, qset);
207 } 209 }
210
211 spin_unlock_irqrestore(&whc->lock, flags);
208} 212}
209 213
210 214
diff --git a/drivers/usb/host/whci/pzl.c b/drivers/usb/host/whci/pzl.c
index ff4ef9e910d9..a9e05bac6646 100644
--- a/drivers/usb/host/whci/pzl.c
+++ b/drivers/usb/host/whci/pzl.c
@@ -255,11 +255,21 @@ void scan_periodic_work(struct work_struct *work)
255 /* 255 /*
256 * Now that the PZL is updated, complete the removal of any 256 * Now that the PZL is updated, complete the removal of any
257 * removed qsets. 257 * removed qsets.
258 *
259 * If the qset was to be reset, do so and reinsert it into the
260 * PZL if it has pending transfers.
258 */ 261 */
259 spin_lock_irq(&whc->lock); 262 spin_lock_irq(&whc->lock);
260 263
261 list_for_each_entry_safe(qset, t, &whc->periodic_removed_list, list_node) { 264 list_for_each_entry_safe(qset, t, &whc->periodic_removed_list, list_node) {
262 qset_remove_complete(whc, qset); 265 qset_remove_complete(whc, qset);
266 if (qset->reset) {
267 qset_reset(whc, qset);
268 if (!list_empty(&qset->stds)) {
269 qset_insert_in_sw_list(whc, qset);
270 queue_work(whc->workqueue, &whc->periodic_work);
271 }
272 }
263 } 273 }
264 274
265 spin_unlock_irq(&whc->lock); 275 spin_unlock_irq(&whc->lock);
@@ -295,7 +305,7 @@ int pzl_urb_enqueue(struct whc *whc, struct urb *urb, gfp_t mem_flags)
295 else 305 else
296 err = qset_add_urb(whc, qset, urb, GFP_ATOMIC); 306 err = qset_add_urb(whc, qset, urb, GFP_ATOMIC);
297 if (!err) { 307 if (!err) {
298 if (!qset->in_sw_list) 308 if (!qset->in_sw_list && !qset->remove)
299 qset_insert_in_sw_list(whc, qset); 309 qset_insert_in_sw_list(whc, qset);
300 } else 310 } else
301 usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb); 311 usb_hcd_unlink_urb_from_ep(&whc->wusbhc.usb_hcd, urb);
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index 640b38fbd051..1b9dc1571570 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -103,7 +103,6 @@ static void qset_fill_qh(struct whc_qset *qset, struct urb *urb)
103void qset_clear(struct whc *whc, struct whc_qset *qset) 103void qset_clear(struct whc *whc, struct whc_qset *qset)
104{ 104{
105 qset->td_start = qset->td_end = qset->ntds = 0; 105 qset->td_start = qset->td_end = qset->ntds = 0;
106 qset->remove = 0;
107 106
108 qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T); 107 qset->qh.link = cpu_to_le32(QH_LINK_NTDS(8) | QH_LINK_T);
109 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK; 108 qset->qh.status = qset->qh.status & QH_STATUS_SEQ_MASK;
@@ -125,7 +124,7 @@ void qset_clear(struct whc *whc, struct whc_qset *qset)
125 */ 124 */
126void qset_reset(struct whc *whc, struct whc_qset *qset) 125void qset_reset(struct whc *whc, struct whc_qset *qset)
127{ 126{
128 wait_for_completion(&qset->remove_complete); 127 qset->reset = 0;
129 128
130 qset->qh.status &= ~QH_STATUS_SEQ_MASK; 129 qset->qh.status &= ~QH_STATUS_SEQ_MASK;
131 qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1); 130 qset->qh.cur_window = cpu_to_le32((1 << qset->max_burst) - 1);
@@ -156,6 +155,7 @@ struct whc_qset *get_qset(struct whc *whc, struct urb *urb,
156 155
157void qset_remove_complete(struct whc *whc, struct whc_qset *qset) 156void qset_remove_complete(struct whc *whc, struct whc_qset *qset)
158{ 157{
158 qset->remove = 0;
159 list_del_init(&qset->list_node); 159 list_del_init(&qset->list_node);
160 complete(&qset->remove_complete); 160 complete(&qset->remove_complete);
161} 161}
diff --git a/drivers/usb/host/whci/whci-hc.h b/drivers/usb/host/whci/whci-hc.h
index 794dba0d0f0a..e8d0001605be 100644
--- a/drivers/usb/host/whci/whci-hc.h
+++ b/drivers/usb/host/whci/whci-hc.h
@@ -264,6 +264,7 @@ struct whc_qset {
264 unsigned in_sw_list:1; 264 unsigned in_sw_list:1;
265 unsigned in_hw_list:1; 265 unsigned in_hw_list:1;
266 unsigned remove:1; 266 unsigned remove:1;
267 unsigned reset:1;
267 struct urb *pause_after_urb; 268 struct urb *pause_after_urb;
268 struct completion remove_complete; 269 struct completion remove_complete;
269 int max_burst; 270 int max_burst;
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 705e34324156..33128d52f212 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -413,7 +413,8 @@ void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
413 int i; 413 int i;
414 414
415 struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx); 415 struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
416 dma_addr_t dma = ctx->dma + ((unsigned long)slot_ctx - (unsigned long)ctx); 416 dma_addr_t dma = ctx->dma +
417 ((unsigned long)slot_ctx - (unsigned long)ctx->bytes);
417 int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params); 418 int csz = HCC_64BYTE_CONTEXT(xhci->hcc_params);
418 419
419 xhci_dbg(xhci, "Slot Context:\n"); 420 xhci_dbg(xhci, "Slot Context:\n");
@@ -459,7 +460,7 @@ void xhci_dbg_ep_ctx(struct xhci_hcd *xhci,
459 for (i = 0; i < last_ep_ctx; ++i) { 460 for (i = 0; i < last_ep_ctx; ++i) {
460 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i); 461 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, ctx, i);
461 dma_addr_t dma = ctx->dma + 462 dma_addr_t dma = ctx->dma +
462 ((unsigned long)ep_ctx - (unsigned long)ctx); 463 ((unsigned long)ep_ctx - (unsigned long)ctx->bytes);
463 464
464 xhci_dbg(xhci, "Endpoint %02d Context:\n", i); 465 xhci_dbg(xhci, "Endpoint %02d Context:\n", i);
465 xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n", 466 xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - ep_info\n",
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci-hcd.c
index 816c39caca1c..99911e727e0b 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci-hcd.c
@@ -22,12 +22,18 @@
22 22
23#include <linux/irq.h> 23#include <linux/irq.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h>
25 26
26#include "xhci.h" 27#include "xhci.h"
27 28
28#define DRIVER_AUTHOR "Sarah Sharp" 29#define DRIVER_AUTHOR "Sarah Sharp"
29#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" 30#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
30 31
32/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
33static int link_quirk;
34module_param(link_quirk, int, S_IRUGO | S_IWUSR);
35MODULE_PARM_DESC(link_quirk, "Don't clear the chain bit on a link TRB");
36
31/* TODO: copied from ehci-hcd.c - can this be refactored? */ 37/* TODO: copied from ehci-hcd.c - can this be refactored? */
32/* 38/*
33 * handshake - spin reading hc until handshake completes or fails 39 * handshake - spin reading hc until handshake completes or fails
@@ -214,6 +220,12 @@ int xhci_init(struct usb_hcd *hcd)
214 220
215 xhci_dbg(xhci, "xhci_init\n"); 221 xhci_dbg(xhci, "xhci_init\n");
216 spin_lock_init(&xhci->lock); 222 spin_lock_init(&xhci->lock);
223 if (link_quirk) {
224 xhci_dbg(xhci, "QUIRK: Not clearing Link TRB chain bits.\n");
225 xhci->quirks |= XHCI_LINK_TRB_QUIRK;
226 } else {
227 xhci_dbg(xhci, "xHCI doesn't need link TRB QUIRK\n");
228 }
217 retval = xhci_mem_init(xhci, GFP_KERNEL); 229 retval = xhci_mem_init(xhci, GFP_KERNEL);
218 xhci_dbg(xhci, "Finished xhci_init\n"); 230 xhci_dbg(xhci, "Finished xhci_init\n");
219 231
@@ -339,13 +351,14 @@ void xhci_event_ring_work(unsigned long arg)
339 xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring); 351 xhci_dbg_ring_ptrs(xhci, xhci->cmd_ring);
340 xhci_dbg_cmd_ptrs(xhci); 352 xhci_dbg_cmd_ptrs(xhci);
341 for (i = 0; i < MAX_HC_SLOTS; ++i) { 353 for (i = 0; i < MAX_HC_SLOTS; ++i) {
342 if (xhci->devs[i]) { 354 if (!xhci->devs[i])
343 for (j = 0; j < 31; ++j) { 355 continue;
344 if (xhci->devs[i]->ep_rings[j]) { 356 for (j = 0; j < 31; ++j) {
345 xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j); 357 struct xhci_ring *ring = xhci->devs[i]->eps[j].ring;
346 xhci_debug_segment(xhci, xhci->devs[i]->ep_rings[j]->deq_seg); 358 if (!ring)
347 } 359 continue;
348 } 360 xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j);
361 xhci_debug_segment(xhci, ring->deq_seg);
349 } 362 }
350 } 363 }
351 364
@@ -555,13 +568,22 @@ unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc)
555 return 1 << (xhci_get_endpoint_index(desc) + 1); 568 return 1 << (xhci_get_endpoint_index(desc) + 1);
556} 569}
557 570
571/* Find the flag for this endpoint (for use in the control context). Use the
572 * endpoint index to create a bitmask. The slot context is bit 0, endpoint 0 is
573 * bit 1, etc.
574 */
575unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index)
576{
577 return 1 << (ep_index + 1);
578}
579
558/* Compute the last valid endpoint context index. Basically, this is the 580/* Compute the last valid endpoint context index. Basically, this is the
559 * endpoint index plus one. For slot contexts with more than valid endpoint, 581 * endpoint index plus one. For slot contexts with more than valid endpoint,
560 * we find the most significant bit set in the added contexts flags. 582 * we find the most significant bit set in the added contexts flags.
561 * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000 583 * e.g. ep 1 IN (with epnum 0x81) => added_ctxs = 0b1000
562 * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one. 584 * fls(0b1000) = 4, but the endpoint context index is 3, so subtract one.
563 */ 585 */
564static inline unsigned int xhci_last_valid_endpoint(u32 added_ctxs) 586unsigned int xhci_last_valid_endpoint(u32 added_ctxs)
565{ 587{
566 return fls(added_ctxs) - 1; 588 return fls(added_ctxs) - 1;
567} 589}
@@ -589,6 +611,71 @@ int xhci_check_args(struct usb_hcd *hcd, struct usb_device *udev,
589 return 1; 611 return 1;
590} 612}
591 613
614static int xhci_configure_endpoint(struct xhci_hcd *xhci,
615 struct usb_device *udev, struct xhci_command *command,
616 bool ctx_change, bool must_succeed);
617
618/*
619 * Full speed devices may have a max packet size greater than 8 bytes, but the
620 * USB core doesn't know that until it reads the first 8 bytes of the
621 * descriptor. If the usb_device's max packet size changes after that point,
622 * we need to issue an evaluate context command and wait on it.
623 */
624static int xhci_check_maxpacket(struct xhci_hcd *xhci, unsigned int slot_id,
625 unsigned int ep_index, struct urb *urb)
626{
627 struct xhci_container_ctx *in_ctx;
628 struct xhci_container_ctx *out_ctx;
629 struct xhci_input_control_ctx *ctrl_ctx;
630 struct xhci_ep_ctx *ep_ctx;
631 int max_packet_size;
632 int hw_max_packet_size;
633 int ret = 0;
634
635 out_ctx = xhci->devs[slot_id]->out_ctx;
636 ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
637 hw_max_packet_size = MAX_PACKET_DECODED(ep_ctx->ep_info2);
638 max_packet_size = urb->dev->ep0.desc.wMaxPacketSize;
639 if (hw_max_packet_size != max_packet_size) {
640 xhci_dbg(xhci, "Max Packet Size for ep 0 changed.\n");
641 xhci_dbg(xhci, "Max packet size in usb_device = %d\n",
642 max_packet_size);
643 xhci_dbg(xhci, "Max packet size in xHCI HW = %d\n",
644 hw_max_packet_size);
645 xhci_dbg(xhci, "Issuing evaluate context command.\n");
646
647 /* Set up the modified control endpoint 0 */
648 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx,
649 xhci->devs[slot_id]->out_ctx, ep_index);
650 in_ctx = xhci->devs[slot_id]->in_ctx;
651 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
652 ep_ctx->ep_info2 &= ~MAX_PACKET_MASK;
653 ep_ctx->ep_info2 |= MAX_PACKET(max_packet_size);
654
655 /* Set up the input context flags for the command */
656 /* FIXME: This won't work if a non-default control endpoint
657 * changes max packet sizes.
658 */
659 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
660 ctrl_ctx->add_flags = EP0_FLAG;
661 ctrl_ctx->drop_flags = 0;
662
663 xhci_dbg(xhci, "Slot %d input context\n", slot_id);
664 xhci_dbg_ctx(xhci, in_ctx, ep_index);
665 xhci_dbg(xhci, "Slot %d output context\n", slot_id);
666 xhci_dbg_ctx(xhci, out_ctx, ep_index);
667
668 ret = xhci_configure_endpoint(xhci, urb->dev, NULL,
669 true, false);
670
671 /* Clean up the input context for later use by bandwidth
672 * functions.
673 */
674 ctrl_ctx->add_flags = SLOT_FLAG;
675 }
676 return ret;
677}
678
592/* 679/*
593 * non-error returns are a promise to giveback() the urb later 680 * non-error returns are a promise to giveback() the urb later
594 * we drop ownership so next owner (or urb unlink) can get it 681 * we drop ownership so next owner (or urb unlink) can get it
@@ -600,13 +687,13 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
600 int ret = 0; 687 int ret = 0;
601 unsigned int slot_id, ep_index; 688 unsigned int slot_id, ep_index;
602 689
690
603 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0) 691 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, true, __func__) <= 0)
604 return -EINVAL; 692 return -EINVAL;
605 693
606 slot_id = urb->dev->slot_id; 694 slot_id = urb->dev->slot_id;
607 ep_index = xhci_get_endpoint_index(&urb->ep->desc); 695 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
608 696
609 spin_lock_irqsave(&xhci->lock, flags);
610 if (!xhci->devs || !xhci->devs[slot_id]) { 697 if (!xhci->devs || !xhci->devs[slot_id]) {
611 if (!in_interrupt()) 698 if (!in_interrupt())
612 dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n"); 699 dev_warn(&urb->dev->dev, "WARN: urb submitted for dev with no Slot ID\n");
@@ -619,19 +706,38 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
619 ret = -ESHUTDOWN; 706 ret = -ESHUTDOWN;
620 goto exit; 707 goto exit;
621 } 708 }
622 if (usb_endpoint_xfer_control(&urb->ep->desc)) 709 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
710 /* Check to see if the max packet size for the default control
711 * endpoint changed during FS device enumeration
712 */
713 if (urb->dev->speed == USB_SPEED_FULL) {
714 ret = xhci_check_maxpacket(xhci, slot_id,
715 ep_index, urb);
716 if (ret < 0)
717 return ret;
718 }
719
623 /* We have a spinlock and interrupts disabled, so we must pass 720 /* We have a spinlock and interrupts disabled, so we must pass
624 * atomic context to this function, which may allocate memory. 721 * atomic context to this function, which may allocate memory.
625 */ 722 */
723 spin_lock_irqsave(&xhci->lock, flags);
626 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, 724 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
627 slot_id, ep_index); 725 slot_id, ep_index);
628 else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) 726 spin_unlock_irqrestore(&xhci->lock, flags);
727 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
728 spin_lock_irqsave(&xhci->lock, flags);
629 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 729 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
630 slot_id, ep_index); 730 slot_id, ep_index);
631 else 731 spin_unlock_irqrestore(&xhci->lock, flags);
732 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
733 spin_lock_irqsave(&xhci->lock, flags);
734 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
735 slot_id, ep_index);
736 spin_unlock_irqrestore(&xhci->lock, flags);
737 } else {
632 ret = -EINVAL; 738 ret = -EINVAL;
739 }
633exit: 740exit:
634 spin_unlock_irqrestore(&xhci->lock, flags);
635 return ret; 741 return ret;
636} 742}
637 743
@@ -674,6 +780,7 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
674 struct xhci_td *td; 780 struct xhci_td *td;
675 unsigned int ep_index; 781 unsigned int ep_index;
676 struct xhci_ring *ep_ring; 782 struct xhci_ring *ep_ring;
783 struct xhci_virt_ep *ep;
677 784
678 xhci = hcd_to_xhci(hcd); 785 xhci = hcd_to_xhci(hcd);
679 spin_lock_irqsave(&xhci->lock, flags); 786 spin_lock_irqsave(&xhci->lock, flags);
@@ -686,17 +793,18 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
686 xhci_dbg(xhci, "Event ring:\n"); 793 xhci_dbg(xhci, "Event ring:\n");
687 xhci_debug_ring(xhci, xhci->event_ring); 794 xhci_debug_ring(xhci, xhci->event_ring);
688 ep_index = xhci_get_endpoint_index(&urb->ep->desc); 795 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
689 ep_ring = xhci->devs[urb->dev->slot_id]->ep_rings[ep_index]; 796 ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index];
797 ep_ring = ep->ring;
690 xhci_dbg(xhci, "Endpoint ring:\n"); 798 xhci_dbg(xhci, "Endpoint ring:\n");
691 xhci_debug_ring(xhci, ep_ring); 799 xhci_debug_ring(xhci, ep_ring);
692 td = (struct xhci_td *) urb->hcpriv; 800 td = (struct xhci_td *) urb->hcpriv;
693 801
694 ep_ring->cancels_pending++; 802 ep->cancels_pending++;
695 list_add_tail(&td->cancelled_td_list, &ep_ring->cancelled_td_list); 803 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list);
696 /* Queue a stop endpoint command, but only if this is 804 /* Queue a stop endpoint command, but only if this is
697 * the first cancellation to be handled. 805 * the first cancellation to be handled.
698 */ 806 */
699 if (ep_ring->cancels_pending == 1) { 807 if (ep->cancels_pending == 1) {
700 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); 808 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index);
701 xhci_ring_cmd_db(xhci); 809 xhci_ring_cmd_db(xhci);
702 } 810 }
@@ -930,6 +1038,141 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir
930 } 1038 }
931} 1039}
932 1040
1041static int xhci_configure_endpoint_result(struct xhci_hcd *xhci,
1042 struct usb_device *udev, int *cmd_status)
1043{
1044 int ret;
1045
1046 switch (*cmd_status) {
1047 case COMP_ENOMEM:
1048 dev_warn(&udev->dev, "Not enough host controller resources "
1049 "for new device state.\n");
1050 ret = -ENOMEM;
1051 /* FIXME: can we allocate more resources for the HC? */
1052 break;
1053 case COMP_BW_ERR:
1054 dev_warn(&udev->dev, "Not enough bandwidth "
1055 "for new device state.\n");
1056 ret = -ENOSPC;
1057 /* FIXME: can we go back to the old state? */
1058 break;
1059 case COMP_TRB_ERR:
1060 /* the HCD set up something wrong */
1061 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, "
1062 "add flag = 1, "
1063 "and endpoint is not disabled.\n");
1064 ret = -EINVAL;
1065 break;
1066 case COMP_SUCCESS:
1067 dev_dbg(&udev->dev, "Successful Endpoint Configure command\n");
1068 ret = 0;
1069 break;
1070 default:
1071 xhci_err(xhci, "ERROR: unexpected command completion "
1072 "code 0x%x.\n", *cmd_status);
1073 ret = -EINVAL;
1074 break;
1075 }
1076 return ret;
1077}
1078
1079static int xhci_evaluate_context_result(struct xhci_hcd *xhci,
1080 struct usb_device *udev, int *cmd_status)
1081{
1082 int ret;
1083 struct xhci_virt_device *virt_dev = xhci->devs[udev->slot_id];
1084
1085 switch (*cmd_status) {
1086 case COMP_EINVAL:
1087 dev_warn(&udev->dev, "WARN: xHCI driver setup invalid evaluate "
1088 "context command.\n");
1089 ret = -EINVAL;
1090 break;
1091 case COMP_EBADSLT:
1092 dev_warn(&udev->dev, "WARN: slot not enabled for"
1093 "evaluate context command.\n");
1094 case COMP_CTX_STATE:
1095 dev_warn(&udev->dev, "WARN: invalid context state for "
1096 "evaluate context command.\n");
1097 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 1);
1098 ret = -EINVAL;
1099 break;
1100 case COMP_SUCCESS:
1101 dev_dbg(&udev->dev, "Successful evaluate context command\n");
1102 ret = 0;
1103 break;
1104 default:
1105 xhci_err(xhci, "ERROR: unexpected command completion "
1106 "code 0x%x.\n", *cmd_status);
1107 ret = -EINVAL;
1108 break;
1109 }
1110 return ret;
1111}
1112
1113/* Issue a configure endpoint command or evaluate context command
1114 * and wait for it to finish.
1115 */
1116static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1117 struct usb_device *udev,
1118 struct xhci_command *command,
1119 bool ctx_change, bool must_succeed)
1120{
1121 int ret;
1122 int timeleft;
1123 unsigned long flags;
1124 struct xhci_container_ctx *in_ctx;
1125 struct completion *cmd_completion;
1126 int *cmd_status;
1127 struct xhci_virt_device *virt_dev;
1128
1129 spin_lock_irqsave(&xhci->lock, flags);
1130 virt_dev = xhci->devs[udev->slot_id];
1131 if (command) {
1132 in_ctx = command->in_ctx;
1133 cmd_completion = command->completion;
1134 cmd_status = &command->status;
1135 command->command_trb = xhci->cmd_ring->enqueue;
1136 list_add_tail(&command->cmd_list, &virt_dev->cmd_list);
1137 } else {
1138 in_ctx = virt_dev->in_ctx;
1139 cmd_completion = &virt_dev->cmd_completion;
1140 cmd_status = &virt_dev->cmd_status;
1141 }
1142
1143 if (!ctx_change)
1144 ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma,
1145 udev->slot_id, must_succeed);
1146 else
1147 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma,
1148 udev->slot_id);
1149 if (ret < 0) {
1150 spin_unlock_irqrestore(&xhci->lock, flags);
1151 xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
1152 return -ENOMEM;
1153 }
1154 xhci_ring_cmd_db(xhci);
1155 spin_unlock_irqrestore(&xhci->lock, flags);
1156
1157 /* Wait for the configure endpoint command to complete */
1158 timeleft = wait_for_completion_interruptible_timeout(
1159 cmd_completion,
1160 USB_CTRL_SET_TIMEOUT);
1161 if (timeleft <= 0) {
1162 xhci_warn(xhci, "%s while waiting for %s command\n",
1163 timeleft == 0 ? "Timeout" : "Signal",
1164 ctx_change == 0 ?
1165 "configure endpoint" :
1166 "evaluate context");
1167 /* FIXME cancel the configure endpoint command */
1168 return -ETIME;
1169 }
1170
1171 if (!ctx_change)
1172 return xhci_configure_endpoint_result(xhci, udev, cmd_status);
1173 return xhci_evaluate_context_result(xhci, udev, cmd_status);
1174}
1175
933/* Called after one or more calls to xhci_add_endpoint() or 1176/* Called after one or more calls to xhci_add_endpoint() or
934 * xhci_drop_endpoint(). If this call fails, the USB core is expected 1177 * xhci_drop_endpoint(). If this call fails, the USB core is expected
935 * to call xhci_reset_bandwidth(). 1178 * to call xhci_reset_bandwidth().
@@ -944,8 +1187,6 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
944{ 1187{
945 int i; 1188 int i;
946 int ret = 0; 1189 int ret = 0;
947 int timeleft;
948 unsigned long flags;
949 struct xhci_hcd *xhci; 1190 struct xhci_hcd *xhci;
950 struct xhci_virt_device *virt_dev; 1191 struct xhci_virt_device *virt_dev;
951 struct xhci_input_control_ctx *ctrl_ctx; 1192 struct xhci_input_control_ctx *ctrl_ctx;
@@ -975,56 +1216,8 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
975 xhci_dbg_ctx(xhci, virt_dev->in_ctx, 1216 xhci_dbg_ctx(xhci, virt_dev->in_ctx,
976 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); 1217 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info));
977 1218
978 spin_lock_irqsave(&xhci->lock, flags); 1219 ret = xhci_configure_endpoint(xhci, udev, NULL,
979 ret = xhci_queue_configure_endpoint(xhci, virt_dev->in_ctx->dma, 1220 false, false);
980 udev->slot_id);
981 if (ret < 0) {
982 spin_unlock_irqrestore(&xhci->lock, flags);
983 xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
984 return -ENOMEM;
985 }
986 xhci_ring_cmd_db(xhci);
987 spin_unlock_irqrestore(&xhci->lock, flags);
988
989 /* Wait for the configure endpoint command to complete */
990 timeleft = wait_for_completion_interruptible_timeout(
991 &virt_dev->cmd_completion,
992 USB_CTRL_SET_TIMEOUT);
993 if (timeleft <= 0) {
994 xhci_warn(xhci, "%s while waiting for configure endpoint command\n",
995 timeleft == 0 ? "Timeout" : "Signal");
996 /* FIXME cancel the configure endpoint command */
997 return -ETIME;
998 }
999
1000 switch (virt_dev->cmd_status) {
1001 case COMP_ENOMEM:
1002 dev_warn(&udev->dev, "Not enough host controller resources "
1003 "for new device state.\n");
1004 ret = -ENOMEM;
1005 /* FIXME: can we allocate more resources for the HC? */
1006 break;
1007 case COMP_BW_ERR:
1008 dev_warn(&udev->dev, "Not enough bandwidth "
1009 "for new device state.\n");
1010 ret = -ENOSPC;
1011 /* FIXME: can we go back to the old state? */
1012 break;
1013 case COMP_TRB_ERR:
1014 /* the HCD set up something wrong */
1015 dev_warn(&udev->dev, "ERROR: Endpoint drop flag = 0, add flag = 1, "
1016 "and endpoint is not disabled.\n");
1017 ret = -EINVAL;
1018 break;
1019 case COMP_SUCCESS:
1020 dev_dbg(&udev->dev, "Successful Endpoint Configure command\n");
1021 break;
1022 default:
1023 xhci_err(xhci, "ERROR: unexpected command completion "
1024 "code 0x%x.\n", virt_dev->cmd_status);
1025 ret = -EINVAL;
1026 break;
1027 }
1028 if (ret) { 1221 if (ret) {
1029 /* Callee should call reset_bandwidth() */ 1222 /* Callee should call reset_bandwidth() */
1030 return ret; 1223 return ret;
@@ -1037,10 +1230,10 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1037 xhci_zero_in_ctx(xhci, virt_dev); 1230 xhci_zero_in_ctx(xhci, virt_dev);
1038 /* Free any old rings */ 1231 /* Free any old rings */
1039 for (i = 1; i < 31; ++i) { 1232 for (i = 1; i < 31; ++i) {
1040 if (virt_dev->new_ep_rings[i]) { 1233 if (virt_dev->eps[i].new_ring) {
1041 xhci_ring_free(xhci, virt_dev->ep_rings[i]); 1234 xhci_ring_free(xhci, virt_dev->eps[i].ring);
1042 virt_dev->ep_rings[i] = virt_dev->new_ep_rings[i]; 1235 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring;
1043 virt_dev->new_ep_rings[i] = NULL; 1236 virt_dev->eps[i].new_ring = NULL;
1044 } 1237 }
1045 } 1238 }
1046 1239
@@ -1067,14 +1260,93 @@ void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1067 virt_dev = xhci->devs[udev->slot_id]; 1260 virt_dev = xhci->devs[udev->slot_id];
1068 /* Free any rings allocated for added endpoints */ 1261 /* Free any rings allocated for added endpoints */
1069 for (i = 0; i < 31; ++i) { 1262 for (i = 0; i < 31; ++i) {
1070 if (virt_dev->new_ep_rings[i]) { 1263 if (virt_dev->eps[i].new_ring) {
1071 xhci_ring_free(xhci, virt_dev->new_ep_rings[i]); 1264 xhci_ring_free(xhci, virt_dev->eps[i].new_ring);
1072 virt_dev->new_ep_rings[i] = NULL; 1265 virt_dev->eps[i].new_ring = NULL;
1073 } 1266 }
1074 } 1267 }
1075 xhci_zero_in_ctx(xhci, virt_dev); 1268 xhci_zero_in_ctx(xhci, virt_dev);
1076} 1269}
1077 1270
1271static void xhci_setup_input_ctx_for_config_ep(struct xhci_hcd *xhci,
1272 struct xhci_container_ctx *in_ctx,
1273 struct xhci_container_ctx *out_ctx,
1274 u32 add_flags, u32 drop_flags)
1275{
1276 struct xhci_input_control_ctx *ctrl_ctx;
1277 ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
1278 ctrl_ctx->add_flags = add_flags;
1279 ctrl_ctx->drop_flags = drop_flags;
1280 xhci_slot_copy(xhci, in_ctx, out_ctx);
1281 ctrl_ctx->add_flags |= SLOT_FLAG;
1282
1283 xhci_dbg(xhci, "Input Context:\n");
1284 xhci_dbg_ctx(xhci, in_ctx, xhci_last_valid_endpoint(add_flags));
1285}
1286
1287void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
1288 unsigned int slot_id, unsigned int ep_index,
1289 struct xhci_dequeue_state *deq_state)
1290{
1291 struct xhci_container_ctx *in_ctx;
1292 struct xhci_ep_ctx *ep_ctx;
1293 u32 added_ctxs;
1294 dma_addr_t addr;
1295
1296 xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx,
1297 xhci->devs[slot_id]->out_ctx, ep_index);
1298 in_ctx = xhci->devs[slot_id]->in_ctx;
1299 ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
1300 addr = xhci_trb_virt_to_dma(deq_state->new_deq_seg,
1301 deq_state->new_deq_ptr);
1302 if (addr == 0) {
1303 xhci_warn(xhci, "WARN Cannot submit config ep after "
1304 "reset ep command\n");
1305 xhci_warn(xhci, "WARN deq seg = %p, deq ptr = %p\n",
1306 deq_state->new_deq_seg,
1307 deq_state->new_deq_ptr);
1308 return;
1309 }
1310 ep_ctx->deq = addr | deq_state->new_cycle_state;
1311
1312 added_ctxs = xhci_get_endpoint_flag_from_index(ep_index);
1313 xhci_setup_input_ctx_for_config_ep(xhci, xhci->devs[slot_id]->in_ctx,
1314 xhci->devs[slot_id]->out_ctx, added_ctxs, added_ctxs);
1315}
1316
1317void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1318 struct usb_device *udev, unsigned int ep_index)
1319{
1320 struct xhci_dequeue_state deq_state;
1321 struct xhci_virt_ep *ep;
1322
1323 xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n");
1324 ep = &xhci->devs[udev->slot_id]->eps[ep_index];
1325 /* We need to move the HW's dequeue pointer past this TD,
1326 * or it will attempt to resend it on the next doorbell ring.
1327 */
1328 xhci_find_new_dequeue_state(xhci, udev->slot_id,
1329 ep_index, ep->stopped_td,
1330 &deq_state);
1331
1332 /* HW with the reset endpoint quirk will use the saved dequeue state to
1333 * issue a configure endpoint command later.
1334 */
1335 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
1336 xhci_dbg(xhci, "Queueing new dequeue state\n");
1337 xhci_queue_new_dequeue_state(xhci, udev->slot_id,
1338 ep_index, &deq_state);
1339 } else {
1340 /* Better hope no one uses the input context between now and the
1341 * reset endpoint completion!
1342 */
1343 xhci_dbg(xhci, "Setting up input context for "
1344 "configure endpoint command\n");
1345 xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id,
1346 ep_index, &deq_state);
1347 }
1348}
1349
1078/* Deal with stalled endpoints. The core should have sent the control message 1350/* Deal with stalled endpoints. The core should have sent the control message
1079 * to clear the halt condition. However, we need to make the xHCI hardware 1351 * to clear the halt condition. However, we need to make the xHCI hardware
1080 * reset its sequence number, since a device will expect a sequence number of 1352 * reset its sequence number, since a device will expect a sequence number of
@@ -1089,8 +1361,7 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1089 unsigned int ep_index; 1361 unsigned int ep_index;
1090 unsigned long flags; 1362 unsigned long flags;
1091 int ret; 1363 int ret;
1092 struct xhci_dequeue_state deq_state; 1364 struct xhci_virt_ep *virt_ep;
1093 struct xhci_ring *ep_ring;
1094 1365
1095 xhci = hcd_to_xhci(hcd); 1366 xhci = hcd_to_xhci(hcd);
1096 udev = (struct usb_device *) ep->hcpriv; 1367 udev = (struct usb_device *) ep->hcpriv;
@@ -1100,12 +1371,16 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1100 if (!ep->hcpriv) 1371 if (!ep->hcpriv)
1101 return; 1372 return;
1102 ep_index = xhci_get_endpoint_index(&ep->desc); 1373 ep_index = xhci_get_endpoint_index(&ep->desc);
1103 ep_ring = xhci->devs[udev->slot_id]->ep_rings[ep_index]; 1374 virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index];
1104 if (!ep_ring->stopped_td) { 1375 if (!virt_ep->stopped_td) {
1105 xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n", 1376 xhci_dbg(xhci, "Endpoint 0x%x not halted, refusing to reset.\n",
1106 ep->desc.bEndpointAddress); 1377 ep->desc.bEndpointAddress);
1107 return; 1378 return;
1108 } 1379 }
1380 if (usb_endpoint_xfer_control(&ep->desc)) {
1381 xhci_dbg(xhci, "Control endpoint stall already handled.\n");
1382 return;
1383 }
1109 1384
1110 xhci_dbg(xhci, "Queueing reset endpoint command\n"); 1385 xhci_dbg(xhci, "Queueing reset endpoint command\n");
1111 spin_lock_irqsave(&xhci->lock, flags); 1386 spin_lock_irqsave(&xhci->lock, flags);
@@ -1116,17 +1391,8 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1116 * command. Better hope that last command worked! 1391 * command. Better hope that last command worked!
1117 */ 1392 */
1118 if (!ret) { 1393 if (!ret) {
1119 xhci_dbg(xhci, "Cleaning up stalled endpoint ring\n"); 1394 xhci_cleanup_stalled_ring(xhci, udev, ep_index);
1120 /* We need to move the HW's dequeue pointer past this TD, 1395 kfree(virt_ep->stopped_td);
1121 * or it will attempt to resend it on the next doorbell ring.
1122 */
1123 xhci_find_new_dequeue_state(xhci, udev->slot_id,
1124 ep_index, ep_ring->stopped_td, &deq_state);
1125 xhci_dbg(xhci, "Queueing new dequeue state\n");
1126 xhci_queue_new_dequeue_state(xhci, ep_ring,
1127 udev->slot_id,
1128 ep_index, &deq_state);
1129 kfree(ep_ring->stopped_td);
1130 xhci_ring_cmd_db(xhci); 1396 xhci_ring_cmd_db(xhci);
1131 } 1397 }
1132 spin_unlock_irqrestore(&xhci->lock, flags); 1398 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -1328,6 +1594,88 @@ int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev)
1328 return 0; 1594 return 0;
1329} 1595}
1330 1596
1597/* Once a hub descriptor is fetched for a device, we need to update the xHC's
1598 * internal data structures for the device.
1599 */
1600int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1601 struct usb_tt *tt, gfp_t mem_flags)
1602{
1603 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1604 struct xhci_virt_device *vdev;
1605 struct xhci_command *config_cmd;
1606 struct xhci_input_control_ctx *ctrl_ctx;
1607 struct xhci_slot_ctx *slot_ctx;
1608 unsigned long flags;
1609 unsigned think_time;
1610 int ret;
1611
1612 /* Ignore root hubs */
1613 if (!hdev->parent)
1614 return 0;
1615
1616 vdev = xhci->devs[hdev->slot_id];
1617 if (!vdev) {
1618 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n");
1619 return -EINVAL;
1620 }
1621 config_cmd = xhci_alloc_command(xhci, true, mem_flags);
1622 if (!config_cmd) {
1623 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n");
1624 return -ENOMEM;
1625 }
1626
1627 spin_lock_irqsave(&xhci->lock, flags);
1628 xhci_slot_copy(xhci, config_cmd->in_ctx, vdev->out_ctx);
1629 ctrl_ctx = xhci_get_input_control_ctx(xhci, config_cmd->in_ctx);
1630 ctrl_ctx->add_flags |= SLOT_FLAG;
1631 slot_ctx = xhci_get_slot_ctx(xhci, config_cmd->in_ctx);
1632 slot_ctx->dev_info |= DEV_HUB;
1633 if (tt->multi)
1634 slot_ctx->dev_info |= DEV_MTT;
1635 if (xhci->hci_version > 0x95) {
1636 xhci_dbg(xhci, "xHCI version %x needs hub "
1637 "TT think time and number of ports\n",
1638 (unsigned int) xhci->hci_version);
1639 slot_ctx->dev_info2 |= XHCI_MAX_PORTS(hdev->maxchild);
1640 /* Set TT think time - convert from ns to FS bit times.
1641 * 0 = 8 FS bit times, 1 = 16 FS bit times,
1642 * 2 = 24 FS bit times, 3 = 32 FS bit times.
1643 */
1644 think_time = tt->think_time;
1645 if (think_time != 0)
1646 think_time = (think_time / 666) - 1;
1647 slot_ctx->tt_info |= TT_THINK_TIME(think_time);
1648 } else {
1649 xhci_dbg(xhci, "xHCI version %x doesn't need hub "
1650 "TT think time or number of ports\n",
1651 (unsigned int) xhci->hci_version);
1652 }
1653 slot_ctx->dev_state = 0;
1654 spin_unlock_irqrestore(&xhci->lock, flags);
1655
1656 xhci_dbg(xhci, "Set up %s for hub device.\n",
1657 (xhci->hci_version > 0x95) ?
1658 "configure endpoint" : "evaluate context");
1659 xhci_dbg(xhci, "Slot %u Input Context:\n", hdev->slot_id);
1660 xhci_dbg_ctx(xhci, config_cmd->in_ctx, 0);
1661
1662 /* Issue and wait for the configure endpoint or
1663 * evaluate context command.
1664 */
1665 if (xhci->hci_version > 0x95)
1666 ret = xhci_configure_endpoint(xhci, hdev, config_cmd,
1667 false, false);
1668 else
1669 ret = xhci_configure_endpoint(xhci, hdev, config_cmd,
1670 true, false);
1671
1672 xhci_dbg(xhci, "Slot %u Output Context:\n", hdev->slot_id);
1673 xhci_dbg_ctx(xhci, vdev->out_ctx, 0);
1674
1675 xhci_free_command(xhci, config_cmd);
1676 return ret;
1677}
1678
1331int xhci_get_frame(struct usb_hcd *hcd) 1679int xhci_get_frame(struct usb_hcd *hcd)
1332{ 1680{
1333 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1681 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index e6b9a1c6002d..1db4fea8c170 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -94,6 +94,9 @@ static void xhci_link_segments(struct xhci_hcd *xhci, struct xhci_segment *prev,
94 val = prev->trbs[TRBS_PER_SEGMENT-1].link.control; 94 val = prev->trbs[TRBS_PER_SEGMENT-1].link.control;
95 val &= ~TRB_TYPE_BITMASK; 95 val &= ~TRB_TYPE_BITMASK;
96 val |= TRB_TYPE(TRB_LINK); 96 val |= TRB_TYPE(TRB_LINK);
97 /* Always set the chain bit with 0.95 hardware */
98 if (xhci_link_trb_quirk(xhci))
99 val |= TRB_CHAIN;
97 prev->trbs[TRBS_PER_SEGMENT-1].link.control = val; 100 prev->trbs[TRBS_PER_SEGMENT-1].link.control = val;
98 } 101 }
99 xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n", 102 xhci_dbg(xhci, "Linking segment 0x%llx to segment 0x%llx (DMA)\n",
@@ -141,7 +144,6 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
141 return 0; 144 return 0;
142 145
143 INIT_LIST_HEAD(&ring->td_list); 146 INIT_LIST_HEAD(&ring->td_list);
144 INIT_LIST_HEAD(&ring->cancelled_td_list);
145 if (num_segs == 0) 147 if (num_segs == 0)
146 return ring; 148 return ring;
147 149
@@ -262,8 +264,8 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
262 return; 264 return;
263 265
264 for (i = 0; i < 31; ++i) 266 for (i = 0; i < 31; ++i)
265 if (dev->ep_rings[i]) 267 if (dev->eps[i].ring)
266 xhci_ring_free(xhci, dev->ep_rings[i]); 268 xhci_ring_free(xhci, dev->eps[i].ring);
267 269
268 if (dev->in_ctx) 270 if (dev->in_ctx)
269 xhci_free_container_ctx(xhci, dev->in_ctx); 271 xhci_free_container_ctx(xhci, dev->in_ctx);
@@ -278,6 +280,7 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
278 struct usb_device *udev, gfp_t flags) 280 struct usb_device *udev, gfp_t flags)
279{ 281{
280 struct xhci_virt_device *dev; 282 struct xhci_virt_device *dev;
283 int i;
281 284
282 /* Slot ID 0 is reserved */ 285 /* Slot ID 0 is reserved */
283 if (slot_id == 0 || xhci->devs[slot_id]) { 286 if (slot_id == 0 || xhci->devs[slot_id]) {
@@ -306,12 +309,17 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
306 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, 309 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id,
307 (unsigned long long)dev->in_ctx->dma); 310 (unsigned long long)dev->in_ctx->dma);
308 311
312 /* Initialize the cancellation list for each endpoint */
313 for (i = 0; i < 31; i++)
314 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list);
315
309 /* Allocate endpoint 0 ring */ 316 /* Allocate endpoint 0 ring */
310 dev->ep_rings[0] = xhci_ring_alloc(xhci, 1, true, flags); 317 dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags);
311 if (!dev->ep_rings[0]) 318 if (!dev->eps[0].ring)
312 goto fail; 319 goto fail;
313 320
314 init_completion(&dev->cmd_completion); 321 init_completion(&dev->cmd_completion);
322 INIT_LIST_HEAD(&dev->cmd_list);
315 323
316 /* Point to output device context in dcbaa. */ 324 /* Point to output device context in dcbaa. */
317 xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma; 325 xhci->dcbaa->dev_context_ptrs[slot_id] = dev->out_ctx->dma;
@@ -352,9 +360,9 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
352 /* 3) Only the control endpoint is valid - one endpoint context */ 360 /* 3) Only the control endpoint is valid - one endpoint context */
353 slot_ctx->dev_info |= LAST_CTX(1); 361 slot_ctx->dev_info |= LAST_CTX(1);
354 362
363 slot_ctx->dev_info |= (u32) udev->route;
355 switch (udev->speed) { 364 switch (udev->speed) {
356 case USB_SPEED_SUPER: 365 case USB_SPEED_SUPER:
357 slot_ctx->dev_info |= (u32) udev->route;
358 slot_ctx->dev_info |= (u32) SLOT_SPEED_SS; 366 slot_ctx->dev_info |= (u32) SLOT_SPEED_SS;
359 break; 367 break;
360 case USB_SPEED_HIGH: 368 case USB_SPEED_HIGH:
@@ -382,14 +390,12 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
382 xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum); 390 xhci_dbg(xhci, "Set root hub portnum to %d\n", top_dev->portnum);
383 391
384 /* Is this a LS/FS device under a HS hub? */ 392 /* Is this a LS/FS device under a HS hub? */
385 /*
386 * FIXME: I don't think this is right, where does the TT info for the
387 * roothub or parent hub come from?
388 */
389 if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) && 393 if ((udev->speed == USB_SPEED_LOW || udev->speed == USB_SPEED_FULL) &&
390 udev->tt) { 394 udev->tt) {
391 slot_ctx->tt_info = udev->tt->hub->slot_id; 395 slot_ctx->tt_info = udev->tt->hub->slot_id;
392 slot_ctx->tt_info |= udev->ttport << 8; 396 slot_ctx->tt_info |= udev->ttport << 8;
397 if (udev->tt->multi)
398 slot_ctx->dev_info |= DEV_MTT;
393 } 399 }
394 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt); 400 xhci_dbg(xhci, "udev->tt = %p\n", udev->tt);
395 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport); 401 xhci_dbg(xhci, "udev->ttport = 0x%x\n", udev->ttport);
@@ -398,22 +404,35 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
398 /* Step 5 */ 404 /* Step 5 */
399 ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP); 405 ep0_ctx->ep_info2 = EP_TYPE(CTRL_EP);
400 /* 406 /*
401 * See section 4.3 bullet 6:
402 * The default Max Packet size for ep0 is "8 bytes for a USB2
403 * LS/FS/HS device or 512 bytes for a USB3 SS device"
404 * XXX: Not sure about wireless USB devices. 407 * XXX: Not sure about wireless USB devices.
405 */ 408 */
406 if (udev->speed == USB_SPEED_SUPER) 409 switch (udev->speed) {
410 case USB_SPEED_SUPER:
407 ep0_ctx->ep_info2 |= MAX_PACKET(512); 411 ep0_ctx->ep_info2 |= MAX_PACKET(512);
408 else 412 break;
413 case USB_SPEED_HIGH:
414 /* USB core guesses at a 64-byte max packet first for FS devices */
415 case USB_SPEED_FULL:
416 ep0_ctx->ep_info2 |= MAX_PACKET(64);
417 break;
418 case USB_SPEED_LOW:
409 ep0_ctx->ep_info2 |= MAX_PACKET(8); 419 ep0_ctx->ep_info2 |= MAX_PACKET(8);
420 break;
421 case USB_SPEED_VARIABLE:
422 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
423 return -EINVAL;
424 break;
425 default:
426 /* New speed? */
427 BUG();
428 }
410 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */ 429 /* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
411 ep0_ctx->ep_info2 |= MAX_BURST(0); 430 ep0_ctx->ep_info2 |= MAX_BURST(0);
412 ep0_ctx->ep_info2 |= ERROR_COUNT(3); 431 ep0_ctx->ep_info2 |= ERROR_COUNT(3);
413 432
414 ep0_ctx->deq = 433 ep0_ctx->deq =
415 dev->ep_rings[0]->first_seg->dma; 434 dev->eps[0].ring->first_seg->dma;
416 ep0_ctx->deq |= dev->ep_rings[0]->cycle_state; 435 ep0_ctx->deq |= dev->eps[0].ring->cycle_state;
417 436
418 /* Steps 7 and 8 were done in xhci_alloc_virt_device() */ 437 /* Steps 7 and 8 were done in xhci_alloc_virt_device() */
419 438
@@ -523,10 +542,11 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
523 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 542 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
524 543
525 /* Set up the endpoint ring */ 544 /* Set up the endpoint ring */
526 virt_dev->new_ep_rings[ep_index] = xhci_ring_alloc(xhci, 1, true, mem_flags); 545 virt_dev->eps[ep_index].new_ring =
527 if (!virt_dev->new_ep_rings[ep_index]) 546 xhci_ring_alloc(xhci, 1, true, mem_flags);
547 if (!virt_dev->eps[ep_index].new_ring)
528 return -ENOMEM; 548 return -ENOMEM;
529 ep_ring = virt_dev->new_ep_rings[ep_index]; 549 ep_ring = virt_dev->eps[ep_index].new_ring;
530 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 550 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state;
531 551
532 ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); 552 ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep);
@@ -598,6 +618,48 @@ void xhci_endpoint_zero(struct xhci_hcd *xhci,
598 */ 618 */
599} 619}
600 620
621/* Copy output xhci_ep_ctx to the input xhci_ep_ctx copy.
622 * Useful when you want to change one particular aspect of the endpoint and then
623 * issue a configure endpoint command.
624 */
625void xhci_endpoint_copy(struct xhci_hcd *xhci,
626 struct xhci_container_ctx *in_ctx,
627 struct xhci_container_ctx *out_ctx,
628 unsigned int ep_index)
629{
630 struct xhci_ep_ctx *out_ep_ctx;
631 struct xhci_ep_ctx *in_ep_ctx;
632
633 out_ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index);
634 in_ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
635
636 in_ep_ctx->ep_info = out_ep_ctx->ep_info;
637 in_ep_ctx->ep_info2 = out_ep_ctx->ep_info2;
638 in_ep_ctx->deq = out_ep_ctx->deq;
639 in_ep_ctx->tx_info = out_ep_ctx->tx_info;
640}
641
642/* Copy output xhci_slot_ctx to the input xhci_slot_ctx.
643 * Useful when you want to change one particular aspect of the endpoint and then
644 * issue a configure endpoint command. Only the context entries field matters,
645 * but we'll copy the whole thing anyway.
646 */
647void xhci_slot_copy(struct xhci_hcd *xhci,
648 struct xhci_container_ctx *in_ctx,
649 struct xhci_container_ctx *out_ctx)
650{
651 struct xhci_slot_ctx *in_slot_ctx;
652 struct xhci_slot_ctx *out_slot_ctx;
653
654 in_slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
655 out_slot_ctx = xhci_get_slot_ctx(xhci, out_ctx);
656
657 in_slot_ctx->dev_info = out_slot_ctx->dev_info;
658 in_slot_ctx->dev_info2 = out_slot_ctx->dev_info2;
659 in_slot_ctx->tt_info = out_slot_ctx->tt_info;
660 in_slot_ctx->dev_state = out_slot_ctx->dev_state;
661}
662
601/* Set up the scratchpad buffer array and scratchpad buffers, if needed. */ 663/* Set up the scratchpad buffer array and scratchpad buffers, if needed. */
602static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags) 664static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
603{ 665{
@@ -695,6 +757,44 @@ static void scratchpad_free(struct xhci_hcd *xhci)
695 xhci->scratchpad = NULL; 757 xhci->scratchpad = NULL;
696} 758}
697 759
760struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
761 bool allocate_completion, gfp_t mem_flags)
762{
763 struct xhci_command *command;
764
765 command = kzalloc(sizeof(*command), mem_flags);
766 if (!command)
767 return NULL;
768
769 command->in_ctx =
770 xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, mem_flags);
771 if (!command->in_ctx)
772 return NULL;
773
774 if (allocate_completion) {
775 command->completion =
776 kzalloc(sizeof(struct completion), mem_flags);
777 if (!command->completion) {
778 xhci_free_container_ctx(xhci, command->in_ctx);
779 return NULL;
780 }
781 init_completion(command->completion);
782 }
783
784 command->status = 0;
785 INIT_LIST_HEAD(&command->cmd_list);
786 return command;
787}
788
789void xhci_free_command(struct xhci_hcd *xhci,
790 struct xhci_command *command)
791{
792 xhci_free_container_ctx(xhci,
793 command->in_ctx);
794 kfree(command->completion);
795 kfree(command);
796}
797
698void xhci_mem_cleanup(struct xhci_hcd *xhci) 798void xhci_mem_cleanup(struct xhci_hcd *xhci)
699{ 799{
700 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 800 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 592fe7e623f7..06595ec27bb7 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -24,6 +24,10 @@
24 24
25#include "xhci.h" 25#include "xhci.h"
26 26
27/* Device for a quirk */
28#define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73
29#define PCI_DEVICE_ID_FRESCO_LOGIC_PDK 0x1000
30
27static const char hcd_name[] = "xhci_hcd"; 31static const char hcd_name[] = "xhci_hcd";
28 32
29/* called after powerup, by probe or system-pm "wakeup" */ 33/* called after powerup, by probe or system-pm "wakeup" */
@@ -59,9 +63,20 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
59 xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1); 63 xhci->hcs_params1 = xhci_readl(xhci, &xhci->cap_regs->hcs_params1);
60 xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2); 64 xhci->hcs_params2 = xhci_readl(xhci, &xhci->cap_regs->hcs_params2);
61 xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3); 65 xhci->hcs_params3 = xhci_readl(xhci, &xhci->cap_regs->hcs_params3);
66 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
67 xhci->hci_version = HC_VERSION(xhci->hcc_params);
62 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params); 68 xhci->hcc_params = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
63 xhci_print_registers(xhci); 69 xhci_print_registers(xhci);
64 70
71 /* Look for vendor-specific quirks */
72 if (pdev->vendor == PCI_VENDOR_ID_FRESCO_LOGIC &&
73 pdev->device == PCI_DEVICE_ID_FRESCO_LOGIC_PDK &&
74 pdev->revision == 0x0) {
75 xhci->quirks |= XHCI_RESET_EP_QUIRK;
76 xhci_dbg(xhci, "QUIRK: Fresco Logic xHC needs configure"
77 " endpoint cmd after reset endpoint\n");
78 }
79
65 /* Make sure the HC is halted. */ 80 /* Make sure the HC is halted. */
66 retval = xhci_halt(xhci); 81 retval = xhci_halt(xhci);
67 if (retval) 82 if (retval)
@@ -121,6 +136,7 @@ static const struct hc_driver xhci_pci_hc_driver = {
121 .check_bandwidth = xhci_check_bandwidth, 136 .check_bandwidth = xhci_check_bandwidth,
122 .reset_bandwidth = xhci_reset_bandwidth, 137 .reset_bandwidth = xhci_reset_bandwidth,
123 .address_device = xhci_address_device, 138 .address_device = xhci_address_device,
139 .update_hub_device = xhci_update_hub_device,
124 140
125 /* 141 /*
126 * scheduling support 142 * scheduling support
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index aa88a067148b..173c39c76489 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -172,8 +172,9 @@ static void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
172 * have their chain bit cleared (so that each Link TRB is a separate TD). 172 * have their chain bit cleared (so that each Link TRB is a separate TD).
173 * 173 *
174 * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit 174 * Section 6.4.4.1 of the 0.95 spec says link TRBs cannot have the chain bit
175 * set, but other sections talk about dealing with the chain bit set. 175 * set, but other sections talk about dealing with the chain bit set. This was
176 * Assume section 6.4.4.1 is wrong, and the chain bit can be set in a Link TRB. 176 * fixed in the 0.96 specification errata, but we have to assume that all 0.95
177 * xHCI hardware can't handle the chain bit being cleared on a link TRB.
177 */ 178 */
178static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer) 179static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer)
179{ 180{
@@ -191,8 +192,14 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
191 while (last_trb(xhci, ring, ring->enq_seg, next)) { 192 while (last_trb(xhci, ring, ring->enq_seg, next)) {
192 if (!consumer) { 193 if (!consumer) {
193 if (ring != xhci->event_ring) { 194 if (ring != xhci->event_ring) {
194 next->link.control &= ~TRB_CHAIN; 195 /* If we're not dealing with 0.95 hardware,
195 next->link.control |= chain; 196 * carry over the chain bit of the previous TRB
197 * (which may mean the chain bit is cleared).
198 */
199 if (!xhci_link_trb_quirk(xhci)) {
200 next->link.control &= ~TRB_CHAIN;
201 next->link.control |= chain;
202 }
196 /* Give this link TRB to the hardware */ 203 /* Give this link TRB to the hardware */
197 wmb(); 204 wmb();
198 if (next->link.control & TRB_CYCLE) 205 if (next->link.control & TRB_CYCLE)
@@ -289,16 +296,18 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
289 unsigned int slot_id, 296 unsigned int slot_id,
290 unsigned int ep_index) 297 unsigned int ep_index)
291{ 298{
292 struct xhci_ring *ep_ring; 299 struct xhci_virt_ep *ep;
300 unsigned int ep_state;
293 u32 field; 301 u32 field;
294 __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id]; 302 __u32 __iomem *db_addr = &xhci->dba->doorbell[slot_id];
295 303
296 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; 304 ep = &xhci->devs[slot_id]->eps[ep_index];
305 ep_state = ep->ep_state;
297 /* Don't ring the doorbell for this endpoint if there are pending 306 /* Don't ring the doorbell for this endpoint if there are pending
298 * cancellations because the we don't want to interrupt processing. 307 * cancellations because the we don't want to interrupt processing.
299 */ 308 */
300 if (!ep_ring->cancels_pending && !(ep_ring->state & SET_DEQ_PENDING) 309 if (!ep->cancels_pending && !(ep_state & SET_DEQ_PENDING)
301 && !(ep_ring->state & EP_HALTED)) { 310 && !(ep_state & EP_HALTED)) {
302 field = xhci_readl(xhci, db_addr) & DB_MASK; 311 field = xhci_readl(xhci, db_addr) & DB_MASK;
303 xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); 312 xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr);
304 /* Flush PCI posted writes - FIXME Matthew Wilcox says this 313 /* Flush PCI posted writes - FIXME Matthew Wilcox says this
@@ -354,7 +363,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
354 struct xhci_td *cur_td, struct xhci_dequeue_state *state) 363 struct xhci_td *cur_td, struct xhci_dequeue_state *state)
355{ 364{
356 struct xhci_virt_device *dev = xhci->devs[slot_id]; 365 struct xhci_virt_device *dev = xhci->devs[slot_id];
357 struct xhci_ring *ep_ring = dev->ep_rings[ep_index]; 366 struct xhci_ring *ep_ring = dev->eps[ep_index].ring;
358 struct xhci_generic_trb *trb; 367 struct xhci_generic_trb *trb;
359 struct xhci_ep_ctx *ep_ctx; 368 struct xhci_ep_ctx *ep_ctx;
360 dma_addr_t addr; 369 dma_addr_t addr;
@@ -362,7 +371,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
362 state->new_cycle_state = 0; 371 state->new_cycle_state = 0;
363 xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); 372 xhci_dbg(xhci, "Finding segment containing stopped TRB.\n");
364 state->new_deq_seg = find_trb_seg(cur_td->start_seg, 373 state->new_deq_seg = find_trb_seg(cur_td->start_seg,
365 ep_ring->stopped_trb, 374 dev->eps[ep_index].stopped_trb,
366 &state->new_cycle_state); 375 &state->new_cycle_state);
367 if (!state->new_deq_seg) 376 if (!state->new_deq_seg)
368 BUG(); 377 BUG();
@@ -442,9 +451,11 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
442 union xhci_trb *deq_ptr, u32 cycle_state); 451 union xhci_trb *deq_ptr, u32 cycle_state);
443 452
444void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, 453void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
445 struct xhci_ring *ep_ring, unsigned int slot_id, 454 unsigned int slot_id, unsigned int ep_index,
446 unsigned int ep_index, struct xhci_dequeue_state *deq_state) 455 struct xhci_dequeue_state *deq_state)
447{ 456{
457 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
458
448 xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), " 459 xhci_dbg(xhci, "Set TR Deq Ptr cmd, new deq seg = %p (0x%llx dma), "
449 "new deq ptr = %p (0x%llx dma), new cycle = %u\n", 460 "new deq ptr = %p (0x%llx dma), new cycle = %u\n",
450 deq_state->new_deq_seg, 461 deq_state->new_deq_seg,
@@ -461,8 +472,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
461 * if the ring is running, and ringing the doorbell starts the 472 * if the ring is running, and ringing the doorbell starts the
462 * ring running. 473 * ring running.
463 */ 474 */
464 ep_ring->state |= SET_DEQ_PENDING; 475 ep->ep_state |= SET_DEQ_PENDING;
465 xhci_ring_cmd_db(xhci);
466} 476}
467 477
468/* 478/*
@@ -481,6 +491,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
481 unsigned int slot_id; 491 unsigned int slot_id;
482 unsigned int ep_index; 492 unsigned int ep_index;
483 struct xhci_ring *ep_ring; 493 struct xhci_ring *ep_ring;
494 struct xhci_virt_ep *ep;
484 struct list_head *entry; 495 struct list_head *entry;
485 struct xhci_td *cur_td = 0; 496 struct xhci_td *cur_td = 0;
486 struct xhci_td *last_unlinked_td; 497 struct xhci_td *last_unlinked_td;
@@ -493,9 +504,10 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
493 memset(&deq_state, 0, sizeof(deq_state)); 504 memset(&deq_state, 0, sizeof(deq_state));
494 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 505 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
495 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 506 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
496 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; 507 ep = &xhci->devs[slot_id]->eps[ep_index];
508 ep_ring = ep->ring;
497 509
498 if (list_empty(&ep_ring->cancelled_td_list)) 510 if (list_empty(&ep->cancelled_td_list))
499 return; 511 return;
500 512
501 /* Fix up the ep ring first, so HW stops executing cancelled TDs. 513 /* Fix up the ep ring first, so HW stops executing cancelled TDs.
@@ -503,7 +515,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
503 * it. We're also in the event handler, so we can't get re-interrupted 515 * it. We're also in the event handler, so we can't get re-interrupted
504 * if another Stop Endpoint command completes 516 * if another Stop Endpoint command completes
505 */ 517 */
506 list_for_each(entry, &ep_ring->cancelled_td_list) { 518 list_for_each(entry, &ep->cancelled_td_list) {
507 cur_td = list_entry(entry, struct xhci_td, cancelled_td_list); 519 cur_td = list_entry(entry, struct xhci_td, cancelled_td_list);
508 xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n", 520 xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n",
509 cur_td->first_trb, 521 cur_td->first_trb,
@@ -512,7 +524,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
512 * If we stopped on the TD we need to cancel, then we have to 524 * If we stopped on the TD we need to cancel, then we have to
513 * move the xHC endpoint ring dequeue pointer past this TD. 525 * move the xHC endpoint ring dequeue pointer past this TD.
514 */ 526 */
515 if (cur_td == ep_ring->stopped_td) 527 if (cur_td == ep->stopped_td)
516 xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, 528 xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td,
517 &deq_state); 529 &deq_state);
518 else 530 else
@@ -523,14 +535,15 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
523 * the cancelled TD list for URB completion later. 535 * the cancelled TD list for URB completion later.
524 */ 536 */
525 list_del(&cur_td->td_list); 537 list_del(&cur_td->td_list);
526 ep_ring->cancels_pending--; 538 ep->cancels_pending--;
527 } 539 }
528 last_unlinked_td = cur_td; 540 last_unlinked_td = cur_td;
529 541
530 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ 542 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */
531 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { 543 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
532 xhci_queue_new_dequeue_state(xhci, ep_ring, 544 xhci_queue_new_dequeue_state(xhci,
533 slot_id, ep_index, &deq_state); 545 slot_id, ep_index, &deq_state);
546 xhci_ring_cmd_db(xhci);
534 } else { 547 } else {
535 /* Otherwise just ring the doorbell to restart the ring */ 548 /* Otherwise just ring the doorbell to restart the ring */
536 ring_ep_doorbell(xhci, slot_id, ep_index); 549 ring_ep_doorbell(xhci, slot_id, ep_index);
@@ -543,7 +556,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
543 * So stop when we've completed the URB for the last TD we unlinked. 556 * So stop when we've completed the URB for the last TD we unlinked.
544 */ 557 */
545 do { 558 do {
546 cur_td = list_entry(ep_ring->cancelled_td_list.next, 559 cur_td = list_entry(ep->cancelled_td_list.next,
547 struct xhci_td, cancelled_td_list); 560 struct xhci_td, cancelled_td_list);
548 list_del(&cur_td->cancelled_td_list); 561 list_del(&cur_td->cancelled_td_list);
549 562
@@ -590,7 +603,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
590 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 603 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
591 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 604 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
592 dev = xhci->devs[slot_id]; 605 dev = xhci->devs[slot_id];
593 ep_ring = dev->ep_rings[ep_index]; 606 ep_ring = dev->eps[ep_index].ring;
594 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 607 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
595 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); 608 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
596 609
@@ -634,7 +647,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
634 ep_ctx->deq); 647 ep_ctx->deq);
635 } 648 }
636 649
637 ep_ring->state &= ~SET_DEQ_PENDING; 650 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
638 ring_ep_doorbell(xhci, slot_id, ep_index); 651 ring_ep_doorbell(xhci, slot_id, ep_index);
639} 652}
640 653
@@ -644,18 +657,60 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
644{ 657{
645 int slot_id; 658 int slot_id;
646 unsigned int ep_index; 659 unsigned int ep_index;
660 struct xhci_ring *ep_ring;
647 661
648 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 662 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
649 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 663 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
664 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
650 /* This command will only fail if the endpoint wasn't halted, 665 /* This command will only fail if the endpoint wasn't halted,
651 * but we don't care. 666 * but we don't care.
652 */ 667 */
653 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n", 668 xhci_dbg(xhci, "Ignoring reset ep completion code of %u\n",
654 (unsigned int) GET_COMP_CODE(event->status)); 669 (unsigned int) GET_COMP_CODE(event->status));
655 670
656 /* Clear our internal halted state and restart the ring */ 671 /* HW with the reset endpoint quirk needs to have a configure endpoint
657 xhci->devs[slot_id]->ep_rings[ep_index]->state &= ~EP_HALTED; 672 * command complete before the endpoint can be used. Queue that here
658 ring_ep_doorbell(xhci, slot_id, ep_index); 673 * because the HW can't handle two commands being queued in a row.
674 */
675 if (xhci->quirks & XHCI_RESET_EP_QUIRK) {
676 xhci_dbg(xhci, "Queueing configure endpoint command\n");
677 xhci_queue_configure_endpoint(xhci,
678 xhci->devs[slot_id]->in_ctx->dma, slot_id,
679 false);
680 xhci_ring_cmd_db(xhci);
681 } else {
682 /* Clear our internal halted state and restart the ring */
683 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED;
684 ring_ep_doorbell(xhci, slot_id, ep_index);
685 }
686}
687
688/* Check to see if a command in the device's command queue matches this one.
689 * Signal the completion or free the command, and return 1. Return 0 if the
690 * completed command isn't at the head of the command list.
691 */
692static int handle_cmd_in_cmd_wait_list(struct xhci_hcd *xhci,
693 struct xhci_virt_device *virt_dev,
694 struct xhci_event_cmd *event)
695{
696 struct xhci_command *command;
697
698 if (list_empty(&virt_dev->cmd_list))
699 return 0;
700
701 command = list_entry(virt_dev->cmd_list.next,
702 struct xhci_command, cmd_list);
703 if (xhci->cmd_ring->dequeue != command->command_trb)
704 return 0;
705
706 command->status =
707 GET_COMP_CODE(event->status);
708 list_del(&command->cmd_list);
709 if (command->completion)
710 complete(command->completion);
711 else
712 xhci_free_command(xhci, command);
713 return 1;
659} 714}
660 715
661static void handle_cmd_completion(struct xhci_hcd *xhci, 716static void handle_cmd_completion(struct xhci_hcd *xhci,
@@ -664,6 +719,11 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
664 int slot_id = TRB_TO_SLOT_ID(event->flags); 719 int slot_id = TRB_TO_SLOT_ID(event->flags);
665 u64 cmd_dma; 720 u64 cmd_dma;
666 dma_addr_t cmd_dequeue_dma; 721 dma_addr_t cmd_dequeue_dma;
722 struct xhci_input_control_ctx *ctrl_ctx;
723 struct xhci_virt_device *virt_dev;
724 unsigned int ep_index;
725 struct xhci_ring *ep_ring;
726 unsigned int ep_state;
667 727
668 cmd_dma = event->cmd_trb; 728 cmd_dma = event->cmd_trb;
669 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg, 729 cmd_dequeue_dma = xhci_trb_virt_to_dma(xhci->cmd_ring->deq_seg,
@@ -691,6 +751,47 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
691 xhci_free_virt_device(xhci, slot_id); 751 xhci_free_virt_device(xhci, slot_id);
692 break; 752 break;
693 case TRB_TYPE(TRB_CONFIG_EP): 753 case TRB_TYPE(TRB_CONFIG_EP):
754 virt_dev = xhci->devs[slot_id];
755 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
756 break;
757 /*
758 * Configure endpoint commands can come from the USB core
759 * configuration or alt setting changes, or because the HW
760 * needed an extra configure endpoint command after a reset
761 * endpoint command. In the latter case, the xHCI driver is
762 * not waiting on the configure endpoint command.
763 */
764 ctrl_ctx = xhci_get_input_control_ctx(xhci,
765 virt_dev->in_ctx);
766 /* Input ctx add_flags are the endpoint index plus one */
767 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1;
768 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
769 if (!ep_ring) {
770 /* This must have been an initial configure endpoint */
771 xhci->devs[slot_id]->cmd_status =
772 GET_COMP_CODE(event->status);
773 complete(&xhci->devs[slot_id]->cmd_completion);
774 break;
775 }
776 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
777 xhci_dbg(xhci, "Completed config ep cmd - last ep index = %d, "
778 "state = %d\n", ep_index, ep_state);
779 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
780 ep_state & EP_HALTED) {
781 /* Clear our internal halted state and restart ring */
782 xhci->devs[slot_id]->eps[ep_index].ep_state &=
783 ~EP_HALTED;
784 ring_ep_doorbell(xhci, slot_id, ep_index);
785 } else {
786 xhci->devs[slot_id]->cmd_status =
787 GET_COMP_CODE(event->status);
788 complete(&xhci->devs[slot_id]->cmd_completion);
789 }
790 break;
791 case TRB_TYPE(TRB_EVAL_CONTEXT):
792 virt_dev = xhci->devs[slot_id];
793 if (handle_cmd_in_cmd_wait_list(xhci, virt_dev, event))
794 break;
694 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status); 795 xhci->devs[slot_id]->cmd_status = GET_COMP_CODE(event->status);
695 complete(&xhci->devs[slot_id]->cmd_completion); 796 complete(&xhci->devs[slot_id]->cmd_completion);
696 break; 797 break;
@@ -805,7 +906,9 @@ static int handle_tx_event(struct xhci_hcd *xhci,
805 struct xhci_transfer_event *event) 906 struct xhci_transfer_event *event)
806{ 907{
807 struct xhci_virt_device *xdev; 908 struct xhci_virt_device *xdev;
909 struct xhci_virt_ep *ep;
808 struct xhci_ring *ep_ring; 910 struct xhci_ring *ep_ring;
911 unsigned int slot_id;
809 int ep_index; 912 int ep_index;
810 struct xhci_td *td = 0; 913 struct xhci_td *td = 0;
811 dma_addr_t event_dma; 914 dma_addr_t event_dma;
@@ -814,9 +917,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
814 struct urb *urb = 0; 917 struct urb *urb = 0;
815 int status = -EINPROGRESS; 918 int status = -EINPROGRESS;
816 struct xhci_ep_ctx *ep_ctx; 919 struct xhci_ep_ctx *ep_ctx;
920 u32 trb_comp_code;
817 921
818 xhci_dbg(xhci, "In %s\n", __func__); 922 xhci_dbg(xhci, "In %s\n", __func__);
819 xdev = xhci->devs[TRB_TO_SLOT_ID(event->flags)]; 923 slot_id = TRB_TO_SLOT_ID(event->flags);
924 xdev = xhci->devs[slot_id];
820 if (!xdev) { 925 if (!xdev) {
821 xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n"); 926 xhci_err(xhci, "ERROR Transfer event pointed to bad slot\n");
822 return -ENODEV; 927 return -ENODEV;
@@ -825,7 +930,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
825 /* Endpoint ID is 1 based, our index is zero based */ 930 /* Endpoint ID is 1 based, our index is zero based */
826 ep_index = TRB_TO_EP_ID(event->flags) - 1; 931 ep_index = TRB_TO_EP_ID(event->flags) - 1;
827 xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index); 932 xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index);
828 ep_ring = xdev->ep_rings[ep_index]; 933 ep = &xdev->eps[ep_index];
934 ep_ring = ep->ring;
829 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 935 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
830 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 936 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) {
831 xhci_err(xhci, "ERROR Transfer event pointed to disabled endpoint\n"); 937 xhci_err(xhci, "ERROR Transfer event pointed to disabled endpoint\n");
@@ -870,7 +976,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
870 (unsigned int) event->flags); 976 (unsigned int) event->flags);
871 977
872 /* Look for common error cases */ 978 /* Look for common error cases */
873 switch (GET_COMP_CODE(event->transfer_len)) { 979 trb_comp_code = GET_COMP_CODE(event->transfer_len);
980 switch (trb_comp_code) {
874 /* Skip codes that require special handling depending on 981 /* Skip codes that require special handling depending on
875 * transfer type 982 * transfer type
876 */ 983 */
@@ -885,7 +992,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
885 break; 992 break;
886 case COMP_STALL: 993 case COMP_STALL:
887 xhci_warn(xhci, "WARN: Stalled endpoint\n"); 994 xhci_warn(xhci, "WARN: Stalled endpoint\n");
888 ep_ring->state |= EP_HALTED; 995 ep->ep_state |= EP_HALTED;
889 status = -EPIPE; 996 status = -EPIPE;
890 break; 997 break;
891 case COMP_TRB_ERR: 998 case COMP_TRB_ERR:
@@ -913,7 +1020,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
913 /* Was this a control transfer? */ 1020 /* Was this a control transfer? */
914 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) { 1021 if (usb_endpoint_xfer_control(&td->urb->ep->desc)) {
915 xhci_debug_trb(xhci, xhci->event_ring->dequeue); 1022 xhci_debug_trb(xhci, xhci->event_ring->dequeue);
916 switch (GET_COMP_CODE(event->transfer_len)) { 1023 switch (trb_comp_code) {
917 case COMP_SUCCESS: 1024 case COMP_SUCCESS:
918 if (event_trb == ep_ring->dequeue) { 1025 if (event_trb == ep_ring->dequeue) {
919 xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n"); 1026 xhci_warn(xhci, "WARN: Success on ctrl setup TRB without IOC set??\n");
@@ -928,8 +1035,37 @@ static int handle_tx_event(struct xhci_hcd *xhci,
928 break; 1035 break;
929 case COMP_SHORT_TX: 1036 case COMP_SHORT_TX:
930 xhci_warn(xhci, "WARN: short transfer on control ep\n"); 1037 xhci_warn(xhci, "WARN: short transfer on control ep\n");
931 status = -EREMOTEIO; 1038 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1039 status = -EREMOTEIO;
1040 else
1041 status = 0;
932 break; 1042 break;
1043 case COMP_BABBLE:
1044 /* The 0.96 spec says a babbling control endpoint
1045 * is not halted. The 0.96 spec says it is. Some HW
1046 * claims to be 0.95 compliant, but it halts the control
1047 * endpoint anyway. Check if a babble halted the
1048 * endpoint.
1049 */
1050 if (ep_ctx->ep_info != EP_STATE_HALTED)
1051 break;
1052 /* else fall through */
1053 case COMP_STALL:
1054 /* Did we transfer part of the data (middle) phase? */
1055 if (event_trb != ep_ring->dequeue &&
1056 event_trb != td->last_trb)
1057 td->urb->actual_length =
1058 td->urb->transfer_buffer_length
1059 - TRB_LEN(event->transfer_len);
1060 else
1061 td->urb->actual_length = 0;
1062
1063 ep->stopped_td = td;
1064 ep->stopped_trb = event_trb;
1065 xhci_queue_reset_ep(xhci, slot_id, ep_index);
1066 xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index);
1067 xhci_ring_cmd_db(xhci);
1068 goto td_cleanup;
933 default: 1069 default:
934 /* Others already handled above */ 1070 /* Others already handled above */
935 break; 1071 break;
@@ -943,7 +1079,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,
943 if (event_trb == td->last_trb) { 1079 if (event_trb == td->last_trb) {
944 if (td->urb->actual_length != 0) { 1080 if (td->urb->actual_length != 0) {
945 /* Don't overwrite a previously set error code */ 1081 /* Don't overwrite a previously set error code */
946 if (status == -EINPROGRESS || status == 0) 1082 if ((status == -EINPROGRESS ||
1083 status == 0) &&
1084 (td->urb->transfer_flags
1085 & URB_SHORT_NOT_OK))
947 /* Did we already see a short data stage? */ 1086 /* Did we already see a short data stage? */
948 status = -EREMOTEIO; 1087 status = -EREMOTEIO;
949 } else { 1088 } else {
@@ -952,7 +1091,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
952 } 1091 }
953 } else { 1092 } else {
954 /* Maybe the event was for the data stage? */ 1093 /* Maybe the event was for the data stage? */
955 if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL) { 1094 if (trb_comp_code != COMP_STOP_INVAL) {
956 /* We didn't stop on a link TRB in the middle */ 1095 /* We didn't stop on a link TRB in the middle */
957 td->urb->actual_length = 1096 td->urb->actual_length =
958 td->urb->transfer_buffer_length - 1097 td->urb->transfer_buffer_length -
@@ -964,7 +1103,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
964 } 1103 }
965 } 1104 }
966 } else { 1105 } else {
967 switch (GET_COMP_CODE(event->transfer_len)) { 1106 switch (trb_comp_code) {
968 case COMP_SUCCESS: 1107 case COMP_SUCCESS:
969 /* Double check that the HW transferred everything. */ 1108 /* Double check that the HW transferred everything. */
970 if (event_trb != td->last_trb) { 1109 if (event_trb != td->last_trb) {
@@ -975,7 +1114,12 @@ static int handle_tx_event(struct xhci_hcd *xhci,
975 else 1114 else
976 status = 0; 1115 status = 0;
977 } else { 1116 } else {
978 xhci_dbg(xhci, "Successful bulk transfer!\n"); 1117 if (usb_endpoint_xfer_bulk(&td->urb->ep->desc))
1118 xhci_dbg(xhci, "Successful bulk "
1119 "transfer!\n");
1120 else
1121 xhci_dbg(xhci, "Successful interrupt "
1122 "transfer!\n");
979 status = 0; 1123 status = 0;
980 } 1124 }
981 break; 1125 break;
@@ -1001,11 +1145,17 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1001 td->urb->actual_length = 1145 td->urb->actual_length =
1002 td->urb->transfer_buffer_length - 1146 td->urb->transfer_buffer_length -
1003 TRB_LEN(event->transfer_len); 1147 TRB_LEN(event->transfer_len);
1004 if (td->urb->actual_length < 0) { 1148 if (td->urb->transfer_buffer_length <
1149 td->urb->actual_length) {
1005 xhci_warn(xhci, "HC gave bad length " 1150 xhci_warn(xhci, "HC gave bad length "
1006 "of %d bytes left\n", 1151 "of %d bytes left\n",
1007 TRB_LEN(event->transfer_len)); 1152 TRB_LEN(event->transfer_len));
1008 td->urb->actual_length = 0; 1153 td->urb->actual_length = 0;
1154 if (td->urb->transfer_flags &
1155 URB_SHORT_NOT_OK)
1156 status = -EREMOTEIO;
1157 else
1158 status = 0;
1009 } 1159 }
1010 /* Don't overwrite a previously set error code */ 1160 /* Don't overwrite a previously set error code */
1011 if (status == -EINPROGRESS) { 1161 if (status == -EINPROGRESS) {
@@ -1041,30 +1191,31 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1041 /* If the ring didn't stop on a Link or No-op TRB, add 1191 /* If the ring didn't stop on a Link or No-op TRB, add
1042 * in the actual bytes transferred from the Normal TRB 1192 * in the actual bytes transferred from the Normal TRB
1043 */ 1193 */
1044 if (GET_COMP_CODE(event->transfer_len) != COMP_STOP_INVAL) 1194 if (trb_comp_code != COMP_STOP_INVAL)
1045 td->urb->actual_length += 1195 td->urb->actual_length +=
1046 TRB_LEN(cur_trb->generic.field[2]) - 1196 TRB_LEN(cur_trb->generic.field[2]) -
1047 TRB_LEN(event->transfer_len); 1197 TRB_LEN(event->transfer_len);
1048 } 1198 }
1049 } 1199 }
1050 if (GET_COMP_CODE(event->transfer_len) == COMP_STOP_INVAL || 1200 if (trb_comp_code == COMP_STOP_INVAL ||
1051 GET_COMP_CODE(event->transfer_len) == COMP_STOP) { 1201 trb_comp_code == COMP_STOP) {
1052 /* The Endpoint Stop Command completion will take care of any 1202 /* The Endpoint Stop Command completion will take care of any
1053 * stopped TDs. A stopped TD may be restarted, so don't update 1203 * stopped TDs. A stopped TD may be restarted, so don't update
1054 * the ring dequeue pointer or take this TD off any lists yet. 1204 * the ring dequeue pointer or take this TD off any lists yet.
1055 */ 1205 */
1056 ep_ring->stopped_td = td; 1206 ep->stopped_td = td;
1057 ep_ring->stopped_trb = event_trb; 1207 ep->stopped_trb = event_trb;
1058 } else { 1208 } else {
1059 if (GET_COMP_CODE(event->transfer_len) == COMP_STALL) { 1209 if (trb_comp_code == COMP_STALL ||
1210 trb_comp_code == COMP_BABBLE) {
1060 /* The transfer is completed from the driver's 1211 /* The transfer is completed from the driver's
1061 * perspective, but we need to issue a set dequeue 1212 * perspective, but we need to issue a set dequeue
1062 * command for this stalled endpoint to move the dequeue 1213 * command for this stalled endpoint to move the dequeue
1063 * pointer past the TD. We can't do that here because 1214 * pointer past the TD. We can't do that here because
1064 * the halt condition must be cleared first. 1215 * the halt condition must be cleared first.
1065 */ 1216 */
1066 ep_ring->stopped_td = td; 1217 ep->stopped_td = td;
1067 ep_ring->stopped_trb = event_trb; 1218 ep->stopped_trb = event_trb;
1068 } else { 1219 } else {
1069 /* Update ring dequeue pointer */ 1220 /* Update ring dequeue pointer */
1070 while (ep_ring->dequeue != td->last_trb) 1221 while (ep_ring->dequeue != td->last_trb)
@@ -1072,16 +1223,41 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1072 inc_deq(xhci, ep_ring, false); 1223 inc_deq(xhci, ep_ring, false);
1073 } 1224 }
1074 1225
1226td_cleanup:
1075 /* Clean up the endpoint's TD list */ 1227 /* Clean up the endpoint's TD list */
1076 urb = td->urb; 1228 urb = td->urb;
1229 /* Do one last check of the actual transfer length.
1230 * If the host controller said we transferred more data than
1231 * the buffer length, urb->actual_length will be a very big
1232 * number (since it's unsigned). Play it safe and say we didn't
1233 * transfer anything.
1234 */
1235 if (urb->actual_length > urb->transfer_buffer_length) {
1236 xhci_warn(xhci, "URB transfer length is wrong, "
1237 "xHC issue? req. len = %u, "
1238 "act. len = %u\n",
1239 urb->transfer_buffer_length,
1240 urb->actual_length);
1241 urb->actual_length = 0;
1242 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1243 status = -EREMOTEIO;
1244 else
1245 status = 0;
1246 }
1077 list_del(&td->td_list); 1247 list_del(&td->td_list);
1078 /* Was this TD slated to be cancelled but completed anyway? */ 1248 /* Was this TD slated to be cancelled but completed anyway? */
1079 if (!list_empty(&td->cancelled_td_list)) { 1249 if (!list_empty(&td->cancelled_td_list)) {
1080 list_del(&td->cancelled_td_list); 1250 list_del(&td->cancelled_td_list);
1081 ep_ring->cancels_pending--; 1251 ep->cancels_pending--;
1082 } 1252 }
1083 /* Leave the TD around for the reset endpoint function to use */ 1253 /* Leave the TD around for the reset endpoint function to use
1084 if (GET_COMP_CODE(event->transfer_len) != COMP_STALL) { 1254 * (but only if it's not a control endpoint, since we already
1255 * queued the Set TR dequeue pointer command for stalled
1256 * control endpoints).
1257 */
1258 if (usb_endpoint_xfer_control(&urb->ep->desc) ||
1259 (trb_comp_code != COMP_STALL &&
1260 trb_comp_code != COMP_BABBLE)) {
1085 kfree(td); 1261 kfree(td);
1086 } 1262 }
1087 urb->hcpriv = NULL; 1263 urb->hcpriv = NULL;
@@ -1094,7 +1270,7 @@ cleanup:
1094 if (urb) { 1270 if (urb) {
1095 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb); 1271 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), urb);
1096 xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n", 1272 xhci_dbg(xhci, "Giveback URB %p, len = %d, status = %d\n",
1097 urb, td->urb->actual_length, status); 1273 urb, urb->actual_length, status);
1098 spin_unlock(&xhci->lock); 1274 spin_unlock(&xhci->lock);
1099 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status); 1275 usb_hcd_giveback_urb(xhci_to_hcd(xhci), urb, status);
1100 spin_lock(&xhci->lock); 1276 spin_lock(&xhci->lock);
@@ -1235,7 +1411,7 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1235{ 1411{
1236 int ret; 1412 int ret;
1237 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1413 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1238 ret = prepare_ring(xhci, xdev->ep_rings[ep_index], 1414 ret = prepare_ring(xhci, xdev->eps[ep_index].ring,
1239 ep_ctx->ep_info & EP_STATE_MASK, 1415 ep_ctx->ep_info & EP_STATE_MASK,
1240 num_trbs, mem_flags); 1416 num_trbs, mem_flags);
1241 if (ret) 1417 if (ret)
@@ -1255,9 +1431,9 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1255 (*td)->urb = urb; 1431 (*td)->urb = urb;
1256 urb->hcpriv = (void *) (*td); 1432 urb->hcpriv = (void *) (*td);
1257 /* Add this TD to the tail of the endpoint ring's TD list */ 1433 /* Add this TD to the tail of the endpoint ring's TD list */
1258 list_add_tail(&(*td)->td_list, &xdev->ep_rings[ep_index]->td_list); 1434 list_add_tail(&(*td)->td_list, &xdev->eps[ep_index].ring->td_list);
1259 (*td)->start_seg = xdev->ep_rings[ep_index]->enq_seg; 1435 (*td)->start_seg = xdev->eps[ep_index].ring->enq_seg;
1260 (*td)->first_trb = xdev->ep_rings[ep_index]->enqueue; 1436 (*td)->first_trb = xdev->eps[ep_index].ring->enqueue;
1261 1437
1262 return 0; 1438 return 0;
1263} 1439}
@@ -1335,6 +1511,47 @@ static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
1335 ring_ep_doorbell(xhci, slot_id, ep_index); 1511 ring_ep_doorbell(xhci, slot_id, ep_index);
1336} 1512}
1337 1513
1514/*
1515 * xHCI uses normal TRBs for both bulk and interrupt. When the interrupt
1516 * endpoint is to be serviced, the xHC will consume (at most) one TD. A TD
1517 * (comprised of sg list entries) can take several service intervals to
1518 * transmit.
1519 */
1520int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1521 struct urb *urb, int slot_id, unsigned int ep_index)
1522{
1523 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci,
1524 xhci->devs[slot_id]->out_ctx, ep_index);
1525 int xhci_interval;
1526 int ep_interval;
1527
1528 xhci_interval = EP_INTERVAL_TO_UFRAMES(ep_ctx->ep_info);
1529 ep_interval = urb->interval;
1530 /* Convert to microframes */
1531 if (urb->dev->speed == USB_SPEED_LOW ||
1532 urb->dev->speed == USB_SPEED_FULL)
1533 ep_interval *= 8;
1534 /* FIXME change this to a warning and a suggestion to use the new API
1535 * to set the polling interval (once the API is added).
1536 */
1537 if (xhci_interval != ep_interval) {
1538 if (!printk_ratelimit())
1539 dev_dbg(&urb->dev->dev, "Driver uses different interval"
1540 " (%d microframe%s) than xHCI "
1541 "(%d microframe%s)\n",
1542 ep_interval,
1543 ep_interval == 1 ? "" : "s",
1544 xhci_interval,
1545 xhci_interval == 1 ? "" : "s");
1546 urb->interval = xhci_interval;
1547 /* Convert back to frames for LS/FS devices */
1548 if (urb->dev->speed == USB_SPEED_LOW ||
1549 urb->dev->speed == USB_SPEED_FULL)
1550 urb->interval /= 8;
1551 }
1552 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
1553}
1554
1338static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 1555static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1339 struct urb *urb, int slot_id, unsigned int ep_index) 1556 struct urb *urb, int slot_id, unsigned int ep_index)
1340{ 1557{
@@ -1350,7 +1567,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1350 struct xhci_generic_trb *start_trb; 1567 struct xhci_generic_trb *start_trb;
1351 int start_cycle; 1568 int start_cycle;
1352 1569
1353 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; 1570 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1354 num_trbs = count_sg_trbs_needed(xhci, urb); 1571 num_trbs = count_sg_trbs_needed(xhci, urb);
1355 num_sgs = urb->num_sgs; 1572 num_sgs = urb->num_sgs;
1356 1573
@@ -1483,7 +1700,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1483 if (urb->sg) 1700 if (urb->sg)
1484 return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index); 1701 return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index);
1485 1702
1486 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; 1703 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1487 1704
1488 num_trbs = 0; 1705 num_trbs = 0;
1489 /* How much data is (potentially) left before the 64KB boundary? */ 1706 /* How much data is (potentially) left before the 64KB boundary? */
@@ -1594,7 +1811,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1594 u32 field, length_field; 1811 u32 field, length_field;
1595 struct xhci_td *td; 1812 struct xhci_td *td;
1596 1813
1597 ep_ring = xhci->devs[slot_id]->ep_rings[ep_index]; 1814 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
1598 1815
1599 /* 1816 /*
1600 * Need to copy setup packet into setup TRB, so we can't use the setup 1817 * Need to copy setup packet into setup TRB, so we can't use the setup
@@ -1677,12 +1894,27 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1677 1894
1678/**** Command Ring Operations ****/ 1895/**** Command Ring Operations ****/
1679 1896
1680/* Generic function for queueing a command TRB on the command ring */ 1897/* Generic function for queueing a command TRB on the command ring.
1681static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, u32 field3, u32 field4) 1898 * Check to make sure there's room on the command ring for one command TRB.
1899 * Also check that there's room reserved for commands that must not fail.
1900 * If this is a command that must not fail, meaning command_must_succeed = TRUE,
1901 * then only check for the number of reserved spots.
1902 * Don't decrement xhci->cmd_ring_reserved_trbs after we've queued the TRB
1903 * because the command event handler may want to resubmit a failed command.
1904 */
1905static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2,
1906 u32 field3, u32 field4, bool command_must_succeed)
1682{ 1907{
1683 if (!room_on_ring(xhci, xhci->cmd_ring, 1)) { 1908 int reserved_trbs = xhci->cmd_ring_reserved_trbs;
1909 if (!command_must_succeed)
1910 reserved_trbs++;
1911
1912 if (!room_on_ring(xhci, xhci->cmd_ring, reserved_trbs)) {
1684 if (!in_interrupt()) 1913 if (!in_interrupt())
1685 xhci_err(xhci, "ERR: No room for command on command ring\n"); 1914 xhci_err(xhci, "ERR: No room for command on command ring\n");
1915 if (command_must_succeed)
1916 xhci_err(xhci, "ERR: Reserved TRB counting for "
1917 "unfailable commands failed.\n");
1686 return -ENOMEM; 1918 return -ENOMEM;
1687 } 1919 }
1688 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3, 1920 queue_trb(xhci, xhci->cmd_ring, false, field1, field2, field3,
@@ -1693,7 +1925,7 @@ static int queue_command(struct xhci_hcd *xhci, u32 field1, u32 field2, u32 fiel
1693/* Queue a no-op command on the command ring */ 1925/* Queue a no-op command on the command ring */
1694static int queue_cmd_noop(struct xhci_hcd *xhci) 1926static int queue_cmd_noop(struct xhci_hcd *xhci)
1695{ 1927{
1696 return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP)); 1928 return queue_command(xhci, 0, 0, 0, TRB_TYPE(TRB_CMD_NOOP), false);
1697} 1929}
1698 1930
1699/* 1931/*
@@ -1712,7 +1944,7 @@ void *xhci_setup_one_noop(struct xhci_hcd *xhci)
1712int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id) 1944int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id)
1713{ 1945{
1714 return queue_command(xhci, 0, 0, 0, 1946 return queue_command(xhci, 0, 0, 0,
1715 TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id)); 1947 TRB_TYPE(trb_type) | SLOT_ID_FOR_TRB(slot_id), false);
1716} 1948}
1717 1949
1718/* Queue an address device command TRB */ 1950/* Queue an address device command TRB */
@@ -1721,16 +1953,28 @@ int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1721{ 1953{
1722 return queue_command(xhci, lower_32_bits(in_ctx_ptr), 1954 return queue_command(xhci, lower_32_bits(in_ctx_ptr),
1723 upper_32_bits(in_ctx_ptr), 0, 1955 upper_32_bits(in_ctx_ptr), 0,
1724 TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id)); 1956 TRB_TYPE(TRB_ADDR_DEV) | SLOT_ID_FOR_TRB(slot_id),
1957 false);
1725} 1958}
1726 1959
1727/* Queue a configure endpoint command TRB */ 1960/* Queue a configure endpoint command TRB */
1728int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1961int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1962 u32 slot_id, bool command_must_succeed)
1963{
1964 return queue_command(xhci, lower_32_bits(in_ctx_ptr),
1965 upper_32_bits(in_ctx_ptr), 0,
1966 TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id),
1967 command_must_succeed);
1968}
1969
1970/* Queue an evaluate context command TRB */
1971int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1729 u32 slot_id) 1972 u32 slot_id)
1730{ 1973{
1731 return queue_command(xhci, lower_32_bits(in_ctx_ptr), 1974 return queue_command(xhci, lower_32_bits(in_ctx_ptr),
1732 upper_32_bits(in_ctx_ptr), 0, 1975 upper_32_bits(in_ctx_ptr), 0,
1733 TRB_TYPE(TRB_CONFIG_EP) | SLOT_ID_FOR_TRB(slot_id)); 1976 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id),
1977 false);
1734} 1978}
1735 1979
1736int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id, 1980int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
@@ -1741,7 +1985,7 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
1741 u32 type = TRB_TYPE(TRB_STOP_RING); 1985 u32 type = TRB_TYPE(TRB_STOP_RING);
1742 1986
1743 return queue_command(xhci, 0, 0, 0, 1987 return queue_command(xhci, 0, 0, 0,
1744 trb_slot_id | trb_ep_index | type); 1988 trb_slot_id | trb_ep_index | type, false);
1745} 1989}
1746 1990
1747/* Set Transfer Ring Dequeue Pointer command. 1991/* Set Transfer Ring Dequeue Pointer command.
@@ -1765,7 +2009,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
1765 } 2009 }
1766 return queue_command(xhci, lower_32_bits(addr) | cycle_state, 2010 return queue_command(xhci, lower_32_bits(addr) | cycle_state,
1767 upper_32_bits(addr), 0, 2011 upper_32_bits(addr), 0,
1768 trb_slot_id | trb_ep_index | type); 2012 trb_slot_id | trb_ep_index | type, false);
1769} 2013}
1770 2014
1771int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 2015int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
@@ -1775,5 +2019,6 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1775 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 2019 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
1776 u32 type = TRB_TYPE(TRB_RESET_EP); 2020 u32 type = TRB_TYPE(TRB_RESET_EP);
1777 2021
1778 return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type); 2022 return queue_command(xhci, 0, 0, 0, trb_slot_id | trb_ep_index | type,
2023 false);
1779} 2024}
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ffe1625d4e1b..4b254b6fa245 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -509,6 +509,8 @@ struct xhci_slot_ctx {
509#define MAX_EXIT (0xffff) 509#define MAX_EXIT (0xffff)
510/* Root hub port number that is needed to access the USB device */ 510/* Root hub port number that is needed to access the USB device */
511#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16) 511#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
512/* Maximum number of ports under a hub device */
513#define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
512 514
513/* tt_info bitmasks */ 515/* tt_info bitmasks */
514/* 516/*
@@ -522,6 +524,7 @@ struct xhci_slot_ctx {
522 * '0' if the device is not low or full speed. 524 * '0' if the device is not low or full speed.
523 */ 525 */
524#define TT_PORT (0xff << 8) 526#define TT_PORT (0xff << 8)
527#define TT_THINK_TIME(p) (((p) & 0x3) << 16)
525 528
526/* dev_state bitmasks */ 529/* dev_state bitmasks */
527/* USB device address - assigned by the HC */ 530/* USB device address - assigned by the HC */
@@ -581,6 +584,7 @@ struct xhci_ep_ctx {
581/* bit 15 is Linear Stream Array */ 584/* bit 15 is Linear Stream Array */
582/* Interval - period between requests to an endpoint - 125u increments. */ 585/* Interval - period between requests to an endpoint - 125u increments. */
583#define EP_INTERVAL(p) ((p & 0xff) << 16) 586#define EP_INTERVAL(p) ((p & 0xff) << 16)
587#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
584 588
585/* ep_info2 bitmasks */ 589/* ep_info2 bitmasks */
586/* 590/*
@@ -589,6 +593,7 @@ struct xhci_ep_ctx {
589 */ 593 */
590#define FORCE_EVENT (0x1) 594#define FORCE_EVENT (0x1)
591#define ERROR_COUNT(p) (((p) & 0x3) << 1) 595#define ERROR_COUNT(p) (((p) & 0x3) << 1)
596#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
592#define EP_TYPE(p) ((p) << 3) 597#define EP_TYPE(p) ((p) << 3)
593#define ISOC_OUT_EP 1 598#define ISOC_OUT_EP 1
594#define BULK_OUT_EP 2 599#define BULK_OUT_EP 2
@@ -601,6 +606,8 @@ struct xhci_ep_ctx {
601/* bit 7 is Host Initiate Disable - for disabling stream selection */ 606/* bit 7 is Host Initiate Disable - for disabling stream selection */
602#define MAX_BURST(p) (((p)&0xff) << 8) 607#define MAX_BURST(p) (((p)&0xff) << 8)
603#define MAX_PACKET(p) (((p)&0xffff) << 16) 608#define MAX_PACKET(p) (((p)&0xffff) << 16)
609#define MAX_PACKET_MASK (0xffff << 16)
610#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
604 611
605 612
606/** 613/**
@@ -616,11 +623,44 @@ struct xhci_input_control_ctx {
616 u32 rsvd2[6]; 623 u32 rsvd2[6];
617}; 624};
618 625
626/* Represents everything that is needed to issue a command on the command ring.
627 * It's useful to pre-allocate these for commands that cannot fail due to
628 * out-of-memory errors, like freeing streams.
629 */
630struct xhci_command {
631 /* Input context for changing device state */
632 struct xhci_container_ctx *in_ctx;
633 u32 status;
634 /* If completion is null, no one is waiting on this command
635 * and the structure can be freed after the command completes.
636 */
637 struct completion *completion;
638 union xhci_trb *command_trb;
639 struct list_head cmd_list;
640};
641
619/* drop context bitmasks */ 642/* drop context bitmasks */
620#define DROP_EP(x) (0x1 << x) 643#define DROP_EP(x) (0x1 << x)
621/* add context bitmasks */ 644/* add context bitmasks */
622#define ADD_EP(x) (0x1 << x) 645#define ADD_EP(x) (0x1 << x)
623 646
647struct xhci_virt_ep {
648 struct xhci_ring *ring;
649 /* Temporary storage in case the configure endpoint command fails and we
650 * have to restore the device state to the previous state
651 */
652 struct xhci_ring *new_ring;
653 unsigned int ep_state;
654#define SET_DEQ_PENDING (1 << 0)
655#define EP_HALTED (1 << 1)
656 /* ---- Related to URB cancellation ---- */
657 struct list_head cancelled_td_list;
658 unsigned int cancels_pending;
659 /* The TRB that was last reported in a stopped endpoint ring */
660 union xhci_trb *stopped_trb;
661 struct xhci_td *stopped_td;
662};
663
624struct xhci_virt_device { 664struct xhci_virt_device {
625 /* 665 /*
626 * Commands to the hardware are passed an "input context" that 666 * Commands to the hardware are passed an "input context" that
@@ -633,16 +673,11 @@ struct xhci_virt_device {
633 struct xhci_container_ctx *out_ctx; 673 struct xhci_container_ctx *out_ctx;
634 /* Used for addressing devices and configuration changes */ 674 /* Used for addressing devices and configuration changes */
635 struct xhci_container_ctx *in_ctx; 675 struct xhci_container_ctx *in_ctx;
636 676 struct xhci_virt_ep eps[31];
637 /* FIXME when stream support is added */
638 struct xhci_ring *ep_rings[31];
639 /* Temporary storage in case the configure endpoint command fails and we
640 * have to restore the device state to the previous state
641 */
642 struct xhci_ring *new_ep_rings[31];
643 struct completion cmd_completion; 677 struct completion cmd_completion;
644 /* Status of the last command issued for this device */ 678 /* Status of the last command issued for this device */
645 u32 cmd_status; 679 u32 cmd_status;
680 struct list_head cmd_list;
646}; 681};
647 682
648 683
@@ -905,6 +940,8 @@ union xhci_trb {
905 * It must also be greater than 16. 940 * It must also be greater than 16.
906 */ 941 */
907#define TRBS_PER_SEGMENT 64 942#define TRBS_PER_SEGMENT 64
943/* Allow two commands + a link TRB, along with any reserved command TRBs */
944#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
908#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 945#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
909/* TRB buffer pointers can't cross 64KB boundaries */ 946/* TRB buffer pointers can't cross 64KB boundaries */
910#define TRB_MAX_BUFF_SHIFT 16 947#define TRB_MAX_BUFF_SHIFT 16
@@ -926,6 +963,12 @@ struct xhci_td {
926 union xhci_trb *last_trb; 963 union xhci_trb *last_trb;
927}; 964};
928 965
966struct xhci_dequeue_state {
967 struct xhci_segment *new_deq_seg;
968 union xhci_trb *new_deq_ptr;
969 int new_cycle_state;
970};
971
929struct xhci_ring { 972struct xhci_ring {
930 struct xhci_segment *first_seg; 973 struct xhci_segment *first_seg;
931 union xhci_trb *enqueue; 974 union xhci_trb *enqueue;
@@ -935,15 +978,6 @@ struct xhci_ring {
935 struct xhci_segment *deq_seg; 978 struct xhci_segment *deq_seg;
936 unsigned int deq_updates; 979 unsigned int deq_updates;
937 struct list_head td_list; 980 struct list_head td_list;
938 /* ---- Related to URB cancellation ---- */
939 struct list_head cancelled_td_list;
940 unsigned int cancels_pending;
941 unsigned int state;
942#define SET_DEQ_PENDING (1 << 0)
943#define EP_HALTED (1 << 1)
944 /* The TRB that was last reported in a stopped endpoint ring */
945 union xhci_trb *stopped_trb;
946 struct xhci_td *stopped_td;
947 /* 981 /*
948 * Write the cycle state into the TRB cycle field to give ownership of 982 * Write the cycle state into the TRB cycle field to give ownership of
949 * the TRB to the host controller (if we are the producer), or to check 983 * the TRB to the host controller (if we are the producer), or to check
@@ -952,12 +986,6 @@ struct xhci_ring {
952 u32 cycle_state; 986 u32 cycle_state;
953}; 987};
954 988
955struct xhci_dequeue_state {
956 struct xhci_segment *new_deq_seg;
957 union xhci_trb *new_deq_ptr;
958 int new_cycle_state;
959};
960
961struct xhci_erst_entry { 989struct xhci_erst_entry {
962 /* 64-bit event ring segment address */ 990 /* 64-bit event ring segment address */
963 u64 seg_addr; 991 u64 seg_addr;
@@ -1034,6 +1062,7 @@ struct xhci_hcd {
1034 /* data structures */ 1062 /* data structures */
1035 struct xhci_device_context_array *dcbaa; 1063 struct xhci_device_context_array *dcbaa;
1036 struct xhci_ring *cmd_ring; 1064 struct xhci_ring *cmd_ring;
1065 unsigned int cmd_ring_reserved_trbs;
1037 struct xhci_ring *event_ring; 1066 struct xhci_ring *event_ring;
1038 struct xhci_erst erst; 1067 struct xhci_erst erst;
1039 /* Scratchpad */ 1068 /* Scratchpad */
@@ -1058,6 +1087,9 @@ struct xhci_hcd {
1058 int noops_submitted; 1087 int noops_submitted;
1059 int noops_handled; 1088 int noops_handled;
1060 int error_bitmask; 1089 int error_bitmask;
1090 unsigned int quirks;
1091#define XHCI_LINK_TRB_QUIRK (1 << 0)
1092#define XHCI_RESET_EP_QUIRK (1 << 1)
1061}; 1093};
1062 1094
1063/* For testing purposes */ 1095/* For testing purposes */
@@ -1136,6 +1168,13 @@ static inline void xhci_write_64(struct xhci_hcd *xhci,
1136 writel(val_hi, ptr + 1); 1168 writel(val_hi, ptr + 1);
1137} 1169}
1138 1170
1171static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1172{
1173 u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
1174 return ((HC_VERSION(temp) == 0x95) &&
1175 (xhci->quirks & XHCI_LINK_TRB_QUIRK));
1176}
1177
1139/* xHCI debugging */ 1178/* xHCI debugging */
1140void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num); 1179void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num);
1141void xhci_print_registers(struct xhci_hcd *xhci); 1180void xhci_print_registers(struct xhci_hcd *xhci);
@@ -1158,11 +1197,24 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device
1158int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev); 1197int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
1159unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc); 1198unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
1160unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc); 1199unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1200unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
1201unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
1161void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep); 1202void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
1203void xhci_endpoint_copy(struct xhci_hcd *xhci,
1204 struct xhci_container_ctx *in_ctx,
1205 struct xhci_container_ctx *out_ctx,
1206 unsigned int ep_index);
1207void xhci_slot_copy(struct xhci_hcd *xhci,
1208 struct xhci_container_ctx *in_ctx,
1209 struct xhci_container_ctx *out_ctx);
1162int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, 1210int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
1163 struct usb_device *udev, struct usb_host_endpoint *ep, 1211 struct usb_device *udev, struct usb_host_endpoint *ep,
1164 gfp_t mem_flags); 1212 gfp_t mem_flags);
1165void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring); 1213void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
1214struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1215 bool allocate_completion, gfp_t mem_flags);
1216void xhci_free_command(struct xhci_hcd *xhci,
1217 struct xhci_command *command);
1166 1218
1167#ifdef CONFIG_PCI 1219#ifdef CONFIG_PCI
1168/* xHCI PCI glue */ 1220/* xHCI PCI glue */
@@ -1182,6 +1234,8 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd);
1182int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1234int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1183void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1235void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1184int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); 1236int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
1237int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1238 struct usb_tt *tt, gfp_t mem_flags);
1185int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); 1239int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
1186int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); 1240int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1187int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); 1241int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
@@ -1205,7 +1259,11 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1205 int slot_id, unsigned int ep_index); 1259 int slot_id, unsigned int ep_index);
1206int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb, 1260int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1207 int slot_id, unsigned int ep_index); 1261 int slot_id, unsigned int ep_index);
1262int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1263 int slot_id, unsigned int ep_index);
1208int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1264int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1265 u32 slot_id, bool command_must_succeed);
1266int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1209 u32 slot_id); 1267 u32 slot_id);
1210int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 1268int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1211 unsigned int ep_index); 1269 unsigned int ep_index);
@@ -1213,8 +1271,13 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
1213 unsigned int slot_id, unsigned int ep_index, 1271 unsigned int slot_id, unsigned int ep_index,
1214 struct xhci_td *cur_td, struct xhci_dequeue_state *state); 1272 struct xhci_td *cur_td, struct xhci_dequeue_state *state);
1215void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, 1273void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
1216 struct xhci_ring *ep_ring, unsigned int slot_id, 1274 unsigned int slot_id, unsigned int ep_index,
1217 unsigned int ep_index, struct xhci_dequeue_state *deq_state); 1275 struct xhci_dequeue_state *deq_state);
1276void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1277 struct usb_device *udev, unsigned int ep_index);
1278void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1279 unsigned int slot_id, unsigned int ep_index,
1280 struct xhci_dequeue_state *deq_state);
1218 1281
1219/* xHCI roothub code */ 1282/* xHCI roothub code */
1220int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1283int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 4541dfcea88f..459a7287fe01 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -653,33 +653,6 @@ static struct scsi_host_template mts_scsi_host_template = {
653 .max_sectors= 256, /* 128 K */ 653 .max_sectors= 256, /* 128 K */
654}; 654};
655 655
656struct vendor_product
657{
658 char* name;
659 enum
660 {
661 mts_sup_unknown=0,
662 mts_sup_alpha,
663 mts_sup_full
664 }
665 support_status;
666} ;
667
668
669/* These are taken from the msmUSB.inf file on the Windows driver CD */
670static const struct vendor_product mts_supported_products[] =
671{
672 { "Phantom 336CX", mts_sup_unknown},
673 { "Phantom 336CX", mts_sup_unknown},
674 { "Scanmaker X6", mts_sup_alpha},
675 { "Phantom C6", mts_sup_unknown},
676 { "Phantom 336CX", mts_sup_unknown},
677 { "ScanMaker V6USL", mts_sup_unknown},
678 { "ScanMaker V6USL", mts_sup_unknown},
679 { "Scanmaker V6UL", mts_sup_unknown},
680 { "Scanmaker V6UPL", mts_sup_alpha},
681};
682
683/* The entries of microtek_table must correspond, line-by-line to 656/* The entries of microtek_table must correspond, line-by-line to
684 the entries of mts_supported_products[]. */ 657 the entries of mts_supported_products[]. */
685 658
@@ -711,7 +684,6 @@ static int mts_usb_probe(struct usb_interface *intf,
711 int err_retval = -ENOMEM; 684 int err_retval = -ENOMEM;
712 685
713 struct mts_desc * new_desc; 686 struct mts_desc * new_desc;
714 struct vendor_product const* p;
715 struct usb_device *dev = interface_to_usbdev (intf); 687 struct usb_device *dev = interface_to_usbdev (intf);
716 688
717 /* the current altsetting on the interface we're probing */ 689 /* the current altsetting on the interface we're probing */
@@ -726,15 +698,6 @@ static int mts_usb_probe(struct usb_interface *intf,
726 698
727 MTS_DEBUG_GOT_HERE(); 699 MTS_DEBUG_GOT_HERE();
728 700
729 p = &mts_supported_products[id - mts_usb_ids];
730
731 MTS_DEBUG_GOT_HERE();
732
733 MTS_DEBUG( "found model %s\n", p->name );
734 if ( p->support_status != mts_sup_full )
735 MTS_MESSAGE( "model %s is not known to be fully supported, reports welcome!\n",
736 p->name );
737
738 /* the current altsetting on the interface we're probing */ 701 /* the current altsetting on the interface we're probing */
739 altsetting = intf->cur_altsetting; 702 altsetting = intf->cur_altsetting;
740 703
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index 6da8887538c7..1337a9ce80b9 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -96,6 +96,8 @@ static int idmouse_probe(struct usb_interface *interface,
96 const struct usb_device_id *id); 96 const struct usb_device_id *id);
97 97
98static void idmouse_disconnect(struct usb_interface *interface); 98static void idmouse_disconnect(struct usb_interface *interface);
99static int idmouse_suspend(struct usb_interface *intf, pm_message_t message);
100static int idmouse_resume(struct usb_interface *intf);
99 101
100/* file operation pointers */ 102/* file operation pointers */
101static const struct file_operations idmouse_fops = { 103static const struct file_operations idmouse_fops = {
@@ -117,7 +119,11 @@ static struct usb_driver idmouse_driver = {
117 .name = DRIVER_SHORT, 119 .name = DRIVER_SHORT,
118 .probe = idmouse_probe, 120 .probe = idmouse_probe,
119 .disconnect = idmouse_disconnect, 121 .disconnect = idmouse_disconnect,
122 .suspend = idmouse_suspend,
123 .resume = idmouse_resume,
124 .reset_resume = idmouse_resume,
120 .id_table = idmouse_table, 125 .id_table = idmouse_table,
126 .supports_autosuspend = 1,
121}; 127};
122 128
123static int idmouse_create_image(struct usb_idmouse *dev) 129static int idmouse_create_image(struct usb_idmouse *dev)
@@ -197,6 +203,17 @@ reset:
197 return result; 203 return result;
198} 204}
199 205
206/* PM operations are nops as this driver does IO only during open() */
207static int idmouse_suspend(struct usb_interface *intf, pm_message_t message)
208{
209 return 0;
210}
211
212static int idmouse_resume(struct usb_interface *intf)
213{
214 return 0;
215}
216
200static inline void idmouse_delete(struct usb_idmouse *dev) 217static inline void idmouse_delete(struct usb_idmouse *dev)
201{ 218{
202 kfree(dev->bulk_in_buffer); 219 kfree(dev->bulk_in_buffer);
@@ -235,9 +252,13 @@ static int idmouse_open(struct inode *inode, struct file *file)
235 } else { 252 } else {
236 253
237 /* create a new image and check for success */ 254 /* create a new image and check for success */
255 result = usb_autopm_get_interface(interface);
256 if (result)
257 goto error;
238 result = idmouse_create_image (dev); 258 result = idmouse_create_image (dev);
239 if (result) 259 if (result)
240 goto error; 260 goto error;
261 usb_autopm_put_interface(interface);
241 262
242 /* increment our usage count for the driver */ 263 /* increment our usage count for the driver */
243 ++dev->open; 264 ++dev->open;
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index ad4fb15b5dcb..90f130126c10 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -412,6 +412,9 @@ static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
412 412
413 dev = file->private_data; 413 dev = file->private_data;
414 414
415 if (!dev->intf)
416 return POLLERR | POLLHUP;
417
415 poll_wait(file, &dev->read_wait, wait); 418 poll_wait(file, &dev->read_wait, wait);
416 poll_wait(file, &dev->write_wait, wait); 419 poll_wait(file, &dev->write_wait, wait);
417 420
@@ -767,6 +770,9 @@ static void ld_usb_disconnect(struct usb_interface *intf)
767 ld_usb_delete(dev); 770 ld_usb_delete(dev);
768 } else { 771 } else {
769 dev->intf = NULL; 772 dev->intf = NULL;
773 /* wake up pollers */
774 wake_up_interruptible_all(&dev->read_wait);
775 wake_up_interruptible_all(&dev->write_wait);
770 mutex_unlock(&dev->mutex); 776 mutex_unlock(&dev->mutex);
771 } 777 }
772 778
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 97efeaec4d52..faa6d623de78 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -552,6 +552,9 @@ static unsigned int tower_poll (struct file *file, poll_table *wait)
552 552
553 dev = file->private_data; 553 dev = file->private_data;
554 554
555 if (!dev->udev)
556 return POLLERR | POLLHUP;
557
555 poll_wait(file, &dev->read_wait, wait); 558 poll_wait(file, &dev->read_wait, wait);
556 poll_wait(file, &dev->write_wait, wait); 559 poll_wait(file, &dev->write_wait, wait);
557 560
@@ -1025,6 +1028,9 @@ static void tower_disconnect (struct usb_interface *interface)
1025 tower_delete (dev); 1028 tower_delete (dev);
1026 } else { 1029 } else {
1027 dev->udev = NULL; 1030 dev->udev = NULL;
1031 /* wake up pollers */
1032 wake_up_interruptible_all(&dev->read_wait);
1033 wake_up_interruptible_all(&dev->write_wait);
1028 mutex_unlock(&dev->lock); 1034 mutex_unlock(&dev->lock);
1029 } 1035 }
1030 1036
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index b4ec716de7da..0025847743f3 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -79,14 +79,12 @@ sisusb_free_buffers(struct sisusb_usb_data *sisusb)
79 79
80 for (i = 0; i < NUMOBUFS; i++) { 80 for (i = 0; i < NUMOBUFS; i++) {
81 if (sisusb->obuf[i]) { 81 if (sisusb->obuf[i]) {
82 usb_buffer_free(sisusb->sisusb_dev, sisusb->obufsize, 82 kfree(sisusb->obuf[i]);
83 sisusb->obuf[i], sisusb->transfer_dma_out[i]);
84 sisusb->obuf[i] = NULL; 83 sisusb->obuf[i] = NULL;
85 } 84 }
86 } 85 }
87 if (sisusb->ibuf) { 86 if (sisusb->ibuf) {
88 usb_buffer_free(sisusb->sisusb_dev, sisusb->ibufsize, 87 kfree(sisusb->ibuf);
89 sisusb->ibuf, sisusb->transfer_dma_in);
90 sisusb->ibuf = NULL; 88 sisusb->ibuf = NULL;
91 } 89 }
92} 90}
@@ -230,8 +228,7 @@ sisusb_bulk_completeout(struct urb *urb)
230 228
231static int 229static int
232sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, void *data, 230sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, void *data,
233 int len, int *actual_length, int timeout, unsigned int tflags, 231 int len, int *actual_length, int timeout, unsigned int tflags)
234 dma_addr_t transfer_dma)
235{ 232{
236 struct urb *urb = sisusb->sisurbout[index]; 233 struct urb *urb = sisusb->sisurbout[index];
237 int retval, byteswritten = 0; 234 int retval, byteswritten = 0;
@@ -245,9 +242,6 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
245 urb->transfer_flags |= tflags; 242 urb->transfer_flags |= tflags;
246 urb->actual_length = 0; 243 urb->actual_length = 0;
247 244
248 if ((urb->transfer_dma = transfer_dma))
249 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
250
251 /* Set up context */ 245 /* Set up context */
252 sisusb->urbout_context[index].actual_length = (timeout) ? 246 sisusb->urbout_context[index].actual_length = (timeout) ?
253 NULL : actual_length; 247 NULL : actual_length;
@@ -297,8 +291,8 @@ sisusb_bulk_completein(struct urb *urb)
297} 291}
298 292
299static int 293static int
300sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data, int len, 294sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
301 int *actual_length, int timeout, unsigned int tflags, dma_addr_t transfer_dma) 295 int len, int *actual_length, int timeout, unsigned int tflags)
302{ 296{
303 struct urb *urb = sisusb->sisurbin; 297 struct urb *urb = sisusb->sisurbin;
304 int retval, readbytes = 0; 298 int retval, readbytes = 0;
@@ -311,9 +305,6 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
311 urb->transfer_flags |= tflags; 305 urb->transfer_flags |= tflags;
312 urb->actual_length = 0; 306 urb->actual_length = 0;
313 307
314 if ((urb->transfer_dma = transfer_dma))
315 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
316
317 sisusb->completein = 0; 308 sisusb->completein = 0;
318 retval = usb_submit_urb(urb, GFP_ATOMIC); 309 retval = usb_submit_urb(urb, GFP_ATOMIC);
319 if (retval == 0) { 310 if (retval == 0) {
@@ -422,8 +413,7 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
422 thispass, 413 thispass,
423 &transferred_len, 414 &transferred_len,
424 async ? 0 : 5 * HZ, 415 async ? 0 : 5 * HZ,
425 tflags, 416 tflags);
426 sisusb->transfer_dma_out[index]);
427 417
428 if (result == -ETIMEDOUT) { 418 if (result == -ETIMEDOUT) {
429 419
@@ -432,29 +422,16 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
432 return -ETIME; 422 return -ETIME;
433 423
434 continue; 424 continue;
425 }
435 426
436 } else if ((result == 0) && !async && transferred_len) { 427 if ((result == 0) && !async && transferred_len) {
437 428
438 thispass -= transferred_len; 429 thispass -= transferred_len;
439 if (thispass) { 430 buffer += transferred_len;
440 if (sisusb->transfer_dma_out) {
441 /* If DMA, copy remaining
442 * to beginning of buffer
443 */
444 memcpy(buffer,
445 buffer + transferred_len,
446 thispass);
447 } else {
448 /* If not DMA, simply increase
449 * the pointer
450 */
451 buffer += transferred_len;
452 }
453 }
454 431
455 } else 432 } else
456 break; 433 break;
457 }; 434 }
458 435
459 if (result) 436 if (result)
460 return result; 437 return result;
@@ -530,8 +507,7 @@ static int sisusb_recv_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
530 thispass, 507 thispass,
531 &transferred_len, 508 &transferred_len,
532 5 * HZ, 509 5 * HZ,
533 tflags, 510 tflags);
534 sisusb->transfer_dma_in);
535 511
536 if (transferred_len) 512 if (transferred_len)
537 thispass = transferred_len; 513 thispass = transferred_len;
@@ -3132,8 +3108,7 @@ static int sisusb_probe(struct usb_interface *intf,
3132 3108
3133 /* Allocate buffers */ 3109 /* Allocate buffers */
3134 sisusb->ibufsize = SISUSB_IBUF_SIZE; 3110 sisusb->ibufsize = SISUSB_IBUF_SIZE;
3135 if (!(sisusb->ibuf = usb_buffer_alloc(dev, SISUSB_IBUF_SIZE, 3111 if (!(sisusb->ibuf = kmalloc(SISUSB_IBUF_SIZE, GFP_KERNEL))) {
3136 GFP_KERNEL, &sisusb->transfer_dma_in))) {
3137 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer"); 3112 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer");
3138 retval = -ENOMEM; 3113 retval = -ENOMEM;
3139 goto error_2; 3114 goto error_2;
@@ -3142,9 +3117,7 @@ static int sisusb_probe(struct usb_interface *intf,
3142 sisusb->numobufs = 0; 3117 sisusb->numobufs = 0;
3143 sisusb->obufsize = SISUSB_OBUF_SIZE; 3118 sisusb->obufsize = SISUSB_OBUF_SIZE;
3144 for (i = 0; i < NUMOBUFS; i++) { 3119 for (i = 0; i < NUMOBUFS; i++) {
3145 if (!(sisusb->obuf[i] = usb_buffer_alloc(dev, SISUSB_OBUF_SIZE, 3120 if (!(sisusb->obuf[i] = kmalloc(SISUSB_OBUF_SIZE, GFP_KERNEL))) {
3146 GFP_KERNEL,
3147 &sisusb->transfer_dma_out[i]))) {
3148 if (i == 0) { 3121 if (i == 0) {
3149 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n"); 3122 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n");
3150 retval = -ENOMEM; 3123 retval = -ENOMEM;
diff --git a/drivers/usb/misc/sisusbvga/sisusb.h b/drivers/usb/misc/sisusbvga/sisusb.h
index cf0b4a5883f6..55492a5930bd 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.h
+++ b/drivers/usb/misc/sisusbvga/sisusb.h
@@ -123,8 +123,6 @@ struct sisusb_usb_data {
123 int numobufs; /* number of obufs = number of out urbs */ 123 int numobufs; /* number of obufs = number of out urbs */
124 char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */ 124 char *obuf[NUMOBUFS], *ibuf; /* transfer buffers */
125 int obufsize, ibufsize; 125 int obufsize, ibufsize;
126 dma_addr_t transfer_dma_out[NUMOBUFS];
127 dma_addr_t transfer_dma_in;
128 struct urb *sisurbout[NUMOBUFS]; 126 struct urb *sisurbout[NUMOBUFS];
129 struct urb *sisurbin; 127 struct urb *sisurbin;
130 unsigned char urbstatus[NUMOBUFS]; 128 unsigned char urbstatus[NUMOBUFS];
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
index 28a6a3a09538..3db255537e79 100644
--- a/drivers/usb/misc/usbsevseg.c
+++ b/drivers/usb/misc/usbsevseg.c
@@ -38,6 +38,7 @@ static char *display_textmodes[] = {"raw", "hex", "ascii", NULL};
38 38
39struct usb_sevsegdev { 39struct usb_sevsegdev {
40 struct usb_device *udev; 40 struct usb_device *udev;
41 struct usb_interface *intf;
41 42
42 u8 powered; 43 u8 powered;
43 u8 mode_msb; 44 u8 mode_msb;
@@ -46,6 +47,8 @@ struct usb_sevsegdev {
46 u8 textmode; 47 u8 textmode;
47 u8 text[MAXLEN]; 48 u8 text[MAXLEN];
48 u16 textlength; 49 u16 textlength;
50
51 u8 shadow_power; /* for PM */
49}; 52};
50 53
51/* sysfs_streq can't replace this completely 54/* sysfs_streq can't replace this completely
@@ -65,6 +68,12 @@ static void update_display_powered(struct usb_sevsegdev *mydev)
65{ 68{
66 int rc; 69 int rc;
67 70
71 if (!mydev->shadow_power && mydev->powered) {
72 rc = usb_autopm_get_interface(mydev->intf);
73 if (rc < 0)
74 return;
75 }
76
68 rc = usb_control_msg(mydev->udev, 77 rc = usb_control_msg(mydev->udev,
69 usb_sndctrlpipe(mydev->udev, 0), 78 usb_sndctrlpipe(mydev->udev, 0),
70 0x12, 79 0x12,
@@ -76,12 +85,18 @@ static void update_display_powered(struct usb_sevsegdev *mydev)
76 2000); 85 2000);
77 if (rc < 0) 86 if (rc < 0)
78 dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); 87 dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc);
88
89 if (mydev->shadow_power && !mydev->powered)
90 usb_autopm_put_interface(mydev->intf);
79} 91}
80 92
81static void update_display_mode(struct usb_sevsegdev *mydev) 93static void update_display_mode(struct usb_sevsegdev *mydev)
82{ 94{
83 int rc; 95 int rc;
84 96
97 if(mydev->shadow_power != 1)
98 return;
99
85 rc = usb_control_msg(mydev->udev, 100 rc = usb_control_msg(mydev->udev,
86 usb_sndctrlpipe(mydev->udev, 0), 101 usb_sndctrlpipe(mydev->udev, 0),
87 0x12, 102 0x12,
@@ -96,14 +111,17 @@ static void update_display_mode(struct usb_sevsegdev *mydev)
96 dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc); 111 dev_dbg(&mydev->udev->dev, "mode retval = %d\n", rc);
97} 112}
98 113
99static void update_display_visual(struct usb_sevsegdev *mydev) 114static void update_display_visual(struct usb_sevsegdev *mydev, gfp_t mf)
100{ 115{
101 int rc; 116 int rc;
102 int i; 117 int i;
103 unsigned char *buffer; 118 unsigned char *buffer;
104 u8 decimals = 0; 119 u8 decimals = 0;
105 120
106 buffer = kzalloc(MAXLEN, GFP_KERNEL); 121 if(mydev->shadow_power != 1)
122 return;
123
124 buffer = kzalloc(MAXLEN, mf);
107 if (!buffer) { 125 if (!buffer) {
108 dev_err(&mydev->udev->dev, "out of memory\n"); 126 dev_err(&mydev->udev->dev, "out of memory\n");
109 return; 127 return;
@@ -163,7 +181,7 @@ static ssize_t set_attr_##name(struct device *dev, \
163 struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \ 181 struct usb_sevsegdev *mydev = usb_get_intfdata(intf); \
164 \ 182 \
165 mydev->name = simple_strtoul(buf, NULL, 10); \ 183 mydev->name = simple_strtoul(buf, NULL, 10); \
166 update_fcn(mydev); \ 184 update_fcn(mydev); \
167 \ 185 \
168 return count; \ 186 return count; \
169} \ 187} \
@@ -194,7 +212,7 @@ static ssize_t set_attr_text(struct device *dev,
194 if (end > 0) 212 if (end > 0)
195 memcpy(mydev->text, buf, end); 213 memcpy(mydev->text, buf, end);
196 214
197 update_display_visual(mydev); 215 update_display_visual(mydev, GFP_KERNEL);
198 return count; 216 return count;
199} 217}
200 218
@@ -242,7 +260,7 @@ static ssize_t set_attr_decimals(struct device *dev,
242 if (buf[i] == '1') 260 if (buf[i] == '1')
243 mydev->decimals[end-1-i] = 1; 261 mydev->decimals[end-1-i] = 1;
244 262
245 update_display_visual(mydev); 263 update_display_visual(mydev, GFP_KERNEL);
246 264
247 return count; 265 return count;
248} 266}
@@ -286,7 +304,7 @@ static ssize_t set_attr_textmode(struct device *dev,
286 for (i = 0; display_textmodes[i]; i++) { 304 for (i = 0; display_textmodes[i]; i++) {
287 if (sysfs_streq(display_textmodes[i], buf)) { 305 if (sysfs_streq(display_textmodes[i], buf)) {
288 mydev->textmode = i; 306 mydev->textmode = i;
289 update_display_visual(mydev); 307 update_display_visual(mydev, GFP_KERNEL);
290 return count; 308 return count;
291 } 309 }
292 } 310 }
@@ -330,6 +348,7 @@ static int sevseg_probe(struct usb_interface *interface,
330 } 348 }
331 349
332 mydev->udev = usb_get_dev(udev); 350 mydev->udev = usb_get_dev(udev);
351 mydev->intf = interface;
333 usb_set_intfdata(interface, mydev); 352 usb_set_intfdata(interface, mydev);
334 353
335 /*set defaults */ 354 /*set defaults */
@@ -364,11 +383,49 @@ static void sevseg_disconnect(struct usb_interface *interface)
364 dev_info(&interface->dev, "USB 7 Segment now disconnected\n"); 383 dev_info(&interface->dev, "USB 7 Segment now disconnected\n");
365} 384}
366 385
386static int sevseg_suspend(struct usb_interface *intf, pm_message_t message)
387{
388 struct usb_sevsegdev *mydev;
389
390 mydev = usb_get_intfdata(intf);
391 mydev->shadow_power = 0;
392
393 return 0;
394}
395
396static int sevseg_resume(struct usb_interface *intf)
397{
398 struct usb_sevsegdev *mydev;
399
400 mydev = usb_get_intfdata(intf);
401 mydev->shadow_power = 1;
402 update_display_mode(mydev);
403 update_display_visual(mydev, GFP_NOIO);
404
405 return 0;
406}
407
408static int sevseg_reset_resume(struct usb_interface *intf)
409{
410 struct usb_sevsegdev *mydev;
411
412 mydev = usb_get_intfdata(intf);
413 mydev->shadow_power = 1;
414 update_display_mode(mydev);
415 update_display_visual(mydev, GFP_NOIO);
416
417 return 0;
418}
419
367static struct usb_driver sevseg_driver = { 420static struct usb_driver sevseg_driver = {
368 .name = "usbsevseg", 421 .name = "usbsevseg",
369 .probe = sevseg_probe, 422 .probe = sevseg_probe,
370 .disconnect = sevseg_disconnect, 423 .disconnect = sevseg_disconnect,
424 .suspend = sevseg_suspend,
425 .resume = sevseg_resume,
426 .reset_resume = sevseg_reset_resume,
371 .id_table = id_table, 427 .id_table = id_table,
428 .supports_autosuspend = 1,
372}; 429};
373 430
374static int __init usb_sevseg_init(void) 431static int __init usb_sevseg_init(void)
diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig
index f28f350cd96a..635745f57fbd 100644
--- a/drivers/usb/mon/Kconfig
+++ b/drivers/usb/mon/Kconfig
@@ -5,11 +5,9 @@
5config USB_MON 5config USB_MON
6 tristate "USB Monitor" 6 tristate "USB Monitor"
7 depends on USB 7 depends on USB
8 default y if USB=y
9 default m if USB=m
10 help 8 help
11 If you select this option, a component which captures the USB traffic 9 If you select this option, a component which captures the USB traffic
12 between peripheral-specific drivers and HC drivers will be built. 10 between peripheral-specific drivers and HC drivers will be built.
13 For more information, see <file:Documentation/usb/usbmon.txt>. 11 For more information, see <file:Documentation/usb/usbmon.txt>.
14 12
15 If unsure, say Y (if allowed), otherwise M. 13 If unsure, say Y, if allowed, otherwise M.
diff --git a/drivers/usb/mon/Makefile b/drivers/usb/mon/Makefile
index c6516b566731..384b198faa7c 100644
--- a/drivers/usb/mon/Makefile
+++ b/drivers/usb/mon/Makefile
@@ -2,6 +2,6 @@
2# Makefile for USB monitor 2# Makefile for USB monitor
3# 3#
4 4
5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o mon_dma.o 5usbmon-objs := mon_main.o mon_stat.o mon_text.o mon_bin.o
6 6
7obj-$(CONFIG_USB_MON) += usbmon.o 7obj-$(CONFIG_USB_MON) += usbmon.o
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 0f7a30b7d2d1..dfdc43e2e00d 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -220,9 +220,8 @@ static void mon_free_buff(struct mon_pgmap *map, int npages);
220 220
221/* 221/*
222 * This is a "chunked memcpy". It does not manipulate any counters. 222 * This is a "chunked memcpy". It does not manipulate any counters.
223 * But it returns the new offset for repeated application.
224 */ 223 */
225unsigned int mon_copy_to_buff(const struct mon_reader_bin *this, 224static void mon_copy_to_buff(const struct mon_reader_bin *this,
226 unsigned int off, const unsigned char *from, unsigned int length) 225 unsigned int off, const unsigned char *from, unsigned int length)
227{ 226{
228 unsigned int step_len; 227 unsigned int step_len;
@@ -247,7 +246,6 @@ unsigned int mon_copy_to_buff(const struct mon_reader_bin *this,
247 from += step_len; 246 from += step_len;
248 length -= step_len; 247 length -= step_len;
249 } 248 }
250 return off;
251} 249}
252 250
253/* 251/*
@@ -400,15 +398,8 @@ static char mon_bin_get_data(const struct mon_reader_bin *rp,
400 unsigned int offset, struct urb *urb, unsigned int length) 398 unsigned int offset, struct urb *urb, unsigned int length)
401{ 399{
402 400
403 if (urb->dev->bus->uses_dma &&
404 (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
405 mon_dmapeek_vec(rp, offset, urb->transfer_dma, length);
406 return 0;
407 }
408
409 if (urb->transfer_buffer == NULL) 401 if (urb->transfer_buffer == NULL)
410 return 'Z'; 402 return 'Z';
411
412 mon_copy_to_buff(rp, offset, urb->transfer_buffer, length); 403 mon_copy_to_buff(rp, offset, urb->transfer_buffer, length);
413 return 0; 404 return 0;
414} 405}
@@ -635,7 +626,6 @@ static int mon_bin_open(struct inode *inode, struct file *file)
635 spin_lock_init(&rp->b_lock); 626 spin_lock_init(&rp->b_lock);
636 init_waitqueue_head(&rp->b_wait); 627 init_waitqueue_head(&rp->b_wait);
637 mutex_init(&rp->fetch_lock); 628 mutex_init(&rp->fetch_lock);
638
639 rp->b_size = BUFF_DFL; 629 rp->b_size = BUFF_DFL;
640 630
641 size = sizeof(struct mon_pgmap) * (rp->b_size/CHUNK_SIZE); 631 size = sizeof(struct mon_pgmap) * (rp->b_size/CHUNK_SIZE);
diff --git a/drivers/usb/mon/mon_dma.c b/drivers/usb/mon/mon_dma.c
deleted file mode 100644
index 140cc80bd2b1..000000000000
--- a/drivers/usb/mon/mon_dma.c
+++ /dev/null
@@ -1,95 +0,0 @@
1/*
2 * The USB Monitor, inspired by Dave Harding's USBMon.
3 *
4 * mon_dma.c: Library which snoops on DMA areas.
5 *
6 * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com)
7 */
8#include <linux/kernel.h>
9#include <linux/list.h>
10#include <linux/highmem.h>
11#include <asm/page.h>
12
13#include <linux/usb.h> /* Only needed for declarations in usb_mon.h */
14#include "usb_mon.h"
15
16/*
17 * PC-compatibles, are, fortunately, sufficiently cache-coherent for this.
18 */
19#if defined(__i386__) || defined(__x86_64__) /* CONFIG_ARCH_I386 doesn't exit */
20#define MON_HAS_UNMAP 1
21
22#define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT)
23
24char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
25{
26 struct page *pg;
27 unsigned long flags;
28 unsigned char *map;
29 unsigned char *ptr;
30
31 /*
32 * On i386, a DMA handle is the "physical" address of a page.
33 * In other words, the bus address is equal to physical address.
34 * There is no IOMMU.
35 */
36 pg = phys_to_page(dma_addr);
37
38 /*
39 * We are called from hardware IRQs in case of callbacks.
40 * But we can be called from softirq or process context in case
41 * of submissions. In such case, we need to protect KM_IRQ0.
42 */
43 local_irq_save(flags);
44 map = kmap_atomic(pg, KM_IRQ0);
45 ptr = map + (dma_addr & (PAGE_SIZE-1));
46 memcpy(dst, ptr, len);
47 kunmap_atomic(map, KM_IRQ0);
48 local_irq_restore(flags);
49 return 0;
50}
51
52void mon_dmapeek_vec(const struct mon_reader_bin *rp,
53 unsigned int offset, dma_addr_t dma_addr, unsigned int length)
54{
55 unsigned long flags;
56 unsigned int step_len;
57 struct page *pg;
58 unsigned char *map;
59 unsigned long page_off, page_len;
60
61 local_irq_save(flags);
62 while (length) {
63 /* compute number of bytes we are going to copy in this page */
64 step_len = length;
65 page_off = dma_addr & (PAGE_SIZE-1);
66 page_len = PAGE_SIZE - page_off;
67 if (page_len < step_len)
68 step_len = page_len;
69
70 /* copy data and advance pointers */
71 pg = phys_to_page(dma_addr);
72 map = kmap_atomic(pg, KM_IRQ0);
73 offset = mon_copy_to_buff(rp, offset, map + page_off, step_len);
74 kunmap_atomic(map, KM_IRQ0);
75 dma_addr += step_len;
76 length -= step_len;
77 }
78 local_irq_restore(flags);
79}
80
81#endif /* __i386__ */
82
83#ifndef MON_HAS_UNMAP
84char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len)
85{
86 return 'D';
87}
88
89void mon_dmapeek_vec(const struct mon_reader_bin *rp,
90 unsigned int offset, dma_addr_t dma_addr, unsigned int length)
91{
92 ;
93}
94
95#endif /* MON_HAS_UNMAP */
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 5e0ab4201c00..e0c2db3b767b 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -361,7 +361,6 @@ static int __init mon_init(void)
361 } 361 }
362 // MOD_INC_USE_COUNT(which_module?); 362 // MOD_INC_USE_COUNT(which_module?);
363 363
364
365 mutex_lock(&usb_bus_list_lock); 364 mutex_lock(&usb_bus_list_lock);
366 list_for_each_entry (ubus, &usb_bus_list, bus_list) { 365 list_for_each_entry (ubus, &usb_bus_list, bus_list) {
367 mon_bus_init(ubus); 366 mon_bus_init(ubus);
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index a7eb4c99342c..9f1a9227ebe6 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -150,20 +150,6 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
150 return '>'; 150 return '>';
151 } 151 }
152 152
153 /*
154 * The check to see if it's safe to poke at data has an enormous
155 * number of corner cases, but it seems that the following is
156 * more or less safe.
157 *
158 * We do not even try to look at transfer_buffer, because it can
159 * contain non-NULL garbage in case the upper level promised to
160 * set DMA for the HCD.
161 */
162 if (urb->dev->bus->uses_dma &&
163 (urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
164 return mon_dmapeek(ep->data, urb->transfer_dma, len);
165 }
166
167 if (urb->transfer_buffer == NULL) 153 if (urb->transfer_buffer == NULL)
168 return 'Z'; /* '0' would be not as pretty. */ 154 return 'Z'; /* '0' would be not as pretty. */
169 155
diff --git a/drivers/usb/mon/usb_mon.h b/drivers/usb/mon/usb_mon.h
index f5d84ff8c101..df9a4df342c7 100644
--- a/drivers/usb/mon/usb_mon.h
+++ b/drivers/usb/mon/usb_mon.h
@@ -65,20 +65,6 @@ int __init mon_bin_init(void);
65void mon_bin_exit(void); 65void mon_bin_exit(void);
66 66
67/* 67/*
68 * DMA interface.
69 *
70 * XXX The vectored side needs a serious re-thinking. Abstracting vectors,
71 * like in Paolo's original patch, produces a double pkmap. We need an idea.
72*/
73extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len);
74
75struct mon_reader_bin;
76extern void mon_dmapeek_vec(const struct mon_reader_bin *rp,
77 unsigned int offset, dma_addr_t dma_addr, unsigned int len);
78extern unsigned int mon_copy_to_buff(const struct mon_reader_bin *rp,
79 unsigned int offset, const unsigned char *from, unsigned int len);
80
81/*
82 */ 68 */
83extern struct mutex mon_lock; 69extern struct mutex mon_lock;
84 70
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 1d26beddf2ca..3a61ddb62bd2 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1850,6 +1850,10 @@ static void musb_free(struct musb *musb)
1850 dma_controller_destroy(c); 1850 dma_controller_destroy(c);
1851 } 1851 }
1852 1852
1853#ifdef CONFIG_USB_MUSB_OTG
1854 put_device(musb->xceiv->dev);
1855#endif
1856
1853 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 1857 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1854 musb_platform_exit(musb); 1858 musb_platform_exit(musb);
1855 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); 1859 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
@@ -1859,10 +1863,6 @@ static void musb_free(struct musb *musb)
1859 clk_put(musb->clock); 1863 clk_put(musb->clock);
1860 } 1864 }
1861 1865
1862#ifdef CONFIG_USB_MUSB_OTG
1863 put_device(musb->xceiv->dev);
1864#endif
1865
1866#ifdef CONFIG_USB_MUSB_HDRC_HCD 1866#ifdef CONFIG_USB_MUSB_HDRC_HCD
1867 usb_put_hcd(musb_to_hcd(musb)); 1867 usb_put_hcd(musb_to_hcd(musb));
1868#else 1868#else
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index e0d56ef2bcb0..77a5f4188999 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -117,24 +117,7 @@ static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
117 pr_debug(" VBUS %d mA error %d\n", mA, status); 117 pr_debug(" VBUS %d mA error %d\n", mA, status);
118} 118}
119 119
120static void enable_vbus_source(struct isp1301 *isp) 120#else
121{
122 /* this board won't supply more than 8mA vbus power.
123 * some boards can switch a 100ma "unit load" (or more).
124 */
125}
126
127
128/* products will deliver OTG messages with LEDs, GUI, etc */
129static inline void notresponding(struct isp1301 *isp)
130{
131 printk(KERN_NOTICE "OTG device not responding.\n");
132}
133
134
135#endif
136
137#if defined(CONFIG_MACH_OMAP_H4)
138 121
139static void enable_vbus_draw(struct isp1301 *isp, unsigned mA) 122static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
140{ 123{
@@ -144,6 +127,8 @@ static void enable_vbus_draw(struct isp1301 *isp, unsigned mA)
144 */ 127 */
145} 128}
146 129
130#endif
131
147static void enable_vbus_source(struct isp1301 *isp) 132static void enable_vbus_source(struct isp1301 *isp)
148{ 133{
149 /* this board won't supply more than 8mA vbus power. 134 /* this board won't supply more than 8mA vbus power.
@@ -159,8 +144,6 @@ static inline void notresponding(struct isp1301 *isp)
159} 144}
160 145
161 146
162#endif
163
164/*-------------------------------------------------------------------------*/ 147/*-------------------------------------------------------------------------*/
165 148
166static struct i2c_driver isp1301_driver; 149static struct i2c_driver isp1301_driver;
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 5d25d3e52bf6..131e61adaaf7 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -31,10 +31,20 @@ static int debug;
31 31
32static struct usb_device_id id_table [] = { 32static struct usb_device_id id_table [] = {
33 { USB_DEVICE(0x6547, 0x0232) }, 33 { USB_DEVICE(0x6547, 0x0232) },
34 { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */
34 { }, 35 { },
35}; 36};
36MODULE_DEVICE_TABLE(usb, id_table); 37MODULE_DEVICE_TABLE(usb, id_table);
37 38
39static int is_irda(struct usb_serial *serial)
40{
41 struct usb_device *dev = serial->dev;
42 if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec &&
43 le16_to_cpu(dev->descriptor.idProduct) == 0x3118)
44 return 1;
45 return 0;
46}
47
38static inline void ARK3116_SND(struct usb_serial *serial, int seq, 48static inline void ARK3116_SND(struct usb_serial *serial, int seq,
39 __u8 request, __u8 requesttype, 49 __u8 request, __u8 requesttype,
40 __u16 value, __u16 index) 50 __u16 value, __u16 index)
@@ -84,11 +94,21 @@ static int ark3116_attach(struct usb_serial *serial)
84 return -ENOMEM; 94 return -ENOMEM;
85 } 95 }
86 96
97 if (is_irda(serial))
98 dbg("IrDA mode");
99
87 /* 3 */ 100 /* 3 */
88 ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002); 101 ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
89 ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001); 102 ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
90 ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008); 103 ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
91 ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B); 104 ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000,
105 0x000B);
106
107 if (is_irda(serial)) {
108 ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C);
109 ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D);
110 ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A);
111 }
92 112
93 /* <-- seq7 */ 113 /* <-- seq7 */
94 ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); 114 ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
@@ -125,6 +145,8 @@ static int ark3116_attach(struct usb_serial *serial)
125 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003); 145 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
126 ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000); 146 ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
127 ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001); 147 ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
148 if (is_irda(serial))
149 ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
128 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003); 150 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
129 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf); 151 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
130 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003); 152 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 8c894a7d5dcf..59eff721fcc5 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -56,6 +56,18 @@
56#define CH341_BAUDBASE_FACTOR 1532620800 56#define CH341_BAUDBASE_FACTOR 1532620800
57#define CH341_BAUDBASE_DIVMAX 3 57#define CH341_BAUDBASE_DIVMAX 3
58 58
59/* Break support - the information used to implement this was gleaned from
60 * the Net/FreeBSD uchcom.c driver by Takanori Watanabe. Domo arigato.
61 */
62
63#define CH341_REQ_WRITE_REG 0x9A
64#define CH341_REQ_READ_REG 0x95
65#define CH341_REG_BREAK1 0x05
66#define CH341_REG_BREAK2 0x18
67#define CH341_NBREAK_BITS_REG1 0x01
68#define CH341_NBREAK_BITS_REG2 0x40
69
70
59static int debug; 71static int debug;
60 72
61static struct usb_device_id id_table [] = { 73static struct usb_device_id id_table [] = {
@@ -373,6 +385,45 @@ static void ch341_set_termios(struct tty_struct *tty,
373 */ 385 */
374} 386}
375 387
388static void ch341_break_ctl(struct tty_struct *tty, int break_state)
389{
390 const uint16_t ch341_break_reg =
391 CH341_REG_BREAK1 | ((uint16_t) CH341_REG_BREAK2 << 8);
392 struct usb_serial_port *port = tty->driver_data;
393 int r;
394 uint16_t reg_contents;
395 uint8_t break_reg[2];
396
397 dbg("%s()", __func__);
398
399 r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
400 ch341_break_reg, 0, break_reg, sizeof(break_reg));
401 if (r < 0) {
402 printk(KERN_WARNING "%s: USB control read error whilst getting"
403 " break register contents.\n", __FILE__);
404 return;
405 }
406 dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x",
407 __func__, break_reg[0], break_reg[1]);
408 if (break_state != 0) {
409 dbg("%s - Enter break state requested", __func__);
410 break_reg[0] &= ~CH341_NBREAK_BITS_REG1;
411 break_reg[1] &= ~CH341_NBREAK_BITS_REG2;
412 } else {
413 dbg("%s - Leave break state requested", __func__);
414 break_reg[0] |= CH341_NBREAK_BITS_REG1;
415 break_reg[1] |= CH341_NBREAK_BITS_REG2;
416 }
417 dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x",
418 __func__, break_reg[0], break_reg[1]);
419 reg_contents = (uint16_t)break_reg[0] | ((uint16_t)break_reg[1] << 8);
420 r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG,
421 ch341_break_reg, reg_contents);
422 if (r < 0)
423 printk(KERN_WARNING "%s: USB control write error whilst setting"
424 " break register contents.\n", __FILE__);
425}
426
376static int ch341_tiocmset(struct tty_struct *tty, struct file *file, 427static int ch341_tiocmset(struct tty_struct *tty, struct file *file,
377 unsigned int set, unsigned int clear) 428 unsigned int set, unsigned int clear)
378{ 429{
@@ -576,6 +627,7 @@ static struct usb_serial_driver ch341_device = {
576 .close = ch341_close, 627 .close = ch341_close,
577 .ioctl = ch341_ioctl, 628 .ioctl = ch341_ioctl,
578 .set_termios = ch341_set_termios, 629 .set_termios = ch341_set_termios,
630 .break_ctl = ch341_break_ctl,
579 .tiocmget = ch341_tiocmget, 631 .tiocmget = ch341_tiocmget,
580 .tiocmset = ch341_tiocmset, 632 .tiocmset = ch341_tiocmset,
581 .read_int_callback = ch341_read_int_callback, 633 .read_int_callback = ch341_read_int_callback,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 76a17f915eef..4f883b1773d0 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -176,6 +176,9 @@ static struct usb_device_id id_table_combined [] = {
176 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) }, 176 { USB_DEVICE(FTDI_VID, FTDI_MICRO_CHAMELEON_PID) },
177 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) }, 177 { USB_DEVICE(FTDI_VID, FTDI_RELAIS_PID) },
178 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) }, 178 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_PID) },
179 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_SNIFFER_PID) },
180 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) },
181 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) },
179 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 182 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
180 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 183 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
181 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) }, 184 { USB_DEVICE(FTDI_VID, FTDI_SPROG_II) },
@@ -694,6 +697,8 @@ static struct usb_device_id id_table_combined [] = {
694 { USB_DEVICE(DE_VID, WHT_PID) }, 697 { USB_DEVICE(DE_VID, WHT_PID) },
695 { USB_DEVICE(ADI_VID, ADI_GNICE_PID), 698 { USB_DEVICE(ADI_VID, ADI_GNICE_PID),
696 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 699 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
700 { USB_DEVICE(ADI_VID, ADI_GNICEPLUS_PID),
701 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
697 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, 702 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) },
698 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), 703 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID),
699 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 704 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
@@ -702,6 +707,8 @@ static struct usb_device_id id_table_combined [] = {
702 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) }, 707 { USB_DEVICE(BAYER_VID, BAYER_CONTOUR_CABLE_PID) },
703 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), 708 { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID),
704 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 709 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
710 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) },
711 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) },
705 { }, /* Optional parameter entry */ 712 { }, /* Optional parameter entry */
706 { } /* Terminating entry */ 713 { } /* Terminating entry */
707}; 714};
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 8c92b88166ae..6f31e0d71898 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -81,6 +81,9 @@
81 81
82/* OpenDCC (www.opendcc.de) product id */ 82/* OpenDCC (www.opendcc.de) product id */
83#define FTDI_OPENDCC_PID 0xBFD8 83#define FTDI_OPENDCC_PID 0xBFD8
84#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9
85#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
86#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
84 87
85/* Sprog II (Andrew Crosland's SprogII DCC interface) */ 88/* Sprog II (Andrew Crosland's SprogII DCC interface) */
86#define FTDI_SPROG_II 0xF0C8 89#define FTDI_SPROG_II 0xF0C8
@@ -930,6 +933,7 @@
930 */ 933 */
931#define ADI_VID 0x0456 934#define ADI_VID 0x0456
932#define ADI_GNICE_PID 0xF000 935#define ADI_GNICE_PID 0xF000
936#define ADI_GNICEPLUS_PID 0xF001
933 937
934/* 938/*
935 * JETI SPECTROMETER SPECBOS 1201 939 * JETI SPECTROMETER SPECBOS 1201
@@ -968,6 +972,12 @@
968#define MARVELL_OPENRD_PID 0x9e90 972#define MARVELL_OPENRD_PID 0x9e90
969 973
970/* 974/*
975 * Hameg HO820 and HO870 interface (using VID 0x0403)
976 */
977#define HAMEG_HO820_PID 0xed74
978#define HAMEG_HO870_PID 0xed71
979
980/*
971 * BmRequestType: 1100 0000b 981 * BmRequestType: 1100 0000b
972 * bRequest: FTDI_E2_READ 982 * bRequest: FTDI_E2_READ
973 * wValue: 0 983 * wValue: 0
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index d9398e9f30ce..deba08c7a015 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -19,7 +19,7 @@
19#include <linux/usb.h> 19#include <linux/usb.h>
20#include <linux/usb/serial.h> 20#include <linux/usb/serial.h>
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22 22#include <linux/kfifo.h>
23 23
24static int debug; 24static int debug;
25 25
@@ -166,24 +166,6 @@ static void generic_cleanup(struct usb_serial_port *port)
166 } 166 }
167} 167}
168 168
169int usb_serial_generic_resume(struct usb_serial *serial)
170{
171 struct usb_serial_port *port;
172 int i, c = 0, r;
173
174 for (i = 0; i < serial->num_ports; i++) {
175 port = serial->port[i];
176 if (port->port.count && port->read_urb) {
177 r = usb_submit_urb(port->read_urb, GFP_NOIO);
178 if (r < 0)
179 c++;
180 }
181 }
182
183 return c ? -EIO : 0;
184}
185EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
186
187void usb_serial_generic_close(struct usb_serial_port *port) 169void usb_serial_generic_close(struct usb_serial_port *port)
188{ 170{
189 dbg("%s - port %d", __func__, port->number); 171 dbg("%s - port %d", __func__, port->number);
@@ -272,12 +254,81 @@ error_no_buffer:
272 return bwrite; 254 return bwrite;
273} 255}
274 256
257/**
258 * usb_serial_generic_write_start - kick off an URB write
259 * @port: Pointer to the &struct usb_serial_port data
260 *
261 * Returns the number of bytes queued on success. This will be zero if there
262 * was nothing to send. Otherwise, it returns a negative errno value
263 */
264static int usb_serial_generic_write_start(struct usb_serial_port *port)
265{
266 struct usb_serial *serial = port->serial;
267 unsigned char *data;
268 int result;
269 int count;
270 unsigned long flags;
271 bool start_io;
272
273 /* Atomically determine whether we can and need to start a USB
274 * operation. */
275 spin_lock_irqsave(&port->lock, flags);
276 if (port->write_urb_busy)
277 start_io = false;
278 else {
279 start_io = (__kfifo_len(port->write_fifo) != 0);
280 port->write_urb_busy = start_io;
281 }
282 spin_unlock_irqrestore(&port->lock, flags);
283
284 if (!start_io)
285 return 0;
286
287 data = port->write_urb->transfer_buffer;
288 count = kfifo_get(port->write_fifo, data, port->bulk_out_size);
289 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
290
291 /* set up our urb */
292 usb_fill_bulk_urb(port->write_urb, serial->dev,
293 usb_sndbulkpipe(serial->dev,
294 port->bulk_out_endpointAddress),
295 port->write_urb->transfer_buffer, count,
296 ((serial->type->write_bulk_callback) ?
297 serial->type->write_bulk_callback :
298 usb_serial_generic_write_bulk_callback),
299 port);
300
301 /* send the data out the bulk port */
302 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
303 if (result) {
304 dev_err(&port->dev,
305 "%s - failed submitting write urb, error %d\n",
306 __func__, result);
307 /* don't have to grab the lock here, as we will
308 retry if != 0 */
309 port->write_urb_busy = 0;
310 } else
311 result = count;
312
313 return result;
314}
315
316/**
317 * usb_serial_generic_write - generic write function for serial USB devices
318 * @tty: Pointer to &struct tty_struct for the device
319 * @port: Pointer to the &usb_serial_port structure for the device
320 * @buf: Pointer to the data to write
321 * @count: Number of bytes to write
322 *
323 * Returns the number of characters actually written, which may be anything
324 * from zero to @count. If an error occurs, it returns the negative errno
325 * value.
326 */
275int usb_serial_generic_write(struct tty_struct *tty, 327int usb_serial_generic_write(struct tty_struct *tty,
276 struct usb_serial_port *port, const unsigned char *buf, int count) 328 struct usb_serial_port *port, const unsigned char *buf, int count)
277{ 329{
278 struct usb_serial *serial = port->serial; 330 struct usb_serial *serial = port->serial;
279 int result; 331 int result;
280 unsigned char *data;
281 332
282 dbg("%s - port %d", __func__, port->number); 333 dbg("%s - port %d", __func__, port->number);
283 334
@@ -287,57 +338,20 @@ int usb_serial_generic_write(struct tty_struct *tty,
287 } 338 }
288 339
289 /* only do something if we have a bulk out endpoint */ 340 /* only do something if we have a bulk out endpoint */
290 if (serial->num_bulk_out) { 341 if (!serial->num_bulk_out)
291 unsigned long flags; 342 return 0;
292
293 if (serial->type->max_in_flight_urbs)
294 return usb_serial_multi_urb_write(tty, port,
295 buf, count);
296
297 spin_lock_irqsave(&port->lock, flags);
298 if (port->write_urb_busy) {
299 spin_unlock_irqrestore(&port->lock, flags);
300 dbg("%s - already writing", __func__);
301 return 0;
302 }
303 port->write_urb_busy = 1;
304 spin_unlock_irqrestore(&port->lock, flags);
305
306 count = (count > port->bulk_out_size) ?
307 port->bulk_out_size : count;
308
309 memcpy(port->write_urb->transfer_buffer, buf, count);
310 data = port->write_urb->transfer_buffer;
311 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
312 343
313 /* set up our urb */ 344 if (serial->type->max_in_flight_urbs)
314 usb_fill_bulk_urb(port->write_urb, serial->dev, 345 return usb_serial_multi_urb_write(tty, port,
315 usb_sndbulkpipe(serial->dev, 346 buf, count);
316 port->bulk_out_endpointAddress),
317 port->write_urb->transfer_buffer, count,
318 ((serial->type->write_bulk_callback) ?
319 serial->type->write_bulk_callback :
320 usb_serial_generic_write_bulk_callback),
321 port);
322 347
323 /* send the data out the bulk port */ 348 count = kfifo_put(port->write_fifo, buf, count);
324 port->write_urb_busy = 1; 349 result = usb_serial_generic_write_start(port);
325 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
326 if (result) {
327 dev_err(&port->dev,
328 "%s - failed submitting write urb, error %d\n",
329 __func__, result);
330 /* don't have to grab the lock here, as we will
331 retry if != 0 */
332 port->write_urb_busy = 0;
333 } else
334 result = count;
335 350
336 return result; 351 if (result >= 0)
337 } 352 result = count;
338 353
339 /* no bulk out, so return 0 bytes written */ 354 return result;
340 return 0;
341} 355}
342EXPORT_SYMBOL_GPL(usb_serial_generic_write); 356EXPORT_SYMBOL_GPL(usb_serial_generic_write);
343 357
@@ -355,9 +369,8 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
355 room = port->bulk_out_size * 369 room = port->bulk_out_size *
356 (serial->type->max_in_flight_urbs - 370 (serial->type->max_in_flight_urbs -
357 port->urbs_in_flight); 371 port->urbs_in_flight);
358 } else if (serial->num_bulk_out && !(port->write_urb_busy)) { 372 } else if (serial->num_bulk_out)
359 room = port->bulk_out_size; 373 room = port->write_fifo->size - __kfifo_len(port->write_fifo);
360 }
361 spin_unlock_irqrestore(&port->lock, flags); 374 spin_unlock_irqrestore(&port->lock, flags);
362 375
363 dbg("%s - returns %d", __func__, room); 376 dbg("%s - returns %d", __func__, room);
@@ -377,11 +390,8 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
377 spin_lock_irqsave(&port->lock, flags); 390 spin_lock_irqsave(&port->lock, flags);
378 chars = port->tx_bytes_flight; 391 chars = port->tx_bytes_flight;
379 spin_unlock_irqrestore(&port->lock, flags); 392 spin_unlock_irqrestore(&port->lock, flags);
380 } else if (serial->num_bulk_out) { 393 } else if (serial->num_bulk_out)
381 /* FIXME: Locking */ 394 chars = kfifo_len(port->write_fifo);
382 if (port->write_urb_busy)
383 chars = port->write_urb->transfer_buffer_length;
384 }
385 395
386 dbg("%s - returns %d", __func__, chars); 396 dbg("%s - returns %d", __func__, chars);
387 return chars; 397 return chars;
@@ -485,16 +495,23 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
485 if (port->urbs_in_flight < 0) 495 if (port->urbs_in_flight < 0)
486 port->urbs_in_flight = 0; 496 port->urbs_in_flight = 0;
487 spin_unlock_irqrestore(&port->lock, flags); 497 spin_unlock_irqrestore(&port->lock, flags);
498
499 if (status) {
500 dbg("%s - nonzero multi-urb write bulk status "
501 "received: %d", __func__, status);
502 return;
503 }
488 } else { 504 } else {
489 /* Handle the case for single urb mode */
490 port->write_urb_busy = 0; 505 port->write_urb_busy = 0;
491 }
492 506
493 if (status) { 507 if (status) {
494 dbg("%s - nonzero write bulk status received: %d", 508 dbg("%s - nonzero multi-urb write bulk status "
495 __func__, status); 509 "received: %d", __func__, status);
496 return; 510 kfifo_reset(port->write_fifo);
511 } else
512 usb_serial_generic_write_start(port);
497 } 513 }
514
498 usb_serial_port_softint(port); 515 usb_serial_port_softint(port);
499} 516}
500EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 517EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
@@ -559,6 +576,33 @@ int usb_serial_handle_break(struct usb_serial_port *port)
559} 576}
560EXPORT_SYMBOL_GPL(usb_serial_handle_break); 577EXPORT_SYMBOL_GPL(usb_serial_handle_break);
561 578
579int usb_serial_generic_resume(struct usb_serial *serial)
580{
581 struct usb_serial_port *port;
582 int i, c = 0, r;
583
584 for (i = 0; i < serial->num_ports; i++) {
585 port = serial->port[i];
586 if (!port->port.count)
587 continue;
588
589 if (port->read_urb) {
590 r = usb_submit_urb(port->read_urb, GFP_NOIO);
591 if (r < 0)
592 c++;
593 }
594
595 if (port->write_urb) {
596 r = usb_serial_generic_write_start(port);
597 if (r < 0)
598 c++;
599 }
600 }
601
602 return c ? -EIO : 0;
603}
604EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
605
562void usb_serial_generic_disconnect(struct usb_serial *serial) 606void usb_serial_generic_disconnect(struct usb_serial *serial)
563{ 607{
564 int i; 608 int i;
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 6138c1cda35f..e6e02b178d2b 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -40,7 +40,7 @@ static int debug;
40/* 40/*
41 * Version Information 41 * Version Information
42 */ 42 */
43#define DRIVER_VERSION "v0.10" 43#define DRIVER_VERSION "v0.11"
44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" 44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
45 45
46static struct usb_device_id id_table[] = { 46static struct usb_device_id id_table[] = {
@@ -64,6 +64,7 @@ static int cdmode = 1;
64static int iuu_cardin; 64static int iuu_cardin;
65static int iuu_cardout; 65static int iuu_cardout;
66static int xmas; 66static int xmas;
67static int vcc_default = 5;
67 68
68static void read_rxcmd_callback(struct urb *urb); 69static void read_rxcmd_callback(struct urb *urb);
69 70
@@ -79,6 +80,7 @@ struct iuu_private {
79 u8 *buf; /* used for initialize speed */ 80 u8 *buf; /* used for initialize speed */
80 u8 *dbgbuf; /* debug buffer */ 81 u8 *dbgbuf; /* debug buffer */
81 u8 len; 82 u8 len;
83 int vcc; /* vcc (either 3 or 5 V) */
82}; 84};
83 85
84 86
@@ -114,6 +116,7 @@ static int iuu_startup(struct usb_serial *serial)
114 kfree(priv); 116 kfree(priv);
115 return -ENOMEM; 117 return -ENOMEM;
116 } 118 }
119 priv->vcc = vcc_default;
117 spin_lock_init(&priv->lock); 120 spin_lock_init(&priv->lock);
118 init_waitqueue_head(&priv->delta_msr_wait); 121 init_waitqueue_head(&priv->delta_msr_wait);
119 usb_set_serial_port_data(serial->port[0], priv); 122 usb_set_serial_port_data(serial->port[0], priv);
@@ -1009,11 +1012,7 @@ static void iuu_close(struct usb_serial_port *port)
1009 usb_kill_urb(port->write_urb); 1012 usb_kill_urb(port->write_urb);
1010 usb_kill_urb(port->read_urb); 1013 usb_kill_urb(port->read_urb);
1011 usb_kill_urb(port->interrupt_in_urb); 1014 usb_kill_urb(port->interrupt_in_urb);
1012 msleep(1000);
1013 /* wait one second to free all buffers */
1014 iuu_led(port, 0, 0, 0xF000, 0xFF); 1015 iuu_led(port, 0, 0, 0xF000, 0xFF);
1015 msleep(1000);
1016 usb_reset_device(port->serial->dev);
1017 } 1016 }
1018} 1017}
1019 1018
@@ -1182,6 +1181,95 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
1182 return result; 1181 return result;
1183} 1182}
1184 1183
1184/* how to change VCC */
1185static int iuu_vcc_set(struct usb_serial_port *port, unsigned int vcc)
1186{
1187 int status;
1188 u8 *buf;
1189
1190 buf = kmalloc(5, GFP_KERNEL);
1191 if (!buf)
1192 return -ENOMEM;
1193
1194 dbg("%s - enter", __func__);
1195
1196 buf[0] = IUU_SET_VCC;
1197 buf[1] = vcc & 0xFF;
1198 buf[2] = (vcc >> 8) & 0xFF;
1199 buf[3] = (vcc >> 16) & 0xFF;
1200 buf[4] = (vcc >> 24) & 0xFF;
1201
1202 status = bulk_immediate(port, buf, 5);
1203 kfree(buf);
1204
1205 if (status != IUU_OPERATION_OK)
1206 dbg("%s - vcc error status = %2x", __func__, status);
1207 else
1208 dbg("%s - vcc OK !", __func__);
1209
1210 return status;
1211}
1212
1213/*
1214 * Sysfs Attributes
1215 */
1216
1217static ssize_t show_vcc_mode(struct device *dev,
1218 struct device_attribute *attr, char *buf)
1219{
1220 struct usb_serial_port *port = to_usb_serial_port(dev);
1221 struct iuu_private *priv = usb_get_serial_port_data(port);
1222
1223 return sprintf(buf, "%d\n", priv->vcc);
1224}
1225
1226static ssize_t store_vcc_mode(struct device *dev,
1227 struct device_attribute *attr, const char *buf, size_t count)
1228{
1229 struct usb_serial_port *port = to_usb_serial_port(dev);
1230 struct iuu_private *priv = usb_get_serial_port_data(port);
1231 unsigned long v;
1232
1233 if (strict_strtoul(buf, 10, &v)) {
1234 dev_err(dev, "%s - vcc_mode: %s is not a unsigned long\n",
1235 __func__, buf);
1236 goto fail_store_vcc_mode;
1237 }
1238
1239 dbg("%s: setting vcc_mode = %ld", __func__, v);
1240
1241 if ((v != 3) && (v != 5)) {
1242 dev_err(dev, "%s - vcc_mode %ld is invalid\n", __func__, v);
1243 } else {
1244 iuu_vcc_set(port, v);
1245 priv->vcc = v;
1246 }
1247fail_store_vcc_mode:
1248 return count;
1249}
1250
1251static DEVICE_ATTR(vcc_mode, S_IRUSR | S_IWUSR, show_vcc_mode,
1252 store_vcc_mode);
1253
1254static int iuu_create_sysfs_attrs(struct usb_serial_port *port)
1255{
1256 dbg("%s", __func__);
1257
1258 return device_create_file(&port->dev, &dev_attr_vcc_mode);
1259}
1260
1261static int iuu_remove_sysfs_attrs(struct usb_serial_port *port)
1262{
1263 dbg("%s", __func__);
1264
1265 device_remove_file(&port->dev, &dev_attr_vcc_mode);
1266 return 0;
1267}
1268
1269/*
1270 * End Sysfs Attributes
1271 */
1272
1185static struct usb_serial_driver iuu_device = { 1273static struct usb_serial_driver iuu_device = {
1186 .driver = { 1274 .driver = {
1187 .owner = THIS_MODULE, 1275 .owner = THIS_MODULE,
@@ -1189,6 +1277,8 @@ static struct usb_serial_driver iuu_device = {
1189 }, 1277 },
1190 .id_table = id_table, 1278 .id_table = id_table,
1191 .num_ports = 1, 1279 .num_ports = 1,
1280 .port_probe = iuu_create_sysfs_attrs,
1281 .port_remove = iuu_remove_sysfs_attrs,
1192 .open = iuu_open, 1282 .open = iuu_open,
1193 .close = iuu_close, 1283 .close = iuu_close,
1194 .write = iuu_uart_write, 1284 .write = iuu_uart_write,
@@ -1238,14 +1328,19 @@ module_param(debug, bool, S_IRUGO | S_IWUSR);
1238MODULE_PARM_DESC(debug, "Debug enabled or not"); 1328MODULE_PARM_DESC(debug, "Debug enabled or not");
1239 1329
1240module_param(xmas, bool, S_IRUGO | S_IWUSR); 1330module_param(xmas, bool, S_IRUGO | S_IWUSR);
1241MODULE_PARM_DESC(xmas, "xmas color enabled or not"); 1331MODULE_PARM_DESC(xmas, "Xmas colors enabled or not");
1242 1332
1243module_param(boost, int, S_IRUGO | S_IWUSR); 1333module_param(boost, int, S_IRUGO | S_IWUSR);
1244MODULE_PARM_DESC(boost, "overclock boost percent 100 to 500"); 1334MODULE_PARM_DESC(boost, "Card overclock boost (in percent 100-500)");
1245 1335
1246module_param(clockmode, int, S_IRUGO | S_IWUSR); 1336module_param(clockmode, int, S_IRUGO | S_IWUSR);
1247MODULE_PARM_DESC(clockmode, "1=3Mhz579,2=3Mhz680,3=6Mhz"); 1337MODULE_PARM_DESC(clockmode, "Card clock mode (1=3.579 MHz, 2=3.680 MHz, "
1338 "3=6 Mhz)");
1248 1339
1249module_param(cdmode, int, S_IRUGO | S_IWUSR); 1340module_param(cdmode, int, S_IRUGO | S_IWUSR);
1250MODULE_PARM_DESC(cdmode, "Card detect mode 0=none, 1=CD, 2=!CD, 3=DSR, " 1341MODULE_PARM_DESC(cdmode, "Card detect mode (0=none, 1=CD, 2=!CD, 3=DSR, "
1251 "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING"); 1342 "4=!DSR, 5=CTS, 6=!CTS, 7=RING, 8=!RING)");
1343
1344module_param(vcc_default, int, S_IRUGO | S_IWUSR);
1345MODULE_PARM_DESC(vcc_default, "Set default VCC (either 3 for 3.3V or 5 "
1346 "for 5V). Default to 5.");
diff --git a/drivers/usb/serial/moto_modem.c b/drivers/usb/serial/moto_modem.c
index b66b71ccd12b..99bd00f5188a 100644
--- a/drivers/usb/serial/moto_modem.c
+++ b/drivers/usb/serial/moto_modem.c
@@ -8,7 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * 9 *
10 * {sigh} 10 * {sigh}
11 * Mororola should be using the CDC ACM USB spec, but instead 11 * Motorola should be using the CDC ACM USB spec, but instead
12 * they try to just "do their own thing"... This driver should handle a 12 * they try to just "do their own thing"... This driver should handle a
13 * few phones in which a basic "dumb serial connection" is needed to be 13 * few phones in which a basic "dumb serial connection" is needed to be
14 * able to get a connection through to them. 14 * able to get a connection through to them.
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index fe47051dbef2..f66e39883218 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -291,6 +291,7 @@ static int option_resume(struct usb_serial *serial);
291 291
292#define TELIT_VENDOR_ID 0x1bc7 292#define TELIT_VENDOR_ID 0x1bc7
293#define TELIT_PRODUCT_UC864E 0x1003 293#define TELIT_PRODUCT_UC864E 0x1003
294#define TELIT_PRODUCT_UC864G 0x1004
294 295
295/* ZTE PRODUCTS */ 296/* ZTE PRODUCTS */
296#define ZTE_VENDOR_ID 0x19d2 297#define ZTE_VENDOR_ID 0x19d2
@@ -299,6 +300,7 @@ static int option_resume(struct usb_serial *serial);
299#define ZTE_PRODUCT_MF626 0x0031 300#define ZTE_PRODUCT_MF626 0x0031
300#define ZTE_PRODUCT_CDMA_TECH 0xfffe 301#define ZTE_PRODUCT_CDMA_TECH 0xfffe
301#define ZTE_PRODUCT_AC8710 0xfff1 302#define ZTE_PRODUCT_AC8710 0xfff1
303#define ZTE_PRODUCT_AC2726 0xfff5
302 304
303#define BENQ_VENDOR_ID 0x04a5 305#define BENQ_VENDOR_ID 0x04a5
304#define BENQ_PRODUCT_H10 0x4068 306#define BENQ_PRODUCT_H10 0x4068
@@ -502,6 +504,7 @@ static struct usb_device_id option_ids[] = {
502 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 504 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
503 { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */ 505 { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */
504 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, 506 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
507 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) },
505 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ 508 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */
506 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) }, 509 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0002, 0xff, 0xff, 0xff) },
507 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) }, 510 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0003, 0xff, 0xff, 0xff) },
@@ -571,6 +574,7 @@ static struct usb_device_id option_ids[] = {
571 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, 574 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
572 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, 575 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
573 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 576 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
577 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
574 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 578 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
575 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 579 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
576 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) }, 580 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) },
@@ -592,6 +596,7 @@ static struct usb_driver option_driver = {
592#ifdef CONFIG_PM 596#ifdef CONFIG_PM
593 .suspend = usb_serial_suspend, 597 .suspend = usb_serial_suspend,
594 .resume = usb_serial_resume, 598 .resume = usb_serial_resume,
599 .supports_autosuspend = 1,
595#endif 600#endif
596 .id_table = option_ids, 601 .id_table = option_ids,
597 .no_dynamic_id = 1, 602 .no_dynamic_id = 1,
@@ -639,6 +644,12 @@ static int debug;
639#define IN_BUFLEN 4096 644#define IN_BUFLEN 4096
640#define OUT_BUFLEN 4096 645#define OUT_BUFLEN 4096
641 646
647struct option_intf_private {
648 spinlock_t susp_lock;
649 unsigned int suspended:1;
650 int in_flight;
651};
652
642struct option_port_private { 653struct option_port_private {
643 /* Input endpoints and buffer for this port */ 654 /* Input endpoints and buffer for this port */
644 struct urb *in_urbs[N_IN_URB]; 655 struct urb *in_urbs[N_IN_URB];
@@ -647,6 +658,8 @@ struct option_port_private {
647 struct urb *out_urbs[N_OUT_URB]; 658 struct urb *out_urbs[N_OUT_URB];
648 u8 *out_buffer[N_OUT_URB]; 659 u8 *out_buffer[N_OUT_URB];
649 unsigned long out_busy; /* Bit vector of URBs in use */ 660 unsigned long out_busy; /* Bit vector of URBs in use */
661 int opened;
662 struct usb_anchor delayed;
650 663
651 /* Settings for the port */ 664 /* Settings for the port */
652 int rts_state; /* Handshaking pins (outputs) */ 665 int rts_state; /* Handshaking pins (outputs) */
@@ -693,12 +706,17 @@ module_exit(option_exit);
693static int option_probe(struct usb_serial *serial, 706static int option_probe(struct usb_serial *serial,
694 const struct usb_device_id *id) 707 const struct usb_device_id *id)
695{ 708{
709 struct option_intf_private *data;
696 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ 710 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */
697 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && 711 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID &&
698 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && 712 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 &&
699 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) 713 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8)
700 return -ENODEV; 714 return -ENODEV;
701 715
716 data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL);
717 if (!data)
718 return -ENOMEM;
719 spin_lock_init(&data->susp_lock);
702 return 0; 720 return 0;
703} 721}
704 722
@@ -755,12 +773,15 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
755 const unsigned char *buf, int count) 773 const unsigned char *buf, int count)
756{ 774{
757 struct option_port_private *portdata; 775 struct option_port_private *portdata;
776 struct option_intf_private *intfdata;
758 int i; 777 int i;
759 int left, todo; 778 int left, todo;
760 struct urb *this_urb = NULL; /* spurious */ 779 struct urb *this_urb = NULL; /* spurious */
761 int err; 780 int err;
781 unsigned long flags;
762 782
763 portdata = usb_get_serial_port_data(port); 783 portdata = usb_get_serial_port_data(port);
784 intfdata = port->serial->private;
764 785
765 dbg("%s: write (%d chars)", __func__, count); 786 dbg("%s: write (%d chars)", __func__, count);
766 787
@@ -782,17 +803,33 @@ static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
782 dbg("%s: endpoint %d buf %d", __func__, 803 dbg("%s: endpoint %d buf %d", __func__,
783 usb_pipeendpoint(this_urb->pipe), i); 804 usb_pipeendpoint(this_urb->pipe), i);
784 805
806 err = usb_autopm_get_interface_async(port->serial->interface);
807 if (err < 0)
808 break;
809
785 /* send the data */ 810 /* send the data */
786 memcpy(this_urb->transfer_buffer, buf, todo); 811 memcpy(this_urb->transfer_buffer, buf, todo);
787 this_urb->transfer_buffer_length = todo; 812 this_urb->transfer_buffer_length = todo;
788 813
789 err = usb_submit_urb(this_urb, GFP_ATOMIC); 814 spin_lock_irqsave(&intfdata->susp_lock, flags);
790 if (err) { 815 if (intfdata->suspended) {
791 dbg("usb_submit_urb %p (write bulk) failed " 816 usb_anchor_urb(this_urb, &portdata->delayed);
792 "(%d)", this_urb, err); 817 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
793 clear_bit(i, &portdata->out_busy); 818 } else {
794 continue; 819 intfdata->in_flight++;
820 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
821 err = usb_submit_urb(this_urb, GFP_ATOMIC);
822 if (err) {
823 dbg("usb_submit_urb %p (write bulk) failed "
824 "(%d)", this_urb, err);
825 clear_bit(i, &portdata->out_busy);
826 spin_lock_irqsave(&intfdata->susp_lock, flags);
827 intfdata->in_flight--;
828 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
829 continue;
830 }
795 } 831 }
832
796 portdata->tx_start_time[i] = jiffies; 833 portdata->tx_start_time[i] = jiffies;
797 buf += todo; 834 buf += todo;
798 left -= todo; 835 left -= todo;
@@ -836,7 +873,10 @@ static void option_indat_callback(struct urb *urb)
836 if (err) 873 if (err)
837 printk(KERN_ERR "%s: resubmit read urb failed. " 874 printk(KERN_ERR "%s: resubmit read urb failed. "
838 "(%d)", __func__, err); 875 "(%d)", __func__, err);
876 else
877 usb_mark_last_busy(port->serial->dev);
839 } 878 }
879
840 } 880 }
841 return; 881 return;
842} 882}
@@ -845,15 +885,21 @@ static void option_outdat_callback(struct urb *urb)
845{ 885{
846 struct usb_serial_port *port; 886 struct usb_serial_port *port;
847 struct option_port_private *portdata; 887 struct option_port_private *portdata;
888 struct option_intf_private *intfdata;
848 int i; 889 int i;
849 890
850 dbg("%s", __func__); 891 dbg("%s", __func__);
851 892
852 port = urb->context; 893 port = urb->context;
894 intfdata = port->serial->private;
853 895
854 usb_serial_port_softint(port); 896 usb_serial_port_softint(port);
855 897 usb_autopm_put_interface_async(port->serial->interface);
856 portdata = usb_get_serial_port_data(port); 898 portdata = usb_get_serial_port_data(port);
899 spin_lock(&intfdata->susp_lock);
900 intfdata->in_flight--;
901 spin_unlock(&intfdata->susp_lock);
902
857 for (i = 0; i < N_OUT_URB; ++i) { 903 for (i = 0; i < N_OUT_URB; ++i) {
858 if (portdata->out_urbs[i] == urb) { 904 if (portdata->out_urbs[i] == urb) {
859 smp_mb__before_clear_bit(); 905 smp_mb__before_clear_bit();
@@ -963,10 +1009,13 @@ static int option_chars_in_buffer(struct tty_struct *tty)
963static int option_open(struct tty_struct *tty, struct usb_serial_port *port) 1009static int option_open(struct tty_struct *tty, struct usb_serial_port *port)
964{ 1010{
965 struct option_port_private *portdata; 1011 struct option_port_private *portdata;
1012 struct option_intf_private *intfdata;
1013 struct usb_serial *serial = port->serial;
966 int i, err; 1014 int i, err;
967 struct urb *urb; 1015 struct urb *urb;
968 1016
969 portdata = usb_get_serial_port_data(port); 1017 portdata = usb_get_serial_port_data(port);
1018 intfdata = serial->private;
970 1019
971 dbg("%s", __func__); 1020 dbg("%s", __func__);
972 1021
@@ -985,6 +1034,12 @@ static int option_open(struct tty_struct *tty, struct usb_serial_port *port)
985 1034
986 option_send_setup(port); 1035 option_send_setup(port);
987 1036
1037 serial->interface->needs_remote_wakeup = 1;
1038 spin_lock_irq(&intfdata->susp_lock);
1039 portdata->opened = 1;
1040 spin_unlock_irq(&intfdata->susp_lock);
1041 usb_autopm_put_interface(serial->interface);
1042
988 return 0; 1043 return 0;
989} 1044}
990 1045
@@ -1009,16 +1064,23 @@ static void option_close(struct usb_serial_port *port)
1009 int i; 1064 int i;
1010 struct usb_serial *serial = port->serial; 1065 struct usb_serial *serial = port->serial;
1011 struct option_port_private *portdata; 1066 struct option_port_private *portdata;
1067 struct option_intf_private *intfdata = port->serial->private;
1012 1068
1013 dbg("%s", __func__); 1069 dbg("%s", __func__);
1014 portdata = usb_get_serial_port_data(port); 1070 portdata = usb_get_serial_port_data(port);
1015 1071
1016 if (serial->dev) { 1072 if (serial->dev) {
1017 /* Stop reading/writing urbs */ 1073 /* Stop reading/writing urbs */
1074 spin_lock_irq(&intfdata->susp_lock);
1075 portdata->opened = 0;
1076 spin_unlock_irq(&intfdata->susp_lock);
1077
1018 for (i = 0; i < N_IN_URB; i++) 1078 for (i = 0; i < N_IN_URB; i++)
1019 usb_kill_urb(portdata->in_urbs[i]); 1079 usb_kill_urb(portdata->in_urbs[i]);
1020 for (i = 0; i < N_OUT_URB; i++) 1080 for (i = 0; i < N_OUT_URB; i++)
1021 usb_kill_urb(portdata->out_urbs[i]); 1081 usb_kill_urb(portdata->out_urbs[i]);
1082 usb_autopm_get_interface(serial->interface);
1083 serial->interface->needs_remote_wakeup = 0;
1022 } 1084 }
1023} 1085}
1024 1086
@@ -1123,6 +1185,7 @@ static int option_startup(struct usb_serial *serial)
1123 __func__, i); 1185 __func__, i);
1124 return 1; 1186 return 1;
1125 } 1187 }
1188 init_usb_anchor(&portdata->delayed);
1126 1189
1127 for (j = 0; j < N_IN_URB; j++) { 1190 for (j = 0; j < N_IN_URB; j++) {
1128 buffer = (u8 *)__get_free_page(GFP_KERNEL); 1191 buffer = (u8 *)__get_free_page(GFP_KERNEL);
@@ -1225,18 +1288,52 @@ static void option_release(struct usb_serial *serial)
1225#ifdef CONFIG_PM 1288#ifdef CONFIG_PM
1226static int option_suspend(struct usb_serial *serial, pm_message_t message) 1289static int option_suspend(struct usb_serial *serial, pm_message_t message)
1227{ 1290{
1291 struct option_intf_private *intfdata = serial->private;
1292 int b;
1293
1228 dbg("%s entered", __func__); 1294 dbg("%s entered", __func__);
1295
1296 if (serial->dev->auto_pm) {
1297 spin_lock_irq(&intfdata->susp_lock);
1298 b = intfdata->in_flight;
1299 spin_unlock_irq(&intfdata->susp_lock);
1300
1301 if (b)
1302 return -EBUSY;
1303 }
1304
1305 spin_lock_irq(&intfdata->susp_lock);
1306 intfdata->suspended = 1;
1307 spin_unlock_irq(&intfdata->susp_lock);
1229 stop_read_write_urbs(serial); 1308 stop_read_write_urbs(serial);
1230 1309
1231 return 0; 1310 return 0;
1232} 1311}
1233 1312
1313static void play_delayed(struct usb_serial_port *port)
1314{
1315 struct option_intf_private *data;
1316 struct option_port_private *portdata;
1317 struct urb *urb;
1318 int err;
1319
1320 portdata = usb_get_serial_port_data(port);
1321 data = port->serial->private;
1322 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
1323 err = usb_submit_urb(urb, GFP_ATOMIC);
1324 if (!err)
1325 data->in_flight++;
1326 }
1327}
1328
1234static int option_resume(struct usb_serial *serial) 1329static int option_resume(struct usb_serial *serial)
1235{ 1330{
1236 int err, i, j; 1331 int i, j;
1237 struct usb_serial_port *port; 1332 struct usb_serial_port *port;
1238 struct urb *urb; 1333 struct option_intf_private *intfdata = serial->private;
1239 struct option_port_private *portdata; 1334 struct option_port_private *portdata;
1335 struct urb *urb;
1336 int err = 0;
1240 1337
1241 dbg("%s entered", __func__); 1338 dbg("%s entered", __func__);
1242 /* get the interrupt URBs resubmitted unconditionally */ 1339 /* get the interrupt URBs resubmitted unconditionally */
@@ -1251,7 +1348,7 @@ static int option_resume(struct usb_serial *serial)
1251 if (err < 0) { 1348 if (err < 0) {
1252 err("%s: Error %d for interrupt URB of port%d", 1349 err("%s: Error %d for interrupt URB of port%d",
1253 __func__, err, i); 1350 __func__, err, i);
1254 return err; 1351 goto err_out;
1255 } 1352 }
1256 } 1353 }
1257 1354
@@ -1259,27 +1356,32 @@ static int option_resume(struct usb_serial *serial)
1259 /* walk all ports */ 1356 /* walk all ports */
1260 port = serial->port[i]; 1357 port = serial->port[i];
1261 portdata = usb_get_serial_port_data(port); 1358 portdata = usb_get_serial_port_data(port);
1262 mutex_lock(&port->mutex);
1263 1359
1264 /* skip closed ports */ 1360 /* skip closed ports */
1265 if (!port->port.count) { 1361 spin_lock_irq(&intfdata->susp_lock);
1266 mutex_unlock(&port->mutex); 1362 if (!portdata->opened) {
1363 spin_unlock_irq(&intfdata->susp_lock);
1267 continue; 1364 continue;
1268 } 1365 }
1269 1366
1270 for (j = 0; j < N_IN_URB; j++) { 1367 for (j = 0; j < N_IN_URB; j++) {
1271 urb = portdata->in_urbs[j]; 1368 urb = portdata->in_urbs[j];
1272 err = usb_submit_urb(urb, GFP_NOIO); 1369 err = usb_submit_urb(urb, GFP_ATOMIC);
1273 if (err < 0) { 1370 if (err < 0) {
1274 mutex_unlock(&port->mutex);
1275 err("%s: Error %d for bulk URB %d", 1371 err("%s: Error %d for bulk URB %d",
1276 __func__, err, i); 1372 __func__, err, i);
1277 return err; 1373 spin_unlock_irq(&intfdata->susp_lock);
1374 goto err_out;
1278 } 1375 }
1279 } 1376 }
1280 mutex_unlock(&port->mutex); 1377 play_delayed(port);
1378 spin_unlock_irq(&intfdata->susp_lock);
1281 } 1379 }
1282 return 0; 1380 spin_lock_irq(&intfdata->susp_lock);
1381 intfdata->suspended = 0;
1382 spin_unlock_irq(&intfdata->susp_lock);
1383err_out:
1384 return err;
1283} 1385}
1284#endif 1386#endif
1285 1387
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index a63ea99936f7..1128e01525b1 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -96,6 +96,7 @@ static struct usb_device_id id_table [] = {
96 { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) }, 96 { USB_DEVICE(HP_VENDOR_ID, HP_LD220_PRODUCT_ID) },
97 { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) }, 97 { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) },
98 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, 98 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
99 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
99 { } /* Terminating entry */ 100 { } /* Terminating entry */
100}; 101};
101 102
@@ -527,6 +528,12 @@ static void pl2303_set_termios(struct tty_struct *tty,
527 int baud; 528 int baud;
528 int i; 529 int i;
529 u8 control; 530 u8 control;
531 const int baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600,
532 4800, 7200, 9600, 14400, 19200, 28800, 38400,
533 57600, 115200, 230400, 460800, 614400,
534 921600, 1228800, 2457600, 3000000, 6000000 };
535 int baud_floor, baud_ceil;
536 int k;
530 537
531 dbg("%s - port %d", __func__, port->number); 538 dbg("%s - port %d", __func__, port->number);
532 539
@@ -572,9 +579,39 @@ static void pl2303_set_termios(struct tty_struct *tty,
572 dbg("%s - data bits = %d", __func__, buf[6]); 579 dbg("%s - data bits = %d", __func__, buf[6]);
573 } 580 }
574 581
582 /* For reference buf[0]:buf[3] baud rate value */
583 /* NOTE: Only the values defined in baud_sup are supported !
584 * => if unsupported values are set, the PL2303 seems to use
585 * 9600 baud (at least my PL2303X always does)
586 */
575 baud = tty_get_baud_rate(tty); 587 baud = tty_get_baud_rate(tty);
576 dbg("%s - baud = %d", __func__, baud); 588 dbg("%s - baud requested = %d", __func__, baud);
577 if (baud) { 589 if (baud) {
590 /* Set baudrate to nearest supported value */
591 for (k=0; k<ARRAY_SIZE(baud_sup); k++) {
592 if (baud_sup[k] / baud) {
593 baud_ceil = baud_sup[k];
594 if (k==0) {
595 baud = baud_ceil;
596 } else {
597 baud_floor = baud_sup[k-1];
598 if ((baud_ceil % baud)
599 > (baud % baud_floor))
600 baud = baud_floor;
601 else
602 baud = baud_ceil;
603 }
604 break;
605 }
606 }
607 if (baud > 1228800) {
608 /* type_0, type_1 only support up to 1228800 baud */
609 if (priv->type != HX)
610 baud = 1228800;
611 else if (baud > 6000000)
612 baud = 6000000;
613 }
614 dbg("%s - baud set = %d", __func__, baud);
578 buf[0] = baud & 0xff; 615 buf[0] = baud & 0xff;
579 buf[1] = (baud >> 8) & 0xff; 616 buf[1] = (baud >> 8) & 0xff;
580 buf[2] = (baud >> 16) & 0xff; 617 buf[2] = (baud >> 16) & 0xff;
@@ -585,8 +622,16 @@ static void pl2303_set_termios(struct tty_struct *tty,
585 /* For reference buf[4]=1 is 1.5 stop bits */ 622 /* For reference buf[4]=1 is 1.5 stop bits */
586 /* For reference buf[4]=2 is 2 stop bits */ 623 /* For reference buf[4]=2 is 2 stop bits */
587 if (cflag & CSTOPB) { 624 if (cflag & CSTOPB) {
588 buf[4] = 2; 625 /* NOTE: Comply with "real" UARTs / RS232:
589 dbg("%s - stop bits = 2", __func__); 626 * use 1.5 instead of 2 stop bits with 5 data bits
627 */
628 if ((cflag & CSIZE) == CS5) {
629 buf[4] = 1;
630 dbg("%s - stop bits = 1.5", __func__);
631 } else {
632 buf[4] = 2;
633 dbg("%s - stop bits = 2", __func__);
634 }
590 } else { 635 } else {
591 buf[4] = 0; 636 buf[4] = 0;
592 dbg("%s - stop bits = 1", __func__); 637 dbg("%s - stop bits = 1", __func__);
@@ -599,11 +644,21 @@ static void pl2303_set_termios(struct tty_struct *tty,
599 /* For reference buf[5]=3 is mark parity */ 644 /* For reference buf[5]=3 is mark parity */
600 /* For reference buf[5]=4 is space parity */ 645 /* For reference buf[5]=4 is space parity */
601 if (cflag & PARODD) { 646 if (cflag & PARODD) {
602 buf[5] = 1; 647 if (cflag & CMSPAR) {
603 dbg("%s - parity = odd", __func__); 648 buf[5] = 3;
649 dbg("%s - parity = mark", __func__);
650 } else {
651 buf[5] = 1;
652 dbg("%s - parity = odd", __func__);
653 }
604 } else { 654 } else {
605 buf[5] = 2; 655 if (cflag & CMSPAR) {
606 dbg("%s - parity = even", __func__); 656 buf[5] = 4;
657 dbg("%s - parity = space", __func__);
658 } else {
659 buf[5] = 2;
660 dbg("%s - parity = even", __func__);
661 }
607 } 662 }
608 } else { 663 } else {
609 buf[5] = 0; 664 buf[5] = 0;
@@ -647,7 +702,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
647 pl2303_vendor_write(0x0, 0x0, serial); 702 pl2303_vendor_write(0x0, 0x0, serial);
648 } 703 }
649 704
650 /* FIXME: Need to read back resulting baud rate */ 705 /* Save resulting baud rate */
651 if (baud) 706 if (baud)
652 tty_encode_baud_rate(tty, baud, baud); 707 tty_encode_baud_rate(tty, baud, baud);
653 708
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index ee9505e1dd92..d640dc951568 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -130,3 +130,7 @@
130/* Sony, USB data cable for CMD-Jxx mobile phones */ 130/* Sony, USB data cable for CMD-Jxx mobile phones */
131#define SONY_VENDOR_ID 0x054c 131#define SONY_VENDOR_ID 0x054c
132#define SONY_QN3USB_PRODUCT_ID 0x0437 132#define SONY_QN3USB_PRODUCT_ID 0x0437
133
134/* Sanwa KB-USB2 multimeter cable (ID: 11ad:0001) */
135#define SANWA_VENDOR_ID 0x11ad
136#define SANWA_PRODUCT_ID 0x0001
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 55391bbe1230..68fa0e43b781 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -51,6 +51,12 @@ struct sierra_iface_info {
51 const u8 *ifaceinfo; /* pointer to the array holding the numbers */ 51 const u8 *ifaceinfo; /* pointer to the array holding the numbers */
52}; 52};
53 53
54struct sierra_intf_private {
55 spinlock_t susp_lock;
56 unsigned int suspended:1;
57 int in_flight;
58};
59
54static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 60static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
55{ 61{
56 int result; 62 int result;
@@ -144,6 +150,7 @@ static int sierra_probe(struct usb_serial *serial,
144{ 150{
145 int result = 0; 151 int result = 0;
146 struct usb_device *udev; 152 struct usb_device *udev;
153 struct sierra_intf_private *data;
147 u8 ifnum; 154 u8 ifnum;
148 155
149 udev = serial->dev; 156 udev = serial->dev;
@@ -171,6 +178,11 @@ static int sierra_probe(struct usb_serial *serial,
171 return -ENODEV; 178 return -ENODEV;
172 } 179 }
173 180
181 data = serial->private = kzalloc(sizeof(struct sierra_intf_private), GFP_KERNEL);
182 if (!data)
183 return -ENOMEM;
184 spin_lock_init(&data->susp_lock);
185
174 return result; 186 return result;
175} 187}
176 188
@@ -261,13 +273,18 @@ static struct usb_driver sierra_driver = {
261 .name = "sierra", 273 .name = "sierra",
262 .probe = usb_serial_probe, 274 .probe = usb_serial_probe,
263 .disconnect = usb_serial_disconnect, 275 .disconnect = usb_serial_disconnect,
276 .suspend = usb_serial_suspend,
277 .resume = usb_serial_resume,
264 .id_table = id_table, 278 .id_table = id_table,
265 .no_dynamic_id = 1, 279 .no_dynamic_id = 1,
280 .supports_autosuspend = 1,
266}; 281};
267 282
268struct sierra_port_private { 283struct sierra_port_private {
269 spinlock_t lock; /* lock the structure */ 284 spinlock_t lock; /* lock the structure */
270 int outstanding_urbs; /* number of out urbs in flight */ 285 int outstanding_urbs; /* number of out urbs in flight */
286 struct usb_anchor active;
287 struct usb_anchor delayed;
271 288
272 /* Input endpoints and buffers for this port */ 289 /* Input endpoints and buffers for this port */
273 struct urb *in_urbs[N_IN_URB]; 290 struct urb *in_urbs[N_IN_URB];
@@ -279,6 +296,8 @@ struct sierra_port_private {
279 int dsr_state; 296 int dsr_state;
280 int dcd_state; 297 int dcd_state;
281 int ri_state; 298 int ri_state;
299
300 unsigned int opened:1;
282}; 301};
283 302
284static int sierra_send_setup(struct usb_serial_port *port) 303static int sierra_send_setup(struct usb_serial_port *port)
@@ -390,21 +409,25 @@ static void sierra_outdat_callback(struct urb *urb)
390{ 409{
391 struct usb_serial_port *port = urb->context; 410 struct usb_serial_port *port = urb->context;
392 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 411 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
412 struct sierra_intf_private *intfdata;
393 int status = urb->status; 413 int status = urb->status;
394 unsigned long flags;
395 414
396 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number); 415 dev_dbg(&port->dev, "%s - port %d\n", __func__, port->number);
416 intfdata = port->serial->private;
397 417
398 /* free up the transfer buffer, as usb_free_urb() does not do this */ 418 /* free up the transfer buffer, as usb_free_urb() does not do this */
399 kfree(urb->transfer_buffer); 419 kfree(urb->transfer_buffer);
400 420 usb_autopm_put_interface_async(port->serial->interface);
401 if (status) 421 if (status)
402 dev_dbg(&port->dev, "%s - nonzero write bulk status " 422 dev_dbg(&port->dev, "%s - nonzero write bulk status "
403 "received: %d\n", __func__, status); 423 "received: %d\n", __func__, status);
404 424
405 spin_lock_irqsave(&portdata->lock, flags); 425 spin_lock(&portdata->lock);
406 --portdata->outstanding_urbs; 426 --portdata->outstanding_urbs;
407 spin_unlock_irqrestore(&portdata->lock, flags); 427 spin_unlock(&portdata->lock);
428 spin_lock(&intfdata->susp_lock);
429 --intfdata->in_flight;
430 spin_unlock(&intfdata->susp_lock);
408 431
409 usb_serial_port_softint(port); 432 usb_serial_port_softint(port);
410} 433}
@@ -414,6 +437,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
414 const unsigned char *buf, int count) 437 const unsigned char *buf, int count)
415{ 438{
416 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 439 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
440 struct sierra_intf_private *intfdata;
417 struct usb_serial *serial = port->serial; 441 struct usb_serial *serial = port->serial;
418 unsigned long flags; 442 unsigned long flags;
419 unsigned char *buffer; 443 unsigned char *buffer;
@@ -426,9 +450,9 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
426 return 0; 450 return 0;
427 451
428 portdata = usb_get_serial_port_data(port); 452 portdata = usb_get_serial_port_data(port);
453 intfdata = serial->private;
429 454
430 dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize); 455 dev_dbg(&port->dev, "%s: write (%zd bytes)\n", __func__, writesize);
431
432 spin_lock_irqsave(&portdata->lock, flags); 456 spin_lock_irqsave(&portdata->lock, flags);
433 dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, 457 dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__,
434 portdata->outstanding_urbs); 458 portdata->outstanding_urbs);
@@ -442,6 +466,14 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
442 portdata->outstanding_urbs); 466 portdata->outstanding_urbs);
443 spin_unlock_irqrestore(&portdata->lock, flags); 467 spin_unlock_irqrestore(&portdata->lock, flags);
444 468
469 retval = usb_autopm_get_interface_async(serial->interface);
470 if (retval < 0) {
471 spin_lock_irqsave(&portdata->lock, flags);
472 portdata->outstanding_urbs--;
473 spin_unlock_irqrestore(&portdata->lock, flags);
474 goto error_simple;
475 }
476
445 buffer = kmalloc(writesize, GFP_ATOMIC); 477 buffer = kmalloc(writesize, GFP_ATOMIC);
446 if (!buffer) { 478 if (!buffer) {
447 dev_err(&port->dev, "out of memory\n"); 479 dev_err(&port->dev, "out of memory\n");
@@ -468,14 +500,29 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
468 /* Handle the need to send a zero length packet */ 500 /* Handle the need to send a zero length packet */
469 urb->transfer_flags |= URB_ZERO_PACKET; 501 urb->transfer_flags |= URB_ZERO_PACKET;
470 502
503 spin_lock_irqsave(&intfdata->susp_lock, flags);
504
505 if (intfdata->suspended) {
506 usb_anchor_urb(urb, &portdata->delayed);
507 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
508 goto skip_power;
509 } else {
510 usb_anchor_urb(urb, &portdata->active);
511 }
471 /* send it down the pipe */ 512 /* send it down the pipe */
472 retval = usb_submit_urb(urb, GFP_ATOMIC); 513 retval = usb_submit_urb(urb, GFP_ATOMIC);
473 if (retval) { 514 if (retval) {
515 usb_unanchor_urb(urb);
516 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
474 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed " 517 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed "
475 "with status = %d\n", __func__, retval); 518 "with status = %d\n", __func__, retval);
476 goto error; 519 goto error;
520 } else {
521 intfdata->in_flight++;
522 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
477 } 523 }
478 524
525skip_power:
479 /* we are done with this urb, so let the host driver 526 /* we are done with this urb, so let the host driver
480 * really free it when it is finished with it */ 527 * really free it when it is finished with it */
481 usb_free_urb(urb); 528 usb_free_urb(urb);
@@ -491,6 +538,8 @@ error_no_buffer:
491 dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__, 538 dev_dbg(&port->dev, "%s - 2. outstanding_urbs: %d\n", __func__,
492 portdata->outstanding_urbs); 539 portdata->outstanding_urbs);
493 spin_unlock_irqrestore(&portdata->lock, flags); 540 spin_unlock_irqrestore(&portdata->lock, flags);
541 usb_autopm_put_interface_async(serial->interface);
542error_simple:
494 return retval; 543 return retval;
495} 544}
496 545
@@ -530,6 +579,7 @@ static void sierra_indat_callback(struct urb *urb)
530 579
531 /* Resubmit urb so we continue receiving */ 580 /* Resubmit urb so we continue receiving */
532 if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { 581 if (port->port.count && status != -ESHUTDOWN && status != -EPERM) {
582 usb_mark_last_busy(port->serial->dev);
533 err = usb_submit_urb(urb, GFP_ATOMIC); 583 err = usb_submit_urb(urb, GFP_ATOMIC);
534 if (err) 584 if (err)
535 dev_err(&port->dev, "resubmit read urb failed." 585 dev_err(&port->dev, "resubmit read urb failed."
@@ -591,6 +641,7 @@ static void sierra_instat_callback(struct urb *urb)
591 641
592 /* Resubmit urb so we continue receiving IRQ data */ 642 /* Resubmit urb so we continue receiving IRQ data */
593 if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { 643 if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) {
644 usb_mark_last_busy(serial->dev);
594 urb->dev = serial->dev; 645 urb->dev = serial->dev;
595 err = usb_submit_urb(urb, GFP_ATOMIC); 646 err = usb_submit_urb(urb, GFP_ATOMIC);
596 if (err) 647 if (err)
@@ -711,6 +762,8 @@ static void sierra_close(struct usb_serial_port *port)
711 int i; 762 int i;
712 struct usb_serial *serial = port->serial; 763 struct usb_serial *serial = port->serial;
713 struct sierra_port_private *portdata; 764 struct sierra_port_private *portdata;
765 struct sierra_intf_private *intfdata = port->serial->private;
766
714 767
715 dev_dbg(&port->dev, "%s\n", __func__); 768 dev_dbg(&port->dev, "%s\n", __func__);
716 portdata = usb_get_serial_port_data(port); 769 portdata = usb_get_serial_port_data(port);
@@ -723,6 +776,10 @@ static void sierra_close(struct usb_serial_port *port)
723 if (!serial->disconnected) 776 if (!serial->disconnected)
724 sierra_send_setup(port); 777 sierra_send_setup(port);
725 mutex_unlock(&serial->disc_mutex); 778 mutex_unlock(&serial->disc_mutex);
779 spin_lock_irq(&intfdata->susp_lock);
780 portdata->opened = 0;
781 spin_unlock_irq(&intfdata->susp_lock);
782
726 783
727 /* Stop reading urbs */ 784 /* Stop reading urbs */
728 sierra_stop_rx_urbs(port); 785 sierra_stop_rx_urbs(port);
@@ -731,6 +788,8 @@ static void sierra_close(struct usb_serial_port *port)
731 sierra_release_urb(portdata->in_urbs[i]); 788 sierra_release_urb(portdata->in_urbs[i]);
732 portdata->in_urbs[i] = NULL; 789 portdata->in_urbs[i] = NULL;
733 } 790 }
791 usb_autopm_get_interface(serial->interface);
792 serial->interface->needs_remote_wakeup = 0;
734 } 793 }
735} 794}
736 795
@@ -738,6 +797,7 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port)
738{ 797{
739 struct sierra_port_private *portdata; 798 struct sierra_port_private *portdata;
740 struct usb_serial *serial = port->serial; 799 struct usb_serial *serial = port->serial;
800 struct sierra_intf_private *intfdata = serial->private;
741 int i; 801 int i;
742 int err; 802 int err;
743 int endpoint; 803 int endpoint;
@@ -771,6 +831,12 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port)
771 } 831 }
772 sierra_send_setup(port); 832 sierra_send_setup(port);
773 833
834 serial->interface->needs_remote_wakeup = 1;
835 spin_lock_irq(&intfdata->susp_lock);
836 portdata->opened = 1;
837 spin_unlock_irq(&intfdata->susp_lock);
838 usb_autopm_put_interface(serial->interface);
839
774 return 0; 840 return 0;
775} 841}
776 842
@@ -818,6 +884,8 @@ static int sierra_startup(struct usb_serial *serial)
818 return -ENOMEM; 884 return -ENOMEM;
819 } 885 }
820 spin_lock_init(&portdata->lock); 886 spin_lock_init(&portdata->lock);
887 init_usb_anchor(&portdata->active);
888 init_usb_anchor(&portdata->delayed);
821 /* Set the port private data pointer */ 889 /* Set the port private data pointer */
822 usb_set_serial_port_data(port, portdata); 890 usb_set_serial_port_data(port, portdata);
823 } 891 }
@@ -844,6 +912,83 @@ static void sierra_release(struct usb_serial *serial)
844 } 912 }
845} 913}
846 914
915static void stop_read_write_urbs(struct usb_serial *serial)
916{
917 int i, j;
918 struct usb_serial_port *port;
919 struct sierra_port_private *portdata;
920
921 /* Stop reading/writing urbs */
922 for (i = 0; i < serial->num_ports; ++i) {
923 port = serial->port[i];
924 portdata = usb_get_serial_port_data(port);
925 for (j = 0; j < N_IN_URB; j++)
926 usb_kill_urb(portdata->in_urbs[j]);
927 usb_kill_anchored_urbs(&portdata->active);
928 }
929}
930
931static int sierra_suspend(struct usb_serial *serial, pm_message_t message)
932{
933 struct sierra_intf_private *intfdata;
934 int b;
935
936 if (serial->dev->auto_pm) {
937 intfdata = serial->private;
938 spin_lock_irq(&intfdata->susp_lock);
939 b = intfdata->in_flight;
940
941 if (b) {
942 spin_unlock_irq(&intfdata->susp_lock);
943 return -EBUSY;
944 } else {
945 intfdata->suspended = 1;
946 spin_unlock_irq(&intfdata->susp_lock);
947 }
948 }
949 stop_read_write_urbs(serial);
950
951 return 0;
952}
953
954static int sierra_resume(struct usb_serial *serial)
955{
956 struct usb_serial_port *port;
957 struct sierra_intf_private *intfdata = serial->private;
958 struct sierra_port_private *portdata;
959 struct urb *urb;
960 int ec = 0;
961 int i, err;
962
963 spin_lock_irq(&intfdata->susp_lock);
964 for (i = 0; i < serial->num_ports; i++) {
965 port = serial->port[i];
966 portdata = usb_get_serial_port_data(port);
967
968 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
969 usb_anchor_urb(urb, &portdata->active);
970 intfdata->in_flight++;
971 err = usb_submit_urb(urb, GFP_ATOMIC);
972 if (err < 0) {
973 intfdata->in_flight--;
974 usb_unanchor_urb(urb);
975 usb_scuttle_anchored_urbs(&portdata->delayed);
976 break;
977 }
978 }
979
980 if (portdata->opened) {
981 err = sierra_submit_rx_urbs(port, GFP_ATOMIC);
982 if (err)
983 ec++;
984 }
985 }
986 intfdata->suspended = 0;
987 spin_unlock_irq(&intfdata->susp_lock);
988
989 return ec ? -EIO : 0;
990}
991
847static struct usb_serial_driver sierra_device = { 992static struct usb_serial_driver sierra_device = {
848 .driver = { 993 .driver = {
849 .owner = THIS_MODULE, 994 .owner = THIS_MODULE,
@@ -864,6 +1009,8 @@ static struct usb_serial_driver sierra_device = {
864 .tiocmset = sierra_tiocmset, 1009 .tiocmset = sierra_tiocmset,
865 .attach = sierra_startup, 1010 .attach = sierra_startup,
866 .release = sierra_release, 1011 .release = sierra_release,
1012 .suspend = sierra_suspend,
1013 .resume = sierra_resume,
867 .read_int_callback = sierra_instat_callback, 1014 .read_int_callback = sierra_instat_callback,
868}; 1015};
869 1016
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 9d7ca4868d37..ff75a3589e7e 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -35,6 +35,7 @@
35#include <linux/serial.h> 35#include <linux/serial.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/usb/serial.h> 37#include <linux/usb/serial.h>
38#include <linux/kfifo.h>
38#include "pl2303.h" 39#include "pl2303.h"
39 40
40/* 41/*
@@ -292,8 +293,6 @@ static int serial_open(struct tty_struct *tty, struct file *filp)
292static void serial_down(struct usb_serial_port *port) 293static void serial_down(struct usb_serial_port *port)
293{ 294{
294 struct usb_serial_driver *drv = port->serial->type; 295 struct usb_serial_driver *drv = port->serial->type;
295 struct usb_serial *serial;
296 struct module *owner;
297 296
298 /* 297 /*
299 * The console is magical. Do not hang up the console hardware 298 * The console is magical. Do not hang up the console hardware
@@ -309,12 +308,8 @@ static void serial_down(struct usb_serial_port *port)
309 return; 308 return;
310 309
311 mutex_lock(&port->mutex); 310 mutex_lock(&port->mutex);
312 serial = port->serial;
313 owner = serial->type->driver.owner;
314
315 if (drv->close) 311 if (drv->close)
316 drv->close(port); 312 drv->close(port);
317
318 mutex_unlock(&port->mutex); 313 mutex_unlock(&port->mutex);
319} 314}
320 315
@@ -631,6 +626,8 @@ static void port_release(struct device *dev)
631 usb_free_urb(port->write_urb); 626 usb_free_urb(port->write_urb);
632 usb_free_urb(port->interrupt_in_urb); 627 usb_free_urb(port->interrupt_in_urb);
633 usb_free_urb(port->interrupt_out_urb); 628 usb_free_urb(port->interrupt_out_urb);
629 if (!IS_ERR(port->write_fifo) && port->write_fifo)
630 kfifo_free(port->write_fifo);
634 kfree(port->bulk_in_buffer); 631 kfree(port->bulk_in_buffer);
635 kfree(port->bulk_out_buffer); 632 kfree(port->bulk_out_buffer);
636 kfree(port->interrupt_in_buffer); 633 kfree(port->interrupt_in_buffer);
@@ -970,6 +967,10 @@ int usb_serial_probe(struct usb_interface *interface,
970 dev_err(&interface->dev, "No free urbs available\n"); 967 dev_err(&interface->dev, "No free urbs available\n");
971 goto probe_error; 968 goto probe_error;
972 } 969 }
970 port->write_fifo = kfifo_alloc(PAGE_SIZE, GFP_KERNEL,
971 &port->lock);
972 if (IS_ERR(port->write_fifo))
973 goto probe_error;
973 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 974 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
974 port->bulk_out_size = buffer_size; 975 port->bulk_out_size = buffer_size;
975 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 976 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
@@ -1163,15 +1164,19 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1163 1164
1164 serial->suspending = 1; 1165 serial->suspending = 1;
1165 1166
1167 if (serial->type->suspend) {
1168 r = serial->type->suspend(serial, message);
1169 if (r < 0)
1170 goto err_out;
1171 }
1172
1166 for (i = 0; i < serial->num_ports; ++i) { 1173 for (i = 0; i < serial->num_ports; ++i) {
1167 port = serial->port[i]; 1174 port = serial->port[i];
1168 if (port) 1175 if (port)
1169 kill_traffic(port); 1176 kill_traffic(port);
1170 } 1177 }
1171 1178
1172 if (serial->type->suspend) 1179err_out:
1173 r = serial->type->suspend(serial, message);
1174
1175 return r; 1180 return r;
1176} 1181}
1177EXPORT_SYMBOL(usb_serial_suspend); 1182EXPORT_SYMBOL(usb_serial_suspend);
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 2b6e565262c2..ded836b02d7b 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -334,7 +334,7 @@ static int datafab_determine_lun(struct us_data *us,
334 unsigned char *buf; 334 unsigned char *buf;
335 int count = 0, rc; 335 int count = 0, rc;
336 336
337 if (!us || !info) 337 if (!info)
338 return USB_STOR_TRANSPORT_ERROR; 338 return USB_STOR_TRANSPORT_ERROR;
339 339
340 memcpy(command, scommand, 8); 340 memcpy(command, scommand, 8);
@@ -399,7 +399,7 @@ static int datafab_id_device(struct us_data *us,
399 unsigned char *reply; 399 unsigned char *reply;
400 int rc; 400 int rc;
401 401
402 if (!us || !info) 402 if (!info)
403 return USB_STOR_TRANSPORT_ERROR; 403 return USB_STOR_TRANSPORT_ERROR;
404 404
405 if (info->lun == -1) { 405 if (info->lun == -1) {
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index ec17c96371af..105d900150c1 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -102,5 +102,5 @@ int usb_stor_huawei_e220_init(struct us_data *us)
102 USB_TYPE_STANDARD | USB_RECIP_DEVICE, 102 USB_TYPE_STANDARD | USB_RECIP_DEVICE,
103 0x01, 0x0, NULL, 0x0, 1000); 103 0x01, 0x0, NULL, 0x0, 1000);
104 US_DEBUGP("Huawei mode set result is %d\n", result); 104 US_DEBUGP("Huawei mode set result is %d\n", result);
105 return (result ? 0 : -ENODEV); 105 return 0;
106} 106}
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index 1c69420e3acf..6168596c5ac6 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -335,7 +335,7 @@ static int jumpshot_id_device(struct us_data *us,
335 unsigned char *reply; 335 unsigned char *reply;
336 int rc; 336 int rc;
337 337
338 if (!us || !info) 338 if (!info)
339 return USB_STOR_TRANSPORT_ERROR; 339 return USB_STOR_TRANSPORT_ERROR;
340 340
341 command[0] = 0xE0; 341 command[0] = 0xE0;
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 380233bd6a39..80e65f29921c 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -163,7 +163,7 @@ static void usb_onetouch_pm_hook(struct us_data *us, int action)
163 usb_kill_urb(onetouch->irq); 163 usb_kill_urb(onetouch->irq);
164 break; 164 break;
165 case US_RESUME: 165 case US_RESUME:
166 if (usb_submit_urb(onetouch->irq, GFP_KERNEL) != 0) 166 if (usb_submit_urb(onetouch->irq, GFP_NOIO) != 0)
167 dev_err(&onetouch->irq->dev->dev, 167 dev_err(&onetouch->irq->dev->dev,
168 "usb_submit_urb failed\n"); 168 "usb_submit_urb failed\n");
169 break; 169 break;
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 7477d411959f..079ae0f7bec1 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -66,13 +66,6 @@ UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100,
66 US_SC_DEVICE, US_PR_DEVICE, NULL, 66 US_SC_DEVICE, US_PR_DEVICE, NULL,
67 US_FL_IGNORE_RESIDUE), 67 US_FL_IGNORE_RESIDUE),
68 68
69/* modified by Tobias Lorenz <tobias.lorenz@gmx.net> */
70UNUSUAL_DEV( 0x03ee, 0x6901, 0x0000, 0x0200,
71 "Mitsumi",
72 "USB FDD",
73 US_SC_DEVICE, US_PR_DEVICE, NULL,
74 US_FL_SINGLE_LUN ),
75
76/* Reported by Rodolfo Quesada <rquesada@roqz.net> */ 69/* Reported by Rodolfo Quesada <rquesada@roqz.net> */
77UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003, 70UNUSUAL_DEV( 0x03ee, 0x6906, 0x0003, 0x0003,
78 "VIA Technologies Inc.", 71 "VIA Technologies Inc.",
@@ -233,13 +226,6 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
233 US_SC_DEVICE, US_PR_DEVICE, NULL, 226 US_SC_DEVICE, US_PR_DEVICE, NULL,
234 US_FL_MAX_SECTORS_64 ), 227 US_FL_MAX_SECTORS_64 ),
235 228
236/* Reported by Olaf Hering <olh@suse.de> from novell bug #105878 */
237UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
238 "SMSC",
239 "FDC GOLD-2.30",
240 US_SC_DEVICE, US_PR_DEVICE, NULL,
241 US_FL_SINGLE_LUN ),
242
243#ifdef NO_SDDR09 229#ifdef NO_SDDR09
244UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, 230UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
245 "Microtech", 231 "Microtech",
@@ -664,19 +650,13 @@ UNUSUAL_DEV( 0x055d, 0x2020, 0x0000, 0x0210,
664 US_SC_DEVICE, US_PR_DEVICE, NULL, 650 US_SC_DEVICE, US_PR_DEVICE, NULL,
665 US_FL_SINGLE_LUN ), 651 US_FL_SINGLE_LUN ),
666 652
667 653/* We keep this entry to force the transport; firmware 3.00 and later is ok. */
668UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299, 654UNUSUAL_DEV( 0x057b, 0x0000, 0x0000, 0x0299,
669 "Y-E Data", 655 "Y-E Data",
670 "Flashbuster-U", 656 "Flashbuster-U",
671 US_SC_DEVICE, US_PR_CB, NULL, 657 US_SC_DEVICE, US_PR_CB, NULL,
672 US_FL_SINGLE_LUN), 658 US_FL_SINGLE_LUN),
673 659
674UNUSUAL_DEV( 0x057b, 0x0000, 0x0300, 0x9999,
675 "Y-E Data",
676 "Flashbuster-U",
677 US_SC_DEVICE, US_PR_DEVICE, NULL,
678 US_FL_SINGLE_LUN),
679
680/* Reported by Johann Cardon <johann.cardon@free.fr> 660/* Reported by Johann Cardon <johann.cardon@free.fr>
681 * This entry is needed only because the device reports 661 * This entry is needed only because the device reports
682 * bInterfaceClass = 0xff (vendor-specific) 662 * bInterfaceClass = 0xff (vendor-specific)
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 60ba631e99c2..b62f2bc064f6 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -18,7 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/kref.h> 20#include <linux/kref.h>
21#include <asm/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/usb.h> 22#include <linux/usb.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24 24
@@ -28,7 +28,7 @@
28#define USB_SKEL_PRODUCT_ID 0xfff0 28#define USB_SKEL_PRODUCT_ID 0xfff0
29 29
30/* table of devices that work with this driver */ 30/* table of devices that work with this driver */
31static struct usb_device_id skel_table [] = { 31static struct usb_device_id skel_table[] = {
32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
33 { } /* Terminating entry */ 33 { } /* Terminating entry */
34}; 34};
@@ -52,15 +52,21 @@ struct usb_skel {
52 struct usb_interface *interface; /* the interface for this device */ 52 struct usb_interface *interface; /* the interface for this device */
53 struct semaphore limit_sem; /* limiting the number of writes in progress */ 53 struct semaphore limit_sem; /* limiting the number of writes in progress */
54 struct usb_anchor submitted; /* in case we need to retract our submissions */ 54 struct usb_anchor submitted; /* in case we need to retract our submissions */
55 struct urb *bulk_in_urb; /* the urb to read data with */
55 unsigned char *bulk_in_buffer; /* the buffer to receive data */ 56 unsigned char *bulk_in_buffer; /* the buffer to receive data */
56 size_t bulk_in_size; /* the size of the receive buffer */ 57 size_t bulk_in_size; /* the size of the receive buffer */
58 size_t bulk_in_filled; /* number of bytes in the buffer */
59 size_t bulk_in_copied; /* already copied to user space */
57 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */ 60 __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
58 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 61 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
59 int errors; /* the last request tanked */ 62 int errors; /* the last request tanked */
60 int open_count; /* count the number of openers */ 63 int open_count; /* count the number of openers */
64 bool ongoing_read; /* a read is going on */
65 bool processed_urb; /* indicates we haven't processed the urb */
61 spinlock_t err_lock; /* lock for errors */ 66 spinlock_t err_lock; /* lock for errors */
62 struct kref kref; 67 struct kref kref;
63 struct mutex io_mutex; /* synchronize I/O with disconnect */ 68 struct mutex io_mutex; /* synchronize I/O with disconnect */
69 struct completion bulk_in_completion; /* to wait for an ongoing read */
64}; 70};
65#define to_skel_dev(d) container_of(d, struct usb_skel, kref) 71#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
66 72
@@ -71,6 +77,7 @@ static void skel_delete(struct kref *kref)
71{ 77{
72 struct usb_skel *dev = to_skel_dev(kref); 78 struct usb_skel *dev = to_skel_dev(kref);
73 79
80 usb_free_urb(dev->bulk_in_urb);
74 usb_put_dev(dev->udev); 81 usb_put_dev(dev->udev);
75 kfree(dev->bulk_in_buffer); 82 kfree(dev->bulk_in_buffer);
76 kfree(dev); 83 kfree(dev);
@@ -87,7 +94,7 @@ static int skel_open(struct inode *inode, struct file *file)
87 94
88 interface = usb_find_interface(&skel_driver, subminor); 95 interface = usb_find_interface(&skel_driver, subminor);
89 if (!interface) { 96 if (!interface) {
90 err ("%s - error, can't find device for minor %d", 97 err("%s - error, can't find device for minor %d",
91 __func__, subminor); 98 __func__, subminor);
92 retval = -ENODEV; 99 retval = -ENODEV;
93 goto exit; 100 goto exit;
@@ -174,38 +181,190 @@ static int skel_flush(struct file *file, fl_owner_t id)
174 return res; 181 return res;
175} 182}
176 183
177static ssize_t skel_read(struct file *file, char *buffer, size_t count, loff_t *ppos) 184static void skel_read_bulk_callback(struct urb *urb)
178{ 185{
179 struct usb_skel *dev; 186 struct usb_skel *dev;
180 int retval; 187
181 int bytes_read; 188 dev = urb->context;
189
190 spin_lock(&dev->err_lock);
191 /* sync/async unlink faults aren't errors */
192 if (urb->status) {
193 if (!(urb->status == -ENOENT ||
194 urb->status == -ECONNRESET ||
195 urb->status == -ESHUTDOWN))
196 err("%s - nonzero write bulk status received: %d",
197 __func__, urb->status);
198
199 dev->errors = urb->status;
200 } else {
201 dev->bulk_in_filled = urb->actual_length;
202 }
203 dev->ongoing_read = 0;
204 spin_unlock(&dev->err_lock);
205
206 complete(&dev->bulk_in_completion);
207}
208
209static int skel_do_read_io(struct usb_skel *dev, size_t count)
210{
211 int rv;
212
213 /* prepare a read */
214 usb_fill_bulk_urb(dev->bulk_in_urb,
215 dev->udev,
216 usb_rcvbulkpipe(dev->udev,
217 dev->bulk_in_endpointAddr),
218 dev->bulk_in_buffer,
219 min(dev->bulk_in_size, count),
220 skel_read_bulk_callback,
221 dev);
222 /* tell everybody to leave the URB alone */
223 spin_lock_irq(&dev->err_lock);
224 dev->ongoing_read = 1;
225 spin_unlock_irq(&dev->err_lock);
226
227 /* do it */
228 rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL);
229 if (rv < 0) {
230 err("%s - failed submitting read urb, error %d",
231 __func__, rv);
232 dev->bulk_in_filled = 0;
233 rv = (rv == -ENOMEM) ? rv : -EIO;
234 spin_lock_irq(&dev->err_lock);
235 dev->ongoing_read = 0;
236 spin_unlock_irq(&dev->err_lock);
237 }
238
239 return rv;
240}
241
242static ssize_t skel_read(struct file *file, char *buffer, size_t count,
243 loff_t *ppos)
244{
245 struct usb_skel *dev;
246 int rv;
247 bool ongoing_io;
182 248
183 dev = (struct usb_skel *)file->private_data; 249 dev = (struct usb_skel *)file->private_data;
184 250
185 mutex_lock(&dev->io_mutex); 251 /* if we cannot read at all, return EOF */
252 if (!dev->bulk_in_urb || !count)
253 return 0;
254
255 /* no concurrent readers */
256 rv = mutex_lock_interruptible(&dev->io_mutex);
257 if (rv < 0)
258 return rv;
259
186 if (!dev->interface) { /* disconnect() was called */ 260 if (!dev->interface) { /* disconnect() was called */
187 retval = -ENODEV; 261 rv = -ENODEV;
188 goto exit; 262 goto exit;
189 } 263 }
190 264
191 /* do a blocking bulk read to get data from the device */ 265 /* if IO is under way, we must not touch things */
192 retval = usb_bulk_msg(dev->udev, 266retry:
193 usb_rcvbulkpipe(dev->udev, dev->bulk_in_endpointAddr), 267 spin_lock_irq(&dev->err_lock);
194 dev->bulk_in_buffer, 268 ongoing_io = dev->ongoing_read;
195 min(dev->bulk_in_size, count), 269 spin_unlock_irq(&dev->err_lock);
196 &bytes_read, 10000); 270
197 271 if (ongoing_io) {
198 /* if the read was successful, copy the data to userspace */ 272 /* nonblocking IO shall not wait */
199 if (!retval) { 273 if (file->f_flags & O_NONBLOCK) {
200 if (copy_to_user(buffer, dev->bulk_in_buffer, bytes_read)) 274 rv = -EAGAIN;
201 retval = -EFAULT; 275 goto exit;
202 else 276 }
203 retval = bytes_read; 277 /*
278 * IO may take forever
279 * hence wait in an interruptible state
280 */
281 rv = wait_for_completion_interruptible(&dev->bulk_in_completion);
282 if (rv < 0)
283 goto exit;
284 /*
285 * by waiting we also semiprocessed the urb
286 * we must finish now
287 */
288 dev->bulk_in_copied = 0;
289 dev->processed_urb = 1;
290 }
291
292 if (!dev->processed_urb) {
293 /*
294 * the URB hasn't been processed
295 * do it now
296 */
297 wait_for_completion(&dev->bulk_in_completion);
298 dev->bulk_in_copied = 0;
299 dev->processed_urb = 1;
300 }
301
302 /* errors must be reported */
303 rv = dev->errors;
304 if (rv < 0) {
305 /* any error is reported once */
306 dev->errors = 0;
307 /* to preserve notifications about reset */
308 rv = (rv == -EPIPE) ? rv : -EIO;
309 /* no data to deliver */
310 dev->bulk_in_filled = 0;
311 /* report it */
312 goto exit;
204 } 313 }
205 314
315 /*
316 * if the buffer is filled we may satisfy the read
317 * else we need to start IO
318 */
319
320 if (dev->bulk_in_filled) {
321 /* we had read data */
322 size_t available = dev->bulk_in_filled - dev->bulk_in_copied;
323 size_t chunk = min(available, count);
324
325 if (!available) {
326 /*
327 * all data has been used
328 * actual IO needs to be done
329 */
330 rv = skel_do_read_io(dev, count);
331 if (rv < 0)
332 goto exit;
333 else
334 goto retry;
335 }
336 /*
337 * data is available
338 * chunk tells us how much shall be copied
339 */
340
341 if (copy_to_user(buffer,
342 dev->bulk_in_buffer + dev->bulk_in_copied,
343 chunk))
344 rv = -EFAULT;
345 else
346 rv = chunk;
347
348 dev->bulk_in_copied += chunk;
349
350 /*
351 * if we are asked for more than we have,
352 * we start IO but don't wait
353 */
354 if (available < count)
355 skel_do_read_io(dev, count - chunk);
356 } else {
357 /* no data in the buffer */
358 rv = skel_do_read_io(dev, count);
359 if (rv < 0)
360 goto exit;
361 else if (!file->f_flags & O_NONBLOCK)
362 goto retry;
363 rv = -EAGAIN;
364 }
206exit: 365exit:
207 mutex_unlock(&dev->io_mutex); 366 mutex_unlock(&dev->io_mutex);
208 return retval; 367 return rv;
209} 368}
210 369
211static void skel_write_bulk_callback(struct urb *urb) 370static void skel_write_bulk_callback(struct urb *urb)
@@ -216,7 +375,7 @@ static void skel_write_bulk_callback(struct urb *urb)
216 375
217 /* sync/async unlink faults aren't errors */ 376 /* sync/async unlink faults aren't errors */
218 if (urb->status) { 377 if (urb->status) {
219 if(!(urb->status == -ENOENT || 378 if (!(urb->status == -ENOENT ||
220 urb->status == -ECONNRESET || 379 urb->status == -ECONNRESET ||
221 urb->status == -ESHUTDOWN)) 380 urb->status == -ESHUTDOWN))
222 err("%s - nonzero write bulk status received: %d", 381 err("%s - nonzero write bulk status received: %d",
@@ -233,7 +392,8 @@ static void skel_write_bulk_callback(struct urb *urb)
233 up(&dev->limit_sem); 392 up(&dev->limit_sem);
234} 393}
235 394
236static ssize_t skel_write(struct file *file, const char *user_buffer, size_t count, loff_t *ppos) 395static ssize_t skel_write(struct file *file, const char *user_buffer,
396 size_t count, loff_t *ppos)
237{ 397{
238 struct usb_skel *dev; 398 struct usb_skel *dev;
239 int retval = 0; 399 int retval = 0;
@@ -247,14 +407,25 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
247 if (count == 0) 407 if (count == 0)
248 goto exit; 408 goto exit;
249 409
250 /* limit the number of URBs in flight to stop a user from using up all RAM */ 410 /*
251 if (down_interruptible(&dev->limit_sem)) { 411 * limit the number of URBs in flight to stop a user from using up all
252 retval = -ERESTARTSYS; 412 * RAM
253 goto exit; 413 */
414 if (!file->f_flags & O_NONBLOCK) {
415 if (down_interruptible(&dev->limit_sem)) {
416 retval = -ERESTARTSYS;
417 goto exit;
418 }
419 } else {
420 if (down_trylock(&dev->limit_sem)) {
421 retval = -EAGAIN;
422 goto exit;
423 }
254 } 424 }
255 425
256 spin_lock_irq(&dev->err_lock); 426 spin_lock_irq(&dev->err_lock);
257 if ((retval = dev->errors) < 0) { 427 retval = dev->errors;
428 if (retval < 0) {
258 /* any error is reported once */ 429 /* any error is reported once */
259 dev->errors = 0; 430 dev->errors = 0;
260 /* to preserve notifications about reset */ 431 /* to preserve notifications about reset */
@@ -271,7 +442,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
271 goto error; 442 goto error;
272 } 443 }
273 444
274 buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, &urb->transfer_dma); 445 buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL,
446 &urb->transfer_dma);
275 if (!buf) { 447 if (!buf) {
276 retval = -ENOMEM; 448 retval = -ENOMEM;
277 goto error; 449 goto error;
@@ -301,11 +473,15 @@ static ssize_t skel_write(struct file *file, const char *user_buffer, size_t cou
301 retval = usb_submit_urb(urb, GFP_KERNEL); 473 retval = usb_submit_urb(urb, GFP_KERNEL);
302 mutex_unlock(&dev->io_mutex); 474 mutex_unlock(&dev->io_mutex);
303 if (retval) { 475 if (retval) {
304 err("%s - failed submitting write urb, error %d", __func__, retval); 476 err("%s - failed submitting write urb, error %d", __func__,
477 retval);
305 goto error_unanchor; 478 goto error_unanchor;
306 } 479 }
307 480
308 /* release our reference to this urb, the USB core will eventually free it entirely */ 481 /*
482 * release our reference to this urb, the USB core will eventually free
483 * it entirely
484 */
309 usb_free_urb(urb); 485 usb_free_urb(urb);
310 486
311 487
@@ -343,7 +519,8 @@ static struct usb_class_driver skel_class = {
343 .minor_base = USB_SKEL_MINOR_BASE, 519 .minor_base = USB_SKEL_MINOR_BASE,
344}; 520};
345 521
346static int skel_probe(struct usb_interface *interface, const struct usb_device_id *id) 522static int skel_probe(struct usb_interface *interface,
523 const struct usb_device_id *id)
347{ 524{
348 struct usb_skel *dev; 525 struct usb_skel *dev;
349 struct usb_host_interface *iface_desc; 526 struct usb_host_interface *iface_desc;
@@ -363,6 +540,7 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
363 mutex_init(&dev->io_mutex); 540 mutex_init(&dev->io_mutex);
364 spin_lock_init(&dev->err_lock); 541 spin_lock_init(&dev->err_lock);
365 init_usb_anchor(&dev->submitted); 542 init_usb_anchor(&dev->submitted);
543 init_completion(&dev->bulk_in_completion);
366 544
367 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 545 dev->udev = usb_get_dev(interface_to_usbdev(interface));
368 dev->interface = interface; 546 dev->interface = interface;
@@ -384,6 +562,11 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
384 err("Could not allocate bulk_in_buffer"); 562 err("Could not allocate bulk_in_buffer");
385 goto error; 563 goto error;
386 } 564 }
565 dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
566 if (!dev->bulk_in_urb) {
567 err("Could not allocate bulk_in_urb");
568 goto error;
569 }
387 } 570 }
388 571
389 if (!dev->bulk_out_endpointAddr && 572 if (!dev->bulk_out_endpointAddr &&
@@ -453,6 +636,7 @@ static void skel_draw_down(struct usb_skel *dev)
453 time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000); 636 time = usb_wait_anchor_empty_timeout(&dev->submitted, 1000);
454 if (!time) 637 if (!time)
455 usb_kill_anchored_urbs(&dev->submitted); 638 usb_kill_anchored_urbs(&dev->submitted);
639 usb_kill_urb(dev->bulk_in_urb);
456} 640}
457 641
458static int skel_suspend(struct usb_interface *intf, pm_message_t message) 642static int skel_suspend(struct usb_interface *intf, pm_message_t message)
@@ -465,7 +649,7 @@ static int skel_suspend(struct usb_interface *intf, pm_message_t message)
465 return 0; 649 return 0;
466} 650}
467 651
468static int skel_resume (struct usb_interface *intf) 652static int skel_resume(struct usb_interface *intf)
469{ 653{
470 return 0; 654 return 0;
471} 655}
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 19fabc487beb..a34fa89f1474 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -195,7 +195,7 @@ struct usb_interface {
195 195
196 struct device dev; /* interface specific device info */ 196 struct device dev; /* interface specific device info */
197 struct device *usb_dev; 197 struct device *usb_dev;
198 int pm_usage_cnt; /* usage counter for autosuspend */ 198 atomic_t pm_usage_cnt; /* usage counter for autosuspend */
199 struct work_struct reset_ws; /* for resets in atomic context */ 199 struct work_struct reset_ws; /* for resets in atomic context */
200}; 200};
201#define to_usb_interface(d) container_of(d, struct usb_interface, dev) 201#define to_usb_interface(d) container_of(d, struct usb_interface, dev)
@@ -551,13 +551,13 @@ extern void usb_autopm_put_interface_async(struct usb_interface *intf);
551 551
552static inline void usb_autopm_enable(struct usb_interface *intf) 552static inline void usb_autopm_enable(struct usb_interface *intf)
553{ 553{
554 intf->pm_usage_cnt = 0; 554 atomic_set(&intf->pm_usage_cnt, 0);
555 usb_autopm_set_interface(intf); 555 usb_autopm_set_interface(intf);
556} 556}
557 557
558static inline void usb_autopm_disable(struct usb_interface *intf) 558static inline void usb_autopm_disable(struct usb_interface *intf)
559{ 559{
560 intf->pm_usage_cnt = 1; 560 atomic_set(&intf->pm_usage_cnt, 1);
561 usb_autopm_set_interface(intf); 561 usb_autopm_set_interface(intf);
562} 562}
563 563
@@ -1036,9 +1036,10 @@ typedef void (*usb_complete_t)(struct urb *);
1036 * @transfer_flags: A variety of flags may be used to affect how URB 1036 * @transfer_flags: A variety of flags may be used to affect how URB
1037 * submission, unlinking, or operation are handled. Different 1037 * submission, unlinking, or operation are handled. Different
1038 * kinds of URB can use different flags. 1038 * kinds of URB can use different flags.
1039 * @transfer_buffer: This identifies the buffer to (or from) which 1039 * @transfer_buffer: This identifies the buffer to (or from) which the I/O
1040 * the I/O request will be performed (unless URB_NO_TRANSFER_DMA_MAP 1040 * request will be performed unless URB_NO_TRANSFER_DMA_MAP is set
1041 * is set). This buffer must be suitable for DMA; allocate it with 1041 * (however, do not leave garbage in transfer_buffer even then).
1042 * This buffer must be suitable for DMA; allocate it with
1042 * kmalloc() or equivalent. For transfers to "in" endpoints, contents 1043 * kmalloc() or equivalent. For transfers to "in" endpoints, contents
1043 * of this buffer will be modified. This buffer is used for the data 1044 * of this buffer will be modified. This buffer is used for the data
1044 * stage of control transfers. 1045 * stage of control transfers.
@@ -1104,9 +1105,15 @@ typedef void (*usb_complete_t)(struct urb *);
1104 * allocate a DMA buffer with usb_buffer_alloc() or call usb_buffer_map(). 1105 * allocate a DMA buffer with usb_buffer_alloc() or call usb_buffer_map().
1105 * When these transfer flags are provided, host controller drivers will 1106 * When these transfer flags are provided, host controller drivers will
1106 * attempt to use the dma addresses found in the transfer_dma and/or 1107 * attempt to use the dma addresses found in the transfer_dma and/or
1107 * setup_dma fields rather than determining a dma address themselves. (Note 1108 * setup_dma fields rather than determining a dma address themselves.
1108 * that transfer_buffer and setup_packet must still be set because not all 1109 *
1109 * host controllers use DMA, nor do virtual root hubs). 1110 * Note that transfer_buffer must still be set if the controller
1111 * does not support DMA (as indicated by bus.uses_dma) and when talking
1112 * to root hub. If you have to trasfer between highmem zone and the device
1113 * on such controller, create a bounce buffer or bail out with an error.
1114 * If transfer_buffer cannot be set (is in highmem) and the controller is DMA
1115 * capable, assign NULL to it, so that usbmon knows not to use the value.
1116 * The setup_packet must always be set, so it cannot be located in highmem.
1110 * 1117 *
1111 * Initialization: 1118 * Initialization:
1112 * 1119 *
diff --git a/include/linux/usb/audio.h b/include/linux/usb/audio.h
index b5744bc218ab..eaf9dffe0a01 100644
--- a/include/linux/usb/audio.h
+++ b/include/linux/usb/audio.h
@@ -24,88 +24,78 @@
24#define USB_SUBCLASS_AUDIOCONTROL 0x01 24#define USB_SUBCLASS_AUDIOCONTROL 0x01
25#define USB_SUBCLASS_AUDIOSTREAMING 0x02 25#define USB_SUBCLASS_AUDIOSTREAMING 0x02
26#define USB_SUBCLASS_MIDISTREAMING 0x03 26#define USB_SUBCLASS_MIDISTREAMING 0x03
27#define USB_SUBCLASS_VENDOR_SPEC 0xff 27
28 28/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
29/* A.5 Audio Class-Specific AC interface Descriptor Subtypes*/ 29#define UAC_HEADER 0x01
30#define HEADER 0x01 30#define UAC_INPUT_TERMINAL 0x02
31#define INPUT_TERMINAL 0x02 31#define UAC_OUTPUT_TERMINAL 0x03
32#define OUTPUT_TERMINAL 0x03 32#define UAC_MIXER_UNIT 0x04
33#define MIXER_UNIT 0x04 33#define UAC_SELECTOR_UNIT 0x05
34#define SELECTOR_UNIT 0x05 34#define UAC_FEATURE_UNIT 0x06
35#define FEATURE_UNIT 0x06 35#define UAC_PROCESSING_UNIT 0x07
36#define PROCESSING_UNIT 0x07 36#define UAC_EXTENSION_UNIT 0x08
37#define EXTENSION_UNIT 0x08 37
38 38/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
39#define AS_GENERAL 0x01 39#define UAC_AS_GENERAL 0x01
40#define FORMAT_TYPE 0x02 40#define UAC_FORMAT_TYPE 0x02
41#define FORMAT_SPECIFIC 0x03 41#define UAC_FORMAT_SPECIFIC 0x03
42 42
43#define EP_GENERAL 0x01 43/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */
44 44#define UAC_EP_GENERAL 0x01
45#define MS_GENERAL 0x01 45
46#define MIDI_IN_JACK 0x02 46/* A.9 Audio Class-Specific Request Codes */
47#define MIDI_OUT_JACK 0x03 47#define UAC_SET_ 0x00
48 48#define UAC_GET_ 0x80
49/* endpoint attributes */ 49
50#define EP_ATTR_MASK 0x0c 50#define UAC__CUR 0x1
51#define EP_ATTR_ASYNC 0x04 51#define UAC__MIN 0x2
52#define EP_ATTR_ADAPTIVE 0x08 52#define UAC__MAX 0x3
53#define EP_ATTR_SYNC 0x0c 53#define UAC__RES 0x4
54 54#define UAC__MEM 0x5
55/* cs endpoint attributes */ 55
56#define EP_CS_ATTR_SAMPLE_RATE 0x01 56#define UAC_SET_CUR (UAC_SET_ | UAC__CUR)
57#define EP_CS_ATTR_PITCH_CONTROL 0x02 57#define UAC_GET_CUR (UAC_GET_ | UAC__CUR)
58#define EP_CS_ATTR_FILL_MAX 0x80 58#define UAC_SET_MIN (UAC_SET_ | UAC__MIN)
59 59#define UAC_GET_MIN (UAC_GET_ | UAC__MIN)
60/* Audio Class specific Request Codes */ 60#define UAC_SET_MAX (UAC_SET_ | UAC__MAX)
61#define USB_AUDIO_SET_INTF 0x21 61#define UAC_GET_MAX (UAC_GET_ | UAC__MAX)
62#define USB_AUDIO_SET_ENDPOINT 0x22 62#define UAC_SET_RES (UAC_SET_ | UAC__RES)
63#define USB_AUDIO_GET_INTF 0xa1 63#define UAC_GET_RES (UAC_GET_ | UAC__RES)
64#define USB_AUDIO_GET_ENDPOINT 0xa2 64#define UAC_SET_MEM (UAC_SET_ | UAC__MEM)
65 65#define UAC_GET_MEM (UAC_GET_ | UAC__MEM)
66#define SET_ 0x00 66
67#define GET_ 0x80 67#define UAC_GET_STAT 0xff
68 68
69#define _CUR 0x1 69/* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
70#define _MIN 0x2 70#define UAC_MS_HEADER 0x01
71#define _MAX 0x3 71#define UAC_MIDI_IN_JACK 0x02
72#define _RES 0x4 72#define UAC_MIDI_OUT_JACK 0x03
73#define _MEM 0x5 73
74 74/* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */
75#define SET_CUR (SET_ | _CUR) 75#define UAC_MS_GENERAL 0x01
76#define GET_CUR (GET_ | _CUR) 76
77#define SET_MIN (SET_ | _MIN) 77/* Terminals - 2.1 USB Terminal Types */
78#define GET_MIN (GET_ | _MIN) 78#define UAC_TERMINAL_UNDEFINED 0x100
79#define SET_MAX (SET_ | _MAX) 79#define UAC_TERMINAL_STREAMING 0x101
80#define GET_MAX (GET_ | _MAX) 80#define UAC_TERMINAL_VENDOR_SPEC 0x1FF
81#define SET_RES (SET_ | _RES)
82#define GET_RES (GET_ | _RES)
83#define SET_MEM (SET_ | _MEM)
84#define GET_MEM (GET_ | _MEM)
85
86#define GET_STAT 0xff
87
88#define USB_AC_TERMINAL_UNDEFINED 0x100
89#define USB_AC_TERMINAL_STREAMING 0x101
90#define USB_AC_TERMINAL_VENDOR_SPEC 0x1FF
91 81
92/* Terminal Control Selectors */ 82/* Terminal Control Selectors */
93/* 4.3.2 Class-Specific AC Interface Descriptor */ 83/* 4.3.2 Class-Specific AC Interface Descriptor */
94struct usb_ac_header_descriptor { 84struct uac_ac_header_descriptor {
95 __u8 bLength; /* 8 + n */ 85 __u8 bLength; /* 8 + n */
96 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 86 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
97 __u8 bDescriptorSubtype; /* USB_MS_HEADER */ 87 __u8 bDescriptorSubtype; /* UAC_MS_HEADER */
98 __le16 bcdADC; /* 0x0100 */ 88 __le16 bcdADC; /* 0x0100 */
99 __le16 wTotalLength; /* includes Unit and Terminal desc. */ 89 __le16 wTotalLength; /* includes Unit and Terminal desc. */
100 __u8 bInCollection; /* n */ 90 __u8 bInCollection; /* n */
101 __u8 baInterfaceNr[]; /* [n] */ 91 __u8 baInterfaceNr[]; /* [n] */
102} __attribute__ ((packed)); 92} __attribute__ ((packed));
103 93
104#define USB_DT_AC_HEADER_SIZE(n) (8 + (n)) 94#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
105 95
106/* As above, but more useful for defining your own descriptors: */ 96/* As above, but more useful for defining your own descriptors: */
107#define DECLARE_USB_AC_HEADER_DESCRIPTOR(n) \ 97#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
108struct usb_ac_header_descriptor_##n { \ 98struct uac_ac_header_descriptor_##n { \
109 __u8 bLength; \ 99 __u8 bLength; \
110 __u8 bDescriptorType; \ 100 __u8 bDescriptorType; \
111 __u8 bDescriptorSubtype; \ 101 __u8 bDescriptorSubtype; \
@@ -116,7 +106,7 @@ struct usb_ac_header_descriptor_##n { \
116} __attribute__ ((packed)) 106} __attribute__ ((packed))
117 107
118/* 4.3.2.1 Input Terminal Descriptor */ 108/* 4.3.2.1 Input Terminal Descriptor */
119struct usb_input_terminal_descriptor { 109struct uac_input_terminal_descriptor {
120 __u8 bLength; /* in bytes: 12 */ 110 __u8 bLength; /* in bytes: 12 */
121 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 111 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
122 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */ 112 __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */
@@ -129,18 +119,19 @@ struct usb_input_terminal_descriptor {
129 __u8 iTerminal; 119 __u8 iTerminal;
130} __attribute__ ((packed)); 120} __attribute__ ((packed));
131 121
132#define USB_DT_AC_INPUT_TERMINAL_SIZE 12 122#define UAC_DT_INPUT_TERMINAL_SIZE 12
133 123
134#define USB_AC_INPUT_TERMINAL_UNDEFINED 0x200 124/* Terminals - 2.2 Input Terminal Types */
135#define USB_AC_INPUT_TERMINAL_MICROPHONE 0x201 125#define UAC_INPUT_TERMINAL_UNDEFINED 0x200
136#define USB_AC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202 126#define UAC_INPUT_TERMINAL_MICROPHONE 0x201
137#define USB_AC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203 127#define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202
138#define USB_AC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204 128#define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203
139#define USB_AC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205 129#define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204
140#define USB_AC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206 130#define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205
131#define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206
141 132
142/* 4.3.2.2 Output Terminal Descriptor */ 133/* 4.3.2.2 Output Terminal Descriptor */
143struct usb_output_terminal_descriptor { 134struct uac_output_terminal_descriptor {
144 __u8 bLength; /* in bytes: 9 */ 135 __u8 bLength; /* in bytes: 9 */
145 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 136 __u8 bDescriptorType; /* CS_INTERFACE descriptor type */
146 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */ 137 __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */
@@ -151,23 +142,24 @@ struct usb_output_terminal_descriptor {
151 __u8 iTerminal; 142 __u8 iTerminal;
152} __attribute__ ((packed)); 143} __attribute__ ((packed));
153 144
154#define USB_DT_AC_OUTPUT_TERMINAL_SIZE 9 145#define UAC_DT_OUTPUT_TERMINAL_SIZE 9
155 146
156#define USB_AC_OUTPUT_TERMINAL_UNDEFINED 0x300 147/* Terminals - 2.3 Output Terminal Types */
157#define USB_AC_OUTPUT_TERMINAL_SPEAKER 0x301 148#define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300
158#define USB_AC_OUTPUT_TERMINAL_HEADPHONES 0x302 149#define UAC_OUTPUT_TERMINAL_SPEAKER 0x301
159#define USB_AC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303 150#define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302
160#define USB_AC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304 151#define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303
161#define USB_AC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305 152#define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304
162#define USB_AC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306 153#define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305
163#define USB_AC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307 154#define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306
155#define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307
164 156
165/* Set bControlSize = 2 as default setting */ 157/* Set bControlSize = 2 as default setting */
166#define USB_DT_AC_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) 158#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
167 159
168/* As above, but more useful for defining your own descriptors: */ 160/* As above, but more useful for defining your own descriptors: */
169#define DECLARE_USB_AC_FEATURE_UNIT_DESCRIPTOR(ch) \ 161#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
170struct usb_ac_feature_unit_descriptor_##ch { \ 162struct uac_feature_unit_descriptor_##ch { \
171 __u8 bLength; \ 163 __u8 bLength; \
172 __u8 bDescriptorType; \ 164 __u8 bDescriptorType; \
173 __u8 bDescriptorSubtype; \ 165 __u8 bDescriptorSubtype; \
@@ -179,7 +171,7 @@ struct usb_ac_feature_unit_descriptor_##ch { \
179} __attribute__ ((packed)) 171} __attribute__ ((packed))
180 172
181/* 4.5.2 Class-Specific AS Interface Descriptor */ 173/* 4.5.2 Class-Specific AS Interface Descriptor */
182struct usb_as_header_descriptor { 174struct uac_as_header_descriptor {
183 __u8 bLength; /* in bytes: 7 */ 175 __u8 bLength; /* in bytes: 7 */
184 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 176 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
185 __u8 bDescriptorSubtype; /* AS_GENERAL */ 177 __u8 bDescriptorSubtype; /* AS_GENERAL */
@@ -188,16 +180,17 @@ struct usb_as_header_descriptor {
188 __le16 wFormatTag; /* The Audio Data Format */ 180 __le16 wFormatTag; /* The Audio Data Format */
189} __attribute__ ((packed)); 181} __attribute__ ((packed));
190 182
191#define USB_DT_AS_HEADER_SIZE 7 183#define UAC_DT_AS_HEADER_SIZE 7
192 184
193#define USB_AS_AUDIO_FORMAT_TYPE_I_UNDEFINED 0x0 185/* Formats - A.1.1 Audio Data Format Type I Codes */
194#define USB_AS_AUDIO_FORMAT_TYPE_I_PCM 0x1 186#define UAC_FORMAT_TYPE_I_UNDEFINED 0x0
195#define USB_AS_AUDIO_FORMAT_TYPE_I_PCM8 0x2 187#define UAC_FORMAT_TYPE_I_PCM 0x1
196#define USB_AS_AUDIO_FORMAT_TYPE_I_IEEE_FLOAT 0x3 188#define UAC_FORMAT_TYPE_I_PCM8 0x2
197#define USB_AS_AUDIO_FORMAT_TYPE_I_ALAW 0x4 189#define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3
198#define USB_AS_AUDIO_FORMAT_TYPE_I_MULAW 0x5 190#define UAC_FORMAT_TYPE_I_ALAW 0x4
191#define UAC_FORMAT_TYPE_I_MULAW 0x5
199 192
200struct usb_as_format_type_i_continuous_descriptor { 193struct uac_format_type_i_continuous_descriptor {
201 __u8 bLength; /* in bytes: 8 + (ns * 3) */ 194 __u8 bLength; /* in bytes: 8 + (ns * 3) */
202 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 195 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
203 __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 196 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
@@ -210,9 +203,9 @@ struct usb_as_format_type_i_continuous_descriptor {
210 __u8 tUpperSamFreq[3]; 203 __u8 tUpperSamFreq[3];
211} __attribute__ ((packed)); 204} __attribute__ ((packed));
212 205
213#define USB_AS_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14 206#define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14
214 207
215struct usb_as_formate_type_i_discrete_descriptor { 208struct uac_format_type_i_discrete_descriptor {
216 __u8 bLength; /* in bytes: 8 + (ns * 3) */ 209 __u8 bLength; /* in bytes: 8 + (ns * 3) */
217 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 210 __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */
218 __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 211 __u8 bDescriptorSubtype; /* FORMAT_TYPE */
@@ -224,8 +217,8 @@ struct usb_as_formate_type_i_discrete_descriptor {
224 __u8 tSamFreq[][3]; 217 __u8 tSamFreq[][3];
225} __attribute__ ((packed)); 218} __attribute__ ((packed));
226 219
227#define DECLARE_USB_AS_FORMAT_TYPE_I_DISCRETE_DESC(n) \ 220#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
228struct usb_as_formate_type_i_discrete_descriptor_##n { \ 221struct uac_format_type_i_discrete_descriptor_##n { \
229 __u8 bLength; \ 222 __u8 bLength; \
230 __u8 bDescriptorType; \ 223 __u8 bDescriptorType; \
231 __u8 bDescriptorSubtype; \ 224 __u8 bDescriptorSubtype; \
@@ -237,18 +230,15 @@ struct usb_as_formate_type_i_discrete_descriptor_##n { \
237 __u8 tSamFreq[n][3]; \ 230 __u8 tSamFreq[n][3]; \
238} __attribute__ ((packed)) 231} __attribute__ ((packed))
239 232
240#define USB_AS_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3)) 233#define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3))
241
242#define USB_AS_FORMAT_TYPE_UNDEFINED 0x0
243#define USB_AS_FORMAT_TYPE_I 0x1
244#define USB_AS_FORMAT_TYPE_II 0x2
245#define USB_AS_FORMAT_TYPE_III 0x3
246 234
247#define USB_AS_ENDPOINT_ASYNC (1 << 2) 235/* Formats - A.2 Format Type Codes */
248#define USB_AS_ENDPOINT_ADAPTIVE (2 << 2) 236#define UAC_FORMAT_TYPE_UNDEFINED 0x0
249#define USB_AS_ENDPOINT_SYNC (3 << 2) 237#define UAC_FORMAT_TYPE_I 0x1
238#define UAC_FORMAT_TYPE_II 0x2
239#define UAC_FORMAT_TYPE_III 0x3
250 240
251struct usb_as_iso_endpoint_descriptor { 241struct uac_iso_endpoint_descriptor {
252 __u8 bLength; /* in bytes: 7 */ 242 __u8 bLength; /* in bytes: 7 */
253 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ 243 __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */
254 __u8 bDescriptorSubtype; /* EP_GENERAL */ 244 __u8 bDescriptorSubtype; /* EP_GENERAL */
@@ -256,30 +246,37 @@ struct usb_as_iso_endpoint_descriptor {
256 __u8 bLockDelayUnits; 246 __u8 bLockDelayUnits;
257 __le16 wLockDelay; 247 __le16 wLockDelay;
258}; 248};
259#define USB_AS_ISO_ENDPOINT_DESC_SIZE 7 249#define UAC_ISO_ENDPOINT_DESC_SIZE 7
260 250
261#define FU_CONTROL_UNDEFINED 0x00 251#define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01
262#define MUTE_CONTROL 0x01 252#define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02
263#define VOLUME_CONTROL 0x02 253#define UAC_EP_CS_ATTR_FILL_MAX 0x80
264#define BASS_CONTROL 0x03 254
265#define MID_CONTROL 0x04 255/* A.10.2 Feature Unit Control Selectors */
266#define TREBLE_CONTROL 0x05 256#define UAC_FU_CONTROL_UNDEFINED 0x00
267#define GRAPHIC_EQUALIZER_CONTROL 0x06 257#define UAC_MUTE_CONTROL 0x01
268#define AUTOMATIC_GAIN_CONTROL 0x07 258#define UAC_VOLUME_CONTROL 0x02
269#define DELAY_CONTROL 0x08 259#define UAC_BASS_CONTROL 0x03
270#define BASS_BOOST_CONTROL 0x09 260#define UAC_MID_CONTROL 0x04
271#define LOUDNESS_CONTROL 0x0a 261#define UAC_TREBLE_CONTROL 0x05
272 262#define UAC_GRAPHIC_EQUALIZER_CONTROL 0x06
273#define FU_MUTE (1 << (MUTE_CONTROL - 1)) 263#define UAC_AUTOMATIC_GAIN_CONTROL 0x07
274#define FU_VOLUME (1 << (VOLUME_CONTROL - 1)) 264#define UAC_DELAY_CONTROL 0x08
275#define FU_BASS (1 << (BASS_CONTROL - 1)) 265#define UAC_BASS_BOOST_CONTROL 0x09
276#define FU_MID (1 << (MID_CONTROL - 1)) 266#define UAC_LOUDNESS_CONTROL 0x0a
277#define FU_TREBLE (1 << (TREBLE_CONTROL - 1)) 267
278#define FU_GRAPHIC_EQ (1 << (GRAPHIC_EQUALIZER_CONTROL - 1)) 268#define UAC_FU_MUTE (1 << (UAC_MUTE_CONTROL - 1))
279#define FU_AUTO_GAIN (1 << (AUTOMATIC_GAIN_CONTROL - 1)) 269#define UAC_FU_VOLUME (1 << (UAC_VOLUME_CONTROL - 1))
280#define FU_DELAY (1 << (DELAY_CONTROL - 1)) 270#define UAC_FU_BASS (1 << (UAC_BASS_CONTROL - 1))
281#define FU_BASS_BOOST (1 << (BASS_BOOST_CONTROL - 1)) 271#define UAC_FU_MID (1 << (UAC_MID_CONTROL - 1))
282#define FU_LOUDNESS (1 << (LOUDNESS_CONTROL - 1)) 272#define UAC_FU_TREBLE (1 << (UAC_TREBLE_CONTROL - 1))
273#define UAC_FU_GRAPHIC_EQ (1 << (UAC_GRAPHIC_EQUALIZER_CONTROL - 1))
274#define UAC_FU_AUTO_GAIN (1 << (UAC_AUTOMATIC_GAIN_CONTROL - 1))
275#define UAC_FU_DELAY (1 << (UAC_DELAY_CONTROL - 1))
276#define UAC_FU_BASS_BOOST (1 << (UAC_BASS_BOOST_CONTROL - 1))
277#define UAC_FU_LOUDNESS (1 << (UAC_LOUDNESS_CONTROL - 1))
278
279#ifdef __KERNEL__
283 280
284struct usb_audio_control { 281struct usb_audio_control {
285 struct list_head list; 282 struct list_head list;
@@ -290,18 +287,6 @@ struct usb_audio_control {
290 int (*get)(struct usb_audio_control *con, u8 cmd); 287 int (*get)(struct usb_audio_control *con, u8 cmd);
291}; 288};
292 289
293static inline int generic_set_cmd(struct usb_audio_control *con, u8 cmd, int value)
294{
295 con->data[cmd] = value;
296
297 return 0;
298}
299
300static inline int generic_get_cmd(struct usb_audio_control *con, u8 cmd)
301{
302 return con->data[cmd];
303}
304
305struct usb_audio_control_selector { 290struct usb_audio_control_selector {
306 struct list_head list; 291 struct list_head list;
307 struct list_head control; 292 struct list_head control;
@@ -311,4 +296,6 @@ struct usb_audio_control_selector {
311 struct usb_descriptor_header *desc; 296 struct usb_descriptor_header *desc;
312}; 297};
313 298
299#endif /* __KERNEL__ */
300
314#endif /* __LINUX_USB_AUDIO_H */ 301#endif /* __LINUX_USB_AUDIO_H */
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 93223638f702..94012e649d86 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -258,6 +258,8 @@ struct usb_device_descriptor {
258#define USB_CLASS_APP_SPEC 0xfe 258#define USB_CLASS_APP_SPEC 0xfe
259#define USB_CLASS_VENDOR_SPEC 0xff 259#define USB_CLASS_VENDOR_SPEC 0xff
260 260
261#define USB_SUBCLASS_VENDOR_SPEC 0xff
262
261/*-------------------------------------------------------------------------*/ 263/*-------------------------------------------------------------------------*/
262 264
263/* USB_DT_CONFIG: Configuration descriptor information. 265/* USB_DT_CONFIG: Configuration descriptor information.
@@ -348,6 +350,12 @@ struct usb_endpoint_descriptor {
348#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ 350#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
349#define USB_ENDPOINT_DIR_MASK 0x80 351#define USB_ENDPOINT_DIR_MASK 0x80
350 352
353#define USB_ENDPOINT_SYNCTYPE 0x0c
354#define USB_ENDPOINT_SYNC_NONE (0 << 2)
355#define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
356#define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
357#define USB_ENDPOINT_SYNC_SYNC (3 << 2)
358
351#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ 359#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
352#define USB_ENDPOINT_XFER_CONTROL 0 360#define USB_ENDPOINT_XFER_CONTROL 0
353#define USB_ENDPOINT_XFER_ISOC 1 361#define USB_ENDPOINT_XFER_ISOC 1
diff --git a/include/linux/usb/ehci_def.h b/include/linux/usb/ehci_def.h
index 5b88e36c9103..af4b86f3aca3 100644
--- a/include/linux/usb/ehci_def.h
+++ b/include/linux/usb/ehci_def.h
@@ -105,6 +105,7 @@ struct ehci_regs {
105#define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ 105#define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */
106#define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */ 106#define PORT_WKCONN_E (1<<20) /* wake on connect (enable) */
107/* 19:16 for port testing */ 107/* 19:16 for port testing */
108#define PORT_TEST_PKT (0x4<<16) /* Port Test Control - packet test */
108#define PORT_LED_OFF (0<<14) 109#define PORT_LED_OFF (0<<14)
109#define PORT_LED_AMBER (1<<14) 110#define PORT_LED_AMBER (1<<14)
110#define PORT_LED_GREEN (2<<14) 111#define PORT_LED_GREEN (2<<14)
@@ -132,6 +133,19 @@ struct ehci_regs {
132#define USBMODE_CM_HC (3<<0) /* host controller mode */ 133#define USBMODE_CM_HC (3<<0) /* host controller mode */
133#define USBMODE_CM_IDLE (0<<0) /* idle state */ 134#define USBMODE_CM_IDLE (0<<0) /* idle state */
134 135
136/* Moorestown has some non-standard registers, partially due to the fact that
137 * its EHCI controller has both TT and LPM support. HOSTPCx are extentions to
138 * PORTSCx
139 */
140#define HOSTPC0 0x84 /* HOSTPC extension */
141#define HOSTPC_PHCD (1<<22) /* Phy clock disable */
142#define HOSTPC_PSPD (3<<25) /* Port speed detection */
143#define USBMODE_EX 0xc8 /* USB Device mode extension */
144#define USBMODE_EX_VBPS (1<<5) /* VBus Power Select On */
145#define USBMODE_EX_HC (3<<0) /* host controller mode */
146#define TXFILLTUNING 0x24 /* TX FIFO Tuning register */
147#define TXFIFO_DEFAULT (8<<16) /* FIFO burst threshold 8 */
148
135/* Appendix C, Debug port ... intended for use with special "debug devices" 149/* Appendix C, Debug port ... intended for use with special "debug devices"
136 * that can help if there's no serial console. (nonstandard enumeration.) 150 * that can help if there's no serial console. (nonstandard enumeration.)
137 */ 151 */
@@ -157,4 +171,25 @@ struct ehci_dbg_port {
157#define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep)) 171#define DBGP_EPADDR(dev, ep) (((dev)<<8)|(ep))
158} __attribute__ ((packed)); 172} __attribute__ ((packed));
159 173
174#ifdef CONFIG_EARLY_PRINTK_DBGP
175#include <linux/init.h>
176extern int __init early_dbgp_init(char *s);
177extern struct console early_dbgp_console;
178#endif /* CONFIG_EARLY_PRINTK_DBGP */
179
180#ifdef CONFIG_EARLY_PRINTK_DBGP
181/* Call backs from ehci host driver to ehci debug driver */
182extern int dbgp_external_startup(void);
183extern int dbgp_reset_prep(void);
184#else
185static inline int dbgp_reset_prep(void)
186{
187 return 1;
188}
189static inline int dbgp_external_startup(void)
190{
191 return -1;
192}
193#endif
194
160#endif /* __LINUX_USB_EHCI_DEF_H */ 195#endif /* __LINUX_USB_EHCI_DEF_H */
diff --git a/include/linux/usb/isp1362.h b/include/linux/usb/isp1362.h
new file mode 100644
index 000000000000..642684bb9292
--- /dev/null
+++ b/include/linux/usb/isp1362.h
@@ -0,0 +1,46 @@
1/*
2 * board initialization code should put one of these into dev->platform_data
3 * and place the isp1362 onto platform_bus.
4 */
5
6#ifndef __LINUX_USB_ISP1362_H__
7#define __LINUX_USB_ISP1362_H__
8
9struct isp1362_platform_data {
10 /* Enable internal pulldown resistors on downstream ports */
11 unsigned sel15Kres:1;
12 /* Clock cannot be stopped */
13 unsigned clknotstop:1;
14 /* On-chip overcurrent protection */
15 unsigned oc_enable:1;
16 /* INT output polarity */
17 unsigned int_act_high:1;
18 /* INT edge or level triggered */
19 unsigned int_edge_triggered:1;
20 /* DREQ output polarity */
21 unsigned dreq_act_high:1;
22 /* DACK input polarity */
23 unsigned dack_act_high:1;
24 /* chip can be resumed via H_WAKEUP pin */
25 unsigned remote_wakeup_connected:1;
26 /* Switch or not to switch (keep always powered) */
27 unsigned no_power_switching:1;
28 /* Ganged port power switching (0) or individual port power switching (1) */
29 unsigned power_switching_mode:1;
30 /* Given port_power, msec/2 after power on till power good */
31 u8 potpg;
32 /* Hardware reset set/clear */
33 void (*reset) (struct device *dev, int set);
34 /* Clock start/stop */
35 void (*clock) (struct device *dev, int start);
36 /* Inter-io delay (ns). The chip is picky about access timings; it
37 * expects at least:
38 * 110ns delay between consecutive accesses to DATA_REG,
39 * 300ns delay between access to ADDR_REG and DATA_REG (registers)
40 * 462ns delay between access to ADDR_REG and DATA_REG (buffer memory)
41 * WE MUST NOT be activated during these intervals (even without CS!)
42 */
43 void (*delay) (struct device *dev, unsigned int delay);
44};
45
46#endif
diff --git a/include/linux/usb/isp1760.h b/include/linux/usb/isp1760.h
new file mode 100644
index 000000000000..de7de53c5531
--- /dev/null
+++ b/include/linux/usb/isp1760.h
@@ -0,0 +1,18 @@
1/*
2 * board initialization should put one of these into dev->platform_data
3 * and place the isp1760 onto platform_bus named "isp1760-hcd".
4 */
5
6#ifndef __LINUX_USB_ISP1760_H
7#define __LINUX_USB_ISP1760_H
8
9struct isp1760_platform_data {
10 unsigned is_isp1761:1; /* Chip is ISP1761 */
11 unsigned bus_width_16:1; /* 16/32-bit data bus width */
12 unsigned port1_otg:1; /* Port 1 supports OTG */
13 unsigned analog_oc:1; /* Analog overcurrent */
14 unsigned dack_polarity_high:1; /* DACK active high */
15 unsigned dreq_polarity_high:1; /* DREQ active high */
16};
17
18#endif /* __LINUX_USB_ISP1760_H */
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 7b85e327af91..c17eb64d7213 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -59,6 +59,7 @@ enum port_dev_state {
59 * @bulk_out_buffer: pointer to the bulk out buffer for this port. 59 * @bulk_out_buffer: pointer to the bulk out buffer for this port.
60 * @bulk_out_size: the size of the bulk_out_buffer, in bytes. 60 * @bulk_out_size: the size of the bulk_out_buffer, in bytes.
61 * @write_urb: pointer to the bulk out struct urb for this port. 61 * @write_urb: pointer to the bulk out struct urb for this port.
62 * @write_fifo: kfifo used to buffer outgoing data
62 * @write_urb_busy: port`s writing status 63 * @write_urb_busy: port`s writing status
63 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this 64 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this
64 * port. 65 * port.
@@ -96,6 +97,7 @@ struct usb_serial_port {
96 unsigned char *bulk_out_buffer; 97 unsigned char *bulk_out_buffer;
97 int bulk_out_size; 98 int bulk_out_size;
98 struct urb *write_urb; 99 struct urb *write_urb;
100 struct kfifo *write_fifo;
99 int write_urb_busy; 101 int write_urb_busy;
100 __u8 bulk_out_endpointAddress; 102 __u8 bulk_out_endpointAddress;
101 103
diff --git a/include/linux/usbdevice_fs.h b/include/linux/usbdevice_fs.h
index 0044d9b4cb85..b2a7d8ba6ee3 100644
--- a/include/linux/usbdevice_fs.h
+++ b/include/linux/usbdevice_fs.h
@@ -77,6 +77,7 @@ struct usbdevfs_connectinfo {
77 77
78#define USBDEVFS_URB_SHORT_NOT_OK 0x01 78#define USBDEVFS_URB_SHORT_NOT_OK 0x01
79#define USBDEVFS_URB_ISO_ASAP 0x02 79#define USBDEVFS_URB_ISO_ASAP 0x02
80#define USBDEVFS_URB_BULK_CONTINUATION 0x04
80#define USBDEVFS_URB_NO_FSBR 0x20 81#define USBDEVFS_URB_NO_FSBR 0x20
81#define USBDEVFS_URB_ZERO_PACKET 0x40 82#define USBDEVFS_URB_ZERO_PACKET 0x40
82#define USBDEVFS_URB_NO_INTERRUPT 0x80 83#define USBDEVFS_URB_NO_INTERRUPT 0x80
@@ -175,4 +176,6 @@ struct usbdevfs_ioctl32 {
175#define USBDEVFS_CLEAR_HALT _IOR('U', 21, unsigned int) 176#define USBDEVFS_CLEAR_HALT _IOR('U', 21, unsigned int)
176#define USBDEVFS_DISCONNECT _IO('U', 22) 177#define USBDEVFS_DISCONNECT _IO('U', 22)
177#define USBDEVFS_CONNECT _IO('U', 23) 178#define USBDEVFS_CONNECT _IO('U', 23)
179#define USBDEVFS_CLAIM_PORT _IOR('U', 24, unsigned int)
180#define USBDEVFS_RELEASE_PORT _IOR('U', 25, unsigned int)
178#endif /* _LINUX_USBDEVICE_FS_H */ 181#endif /* _LINUX_USBDEVICE_FS_H */