aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-05-21 00:26:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-21 00:26:12 -0400
commit7a9b149212f3716c598afe973b6261fd58453b7a (patch)
tree477716d84c71da124448b72278e98da28aadbd3d
parent3d62e3fdce8ef265a3706c52ae1ca6ab84e30f0e (diff)
parente26bcf37234c67624f62d9fc95f922b8dbda1363 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6: (229 commits) USB: remove unused usb_buffer_alloc and usb_buffer_free macros usb: musb: update gfp/slab.h includes USB: ftdi_sio: fix legacy SIO-device header USB: kl5usb105: reimplement using generic framework USB: kl5usb105: minor clean ups USB: kl5usb105: fix memory leak USB: io_ti: use kfifo to implement write buffering USB: io_ti: remove unsused private counter USB: ti_usb: use kfifo to implement write buffering USB: ir-usb: fix incorrect write-buffer length USB: aircable: fix incorrect write-buffer length USB: safe_serial: straighten out read processing USB: safe_serial: reimplement read using generic framework USB: safe_serial: reimplement write using generic framework usb-storage: always print quirks USB: usb-storage: trivial debug improvements USB: oti6858: use port write fifo USB: oti6858: use kfifo to implement write buffering USB: cypress_m8: use kfifo to implement write buffering USB: cypress_m8: remove unused drain define ... Fix up conflicts (due to usb_buffer_alloc/free renaming) in drivers/input/tablet/acecad.c drivers/input/tablet/kbtab.c drivers/input/tablet/wacom_sys.c drivers/media/video/gspca/gspca.c sound/usb/usbaudio.c
-rw-r--r--Documentation/ABI/obsolete/sysfs-bus-usb31
-rw-r--r--Documentation/ABI/testing/sysfs-bus-usb28
-rw-r--r--Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget9
-rw-r--r--Documentation/DocBook/writing_usb_driver.tmpl2
-rw-r--r--Documentation/usb/bulk-streams.txt78
-rw-r--r--Documentation/usb/dma.txt22
-rw-r--r--Documentation/usb/gadget_hid.txt445
-rw-r--r--Documentation/usb/power-management.txt19
-rw-r--r--Documentation/usb/usb-serial.txt29
-rw-r--r--arch/arm/mach-omap2/board-omap3evm.c3
-rw-r--r--arch/arm/mach-omap2/usb-ehci.c155
-rw-r--r--arch/arm/mach-omap2/usb-musb.c1
-rw-r--r--arch/arm/plat-omap/include/plat/usb.h24
-rw-r--r--drivers/hid/usbhid/hid-core.c20
-rw-r--r--drivers/hid/usbhid/usbhid.h1
-rw-r--r--drivers/hid/usbhid/usbkbd.c16
-rw-r--r--drivers/hid/usbhid/usbmouse.c6
-rw-r--r--drivers/input/joystick/xpad.c16
-rw-r--r--drivers/input/misc/ati_remote.c12
-rw-r--r--drivers/input/misc/ati_remote2.c4
-rw-r--r--drivers/input/misc/cm109.c28
-rw-r--r--drivers/input/misc/keyspan_remote.c6
-rw-r--r--drivers/input/misc/powermate.c17
-rw-r--r--drivers/input/misc/yealink.c25
-rw-r--r--drivers/input/mouse/appletouch.c12
-rw-r--r--drivers/input/mouse/bcm5974.c24
-rw-r--r--drivers/input/tablet/acecad.c6
-rw-r--r--drivers/input/tablet/aiptek.c14
-rw-r--r--drivers/input/tablet/gtco.c12
-rw-r--r--drivers/input/tablet/kbtab.c6
-rw-r--r--drivers/input/tablet/wacom_sys.c8
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c8
-rw-r--r--drivers/media/dvb/dvb-usb/usb-urb.c7
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c6
-rw-r--r--drivers/media/video/au0828/au0828-video.c4
-rw-r--r--drivers/media/video/cx231xx/cx231xx-core.c14
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c4
-rw-r--r--drivers/media/video/gspca/benq.c4
-rw-r--r--drivers/media/video/gspca/gspca.c30
-rw-r--r--drivers/media/video/hdpvr/hdpvr-video.c8
-rw-r--r--drivers/media/video/tlg2300/pd-main.c2
-rw-r--r--drivers/media/video/tlg2300/pd-video.c14
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c16
-rw-r--r--drivers/media/video/uvc/uvc_video.c4
-rw-r--r--drivers/net/can/usb/ems_usb.c18
-rw-r--r--drivers/net/usb/ipheth.c24
-rw-r--r--drivers/net/usb/kaweth.c12
-rw-r--r--drivers/net/wimax/i2400m/usb.c2
-rw-r--r--drivers/net/wireless/ath/ar9170/usb.c8
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c10
-rw-r--r--drivers/staging/rt2860/iface/rtmp_usb.h4
-rw-r--r--drivers/staging/udlfb/udlfb.c8
-rw-r--r--drivers/staging/usbip/stub_rx.c2
-rw-r--r--drivers/staging/usbip/usbip_common.c2
-rw-r--r--drivers/staging/usbip/vhci.h2
-rw-r--r--drivers/usb/atm/ueagle-atm.c347
-rw-r--r--drivers/usb/c67x00/c67x00-hcd.h2
-rw-r--r--drivers/usb/class/cdc-acm.c22
-rw-r--r--drivers/usb/class/cdc-acm.h4
-rw-r--r--drivers/usb/class/cdc-wdm.c38
-rw-r--r--drivers/usb/class/usblp.c2
-rw-r--r--drivers/usb/core/buffer.c2
-rw-r--r--drivers/usb/core/config.c214
-rw-r--r--drivers/usb/core/devices.c19
-rw-r--r--drivers/usb/core/devio.c3
-rw-r--r--drivers/usb/core/driver.c60
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hcd-pci.c2
-rw-r--r--drivers/usb/core/hcd.c246
-rw-r--r--drivers/usb/core/hub.c30
-rw-r--r--drivers/usb/core/inode.c2
-rw-r--r--drivers/usb/core/message.c133
-rw-r--r--drivers/usb/core/quirks.c4
-rw-r--r--drivers/usb/core/sysfs.c22
-rw-r--r--drivers/usb/core/urb.c18
-rw-r--r--drivers/usb/core/usb.c94
-rw-r--r--drivers/usb/gadget/Kconfig58
-rw-r--r--drivers/usb/gadget/Makefile8
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c3
-rw-r--r--drivers/usb/gadget/composite.c60
-rw-r--r--drivers/usb/gadget/config.c4
-rw-r--r--drivers/usb/gadget/dummy_hcd.c4
-rw-r--r--drivers/usb/gadget/epautoconf.c12
-rw-r--r--drivers/usb/gadget/f_acm.c32
-rw-r--r--drivers/usb/gadget/f_ecm.c33
-rw-r--r--drivers/usb/gadget/f_fs.c2442
-rw-r--r--drivers/usb/gadget/f_hid.c673
-rw-r--r--drivers/usb/gadget/f_mass_storage.c138
-rw-r--r--drivers/usb/gadget/f_rndis.c33
-rw-r--r--drivers/usb/gadget/f_uvc.c661
-rw-r--r--drivers/usb/gadget/f_uvc.h376
-rw-r--r--drivers/usb/gadget/fsl_mxc_udc.c (renamed from drivers/usb/gadget/fsl_mx3_udc.c)14
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c2
-rw-r--r--drivers/usb/gadget/g_ffs.c426
-rw-r--r--drivers/usb/gadget/hid.c298
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h2
-rw-r--r--drivers/usb/gadget/u_ether.c4
-rw-r--r--drivers/usb/gadget/uvc.h241
-rw-r--r--drivers/usb/gadget/uvc_queue.c583
-rw-r--r--drivers/usb/gadget/uvc_queue.h89
-rw-r--r--drivers/usb/gadget/uvc_v4l2.c374
-rw-r--r--drivers/usb/gadget/uvc_video.c386
-rw-r--r--drivers/usb/gadget/webcam.c399
-rw-r--r--drivers/usb/host/Kconfig15
-rw-r--r--drivers/usb/host/ehci-au1xxx.c27
-rw-r--r--drivers/usb/host/ehci-fsl.c2
-rw-r--r--drivers/usb/host/ehci-hcd.c3
-rw-r--r--drivers/usb/host/ehci-hub.c182
-rw-r--r--drivers/usb/host/ehci-omap.c21
-rw-r--r--drivers/usb/host/ehci-pci.c18
-rw-r--r--drivers/usb/host/ehci-q.c2
-rw-r--r--drivers/usb/host/ehci.h18
-rw-r--r--drivers/usb/host/fhci-dbg.c2
-rw-r--r--drivers/usb/host/fhci-hcd.c2
-rw-r--r--drivers/usb/host/fhci-hub.c2
-rw-r--r--drivers/usb/host/fhci-mem.c2
-rw-r--r--drivers/usb/host/fhci-q.c2
-rw-r--r--drivers/usb/host/fhci-sched.c2
-rw-r--r--drivers/usb/host/fhci-tds.c2
-rw-r--r--drivers/usb/host/fhci.h11
-rw-r--r--drivers/usb/host/imx21-hcd.c2
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/isp1362-hcd.c6
-rw-r--r--drivers/usb/host/isp1760-hcd.c29
-rw-r--r--drivers/usb/host/isp1760-if.c13
-rw-r--r--drivers/usb/host/ohci-hcd.c33
-rw-r--r--drivers/usb/host/ohci-omap3.c735
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c31
-rw-r--r--drivers/usb/host/r8a66597-hcd.c39
-rw-r--r--drivers/usb/host/sl811-hcd.c60
-rw-r--r--drivers/usb/host/u132-hcd.c6
-rw-r--r--drivers/usb/host/uhci-hcd.c2
-rw-r--r--drivers/usb/host/whci/debug.c2
-rw-r--r--drivers/usb/host/whci/qset.c6
-rw-r--r--drivers/usb/host/xhci-dbg.c24
-rw-r--r--drivers/usb/host/xhci-hub.c39
-rw-r--r--drivers/usb/host/xhci-mem.c489
-rw-r--r--drivers/usb/host/xhci-pci.c8
-rw-r--r--drivers/usb/host/xhci-ring.c329
-rw-r--r--drivers/usb/host/xhci.c416
-rw-r--r--drivers/usb/host/xhci.h112
-rw-r--r--drivers/usb/misc/appledisplay.c6
-rw-r--r--drivers/usb/misc/ftdi-elan.c20
-rw-r--r--drivers/usb/misc/iowarrior.c12
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c13
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_con.c8
-rw-r--r--drivers/usb/misc/usblcd.c8
-rw-r--r--drivers/usb/misc/usbtest.c17
-rw-r--r--drivers/usb/mon/mon_bin.c4
-rw-r--r--drivers/usb/mon/mon_main.c3
-rw-r--r--drivers/usb/mon/mon_text.c6
-rw-r--r--drivers/usb/musb/Kconfig6
-rw-r--r--drivers/usb/musb/Makefile14
-rw-r--r--drivers/usb/musb/blackfin.c96
-rw-r--r--drivers/usb/musb/davinci.c2
-rw-r--r--drivers/usb/musb/musb_core.c147
-rw-r--r--drivers/usb/musb/musb_core.h10
-rw-r--r--drivers/usb/musb/musb_debug.h13
-rw-r--r--drivers/usb/musb/musb_debugfs.c294
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c25
-rw-r--r--drivers/usb/musb/musb_regs.h10
-rw-r--r--drivers/usb/musb/musb_virthub.c4
-rw-r--r--drivers/usb/musb/musbhsdma.h16
-rw-r--r--drivers/usb/musb/omap2430.c29
-rw-r--r--drivers/usb/musb/tusb6010.c2
-rw-r--r--drivers/usb/otg/isp1301_omap.c2
-rw-r--r--drivers/usb/otg/twl4030-usb.c108
-rw-r--r--drivers/usb/otg/ulpi.c50
-rw-r--r--drivers/usb/serial/Kconfig23
-rw-r--r--drivers/usb/serial/Makefile2
-rw-r--r--drivers/usb/serial/aircable.c499
-rw-r--r--drivers/usb/serial/ark3116.c111
-rw-r--r--drivers/usb/serial/belkin_sa.c130
-rw-r--r--drivers/usb/serial/belkin_sa.h10
-rw-r--r--drivers/usb/serial/ch341.c5
-rw-r--r--drivers/usb/serial/console.c27
-rw-r--r--drivers/usb/serial/cp210x.c63
-rw-r--r--drivers/usb/serial/cypress_m8.c242
-rw-r--r--drivers/usb/serial/cypress_m8.h53
-rw-r--r--drivers/usb/serial/digi_acceleport.c4
-rw-r--r--drivers/usb/serial/empeg.c401
-rw-r--r--drivers/usb/serial/ftdi_sio.c457
-rw-r--r--drivers/usb/serial/ftdi_sio.h126
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h42
-rw-r--r--drivers/usb/serial/generic.c330
-rw-r--r--drivers/usb/serial/io_edgeport.c3
-rw-r--r--drivers/usb/serial/io_edgeport.h16
-rw-r--r--drivers/usb/serial/io_ionsp.h95
-rw-r--r--drivers/usb/serial/io_ti.c228
-rw-r--r--drivers/usb/serial/io_ti.h92
-rw-r--r--drivers/usb/serial/io_usbvend.h87
-rw-r--r--drivers/usb/serial/ipaq.c357
-rw-r--r--drivers/usb/serial/ipaq.h54
-rw-r--r--drivers/usb/serial/ipw.c184
-rw-r--r--drivers/usb/serial/ir-usb.c272
-rw-r--r--drivers/usb/serial/iuu_phoenix.c30
-rw-r--r--drivers/usb/serial/kl5kusb105.c436
-rw-r--r--drivers/usb/serial/kl5kusb105.h47
-rw-r--r--drivers/usb/serial/kobil_sct.c3
-rw-r--r--drivers/usb/serial/kobil_sct.h75
-rw-r--r--drivers/usb/serial/mct_u232.c7
-rw-r--r--drivers/usb/serial/mct_u232.h254
-rw-r--r--drivers/usb/serial/mos7720.c1130
-rw-r--r--drivers/usb/serial/mos7840.c1
-rw-r--r--drivers/usb/serial/option.c841
-rw-r--r--drivers/usb/serial/oti6858.c254
-rw-r--r--drivers/usb/serial/pl2303.c430
-rw-r--r--drivers/usb/serial/pl2303.h6
-rw-r--r--drivers/usb/serial/qcaux.c5
-rw-r--r--drivers/usb/serial/qcserial.c64
-rw-r--r--drivers/usb/serial/safe_serial.c231
-rw-r--r--drivers/usb/serial/spcp8x5.c407
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c179
-rw-r--r--drivers/usb/serial/usb-serial.c47
-rw-r--r--drivers/usb/serial/usb-wwan.h67
-rw-r--r--drivers/usb/serial/usb_debug.c12
-rw-r--r--drivers/usb/serial/usb_wwan.c665
-rw-r--r--drivers/usb/serial/visor.c344
-rw-r--r--drivers/usb/serial/visor.h9
-rw-r--r--drivers/usb/serial/zio.c64
-rw-r--r--drivers/usb/storage/isd200.c4
-rw-r--r--drivers/usb/storage/onetouch.c12
-rw-r--r--drivers/usb/storage/transport.c2
-rw-r--r--drivers/usb/storage/unusual_devs.h24
-rw-r--r--drivers/usb/storage/usb.c87
-rw-r--r--drivers/usb/storage/usb.h3
-rw-r--r--drivers/usb/usb-skeleton.c10
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c2
-rw-r--r--drivers/usb/wusbcore/wusbhc.h4
-rw-r--r--drivers/watchdog/pcwd_usb.c6
-rw-r--r--fs/timerfd.c25
-rw-r--r--include/linux/usb.h137
-rw-r--r--include/linux/usb/Kbuild1
-rw-r--r--include/linux/usb/atmel_usba_udc.h2
-rw-r--r--include/linux/usb/audio.h6
-rw-r--r--include/linux/usb/cdc.h94
-rw-r--r--include/linux/usb/ch11.h (renamed from drivers/usb/core/hub.h)60
-rw-r--r--include/linux/usb/ch9.h16
-rw-r--r--include/linux/usb/composite.h1
-rw-r--r--include/linux/usb/ehci_def.h6
-rw-r--r--include/linux/usb/functionfs.h199
-rw-r--r--include/linux/usb/g_hid.h32
-rw-r--r--include/linux/usb/gadget.h6
-rw-r--r--include/linux/usb/gadgetfs.h2
-rw-r--r--include/linux/usb/hcd.h (renamed from drivers/usb/core/hcd.h)75
-rw-r--r--include/linux/usb/langwell_udc.h2
-rw-r--r--include/linux/usb/musb.h40
-rw-r--r--include/linux/usb/ncm.h114
-rw-r--r--include/linux/usb/net2280.h6
-rw-r--r--include/linux/usb/quirks.h4
-rw-r--r--include/linux/usb/rndis_host.h66
-rw-r--r--include/linux/usb/serial.h36
-rw-r--r--include/linux/usb/ulpi.h140
-rw-r--r--include/linux/usb/usbnet.h40
-rw-r--r--include/linux/usb/wusb-wa.h2
-rw-r--r--include/linux/wait.h149
-rw-r--r--kernel/sched.c1
-rw-r--r--sound/usb/midi.c14
-rw-r--r--sound/usb/misc/ua101.c16
-rw-r--r--tools/usb/ffs-test.c554
-rw-r--r--tools/usb/testusb.c547
261 files changed, 17242 insertions, 8360 deletions
diff --git a/Documentation/ABI/obsolete/sysfs-bus-usb b/Documentation/ABI/obsolete/sysfs-bus-usb
new file mode 100644
index 000000000000..bd096d33fbc7
--- /dev/null
+++ b/Documentation/ABI/obsolete/sysfs-bus-usb
@@ -0,0 +1,31 @@
1What: /sys/bus/usb/devices/.../power/level
2Date: March 2007
3KernelVersion: 2.6.21
4Contact: Alan Stern <stern@rowland.harvard.edu>
5Description:
6 Each USB device directory will contain a file named
7 power/level. This file holds a power-level setting for
8 the device, either "on" or "auto".
9
10 "on" means that the device is not allowed to autosuspend,
11 although normal suspends for system sleep will still
12 be honored. "auto" means the device will autosuspend
13 and autoresume in the usual manner, according to the
14 capabilities of its driver.
15
16 During normal use, devices should be left in the "auto"
17 level. The "on" level is meant for administrative uses.
18 If you want to suspend a device immediately but leave it
19 free to wake up in response to I/O requests, you should
20 write "0" to power/autosuspend.
21
22 Device not capable of proper suspend and resume should be
23 left in the "on" level. Although the USB spec requires
24 devices to support suspend/resume, many of them do not.
25 In fact so many don't that by default, the USB core
26 initializes all non-hub devices in the "on" level. Some
27 drivers may change this setting when they are bound.
28
29 This file is deprecated and will be removed after 2010.
30 Use the power/control file instead; it does exactly the
31 same thing.
diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index bcebb9eaedce..294aa864a60a 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -14,34 +14,6 @@ Description:
14 The autosuspend delay for newly-created devices is set to 14 The autosuspend delay for newly-created devices is set to
15 the value of the usbcore.autosuspend module parameter. 15 the value of the usbcore.autosuspend module parameter.
16 16
17What: /sys/bus/usb/devices/.../power/level
18Date: March 2007
19KernelVersion: 2.6.21
20Contact: Alan Stern <stern@rowland.harvard.edu>
21Description:
22 Each USB device directory will contain a file named
23 power/level. This file holds a power-level setting for
24 the device, either "on" or "auto".
25
26 "on" means that the device is not allowed to autosuspend,
27 although normal suspends for system sleep will still
28 be honored. "auto" means the device will autosuspend
29 and autoresume in the usual manner, according to the
30 capabilities of its driver.
31
32 During normal use, devices should be left in the "auto"
33 level. The "on" level is meant for administrative uses.
34 If you want to suspend a device immediately but leave it
35 free to wake up in response to I/O requests, you should
36 write "0" to power/autosuspend.
37
38 Device not capable of proper suspend and resume should be
39 left in the "on" level. Although the USB spec requires
40 devices to support suspend/resume, many of them do not.
41 In fact so many don't that by default, the USB core
42 initializes all non-hub devices in the "on" level. Some
43 drivers may change this setting when they are bound.
44
45What: /sys/bus/usb/devices/.../power/persist 17What: /sys/bus/usb/devices/.../power/persist
46Date: May 2007 18Date: May 2007
47KernelVersion: 2.6.23 19KernelVersion: 2.6.23
diff --git a/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget b/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
new file mode 100644
index 000000000000..34034027b13c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-platform-_UDC_-gadget
@@ -0,0 +1,9 @@
1What: /sys/devices/platform/_UDC_/gadget/suspended
2Date: April 2010
3Contact: Fabien Chouteau <fabien.chouteau@barco.com>
4Description:
5 Show the suspend state of an USB composite gadget.
6 1 -> suspended
7 0 -> resumed
8
9 (_UDC_ is the name of the USB Device Controller driver)
diff --git a/Documentation/DocBook/writing_usb_driver.tmpl b/Documentation/DocBook/writing_usb_driver.tmpl
index eeff19ca831b..bd97a13fa5ae 100644
--- a/Documentation/DocBook/writing_usb_driver.tmpl
+++ b/Documentation/DocBook/writing_usb_driver.tmpl
@@ -342,7 +342,7 @@ static inline void skel_delete (struct usb_skel *dev)
342{ 342{
343 kfree (dev->bulk_in_buffer); 343 kfree (dev->bulk_in_buffer);
344 if (dev->bulk_out_buffer != NULL) 344 if (dev->bulk_out_buffer != NULL)
345 usb_buffer_free (dev->udev, dev->bulk_out_size, 345 usb_free_coherent (dev->udev, dev->bulk_out_size,
346 dev->bulk_out_buffer, 346 dev->bulk_out_buffer,
347 dev->write_urb->transfer_dma); 347 dev->write_urb->transfer_dma);
348 usb_free_urb (dev->write_urb); 348 usb_free_urb (dev->write_urb);
diff --git a/Documentation/usb/bulk-streams.txt b/Documentation/usb/bulk-streams.txt
new file mode 100644
index 000000000000..ffc02021863e
--- /dev/null
+++ b/Documentation/usb/bulk-streams.txt
@@ -0,0 +1,78 @@
1Background
2==========
3
4Bulk endpoint streams were added in the USB 3.0 specification. Streams allow a
5device driver to overload a bulk endpoint so that multiple transfers can be
6queued at once.
7
8Streams are defined in sections 4.4.6.4 and 8.12.1.4 of the Universal Serial Bus
93.0 specification at http://www.usb.org/developers/docs/ The USB Attached SCSI
10Protocol, which uses streams to queue multiple SCSI commands, can be found on
11the T10 website (http://t10.org/).
12
13
14Device-side implications
15========================
16
17Once a buffer has been queued to a stream ring, the device is notified (through
18an out-of-band mechanism on another endpoint) that data is ready for that stream
19ID. The device then tells the host which "stream" it wants to start. The host
20can also initiate a transfer on a stream without the device asking, but the
21device can refuse that transfer. Devices can switch between streams at any
22time.
23
24
25Driver implications
26===================
27
28int usb_alloc_streams(struct usb_interface *interface,
29 struct usb_host_endpoint **eps, unsigned int num_eps,
30 unsigned int num_streams, gfp_t mem_flags);
31
32Device drivers will call this API to request that the host controller driver
33allocate memory so the driver can use up to num_streams stream IDs. They must
34pass an array of usb_host_endpoints that need to be setup with similar stream
35IDs. This is to ensure that a UASP driver will be able to use the same stream
36ID for the bulk IN and OUT endpoints used in a Bi-directional command sequence.
37
38The return value is an error condition (if one of the endpoints doesn't support
39streams, or the xHCI driver ran out of memory), or the number of streams the
40host controller allocated for this endpoint. The xHCI host controller hardware
41declares how many stream IDs it can support, and each bulk endpoint on a
42SuperSpeed device will say how many stream IDs it can handle. Therefore,
43drivers should be able to deal with being allocated less stream IDs than they
44requested.
45
46Do NOT call this function if you have URBs enqueued for any of the endpoints
47passed in as arguments. Do not call this function to request less than two
48streams.
49
50Drivers will only be allowed to call this API once for the same endpoint
51without calling usb_free_streams(). This is a simplification for the xHCI host
52controller driver, and may change in the future.
53
54
55Picking new Stream IDs to use
56============================
57
58Stream ID 0 is reserved, and should not be used to communicate with devices. If
59usb_alloc_streams() returns with a value of N, you may use streams 1 though N.
60To queue an URB for a specific stream, set the urb->stream_id value. If the
61endpoint does not support streams, an error will be returned.
62
63Note that new API to choose the next stream ID will have to be added if the xHCI
64driver supports secondary stream IDs.
65
66
67Clean up
68========
69
70If a driver wishes to stop using streams to communicate with the device, it
71should call
72
73void usb_free_streams(struct usb_interface *interface,
74 struct usb_host_endpoint **eps, unsigned int num_eps,
75 gfp_t mem_flags);
76
77All stream IDs will be deallocated when the driver releases the interface, to
78ensure that drivers that don't support streams will be able to use the endpoint.
diff --git a/Documentation/usb/dma.txt b/Documentation/usb/dma.txt
index cfdcd16e3abf..84ef865237db 100644
--- a/Documentation/usb/dma.txt
+++ b/Documentation/usb/dma.txt
@@ -16,11 +16,11 @@ OR: they can now be DMA-aware.
16 manage dma mappings for existing dma-ready buffers (see below). 16 manage dma mappings for existing dma-ready buffers (see below).
17 17
18- URBs have an additional "transfer_dma" field, as well as a transfer_flags 18- URBs have an additional "transfer_dma" field, as well as a transfer_flags
19 bit saying if it's valid. (Control requests also have "setup_dma" and a 19 bit saying if it's valid. (Control requests also have "setup_dma", but
20 corresponding transfer_flags bit.) 20 drivers must not use it.)
21 21
22- "usbcore" will map those DMA addresses, if a DMA-aware driver didn't do 22- "usbcore" will map this DMA address, if a DMA-aware driver didn't do
23 it first and set URB_NO_TRANSFER_DMA_MAP or URB_NO_SETUP_DMA_MAP. HCDs 23 it first and set URB_NO_TRANSFER_DMA_MAP. HCDs
24 don't manage dma mappings for URBs. 24 don't manage dma mappings for URBs.
25 25
26- There's a new "generic DMA API", parts of which are usable by USB device 26- There's a new "generic DMA API", parts of which are usable by USB device
@@ -43,22 +43,16 @@ and effects like cache-trashing can impose subtle penalties.
43 kind of addresses to store in urb->transfer_buffer and urb->transfer_dma. 43 kind of addresses to store in urb->transfer_buffer and urb->transfer_dma.
44 You'd also set URB_NO_TRANSFER_DMA_MAP in urb->transfer_flags: 44 You'd also set URB_NO_TRANSFER_DMA_MAP in urb->transfer_flags:
45 45
46 void *usb_buffer_alloc (struct usb_device *dev, size_t size, 46 void *usb_alloc_coherent (struct usb_device *dev, size_t size,
47 int mem_flags, dma_addr_t *dma); 47 int mem_flags, dma_addr_t *dma);
48 48
49 void usb_buffer_free (struct usb_device *dev, size_t size, 49 void usb_free_coherent (struct usb_device *dev, size_t size,
50 void *addr, dma_addr_t dma); 50 void *addr, dma_addr_t dma);
51 51
52 Most drivers should *NOT* be using these primitives; they don't need 52 Most drivers should *NOT* be using these primitives; they don't need
53 to use this type of memory ("dma-coherent"), and memory returned from 53 to use this type of memory ("dma-coherent"), and memory returned from
54 kmalloc() will work just fine. 54 kmalloc() will work just fine.
55 55
56 For control transfers you can use the buffer primitives or not for each
57 of the transfer buffer and setup buffer independently. Set the flag bits
58 URB_NO_TRANSFER_DMA_MAP and URB_NO_SETUP_DMA_MAP to indicate which
59 buffers you have prepared. For non-control transfers URB_NO_SETUP_DMA_MAP
60 is ignored.
61
62 The memory buffer returned is "dma-coherent"; sometimes you might need to 56 The memory buffer returned is "dma-coherent"; sometimes you might need to
63 force a consistent memory access ordering by using memory barriers. It's 57 force a consistent memory access ordering by using memory barriers. It's
64 not using a streaming DMA mapping, so it's good for small transfers on 58 not using a streaming DMA mapping, so it's good for small transfers on
@@ -130,8 +124,8 @@ of Documentation/PCI/PCI-DMA-mapping.txt, titled "What memory is DMA-able?")
130 void usb_buffer_unmap (struct urb *urb); 124 void usb_buffer_unmap (struct urb *urb);
131 125
132 The calls manage urb->transfer_dma for you, and set URB_NO_TRANSFER_DMA_MAP 126 The calls manage urb->transfer_dma for you, and set URB_NO_TRANSFER_DMA_MAP
133 so that usbcore won't map or unmap the buffer. The same goes for 127 so that usbcore won't map or unmap the buffer. They cannot be used for
134 urb->setup_dma and URB_NO_SETUP_DMA_MAP for control requests. 128 setup_packet buffers in control requests.
135 129
136Note that several of those interfaces are currently commented out, since 130Note that several of those interfaces are currently commented out, since
137they don't have current users. See the source code. Other than the dmasync 131they don't have current users. See the source code. Other than the dmasync
diff --git a/Documentation/usb/gadget_hid.txt b/Documentation/usb/gadget_hid.txt
new file mode 100644
index 000000000000..f4a51f567427
--- /dev/null
+++ b/Documentation/usb/gadget_hid.txt
@@ -0,0 +1,445 @@
1
2 Linux USB HID gadget driver
3
4Introduction
5
6 The HID Gadget driver provides emulation of USB Human Interface
7 Devices (HID). The basic HID handling is done in the kernel,
8 and HID reports can be sent/received through I/O on the
9 /dev/hidgX character devices.
10
11 For more details about HID, see the developer page on
12 http://www.usb.org/developers/hidpage/
13
14Configuration
15
16 g_hid is a platform driver, so to use it you need to add
17 struct platform_device(s) to your platform code defining the
18 HID function descriptors you want to use - E.G. something
19 like:
20
21#include <linux/platform_device.h>
22#include <linux/usb/g_hid.h>
23
24/* hid descriptor for a keyboard */
25static struct hidg_func_descriptor my_hid_data = {
26 .subclass = 0, /* No subclass */
27 .protocol = 1, /* Keyboard */
28 .report_length = 8,
29 .report_desc_length = 63,
30 .report_desc = {
31 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
32 0x09, 0x06, /* USAGE (Keyboard) */
33 0xa1, 0x01, /* COLLECTION (Application) */
34 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
35 0x19, 0xe0, /* USAGE_MINIMUM (Keyboard LeftControl) */
36 0x29, 0xe7, /* USAGE_MAXIMUM (Keyboard Right GUI) */
37 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
38 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
39 0x75, 0x01, /* REPORT_SIZE (1) */
40 0x95, 0x08, /* REPORT_COUNT (8) */
41 0x81, 0x02, /* INPUT (Data,Var,Abs) */
42 0x95, 0x01, /* REPORT_COUNT (1) */
43 0x75, 0x08, /* REPORT_SIZE (8) */
44 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */
45 0x95, 0x05, /* REPORT_COUNT (5) */
46 0x75, 0x01, /* REPORT_SIZE (1) */
47 0x05, 0x08, /* USAGE_PAGE (LEDs) */
48 0x19, 0x01, /* USAGE_MINIMUM (Num Lock) */
49 0x29, 0x05, /* USAGE_MAXIMUM (Kana) */
50 0x91, 0x02, /* OUTPUT (Data,Var,Abs) */
51 0x95, 0x01, /* REPORT_COUNT (1) */
52 0x75, 0x03, /* REPORT_SIZE (3) */
53 0x91, 0x03, /* OUTPUT (Cnst,Var,Abs) */
54 0x95, 0x06, /* REPORT_COUNT (6) */
55 0x75, 0x08, /* REPORT_SIZE (8) */
56 0x15, 0x00, /* LOGICAL_MINIMUM (0) */
57 0x25, 0x65, /* LOGICAL_MAXIMUM (101) */
58 0x05, 0x07, /* USAGE_PAGE (Keyboard) */
59 0x19, 0x00, /* USAGE_MINIMUM (Reserved) */
60 0x29, 0x65, /* USAGE_MAXIMUM (Keyboard Application) */
61 0x81, 0x00, /* INPUT (Data,Ary,Abs) */
62 0xc0 /* END_COLLECTION */
63 }
64};
65
66static struct platform_device my_hid = {
67 .name = "hidg",
68 .id = 0,
69 .num_resources = 0,
70 .resource = 0,
71 .dev.platform_data = &my_hid_data,
72};
73
74 You can add as many HID functions as you want, only limited by
75 the amount of interrupt endpoints your gadget driver supports.
76
77Send and receive HID reports
78
79 HID reports can be sent/received using read/write on the
80 /dev/hidgX character devices. See below for an example program
81 to do this.
82
83 hid_gadget_test is a small interactive program to test the HID
84 gadget driver. To use, point it at a hidg device and set the
85 device type (keyboard / mouse / joystick) - E.G.:
86
87 # hid_gadget_test /dev/hidg0 keyboard
88
89 You are now in the prompt of hid_gadget_test. You can type any
90 combination of options and values. Available options and
91 values are listed at program start. In keyboard mode you can
92 send up to six values.
93
94 For example type: g i s t r --left-shift
95
96 Hit return and the corresponding report will be sent by the
97 HID gadget.
98
99 Another interesting example is the caps lock test. Type
100 -–caps-lock and hit return. A report is then sent by the
101 gadget and you should receive the host answer, corresponding
102 to the caps lock LED status.
103
104 --caps-lock
105 recv report:2
106
107 With this command:
108
109 # hid_gadget_test /dev/hidg1 mouse
110
111 You can test the mouse emulation. Values are two signed numbers.
112
113
114Sample code
115
116/* hid_gadget_test */
117
118#include <pthread.h>
119#include <string.h>
120#include <stdio.h>
121#include <ctype.h>
122#include <fcntl.h>
123#include <errno.h>
124#include <stdio.h>
125#include <stdlib.h>
126#include <unistd.h>
127
128#define BUF_LEN 512
129
130struct options {
131 const char *opt;
132 unsigned char val;
133};
134
135static struct options kmod[] = {
136 {.opt = "--left-ctrl", .val = 0x01},
137 {.opt = "--right-ctrl", .val = 0x10},
138 {.opt = "--left-shift", .val = 0x02},
139 {.opt = "--right-shift", .val = 0x20},
140 {.opt = "--left-alt", .val = 0x04},
141 {.opt = "--right-alt", .val = 0x40},
142 {.opt = "--left-meta", .val = 0x08},
143 {.opt = "--right-meta", .val = 0x80},
144 {.opt = NULL}
145};
146
147static struct options kval[] = {
148 {.opt = "--return", .val = 0x28},
149 {.opt = "--esc", .val = 0x29},
150 {.opt = "--bckspc", .val = 0x2a},
151 {.opt = "--tab", .val = 0x2b},
152 {.opt = "--spacebar", .val = 0x2c},
153 {.opt = "--caps-lock", .val = 0x39},
154 {.opt = "--f1", .val = 0x3a},
155 {.opt = "--f2", .val = 0x3b},
156 {.opt = "--f3", .val = 0x3c},
157 {.opt = "--f4", .val = 0x3d},
158 {.opt = "--f5", .val = 0x3e},
159 {.opt = "--f6", .val = 0x3f},
160 {.opt = "--f7", .val = 0x40},
161 {.opt = "--f8", .val = 0x41},
162 {.opt = "--f9", .val = 0x42},
163 {.opt = "--f10", .val = 0x43},
164 {.opt = "--f11", .val = 0x44},
165 {.opt = "--f12", .val = 0x45},
166 {.opt = "--insert", .val = 0x49},
167 {.opt = "--home", .val = 0x4a},
168 {.opt = "--pageup", .val = 0x4b},
169 {.opt = "--del", .val = 0x4c},
170 {.opt = "--end", .val = 0x4d},
171 {.opt = "--pagedown", .val = 0x4e},
172 {.opt = "--right", .val = 0x4f},
173 {.opt = "--left", .val = 0x50},
174 {.opt = "--down", .val = 0x51},
175 {.opt = "--kp-enter", .val = 0x58},
176 {.opt = "--up", .val = 0x52},
177 {.opt = "--num-lock", .val = 0x53},
178 {.opt = NULL}
179};
180
181int keyboard_fill_report(char report[8], char buf[BUF_LEN], int *hold)
182{
183 char *tok = strtok(buf, " ");
184 int key = 0;
185 int i = 0;
186
187 for (; tok != NULL; tok = strtok(NULL, " ")) {
188
189 if (strcmp(tok, "--quit") == 0)
190 return -1;
191
192 if (strcmp(tok, "--hold") == 0) {
193 *hold = 1;
194 continue;
195 }
196
197 if (key < 6) {
198 for (i = 0; kval[i].opt != NULL; i++)
199 if (strcmp(tok, kval[i].opt) == 0) {
200 report[2 + key++] = kval[i].val;
201 break;
202 }
203 if (kval[i].opt != NULL)
204 continue;
205 }
206
207 if (key < 6)
208 if (islower(tok[0])) {
209 report[2 + key++] = (tok[0] - ('a' - 0x04));
210 continue;
211 }
212
213 for (i = 0; kmod[i].opt != NULL; i++)
214 if (strcmp(tok, kmod[i].opt) == 0) {
215 report[0] = report[0] | kmod[i].val;
216 break;
217 }
218 if (kmod[i].opt != NULL)
219 continue;
220
221 if (key < 6)
222 fprintf(stderr, "unknown option: %s\n", tok);
223 }
224 return 8;
225}
226
227static struct options mmod[] = {
228 {.opt = "--b1", .val = 0x01},
229 {.opt = "--b2", .val = 0x02},
230 {.opt = "--b3", .val = 0x04},
231 {.opt = NULL}
232};
233
234int mouse_fill_report(char report[8], char buf[BUF_LEN], int *hold)
235{
236 char *tok = strtok(buf, " ");
237 int mvt = 0;
238 int i = 0;
239 for (; tok != NULL; tok = strtok(NULL, " ")) {
240
241 if (strcmp(tok, "--quit") == 0)
242 return -1;
243
244 if (strcmp(tok, "--hold") == 0) {
245 *hold = 1;
246 continue;
247 }
248
249 for (i = 0; mmod[i].opt != NULL; i++)
250 if (strcmp(tok, mmod[i].opt) == 0) {
251 report[0] = report[0] | mmod[i].val;
252 break;
253 }
254 if (mmod[i].opt != NULL)
255 continue;
256
257 if (!(tok[0] == '-' && tok[1] == '-') && mvt < 2) {
258 errno = 0;
259 report[1 + mvt++] = (char)strtol(tok, NULL, 0);
260 if (errno != 0) {
261 fprintf(stderr, "Bad value:'%s'\n", tok);
262 report[1 + mvt--] = 0;
263 }
264 continue;
265 }
266
267 fprintf(stderr, "unknown option: %s\n", tok);
268 }
269 return 3;
270}
271
272static struct options jmod[] = {
273 {.opt = "--b1", .val = 0x10},
274 {.opt = "--b2", .val = 0x20},
275 {.opt = "--b3", .val = 0x40},
276 {.opt = "--b4", .val = 0x80},
277 {.opt = "--hat1", .val = 0x00},
278 {.opt = "--hat2", .val = 0x01},
279 {.opt = "--hat3", .val = 0x02},
280 {.opt = "--hat4", .val = 0x03},
281 {.opt = "--hatneutral", .val = 0x04},
282 {.opt = NULL}
283};
284
285int joystick_fill_report(char report[8], char buf[BUF_LEN], int *hold)
286{
287 char *tok = strtok(buf, " ");
288 int mvt = 0;
289 int i = 0;
290
291 *hold = 1;
292
293 /* set default hat position: neutral */
294 report[3] = 0x04;
295
296 for (; tok != NULL; tok = strtok(NULL, " ")) {
297
298 if (strcmp(tok, "--quit") == 0)
299 return -1;
300
301 for (i = 0; jmod[i].opt != NULL; i++)
302 if (strcmp(tok, jmod[i].opt) == 0) {
303 report[3] = (report[3] & 0xF0) | jmod[i].val;
304 break;
305 }
306 if (jmod[i].opt != NULL)
307 continue;
308
309 if (!(tok[0] == '-' && tok[1] == '-') && mvt < 3) {
310 errno = 0;
311 report[mvt++] = (char)strtol(tok, NULL, 0);
312 if (errno != 0) {
313 fprintf(stderr, "Bad value:'%s'\n", tok);
314 report[mvt--] = 0;
315 }
316 continue;
317 }
318
319 fprintf(stderr, "unknown option: %s\n", tok);
320 }
321 return 4;
322}
323
324void print_options(char c)
325{
326 int i = 0;
327
328 if (c == 'k') {
329 printf(" keyboard options:\n"
330 " --hold\n");
331 for (i = 0; kmod[i].opt != NULL; i++)
332 printf("\t\t%s\n", kmod[i].opt);
333 printf("\n keyboard values:\n"
334 " [a-z] or\n");
335 for (i = 0; kval[i].opt != NULL; i++)
336 printf("\t\t%-8s%s", kval[i].opt, i % 2 ? "\n" : "");
337 printf("\n");
338 } else if (c == 'm') {
339 printf(" mouse options:\n"
340 " --hold\n");
341 for (i = 0; mmod[i].opt != NULL; i++)
342 printf("\t\t%s\n", mmod[i].opt);
343 printf("\n mouse values:\n"
344 " Two signed numbers\n"
345 "--quit to close\n");
346 } else {
347 printf(" joystick options:\n");
348 for (i = 0; jmod[i].opt != NULL; i++)
349 printf("\t\t%s\n", jmod[i].opt);
350 printf("\n joystick values:\n"
351 " three signed numbers\n"
352 "--quit to close\n");
353 }
354}
355
356int main(int argc, const char *argv[])
357{
358 const char *filename = NULL;
359 int fd = 0;
360 char buf[BUF_LEN];
361 int cmd_len;
362 char report[8];
363 int to_send = 8;
364 int hold = 0;
365 fd_set rfds;
366 int retval, i;
367
368 if (argc < 3) {
369 fprintf(stderr, "Usage: %s devname mouse|keyboard|joystick\n",
370 argv[0]);
371 return 1;
372 }
373
374 if (argv[2][0] != 'k' && argv[2][0] != 'm' && argv[2][0] != 'j')
375 return 2;
376
377 filename = argv[1];
378
379 if ((fd = open(filename, O_RDWR, 0666)) == -1) {
380 perror(filename);
381 return 3;
382 }
383
384 print_options(argv[2][0]);
385
386 while (42) {
387
388 FD_ZERO(&rfds);
389 FD_SET(STDIN_FILENO, &rfds);
390 FD_SET(fd, &rfds);
391
392 retval = select(fd + 1, &rfds, NULL, NULL, NULL);
393 if (retval == -1 && errno == EINTR)
394 continue;
395 if (retval < 0) {
396 perror("select()");
397 return 4;
398 }
399
400 if (FD_ISSET(fd, &rfds)) {
401 cmd_len = read(fd, buf, BUF_LEN - 1);
402 printf("recv report:");
403 for (i = 0; i < cmd_len; i++)
404 printf(" %02x", buf[i]);
405 printf("\n");
406 }
407
408 if (FD_ISSET(STDIN_FILENO, &rfds)) {
409 memset(report, 0x0, sizeof(report));
410 cmd_len = read(STDIN_FILENO, buf, BUF_LEN - 1);
411
412 if (cmd_len == 0)
413 break;
414
415 buf[cmd_len - 1] = '\0';
416 hold = 0;
417
418 memset(report, 0x0, sizeof(report));
419 if (argv[2][0] == 'k')
420 to_send = keyboard_fill_report(report, buf, &hold);
421 else if (argv[2][0] == 'm')
422 to_send = mouse_fill_report(report, buf, &hold);
423 else
424 to_send = joystick_fill_report(report, buf, &hold);
425
426 if (to_send == -1)
427 break;
428
429 if (write(fd, report, to_send) != to_send) {
430 perror(filename);
431 return 5;
432 }
433 if (!hold) {
434 memset(report, 0x0, sizeof(report));
435 if (write(fd, report, to_send) != to_send) {
436 perror(filename);
437 return 6;
438 }
439 }
440 }
441 }
442
443 close(fd);
444 return 0;
445}
diff --git a/Documentation/usb/power-management.txt b/Documentation/usb/power-management.txt
index 2790ad48cfc2..b29d8e56cf28 100644
--- a/Documentation/usb/power-management.txt
+++ b/Documentation/usb/power-management.txt
@@ -107,7 +107,9 @@ allowed to issue dynamic suspends.
107The user interface for controlling dynamic PM is located in the power/ 107The user interface for controlling dynamic PM is located in the power/
108subdirectory of each USB device's sysfs directory, that is, in 108subdirectory of each USB device's sysfs directory, that is, in
109/sys/bus/usb/devices/.../power/ where "..." is the device's ID. The 109/sys/bus/usb/devices/.../power/ where "..." is the device's ID. The
110relevant attribute files are: wakeup, level, and autosuspend. 110relevant attribute files are: wakeup, control, and autosuspend.
111(There may also be a file named "level"; this file was deprecated
112as of the 2.6.35 kernel and replaced by the "control" file.)
111 113
112 power/wakeup 114 power/wakeup
113 115
@@ -120,7 +122,7 @@ relevant attribute files are: wakeup, level, and autosuspend.
120 while the device is suspended, the change won't take 122 while the device is suspended, the change won't take
121 effect until the following suspend.) 123 effect until the following suspend.)
122 124
123 power/level 125 power/control
124 126
125 This file contains one of two words: "on" or "auto". 127 This file contains one of two words: "on" or "auto".
126 You can write those words to the file to change the 128 You can write those words to the file to change the
@@ -148,14 +150,15 @@ relevant attribute files are: wakeup, level, and autosuspend.
148 never to autosuspend. You can write a number to the 150 never to autosuspend. You can write a number to the
149 file to change the autosuspend idle-delay time. 151 file to change the autosuspend idle-delay time.
150 152
151Writing "-1" to power/autosuspend and writing "on" to power/level do 153Writing "-1" to power/autosuspend and writing "on" to power/control do
152essentially the same thing -- they both prevent the device from being 154essentially the same thing -- they both prevent the device from being
153autosuspended. Yes, this is a redundancy in the API. 155autosuspended. Yes, this is a redundancy in the API.
154 156
155(In 2.6.21 writing "0" to power/autosuspend would prevent the device 157(In 2.6.21 writing "0" to power/autosuspend would prevent the device
156from being autosuspended; the behavior was changed in 2.6.22. The 158from being autosuspended; the behavior was changed in 2.6.22. The
157power/autosuspend attribute did not exist prior to 2.6.21, and the 159power/autosuspend attribute did not exist prior to 2.6.21, and the
158power/level attribute did not exist prior to 2.6.22.) 160power/level attribute did not exist prior to 2.6.22. power/control
161was added in 2.6.34.)
159 162
160 163
161 Changing the default idle-delay time 164 Changing the default idle-delay time
@@ -212,7 +215,7 @@ among printers and scanners, but plenty of other types of device have
212the same deficiency. 215the same deficiency.
213 216
214For this reason, by default the kernel disables autosuspend (the 217For this reason, by default the kernel disables autosuspend (the
215power/level attribute is initialized to "on") for all devices other 218power/control attribute is initialized to "on") for all devices other
216than hubs. Hubs, at least, appear to be reasonably well-behaved in 219than hubs. Hubs, at least, appear to be reasonably well-behaved in
217this regard. 220this regard.
218 221
@@ -373,7 +376,7 @@ usb_autopm_put_interface() in its close or release routine. But other
373patterns are possible. 376patterns are possible.
374 377
375The autosuspend attempts mentioned above will often fail for one 378The autosuspend attempts mentioned above will often fail for one
376reason or another. For example, the power/level attribute might be 379reason or another. For example, the power/control attribute might be
377set to "on", or another interface in the same device might not be 380set to "on", or another interface in the same device might not be
378idle. This is perfectly normal. If the reason for failure was that 381idle. This is perfectly normal. If the reason for failure was that
379the device hasn't been idle for long enough, a timer is scheduled to 382the device hasn't been idle for long enough, a timer is scheduled to
@@ -394,12 +397,12 @@ Drivers can enable autosuspend for their devices by calling
394 397
395in their probe() routine, if they know that the device is capable of 398in their probe() routine, if they know that the device is capable of
396suspending and resuming correctly. This is exactly equivalent to 399suspending and resuming correctly. This is exactly equivalent to
397writing "auto" to the device's power/level attribute. Likewise, 400writing "auto" to the device's power/control attribute. Likewise,
398drivers can disable autosuspend by calling 401drivers can disable autosuspend by calling
399 402
400 usb_disable_autosuspend(struct usb_device *udev); 403 usb_disable_autosuspend(struct usb_device *udev);
401 404
402This is exactly the same as writing "on" to the power/level attribute. 405This is exactly the same as writing "on" to the power/control attribute.
403 406
404Sometimes a driver needs to make sure that remote wakeup is enabled 407Sometimes a driver needs to make sure that remote wakeup is enabled
405during autosuspend. For example, there's not much point 408during autosuspend. For example, there's not much point
diff --git a/Documentation/usb/usb-serial.txt b/Documentation/usb/usb-serial.txt
index ff2c1ff57ba2..f4d214510259 100644
--- a/Documentation/usb/usb-serial.txt
+++ b/Documentation/usb/usb-serial.txt
@@ -194,6 +194,10 @@ FTDI Single Port Serial Driver
194 194
195 This is a single port DB-25 serial adapter. 195 This is a single port DB-25 serial adapter.
196 196
197 Devices supported include:
198 -TripNav TN-200 USB GPS
199 -Navis Engineering Bureau CH-4711 USB GPS
200
197 For any questions or problems with this driver, please contact Bill Ryder. 201 For any questions or problems with this driver, please contact Bill Ryder.
198 202
199 203
@@ -216,7 +220,7 @@ Cypress M8 CY4601 Family Serial Driver
216 220
217 Devices supported: 221 Devices supported:
218 222
219 -DeLorme's USB Earthmate (SiRF Star II lp arch) 223 -DeLorme's USB Earthmate GPS (SiRF Star II lp arch)
220 -Cypress HID->COM RS232 adapter 224 -Cypress HID->COM RS232 adapter
221 225
222 Note: Cypress Semiconductor claims no affiliation with the 226 Note: Cypress Semiconductor claims no affiliation with the
@@ -392,9 +396,10 @@ REINER SCT cyberJack pinpad/e-com USB chipcard reader
392Prolific PL2303 Driver 396Prolific PL2303 Driver
393 397
394 This driver supports any device that has the PL2303 chip from Prolific 398 This driver supports any device that has the PL2303 chip from Prolific
395 in it. This includes a number of single port USB to serial 399 in it. This includes a number of single port USB to serial converters,
396 converters and USB GPS devices. Devices from Aten (the UC-232) and 400 more than 70% of USB GPS devices (in 2010), and some USB UPSes. Devices
397 IO-Data work with this driver, as does the DCU-11 mobile-phone cable. 401 from Aten (the UC-232) and IO-Data work with this driver, as does
402 the DCU-11 mobile-phone cable.
398 403
399 For any questions or problems with this driver, please contact Greg 404 For any questions or problems with this driver, please contact Greg
400 Kroah-Hartman at greg@kroah.com 405 Kroah-Hartman at greg@kroah.com
@@ -435,6 +440,22 @@ Winchiphead CH341 Driver
435 For any questions or problems with this driver, please contact 440 For any questions or problems with this driver, please contact
436 frank@kingswood-consulting.co.uk. 441 frank@kingswood-consulting.co.uk.
437 442
443Moschip MCS7720, MCS7715 driver
444
445 These chips are present in devices sold by various manufacturers, such as Syba
446 and Cables Unlimited. There may be others. The 7720 provides two serial
447 ports, and the 7715 provides one serial and one standard PC parallel port.
448 Support for the 7715's parallel port is enabled by a separate option, which
449 will not appear unless parallel port support is first enabled at the top-level
450 of the Device Drivers config menu. Currently only compatibility mode is
451 supported on the parallel port (no ECP/EPP).
452
453 TODO:
454 - Implement ECP/EPP modes for the parallel port.
455 - Baud rates higher than 115200 are currently broken.
456 - Devices with a single serial port based on the Moschip MCS7703 may work
457 with this driver with a simple addition to the usb_device_id table. I
458 don't have one of these devices, so I can't say for sure.
438 459
439Generic Serial driver 460Generic Serial driver
440 461
diff --git a/arch/arm/mach-omap2/board-omap3evm.c b/arch/arm/mach-omap2/board-omap3evm.c
index 017bb2f4f7d2..7d7b5bc8dc31 100644
--- a/arch/arm/mach-omap2/board-omap3evm.c
+++ b/arch/arm/mach-omap2/board-omap3evm.c
@@ -702,6 +702,9 @@ static void __init omap3_evm_init(void)
702 omap_mux_init_gpio(21, OMAP_PIN_INPUT_PULLUP); 702 omap_mux_init_gpio(21, OMAP_PIN_INPUT_PULLUP);
703 ehci_pdata.reset_gpio_port[1] = 21; 703 ehci_pdata.reset_gpio_port[1] = 21;
704 704
705 /* EVM REV >= E can supply 500mA with EXTVBUS programming */
706 musb_board_data.power = 500;
707 musb_board_data.extvbus = 1;
705 } else { 708 } else {
706 /* setup EHCI phy reset on MDC */ 709 /* setup EHCI phy reset on MDC */
707 omap_mux_init_gpio(135, OMAP_PIN_OUTPUT); 710 omap_mux_init_gpio(135, OMAP_PIN_OUTPUT);
diff --git a/arch/arm/mach-omap2/usb-ehci.c b/arch/arm/mach-omap2/usb-ehci.c
index ee9f548d5d81..c68f799e83c5 100644
--- a/arch/arm/mach-omap2/usb-ehci.c
+++ b/arch/arm/mach-omap2/usb-ehci.c
@@ -236,3 +236,158 @@ void __init usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata)
236 236
237#endif /* CONFIG_USB_EHCI_HCD */ 237#endif /* CONFIG_USB_EHCI_HCD */
238 238
239#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
240
241static struct resource ohci_resources[] = {
242 {
243 .start = OMAP34XX_OHCI_BASE,
244 .end = OMAP34XX_OHCI_BASE + SZ_1K - 1,
245 .flags = IORESOURCE_MEM,
246 },
247 {
248 .start = OMAP34XX_UHH_CONFIG_BASE,
249 .end = OMAP34XX_UHH_CONFIG_BASE + SZ_1K - 1,
250 .flags = IORESOURCE_MEM,
251 },
252 {
253 .start = OMAP34XX_USBTLL_BASE,
254 .end = OMAP34XX_USBTLL_BASE + SZ_4K - 1,
255 .flags = IORESOURCE_MEM,
256 },
257 { /* general IRQ */
258 .start = INT_34XX_OHCI_IRQ,
259 .flags = IORESOURCE_IRQ,
260 }
261};
262
263static u64 ohci_dmamask = DMA_BIT_MASK(32);
264
265static struct platform_device ohci_device = {
266 .name = "ohci-omap3",
267 .id = 0,
268 .dev = {
269 .dma_mask = &ohci_dmamask,
270 .coherent_dma_mask = 0xffffffff,
271 },
272 .num_resources = ARRAY_SIZE(ohci_resources),
273 .resource = ohci_resources,
274};
275
276static void setup_ohci_io_mux(const enum ohci_omap3_port_mode *port_mode)
277{
278 switch (port_mode[0]) {
279 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
280 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
281 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
282 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
283 omap_mux_init_signal("mm1_rxdp",
284 OMAP_PIN_INPUT_PULLDOWN);
285 omap_mux_init_signal("mm1_rxdm",
286 OMAP_PIN_INPUT_PULLDOWN);
287 /* FALLTHROUGH */
288 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
289 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
290 omap_mux_init_signal("mm1_rxrcv",
291 OMAP_PIN_INPUT_PULLDOWN);
292 /* FALLTHROUGH */
293 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
294 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
295 omap_mux_init_signal("mm1_txen_n", OMAP_PIN_OUTPUT);
296 /* FALLTHROUGH */
297 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
298 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
299 omap_mux_init_signal("mm1_txse0",
300 OMAP_PIN_INPUT_PULLDOWN);
301 omap_mux_init_signal("mm1_txdat",
302 OMAP_PIN_INPUT_PULLDOWN);
303 break;
304 case OMAP_OHCI_PORT_MODE_UNUSED:
305 /* FALLTHROUGH */
306 default:
307 break;
308 }
309 switch (port_mode[1]) {
310 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
311 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
312 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
313 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
314 omap_mux_init_signal("mm2_rxdp",
315 OMAP_PIN_INPUT_PULLDOWN);
316 omap_mux_init_signal("mm2_rxdm",
317 OMAP_PIN_INPUT_PULLDOWN);
318 /* FALLTHROUGH */
319 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
320 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
321 omap_mux_init_signal("mm2_rxrcv",
322 OMAP_PIN_INPUT_PULLDOWN);
323 /* FALLTHROUGH */
324 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
325 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
326 omap_mux_init_signal("mm2_txen_n", OMAP_PIN_OUTPUT);
327 /* FALLTHROUGH */
328 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
329 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
330 omap_mux_init_signal("mm2_txse0",
331 OMAP_PIN_INPUT_PULLDOWN);
332 omap_mux_init_signal("mm2_txdat",
333 OMAP_PIN_INPUT_PULLDOWN);
334 break;
335 case OMAP_OHCI_PORT_MODE_UNUSED:
336 /* FALLTHROUGH */
337 default:
338 break;
339 }
340 switch (port_mode[2]) {
341 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
342 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
343 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
344 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
345 omap_mux_init_signal("mm3_rxdp",
346 OMAP_PIN_INPUT_PULLDOWN);
347 omap_mux_init_signal("mm3_rxdm",
348 OMAP_PIN_INPUT_PULLDOWN);
349 /* FALLTHROUGH */
350 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
351 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
352 omap_mux_init_signal("mm3_rxrcv",
353 OMAP_PIN_INPUT_PULLDOWN);
354 /* FALLTHROUGH */
355 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
356 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
357 omap_mux_init_signal("mm3_txen_n", OMAP_PIN_OUTPUT);
358 /* FALLTHROUGH */
359 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
360 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
361 omap_mux_init_signal("mm3_txse0",
362 OMAP_PIN_INPUT_PULLDOWN);
363 omap_mux_init_signal("mm3_txdat",
364 OMAP_PIN_INPUT_PULLDOWN);
365 break;
366 case OMAP_OHCI_PORT_MODE_UNUSED:
367 /* FALLTHROUGH */
368 default:
369 break;
370 }
371}
372
373void __init usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata)
374{
375 platform_device_add_data(&ohci_device, pdata, sizeof(*pdata));
376
377 /* Setup Pin IO MUX for OHCI */
378 if (cpu_is_omap34xx())
379 setup_ohci_io_mux(pdata->port_mode);
380
381 if (platform_device_register(&ohci_device) < 0) {
382 pr_err("Unable to register FS-USB (OHCI) device\n");
383 return;
384 }
385}
386
387#else
388
389void __init usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata)
390{
391}
392
393#endif /* CONFIG_USB_OHCI_HCD */
diff --git a/arch/arm/mach-omap2/usb-musb.c b/arch/arm/mach-omap2/usb-musb.c
index 6d41fa7b2ce8..96f6787e00b2 100644
--- a/arch/arm/mach-omap2/usb-musb.c
+++ b/arch/arm/mach-omap2/usb-musb.c
@@ -107,6 +107,7 @@ void __init usb_musb_init(struct omap_musb_board_data *board_data)
107 musb_plat.board_data = board_data; 107 musb_plat.board_data = board_data;
108 musb_plat.power = board_data->power >> 1; 108 musb_plat.power = board_data->power >> 1;
109 musb_plat.mode = board_data->mode; 109 musb_plat.mode = board_data->mode;
110 musb_plat.extvbus = board_data->extvbus;
110 111
111 if (platform_device_register(&musb_device) < 0) 112 if (platform_device_register(&musb_device) < 0)
112 printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n"); 113 printk(KERN_ERR "Unable to register HS-USB (MUSB) device\n");
diff --git a/arch/arm/plat-omap/include/plat/usb.h b/arch/arm/plat-omap/include/plat/usb.h
index 876ca8d5e927..98eef5360e6d 100644
--- a/arch/arm/plat-omap/include/plat/usb.h
+++ b/arch/arm/plat-omap/include/plat/usb.h
@@ -13,6 +13,20 @@ enum ehci_hcd_omap_mode {
13 EHCI_HCD_OMAP_MODE_TLL, 13 EHCI_HCD_OMAP_MODE_TLL,
14}; 14};
15 15
16enum ohci_omap3_port_mode {
17 OMAP_OHCI_PORT_MODE_UNUSED,
18 OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0,
19 OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM,
20 OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0,
21 OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM,
22 OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0,
23 OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM,
24 OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0,
25 OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM,
26 OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0,
27 OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM,
28};
29
16struct ehci_hcd_omap_platform_data { 30struct ehci_hcd_omap_platform_data {
17 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS]; 31 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
18 unsigned phy_reset:1; 32 unsigned phy_reset:1;
@@ -21,6 +35,13 @@ struct ehci_hcd_omap_platform_data {
21 int reset_gpio_port[OMAP3_HS_USB_PORTS]; 35 int reset_gpio_port[OMAP3_HS_USB_PORTS];
22}; 36};
23 37
38struct ohci_hcd_omap_platform_data {
39 enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS];
40
41 /* Set this to true for ES2.x silicon */
42 unsigned es2_compatibility:1;
43};
44
24/*-------------------------------------------------------------------------*/ 45/*-------------------------------------------------------------------------*/
25 46
26#define OMAP1_OTG_BASE 0xfffb0400 47#define OMAP1_OTG_BASE 0xfffb0400
@@ -47,6 +68,7 @@ struct omap_musb_board_data {
47 u8 interface_type; 68 u8 interface_type;
48 u8 mode; 69 u8 mode;
49 u16 power; 70 u16 power;
71 unsigned extvbus:1;
50}; 72};
51 73
52enum musb_interface {MUSB_INTERFACE_ULPI, MUSB_INTERFACE_UTMI}; 74enum musb_interface {MUSB_INTERFACE_ULPI, MUSB_INTERFACE_UTMI};
@@ -55,6 +77,8 @@ extern void usb_musb_init(struct omap_musb_board_data *board_data);
55 77
56extern void usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata); 78extern void usb_ehci_init(const struct ehci_hcd_omap_platform_data *pdata);
57 79
80extern void usb_ohci_init(const struct ohci_hcd_omap_platform_data *pdata);
81
58#endif 82#endif
59 83
60void omap_usb_init(struct omap_usb_config *pdata); 84void omap_usb_init(struct omap_usb_config *pdata);
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 7b85b696fdab..df619756b7ae 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -783,13 +783,12 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
783{ 783{
784 struct usbhid_device *usbhid = hid->driver_data; 784 struct usbhid_device *usbhid = hid->driver_data;
785 785
786 usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL, 786 usbhid->inbuf = usb_alloc_coherent(dev, usbhid->bufsize, GFP_KERNEL,
787 &usbhid->inbuf_dma); 787 &usbhid->inbuf_dma);
788 usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL, 788 usbhid->outbuf = usb_alloc_coherent(dev, usbhid->bufsize, GFP_KERNEL,
789 &usbhid->outbuf_dma); 789 &usbhid->outbuf_dma);
790 usbhid->cr = usb_buffer_alloc(dev, sizeof(*usbhid->cr), GFP_KERNEL, 790 usbhid->cr = kmalloc(sizeof(*usbhid->cr), GFP_KERNEL);
791 &usbhid->cr_dma); 791 usbhid->ctrlbuf = usb_alloc_coherent(dev, usbhid->bufsize, GFP_KERNEL,
792 usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_KERNEL,
793 &usbhid->ctrlbuf_dma); 792 &usbhid->ctrlbuf_dma);
794 if (!usbhid->inbuf || !usbhid->outbuf || !usbhid->cr || 793 if (!usbhid->inbuf || !usbhid->outbuf || !usbhid->cr ||
795 !usbhid->ctrlbuf) 794 !usbhid->ctrlbuf)
@@ -844,10 +843,10 @@ static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
844{ 843{
845 struct usbhid_device *usbhid = hid->driver_data; 844 struct usbhid_device *usbhid = hid->driver_data;
846 845
847 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); 846 usb_free_coherent(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
848 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); 847 usb_free_coherent(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
849 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma); 848 kfree(usbhid->cr);
850 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); 849 usb_free_coherent(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
851} 850}
852 851
853static int usbhid_parse(struct hid_device *hid) 852static int usbhid_parse(struct hid_device *hid)
@@ -1007,9 +1006,8 @@ static int usbhid_start(struct hid_device *hid)
1007 1006
1008 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, 1007 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
1009 usbhid->ctrlbuf, 1, hid_ctrl, hid); 1008 usbhid->ctrlbuf, 1, hid_ctrl, hid);
1010 usbhid->urbctrl->setup_dma = usbhid->cr_dma;
1011 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; 1009 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
1012 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 1010 usbhid->urbctrl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1013 1011
1014 if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS)) 1012 if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS))
1015 usbhid_init_reports(hid); 1013 usbhid_init_reports(hid);
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index ec20400c7f29..693fd3e720df 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -75,7 +75,6 @@ struct usbhid_device {
75 75
76 struct urb *urbctrl; /* Control URB */ 76 struct urb *urbctrl; /* Control URB */
77 struct usb_ctrlrequest *cr; /* Control request struct */ 77 struct usb_ctrlrequest *cr; /* Control request struct */
78 dma_addr_t cr_dma; /* Control request struct dma */
79 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */ 78 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
80 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */ 79 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
81 char *ctrlbuf; /* Control buffer */ 80 char *ctrlbuf; /* Control buffer */
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index f843443ba5c3..bb14c8270af3 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -74,7 +74,6 @@ struct usb_kbd {
74 unsigned char *new; 74 unsigned char *new;
75 struct usb_ctrlrequest *cr; 75 struct usb_ctrlrequest *cr;
76 unsigned char *leds; 76 unsigned char *leds;
77 dma_addr_t cr_dma;
78 dma_addr_t new_dma; 77 dma_addr_t new_dma;
79 dma_addr_t leds_dma; 78 dma_addr_t leds_dma;
80}; 79};
@@ -197,11 +196,11 @@ static int usb_kbd_alloc_mem(struct usb_device *dev, struct usb_kbd *kbd)
197 return -1; 196 return -1;
198 if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL))) 197 if (!(kbd->led = usb_alloc_urb(0, GFP_KERNEL)))
199 return -1; 198 return -1;
200 if (!(kbd->new = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &kbd->new_dma))) 199 if (!(kbd->new = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &kbd->new_dma)))
201 return -1; 200 return -1;
202 if (!(kbd->cr = usb_buffer_alloc(dev, sizeof(struct usb_ctrlrequest), GFP_ATOMIC, &kbd->cr_dma))) 201 if (!(kbd->cr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL)))
203 return -1; 202 return -1;
204 if (!(kbd->leds = usb_buffer_alloc(dev, 1, GFP_ATOMIC, &kbd->leds_dma))) 203 if (!(kbd->leds = usb_alloc_coherent(dev, 1, GFP_ATOMIC, &kbd->leds_dma)))
205 return -1; 204 return -1;
206 205
207 return 0; 206 return 0;
@@ -211,9 +210,9 @@ static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
211{ 210{
212 usb_free_urb(kbd->irq); 211 usb_free_urb(kbd->irq);
213 usb_free_urb(kbd->led); 212 usb_free_urb(kbd->led);
214 usb_buffer_free(dev, 8, kbd->new, kbd->new_dma); 213 usb_free_coherent(dev, 8, kbd->new, kbd->new_dma);
215 usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma); 214 kfree(kbd->cr);
216 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma); 215 usb_free_coherent(dev, 1, kbd->leds, kbd->leds_dma);
217} 216}
218 217
219static int usb_kbd_probe(struct usb_interface *iface, 218static int usb_kbd_probe(struct usb_interface *iface,
@@ -304,9 +303,8 @@ static int usb_kbd_probe(struct usb_interface *iface,
304 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0), 303 usb_fill_control_urb(kbd->led, dev, usb_sndctrlpipe(dev, 0),
305 (void *) kbd->cr, kbd->leds, 1, 304 (void *) kbd->cr, kbd->leds, 1,
306 usb_kbd_led, kbd); 305 usb_kbd_led, kbd);
307 kbd->led->setup_dma = kbd->cr_dma;
308 kbd->led->transfer_dma = kbd->leds_dma; 306 kbd->led->transfer_dma = kbd->leds_dma;
309 kbd->led->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 307 kbd->led->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
310 308
311 error = input_register_device(kbd->dev); 309 error = input_register_device(kbd->dev);
312 if (error) 310 if (error)
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c
index 72ab4b268096..79b2bf81a059 100644
--- a/drivers/hid/usbhid/usbmouse.c
+++ b/drivers/hid/usbhid/usbmouse.c
@@ -142,7 +142,7 @@ static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
142 if (!mouse || !input_dev) 142 if (!mouse || !input_dev)
143 goto fail1; 143 goto fail1;
144 144
145 mouse->data = usb_buffer_alloc(dev, 8, GFP_ATOMIC, &mouse->data_dma); 145 mouse->data = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &mouse->data_dma);
146 if (!mouse->data) 146 if (!mouse->data)
147 goto fail1; 147 goto fail1;
148 148
@@ -205,7 +205,7 @@ static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
205fail3: 205fail3:
206 usb_free_urb(mouse->irq); 206 usb_free_urb(mouse->irq);
207fail2: 207fail2:
208 usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); 208 usb_free_coherent(dev, 8, mouse->data, mouse->data_dma);
209fail1: 209fail1:
210 input_free_device(input_dev); 210 input_free_device(input_dev);
211 kfree(mouse); 211 kfree(mouse);
@@ -221,7 +221,7 @@ static void usb_mouse_disconnect(struct usb_interface *intf)
221 usb_kill_urb(mouse->irq); 221 usb_kill_urb(mouse->irq);
222 input_unregister_device(mouse->dev); 222 input_unregister_device(mouse->dev);
223 usb_free_urb(mouse->irq); 223 usb_free_urb(mouse->irq);
224 usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); 224 usb_free_coherent(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);
225 kfree(mouse); 225 kfree(mouse);
226 } 226 }
227} 227}
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 9b3353b404da..c1087ce4cef9 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -533,8 +533,8 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
533 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX) 533 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX)
534 return 0; 534 return 0;
535 535
536 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 536 xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
537 GFP_KERNEL, &xpad->odata_dma); 537 GFP_KERNEL, &xpad->odata_dma);
538 if (!xpad->odata) 538 if (!xpad->odata)
539 goto fail1; 539 goto fail1;
540 540
@@ -554,7 +554,7 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
554 554
555 return 0; 555 return 0;
556 556
557 fail2: usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); 557 fail2: usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
558 fail1: return error; 558 fail1: return error;
559} 559}
560 560
@@ -568,7 +568,7 @@ static void xpad_deinit_output(struct usb_xpad *xpad)
568{ 568{
569 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX) { 569 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX) {
570 usb_free_urb(xpad->irq_out); 570 usb_free_urb(xpad->irq_out);
571 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 571 usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
572 xpad->odata, xpad->odata_dma); 572 xpad->odata, xpad->odata_dma);
573 } 573 }
574} 574}
@@ -788,8 +788,8 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
788 if (!xpad || !input_dev) 788 if (!xpad || !input_dev)
789 goto fail1; 789 goto fail1;
790 790
791 xpad->idata = usb_buffer_alloc(udev, XPAD_PKT_LEN, 791 xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN,
792 GFP_KERNEL, &xpad->idata_dma); 792 GFP_KERNEL, &xpad->idata_dma);
793 if (!xpad->idata) 793 if (!xpad->idata)
794 goto fail1; 794 goto fail1;
795 795
@@ -942,7 +942,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
942 fail5: usb_kill_urb(xpad->irq_in); 942 fail5: usb_kill_urb(xpad->irq_in);
943 fail4: usb_free_urb(xpad->irq_in); 943 fail4: usb_free_urb(xpad->irq_in);
944 fail3: xpad_deinit_output(xpad); 944 fail3: xpad_deinit_output(xpad);
945 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 945 fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
946 fail1: input_free_device(input_dev); 946 fail1: input_free_device(input_dev);
947 kfree(xpad); 947 kfree(xpad);
948 return error; 948 return error;
@@ -964,7 +964,7 @@ static void xpad_disconnect(struct usb_interface *intf)
964 usb_kill_urb(xpad->irq_in); 964 usb_kill_urb(xpad->irq_in);
965 } 965 }
966 usb_free_urb(xpad->irq_in); 966 usb_free_urb(xpad->irq_in);
967 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 967 usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
968 xpad->idata, xpad->idata_dma); 968 xpad->idata, xpad->idata_dma);
969 kfree(xpad); 969 kfree(xpad);
970 } 970 }
diff --git a/drivers/input/misc/ati_remote.c b/drivers/input/misc/ati_remote.c
index e8bbc619f6df..bce57129afba 100644
--- a/drivers/input/misc/ati_remote.c
+++ b/drivers/input/misc/ati_remote.c
@@ -624,13 +624,13 @@ static void ati_remote_irq_in(struct urb *urb)
624static int ati_remote_alloc_buffers(struct usb_device *udev, 624static int ati_remote_alloc_buffers(struct usb_device *udev,
625 struct ati_remote *ati_remote) 625 struct ati_remote *ati_remote)
626{ 626{
627 ati_remote->inbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, GFP_ATOMIC, 627 ati_remote->inbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
628 &ati_remote->inbuf_dma); 628 &ati_remote->inbuf_dma);
629 if (!ati_remote->inbuf) 629 if (!ati_remote->inbuf)
630 return -1; 630 return -1;
631 631
632 ati_remote->outbuf = usb_buffer_alloc(udev, DATA_BUFSIZE, GFP_ATOMIC, 632 ati_remote->outbuf = usb_alloc_coherent(udev, DATA_BUFSIZE, GFP_ATOMIC,
633 &ati_remote->outbuf_dma); 633 &ati_remote->outbuf_dma);
634 if (!ati_remote->outbuf) 634 if (!ati_remote->outbuf)
635 return -1; 635 return -1;
636 636
@@ -653,10 +653,10 @@ static void ati_remote_free_buffers(struct ati_remote *ati_remote)
653 usb_free_urb(ati_remote->irq_urb); 653 usb_free_urb(ati_remote->irq_urb);
654 usb_free_urb(ati_remote->out_urb); 654 usb_free_urb(ati_remote->out_urb);
655 655
656 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 656 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
657 ati_remote->inbuf, ati_remote->inbuf_dma); 657 ati_remote->inbuf, ati_remote->inbuf_dma);
658 658
659 usb_buffer_free(ati_remote->udev, DATA_BUFSIZE, 659 usb_free_coherent(ati_remote->udev, DATA_BUFSIZE,
660 ati_remote->outbuf, ati_remote->outbuf_dma); 660 ati_remote->outbuf, ati_remote->outbuf_dma);
661} 661}
662 662
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 2124b99378bb..e148749b5851 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -589,7 +589,7 @@ static int ati_remote2_urb_init(struct ati_remote2 *ar2)
589 int i, pipe, maxp; 589 int i, pipe, maxp;
590 590
591 for (i = 0; i < 2; i++) { 591 for (i = 0; i < 2; i++) {
592 ar2->buf[i] = usb_buffer_alloc(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]); 592 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
593 if (!ar2->buf[i]) 593 if (!ar2->buf[i])
594 return -ENOMEM; 594 return -ENOMEM;
595 595
@@ -617,7 +617,7 @@ static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
617 617
618 for (i = 0; i < 2; i++) { 618 for (i = 0; i < 2; i++) {
619 usb_free_urb(ar2->urb[i]); 619 usb_free_urb(ar2->urb[i]);
620 usb_buffer_free(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]); 620 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
621 } 621 }
622} 622}
623 623
diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c
index 86457feccfc4..2b0eba6619bd 100644
--- a/drivers/input/misc/cm109.c
+++ b/drivers/input/misc/cm109.c
@@ -102,7 +102,6 @@ struct cm109_dev {
102 struct cm109_ctl_packet *ctl_data; 102 struct cm109_ctl_packet *ctl_data;
103 dma_addr_t ctl_dma; 103 dma_addr_t ctl_dma;
104 struct usb_ctrlrequest *ctl_req; 104 struct usb_ctrlrequest *ctl_req;
105 dma_addr_t ctl_req_dma;
106 struct urb *urb_ctl; 105 struct urb *urb_ctl;
107 /* 106 /*
108 * The 3 bitfields below are protected by ctl_submit_lock. 107 * The 3 bitfields below are protected by ctl_submit_lock.
@@ -629,15 +628,13 @@ static const struct usb_device_id cm109_usb_table[] = {
629 628
630static void cm109_usb_cleanup(struct cm109_dev *dev) 629static void cm109_usb_cleanup(struct cm109_dev *dev)
631{ 630{
632 if (dev->ctl_req) 631 kfree(dev->ctl_req);
633 usb_buffer_free(dev->udev, sizeof(*(dev->ctl_req)),
634 dev->ctl_req, dev->ctl_req_dma);
635 if (dev->ctl_data) 632 if (dev->ctl_data)
636 usb_buffer_free(dev->udev, USB_PKT_LEN, 633 usb_free_coherent(dev->udev, USB_PKT_LEN,
637 dev->ctl_data, dev->ctl_dma); 634 dev->ctl_data, dev->ctl_dma);
638 if (dev->irq_data) 635 if (dev->irq_data)
639 usb_buffer_free(dev->udev, USB_PKT_LEN, 636 usb_free_coherent(dev->udev, USB_PKT_LEN,
640 dev->irq_data, dev->irq_dma); 637 dev->irq_data, dev->irq_dma);
641 638
642 usb_free_urb(dev->urb_irq); /* parameter validation in core/urb */ 639 usb_free_urb(dev->urb_irq); /* parameter validation in core/urb */
643 usb_free_urb(dev->urb_ctl); /* parameter validation in core/urb */ 640 usb_free_urb(dev->urb_ctl); /* parameter validation in core/urb */
@@ -686,18 +683,17 @@ static int cm109_usb_probe(struct usb_interface *intf,
686 goto err_out; 683 goto err_out;
687 684
688 /* allocate usb buffers */ 685 /* allocate usb buffers */
689 dev->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN, 686 dev->irq_data = usb_alloc_coherent(udev, USB_PKT_LEN,
690 GFP_KERNEL, &dev->irq_dma); 687 GFP_KERNEL, &dev->irq_dma);
691 if (!dev->irq_data) 688 if (!dev->irq_data)
692 goto err_out; 689 goto err_out;
693 690
694 dev->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN, 691 dev->ctl_data = usb_alloc_coherent(udev, USB_PKT_LEN,
695 GFP_KERNEL, &dev->ctl_dma); 692 GFP_KERNEL, &dev->ctl_dma);
696 if (!dev->ctl_data) 693 if (!dev->ctl_data)
697 goto err_out; 694 goto err_out;
698 695
699 dev->ctl_req = usb_buffer_alloc(udev, sizeof(*(dev->ctl_req)), 696 dev->ctl_req = kmalloc(sizeof(*(dev->ctl_req)), GFP_KERNEL);
700 GFP_KERNEL, &dev->ctl_req_dma);
701 if (!dev->ctl_req) 697 if (!dev->ctl_req)
702 goto err_out; 698 goto err_out;
703 699
@@ -735,10 +731,8 @@ static int cm109_usb_probe(struct usb_interface *intf,
735 usb_fill_control_urb(dev->urb_ctl, udev, usb_sndctrlpipe(udev, 0), 731 usb_fill_control_urb(dev->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
736 (void *)dev->ctl_req, dev->ctl_data, USB_PKT_LEN, 732 (void *)dev->ctl_req, dev->ctl_data, USB_PKT_LEN,
737 cm109_urb_ctl_callback, dev); 733 cm109_urb_ctl_callback, dev);
738 dev->urb_ctl->setup_dma = dev->ctl_req_dma;
739 dev->urb_ctl->transfer_dma = dev->ctl_dma; 734 dev->urb_ctl->transfer_dma = dev->ctl_dma;
740 dev->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP | 735 dev->urb_ctl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
741 URB_NO_TRANSFER_DMA_MAP;
742 dev->urb_ctl->dev = udev; 736 dev->urb_ctl->dev = udev;
743 737
744 /* find out the physical bus location */ 738 /* find out the physical bus location */
diff --git a/drivers/input/misc/keyspan_remote.c b/drivers/input/misc/keyspan_remote.c
index 86afdd1fdf9d..a93c525475c6 100644
--- a/drivers/input/misc/keyspan_remote.c
+++ b/drivers/input/misc/keyspan_remote.c
@@ -464,7 +464,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic
464 remote->in_endpoint = endpoint; 464 remote->in_endpoint = endpoint;
465 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */ 465 remote->toggle = -1; /* Set to -1 so we will always not match the toggle from the first remote message. */
466 466
467 remote->in_buffer = usb_buffer_alloc(udev, RECV_SIZE, GFP_ATOMIC, &remote->in_dma); 467 remote->in_buffer = usb_alloc_coherent(udev, RECV_SIZE, GFP_ATOMIC, &remote->in_dma);
468 if (!remote->in_buffer) { 468 if (!remote->in_buffer) {
469 error = -ENOMEM; 469 error = -ENOMEM;
470 goto fail1; 470 goto fail1;
@@ -543,7 +543,7 @@ static int keyspan_probe(struct usb_interface *interface, const struct usb_devic
543 return 0; 543 return 0;
544 544
545 fail3: usb_free_urb(remote->irq_urb); 545 fail3: usb_free_urb(remote->irq_urb);
546 fail2: usb_buffer_free(udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 546 fail2: usb_free_coherent(udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
547 fail1: kfree(remote); 547 fail1: kfree(remote);
548 input_free_device(input_dev); 548 input_free_device(input_dev);
549 549
@@ -564,7 +564,7 @@ static void keyspan_disconnect(struct usb_interface *interface)
564 input_unregister_device(remote->input); 564 input_unregister_device(remote->input);
565 usb_kill_urb(remote->irq_urb); 565 usb_kill_urb(remote->irq_urb);
566 usb_free_urb(remote->irq_urb); 566 usb_free_urb(remote->irq_urb);
567 usb_buffer_free(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma); 567 usb_free_coherent(remote->udev, RECV_SIZE, remote->in_buffer, remote->in_dma);
568 kfree(remote); 568 kfree(remote);
569 } 569 }
570} 570}
diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c
index 668913d12044..bf170f6b4422 100644
--- a/drivers/input/misc/powermate.c
+++ b/drivers/input/misc/powermate.c
@@ -64,7 +64,6 @@ struct powermate_device {
64 dma_addr_t data_dma; 64 dma_addr_t data_dma;
65 struct urb *irq, *config; 65 struct urb *irq, *config;
66 struct usb_ctrlrequest *configcr; 66 struct usb_ctrlrequest *configcr;
67 dma_addr_t configcr_dma;
68 struct usb_device *udev; 67 struct usb_device *udev;
69 struct input_dev *input; 68 struct input_dev *input;
70 spinlock_t lock; 69 spinlock_t lock;
@@ -182,8 +181,6 @@ static void powermate_sync_state(struct powermate_device *pm)
182 usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0), 181 usb_fill_control_urb(pm->config, pm->udev, usb_sndctrlpipe(pm->udev, 0),
183 (void *) pm->configcr, NULL, 0, 182 (void *) pm->configcr, NULL, 0,
184 powermate_config_complete, pm); 183 powermate_config_complete, pm);
185 pm->config->setup_dma = pm->configcr_dma;
186 pm->config->transfer_flags |= URB_NO_SETUP_DMA_MAP;
187 184
188 if (usb_submit_urb(pm->config, GFP_ATOMIC)) 185 if (usb_submit_urb(pm->config, GFP_ATOMIC))
189 printk(KERN_ERR "powermate: usb_submit_urb(config) failed"); 186 printk(KERN_ERR "powermate: usb_submit_urb(config) failed");
@@ -276,13 +273,12 @@ static int powermate_input_event(struct input_dev *dev, unsigned int type, unsig
276 273
277static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm) 274static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_device *pm)
278{ 275{
279 pm->data = usb_buffer_alloc(udev, POWERMATE_PAYLOAD_SIZE_MAX, 276 pm->data = usb_alloc_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
280 GFP_ATOMIC, &pm->data_dma); 277 GFP_ATOMIC, &pm->data_dma);
281 if (!pm->data) 278 if (!pm->data)
282 return -1; 279 return -1;
283 280
284 pm->configcr = usb_buffer_alloc(udev, sizeof(*(pm->configcr)), 281 pm->configcr = kmalloc(sizeof(*(pm->configcr)), GFP_KERNEL);
285 GFP_ATOMIC, &pm->configcr_dma);
286 if (!pm->configcr) 282 if (!pm->configcr)
287 return -1; 283 return -1;
288 284
@@ -291,10 +287,9 @@ static int powermate_alloc_buffers(struct usb_device *udev, struct powermate_dev
291 287
292static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm) 288static void powermate_free_buffers(struct usb_device *udev, struct powermate_device *pm)
293{ 289{
294 usb_buffer_free(udev, POWERMATE_PAYLOAD_SIZE_MAX, 290 usb_free_coherent(udev, POWERMATE_PAYLOAD_SIZE_MAX,
295 pm->data, pm->data_dma); 291 pm->data, pm->data_dma);
296 usb_buffer_free(udev, sizeof(*(pm->configcr)), 292 kfree(pm->configcr);
297 pm->configcr, pm->configcr_dma);
298} 293}
299 294
300/* Called whenever a USB device matching one in our supported devices table is connected */ 295/* Called whenever a USB device matching one in our supported devices table is connected */
diff --git a/drivers/input/misc/yealink.c b/drivers/input/misc/yealink.c
index 93a22ac0f88c..41201c6b5e68 100644
--- a/drivers/input/misc/yealink.c
+++ b/drivers/input/misc/yealink.c
@@ -111,7 +111,6 @@ struct yealink_dev {
111 struct yld_ctl_packet *ctl_data; 111 struct yld_ctl_packet *ctl_data;
112 dma_addr_t ctl_dma; 112 dma_addr_t ctl_dma;
113 struct usb_ctrlrequest *ctl_req; 113 struct usb_ctrlrequest *ctl_req;
114 dma_addr_t ctl_req_dma;
115 struct urb *urb_ctl; 114 struct urb *urb_ctl;
116 115
117 char phys[64]; /* physical device path */ 116 char phys[64]; /* physical device path */
@@ -836,12 +835,9 @@ static int usb_cleanup(struct yealink_dev *yld, int err)
836 usb_free_urb(yld->urb_irq); 835 usb_free_urb(yld->urb_irq);
837 usb_free_urb(yld->urb_ctl); 836 usb_free_urb(yld->urb_ctl);
838 837
839 usb_buffer_free(yld->udev, sizeof(*(yld->ctl_req)), 838 kfree(yld->ctl_req);
840 yld->ctl_req, yld->ctl_req_dma); 839 usb_free_coherent(yld->udev, USB_PKT_LEN, yld->ctl_data, yld->ctl_dma);
841 usb_buffer_free(yld->udev, USB_PKT_LEN, 840 usb_free_coherent(yld->udev, USB_PKT_LEN, yld->irq_data, yld->irq_dma);
842 yld->ctl_data, yld->ctl_dma);
843 usb_buffer_free(yld->udev, USB_PKT_LEN,
844 yld->irq_data, yld->irq_dma);
845 841
846 kfree(yld); 842 kfree(yld);
847 return err; 843 return err;
@@ -886,18 +882,17 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
886 return usb_cleanup(yld, -ENOMEM); 882 return usb_cleanup(yld, -ENOMEM);
887 883
888 /* allocate usb buffers */ 884 /* allocate usb buffers */
889 yld->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN, 885 yld->irq_data = usb_alloc_coherent(udev, USB_PKT_LEN,
890 GFP_ATOMIC, &yld->irq_dma); 886 GFP_ATOMIC, &yld->irq_dma);
891 if (yld->irq_data == NULL) 887 if (yld->irq_data == NULL)
892 return usb_cleanup(yld, -ENOMEM); 888 return usb_cleanup(yld, -ENOMEM);
893 889
894 yld->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN, 890 yld->ctl_data = usb_alloc_coherent(udev, USB_PKT_LEN,
895 GFP_ATOMIC, &yld->ctl_dma); 891 GFP_ATOMIC, &yld->ctl_dma);
896 if (!yld->ctl_data) 892 if (!yld->ctl_data)
897 return usb_cleanup(yld, -ENOMEM); 893 return usb_cleanup(yld, -ENOMEM);
898 894
899 yld->ctl_req = usb_buffer_alloc(udev, sizeof(*(yld->ctl_req)), 895 yld->ctl_req = kmalloc(sizeof(*(yld->ctl_req)), GFP_KERNEL);
900 GFP_ATOMIC, &yld->ctl_req_dma);
901 if (yld->ctl_req == NULL) 896 if (yld->ctl_req == NULL)
902 return usb_cleanup(yld, -ENOMEM); 897 return usb_cleanup(yld, -ENOMEM);
903 898
@@ -936,10 +931,8 @@ static int usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
936 usb_fill_control_urb(yld->urb_ctl, udev, usb_sndctrlpipe(udev, 0), 931 usb_fill_control_urb(yld->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
937 (void *)yld->ctl_req, yld->ctl_data, USB_PKT_LEN, 932 (void *)yld->ctl_req, yld->ctl_data, USB_PKT_LEN,
938 urb_ctl_callback, yld); 933 urb_ctl_callback, yld);
939 yld->urb_ctl->setup_dma = yld->ctl_req_dma;
940 yld->urb_ctl->transfer_dma = yld->ctl_dma; 934 yld->urb_ctl->transfer_dma = yld->ctl_dma;
941 yld->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP | 935 yld->urb_ctl->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
942 URB_NO_TRANSFER_DMA_MAP;
943 yld->urb_ctl->dev = udev; 936 yld->urb_ctl->dev = udev;
944 937
945 /* find out the physical bus location */ 938 /* find out the physical bus location */
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index 53ec7ddd1826..05edd75abca0 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -806,8 +806,8 @@ static int atp_probe(struct usb_interface *iface,
806 if (!dev->urb) 806 if (!dev->urb)
807 goto err_free_devs; 807 goto err_free_devs;
808 808
809 dev->data = usb_buffer_alloc(dev->udev, dev->info->datalen, GFP_KERNEL, 809 dev->data = usb_alloc_coherent(dev->udev, dev->info->datalen, GFP_KERNEL,
810 &dev->urb->transfer_dma); 810 &dev->urb->transfer_dma);
811 if (!dev->data) 811 if (!dev->data)
812 goto err_free_urb; 812 goto err_free_urb;
813 813
@@ -862,8 +862,8 @@ static int atp_probe(struct usb_interface *iface,
862 return 0; 862 return 0;
863 863
864 err_free_buffer: 864 err_free_buffer:
865 usb_buffer_free(dev->udev, dev->info->datalen, 865 usb_free_coherent(dev->udev, dev->info->datalen,
866 dev->data, dev->urb->transfer_dma); 866 dev->data, dev->urb->transfer_dma);
867 err_free_urb: 867 err_free_urb:
868 usb_free_urb(dev->urb); 868 usb_free_urb(dev->urb);
869 err_free_devs: 869 err_free_devs:
@@ -881,8 +881,8 @@ static void atp_disconnect(struct usb_interface *iface)
881 if (dev) { 881 if (dev) {
882 usb_kill_urb(dev->urb); 882 usb_kill_urb(dev->urb);
883 input_unregister_device(dev->input); 883 input_unregister_device(dev->input);
884 usb_buffer_free(dev->udev, dev->info->datalen, 884 usb_free_coherent(dev->udev, dev->info->datalen,
885 dev->data, dev->urb->transfer_dma); 885 dev->data, dev->urb->transfer_dma);
886 usb_free_urb(dev->urb); 886 usb_free_urb(dev->urb);
887 kfree(dev); 887 kfree(dev);
888 } 888 }
diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c
index b89879bd860f..6dedded27222 100644
--- a/drivers/input/mouse/bcm5974.c
+++ b/drivers/input/mouse/bcm5974.c
@@ -715,15 +715,15 @@ static int bcm5974_probe(struct usb_interface *iface,
715 if (!dev->tp_urb) 715 if (!dev->tp_urb)
716 goto err_free_bt_urb; 716 goto err_free_bt_urb;
717 717
718 dev->bt_data = usb_buffer_alloc(dev->udev, 718 dev->bt_data = usb_alloc_coherent(dev->udev,
719 dev->cfg.bt_datalen, GFP_KERNEL, 719 dev->cfg.bt_datalen, GFP_KERNEL,
720 &dev->bt_urb->transfer_dma); 720 &dev->bt_urb->transfer_dma);
721 if (!dev->bt_data) 721 if (!dev->bt_data)
722 goto err_free_urb; 722 goto err_free_urb;
723 723
724 dev->tp_data = usb_buffer_alloc(dev->udev, 724 dev->tp_data = usb_alloc_coherent(dev->udev,
725 dev->cfg.tp_datalen, GFP_KERNEL, 725 dev->cfg.tp_datalen, GFP_KERNEL,
726 &dev->tp_urb->transfer_dma); 726 &dev->tp_urb->transfer_dma);
727 if (!dev->tp_data) 727 if (!dev->tp_data)
728 goto err_free_bt_buffer; 728 goto err_free_bt_buffer;
729 729
@@ -765,10 +765,10 @@ static int bcm5974_probe(struct usb_interface *iface,
765 return 0; 765 return 0;
766 766
767err_free_buffer: 767err_free_buffer:
768 usb_buffer_free(dev->udev, dev->cfg.tp_datalen, 768 usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
769 dev->tp_data, dev->tp_urb->transfer_dma); 769 dev->tp_data, dev->tp_urb->transfer_dma);
770err_free_bt_buffer: 770err_free_bt_buffer:
771 usb_buffer_free(dev->udev, dev->cfg.bt_datalen, 771 usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
772 dev->bt_data, dev->bt_urb->transfer_dma); 772 dev->bt_data, dev->bt_urb->transfer_dma);
773err_free_urb: 773err_free_urb:
774 usb_free_urb(dev->tp_urb); 774 usb_free_urb(dev->tp_urb);
@@ -788,10 +788,10 @@ static void bcm5974_disconnect(struct usb_interface *iface)
788 usb_set_intfdata(iface, NULL); 788 usb_set_intfdata(iface, NULL);
789 789
790 input_unregister_device(dev->input); 790 input_unregister_device(dev->input);
791 usb_buffer_free(dev->udev, dev->cfg.tp_datalen, 791 usb_free_coherent(dev->udev, dev->cfg.tp_datalen,
792 dev->tp_data, dev->tp_urb->transfer_dma); 792 dev->tp_data, dev->tp_urb->transfer_dma);
793 usb_buffer_free(dev->udev, dev->cfg.bt_datalen, 793 usb_free_coherent(dev->udev, dev->cfg.bt_datalen,
794 dev->bt_data, dev->bt_urb->transfer_dma); 794 dev->bt_data, dev->bt_urb->transfer_dma);
795 usb_free_urb(dev->tp_urb); 795 usb_free_urb(dev->tp_urb);
796 usb_free_urb(dev->bt_urb); 796 usb_free_urb(dev->bt_urb);
797 kfree(dev); 797 kfree(dev);
diff --git a/drivers/input/tablet/acecad.c b/drivers/input/tablet/acecad.c
index 37d0539fefa0..aea9a9399a36 100644
--- a/drivers/input/tablet/acecad.c
+++ b/drivers/input/tablet/acecad.c
@@ -155,7 +155,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
155 goto fail1; 155 goto fail1;
156 } 156 }
157 157
158 acecad->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &acecad->data_dma); 158 acecad->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &acecad->data_dma);
159 if (!acecad->data) { 159 if (!acecad->data) {
160 err= -ENOMEM; 160 err= -ENOMEM;
161 goto fail1; 161 goto fail1;
@@ -235,7 +235,7 @@ static int usb_acecad_probe(struct usb_interface *intf, const struct usb_device_
235 235
236 return 0; 236 return 0;
237 237
238 fail2: usb_buffer_free(dev, 8, acecad->data, acecad->data_dma); 238 fail2: usb_free_coherent(dev, 8, acecad->data, acecad->data_dma);
239 fail1: input_free_device(input_dev); 239 fail1: input_free_device(input_dev);
240 kfree(acecad); 240 kfree(acecad);
241 return err; 241 return err;
@@ -249,7 +249,7 @@ static void usb_acecad_disconnect(struct usb_interface *intf)
249 249
250 input_unregister_device(acecad->input); 250 input_unregister_device(acecad->input);
251 usb_free_urb(acecad->irq); 251 usb_free_urb(acecad->irq);
252 usb_buffer_free(acecad->usbdev, 8, acecad->data, acecad->data_dma); 252 usb_free_coherent(acecad->usbdev, 8, acecad->data, acecad->data_dma);
253 kfree(acecad); 253 kfree(acecad);
254} 254}
255 255
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 4be039d7dcad..51b80b08d467 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -1711,8 +1711,8 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1711 goto fail1; 1711 goto fail1;
1712 } 1712 }
1713 1713
1714 aiptek->data = usb_buffer_alloc(usbdev, AIPTEK_PACKET_LENGTH, 1714 aiptek->data = usb_alloc_coherent(usbdev, AIPTEK_PACKET_LENGTH,
1715 GFP_ATOMIC, &aiptek->data_dma); 1715 GFP_ATOMIC, &aiptek->data_dma);
1716 if (!aiptek->data) { 1716 if (!aiptek->data) {
1717 dev_warn(&intf->dev, "cannot allocate usb buffer\n"); 1717 dev_warn(&intf->dev, "cannot allocate usb buffer\n");
1718 goto fail1; 1718 goto fail1;
@@ -1884,8 +1884,8 @@ aiptek_probe(struct usb_interface *intf, const struct usb_device_id *id)
1884 1884
1885 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group); 1885 fail4: sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1886 fail3: usb_free_urb(aiptek->urb); 1886 fail3: usb_free_urb(aiptek->urb);
1887 fail2: usb_buffer_free(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data, 1887 fail2: usb_free_coherent(usbdev, AIPTEK_PACKET_LENGTH, aiptek->data,
1888 aiptek->data_dma); 1888 aiptek->data_dma);
1889 fail1: usb_set_intfdata(intf, NULL); 1889 fail1: usb_set_intfdata(intf, NULL);
1890 input_free_device(inputdev); 1890 input_free_device(inputdev);
1891 kfree(aiptek); 1891 kfree(aiptek);
@@ -1909,9 +1909,9 @@ static void aiptek_disconnect(struct usb_interface *intf)
1909 input_unregister_device(aiptek->inputdev); 1909 input_unregister_device(aiptek->inputdev);
1910 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group); 1910 sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
1911 usb_free_urb(aiptek->urb); 1911 usb_free_urb(aiptek->urb);
1912 usb_buffer_free(interface_to_usbdev(intf), 1912 usb_free_coherent(interface_to_usbdev(intf),
1913 AIPTEK_PACKET_LENGTH, 1913 AIPTEK_PACKET_LENGTH,
1914 aiptek->data, aiptek->data_dma); 1914 aiptek->data, aiptek->data_dma);
1915 kfree(aiptek); 1915 kfree(aiptek);
1916 } 1916 }
1917} 1917}
diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
index 866a9ee1af1a..8ea6afe2e992 100644
--- a/drivers/input/tablet/gtco.c
+++ b/drivers/input/tablet/gtco.c
@@ -850,8 +850,8 @@ static int gtco_probe(struct usb_interface *usbinterface,
850 gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface)); 850 gtco->usbdev = usb_get_dev(interface_to_usbdev(usbinterface));
851 851
852 /* Allocate some data for incoming reports */ 852 /* Allocate some data for incoming reports */
853 gtco->buffer = usb_buffer_alloc(gtco->usbdev, REPORT_MAX_SIZE, 853 gtco->buffer = usb_alloc_coherent(gtco->usbdev, REPORT_MAX_SIZE,
854 GFP_KERNEL, &gtco->buf_dma); 854 GFP_KERNEL, &gtco->buf_dma);
855 if (!gtco->buffer) { 855 if (!gtco->buffer) {
856 err("No more memory for us buffers"); 856 err("No more memory for us buffers");
857 error = -ENOMEM; 857 error = -ENOMEM;
@@ -982,8 +982,8 @@ static int gtco_probe(struct usb_interface *usbinterface,
982 err_free_urb: 982 err_free_urb:
983 usb_free_urb(gtco->urbinfo); 983 usb_free_urb(gtco->urbinfo);
984 err_free_buf: 984 err_free_buf:
985 usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, 985 usb_free_coherent(gtco->usbdev, REPORT_MAX_SIZE,
986 gtco->buffer, gtco->buf_dma); 986 gtco->buffer, gtco->buf_dma);
987 err_free_devs: 987 err_free_devs:
988 input_free_device(input_dev); 988 input_free_device(input_dev);
989 kfree(gtco); 989 kfree(gtco);
@@ -1005,8 +1005,8 @@ static void gtco_disconnect(struct usb_interface *interface)
1005 input_unregister_device(gtco->inputdevice); 1005 input_unregister_device(gtco->inputdevice);
1006 usb_kill_urb(gtco->urbinfo); 1006 usb_kill_urb(gtco->urbinfo);
1007 usb_free_urb(gtco->urbinfo); 1007 usb_free_urb(gtco->urbinfo);
1008 usb_buffer_free(gtco->usbdev, REPORT_MAX_SIZE, 1008 usb_free_coherent(gtco->usbdev, REPORT_MAX_SIZE,
1009 gtco->buffer, gtco->buf_dma); 1009 gtco->buffer, gtco->buf_dma);
1010 kfree(gtco); 1010 kfree(gtco);
1011 } 1011 }
1012 1012
diff --git a/drivers/input/tablet/kbtab.c b/drivers/input/tablet/kbtab.c
index b9969f120247..290f4e57b589 100644
--- a/drivers/input/tablet/kbtab.c
+++ b/drivers/input/tablet/kbtab.c
@@ -122,7 +122,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
122 if (!kbtab || !input_dev) 122 if (!kbtab || !input_dev)
123 goto fail1; 123 goto fail1;
124 124
125 kbtab->data = usb_buffer_alloc(dev, 8, GFP_KERNEL, &kbtab->data_dma); 125 kbtab->data = usb_alloc_coherent(dev, 8, GFP_KERNEL, &kbtab->data_dma);
126 if (!kbtab->data) 126 if (!kbtab->data)
127 goto fail1; 127 goto fail1;
128 128
@@ -173,7 +173,7 @@ static int kbtab_probe(struct usb_interface *intf, const struct usb_device_id *i
173 return 0; 173 return 0;
174 174
175 fail3: usb_free_urb(kbtab->irq); 175 fail3: usb_free_urb(kbtab->irq);
176 fail2: usb_buffer_free(dev, 8, kbtab->data, kbtab->data_dma); 176 fail2: usb_free_coherent(dev, 8, kbtab->data, kbtab->data_dma);
177 fail1: input_free_device(input_dev); 177 fail1: input_free_device(input_dev);
178 kfree(kbtab); 178 kfree(kbtab);
179 return error; 179 return error;
@@ -187,7 +187,7 @@ static void kbtab_disconnect(struct usb_interface *intf)
187 187
188 input_unregister_device(kbtab->dev); 188 input_unregister_device(kbtab->dev);
189 usb_free_urb(kbtab->irq); 189 usb_free_urb(kbtab->irq);
190 usb_buffer_free(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma); 190 usb_free_coherent(kbtab->usbdev, 8, kbtab->data, kbtab->data_dma);
191 kfree(kbtab); 191 kfree(kbtab);
192} 192}
193 193
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index d90f4e00e51d..2dc0c07c0469 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -465,8 +465,8 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
465 goto fail1; 465 goto fail1;
466 } 466 }
467 467
468 wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX, 468 wacom_wac->data = usb_alloc_coherent(dev, WACOM_PKGLEN_MAX,
469 GFP_KERNEL, &wacom->data_dma); 469 GFP_KERNEL, &wacom->data_dma);
470 if (!wacom_wac->data) { 470 if (!wacom_wac->data) {
471 error = -ENOMEM; 471 error = -ENOMEM;
472 goto fail1; 472 goto fail1;
@@ -536,7 +536,7 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
536 536
537 fail4: wacom_remove_shared_data(wacom_wac); 537 fail4: wacom_remove_shared_data(wacom_wac);
538 fail3: usb_free_urb(wacom->irq); 538 fail3: usb_free_urb(wacom->irq);
539 fail2: usb_buffer_free(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma); 539 fail2: usb_free_coherent(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
540 fail1: input_free_device(input_dev); 540 fail1: input_free_device(input_dev);
541 kfree(wacom); 541 kfree(wacom);
542 return error; 542 return error;
@@ -551,7 +551,7 @@ static void wacom_disconnect(struct usb_interface *intf)
551 usb_kill_urb(wacom->irq); 551 usb_kill_urb(wacom->irq);
552 input_unregister_device(wacom->wacom_wac.input); 552 input_unregister_device(wacom->wacom_wac.input);
553 usb_free_urb(wacom->irq); 553 usb_free_urb(wacom->irq);
554 usb_buffer_free(interface_to_usbdev(intf), WACOM_PKGLEN_MAX, 554 usb_free_coherent(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
555 wacom->wacom_wac.data, wacom->data_dma); 555 wacom->wacom_wac.data, wacom->data_dma);
556 wacom_remove_shared_data(&wacom->wacom_wac); 556 wacom_remove_shared_data(&wacom->wacom_wac);
557 kfree(wacom); 557 kfree(wacom);
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 0b0ae2e17a60..29a8bbf3f086 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -1290,8 +1290,8 @@ static void usbtouch_close(struct input_dev *input)
1290static void usbtouch_free_buffers(struct usb_device *udev, 1290static void usbtouch_free_buffers(struct usb_device *udev,
1291 struct usbtouch_usb *usbtouch) 1291 struct usbtouch_usb *usbtouch)
1292{ 1292{
1293 usb_buffer_free(udev, usbtouch->type->rept_size, 1293 usb_free_coherent(udev, usbtouch->type->rept_size,
1294 usbtouch->data, usbtouch->data_dma); 1294 usbtouch->data, usbtouch->data_dma);
1295 kfree(usbtouch->buffer); 1295 kfree(usbtouch->buffer);
1296} 1296}
1297 1297
@@ -1335,8 +1335,8 @@ static int usbtouch_probe(struct usb_interface *intf,
1335 if (!type->process_pkt) 1335 if (!type->process_pkt)
1336 type->process_pkt = usbtouch_process_pkt; 1336 type->process_pkt = usbtouch_process_pkt;
1337 1337
1338 usbtouch->data = usb_buffer_alloc(udev, type->rept_size, 1338 usbtouch->data = usb_alloc_coherent(udev, type->rept_size,
1339 GFP_KERNEL, &usbtouch->data_dma); 1339 GFP_KERNEL, &usbtouch->data_dma);
1340 if (!usbtouch->data) 1340 if (!usbtouch->data)
1341 goto out_free; 1341 goto out_free;
1342 1342
diff --git a/drivers/media/dvb/dvb-usb/usb-urb.c b/drivers/media/dvb/dvb-usb/usb-urb.c
index f9702e3756b6..86d68933b6b4 100644
--- a/drivers/media/dvb/dvb-usb/usb-urb.c
+++ b/drivers/media/dvb/dvb-usb/usb-urb.c
@@ -96,8 +96,9 @@ static int usb_free_stream_buffers(struct usb_data_stream *stream)
96 while (stream->buf_num) { 96 while (stream->buf_num) {
97 stream->buf_num--; 97 stream->buf_num--;
98 deb_mem("freeing buffer %d\n",stream->buf_num); 98 deb_mem("freeing buffer %d\n",stream->buf_num);
99 usb_buffer_free(stream->udev, stream->buf_size, 99 usb_free_coherent(stream->udev, stream->buf_size,
100 stream->buf_list[stream->buf_num], stream->dma_addr[stream->buf_num]); 100 stream->buf_list[stream->buf_num],
101 stream->dma_addr[stream->buf_num]);
101 } 102 }
102 } 103 }
103 104
@@ -116,7 +117,7 @@ static int usb_allocate_stream_buffers(struct usb_data_stream *stream, int num,
116 for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) { 117 for (stream->buf_num = 0; stream->buf_num < num; stream->buf_num++) {
117 deb_mem("allocating buffer %d\n",stream->buf_num); 118 deb_mem("allocating buffer %d\n",stream->buf_num);
118 if (( stream->buf_list[stream->buf_num] = 119 if (( stream->buf_list[stream->buf_num] =
119 usb_buffer_alloc(stream->udev, size, GFP_ATOMIC, 120 usb_alloc_coherent(stream->udev, size, GFP_ATOMIC,
120 &stream->dma_addr[stream->buf_num]) ) == NULL) { 121 &stream->dma_addr[stream->buf_num]) ) == NULL) {
121 deb_mem("not enough memory for urb-buffer allocation.\n"); 122 deb_mem("not enough memory for urb-buffer allocation.\n");
122 usb_free_stream_buffers(stream); 123 usb_free_stream_buffers(stream);
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 53baccbab17f..fe1b8037b247 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -1257,7 +1257,7 @@ static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1257 if(!dec->irq_urb) { 1257 if(!dec->irq_urb) {
1258 return -ENOMEM; 1258 return -ENOMEM;
1259 } 1259 }
1260 dec->irq_buffer = usb_buffer_alloc(dec->udev,IRQ_PACKET_SIZE, 1260 dec->irq_buffer = usb_alloc_coherent(dec->udev,IRQ_PACKET_SIZE,
1261 GFP_ATOMIC, &dec->irq_dma_handle); 1261 GFP_ATOMIC, &dec->irq_dma_handle);
1262 if(!dec->irq_buffer) { 1262 if(!dec->irq_buffer) {
1263 usb_free_urb(dec->irq_urb); 1263 usb_free_urb(dec->irq_urb);
@@ -1550,8 +1550,8 @@ static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
1550 1550
1551 usb_free_urb(dec->irq_urb); 1551 usb_free_urb(dec->irq_urb);
1552 1552
1553 usb_buffer_free(dec->udev,IRQ_PACKET_SIZE, 1553 usb_free_coherent(dec->udev,IRQ_PACKET_SIZE,
1554 dec->irq_buffer, dec->irq_dma_handle); 1554 dec->irq_buffer, dec->irq_dma_handle);
1555 1555
1556 if (dec->rc_input_dev) { 1556 if (dec->rc_input_dev) {
1557 input_unregister_device(dec->rc_input_dev); 1557 input_unregister_device(dec->rc_input_dev);
diff --git a/drivers/media/video/au0828/au0828-video.c b/drivers/media/video/au0828/au0828-video.c
index 66150216f976..52f25aabb6dc 100644
--- a/drivers/media/video/au0828/au0828-video.c
+++ b/drivers/media/video/au0828/au0828-video.c
@@ -177,7 +177,7 @@ void au0828_uninit_isoc(struct au0828_dev *dev)
177 usb_unlink_urb(urb); 177 usb_unlink_urb(urb);
178 178
179 if (dev->isoc_ctl.transfer_buffer[i]) { 179 if (dev->isoc_ctl.transfer_buffer[i]) {
180 usb_buffer_free(dev->usbdev, 180 usb_free_coherent(dev->usbdev,
181 urb->transfer_buffer_length, 181 urb->transfer_buffer_length,
182 dev->isoc_ctl.transfer_buffer[i], 182 dev->isoc_ctl.transfer_buffer[i],
183 urb->transfer_dma); 183 urb->transfer_dma);
@@ -247,7 +247,7 @@ int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
247 } 247 }
248 dev->isoc_ctl.urb[i] = urb; 248 dev->isoc_ctl.urb[i] = urb;
249 249
250 dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->usbdev, 250 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->usbdev,
251 sb_size, GFP_KERNEL, &urb->transfer_dma); 251 sb_size, GFP_KERNEL, &urb->transfer_dma);
252 if (!dev->isoc_ctl.transfer_buffer[i]) { 252 if (!dev->isoc_ctl.transfer_buffer[i]) {
253 printk("unable to allocate %i bytes for transfer" 253 printk("unable to allocate %i bytes for transfer"
diff --git a/drivers/media/video/cx231xx/cx231xx-core.c b/drivers/media/video/cx231xx/cx231xx-core.c
index f5e1a2315fcc..912a4d740206 100644
--- a/drivers/media/video/cx231xx/cx231xx-core.c
+++ b/drivers/media/video/cx231xx/cx231xx-core.c
@@ -676,11 +676,11 @@ void cx231xx_uninit_isoc(struct cx231xx *dev)
676 usb_unlink_urb(urb); 676 usb_unlink_urb(urb);
677 677
678 if (dev->video_mode.isoc_ctl.transfer_buffer[i]) { 678 if (dev->video_mode.isoc_ctl.transfer_buffer[i]) {
679 usb_buffer_free(dev->udev, 679 usb_free_coherent(dev->udev,
680 urb->transfer_buffer_length, 680 urb->transfer_buffer_length,
681 dev->video_mode.isoc_ctl. 681 dev->video_mode.isoc_ctl.
682 transfer_buffer[i], 682 transfer_buffer[i],
683 urb->transfer_dma); 683 urb->transfer_dma);
684 } 684 }
685 usb_free_urb(urb); 685 usb_free_urb(urb);
686 dev->video_mode.isoc_ctl.urb[i] = NULL; 686 dev->video_mode.isoc_ctl.urb[i] = NULL;
@@ -767,8 +767,8 @@ int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
767 dev->video_mode.isoc_ctl.urb[i] = urb; 767 dev->video_mode.isoc_ctl.urb[i] = urb;
768 768
769 dev->video_mode.isoc_ctl.transfer_buffer[i] = 769 dev->video_mode.isoc_ctl.transfer_buffer[i] =
770 usb_buffer_alloc(dev->udev, sb_size, GFP_KERNEL, 770 usb_alloc_coherent(dev->udev, sb_size, GFP_KERNEL,
771 &urb->transfer_dma); 771 &urb->transfer_dma);
772 if (!dev->video_mode.isoc_ctl.transfer_buffer[i]) { 772 if (!dev->video_mode.isoc_ctl.transfer_buffer[i]) {
773 cx231xx_err("unable to allocate %i bytes for transfer" 773 cx231xx_err("unable to allocate %i bytes for transfer"
774 " buffer %i%s\n", 774 " buffer %i%s\n",
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index d3813ed789d9..331e1cac4272 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -970,7 +970,7 @@ void em28xx_uninit_isoc(struct em28xx *dev)
970 usb_unlink_urb(urb); 970 usb_unlink_urb(urb);
971 971
972 if (dev->isoc_ctl.transfer_buffer[i]) { 972 if (dev->isoc_ctl.transfer_buffer[i]) {
973 usb_buffer_free(dev->udev, 973 usb_free_coherent(dev->udev,
974 urb->transfer_buffer_length, 974 urb->transfer_buffer_length,
975 dev->isoc_ctl.transfer_buffer[i], 975 dev->isoc_ctl.transfer_buffer[i],
976 urb->transfer_dma); 976 urb->transfer_dma);
@@ -1045,7 +1045,7 @@ int em28xx_init_isoc(struct em28xx *dev, int max_packets,
1045 } 1045 }
1046 dev->isoc_ctl.urb[i] = urb; 1046 dev->isoc_ctl.urb[i] = urb;
1047 1047
1048 dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->udev, 1048 dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
1049 sb_size, GFP_KERNEL, &urb->transfer_dma); 1049 sb_size, GFP_KERNEL, &urb->transfer_dma);
1050 if (!dev->isoc_ctl.transfer_buffer[i]) { 1050 if (!dev->isoc_ctl.transfer_buffer[i]) {
1051 em28xx_err("unable to allocate %i bytes for transfer" 1051 em28xx_err("unable to allocate %i bytes for transfer"
diff --git a/drivers/media/video/gspca/benq.c b/drivers/media/video/gspca/benq.c
index 43ac4af8d3ed..fce8d9492641 100644
--- a/drivers/media/video/gspca/benq.c
+++ b/drivers/media/video/gspca/benq.c
@@ -117,13 +117,13 @@ static int sd_start(struct gspca_dev *gspca_dev)
117 return -ENOMEM; 117 return -ENOMEM;
118 } 118 }
119 gspca_dev->urb[n] = urb; 119 gspca_dev->urb[n] = urb;
120 urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, 120 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev,
121 SD_PKT_SZ * SD_NPKT, 121 SD_PKT_SZ * SD_NPKT,
122 GFP_KERNEL, 122 GFP_KERNEL,
123 &urb->transfer_dma); 123 &urb->transfer_dma);
124 124
125 if (urb->transfer_buffer == NULL) { 125 if (urb->transfer_buffer == NULL) {
126 err("usb_buffer_alloc failed"); 126 err("usb_alloc_coherent failed");
127 return -ENOMEM; 127 return -ENOMEM;
128 } 128 }
129 urb->dev = gspca_dev->dev; 129 urb->dev = gspca_dev->dev;
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index efe615938783..678675bb3652 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -213,7 +213,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
213 goto error; 213 goto error;
214 } 214 }
215 215
216 buffer = usb_buffer_alloc(dev, buffer_len, 216 buffer = usb_alloc_coherent(dev, buffer_len,
217 GFP_KERNEL, &urb->transfer_dma); 217 GFP_KERNEL, &urb->transfer_dma);
218 if (!buffer) { 218 if (!buffer) {
219 ret = -ENOMEM; 219 ret = -ENOMEM;
@@ -232,10 +232,10 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
232 return ret; 232 return ret;
233 233
234error_submit: 234error_submit:
235 usb_buffer_free(dev, 235 usb_free_coherent(dev,
236 urb->transfer_buffer_length, 236 urb->transfer_buffer_length,
237 urb->transfer_buffer, 237 urb->transfer_buffer,
238 urb->transfer_dma); 238 urb->transfer_dma);
239error_buffer: 239error_buffer:
240 usb_free_urb(urb); 240 usb_free_urb(urb);
241error: 241error:
@@ -272,10 +272,10 @@ static void gspca_input_destroy_urb(struct gspca_dev *gspca_dev)
272 if (urb) { 272 if (urb) {
273 gspca_dev->int_urb = NULL; 273 gspca_dev->int_urb = NULL;
274 usb_kill_urb(urb); 274 usb_kill_urb(urb);
275 usb_buffer_free(gspca_dev->dev, 275 usb_free_coherent(gspca_dev->dev,
276 urb->transfer_buffer_length, 276 urb->transfer_buffer_length,
277 urb->transfer_buffer, 277 urb->transfer_buffer,
278 urb->transfer_dma); 278 urb->transfer_dma);
279 usb_free_urb(urb); 279 usb_free_urb(urb);
280 } 280 }
281} 281}
@@ -605,10 +605,10 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
605 gspca_dev->urb[i] = NULL; 605 gspca_dev->urb[i] = NULL;
606 usb_kill_urb(urb); 606 usb_kill_urb(urb);
607 if (urb->transfer_buffer != NULL) 607 if (urb->transfer_buffer != NULL)
608 usb_buffer_free(gspca_dev->dev, 608 usb_free_coherent(gspca_dev->dev,
609 urb->transfer_buffer_length, 609 urb->transfer_buffer_length,
610 urb->transfer_buffer, 610 urb->transfer_buffer,
611 urb->transfer_dma); 611 urb->transfer_dma);
612 usb_free_urb(urb); 612 usb_free_urb(urb);
613 } 613 }
614} 614}
@@ -760,13 +760,13 @@ static int create_urbs(struct gspca_dev *gspca_dev,
760 return -ENOMEM; 760 return -ENOMEM;
761 } 761 }
762 gspca_dev->urb[n] = urb; 762 gspca_dev->urb[n] = urb;
763 urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, 763 urb->transfer_buffer = usb_alloc_coherent(gspca_dev->dev,
764 bsize, 764 bsize,
765 GFP_KERNEL, 765 GFP_KERNEL,
766 &urb->transfer_dma); 766 &urb->transfer_dma);
767 767
768 if (urb->transfer_buffer == NULL) { 768 if (urb->transfer_buffer == NULL) {
769 err("usb_buffer_alloc failed"); 769 err("usb_alloc_coherent failed");
770 return -ENOMEM; 770 return -ENOMEM;
771 } 771 }
772 urb->dev = gspca_dev->dev; 772 urb->dev = gspca_dev->dev;
diff --git a/drivers/media/video/hdpvr/hdpvr-video.c b/drivers/media/video/hdpvr/hdpvr-video.c
index d2f0ee29737f..7cfccfd1b870 100644
--- a/drivers/media/video/hdpvr/hdpvr-video.c
+++ b/drivers/media/video/hdpvr/hdpvr-video.c
@@ -92,8 +92,8 @@ static int hdpvr_free_queue(struct list_head *q)
92 buf = list_entry(p, struct hdpvr_buffer, buff_list); 92 buf = list_entry(p, struct hdpvr_buffer, buff_list);
93 93
94 urb = buf->urb; 94 urb = buf->urb;
95 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 95 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
96 urb->transfer_buffer, urb->transfer_dma); 96 urb->transfer_buffer, urb->transfer_dma);
97 usb_free_urb(urb); 97 usb_free_urb(urb);
98 tmp = p->next; 98 tmp = p->next;
99 list_del(p); 99 list_del(p);
@@ -143,8 +143,8 @@ int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count)
143 } 143 }
144 buf->urb = urb; 144 buf->urb = urb;
145 145
146 mem = usb_buffer_alloc(dev->udev, dev->bulk_in_size, GFP_KERNEL, 146 mem = usb_alloc_coherent(dev->udev, dev->bulk_in_size, GFP_KERNEL,
147 &urb->transfer_dma); 147 &urb->transfer_dma);
148 if (!mem) { 148 if (!mem) {
149 v4l2_err(&dev->v4l2_dev, 149 v4l2_err(&dev->v4l2_dev,
150 "cannot allocate usb transfer buffer\n"); 150 "cannot allocate usb transfer buffer\n");
diff --git a/drivers/media/video/tlg2300/pd-main.c b/drivers/media/video/tlg2300/pd-main.c
index c267e0cfb54b..256cc558ba13 100644
--- a/drivers/media/video/tlg2300/pd-main.c
+++ b/drivers/media/video/tlg2300/pd-main.c
@@ -454,8 +454,8 @@ static int poseidon_probe(struct usb_interface *interface,
454 454
455 device_init_wakeup(&udev->dev, 1); 455 device_init_wakeup(&udev->dev, 1);
456#ifdef CONFIG_PM 456#ifdef CONFIG_PM
457 pd->udev->autosuspend_disabled = 0;
458 pd->udev->autosuspend_delay = HZ * PM_SUSPEND_DELAY; 457 pd->udev->autosuspend_delay = HZ * PM_SUSPEND_DELAY;
458 usb_enable_autosuspend(pd->udev);
459 459
460 if (in_hibernation(pd)) { 460 if (in_hibernation(pd)) {
461 INIT_WORK(&pd->pm_work, hibernation_resume); 461 INIT_WORK(&pd->pm_work, hibernation_resume);
diff --git a/drivers/media/video/tlg2300/pd-video.c b/drivers/media/video/tlg2300/pd-video.c
index c750fd115ec4..d0cc012f7ae6 100644
--- a/drivers/media/video/tlg2300/pd-video.c
+++ b/drivers/media/video/tlg2300/pd-video.c
@@ -478,10 +478,10 @@ static int prepare_iso_urb(struct video_data *video)
478 goto out; 478 goto out;
479 479
480 video->urb_array[i] = urb; 480 video->urb_array[i] = urb;
481 mem = usb_buffer_alloc(udev, 481 mem = usb_alloc_coherent(udev,
482 ISO_PKT_SIZE * PK_PER_URB, 482 ISO_PKT_SIZE * PK_PER_URB,
483 GFP_KERNEL, 483 GFP_KERNEL,
484 &urb->transfer_dma); 484 &urb->transfer_dma);
485 485
486 urb->complete = urb_complete_iso; /* handler */ 486 urb->complete = urb_complete_iso; /* handler */
487 urb->dev = udev; 487 urb->dev = udev;
@@ -521,8 +521,8 @@ int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
521 if (urb == NULL) 521 if (urb == NULL)
522 return i; 522 return i;
523 523
524 mem = usb_buffer_alloc(udev, buf_size, gfp_flags, 524 mem = usb_alloc_coherent(udev, buf_size, gfp_flags,
525 &urb->transfer_dma); 525 &urb->transfer_dma);
526 if (mem == NULL) 526 if (mem == NULL)
527 return i; 527 return i;
528 528
@@ -542,7 +542,7 @@ void free_all_urb_generic(struct urb **urb_array, int num)
542 for (i = 0; i < num; i++) { 542 for (i = 0; i < num; i++) {
543 urb = urb_array[i]; 543 urb = urb_array[i];
544 if (urb) { 544 if (urb) {
545 usb_buffer_free(urb->dev, 545 usb_free_coherent(urb->dev,
546 urb->transfer_buffer_length, 546 urb->transfer_buffer_length,
547 urb->transfer_buffer, 547 urb->transfer_buffer,
548 urb->transfer_dma); 548 urb->transfer_dma);
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index f7aae2293758..b9dd74fde212 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -2493,10 +2493,10 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2493 } 2493 }
2494 usbvision->sbuf[bufIdx].urb = urb; 2494 usbvision->sbuf[bufIdx].urb = urb;
2495 usbvision->sbuf[bufIdx].data = 2495 usbvision->sbuf[bufIdx].data =
2496 usb_buffer_alloc(usbvision->dev, 2496 usb_alloc_coherent(usbvision->dev,
2497 sb_size, 2497 sb_size,
2498 GFP_KERNEL, 2498 GFP_KERNEL,
2499 &urb->transfer_dma); 2499 &urb->transfer_dma);
2500 urb->dev = dev; 2500 urb->dev = dev;
2501 urb->context = usbvision; 2501 urb->context = usbvision;
2502 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2502 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
@@ -2552,10 +2552,10 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2552 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2552 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2553 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2553 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2554 if (usbvision->sbuf[bufIdx].data){ 2554 if (usbvision->sbuf[bufIdx].data){
2555 usb_buffer_free(usbvision->dev, 2555 usb_free_coherent(usbvision->dev,
2556 sb_size, 2556 sb_size,
2557 usbvision->sbuf[bufIdx].data, 2557 usbvision->sbuf[bufIdx].data,
2558 usbvision->sbuf[bufIdx].urb->transfer_dma); 2558 usbvision->sbuf[bufIdx].urb->transfer_dma);
2559 } 2559 }
2560 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2560 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2561 usbvision->sbuf[bufIdx].urb = NULL; 2561 usbvision->sbuf[bufIdx].urb = NULL;
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 821a9969b7bf..53f3ef4635eb 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -739,7 +739,7 @@ static void uvc_free_urb_buffers(struct uvc_streaming *stream)
739 739
740 for (i = 0; i < UVC_URBS; ++i) { 740 for (i = 0; i < UVC_URBS; ++i) {
741 if (stream->urb_buffer[i]) { 741 if (stream->urb_buffer[i]) {
742 usb_buffer_free(stream->dev->udev, stream->urb_size, 742 usb_free_coherent(stream->dev->udev, stream->urb_size,
743 stream->urb_buffer[i], stream->urb_dma[i]); 743 stream->urb_buffer[i], stream->urb_dma[i]);
744 stream->urb_buffer[i] = NULL; 744 stream->urb_buffer[i] = NULL;
745 } 745 }
@@ -780,7 +780,7 @@ static int uvc_alloc_urb_buffers(struct uvc_streaming *stream,
780 for (; npackets > 1; npackets /= 2) { 780 for (; npackets > 1; npackets /= 2) {
781 for (i = 0; i < UVC_URBS; ++i) { 781 for (i = 0; i < UVC_URBS; ++i) {
782 stream->urb_size = psize * npackets; 782 stream->urb_size = psize * npackets;
783 stream->urb_buffer[i] = usb_buffer_alloc( 783 stream->urb_buffer[i] = usb_alloc_coherent(
784 stream->dev->udev, stream->urb_size, 784 stream->dev->udev, stream->urb_size,
785 gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]); 785 gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]);
786 if (!stream->urb_buffer[i]) { 786 if (!stream->urb_buffer[i]) {
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index df0a6369d2f2..1fc0871d2ef7 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -512,8 +512,8 @@ static void ems_usb_write_bulk_callback(struct urb *urb)
512 netdev = dev->netdev; 512 netdev = dev->netdev;
513 513
514 /* free up our allocated buffer */ 514 /* free up our allocated buffer */
515 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 515 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
516 urb->transfer_buffer, urb->transfer_dma); 516 urb->transfer_buffer, urb->transfer_dma);
517 517
518 atomic_dec(&dev->active_tx_urbs); 518 atomic_dec(&dev->active_tx_urbs);
519 519
@@ -610,8 +610,8 @@ static int ems_usb_start(struct ems_usb *dev)
610 return -ENOMEM; 610 return -ENOMEM;
611 } 611 }
612 612
613 buf = usb_buffer_alloc(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL, 613 buf = usb_alloc_coherent(dev->udev, RX_BUFFER_SIZE, GFP_KERNEL,
614 &urb->transfer_dma); 614 &urb->transfer_dma);
615 if (!buf) { 615 if (!buf) {
616 dev_err(netdev->dev.parent, 616 dev_err(netdev->dev.parent,
617 "No memory left for USB buffer\n"); 617 "No memory left for USB buffer\n");
@@ -631,8 +631,8 @@ static int ems_usb_start(struct ems_usb *dev)
631 netif_device_detach(dev->netdev); 631 netif_device_detach(dev->netdev);
632 632
633 usb_unanchor_urb(urb); 633 usb_unanchor_urb(urb);
634 usb_buffer_free(dev->udev, RX_BUFFER_SIZE, buf, 634 usb_free_coherent(dev->udev, RX_BUFFER_SIZE, buf,
635 urb->transfer_dma); 635 urb->transfer_dma);
636 break; 636 break;
637 } 637 }
638 638
@@ -773,7 +773,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
773 goto nomem; 773 goto nomem;
774 } 774 }
775 775
776 buf = usb_buffer_alloc(dev->udev, size, GFP_ATOMIC, &urb->transfer_dma); 776 buf = usb_alloc_coherent(dev->udev, size, GFP_ATOMIC, &urb->transfer_dma);
777 if (!buf) { 777 if (!buf) {
778 dev_err(netdev->dev.parent, "No memory left for USB buffer\n"); 778 dev_err(netdev->dev.parent, "No memory left for USB buffer\n");
779 usb_free_urb(urb); 779 usb_free_urb(urb);
@@ -816,7 +816,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
816 */ 816 */
817 if (!context) { 817 if (!context) {
818 usb_unanchor_urb(urb); 818 usb_unanchor_urb(urb);
819 usb_buffer_free(dev->udev, size, buf, urb->transfer_dma); 819 usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
820 820
821 dev_warn(netdev->dev.parent, "couldn't find free context\n"); 821 dev_warn(netdev->dev.parent, "couldn't find free context\n");
822 822
@@ -841,7 +841,7 @@ static netdev_tx_t ems_usb_start_xmit(struct sk_buff *skb, struct net_device *ne
841 can_free_echo_skb(netdev, context->echo_index); 841 can_free_echo_skb(netdev, context->echo_index);
842 842
843 usb_unanchor_urb(urb); 843 usb_unanchor_urb(urb);
844 usb_buffer_free(dev->udev, size, buf, urb->transfer_dma); 844 usb_free_coherent(dev->udev, size, buf, urb->transfer_dma);
845 dev_kfree_skb(skb); 845 dev_kfree_skb(skb);
846 846
847 atomic_dec(&dev->active_tx_urbs); 847 atomic_dec(&dev->active_tx_urbs);
diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c
index 418825d26f90..197c352c47fb 100644
--- a/drivers/net/usb/ipheth.c
+++ b/drivers/net/usb/ipheth.c
@@ -128,17 +128,13 @@ static int ipheth_alloc_urbs(struct ipheth_device *iphone)
128 if (rx_urb == NULL) 128 if (rx_urb == NULL)
129 goto free_tx_urb; 129 goto free_tx_urb;
130 130
131 tx_buf = usb_buffer_alloc(iphone->udev, 131 tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
132 IPHETH_BUF_SIZE, 132 GFP_KERNEL, &tx_urb->transfer_dma);
133 GFP_KERNEL,
134 &tx_urb->transfer_dma);
135 if (tx_buf == NULL) 133 if (tx_buf == NULL)
136 goto free_rx_urb; 134 goto free_rx_urb;
137 135
138 rx_buf = usb_buffer_alloc(iphone->udev, 136 rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
139 IPHETH_BUF_SIZE, 137 GFP_KERNEL, &rx_urb->transfer_dma);
140 GFP_KERNEL,
141 &rx_urb->transfer_dma);
142 if (rx_buf == NULL) 138 if (rx_buf == NULL)
143 goto free_tx_buf; 139 goto free_tx_buf;
144 140
@@ -150,8 +146,8 @@ static int ipheth_alloc_urbs(struct ipheth_device *iphone)
150 return 0; 146 return 0;
151 147
152free_tx_buf: 148free_tx_buf:
153 usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, tx_buf, 149 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
154 tx_urb->transfer_dma); 150 tx_urb->transfer_dma);
155free_rx_urb: 151free_rx_urb:
156 usb_free_urb(rx_urb); 152 usb_free_urb(rx_urb);
157free_tx_urb: 153free_tx_urb:
@@ -162,10 +158,10 @@ error_nomem:
162 158
163static void ipheth_free_urbs(struct ipheth_device *iphone) 159static void ipheth_free_urbs(struct ipheth_device *iphone)
164{ 160{
165 usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf, 161 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
166 iphone->rx_urb->transfer_dma); 162 iphone->rx_urb->transfer_dma);
167 usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf, 163 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
168 iphone->tx_urb->transfer_dma); 164 iphone->tx_urb->transfer_dma);
169 usb_free_urb(iphone->rx_urb); 165 usb_free_urb(iphone->rx_urb);
170 usb_free_urb(iphone->tx_urb); 166 usb_free_urb(iphone->tx_urb);
171} 167}
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 46890dc625dc..d6078b8c4273 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -1155,13 +1155,13 @@ err_fw:
1155 if (!kaweth->irq_urb) 1155 if (!kaweth->irq_urb)
1156 goto err_tx_and_rx; 1156 goto err_tx_and_rx;
1157 1157
1158 kaweth->intbuffer = usb_buffer_alloc( kaweth->dev, 1158 kaweth->intbuffer = usb_alloc_coherent( kaweth->dev,
1159 INTBUFFERSIZE, 1159 INTBUFFERSIZE,
1160 GFP_KERNEL, 1160 GFP_KERNEL,
1161 &kaweth->intbufferhandle); 1161 &kaweth->intbufferhandle);
1162 if (!kaweth->intbuffer) 1162 if (!kaweth->intbuffer)
1163 goto err_tx_and_rx_and_irq; 1163 goto err_tx_and_rx_and_irq;
1164 kaweth->rx_buf = usb_buffer_alloc( kaweth->dev, 1164 kaweth->rx_buf = usb_alloc_coherent( kaweth->dev,
1165 KAWETH_BUF_SIZE, 1165 KAWETH_BUF_SIZE,
1166 GFP_KERNEL, 1166 GFP_KERNEL,
1167 &kaweth->rxbufferhandle); 1167 &kaweth->rxbufferhandle);
@@ -1202,9 +1202,9 @@ err_fw:
1202 1202
1203err_intfdata: 1203err_intfdata:
1204 usb_set_intfdata(intf, NULL); 1204 usb_set_intfdata(intf, NULL);
1205 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle); 1205 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1206err_all_but_rxbuf: 1206err_all_but_rxbuf:
1207 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle); 1207 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1208err_tx_and_rx_and_irq: 1208err_tx_and_rx_and_irq:
1209 usb_free_urb(kaweth->irq_urb); 1209 usb_free_urb(kaweth->irq_urb);
1210err_tx_and_rx: 1210err_tx_and_rx:
@@ -1241,8 +1241,8 @@ static void kaweth_disconnect(struct usb_interface *intf)
1241 usb_free_urb(kaweth->tx_urb); 1241 usb_free_urb(kaweth->tx_urb);
1242 usb_free_urb(kaweth->irq_urb); 1242 usb_free_urb(kaweth->irq_urb);
1243 1243
1244 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle); 1244 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1245 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle); 1245 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1246 1246
1247 free_netdev(netdev); 1247 free_netdev(netdev);
1248} 1248}
diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c
index 16341ffc3df3..0d5081d77dc0 100644
--- a/drivers/net/wimax/i2400m/usb.c
+++ b/drivers/net/wimax/i2400m/usb.c
@@ -514,7 +514,7 @@ int i2400mu_probe(struct usb_interface *iface,
514 iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */ 514 iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */
515 device_init_wakeup(dev, 1); 515 device_init_wakeup(dev, 1);
516 usb_dev->autosuspend_delay = 15 * HZ; 516 usb_dev->autosuspend_delay = 15 * HZ;
517 usb_dev->autosuspend_disabled = 0; 517 usb_enable_autosuspend(usb_dev);
518#endif 518#endif
519 519
520 result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT); 520 result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
diff --git a/drivers/net/wireless/ath/ar9170/usb.c b/drivers/net/wireless/ath/ar9170/usb.c
index abd083a357f5..82ab532a4923 100644
--- a/drivers/net/wireless/ath/ar9170/usb.c
+++ b/drivers/net/wireless/ath/ar9170/usb.c
@@ -215,7 +215,7 @@ resubmit:
215 return; 215 return;
216 216
217free: 217free:
218 usb_buffer_free(aru->udev, 64, urb->transfer_buffer, urb->transfer_dma); 218 usb_free_coherent(aru->udev, 64, urb->transfer_buffer, urb->transfer_dma);
219} 219}
220 220
221static void ar9170_usb_rx_completed(struct urb *urb) 221static void ar9170_usb_rx_completed(struct urb *urb)
@@ -296,7 +296,7 @@ static int ar9170_usb_alloc_rx_irq_urb(struct ar9170_usb *aru)
296 if (!urb) 296 if (!urb)
297 goto out; 297 goto out;
298 298
299 ibuf = usb_buffer_alloc(aru->udev, 64, GFP_KERNEL, &urb->transfer_dma); 299 ibuf = usb_alloc_coherent(aru->udev, 64, GFP_KERNEL, &urb->transfer_dma);
300 if (!ibuf) 300 if (!ibuf)
301 goto out; 301 goto out;
302 302
@@ -309,8 +309,8 @@ static int ar9170_usb_alloc_rx_irq_urb(struct ar9170_usb *aru)
309 err = usb_submit_urb(urb, GFP_KERNEL); 309 err = usb_submit_urb(urb, GFP_KERNEL);
310 if (err) { 310 if (err) {
311 usb_unanchor_urb(urb); 311 usb_unanchor_urb(urb);
312 usb_buffer_free(aru->udev, 64, urb->transfer_buffer, 312 usb_free_coherent(aru->udev, 64, urb->transfer_buffer,
313 urb->transfer_dma); 313 urb->transfer_dma);
314 } 314 }
315 315
316out: 316out:
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index d91ad1a612af..c257940b71b6 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -664,15 +664,15 @@ static struct urb *alloc_rx_urb(struct zd_usb *usb)
664 urb = usb_alloc_urb(0, GFP_KERNEL); 664 urb = usb_alloc_urb(0, GFP_KERNEL);
665 if (!urb) 665 if (!urb)
666 return NULL; 666 return NULL;
667 buffer = usb_buffer_alloc(udev, USB_MAX_RX_SIZE, GFP_KERNEL, 667 buffer = usb_alloc_coherent(udev, USB_MAX_RX_SIZE, GFP_KERNEL,
668 &urb->transfer_dma); 668 &urb->transfer_dma);
669 if (!buffer) { 669 if (!buffer) {
670 usb_free_urb(urb); 670 usb_free_urb(urb);
671 return NULL; 671 return NULL;
672 } 672 }
673 673
674 usb_fill_bulk_urb(urb, udev, usb_rcvbulkpipe(udev, EP_DATA_IN), 674 usb_fill_bulk_urb(urb, udev, usb_rcvbulkpipe(udev, EP_DATA_IN),
675 buffer, USB_MAX_RX_SIZE, 675 buffer, USB_MAX_RX_SIZE,
676 rx_urb_complete, usb); 676 rx_urb_complete, usb);
677 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 677 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
678 678
@@ -683,8 +683,8 @@ static void free_rx_urb(struct urb *urb)
683{ 683{
684 if (!urb) 684 if (!urb)
685 return; 685 return;
686 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 686 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
687 urb->transfer_buffer, urb->transfer_dma); 687 urb->transfer_buffer, urb->transfer_dma);
688 usb_free_urb(urb); 688 usb_free_urb(urb);
689} 689}
690 690
diff --git a/drivers/staging/rt2860/iface/rtmp_usb.h b/drivers/staging/rt2860/iface/rtmp_usb.h
index 6bb384a74660..33479cc443a5 100644
--- a/drivers/staging/rt2860/iface/rtmp_usb.h
+++ b/drivers/staging/rt2860/iface/rtmp_usb.h
@@ -81,8 +81,8 @@ extern u8 EpToQueue[6];
81#define RT28XX_PUT_DEVICE usb_put_dev 81#define RT28XX_PUT_DEVICE usb_put_dev
82#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC) 82#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC)
83#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, GFP_ATOMIC) 83#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, GFP_ATOMIC)
84#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_buffer_alloc(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr) 84#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, BufSize, pDma_addr) usb_alloc_coherent(pUsb_Dev, BufSize, GFP_ATOMIC, pDma_addr)
85#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) usb_buffer_free(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) 85#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, BufSize, pTransferBuf, Dma_addr) usb_free_coherent(pUsb_Dev, BufSize, pTransferBuf, Dma_addr)
86 86
87#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb) 87#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb)
88 88
diff --git a/drivers/staging/udlfb/udlfb.c b/drivers/staging/udlfb/udlfb.c
index a78ade0dc687..aa8195199a2c 100644
--- a/drivers/staging/udlfb/udlfb.c
+++ b/drivers/staging/udlfb/udlfb.c
@@ -1508,8 +1508,8 @@ static void dlfb_free_urb_list(struct dlfb_data *dev)
1508 urb = unode->urb; 1508 urb = unode->urb;
1509 1509
1510 /* Free each separately allocated piece */ 1510 /* Free each separately allocated piece */
1511 usb_buffer_free(urb->dev, dev->urbs.size, 1511 usb_free_coherent(urb->dev, dev->urbs.size,
1512 urb->transfer_buffer, urb->transfer_dma); 1512 urb->transfer_buffer, urb->transfer_dma);
1513 usb_free_urb(urb); 1513 usb_free_urb(urb);
1514 kfree(node); 1514 kfree(node);
1515 } 1515 }
@@ -1543,8 +1543,8 @@ static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size)
1543 } 1543 }
1544 unode->urb = urb; 1544 unode->urb = urb;
1545 1545
1546 buf = usb_buffer_alloc(dev->udev, MAX_TRANSFER, GFP_KERNEL, 1546 buf = usb_alloc_coherent(dev->udev, MAX_TRANSFER, GFP_KERNEL,
1547 &urb->transfer_dma); 1547 &urb->transfer_dma);
1548 if (!buf) { 1548 if (!buf) {
1549 kfree(unode); 1549 kfree(unode);
1550 usb_free_urb(urb); 1550 usb_free_urb(urb);
diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c
index bc2674086673..da30658fa048 100644
--- a/drivers/staging/usbip/stub_rx.c
+++ b/drivers/staging/usbip/stub_rx.c
@@ -21,7 +21,7 @@
21 21
22#include "usbip_common.h" 22#include "usbip_common.h"
23#include "stub.h" 23#include "stub.h"
24#include "../../usb/core/hcd.h" 24#include <linux/usb/hcd.h>
25 25
26 26
27static int is_clear_halt_cmd(struct urb *urb) 27static int is_clear_halt_cmd(struct urb *urb)
diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
index e3fa4216c1cd..52408164036f 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -562,7 +562,7 @@ EXPORT_SYMBOL_GPL(sockfd_to_socket);
562/* there may be more cases to tweak the flags. */ 562/* there may be more cases to tweak the flags. */
563static unsigned int tweak_transfer_flags(unsigned int flags) 563static unsigned int tweak_transfer_flags(unsigned int flags)
564{ 564{
565 flags &= ~(URB_NO_TRANSFER_DMA_MAP|URB_NO_SETUP_DMA_MAP); 565 flags &= ~URB_NO_TRANSFER_DMA_MAP;
566 return flags; 566 return flags;
567} 567}
568 568
diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
index 5e375173bbce..41a1fe5138f4 100644
--- a/drivers/staging/usbip/vhci.h
+++ b/drivers/staging/usbip/vhci.h
@@ -18,7 +18,7 @@
18 */ 18 */
19 19
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include "../../usb/core/hcd.h" 21#include <linux/usb/hcd.h>
22 22
23 23
24struct vhci_device { 24struct vhci_device {
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 25f01b536f67..e213d3fa4920 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -94,19 +94,19 @@
94 } while (0) 94 } while (0)
95 95
96#define uea_enters(usb_dev) \ 96#define uea_enters(usb_dev) \
97 uea_vdbg(usb_dev, "entering %s\n", __func__) 97 uea_vdbg(usb_dev, "entering %s\n" , __func__)
98 98
99#define uea_leaves(usb_dev) \ 99#define uea_leaves(usb_dev) \
100 uea_vdbg(usb_dev, "leaving %s\n", __func__) 100 uea_vdbg(usb_dev, "leaving %s\n" , __func__)
101 101
102#define uea_err(usb_dev, format,args...) \ 102#define uea_err(usb_dev, format, args...) \
103 dev_err(&(usb_dev)->dev ,"[UEAGLE-ATM] " format , ##args) 103 dev_err(&(usb_dev)->dev , "[UEAGLE-ATM] " format , ##args)
104 104
105#define uea_warn(usb_dev, format,args...) \ 105#define uea_warn(usb_dev, format, args...) \
106 dev_warn(&(usb_dev)->dev ,"[Ueagle-atm] " format, ##args) 106 dev_warn(&(usb_dev)->dev , "[Ueagle-atm] " format, ##args)
107 107
108#define uea_info(usb_dev, format,args...) \ 108#define uea_info(usb_dev, format, args...) \
109 dev_info(&(usb_dev)->dev ,"[ueagle-atm] " format, ##args) 109 dev_info(&(usb_dev)->dev , "[ueagle-atm] " format, ##args)
110 110
111struct intr_pkt; 111struct intr_pkt;
112 112
@@ -289,7 +289,7 @@ enum {
289#define IS_ISDN(x) \ 289#define IS_ISDN(x) \
290 ((x)->annex & ANNEXB) 290 ((x)->annex & ANNEXB)
291 291
292#define INS_TO_USBDEV(ins) ins->usb_dev 292#define INS_TO_USBDEV(ins) (ins->usb_dev)
293 293
294#define GET_STATUS(data) \ 294#define GET_STATUS(data) \
295 ((data >> 8) & 0xf) 295 ((data >> 8) & 0xf)
@@ -304,7 +304,7 @@ enum {
304 * The FW_GET_BYTE() macro is provided only for consistency. 304 * The FW_GET_BYTE() macro is provided only for consistency.
305 */ 305 */
306 306
307#define FW_GET_BYTE(p) *((__u8 *) (p)) 307#define FW_GET_BYTE(p) (*((__u8 *) (p)))
308 308
309#define FW_DIR "ueagle-atm/" 309#define FW_DIR "ueagle-atm/"
310#define UEA_FW_NAME_MAX 30 310#define UEA_FW_NAME_MAX 30
@@ -315,7 +315,7 @@ enum {
315 315
316#define ACK_TIMEOUT msecs_to_jiffies(3000) 316#define ACK_TIMEOUT msecs_to_jiffies(3000)
317 317
318#define UEA_INTR_IFACE_NO 0 318#define UEA_INTR_IFACE_NO 0
319#define UEA_US_IFACE_NO 1 319#define UEA_US_IFACE_NO 1
320#define UEA_DS_IFACE_NO 2 320#define UEA_DS_IFACE_NO 2
321 321
@@ -326,9 +326,9 @@ enum {
326#define UEA_INTR_PIPE 0x04 326#define UEA_INTR_PIPE 0x04
327#define UEA_ISO_DATA_PIPE 0x08 327#define UEA_ISO_DATA_PIPE 0x08
328 328
329#define UEA_E1_SET_BLOCK 0x0001 329#define UEA_E1_SET_BLOCK 0x0001
330#define UEA_E4_SET_BLOCK 0x002c 330#define UEA_E4_SET_BLOCK 0x002c
331#define UEA_SET_MODE 0x0003 331#define UEA_SET_MODE 0x0003
332#define UEA_SET_2183_DATA 0x0004 332#define UEA_SET_2183_DATA 0x0004
333#define UEA_SET_TIMEOUT 0x0011 333#define UEA_SET_TIMEOUT 0x0011
334 334
@@ -366,7 +366,7 @@ struct l1_code {
366 u8 string_header[E4_L1_STRING_HEADER]; 366 u8 string_header[E4_L1_STRING_HEADER];
367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER]; 367 u8 page_number_to_block_index[E4_MAX_PAGE_NUMBER];
368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS]; 368 struct block_index page_header[E4_NO_SWAPPAGE_HEADERS];
369 u8 code [0]; 369 u8 code[0];
370} __attribute__ ((packed)); 370} __attribute__ ((packed));
371 371
372/* structures describing a block within a DSP page */ 372/* structures describing a block within a DSP page */
@@ -428,7 +428,8 @@ struct block_info_e4 {
428#define E4_MODEMREADY 0x1 428#define E4_MODEMREADY 0x1
429 429
430#define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf)) 430#define E1_MAKEFUNCTION(t, s) (((t) & 0xf) << 4 | ((s) & 0xf))
431#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | ((st) & 0xf) << 4 | ((s) & 0xf)) 431#define E4_MAKEFUNCTION(t, st, s) (((t) & 0xf) << 8 | \
432 ((st) & 0xf) << 4 | ((s) & 0xf))
432 433
433#define E1_MAKESA(a, b, c, d) \ 434#define E1_MAKESA(a, b, c, d) \
434 (((c) & 0xff) << 24 | \ 435 (((c) & 0xff) << 24 | \
@@ -473,7 +474,7 @@ struct cmv_e4 {
473 __be16 wFunction; 474 __be16 wFunction;
474 __be16 wOffset; 475 __be16 wOffset;
475 __be16 wAddress; 476 __be16 wAddress;
476 __be32 dwData [6]; 477 __be32 dwData[6];
477} __attribute__ ((packed)); 478} __attribute__ ((packed));
478 479
479/* structures representing swap information */ 480/* structures representing swap information */
@@ -534,11 +535,13 @@ struct intr_pkt {
534 535
535static struct usb_driver uea_driver; 536static struct usb_driver uea_driver;
536static DEFINE_MUTEX(uea_mutex); 537static DEFINE_MUTEX(uea_mutex);
537static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III", "Eagle IV"}; 538static const char *chip_name[] = {"ADI930", "Eagle I", "Eagle II", "Eagle III",
539 "Eagle IV"};
538 540
539static int modem_index; 541static int modem_index;
540static unsigned int debug; 542static unsigned int debug;
541static unsigned int altsetting[NB_MODEM] = {[0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF}; 543static unsigned int altsetting[NB_MODEM] = {
544 [0 ... (NB_MODEM - 1)] = FASTEST_ISO_INTF};
542static int sync_wait[NB_MODEM]; 545static int sync_wait[NB_MODEM];
543static char *cmv_file[NB_MODEM]; 546static char *cmv_file[NB_MODEM];
544static int annex[NB_MODEM]; 547static int annex[NB_MODEM];
@@ -555,7 +558,7 @@ MODULE_PARM_DESC(cmv_file,
555 "file name with configuration and management variables"); 558 "file name with configuration and management variables");
556module_param_array(annex, uint, NULL, 0644); 559module_param_array(annex, uint, NULL, 0644);
557MODULE_PARM_DESC(annex, 560MODULE_PARM_DESC(annex,
558 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)"); 561 "manually set annex a/b (0=auto, 1=annex a, 2=annex b)");
559 562
560#define uea_wait(sc, cond, timeo) \ 563#define uea_wait(sc, cond, timeo) \
561({ \ 564({ \
@@ -602,7 +605,8 @@ static int uea_send_modem_cmd(struct usb_device *usb,
602 return (ret == size) ? 0 : -EIO; 605 return (ret == size) ? 0 : -EIO;
603} 606}
604 607
605static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *context) 608static void uea_upload_pre_firmware(const struct firmware *fw_entry,
609 void *context)
606{ 610{
607 struct usb_device *usb = context; 611 struct usb_device *usb = context;
608 const u8 *pfw; 612 const u8 *pfw;
@@ -707,7 +711,8 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
707 } 711 }
708 712
709 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, 713 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
710 GFP_KERNEL, usb, uea_upload_pre_firmware); 714 GFP_KERNEL, usb,
715 uea_upload_pre_firmware);
711 if (ret) 716 if (ret)
712 uea_err(usb, "firmware %s is not available\n", fw_name); 717 uea_err(usb, "firmware %s is not available\n", fw_name);
713 else 718 else
@@ -876,7 +881,7 @@ static int request_dsp(struct uea_softc *sc)
876 if (ret < 0) { 881 if (ret < 0) {
877 uea_err(INS_TO_USBDEV(sc), 882 uea_err(INS_TO_USBDEV(sc),
878 "requesting firmware %s failed with error %d\n", 883 "requesting firmware %s failed with error %d\n",
879 dsp_name, ret); 884 dsp_name, ret);
880 return ret; 885 return ret;
881 } 886 }
882 887
@@ -994,14 +999,17 @@ static void __uea_load_page_e4(struct uea_softc *sc, u8 pageno, int boot)
994 999
995 blockidx = &p->page_header[blockno]; 1000 blockidx = &p->page_header[blockno];
996 blocksize = E4_PAGE_BYTES(blockidx->PageSize); 1001 blocksize = E4_PAGE_BYTES(blockidx->PageSize);
997 blockoffset = sc->dsp_firm->data + le32_to_cpu(blockidx->PageOffset); 1002 blockoffset = sc->dsp_firm->data + le32_to_cpu(
1003 blockidx->PageOffset);
998 1004
999 bi.dwSize = cpu_to_be32(blocksize); 1005 bi.dwSize = cpu_to_be32(blocksize);
1000 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress)); 1006 bi.dwAddress = cpu_to_be32(le32_to_cpu(blockidx->PageAddress));
1001 1007
1002 uea_dbg(INS_TO_USBDEV(sc), 1008 uea_dbg(INS_TO_USBDEV(sc),
1003 "sending block %u for DSP page %u size %u address %x\n", 1009 "sending block %u for DSP page "
1004 blockno, pageno, blocksize, le32_to_cpu(blockidx->PageAddress)); 1010 "%u size %u address %x\n",
1011 blockno, pageno, blocksize,
1012 le32_to_cpu(blockidx->PageAddress));
1005 1013
1006 /* send block info through the IDMA pipe */ 1014 /* send block info through the IDMA pipe */
1007 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE)) 1015 if (uea_idma_write(sc, &bi, E4_BLOCK_INFO_SIZE))
@@ -1042,7 +1050,8 @@ static void uea_load_page_e4(struct work_struct *work)
1042 1050
1043 p = (struct l1_code *) sc->dsp_firm->data; 1051 p = (struct l1_code *) sc->dsp_firm->data;
1044 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) { 1052 if (pageno >= le16_to_cpu(p->page_header[0].PageNumber)) {
1045 uea_err(INS_TO_USBDEV(sc), "invalid DSP page %u requested\n", pageno); 1053 uea_err(INS_TO_USBDEV(sc), "invalid DSP "
1054 "page %u requested\n", pageno);
1046 return; 1055 return;
1047 } 1056 }
1048 1057
@@ -1059,7 +1068,7 @@ static void uea_load_page_e4(struct work_struct *work)
1059 __uea_load_page_e4(sc, i, 1); 1068 __uea_load_page_e4(sc, i, 1);
1060 } 1069 }
1061 1070
1062 uea_dbg(INS_TO_USBDEV(sc),"sending start bi\n"); 1071 uea_dbg(INS_TO_USBDEV(sc) , "sending start bi\n");
1063 1072
1064 bi.wHdr = cpu_to_be16(UEA_BIHDR); 1073 bi.wHdr = cpu_to_be16(UEA_BIHDR);
1065 bi.bBootPage = 0; 1074 bi.bBootPage = 0;
@@ -1139,8 +1148,10 @@ static int uea_cmv_e1(struct uea_softc *sc,
1139 uea_enters(INS_TO_USBDEV(sc)); 1148 uea_enters(INS_TO_USBDEV(sc));
1140 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, " 1149 uea_vdbg(INS_TO_USBDEV(sc), "Function : %d-%d, Address : %c%c%c%c, "
1141 "offset : 0x%04x, data : 0x%08x\n", 1150 "offset : 0x%04x, data : 0x%08x\n",
1142 E1_FUNCTION_TYPE(function), E1_FUNCTION_SUBTYPE(function), 1151 E1_FUNCTION_TYPE(function),
1143 E1_GETSA1(address), E1_GETSA2(address), E1_GETSA3(address), 1152 E1_FUNCTION_SUBTYPE(function),
1153 E1_GETSA1(address), E1_GETSA2(address),
1154 E1_GETSA3(address),
1144 E1_GETSA4(address), offset, data); 1155 E1_GETSA4(address), offset, data);
1145 1156
1146 /* we send a request, but we expect a reply */ 1157 /* we send a request, but we expect a reply */
@@ -1157,7 +1168,8 @@ static int uea_cmv_e1(struct uea_softc *sc,
1157 cmv.wOffsetAddress = cpu_to_le16(offset); 1168 cmv.wOffsetAddress = cpu_to_le16(offset);
1158 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData); 1169 put_unaligned_le32(data >> 16 | data << 16, &cmv.dwData);
1159 1170
1160 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv); 1171 ret = uea_request(sc, UEA_E1_SET_BLOCK, UEA_MPTX_START,
1172 sizeof(cmv), &cmv);
1161 if (ret < 0) 1173 if (ret < 0)
1162 return ret; 1174 return ret;
1163 ret = wait_cmv_ack(sc); 1175 ret = wait_cmv_ack(sc);
@@ -1191,7 +1203,8 @@ static int uea_cmv_e4(struct uea_softc *sc,
1191 cmv.wOffset = cpu_to_be16(offset); 1203 cmv.wOffset = cpu_to_be16(offset);
1192 cmv.dwData[0] = cpu_to_be32(data); 1204 cmv.dwData[0] = cpu_to_be32(data);
1193 1205
1194 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START, sizeof(cmv), &cmv); 1206 ret = uea_request(sc, UEA_E4_SET_BLOCK, UEA_MPTX_START,
1207 sizeof(cmv), &cmv);
1195 if (ret < 0) 1208 if (ret < 0)
1196 return ret; 1209 return ret;
1197 ret = wait_cmv_ack(sc); 1210 ret = wait_cmv_ack(sc);
@@ -1208,7 +1221,7 @@ static inline int uea_read_cmv_e1(struct uea_softc *sc,
1208 uea_err(INS_TO_USBDEV(sc), 1221 uea_err(INS_TO_USBDEV(sc),
1209 "reading cmv failed with error %d\n", ret); 1222 "reading cmv failed with error %d\n", ret);
1210 else 1223 else
1211 *data = sc->data; 1224 *data = sc->data;
1212 1225
1213 return ret; 1226 return ret;
1214} 1227}
@@ -1216,13 +1229,14 @@ static inline int uea_read_cmv_e1(struct uea_softc *sc,
1216static inline int uea_read_cmv_e4(struct uea_softc *sc, 1229static inline int uea_read_cmv_e4(struct uea_softc *sc,
1217 u8 size, u16 group, u16 address, u16 offset, u32 *data) 1230 u8 size, u16 group, u16 address, u16 offset, u32 *data)
1218{ 1231{
1219 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTREAD, size), 1232 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1233 E4_REQUESTREAD, size),
1220 group, address, offset, 0); 1234 group, address, offset, 0);
1221 if (ret < 0) 1235 if (ret < 0)
1222 uea_err(INS_TO_USBDEV(sc), 1236 uea_err(INS_TO_USBDEV(sc),
1223 "reading cmv failed with error %d\n", ret); 1237 "reading cmv failed with error %d\n", ret);
1224 else { 1238 else {
1225 *data = sc->data; 1239 *data = sc->data;
1226 /* size is in 16-bit word quantities */ 1240 /* size is in 16-bit word quantities */
1227 if (size > 2) 1241 if (size > 2)
1228 *(data + 1) = sc->data1; 1242 *(data + 1) = sc->data1;
@@ -1245,7 +1259,8 @@ static inline int uea_write_cmv_e1(struct uea_softc *sc,
1245static inline int uea_write_cmv_e4(struct uea_softc *sc, 1259static inline int uea_write_cmv_e4(struct uea_softc *sc,
1246 u8 size, u16 group, u16 address, u16 offset, u32 data) 1260 u8 size, u16 group, u16 address, u16 offset, u32 data)
1247{ 1261{
1248 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS, E4_REQUESTWRITE, size), 1262 int ret = uea_cmv_e4(sc, E4_MAKEFUNCTION(E4_MEMACCESS,
1263 E4_REQUESTWRITE, size),
1249 group, address, offset, data); 1264 group, address, offset, data);
1250 if (ret < 0) 1265 if (ret < 0)
1251 uea_err(INS_TO_USBDEV(sc), 1266 uea_err(INS_TO_USBDEV(sc),
@@ -1442,27 +1457,29 @@ static int uea_stat_e4(struct uea_softc *sc)
1442 return ret; 1457 return ret;
1443 1458
1444 switch (sc->stats.phy.state) { 1459 switch (sc->stats.phy.state) {
1445 case 0x0: /* not yet synchronized */ 1460 case 0x0: /* not yet synchronized */
1446 case 0x1: 1461 case 0x1:
1447 case 0x3: 1462 case 0x3:
1448 case 0x4: 1463 case 0x4:
1449 uea_dbg(INS_TO_USBDEV(sc), "modem not yet synchronized\n"); 1464 uea_dbg(INS_TO_USBDEV(sc), "modem not yet "
1450 return 0; 1465 "synchronized\n");
1451 case 0x5: /* initialization */ 1466 return 0;
1452 case 0x6: 1467 case 0x5: /* initialization */
1453 case 0x9: 1468 case 0x6:
1454 case 0xa: 1469 case 0x9:
1455 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n"); 1470 case 0xa:
1456 return 0; 1471 uea_dbg(INS_TO_USBDEV(sc), "modem initializing\n");
1457 case 0x2: /* fail ... */ 1472 return 0;
1458 uea_info(INS_TO_USBDEV(sc), "modem synchronization failed" 1473 case 0x2: /* fail ... */
1459 " (may be try other cmv/dsp)\n"); 1474 uea_info(INS_TO_USBDEV(sc), "modem synchronization "
1460 return -EAGAIN; 1475 "failed (may be try other cmv/dsp)\n");
1461 case 0x7: /* operational */ 1476 return -EAGAIN;
1462 break; 1477 case 0x7: /* operational */
1463 default: 1478 break;
1464 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n", sc->stats.phy.state); 1479 default:
1465 return 0; 1480 uea_warn(INS_TO_USBDEV(sc), "unknown state: %x\n",
1481 sc->stats.phy.state);
1482 return 0;
1466 } 1483 }
1467 1484
1468 if (data != 7) { 1485 if (data != 7) {
@@ -1502,9 +1519,9 @@ static int uea_stat_e4(struct uea_softc *sc)
1502 if (sc->stats.phy.flags) { 1519 if (sc->stats.phy.flags) {
1503 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n", 1520 uea_dbg(INS_TO_USBDEV(sc), "Stat flag = 0x%x\n",
1504 sc->stats.phy.flags); 1521 sc->stats.phy.flags);
1505 if (sc->stats.phy.flags & 1) //delineation LOSS 1522 if (sc->stats.phy.flags & 1) /* delineation LOSS */
1506 return -EAGAIN; 1523 return -EAGAIN;
1507 if (sc->stats.phy.flags & 0x4000) //Reset Flag 1524 if (sc->stats.phy.flags & 0x4000) /* Reset Flag */
1508 return -EAGAIN; 1525 return -EAGAIN;
1509 return 0; 1526 return 0;
1510 } 1527 }
@@ -1618,7 +1635,8 @@ static int request_cmvs(struct uea_softc *sc,
1618 if (ret < 0) { 1635 if (ret < 0) {
1619 /* if caller can handle old version, try to provide it */ 1636 /* if caller can handle old version, try to provide it */
1620 if (*ver == 1) { 1637 if (*ver == 1) {
1621 uea_warn(INS_TO_USBDEV(sc), "requesting firmware %s failed, " 1638 uea_warn(INS_TO_USBDEV(sc), "requesting "
1639 "firmware %s failed, "
1622 "try to get older cmvs\n", cmv_name); 1640 "try to get older cmvs\n", cmv_name);
1623 return request_cmvs_old(sc, cmvs, fw); 1641 return request_cmvs_old(sc, cmvs, fw);
1624 } 1642 }
@@ -1632,8 +1650,8 @@ static int request_cmvs(struct uea_softc *sc,
1632 data = (u8 *) (*fw)->data; 1650 data = (u8 *) (*fw)->data;
1633 if (size < 4 || strncmp(data, "cmv2", 4) != 0) { 1651 if (size < 4 || strncmp(data, "cmv2", 4) != 0) {
1634 if (*ver == 1) { 1652 if (*ver == 1) {
1635 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted, " 1653 uea_warn(INS_TO_USBDEV(sc), "firmware %s is corrupted,"
1636 "try to get older cmvs\n", cmv_name); 1654 " try to get older cmvs\n", cmv_name);
1637 release_firmware(*fw); 1655 release_firmware(*fw);
1638 return request_cmvs_old(sc, cmvs, fw); 1656 return request_cmvs_old(sc, cmvs, fw);
1639 } 1657 }
@@ -1670,7 +1688,7 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1670 int i, ret, len; 1688 int i, ret, len;
1671 void *cmvs_ptr; 1689 void *cmvs_ptr;
1672 const struct firmware *cmvs_fw; 1690 const struct firmware *cmvs_fw;
1673 int ver = 1; // we can handle v1 cmv firmware version; 1691 int ver = 1; /* we can handle v1 cmv firmware version; */
1674 1692
1675 /* Enter in R-IDLE (cmv) until instructed otherwise */ 1693 /* Enter in R-IDLE (cmv) until instructed otherwise */
1676 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1); 1694 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 1);
@@ -1685,7 +1703,7 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1685 sc->stats.phy.firmid); 1703 sc->stats.phy.firmid);
1686 1704
1687 /* get options */ 1705 /* get options */
1688 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver); 1706 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1689 if (ret < 0) 1707 if (ret < 0)
1690 return ret; 1708 return ret;
1691 1709
@@ -1697,9 +1715,10 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1697 "please update your firmware\n"); 1715 "please update your firmware\n");
1698 1716
1699 for (i = 0; i < len; i++) { 1717 for (i = 0; i < len; i++) {
1700 ret = uea_write_cmv_e1(sc, get_unaligned_le32(&cmvs_v1[i].address), 1718 ret = uea_write_cmv_e1(sc,
1701 get_unaligned_le16(&cmvs_v1[i].offset), 1719 get_unaligned_le32(&cmvs_v1[i].address),
1702 get_unaligned_le32(&cmvs_v1[i].data)); 1720 get_unaligned_le16(&cmvs_v1[i].offset),
1721 get_unaligned_le32(&cmvs_v1[i].data));
1703 if (ret < 0) 1722 if (ret < 0)
1704 goto out; 1723 goto out;
1705 } 1724 }
@@ -1707,9 +1726,10 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1707 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr; 1726 struct uea_cmvs_v2 *cmvs_v2 = cmvs_ptr;
1708 1727
1709 for (i = 0; i < len; i++) { 1728 for (i = 0; i < len; i++) {
1710 ret = uea_write_cmv_e1(sc, get_unaligned_le32(&cmvs_v2[i].address), 1729 ret = uea_write_cmv_e1(sc,
1711 (u16) get_unaligned_le32(&cmvs_v2[i].offset), 1730 get_unaligned_le32(&cmvs_v2[i].address),
1712 get_unaligned_le32(&cmvs_v2[i].data)); 1731 (u16) get_unaligned_le32(&cmvs_v2[i].offset),
1732 get_unaligned_le32(&cmvs_v2[i].data));
1713 if (ret < 0) 1733 if (ret < 0)
1714 goto out; 1734 goto out;
1715 } 1735 }
@@ -1722,7 +1742,8 @@ static int uea_send_cmvs_e1(struct uea_softc *sc)
1722 /* Enter in R-ACT-REQ */ 1742 /* Enter in R-ACT-REQ */
1723 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2); 1743 ret = uea_write_cmv_e1(sc, E1_SA_CNTL, 0, 2);
1724 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n"); 1744 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1725 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n"); 1745 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1746 "synchronization...\n");
1726out: 1747out:
1727 release_firmware(cmvs_fw); 1748 release_firmware(cmvs_fw);
1728 return ret; 1749 return ret;
@@ -1733,7 +1754,7 @@ static int uea_send_cmvs_e4(struct uea_softc *sc)
1733 int i, ret, len; 1754 int i, ret, len;
1734 void *cmvs_ptr; 1755 void *cmvs_ptr;
1735 const struct firmware *cmvs_fw; 1756 const struct firmware *cmvs_fw;
1736 int ver = 2; // we can only handle v2 cmv firmware version; 1757 int ver = 2; /* we can only handle v2 cmv firmware version; */
1737 1758
1738 /* Enter in R-IDLE (cmv) until instructed otherwise */ 1759 /* Enter in R-IDLE (cmv) until instructed otherwise */
1739 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1); 1760 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 1);
@@ -1750,7 +1771,7 @@ static int uea_send_cmvs_e4(struct uea_softc *sc)
1750 1771
1751 1772
1752 /* get options */ 1773 /* get options */
1753 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver); 1774 ret = len = request_cmvs(sc, &cmvs_ptr, &cmvs_fw, &ver);
1754 if (ret < 0) 1775 if (ret < 0)
1755 return ret; 1776 return ret;
1756 1777
@@ -1760,10 +1781,10 @@ static int uea_send_cmvs_e4(struct uea_softc *sc)
1760 1781
1761 for (i = 0; i < len; i++) { 1782 for (i = 0; i < len; i++) {
1762 ret = uea_write_cmv_e4(sc, 1, 1783 ret = uea_write_cmv_e4(sc, 1,
1763 get_unaligned_le32(&cmvs_v2[i].group), 1784 get_unaligned_le32(&cmvs_v2[i].group),
1764 get_unaligned_le32(&cmvs_v2[i].address), 1785 get_unaligned_le32(&cmvs_v2[i].address),
1765 get_unaligned_le32(&cmvs_v2[i].offset), 1786 get_unaligned_le32(&cmvs_v2[i].offset),
1766 get_unaligned_le32(&cmvs_v2[i].data)); 1787 get_unaligned_le32(&cmvs_v2[i].data));
1767 if (ret < 0) 1788 if (ret < 0)
1768 goto out; 1789 goto out;
1769 } 1790 }
@@ -1776,7 +1797,8 @@ static int uea_send_cmvs_e4(struct uea_softc *sc)
1776 /* Enter in R-ACT-REQ */ 1797 /* Enter in R-ACT-REQ */
1777 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2); 1798 ret = uea_write_cmv_e4(sc, 1, E4_SA_CNTL, 0, 0, 2);
1778 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n"); 1799 uea_vdbg(INS_TO_USBDEV(sc), "Entering in R-ACT-REQ state\n");
1779 uea_info(INS_TO_USBDEV(sc), "modem started, waiting synchronization...\n"); 1800 uea_info(INS_TO_USBDEV(sc), "modem started, waiting "
1801 "synchronization...\n");
1780out: 1802out:
1781 release_firmware(cmvs_fw); 1803 release_firmware(cmvs_fw);
1782 return ret; 1804 return ret;
@@ -1812,7 +1834,7 @@ static int uea_start_reset(struct uea_softc *sc)
1812 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL); 1834 uea_request(sc, UEA_SET_MODE, UEA_LOOPBACK_ON, 0, NULL);
1813 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL); 1835 uea_request(sc, UEA_SET_MODE, UEA_BOOT_IDMA, 0, NULL);
1814 1836
1815 /* enter reset mode */ 1837 /* enter reset mode */
1816 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL); 1838 uea_request(sc, UEA_SET_MODE, UEA_START_RESET, 0, NULL);
1817 1839
1818 /* original driver use 200ms, but windows driver use 100ms */ 1840 /* original driver use 200ms, but windows driver use 100ms */
@@ -1824,7 +1846,7 @@ static int uea_start_reset(struct uea_softc *sc)
1824 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL); 1846 uea_request(sc, UEA_SET_MODE, UEA_END_RESET, 0, NULL);
1825 1847
1826 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) { 1848 if (UEA_CHIP_VERSION(sc) != EAGLE_IV) {
1827 /* clear tx and rx mailboxes */ 1849 /* clear tx and rx mailboxes */
1828 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero); 1850 uea_request(sc, UEA_SET_2183_DATA, UEA_MPTX_MAILBOX, 2, &zero);
1829 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero); 1851 uea_request(sc, UEA_SET_2183_DATA, UEA_MPRX_MAILBOX, 2, &zero);
1830 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero); 1852 uea_request(sc, UEA_SET_2183_DATA, UEA_SWAP_MAILBOX, 2, &zero);
@@ -1835,9 +1857,11 @@ static int uea_start_reset(struct uea_softc *sc)
1835 return ret; 1857 return ret;
1836 1858
1837 if (UEA_CHIP_VERSION(sc) == EAGLE_IV) 1859 if (UEA_CHIP_VERSION(sc) == EAGLE_IV)
1838 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1); 1860 sc->cmv_dsc.e4.function = E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
1861 E4_MODEMREADY, 1);
1839 else 1862 else
1840 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY); 1863 sc->cmv_dsc.e1.function = E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
1864 E1_MODEMREADY);
1841 1865
1842 /* demask interrupt */ 1866 /* demask interrupt */
1843 sc->booting = 0; 1867 sc->booting = 0;
@@ -1937,7 +1961,8 @@ static int load_XILINX_firmware(struct uea_softc *sc)
1937 value = 0; 1961 value = 0;
1938 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value); 1962 ret = uea_send_modem_cmd(sc->usb_dev, 0xe, 1, &value);
1939 if (ret < 0) 1963 if (ret < 0)
1940 uea_err(sc->usb_dev, "elsa de-assert failed with error %d\n", ret); 1964 uea_err(sc->usb_dev, "elsa de-assert failed with error"
1965 " %d\n", ret);
1941 1966
1942err1: 1967err1:
1943 release_firmware(fw_entry); 1968 release_firmware(fw_entry);
@@ -1966,13 +1991,15 @@ static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1966 if (UEA_CHIP_VERSION(sc) == ADI930 1991 if (UEA_CHIP_VERSION(sc) == ADI930
1967 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) { 1992 && cmv->bFunction == E1_MAKEFUNCTION(2, 2)) {
1968 cmv->wIndex = cpu_to_le16(dsc->idx); 1993 cmv->wIndex = cpu_to_le16(dsc->idx);
1969 put_unaligned_le32(dsc->address, &cmv->dwSymbolicAddress); 1994 put_unaligned_le32(dsc->address,
1995 &cmv->dwSymbolicAddress);
1970 cmv->wOffsetAddress = cpu_to_le16(dsc->offset); 1996 cmv->wOffsetAddress = cpu_to_le16(dsc->offset);
1971 } else 1997 } else
1972 goto bad2; 1998 goto bad2;
1973 } 1999 }
1974 2000
1975 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE, E1_MODEMREADY)) { 2001 if (cmv->bFunction == E1_MAKEFUNCTION(E1_ADSLDIRECTIVE,
2002 E1_MODEMREADY)) {
1976 wake_up_cmv_ack(sc); 2003 wake_up_cmv_ack(sc);
1977 uea_leaves(INS_TO_USBDEV(sc)); 2004 uea_leaves(INS_TO_USBDEV(sc));
1978 return; 2005 return;
@@ -2021,7 +2048,8 @@ static void uea_dispatch_cmv_e4(struct uea_softc *sc, struct intr_pkt *intr)
2021 if (be16_to_cpu(cmv->wFunction) != dsc->function) 2048 if (be16_to_cpu(cmv->wFunction) != dsc->function)
2022 goto bad2; 2049 goto bad2;
2023 2050
2024 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE, E4_MODEMREADY, 1)) { 2051 if (be16_to_cpu(cmv->wFunction) == E4_MAKEFUNCTION(E4_ADSLDIRECTIVE,
2052 E4_MODEMREADY, 1)) {
2025 wake_up_cmv_ack(sc); 2053 wake_up_cmv_ack(sc);
2026 uea_leaves(INS_TO_USBDEV(sc)); 2054 uea_leaves(INS_TO_USBDEV(sc));
2027 return; 2055 return;
@@ -2048,14 +2076,16 @@ bad2:
2048 return; 2076 return;
2049} 2077}
2050 2078
2051static void uea_schedule_load_page_e1(struct uea_softc *sc, struct intr_pkt *intr) 2079static void uea_schedule_load_page_e1(struct uea_softc *sc,
2080 struct intr_pkt *intr)
2052{ 2081{
2053 sc->pageno = intr->e1_bSwapPageNo; 2082 sc->pageno = intr->e1_bSwapPageNo;
2054 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4; 2083 sc->ovl = intr->e1_bOvl >> 4 | intr->e1_bOvl << 4;
2055 queue_work(sc->work_q, &sc->task); 2084 queue_work(sc->work_q, &sc->task);
2056} 2085}
2057 2086
2058static void uea_schedule_load_page_e4(struct uea_softc *sc, struct intr_pkt *intr) 2087static void uea_schedule_load_page_e4(struct uea_softc *sc,
2088 struct intr_pkt *intr)
2059{ 2089{
2060 sc->pageno = intr->e4_bSwapPageNo; 2090 sc->pageno = intr->e4_bSwapPageNo;
2061 queue_work(sc->work_q, &sc->task); 2091 queue_work(sc->work_q, &sc->task);
@@ -2263,8 +2293,8 @@ out:
2263 2293
2264static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot); 2294static DEVICE_ATTR(stat_status, S_IWUGO | S_IRUGO, read_status, reboot);
2265 2295
2266static ssize_t read_human_status(struct device *dev, struct device_attribute *attr, 2296static ssize_t read_human_status(struct device *dev,
2267 char *buf) 2297 struct device_attribute *attr, char *buf)
2268{ 2298{
2269 int ret = -ENODEV; 2299 int ret = -ENODEV;
2270 int modem_state; 2300 int modem_state;
@@ -2289,7 +2319,7 @@ static ssize_t read_human_status(struct device *dev, struct device_attribute *at
2289 case 0xa: 2319 case 0xa:
2290 modem_state = 1; 2320 modem_state = 1;
2291 break; 2321 break;
2292 case 0x7: /* operational */ 2322 case 0x7: /* operational */
2293 modem_state = 2; 2323 modem_state = 2;
2294 break; 2324 break;
2295 case 0x2: /* fail ... */ 2325 case 0x2: /* fail ... */
@@ -2324,7 +2354,8 @@ out:
2324 return ret; 2354 return ret;
2325} 2355}
2326 2356
2327static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO, read_human_status, NULL); 2357static DEVICE_ATTR(stat_human_status, S_IWUGO | S_IRUGO,
2358 read_human_status, NULL);
2328 2359
2329static ssize_t read_delin(struct device *dev, struct device_attribute *attr, 2360static ssize_t read_delin(struct device *dev, struct device_attribute *attr,
2330 char *buf) 2361 char *buf)
@@ -2358,25 +2389,25 @@ out:
2358 2389
2359static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL); 2390static DEVICE_ATTR(stat_delin, S_IWUGO | S_IRUGO, read_delin, NULL);
2360 2391
2361#define UEA_ATTR(name, reset) \ 2392#define UEA_ATTR(name, reset) \
2362 \ 2393 \
2363static ssize_t read_##name(struct device *dev, \ 2394static ssize_t read_##name(struct device *dev, \
2364 struct device_attribute *attr, char *buf) \ 2395 struct device_attribute *attr, char *buf) \
2365{ \ 2396{ \
2366 int ret = -ENODEV; \ 2397 int ret = -ENODEV; \
2367 struct uea_softc *sc; \ 2398 struct uea_softc *sc; \
2368 \ 2399 \
2369 mutex_lock(&uea_mutex); \ 2400 mutex_lock(&uea_mutex); \
2370 sc = dev_to_uea(dev); \ 2401 sc = dev_to_uea(dev); \
2371 if (!sc) \ 2402 if (!sc) \
2372 goto out; \ 2403 goto out; \
2373 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \ 2404 ret = snprintf(buf, 10, "%08x\n", sc->stats.phy.name); \
2374 if (reset) \ 2405 if (reset) \
2375 sc->stats.phy.name = 0; \ 2406 sc->stats.phy.name = 0; \
2376out: \ 2407out: \
2377 mutex_unlock(&uea_mutex); \ 2408 mutex_unlock(&uea_mutex); \
2378 return ret; \ 2409 return ret; \
2379} \ 2410} \
2380 \ 2411 \
2381static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL) 2412static DEVICE_ATTR(stat_##name, S_IRUGO, read_##name, NULL)
2382 2413
@@ -2527,12 +2558,14 @@ static int uea_bind(struct usbatm_data *usbatm, struct usb_interface *intf,
2527 else if (sc->driver_info & AUTO_ANNEX_B) 2558 else if (sc->driver_info & AUTO_ANNEX_B)
2528 sc->annex = ANNEXB; 2559 sc->annex = ANNEXB;
2529 else 2560 else
2530 sc->annex = (le16_to_cpu(sc->usb_dev->descriptor.bcdDevice) & 0x80)?ANNEXB:ANNEXA; 2561 sc->annex = (le16_to_cpu
2562 (sc->usb_dev->descriptor.bcdDevice) & 0x80) ? ANNEXB : ANNEXA;
2531 2563
2532 alt = altsetting[sc->modem_index]; 2564 alt = altsetting[sc->modem_index];
2533 /* ADI930 don't support iso */ 2565 /* ADI930 don't support iso */
2534 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) { 2566 if (UEA_CHIP_VERSION(id) != ADI930 && alt > 0) {
2535 if (alt <= 8 && usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) { 2567 if (alt <= 8 &&
2568 usb_set_interface(usb, UEA_DS_IFACE_NO, alt) == 0) {
2536 uea_dbg(usb, "set alternate %u for 2 interface\n", alt); 2569 uea_dbg(usb, "set alternate %u for 2 interface\n", alt);
2537 uea_info(usb, "using iso mode\n"); 2570 uea_info(usb, "using iso mode\n");
2538 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ; 2571 usbatm->flags |= UDSL_USE_ISOC | UDSL_IGNORE_EILSEQ;
@@ -2621,40 +2654,74 @@ static void uea_disconnect(struct usb_interface *intf)
2621 * List of supported VID/PID 2654 * List of supported VID/PID
2622 */ 2655 */
2623static const struct usb_device_id uea_ids[] = { 2656static const struct usb_device_id uea_ids[] = {
2624 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM), .driver_info = ADI930 | PREFIRM}, 2657 {USB_DEVICE(ANALOG_VID, ADI930_PID_PREFIRM),
2625 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM}, 2658 .driver_info = ADI930 | PREFIRM},
2626 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, 2659 {USB_DEVICE(ANALOG_VID, ADI930_PID_PSTFIRM),
2627 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM}, 2660 .driver_info = ADI930 | PSTFIRM},
2628 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, 2661 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PREFIRM),
2629 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM}, 2662 .driver_info = EAGLE_I | PREFIRM},
2630 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, 2663 {USB_DEVICE(ANALOG_VID, EAGLE_I_PID_PSTFIRM),
2631 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM}, 2664 .driver_info = EAGLE_I | PSTFIRM},
2632 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM), .driver_info = EAGLE_III | PREFIRM}, 2665 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PREFIRM),
2633 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM), .driver_info = EAGLE_III | PSTFIRM}, 2666 .driver_info = EAGLE_II | PREFIRM},
2634 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM), .driver_info = EAGLE_IV | PREFIRM}, 2667 {USB_DEVICE(ANALOG_VID, EAGLE_II_PID_PSTFIRM),
2635 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM), .driver_info = EAGLE_IV | PSTFIRM}, 2668 .driver_info = EAGLE_II | PSTFIRM},
2636 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, 2669 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PREFIRM),
2637 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, 2670 .driver_info = EAGLE_II | PREFIRM},
2638 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, 2671 {USB_DEVICE(ANALOG_VID, EAGLE_IIC_PID_PSTFIRM),
2639 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, 2672 .driver_info = EAGLE_II | PSTFIRM},
2640 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, 2673 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PREFIRM),
2641 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A}, 2674 .driver_info = EAGLE_III | PREFIRM},
2642 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM), .driver_info = EAGLE_II | PREFIRM}, 2675 {USB_DEVICE(ANALOG_VID, EAGLE_III_PID_PSTFIRM),
2643 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM), .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B}, 2676 .driver_info = EAGLE_III | PSTFIRM},
2644 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM), .driver_info = ADI930 | PREFIRM}, 2677 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PREFIRM),
2645 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM), .driver_info = ADI930 | PSTFIRM}, 2678 .driver_info = EAGLE_IV | PREFIRM},
2646 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM), .driver_info = ADI930 | PREFIRM}, 2679 {USB_DEVICE(ANALOG_VID, EAGLE_IV_PID_PSTFIRM),
2647 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A}, 2680 .driver_info = EAGLE_IV | PSTFIRM},
2648 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM), .driver_info = ADI930 | PREFIRM}, 2681 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PREFIRM),
2649 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM), .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B}, 2682 .driver_info = EAGLE_I | PREFIRM},
2650 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, 2683 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_A_PID_PSTFIRM),
2651 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, 2684 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2652 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM), .driver_info = EAGLE_I | PREFIRM}, 2685 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PREFIRM),
2653 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM), .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, 2686 .driver_info = EAGLE_I | PREFIRM},
2654 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, 2687 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_I_B_PID_PSTFIRM),
2655 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A}, 2688 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2656 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),.driver_info = EAGLE_I | PREFIRM}, 2689 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PREFIRM),
2657 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),.driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B}, 2690 .driver_info = EAGLE_II | PREFIRM},
2691 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_A_PID_PSTFIRM),
2692 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_A},
2693 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PREFIRM),
2694 .driver_info = EAGLE_II | PREFIRM},
2695 {USB_DEVICE(DEVOLO_VID, DEVOLO_EAGLE_II_B_PID_PSTFIRM),
2696 .driver_info = EAGLE_II | PSTFIRM | AUTO_ANNEX_B},
2697 {USB_DEVICE(ELSA_VID, ELSA_PID_PREFIRM),
2698 .driver_info = ADI930 | PREFIRM},
2699 {USB_DEVICE(ELSA_VID, ELSA_PID_PSTFIRM),
2700 .driver_info = ADI930 | PSTFIRM},
2701 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PREFIRM),
2702 .driver_info = ADI930 | PREFIRM},
2703 {USB_DEVICE(ELSA_VID, ELSA_PID_A_PSTFIRM),
2704 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_A},
2705 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PREFIRM),
2706 .driver_info = ADI930 | PREFIRM},
2707 {USB_DEVICE(ELSA_VID, ELSA_PID_B_PSTFIRM),
2708 .driver_info = ADI930 | PSTFIRM | AUTO_ANNEX_B},
2709 {USB_DEVICE(USR_VID, MILLER_A_PID_PREFIRM),
2710 .driver_info = EAGLE_I | PREFIRM},
2711 {USB_DEVICE(USR_VID, MILLER_A_PID_PSTFIRM),
2712 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2713 {USB_DEVICE(USR_VID, MILLER_B_PID_PREFIRM),
2714 .driver_info = EAGLE_I | PREFIRM},
2715 {USB_DEVICE(USR_VID, MILLER_B_PID_PSTFIRM),
2716 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2717 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PREFIRM),
2718 .driver_info = EAGLE_I | PREFIRM},
2719 {USB_DEVICE(USR_VID, HEINEKEN_A_PID_PSTFIRM),
2720 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_A},
2721 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PREFIRM),
2722 .driver_info = EAGLE_I | PREFIRM},
2723 {USB_DEVICE(USR_VID, HEINEKEN_B_PID_PSTFIRM),
2724 .driver_info = EAGLE_I | PSTFIRM | AUTO_ANNEX_B},
2658 {} 2725 {}
2659}; 2726};
2660 2727
diff --git a/drivers/usb/c67x00/c67x00-hcd.h b/drivers/usb/c67x00/c67x00-hcd.h
index e8c6d94b2514..74e44621e313 100644
--- a/drivers/usb/c67x00/c67x00-hcd.h
+++ b/drivers/usb/c67x00/c67x00-hcd.h
@@ -28,7 +28,7 @@
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/usb.h> 30#include <linux/usb.h>
31#include "../core/hcd.h" 31#include <linux/usb/hcd.h>
32#include "c67x00.h" 32#include "c67x00.h"
33 33
34/* 34/*
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 5e1a253b08a0..0c2f14ff9696 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -892,7 +892,7 @@ static void acm_write_buffers_free(struct acm *acm)
892 struct usb_device *usb_dev = interface_to_usbdev(acm->control); 892 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
893 893
894 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) 894 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
895 usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); 895 usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah);
896} 896}
897 897
898static void acm_read_buffers_free(struct acm *acm) 898static void acm_read_buffers_free(struct acm *acm)
@@ -901,8 +901,8 @@ static void acm_read_buffers_free(struct acm *acm)
901 int i, n = acm->rx_buflimit; 901 int i, n = acm->rx_buflimit;
902 902
903 for (i = 0; i < n; i++) 903 for (i = 0; i < n; i++)
904 usb_buffer_free(usb_dev, acm->readsize, 904 usb_free_coherent(usb_dev, acm->readsize,
905 acm->rb[i].base, acm->rb[i].dma); 905 acm->rb[i].base, acm->rb[i].dma);
906} 906}
907 907
908/* Little helper: write buffers allocate */ 908/* Little helper: write buffers allocate */
@@ -912,13 +912,13 @@ static int acm_write_buffers_alloc(struct acm *acm)
912 struct acm_wb *wb; 912 struct acm_wb *wb;
913 913
914 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { 914 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
915 wb->buf = usb_buffer_alloc(acm->dev, acm->writesize, GFP_KERNEL, 915 wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL,
916 &wb->dmah); 916 &wb->dmah);
917 if (!wb->buf) { 917 if (!wb->buf) {
918 while (i != 0) { 918 while (i != 0) {
919 --i; 919 --i;
920 --wb; 920 --wb;
921 usb_buffer_free(acm->dev, acm->writesize, 921 usb_free_coherent(acm->dev, acm->writesize,
922 wb->buf, wb->dmah); 922 wb->buf, wb->dmah);
923 } 923 }
924 return -ENOMEM; 924 return -ENOMEM;
@@ -1177,7 +1177,7 @@ made_compressed_probe:
1177 tty_port_init(&acm->port); 1177 tty_port_init(&acm->port);
1178 acm->port.ops = &acm_port_ops; 1178 acm->port.ops = &acm_port_ops;
1179 1179
1180 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1180 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1181 if (!buf) { 1181 if (!buf) {
1182 dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n"); 1182 dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n");
1183 goto alloc_fail2; 1183 goto alloc_fail2;
@@ -1210,11 +1210,11 @@ made_compressed_probe:
1210 for (i = 0; i < num_rx_buf; i++) { 1210 for (i = 0; i < num_rx_buf; i++) {
1211 struct acm_rb *rb = &(acm->rb[i]); 1211 struct acm_rb *rb = &(acm->rb[i]);
1212 1212
1213 rb->base = usb_buffer_alloc(acm->dev, readsize, 1213 rb->base = usb_alloc_coherent(acm->dev, readsize,
1214 GFP_KERNEL, &rb->dma); 1214 GFP_KERNEL, &rb->dma);
1215 if (!rb->base) { 1215 if (!rb->base) {
1216 dev_dbg(&intf->dev, 1216 dev_dbg(&intf->dev,
1217 "out of memory (read bufs usb_buffer_alloc)\n"); 1217 "out of memory (read bufs usb_alloc_coherent)\n");
1218 goto alloc_fail7; 1218 goto alloc_fail7;
1219 } 1219 }
1220 } 1220 }
@@ -1306,7 +1306,7 @@ alloc_fail7:
1306alloc_fail5: 1306alloc_fail5:
1307 acm_write_buffers_free(acm); 1307 acm_write_buffers_free(acm);
1308alloc_fail4: 1308alloc_fail4:
1309 usb_buffer_free(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1309 usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
1310alloc_fail2: 1310alloc_fail2:
1311 kfree(acm); 1311 kfree(acm);
1312alloc_fail: 1312alloc_fail:
@@ -1356,8 +1356,8 @@ static void acm_disconnect(struct usb_interface *intf)
1356 stop_data_traffic(acm); 1356 stop_data_traffic(acm);
1357 1357
1358 acm_write_buffers_free(acm); 1358 acm_write_buffers_free(acm);
1359 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, 1359 usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer,
1360 acm->ctrl_dma); 1360 acm->ctrl_dma);
1361 acm_read_buffers_free(acm); 1361 acm_read_buffers_free(acm);
1362 1362
1363 if (!acm->combined_interfaces) 1363 if (!acm->combined_interfaces)
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 4a8e87ec6ce9..5eeb570b9a61 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -124,8 +124,8 @@ struct acm {
124 unsigned char clocal; /* termios CLOCAL */ 124 unsigned char clocal; /* termios CLOCAL */
125 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 125 unsigned int ctrl_caps; /* control capabilities from the class specific header */
126 unsigned int susp_count; /* number of suspended interfaces */ 126 unsigned int susp_count; /* number of suspended interfaces */
127 int combined_interfaces:1; /* control and data collapsed */ 127 unsigned int combined_interfaces:1; /* control and data collapsed */
128 int is_int_ep:1; /* interrupt endpoints contrary to spec used */ 128 unsigned int is_int_ep:1; /* interrupt endpoints contrary to spec used */
129 u8 bInterval; 129 u8 bInterval;
130 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ 130 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */
131}; 131};
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 189141ca4e05..094c76b5de17 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -276,14 +276,14 @@ static void free_urbs(struct wdm_device *desc)
276 276
277static void cleanup(struct wdm_device *desc) 277static void cleanup(struct wdm_device *desc)
278{ 278{
279 usb_buffer_free(interface_to_usbdev(desc->intf), 279 usb_free_coherent(interface_to_usbdev(desc->intf),
280 desc->wMaxPacketSize, 280 desc->wMaxPacketSize,
281 desc->sbuf, 281 desc->sbuf,
282 desc->validity->transfer_dma); 282 desc->validity->transfer_dma);
283 usb_buffer_free(interface_to_usbdev(desc->intf), 283 usb_free_coherent(interface_to_usbdev(desc->intf),
284 desc->wMaxCommand, 284 desc->wMaxCommand,
285 desc->inbuf, 285 desc->inbuf,
286 desc->response->transfer_dma); 286 desc->response->transfer_dma);
287 kfree(desc->orq); 287 kfree(desc->orq);
288 kfree(desc->irq); 288 kfree(desc->irq);
289 kfree(desc->ubuf); 289 kfree(desc->ubuf);
@@ -705,17 +705,17 @@ next_desc:
705 if (!desc->ubuf) 705 if (!desc->ubuf)
706 goto err; 706 goto err;
707 707
708 desc->sbuf = usb_buffer_alloc(interface_to_usbdev(intf), 708 desc->sbuf = usb_alloc_coherent(interface_to_usbdev(intf),
709 desc->wMaxPacketSize, 709 desc->wMaxPacketSize,
710 GFP_KERNEL, 710 GFP_KERNEL,
711 &desc->validity->transfer_dma); 711 &desc->validity->transfer_dma);
712 if (!desc->sbuf) 712 if (!desc->sbuf)
713 goto err; 713 goto err;
714 714
715 desc->inbuf = usb_buffer_alloc(interface_to_usbdev(intf), 715 desc->inbuf = usb_alloc_coherent(interface_to_usbdev(intf),
716 desc->bMaxPacketSize0, 716 desc->bMaxPacketSize0,
717 GFP_KERNEL, 717 GFP_KERNEL,
718 &desc->response->transfer_dma); 718 &desc->response->transfer_dma);
719 if (!desc->inbuf) 719 if (!desc->inbuf)
720 goto err2; 720 goto err2;
721 721
@@ -742,15 +742,15 @@ out:
742 return rv; 742 return rv;
743err3: 743err3:
744 usb_set_intfdata(intf, NULL); 744 usb_set_intfdata(intf, NULL);
745 usb_buffer_free(interface_to_usbdev(desc->intf), 745 usb_free_coherent(interface_to_usbdev(desc->intf),
746 desc->bMaxPacketSize0, 746 desc->bMaxPacketSize0,
747 desc->inbuf, 747 desc->inbuf,
748 desc->response->transfer_dma); 748 desc->response->transfer_dma);
749err2: 749err2:
750 usb_buffer_free(interface_to_usbdev(desc->intf), 750 usb_free_coherent(interface_to_usbdev(desc->intf),
751 desc->wMaxPacketSize, 751 desc->wMaxPacketSize,
752 desc->sbuf, 752 desc->sbuf,
753 desc->validity->transfer_dma); 753 desc->validity->transfer_dma);
754err: 754err:
755 free_urbs(desc); 755 free_urbs(desc);
756 kfree(desc->ubuf); 756 kfree(desc->ubuf);
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 93b5f85d7ceb..2250095db0a0 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -27,7 +27,7 @@
27 * v0.11 - add proto_bias option (Pete Zaitcev) 27 * v0.11 - add proto_bias option (Pete Zaitcev)
28 * v0.12 - add hpoj.sourceforge.net ioctls (David Paschal) 28 * v0.12 - add hpoj.sourceforge.net ioctls (David Paschal)
29 * v0.13 - alloc space for statusbuf (<status> not on stack); 29 * v0.13 - alloc space for statusbuf (<status> not on stack);
30 * use usb_buffer_alloc() for read buf & write buf; 30 * use usb_alloc_coherent() for read buf & write buf;
31 * none - Maintained in Linux kernel after v0.13 31 * none - Maintained in Linux kernel after v0.13
32 */ 32 */
33 33
diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 3ba2fff71490..2c6965484fe8 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -14,7 +14,7 @@
14#include <linux/dma-mapping.h> 14#include <linux/dma-mapping.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
17#include "hcd.h" 17#include <linux/usb/hcd.h>
18 18
19 19
20/* 20/*
diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 0d3af6a6ee49..83126b03e7cf 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -1,12 +1,14 @@
1#include <linux/usb.h> 1#include <linux/usb.h>
2#include <linux/usb/ch9.h> 2#include <linux/usb/ch9.h>
3#include <linux/usb/hcd.h>
4#include <linux/usb/quirks.h>
3#include <linux/module.h> 5#include <linux/module.h>
4#include <linux/init.h> 6#include <linux/init.h>
5#include <linux/slab.h> 7#include <linux/slab.h>
6#include <linux/device.h> 8#include <linux/device.h>
7#include <asm/byteorder.h> 9#include <asm/byteorder.h>
8#include "usb.h" 10#include "usb.h"
9#include "hcd.h" 11
10 12
11#define USB_MAXALTSETTING 128 /* Hard limit */ 13#define USB_MAXALTSETTING 128 /* Hard limit */
12#define USB_MAXENDPOINTS 30 /* Hard limit */ 14#define USB_MAXENDPOINTS 30 /* Hard limit */
@@ -19,32 +21,6 @@ static inline const char *plural(int n)
19 return (n == 1 ? "" : "s"); 21 return (n == 1 ? "" : "s");
20} 22}
21 23
22/* FIXME: this is a kludge */
23static int find_next_descriptor_more(unsigned char *buffer, int size,
24 int dt1, int dt2, int dt3, int *num_skipped)
25{
26 struct usb_descriptor_header *h;
27 int n = 0;
28 unsigned char *buffer0 = buffer;
29
30 /* Find the next descriptor of type dt1 or dt2 or dt3 */
31 while (size > 0) {
32 h = (struct usb_descriptor_header *) buffer;
33 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2 ||
34 h->bDescriptorType == dt3)
35 break;
36 buffer += h->bLength;
37 size -= h->bLength;
38 ++n;
39 }
40
41 /* Store the number of descriptors skipped and return the
42 * number of bytes skipped */
43 if (num_skipped)
44 *num_skipped = n;
45 return buffer - buffer0;
46}
47
48static int find_next_descriptor(unsigned char *buffer, int size, 24static int find_next_descriptor(unsigned char *buffer, int size,
49 int dt1, int dt2, int *num_skipped) 25 int dt1, int dt2, int *num_skipped)
50{ 26{
@@ -69,47 +45,41 @@ static int find_next_descriptor(unsigned char *buffer, int size,
69 return buffer - buffer0; 45 return buffer - buffer0;
70} 46}
71 47
72static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno, 48static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
73 int inum, int asnum, struct usb_host_endpoint *ep, 49 int inum, int asnum, struct usb_host_endpoint *ep,
74 int num_ep, unsigned char *buffer, int size) 50 unsigned char *buffer, int size)
75{ 51{
76 unsigned char *buffer_start = buffer; 52 struct usb_ss_ep_comp_descriptor *desc;
77 struct usb_ss_ep_comp_descriptor *desc;
78 int retval;
79 int num_skipped;
80 int max_tx; 53 int max_tx;
81 int i;
82 54
55 /* The SuperSpeed endpoint companion descriptor is supposed to
56 * be the first thing immediately following the endpoint descriptor.
57 */
83 desc = (struct usb_ss_ep_comp_descriptor *) buffer; 58 desc = (struct usb_ss_ep_comp_descriptor *) buffer;
84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP) { 59 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP ||
60 size < USB_DT_SS_EP_COMP_SIZE) {
85 dev_warn(ddev, "No SuperSpeed endpoint companion for config %d " 61 dev_warn(ddev, "No SuperSpeed endpoint companion for config %d "
86 " interface %d altsetting %d ep %d: " 62 " interface %d altsetting %d ep %d: "
87 "using minimum values\n", 63 "using minimum values\n",
88 cfgno, inum, asnum, ep->desc.bEndpointAddress); 64 cfgno, inum, asnum, ep->desc.bEndpointAddress);
89 /* 65
90 * The next descriptor is for an Endpoint or Interface, 66 /* Fill in some default values.
91 * no extra descriptors to copy into the companion structure, 67 * Leave bmAttributes as zero, which will mean no streams for
92 * and we didn't eat up any of the buffer. 68 * bulk, and isoc won't support multiple bursts of packets.
69 * With bursts of only one packet, and a Mult of 1, the max
70 * amount of data moved per endpoint service interval is one
71 * packet.
93 */ 72 */
94 return 0; 73 ep->ss_ep_comp.bLength = USB_DT_SS_EP_COMP_SIZE;
74 ep->ss_ep_comp.bDescriptorType = USB_DT_SS_ENDPOINT_COMP;
75 if (usb_endpoint_xfer_isoc(&ep->desc) ||
76 usb_endpoint_xfer_int(&ep->desc))
77 ep->ss_ep_comp.wBytesPerInterval =
78 ep->desc.wMaxPacketSize;
79 return;
95 } 80 }
96 memcpy(&ep->ss_ep_comp->desc, desc, USB_DT_SS_EP_COMP_SIZE);
97 desc = &ep->ss_ep_comp->desc;
98 buffer += desc->bLength;
99 size -= desc->bLength;
100 81
101 /* Eat up the other descriptors we don't care about */ 82 memcpy(&ep->ss_ep_comp, desc, USB_DT_SS_EP_COMP_SIZE);
102 ep->ss_ep_comp->extra = buffer;
103 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
104 USB_DT_INTERFACE, &num_skipped);
105 ep->ss_ep_comp->extralen = i;
106 buffer += i;
107 size -= i;
108 retval = buffer - buffer_start;
109 if (num_skipped > 0)
110 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
111 num_skipped, plural(num_skipped),
112 "SuperSpeed endpoint companion");
113 83
114 /* Check the various values */ 84 /* Check the various values */
115 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) { 85 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) {
@@ -117,47 +87,48 @@ static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
117 "config %d interface %d altsetting %d ep %d: " 87 "config %d interface %d altsetting %d ep %d: "
118 "setting to zero\n", desc->bMaxBurst, 88 "setting to zero\n", desc->bMaxBurst,
119 cfgno, inum, asnum, ep->desc.bEndpointAddress); 89 cfgno, inum, asnum, ep->desc.bEndpointAddress);
120 desc->bMaxBurst = 0; 90 ep->ss_ep_comp.bMaxBurst = 0;
121 } 91 } else if (desc->bMaxBurst > 15) {
122 if (desc->bMaxBurst > 15) {
123 dev_warn(ddev, "Endpoint with bMaxBurst = %d in " 92 dev_warn(ddev, "Endpoint with bMaxBurst = %d in "
124 "config %d interface %d altsetting %d ep %d: " 93 "config %d interface %d altsetting %d ep %d: "
125 "setting to 15\n", desc->bMaxBurst, 94 "setting to 15\n", desc->bMaxBurst,
126 cfgno, inum, asnum, ep->desc.bEndpointAddress); 95 cfgno, inum, asnum, ep->desc.bEndpointAddress);
127 desc->bMaxBurst = 15; 96 ep->ss_ep_comp.bMaxBurst = 15;
128 } 97 }
129 if ((usb_endpoint_xfer_control(&ep->desc) || usb_endpoint_xfer_int(&ep->desc)) 98
130 && desc->bmAttributes != 0) { 99 if ((usb_endpoint_xfer_control(&ep->desc) ||
100 usb_endpoint_xfer_int(&ep->desc)) &&
101 desc->bmAttributes != 0) {
131 dev_warn(ddev, "%s endpoint with bmAttributes = %d in " 102 dev_warn(ddev, "%s endpoint with bmAttributes = %d in "
132 "config %d interface %d altsetting %d ep %d: " 103 "config %d interface %d altsetting %d ep %d: "
133 "setting to zero\n", 104 "setting to zero\n",
134 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk", 105 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk",
135 desc->bmAttributes, 106 desc->bmAttributes,
136 cfgno, inum, asnum, ep->desc.bEndpointAddress); 107 cfgno, inum, asnum, ep->desc.bEndpointAddress);
137 desc->bmAttributes = 0; 108 ep->ss_ep_comp.bmAttributes = 0;
138 } 109 } else if (usb_endpoint_xfer_bulk(&ep->desc) &&
139 if (usb_endpoint_xfer_bulk(&ep->desc) && desc->bmAttributes > 16) { 110 desc->bmAttributes > 16) {
140 dev_warn(ddev, "Bulk endpoint with more than 65536 streams in " 111 dev_warn(ddev, "Bulk endpoint with more than 65536 streams in "
141 "config %d interface %d altsetting %d ep %d: " 112 "config %d interface %d altsetting %d ep %d: "
142 "setting to max\n", 113 "setting to max\n",
143 cfgno, inum, asnum, ep->desc.bEndpointAddress); 114 cfgno, inum, asnum, ep->desc.bEndpointAddress);
144 desc->bmAttributes = 16; 115 ep->ss_ep_comp.bmAttributes = 16;
145 } 116 } else if (usb_endpoint_xfer_isoc(&ep->desc) &&
146 if (usb_endpoint_xfer_isoc(&ep->desc) && desc->bmAttributes > 2) { 117 desc->bmAttributes > 2) {
147 dev_warn(ddev, "Isoc endpoint has Mult of %d in " 118 dev_warn(ddev, "Isoc endpoint has Mult of %d in "
148 "config %d interface %d altsetting %d ep %d: " 119 "config %d interface %d altsetting %d ep %d: "
149 "setting to 3\n", desc->bmAttributes + 1, 120 "setting to 3\n", desc->bmAttributes + 1,
150 cfgno, inum, asnum, ep->desc.bEndpointAddress); 121 cfgno, inum, asnum, ep->desc.bEndpointAddress);
151 desc->bmAttributes = 2; 122 ep->ss_ep_comp.bmAttributes = 2;
152 } 123 }
153 if (usb_endpoint_xfer_isoc(&ep->desc)) { 124
125 if (usb_endpoint_xfer_isoc(&ep->desc))
154 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1) * 126 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1) *
155 (desc->bmAttributes + 1); 127 (desc->bmAttributes + 1);
156 } else if (usb_endpoint_xfer_int(&ep->desc)) { 128 else if (usb_endpoint_xfer_int(&ep->desc))
157 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1); 129 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1);
158 } else { 130 else
159 goto valid; 131 max_tx = 999999;
160 }
161 if (desc->wBytesPerInterval > max_tx) { 132 if (desc->wBytesPerInterval > max_tx) {
162 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in " 133 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in "
163 "config %d interface %d altsetting %d ep %d: " 134 "config %d interface %d altsetting %d ep %d: "
@@ -166,10 +137,8 @@ static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
166 desc->wBytesPerInterval, 137 desc->wBytesPerInterval,
167 cfgno, inum, asnum, ep->desc.bEndpointAddress, 138 cfgno, inum, asnum, ep->desc.bEndpointAddress,
168 max_tx); 139 max_tx);
169 desc->wBytesPerInterval = max_tx; 140 ep->ss_ep_comp.wBytesPerInterval = max_tx;
170 } 141 }
171valid:
172 return retval;
173} 142}
174 143
175static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum, 144static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
@@ -291,61 +260,19 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
291 cfgno, inum, asnum, d->bEndpointAddress, 260 cfgno, inum, asnum, d->bEndpointAddress,
292 maxp); 261 maxp);
293 } 262 }
294 /* Allocate room for and parse any SS endpoint companion descriptors */
295 if (to_usb_device(ddev)->speed == USB_SPEED_SUPER) {
296 endpoint->extra = buffer;
297 i = find_next_descriptor_more(buffer, size, USB_DT_SS_ENDPOINT_COMP,
298 USB_DT_ENDPOINT, USB_DT_INTERFACE, &n);
299 endpoint->extralen = i;
300 buffer += i;
301 size -= i;
302
303 /* Allocate space for the SS endpoint companion descriptor */
304 endpoint->ss_ep_comp = kzalloc(sizeof(struct usb_host_ss_ep_comp),
305 GFP_KERNEL);
306 if (!endpoint->ss_ep_comp)
307 return -ENOMEM;
308 263
309 /* Fill in some default values (may be overwritten later) */ 264 /* Parse a possible SuperSpeed endpoint companion descriptor */
310 endpoint->ss_ep_comp->desc.bLength = USB_DT_SS_EP_COMP_SIZE; 265 if (to_usb_device(ddev)->speed == USB_SPEED_SUPER)
311 endpoint->ss_ep_comp->desc.bDescriptorType = USB_DT_SS_ENDPOINT_COMP; 266 usb_parse_ss_endpoint_companion(ddev, cfgno,
312 endpoint->ss_ep_comp->desc.bMaxBurst = 0; 267 inum, asnum, endpoint, buffer, size);
313 /* 268
314 * Leave bmAttributes as zero, which will mean no streams for 269 /* Skip over any Class Specific or Vendor Specific descriptors;
315 * bulk, and isoc won't support multiple bursts of packets. 270 * find the next endpoint or interface descriptor */
316 * With bursts of only one packet, and a Mult of 1, the max 271 endpoint->extra = buffer;
317 * amount of data moved per endpoint service interval is one 272 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
318 * packet. 273 USB_DT_INTERFACE, &n);
319 */ 274 endpoint->extralen = i;
320 if (usb_endpoint_xfer_isoc(&endpoint->desc) || 275 retval = buffer - buffer0 + i;
321 usb_endpoint_xfer_int(&endpoint->desc))
322 endpoint->ss_ep_comp->desc.wBytesPerInterval =
323 endpoint->desc.wMaxPacketSize;
324
325 if (size > 0) {
326 retval = usb_parse_ss_endpoint_companion(ddev, cfgno,
327 inum, asnum, endpoint, num_ep, buffer,
328 size);
329 if (retval >= 0) {
330 buffer += retval;
331 retval = buffer - buffer0;
332 }
333 } else {
334 dev_warn(ddev, "config %d interface %d altsetting %d "
335 "endpoint 0x%X has no "
336 "SuperSpeed companion descriptor\n",
337 cfgno, inum, asnum, d->bEndpointAddress);
338 retval = buffer - buffer0;
339 }
340 } else {
341 /* Skip over any Class Specific or Vendor Specific descriptors;
342 * find the next endpoint or interface descriptor */
343 endpoint->extra = buffer;
344 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
345 USB_DT_INTERFACE, &n);
346 endpoint->extralen = i;
347 retval = buffer - buffer0 + i;
348 }
349 if (n > 0) 276 if (n > 0)
350 dev_dbg(ddev, "skipped %d descriptor%s after %s\n", 277 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
351 n, plural(n), "endpoint"); 278 n, plural(n), "endpoint");
@@ -478,9 +405,10 @@ skip_to_next_interface_descriptor:
478 return buffer - buffer0 + i; 405 return buffer - buffer0 + i;
479} 406}
480 407
481static int usb_parse_configuration(struct device *ddev, int cfgidx, 408static int usb_parse_configuration(struct usb_device *dev, int cfgidx,
482 struct usb_host_config *config, unsigned char *buffer, int size) 409 struct usb_host_config *config, unsigned char *buffer, int size)
483{ 410{
411 struct device *ddev = &dev->dev;
484 unsigned char *buffer0 = buffer; 412 unsigned char *buffer0 = buffer;
485 int cfgno; 413 int cfgno;
486 int nintf, nintf_orig; 414 int nintf, nintf_orig;
@@ -549,6 +477,16 @@ static int usb_parse_configuration(struct device *ddev, int cfgidx,
549 } 477 }
550 478
551 inum = d->bInterfaceNumber; 479 inum = d->bInterfaceNumber;
480
481 if ((dev->quirks & USB_QUIRK_HONOR_BNUMINTERFACES) &&
482 n >= nintf_orig) {
483 dev_warn(ddev, "config %d has more interface "
484 "descriptors, than it declares in "
485 "bNumInterfaces, ignoring interface "
486 "number: %d\n", cfgno, inum);
487 continue;
488 }
489
552 if (inum >= nintf_orig) 490 if (inum >= nintf_orig)
553 dev_warn(ddev, "config %d has an invalid " 491 dev_warn(ddev, "config %d has an invalid "
554 "interface number: %d but max is %d\n", 492 "interface number: %d but max is %d\n",
@@ -722,7 +660,6 @@ int usb_get_configuration(struct usb_device *dev)
722 int ncfg = dev->descriptor.bNumConfigurations; 660 int ncfg = dev->descriptor.bNumConfigurations;
723 int result = 0; 661 int result = 0;
724 unsigned int cfgno, length; 662 unsigned int cfgno, length;
725 unsigned char *buffer;
726 unsigned char *bigbuffer; 663 unsigned char *bigbuffer;
727 struct usb_config_descriptor *desc; 664 struct usb_config_descriptor *desc;
728 665
@@ -751,17 +688,16 @@ int usb_get_configuration(struct usb_device *dev)
751 if (!dev->rawdescriptors) 688 if (!dev->rawdescriptors)
752 goto err2; 689 goto err2;
753 690
754 buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL); 691 desc = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
755 if (!buffer) 692 if (!desc)
756 goto err2; 693 goto err2;
757 desc = (struct usb_config_descriptor *)buffer;
758 694
759 result = 0; 695 result = 0;
760 for (; cfgno < ncfg; cfgno++) { 696 for (; cfgno < ncfg; cfgno++) {
761 /* We grab just the first descriptor so we know how long 697 /* We grab just the first descriptor so we know how long
762 * the whole configuration is */ 698 * the whole configuration is */
763 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, 699 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
764 buffer, USB_DT_CONFIG_SIZE); 700 desc, USB_DT_CONFIG_SIZE);
765 if (result < 0) { 701 if (result < 0) {
766 dev_err(ddev, "unable to read config index %d " 702 dev_err(ddev, "unable to read config index %d "
767 "descriptor/%s: %d\n", cfgno, "start", result); 703 "descriptor/%s: %d\n", cfgno, "start", result);
@@ -800,7 +736,7 @@ int usb_get_configuration(struct usb_device *dev)
800 736
801 dev->rawdescriptors[cfgno] = bigbuffer; 737 dev->rawdescriptors[cfgno] = bigbuffer;
802 738
803 result = usb_parse_configuration(&dev->dev, cfgno, 739 result = usb_parse_configuration(dev, cfgno,
804 &dev->config[cfgno], bigbuffer, length); 740 &dev->config[cfgno], bigbuffer, length);
805 if (result < 0) { 741 if (result < 0) {
806 ++cfgno; 742 ++cfgno;
@@ -810,7 +746,7 @@ int usb_get_configuration(struct usb_device *dev)
810 result = 0; 746 result = 0;
811 747
812err: 748err:
813 kfree(buffer); 749 kfree(desc);
814out_not_authorized: 750out_not_authorized:
815 dev->descriptor.bNumConfigurations = cfgno; 751 dev->descriptor.bNumConfigurations = cfgno;
816err2: 752err2:
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 19bc03a9fecf..3449742c00e1 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * devices.c 2 * devices.c
3 * (C) Copyright 1999 Randy Dunlap. 3 * (C) Copyright 1999 Randy Dunlap.
4 * (C) Copyright 1999,2000 Thomas Sailer <sailer@ife.ee.ethz.ch>. (proc file per device) 4 * (C) Copyright 1999,2000 Thomas Sailer <sailer@ife.ee.ethz.ch>.
5 * (proc file per device)
5 * (C) Copyright 1999 Deti Fliegl (new USB architecture) 6 * (C) Copyright 1999 Deti Fliegl (new USB architecture)
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
@@ -55,11 +56,11 @@
55#include <linux/usb.h> 56#include <linux/usb.h>
56#include <linux/smp_lock.h> 57#include <linux/smp_lock.h>
57#include <linux/usbdevice_fs.h> 58#include <linux/usbdevice_fs.h>
59#include <linux/usb/hcd.h>
58#include <linux/mutex.h> 60#include <linux/mutex.h>
59#include <asm/uaccess.h> 61#include <linux/uaccess.h>
60 62
61#include "usb.h" 63#include "usb.h"
62#include "hcd.h"
63 64
64/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */ 65/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */
65#define ALLOW_SERIAL_NUMBER 66#define ALLOW_SERIAL_NUMBER
@@ -138,8 +139,8 @@ struct class_info {
138 char *class_name; 139 char *class_name;
139}; 140};
140 141
141static const struct class_info clas_info[] = 142static const struct class_info clas_info[] = {
142{ /* max. 5 chars. per name string */ 143 /* max. 5 chars. per name string */
143 {USB_CLASS_PER_INTERFACE, ">ifc"}, 144 {USB_CLASS_PER_INTERFACE, ">ifc"},
144 {USB_CLASS_AUDIO, "audio"}, 145 {USB_CLASS_AUDIO, "audio"},
145 {USB_CLASS_COMM, "comm."}, 146 {USB_CLASS_COMM, "comm."},
@@ -191,8 +192,10 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
191 192
192 if (speed == USB_SPEED_HIGH) { 193 if (speed == USB_SPEED_HIGH) {
193 switch (le16_to_cpu(desc->wMaxPacketSize) & (0x03 << 11)) { 194 switch (le16_to_cpu(desc->wMaxPacketSize) & (0x03 << 11)) {
194 case 1 << 11: bandwidth = 2; break; 195 case 1 << 11:
195 case 2 << 11: bandwidth = 3; break; 196 bandwidth = 2; break;
197 case 2 << 11:
198 bandwidth = 3; break;
196 } 199 }
197 } 200 }
198 201
@@ -200,7 +203,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
200 switch (usb_endpoint_type(desc)) { 203 switch (usb_endpoint_type(desc)) {
201 case USB_ENDPOINT_XFER_CONTROL: 204 case USB_ENDPOINT_XFER_CONTROL:
202 type = "Ctrl"; 205 type = "Ctrl";
203 if (speed == USB_SPEED_HIGH) /* uframes per NAK */ 206 if (speed == USB_SPEED_HIGH) /* uframes per NAK */
204 interval = desc->bInterval; 207 interval = desc->bInterval;
205 else 208 else
206 interval = 0; 209 interval = 0;
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 3466fdc5bb11..c2f62a3993d2 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -43,6 +43,7 @@
43#include <linux/module.h> 43#include <linux/module.h>
44#include <linux/usb.h> 44#include <linux/usb.h>
45#include <linux/usbdevice_fs.h> 45#include <linux/usbdevice_fs.h>
46#include <linux/usb/hcd.h> /* for usbcore internals */
46#include <linux/cdev.h> 47#include <linux/cdev.h>
47#include <linux/notifier.h> 48#include <linux/notifier.h>
48#include <linux/security.h> 49#include <linux/security.h>
@@ -50,9 +51,7 @@
50#include <asm/byteorder.h> 51#include <asm/byteorder.h>
51#include <linux/moduleparam.h> 52#include <linux/moduleparam.h>
52 53
53#include "hcd.h" /* for usbcore internals */
54#include "usb.h" 54#include "usb.h"
55#include "hub.h"
56 55
57#define USB_MAXBUS 64 56#define USB_MAXBUS 64
58#define USB_DEVICE_MAX USB_MAXBUS * 128 57#define USB_DEVICE_MAX USB_MAXBUS * 128
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 2f3dc4cdf79b..ded550eda5d9 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -26,8 +26,9 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/quirks.h> 28#include <linux/usb/quirks.h>
29#include <linux/usb/hcd.h>
29#include <linux/pm_runtime.h> 30#include <linux/pm_runtime.h>
30#include "hcd.h" 31
31#include "usb.h" 32#include "usb.h"
32 33
33 34
@@ -333,7 +334,8 @@ static int usb_probe_interface(struct device *dev)
333 usb_cancel_queued_reset(intf); 334 usb_cancel_queued_reset(intf);
334 335
335 /* Unbound interfaces are always runtime-PM-disabled and -suspended */ 336 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
336 pm_runtime_disable(dev); 337 if (driver->supports_autosuspend)
338 pm_runtime_disable(dev);
337 pm_runtime_set_suspended(dev); 339 pm_runtime_set_suspended(dev);
338 340
339 usb_autosuspend_device(udev); 341 usb_autosuspend_device(udev);
@@ -388,7 +390,8 @@ static int usb_unbind_interface(struct device *dev)
388 intf->needs_remote_wakeup = 0; 390 intf->needs_remote_wakeup = 0;
389 391
390 /* Unbound interfaces are always runtime-PM-disabled and -suspended */ 392 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
391 pm_runtime_disable(dev); 393 if (driver->supports_autosuspend)
394 pm_runtime_disable(dev);
392 pm_runtime_set_suspended(dev); 395 pm_runtime_set_suspended(dev);
393 396
394 /* Undo any residual pm_autopm_get_interface_* calls */ 397 /* Undo any residual pm_autopm_get_interface_* calls */
@@ -437,14 +440,17 @@ int usb_driver_claim_interface(struct usb_driver *driver,
437 440
438 iface->condition = USB_INTERFACE_BOUND; 441 iface->condition = USB_INTERFACE_BOUND;
439 442
440 /* Claimed interfaces are initially inactive (suspended). They are 443 /* Claimed interfaces are initially inactive (suspended) and
441 * runtime-PM-enabled only if the driver has autosuspend support. 444 * runtime-PM-enabled, but only if the driver has autosuspend
442 * They are sensitive to their children's power states. 445 * support. Otherwise they are marked active, to prevent the
446 * device from being autosuspended, but left disabled. In either
447 * case they are sensitive to their children's power states.
443 */ 448 */
444 pm_runtime_set_suspended(dev);
445 pm_suspend_ignore_children(dev, false); 449 pm_suspend_ignore_children(dev, false);
446 if (driver->supports_autosuspend) 450 if (driver->supports_autosuspend)
447 pm_runtime_enable(dev); 451 pm_runtime_enable(dev);
452 else
453 pm_runtime_set_active(dev);
448 454
449 /* if interface was already added, bind now; else let 455 /* if interface was already added, bind now; else let
450 * the future device_add() bind it, bypassing probe() 456 * the future device_add() bind it, bypassing probe()
@@ -1355,13 +1361,9 @@ int usb_resume(struct device *dev, pm_message_t msg)
1355 * 1361 *
1356 * The caller must hold @udev's device lock. 1362 * The caller must hold @udev's device lock.
1357 */ 1363 */
1358int usb_enable_autosuspend(struct usb_device *udev) 1364void usb_enable_autosuspend(struct usb_device *udev)
1359{ 1365{
1360 if (udev->autosuspend_disabled) { 1366 pm_runtime_allow(&udev->dev);
1361 udev->autosuspend_disabled = 0;
1362 usb_autosuspend_device(udev);
1363 }
1364 return 0;
1365} 1367}
1366EXPORT_SYMBOL_GPL(usb_enable_autosuspend); 1368EXPORT_SYMBOL_GPL(usb_enable_autosuspend);
1367 1369
@@ -1374,16 +1376,9 @@ EXPORT_SYMBOL_GPL(usb_enable_autosuspend);
1374 * 1376 *
1375 * The caller must hold @udev's device lock. 1377 * The caller must hold @udev's device lock.
1376 */ 1378 */
1377int usb_disable_autosuspend(struct usb_device *udev) 1379void usb_disable_autosuspend(struct usb_device *udev)
1378{ 1380{
1379 int rc = 0; 1381 pm_runtime_forbid(&udev->dev);
1380
1381 if (!udev->autosuspend_disabled) {
1382 rc = usb_autoresume_device(udev);
1383 if (rc == 0)
1384 udev->autosuspend_disabled = 1;
1385 }
1386 return rc;
1387} 1382}
1388EXPORT_SYMBOL_GPL(usb_disable_autosuspend); 1383EXPORT_SYMBOL_GPL(usb_disable_autosuspend);
1389 1384
@@ -1485,9 +1480,6 @@ int usb_autoresume_device(struct usb_device *udev)
1485 * 0, a delayed autosuspend request for @intf's device is attempted. The 1480 * 0, a delayed autosuspend request for @intf's device is attempted. The
1486 * attempt may fail (see autosuspend_check()). 1481 * attempt may fail (see autosuspend_check()).
1487 * 1482 *
1488 * If the driver has set @intf->needs_remote_wakeup then autosuspend will
1489 * take place only if the device's remote-wakeup facility is enabled.
1490 *
1491 * This routine can run only in process context. 1483 * This routine can run only in process context.
1492 */ 1484 */
1493void usb_autopm_put_interface(struct usb_interface *intf) 1485void usb_autopm_put_interface(struct usb_interface *intf)
@@ -1530,7 +1522,7 @@ void usb_autopm_put_interface_async(struct usb_interface *intf)
1530 atomic_dec(&intf->pm_usage_cnt); 1522 atomic_dec(&intf->pm_usage_cnt);
1531 pm_runtime_put_noidle(&intf->dev); 1523 pm_runtime_put_noidle(&intf->dev);
1532 1524
1533 if (!udev->autosuspend_disabled) { 1525 if (udev->dev.power.runtime_auto) {
1534 /* Optimization: Don't schedule a delayed autosuspend if 1526 /* Optimization: Don't schedule a delayed autosuspend if
1535 * the timer is already running and the expiration time 1527 * the timer is already running and the expiration time
1536 * wouldn't change. 1528 * wouldn't change.
@@ -1672,14 +1664,14 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface_no_resume);
1672/* Internal routine to check whether we may autosuspend a device. */ 1664/* Internal routine to check whether we may autosuspend a device. */
1673static int autosuspend_check(struct usb_device *udev) 1665static int autosuspend_check(struct usb_device *udev)
1674{ 1666{
1675 int i; 1667 int w, i;
1676 struct usb_interface *intf; 1668 struct usb_interface *intf;
1677 unsigned long suspend_time, j; 1669 unsigned long suspend_time, j;
1678 1670
1679 /* Fail if autosuspend is disabled, or any interfaces are in use, or 1671 /* Fail if autosuspend is disabled, or any interfaces are in use, or
1680 * any interface drivers require remote wakeup but it isn't available. 1672 * any interface drivers require remote wakeup but it isn't available.
1681 */ 1673 */
1682 udev->do_remote_wakeup = device_may_wakeup(&udev->dev); 1674 w = 0;
1683 if (udev->actconfig) { 1675 if (udev->actconfig) {
1684 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1676 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1685 intf = udev->actconfig->interface[i]; 1677 intf = udev->actconfig->interface[i];
@@ -1693,12 +1685,7 @@ static int autosuspend_check(struct usb_device *udev)
1693 continue; 1685 continue;
1694 if (atomic_read(&intf->dev.power.usage_count) > 0) 1686 if (atomic_read(&intf->dev.power.usage_count) > 0)
1695 return -EBUSY; 1687 return -EBUSY;
1696 if (intf->needs_remote_wakeup && 1688 w |= intf->needs_remote_wakeup;
1697 !udev->do_remote_wakeup) {
1698 dev_dbg(&udev->dev, "remote wakeup needed "
1699 "for autosuspend\n");
1700 return -EOPNOTSUPP;
1701 }
1702 1689
1703 /* Don't allow autosuspend if the device will need 1690 /* Don't allow autosuspend if the device will need
1704 * a reset-resume and any of its interface drivers 1691 * a reset-resume and any of its interface drivers
@@ -1714,6 +1701,11 @@ static int autosuspend_check(struct usb_device *udev)
1714 } 1701 }
1715 } 1702 }
1716 } 1703 }
1704 if (w && !device_can_wakeup(&udev->dev)) {
1705 dev_dbg(&udev->dev, "remote wakeup needed for autosuspend\n");
1706 return -EOPNOTSUPP;
1707 }
1708 udev->do_remote_wakeup = w;
1717 1709
1718 /* If everything is okay but the device hasn't been idle for long 1710 /* If everything is okay but the device hasn't been idle for long
1719 * enough, queue a delayed autosuspend request. 1711 * enough, queue a delayed autosuspend request.
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 2c95153c0f24..9a34ccb0a1c0 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -18,8 +18,8 @@
18 */ 18 */
19 19
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usb/hcd.h>
21#include "usb.h" 22#include "usb.h"
22#include "hcd.h"
23 23
24static inline const char *plural(int n) 24static inline const char *plural(int n)
25{ 25{
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 15286533c15a..1cf2d1e79a5c 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -21,6 +21,7 @@
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/pm_runtime.h> 22#include <linux/pm_runtime.h>
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/usb/hcd.h>
24 25
25#include <asm/io.h> 26#include <asm/io.h>
26#include <asm/irq.h> 27#include <asm/irq.h>
@@ -33,7 +34,6 @@
33#endif 34#endif
34 35
35#include "usb.h" 36#include "usb.h"
36#include "hcd.h"
37 37
38 38
39/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ 39/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 2f8cedda8007..12742f152f43 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -38,14 +38,12 @@
38#include <asm/unaligned.h> 38#include <asm/unaligned.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/mutex.h>
42#include <linux/pm_runtime.h> 41#include <linux/pm_runtime.h>
43 42
44#include <linux/usb.h> 43#include <linux/usb.h>
44#include <linux/usb/hcd.h>
45 45
46#include "usb.h" 46#include "usb.h"
47#include "hcd.h"
48#include "hub.h"
49 47
50 48
51/*-------------------------------------------------------------------------*/ 49/*-------------------------------------------------------------------------*/
@@ -1261,6 +1259,51 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
1261 *dma_handle = 0; 1259 *dma_handle = 0;
1262} 1260}
1263 1261
1262static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1263{
1264 enum dma_data_direction dir;
1265
1266 if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
1267 dma_unmap_single(hcd->self.controller,
1268 urb->setup_dma,
1269 sizeof(struct usb_ctrlrequest),
1270 DMA_TO_DEVICE);
1271 else if (urb->transfer_flags & URB_SETUP_MAP_LOCAL)
1272 hcd_free_coherent(urb->dev->bus,
1273 &urb->setup_dma,
1274 (void **) &urb->setup_packet,
1275 sizeof(struct usb_ctrlrequest),
1276 DMA_TO_DEVICE);
1277
1278 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1279 if (urb->transfer_flags & URB_DMA_MAP_SG)
1280 dma_unmap_sg(hcd->self.controller,
1281 urb->sg,
1282 urb->num_sgs,
1283 dir);
1284 else if (urb->transfer_flags & URB_DMA_MAP_PAGE)
1285 dma_unmap_page(hcd->self.controller,
1286 urb->transfer_dma,
1287 urb->transfer_buffer_length,
1288 dir);
1289 else if (urb->transfer_flags & URB_DMA_MAP_SINGLE)
1290 dma_unmap_single(hcd->self.controller,
1291 urb->transfer_dma,
1292 urb->transfer_buffer_length,
1293 dir);
1294 else if (urb->transfer_flags & URB_MAP_LOCAL)
1295 hcd_free_coherent(urb->dev->bus,
1296 &urb->transfer_dma,
1297 &urb->transfer_buffer,
1298 urb->transfer_buffer_length,
1299 dir);
1300
1301 /* Make it safe to call this routine more than once */
1302 urb->transfer_flags &= ~(URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL |
1303 URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
1304 URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
1305}
1306
1264static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, 1307static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1265 gfp_t mem_flags) 1308 gfp_t mem_flags)
1266{ 1309{
@@ -1272,11 +1315,8 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1272 * unless it uses pio or talks to another transport, 1315 * unless it uses pio or talks to another transport,
1273 * or uses the provided scatter gather list for bulk. 1316 * or uses the provided scatter gather list for bulk.
1274 */ 1317 */
1275 if (is_root_hub(urb->dev))
1276 return 0;
1277 1318
1278 if (usb_endpoint_xfer_control(&urb->ep->desc) 1319 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
1279 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
1280 if (hcd->self.uses_dma) { 1320 if (hcd->self.uses_dma) {
1281 urb->setup_dma = dma_map_single( 1321 urb->setup_dma = dma_map_single(
1282 hcd->self.controller, 1322 hcd->self.controller,
@@ -1286,27 +1326,64 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1286 if (dma_mapping_error(hcd->self.controller, 1326 if (dma_mapping_error(hcd->self.controller,
1287 urb->setup_dma)) 1327 urb->setup_dma))
1288 return -EAGAIN; 1328 return -EAGAIN;
1289 } else if (hcd->driver->flags & HCD_LOCAL_MEM) 1329 urb->transfer_flags |= URB_SETUP_MAP_SINGLE;
1330 } else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1290 ret = hcd_alloc_coherent( 1331 ret = hcd_alloc_coherent(
1291 urb->dev->bus, mem_flags, 1332 urb->dev->bus, mem_flags,
1292 &urb->setup_dma, 1333 &urb->setup_dma,
1293 (void **)&urb->setup_packet, 1334 (void **)&urb->setup_packet,
1294 sizeof(struct usb_ctrlrequest), 1335 sizeof(struct usb_ctrlrequest),
1295 DMA_TO_DEVICE); 1336 DMA_TO_DEVICE);
1337 if (ret)
1338 return ret;
1339 urb->transfer_flags |= URB_SETUP_MAP_LOCAL;
1340 }
1296 } 1341 }
1297 1342
1298 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1343 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1299 if (ret == 0 && urb->transfer_buffer_length != 0 1344 if (urb->transfer_buffer_length != 0
1300 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { 1345 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1301 if (hcd->self.uses_dma) { 1346 if (hcd->self.uses_dma) {
1302 urb->transfer_dma = dma_map_single ( 1347 if (urb->num_sgs) {
1303 hcd->self.controller, 1348 int n = dma_map_sg(
1304 urb->transfer_buffer, 1349 hcd->self.controller,
1305 urb->transfer_buffer_length, 1350 urb->sg,
1306 dir); 1351 urb->num_sgs,
1307 if (dma_mapping_error(hcd->self.controller, 1352 dir);
1353 if (n <= 0)
1354 ret = -EAGAIN;
1355 else
1356 urb->transfer_flags |= URB_DMA_MAP_SG;
1357 if (n != urb->num_sgs) {
1358 urb->num_sgs = n;
1359 urb->transfer_flags |=
1360 URB_DMA_SG_COMBINED;
1361 }
1362 } else if (urb->sg) {
1363 struct scatterlist *sg = urb->sg;
1364 urb->transfer_dma = dma_map_page(
1365 hcd->self.controller,
1366 sg_page(sg),
1367 sg->offset,
1368 urb->transfer_buffer_length,
1369 dir);
1370 if (dma_mapping_error(hcd->self.controller,
1308 urb->transfer_dma)) 1371 urb->transfer_dma))
1309 return -EAGAIN; 1372 ret = -EAGAIN;
1373 else
1374 urb->transfer_flags |= URB_DMA_MAP_PAGE;
1375 } else {
1376 urb->transfer_dma = dma_map_single(
1377 hcd->self.controller,
1378 urb->transfer_buffer,
1379 urb->transfer_buffer_length,
1380 dir);
1381 if (dma_mapping_error(hcd->self.controller,
1382 urb->transfer_dma))
1383 ret = -EAGAIN;
1384 else
1385 urb->transfer_flags |= URB_DMA_MAP_SINGLE;
1386 }
1310 } else if (hcd->driver->flags & HCD_LOCAL_MEM) { 1387 } else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1311 ret = hcd_alloc_coherent( 1388 ret = hcd_alloc_coherent(
1312 urb->dev->bus, mem_flags, 1389 urb->dev->bus, mem_flags,
@@ -1314,55 +1391,16 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1314 &urb->transfer_buffer, 1391 &urb->transfer_buffer,
1315 urb->transfer_buffer_length, 1392 urb->transfer_buffer_length,
1316 dir); 1393 dir);
1317 1394 if (ret == 0)
1318 if (ret && usb_endpoint_xfer_control(&urb->ep->desc) 1395 urb->transfer_flags |= URB_MAP_LOCAL;
1319 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
1320 hcd_free_coherent(urb->dev->bus,
1321 &urb->setup_dma,
1322 (void **)&urb->setup_packet,
1323 sizeof(struct usb_ctrlrequest),
1324 DMA_TO_DEVICE);
1325 } 1396 }
1397 if (ret && (urb->transfer_flags & (URB_SETUP_MAP_SINGLE |
1398 URB_SETUP_MAP_LOCAL)))
1399 unmap_urb_for_dma(hcd, urb);
1326 } 1400 }
1327 return ret; 1401 return ret;
1328} 1402}
1329 1403
1330static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1331{
1332 enum dma_data_direction dir;
1333
1334 if (is_root_hub(urb->dev))
1335 return;
1336
1337 if (usb_endpoint_xfer_control(&urb->ep->desc)
1338 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
1339 if (hcd->self.uses_dma)
1340 dma_unmap_single(hcd->self.controller, urb->setup_dma,
1341 sizeof(struct usb_ctrlrequest),
1342 DMA_TO_DEVICE);
1343 else if (hcd->driver->flags & HCD_LOCAL_MEM)
1344 hcd_free_coherent(urb->dev->bus, &urb->setup_dma,
1345 (void **)&urb->setup_packet,
1346 sizeof(struct usb_ctrlrequest),
1347 DMA_TO_DEVICE);
1348 }
1349
1350 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1351 if (urb->transfer_buffer_length != 0
1352 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1353 if (hcd->self.uses_dma)
1354 dma_unmap_single(hcd->self.controller,
1355 urb->transfer_dma,
1356 urb->transfer_buffer_length,
1357 dir);
1358 else if (hcd->driver->flags & HCD_LOCAL_MEM)
1359 hcd_free_coherent(urb->dev->bus, &urb->transfer_dma,
1360 &urb->transfer_buffer,
1361 urb->transfer_buffer_length,
1362 dir);
1363 }
1364}
1365
1366/*-------------------------------------------------------------------------*/ 1404/*-------------------------------------------------------------------------*/
1367 1405
1368/* may be called in any context with a valid urb->dev usecount 1406/* may be called in any context with a valid urb->dev usecount
@@ -1391,21 +1429,20 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1391 * URBs must be submitted in process context with interrupts 1429 * URBs must be submitted in process context with interrupts
1392 * enabled. 1430 * enabled.
1393 */ 1431 */
1394 status = map_urb_for_dma(hcd, urb, mem_flags);
1395 if (unlikely(status)) {
1396 usbmon_urb_submit_error(&hcd->self, urb, status);
1397 goto error;
1398 }
1399 1432
1400 if (is_root_hub(urb->dev)) 1433 if (is_root_hub(urb->dev)) {
1401 status = rh_urb_enqueue(hcd, urb); 1434 status = rh_urb_enqueue(hcd, urb);
1402 else 1435 } else {
1403 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags); 1436 status = map_urb_for_dma(hcd, urb, mem_flags);
1437 if (likely(status == 0)) {
1438 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);
1439 if (unlikely(status))
1440 unmap_urb_for_dma(hcd, urb);
1441 }
1442 }
1404 1443
1405 if (unlikely(status)) { 1444 if (unlikely(status)) {
1406 usbmon_urb_submit_error(&hcd->self, urb, status); 1445 usbmon_urb_submit_error(&hcd->self, urb, status);
1407 unmap_urb_for_dma(hcd, urb);
1408 error:
1409 urb->hcpriv = NULL; 1446 urb->hcpriv = NULL;
1410 INIT_LIST_HEAD(&urb->urb_list); 1447 INIT_LIST_HEAD(&urb->urb_list);
1411 atomic_dec(&urb->use_count); 1448 atomic_dec(&urb->use_count);
@@ -1775,6 +1812,75 @@ void usb_hcd_reset_endpoint(struct usb_device *udev,
1775 } 1812 }
1776} 1813}
1777 1814
1815/**
1816 * usb_alloc_streams - allocate bulk endpoint stream IDs.
1817 * @interface: alternate setting that includes all endpoints.
1818 * @eps: array of endpoints that need streams.
1819 * @num_eps: number of endpoints in the array.
1820 * @num_streams: number of streams to allocate.
1821 * @mem_flags: flags hcd should use to allocate memory.
1822 *
1823 * Sets up a group of bulk endpoints to have num_streams stream IDs available.
1824 * Drivers may queue multiple transfers to different stream IDs, which may
1825 * complete in a different order than they were queued.
1826 */
1827int usb_alloc_streams(struct usb_interface *interface,
1828 struct usb_host_endpoint **eps, unsigned int num_eps,
1829 unsigned int num_streams, gfp_t mem_flags)
1830{
1831 struct usb_hcd *hcd;
1832 struct usb_device *dev;
1833 int i;
1834
1835 dev = interface_to_usbdev(interface);
1836 hcd = bus_to_hcd(dev->bus);
1837 if (!hcd->driver->alloc_streams || !hcd->driver->free_streams)
1838 return -EINVAL;
1839 if (dev->speed != USB_SPEED_SUPER)
1840 return -EINVAL;
1841
1842 /* Streams only apply to bulk endpoints. */
1843 for (i = 0; i < num_eps; i++)
1844 if (!usb_endpoint_xfer_bulk(&eps[i]->desc))
1845 return -EINVAL;
1846
1847 return hcd->driver->alloc_streams(hcd, dev, eps, num_eps,
1848 num_streams, mem_flags);
1849}
1850EXPORT_SYMBOL_GPL(usb_alloc_streams);
1851
1852/**
1853 * usb_free_streams - free bulk endpoint stream IDs.
1854 * @interface: alternate setting that includes all endpoints.
1855 * @eps: array of endpoints to remove streams from.
1856 * @num_eps: number of endpoints in the array.
1857 * @mem_flags: flags hcd should use to allocate memory.
1858 *
1859 * Reverts a group of bulk endpoints back to not using stream IDs.
1860 * Can fail if we are given bad arguments, or HCD is broken.
1861 */
1862void usb_free_streams(struct usb_interface *interface,
1863 struct usb_host_endpoint **eps, unsigned int num_eps,
1864 gfp_t mem_flags)
1865{
1866 struct usb_hcd *hcd;
1867 struct usb_device *dev;
1868 int i;
1869
1870 dev = interface_to_usbdev(interface);
1871 hcd = bus_to_hcd(dev->bus);
1872 if (dev->speed != USB_SPEED_SUPER)
1873 return;
1874
1875 /* Streams only apply to bulk endpoints. */
1876 for (i = 0; i < num_eps; i++)
1877 if (!usb_endpoint_xfer_bulk(&eps[i]->desc))
1878 return;
1879
1880 hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags);
1881}
1882EXPORT_SYMBOL_GPL(usb_free_streams);
1883
1778/* Protect against drivers that try to unlink URBs after the device 1884/* Protect against drivers that try to unlink URBs after the device
1779 * is gone, by waiting until all unlinks for @udev are finished. 1885 * is gone, by waiting until all unlinks for @udev are finished.
1780 * Since we don't currently track URBs by device, simply wait until 1886 * Since we don't currently track URBs by device, simply wait until
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 0940ccd6f4f4..83e7bbbe97fa 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -19,6 +19,7 @@
19#include <linux/ioctl.h> 19#include <linux/ioctl.h>
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usbdevice_fs.h> 21#include <linux/usbdevice_fs.h>
22#include <linux/usb/hcd.h>
22#include <linux/kthread.h> 23#include <linux/kthread.h>
23#include <linux/mutex.h> 24#include <linux/mutex.h>
24#include <linux/freezer.h> 25#include <linux/freezer.h>
@@ -28,8 +29,6 @@
28#include <asm/byteorder.h> 29#include <asm/byteorder.h>
29 30
30#include "usb.h" 31#include "usb.h"
31#include "hcd.h"
32#include "hub.h"
33 32
34/* if we are in debug mode, always announce new devices */ 33/* if we are in debug mode, always announce new devices */
35#ifdef DEBUG 34#ifdef DEBUG
@@ -154,11 +153,11 @@ static int usb_reset_and_verify_device(struct usb_device *udev);
154 153
155static inline char *portspeed(int portstatus) 154static inline char *portspeed(int portstatus)
156{ 155{
157 if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) 156 if (portstatus & USB_PORT_STAT_HIGH_SPEED)
158 return "480 Mb/s"; 157 return "480 Mb/s";
159 else if (portstatus & (1 << USB_PORT_FEAT_LOWSPEED)) 158 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
160 return "1.5 Mb/s"; 159 return "1.5 Mb/s";
161 else if (portstatus & (1 << USB_PORT_FEAT_SUPERSPEED)) 160 else if (portstatus & USB_PORT_STAT_SUPER_SPEED)
162 return "5.0 Gb/s"; 161 return "5.0 Gb/s";
163 else 162 else
164 return "12 Mb/s"; 163 return "12 Mb/s";
@@ -745,8 +744,20 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
745 !(portstatus & USB_PORT_STAT_CONNECTION) || 744 !(portstatus & USB_PORT_STAT_CONNECTION) ||
746 !udev || 745 !udev ||
747 udev->state == USB_STATE_NOTATTACHED)) { 746 udev->state == USB_STATE_NOTATTACHED)) {
748 clear_port_feature(hdev, port1, USB_PORT_FEAT_ENABLE); 747 /*
749 portstatus &= ~USB_PORT_STAT_ENABLE; 748 * USB3 protocol ports will automatically transition
749 * to Enabled state when detect an USB3.0 device attach.
750 * Do not disable USB3 protocol ports.
751 * FIXME: USB3 root hub and external hubs are treated
752 * differently here.
753 */
754 if (hdev->descriptor.bDeviceProtocol != 3 ||
755 (!hdev->parent &&
756 !(portstatus & USB_PORT_STAT_SUPER_SPEED))) {
757 clear_port_feature(hdev, port1,
758 USB_PORT_FEAT_ENABLE);
759 portstatus &= ~USB_PORT_STAT_ENABLE;
760 }
750 } 761 }
751 762
752 /* Clear status-change flags; we'll debounce later */ 763 /* Clear status-change flags; we'll debounce later */
@@ -1784,7 +1795,6 @@ int usb_new_device(struct usb_device *udev)
1784 * sysfs power/wakeup controls wakeup enabled/disabled 1795 * sysfs power/wakeup controls wakeup enabled/disabled
1785 */ 1796 */
1786 device_init_wakeup(&udev->dev, 0); 1797 device_init_wakeup(&udev->dev, 0);
1787 device_set_wakeup_enable(&udev->dev, 1);
1788 } 1798 }
1789 1799
1790 /* Tell the runtime-PM framework the device is active */ 1800 /* Tell the runtime-PM framework the device is active */
@@ -3038,7 +3048,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3038 3048
3039 /* maybe switch power back on (e.g. root hub was reset) */ 3049 /* maybe switch power back on (e.g. root hub was reset) */
3040 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 3050 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2
3041 && !(portstatus & (1 << USB_PORT_FEAT_POWER))) 3051 && !(portstatus & USB_PORT_STAT_POWER))
3042 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER); 3052 set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
3043 3053
3044 if (portstatus & USB_PORT_STAT_ENABLE) 3054 if (portstatus & USB_PORT_STAT_ENABLE)
@@ -3076,7 +3086,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
3076 if (!(hcd->driver->flags & HCD_USB3)) 3086 if (!(hcd->driver->flags & HCD_USB3))
3077 udev->speed = USB_SPEED_UNKNOWN; 3087 udev->speed = USB_SPEED_UNKNOWN;
3078 else if ((hdev->parent == NULL) && 3088 else if ((hdev->parent == NULL) &&
3079 (portstatus & (1 << USB_PORT_FEAT_SUPERSPEED))) 3089 (portstatus & USB_PORT_STAT_SUPER_SPEED))
3080 udev->speed = USB_SPEED_SUPER; 3090 udev->speed = USB_SPEED_SUPER;
3081 else 3091 else
3082 udev->speed = USB_SPEED_UNKNOWN; 3092 udev->speed = USB_SPEED_UNKNOWN;
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 111a01a747fc..1a27618b67d6 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -40,9 +40,9 @@
40#include <linux/notifier.h> 40#include <linux/notifier.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/smp_lock.h> 42#include <linux/smp_lock.h>
43#include <linux/usb/hcd.h>
43#include <asm/byteorder.h> 44#include <asm/byteorder.h>
44#include "usb.h" 45#include "usb.h"
45#include "hcd.h"
46 46
47#define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO) 47#define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO)
48#define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO) 48#define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index cd220277c6c3..a73e08fdab36 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -14,9 +14,9 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/scatterlist.h> 15#include <linux/scatterlist.h>
16#include <linux/usb/quirks.h> 16#include <linux/usb/quirks.h>
17#include <linux/usb/hcd.h> /* for usbcore internals */
17#include <asm/byteorder.h> 18#include <asm/byteorder.h>
18 19
19#include "hcd.h" /* for usbcore internals */
20#include "usb.h" 20#include "usb.h"
21 21
22static void cancel_async_set_config(struct usb_device *udev); 22static void cancel_async_set_config(struct usb_device *udev);
@@ -226,8 +226,7 @@ int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
226 struct urb *urb; 226 struct urb *urb;
227 struct usb_host_endpoint *ep; 227 struct usb_host_endpoint *ep;
228 228
229 ep = (usb_pipein(pipe) ? usb_dev->ep_in : usb_dev->ep_out) 229 ep = usb_pipe_endpoint(usb_dev, pipe);
230 [usb_pipeendpoint(pipe)];
231 if (!ep || len < 0) 230 if (!ep || len < 0)
232 return -EINVAL; 231 return -EINVAL;
233 232
@@ -259,9 +258,6 @@ static void sg_clean(struct usb_sg_request *io)
259 kfree(io->urbs); 258 kfree(io->urbs);
260 io->urbs = NULL; 259 io->urbs = NULL;
261 } 260 }
262 if (io->dev->dev.dma_mask != NULL)
263 usb_buffer_unmap_sg(io->dev, usb_pipein(io->pipe),
264 io->sg, io->nents);
265 io->dev = NULL; 261 io->dev = NULL;
266} 262}
267 263
@@ -364,7 +360,6 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
364{ 360{
365 int i; 361 int i;
366 int urb_flags; 362 int urb_flags;
367 int dma;
368 int use_sg; 363 int use_sg;
369 364
370 if (!io || !dev || !sg 365 if (!io || !dev || !sg
@@ -376,114 +371,76 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
376 spin_lock_init(&io->lock); 371 spin_lock_init(&io->lock);
377 io->dev = dev; 372 io->dev = dev;
378 io->pipe = pipe; 373 io->pipe = pipe;
379 io->sg = sg;
380 io->nents = nents;
381
382 /* not all host controllers use DMA (like the mainstream pci ones);
383 * they can use PIO (sl811) or be software over another transport.
384 */
385 dma = (dev->dev.dma_mask != NULL);
386 if (dma)
387 io->entries = usb_buffer_map_sg(dev, usb_pipein(pipe),
388 sg, nents);
389 else
390 io->entries = nents;
391
392 /* initialize all the urbs we'll use */
393 if (io->entries <= 0)
394 return io->entries;
395 374
396 if (dev->bus->sg_tablesize > 0) { 375 if (dev->bus->sg_tablesize > 0) {
397 io->urbs = kmalloc(sizeof *io->urbs, mem_flags);
398 use_sg = true; 376 use_sg = true;
377 io->entries = 1;
399 } else { 378 } else {
400 io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
401 use_sg = false; 379 use_sg = false;
380 io->entries = nents;
402 } 381 }
382
383 /* initialize all the urbs we'll use */
384 io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
403 if (!io->urbs) 385 if (!io->urbs)
404 goto nomem; 386 goto nomem;
405 387
406 urb_flags = 0; 388 urb_flags = URB_NO_INTERRUPT;
407 if (dma)
408 urb_flags |= URB_NO_TRANSFER_DMA_MAP;
409 if (usb_pipein(pipe)) 389 if (usb_pipein(pipe))
410 urb_flags |= URB_SHORT_NOT_OK; 390 urb_flags |= URB_SHORT_NOT_OK;
411 391
412 if (use_sg) { 392 for_each_sg(sg, sg, io->entries, i) {
413 io->urbs[0] = usb_alloc_urb(0, mem_flags); 393 struct urb *urb;
414 if (!io->urbs[0]) { 394 unsigned len;
415 io->entries = 0;
416 goto nomem;
417 }
418 395
419 io->urbs[0]->dev = NULL; 396 urb = usb_alloc_urb(0, mem_flags);
420 io->urbs[0]->pipe = pipe; 397 if (!urb) {
421 io->urbs[0]->interval = period; 398 io->entries = i;
422 io->urbs[0]->transfer_flags = urb_flags; 399 goto nomem;
423
424 io->urbs[0]->complete = sg_complete;
425 io->urbs[0]->context = io;
426 /* A length of zero means transfer the whole sg list */
427 io->urbs[0]->transfer_buffer_length = length;
428 if (length == 0) {
429 for_each_sg(sg, sg, io->entries, i) {
430 io->urbs[0]->transfer_buffer_length +=
431 sg_dma_len(sg);
432 }
433 } 400 }
434 io->urbs[0]->sg = io; 401 io->urbs[i] = urb;
435 io->urbs[0]->num_sgs = io->entries; 402
436 io->entries = 1; 403 urb->dev = NULL;
437 } else { 404 urb->pipe = pipe;
438 urb_flags |= URB_NO_INTERRUPT; 405 urb->interval = period;
439 for_each_sg(sg, sg, io->entries, i) { 406 urb->transfer_flags = urb_flags;
440 unsigned len; 407 urb->complete = sg_complete;
441 408 urb->context = io;
442 io->urbs[i] = usb_alloc_urb(0, mem_flags); 409 urb->sg = sg;
443 if (!io->urbs[i]) { 410
444 io->entries = i; 411 if (use_sg) {
445 goto nomem; 412 /* There is no single transfer buffer */
413 urb->transfer_buffer = NULL;
414 urb->num_sgs = nents;
415
416 /* A length of zero means transfer the whole sg list */
417 len = length;
418 if (len == 0) {
419 for_each_sg(sg, sg, nents, i)
420 len += sg->length;
446 } 421 }
447 422 } else {
448 io->urbs[i]->dev = NULL;
449 io->urbs[i]->pipe = pipe;
450 io->urbs[i]->interval = period;
451 io->urbs[i]->transfer_flags = urb_flags;
452
453 io->urbs[i]->complete = sg_complete;
454 io->urbs[i]->context = io;
455
456 /* 423 /*
457 * Some systems need to revert to PIO when DMA is temporarily 424 * Some systems can't use DMA; they use PIO instead.
458 * unavailable. For their sakes, both transfer_buffer and 425 * For their sakes, transfer_buffer is set whenever
459 * transfer_dma are set when possible. 426 * possible.
460 *
461 * Note that if IOMMU coalescing occurred, we cannot
462 * trust sg_page anymore, so check if S/G list shrunk.
463 */ 427 */
464 if (io->nents == io->entries && !PageHighMem(sg_page(sg))) 428 if (!PageHighMem(sg_page(sg)))
465 io->urbs[i]->transfer_buffer = sg_virt(sg); 429 urb->transfer_buffer = sg_virt(sg);
466 else 430 else
467 io->urbs[i]->transfer_buffer = NULL; 431 urb->transfer_buffer = NULL;
468
469 if (dma) {
470 io->urbs[i]->transfer_dma = sg_dma_address(sg);
471 len = sg_dma_len(sg);
472 } else {
473 /* hc may use _only_ transfer_buffer */
474 len = sg->length;
475 }
476 432
433 len = sg->length;
477 if (length) { 434 if (length) {
478 len = min_t(unsigned, len, length); 435 len = min_t(unsigned, len, length);
479 length -= len; 436 length -= len;
480 if (length == 0) 437 if (length == 0)
481 io->entries = i + 1; 438 io->entries = i + 1;
482 } 439 }
483 io->urbs[i]->transfer_buffer_length = len;
484 } 440 }
485 io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT; 441 urb->transfer_buffer_length = len;
486 } 442 }
443 io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
487 444
488 /* transaction state */ 445 /* transaction state */
489 io->count = io->entries; 446 io->count = io->entries;
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index f073c5cb4e7b..f22d03df8b17 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -71,6 +71,10 @@ static const struct usb_device_id usb_quirk_list[] = {
71 /* SKYMEDI USB_DRIVE */ 71 /* SKYMEDI USB_DRIVE */
72 { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME }, 72 { USB_DEVICE(0x1516, 0x8628), .driver_info = USB_QUIRK_RESET_RESUME },
73 73
74 /* BUILDWIN Photo Frame */
75 { USB_DEVICE(0x1908, 0x1315), .driver_info =
76 USB_QUIRK_HONOR_BNUMINTERFACES },
77
74 /* INTEL VALUE SSD */ 78 /* INTEL VALUE SSD */
75 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME }, 79 { USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
76 80
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 43c002e3a9aa..06863befaf3a 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -383,13 +383,24 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
383static const char on_string[] = "on"; 383static const char on_string[] = "on";
384static const char auto_string[] = "auto"; 384static const char auto_string[] = "auto";
385 385
386static void warn_level(void) {
387 static int level_warned;
388
389 if (!level_warned) {
390 level_warned = 1;
391 printk(KERN_WARNING "WARNING! power/level is deprecated; "
392 "use power/control instead\n");
393 }
394}
395
386static ssize_t 396static ssize_t
387show_level(struct device *dev, struct device_attribute *attr, char *buf) 397show_level(struct device *dev, struct device_attribute *attr, char *buf)
388{ 398{
389 struct usb_device *udev = to_usb_device(dev); 399 struct usb_device *udev = to_usb_device(dev);
390 const char *p = auto_string; 400 const char *p = auto_string;
391 401
392 if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled) 402 warn_level();
403 if (udev->state != USB_STATE_SUSPENDED && !udev->dev.power.runtime_auto)
393 p = on_string; 404 p = on_string;
394 return sprintf(buf, "%s\n", p); 405 return sprintf(buf, "%s\n", p);
395} 406}
@@ -401,8 +412,9 @@ set_level(struct device *dev, struct device_attribute *attr,
401 struct usb_device *udev = to_usb_device(dev); 412 struct usb_device *udev = to_usb_device(dev);
402 int len = count; 413 int len = count;
403 char *cp; 414 char *cp;
404 int rc; 415 int rc = count;
405 416
417 warn_level();
406 cp = memchr(buf, '\n', count); 418 cp = memchr(buf, '\n', count);
407 if (cp) 419 if (cp)
408 len = cp - buf; 420 len = cp - buf;
@@ -411,17 +423,17 @@ set_level(struct device *dev, struct device_attribute *attr,
411 423
412 if (len == sizeof on_string - 1 && 424 if (len == sizeof on_string - 1 &&
413 strncmp(buf, on_string, len) == 0) 425 strncmp(buf, on_string, len) == 0)
414 rc = usb_disable_autosuspend(udev); 426 usb_disable_autosuspend(udev);
415 427
416 else if (len == sizeof auto_string - 1 && 428 else if (len == sizeof auto_string - 1 &&
417 strncmp(buf, auto_string, len) == 0) 429 strncmp(buf, auto_string, len) == 0)
418 rc = usb_enable_autosuspend(udev); 430 usb_enable_autosuspend(udev);
419 431
420 else 432 else
421 rc = -EINVAL; 433 rc = -EINVAL;
422 434
423 usb_unlock_device(udev); 435 usb_unlock_device(udev);
424 return (rc < 0 ? rc : count); 436 return rc;
425} 437}
426 438
427static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); 439static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level);
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 45a32dadb406..7c0555548ac8 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -6,7 +6,7 @@
6#include <linux/log2.h> 6#include <linux/log2.h>
7#include <linux/usb.h> 7#include <linux/usb.h>
8#include <linux/wait.h> 8#include <linux/wait.h>
9#include "hcd.h" 9#include <linux/usb/hcd.h>
10 10
11#define to_urb(d) container_of(d, struct urb, kref) 11#define to_urb(d) container_of(d, struct urb, kref)
12 12
@@ -308,8 +308,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
308 * will be required to set urb->ep directly and we will eliminate 308 * will be required to set urb->ep directly and we will eliminate
309 * urb->pipe. 309 * urb->pipe.
310 */ 310 */
311 ep = (usb_pipein(urb->pipe) ? dev->ep_in : dev->ep_out) 311 ep = usb_pipe_endpoint(dev, urb->pipe);
312 [usb_pipeendpoint(urb->pipe)];
313 if (!ep) 312 if (!ep)
314 return -ENOENT; 313 return -ENOENT;
315 314
@@ -333,9 +332,12 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
333 is_out = usb_endpoint_dir_out(&ep->desc); 332 is_out = usb_endpoint_dir_out(&ep->desc);
334 } 333 }
335 334
336 /* Cache the direction for later use */ 335 /* Clear the internal flags and cache the direction for later use */
337 urb->transfer_flags = (urb->transfer_flags & ~URB_DIR_MASK) | 336 urb->transfer_flags &= ~(URB_DIR_MASK | URB_DMA_MAP_SINGLE |
338 (is_out ? URB_DIR_OUT : URB_DIR_IN); 337 URB_DMA_MAP_PAGE | URB_DMA_MAP_SG | URB_MAP_LOCAL |
338 URB_SETUP_MAP_SINGLE | URB_SETUP_MAP_LOCAL |
339 URB_DMA_SG_COMBINED);
340 urb->transfer_flags |= (is_out ? URB_DIR_OUT : URB_DIR_IN);
339 341
340 if (xfertype != USB_ENDPOINT_XFER_CONTROL && 342 if (xfertype != USB_ENDPOINT_XFER_CONTROL &&
341 dev->state < USB_STATE_CONFIGURED) 343 dev->state < USB_STATE_CONFIGURED)
@@ -396,8 +398,8 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
396 return -EPIPE; /* The most suitable error code :-) */ 398 return -EPIPE; /* The most suitable error code :-) */
397 399
398 /* enforce simple/standard policy */ 400 /* enforce simple/standard policy */
399 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP | 401 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK |
400 URB_NO_INTERRUPT | URB_DIR_MASK | URB_FREE_BUFFER); 402 URB_FREE_BUFFER);
401 switch (xfertype) { 403 switch (xfertype) {
402 case USB_ENDPOINT_XFER_BULK: 404 case USB_ENDPOINT_XFER_BULK:
403 if (is_out) 405 if (is_out)
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 0561430f2ede..397b678f1c47 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -32,6 +32,7 @@
32#include <linux/spinlock.h> 32#include <linux/spinlock.h>
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/hcd.h>
35#include <linux/mutex.h> 36#include <linux/mutex.h>
36#include <linux/workqueue.h> 37#include <linux/workqueue.h>
37#include <linux/debugfs.h> 38#include <linux/debugfs.h>
@@ -41,7 +42,6 @@
41#include <linux/mm.h> 42#include <linux/mm.h>
42#include <linux/dma-mapping.h> 43#include <linux/dma-mapping.h>
43 44
44#include "hcd.h"
45#include "usb.h" 45#include "usb.h"
46 46
47 47
@@ -593,76 +593,6 @@ int usb_lock_device_for_reset(struct usb_device *udev,
593} 593}
594EXPORT_SYMBOL_GPL(usb_lock_device_for_reset); 594EXPORT_SYMBOL_GPL(usb_lock_device_for_reset);
595 595
596static struct usb_device *match_device(struct usb_device *dev,
597 u16 vendor_id, u16 product_id)
598{
599 struct usb_device *ret_dev = NULL;
600 int child;
601
602 dev_dbg(&dev->dev, "check for vendor %04x, product %04x ...\n",
603 le16_to_cpu(dev->descriptor.idVendor),
604 le16_to_cpu(dev->descriptor.idProduct));
605
606 /* see if this device matches */
607 if ((vendor_id == le16_to_cpu(dev->descriptor.idVendor)) &&
608 (product_id == le16_to_cpu(dev->descriptor.idProduct))) {
609 dev_dbg(&dev->dev, "matched this device!\n");
610 ret_dev = usb_get_dev(dev);
611 goto exit;
612 }
613
614 /* look through all of the children of this device */
615 for (child = 0; child < dev->maxchild; ++child) {
616 if (dev->children[child]) {
617 usb_lock_device(dev->children[child]);
618 ret_dev = match_device(dev->children[child],
619 vendor_id, product_id);
620 usb_unlock_device(dev->children[child]);
621 if (ret_dev)
622 goto exit;
623 }
624 }
625exit:
626 return ret_dev;
627}
628
629/**
630 * usb_find_device - find a specific usb device in the system
631 * @vendor_id: the vendor id of the device to find
632 * @product_id: the product id of the device to find
633 *
634 * Returns a pointer to a struct usb_device if such a specified usb
635 * device is present in the system currently. The usage count of the
636 * device will be incremented if a device is found. Make sure to call
637 * usb_put_dev() when the caller is finished with the device.
638 *
639 * If a device with the specified vendor and product id is not found,
640 * NULL is returned.
641 */
642struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
643{
644 struct list_head *buslist;
645 struct usb_bus *bus;
646 struct usb_device *dev = NULL;
647
648 mutex_lock(&usb_bus_list_lock);
649 for (buslist = usb_bus_list.next;
650 buslist != &usb_bus_list;
651 buslist = buslist->next) {
652 bus = container_of(buslist, struct usb_bus, bus_list);
653 if (!bus->root_hub)
654 continue;
655 usb_lock_device(bus->root_hub);
656 dev = match_device(bus->root_hub, vendor_id, product_id);
657 usb_unlock_device(bus->root_hub);
658 if (dev)
659 goto exit;
660 }
661exit:
662 mutex_unlock(&usb_bus_list_lock);
663 return dev;
664}
665
666/** 596/**
667 * usb_get_current_frame_number - return current bus frame number 597 * usb_get_current_frame_number - return current bus frame number
668 * @dev: the device whose bus is being queried 598 * @dev: the device whose bus is being queried
@@ -775,7 +705,7 @@ EXPORT_SYMBOL_GPL(usb_free_coherent);
775 * @urb: urb whose transfer_buffer/setup_packet will be mapped 705 * @urb: urb whose transfer_buffer/setup_packet will be mapped
776 * 706 *
777 * Return value is either null (indicating no buffer could be mapped), or 707 * Return value is either null (indicating no buffer could be mapped), or
778 * the parameter. URB_NO_TRANSFER_DMA_MAP and URB_NO_SETUP_DMA_MAP are 708 * the parameter. URB_NO_TRANSFER_DMA_MAP is
779 * added to urb->transfer_flags if the operation succeeds. If the device 709 * added to urb->transfer_flags if the operation succeeds. If the device
780 * is connected to this system through a non-DMA controller, this operation 710 * is connected to this system through a non-DMA controller, this operation
781 * always succeeds. 711 * always succeeds.
@@ -803,17 +733,11 @@ struct urb *usb_buffer_map(struct urb *urb)
803 urb->transfer_buffer, urb->transfer_buffer_length, 733 urb->transfer_buffer, urb->transfer_buffer_length,
804 usb_pipein(urb->pipe) 734 usb_pipein(urb->pipe)
805 ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 735 ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
806 if (usb_pipecontrol(urb->pipe))
807 urb->setup_dma = dma_map_single(controller,
808 urb->setup_packet,
809 sizeof(struct usb_ctrlrequest),
810 DMA_TO_DEVICE);
811 /* FIXME generic api broken like pci, can't report errors */ 736 /* FIXME generic api broken like pci, can't report errors */
812 /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */ 737 /* if (urb->transfer_dma == DMA_ADDR_INVALID) return 0; */
813 } else 738 } else
814 urb->transfer_dma = ~0; 739 urb->transfer_dma = ~0;
815 urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP 740 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
816 | URB_NO_SETUP_DMA_MAP);
817 return urb; 741 return urb;
818} 742}
819EXPORT_SYMBOL_GPL(usb_buffer_map); 743EXPORT_SYMBOL_GPL(usb_buffer_map);
@@ -881,18 +805,13 @@ void usb_buffer_unmap(struct urb *urb)
881 urb->transfer_dma, urb->transfer_buffer_length, 805 urb->transfer_dma, urb->transfer_buffer_length,
882 usb_pipein(urb->pipe) 806 usb_pipein(urb->pipe)
883 ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 807 ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
884 if (usb_pipecontrol(urb->pipe))
885 dma_unmap_single(controller,
886 urb->setup_dma,
887 sizeof(struct usb_ctrlrequest),
888 DMA_TO_DEVICE);
889 } 808 }
890 urb->transfer_flags &= ~(URB_NO_TRANSFER_DMA_MAP 809 urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP;
891 | URB_NO_SETUP_DMA_MAP);
892} 810}
893EXPORT_SYMBOL_GPL(usb_buffer_unmap); 811EXPORT_SYMBOL_GPL(usb_buffer_unmap);
894#endif /* 0 */ 812#endif /* 0 */
895 813
814#if 0
896/** 815/**
897 * usb_buffer_map_sg - create scatterlist DMA mapping(s) for an endpoint 816 * usb_buffer_map_sg - create scatterlist DMA mapping(s) for an endpoint
898 * @dev: device to which the scatterlist will be mapped 817 * @dev: device to which the scatterlist will be mapped
@@ -936,6 +855,7 @@ int usb_buffer_map_sg(const struct usb_device *dev, int is_in,
936 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE) ? : -ENOMEM; 855 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE) ? : -ENOMEM;
937} 856}
938EXPORT_SYMBOL_GPL(usb_buffer_map_sg); 857EXPORT_SYMBOL_GPL(usb_buffer_map_sg);
858#endif
939 859
940/* XXX DISABLED, no users currently. If you wish to re-enable this 860/* XXX DISABLED, no users currently. If you wish to re-enable this
941 * XXX please determine whether the sync is to transfer ownership of 861 * XXX please determine whether the sync is to transfer ownership of
@@ -972,6 +892,7 @@ void usb_buffer_dmasync_sg(const struct usb_device *dev, int is_in,
972EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg); 892EXPORT_SYMBOL_GPL(usb_buffer_dmasync_sg);
973#endif 893#endif
974 894
895#if 0
975/** 896/**
976 * usb_buffer_unmap_sg - free DMA mapping(s) for a scatterlist 897 * usb_buffer_unmap_sg - free DMA mapping(s) for a scatterlist
977 * @dev: device to which the scatterlist will be mapped 898 * @dev: device to which the scatterlist will be mapped
@@ -997,6 +918,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
997 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE); 918 is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
998} 919}
999EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg); 920EXPORT_SYMBOL_GPL(usb_buffer_unmap_sg);
921#endif
1000 922
1001/* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */ 923/* To disable USB, kernel command line is 'nousb' not 'usbcore.nousb' */
1002#ifdef MODULE 924#ifdef MODULE
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 11a3e0fa4331..649c0c5f7158 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -710,6 +710,43 @@ config USB_GADGETFS
710 Say "y" to link the driver statically, or "m" to build a 710 Say "y" to link the driver statically, or "m" to build a
711 dynamically linked module called "gadgetfs". 711 dynamically linked module called "gadgetfs".
712 712
713config USB_FUNCTIONFS
714 tristate "Function Filesystem (EXPERIMENTAL)"
715 depends on EXPERIMENTAL
716 help
717 The Function Filesystem (FunctioFS) lets one create USB
718 composite functions in user space in the same way as GadgetFS
719 lets one create USB gadgets in user space. This allows creation
720 of composite gadgets such that some of the functions are
721 implemented in kernel space (for instance Ethernet, serial or
722 mass storage) and other are implemented in user space.
723
724 Say "y" to link the driver statically, or "m" to build
725 a dynamically linked module called "g_ffs".
726
727config USB_FUNCTIONFS_ETH
728 bool "Include CDC ECM (Ethernet) function"
729 depends on USB_FUNCTIONFS && NET
730 help
731 Include an CDC ECM (Ethernet) funcion in the CDC ECM (Funcion)
732 Filesystem. If you also say "y" to the RNDIS query below the
733 gadget will have two configurations.
734
735config USB_FUNCTIONFS_RNDIS
736 bool "Include RNDIS (Ethernet) function"
737 depends on USB_FUNCTIONFS && NET
738 help
739 Include an RNDIS (Ethernet) funcion in the Funcion Filesystem.
740 If you also say "y" to the CDC ECM query above the gadget will
741 have two configurations.
742
743config USB_FUNCTIONFS_GENERIC
744 bool "Include 'pure' configuration"
745 depends on USB_FUNCTIONFS && (USB_FUNCTIONFS_ETH || USB_FUNCTIONFS_RNDIS)
746 help
747 Include a configuration with FunctionFS and no Ethernet
748 configuration.
749
713config USB_FILE_STORAGE 750config USB_FILE_STORAGE
714 tristate "File-backed Storage Gadget" 751 tristate "File-backed Storage Gadget"
715 depends on BLOCK 752 depends on BLOCK
@@ -863,11 +900,30 @@ config USB_G_MULTI_CDC
863 900
864 If unsure, say "y". 901 If unsure, say "y".
865 902
903config USB_G_HID
904 tristate "HID Gadget"
905 help
906 The HID gadget driver provides generic emulation of USB
907 Human Interface Devices (HID).
908
909 For more information, see Documentation/usb/gadget_hid.txt which
910 includes sample code for accessing the device files.
911
912 Say "y" to link the driver statically, or "m" to build a
913 dynamically linked module called "g_hid".
866 914
867# put drivers that need isochronous transfer support (for audio 915# put drivers that need isochronous transfer support (for audio
868# or video class gadget drivers), or specific hardware, here. 916# or video class gadget drivers), or specific hardware, here.
917config USB_G_WEBCAM
918 tristate "USB Webcam Gadget"
919 depends on VIDEO_DEV
920 help
921 The Webcam Gadget acts as a composite USB Audio and Video Class
922 device. It provides a userspace API to process UVC control requests
923 and stream video data to the host.
869 924
870# - none yet 925 Say "y" to link the driver statically, or "m" to build a
926 dynamically linked module called "g_webcam".
871 927
872endchoice 928endchoice
873 929
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 43b51da8d727..9bcde110feb1 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -20,7 +20,7 @@ obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o
20obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o 20obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o
21fsl_usb2_udc-objs := fsl_udc_core.o 21fsl_usb2_udc-objs := fsl_udc_core.o
22ifeq ($(CONFIG_ARCH_MXC),y) 22ifeq ($(CONFIG_ARCH_MXC),y)
23fsl_usb2_udc-objs += fsl_mx3_udc.o 23fsl_usb2_udc-objs += fsl_mxc_udc.o
24endif 24endif
25obj-$(CONFIG_USB_M66592) += m66592-udc.o 25obj-$(CONFIG_USB_M66592) += m66592-udc.o
26obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o 26obj-$(CONFIG_USB_R8A66597) += r8a66597-udc.o
@@ -43,18 +43,24 @@ g_mass_storage-objs := mass_storage.o
43g_printer-objs := printer.o 43g_printer-objs := printer.o
44g_cdc-objs := cdc2.o 44g_cdc-objs := cdc2.o
45g_multi-objs := multi.o 45g_multi-objs := multi.o
46g_hid-objs := hid.o
46g_nokia-objs := nokia.o 47g_nokia-objs := nokia.o
48g_webcam-objs := webcam.o
47 49
48obj-$(CONFIG_USB_ZERO) += g_zero.o 50obj-$(CONFIG_USB_ZERO) += g_zero.o
49obj-$(CONFIG_USB_AUDIO) += g_audio.o 51obj-$(CONFIG_USB_AUDIO) += g_audio.o
50obj-$(CONFIG_USB_ETH) += g_ether.o 52obj-$(CONFIG_USB_ETH) += g_ether.o
51obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 53obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
54obj-$(CONFIG_USB_FUNCTIONFS) += g_ffs.o
55obj-$(CONFIG_USB_ETH_FUNCTIONFS) += g_eth_ffs.o
52obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 56obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
53obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o 57obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o
54obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 58obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
55obj-$(CONFIG_USB_G_PRINTER) += g_printer.o 59obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
56obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 60obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
57obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o 61obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
62obj-$(CONFIG_USB_G_HID) += g_hid.o
58obj-$(CONFIG_USB_G_MULTI) += g_multi.o 63obj-$(CONFIG_USB_G_MULTI) += g_multi.o
59obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o 64obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
65obj-$(CONFIG_USB_G_WEBCAM) += g_webcam.o
60 66
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 75a256f3d45b..d623c7bda1f6 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -48,10 +48,9 @@ static int queue_dbg_open(struct inode *inode, struct file *file)
48 48
49 spin_lock_irq(&ep->udc->lock); 49 spin_lock_irq(&ep->udc->lock);
50 list_for_each_entry(req, &ep->queue, queue) { 50 list_for_each_entry(req, &ep->queue, queue) {
51 req_copy = kmalloc(sizeof(*req_copy), GFP_ATOMIC); 51 req_copy = kmemdup(req, sizeof(*req_copy), GFP_ATOMIC);
52 if (!req_copy) 52 if (!req_copy)
53 goto fail; 53 goto fail;
54 memcpy(req_copy, req, sizeof(*req_copy));
55 list_add_tail(&req_copy->queue, queue_data); 54 list_add_tail(&req_copy->queue, queue_data);
56 } 55 }
57 spin_unlock_irq(&ep->udc->lock); 56 spin_unlock_irq(&ep->udc->lock);
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 09289bb1e20f..391d169f8d07 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38/* big enough to hold our biggest descriptor */ 38/* big enough to hold our biggest descriptor */
39#define USB_BUFSIZ 512 39#define USB_BUFSIZ 1024
40 40
41static struct usb_composite_driver *composite; 41static struct usb_composite_driver *composite;
42 42
@@ -85,7 +85,7 @@ MODULE_PARM_DESC(iSerialNumber, "SerialNumber string");
85 * This function returns the value of the function's bind(), which is 85 * This function returns the value of the function's bind(), which is
86 * zero for success else a negative errno value. 86 * zero for success else a negative errno value.
87 */ 87 */
88int __init usb_add_function(struct usb_configuration *config, 88int usb_add_function(struct usb_configuration *config,
89 struct usb_function *function) 89 struct usb_function *function)
90{ 90{
91 int value = -EINVAL; 91 int value = -EINVAL;
@@ -215,7 +215,7 @@ int usb_function_activate(struct usb_function *function)
215 * Returns the interface ID which was allocated; or -ENODEV if no 215 * Returns the interface ID which was allocated; or -ENODEV if no
216 * more interface IDs can be allocated. 216 * more interface IDs can be allocated.
217 */ 217 */
218int __init usb_interface_id(struct usb_configuration *config, 218int usb_interface_id(struct usb_configuration *config,
219 struct usb_function *function) 219 struct usb_function *function)
220{ 220{
221 unsigned id = config->next_interface_id; 221 unsigned id = config->next_interface_id;
@@ -480,7 +480,7 @@ done:
480 * assigns global resources including string IDs, and per-configuration 480 * assigns global resources including string IDs, and per-configuration
481 * resources such as interface IDs and endpoints. 481 * resources such as interface IDs and endpoints.
482 */ 482 */
483int __init usb_add_config(struct usb_composite_dev *cdev, 483int usb_add_config(struct usb_composite_dev *cdev,
484 struct usb_configuration *config) 484 struct usb_configuration *config)
485{ 485{
486 int status = -EINVAL; 486 int status = -EINVAL;
@@ -677,7 +677,7 @@ static int get_string(struct usb_composite_dev *cdev,
677 * ensure that for example different functions don't wrongly assign 677 * ensure that for example different functions don't wrongly assign
678 * different meanings to the same identifier. 678 * different meanings to the same identifier.
679 */ 679 */
680int __init usb_string_id(struct usb_composite_dev *cdev) 680int usb_string_id(struct usb_composite_dev *cdev)
681{ 681{
682 if (cdev->next_string_id < 254) { 682 if (cdev->next_string_id < 254) {
683 /* string id 0 is reserved */ 683 /* string id 0 is reserved */
@@ -898,7 +898,19 @@ static void composite_disconnect(struct usb_gadget *gadget)
898 898
899/*-------------------------------------------------------------------------*/ 899/*-------------------------------------------------------------------------*/
900 900
901static void /* __init_or_exit */ 901static ssize_t composite_show_suspended(struct device *dev,
902 struct device_attribute *attr,
903 char *buf)
904{
905 struct usb_gadget *gadget = dev_to_usb_gadget(dev);
906 struct usb_composite_dev *cdev = get_gadget_data(gadget);
907
908 return sprintf(buf, "%d\n", cdev->suspended);
909}
910
911static DEVICE_ATTR(suspended, 0444, composite_show_suspended, NULL);
912
913static void
902composite_unbind(struct usb_gadget *gadget) 914composite_unbind(struct usb_gadget *gadget)
903{ 915{
904 struct usb_composite_dev *cdev = get_gadget_data(gadget); 916 struct usb_composite_dev *cdev = get_gadget_data(gadget);
@@ -944,10 +956,11 @@ composite_unbind(struct usb_gadget *gadget)
944 } 956 }
945 kfree(cdev); 957 kfree(cdev);
946 set_gadget_data(gadget, NULL); 958 set_gadget_data(gadget, NULL);
959 device_remove_file(&gadget->dev, &dev_attr_suspended);
947 composite = NULL; 960 composite = NULL;
948} 961}
949 962
950static void __init 963static void
951string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s) 964string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
952{ 965{
953 struct usb_string *str = tab->strings; 966 struct usb_string *str = tab->strings;
@@ -960,7 +973,7 @@ string_override_one(struct usb_gadget_strings *tab, u8 id, const char *s)
960 } 973 }
961} 974}
962 975
963static void __init 976static void
964string_override(struct usb_gadget_strings **tab, u8 id, const char *s) 977string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
965{ 978{
966 while (*tab) { 979 while (*tab) {
@@ -969,7 +982,7 @@ string_override(struct usb_gadget_strings **tab, u8 id, const char *s)
969 } 982 }
970} 983}
971 984
972static int __init composite_bind(struct usb_gadget *gadget) 985static int composite_bind(struct usb_gadget *gadget)
973{ 986{
974 struct usb_composite_dev *cdev; 987 struct usb_composite_dev *cdev;
975 int status = -ENOMEM; 988 int status = -ENOMEM;
@@ -1004,6 +1017,14 @@ static int __init composite_bind(struct usb_gadget *gadget)
1004 */ 1017 */
1005 usb_ep_autoconfig_reset(cdev->gadget); 1018 usb_ep_autoconfig_reset(cdev->gadget);
1006 1019
1020 /* standardized runtime overrides for device ID data */
1021 if (idVendor)
1022 cdev->desc.idVendor = cpu_to_le16(idVendor);
1023 if (idProduct)
1024 cdev->desc.idProduct = cpu_to_le16(idProduct);
1025 if (bcdDevice)
1026 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1027
1007 /* composite gadget needs to assign strings for whole device (like 1028 /* composite gadget needs to assign strings for whole device (like
1008 * serial number), register function drivers, potentially update 1029 * serial number), register function drivers, potentially update
1009 * power state and consumption, etc 1030 * power state and consumption, etc
@@ -1015,14 +1036,6 @@ static int __init composite_bind(struct usb_gadget *gadget)
1015 cdev->desc = *composite->dev; 1036 cdev->desc = *composite->dev;
1016 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket; 1037 cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
1017 1038
1018 /* standardized runtime overrides for device ID data */
1019 if (idVendor)
1020 cdev->desc.idVendor = cpu_to_le16(idVendor);
1021 if (idProduct)
1022 cdev->desc.idProduct = cpu_to_le16(idProduct);
1023 if (bcdDevice)
1024 cdev->desc.bcdDevice = cpu_to_le16(bcdDevice);
1025
1026 /* strings can't be assigned before bind() allocates the 1039 /* strings can't be assigned before bind() allocates the
1027 * releavnt identifiers 1040 * releavnt identifiers
1028 */ 1041 */
@@ -1036,6 +1049,10 @@ static int __init composite_bind(struct usb_gadget *gadget)
1036 string_override(composite->strings, 1049 string_override(composite->strings,
1037 cdev->desc.iSerialNumber, iSerialNumber); 1050 cdev->desc.iSerialNumber, iSerialNumber);
1038 1051
1052 status = device_create_file(&gadget->dev, &dev_attr_suspended);
1053 if (status)
1054 goto fail;
1055
1039 INFO(cdev, "%s ready\n", composite->name); 1056 INFO(cdev, "%s ready\n", composite->name);
1040 return 0; 1057 return 0;
1041 1058
@@ -1064,6 +1081,8 @@ composite_suspend(struct usb_gadget *gadget)
1064 } 1081 }
1065 if (composite->suspend) 1082 if (composite->suspend)
1066 composite->suspend(cdev); 1083 composite->suspend(cdev);
1084
1085 cdev->suspended = 1;
1067} 1086}
1068 1087
1069static void 1088static void
@@ -1084,6 +1103,8 @@ composite_resume(struct usb_gadget *gadget)
1084 f->resume(f); 1103 f->resume(f);
1085 } 1104 }
1086 } 1105 }
1106
1107 cdev->suspended = 0;
1087} 1108}
1088 1109
1089/*-------------------------------------------------------------------------*/ 1110/*-------------------------------------------------------------------------*/
@@ -1092,7 +1113,6 @@ static struct usb_gadget_driver composite_driver = {
1092 .speed = USB_SPEED_HIGH, 1113 .speed = USB_SPEED_HIGH,
1093 1114
1094 .bind = composite_bind, 1115 .bind = composite_bind,
1095 /* .unbind = __exit_p(composite_unbind), */
1096 .unbind = composite_unbind, 1116 .unbind = composite_unbind,
1097 1117
1098 .setup = composite_setup, 1118 .setup = composite_setup,
@@ -1121,7 +1141,7 @@ static struct usb_gadget_driver composite_driver = {
1121 * while it was binding. That would usually be done in order to wait for 1141 * while it was binding. That would usually be done in order to wait for
1122 * some userspace participation. 1142 * some userspace participation.
1123 */ 1143 */
1124int __init usb_composite_register(struct usb_composite_driver *driver) 1144int usb_composite_register(struct usb_composite_driver *driver)
1125{ 1145{
1126 if (!driver || !driver->dev || !driver->bind || composite) 1146 if (!driver || !driver->dev || !driver->bind || composite)
1127 return -EINVAL; 1147 return -EINVAL;
@@ -1142,7 +1162,7 @@ int __init usb_composite_register(struct usb_composite_driver *driver)
1142 * This function is used to unregister drivers using the composite 1162 * This function is used to unregister drivers using the composite
1143 * driver framework. 1163 * driver framework.
1144 */ 1164 */
1145void /* __exit */ usb_composite_unregister(struct usb_composite_driver *driver) 1165void usb_composite_unregister(struct usb_composite_driver *driver)
1146{ 1166{
1147 if (composite != driver) 1167 if (composite != driver)
1148 return; 1168 return;
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index 47e8e722682c..09084fd646ab 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -128,7 +128,7 @@ int usb_gadget_config_buf(
128 * with identifiers (for interfaces, strings, endpoints, and more) 128 * with identifiers (for interfaces, strings, endpoints, and more)
129 * as needed by a given function instance. 129 * as needed by a given function instance.
130 */ 130 */
131struct usb_descriptor_header **__init 131struct usb_descriptor_header **
132usb_copy_descriptors(struct usb_descriptor_header **src) 132usb_copy_descriptors(struct usb_descriptor_header **src)
133{ 133{
134 struct usb_descriptor_header **tmp; 134 struct usb_descriptor_header **tmp;
@@ -175,7 +175,7 @@ usb_copy_descriptors(struct usb_descriptor_header **src)
175 * intended use is to help remembering the endpoint descriptor to use 175 * intended use is to help remembering the endpoint descriptor to use
176 * when enabling a given endpoint. 176 * when enabling a given endpoint.
177 */ 177 */
178struct usb_endpoint_descriptor *__init 178struct usb_endpoint_descriptor *
179usb_find_endpoint( 179usb_find_endpoint(
180 struct usb_descriptor_header **src, 180 struct usb_descriptor_header **src,
181 struct usb_descriptor_header **copy, 181 struct usb_descriptor_header **copy,
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 5e0966485188..4f9e578cde9d 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -47,6 +47,7 @@
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/usb.h> 48#include <linux/usb.h>
49#include <linux/usb/gadget.h> 49#include <linux/usb/gadget.h>
50#include <linux/usb/hcd.h>
50 51
51#include <asm/byteorder.h> 52#include <asm/byteorder.h>
52#include <asm/io.h> 53#include <asm/io.h>
@@ -55,9 +56,6 @@
55#include <asm/unaligned.h> 56#include <asm/unaligned.h>
56 57
57 58
58#include "../core/hcd.h"
59
60
61#define DRIVER_DESC "USB Host+Gadget Emulator" 59#define DRIVER_DESC "USB Host+Gadget Emulator"
62#define DRIVER_VERSION "02 May 2005" 60#define DRIVER_VERSION "02 May 2005"
63 61
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index 3568de210f79..8a832488ccdd 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -34,12 +34,12 @@
34 34
35 35
36/* we must assign addresses for configurable endpoints (like net2280) */ 36/* we must assign addresses for configurable endpoints (like net2280) */
37static __initdata unsigned epnum; 37static unsigned epnum;
38 38
39// #define MANY_ENDPOINTS 39// #define MANY_ENDPOINTS
40#ifdef MANY_ENDPOINTS 40#ifdef MANY_ENDPOINTS
41/* more than 15 configurable endpoints */ 41/* more than 15 configurable endpoints */
42static __initdata unsigned in_epnum; 42static unsigned in_epnum;
43#endif 43#endif
44 44
45 45
@@ -59,7 +59,7 @@ static __initdata unsigned in_epnum;
59 * NOTE: each endpoint is unidirectional, as specified by its USB 59 * NOTE: each endpoint is unidirectional, as specified by its USB
60 * descriptor; and isn't specific to a configuration or altsetting. 60 * descriptor; and isn't specific to a configuration or altsetting.
61 */ 61 */
62static int __init 62static int
63ep_matches ( 63ep_matches (
64 struct usb_gadget *gadget, 64 struct usb_gadget *gadget,
65 struct usb_ep *ep, 65 struct usb_ep *ep,
@@ -187,7 +187,7 @@ ep_matches (
187 return 1; 187 return 1;
188} 188}
189 189
190static struct usb_ep * __init 190static struct usb_ep *
191find_ep (struct usb_gadget *gadget, const char *name) 191find_ep (struct usb_gadget *gadget, const char *name)
192{ 192{
193 struct usb_ep *ep; 193 struct usb_ep *ep;
@@ -229,7 +229,7 @@ find_ep (struct usb_gadget *gadget, const char *name)
229 * 229 *
230 * On failure, this returns a null endpoint descriptor. 230 * On failure, this returns a null endpoint descriptor.
231 */ 231 */
232struct usb_ep * __init usb_ep_autoconfig ( 232struct usb_ep *usb_ep_autoconfig (
233 struct usb_gadget *gadget, 233 struct usb_gadget *gadget,
234 struct usb_endpoint_descriptor *desc 234 struct usb_endpoint_descriptor *desc
235) 235)
@@ -304,7 +304,7 @@ struct usb_ep * __init usb_ep_autoconfig (
304 * state such as ep->driver_data and the record of assigned endpoints 304 * state such as ep->driver_data and the record of assigned endpoints
305 * used by usb_ep_autoconfig(). 305 * used by usb_ep_autoconfig().
306 */ 306 */
307void __init usb_ep_autoconfig_reset (struct usb_gadget *gadget) 307void usb_ep_autoconfig_reset (struct usb_gadget *gadget)
308{ 308{
309 struct usb_ep *ep; 309 struct usb_ep *ep;
310 310
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 400e1ebe6976..d47a123f15ab 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -116,7 +116,7 @@ acm_iad_descriptor = {
116}; 116};
117 117
118 118
119static struct usb_interface_descriptor acm_control_interface_desc __initdata = { 119static struct usb_interface_descriptor acm_control_interface_desc = {
120 .bLength = USB_DT_INTERFACE_SIZE, 120 .bLength = USB_DT_INTERFACE_SIZE,
121 .bDescriptorType = USB_DT_INTERFACE, 121 .bDescriptorType = USB_DT_INTERFACE,
122 /* .bInterfaceNumber = DYNAMIC */ 122 /* .bInterfaceNumber = DYNAMIC */
@@ -127,7 +127,7 @@ static struct usb_interface_descriptor acm_control_interface_desc __initdata = {
127 /* .iInterface = DYNAMIC */ 127 /* .iInterface = DYNAMIC */
128}; 128};
129 129
130static struct usb_interface_descriptor acm_data_interface_desc __initdata = { 130static struct usb_interface_descriptor acm_data_interface_desc = {
131 .bLength = USB_DT_INTERFACE_SIZE, 131 .bLength = USB_DT_INTERFACE_SIZE,
132 .bDescriptorType = USB_DT_INTERFACE, 132 .bDescriptorType = USB_DT_INTERFACE,
133 /* .bInterfaceNumber = DYNAMIC */ 133 /* .bInterfaceNumber = DYNAMIC */
@@ -138,7 +138,7 @@ static struct usb_interface_descriptor acm_data_interface_desc __initdata = {
138 /* .iInterface = DYNAMIC */ 138 /* .iInterface = DYNAMIC */
139}; 139};
140 140
141static struct usb_cdc_header_desc acm_header_desc __initdata = { 141static struct usb_cdc_header_desc acm_header_desc = {
142 .bLength = sizeof(acm_header_desc), 142 .bLength = sizeof(acm_header_desc),
143 .bDescriptorType = USB_DT_CS_INTERFACE, 143 .bDescriptorType = USB_DT_CS_INTERFACE,
144 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 144 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
@@ -146,7 +146,7 @@ static struct usb_cdc_header_desc acm_header_desc __initdata = {
146}; 146};
147 147
148static struct usb_cdc_call_mgmt_descriptor 148static struct usb_cdc_call_mgmt_descriptor
149acm_call_mgmt_descriptor __initdata = { 149acm_call_mgmt_descriptor = {
150 .bLength = sizeof(acm_call_mgmt_descriptor), 150 .bLength = sizeof(acm_call_mgmt_descriptor),
151 .bDescriptorType = USB_DT_CS_INTERFACE, 151 .bDescriptorType = USB_DT_CS_INTERFACE,
152 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE, 152 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
@@ -154,14 +154,14 @@ acm_call_mgmt_descriptor __initdata = {
154 /* .bDataInterface = DYNAMIC */ 154 /* .bDataInterface = DYNAMIC */
155}; 155};
156 156
157static struct usb_cdc_acm_descriptor acm_descriptor __initdata = { 157static struct usb_cdc_acm_descriptor acm_descriptor = {
158 .bLength = sizeof(acm_descriptor), 158 .bLength = sizeof(acm_descriptor),
159 .bDescriptorType = USB_DT_CS_INTERFACE, 159 .bDescriptorType = USB_DT_CS_INTERFACE,
160 .bDescriptorSubType = USB_CDC_ACM_TYPE, 160 .bDescriptorSubType = USB_CDC_ACM_TYPE,
161 .bmCapabilities = USB_CDC_CAP_LINE, 161 .bmCapabilities = USB_CDC_CAP_LINE,
162}; 162};
163 163
164static struct usb_cdc_union_desc acm_union_desc __initdata = { 164static struct usb_cdc_union_desc acm_union_desc = {
165 .bLength = sizeof(acm_union_desc), 165 .bLength = sizeof(acm_union_desc),
166 .bDescriptorType = USB_DT_CS_INTERFACE, 166 .bDescriptorType = USB_DT_CS_INTERFACE,
167 .bDescriptorSubType = USB_CDC_UNION_TYPE, 167 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -171,7 +171,7 @@ static struct usb_cdc_union_desc acm_union_desc __initdata = {
171 171
172/* full speed support: */ 172/* full speed support: */
173 173
174static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = { 174static struct usb_endpoint_descriptor acm_fs_notify_desc = {
175 .bLength = USB_DT_ENDPOINT_SIZE, 175 .bLength = USB_DT_ENDPOINT_SIZE,
176 .bDescriptorType = USB_DT_ENDPOINT, 176 .bDescriptorType = USB_DT_ENDPOINT,
177 .bEndpointAddress = USB_DIR_IN, 177 .bEndpointAddress = USB_DIR_IN,
@@ -180,21 +180,21 @@ static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
180 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL, 180 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
181}; 181};
182 182
183static struct usb_endpoint_descriptor acm_fs_in_desc __initdata = { 183static struct usb_endpoint_descriptor acm_fs_in_desc = {
184 .bLength = USB_DT_ENDPOINT_SIZE, 184 .bLength = USB_DT_ENDPOINT_SIZE,
185 .bDescriptorType = USB_DT_ENDPOINT, 185 .bDescriptorType = USB_DT_ENDPOINT,
186 .bEndpointAddress = USB_DIR_IN, 186 .bEndpointAddress = USB_DIR_IN,
187 .bmAttributes = USB_ENDPOINT_XFER_BULK, 187 .bmAttributes = USB_ENDPOINT_XFER_BULK,
188}; 188};
189 189
190static struct usb_endpoint_descriptor acm_fs_out_desc __initdata = { 190static struct usb_endpoint_descriptor acm_fs_out_desc = {
191 .bLength = USB_DT_ENDPOINT_SIZE, 191 .bLength = USB_DT_ENDPOINT_SIZE,
192 .bDescriptorType = USB_DT_ENDPOINT, 192 .bDescriptorType = USB_DT_ENDPOINT,
193 .bEndpointAddress = USB_DIR_OUT, 193 .bEndpointAddress = USB_DIR_OUT,
194 .bmAttributes = USB_ENDPOINT_XFER_BULK, 194 .bmAttributes = USB_ENDPOINT_XFER_BULK,
195}; 195};
196 196
197static struct usb_descriptor_header *acm_fs_function[] __initdata = { 197static struct usb_descriptor_header *acm_fs_function[] = {
198 (struct usb_descriptor_header *) &acm_iad_descriptor, 198 (struct usb_descriptor_header *) &acm_iad_descriptor,
199 (struct usb_descriptor_header *) &acm_control_interface_desc, 199 (struct usb_descriptor_header *) &acm_control_interface_desc,
200 (struct usb_descriptor_header *) &acm_header_desc, 200 (struct usb_descriptor_header *) &acm_header_desc,
@@ -210,7 +210,7 @@ static struct usb_descriptor_header *acm_fs_function[] __initdata = {
210 210
211/* high speed support: */ 211/* high speed support: */
212 212
213static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = { 213static struct usb_endpoint_descriptor acm_hs_notify_desc = {
214 .bLength = USB_DT_ENDPOINT_SIZE, 214 .bLength = USB_DT_ENDPOINT_SIZE,
215 .bDescriptorType = USB_DT_ENDPOINT, 215 .bDescriptorType = USB_DT_ENDPOINT,
216 .bEndpointAddress = USB_DIR_IN, 216 .bEndpointAddress = USB_DIR_IN,
@@ -219,21 +219,21 @@ static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
219 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4, 219 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
220}; 220};
221 221
222static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = { 222static struct usb_endpoint_descriptor acm_hs_in_desc = {
223 .bLength = USB_DT_ENDPOINT_SIZE, 223 .bLength = USB_DT_ENDPOINT_SIZE,
224 .bDescriptorType = USB_DT_ENDPOINT, 224 .bDescriptorType = USB_DT_ENDPOINT,
225 .bmAttributes = USB_ENDPOINT_XFER_BULK, 225 .bmAttributes = USB_ENDPOINT_XFER_BULK,
226 .wMaxPacketSize = cpu_to_le16(512), 226 .wMaxPacketSize = cpu_to_le16(512),
227}; 227};
228 228
229static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = { 229static struct usb_endpoint_descriptor acm_hs_out_desc = {
230 .bLength = USB_DT_ENDPOINT_SIZE, 230 .bLength = USB_DT_ENDPOINT_SIZE,
231 .bDescriptorType = USB_DT_ENDPOINT, 231 .bDescriptorType = USB_DT_ENDPOINT,
232 .bmAttributes = USB_ENDPOINT_XFER_BULK, 232 .bmAttributes = USB_ENDPOINT_XFER_BULK,
233 .wMaxPacketSize = cpu_to_le16(512), 233 .wMaxPacketSize = cpu_to_le16(512),
234}; 234};
235 235
236static struct usb_descriptor_header *acm_hs_function[] __initdata = { 236static struct usb_descriptor_header *acm_hs_function[] = {
237 (struct usb_descriptor_header *) &acm_iad_descriptor, 237 (struct usb_descriptor_header *) &acm_iad_descriptor,
238 (struct usb_descriptor_header *) &acm_control_interface_desc, 238 (struct usb_descriptor_header *) &acm_control_interface_desc,
239 (struct usb_descriptor_header *) &acm_header_desc, 239 (struct usb_descriptor_header *) &acm_header_desc,
@@ -571,7 +571,7 @@ static int acm_send_break(struct gserial *port, int duration)
571/*-------------------------------------------------------------------------*/ 571/*-------------------------------------------------------------------------*/
572 572
573/* ACM function driver setup/binding */ 573/* ACM function driver setup/binding */
574static int __init 574static int
575acm_bind(struct usb_configuration *c, struct usb_function *f) 575acm_bind(struct usb_configuration *c, struct usb_function *f)
576{ 576{
577 struct usb_composite_dev *cdev = c->cdev; 577 struct usb_composite_dev *cdev = c->cdev;
@@ -719,7 +719,7 @@ static inline bool can_support_cdc(struct usb_configuration *c)
719 * handle all the ones it binds. Caller is also responsible 719 * handle all the ones it binds. Caller is also responsible
720 * for calling @gserial_cleanup() before module unload. 720 * for calling @gserial_cleanup() before module unload.
721 */ 721 */
722int __init acm_bind_config(struct usb_configuration *c, u8 port_num) 722int acm_bind_config(struct usb_configuration *c, u8 port_num)
723{ 723{
724 struct f_acm *acm; 724 struct f_acm *acm;
725 int status; 725 int status;
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 4e595324c614..544257a89ed2 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -113,7 +113,7 @@ static inline unsigned ecm_bitrate(struct usb_gadget *g)
113 113
114/* interface descriptor: */ 114/* interface descriptor: */
115 115
116static struct usb_interface_descriptor ecm_control_intf __initdata = { 116static struct usb_interface_descriptor ecm_control_intf = {
117 .bLength = sizeof ecm_control_intf, 117 .bLength = sizeof ecm_control_intf,
118 .bDescriptorType = USB_DT_INTERFACE, 118 .bDescriptorType = USB_DT_INTERFACE,
119 119
@@ -126,7 +126,7 @@ static struct usb_interface_descriptor ecm_control_intf __initdata = {
126 /* .iInterface = DYNAMIC */ 126 /* .iInterface = DYNAMIC */
127}; 127};
128 128
129static struct usb_cdc_header_desc ecm_header_desc __initdata = { 129static struct usb_cdc_header_desc ecm_header_desc = {
130 .bLength = sizeof ecm_header_desc, 130 .bLength = sizeof ecm_header_desc,
131 .bDescriptorType = USB_DT_CS_INTERFACE, 131 .bDescriptorType = USB_DT_CS_INTERFACE,
132 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 132 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
@@ -134,7 +134,7 @@ static struct usb_cdc_header_desc ecm_header_desc __initdata = {
134 .bcdCDC = cpu_to_le16(0x0110), 134 .bcdCDC = cpu_to_le16(0x0110),
135}; 135};
136 136
137static struct usb_cdc_union_desc ecm_union_desc __initdata = { 137static struct usb_cdc_union_desc ecm_union_desc = {
138 .bLength = sizeof(ecm_union_desc), 138 .bLength = sizeof(ecm_union_desc),
139 .bDescriptorType = USB_DT_CS_INTERFACE, 139 .bDescriptorType = USB_DT_CS_INTERFACE,
140 .bDescriptorSubType = USB_CDC_UNION_TYPE, 140 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -142,7 +142,7 @@ static struct usb_cdc_union_desc ecm_union_desc __initdata = {
142 /* .bSlaveInterface0 = DYNAMIC */ 142 /* .bSlaveInterface0 = DYNAMIC */
143}; 143};
144 144
145static struct usb_cdc_ether_desc ecm_desc __initdata = { 145static struct usb_cdc_ether_desc ecm_desc = {
146 .bLength = sizeof ecm_desc, 146 .bLength = sizeof ecm_desc,
147 .bDescriptorType = USB_DT_CS_INTERFACE, 147 .bDescriptorType = USB_DT_CS_INTERFACE,
148 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, 148 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
@@ -157,7 +157,7 @@ static struct usb_cdc_ether_desc ecm_desc __initdata = {
157 157
158/* the default data interface has no endpoints ... */ 158/* the default data interface has no endpoints ... */
159 159
160static struct usb_interface_descriptor ecm_data_nop_intf __initdata = { 160static struct usb_interface_descriptor ecm_data_nop_intf = {
161 .bLength = sizeof ecm_data_nop_intf, 161 .bLength = sizeof ecm_data_nop_intf,
162 .bDescriptorType = USB_DT_INTERFACE, 162 .bDescriptorType = USB_DT_INTERFACE,
163 163
@@ -172,7 +172,7 @@ static struct usb_interface_descriptor ecm_data_nop_intf __initdata = {
172 172
173/* ... but the "real" data interface has two bulk endpoints */ 173/* ... but the "real" data interface has two bulk endpoints */
174 174
175static struct usb_interface_descriptor ecm_data_intf __initdata = { 175static struct usb_interface_descriptor ecm_data_intf = {
176 .bLength = sizeof ecm_data_intf, 176 .bLength = sizeof ecm_data_intf,
177 .bDescriptorType = USB_DT_INTERFACE, 177 .bDescriptorType = USB_DT_INTERFACE,
178 178
@@ -187,7 +187,7 @@ static struct usb_interface_descriptor ecm_data_intf __initdata = {
187 187
188/* full speed support: */ 188/* full speed support: */
189 189
190static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = { 190static struct usb_endpoint_descriptor fs_ecm_notify_desc = {
191 .bLength = USB_DT_ENDPOINT_SIZE, 191 .bLength = USB_DT_ENDPOINT_SIZE,
192 .bDescriptorType = USB_DT_ENDPOINT, 192 .bDescriptorType = USB_DT_ENDPOINT,
193 193
@@ -197,7 +197,7 @@ static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = {
197 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 197 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
198}; 198};
199 199
200static struct usb_endpoint_descriptor fs_ecm_in_desc __initdata = { 200static struct usb_endpoint_descriptor fs_ecm_in_desc = {
201 .bLength = USB_DT_ENDPOINT_SIZE, 201 .bLength = USB_DT_ENDPOINT_SIZE,
202 .bDescriptorType = USB_DT_ENDPOINT, 202 .bDescriptorType = USB_DT_ENDPOINT,
203 203
@@ -205,7 +205,7 @@ static struct usb_endpoint_descriptor fs_ecm_in_desc __initdata = {
205 .bmAttributes = USB_ENDPOINT_XFER_BULK, 205 .bmAttributes = USB_ENDPOINT_XFER_BULK,
206}; 206};
207 207
208static struct usb_endpoint_descriptor fs_ecm_out_desc __initdata = { 208static struct usb_endpoint_descriptor fs_ecm_out_desc = {
209 .bLength = USB_DT_ENDPOINT_SIZE, 209 .bLength = USB_DT_ENDPOINT_SIZE,
210 .bDescriptorType = USB_DT_ENDPOINT, 210 .bDescriptorType = USB_DT_ENDPOINT,
211 211
@@ -213,7 +213,7 @@ static struct usb_endpoint_descriptor fs_ecm_out_desc __initdata = {
213 .bmAttributes = USB_ENDPOINT_XFER_BULK, 213 .bmAttributes = USB_ENDPOINT_XFER_BULK,
214}; 214};
215 215
216static struct usb_descriptor_header *ecm_fs_function[] __initdata = { 216static struct usb_descriptor_header *ecm_fs_function[] = {
217 /* CDC ECM control descriptors */ 217 /* CDC ECM control descriptors */
218 (struct usb_descriptor_header *) &ecm_control_intf, 218 (struct usb_descriptor_header *) &ecm_control_intf,
219 (struct usb_descriptor_header *) &ecm_header_desc, 219 (struct usb_descriptor_header *) &ecm_header_desc,
@@ -231,7 +231,7 @@ static struct usb_descriptor_header *ecm_fs_function[] __initdata = {
231 231
232/* high speed support: */ 232/* high speed support: */
233 233
234static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = { 234static struct usb_endpoint_descriptor hs_ecm_notify_desc = {
235 .bLength = USB_DT_ENDPOINT_SIZE, 235 .bLength = USB_DT_ENDPOINT_SIZE,
236 .bDescriptorType = USB_DT_ENDPOINT, 236 .bDescriptorType = USB_DT_ENDPOINT,
237 237
@@ -240,7 +240,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = {
240 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT), 240 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
241 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 241 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
242}; 242};
243static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = { 243static struct usb_endpoint_descriptor hs_ecm_in_desc = {
244 .bLength = USB_DT_ENDPOINT_SIZE, 244 .bLength = USB_DT_ENDPOINT_SIZE,
245 .bDescriptorType = USB_DT_ENDPOINT, 245 .bDescriptorType = USB_DT_ENDPOINT,
246 246
@@ -249,7 +249,7 @@ static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
249 .wMaxPacketSize = cpu_to_le16(512), 249 .wMaxPacketSize = cpu_to_le16(512),
250}; 250};
251 251
252static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = { 252static struct usb_endpoint_descriptor hs_ecm_out_desc = {
253 .bLength = USB_DT_ENDPOINT_SIZE, 253 .bLength = USB_DT_ENDPOINT_SIZE,
254 .bDescriptorType = USB_DT_ENDPOINT, 254 .bDescriptorType = USB_DT_ENDPOINT,
255 255
@@ -258,7 +258,7 @@ static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
258 .wMaxPacketSize = cpu_to_le16(512), 258 .wMaxPacketSize = cpu_to_le16(512),
259}; 259};
260 260
261static struct usb_descriptor_header *ecm_hs_function[] __initdata = { 261static struct usb_descriptor_header *ecm_hs_function[] = {
262 /* CDC ECM control descriptors */ 262 /* CDC ECM control descriptors */
263 (struct usb_descriptor_header *) &ecm_control_intf, 263 (struct usb_descriptor_header *) &ecm_control_intf,
264 (struct usb_descriptor_header *) &ecm_header_desc, 264 (struct usb_descriptor_header *) &ecm_header_desc,
@@ -597,7 +597,7 @@ static void ecm_close(struct gether *geth)
597 597
598/* ethernet function driver setup/binding */ 598/* ethernet function driver setup/binding */
599 599
600static int __init 600static int
601ecm_bind(struct usb_configuration *c, struct usb_function *f) 601ecm_bind(struct usb_configuration *c, struct usb_function *f)
602{ 602{
603 struct usb_composite_dev *cdev = c->cdev; 603 struct usb_composite_dev *cdev = c->cdev;
@@ -763,7 +763,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
763 * Caller must have called @gether_setup(). Caller is also responsible 763 * Caller must have called @gether_setup(). Caller is also responsible
764 * for calling @gether_cleanup() before module unload. 764 * for calling @gether_cleanup() before module unload.
765 */ 765 */
766int __init ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 766int
767ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
767{ 768{
768 struct f_ecm *ecm; 769 struct f_ecm *ecm;
769 int status; 770 int status;
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
new file mode 100644
index 000000000000..d69eccf5f197
--- /dev/null
+++ b/drivers/usb/gadget/f_fs.c
@@ -0,0 +1,2442 @@
1/*
2 * f_fs.c -- user mode filesystem api for usb composite funtcion controllers
3 *
4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 *
7 * Based on inode.c (GadgetFS):
8 * Copyright (C) 2003-2004 David Brownell
9 * Copyright (C) 2003 Agilent Technologies
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26
27/* #define DEBUG */
28/* #define VERBOSE_DEBUG */
29
30#include <linux/blkdev.h>
31#include <linux/pagemap.h>
32#include <asm/unaligned.h>
33#include <linux/smp_lock.h>
34
35#include <linux/usb/composite.h>
36#include <linux/usb/functionfs.h>
37
38
39#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
40
41
42/* Debuging *****************************************************************/
43
44#define ffs_printk(level, fmt, args...) printk(level "f_fs: " fmt "\n", ## args)
45
46#define FERR(...) ffs_printk(KERN_ERR, __VA_ARGS__)
47#define FINFO(...) ffs_printk(KERN_INFO, __VA_ARGS__)
48
49#ifdef DEBUG
50# define FDBG(...) ffs_printk(KERN_DEBUG, __VA_ARGS__)
51#else
52# define FDBG(...) do { } while (0)
53#endif /* DEBUG */
54
55#ifdef VERBOSE_DEBUG
56# define FVDBG FDBG
57#else
58# define FVDBG(...) do { } while (0)
59#endif /* VERBOSE_DEBUG */
60
61#define ENTER() FVDBG("%s()", __func__)
62
63#ifdef VERBOSE_DEBUG
64# define ffs_dump_mem(prefix, ptr, len) \
65 print_hex_dump_bytes("f_fs" prefix ": ", DUMP_PREFIX_NONE, ptr, len)
66#else
67# define ffs_dump_mem(prefix, ptr, len) do { } while (0)
68#endif
69
70
71/* The data structure and setup file ****************************************/
72
73enum ffs_state {
74 /* Waiting for descriptors and strings. */
75 /* In this state no open(2), read(2) or write(2) on epfiles
76 * may succeed (which should not be the problem as there
77 * should be no such files opened in the firts place). */
78 FFS_READ_DESCRIPTORS,
79 FFS_READ_STRINGS,
80
81 /* We've got descriptors and strings. We are or have called
82 * functionfs_ready_callback(). functionfs_bind() may have
83 * been called but we don't know. */
84 /* This is the only state in which operations on epfiles may
85 * succeed. */
86 FFS_ACTIVE,
87
88 /* All endpoints have been closed. This state is also set if
89 * we encounter an unrecoverable error. The only
90 * unrecoverable error is situation when after reading strings
91 * from user space we fail to initialise EP files or
92 * functionfs_ready_callback() returns with error (<0). */
93 /* In this state no open(2), read(2) or write(2) (both on ep0
94 * as well as epfile) may succeed (at this point epfiles are
95 * unlinked and all closed so this is not a problem; ep0 is
96 * also closed but ep0 file exists and so open(2) on ep0 must
97 * fail). */
98 FFS_CLOSING
99};
100
101
102enum ffs_setup_state {
103 /* There is no setup request pending. */
104 FFS_NO_SETUP,
105 /* User has read events and there was a setup request event
106 * there. The next read/write on ep0 will handle the
107 * request. */
108 FFS_SETUP_PENDING,
109 /* There was event pending but before user space handled it
110 * some other event was introduced which canceled existing
111 * setup. If this state is set read/write on ep0 return
112 * -EIDRM. This state is only set when adding event. */
113 FFS_SETUP_CANCELED
114};
115
116
117
118struct ffs_epfile;
119struct ffs_function;
120
121struct ffs_data {
122 struct usb_gadget *gadget;
123
124 /* Protect access read/write operations, only one read/write
125 * at a time. As a consequence protects ep0req and company.
126 * While setup request is being processed (queued) this is
127 * held. */
128 struct mutex mutex;
129
130 /* Protect access to enpoint related structures (basically
131 * usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
132 * endpint zero. */
133 spinlock_t eps_lock;
134
135 /* XXX REVISIT do we need our own request? Since we are not
136 * handling setup requests immidiatelly user space may be so
137 * slow that another setup will be sent to the gadget but this
138 * time not to us but another function and then there could be
139 * a race. Is taht the case? Or maybe we can use cdev->req
140 * after all, maybe we just need some spinlock for that? */
141 struct usb_request *ep0req; /* P: mutex */
142 struct completion ep0req_completion; /* P: mutex */
143 int ep0req_status; /* P: mutex */
144
145 /* reference counter */
146 atomic_t ref;
147 /* how many files are opened (EP0 and others) */
148 atomic_t opened;
149
150 /* EP0 state */
151 enum ffs_state state;
152
153 /*
154 * Possible transations:
155 * + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock
156 * happens only in ep0 read which is P: mutex
157 * + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock
158 * happens only in ep0 i/o which is P: mutex
159 * + FFS_SETUP_PENDING -> FFS_SETUP_CANCELED -- P: ev.waitq.lock
160 * + FFS_SETUP_CANCELED -> FFS_NO_SETUP -- cmpxchg
161 */
162 enum ffs_setup_state setup_state;
163
164#define FFS_SETUP_STATE(ffs) \
165 ((enum ffs_setup_state)cmpxchg(&(ffs)->setup_state, \
166 FFS_SETUP_CANCELED, FFS_NO_SETUP))
167
168 /* Events & such. */
169 struct {
170 u8 types[4];
171 unsigned short count;
172 /* XXX REVISIT need to update it in some places, or do we? */
173 unsigned short can_stall;
174 struct usb_ctrlrequest setup;
175
176 wait_queue_head_t waitq;
177 } ev; /* the whole structure, P: ev.waitq.lock */
178
179 /* Flags */
180 unsigned long flags;
181#define FFS_FL_CALL_CLOSED_CALLBACK 0
182#define FFS_FL_BOUND 1
183
184 /* Active function */
185 struct ffs_function *func;
186
187 /* Device name, write once when file system is mounted.
188 * Intendet for user to read if she wants. */
189 const char *dev_name;
190 /* Private data for our user (ie. gadget). Managed by
191 * user. */
192 void *private_data;
193
194 /* filled by __ffs_data_got_descs() */
195 /* real descriptors are 16 bytes after raw_descs (so you need
196 * to skip 16 bytes (ie. ffs->raw_descs + 16) to get to the
197 * first full speed descriptor). raw_descs_length and
198 * raw_fs_descs_length do not have those 16 bytes added. */
199 const void *raw_descs;
200 unsigned raw_descs_length;
201 unsigned raw_fs_descs_length;
202 unsigned fs_descs_count;
203 unsigned hs_descs_count;
204
205 unsigned short strings_count;
206 unsigned short interfaces_count;
207 unsigned short eps_count;
208 unsigned short _pad1;
209
210 /* filled by __ffs_data_got_strings() */
211 /* ids in stringtabs are set in functionfs_bind() */
212 const void *raw_strings;
213 struct usb_gadget_strings **stringtabs;
214
215 /* File system's super block, write once when file system is mounted. */
216 struct super_block *sb;
217
218 /* File permissions, written once when fs is mounted*/
219 struct ffs_file_perms {
220 umode_t mode;
221 uid_t uid;
222 gid_t gid;
223 } file_perms;
224
225 /* The endpoint files, filled by ffs_epfiles_create(),
226 * destroyed by ffs_epfiles_destroy(). */
227 struct ffs_epfile *epfiles;
228};
229
230/* Reference counter handling */
231static void ffs_data_get(struct ffs_data *ffs);
232static void ffs_data_put(struct ffs_data *ffs);
233/* Creates new ffs_data object. */
234static struct ffs_data *__must_check ffs_data_new(void) __attribute__((malloc));
235
236/* Opened counter handling. */
237static void ffs_data_opened(struct ffs_data *ffs);
238static void ffs_data_closed(struct ffs_data *ffs);
239
240/* Called with ffs->mutex held; take over ownerrship of data. */
241static int __must_check
242__ffs_data_got_descs(struct ffs_data *ffs, char *data, size_t len);
243static int __must_check
244__ffs_data_got_strings(struct ffs_data *ffs, char *data, size_t len);
245
246
247/* The function structure ***************************************************/
248
249struct ffs_ep;
250
251struct ffs_function {
252 struct usb_configuration *conf;
253 struct usb_gadget *gadget;
254 struct ffs_data *ffs;
255
256 struct ffs_ep *eps;
257 u8 eps_revmap[16];
258 short *interfaces_nums;
259
260 struct usb_function function;
261};
262
263
264static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
265{
266 return container_of(f, struct ffs_function, function);
267}
268
269static void ffs_func_free(struct ffs_function *func);
270
271
272static void ffs_func_eps_disable(struct ffs_function *func);
273static int __must_check ffs_func_eps_enable(struct ffs_function *func);
274
275
276static int ffs_func_bind(struct usb_configuration *,
277 struct usb_function *);
278static void ffs_func_unbind(struct usb_configuration *,
279 struct usb_function *);
280static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned);
281static void ffs_func_disable(struct usb_function *);
282static int ffs_func_setup(struct usb_function *,
283 const struct usb_ctrlrequest *);
284static void ffs_func_suspend(struct usb_function *);
285static void ffs_func_resume(struct usb_function *);
286
287
288static int ffs_func_revmap_ep(struct ffs_function *func, u8 num);
289static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf);
290
291
292
293/* The endpoints structures *************************************************/
294
295struct ffs_ep {
296 struct usb_ep *ep; /* P: ffs->eps_lock */
297 struct usb_request *req; /* P: epfile->mutex */
298
299 /* [0]: full speed, [1]: high speed */
300 struct usb_endpoint_descriptor *descs[2];
301
302 u8 num;
303
304 int status; /* P: epfile->mutex */
305};
306
307struct ffs_epfile {
308 /* Protects ep->ep and ep->req. */
309 struct mutex mutex;
310 wait_queue_head_t wait;
311
312 struct ffs_data *ffs;
313 struct ffs_ep *ep; /* P: ffs->eps_lock */
314
315 struct dentry *dentry;
316
317 char name[5];
318
319 unsigned char in; /* P: ffs->eps_lock */
320 unsigned char isoc; /* P: ffs->eps_lock */
321
322 unsigned char _pad;
323};
324
325
326static int __must_check ffs_epfiles_create(struct ffs_data *ffs);
327static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count);
328
329static struct inode *__must_check
330ffs_sb_create_file(struct super_block *sb, const char *name, void *data,
331 const struct file_operations *fops,
332 struct dentry **dentry_p);
333
334
335/* Misc helper functions ****************************************************/
336
337static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
338 __attribute__((warn_unused_result, nonnull));
339static char *ffs_prepare_buffer(const char * __user buf, size_t len)
340 __attribute__((warn_unused_result, nonnull));
341
342
343/* Control file aka ep0 *****************************************************/
344
345static void ffs_ep0_complete(struct usb_ep *ep, struct usb_request *req)
346{
347 struct ffs_data *ffs = req->context;
348
349 complete_all(&ffs->ep0req_completion);
350}
351
352
353static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
354{
355 struct usb_request *req = ffs->ep0req;
356 int ret;
357
358 req->zero = len < le16_to_cpu(ffs->ev.setup.wLength);
359
360 spin_unlock_irq(&ffs->ev.waitq.lock);
361
362 req->buf = data;
363 req->length = len;
364
365 INIT_COMPLETION(ffs->ep0req_completion);
366
367 ret = usb_ep_queue(ffs->gadget->ep0, req, GFP_ATOMIC);
368 if (unlikely(ret < 0))
369 return ret;
370
371 ret = wait_for_completion_interruptible(&ffs->ep0req_completion);
372 if (unlikely(ret)) {
373 usb_ep_dequeue(ffs->gadget->ep0, req);
374 return -EINTR;
375 }
376
377 ffs->setup_state = FFS_NO_SETUP;
378 return ffs->ep0req_status;
379}
380
381static int __ffs_ep0_stall(struct ffs_data *ffs)
382{
383 if (ffs->ev.can_stall) {
384 FVDBG("ep0 stall\n");
385 usb_ep_set_halt(ffs->gadget->ep0);
386 ffs->setup_state = FFS_NO_SETUP;
387 return -EL2HLT;
388 } else {
389 FDBG("bogus ep0 stall!\n");
390 return -ESRCH;
391 }
392}
393
394
395static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
396 size_t len, loff_t *ptr)
397{
398 struct ffs_data *ffs = file->private_data;
399 ssize_t ret;
400 char *data;
401
402 ENTER();
403
404 /* Fast check if setup was canceled */
405 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED)
406 return -EIDRM;
407
408 /* Acquire mutex */
409 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
410 if (unlikely(ret < 0))
411 return ret;
412
413
414 /* Check state */
415 switch (ffs->state) {
416 case FFS_READ_DESCRIPTORS:
417 case FFS_READ_STRINGS:
418 /* Copy data */
419 if (unlikely(len < 16)) {
420 ret = -EINVAL;
421 break;
422 }
423
424 data = ffs_prepare_buffer(buf, len);
425 if (unlikely(IS_ERR(data))) {
426 ret = PTR_ERR(data);
427 break;
428 }
429
430 /* Handle data */
431 if (ffs->state == FFS_READ_DESCRIPTORS) {
432 FINFO("read descriptors");
433 ret = __ffs_data_got_descs(ffs, data, len);
434 if (unlikely(ret < 0))
435 break;
436
437 ffs->state = FFS_READ_STRINGS;
438 ret = len;
439 } else {
440 FINFO("read strings");
441 ret = __ffs_data_got_strings(ffs, data, len);
442 if (unlikely(ret < 0))
443 break;
444
445 ret = ffs_epfiles_create(ffs);
446 if (unlikely(ret)) {
447 ffs->state = FFS_CLOSING;
448 break;
449 }
450
451 ffs->state = FFS_ACTIVE;
452 mutex_unlock(&ffs->mutex);
453
454 ret = functionfs_ready_callback(ffs);
455 if (unlikely(ret < 0)) {
456 ffs->state = FFS_CLOSING;
457 return ret;
458 }
459
460 set_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags);
461 return len;
462 }
463 break;
464
465
466 case FFS_ACTIVE:
467 data = NULL;
468 /* We're called from user space, we can use _irq
469 * rather then _irqsave */
470 spin_lock_irq(&ffs->ev.waitq.lock);
471 switch (FFS_SETUP_STATE(ffs)) {
472 case FFS_SETUP_CANCELED:
473 ret = -EIDRM;
474 goto done_spin;
475
476 case FFS_NO_SETUP:
477 ret = -ESRCH;
478 goto done_spin;
479
480 case FFS_SETUP_PENDING:
481 break;
482 }
483
484 /* FFS_SETUP_PENDING */
485 if (!(ffs->ev.setup.bRequestType & USB_DIR_IN)) {
486 spin_unlock_irq(&ffs->ev.waitq.lock);
487 ret = __ffs_ep0_stall(ffs);
488 break;
489 }
490
491 /* FFS_SETUP_PENDING and not stall */
492 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
493
494 spin_unlock_irq(&ffs->ev.waitq.lock);
495
496 data = ffs_prepare_buffer(buf, len);
497 if (unlikely(IS_ERR(data))) {
498 ret = PTR_ERR(data);
499 break;
500 }
501
502 spin_lock_irq(&ffs->ev.waitq.lock);
503
504 /* We are guaranteed to be still in FFS_ACTIVE state
505 * but the state of setup could have changed from
506 * FFS_SETUP_PENDING to FFS_SETUP_CANCELED so we need
507 * to check for that. If that happened we copied data
508 * from user space in vain but it's unlikely. */
509 /* For sure we are not in FFS_NO_SETUP since this is
510 * the only place FFS_SETUP_PENDING -> FFS_NO_SETUP
511 * transition can be performed and it's protected by
512 * mutex. */
513
514 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
515 ret = -EIDRM;
516done_spin:
517 spin_unlock_irq(&ffs->ev.waitq.lock);
518 } else {
519 /* unlocks spinlock */
520 ret = __ffs_ep0_queue_wait(ffs, data, len);
521 }
522 kfree(data);
523 break;
524
525
526 default:
527 ret = -EBADFD;
528 break;
529 }
530
531
532 mutex_unlock(&ffs->mutex);
533 return ret;
534}
535
536
537
538static ssize_t __ffs_ep0_read_events(struct ffs_data *ffs, char __user *buf,
539 size_t n)
540{
541 /* We are holding ffs->ev.waitq.lock and ffs->mutex and we need
542 * to release them. */
543
544 struct usb_functionfs_event events[n];
545 unsigned i = 0;
546
547 memset(events, 0, sizeof events);
548
549 do {
550 events[i].type = ffs->ev.types[i];
551 if (events[i].type == FUNCTIONFS_SETUP) {
552 events[i].u.setup = ffs->ev.setup;
553 ffs->setup_state = FFS_SETUP_PENDING;
554 }
555 } while (++i < n);
556
557 if (n < ffs->ev.count) {
558 ffs->ev.count -= n;
559 memmove(ffs->ev.types, ffs->ev.types + n,
560 ffs->ev.count * sizeof *ffs->ev.types);
561 } else {
562 ffs->ev.count = 0;
563 }
564
565 spin_unlock_irq(&ffs->ev.waitq.lock);
566 mutex_unlock(&ffs->mutex);
567
568 return unlikely(__copy_to_user(buf, events, sizeof events))
569 ? -EFAULT : sizeof events;
570}
571
572
573static ssize_t ffs_ep0_read(struct file *file, char __user *buf,
574 size_t len, loff_t *ptr)
575{
576 struct ffs_data *ffs = file->private_data;
577 char *data = NULL;
578 size_t n;
579 int ret;
580
581 ENTER();
582
583 /* Fast check if setup was canceled */
584 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED)
585 return -EIDRM;
586
587 /* Acquire mutex */
588 ret = ffs_mutex_lock(&ffs->mutex, file->f_flags & O_NONBLOCK);
589 if (unlikely(ret < 0))
590 return ret;
591
592
593 /* Check state */
594 if (ffs->state != FFS_ACTIVE) {
595 ret = -EBADFD;
596 goto done_mutex;
597 }
598
599
600 /* We're called from user space, we can use _irq rather then
601 * _irqsave */
602 spin_lock_irq(&ffs->ev.waitq.lock);
603
604 switch (FFS_SETUP_STATE(ffs)) {
605 case FFS_SETUP_CANCELED:
606 ret = -EIDRM;
607 break;
608
609 case FFS_NO_SETUP:
610 n = len / sizeof(struct usb_functionfs_event);
611 if (unlikely(!n)) {
612 ret = -EINVAL;
613 break;
614 }
615
616 if ((file->f_flags & O_NONBLOCK) && !ffs->ev.count) {
617 ret = -EAGAIN;
618 break;
619 }
620
621 if (unlikely(wait_event_interruptible_exclusive_locked_irq(ffs->ev.waitq, ffs->ev.count))) {
622 ret = -EINTR;
623 break;
624 }
625
626 return __ffs_ep0_read_events(ffs, buf,
627 min(n, (size_t)ffs->ev.count));
628
629
630 case FFS_SETUP_PENDING:
631 if (ffs->ev.setup.bRequestType & USB_DIR_IN) {
632 spin_unlock_irq(&ffs->ev.waitq.lock);
633 ret = __ffs_ep0_stall(ffs);
634 goto done_mutex;
635 }
636
637 len = min(len, (size_t)le16_to_cpu(ffs->ev.setup.wLength));
638
639 spin_unlock_irq(&ffs->ev.waitq.lock);
640
641 if (likely(len)) {
642 data = kmalloc(len, GFP_KERNEL);
643 if (unlikely(!data)) {
644 ret = -ENOMEM;
645 goto done_mutex;
646 }
647 }
648
649 spin_lock_irq(&ffs->ev.waitq.lock);
650
651 /* See ffs_ep0_write() */
652 if (FFS_SETUP_STATE(ffs) == FFS_SETUP_CANCELED) {
653 ret = -EIDRM;
654 break;
655 }
656
657 /* unlocks spinlock */
658 ret = __ffs_ep0_queue_wait(ffs, data, len);
659 if (likely(ret > 0) && unlikely(__copy_to_user(buf, data, len)))
660 ret = -EFAULT;
661 goto done_mutex;
662
663 default:
664 ret = -EBADFD;
665 break;
666 }
667
668 spin_unlock_irq(&ffs->ev.waitq.lock);
669done_mutex:
670 mutex_unlock(&ffs->mutex);
671 kfree(data);
672 return ret;
673}
674
675
676
677static int ffs_ep0_open(struct inode *inode, struct file *file)
678{
679 struct ffs_data *ffs = inode->i_private;
680
681 ENTER();
682
683 if (unlikely(ffs->state == FFS_CLOSING))
684 return -EBUSY;
685
686 file->private_data = ffs;
687 ffs_data_opened(ffs);
688
689 return 0;
690}
691
692
693static int ffs_ep0_release(struct inode *inode, struct file *file)
694{
695 struct ffs_data *ffs = file->private_data;
696
697 ENTER();
698
699 ffs_data_closed(ffs);
700
701 return 0;
702}
703
704
705static long ffs_ep0_ioctl(struct file *file, unsigned code, unsigned long value)
706{
707 struct ffs_data *ffs = file->private_data;
708 struct usb_gadget *gadget = ffs->gadget;
709 long ret;
710
711 ENTER();
712
713 if (code == FUNCTIONFS_INTERFACE_REVMAP) {
714 struct ffs_function *func = ffs->func;
715 ret = func ? ffs_func_revmap_intf(func, value) : -ENODEV;
716 } else if (gadget->ops->ioctl) {
717 lock_kernel();
718 ret = gadget->ops->ioctl(gadget, code, value);
719 unlock_kernel();
720 } else {
721 ret = -ENOTTY;
722 }
723
724 return ret;
725}
726
727
728static const struct file_operations ffs_ep0_operations = {
729 .owner = THIS_MODULE,
730 .llseek = no_llseek,
731
732 .open = ffs_ep0_open,
733 .write = ffs_ep0_write,
734 .read = ffs_ep0_read,
735 .release = ffs_ep0_release,
736 .unlocked_ioctl = ffs_ep0_ioctl,
737};
738
739
740/* "Normal" endpoints operations ********************************************/
741
742
743static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
744{
745 ENTER();
746 if (likely(req->context)) {
747 struct ffs_ep *ep = _ep->driver_data;
748 ep->status = req->status ? req->status : req->actual;
749 complete(req->context);
750 }
751}
752
753
754static ssize_t ffs_epfile_io(struct file *file,
755 char __user *buf, size_t len, int read)
756{
757 struct ffs_epfile *epfile = file->private_data;
758 struct ffs_ep *ep;
759 char *data = NULL;
760 ssize_t ret;
761 int halt;
762
763 goto first_try;
764 do {
765 spin_unlock_irq(&epfile->ffs->eps_lock);
766 mutex_unlock(&epfile->mutex);
767
768first_try:
769 /* Are we still active? */
770 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE)) {
771 ret = -ENODEV;
772 goto error;
773 }
774
775 /* Wait for endpoint to be enabled */
776 ep = epfile->ep;
777 if (!ep) {
778 if (file->f_flags & O_NONBLOCK) {
779 ret = -EAGAIN;
780 goto error;
781 }
782
783 if (unlikely(wait_event_interruptible
784 (epfile->wait, (ep = epfile->ep)))) {
785 ret = -EINTR;
786 goto error;
787 }
788 }
789
790 /* Do we halt? */
791 halt = !read == !epfile->in;
792 if (halt && epfile->isoc) {
793 ret = -EINVAL;
794 goto error;
795 }
796
797 /* Allocate & copy */
798 if (!halt && !data) {
799 data = kzalloc(len, GFP_KERNEL);
800 if (unlikely(!data))
801 return -ENOMEM;
802
803 if (!read &&
804 unlikely(__copy_from_user(data, buf, len))) {
805 ret = -EFAULT;
806 goto error;
807 }
808 }
809
810 /* We will be using request */
811 ret = ffs_mutex_lock(&epfile->mutex,
812 file->f_flags & O_NONBLOCK);
813 if (unlikely(ret))
814 goto error;
815
816 /* We're called from user space, we can use _irq rather then
817 * _irqsave */
818 spin_lock_irq(&epfile->ffs->eps_lock);
819
820 /* While we were acquiring mutex endpoint got disabled
821 * or changed? */
822 } while (unlikely(epfile->ep != ep));
823
824 /* Halt */
825 if (unlikely(halt)) {
826 if (likely(epfile->ep == ep) && !WARN_ON(!ep->ep))
827 usb_ep_set_halt(ep->ep);
828 spin_unlock_irq(&epfile->ffs->eps_lock);
829 ret = -EBADMSG;
830 } else {
831 /* Fire the request */
832 DECLARE_COMPLETION_ONSTACK(done);
833
834 struct usb_request *req = ep->req;
835 req->context = &done;
836 req->complete = ffs_epfile_io_complete;
837 req->buf = data;
838 req->length = len;
839
840 ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
841
842 spin_unlock_irq(&epfile->ffs->eps_lock);
843
844 if (unlikely(ret < 0)) {
845 /* nop */
846 } else if (unlikely(wait_for_completion_interruptible(&done))) {
847 ret = -EINTR;
848 usb_ep_dequeue(ep->ep, req);
849 } else {
850 ret = ep->status;
851 if (read && ret > 0 &&
852 unlikely(copy_to_user(buf, data, ret)))
853 ret = -EFAULT;
854 }
855 }
856
857 mutex_unlock(&epfile->mutex);
858error:
859 kfree(data);
860 return ret;
861}
862
863
864static ssize_t
865ffs_epfile_write(struct file *file, const char __user *buf, size_t len,
866 loff_t *ptr)
867{
868 ENTER();
869
870 return ffs_epfile_io(file, (char __user *)buf, len, 0);
871}
872
873static ssize_t
874ffs_epfile_read(struct file *file, char __user *buf, size_t len, loff_t *ptr)
875{
876 ENTER();
877
878 return ffs_epfile_io(file, buf, len, 1);
879}
880
881static int
882ffs_epfile_open(struct inode *inode, struct file *file)
883{
884 struct ffs_epfile *epfile = inode->i_private;
885
886 ENTER();
887
888 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
889 return -ENODEV;
890
891 file->private_data = epfile;
892 ffs_data_opened(epfile->ffs);
893
894 return 0;
895}
896
897static int
898ffs_epfile_release(struct inode *inode, struct file *file)
899{
900 struct ffs_epfile *epfile = inode->i_private;
901
902 ENTER();
903
904 ffs_data_closed(epfile->ffs);
905
906 return 0;
907}
908
909
910static long ffs_epfile_ioctl(struct file *file, unsigned code,
911 unsigned long value)
912{
913 struct ffs_epfile *epfile = file->private_data;
914 int ret;
915
916 ENTER();
917
918 if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
919 return -ENODEV;
920
921 spin_lock_irq(&epfile->ffs->eps_lock);
922 if (likely(epfile->ep)) {
923 switch (code) {
924 case FUNCTIONFS_FIFO_STATUS:
925 ret = usb_ep_fifo_status(epfile->ep->ep);
926 break;
927 case FUNCTIONFS_FIFO_FLUSH:
928 usb_ep_fifo_flush(epfile->ep->ep);
929 ret = 0;
930 break;
931 case FUNCTIONFS_CLEAR_HALT:
932 ret = usb_ep_clear_halt(epfile->ep->ep);
933 break;
934 case FUNCTIONFS_ENDPOINT_REVMAP:
935 ret = epfile->ep->num;
936 break;
937 default:
938 ret = -ENOTTY;
939 }
940 } else {
941 ret = -ENODEV;
942 }
943 spin_unlock_irq(&epfile->ffs->eps_lock);
944
945 return ret;
946}
947
948
949static const struct file_operations ffs_epfile_operations = {
950 .owner = THIS_MODULE,
951 .llseek = no_llseek,
952
953 .open = ffs_epfile_open,
954 .write = ffs_epfile_write,
955 .read = ffs_epfile_read,
956 .release = ffs_epfile_release,
957 .unlocked_ioctl = ffs_epfile_ioctl,
958};
959
960
961
962/* File system and super block operations ***********************************/
963
964/*
965 * Mounting the filesystem creates a controller file, used first for
966 * function configuration then later for event monitoring.
967 */
968
969
970static struct inode *__must_check
971ffs_sb_make_inode(struct super_block *sb, void *data,
972 const struct file_operations *fops,
973 const struct inode_operations *iops,
974 struct ffs_file_perms *perms)
975{
976 struct inode *inode;
977
978 ENTER();
979
980 inode = new_inode(sb);
981
982 if (likely(inode)) {
983 struct timespec current_time = CURRENT_TIME;
984
985 inode->i_mode = perms->mode;
986 inode->i_uid = perms->uid;
987 inode->i_gid = perms->gid;
988 inode->i_atime = current_time;
989 inode->i_mtime = current_time;
990 inode->i_ctime = current_time;
991 inode->i_private = data;
992 if (fops)
993 inode->i_fop = fops;
994 if (iops)
995 inode->i_op = iops;
996 }
997
998 return inode;
999}
1000
1001
1002/* Create "regular" file */
1003
1004static struct inode *ffs_sb_create_file(struct super_block *sb,
1005 const char *name, void *data,
1006 const struct file_operations *fops,
1007 struct dentry **dentry_p)
1008{
1009 struct ffs_data *ffs = sb->s_fs_info;
1010 struct dentry *dentry;
1011 struct inode *inode;
1012
1013 ENTER();
1014
1015 dentry = d_alloc_name(sb->s_root, name);
1016 if (unlikely(!dentry))
1017 return NULL;
1018
1019 inode = ffs_sb_make_inode(sb, data, fops, NULL, &ffs->file_perms);
1020 if (unlikely(!inode)) {
1021 dput(dentry);
1022 return NULL;
1023 }
1024
1025 d_add(dentry, inode);
1026 if (dentry_p)
1027 *dentry_p = dentry;
1028
1029 return inode;
1030}
1031
1032
1033/* Super block */
1034
1035static const struct super_operations ffs_sb_operations = {
1036 .statfs = simple_statfs,
1037 .drop_inode = generic_delete_inode,
1038};
1039
1040struct ffs_sb_fill_data {
1041 struct ffs_file_perms perms;
1042 umode_t root_mode;
1043 const char *dev_name;
1044};
1045
1046static int ffs_sb_fill(struct super_block *sb, void *_data, int silent)
1047{
1048 struct ffs_sb_fill_data *data = _data;
1049 struct inode *inode;
1050 struct dentry *d;
1051 struct ffs_data *ffs;
1052
1053 ENTER();
1054
1055 /* Initialize data */
1056 ffs = ffs_data_new();
1057 if (unlikely(!ffs))
1058 goto enomem0;
1059
1060 ffs->sb = sb;
1061 ffs->dev_name = data->dev_name;
1062 ffs->file_perms = data->perms;
1063
1064 sb->s_fs_info = ffs;
1065 sb->s_blocksize = PAGE_CACHE_SIZE;
1066 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1067 sb->s_magic = FUNCTIONFS_MAGIC;
1068 sb->s_op = &ffs_sb_operations;
1069 sb->s_time_gran = 1;
1070
1071 /* Root inode */
1072 data->perms.mode = data->root_mode;
1073 inode = ffs_sb_make_inode(sb, NULL,
1074 &simple_dir_operations,
1075 &simple_dir_inode_operations,
1076 &data->perms);
1077 if (unlikely(!inode))
1078 goto enomem1;
1079 d = d_alloc_root(inode);
1080 if (unlikely(!d))
1081 goto enomem2;
1082 sb->s_root = d;
1083
1084 /* EP0 file */
1085 if (unlikely(!ffs_sb_create_file(sb, "ep0", ffs,
1086 &ffs_ep0_operations, NULL)))
1087 goto enomem3;
1088
1089 return 0;
1090
1091enomem3:
1092 dput(d);
1093enomem2:
1094 iput(inode);
1095enomem1:
1096 ffs_data_put(ffs);
1097enomem0:
1098 return -ENOMEM;
1099}
1100
1101
1102static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)
1103{
1104 ENTER();
1105
1106 if (!opts || !*opts)
1107 return 0;
1108
1109 for (;;) {
1110 char *end, *eq, *comma;
1111 unsigned long value;
1112
1113 /* Option limit */
1114 comma = strchr(opts, ',');
1115 if (comma)
1116 *comma = 0;
1117
1118 /* Value limit */
1119 eq = strchr(opts, '=');
1120 if (unlikely(!eq)) {
1121 FERR("'=' missing in %s", opts);
1122 return -EINVAL;
1123 }
1124 *eq = 0;
1125
1126 /* Parse value */
1127 value = simple_strtoul(eq + 1, &end, 0);
1128 if (unlikely(*end != ',' && *end != 0)) {
1129 FERR("%s: invalid value: %s", opts, eq + 1);
1130 return -EINVAL;
1131 }
1132
1133 /* Interpret option */
1134 switch (eq - opts) {
1135 case 5:
1136 if (!memcmp(opts, "rmode", 5))
1137 data->root_mode = (value & 0555) | S_IFDIR;
1138 else if (!memcmp(opts, "fmode", 5))
1139 data->perms.mode = (value & 0666) | S_IFREG;
1140 else
1141 goto invalid;
1142 break;
1143
1144 case 4:
1145 if (!memcmp(opts, "mode", 4)) {
1146 data->root_mode = (value & 0555) | S_IFDIR;
1147 data->perms.mode = (value & 0666) | S_IFREG;
1148 } else {
1149 goto invalid;
1150 }
1151 break;
1152
1153 case 3:
1154 if (!memcmp(opts, "uid", 3))
1155 data->perms.uid = value;
1156 else if (!memcmp(opts, "gid", 3))
1157 data->perms.gid = value;
1158 else
1159 goto invalid;
1160 break;
1161
1162 default:
1163invalid:
1164 FERR("%s: invalid option", opts);
1165 return -EINVAL;
1166 }
1167
1168 /* Next iteration */
1169 if (!comma)
1170 break;
1171 opts = comma + 1;
1172 }
1173
1174 return 0;
1175}
1176
1177
1178/* "mount -t functionfs dev_name /dev/function" ends up here */
1179
1180static int
1181ffs_fs_get_sb(struct file_system_type *t, int flags,
1182 const char *dev_name, void *opts, struct vfsmount *mnt)
1183{
1184 struct ffs_sb_fill_data data = {
1185 .perms = {
1186 .mode = S_IFREG | 0600,
1187 .uid = 0,
1188 .gid = 0
1189 },
1190 .root_mode = S_IFDIR | 0500,
1191 };
1192 int ret;
1193
1194 ENTER();
1195
1196 ret = functionfs_check_dev_callback(dev_name);
1197 if (unlikely(ret < 0))
1198 return ret;
1199
1200 ret = ffs_fs_parse_opts(&data, opts);
1201 if (unlikely(ret < 0))
1202 return ret;
1203
1204 data.dev_name = dev_name;
1205 return get_sb_single(t, flags, &data, ffs_sb_fill, mnt);
1206}
1207
1208static void
1209ffs_fs_kill_sb(struct super_block *sb)
1210{
1211 void *ptr;
1212
1213 ENTER();
1214
1215 kill_litter_super(sb);
1216 ptr = xchg(&sb->s_fs_info, NULL);
1217 if (ptr)
1218 ffs_data_put(ptr);
1219}
1220
1221static struct file_system_type ffs_fs_type = {
1222 .owner = THIS_MODULE,
1223 .name = "functionfs",
1224 .get_sb = ffs_fs_get_sb,
1225 .kill_sb = ffs_fs_kill_sb,
1226};
1227
1228
1229
1230/* Driver's main init/cleanup functions *************************************/
1231
1232
1233static int functionfs_init(void)
1234{
1235 int ret;
1236
1237 ENTER();
1238
1239 ret = register_filesystem(&ffs_fs_type);
1240 if (likely(!ret))
1241 FINFO("file system registered");
1242 else
1243 FERR("failed registering file system (%d)", ret);
1244
1245 return ret;
1246}
1247
1248static void functionfs_cleanup(void)
1249{
1250 ENTER();
1251
1252 FINFO("unloading");
1253 unregister_filesystem(&ffs_fs_type);
1254}
1255
1256
1257
1258/* ffs_data and ffs_function construction and destruction code **************/
1259
1260static void ffs_data_clear(struct ffs_data *ffs);
1261static void ffs_data_reset(struct ffs_data *ffs);
1262
1263
1264static void ffs_data_get(struct ffs_data *ffs)
1265{
1266 ENTER();
1267
1268 atomic_inc(&ffs->ref);
1269}
1270
1271static void ffs_data_opened(struct ffs_data *ffs)
1272{
1273 ENTER();
1274
1275 atomic_inc(&ffs->ref);
1276 atomic_inc(&ffs->opened);
1277}
1278
1279static void ffs_data_put(struct ffs_data *ffs)
1280{
1281 ENTER();
1282
1283 if (unlikely(atomic_dec_and_test(&ffs->ref))) {
1284 FINFO("%s(): freeing", __func__);
1285 ffs_data_clear(ffs);
1286 BUG_ON(mutex_is_locked(&ffs->mutex) ||
1287 spin_is_locked(&ffs->ev.waitq.lock) ||
1288 waitqueue_active(&ffs->ev.waitq) ||
1289 waitqueue_active(&ffs->ep0req_completion.wait));
1290 kfree(ffs);
1291 }
1292}
1293
1294
1295
1296static void ffs_data_closed(struct ffs_data *ffs)
1297{
1298 ENTER();
1299
1300 if (atomic_dec_and_test(&ffs->opened)) {
1301 ffs->state = FFS_CLOSING;
1302 ffs_data_reset(ffs);
1303 }
1304
1305 ffs_data_put(ffs);
1306}
1307
1308
1309static struct ffs_data *ffs_data_new(void)
1310{
1311 struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL);
1312 if (unlikely(!ffs))
1313 return 0;
1314
1315 ENTER();
1316
1317 atomic_set(&ffs->ref, 1);
1318 atomic_set(&ffs->opened, 0);
1319 ffs->state = FFS_READ_DESCRIPTORS;
1320 mutex_init(&ffs->mutex);
1321 spin_lock_init(&ffs->eps_lock);
1322 init_waitqueue_head(&ffs->ev.waitq);
1323 init_completion(&ffs->ep0req_completion);
1324
1325 /* XXX REVISIT need to update it in some places, or do we? */
1326 ffs->ev.can_stall = 1;
1327
1328 return ffs;
1329}
1330
1331
1332static void ffs_data_clear(struct ffs_data *ffs)
1333{
1334 ENTER();
1335
1336 if (test_and_clear_bit(FFS_FL_CALL_CLOSED_CALLBACK, &ffs->flags))
1337 functionfs_closed_callback(ffs);
1338
1339 BUG_ON(ffs->gadget);
1340
1341 if (ffs->epfiles)
1342 ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
1343
1344 kfree(ffs->raw_descs);
1345 kfree(ffs->raw_strings);
1346 kfree(ffs->stringtabs);
1347}
1348
1349
1350static void ffs_data_reset(struct ffs_data *ffs)
1351{
1352 ENTER();
1353
1354 ffs_data_clear(ffs);
1355
1356 ffs->epfiles = NULL;
1357 ffs->raw_descs = NULL;
1358 ffs->raw_strings = NULL;
1359 ffs->stringtabs = NULL;
1360
1361 ffs->raw_descs_length = 0;
1362 ffs->raw_fs_descs_length = 0;
1363 ffs->fs_descs_count = 0;
1364 ffs->hs_descs_count = 0;
1365
1366 ffs->strings_count = 0;
1367 ffs->interfaces_count = 0;
1368 ffs->eps_count = 0;
1369
1370 ffs->ev.count = 0;
1371
1372 ffs->state = FFS_READ_DESCRIPTORS;
1373 ffs->setup_state = FFS_NO_SETUP;
1374 ffs->flags = 0;
1375}
1376
1377
1378static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
1379{
1380 unsigned i, count;
1381
1382 ENTER();
1383
1384 if (WARN_ON(ffs->state != FFS_ACTIVE
1385 || test_and_set_bit(FFS_FL_BOUND, &ffs->flags)))
1386 return -EBADFD;
1387
1388 ffs_data_get(ffs);
1389
1390 ffs->ep0req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
1391 if (unlikely(!ffs->ep0req))
1392 return -ENOMEM;
1393 ffs->ep0req->complete = ffs_ep0_complete;
1394 ffs->ep0req->context = ffs;
1395
1396 /* Get strings identifiers */
1397 for (count = ffs->strings_count, i = 0; i < count; ++i) {
1398 struct usb_gadget_strings **lang;
1399
1400 int id = usb_string_id(cdev);
1401 if (unlikely(id < 0)) {
1402 usb_ep_free_request(cdev->gadget->ep0, ffs->ep0req);
1403 ffs->ep0req = NULL;
1404 return id;
1405 }
1406
1407 lang = ffs->stringtabs;
1408 do {
1409 (*lang)->strings[i].id = id;
1410 ++lang;
1411 } while (*lang);
1412 }
1413
1414 ffs->gadget = cdev->gadget;
1415 return 0;
1416}
1417
1418
1419static void functionfs_unbind(struct ffs_data *ffs)
1420{
1421 ENTER();
1422
1423 if (!WARN_ON(!ffs->gadget)) {
1424 usb_ep_free_request(ffs->gadget->ep0, ffs->ep0req);
1425 ffs->ep0req = NULL;
1426 ffs->gadget = NULL;
1427 ffs_data_put(ffs);
1428 }
1429}
1430
1431
1432static int ffs_epfiles_create(struct ffs_data *ffs)
1433{
1434 struct ffs_epfile *epfile, *epfiles;
1435 unsigned i, count;
1436
1437 ENTER();
1438
1439 count = ffs->eps_count;
1440 epfiles = kzalloc(count * sizeof *epfiles, GFP_KERNEL);
1441 if (!epfiles)
1442 return -ENOMEM;
1443
1444 epfile = epfiles;
1445 for (i = 1; i <= count; ++i, ++epfile) {
1446 epfile->ffs = ffs;
1447 mutex_init(&epfile->mutex);
1448 init_waitqueue_head(&epfile->wait);
1449 sprintf(epfiles->name, "ep%u", i);
1450 if (!unlikely(ffs_sb_create_file(ffs->sb, epfiles->name, epfile,
1451 &ffs_epfile_operations,
1452 &epfile->dentry))) {
1453 ffs_epfiles_destroy(epfiles, i - 1);
1454 return -ENOMEM;
1455 }
1456 }
1457
1458 ffs->epfiles = epfiles;
1459 return 0;
1460}
1461
1462
1463static void ffs_epfiles_destroy(struct ffs_epfile *epfiles, unsigned count)
1464{
1465 struct ffs_epfile *epfile = epfiles;
1466
1467 ENTER();
1468
1469 for (; count; --count, ++epfile) {
1470 BUG_ON(mutex_is_locked(&epfile->mutex) ||
1471 waitqueue_active(&epfile->wait));
1472 if (epfile->dentry) {
1473 d_delete(epfile->dentry);
1474 dput(epfile->dentry);
1475 epfile->dentry = NULL;
1476 }
1477 }
1478
1479 kfree(epfiles);
1480}
1481
1482
1483static int functionfs_add(struct usb_composite_dev *cdev,
1484 struct usb_configuration *c,
1485 struct ffs_data *ffs)
1486{
1487 struct ffs_function *func;
1488 int ret;
1489
1490 ENTER();
1491
1492 func = kzalloc(sizeof *func, GFP_KERNEL);
1493 if (unlikely(!func))
1494 return -ENOMEM;
1495
1496 func->function.name = "Function FS Gadget";
1497 func->function.strings = ffs->stringtabs;
1498
1499 func->function.bind = ffs_func_bind;
1500 func->function.unbind = ffs_func_unbind;
1501 func->function.set_alt = ffs_func_set_alt;
1502 /*func->function.get_alt = ffs_func_get_alt;*/
1503 func->function.disable = ffs_func_disable;
1504 func->function.setup = ffs_func_setup;
1505 func->function.suspend = ffs_func_suspend;
1506 func->function.resume = ffs_func_resume;
1507
1508 func->conf = c;
1509 func->gadget = cdev->gadget;
1510 func->ffs = ffs;
1511 ffs_data_get(ffs);
1512
1513 ret = usb_add_function(c, &func->function);
1514 if (unlikely(ret))
1515 ffs_func_free(func);
1516
1517 return ret;
1518}
1519
1520static void ffs_func_free(struct ffs_function *func)
1521{
1522 ENTER();
1523
1524 ffs_data_put(func->ffs);
1525
1526 kfree(func->eps);
1527 /* eps and interfaces_nums are allocated in the same chunk so
1528 * only one free is required. Descriptors are also allocated
1529 * in the same chunk. */
1530
1531 kfree(func);
1532}
1533
1534
1535static void ffs_func_eps_disable(struct ffs_function *func)
1536{
1537 struct ffs_ep *ep = func->eps;
1538 struct ffs_epfile *epfile = func->ffs->epfiles;
1539 unsigned count = func->ffs->eps_count;
1540 unsigned long flags;
1541
1542 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1543 do {
1544 /* pending requests get nuked */
1545 if (likely(ep->ep))
1546 usb_ep_disable(ep->ep);
1547 epfile->ep = NULL;
1548
1549 ++ep;
1550 ++epfile;
1551 } while (--count);
1552 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1553}
1554
1555static int ffs_func_eps_enable(struct ffs_function *func)
1556{
1557 struct ffs_data *ffs = func->ffs;
1558 struct ffs_ep *ep = func->eps;
1559 struct ffs_epfile *epfile = ffs->epfiles;
1560 unsigned count = ffs->eps_count;
1561 unsigned long flags;
1562 int ret = 0;
1563
1564 spin_lock_irqsave(&func->ffs->eps_lock, flags);
1565 do {
1566 struct usb_endpoint_descriptor *ds;
1567 ds = ep->descs[ep->descs[1] ? 1 : 0];
1568
1569 ep->ep->driver_data = ep;
1570 ret = usb_ep_enable(ep->ep, ds);
1571 if (likely(!ret)) {
1572 epfile->ep = ep;
1573 epfile->in = usb_endpoint_dir_in(ds);
1574 epfile->isoc = usb_endpoint_xfer_isoc(ds);
1575 } else {
1576 break;
1577 }
1578
1579 wake_up(&epfile->wait);
1580
1581 ++ep;
1582 ++epfile;
1583 } while (--count);
1584 spin_unlock_irqrestore(&func->ffs->eps_lock, flags);
1585
1586 return ret;
1587}
1588
1589
1590/* Parsing and building descriptors and strings *****************************/
1591
1592
1593/* This validates if data pointed by data is a valid USB descriptor as
1594 * well as record how many interfaces, endpoints and strings are
1595 * required by given configuration. Returns address afther the
1596 * descriptor or NULL if data is invalid. */
1597
1598enum ffs_entity_type {
1599 FFS_DESCRIPTOR, FFS_INTERFACE, FFS_STRING, FFS_ENDPOINT
1600};
1601
1602typedef int (*ffs_entity_callback)(enum ffs_entity_type entity,
1603 u8 *valuep,
1604 struct usb_descriptor_header *desc,
1605 void *priv);
1606
1607static int __must_check ffs_do_desc(char *data, unsigned len,
1608 ffs_entity_callback entity, void *priv)
1609{
1610 struct usb_descriptor_header *_ds = (void *)data;
1611 u8 length;
1612 int ret;
1613
1614 ENTER();
1615
1616 /* At least two bytes are required: length and type */
1617 if (len < 2) {
1618 FVDBG("descriptor too short");
1619 return -EINVAL;
1620 }
1621
1622 /* If we have at least as many bytes as the descriptor takes? */
1623 length = _ds->bLength;
1624 if (len < length) {
1625 FVDBG("descriptor longer then available data");
1626 return -EINVAL;
1627 }
1628
1629#define __entity_check_INTERFACE(val) 1
1630#define __entity_check_STRING(val) (val)
1631#define __entity_check_ENDPOINT(val) ((val) & USB_ENDPOINT_NUMBER_MASK)
1632#define __entity(type, val) do { \
1633 FVDBG("entity " #type "(%02x)", (val)); \
1634 if (unlikely(!__entity_check_ ##type(val))) { \
1635 FVDBG("invalid entity's value"); \
1636 return -EINVAL; \
1637 } \
1638 ret = entity(FFS_ ##type, &val, _ds, priv); \
1639 if (unlikely(ret < 0)) { \
1640 FDBG("entity " #type "(%02x); ret = %d", \
1641 (val), ret); \
1642 return ret; \
1643 } \
1644 } while (0)
1645
1646 /* Parse descriptor depending on type. */
1647 switch (_ds->bDescriptorType) {
1648 case USB_DT_DEVICE:
1649 case USB_DT_CONFIG:
1650 case USB_DT_STRING:
1651 case USB_DT_DEVICE_QUALIFIER:
1652 /* function can't have any of those */
1653 FVDBG("descriptor reserved for gadget: %d", _ds->bDescriptorType);
1654 return -EINVAL;
1655
1656 case USB_DT_INTERFACE: {
1657 struct usb_interface_descriptor *ds = (void *)_ds;
1658 FVDBG("interface descriptor");
1659 if (length != sizeof *ds)
1660 goto inv_length;
1661
1662 __entity(INTERFACE, ds->bInterfaceNumber);
1663 if (ds->iInterface)
1664 __entity(STRING, ds->iInterface);
1665 }
1666 break;
1667
1668 case USB_DT_ENDPOINT: {
1669 struct usb_endpoint_descriptor *ds = (void *)_ds;
1670 FVDBG("endpoint descriptor");
1671 if (length != USB_DT_ENDPOINT_SIZE &&
1672 length != USB_DT_ENDPOINT_AUDIO_SIZE)
1673 goto inv_length;
1674 __entity(ENDPOINT, ds->bEndpointAddress);
1675 }
1676 break;
1677
1678 case USB_DT_OTG:
1679 if (length != sizeof(struct usb_otg_descriptor))
1680 goto inv_length;
1681 break;
1682
1683 case USB_DT_INTERFACE_ASSOCIATION: {
1684 struct usb_interface_assoc_descriptor *ds = (void *)_ds;
1685 FVDBG("interface association descriptor");
1686 if (length != sizeof *ds)
1687 goto inv_length;
1688 if (ds->iFunction)
1689 __entity(STRING, ds->iFunction);
1690 }
1691 break;
1692
1693 case USB_DT_OTHER_SPEED_CONFIG:
1694 case USB_DT_INTERFACE_POWER:
1695 case USB_DT_DEBUG:
1696 case USB_DT_SECURITY:
1697 case USB_DT_CS_RADIO_CONTROL:
1698 /* TODO */
1699 FVDBG("unimplemented descriptor: %d", _ds->bDescriptorType);
1700 return -EINVAL;
1701
1702 default:
1703 /* We should never be here */
1704 FVDBG("unknown descriptor: %d", _ds->bDescriptorType);
1705 return -EINVAL;
1706
1707 inv_length:
1708 FVDBG("invalid length: %d (descriptor %d)",
1709 _ds->bLength, _ds->bDescriptorType);
1710 return -EINVAL;
1711 }
1712
1713#undef __entity
1714#undef __entity_check_DESCRIPTOR
1715#undef __entity_check_INTERFACE
1716#undef __entity_check_STRING
1717#undef __entity_check_ENDPOINT
1718
1719 return length;
1720}
1721
1722
1723static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len,
1724 ffs_entity_callback entity, void *priv)
1725{
1726 const unsigned _len = len;
1727 unsigned long num = 0;
1728
1729 ENTER();
1730
1731 for (;;) {
1732 int ret;
1733
1734 if (num == count)
1735 data = NULL;
1736
1737 /* Record "descriptor" entitny */
1738 ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv);
1739 if (unlikely(ret < 0)) {
1740 FDBG("entity DESCRIPTOR(%02lx); ret = %d", num, ret);
1741 return ret;
1742 }
1743
1744 if (!data)
1745 return _len - len;
1746
1747 ret = ffs_do_desc(data, len, entity, priv);
1748 if (unlikely(ret < 0)) {
1749 FDBG("%s returns %d", __func__, ret);
1750 return ret;
1751 }
1752
1753 len -= ret;
1754 data += ret;
1755 ++num;
1756 }
1757}
1758
1759
1760static int __ffs_data_do_entity(enum ffs_entity_type type,
1761 u8 *valuep, struct usb_descriptor_header *desc,
1762 void *priv)
1763{
1764 struct ffs_data *ffs = priv;
1765
1766 ENTER();
1767
1768 switch (type) {
1769 case FFS_DESCRIPTOR:
1770 break;
1771
1772 case FFS_INTERFACE:
1773 /* Interfaces are indexed from zero so if we
1774 * encountered interface "n" then there are at least
1775 * "n+1" interfaces. */
1776 if (*valuep >= ffs->interfaces_count)
1777 ffs->interfaces_count = *valuep + 1;
1778 break;
1779
1780 case FFS_STRING:
1781 /* Strings are indexed from 1 (0 is magic ;) reserved
1782 * for languages list or some such) */
1783 if (*valuep > ffs->strings_count)
1784 ffs->strings_count = *valuep;
1785 break;
1786
1787 case FFS_ENDPOINT:
1788 /* Endpoints are indexed from 1 as well. */
1789 if ((*valuep & USB_ENDPOINT_NUMBER_MASK) > ffs->eps_count)
1790 ffs->eps_count = (*valuep & USB_ENDPOINT_NUMBER_MASK);
1791 break;
1792 }
1793
1794 return 0;
1795}
1796
1797
1798static int __ffs_data_got_descs(struct ffs_data *ffs,
1799 char *const _data, size_t len)
1800{
1801 unsigned fs_count, hs_count;
1802 int fs_len, ret = -EINVAL;
1803 char *data = _data;
1804
1805 ENTER();
1806
1807 if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_DESCRIPTORS_MAGIC ||
1808 get_unaligned_le32(data + 4) != len))
1809 goto error;
1810 fs_count = get_unaligned_le32(data + 8);
1811 hs_count = get_unaligned_le32(data + 12);
1812
1813 if (!fs_count && !hs_count)
1814 goto einval;
1815
1816 data += 16;
1817 len -= 16;
1818
1819 if (likely(fs_count)) {
1820 fs_len = ffs_do_descs(fs_count, data, len,
1821 __ffs_data_do_entity, ffs);
1822 if (unlikely(fs_len < 0)) {
1823 ret = fs_len;
1824 goto error;
1825 }
1826
1827 data += fs_len;
1828 len -= fs_len;
1829 } else {
1830 fs_len = 0;
1831 }
1832
1833 if (likely(hs_count)) {
1834 ret = ffs_do_descs(hs_count, data, len,
1835 __ffs_data_do_entity, ffs);
1836 if (unlikely(ret < 0))
1837 goto error;
1838 } else {
1839 ret = 0;
1840 }
1841
1842 if (unlikely(len != ret))
1843 goto einval;
1844
1845 ffs->raw_fs_descs_length = fs_len;
1846 ffs->raw_descs_length = fs_len + ret;
1847 ffs->raw_descs = _data;
1848 ffs->fs_descs_count = fs_count;
1849 ffs->hs_descs_count = hs_count;
1850
1851 return 0;
1852
1853einval:
1854 ret = -EINVAL;
1855error:
1856 kfree(_data);
1857 return ret;
1858}
1859
1860
1861
1862static int __ffs_data_got_strings(struct ffs_data *ffs,
1863 char *const _data, size_t len)
1864{
1865 u32 str_count, needed_count, lang_count;
1866 struct usb_gadget_strings **stringtabs, *t;
1867 struct usb_string *strings, *s;
1868 const char *data = _data;
1869
1870 ENTER();
1871
1872 if (unlikely(get_unaligned_le32(data) != FUNCTIONFS_STRINGS_MAGIC ||
1873 get_unaligned_le32(data + 4) != len))
1874 goto error;
1875 str_count = get_unaligned_le32(data + 8);
1876 lang_count = get_unaligned_le32(data + 12);
1877
1878 /* if one is zero the other must be zero */
1879 if (unlikely(!str_count != !lang_count))
1880 goto error;
1881
1882 /* Do we have at least as many strings as descriptors need? */
1883 needed_count = ffs->strings_count;
1884 if (unlikely(str_count < needed_count))
1885 goto error;
1886
1887 /* If we don't need any strings just return and free all
1888 * memory */
1889 if (!needed_count) {
1890 kfree(_data);
1891 return 0;
1892 }
1893
1894 /* Allocate */
1895 {
1896 /* Allocate everything in one chunk so there's less
1897 * maintanance. */
1898 struct {
1899 struct usb_gadget_strings *stringtabs[lang_count + 1];
1900 struct usb_gadget_strings stringtab[lang_count];
1901 struct usb_string strings[lang_count*(needed_count+1)];
1902 } *d;
1903 unsigned i = 0;
1904
1905 d = kmalloc(sizeof *d, GFP_KERNEL);
1906 if (unlikely(!d)) {
1907 kfree(_data);
1908 return -ENOMEM;
1909 }
1910
1911 stringtabs = d->stringtabs;
1912 t = d->stringtab;
1913 i = lang_count;
1914 do {
1915 *stringtabs++ = t++;
1916 } while (--i);
1917 *stringtabs = NULL;
1918
1919 stringtabs = d->stringtabs;
1920 t = d->stringtab;
1921 s = d->strings;
1922 strings = s;
1923 }
1924
1925 /* For each language */
1926 data += 16;
1927 len -= 16;
1928
1929 do { /* lang_count > 0 so we can use do-while */
1930 unsigned needed = needed_count;
1931
1932 if (unlikely(len < 3))
1933 goto error_free;
1934 t->language = get_unaligned_le16(data);
1935 t->strings = s;
1936 ++t;
1937
1938 data += 2;
1939 len -= 2;
1940
1941 /* For each string */
1942 do { /* str_count > 0 so we can use do-while */
1943 size_t length = strnlen(data, len);
1944
1945 if (unlikely(length == len))
1946 goto error_free;
1947
1948 /* user may provide more strings then we need,
1949 * if that's the case we simply ingore the
1950 * rest */
1951 if (likely(needed)) {
1952 /* s->id will be set while adding
1953 * function to configuration so for
1954 * now just leave garbage here. */
1955 s->s = data;
1956 --needed;
1957 ++s;
1958 }
1959
1960 data += length + 1;
1961 len -= length + 1;
1962 } while (--str_count);
1963
1964 s->id = 0; /* terminator */
1965 s->s = NULL;
1966 ++s;
1967
1968 } while (--lang_count);
1969
1970 /* Some garbage left? */
1971 if (unlikely(len))
1972 goto error_free;
1973
1974 /* Done! */
1975 ffs->stringtabs = stringtabs;
1976 ffs->raw_strings = _data;
1977
1978 return 0;
1979
1980error_free:
1981 kfree(stringtabs);
1982error:
1983 kfree(_data);
1984 return -EINVAL;
1985}
1986
1987
1988
1989
1990/* Events handling and management *******************************************/
1991
1992static void __ffs_event_add(struct ffs_data *ffs,
1993 enum usb_functionfs_event_type type)
1994{
1995 enum usb_functionfs_event_type rem_type1, rem_type2 = type;
1996 int neg = 0;
1997
1998 /* Abort any unhandled setup */
1999 /* We do not need to worry about some cmpxchg() changing value
2000 * of ffs->setup_state without holding the lock because when
2001 * state is FFS_SETUP_PENDING cmpxchg() in several places in
2002 * the source does nothing. */
2003 if (ffs->setup_state == FFS_SETUP_PENDING)
2004 ffs->setup_state = FFS_SETUP_CANCELED;
2005
2006 switch (type) {
2007 case FUNCTIONFS_RESUME:
2008 rem_type2 = FUNCTIONFS_SUSPEND;
2009 /* FALL THGOUTH */
2010 case FUNCTIONFS_SUSPEND:
2011 case FUNCTIONFS_SETUP:
2012 rem_type1 = type;
2013 /* discard all similar events */
2014 break;
2015
2016 case FUNCTIONFS_BIND:
2017 case FUNCTIONFS_UNBIND:
2018 case FUNCTIONFS_DISABLE:
2019 case FUNCTIONFS_ENABLE:
2020 /* discard everything other then power management. */
2021 rem_type1 = FUNCTIONFS_SUSPEND;
2022 rem_type2 = FUNCTIONFS_RESUME;
2023 neg = 1;
2024 break;
2025
2026 default:
2027 BUG();
2028 }
2029
2030 {
2031 u8 *ev = ffs->ev.types, *out = ev;
2032 unsigned n = ffs->ev.count;
2033 for (; n; --n, ++ev)
2034 if ((*ev == rem_type1 || *ev == rem_type2) == neg)
2035 *out++ = *ev;
2036 else
2037 FVDBG("purging event %d", *ev);
2038 ffs->ev.count = out - ffs->ev.types;
2039 }
2040
2041 FVDBG("adding event %d", type);
2042 ffs->ev.types[ffs->ev.count++] = type;
2043 wake_up_locked(&ffs->ev.waitq);
2044}
2045
2046static void ffs_event_add(struct ffs_data *ffs,
2047 enum usb_functionfs_event_type type)
2048{
2049 unsigned long flags;
2050 spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
2051 __ffs_event_add(ffs, type);
2052 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
2053}
2054
2055
2056/* Bind/unbind USB function hooks *******************************************/
2057
2058static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
2059 struct usb_descriptor_header *desc,
2060 void *priv)
2061{
2062 struct usb_endpoint_descriptor *ds = (void *)desc;
2063 struct ffs_function *func = priv;
2064 struct ffs_ep *ffs_ep;
2065
2066 /* If hs_descriptors is not NULL then we are reading hs
2067 * descriptors now */
2068 const int isHS = func->function.hs_descriptors != NULL;
2069 unsigned idx;
2070
2071 if (type != FFS_DESCRIPTOR)
2072 return 0;
2073
2074 if (isHS)
2075 func->function.hs_descriptors[(long)valuep] = desc;
2076 else
2077 func->function.descriptors[(long)valuep] = desc;
2078
2079 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT)
2080 return 0;
2081
2082 idx = (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) - 1;
2083 ffs_ep = func->eps + idx;
2084
2085 if (unlikely(ffs_ep->descs[isHS])) {
2086 FVDBG("two %sspeed descriptors for EP %d",
2087 isHS ? "high" : "full",
2088 ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
2089 return -EINVAL;
2090 }
2091 ffs_ep->descs[isHS] = ds;
2092
2093 ffs_dump_mem(": Original ep desc", ds, ds->bLength);
2094 if (ffs_ep->ep) {
2095 ds->bEndpointAddress = ffs_ep->descs[0]->bEndpointAddress;
2096 if (!ds->wMaxPacketSize)
2097 ds->wMaxPacketSize = ffs_ep->descs[0]->wMaxPacketSize;
2098 } else {
2099 struct usb_request *req;
2100 struct usb_ep *ep;
2101
2102 FVDBG("autoconfig");
2103 ep = usb_ep_autoconfig(func->gadget, ds);
2104 if (unlikely(!ep))
2105 return -ENOTSUPP;
2106 ep->driver_data = func->eps + idx;;
2107
2108 req = usb_ep_alloc_request(ep, GFP_KERNEL);
2109 if (unlikely(!req))
2110 return -ENOMEM;
2111
2112 ffs_ep->ep = ep;
2113 ffs_ep->req = req;
2114 func->eps_revmap[ds->bEndpointAddress &
2115 USB_ENDPOINT_NUMBER_MASK] = idx + 1;
2116 }
2117 ffs_dump_mem(": Rewritten ep desc", ds, ds->bLength);
2118
2119 return 0;
2120}
2121
2122
2123static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep,
2124 struct usb_descriptor_header *desc,
2125 void *priv)
2126{
2127 struct ffs_function *func = priv;
2128 unsigned idx;
2129 u8 newValue;
2130
2131 switch (type) {
2132 default:
2133 case FFS_DESCRIPTOR:
2134 /* Handled in previous pass by __ffs_func_bind_do_descs() */
2135 return 0;
2136
2137 case FFS_INTERFACE:
2138 idx = *valuep;
2139 if (func->interfaces_nums[idx] < 0) {
2140 int id = usb_interface_id(func->conf, &func->function);
2141 if (unlikely(id < 0))
2142 return id;
2143 func->interfaces_nums[idx] = id;
2144 }
2145 newValue = func->interfaces_nums[idx];
2146 break;
2147
2148 case FFS_STRING:
2149 /* String' IDs are allocated when fsf_data is bound to cdev */
2150 newValue = func->ffs->stringtabs[0]->strings[*valuep - 1].id;
2151 break;
2152
2153 case FFS_ENDPOINT:
2154 /* USB_DT_ENDPOINT are handled in
2155 * __ffs_func_bind_do_descs(). */
2156 if (desc->bDescriptorType == USB_DT_ENDPOINT)
2157 return 0;
2158
2159 idx = (*valuep & USB_ENDPOINT_NUMBER_MASK) - 1;
2160 if (unlikely(!func->eps[idx].ep))
2161 return -EINVAL;
2162
2163 {
2164 struct usb_endpoint_descriptor **descs;
2165 descs = func->eps[idx].descs;
2166 newValue = descs[descs[0] ? 0 : 1]->bEndpointAddress;
2167 }
2168 break;
2169 }
2170
2171 FVDBG("%02x -> %02x", *valuep, newValue);
2172 *valuep = newValue;
2173 return 0;
2174}
2175
2176static int ffs_func_bind(struct usb_configuration *c,
2177 struct usb_function *f)
2178{
2179 struct ffs_function *func = ffs_func_from_usb(f);
2180 struct ffs_data *ffs = func->ffs;
2181
2182 const int full = !!func->ffs->fs_descs_count;
2183 const int high = gadget_is_dualspeed(func->gadget) &&
2184 func->ffs->hs_descs_count;
2185
2186 int ret;
2187
2188 /* Make it a single chunk, less management later on */
2189 struct {
2190 struct ffs_ep eps[ffs->eps_count];
2191 struct usb_descriptor_header
2192 *fs_descs[full ? ffs->fs_descs_count + 1 : 0];
2193 struct usb_descriptor_header
2194 *hs_descs[high ? ffs->hs_descs_count + 1 : 0];
2195 short inums[ffs->interfaces_count];
2196 char raw_descs[high ? ffs->raw_descs_length
2197 : ffs->raw_fs_descs_length];
2198 } *data;
2199
2200 ENTER();
2201
2202 /* Only high speed but not supported by gadget? */
2203 if (unlikely(!(full | high)))
2204 return -ENOTSUPP;
2205
2206 /* Allocate */
2207 data = kmalloc(sizeof *data, GFP_KERNEL);
2208 if (unlikely(!data))
2209 return -ENOMEM;
2210
2211 /* Zero */
2212 memset(data->eps, 0, sizeof data->eps);
2213 memcpy(data->raw_descs, ffs->raw_descs + 16, sizeof data->raw_descs);
2214 memset(data->inums, 0xff, sizeof data->inums);
2215 for (ret = ffs->eps_count; ret; --ret)
2216 data->eps[ret].num = -1;
2217
2218 /* Save pointers */
2219 func->eps = data->eps;
2220 func->interfaces_nums = data->inums;
2221
2222 /* Go throught all the endpoint descriptors and allocate
2223 * endpoints first, so that later we can rewrite the endpoint
2224 * numbers without worying that it may be described later on. */
2225 if (likely(full)) {
2226 func->function.descriptors = data->fs_descs;
2227 ret = ffs_do_descs(ffs->fs_descs_count,
2228 data->raw_descs,
2229 sizeof data->raw_descs,
2230 __ffs_func_bind_do_descs, func);
2231 if (unlikely(ret < 0))
2232 goto error;
2233 } else {
2234 ret = 0;
2235 }
2236
2237 if (likely(high)) {
2238 func->function.hs_descriptors = data->hs_descs;
2239 ret = ffs_do_descs(ffs->hs_descs_count,
2240 data->raw_descs + ret,
2241 (sizeof data->raw_descs) - ret,
2242 __ffs_func_bind_do_descs, func);
2243 }
2244
2245 /* Now handle interface numbers allocation and interface and
2246 * enpoint numbers rewritting. We can do that in one go
2247 * now. */
2248 ret = ffs_do_descs(ffs->fs_descs_count +
2249 (high ? ffs->hs_descs_count : 0),
2250 data->raw_descs, sizeof data->raw_descs,
2251 __ffs_func_bind_do_nums, func);
2252 if (unlikely(ret < 0))
2253 goto error;
2254
2255 /* And we're done */
2256 ffs_event_add(ffs, FUNCTIONFS_BIND);
2257 return 0;
2258
2259error:
2260 /* XXX Do we need to release all claimed endpoints here? */
2261 return ret;
2262}
2263
2264
2265/* Other USB function hooks *************************************************/
2266
2267static void ffs_func_unbind(struct usb_configuration *c,
2268 struct usb_function *f)
2269{
2270 struct ffs_function *func = ffs_func_from_usb(f);
2271 struct ffs_data *ffs = func->ffs;
2272
2273 ENTER();
2274
2275 if (ffs->func == func) {
2276 ffs_func_eps_disable(func);
2277 ffs->func = NULL;
2278 }
2279
2280 ffs_event_add(ffs, FUNCTIONFS_UNBIND);
2281
2282 ffs_func_free(func);
2283}
2284
2285
2286static int ffs_func_set_alt(struct usb_function *f,
2287 unsigned interface, unsigned alt)
2288{
2289 struct ffs_function *func = ffs_func_from_usb(f);
2290 struct ffs_data *ffs = func->ffs;
2291 int ret = 0, intf;
2292
2293 if (alt != (unsigned)-1) {
2294 intf = ffs_func_revmap_intf(func, interface);
2295 if (unlikely(intf < 0))
2296 return intf;
2297 }
2298
2299 if (ffs->func)
2300 ffs_func_eps_disable(ffs->func);
2301
2302 if (ffs->state != FFS_ACTIVE)
2303 return -ENODEV;
2304
2305 if (alt == (unsigned)-1) {
2306 ffs->func = NULL;
2307 ffs_event_add(ffs, FUNCTIONFS_DISABLE);
2308 return 0;
2309 }
2310
2311 ffs->func = func;
2312 ret = ffs_func_eps_enable(func);
2313 if (likely(ret >= 0))
2314 ffs_event_add(ffs, FUNCTIONFS_ENABLE);
2315 return ret;
2316}
2317
2318static void ffs_func_disable(struct usb_function *f)
2319{
2320 ffs_func_set_alt(f, 0, (unsigned)-1);
2321}
2322
2323static int ffs_func_setup(struct usb_function *f,
2324 const struct usb_ctrlrequest *creq)
2325{
2326 struct ffs_function *func = ffs_func_from_usb(f);
2327 struct ffs_data *ffs = func->ffs;
2328 unsigned long flags;
2329 int ret;
2330
2331 ENTER();
2332
2333 FVDBG("creq->bRequestType = %02x", creq->bRequestType);
2334 FVDBG("creq->bRequest = %02x", creq->bRequest);
2335 FVDBG("creq->wValue = %04x", le16_to_cpu(creq->wValue));
2336 FVDBG("creq->wIndex = %04x", le16_to_cpu(creq->wIndex));
2337 FVDBG("creq->wLength = %04x", le16_to_cpu(creq->wLength));
2338
2339 /* Most requests directed to interface go throught here
2340 * (notable exceptions are set/get interface) so we need to
2341 * handle them. All other either handled by composite or
2342 * passed to usb_configuration->setup() (if one is set). No
2343 * matter, we will handle requests directed to endpoint here
2344 * as well (as it's straightforward) but what to do with any
2345 * other request? */
2346
2347 if (ffs->state != FFS_ACTIVE)
2348 return -ENODEV;
2349
2350 switch (creq->bRequestType & USB_RECIP_MASK) {
2351 case USB_RECIP_INTERFACE:
2352 ret = ffs_func_revmap_intf(func, le16_to_cpu(creq->wIndex));
2353 if (unlikely(ret < 0))
2354 return ret;
2355 break;
2356
2357 case USB_RECIP_ENDPOINT:
2358 ret = ffs_func_revmap_ep(func, le16_to_cpu(creq->wIndex));
2359 if (unlikely(ret < 0))
2360 return ret;
2361 break;
2362
2363 default:
2364 return -EOPNOTSUPP;
2365 }
2366
2367 spin_lock_irqsave(&ffs->ev.waitq.lock, flags);
2368 ffs->ev.setup = *creq;
2369 ffs->ev.setup.wIndex = cpu_to_le16(ret);
2370 __ffs_event_add(ffs, FUNCTIONFS_SETUP);
2371 spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
2372
2373 return 0;
2374}
2375
2376static void ffs_func_suspend(struct usb_function *f)
2377{
2378 ENTER();
2379 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_SUSPEND);
2380}
2381
2382static void ffs_func_resume(struct usb_function *f)
2383{
2384 ENTER();
2385 ffs_event_add(ffs_func_from_usb(f)->ffs, FUNCTIONFS_RESUME);
2386}
2387
2388
2389
2390/* Enpoint and interface numbers reverse mapping ****************************/
2391
2392static int ffs_func_revmap_ep(struct ffs_function *func, u8 num)
2393{
2394 num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK];
2395 return num ? num : -EDOM;
2396}
2397
2398static int ffs_func_revmap_intf(struct ffs_function *func, u8 intf)
2399{
2400 short *nums = func->interfaces_nums;
2401 unsigned count = func->ffs->interfaces_count;
2402
2403 for (; count; --count, ++nums) {
2404 if (*nums >= 0 && *nums == intf)
2405 return nums - func->interfaces_nums;
2406 }
2407
2408 return -EDOM;
2409}
2410
2411
2412/* Misc helper functions ****************************************************/
2413
2414static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock)
2415{
2416 return nonblock
2417 ? likely(mutex_trylock(mutex)) ? 0 : -EAGAIN
2418 : mutex_lock_interruptible(mutex);
2419}
2420
2421
2422static char *ffs_prepare_buffer(const char * __user buf, size_t len)
2423{
2424 char *data;
2425
2426 if (unlikely(!len))
2427 return NULL;
2428
2429 data = kmalloc(len, GFP_KERNEL);
2430 if (unlikely(!data))
2431 return ERR_PTR(-ENOMEM);
2432
2433 if (unlikely(__copy_from_user(data, buf, len))) {
2434 kfree(data);
2435 return ERR_PTR(-EFAULT);
2436 }
2437
2438 FVDBG("Buffer from user space:");
2439 ffs_dump_mem("", data, len);
2440
2441 return data;
2442}
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
new file mode 100644
index 000000000000..1e00ff9866af
--- /dev/null
+++ b/drivers/usb/gadget/f_hid.c
@@ -0,0 +1,673 @@
1/*
2 * f_hid.c -- USB HID function driver
3 *
4 * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/utsname.h>
23#include <linux/module.h>
24#include <linux/hid.h>
25#include <linux/cdev.h>
26#include <linux/mutex.h>
27#include <linux/poll.h>
28#include <linux/smp_lock.h>
29#include <linux/uaccess.h>
30#include <linux/wait.h>
31#include <linux/usb/g_hid.h>
32
33static int major, minors;
34static struct class *hidg_class;
35
36/*-------------------------------------------------------------------------*/
37/* HID gadget struct */
38
39struct f_hidg {
40 /* configuration */
41 unsigned char bInterfaceSubClass;
42 unsigned char bInterfaceProtocol;
43 unsigned short report_desc_length;
44 char *report_desc;
45 unsigned short report_length;
46
47 /* recv report */
48 char *set_report_buff;
49 unsigned short set_report_length;
50 spinlock_t spinlock;
51 wait_queue_head_t read_queue;
52
53 /* send report */
54 struct mutex lock;
55 bool write_pending;
56 wait_queue_head_t write_queue;
57 struct usb_request *req;
58
59 int minor;
60 struct cdev cdev;
61 struct usb_function func;
62 struct usb_ep *in_ep;
63 struct usb_endpoint_descriptor *fs_in_ep_desc;
64 struct usb_endpoint_descriptor *hs_in_ep_desc;
65};
66
67static inline struct f_hidg *func_to_hidg(struct usb_function *f)
68{
69 return container_of(f, struct f_hidg, func);
70}
71
72/*-------------------------------------------------------------------------*/
73/* Static descriptors */
74
75static struct usb_interface_descriptor hidg_interface_desc = {
76 .bLength = sizeof hidg_interface_desc,
77 .bDescriptorType = USB_DT_INTERFACE,
78 /* .bInterfaceNumber = DYNAMIC */
79 .bAlternateSetting = 0,
80 .bNumEndpoints = 1,
81 .bInterfaceClass = USB_CLASS_HID,
82 /* .bInterfaceSubClass = DYNAMIC */
83 /* .bInterfaceProtocol = DYNAMIC */
84 /* .iInterface = DYNAMIC */
85};
86
87static struct hid_descriptor hidg_desc = {
88 .bLength = sizeof hidg_desc,
89 .bDescriptorType = HID_DT_HID,
90 .bcdHID = 0x0101,
91 .bCountryCode = 0x00,
92 .bNumDescriptors = 0x1,
93 /*.desc[0].bDescriptorType = DYNAMIC */
94 /*.desc[0].wDescriptorLenght = DYNAMIC */
95};
96
97/* High-Speed Support */
98
99static struct usb_endpoint_descriptor hidg_hs_in_ep_desc = {
100 .bLength = USB_DT_ENDPOINT_SIZE,
101 .bDescriptorType = USB_DT_ENDPOINT,
102 .bEndpointAddress = USB_DIR_IN,
103 .bmAttributes = USB_ENDPOINT_XFER_INT,
104 /*.wMaxPacketSize = DYNAMIC */
105 .bInterval = 4, /* FIXME: Add this field in the
106 * HID gadget configuration?
107 * (struct hidg_func_descriptor)
108 */
109};
110
111static struct usb_descriptor_header *hidg_hs_descriptors[] = {
112 (struct usb_descriptor_header *)&hidg_interface_desc,
113 (struct usb_descriptor_header *)&hidg_desc,
114 (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
115 NULL,
116};
117
118/* Full-Speed Support */
119
120static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
121 .bLength = USB_DT_ENDPOINT_SIZE,
122 .bDescriptorType = USB_DT_ENDPOINT,
123 .bEndpointAddress = USB_DIR_IN,
124 .bmAttributes = USB_ENDPOINT_XFER_INT,
125 /*.wMaxPacketSize = DYNAMIC */
126 .bInterval = 10, /* FIXME: Add this field in the
127 * HID gadget configuration?
128 * (struct hidg_func_descriptor)
129 */
130};
131
132static struct usb_descriptor_header *hidg_fs_descriptors[] = {
133 (struct usb_descriptor_header *)&hidg_interface_desc,
134 (struct usb_descriptor_header *)&hidg_desc,
135 (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
136 NULL,
137};
138
139/*-------------------------------------------------------------------------*/
140/* Char Device */
141
142static ssize_t f_hidg_read(struct file *file, char __user *buffer,
143 size_t count, loff_t *ptr)
144{
145 struct f_hidg *hidg = (struct f_hidg *)file->private_data;
146 char *tmp_buff = NULL;
147 unsigned long flags;
148
149 if (!count)
150 return 0;
151
152 if (!access_ok(VERIFY_WRITE, buffer, count))
153 return -EFAULT;
154
155 spin_lock_irqsave(&hidg->spinlock, flags);
156
157#define READ_COND (hidg->set_report_buff != NULL)
158
159 while (!READ_COND) {
160 spin_unlock_irqrestore(&hidg->spinlock, flags);
161 if (file->f_flags & O_NONBLOCK)
162 return -EAGAIN;
163
164 if (wait_event_interruptible(hidg->read_queue, READ_COND))
165 return -ERESTARTSYS;
166
167 spin_lock_irqsave(&hidg->spinlock, flags);
168 }
169
170
171 count = min_t(unsigned, count, hidg->set_report_length);
172 tmp_buff = hidg->set_report_buff;
173 hidg->set_report_buff = NULL;
174
175 spin_unlock_irqrestore(&hidg->spinlock, flags);
176
177 if (tmp_buff != NULL) {
178 /* copy to user outside spinlock */
179 count -= copy_to_user(buffer, tmp_buff, count);
180 kfree(tmp_buff);
181 } else
182 count = -ENOMEM;
183
184 return count;
185}
186
187static void f_hidg_req_complete(struct usb_ep *ep, struct usb_request *req)
188{
189 struct f_hidg *hidg = (struct f_hidg *)ep->driver_data;
190
191 if (req->status != 0) {
192 ERROR(hidg->func.config->cdev,
193 "End Point Request ERROR: %d\n", req->status);
194 }
195
196 hidg->write_pending = 0;
197 wake_up(&hidg->write_queue);
198}
199
200static ssize_t f_hidg_write(struct file *file, const char __user *buffer,
201 size_t count, loff_t *offp)
202{
203 struct f_hidg *hidg = (struct f_hidg *)file->private_data;
204 ssize_t status = -ENOMEM;
205
206 if (!access_ok(VERIFY_READ, buffer, count))
207 return -EFAULT;
208
209 mutex_lock(&hidg->lock);
210
211#define WRITE_COND (!hidg->write_pending)
212
213 /* write queue */
214 while (!WRITE_COND) {
215 mutex_unlock(&hidg->lock);
216 if (file->f_flags & O_NONBLOCK)
217 return -EAGAIN;
218
219 if (wait_event_interruptible_exclusive(
220 hidg->write_queue, WRITE_COND))
221 return -ERESTARTSYS;
222
223 mutex_lock(&hidg->lock);
224 }
225
226 count = min_t(unsigned, count, hidg->report_length);
227 status = copy_from_user(hidg->req->buf, buffer, count);
228
229 if (status != 0) {
230 ERROR(hidg->func.config->cdev,
231 "copy_from_user error\n");
232 mutex_unlock(&hidg->lock);
233 return -EINVAL;
234 }
235
236 hidg->req->status = 0;
237 hidg->req->zero = 0;
238 hidg->req->length = count;
239 hidg->req->complete = f_hidg_req_complete;
240 hidg->req->context = hidg;
241 hidg->write_pending = 1;
242
243 status = usb_ep_queue(hidg->in_ep, hidg->req, GFP_ATOMIC);
244 if (status < 0) {
245 ERROR(hidg->func.config->cdev,
246 "usb_ep_queue error on int endpoint %zd\n", status);
247 hidg->write_pending = 0;
248 wake_up(&hidg->write_queue);
249 } else {
250 status = count;
251 }
252
253 mutex_unlock(&hidg->lock);
254
255 return status;
256}
257
258static unsigned int f_hidg_poll(struct file *file, poll_table *wait)
259{
260 struct f_hidg *hidg = (struct f_hidg *)file->private_data;
261 unsigned int ret = 0;
262
263 poll_wait(file, &hidg->read_queue, wait);
264 poll_wait(file, &hidg->write_queue, wait);
265
266 if (WRITE_COND)
267 ret |= POLLOUT | POLLWRNORM;
268
269 if (READ_COND)
270 ret |= POLLIN | POLLRDNORM;
271
272 return ret;
273}
274
275#undef WRITE_COND
276#undef READ_COND
277
278static int f_hidg_release(struct inode *inode, struct file *fd)
279{
280 fd->private_data = NULL;
281 return 0;
282}
283
284static int f_hidg_open(struct inode *inode, struct file *fd)
285{
286 struct f_hidg *hidg =
287 container_of(inode->i_cdev, struct f_hidg, cdev);
288
289 fd->private_data = hidg;
290
291 return 0;
292}
293
294/*-------------------------------------------------------------------------*/
295/* usb_function */
296
297static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
298{
299 struct f_hidg *hidg = (struct f_hidg *)req->context;
300
301 if (req->status != 0 || req->buf == NULL || req->actual == 0) {
302 ERROR(hidg->func.config->cdev, "%s FAILED\n", __func__);
303 return;
304 }
305
306 spin_lock(&hidg->spinlock);
307
308 hidg->set_report_buff = krealloc(hidg->set_report_buff,
309 req->actual, GFP_ATOMIC);
310
311 if (hidg->set_report_buff == NULL) {
312 spin_unlock(&hidg->spinlock);
313 return;
314 }
315 hidg->set_report_length = req->actual;
316 memcpy(hidg->set_report_buff, req->buf, req->actual);
317
318 spin_unlock(&hidg->spinlock);
319
320 wake_up(&hidg->read_queue);
321
322 return;
323}
324
325static int hidg_setup(struct usb_function *f,
326 const struct usb_ctrlrequest *ctrl)
327{
328 struct f_hidg *hidg = func_to_hidg(f);
329 struct usb_composite_dev *cdev = f->config->cdev;
330 struct usb_request *req = cdev->req;
331 int status = 0;
332 __u16 value, length;
333
334 value = __le16_to_cpu(ctrl->wValue);
335 length = __le16_to_cpu(ctrl->wLength);
336
337 VDBG(cdev, "hid_setup crtl_request : bRequestType:0x%x bRequest:0x%x "
338 "Value:0x%x\n", ctrl->bRequestType, ctrl->bRequest, value);
339
340 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
341 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
342 | HID_REQ_GET_REPORT):
343 VDBG(cdev, "get_report\n");
344
345 /* send an empty report */
346 length = min_t(unsigned, length, hidg->report_length);
347 memset(req->buf, 0x0, length);
348
349 goto respond;
350 break;
351
352 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
353 | HID_REQ_GET_PROTOCOL):
354 VDBG(cdev, "get_protocol\n");
355 goto stall;
356 break;
357
358 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
359 | HID_REQ_SET_REPORT):
360 VDBG(cdev, "set_report | wLenght=%d\n", ctrl->wLength);
361 req->context = hidg;
362 req->complete = hidg_set_report_complete;
363 goto respond;
364 break;
365
366 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8
367 | HID_REQ_SET_PROTOCOL):
368 VDBG(cdev, "set_protocol\n");
369 goto stall;
370 break;
371
372 case ((USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_INTERFACE) << 8
373 | USB_REQ_GET_DESCRIPTOR):
374 switch (value >> 8) {
375 case HID_DT_REPORT:
376 VDBG(cdev, "USB_REQ_GET_DESCRIPTOR: REPORT\n");
377 length = min_t(unsigned short, length,
378 hidg->report_desc_length);
379 memcpy(req->buf, hidg->report_desc, length);
380 goto respond;
381 break;
382
383 default:
384 VDBG(cdev, "Unknown decriptor request 0x%x\n",
385 value >> 8);
386 goto stall;
387 break;
388 }
389 break;
390
391 default:
392 VDBG(cdev, "Unknown request 0x%x\n",
393 ctrl->bRequest);
394 goto stall;
395 break;
396 }
397
398stall:
399 return -EOPNOTSUPP;
400
401respond:
402 req->zero = 0;
403 req->length = length;
404 status = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
405 if (status < 0)
406 ERROR(cdev, "usb_ep_queue error on ep0 %d\n", value);
407 return status;
408}
409
410static void hidg_disable(struct usb_function *f)
411{
412 struct f_hidg *hidg = func_to_hidg(f);
413
414 usb_ep_disable(hidg->in_ep);
415 hidg->in_ep->driver_data = NULL;
416
417 return;
418}
419
420static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
421{
422 struct usb_composite_dev *cdev = f->config->cdev;
423 struct f_hidg *hidg = func_to_hidg(f);
424 const struct usb_endpoint_descriptor *ep_desc;
425 int status = 0;
426
427 VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
428
429 if (hidg->in_ep != NULL) {
430 /* restart endpoint */
431 if (hidg->in_ep->driver_data != NULL)
432 usb_ep_disable(hidg->in_ep);
433
434 ep_desc = ep_choose(f->config->cdev->gadget,
435 hidg->hs_in_ep_desc, hidg->fs_in_ep_desc);
436 status = usb_ep_enable(hidg->in_ep, ep_desc);
437 if (status < 0) {
438 ERROR(cdev, "Enable endpoint FAILED!\n");
439 goto fail;
440 }
441 hidg->in_ep->driver_data = hidg;
442 }
443fail:
444 return status;
445}
446
447const struct file_operations f_hidg_fops = {
448 .owner = THIS_MODULE,
449 .open = f_hidg_open,
450 .release = f_hidg_release,
451 .write = f_hidg_write,
452 .read = f_hidg_read,
453 .poll = f_hidg_poll,
454};
455
456static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
457{
458 struct usb_ep *ep;
459 struct f_hidg *hidg = func_to_hidg(f);
460 int status;
461 dev_t dev;
462
463 /* allocate instance-specific interface IDs, and patch descriptors */
464 status = usb_interface_id(c, f);
465 if (status < 0)
466 goto fail;
467 hidg_interface_desc.bInterfaceNumber = status;
468
469
470 /* allocate instance-specific endpoints */
471 status = -ENODEV;
472 ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_in_ep_desc);
473 if (!ep)
474 goto fail;
475 ep->driver_data = c->cdev; /* claim */
476 hidg->in_ep = ep;
477
478 /* preallocate request and buffer */
479 status = -ENOMEM;
480 hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
481 if (!hidg->req)
482 goto fail;
483
484
485 hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
486 if (!hidg->req->buf)
487 goto fail;
488
489 /* set descriptor dynamic values */
490 hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
491 hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
492 hidg_hs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
493 hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
494 hidg_desc.desc[0].bDescriptorType = HID_DT_REPORT;
495 hidg_desc.desc[0].wDescriptorLength =
496 cpu_to_le16(hidg->report_desc_length);
497
498 hidg->set_report_buff = NULL;
499
500 /* copy descriptors */
501 f->descriptors = usb_copy_descriptors(hidg_fs_descriptors);
502 if (!f->descriptors)
503 goto fail;
504
505 hidg->fs_in_ep_desc = usb_find_endpoint(hidg_fs_descriptors,
506 f->descriptors,
507 &hidg_fs_in_ep_desc);
508
509 if (gadget_is_dualspeed(c->cdev->gadget)) {
510 hidg_hs_in_ep_desc.bEndpointAddress =
511 hidg_fs_in_ep_desc.bEndpointAddress;
512 f->hs_descriptors = usb_copy_descriptors(hidg_hs_descriptors);
513 if (!f->hs_descriptors)
514 goto fail;
515 hidg->hs_in_ep_desc = usb_find_endpoint(hidg_hs_descriptors,
516 f->hs_descriptors,
517 &hidg_hs_in_ep_desc);
518 } else {
519 hidg->hs_in_ep_desc = NULL;
520 }
521
522 mutex_init(&hidg->lock);
523 spin_lock_init(&hidg->spinlock);
524 init_waitqueue_head(&hidg->write_queue);
525 init_waitqueue_head(&hidg->read_queue);
526
527 /* create char device */
528 cdev_init(&hidg->cdev, &f_hidg_fops);
529 dev = MKDEV(major, hidg->minor);
530 status = cdev_add(&hidg->cdev, dev, 1);
531 if (status)
532 goto fail;
533
534 device_create(hidg_class, NULL, dev, NULL, "%s%d", "hidg", hidg->minor);
535
536 return 0;
537
538fail:
539 ERROR(f->config->cdev, "hidg_bind FAILED\n");
540 if (hidg->req != NULL) {
541 kfree(hidg->req->buf);
542 if (hidg->in_ep != NULL)
543 usb_ep_free_request(hidg->in_ep, hidg->req);
544 }
545
546 usb_free_descriptors(f->hs_descriptors);
547 usb_free_descriptors(f->descriptors);
548
549 return status;
550}
551
552static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
553{
554 struct f_hidg *hidg = func_to_hidg(f);
555
556 device_destroy(hidg_class, MKDEV(major, hidg->minor));
557 cdev_del(&hidg->cdev);
558
559 /* disable/free request and end point */
560 usb_ep_disable(hidg->in_ep);
561 usb_ep_dequeue(hidg->in_ep, hidg->req);
562 kfree(hidg->req->buf);
563 usb_ep_free_request(hidg->in_ep, hidg->req);
564
565 /* free descriptors copies */
566 usb_free_descriptors(f->hs_descriptors);
567 usb_free_descriptors(f->descriptors);
568
569 kfree(hidg->report_desc);
570 kfree(hidg->set_report_buff);
571 kfree(hidg);
572}
573
574/*-------------------------------------------------------------------------*/
575/* Strings */
576
577#define CT_FUNC_HID_IDX 0
578
579static struct usb_string ct_func_string_defs[] = {
580 [CT_FUNC_HID_IDX].s = "HID Interface",
581 {}, /* end of list */
582};
583
584static struct usb_gadget_strings ct_func_string_table = {
585 .language = 0x0409, /* en-US */
586 .strings = ct_func_string_defs,
587};
588
589static struct usb_gadget_strings *ct_func_strings[] = {
590 &ct_func_string_table,
591 NULL,
592};
593
594/*-------------------------------------------------------------------------*/
595/* usb_configuration */
596
597int __init hidg_bind_config(struct usb_configuration *c,
598 struct hidg_func_descriptor *fdesc, int index)
599{
600 struct f_hidg *hidg;
601 int status;
602
603 if (index >= minors)
604 return -ENOENT;
605
606 /* maybe allocate device-global string IDs, and patch descriptors */
607 if (ct_func_string_defs[CT_FUNC_HID_IDX].id == 0) {
608 status = usb_string_id(c->cdev);
609 if (status < 0)
610 return status;
611 ct_func_string_defs[CT_FUNC_HID_IDX].id = status;
612 hidg_interface_desc.iInterface = status;
613 }
614
615 /* allocate and initialize one new instance */
616 hidg = kzalloc(sizeof *hidg, GFP_KERNEL);
617 if (!hidg)
618 return -ENOMEM;
619
620 hidg->minor = index;
621 hidg->bInterfaceSubClass = fdesc->subclass;
622 hidg->bInterfaceProtocol = fdesc->protocol;
623 hidg->report_length = fdesc->report_length;
624 hidg->report_desc_length = fdesc->report_desc_length;
625 hidg->report_desc = kmemdup(fdesc->report_desc,
626 fdesc->report_desc_length,
627 GFP_KERNEL);
628 if (!hidg->report_desc) {
629 kfree(hidg);
630 return -ENOMEM;
631 }
632
633 hidg->func.name = "hid";
634 hidg->func.strings = ct_func_strings;
635 hidg->func.bind = hidg_bind;
636 hidg->func.unbind = hidg_unbind;
637 hidg->func.set_alt = hidg_set_alt;
638 hidg->func.disable = hidg_disable;
639 hidg->func.setup = hidg_setup;
640
641 status = usb_add_function(c, &hidg->func);
642 if (status)
643 kfree(hidg);
644
645 return status;
646}
647
648int __init ghid_setup(struct usb_gadget *g, int count)
649{
650 int status;
651 dev_t dev;
652
653 hidg_class = class_create(THIS_MODULE, "hidg");
654
655 status = alloc_chrdev_region(&dev, 0, count, "hidg");
656 if (!status) {
657 major = MAJOR(dev);
658 minors = count;
659 }
660
661 return status;
662}
663
664void ghid_cleanup(void)
665{
666 if (major) {
667 unregister_chrdev_region(MKDEV(major, 0), minors);
668 major = minors = 0;
669 }
670
671 class_destroy(hidg_class);
672 hidg_class = NULL;
673}
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index f4911c09022e..7d05a0be5c60 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -163,6 +163,10 @@
163 * ro setting are not allowed when the medium is loaded or if CD-ROM 163 * ro setting are not allowed when the medium is loaded or if CD-ROM
164 * emulation is being used. 164 * emulation is being used.
165 * 165 *
166 * When a LUN receive an "eject" SCSI request (Start/Stop Unit),
167 * if the LUN is removable, the backing file is released to simulate
168 * ejection.
169 *
166 * 170 *
167 * This function is heavily based on "File-backed Storage Gadget" by 171 * This function is heavily based on "File-backed Storage Gadget" by
168 * Alan Stern which in turn is heavily based on "Gadget Zero" by David 172 * Alan Stern which in turn is heavily based on "Gadget Zero" by David
@@ -302,7 +306,6 @@ static const char fsg_string_interface[] = "Mass Storage";
302 306
303 307
304#define FSG_NO_INTR_EP 1 308#define FSG_NO_INTR_EP 1
305#define FSG_BUFFHD_STATIC_BUFFER 1
306#define FSG_NO_DEVICE_STRINGS 1 309#define FSG_NO_DEVICE_STRINGS 1
307#define FSG_NO_OTG 1 310#define FSG_NO_OTG 1
308#define FSG_NO_INTR_EP 1 311#define FSG_NO_INTR_EP 1
@@ -1385,12 +1388,50 @@ static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1385 1388
1386static int do_start_stop(struct fsg_common *common) 1389static int do_start_stop(struct fsg_common *common)
1387{ 1390{
1388 if (!common->curlun) { 1391 struct fsg_lun *curlun = common->curlun;
1392 int loej, start;
1393
1394 if (!curlun) {
1389 return -EINVAL; 1395 return -EINVAL;
1390 } else if (!common->curlun->removable) { 1396 } else if (!curlun->removable) {
1391 common->curlun->sense_data = SS_INVALID_COMMAND; 1397 curlun->sense_data = SS_INVALID_COMMAND;
1392 return -EINVAL; 1398 return -EINVAL;
1393 } 1399 }
1400
1401 loej = common->cmnd[4] & 0x02;
1402 start = common->cmnd[4] & 0x01;
1403
1404 /* eject code from file_storage.c:do_start_stop() */
1405
1406 if ((common->cmnd[1] & ~0x01) != 0 || /* Mask away Immed */
1407 (common->cmnd[4] & ~0x03) != 0) { /* Mask LoEj, Start */
1408 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1409 return -EINVAL;
1410 }
1411
1412 if (!start) {
1413 /* Are we allowed to unload the media? */
1414 if (curlun->prevent_medium_removal) {
1415 LDBG(curlun, "unload attempt prevented\n");
1416 curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
1417 return -EINVAL;
1418 }
1419 if (loej) { /* Simulate an unload/eject */
1420 up_read(&common->filesem);
1421 down_write(&common->filesem);
1422 fsg_lun_close(curlun);
1423 up_write(&common->filesem);
1424 down_read(&common->filesem);
1425 }
1426 } else {
1427
1428 /* Our emulation doesn't support mounting; the medium is
1429 * available for use as soon as it is loaded. */
1430 if (!fsg_lun_is_open(curlun)) {
1431 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
1432 return -EINVAL;
1433 }
1434 }
1394 return 0; 1435 return 0;
1395} 1436}
1396 1437
@@ -2701,10 +2742,8 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2701 /* Maybe allocate device-global string IDs, and patch descriptors */ 2742 /* Maybe allocate device-global string IDs, and patch descriptors */
2702 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) { 2743 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
2703 rc = usb_string_id(cdev); 2744 rc = usb_string_id(cdev);
2704 if (rc < 0) { 2745 if (unlikely(rc < 0))
2705 kfree(common); 2746 goto error_release;
2706 return ERR_PTR(rc);
2707 }
2708 fsg_strings[FSG_STRING_INTERFACE].id = rc; 2747 fsg_strings[FSG_STRING_INTERFACE].id = rc;
2709 fsg_intf_desc.iInterface = rc; 2748 fsg_intf_desc.iInterface = rc;
2710 } 2749 }
@@ -2712,9 +2751,9 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2712 /* Create the LUNs, open their backing files, and register the 2751 /* Create the LUNs, open their backing files, and register the
2713 * LUN devices in sysfs. */ 2752 * LUN devices in sysfs. */
2714 curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL); 2753 curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL);
2715 if (!curlun) { 2754 if (unlikely(!curlun)) {
2716 kfree(common); 2755 rc = -ENOMEM;
2717 return ERR_PTR(-ENOMEM); 2756 goto error_release;
2718 } 2757 }
2719 common->luns = curlun; 2758 common->luns = curlun;
2720 2759
@@ -2762,13 +2801,19 @@ static struct fsg_common *fsg_common_init(struct fsg_common *common,
2762 2801
2763 2802
2764 /* Data buffers cyclic list */ 2803 /* Data buffers cyclic list */
2765 /* Buffers in buffhds are static -- no need for additional
2766 * allocation. */
2767 bh = common->buffhds; 2804 bh = common->buffhds;
2768 i = FSG_NUM_BUFFERS - 1; 2805 i = FSG_NUM_BUFFERS;
2806 goto buffhds_first_it;
2769 do { 2807 do {
2770 bh->next = bh + 1; 2808 bh->next = bh + 1;
2771 } while (++bh, --i); 2809 ++bh;
2810buffhds_first_it:
2811 bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
2812 if (unlikely(!bh->buf)) {
2813 rc = -ENOMEM;
2814 goto error_release;
2815 }
2816 } while (--i);
2772 bh->next = common->buffhds; 2817 bh->next = common->buffhds;
2773 2818
2774 2819
@@ -2867,10 +2912,7 @@ error_release:
2867 2912
2868static void fsg_common_release(struct kref *ref) 2913static void fsg_common_release(struct kref *ref)
2869{ 2914{
2870 struct fsg_common *common = 2915 struct fsg_common *common = container_of(ref, struct fsg_common, ref);
2871 container_of(ref, struct fsg_common, ref);
2872 unsigned i = common->nluns;
2873 struct fsg_lun *lun = common->luns;
2874 2916
2875 /* If the thread isn't already dead, tell it to exit now */ 2917 /* If the thread isn't already dead, tell it to exit now */
2876 if (common->state != FSG_STATE_TERMINATED) { 2918 if (common->state != FSG_STATE_TERMINATED) {
@@ -2881,17 +2923,29 @@ static void fsg_common_release(struct kref *ref)
2881 complete(&common->thread_notifier); 2923 complete(&common->thread_notifier);
2882 } 2924 }
2883 2925
2884 /* Beware tempting for -> do-while optimization: when in error 2926 if (likely(common->luns)) {
2885 * recovery nluns may be zero. */ 2927 struct fsg_lun *lun = common->luns;
2928 unsigned i = common->nluns;
2929
2930 /* In error recovery common->nluns may be zero. */
2931 for (; i; --i, ++lun) {
2932 device_remove_file(&lun->dev, &dev_attr_ro);
2933 device_remove_file(&lun->dev, &dev_attr_file);
2934 fsg_lun_close(lun);
2935 device_unregister(&lun->dev);
2936 }
2937
2938 kfree(common->luns);
2939 }
2886 2940
2887 for (; i; --i, ++lun) { 2941 {
2888 device_remove_file(&lun->dev, &dev_attr_ro); 2942 struct fsg_buffhd *bh = common->buffhds;
2889 device_remove_file(&lun->dev, &dev_attr_file); 2943 unsigned i = FSG_NUM_BUFFERS;
2890 fsg_lun_close(lun); 2944 do {
2891 device_unregister(&lun->dev); 2945 kfree(bh->buf);
2946 } while (++bh, --i);
2892 } 2947 }
2893 2948
2894 kfree(common->luns);
2895 if (common->free_storage_on_release) 2949 if (common->free_storage_on_release)
2896 kfree(common); 2950 kfree(common);
2897} 2951}
@@ -2906,11 +2960,13 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2906 2960
2907 DBG(fsg, "unbind\n"); 2961 DBG(fsg, "unbind\n");
2908 fsg_common_put(fsg->common); 2962 fsg_common_put(fsg->common);
2963 usb_free_descriptors(fsg->function.descriptors);
2964 usb_free_descriptors(fsg->function.hs_descriptors);
2909 kfree(fsg); 2965 kfree(fsg);
2910} 2966}
2911 2967
2912 2968
2913static int __init fsg_bind(struct usb_configuration *c, struct usb_function *f) 2969static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
2914{ 2970{
2915 struct fsg_dev *fsg = fsg_from_func(f); 2971 struct fsg_dev *fsg = fsg_from_func(f);
2916 struct usb_gadget *gadget = c->cdev->gadget; 2972 struct usb_gadget *gadget = c->cdev->gadget;
@@ -2946,7 +3002,9 @@ static int __init fsg_bind(struct usb_configuration *c, struct usb_function *f)
2946 fsg_fs_bulk_in_desc.bEndpointAddress; 3002 fsg_fs_bulk_in_desc.bEndpointAddress;
2947 fsg_hs_bulk_out_desc.bEndpointAddress = 3003 fsg_hs_bulk_out_desc.bEndpointAddress =
2948 fsg_fs_bulk_out_desc.bEndpointAddress; 3004 fsg_fs_bulk_out_desc.bEndpointAddress;
2949 f->hs_descriptors = fsg_hs_function; 3005 f->hs_descriptors = usb_copy_descriptors(fsg_hs_function);
3006 if (unlikely(!f->hs_descriptors))
3007 return -ENOMEM;
2950 } 3008 }
2951 3009
2952 return 0; 3010 return 0;
@@ -2978,7 +3036,11 @@ static int fsg_add(struct usb_composite_dev *cdev,
2978 3036
2979 fsg->function.name = FSG_DRIVER_DESC; 3037 fsg->function.name = FSG_DRIVER_DESC;
2980 fsg->function.strings = fsg_strings_array; 3038 fsg->function.strings = fsg_strings_array;
2981 fsg->function.descriptors = fsg_fs_function; 3039 fsg->function.descriptors = usb_copy_descriptors(fsg_fs_function);
3040 if (unlikely(!fsg->function.descriptors)) {
3041 rc = -ENOMEM;
3042 goto error_free_fsg;
3043 }
2982 fsg->function.bind = fsg_bind; 3044 fsg->function.bind = fsg_bind;
2983 fsg->function.unbind = fsg_unbind; 3045 fsg->function.unbind = fsg_unbind;
2984 fsg->function.setup = fsg_setup; 3046 fsg->function.setup = fsg_setup;
@@ -2993,11 +3055,19 @@ static int fsg_add(struct usb_composite_dev *cdev,
2993 * call to usb_add_function() was successful. */ 3055 * call to usb_add_function() was successful. */
2994 3056
2995 rc = usb_add_function(c, &fsg->function); 3057 rc = usb_add_function(c, &fsg->function);
3058 if (unlikely(rc))
3059 goto error_free_all;
2996 3060
2997 if (likely(rc == 0)) 3061 fsg_common_get(fsg->common);
2998 fsg_common_get(fsg->common); 3062 return 0;
2999 else 3063
3000 kfree(fsg); 3064error_free_all:
3065 usb_free_descriptors(fsg->function.descriptors);
3066 /* fsg_bind() might have copied those; or maybe not? who cares
3067 * -- free it just in case. */
3068 usb_free_descriptors(fsg->function.hs_descriptors);
3069error_free_fsg:
3070 kfree(fsg);
3001 3071
3002 return rc; 3072 return rc;
3003} 3073}
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 56b022150f22..882484a40398 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -122,7 +122,7 @@ static unsigned int bitrate(struct usb_gadget *g)
122 122
123/* interface descriptor: */ 123/* interface descriptor: */
124 124
125static struct usb_interface_descriptor rndis_control_intf __initdata = { 125static struct usb_interface_descriptor rndis_control_intf = {
126 .bLength = sizeof rndis_control_intf, 126 .bLength = sizeof rndis_control_intf,
127 .bDescriptorType = USB_DT_INTERFACE, 127 .bDescriptorType = USB_DT_INTERFACE,
128 128
@@ -135,7 +135,7 @@ static struct usb_interface_descriptor rndis_control_intf __initdata = {
135 /* .iInterface = DYNAMIC */ 135 /* .iInterface = DYNAMIC */
136}; 136};
137 137
138static struct usb_cdc_header_desc header_desc __initdata = { 138static struct usb_cdc_header_desc header_desc = {
139 .bLength = sizeof header_desc, 139 .bLength = sizeof header_desc,
140 .bDescriptorType = USB_DT_CS_INTERFACE, 140 .bDescriptorType = USB_DT_CS_INTERFACE,
141 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 141 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
@@ -143,7 +143,7 @@ static struct usb_cdc_header_desc header_desc __initdata = {
143 .bcdCDC = cpu_to_le16(0x0110), 143 .bcdCDC = cpu_to_le16(0x0110),
144}; 144};
145 145
146static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = { 146static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
147 .bLength = sizeof call_mgmt_descriptor, 147 .bLength = sizeof call_mgmt_descriptor,
148 .bDescriptorType = USB_DT_CS_INTERFACE, 148 .bDescriptorType = USB_DT_CS_INTERFACE,
149 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE, 149 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
@@ -152,7 +152,7 @@ static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = {
152 .bDataInterface = 0x01, 152 .bDataInterface = 0x01,
153}; 153};
154 154
155static struct usb_cdc_acm_descriptor rndis_acm_descriptor __initdata = { 155static struct usb_cdc_acm_descriptor rndis_acm_descriptor = {
156 .bLength = sizeof rndis_acm_descriptor, 156 .bLength = sizeof rndis_acm_descriptor,
157 .bDescriptorType = USB_DT_CS_INTERFACE, 157 .bDescriptorType = USB_DT_CS_INTERFACE,
158 .bDescriptorSubType = USB_CDC_ACM_TYPE, 158 .bDescriptorSubType = USB_CDC_ACM_TYPE,
@@ -160,7 +160,7 @@ static struct usb_cdc_acm_descriptor rndis_acm_descriptor __initdata = {
160 .bmCapabilities = 0x00, 160 .bmCapabilities = 0x00,
161}; 161};
162 162
163static struct usb_cdc_union_desc rndis_union_desc __initdata = { 163static struct usb_cdc_union_desc rndis_union_desc = {
164 .bLength = sizeof(rndis_union_desc), 164 .bLength = sizeof(rndis_union_desc),
165 .bDescriptorType = USB_DT_CS_INTERFACE, 165 .bDescriptorType = USB_DT_CS_INTERFACE,
166 .bDescriptorSubType = USB_CDC_UNION_TYPE, 166 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -170,7 +170,7 @@ static struct usb_cdc_union_desc rndis_union_desc __initdata = {
170 170
171/* the data interface has two bulk endpoints */ 171/* the data interface has two bulk endpoints */
172 172
173static struct usb_interface_descriptor rndis_data_intf __initdata = { 173static struct usb_interface_descriptor rndis_data_intf = {
174 .bLength = sizeof rndis_data_intf, 174 .bLength = sizeof rndis_data_intf,
175 .bDescriptorType = USB_DT_INTERFACE, 175 .bDescriptorType = USB_DT_INTERFACE,
176 176
@@ -198,7 +198,7 @@ rndis_iad_descriptor = {
198 198
199/* full speed support: */ 199/* full speed support: */
200 200
201static struct usb_endpoint_descriptor fs_notify_desc __initdata = { 201static struct usb_endpoint_descriptor fs_notify_desc = {
202 .bLength = USB_DT_ENDPOINT_SIZE, 202 .bLength = USB_DT_ENDPOINT_SIZE,
203 .bDescriptorType = USB_DT_ENDPOINT, 203 .bDescriptorType = USB_DT_ENDPOINT,
204 204
@@ -208,7 +208,7 @@ static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
208 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 208 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
209}; 209};
210 210
211static struct usb_endpoint_descriptor fs_in_desc __initdata = { 211static struct usb_endpoint_descriptor fs_in_desc = {
212 .bLength = USB_DT_ENDPOINT_SIZE, 212 .bLength = USB_DT_ENDPOINT_SIZE,
213 .bDescriptorType = USB_DT_ENDPOINT, 213 .bDescriptorType = USB_DT_ENDPOINT,
214 214
@@ -216,7 +216,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = {
216 .bmAttributes = USB_ENDPOINT_XFER_BULK, 216 .bmAttributes = USB_ENDPOINT_XFER_BULK,
217}; 217};
218 218
219static struct usb_endpoint_descriptor fs_out_desc __initdata = { 219static struct usb_endpoint_descriptor fs_out_desc = {
220 .bLength = USB_DT_ENDPOINT_SIZE, 220 .bLength = USB_DT_ENDPOINT_SIZE,
221 .bDescriptorType = USB_DT_ENDPOINT, 221 .bDescriptorType = USB_DT_ENDPOINT,
222 222
@@ -224,7 +224,7 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = {
224 .bmAttributes = USB_ENDPOINT_XFER_BULK, 224 .bmAttributes = USB_ENDPOINT_XFER_BULK,
225}; 225};
226 226
227static struct usb_descriptor_header *eth_fs_function[] __initdata = { 227static struct usb_descriptor_header *eth_fs_function[] = {
228 (struct usb_descriptor_header *) &rndis_iad_descriptor, 228 (struct usb_descriptor_header *) &rndis_iad_descriptor,
229 /* control interface matches ACM, not Ethernet */ 229 /* control interface matches ACM, not Ethernet */
230 (struct usb_descriptor_header *) &rndis_control_intf, 230 (struct usb_descriptor_header *) &rndis_control_intf,
@@ -242,7 +242,7 @@ static struct usb_descriptor_header *eth_fs_function[] __initdata = {
242 242
243/* high speed support: */ 243/* high speed support: */
244 244
245static struct usb_endpoint_descriptor hs_notify_desc __initdata = { 245static struct usb_endpoint_descriptor hs_notify_desc = {
246 .bLength = USB_DT_ENDPOINT_SIZE, 246 .bLength = USB_DT_ENDPOINT_SIZE,
247 .bDescriptorType = USB_DT_ENDPOINT, 247 .bDescriptorType = USB_DT_ENDPOINT,
248 248
@@ -251,7 +251,7 @@ static struct usb_endpoint_descriptor hs_notify_desc __initdata = {
251 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), 251 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
252 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 252 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
253}; 253};
254static struct usb_endpoint_descriptor hs_in_desc __initdata = { 254static struct usb_endpoint_descriptor hs_in_desc = {
255 .bLength = USB_DT_ENDPOINT_SIZE, 255 .bLength = USB_DT_ENDPOINT_SIZE,
256 .bDescriptorType = USB_DT_ENDPOINT, 256 .bDescriptorType = USB_DT_ENDPOINT,
257 257
@@ -260,7 +260,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
260 .wMaxPacketSize = cpu_to_le16(512), 260 .wMaxPacketSize = cpu_to_le16(512),
261}; 261};
262 262
263static struct usb_endpoint_descriptor hs_out_desc __initdata = { 263static struct usb_endpoint_descriptor hs_out_desc = {
264 .bLength = USB_DT_ENDPOINT_SIZE, 264 .bLength = USB_DT_ENDPOINT_SIZE,
265 .bDescriptorType = USB_DT_ENDPOINT, 265 .bDescriptorType = USB_DT_ENDPOINT,
266 266
@@ -269,7 +269,7 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
269 .wMaxPacketSize = cpu_to_le16(512), 269 .wMaxPacketSize = cpu_to_le16(512),
270}; 270};
271 271
272static struct usb_descriptor_header *eth_hs_function[] __initdata = { 272static struct usb_descriptor_header *eth_hs_function[] = {
273 (struct usb_descriptor_header *) &rndis_iad_descriptor, 273 (struct usb_descriptor_header *) &rndis_iad_descriptor,
274 /* control interface matches ACM, not Ethernet */ 274 /* control interface matches ACM, not Ethernet */
275 (struct usb_descriptor_header *) &rndis_control_intf, 275 (struct usb_descriptor_header *) &rndis_control_intf,
@@ -594,7 +594,7 @@ static void rndis_close(struct gether *geth)
594 594
595/* ethernet function driver setup/binding */ 595/* ethernet function driver setup/binding */
596 596
597static int __init 597static int
598rndis_bind(struct usb_configuration *c, struct usb_function *f) 598rndis_bind(struct usb_configuration *c, struct usb_function *f)
599{ 599{
600 struct usb_composite_dev *cdev = c->cdev; 600 struct usb_composite_dev *cdev = c->cdev;
@@ -786,7 +786,8 @@ static inline bool can_support_rndis(struct usb_configuration *c)
786 * Caller must have called @gether_setup(). Caller is also responsible 786 * Caller must have called @gether_setup(). Caller is also responsible
787 * for calling @gether_cleanup() before module unload. 787 * for calling @gether_cleanup() before module unload.
788 */ 788 */
789int __init rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 789int
790rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
790{ 791{
791 struct f_rndis *rndis; 792 struct f_rndis *rndis;
792 int status; 793 int status;
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
new file mode 100644
index 000000000000..fc2611f8b326
--- /dev/null
+++ b/drivers/usb/gadget/f_uvc.c
@@ -0,0 +1,661 @@
1/*
2 * uvc_gadget.c -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/fs.h>
18#include <linux/list.h>
19#include <linux/mutex.h>
20#include <linux/usb/ch9.h>
21#include <linux/usb/gadget.h>
22#include <linux/usb/video.h>
23#include <linux/vmalloc.h>
24#include <linux/wait.h>
25
26#include <media/v4l2-dev.h>
27#include <media/v4l2-event.h>
28
29#include "uvc.h"
30
31unsigned int uvc_trace_param;
32
33/* --------------------------------------------------------------------------
34 * Function descriptors
35 */
36
37/* string IDs are assigned dynamically */
38
39#define UVC_STRING_ASSOCIATION_IDX 0
40#define UVC_STRING_CONTROL_IDX 1
41#define UVC_STRING_STREAMING_IDX 2
42
43static struct usb_string uvc_en_us_strings[] = {
44 [UVC_STRING_ASSOCIATION_IDX].s = "UVC Camera",
45 [UVC_STRING_CONTROL_IDX].s = "Video Control",
46 [UVC_STRING_STREAMING_IDX].s = "Video Streaming",
47 { }
48};
49
50static struct usb_gadget_strings uvc_stringtab = {
51 .language = 0x0409, /* en-us */
52 .strings = uvc_en_us_strings,
53};
54
55static struct usb_gadget_strings *uvc_function_strings[] = {
56 &uvc_stringtab,
57 NULL,
58};
59
60#define UVC_INTF_VIDEO_CONTROL 0
61#define UVC_INTF_VIDEO_STREAMING 1
62
63static struct usb_interface_assoc_descriptor uvc_iad __initdata = {
64 .bLength = USB_DT_INTERFACE_ASSOCIATION_SIZE,
65 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
66 .bFirstInterface = 0,
67 .bInterfaceCount = 2,
68 .bFunctionClass = USB_CLASS_VIDEO,
69 .bFunctionSubClass = 0x03,
70 .bFunctionProtocol = 0x00,
71 .iFunction = 0,
72};
73
74static struct usb_interface_descriptor uvc_control_intf __initdata = {
75 .bLength = USB_DT_INTERFACE_SIZE,
76 .bDescriptorType = USB_DT_INTERFACE,
77 .bInterfaceNumber = UVC_INTF_VIDEO_CONTROL,
78 .bAlternateSetting = 0,
79 .bNumEndpoints = 1,
80 .bInterfaceClass = USB_CLASS_VIDEO,
81 .bInterfaceSubClass = 0x01,
82 .bInterfaceProtocol = 0x00,
83 .iInterface = 0,
84};
85
86static struct usb_endpoint_descriptor uvc_control_ep __initdata = {
87 .bLength = USB_DT_ENDPOINT_SIZE,
88 .bDescriptorType = USB_DT_ENDPOINT,
89 .bEndpointAddress = USB_DIR_IN,
90 .bmAttributes = USB_ENDPOINT_XFER_INT,
91 .wMaxPacketSize = cpu_to_le16(16),
92 .bInterval = 8,
93};
94
95static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = {
96 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE,
97 .bDescriptorType = USB_DT_CS_ENDPOINT,
98 .bDescriptorSubType = UVC_EP_INTERRUPT,
99 .wMaxTransferSize = cpu_to_le16(16),
100};
101
102static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = {
103 .bLength = USB_DT_INTERFACE_SIZE,
104 .bDescriptorType = USB_DT_INTERFACE,
105 .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING,
106 .bAlternateSetting = 0,
107 .bNumEndpoints = 0,
108 .bInterfaceClass = USB_CLASS_VIDEO,
109 .bInterfaceSubClass = 0x02,
110 .bInterfaceProtocol = 0x00,
111 .iInterface = 0,
112};
113
114static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = {
115 .bLength = USB_DT_INTERFACE_SIZE,
116 .bDescriptorType = USB_DT_INTERFACE,
117 .bInterfaceNumber = UVC_INTF_VIDEO_STREAMING,
118 .bAlternateSetting = 1,
119 .bNumEndpoints = 1,
120 .bInterfaceClass = USB_CLASS_VIDEO,
121 .bInterfaceSubClass = 0x02,
122 .bInterfaceProtocol = 0x00,
123 .iInterface = 0,
124};
125
126static struct usb_endpoint_descriptor uvc_streaming_ep = {
127 .bLength = USB_DT_ENDPOINT_SIZE,
128 .bDescriptorType = USB_DT_ENDPOINT,
129 .bEndpointAddress = USB_DIR_IN,
130 .bmAttributes = USB_ENDPOINT_XFER_ISOC,
131 .wMaxPacketSize = cpu_to_le16(512),
132 .bInterval = 1,
133};
134
135static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
136 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
137 (struct usb_descriptor_header *) &uvc_streaming_ep,
138 NULL,
139};
140
141static const struct usb_descriptor_header * const uvc_hs_streaming[] = {
142 (struct usb_descriptor_header *) &uvc_streaming_intf_alt1,
143 (struct usb_descriptor_header *) &uvc_streaming_ep,
144 NULL,
145};
146
147/* --------------------------------------------------------------------------
148 * Control requests
149 */
150
151static void
152uvc_function_ep0_complete(struct usb_ep *ep, struct usb_request *req)
153{
154 struct uvc_device *uvc = req->context;
155 struct v4l2_event v4l2_event;
156 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
157
158 if (uvc->event_setup_out) {
159 uvc->event_setup_out = 0;
160
161 memset(&v4l2_event, 0, sizeof(v4l2_event));
162 v4l2_event.type = UVC_EVENT_DATA;
163 uvc_event->data.length = req->actual;
164 memcpy(&uvc_event->data.data, req->buf, req->actual);
165 v4l2_event_queue(uvc->vdev, &v4l2_event);
166 }
167}
168
169static int
170uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
171{
172 struct uvc_device *uvc = to_uvc(f);
173 struct v4l2_event v4l2_event;
174 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
175
176 /* printk(KERN_INFO "setup request %02x %02x value %04x index %04x %04x\n",
177 * ctrl->bRequestType, ctrl->bRequest, le16_to_cpu(ctrl->wValue),
178 * le16_to_cpu(ctrl->wIndex), le16_to_cpu(ctrl->wLength));
179 */
180
181 if ((ctrl->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS) {
182 INFO(f->config->cdev, "invalid request type\n");
183 return -EINVAL;
184 }
185
186 /* Stall too big requests. */
187 if (le16_to_cpu(ctrl->wLength) > UVC_MAX_REQUEST_SIZE)
188 return -EINVAL;
189
190 memset(&v4l2_event, 0, sizeof(v4l2_event));
191 v4l2_event.type = UVC_EVENT_SETUP;
192 memcpy(&uvc_event->req, ctrl, sizeof(uvc_event->req));
193 v4l2_event_queue(uvc->vdev, &v4l2_event);
194
195 return 0;
196}
197
198static int
199uvc_function_get_alt(struct usb_function *f, unsigned interface)
200{
201 struct uvc_device *uvc = to_uvc(f);
202
203 INFO(f->config->cdev, "uvc_function_get_alt(%u)\n", interface);
204
205 if (interface == uvc->control_intf)
206 return 0;
207 else if (interface != uvc->streaming_intf)
208 return -EINVAL;
209 else
210 return uvc->state == UVC_STATE_STREAMING ? 1 : 0;
211}
212
213static int
214uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
215{
216 struct uvc_device *uvc = to_uvc(f);
217 struct v4l2_event v4l2_event;
218 struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
219
220 INFO(f->config->cdev, "uvc_function_set_alt(%u, %u)\n", interface, alt);
221
222 if (interface == uvc->control_intf) {
223 if (alt)
224 return -EINVAL;
225
226 if (uvc->state == UVC_STATE_DISCONNECTED) {
227 memset(&v4l2_event, 0, sizeof(v4l2_event));
228 v4l2_event.type = UVC_EVENT_CONNECT;
229 uvc_event->speed = f->config->cdev->gadget->speed;
230 v4l2_event_queue(uvc->vdev, &v4l2_event);
231
232 uvc->state = UVC_STATE_CONNECTED;
233 }
234
235 return 0;
236 }
237
238 if (interface != uvc->streaming_intf)
239 return -EINVAL;
240
241 /* TODO
242 if (usb_endpoint_xfer_bulk(&uvc->desc.vs_ep))
243 return alt ? -EINVAL : 0;
244 */
245
246 switch (alt) {
247 case 0:
248 if (uvc->state != UVC_STATE_STREAMING)
249 return 0;
250
251 if (uvc->video.ep)
252 usb_ep_disable(uvc->video.ep);
253
254 memset(&v4l2_event, 0, sizeof(v4l2_event));
255 v4l2_event.type = UVC_EVENT_STREAMOFF;
256 v4l2_event_queue(uvc->vdev, &v4l2_event);
257
258 uvc->state = UVC_STATE_CONNECTED;
259 break;
260
261 case 1:
262 if (uvc->state != UVC_STATE_CONNECTED)
263 return 0;
264
265 if (uvc->video.ep)
266 usb_ep_enable(uvc->video.ep, &uvc_streaming_ep);
267
268 memset(&v4l2_event, 0, sizeof(v4l2_event));
269 v4l2_event.type = UVC_EVENT_STREAMON;
270 v4l2_event_queue(uvc->vdev, &v4l2_event);
271
272 uvc->state = UVC_STATE_STREAMING;
273 break;
274
275 default:
276 return -EINVAL;
277 }
278
279 return 0;
280}
281
282static void
283uvc_function_disable(struct usb_function *f)
284{
285 struct uvc_device *uvc = to_uvc(f);
286 struct v4l2_event v4l2_event;
287
288 INFO(f->config->cdev, "uvc_function_disable\n");
289
290 memset(&v4l2_event, 0, sizeof(v4l2_event));
291 v4l2_event.type = UVC_EVENT_DISCONNECT;
292 v4l2_event_queue(uvc->vdev, &v4l2_event);
293
294 uvc->state = UVC_STATE_DISCONNECTED;
295}
296
297/* --------------------------------------------------------------------------
298 * Connection / disconnection
299 */
300
301void
302uvc_function_connect(struct uvc_device *uvc)
303{
304 struct usb_composite_dev *cdev = uvc->func.config->cdev;
305 int ret;
306
307 if ((ret = usb_function_activate(&uvc->func)) < 0)
308 INFO(cdev, "UVC connect failed with %d\n", ret);
309}
310
311void
312uvc_function_disconnect(struct uvc_device *uvc)
313{
314 struct usb_composite_dev *cdev = uvc->func.config->cdev;
315 int ret;
316
317 if ((ret = usb_function_deactivate(&uvc->func)) < 0)
318 INFO(cdev, "UVC disconnect failed with %d\n", ret);
319}
320
321/* --------------------------------------------------------------------------
322 * USB probe and disconnect
323 */
324
325static int
326uvc_register_video(struct uvc_device *uvc)
327{
328 struct usb_composite_dev *cdev = uvc->func.config->cdev;
329 struct video_device *video;
330
331 /* TODO reference counting. */
332 video = video_device_alloc();
333 if (video == NULL)
334 return -ENOMEM;
335
336 video->parent = &cdev->gadget->dev;
337 video->minor = -1;
338 video->fops = &uvc_v4l2_fops;
339 video->release = video_device_release;
340 strncpy(video->name, cdev->gadget->name, sizeof(video->name));
341
342 uvc->vdev = video;
343 video_set_drvdata(video, uvc);
344
345 return video_register_device(video, VFL_TYPE_GRABBER, -1);
346}
347
348#define UVC_COPY_DESCRIPTOR(mem, dst, desc) \
349 do { \
350 memcpy(mem, desc, (desc)->bLength); \
351 *(dst)++ = mem; \
352 mem += (desc)->bLength; \
353 } while (0);
354
355#define UVC_COPY_DESCRIPTORS(mem, dst, src) \
356 do { \
357 const struct usb_descriptor_header * const *__src; \
358 for (__src = src; *__src; ++__src) { \
359 memcpy(mem, *__src, (*__src)->bLength); \
360 *dst++ = mem; \
361 mem += (*__src)->bLength; \
362 } \
363 } while (0)
364
365static struct usb_descriptor_header ** __init
366uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
367{
368 struct uvc_input_header_descriptor *uvc_streaming_header;
369 struct uvc_header_descriptor *uvc_control_header;
370 const struct uvc_descriptor_header * const *uvc_streaming_cls;
371 const struct usb_descriptor_header * const *uvc_streaming_std;
372 const struct usb_descriptor_header * const *src;
373 struct usb_descriptor_header **dst;
374 struct usb_descriptor_header **hdr;
375 unsigned int control_size;
376 unsigned int streaming_size;
377 unsigned int n_desc;
378 unsigned int bytes;
379 void *mem;
380
381 uvc_streaming_cls = (speed == USB_SPEED_FULL)
382 ? uvc->desc.fs_streaming : uvc->desc.hs_streaming;
383 uvc_streaming_std = (speed == USB_SPEED_FULL)
384 ? uvc_fs_streaming : uvc_hs_streaming;
385
386 /* Descriptors layout
387 *
388 * uvc_iad
389 * uvc_control_intf
390 * Class-specific UVC control descriptors
391 * uvc_control_ep
392 * uvc_control_cs_ep
393 * uvc_streaming_intf_alt0
394 * Class-specific UVC streaming descriptors
395 * uvc_{fs|hs}_streaming
396 */
397
398 /* Count descriptors and compute their size. */
399 control_size = 0;
400 streaming_size = 0;
401 bytes = uvc_iad.bLength + uvc_control_intf.bLength
402 + uvc_control_ep.bLength + uvc_control_cs_ep.bLength
403 + uvc_streaming_intf_alt0.bLength;
404 n_desc = 5;
405
406 for (src = (const struct usb_descriptor_header**)uvc->desc.control; *src; ++src) {
407 control_size += (*src)->bLength;
408 bytes += (*src)->bLength;
409 n_desc++;
410 }
411 for (src = (const struct usb_descriptor_header**)uvc_streaming_cls; *src; ++src) {
412 streaming_size += (*src)->bLength;
413 bytes += (*src)->bLength;
414 n_desc++;
415 }
416 for (src = uvc_streaming_std; *src; ++src) {
417 bytes += (*src)->bLength;
418 n_desc++;
419 }
420
421 mem = kmalloc((n_desc + 1) * sizeof(*src) + bytes, GFP_KERNEL);
422 if (mem == NULL)
423 return NULL;
424
425 hdr = mem;
426 dst = mem;
427 mem += (n_desc + 1) * sizeof(*src);
428
429 /* Copy the descriptors. */
430 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_iad);
431 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_intf);
432
433 uvc_control_header = mem;
434 UVC_COPY_DESCRIPTORS(mem, dst,
435 (const struct usb_descriptor_header**)uvc->desc.control);
436 uvc_control_header->wTotalLength = cpu_to_le16(control_size);
437 uvc_control_header->bInCollection = 1;
438 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
439
440 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_ep);
441 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_cs_ep);
442 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_streaming_intf_alt0);
443
444 uvc_streaming_header = mem;
445 UVC_COPY_DESCRIPTORS(mem, dst,
446 (const struct usb_descriptor_header**)uvc_streaming_cls);
447 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size);
448 uvc_streaming_header->bEndpointAddress = uvc_streaming_ep.bEndpointAddress;
449
450 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std);
451
452 *dst = NULL;
453 return hdr;
454}
455
456static void
457uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
458{
459 struct usb_composite_dev *cdev = c->cdev;
460 struct uvc_device *uvc = to_uvc(f);
461
462 INFO(cdev, "uvc_function_unbind\n");
463
464 if (uvc->vdev) {
465 if (uvc->vdev->minor == -1)
466 video_device_release(uvc->vdev);
467 else
468 video_unregister_device(uvc->vdev);
469 uvc->vdev = NULL;
470 }
471
472 if (uvc->control_ep)
473 uvc->control_ep->driver_data = NULL;
474 if (uvc->video.ep)
475 uvc->video.ep->driver_data = NULL;
476
477 if (uvc->control_req) {
478 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
479 kfree(uvc->control_buf);
480 }
481
482 kfree(f->descriptors);
483 kfree(f->hs_descriptors);
484
485 kfree(uvc);
486}
487
488static int __init
489uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
490{
491 struct usb_composite_dev *cdev = c->cdev;
492 struct uvc_device *uvc = to_uvc(f);
493 struct usb_ep *ep;
494 int ret = -EINVAL;
495
496 INFO(cdev, "uvc_function_bind\n");
497
498 /* Allocate endpoints. */
499 ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep);
500 if (!ep) {
501 INFO(cdev, "Unable to allocate control EP\n");
502 goto error;
503 }
504 uvc->control_ep = ep;
505 ep->driver_data = uvc;
506
507 ep = usb_ep_autoconfig(cdev->gadget, &uvc_streaming_ep);
508 if (!ep) {
509 INFO(cdev, "Unable to allocate streaming EP\n");
510 goto error;
511 }
512 uvc->video.ep = ep;
513 ep->driver_data = uvc;
514
515 /* Allocate interface IDs. */
516 if ((ret = usb_interface_id(c, f)) < 0)
517 goto error;
518 uvc_iad.bFirstInterface = ret;
519 uvc_control_intf.bInterfaceNumber = ret;
520 uvc->control_intf = ret;
521
522 if ((ret = usb_interface_id(c, f)) < 0)
523 goto error;
524 uvc_streaming_intf_alt0.bInterfaceNumber = ret;
525 uvc_streaming_intf_alt1.bInterfaceNumber = ret;
526 uvc->streaming_intf = ret;
527
528 /* Copy descriptors. */
529 f->descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
530 f->hs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_HIGH);
531
532 /* Preallocate control endpoint request. */
533 uvc->control_req = usb_ep_alloc_request(cdev->gadget->ep0, GFP_KERNEL);
534 uvc->control_buf = kmalloc(UVC_MAX_REQUEST_SIZE, GFP_KERNEL);
535 if (uvc->control_req == NULL || uvc->control_buf == NULL) {
536 ret = -ENOMEM;
537 goto error;
538 }
539
540 uvc->control_req->buf = uvc->control_buf;
541 uvc->control_req->complete = uvc_function_ep0_complete;
542 uvc->control_req->context = uvc;
543
544 /* Avoid letting this gadget enumerate until the userspace server is
545 * active.
546 */
547 if ((ret = usb_function_deactivate(f)) < 0)
548 goto error;
549
550 /* Initialise video. */
551 ret = uvc_video_init(&uvc->video);
552 if (ret < 0)
553 goto error;
554
555 /* Register a V4L2 device. */
556 ret = uvc_register_video(uvc);
557 if (ret < 0) {
558 printk(KERN_INFO "Unable to register video device\n");
559 goto error;
560 }
561
562 return 0;
563
564error:
565 uvc_function_unbind(c, f);
566 return ret;
567}
568
569/* --------------------------------------------------------------------------
570 * USB gadget function
571 */
572
573/**
574 * uvc_bind_config - add a UVC function to a configuration
575 * @c: the configuration to support the UVC instance
576 * Context: single threaded during gadget setup
577 *
578 * Returns zero on success, else negative errno.
579 *
580 * Caller must have called @uvc_setup(). Caller is also responsible for
581 * calling @uvc_cleanup() before module unload.
582 */
583int __init
584uvc_bind_config(struct usb_configuration *c,
585 const struct uvc_descriptor_header * const *control,
586 const struct uvc_descriptor_header * const *fs_streaming,
587 const struct uvc_descriptor_header * const *hs_streaming)
588{
589 struct uvc_device *uvc;
590 int ret = 0;
591
592 /* TODO Check if the USB device controller supports the required
593 * features.
594 */
595 if (!gadget_is_dualspeed(c->cdev->gadget))
596 return -EINVAL;
597
598 uvc = kzalloc(sizeof(*uvc), GFP_KERNEL);
599 if (uvc == NULL)
600 return -ENOMEM;
601
602 uvc->state = UVC_STATE_DISCONNECTED;
603
604 /* Validate the descriptors. */
605 if (control == NULL || control[0] == NULL ||
606 control[0]->bDescriptorSubType != UVC_DT_HEADER)
607 goto error;
608
609 if (fs_streaming == NULL || fs_streaming[0] == NULL ||
610 fs_streaming[0]->bDescriptorSubType != UVC_DT_INPUT_HEADER)
611 goto error;
612
613 if (hs_streaming == NULL || hs_streaming[0] == NULL ||
614 hs_streaming[0]->bDescriptorSubType != UVC_DT_INPUT_HEADER)
615 goto error;
616
617 uvc->desc.control = control;
618 uvc->desc.fs_streaming = fs_streaming;
619 uvc->desc.hs_streaming = hs_streaming;
620
621 /* Allocate string descriptor numbers. */
622 if ((ret = usb_string_id(c->cdev)) < 0)
623 goto error;
624 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = ret;
625 uvc_iad.iFunction = ret;
626
627 if ((ret = usb_string_id(c->cdev)) < 0)
628 goto error;
629 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = ret;
630 uvc_control_intf.iInterface = ret;
631
632 if ((ret = usb_string_id(c->cdev)) < 0)
633 goto error;
634 uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id = ret;
635 uvc_streaming_intf_alt0.iInterface = ret;
636 uvc_streaming_intf_alt1.iInterface = ret;
637
638 /* Register the function. */
639 uvc->func.name = "uvc";
640 uvc->func.strings = uvc_function_strings;
641 uvc->func.bind = uvc_function_bind;
642 uvc->func.unbind = uvc_function_unbind;
643 uvc->func.get_alt = uvc_function_get_alt;
644 uvc->func.set_alt = uvc_function_set_alt;
645 uvc->func.disable = uvc_function_disable;
646 uvc->func.setup = uvc_function_setup;
647
648 ret = usb_add_function(c, &uvc->func);
649 if (ret)
650 kfree(uvc);
651
652 return 0;
653
654error:
655 kfree(uvc);
656 return ret;
657}
658
659module_param_named(trace, uvc_trace_param, uint, S_IRUGO|S_IWUSR);
660MODULE_PARM_DESC(trace, "Trace level bitmask");
661
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h
new file mode 100644
index 000000000000..8a5db7c4fe7c
--- /dev/null
+++ b/drivers/usb/gadget/f_uvc.h
@@ -0,0 +1,376 @@
1/*
2 * f_uvc.h -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#ifndef _F_UVC_H_
15#define _F_UVC_H_
16
17#include <linux/usb/composite.h>
18
19#define USB_CLASS_VIDEO_CONTROL 1
20#define USB_CLASS_VIDEO_STREAMING 2
21
22struct uvc_descriptor_header {
23 __u8 bLength;
24 __u8 bDescriptorType;
25 __u8 bDescriptorSubType;
26} __attribute__ ((packed));
27
28struct uvc_header_descriptor {
29 __u8 bLength;
30 __u8 bDescriptorType;
31 __u8 bDescriptorSubType;
32 __u16 bcdUVC;
33 __u16 wTotalLength;
34 __u32 dwClockFrequency;
35 __u8 bInCollection;
36 __u8 baInterfaceNr[];
37} __attribute__((__packed__));
38
39#define UVC_HEADER_DESCRIPTOR(n) uvc_header_descriptor_##n
40
41#define DECLARE_UVC_HEADER_DESCRIPTOR(n) \
42struct UVC_HEADER_DESCRIPTOR(n) { \
43 __u8 bLength; \
44 __u8 bDescriptorType; \
45 __u8 bDescriptorSubType; \
46 __u16 bcdUVC; \
47 __u16 wTotalLength; \
48 __u32 dwClockFrequency; \
49 __u8 bInCollection; \
50 __u8 baInterfaceNr[n]; \
51} __attribute__ ((packed))
52
53struct uvc_input_terminal_descriptor {
54 __u8 bLength;
55 __u8 bDescriptorType;
56 __u8 bDescriptorSubType;
57 __u8 bTerminalID;
58 __u16 wTerminalType;
59 __u8 bAssocTerminal;
60 __u8 iTerminal;
61} __attribute__((__packed__));
62
63struct uvc_output_terminal_descriptor {
64 __u8 bLength;
65 __u8 bDescriptorType;
66 __u8 bDescriptorSubType;
67 __u8 bTerminalID;
68 __u16 wTerminalType;
69 __u8 bAssocTerminal;
70 __u8 bSourceID;
71 __u8 iTerminal;
72} __attribute__((__packed__));
73
74struct uvc_camera_terminal_descriptor {
75 __u8 bLength;
76 __u8 bDescriptorType;
77 __u8 bDescriptorSubType;
78 __u8 bTerminalID;
79 __u16 wTerminalType;
80 __u8 bAssocTerminal;
81 __u8 iTerminal;
82 __u16 wObjectiveFocalLengthMin;
83 __u16 wObjectiveFocalLengthMax;
84 __u16 wOcularFocalLength;
85 __u8 bControlSize;
86 __u8 bmControls[3];
87} __attribute__((__packed__));
88
89struct uvc_selector_unit_descriptor {
90 __u8 bLength;
91 __u8 bDescriptorType;
92 __u8 bDescriptorSubType;
93 __u8 bUnitID;
94 __u8 bNrInPins;
95 __u8 baSourceID[0];
96 __u8 iSelector;
97} __attribute__((__packed__));
98
99#define UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
100 uvc_selector_unit_descriptor_##n
101
102#define DECLARE_UVC_SELECTOR_UNIT_DESCRIPTOR(n) \
103struct UVC_SELECTOR_UNIT_DESCRIPTOR(n) { \
104 __u8 bLength; \
105 __u8 bDescriptorType; \
106 __u8 bDescriptorSubType; \
107 __u8 bUnitID; \
108 __u8 bNrInPins; \
109 __u8 baSourceID[n]; \
110 __u8 iSelector; \
111} __attribute__ ((packed))
112
113struct uvc_processing_unit_descriptor {
114 __u8 bLength;
115 __u8 bDescriptorType;
116 __u8 bDescriptorSubType;
117 __u8 bUnitID;
118 __u8 bSourceID;
119 __u16 wMaxMultiplier;
120 __u8 bControlSize;
121 __u8 bmControls[2];
122 __u8 iProcessing;
123} __attribute__((__packed__));
124
125struct uvc_extension_unit_descriptor {
126 __u8 bLength;
127 __u8 bDescriptorType;
128 __u8 bDescriptorSubType;
129 __u8 bUnitID;
130 __u8 guidExtensionCode[16];
131 __u8 bNumControls;
132 __u8 bNrInPins;
133 __u8 baSourceID[0];
134 __u8 bControlSize;
135 __u8 bmControls[0];
136 __u8 iExtension;
137} __attribute__((__packed__));
138
139#define UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
140 uvc_extension_unit_descriptor_##p_##n
141
142#define DECLARE_UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) \
143struct UVC_EXTENSION_UNIT_DESCRIPTOR(p, n) { \
144 __u8 bLength; \
145 __u8 bDescriptorType; \
146 __u8 bDescriptorSubType; \
147 __u8 bUnitID; \
148 __u8 guidExtensionCode[16]; \
149 __u8 bNumControls; \
150 __u8 bNrInPins; \
151 __u8 baSourceID[p]; \
152 __u8 bControlSize; \
153 __u8 bmControls[n]; \
154 __u8 iExtension; \
155} __attribute__ ((packed))
156
157struct uvc_control_endpoint_descriptor {
158 __u8 bLength;
159 __u8 bDescriptorType;
160 __u8 bDescriptorSubType;
161 __u16 wMaxTransferSize;
162} __attribute__((__packed__));
163
164#define UVC_DT_HEADER 1
165#define UVC_DT_INPUT_TERMINAL 2
166#define UVC_DT_OUTPUT_TERMINAL 3
167#define UVC_DT_SELECTOR_UNIT 4
168#define UVC_DT_PROCESSING_UNIT 5
169#define UVC_DT_EXTENSION_UNIT 6
170
171#define UVC_DT_HEADER_SIZE(n) (12+(n))
172#define UVC_DT_INPUT_TERMINAL_SIZE 8
173#define UVC_DT_OUTPUT_TERMINAL_SIZE 9
174#define UVC_DT_CAMERA_TERMINAL_SIZE(n) (15+(n))
175#define UVC_DT_SELECTOR_UNIT_SIZE(n) (6+(n))
176#define UVC_DT_PROCESSING_UNIT_SIZE(n) (9+(n))
177#define UVC_DT_EXTENSION_UNIT_SIZE(p,n) (24+(p)+(n))
178#define UVC_DT_CONTROL_ENDPOINT_SIZE 5
179
180struct uvc_input_header_descriptor {
181 __u8 bLength;
182 __u8 bDescriptorType;
183 __u8 bDescriptorSubType;
184 __u8 bNumFormats;
185 __u16 wTotalLength;
186 __u8 bEndpointAddress;
187 __u8 bmInfo;
188 __u8 bTerminalLink;
189 __u8 bStillCaptureMethod;
190 __u8 bTriggerSupport;
191 __u8 bTriggerUsage;
192 __u8 bControlSize;
193 __u8 bmaControls[];
194} __attribute__((__packed__));
195
196#define UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
197 uvc_input_header_descriptor_##n_##p
198
199#define DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(n, p) \
200struct UVC_INPUT_HEADER_DESCRIPTOR(n, p) { \
201 __u8 bLength; \
202 __u8 bDescriptorType; \
203 __u8 bDescriptorSubType; \
204 __u8 bNumFormats; \
205 __u16 wTotalLength; \
206 __u8 bEndpointAddress; \
207 __u8 bmInfo; \
208 __u8 bTerminalLink; \
209 __u8 bStillCaptureMethod; \
210 __u8 bTriggerSupport; \
211 __u8 bTriggerUsage; \
212 __u8 bControlSize; \
213 __u8 bmaControls[p][n]; \
214} __attribute__ ((packed))
215
216struct uvc_output_header_descriptor {
217 __u8 bLength;
218 __u8 bDescriptorType;
219 __u8 bDescriptorSubType;
220 __u8 bNumFormats;
221 __u16 wTotalLength;
222 __u8 bEndpointAddress;
223 __u8 bTerminalLink;
224 __u8 bControlSize;
225 __u8 bmaControls[];
226} __attribute__((__packed__));
227
228#define UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
229 uvc_output_header_descriptor_##n_##p
230
231#define DECLARE_UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) \
232struct UVC_OUTPUT_HEADER_DESCRIPTOR(n, p) { \
233 __u8 bLength; \
234 __u8 bDescriptorType; \
235 __u8 bDescriptorSubType; \
236 __u8 bNumFormats; \
237 __u16 wTotalLength; \
238 __u8 bEndpointAddress; \
239 __u8 bTerminalLink; \
240 __u8 bControlSize; \
241 __u8 bmaControls[p][n]; \
242} __attribute__ ((packed))
243
244struct uvc_format_uncompressed {
245 __u8 bLength;
246 __u8 bDescriptorType;
247 __u8 bDescriptorSubType;
248 __u8 bFormatIndex;
249 __u8 bNumFrameDescriptors;
250 __u8 guidFormat[16];
251 __u8 bBitsPerPixel;
252 __u8 bDefaultFrameIndex;
253 __u8 bAspectRatioX;
254 __u8 bAspectRatioY;
255 __u8 bmInterfaceFlags;
256 __u8 bCopyProtect;
257} __attribute__((__packed__));
258
259struct uvc_frame_uncompressed {
260 __u8 bLength;
261 __u8 bDescriptorType;
262 __u8 bDescriptorSubType;
263 __u8 bFrameIndex;
264 __u8 bmCapabilities;
265 __u16 wWidth;
266 __u16 wHeight;
267 __u32 dwMinBitRate;
268 __u32 dwMaxBitRate;
269 __u32 dwMaxVideoFrameBufferSize;
270 __u32 dwDefaultFrameInterval;
271 __u8 bFrameIntervalType;
272 __u32 dwFrameInterval[];
273} __attribute__((__packed__));
274
275#define UVC_FRAME_UNCOMPRESSED(n) \
276 uvc_frame_uncompressed_##n
277
278#define DECLARE_UVC_FRAME_UNCOMPRESSED(n) \
279struct UVC_FRAME_UNCOMPRESSED(n) { \
280 __u8 bLength; \
281 __u8 bDescriptorType; \
282 __u8 bDescriptorSubType; \
283 __u8 bFrameIndex; \
284 __u8 bmCapabilities; \
285 __u16 wWidth; \
286 __u16 wHeight; \
287 __u32 dwMinBitRate; \
288 __u32 dwMaxBitRate; \
289 __u32 dwMaxVideoFrameBufferSize; \
290 __u32 dwDefaultFrameInterval; \
291 __u8 bFrameIntervalType; \
292 __u32 dwFrameInterval[n]; \
293} __attribute__ ((packed))
294
295struct uvc_format_mjpeg {
296 __u8 bLength;
297 __u8 bDescriptorType;
298 __u8 bDescriptorSubType;
299 __u8 bFormatIndex;
300 __u8 bNumFrameDescriptors;
301 __u8 bmFlags;
302 __u8 bDefaultFrameIndex;
303 __u8 bAspectRatioX;
304 __u8 bAspectRatioY;
305 __u8 bmInterfaceFlags;
306 __u8 bCopyProtect;
307} __attribute__((__packed__));
308
309struct uvc_frame_mjpeg {
310 __u8 bLength;
311 __u8 bDescriptorType;
312 __u8 bDescriptorSubType;
313 __u8 bFrameIndex;
314 __u8 bmCapabilities;
315 __u16 wWidth;
316 __u16 wHeight;
317 __u32 dwMinBitRate;
318 __u32 dwMaxBitRate;
319 __u32 dwMaxVideoFrameBufferSize;
320 __u32 dwDefaultFrameInterval;
321 __u8 bFrameIntervalType;
322 __u32 dwFrameInterval[];
323} __attribute__((__packed__));
324
325#define UVC_FRAME_MJPEG(n) \
326 uvc_frame_mjpeg_##n
327
328#define DECLARE_UVC_FRAME_MJPEG(n) \
329struct UVC_FRAME_MJPEG(n) { \
330 __u8 bLength; \
331 __u8 bDescriptorType; \
332 __u8 bDescriptorSubType; \
333 __u8 bFrameIndex; \
334 __u8 bmCapabilities; \
335 __u16 wWidth; \
336 __u16 wHeight; \
337 __u32 dwMinBitRate; \
338 __u32 dwMaxBitRate; \
339 __u32 dwMaxVideoFrameBufferSize; \
340 __u32 dwDefaultFrameInterval; \
341 __u8 bFrameIntervalType; \
342 __u32 dwFrameInterval[n]; \
343} __attribute__ ((packed))
344
345struct uvc_color_matching_descriptor {
346 __u8 bLength;
347 __u8 bDescriptorType;
348 __u8 bDescriptorSubType;
349 __u8 bColorPrimaries;
350 __u8 bTransferCharacteristics;
351 __u8 bMatrixCoefficients;
352} __attribute__((__packed__));
353
354#define UVC_DT_INPUT_HEADER 1
355#define UVC_DT_OUTPUT_HEADER 2
356#define UVC_DT_FORMAT_UNCOMPRESSED 4
357#define UVC_DT_FRAME_UNCOMPRESSED 5
358#define UVC_DT_FORMAT_MJPEG 6
359#define UVC_DT_FRAME_MJPEG 7
360#define UVC_DT_COLOR_MATCHING 13
361
362#define UVC_DT_INPUT_HEADER_SIZE(n, p) (13+(n*p))
363#define UVC_DT_OUTPUT_HEADER_SIZE(n, p) (9+(n*p))
364#define UVC_DT_FORMAT_UNCOMPRESSED_SIZE 27
365#define UVC_DT_FRAME_UNCOMPRESSED_SIZE(n) (26+4*(n))
366#define UVC_DT_FORMAT_MJPEG_SIZE 11
367#define UVC_DT_FRAME_MJPEG_SIZE(n) (26+4*(n))
368#define UVC_DT_COLOR_MATCHING_SIZE 6
369
370extern int uvc_bind_config(struct usb_configuration *c,
371 const struct uvc_descriptor_header * const *control,
372 const struct uvc_descriptor_header * const *fs_streaming,
373 const struct uvc_descriptor_header * const *hs_streaming);
374
375#endif /* _F_UVC_H_ */
376
diff --git a/drivers/usb/gadget/fsl_mx3_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index 20a802ecaa15..d0b8bde59e59 100644
--- a/drivers/usb/gadget/fsl_mx3_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -50,12 +50,14 @@ int fsl_udc_clk_init(struct platform_device *pdev)
50 goto egusb; 50 goto egusb;
51 } 51 }
52 52
53 freq = clk_get_rate(mxc_usb_clk); 53 if (!cpu_is_mx51()) {
54 if (pdata->phy_mode != FSL_USB2_PHY_ULPI && 54 freq = clk_get_rate(mxc_usb_clk);
55 (freq < 59999000 || freq > 60001000)) { 55 if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
56 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq); 56 (freq < 59999000 || freq > 60001000)) {
57 ret = -EINVAL; 57 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
58 goto eclkrate; 58 ret = -EINVAL;
59 goto eclkrate;
60 }
59 } 61 }
60 62
61 ret = clk_enable(mxc_usb_clk); 63 ret = clk_enable(mxc_usb_clk);
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index fa3d142ba64d..08a9a62a39e3 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -489,7 +489,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,
489 case USB_ENDPOINT_XFER_ISOC: 489 case USB_ENDPOINT_XFER_ISOC:
490 /* Calculate transactions needed for high bandwidth iso */ 490 /* Calculate transactions needed for high bandwidth iso */
491 mult = (unsigned char)(1 + ((max >> 11) & 0x03)); 491 mult = (unsigned char)(1 + ((max >> 11) & 0x03));
492 max = max & 0x8ff; /* bit 0~10 */ 492 max = max & 0x7ff; /* bit 0~10 */
493 /* 3 transactions at most */ 493 /* 3 transactions at most */
494 if (mult > 3) 494 if (mult > 3)
495 goto en_done; 495 goto en_done;
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
new file mode 100644
index 000000000000..4b0e4a040d6f
--- /dev/null
+++ b/drivers/usb/gadget/g_ffs.c
@@ -0,0 +1,426 @@
1#include <linux/module.h>
2#include <linux/utsname.h>
3
4
5/*
6 * kbuild is not very cooperative with respect to linking separately
7 * compiled library objects into one module. So for now we won't use
8 * separate compilation ... ensuring init/exit sections work to shrink
9 * the runtime footprint, and giving us at least some parts of what
10 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
11 */
12
13#include "composite.c"
14#include "usbstring.c"
15#include "config.c"
16#include "epautoconf.c"
17
18#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
19# if defined USB_ETH_RNDIS
20# undef USB_ETH_RNDIS
21# endif
22# ifdef CONFIG_USB_FUNCTIONFS_RNDIS
23# define USB_ETH_RNDIS y
24# endif
25
26# include "f_ecm.c"
27# include "f_subset.c"
28# ifdef USB_ETH_RNDIS
29# include "f_rndis.c"
30# include "rndis.c"
31# endif
32# include "u_ether.c"
33
34static u8 gfs_hostaddr[ETH_ALEN];
35#else
36# if !defined CONFIG_USB_FUNCTIONFS_GENERIC
37# define CONFIG_USB_FUNCTIONFS_GENERIC
38# endif
39# define gether_cleanup() do { } while (0)
40# define gether_setup(gadget, hostaddr) ((int)0)
41#endif
42
43#include "f_fs.c"
44
45
46#define DRIVER_NAME "g_ffs"
47#define DRIVER_DESC "USB Function Filesystem"
48#define DRIVER_VERSION "24 Aug 2004"
49
50MODULE_DESCRIPTION(DRIVER_DESC);
51MODULE_AUTHOR("Michal Nazarewicz");
52MODULE_LICENSE("GPL");
53
54
55static unsigned short gfs_vendor_id = 0x0525; /* XXX NetChip */
56static unsigned short gfs_product_id = 0xa4ac; /* XXX */
57
58static struct usb_device_descriptor gfs_dev_desc = {
59 .bLength = sizeof gfs_dev_desc,
60 .bDescriptorType = USB_DT_DEVICE,
61
62 .bcdUSB = cpu_to_le16(0x0200),
63 .bDeviceClass = USB_CLASS_PER_INTERFACE,
64
65 /* Vendor and product id can be overridden by module parameters. */
66 /* .idVendor = cpu_to_le16(gfs_vendor_id), */
67 /* .idProduct = cpu_to_le16(gfs_product_id), */
68 /* .bcdDevice = f(hardware) */
69 /* .iManufacturer = DYNAMIC */
70 /* .iProduct = DYNAMIC */
71 /* NO SERIAL NUMBER */
72 .bNumConfigurations = 1,
73};
74
75#define GFS_MODULE_PARAM_DESC(name, field) \
76 MODULE_PARM_DESC(name, "Value of the " #field " field of the device descriptor sent to the host. Takes effect only prior to the user-space driver registering to the FunctionFS.")
77
78module_param_named(usb_class, gfs_dev_desc.bDeviceClass, byte, 0644);
79GFS_MODULE_PARAM_DESC(usb_class, bDeviceClass);
80module_param_named(usb_subclass, gfs_dev_desc.bDeviceSubClass, byte, 0644);
81GFS_MODULE_PARAM_DESC(usb_subclass, bDeviceSubClass);
82module_param_named(usb_protocol, gfs_dev_desc.bDeviceProtocol, byte, 0644);
83GFS_MODULE_PARAM_DESC(usb_protocol, bDeviceProtocol);
84module_param_named(usb_vendor, gfs_vendor_id, ushort, 0644);
85GFS_MODULE_PARAM_DESC(usb_vendor, idVendor);
86module_param_named(usb_product, gfs_product_id, ushort, 0644);
87GFS_MODULE_PARAM_DESC(usb_product, idProduct);
88
89
90
91static const struct usb_descriptor_header *gfs_otg_desc[] = {
92 (const struct usb_descriptor_header *)
93 &(const struct usb_otg_descriptor) {
94 .bLength = sizeof(struct usb_otg_descriptor),
95 .bDescriptorType = USB_DT_OTG,
96
97 /* REVISIT SRP-only hardware is possible, although
98 * it would not be called "OTG" ... */
99 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
100 },
101
102 NULL
103};
104
105/* string IDs are assigned dynamically */
106
107enum {
108 GFS_STRING_MANUFACTURER_IDX,
109 GFS_STRING_PRODUCT_IDX,
110#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
111 GFS_STRING_RNDIS_CONFIG_IDX,
112#endif
113#ifdef CONFIG_USB_FUNCTIONFS_ETH
114 GFS_STRING_ECM_CONFIG_IDX,
115#endif
116#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
117 GFS_STRING_GENERIC_CONFIG_IDX,
118#endif
119};
120
121static char gfs_manufacturer[50];
122static const char gfs_driver_desc[] = DRIVER_DESC;
123static const char gfs_short_name[] = DRIVER_NAME;
124
125static struct usb_string gfs_strings[] = {
126 [GFS_STRING_MANUFACTURER_IDX].s = gfs_manufacturer,
127 [GFS_STRING_PRODUCT_IDX].s = gfs_driver_desc,
128#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
129 [GFS_STRING_RNDIS_CONFIG_IDX].s = "FunctionFS + RNDIS",
130#endif
131#ifdef CONFIG_USB_FUNCTIONFS_ETH
132 [GFS_STRING_ECM_CONFIG_IDX].s = "FunctionFS + ECM",
133#endif
134#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
135 [GFS_STRING_GENERIC_CONFIG_IDX].s = "FunctionFS",
136#endif
137 { } /* end of list */
138};
139
140static struct usb_gadget_strings *gfs_dev_strings[] = {
141 &(struct usb_gadget_strings) {
142 .language = 0x0409, /* en-us */
143 .strings = gfs_strings,
144 },
145 NULL,
146};
147
148
149#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
150static int gfs_do_rndis_config(struct usb_configuration *c);
151
152static struct usb_configuration gfs_rndis_config_driver = {
153 .label = "FunctionFS + RNDIS",
154 .bind = gfs_do_rndis_config,
155 .bConfigurationValue = 1,
156 /* .iConfiguration = DYNAMIC */
157 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
158};
159# define gfs_add_rndis_config(cdev) \
160 usb_add_config(cdev, &gfs_rndis_config_driver)
161#else
162# define gfs_add_rndis_config(cdev) 0
163#endif
164
165
166#ifdef CONFIG_USB_FUNCTIONFS_ETH
167static int gfs_do_ecm_config(struct usb_configuration *c);
168
169static struct usb_configuration gfs_ecm_config_driver = {
170 .label = "FunctionFS + ECM",
171 .bind = gfs_do_ecm_config,
172 .bConfigurationValue = 1,
173 /* .iConfiguration = DYNAMIC */
174 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
175};
176# define gfs_add_ecm_config(cdev) \
177 usb_add_config(cdev, &gfs_ecm_config_driver)
178#else
179# define gfs_add_ecm_config(cdev) 0
180#endif
181
182
183#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
184static int gfs_do_generic_config(struct usb_configuration *c);
185
186static struct usb_configuration gfs_generic_config_driver = {
187 .label = "FunctionFS",
188 .bind = gfs_do_generic_config,
189 .bConfigurationValue = 2,
190 /* .iConfiguration = DYNAMIC */
191 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
192};
193# define gfs_add_generic_config(cdev) \
194 usb_add_config(cdev, &gfs_generic_config_driver)
195#else
196# define gfs_add_generic_config(cdev) 0
197#endif
198
199
200static int gfs_bind(struct usb_composite_dev *cdev);
201static int gfs_unbind(struct usb_composite_dev *cdev);
202
203static struct usb_composite_driver gfs_driver = {
204 .name = gfs_short_name,
205 .dev = &gfs_dev_desc,
206 .strings = gfs_dev_strings,
207 .bind = gfs_bind,
208 .unbind = gfs_unbind,
209};
210
211
212static struct ffs_data *gfs_ffs_data;
213static unsigned long gfs_registered;
214
215
216static int gfs_init(void)
217{
218 ENTER();
219
220 return functionfs_init();
221}
222module_init(gfs_init);
223
224static void gfs_exit(void)
225{
226 ENTER();
227
228 if (test_and_clear_bit(0, &gfs_registered))
229 usb_composite_unregister(&gfs_driver);
230
231 functionfs_cleanup();
232}
233module_exit(gfs_exit);
234
235
236static int functionfs_ready_callback(struct ffs_data *ffs)
237{
238 int ret;
239
240 ENTER();
241
242 if (WARN_ON(test_and_set_bit(0, &gfs_registered)))
243 return -EBUSY;
244
245 gfs_ffs_data = ffs;
246 ret = usb_composite_register(&gfs_driver);
247 if (unlikely(ret < 0))
248 clear_bit(0, &gfs_registered);
249 return ret;
250}
251
252static void functionfs_closed_callback(struct ffs_data *ffs)
253{
254 ENTER();
255
256 if (test_and_clear_bit(0, &gfs_registered))
257 usb_composite_unregister(&gfs_driver);
258}
259
260
261static int functionfs_check_dev_callback(const char *dev_name)
262{
263 return 0;
264}
265
266
267
268static int gfs_bind(struct usb_composite_dev *cdev)
269{
270 int ret;
271
272 ENTER();
273
274 if (WARN_ON(!gfs_ffs_data))
275 return -ENODEV;
276
277 ret = gether_setup(cdev->gadget, gfs_hostaddr);
278 if (unlikely(ret < 0))
279 goto error_quick;
280
281 gfs_dev_desc.idVendor = cpu_to_le16(gfs_vendor_id);
282 gfs_dev_desc.idProduct = cpu_to_le16(gfs_product_id);
283
284 snprintf(gfs_manufacturer, sizeof gfs_manufacturer, "%s %s with %s",
285 init_utsname()->sysname, init_utsname()->release,
286 cdev->gadget->name);
287 ret = usb_string_id(cdev);
288 if (unlikely(ret < 0))
289 goto error;
290 gfs_strings[GFS_STRING_MANUFACTURER_IDX].id = ret;
291 gfs_dev_desc.iManufacturer = ret;
292
293 ret = usb_string_id(cdev);
294 if (unlikely(ret < 0))
295 goto error;
296 gfs_strings[GFS_STRING_PRODUCT_IDX].id = ret;
297 gfs_dev_desc.iProduct = ret;
298
299#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
300 ret = usb_string_id(cdev);
301 if (unlikely(ret < 0))
302 goto error;
303 gfs_strings[GFS_STRING_RNDIS_CONFIG_IDX].id = ret;
304 gfs_rndis_config_driver.iConfiguration = ret;
305#endif
306
307#ifdef CONFIG_USB_FUNCTIONFS_ETH
308 ret = usb_string_id(cdev);
309 if (unlikely(ret < 0))
310 goto error;
311 gfs_strings[GFS_STRING_ECM_CONFIG_IDX].id = ret;
312 gfs_ecm_config_driver.iConfiguration = ret;
313#endif
314
315#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
316 ret = usb_string_id(cdev);
317 if (unlikely(ret < 0))
318 goto error;
319 gfs_strings[GFS_STRING_GENERIC_CONFIG_IDX].id = ret;
320 gfs_generic_config_driver.iConfiguration = ret;
321#endif
322
323 ret = functionfs_bind(gfs_ffs_data, cdev);
324 if (unlikely(ret < 0))
325 goto error;
326
327 ret = gfs_add_rndis_config(cdev);
328 if (unlikely(ret < 0))
329 goto error_unbind;
330
331 ret = gfs_add_ecm_config(cdev);
332 if (unlikely(ret < 0))
333 goto error_unbind;
334
335 ret = gfs_add_generic_config(cdev);
336 if (unlikely(ret < 0))
337 goto error_unbind;
338
339 return 0;
340
341error_unbind:
342 functionfs_unbind(gfs_ffs_data);
343error:
344 gether_cleanup();
345error_quick:
346 gfs_ffs_data = NULL;
347 return ret;
348}
349
350static int gfs_unbind(struct usb_composite_dev *cdev)
351{
352 ENTER();
353
354 /* We may have been called in an error recovery frem
355 * composite_bind() after gfs_unbind() failure so we need to
356 * check if gfs_ffs_data is not NULL since gfs_bind() handles
357 * all error recovery itself. I'd rather we werent called
358 * from composite on orror recovery, but what you're gonna
359 * do...? */
360
361 if (gfs_ffs_data) {
362 gether_cleanup();
363 functionfs_unbind(gfs_ffs_data);
364 gfs_ffs_data = NULL;
365 }
366
367 return 0;
368}
369
370
371static int __gfs_do_config(struct usb_configuration *c,
372 int (*eth)(struct usb_configuration *c, u8 *ethaddr),
373 u8 *ethaddr)
374{
375 int ret;
376
377 if (WARN_ON(!gfs_ffs_data))
378 return -ENODEV;
379
380 if (gadget_is_otg(c->cdev->gadget)) {
381 c->descriptors = gfs_otg_desc;
382 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
383 }
384
385 if (eth) {
386 ret = eth(c, ethaddr);
387 if (unlikely(ret < 0))
388 return ret;
389 }
390
391 ret = functionfs_add(c->cdev, c, gfs_ffs_data);
392 if (unlikely(ret < 0))
393 return ret;
394
395 return 0;
396}
397
398#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
399static int gfs_do_rndis_config(struct usb_configuration *c)
400{
401 ENTER();
402
403 return __gfs_do_config(c, rndis_bind_config, gfs_hostaddr);
404}
405#endif
406
407#ifdef CONFIG_USB_FUNCTIONFS_ETH
408static int gfs_do_ecm_config(struct usb_configuration *c)
409{
410 ENTER();
411
412 return __gfs_do_config(c,
413 can_support_ecm(c->cdev->gadget)
414 ? ecm_bind_config : geth_bind_config,
415 gfs_hostaddr);
416}
417#endif
418
419#ifdef CONFIG_USB_FUNCTIONFS_GENERIC
420static int gfs_do_generic_config(struct usb_configuration *c)
421{
422 ENTER();
423
424 return __gfs_do_config(c, NULL, NULL);
425}
426#endif
diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.c
new file mode 100644
index 000000000000..775722686ed8
--- /dev/null
+++ b/drivers/usb/gadget/hid.c
@@ -0,0 +1,298 @@
1/*
2 * hid.c -- HID Composite driver
3 *
4 * Based on multi.c
5 *
6 * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.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; 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
24#include <linux/kernel.h>
25#include <linux/platform_device.h>
26#include <linux/list.h>
27
28#define DRIVER_DESC "HID Gadget"
29#define DRIVER_VERSION "2010/03/16"
30
31/*-------------------------------------------------------------------------*/
32
33#define HIDG_VENDOR_NUM 0x0525 /* XXX NetChip */
34#define HIDG_PRODUCT_NUM 0xa4ac /* Linux-USB HID gadget */
35
36/*-------------------------------------------------------------------------*/
37
38/*
39 * kbuild is not very cooperative with respect to linking separately
40 * compiled library objects into one module. So for now we won't use
41 * separate compilation ... ensuring init/exit sections work to shrink
42 * the runtime footprint, and giving us at least some parts of what
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
44 */
45
46#include "composite.c"
47#include "usbstring.c"
48#include "config.c"
49#include "epautoconf.c"
50
51#include "f_hid.c"
52
53
54struct hidg_func_node {
55 struct list_head node;
56 struct hidg_func_descriptor *func;
57};
58
59static LIST_HEAD(hidg_func_list);
60
61/*-------------------------------------------------------------------------*/
62
63static struct usb_device_descriptor device_desc = {
64 .bLength = sizeof device_desc,
65 .bDescriptorType = USB_DT_DEVICE,
66
67 .bcdUSB = cpu_to_le16(0x0200),
68
69 /* .bDeviceClass = USB_CLASS_COMM, */
70 /* .bDeviceSubClass = 0, */
71 /* .bDeviceProtocol = 0, */
72 .bDeviceClass = 0xEF,
73 .bDeviceSubClass = 2,
74 .bDeviceProtocol = 1,
75 /* .bMaxPacketSize0 = f(hardware) */
76
77 /* Vendor and product id can be overridden by module parameters. */
78 .idVendor = cpu_to_le16(HIDG_VENDOR_NUM),
79 .idProduct = cpu_to_le16(HIDG_PRODUCT_NUM),
80 /* .bcdDevice = f(hardware) */
81 /* .iManufacturer = DYNAMIC */
82 /* .iProduct = DYNAMIC */
83 /* NO SERIAL NUMBER */
84 .bNumConfigurations = 1,
85};
86
87static struct usb_otg_descriptor otg_descriptor = {
88 .bLength = sizeof otg_descriptor,
89 .bDescriptorType = USB_DT_OTG,
90
91 /* REVISIT SRP-only hardware is possible, although
92 * it would not be called "OTG" ...
93 */
94 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
95};
96
97static const struct usb_descriptor_header *otg_desc[] = {
98 (struct usb_descriptor_header *) &otg_descriptor,
99 NULL,
100};
101
102
103/* string IDs are assigned dynamically */
104
105#define STRING_MANUFACTURER_IDX 0
106#define STRING_PRODUCT_IDX 1
107
108static char manufacturer[50];
109
110static struct usb_string strings_dev[] = {
111 [STRING_MANUFACTURER_IDX].s = manufacturer,
112 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
113 { } /* end of list */
114};
115
116static struct usb_gadget_strings stringtab_dev = {
117 .language = 0x0409, /* en-us */
118 .strings = strings_dev,
119};
120
121static struct usb_gadget_strings *dev_strings[] = {
122 &stringtab_dev,
123 NULL,
124};
125
126
127
128/****************************** Configurations ******************************/
129
130static int __init do_config(struct usb_configuration *c)
131{
132 struct hidg_func_node *e;
133 int func = 0, status = 0;
134
135 if (gadget_is_otg(c->cdev->gadget)) {
136 c->descriptors = otg_desc;
137 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
138 }
139
140 list_for_each_entry(e, &hidg_func_list, node) {
141 status = hidg_bind_config(c, e->func, func++);
142 if (status)
143 break;
144 }
145
146 return status;
147}
148
149static struct usb_configuration config_driver = {
150 .label = "HID Gadget",
151 .bind = do_config,
152 .bConfigurationValue = 1,
153 /* .iConfiguration = DYNAMIC */
154 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
155};
156
157/****************************** Gadget Bind ******************************/
158
159static int __init hid_bind(struct usb_composite_dev *cdev)
160{
161 struct usb_gadget *gadget = cdev->gadget;
162 struct list_head *tmp;
163 int status, gcnum, funcs = 0;
164
165 list_for_each(tmp, &hidg_func_list)
166 funcs++;
167
168 if (!funcs)
169 return -ENODEV;
170
171 /* set up HID */
172 status = ghid_setup(cdev->gadget, funcs);
173 if (status < 0)
174 return status;
175
176 gcnum = usb_gadget_controller_number(gadget);
177 if (gcnum >= 0)
178 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
179 else
180 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
181
182
183 /* Allocate string descriptor numbers ... note that string
184 * contents can be overridden by the composite_dev glue.
185 */
186
187 /* device descriptor strings: manufacturer, product */
188 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
189 init_utsname()->sysname, init_utsname()->release,
190 gadget->name);
191 status = usb_string_id(cdev);
192 if (status < 0)
193 return status;
194 strings_dev[STRING_MANUFACTURER_IDX].id = status;
195 device_desc.iManufacturer = status;
196
197 status = usb_string_id(cdev);
198 if (status < 0)
199 return status;
200 strings_dev[STRING_PRODUCT_IDX].id = status;
201 device_desc.iProduct = status;
202
203 /* register our configuration */
204 status = usb_add_config(cdev, &config_driver);
205 if (status < 0)
206 return status;
207
208 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
209
210 return 0;
211}
212
213static int __exit hid_unbind(struct usb_composite_dev *cdev)
214{
215 ghid_cleanup();
216 return 0;
217}
218
219static int __init hidg_plat_driver_probe(struct platform_device *pdev)
220{
221 struct hidg_func_descriptor *func = pdev->dev.platform_data;
222 struct hidg_func_node *entry;
223
224 if (!func) {
225 dev_err(&pdev->dev, "Platform data missing\n");
226 return -ENODEV;
227 }
228
229 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
230 if (!entry)
231 return -ENOMEM;
232
233 entry->func = func;
234 list_add_tail(&entry->node, &hidg_func_list);
235
236 return 0;
237}
238
239static int __devexit hidg_plat_driver_remove(struct platform_device *pdev)
240{
241 struct hidg_func_node *e, *n;
242
243 list_for_each_entry_safe(e, n, &hidg_func_list, node) {
244 list_del(&e->node);
245 kfree(e);
246 }
247
248 return 0;
249}
250
251
252/****************************** Some noise ******************************/
253
254
255static struct usb_composite_driver hidg_driver = {
256 .name = "g_hid",
257 .dev = &device_desc,
258 .strings = dev_strings,
259 .bind = hid_bind,
260 .unbind = __exit_p(hid_unbind),
261};
262
263static struct platform_driver hidg_plat_driver = {
264 .remove = __devexit_p(hidg_plat_driver_remove),
265 .driver = {
266 .owner = THIS_MODULE,
267 .name = "hidg",
268 },
269};
270
271
272MODULE_DESCRIPTION(DRIVER_DESC);
273MODULE_AUTHOR("Fabien Chouteau, Peter Korsgaard");
274MODULE_LICENSE("GPL");
275
276static int __init hidg_init(void)
277{
278 int status;
279
280 status = platform_driver_probe(&hidg_plat_driver,
281 hidg_plat_driver_probe);
282 if (status < 0)
283 return status;
284
285 status = usb_composite_register(&hidg_driver);
286 if (status < 0)
287 platform_driver_unregister(&hidg_plat_driver);
288
289 return status;
290}
291module_init(hidg_init);
292
293static void __exit hidg_cleanup(void)
294{
295 platform_driver_unregister(&hidg_plat_driver);
296 usb_composite_unregister(&hidg_driver);
297}
298module_exit(hidg_cleanup);
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index ff61e4866e8a..cd16231d8c73 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -360,7 +360,7 @@ struct pxa_ep {
360 * Specific pxa endpoint data, needed for hardware initialization 360 * Specific pxa endpoint data, needed for hardware initialization
361 */ 361 */
362 unsigned dir_in:1; 362 unsigned dir_in:1;
363 unsigned addr:3; 363 unsigned addr:4;
364 unsigned config:2; 364 unsigned config:2;
365 unsigned interface:3; 365 unsigned interface:3;
366 unsigned alternate:3; 366 unsigned alternate:3;
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 07f4178ad178..1da755a1c855 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -715,7 +715,7 @@ static u8 __init nibble(unsigned char c)
715 return 0; 715 return 0;
716} 716}
717 717
718static int __init get_ether_addr(const char *str, u8 *dev_addr) 718static int get_ether_addr(const char *str, u8 *dev_addr)
719{ 719{
720 if (str) { 720 if (str) {
721 unsigned i; 721 unsigned i;
@@ -764,7 +764,7 @@ static struct device_type gadget_type = {
764 * 764 *
765 * Returns negative errno, or zero on success 765 * Returns negative errno, or zero on success
766 */ 766 */
767int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) 767int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
768{ 768{
769 struct eth_dev *dev; 769 struct eth_dev *dev;
770 struct net_device *net; 770 struct net_device *net;
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
new file mode 100644
index 000000000000..0a705e63c936
--- /dev/null
+++ b/drivers/usb/gadget/uvc.h
@@ -0,0 +1,241 @@
1/*
2 * uvc_gadget.h -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#ifndef _UVC_GADGET_H_
15#define _UVC_GADGET_H_
16
17#include <linux/ioctl.h>
18#include <linux/types.h>
19#include <linux/usb/ch9.h>
20
21#define UVC_EVENT_FIRST (V4L2_EVENT_PRIVATE_START + 0)
22#define UVC_EVENT_CONNECT (V4L2_EVENT_PRIVATE_START + 0)
23#define UVC_EVENT_DISCONNECT (V4L2_EVENT_PRIVATE_START + 1)
24#define UVC_EVENT_STREAMON (V4L2_EVENT_PRIVATE_START + 2)
25#define UVC_EVENT_STREAMOFF (V4L2_EVENT_PRIVATE_START + 3)
26#define UVC_EVENT_SETUP (V4L2_EVENT_PRIVATE_START + 4)
27#define UVC_EVENT_DATA (V4L2_EVENT_PRIVATE_START + 5)
28#define UVC_EVENT_LAST (V4L2_EVENT_PRIVATE_START + 5)
29
30struct uvc_request_data
31{
32 unsigned int length;
33 __u8 data[60];
34};
35
36struct uvc_event
37{
38 union {
39 enum usb_device_speed speed;
40 struct usb_ctrlrequest req;
41 struct uvc_request_data data;
42 };
43};
44
45#define UVCIOC_SEND_RESPONSE _IOW('U', 1, struct uvc_request_data)
46
47#define UVC_INTF_CONTROL 0
48#define UVC_INTF_STREAMING 1
49
50/* ------------------------------------------------------------------------
51 * UVC constants & structures
52 */
53
54/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
55#define UVC_STREAM_EOH (1 << 7)
56#define UVC_STREAM_ERR (1 << 6)
57#define UVC_STREAM_STI (1 << 5)
58#define UVC_STREAM_RES (1 << 4)
59#define UVC_STREAM_SCR (1 << 3)
60#define UVC_STREAM_PTS (1 << 2)
61#define UVC_STREAM_EOF (1 << 1)
62#define UVC_STREAM_FID (1 << 0)
63
64struct uvc_streaming_control {
65 __u16 bmHint;
66 __u8 bFormatIndex;
67 __u8 bFrameIndex;
68 __u32 dwFrameInterval;
69 __u16 wKeyFrameRate;
70 __u16 wPFrameRate;
71 __u16 wCompQuality;
72 __u16 wCompWindowSize;
73 __u16 wDelay;
74 __u32 dwMaxVideoFrameSize;
75 __u32 dwMaxPayloadTransferSize;
76 __u32 dwClockFrequency;
77 __u8 bmFramingInfo;
78 __u8 bPreferedVersion;
79 __u8 bMinVersion;
80 __u8 bMaxVersion;
81} __attribute__((__packed__));
82
83/* ------------------------------------------------------------------------
84 * Debugging, printing and logging
85 */
86
87#ifdef __KERNEL__
88
89#include <linux/usb.h> /* For usb_endpoint_* */
90#include <linux/usb/gadget.h>
91#include <linux/videodev2.h>
92#include <media/v4l2-fh.h>
93
94#include "uvc_queue.h"
95
96#define UVC_TRACE_PROBE (1 << 0)
97#define UVC_TRACE_DESCR (1 << 1)
98#define UVC_TRACE_CONTROL (1 << 2)
99#define UVC_TRACE_FORMAT (1 << 3)
100#define UVC_TRACE_CAPTURE (1 << 4)
101#define UVC_TRACE_CALLS (1 << 5)
102#define UVC_TRACE_IOCTL (1 << 6)
103#define UVC_TRACE_FRAME (1 << 7)
104#define UVC_TRACE_SUSPEND (1 << 8)
105#define UVC_TRACE_STATUS (1 << 9)
106
107#define UVC_WARN_MINMAX 0
108#define UVC_WARN_PROBE_DEF 1
109
110extern unsigned int uvc_trace_param;
111
112#define uvc_trace(flag, msg...) \
113 do { \
114 if (uvc_trace_param & flag) \
115 printk(KERN_DEBUG "uvcvideo: " msg); \
116 } while (0)
117
118#define uvc_warn_once(dev, warn, msg...) \
119 do { \
120 if (!test_and_set_bit(warn, &dev->warnings)) \
121 printk(KERN_INFO "uvcvideo: " msg); \
122 } while (0)
123
124#define uvc_printk(level, msg...) \
125 printk(level "uvcvideo: " msg)
126
127/* ------------------------------------------------------------------------
128 * Driver specific constants
129 */
130
131#define DRIVER_VERSION "0.1.0"
132#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
133
134#define DMA_ADDR_INVALID (~(dma_addr_t)0)
135
136#define UVC_NUM_REQUESTS 4
137#define UVC_MAX_REQUEST_SIZE 64
138#define UVC_MAX_EVENTS 4
139
140#define USB_DT_INTERFACE_ASSOCIATION_SIZE 8
141#define USB_CLASS_MISC 0xef
142
143/* ------------------------------------------------------------------------
144 * Structures
145 */
146
147struct uvc_video
148{
149 struct usb_ep *ep;
150
151 /* Frame parameters */
152 u8 bpp;
153 u32 fcc;
154 unsigned int width;
155 unsigned int height;
156 unsigned int imagesize;
157
158 /* Requests */
159 unsigned int req_size;
160 struct usb_request *req[UVC_NUM_REQUESTS];
161 __u8 *req_buffer[UVC_NUM_REQUESTS];
162 struct list_head req_free;
163 spinlock_t req_lock;
164
165 void (*encode) (struct usb_request *req, struct uvc_video *video,
166 struct uvc_buffer *buf);
167
168 /* Context data used by the completion handler */
169 __u32 payload_size;
170 __u32 max_payload_size;
171
172 struct uvc_video_queue queue;
173 unsigned int fid;
174};
175
176enum uvc_state
177{
178 UVC_STATE_DISCONNECTED,
179 UVC_STATE_CONNECTED,
180 UVC_STATE_STREAMING,
181};
182
183struct uvc_device
184{
185 struct video_device *vdev;
186 enum uvc_state state;
187 struct usb_function func;
188 struct uvc_video video;
189
190 /* Descriptors */
191 struct {
192 const struct uvc_descriptor_header * const *control;
193 const struct uvc_descriptor_header * const *fs_streaming;
194 const struct uvc_descriptor_header * const *hs_streaming;
195 } desc;
196
197 unsigned int control_intf;
198 struct usb_ep *control_ep;
199 struct usb_request *control_req;
200 void *control_buf;
201
202 unsigned int streaming_intf;
203
204 /* Events */
205 unsigned int event_length;
206 unsigned int event_setup_out : 1;
207};
208
209static inline struct uvc_device *to_uvc(struct usb_function *f)
210{
211 return container_of(f, struct uvc_device, func);
212}
213
214struct uvc_file_handle
215{
216 struct v4l2_fh vfh;
217 struct uvc_video *device;
218};
219
220#define to_uvc_file_handle(handle) \
221 container_of(handle, struct uvc_file_handle, vfh)
222
223extern struct v4l2_file_operations uvc_v4l2_fops;
224
225/* ------------------------------------------------------------------------
226 * Functions
227 */
228
229extern int uvc_video_enable(struct uvc_video *video, int enable);
230extern int uvc_video_init(struct uvc_video *video);
231extern int uvc_video_pump(struct uvc_video *video);
232
233extern void uvc_endpoint_stream(struct uvc_device *dev);
234
235extern void uvc_function_connect(struct uvc_device *uvc);
236extern void uvc_function_disconnect(struct uvc_device *uvc);
237
238#endif /* __KERNEL__ */
239
240#endif /* _UVC_GADGET_H_ */
241
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
new file mode 100644
index 000000000000..43891991bf21
--- /dev/null
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -0,0 +1,583 @@
1/*
2 * uvc_queue.c -- USB Video Class driver - Buffers management
3 *
4 * Copyright (C) 2005-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/mm.h>
16#include <linux/list.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19#include <linux/videodev2.h>
20#include <linux/vmalloc.h>
21#include <linux/wait.h>
22#include <asm/atomic.h>
23
24#include "uvc.h"
25
26/* ------------------------------------------------------------------------
27 * Video buffers queue management.
28 *
29 * Video queues is initialized by uvc_queue_init(). The function performs
30 * basic initialization of the uvc_video_queue struct and never fails.
31 *
32 * Video buffer allocation and freeing are performed by uvc_alloc_buffers and
33 * uvc_free_buffers respectively. The former acquires the video queue lock,
34 * while the later must be called with the lock held (so that allocation can
35 * free previously allocated buffers). Trying to free buffers that are mapped
36 * to user space will return -EBUSY.
37 *
38 * Video buffers are managed using two queues. However, unlike most USB video
39 * drivers that use an in queue and an out queue, we use a main queue to hold
40 * all queued buffers (both 'empty' and 'done' buffers), and an irq queue to
41 * hold empty buffers. This design (copied from video-buf) minimizes locking
42 * in interrupt, as only one queue is shared between interrupt and user
43 * contexts.
44 *
45 * Use cases
46 * ---------
47 *
48 * Unless stated otherwise, all operations that modify the irq buffers queue
49 * are protected by the irq spinlock.
50 *
51 * 1. The user queues the buffers, starts streaming and dequeues a buffer.
52 *
53 * The buffers are added to the main and irq queues. Both operations are
54 * protected by the queue lock, and the later is protected by the irq
55 * spinlock as well.
56 *
57 * The completion handler fetches a buffer from the irq queue and fills it
58 * with video data. If no buffer is available (irq queue empty), the handler
59 * returns immediately.
60 *
61 * When the buffer is full, the completion handler removes it from the irq
62 * queue, marks it as ready (UVC_BUF_STATE_DONE) and wakes its wait queue.
63 * At that point, any process waiting on the buffer will be woken up. If a
64 * process tries to dequeue a buffer after it has been marked ready, the
65 * dequeing will succeed immediately.
66 *
67 * 2. Buffers are queued, user is waiting on a buffer and the device gets
68 * disconnected.
69 *
70 * When the device is disconnected, the kernel calls the completion handler
71 * with an appropriate status code. The handler marks all buffers in the
72 * irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so
73 * that any process waiting on a buffer gets woken up.
74 *
75 * Waking up up the first buffer on the irq list is not enough, as the
76 * process waiting on the buffer might restart the dequeue operation
77 * immediately.
78 *
79 */
80
81void uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type)
82{
83 mutex_init(&queue->mutex);
84 spin_lock_init(&queue->irqlock);
85 INIT_LIST_HEAD(&queue->mainqueue);
86 INIT_LIST_HEAD(&queue->irqqueue);
87 queue->type = type;
88}
89
90/*
91 * Allocate the video buffers.
92 *
93 * Pages are reserved to make sure they will not be swapped, as they will be
94 * filled in the URB completion handler.
95 *
96 * Buffers will be individually mapped, so they must all be page aligned.
97 */
98int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
99 unsigned int buflength)
100{
101 unsigned int bufsize = PAGE_ALIGN(buflength);
102 unsigned int i;
103 void *mem = NULL;
104 int ret;
105
106 if (nbuffers > UVC_MAX_VIDEO_BUFFERS)
107 nbuffers = UVC_MAX_VIDEO_BUFFERS;
108
109 mutex_lock(&queue->mutex);
110
111 if ((ret = uvc_free_buffers(queue)) < 0)
112 goto done;
113
114 /* Bail out if no buffers should be allocated. */
115 if (nbuffers == 0)
116 goto done;
117
118 /* Decrement the number of buffers until allocation succeeds. */
119 for (; nbuffers > 0; --nbuffers) {
120 mem = vmalloc_32(nbuffers * bufsize);
121 if (mem != NULL)
122 break;
123 }
124
125 if (mem == NULL) {
126 ret = -ENOMEM;
127 goto done;
128 }
129
130 for (i = 0; i < nbuffers; ++i) {
131 memset(&queue->buffer[i], 0, sizeof queue->buffer[i]);
132 queue->buffer[i].buf.index = i;
133 queue->buffer[i].buf.m.offset = i * bufsize;
134 queue->buffer[i].buf.length = buflength;
135 queue->buffer[i].buf.type = queue->type;
136 queue->buffer[i].buf.sequence = 0;
137 queue->buffer[i].buf.field = V4L2_FIELD_NONE;
138 queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
139 queue->buffer[i].buf.flags = 0;
140 init_waitqueue_head(&queue->buffer[i].wait);
141 }
142
143 queue->mem = mem;
144 queue->count = nbuffers;
145 queue->buf_size = bufsize;
146 ret = nbuffers;
147
148done:
149 mutex_unlock(&queue->mutex);
150 return ret;
151}
152
153/*
154 * Free the video buffers.
155 *
156 * This function must be called with the queue lock held.
157 */
158int uvc_free_buffers(struct uvc_video_queue *queue)
159{
160 unsigned int i;
161
162 for (i = 0; i < queue->count; ++i) {
163 if (queue->buffer[i].vma_use_count != 0)
164 return -EBUSY;
165 }
166
167 if (queue->count) {
168 vfree(queue->mem);
169 queue->count = 0;
170 }
171
172 return 0;
173}
174
175static void __uvc_query_buffer(struct uvc_buffer *buf,
176 struct v4l2_buffer *v4l2_buf)
177{
178 memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf);
179
180 if (buf->vma_use_count)
181 v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED;
182
183 switch (buf->state) {
184 case UVC_BUF_STATE_ERROR:
185 case UVC_BUF_STATE_DONE:
186 v4l2_buf->flags |= V4L2_BUF_FLAG_DONE;
187 break;
188 case UVC_BUF_STATE_QUEUED:
189 case UVC_BUF_STATE_ACTIVE:
190 v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED;
191 break;
192 case UVC_BUF_STATE_IDLE:
193 default:
194 break;
195 }
196}
197
198int uvc_query_buffer(struct uvc_video_queue *queue,
199 struct v4l2_buffer *v4l2_buf)
200{
201 int ret = 0;
202
203 mutex_lock(&queue->mutex);
204 if (v4l2_buf->index >= queue->count) {
205 ret = -EINVAL;
206 goto done;
207 }
208
209 __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf);
210
211done:
212 mutex_unlock(&queue->mutex);
213 return ret;
214}
215
216/*
217 * Queue a video buffer. Attempting to queue a buffer that has already been
218 * queued will return -EINVAL.
219 */
220int uvc_queue_buffer(struct uvc_video_queue *queue,
221 struct v4l2_buffer *v4l2_buf)
222{
223 struct uvc_buffer *buf;
224 unsigned long flags;
225 int ret = 0;
226
227 uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index);
228
229 if (v4l2_buf->type != queue->type ||
230 v4l2_buf->memory != V4L2_MEMORY_MMAP) {
231 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
232 "and/or memory (%u).\n", v4l2_buf->type,
233 v4l2_buf->memory);
234 return -EINVAL;
235 }
236
237 mutex_lock(&queue->mutex);
238 if (v4l2_buf->index >= queue->count) {
239 uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n");
240 ret = -EINVAL;
241 goto done;
242 }
243
244 buf = &queue->buffer[v4l2_buf->index];
245 if (buf->state != UVC_BUF_STATE_IDLE) {
246 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state "
247 "(%u).\n", buf->state);
248 ret = -EINVAL;
249 goto done;
250 }
251
252 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
253 v4l2_buf->bytesused > buf->buf.length) {
254 uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
255 ret = -EINVAL;
256 goto done;
257 }
258
259 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
260 buf->buf.bytesused = 0;
261 else
262 buf->buf.bytesused = v4l2_buf->bytesused;
263
264 spin_lock_irqsave(&queue->irqlock, flags);
265 if (queue->flags & UVC_QUEUE_DISCONNECTED) {
266 spin_unlock_irqrestore(&queue->irqlock, flags);
267 ret = -ENODEV;
268 goto done;
269 }
270 buf->state = UVC_BUF_STATE_QUEUED;
271
272 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0;
273 queue->flags &= ~UVC_QUEUE_PAUSED;
274
275 list_add_tail(&buf->stream, &queue->mainqueue);
276 list_add_tail(&buf->queue, &queue->irqqueue);
277 spin_unlock_irqrestore(&queue->irqlock, flags);
278
279done:
280 mutex_unlock(&queue->mutex);
281 return ret;
282}
283
284static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking)
285{
286 if (nonblocking) {
287 return (buf->state != UVC_BUF_STATE_QUEUED &&
288 buf->state != UVC_BUF_STATE_ACTIVE)
289 ? 0 : -EAGAIN;
290 }
291
292 return wait_event_interruptible(buf->wait,
293 buf->state != UVC_BUF_STATE_QUEUED &&
294 buf->state != UVC_BUF_STATE_ACTIVE);
295}
296
297/*
298 * Dequeue a video buffer. If nonblocking is false, block until a buffer is
299 * available.
300 */
301int uvc_dequeue_buffer(struct uvc_video_queue *queue,
302 struct v4l2_buffer *v4l2_buf, int nonblocking)
303{
304 struct uvc_buffer *buf;
305 int ret = 0;
306
307 if (v4l2_buf->type != queue->type ||
308 v4l2_buf->memory != V4L2_MEMORY_MMAP) {
309 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
310 "and/or memory (%u).\n", v4l2_buf->type,
311 v4l2_buf->memory);
312 return -EINVAL;
313 }
314
315 mutex_lock(&queue->mutex);
316 if (list_empty(&queue->mainqueue)) {
317 uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n");
318 ret = -EINVAL;
319 goto done;
320 }
321
322 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
323 if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0)
324 goto done;
325
326 uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n",
327 buf->buf.index, buf->state, buf->buf.bytesused);
328
329 switch (buf->state) {
330 case UVC_BUF_STATE_ERROR:
331 uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data "
332 "(transmission error).\n");
333 ret = -EIO;
334 case UVC_BUF_STATE_DONE:
335 buf->state = UVC_BUF_STATE_IDLE;
336 break;
337
338 case UVC_BUF_STATE_IDLE:
339 case UVC_BUF_STATE_QUEUED:
340 case UVC_BUF_STATE_ACTIVE:
341 default:
342 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u "
343 "(driver bug?).\n", buf->state);
344 ret = -EINVAL;
345 goto done;
346 }
347
348 list_del(&buf->stream);
349 __uvc_query_buffer(buf, v4l2_buf);
350
351done:
352 mutex_unlock(&queue->mutex);
353 return ret;
354}
355
356/*
357 * Poll the video queue.
358 *
359 * This function implements video queue polling and is intended to be used by
360 * the device poll handler.
361 */
362unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
363 poll_table *wait)
364{
365 struct uvc_buffer *buf;
366 unsigned int mask = 0;
367
368 mutex_lock(&queue->mutex);
369 if (list_empty(&queue->mainqueue))
370 goto done;
371
372 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
373
374 poll_wait(file, &buf->wait, wait);
375 if (buf->state == UVC_BUF_STATE_DONE ||
376 buf->state == UVC_BUF_STATE_ERROR)
377 mask |= POLLOUT | POLLWRNORM;
378
379done:
380 mutex_unlock(&queue->mutex);
381 return mask;
382}
383
384/*
385 * VMA operations.
386 */
387static void uvc_vm_open(struct vm_area_struct *vma)
388{
389 struct uvc_buffer *buffer = vma->vm_private_data;
390 buffer->vma_use_count++;
391}
392
393static void uvc_vm_close(struct vm_area_struct *vma)
394{
395 struct uvc_buffer *buffer = vma->vm_private_data;
396 buffer->vma_use_count--;
397}
398
399static struct vm_operations_struct uvc_vm_ops = {
400 .open = uvc_vm_open,
401 .close = uvc_vm_close,
402};
403
404/*
405 * Memory-map a buffer.
406 *
407 * This function implements video buffer memory mapping and is intended to be
408 * used by the device mmap handler.
409 */
410int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma)
411{
412 struct uvc_buffer *uninitialized_var(buffer);
413 struct page *page;
414 unsigned long addr, start, size;
415 unsigned int i;
416 int ret = 0;
417
418 start = vma->vm_start;
419 size = vma->vm_end - vma->vm_start;
420
421 mutex_lock(&queue->mutex);
422
423 for (i = 0; i < queue->count; ++i) {
424 buffer = &queue->buffer[i];
425 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
426 break;
427 }
428
429 if (i == queue->count || size != queue->buf_size) {
430 ret = -EINVAL;
431 goto done;
432 }
433
434 /*
435 * VM_IO marks the area as being an mmaped region for I/O to a
436 * device. It also prevents the region from being core dumped.
437 */
438 vma->vm_flags |= VM_IO;
439
440 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
441 while (size > 0) {
442 page = vmalloc_to_page((void *)addr);
443 if ((ret = vm_insert_page(vma, start, page)) < 0)
444 goto done;
445
446 start += PAGE_SIZE;
447 addr += PAGE_SIZE;
448 size -= PAGE_SIZE;
449 }
450
451 vma->vm_ops = &uvc_vm_ops;
452 vma->vm_private_data = buffer;
453 uvc_vm_open(vma);
454
455done:
456 mutex_unlock(&queue->mutex);
457 return ret;
458}
459
460/*
461 * Enable or disable the video buffers queue.
462 *
463 * The queue must be enabled before starting video acquisition and must be
464 * disabled after stopping it. This ensures that the video buffers queue
465 * state can be properly initialized before buffers are accessed from the
466 * interrupt handler.
467 *
468 * Enabling the video queue initializes parameters (such as sequence number,
469 * sync pattern, ...). If the queue is already enabled, return -EBUSY.
470 *
471 * Disabling the video queue cancels the queue and removes all buffers from
472 * the main queue.
473 *
474 * This function can't be called from interrupt context. Use
475 * uvc_queue_cancel() instead.
476 */
477int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
478{
479 unsigned int i;
480 int ret = 0;
481
482 mutex_lock(&queue->mutex);
483 if (enable) {
484 if (uvc_queue_streaming(queue)) {
485 ret = -EBUSY;
486 goto done;
487 }
488 queue->sequence = 0;
489 queue->flags |= UVC_QUEUE_STREAMING;
490 queue->buf_used = 0;
491 } else {
492 uvc_queue_cancel(queue, 0);
493 INIT_LIST_HEAD(&queue->mainqueue);
494
495 for (i = 0; i < queue->count; ++i)
496 queue->buffer[i].state = UVC_BUF_STATE_IDLE;
497
498 queue->flags &= ~UVC_QUEUE_STREAMING;
499 }
500
501done:
502 mutex_unlock(&queue->mutex);
503 return ret;
504}
505
506/*
507 * Cancel the video buffers queue.
508 *
509 * Cancelling the queue marks all buffers on the irq queue as erroneous,
510 * wakes them up and removes them from the queue.
511 *
512 * If the disconnect parameter is set, further calls to uvc_queue_buffer will
513 * fail with -ENODEV.
514 *
515 * This function acquires the irq spinlock and can be called from interrupt
516 * context.
517 */
518void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
519{
520 struct uvc_buffer *buf;
521 unsigned long flags;
522
523 spin_lock_irqsave(&queue->irqlock, flags);
524 while (!list_empty(&queue->irqqueue)) {
525 buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
526 queue);
527 list_del(&buf->queue);
528 buf->state = UVC_BUF_STATE_ERROR;
529 wake_up(&buf->wait);
530 }
531 /* This must be protected by the irqlock spinlock to avoid race
532 * conditions between uvc_queue_buffer and the disconnection event that
533 * could result in an interruptible wait in uvc_dequeue_buffer. Do not
534 * blindly replace this logic by checking for the UVC_DEV_DISCONNECTED
535 * state outside the queue code.
536 */
537 if (disconnect)
538 queue->flags |= UVC_QUEUE_DISCONNECTED;
539 spin_unlock_irqrestore(&queue->irqlock, flags);
540}
541
542struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
543 struct uvc_buffer *buf)
544{
545 struct uvc_buffer *nextbuf;
546 unsigned long flags;
547
548 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
549 buf->buf.length != buf->buf.bytesused) {
550 buf->state = UVC_BUF_STATE_QUEUED;
551 buf->buf.bytesused = 0;
552 return buf;
553 }
554
555 spin_lock_irqsave(&queue->irqlock, flags);
556 list_del(&buf->queue);
557 if (!list_empty(&queue->irqqueue))
558 nextbuf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
559 queue);
560 else
561 nextbuf = NULL;
562 spin_unlock_irqrestore(&queue->irqlock, flags);
563
564 buf->buf.sequence = queue->sequence++;
565 do_gettimeofday(&buf->buf.timestamp);
566
567 wake_up(&buf->wait);
568 return nextbuf;
569}
570
571struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue)
572{
573 struct uvc_buffer *buf = NULL;
574
575 if (!list_empty(&queue->irqqueue))
576 buf = list_first_entry(&queue->irqqueue, struct uvc_buffer,
577 queue);
578 else
579 queue->flags |= UVC_QUEUE_PAUSED;
580
581 return buf;
582}
583
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h
new file mode 100644
index 000000000000..7f5a33fe7ae2
--- /dev/null
+++ b/drivers/usb/gadget/uvc_queue.h
@@ -0,0 +1,89 @@
1#ifndef _UVC_QUEUE_H_
2#define _UVC_QUEUE_H_
3
4#ifdef __KERNEL__
5
6#include <linux/kernel.h>
7#include <linux/poll.h>
8#include <linux/videodev2.h>
9
10/* Maximum frame size in bytes, for sanity checking. */
11#define UVC_MAX_FRAME_SIZE (16*1024*1024)
12/* Maximum number of video buffers. */
13#define UVC_MAX_VIDEO_BUFFERS 32
14
15/* ------------------------------------------------------------------------
16 * Structures.
17 */
18
19enum uvc_buffer_state {
20 UVC_BUF_STATE_IDLE = 0,
21 UVC_BUF_STATE_QUEUED = 1,
22 UVC_BUF_STATE_ACTIVE = 2,
23 UVC_BUF_STATE_DONE = 3,
24 UVC_BUF_STATE_ERROR = 4,
25};
26
27struct uvc_buffer {
28 unsigned long vma_use_count;
29 struct list_head stream;
30
31 /* Touched by interrupt handler. */
32 struct v4l2_buffer buf;
33 struct list_head queue;
34 wait_queue_head_t wait;
35 enum uvc_buffer_state state;
36};
37
38#define UVC_QUEUE_STREAMING (1 << 0)
39#define UVC_QUEUE_DISCONNECTED (1 << 1)
40#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2)
41#define UVC_QUEUE_PAUSED (1 << 3)
42
43struct uvc_video_queue {
44 enum v4l2_buf_type type;
45
46 void *mem;
47 unsigned int flags;
48 __u32 sequence;
49
50 unsigned int count;
51 unsigned int buf_size;
52 unsigned int buf_used;
53 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
54 struct mutex mutex; /* protects buffers and mainqueue */
55 spinlock_t irqlock; /* protects irqqueue */
56
57 struct list_head mainqueue;
58 struct list_head irqqueue;
59};
60
61extern void uvc_queue_init(struct uvc_video_queue *queue,
62 enum v4l2_buf_type type);
63extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
64 unsigned int nbuffers, unsigned int buflength);
65extern int uvc_free_buffers(struct uvc_video_queue *queue);
66extern int uvc_query_buffer(struct uvc_video_queue *queue,
67 struct v4l2_buffer *v4l2_buf);
68extern int uvc_queue_buffer(struct uvc_video_queue *queue,
69 struct v4l2_buffer *v4l2_buf);
70extern int uvc_dequeue_buffer(struct uvc_video_queue *queue,
71 struct v4l2_buffer *v4l2_buf, int nonblocking);
72extern int uvc_queue_enable(struct uvc_video_queue *queue, int enable);
73extern void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
74extern struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
75 struct uvc_buffer *buf);
76extern unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
77 struct file *file, poll_table *wait);
78extern int uvc_queue_mmap(struct uvc_video_queue *queue,
79 struct vm_area_struct *vma);
80static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
81{
82 return queue->flags & UVC_QUEUE_STREAMING;
83}
84extern struct uvc_buffer *uvc_queue_head(struct uvc_video_queue *queue);
85
86#endif /* __KERNEL__ */
87
88#endif /* _UVC_QUEUE_H_ */
89
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
new file mode 100644
index 000000000000..a7989f29837e
--- /dev/null
+++ b/drivers/usb/gadget/uvc_v4l2.c
@@ -0,0 +1,374 @@
1/*
2 * uvc_v4l2.c -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/list.h>
18#include <linux/mutex.h>
19#include <linux/version.h>
20#include <linux/videodev2.h>
21#include <linux/vmalloc.h>
22#include <linux/wait.h>
23
24#include <media/v4l2-dev.h>
25#include <media/v4l2-event.h>
26#include <media/v4l2-ioctl.h>
27
28#include "uvc.h"
29#include "uvc_queue.h"
30
31/* --------------------------------------------------------------------------
32 * Requests handling
33 */
34
35static int
36uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
37{
38 struct usb_composite_dev *cdev = uvc->func.config->cdev;
39 struct usb_request *req = uvc->control_req;
40
41 if (data->length < 0)
42 return usb_ep_set_halt(cdev->gadget->ep0);
43
44 req->length = min(uvc->event_length, data->length);
45 req->zero = data->length < uvc->event_length;
46 req->dma = DMA_ADDR_INVALID;
47
48 memcpy(req->buf, data->data, data->length);
49
50 return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL);
51}
52
53/* --------------------------------------------------------------------------
54 * V4L2
55 */
56
57struct uvc_format
58{
59 u8 bpp;
60 u32 fcc;
61};
62
63static struct uvc_format uvc_formats[] = {
64 { 16, V4L2_PIX_FMT_YUYV },
65 { 0, V4L2_PIX_FMT_MJPEG },
66};
67
68static int
69uvc_v4l2_get_format(struct uvc_video *video, struct v4l2_format *fmt)
70{
71 fmt->fmt.pix.pixelformat = video->fcc;
72 fmt->fmt.pix.width = video->width;
73 fmt->fmt.pix.height = video->height;
74 fmt->fmt.pix.field = V4L2_FIELD_NONE;
75 fmt->fmt.pix.bytesperline = video->bpp * video->width / 8;
76 fmt->fmt.pix.sizeimage = video->imagesize;
77 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
78 fmt->fmt.pix.priv = 0;
79
80 return 0;
81}
82
83static int
84uvc_v4l2_set_format(struct uvc_video *video, struct v4l2_format *fmt)
85{
86 struct uvc_format *format;
87 unsigned int imagesize;
88 unsigned int bpl;
89 unsigned int i;
90
91 for (i = 0; i < ARRAY_SIZE(uvc_formats); ++i) {
92 format = &uvc_formats[i];
93 if (format->fcc == fmt->fmt.pix.pixelformat)
94 break;
95 }
96
97 if (format == NULL || format->fcc != fmt->fmt.pix.pixelformat) {
98 printk(KERN_INFO "Unsupported format 0x%08x.\n",
99 fmt->fmt.pix.pixelformat);
100 return -EINVAL;
101 }
102
103 bpl = format->bpp * fmt->fmt.pix.width / 8;
104 imagesize = bpl ? bpl * fmt->fmt.pix.height : fmt->fmt.pix.sizeimage;
105
106 video->fcc = format->fcc;
107 video->bpp = format->bpp;
108 video->width = fmt->fmt.pix.width;
109 video->height = fmt->fmt.pix.height;
110 video->imagesize = imagesize;
111
112 fmt->fmt.pix.field = V4L2_FIELD_NONE;
113 fmt->fmt.pix.bytesperline = bpl;
114 fmt->fmt.pix.sizeimage = imagesize;
115 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
116 fmt->fmt.pix.priv = 0;
117
118 return 0;
119}
120
121static int
122uvc_v4l2_open(struct file *file)
123{
124 struct video_device *vdev = video_devdata(file);
125 struct uvc_device *uvc = video_get_drvdata(vdev);
126 struct uvc_file_handle *handle;
127 int ret;
128
129 handle = kzalloc(sizeof(*handle), GFP_KERNEL);
130 if (handle == NULL)
131 return -ENOMEM;
132
133 ret = v4l2_fh_init(&handle->vfh, vdev);
134 if (ret < 0)
135 goto error;
136
137 ret = v4l2_event_init(&handle->vfh);
138 if (ret < 0)
139 goto error;
140
141 ret = v4l2_event_alloc(&handle->vfh, 8);
142 if (ret < 0)
143 goto error;
144
145 v4l2_fh_add(&handle->vfh);
146
147 handle->device = &uvc->video;
148 file->private_data = &handle->vfh;
149
150 uvc_function_connect(uvc);
151 return 0;
152
153error:
154 v4l2_fh_exit(&handle->vfh);
155 return ret;
156}
157
158static int
159uvc_v4l2_release(struct file *file)
160{
161 struct video_device *vdev = video_devdata(file);
162 struct uvc_device *uvc = video_get_drvdata(vdev);
163 struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
164 struct uvc_video *video = handle->device;
165
166 uvc_function_disconnect(uvc);
167
168 uvc_video_enable(video, 0);
169 mutex_lock(&video->queue.mutex);
170 if (uvc_free_buffers(&video->queue) < 0)
171 printk(KERN_ERR "uvc_v4l2_release: Unable to free "
172 "buffers.\n");
173 mutex_unlock(&video->queue.mutex);
174
175 file->private_data = NULL;
176 v4l2_fh_del(&handle->vfh);
177 v4l2_fh_exit(&handle->vfh);
178 kfree(handle);
179 return 0;
180}
181
182static long
183uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
184{
185 struct video_device *vdev = video_devdata(file);
186 struct uvc_device *uvc = video_get_drvdata(vdev);
187 struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
188 struct usb_composite_dev *cdev = uvc->func.config->cdev;
189 struct uvc_video *video = &uvc->video;
190 int ret = 0;
191
192 switch (cmd) {
193 /* Query capabilities */
194 case VIDIOC_QUERYCAP:
195 {
196 struct v4l2_capability *cap = arg;
197
198 memset(cap, 0, sizeof *cap);
199 strncpy(cap->driver, "g_uvc", sizeof(cap->driver));
200 strncpy(cap->card, cdev->gadget->name, sizeof(cap->card));
201 strncpy(cap->bus_info, dev_name(&cdev->gadget->dev),
202 sizeof cap->bus_info);
203 cap->version = DRIVER_VERSION_NUMBER;
204 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
205 break;
206 }
207
208 /* Get & Set format */
209 case VIDIOC_G_FMT:
210 {
211 struct v4l2_format *fmt = arg;
212
213 if (fmt->type != video->queue.type)
214 return -EINVAL;
215
216 return uvc_v4l2_get_format(video, fmt);
217 }
218
219 case VIDIOC_S_FMT:
220 {
221 struct v4l2_format *fmt = arg;
222
223 if (fmt->type != video->queue.type)
224 return -EINVAL;
225
226 return uvc_v4l2_set_format(video, fmt);
227 }
228
229 /* Buffers & streaming */
230 case VIDIOC_REQBUFS:
231 {
232 struct v4l2_requestbuffers *rb = arg;
233
234 if (rb->type != video->queue.type ||
235 rb->memory != V4L2_MEMORY_MMAP)
236 return -EINVAL;
237
238 ret = uvc_alloc_buffers(&video->queue, rb->count,
239 video->imagesize);
240 if (ret < 0)
241 return ret;
242
243 rb->count = ret;
244 ret = 0;
245 break;
246 }
247
248 case VIDIOC_QUERYBUF:
249 {
250 struct v4l2_buffer *buf = arg;
251
252 if (buf->type != video->queue.type)
253 return -EINVAL;
254
255 return uvc_query_buffer(&video->queue, buf);
256 }
257
258 case VIDIOC_QBUF:
259 if ((ret = uvc_queue_buffer(&video->queue, arg)) < 0)
260 return ret;
261
262 return uvc_video_pump(video);
263
264 case VIDIOC_DQBUF:
265 return uvc_dequeue_buffer(&video->queue, arg,
266 file->f_flags & O_NONBLOCK);
267
268 case VIDIOC_STREAMON:
269 {
270 int *type = arg;
271
272 if (*type != video->queue.type)
273 return -EINVAL;
274
275 return uvc_video_enable(video, 1);
276 }
277
278 case VIDIOC_STREAMOFF:
279 {
280 int *type = arg;
281
282 if (*type != video->queue.type)
283 return -EINVAL;
284
285 return uvc_video_enable(video, 0);
286 }
287
288 /* Events */
289 case VIDIOC_DQEVENT:
290 {
291 struct v4l2_event *event = arg;
292
293 ret = v4l2_event_dequeue(&handle->vfh, event,
294 file->f_flags & O_NONBLOCK);
295 if (ret == 0 && event->type == UVC_EVENT_SETUP) {
296 struct uvc_event *uvc_event = (void *)&event->u.data;
297
298 /* Tell the complete callback to generate an event for
299 * the next request that will be enqueued by
300 * uvc_event_write.
301 */
302 uvc->event_setup_out =
303 !(uvc_event->req.bRequestType & USB_DIR_IN);
304 uvc->event_length = uvc_event->req.wLength;
305 }
306
307 return ret;
308 }
309
310 case VIDIOC_SUBSCRIBE_EVENT:
311 {
312 struct v4l2_event_subscription *sub = arg;
313
314 if (sub->type < UVC_EVENT_FIRST || sub->type > UVC_EVENT_LAST)
315 return -EINVAL;
316
317 return v4l2_event_subscribe(&handle->vfh, arg);
318 }
319
320 case VIDIOC_UNSUBSCRIBE_EVENT:
321 return v4l2_event_unsubscribe(&handle->vfh, arg);
322
323 case UVCIOC_SEND_RESPONSE:
324 ret = uvc_send_response(uvc, arg);
325 break;
326
327 default:
328 return -ENOIOCTLCMD;
329 }
330
331 return ret;
332}
333
334static long
335uvc_v4l2_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
336{
337 return video_usercopy(file, cmd, arg, uvc_v4l2_do_ioctl);
338}
339
340static int
341uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
342{
343 struct video_device *vdev = video_devdata(file);
344 struct uvc_device *uvc = video_get_drvdata(vdev);
345
346 return uvc_queue_mmap(&uvc->video.queue, vma);
347}
348
349static unsigned int
350uvc_v4l2_poll(struct file *file, poll_table *wait)
351{
352 struct video_device *vdev = video_devdata(file);
353 struct uvc_device *uvc = video_get_drvdata(vdev);
354 struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
355 unsigned int mask = 0;
356
357 poll_wait(file, &handle->vfh.events->wait, wait);
358 if (v4l2_event_pending(&handle->vfh))
359 mask |= POLLPRI;
360
361 mask |= uvc_queue_poll(&uvc->video.queue, file, wait);
362
363 return mask;
364}
365
366struct v4l2_file_operations uvc_v4l2_fops = {
367 .owner = THIS_MODULE,
368 .open = uvc_v4l2_open,
369 .release = uvc_v4l2_release,
370 .ioctl = uvc_v4l2_ioctl,
371 .mmap = uvc_v4l2_mmap,
372 .poll = uvc_v4l2_poll,
373};
374
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c
new file mode 100644
index 000000000000..de8cbc46518d
--- /dev/null
+++ b/drivers/usb/gadget/uvc_video.c
@@ -0,0 +1,386 @@
1/*
2 * uvc_video.c -- USB Video Class Gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#include <linux/kernel.h>
15#include <linux/device.h>
16#include <linux/errno.h>
17#include <linux/usb/ch9.h>
18#include <linux/usb/gadget.h>
19
20#include <media/v4l2-dev.h>
21
22#include "uvc.h"
23#include "uvc_queue.h"
24
25/* --------------------------------------------------------------------------
26 * Video codecs
27 */
28
29static int
30uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf,
31 u8 *data, int len)
32{
33 data[0] = 2;
34 data[1] = UVC_STREAM_EOH | video->fid;
35
36 if (buf->buf.bytesused - video->queue.buf_used <= len - 2)
37 data[1] |= UVC_STREAM_EOF;
38
39 return 2;
40}
41
42static int
43uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
44 u8 *data, int len)
45{
46 struct uvc_video_queue *queue = &video->queue;
47 unsigned int nbytes;
48 void *mem;
49
50 /* Copy video data to the USB buffer. */
51 mem = queue->mem + buf->buf.m.offset + queue->buf_used;
52 nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used);
53
54 memcpy(data, mem, nbytes);
55 queue->buf_used += nbytes;
56
57 return nbytes;
58}
59
60static void
61uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
62 struct uvc_buffer *buf)
63{
64 void *mem = req->buf;
65 int len = video->req_size;
66 int ret;
67
68 /* Add a header at the beginning of the payload. */
69 if (video->payload_size == 0) {
70 ret = uvc_video_encode_header(video, buf, mem, len);
71 video->payload_size += ret;
72 mem += ret;
73 len -= ret;
74 }
75
76 /* Process video data. */
77 len = min((int)(video->max_payload_size - video->payload_size), len);
78 ret = uvc_video_encode_data(video, buf, mem, len);
79
80 video->payload_size += ret;
81 len -= ret;
82
83 req->length = video->req_size - len;
84 req->zero = video->payload_size == video->max_payload_size;
85
86 if (buf->buf.bytesused == video->queue.buf_used) {
87 video->queue.buf_used = 0;
88 buf->state = UVC_BUF_STATE_DONE;
89 uvc_queue_next_buffer(&video->queue, buf);
90 video->fid ^= UVC_STREAM_FID;
91
92 video->payload_size = 0;
93 }
94
95 if (video->payload_size == video->max_payload_size ||
96 buf->buf.bytesused == video->queue.buf_used)
97 video->payload_size = 0;
98}
99
100static void
101uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
102 struct uvc_buffer *buf)
103{
104 void *mem = req->buf;
105 int len = video->req_size;
106 int ret;
107
108 /* Add the header. */
109 ret = uvc_video_encode_header(video, buf, mem, len);
110 mem += ret;
111 len -= ret;
112
113 /* Process video data. */
114 ret = uvc_video_encode_data(video, buf, mem, len);
115 len -= ret;
116
117 req->length = video->req_size - len;
118
119 if (buf->buf.bytesused == video->queue.buf_used) {
120 video->queue.buf_used = 0;
121 buf->state = UVC_BUF_STATE_DONE;
122 uvc_queue_next_buffer(&video->queue, buf);
123 video->fid ^= UVC_STREAM_FID;
124 }
125}
126
127/* --------------------------------------------------------------------------
128 * Request handling
129 */
130
131/*
132 * I somehow feel that synchronisation won't be easy to achieve here. We have
133 * three events that control USB requests submission:
134 *
135 * - USB request completion: the completion handler will resubmit the request
136 * if a video buffer is available.
137 *
138 * - USB interface setting selection: in response to a SET_INTERFACE request,
139 * the handler will start streaming if a video buffer is available and if
140 * video is not currently streaming.
141 *
142 * - V4L2 buffer queueing: the driver will start streaming if video is not
143 * currently streaming.
144 *
145 * Race conditions between those 3 events might lead to deadlocks or other
146 * nasty side effects.
147 *
148 * The "video currently streaming" condition can't be detected by the irqqueue
149 * being empty, as a request can still be in flight. A separate "queue paused"
150 * flag is thus needed.
151 *
152 * The paused flag will be set when we try to retrieve the irqqueue head if the
153 * queue is empty, and cleared when we queue a buffer.
154 *
155 * The USB request completion handler will get the buffer at the irqqueue head
156 * under protection of the queue spinlock. If the queue is empty, the streaming
157 * paused flag will be set. Right after releasing the spinlock a userspace
158 * application can queue a buffer. The flag will then cleared, and the ioctl
159 * handler will restart the video stream.
160 */
161static void
162uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
163{
164 struct uvc_video *video = req->context;
165 struct uvc_buffer *buf;
166 unsigned long flags;
167 int ret;
168
169 switch (req->status) {
170 case 0:
171 break;
172
173 case -ESHUTDOWN:
174 printk(KERN_INFO "VS request cancelled.\n");
175 goto requeue;
176
177 default:
178 printk(KERN_INFO "VS request completed with status %d.\n",
179 req->status);
180 goto requeue;
181 }
182
183 spin_lock_irqsave(&video->queue.irqlock, flags);
184 buf = uvc_queue_head(&video->queue);
185 if (buf == NULL) {
186 spin_unlock_irqrestore(&video->queue.irqlock, flags);
187 goto requeue;
188 }
189
190 video->encode(req, video, buf);
191
192 if ((ret = usb_ep_queue(ep, req, GFP_ATOMIC)) < 0) {
193 printk(KERN_INFO "Failed to queue request (%d).\n", ret);
194 usb_ep_set_halt(ep);
195 spin_unlock_irqrestore(&video->queue.irqlock, flags);
196 goto requeue;
197 }
198 spin_unlock_irqrestore(&video->queue.irqlock, flags);
199
200 return;
201
202requeue:
203 spin_lock_irqsave(&video->req_lock, flags);
204 list_add_tail(&req->list, &video->req_free);
205 spin_unlock_irqrestore(&video->req_lock, flags);
206}
207
208static int
209uvc_video_free_requests(struct uvc_video *video)
210{
211 unsigned int i;
212
213 for (i = 0; i < UVC_NUM_REQUESTS; ++i) {
214 if (video->req[i]) {
215 usb_ep_free_request(video->ep, video->req[i]);
216 video->req[i] = NULL;
217 }
218
219 if (video->req_buffer[i]) {
220 kfree(video->req_buffer[i]);
221 video->req_buffer[i] = NULL;
222 }
223 }
224
225 INIT_LIST_HEAD(&video->req_free);
226 video->req_size = 0;
227 return 0;
228}
229
230static int
231uvc_video_alloc_requests(struct uvc_video *video)
232{
233 unsigned int i;
234 int ret = -ENOMEM;
235
236 BUG_ON(video->req_size);
237
238 for (i = 0; i < UVC_NUM_REQUESTS; ++i) {
239 video->req_buffer[i] = kmalloc(video->ep->maxpacket, GFP_KERNEL);
240 if (video->req_buffer[i] == NULL)
241 goto error;
242
243 video->req[i] = usb_ep_alloc_request(video->ep, GFP_KERNEL);
244 if (video->req[i] == NULL)
245 goto error;
246
247 video->req[i]->buf = video->req_buffer[i];
248 video->req[i]->length = 0;
249 video->req[i]->dma = DMA_ADDR_INVALID;
250 video->req[i]->complete = uvc_video_complete;
251 video->req[i]->context = video;
252
253 list_add_tail(&video->req[i]->list, &video->req_free);
254 }
255
256 video->req_size = video->ep->maxpacket;
257 return 0;
258
259error:
260 uvc_video_free_requests(video);
261 return ret;
262}
263
264/* --------------------------------------------------------------------------
265 * Video streaming
266 */
267
268/*
269 * uvc_video_pump - Pump video data into the USB requests
270 *
271 * This function fills the available USB requests (listed in req_free) with
272 * video data from the queued buffers.
273 */
274int
275uvc_video_pump(struct uvc_video *video)
276{
277 struct usb_request *req;
278 struct uvc_buffer *buf;
279 unsigned long flags;
280 int ret;
281
282 /* FIXME TODO Race between uvc_video_pump and requests completion
283 * handler ???
284 */
285
286 while (1) {
287 /* Retrieve the first available USB request, protected by the
288 * request lock.
289 */
290 spin_lock_irqsave(&video->req_lock, flags);
291 if (list_empty(&video->req_free)) {
292 spin_unlock_irqrestore(&video->req_lock, flags);
293 return 0;
294 }
295 req = list_first_entry(&video->req_free, struct usb_request,
296 list);
297 list_del(&req->list);
298 spin_unlock_irqrestore(&video->req_lock, flags);
299
300 /* Retrieve the first available video buffer and fill the
301 * request, protected by the video queue irqlock.
302 */
303 spin_lock_irqsave(&video->queue.irqlock, flags);
304 buf = uvc_queue_head(&video->queue);
305 if (buf == NULL) {
306 spin_unlock_irqrestore(&video->queue.irqlock, flags);
307 break;
308 }
309
310 video->encode(req, video, buf);
311
312 /* Queue the USB request */
313 if ((ret = usb_ep_queue(video->ep, req, GFP_KERNEL)) < 0) {
314 printk(KERN_INFO "Failed to queue request (%d)\n", ret);
315 usb_ep_set_halt(video->ep);
316 spin_unlock_irqrestore(&video->queue.irqlock, flags);
317 break;
318 }
319 spin_unlock_irqrestore(&video->queue.irqlock, flags);
320 }
321
322 spin_lock_irqsave(&video->req_lock, flags);
323 list_add_tail(&req->list, &video->req_free);
324 spin_unlock_irqrestore(&video->req_lock, flags);
325 return 0;
326}
327
328/*
329 * Enable or disable the video stream.
330 */
331int
332uvc_video_enable(struct uvc_video *video, int enable)
333{
334 unsigned int i;
335 int ret;
336
337 if (video->ep == NULL) {
338 printk(KERN_INFO "Video enable failed, device is "
339 "uninitialized.\n");
340 return -ENODEV;
341 }
342
343 if (!enable) {
344 for (i = 0; i < UVC_NUM_REQUESTS; ++i)
345 usb_ep_dequeue(video->ep, video->req[i]);
346
347 uvc_video_free_requests(video);
348 uvc_queue_enable(&video->queue, 0);
349 return 0;
350 }
351
352 if ((ret = uvc_queue_enable(&video->queue, 1)) < 0)
353 return ret;
354
355 if ((ret = uvc_video_alloc_requests(video)) < 0)
356 return ret;
357
358 if (video->max_payload_size) {
359 video->encode = uvc_video_encode_bulk;
360 video->payload_size = 0;
361 } else
362 video->encode = uvc_video_encode_isoc;
363
364 return uvc_video_pump(video);
365}
366
367/*
368 * Initialize the UVC video stream.
369 */
370int
371uvc_video_init(struct uvc_video *video)
372{
373 INIT_LIST_HEAD(&video->req_free);
374 spin_lock_init(&video->req_lock);
375
376 video->fcc = V4L2_PIX_FMT_YUYV;
377 video->bpp = 16;
378 video->width = 320;
379 video->height = 240;
380 video->imagesize = 320 * 240 * 2;
381
382 /* Initialize the video buffers queue. */
383 uvc_queue_init(&video->queue, V4L2_BUF_TYPE_VIDEO_OUTPUT);
384 return 0;
385}
386
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
new file mode 100644
index 000000000000..417fd6887698
--- /dev/null
+++ b/drivers/usb/gadget/webcam.c
@@ -0,0 +1,399 @@
1/*
2 * webcam.c -- USB webcam gadget driver
3 *
4 * Copyright (C) 2009-2010
5 * Laurent Pinchart (laurent.pinchart@ideasonboard.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13#include <linux/kernel.h>
14#include <linux/device.h>
15#include <linux/usb/video.h>
16
17#include "f_uvc.h"
18
19/*
20 * Kbuild is not very cooperative with respect to linking separately
21 * compiled library objects into one module. So for now we won't use
22 * separate compilation ... ensuring init/exit sections work to shrink
23 * the runtime footprint, and giving us at least some parts of what
24 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
25 */
26#include "composite.c"
27#include "usbstring.c"
28#include "config.c"
29#include "epautoconf.c"
30
31#include "f_uvc.c"
32#include "uvc_queue.c"
33#include "uvc_v4l2.c"
34#include "uvc_video.c"
35
36/* --------------------------------------------------------------------------
37 * Device descriptor
38 */
39
40#define WEBCAM_VENDOR_ID 0x1d6b /* Linux Foundation */
41#define WEBCAM_PRODUCT_ID 0x0102 /* Webcam A/V gadget */
42#define WEBCAM_DEVICE_BCD 0x0010 /* 0.10 */
43
44static char webcam_vendor_label[] = "Linux Foundation";
45static char webcam_product_label[] = "Webcam gadget";
46static char webcam_config_label[] = "Video";
47
48/* string IDs are assigned dynamically */
49
50#define STRING_MANUFACTURER_IDX 0
51#define STRING_PRODUCT_IDX 1
52#define STRING_DESCRIPTION_IDX 2
53
54static struct usb_string webcam_strings[] = {
55 [STRING_MANUFACTURER_IDX].s = webcam_vendor_label,
56 [STRING_PRODUCT_IDX].s = webcam_product_label,
57 [STRING_DESCRIPTION_IDX].s = webcam_config_label,
58 { }
59};
60
61static struct usb_gadget_strings webcam_stringtab = {
62 .language = 0x0409, /* en-us */
63 .strings = webcam_strings,
64};
65
66static struct usb_gadget_strings *webcam_device_strings[] = {
67 &webcam_stringtab,
68 NULL,
69};
70
71static struct usb_device_descriptor webcam_device_descriptor = {
72 .bLength = USB_DT_DEVICE_SIZE,
73 .bDescriptorType = USB_DT_DEVICE,
74 .bcdUSB = cpu_to_le16(0x0200),
75 .bDeviceClass = USB_CLASS_MISC,
76 .bDeviceSubClass = 0x02,
77 .bDeviceProtocol = 0x01,
78 .bMaxPacketSize0 = 0, /* dynamic */
79 .idVendor = cpu_to_le16(WEBCAM_VENDOR_ID),
80 .idProduct = cpu_to_le16(WEBCAM_PRODUCT_ID),
81 .bcdDevice = cpu_to_le16(WEBCAM_DEVICE_BCD),
82 .iManufacturer = 0, /* dynamic */
83 .iProduct = 0, /* dynamic */
84 .iSerialNumber = 0, /* dynamic */
85 .bNumConfigurations = 0, /* dynamic */
86};
87
88DECLARE_UVC_HEADER_DESCRIPTOR(1);
89
90static const struct UVC_HEADER_DESCRIPTOR(1) uvc_control_header = {
91 .bLength = UVC_DT_HEADER_SIZE(1),
92 .bDescriptorType = USB_DT_CS_INTERFACE,
93 .bDescriptorSubType = UVC_DT_HEADER,
94 .bcdUVC = cpu_to_le16(0x0100),
95 .wTotalLength = 0, /* dynamic */
96 .dwClockFrequency = cpu_to_le32(48000000),
97 .bInCollection = 0, /* dynamic */
98 .baInterfaceNr[0] = 0, /* dynamic */
99};
100
101static const struct uvc_camera_terminal_descriptor uvc_camera_terminal = {
102 .bLength = UVC_DT_CAMERA_TERMINAL_SIZE(3),
103 .bDescriptorType = USB_DT_CS_INTERFACE,
104 .bDescriptorSubType = UVC_DT_INPUT_TERMINAL,
105 .bTerminalID = 1,
106 .wTerminalType = cpu_to_le16(0x0201),
107 .bAssocTerminal = 0,
108 .iTerminal = 0,
109 .wObjectiveFocalLengthMin = cpu_to_le16(0),
110 .wObjectiveFocalLengthMax = cpu_to_le16(0),
111 .wOcularFocalLength = cpu_to_le16(0),
112 .bControlSize = 3,
113 .bmControls[0] = 2,
114 .bmControls[1] = 0,
115 .bmControls[2] = 0,
116};
117
118static const struct uvc_processing_unit_descriptor uvc_processing = {
119 .bLength = UVC_DT_PROCESSING_UNIT_SIZE(2),
120 .bDescriptorType = USB_DT_CS_INTERFACE,
121 .bDescriptorSubType = UVC_DT_PROCESSING_UNIT,
122 .bUnitID = 2,
123 .bSourceID = 1,
124 .wMaxMultiplier = cpu_to_le16(16*1024),
125 .bControlSize = 2,
126 .bmControls[0] = 1,
127 .bmControls[1] = 0,
128 .iProcessing = 0,
129};
130
131static const struct uvc_output_terminal_descriptor uvc_output_terminal = {
132 .bLength = UVC_DT_OUTPUT_TERMINAL_SIZE,
133 .bDescriptorType = USB_DT_CS_INTERFACE,
134 .bDescriptorSubType = UVC_DT_OUTPUT_TERMINAL,
135 .bTerminalID = 3,
136 .wTerminalType = cpu_to_le16(0x0101),
137 .bAssocTerminal = 0,
138 .bSourceID = 2,
139 .iTerminal = 0,
140};
141
142DECLARE_UVC_INPUT_HEADER_DESCRIPTOR(1, 2);
143
144static const struct UVC_INPUT_HEADER_DESCRIPTOR(1, 2) uvc_input_header = {
145 .bLength = UVC_DT_INPUT_HEADER_SIZE(1, 2),
146 .bDescriptorType = USB_DT_CS_INTERFACE,
147 .bDescriptorSubType = UVC_DT_INPUT_HEADER,
148 .bNumFormats = 2,
149 .wTotalLength = 0, /* dynamic */
150 .bEndpointAddress = 0, /* dynamic */
151 .bmInfo = 0,
152 .bTerminalLink = 3,
153 .bStillCaptureMethod = 0,
154 .bTriggerSupport = 0,
155 .bTriggerUsage = 0,
156 .bControlSize = 1,
157 .bmaControls[0][0] = 0,
158 .bmaControls[1][0] = 4,
159};
160
161static const struct uvc_format_uncompressed uvc_format_yuv = {
162 .bLength = UVC_DT_FORMAT_UNCOMPRESSED_SIZE,
163 .bDescriptorType = USB_DT_CS_INTERFACE,
164 .bDescriptorSubType = UVC_DT_FORMAT_UNCOMPRESSED,
165 .bFormatIndex = 1,
166 .bNumFrameDescriptors = 2,
167 .guidFormat =
168 { 'Y', 'U', 'Y', '2', 0x00, 0x00, 0x10, 0x00,
169 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71},
170 .bBitsPerPixel = 16,
171 .bDefaultFrameIndex = 1,
172 .bAspectRatioX = 0,
173 .bAspectRatioY = 0,
174 .bmInterfaceFlags = 0,
175 .bCopyProtect = 0,
176};
177
178DECLARE_UVC_FRAME_UNCOMPRESSED(1);
179DECLARE_UVC_FRAME_UNCOMPRESSED(3);
180
181static const struct UVC_FRAME_UNCOMPRESSED(3) uvc_frame_yuv_360p = {
182 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(3),
183 .bDescriptorType = USB_DT_CS_INTERFACE,
184 .bDescriptorSubType = UVC_DT_FRAME_UNCOMPRESSED,
185 .bFrameIndex = 1,
186 .bmCapabilities = 0,
187 .wWidth = cpu_to_le16(640),
188 .wHeight = cpu_to_le16(360),
189 .dwMinBitRate = cpu_to_le32(18432000),
190 .dwMaxBitRate = cpu_to_le32(55296000),
191 .dwMaxVideoFrameBufferSize = cpu_to_le32(460800),
192 .dwDefaultFrameInterval = cpu_to_le32(666666),
193 .bFrameIntervalType = 3,
194 .dwFrameInterval[0] = cpu_to_le32(666666),
195 .dwFrameInterval[1] = cpu_to_le32(1000000),
196 .dwFrameInterval[2] = cpu_to_le32(5000000),
197};
198
199static const struct UVC_FRAME_UNCOMPRESSED(1) uvc_frame_yuv_720p = {
200 .bLength = UVC_DT_FRAME_UNCOMPRESSED_SIZE(1),
201 .bDescriptorType = USB_DT_CS_INTERFACE,
202 .bDescriptorSubType = UVC_DT_FRAME_UNCOMPRESSED,
203 .bFrameIndex = 2,
204 .bmCapabilities = 0,
205 .wWidth = cpu_to_le16(1280),
206 .wHeight = cpu_to_le16(720),
207 .dwMinBitRate = cpu_to_le32(29491200),
208 .dwMaxBitRate = cpu_to_le32(29491200),
209 .dwMaxVideoFrameBufferSize = cpu_to_le32(1843200),
210 .dwDefaultFrameInterval = cpu_to_le32(5000000),
211 .bFrameIntervalType = 1,
212 .dwFrameInterval[0] = cpu_to_le32(5000000),
213};
214
215static const struct uvc_format_mjpeg uvc_format_mjpg = {
216 .bLength = UVC_DT_FORMAT_MJPEG_SIZE,
217 .bDescriptorType = USB_DT_CS_INTERFACE,
218 .bDescriptorSubType = UVC_DT_FORMAT_MJPEG,
219 .bFormatIndex = 2,
220 .bNumFrameDescriptors = 2,
221 .bmFlags = 0,
222 .bDefaultFrameIndex = 1,
223 .bAspectRatioX = 0,
224 .bAspectRatioY = 0,
225 .bmInterfaceFlags = 0,
226 .bCopyProtect = 0,
227};
228
229DECLARE_UVC_FRAME_MJPEG(1);
230DECLARE_UVC_FRAME_MJPEG(3);
231
232static const struct UVC_FRAME_MJPEG(3) uvc_frame_mjpg_360p = {
233 .bLength = UVC_DT_FRAME_MJPEG_SIZE(3),
234 .bDescriptorType = USB_DT_CS_INTERFACE,
235 .bDescriptorSubType = UVC_DT_FRAME_MJPEG,
236 .bFrameIndex = 1,
237 .bmCapabilities = 0,
238 .wWidth = cpu_to_le16(640),
239 .wHeight = cpu_to_le16(360),
240 .dwMinBitRate = cpu_to_le32(18432000),
241 .dwMaxBitRate = cpu_to_le32(55296000),
242 .dwMaxVideoFrameBufferSize = cpu_to_le32(460800),
243 .dwDefaultFrameInterval = cpu_to_le32(666666),
244 .bFrameIntervalType = 3,
245 .dwFrameInterval[0] = cpu_to_le32(666666),
246 .dwFrameInterval[1] = cpu_to_le32(1000000),
247 .dwFrameInterval[2] = cpu_to_le32(5000000),
248};
249
250static const struct UVC_FRAME_MJPEG(1) uvc_frame_mjpg_720p = {
251 .bLength = UVC_DT_FRAME_MJPEG_SIZE(1),
252 .bDescriptorType = USB_DT_CS_INTERFACE,
253 .bDescriptorSubType = UVC_DT_FRAME_MJPEG,
254 .bFrameIndex = 2,
255 .bmCapabilities = 0,
256 .wWidth = cpu_to_le16(1280),
257 .wHeight = cpu_to_le16(720),
258 .dwMinBitRate = cpu_to_le32(29491200),
259 .dwMaxBitRate = cpu_to_le32(29491200),
260 .dwMaxVideoFrameBufferSize = cpu_to_le32(1843200),
261 .dwDefaultFrameInterval = cpu_to_le32(5000000),
262 .bFrameIntervalType = 1,
263 .dwFrameInterval[0] = cpu_to_le32(5000000),
264};
265
266static const struct uvc_color_matching_descriptor uvc_color_matching = {
267 .bLength = UVC_DT_COLOR_MATCHING_SIZE,
268 .bDescriptorType = USB_DT_CS_INTERFACE,
269 .bDescriptorSubType = UVC_DT_COLOR_MATCHING,
270 .bColorPrimaries = 1,
271 .bTransferCharacteristics = 1,
272 .bMatrixCoefficients = 4,
273};
274
275static const struct uvc_descriptor_header * const uvc_control_cls[] = {
276 (const struct uvc_descriptor_header *) &uvc_control_header,
277 (const struct uvc_descriptor_header *) &uvc_camera_terminal,
278 (const struct uvc_descriptor_header *) &uvc_processing,
279 (const struct uvc_descriptor_header *) &uvc_output_terminal,
280 NULL,
281};
282
283static const struct uvc_descriptor_header * const uvc_fs_streaming_cls[] = {
284 (const struct uvc_descriptor_header *) &uvc_input_header,
285 (const struct uvc_descriptor_header *) &uvc_format_yuv,
286 (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p,
287 (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p,
288 (const struct uvc_descriptor_header *) &uvc_format_mjpg,
289 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p,
290 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p,
291 (const struct uvc_descriptor_header *) &uvc_color_matching,
292 NULL,
293};
294
295static const struct uvc_descriptor_header * const uvc_hs_streaming_cls[] = {
296 (const struct uvc_descriptor_header *) &uvc_input_header,
297 (const struct uvc_descriptor_header *) &uvc_format_yuv,
298 (const struct uvc_descriptor_header *) &uvc_frame_yuv_360p,
299 (const struct uvc_descriptor_header *) &uvc_frame_yuv_720p,
300 (const struct uvc_descriptor_header *) &uvc_format_mjpg,
301 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_360p,
302 (const struct uvc_descriptor_header *) &uvc_frame_mjpg_720p,
303 (const struct uvc_descriptor_header *) &uvc_color_matching,
304 NULL,
305};
306
307/* --------------------------------------------------------------------------
308 * USB configuration
309 */
310
311static int __init
312webcam_config_bind(struct usb_configuration *c)
313{
314 return uvc_bind_config(c, uvc_control_cls, uvc_fs_streaming_cls,
315 uvc_hs_streaming_cls);
316}
317
318static struct usb_configuration webcam_config_driver = {
319 .label = webcam_config_label,
320 .bind = webcam_config_bind,
321 .bConfigurationValue = 1,
322 .iConfiguration = 0, /* dynamic */
323 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
324 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
325};
326
327static int /* __init_or_exit */
328webcam_unbind(struct usb_composite_dev *cdev)
329{
330 return 0;
331}
332
333static int __init
334webcam_bind(struct usb_composite_dev *cdev)
335{
336 int ret;
337
338 /* Allocate string descriptor numbers ... note that string contents
339 * can be overridden by the composite_dev glue.
340 */
341 if ((ret = usb_string_id(cdev)) < 0)
342 goto error;
343 webcam_strings[STRING_MANUFACTURER_IDX].id = ret;
344 webcam_device_descriptor.iManufacturer = ret;
345
346 if ((ret = usb_string_id(cdev)) < 0)
347 goto error;
348 webcam_strings[STRING_PRODUCT_IDX].id = ret;
349 webcam_device_descriptor.iProduct = ret;
350
351 if ((ret = usb_string_id(cdev)) < 0)
352 goto error;
353 webcam_strings[STRING_DESCRIPTION_IDX].id = ret;
354 webcam_config_driver.iConfiguration = ret;
355
356 /* Register our configuration. */
357 if ((ret = usb_add_config(cdev, &webcam_config_driver)) < 0)
358 goto error;
359
360 INFO(cdev, "Webcam Video Gadget\n");
361 return 0;
362
363error:
364 webcam_unbind(cdev);
365 return ret;
366}
367
368/* --------------------------------------------------------------------------
369 * Driver
370 */
371
372static struct usb_composite_driver webcam_driver = {
373 .name = "g_webcam",
374 .dev = &webcam_device_descriptor,
375 .strings = webcam_device_strings,
376 .bind = webcam_bind,
377 .unbind = webcam_unbind,
378};
379
380static int __init
381webcam_init(void)
382{
383 return usb_composite_register(&webcam_driver);
384}
385
386static void __exit
387webcam_cleanup(void)
388{
389 usb_composite_unregister(&webcam_driver);
390}
391
392module_init(webcam_init);
393module_exit(webcam_cleanup);
394
395MODULE_AUTHOR("Laurent Pinchart");
396MODULE_DESCRIPTION("Webcam Video Gadget");
397MODULE_LICENSE("GPL");
398MODULE_VERSION("0.1.0");
399
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 8d3df0397de3..f865be2276d4 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -207,6 +207,21 @@ config USB_OHCI_HCD
207 To compile this driver as a module, choose M here: the 207 To compile this driver as a module, choose M here: the
208 module will be called ohci-hcd. 208 module will be called ohci-hcd.
209 209
210config USB_OHCI_HCD_OMAP1
211 bool "OHCI support for OMAP1/2 chips"
212 depends on USB_OHCI_HCD && (ARCH_OMAP1 || ARCH_OMAP2)
213 default y
214 ---help---
215 Enables support for the OHCI controller on OMAP1/2 chips.
216
217config USB_OHCI_HCD_OMAP3
218 bool "OHCI support for OMAP3 and later chips"
219 depends on USB_OHCI_HCD && (ARCH_OMAP3 || ARCH_OMAP4)
220 default y
221 ---help---
222 Enables support for the on-chip OHCI controller on
223 OMAP3 and later chips.
224
210config USB_OHCI_HCD_PPC_SOC 225config USB_OHCI_HCD_PPC_SOC
211 bool "OHCI support for on-chip PPC USB controller" 226 bool "OHCI support for on-chip PPC USB controller"
212 depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx) 227 depends on USB_OHCI_HCD && (STB03xxx || PPC_MPC52xx)
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index e3a74e75e822..faa61748db70 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -69,6 +69,15 @@ static void au1xxx_stop_ehc(void)
69 au_sync(); 69 au_sync();
70} 70}
71 71
72static int au1xxx_ehci_setup(struct usb_hcd *hcd)
73{
74 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
75 int ret = ehci_init(hcd);
76
77 ehci->need_io_watchdog = 0;
78 return ret;
79}
80
72static const struct hc_driver ehci_au1xxx_hc_driver = { 81static const struct hc_driver ehci_au1xxx_hc_driver = {
73 .description = hcd_name, 82 .description = hcd_name,
74 .product_desc = "Au1xxx EHCI", 83 .product_desc = "Au1xxx EHCI",
@@ -86,7 +95,7 @@ static const struct hc_driver ehci_au1xxx_hc_driver = {
86 * FIXME -- ehci_init() doesn't do enough here. 95 * FIXME -- ehci_init() doesn't do enough here.
87 * See ehci-ppc-soc for a complete implementation. 96 * See ehci-ppc-soc for a complete implementation.
88 */ 97 */
89 .reset = ehci_init, 98 .reset = au1xxx_ehci_setup,
90 .start = ehci_run, 99 .start = ehci_run,
91 .stop = ehci_stop, 100 .stop = ehci_stop,
92 .shutdown = ehci_shutdown, 101 .shutdown = ehci_shutdown,
@@ -215,26 +224,17 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
215 msleep(10); 224 msleep(10);
216 225
217 /* Root hub was already suspended. Disable irq emission and 226 /* Root hub was already suspended. Disable irq emission and
218 * mark HW unaccessible, bail out if RH has been resumed. Use 227 * mark HW unaccessible. The PM and USB cores make sure that
219 * the spinlock to properly synchronize with possible pending 228 * the root hub is either suspended or stopped.
220 * RH suspend or resume activity.
221 *
222 * This is still racy as hcd->state is manipulated outside of
223 * any locks =P But that will be a different fix.
224 */ 229 */
225 spin_lock_irqsave(&ehci->lock, flags); 230 spin_lock_irqsave(&ehci->lock, flags);
226 if (hcd->state != HC_STATE_SUSPENDED) { 231 ehci_prepare_ports_for_controller_suspend(ehci);
227 rc = -EINVAL;
228 goto bail;
229 }
230 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 232 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
231 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 233 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
232 234
233 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 235 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
234 236
235 au1xxx_stop_ehc(); 237 au1xxx_stop_ehc();
236
237bail:
238 spin_unlock_irqrestore(&ehci->lock, flags); 238 spin_unlock_irqrestore(&ehci->lock, flags);
239 239
240 // could save FLADJ in case of Vaux power loss 240 // could save FLADJ in case of Vaux power loss
@@ -264,6 +264,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
264 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) { 264 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
265 int mask = INTR_MASK; 265 int mask = INTR_MASK;
266 266
267 ehci_prepare_ports_for_controller_resume(ehci);
267 if (!hcd->self.root_hub->do_remote_wakeup) 268 if (!hcd->self.root_hub->do_remote_wakeup)
268 mask &= ~STS_PCD; 269 mask &= ~STS_PCD;
269 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 270 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 0e26aa13f158..5cd967d28938 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -313,6 +313,7 @@ static int ehci_fsl_drv_suspend(struct device *dev)
313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); 313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
314 void __iomem *non_ehci = hcd->regs; 314 void __iomem *non_ehci = hcd->regs;
315 315
316 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd));
316 if (!fsl_deep_sleep()) 317 if (!fsl_deep_sleep())
317 return 0; 318 return 0;
318 319
@@ -327,6 +328,7 @@ static int ehci_fsl_drv_resume(struct device *dev)
327 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 328 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
328 void __iomem *non_ehci = hcd->regs; 329 void __iomem *non_ehci = hcd->regs;
329 330
331 ehci_prepare_ports_for_controller_resume(ehci);
330 if (!fsl_deep_sleep()) 332 if (!fsl_deep_sleep())
331 return 0; 333 return 0;
332 334
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 13ead00aecd5..ef3e88f0b3c3 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -31,13 +31,12 @@
31#include <linux/list.h> 31#include <linux/list.h>
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/usb/hcd.h>
34#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <linux/debugfs.h> 37#include <linux/debugfs.h>
37#include <linux/slab.h> 38#include <linux/slab.h>
38 39
39#include "../core/hcd.h"
40
41#include <asm/byteorder.h> 40#include <asm/byteorder.h>
42#include <asm/io.h> 41#include <asm/io.h>
43#include <asm/irq.h> 42#include <asm/irq.h>
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index c7178bcde67a..e7d3d8def282 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -106,12 +106,75 @@ static void ehci_handover_companion_ports(struct ehci_hcd *ehci)
106 ehci->owned_ports = 0; 106 ehci->owned_ports = 0;
107} 107}
108 108
109static void ehci_adjust_port_wakeup_flags(struct ehci_hcd *ehci,
110 bool suspending)
111{
112 int port;
113 u32 temp;
114
115 /* If remote wakeup is enabled for the root hub but disabled
116 * for the controller, we must adjust all the port wakeup flags
117 * when the controller is suspended or resumed. In all other
118 * cases they don't need to be changed.
119 */
120 if (!ehci_to_hcd(ehci)->self.root_hub->do_remote_wakeup ||
121 device_may_wakeup(ehci_to_hcd(ehci)->self.controller))
122 return;
123
124 /* clear phy low-power mode before changing wakeup flags */
125 if (ehci->has_hostpc) {
126 port = HCS_N_PORTS(ehci->hcs_params);
127 while (port--) {
128 u32 __iomem *hostpc_reg;
129
130 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
131 + HOSTPC0 + 4 * port);
132 temp = ehci_readl(ehci, hostpc_reg);
133 ehci_writel(ehci, temp & ~HOSTPC_PHCD, hostpc_reg);
134 }
135 msleep(5);
136 }
137
138 port = HCS_N_PORTS(ehci->hcs_params);
139 while (port--) {
140 u32 __iomem *reg = &ehci->regs->port_status[port];
141 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
142 u32 t2 = t1 & ~PORT_WAKE_BITS;
143
144 /* If we are suspending the controller, clear the flags.
145 * If we are resuming the controller, set the wakeup flags.
146 */
147 if (!suspending) {
148 if (t1 & PORT_CONNECT)
149 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
150 else
151 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
152 }
153 ehci_vdbg(ehci, "port %d, %08x -> %08x\n",
154 port + 1, t1, t2);
155 ehci_writel(ehci, t2, reg);
156 }
157
158 /* enter phy low-power mode again */
159 if (ehci->has_hostpc) {
160 port = HCS_N_PORTS(ehci->hcs_params);
161 while (port--) {
162 u32 __iomem *hostpc_reg;
163
164 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
165 + HOSTPC0 + 4 * port);
166 temp = ehci_readl(ehci, hostpc_reg);
167 ehci_writel(ehci, temp | HOSTPC_PHCD, hostpc_reg);
168 }
169 }
170}
171
109static int ehci_bus_suspend (struct usb_hcd *hcd) 172static int ehci_bus_suspend (struct usb_hcd *hcd)
110{ 173{
111 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 174 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
112 int port; 175 int port;
113 int mask; 176 int mask;
114 u32 __iomem *hostpc_reg = NULL; 177 int changed;
115 178
116 ehci_dbg(ehci, "suspend root hub\n"); 179 ehci_dbg(ehci, "suspend root hub\n");
117 180
@@ -155,15 +218,13 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
155 */ 218 */
156 ehci->bus_suspended = 0; 219 ehci->bus_suspended = 0;
157 ehci->owned_ports = 0; 220 ehci->owned_ports = 0;
221 changed = 0;
158 port = HCS_N_PORTS(ehci->hcs_params); 222 port = HCS_N_PORTS(ehci->hcs_params);
159 while (port--) { 223 while (port--) {
160 u32 __iomem *reg = &ehci->regs->port_status [port]; 224 u32 __iomem *reg = &ehci->regs->port_status [port];
161 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; 225 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
162 u32 t2 = t1; 226 u32 t2 = t1 & ~PORT_WAKE_BITS;
163 227
164 if (ehci->has_hostpc)
165 hostpc_reg = (u32 __iomem *)((u8 *)ehci->regs
166 + HOSTPC0 + 4 * (port & 0xff));
167 /* keep track of which ports we suspend */ 228 /* keep track of which ports we suspend */
168 if (t1 & PORT_OWNER) 229 if (t1 & PORT_OWNER)
169 set_bit(port, &ehci->owned_ports); 230 set_bit(port, &ehci->owned_ports);
@@ -172,40 +233,45 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
172 set_bit(port, &ehci->bus_suspended); 233 set_bit(port, &ehci->bus_suspended);
173 } 234 }
174 235
175 /* enable remote wakeup on all ports */ 236 /* enable remote wakeup on all ports, if told to do so */
176 if (hcd->self.root_hub->do_remote_wakeup) { 237 if (hcd->self.root_hub->do_remote_wakeup) {
177 /* only enable appropriate wake bits, otherwise the 238 /* only enable appropriate wake bits, otherwise the
178 * hardware can not go phy low power mode. If a race 239 * hardware can not go phy low power mode. If a race
179 * condition happens here(connection change during bits 240 * condition happens here(connection change during bits
180 * set), the port change detection will finally fix it. 241 * set), the port change detection will finally fix it.
181 */ 242 */
182 if (t1 & PORT_CONNECT) { 243 if (t1 & PORT_CONNECT)
183 t2 |= PORT_WKOC_E | PORT_WKDISC_E; 244 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
184 t2 &= ~PORT_WKCONN_E; 245 else
185 } else {
186 t2 |= PORT_WKOC_E | PORT_WKCONN_E; 246 t2 |= PORT_WKOC_E | PORT_WKCONN_E;
187 t2 &= ~PORT_WKDISC_E; 247 }
188 }
189 } else
190 t2 &= ~PORT_WAKE_BITS;
191 248
192 if (t1 != t2) { 249 if (t1 != t2) {
193 ehci_vdbg (ehci, "port %d, %08x -> %08x\n", 250 ehci_vdbg (ehci, "port %d, %08x -> %08x\n",
194 port + 1, t1, t2); 251 port + 1, t1, t2);
195 ehci_writel(ehci, t2, reg); 252 ehci_writel(ehci, t2, reg);
196 if (hostpc_reg) { 253 changed = 1;
197 u32 t3; 254 }
255 }
198 256
199 spin_unlock_irq(&ehci->lock); 257 if (changed && ehci->has_hostpc) {
200 msleep(5);/* 5ms for HCD enter low pwr mode */ 258 spin_unlock_irq(&ehci->lock);
201 spin_lock_irq(&ehci->lock); 259 msleep(5); /* 5 ms for HCD to enter low-power mode */
202 t3 = ehci_readl(ehci, hostpc_reg); 260 spin_lock_irq(&ehci->lock);
203 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); 261
204 t3 = ehci_readl(ehci, hostpc_reg); 262 port = HCS_N_PORTS(ehci->hcs_params);
205 ehci_dbg(ehci, "Port%d phy low pwr mode %s\n", 263 while (port--) {
264 u32 __iomem *hostpc_reg;
265 u32 t3;
266
267 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
268 + HOSTPC0 + 4 * port);
269 t3 = ehci_readl(ehci, hostpc_reg);
270 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
271 t3 = ehci_readl(ehci, hostpc_reg);
272 ehci_dbg(ehci, "Port %d phy low-power mode %s\n",
206 port, (t3 & HOSTPC_PHCD) ? 273 port, (t3 & HOSTPC_PHCD) ?
207 "succeeded" : "failed"); 274 "succeeded" : "failed");
208 }
209 } 275 }
210 } 276 }
211 277
@@ -291,6 +357,25 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
291 msleep(8); 357 msleep(8);
292 spin_lock_irq(&ehci->lock); 358 spin_lock_irq(&ehci->lock);
293 359
360 /* clear phy low-power mode before resume */
361 if (ehci->bus_suspended && ehci->has_hostpc) {
362 i = HCS_N_PORTS(ehci->hcs_params);
363 while (i--) {
364 if (test_bit(i, &ehci->bus_suspended)) {
365 u32 __iomem *hostpc_reg;
366
367 hostpc_reg = (u32 __iomem *)((u8 *) ehci->regs
368 + HOSTPC0 + 4 * i);
369 temp = ehci_readl(ehci, hostpc_reg);
370 ehci_writel(ehci, temp & ~HOSTPC_PHCD,
371 hostpc_reg);
372 }
373 }
374 spin_unlock_irq(&ehci->lock);
375 msleep(5);
376 spin_lock_irq(&ehci->lock);
377 }
378
294 /* manually resume the ports we suspended during bus_suspend() */ 379 /* manually resume the ports we suspended during bus_suspend() */
295 i = HCS_N_PORTS (ehci->hcs_params); 380 i = HCS_N_PORTS (ehci->hcs_params);
296 while (i--) { 381 while (i--) {
@@ -659,7 +744,7 @@ static int ehci_hub_control (
659 * Even if OWNER is set, so the port is owned by the 744 * Even if OWNER is set, so the port is owned by the
660 * companion controller, khubd needs to be able to clear 745 * companion controller, khubd needs to be able to clear
661 * the port-change status bits (especially 746 * the port-change status bits (especially
662 * USB_PORT_FEAT_C_CONNECTION). 747 * USB_PORT_STAT_C_CONNECTION).
663 */ 748 */
664 749
665 switch (wValue) { 750 switch (wValue) {
@@ -675,16 +760,25 @@ static int ehci_hub_control (
675 goto error; 760 goto error;
676 if (ehci->no_selective_suspend) 761 if (ehci->no_selective_suspend)
677 break; 762 break;
678 if (temp & PORT_SUSPEND) { 763 if (!(temp & PORT_SUSPEND))
679 if ((temp & PORT_PE) == 0) 764 break;
680 goto error; 765 if ((temp & PORT_PE) == 0)
681 /* resume signaling for 20 msec */ 766 goto error;
682 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 767
683 ehci_writel(ehci, temp | PORT_RESUME, 768 /* clear phy low-power mode before resume */
684 status_reg); 769 if (hostpc_reg) {
685 ehci->reset_done [wIndex] = jiffies 770 temp1 = ehci_readl(ehci, hostpc_reg);
686 + msecs_to_jiffies (20); 771 ehci_writel(ehci, temp1 & ~HOSTPC_PHCD,
772 hostpc_reg);
773 spin_unlock_irqrestore(&ehci->lock, flags);
774 msleep(5);/* wait to leave low-power mode */
775 spin_lock_irqsave(&ehci->lock, flags);
687 } 776 }
777 /* resume signaling for 20 msec */
778 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
779 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
780 ehci->reset_done[wIndex] = jiffies
781 + msecs_to_jiffies(20);
688 break; 782 break;
689 case USB_PORT_FEAT_C_SUSPEND: 783 case USB_PORT_FEAT_C_SUSPEND:
690 clear_bit(wIndex, &ehci->port_c_suspend); 784 clear_bit(wIndex, &ehci->port_c_suspend);
@@ -729,12 +823,12 @@ static int ehci_hub_control (
729 823
730 // wPortChange bits 824 // wPortChange bits
731 if (temp & PORT_CSC) 825 if (temp & PORT_CSC)
732 status |= 1 << USB_PORT_FEAT_C_CONNECTION; 826 status |= USB_PORT_STAT_C_CONNECTION << 16;
733 if (temp & PORT_PEC) 827 if (temp & PORT_PEC)
734 status |= 1 << USB_PORT_FEAT_C_ENABLE; 828 status |= USB_PORT_STAT_C_ENABLE << 16;
735 829
736 if ((temp & PORT_OCC) && !ignore_oc){ 830 if ((temp & PORT_OCC) && !ignore_oc){
737 status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; 831 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
738 832
739 /* 833 /*
740 * Hubs should disable port power on over-current. 834 * Hubs should disable port power on over-current.
@@ -791,7 +885,7 @@ static int ehci_hub_control (
791 if ((temp & PORT_RESET) 885 if ((temp & PORT_RESET)
792 && time_after_eq(jiffies, 886 && time_after_eq(jiffies,
793 ehci->reset_done[wIndex])) { 887 ehci->reset_done[wIndex])) {
794 status |= 1 << USB_PORT_FEAT_C_RESET; 888 status |= USB_PORT_STAT_C_RESET << 16;
795 ehci->reset_done [wIndex] = 0; 889 ehci->reset_done [wIndex] = 0;
796 890
797 /* force reset to complete */ 891 /* force reset to complete */
@@ -833,7 +927,7 @@ static int ehci_hub_control (
833 */ 927 */
834 928
835 if (temp & PORT_CONNECT) { 929 if (temp & PORT_CONNECT) {
836 status |= 1 << USB_PORT_FEAT_CONNECTION; 930 status |= USB_PORT_STAT_CONNECTION;
837 // status may be from integrated TT 931 // status may be from integrated TT
838 if (ehci->has_hostpc) { 932 if (ehci->has_hostpc) {
839 temp1 = ehci_readl(ehci, hostpc_reg); 933 temp1 = ehci_readl(ehci, hostpc_reg);
@@ -842,11 +936,11 @@ static int ehci_hub_control (
842 status |= ehci_port_speed(ehci, temp); 936 status |= ehci_port_speed(ehci, temp);
843 } 937 }
844 if (temp & PORT_PE) 938 if (temp & PORT_PE)
845 status |= 1 << USB_PORT_FEAT_ENABLE; 939 status |= USB_PORT_STAT_ENABLE;
846 940
847 /* maybe the port was unsuspended without our knowledge */ 941 /* maybe the port was unsuspended without our knowledge */
848 if (temp & (PORT_SUSPEND|PORT_RESUME)) { 942 if (temp & (PORT_SUSPEND|PORT_RESUME)) {
849 status |= 1 << USB_PORT_FEAT_SUSPEND; 943 status |= USB_PORT_STAT_SUSPEND;
850 } else if (test_bit(wIndex, &ehci->suspended_ports)) { 944 } else if (test_bit(wIndex, &ehci->suspended_ports)) {
851 clear_bit(wIndex, &ehci->suspended_ports); 945 clear_bit(wIndex, &ehci->suspended_ports);
852 ehci->reset_done[wIndex] = 0; 946 ehci->reset_done[wIndex] = 0;
@@ -855,13 +949,13 @@ static int ehci_hub_control (
855 } 949 }
856 950
857 if (temp & PORT_OC) 951 if (temp & PORT_OC)
858 status |= 1 << USB_PORT_FEAT_OVER_CURRENT; 952 status |= USB_PORT_STAT_OVERCURRENT;
859 if (temp & PORT_RESET) 953 if (temp & PORT_RESET)
860 status |= 1 << USB_PORT_FEAT_RESET; 954 status |= USB_PORT_STAT_RESET;
861 if (temp & PORT_POWER) 955 if (temp & PORT_POWER)
862 status |= 1 << USB_PORT_FEAT_POWER; 956 status |= USB_PORT_STAT_POWER;
863 if (test_bit(wIndex, &ehci->port_c_suspend)) 957 if (test_bit(wIndex, &ehci->port_c_suspend))
864 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 958 status |= USB_PORT_STAT_C_SUSPEND << 16;
865 959
866#ifndef VERBOSE_DEBUG 960#ifndef VERBOSE_DEBUG
867 if (status & ~0xffff) /* only if wPortChange is interesting */ 961 if (status & ~0xffff) /* only if wPortChange is interesting */
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 0cd6c7795d90..5450e628157f 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -116,6 +116,8 @@
116#define OMAP_UHH_DEBUG_CSR (0x44) 116#define OMAP_UHH_DEBUG_CSR (0x44)
117 117
118/* EHCI Register Set */ 118/* EHCI Register Set */
119#define EHCI_INSNREG04 (0xA0)
120#define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5)
119#define EHCI_INSNREG05_ULPI (0xA4) 121#define EHCI_INSNREG05_ULPI (0xA4)
120#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31 122#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
121#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24 123#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
@@ -352,8 +354,8 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
352 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; 354 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
353 355
354 /* Bypass the TLL module for PHY mode operation */ 356 /* Bypass the TLL module for PHY mode operation */
355 if (omap_rev() <= OMAP3430_REV_ES2_1) { 357 if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) {
356 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1 \n"); 358 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
357 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) || 359 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
358 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) || 360 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
359 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)) 361 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
@@ -382,6 +384,18 @@ static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
382 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg); 384 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
383 385
384 386
387 /*
388 * An undocumented "feature" in the OMAP3 EHCI controller,
389 * causes suspended ports to be taken out of suspend when
390 * the USBCMD.Run/Stop bit is cleared (for example when
391 * we do ehci_bus_suspend).
392 * This breaks suspend-resume if the root-hub is allowed
393 * to suspend. Writing 1 to this undocumented register bit
394 * disables this feature and restores normal behavior.
395 */
396 ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04,
397 EHCI_INSNREG04_DISABLE_UNSUSPEND);
398
385 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) || 399 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
386 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) || 400 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
387 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) { 401 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
@@ -659,6 +673,9 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
659 goto err_add_hcd; 673 goto err_add_hcd;
660 } 674 }
661 675
676 /* root ports should always stay powered */
677 ehci_port_power(omap->ehci, 1);
678
662 return 0; 679 return 0;
663 680
664err_add_hcd: 681err_add_hcd:
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index ead5f4f2aa5a..d43d176161aa 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -109,6 +109,9 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
109 return retval; 109 return retval;
110 110
111 switch (pdev->vendor) { 111 switch (pdev->vendor) {
112 case PCI_VENDOR_ID_NEC:
113 ehci->need_io_watchdog = 0;
114 break;
112 case PCI_VENDOR_ID_INTEL: 115 case PCI_VENDOR_ID_INTEL:
113 ehci->need_io_watchdog = 0; 116 ehci->need_io_watchdog = 0;
114 if (pdev->device == 0x27cc) { 117 if (pdev->device == 0x27cc) {
@@ -284,23 +287,15 @@ static int ehci_pci_suspend(struct usb_hcd *hcd)
284 msleep(10); 287 msleep(10);
285 288
286 /* Root hub was already suspended. Disable irq emission and 289 /* Root hub was already suspended. Disable irq emission and
287 * mark HW unaccessible, bail out if RH has been resumed. Use 290 * mark HW unaccessible. The PM and USB cores make sure that
288 * the spinlock to properly synchronize with possible pending 291 * the root hub is either suspended or stopped.
289 * RH suspend or resume activity.
290 *
291 * This is still racy as hcd->state is manipulated outside of
292 * any locks =P But that will be a different fix.
293 */ 292 */
294 spin_lock_irqsave (&ehci->lock, flags); 293 spin_lock_irqsave (&ehci->lock, flags);
295 if (hcd->state != HC_STATE_SUSPENDED) { 294 ehci_prepare_ports_for_controller_suspend(ehci);
296 rc = -EINVAL;
297 goto bail;
298 }
299 ehci_writel(ehci, 0, &ehci->regs->intr_enable); 295 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
300 (void)ehci_readl(ehci, &ehci->regs->intr_enable); 296 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
301 297
302 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 298 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
303 bail:
304 spin_unlock_irqrestore (&ehci->lock, flags); 299 spin_unlock_irqrestore (&ehci->lock, flags);
305 300
306 // could save FLADJ in case of Vaux power loss 301 // could save FLADJ in case of Vaux power loss
@@ -330,6 +325,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
330 !hibernated) { 325 !hibernated) {
331 int mask = INTR_MASK; 326 int mask = INTR_MASK;
332 327
328 ehci_prepare_ports_for_controller_resume(ehci);
333 if (!hcd->self.root_hub->do_remote_wakeup) 329 if (!hcd->self.root_hub->do_remote_wakeup)
334 mask &= ~STS_PCD; 330 mask &= ~STS_PCD;
335 ehci_writel(ehci, mask, &ehci->regs->intr_enable); 331 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 89521775c567..11a79c4f4a9d 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -663,7 +663,7 @@ qh_urb_transaction (
663 */ 663 */
664 i = urb->num_sgs; 664 i = urb->num_sgs;
665 if (len > 0 && i > 0) { 665 if (len > 0 && i > 0) {
666 sg = urb->sg->sg; 666 sg = urb->sg;
667 buf = sg_dma_address(sg); 667 buf = sg_dma_address(sg);
668 668
669 /* urb->transfer_buffer_length may be smaller than the 669 /* urb->transfer_buffer_length may be smaller than the
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 556c0b48f3ab..650a687f2854 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -536,6 +536,16 @@ struct ehci_fstn {
536 536
537/*-------------------------------------------------------------------------*/ 537/*-------------------------------------------------------------------------*/
538 538
539/* Prepare the PORTSC wakeup flags during controller suspend/resume */
540
541#define ehci_prepare_ports_for_controller_suspend(ehci) \
542 ehci_adjust_port_wakeup_flags(ehci, true);
543
544#define ehci_prepare_ports_for_controller_resume(ehci) \
545 ehci_adjust_port_wakeup_flags(ehci, false);
546
547/*-------------------------------------------------------------------------*/
548
539#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT 549#ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
540 550
541/* 551/*
@@ -556,20 +566,20 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
556 case 0: 566 case 0:
557 return 0; 567 return 0;
558 case 1: 568 case 1:
559 return (1<<USB_PORT_FEAT_LOWSPEED); 569 return USB_PORT_STAT_LOW_SPEED;
560 case 2: 570 case 2:
561 default: 571 default:
562 return (1<<USB_PORT_FEAT_HIGHSPEED); 572 return USB_PORT_STAT_HIGH_SPEED;
563 } 573 }
564 } 574 }
565 return (1<<USB_PORT_FEAT_HIGHSPEED); 575 return USB_PORT_STAT_HIGH_SPEED;
566} 576}
567 577
568#else 578#else
569 579
570#define ehci_is_TDI(e) (0) 580#define ehci_is_TDI(e) (0)
571 581
572#define ehci_port_speed(ehci, portsc) (1<<USB_PORT_FEAT_HIGHSPEED) 582#define ehci_port_speed(ehci, portsc) USB_PORT_STAT_HIGH_SPEED
573#endif 583#endif
574 584
575/*-------------------------------------------------------------------------*/ 585/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/fhci-dbg.c b/drivers/usb/host/fhci-dbg.c
index e799f86dab11..6fe550049119 100644
--- a/drivers/usb/host/fhci-dbg.c
+++ b/drivers/usb/host/fhci-dbg.c
@@ -20,7 +20,7 @@
20#include <linux/debugfs.h> 20#include <linux/debugfs.h>
21#include <linux/seq_file.h> 21#include <linux/seq_file.h>
22#include <linux/usb.h> 22#include <linux/usb.h>
23#include "../core/hcd.h" 23#include <linux/usb/hcd.h>
24#include "fhci.h" 24#include "fhci.h"
25 25
26void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er) 26void fhci_dbg_isr(struct fhci_hcd *fhci, int usb_er)
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index 15379c636143..90453379a434 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -25,12 +25,12 @@
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/hcd.h>
28#include <linux/of_platform.h> 29#include <linux/of_platform.h>
29#include <linux/of_gpio.h> 30#include <linux/of_gpio.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31#include <asm/qe.h> 32#include <asm/qe.h>
32#include <asm/fsl_gtm.h> 33#include <asm/fsl_gtm.h>
33#include "../core/hcd.h"
34#include "fhci.h" 34#include "fhci.h"
35 35
36void fhci_start_sof_timer(struct fhci_hcd *fhci) 36void fhci_start_sof_timer(struct fhci_hcd *fhci)
diff --git a/drivers/usb/host/fhci-hub.c b/drivers/usb/host/fhci-hub.c
index 0cfaedc3e124..348fe62e94f7 100644
--- a/drivers/usb/host/fhci-hub.c
+++ b/drivers/usb/host/fhci-hub.c
@@ -22,9 +22,9 @@
22#include <linux/errno.h> 22#include <linux/errno.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/usb/hcd.h>
25#include <linux/gpio.h> 26#include <linux/gpio.h>
26#include <asm/qe.h> 27#include <asm/qe.h>
27#include "../core/hcd.h"
28#include "fhci.h" 28#include "fhci.h"
29 29
30/* virtual root hub specific descriptor */ 30/* virtual root hub specific descriptor */
diff --git a/drivers/usb/host/fhci-mem.c b/drivers/usb/host/fhci-mem.c
index 5591bfb499d1..b0b88f57a5ac 100644
--- a/drivers/usb/host/fhci-mem.c
+++ b/drivers/usb/host/fhci-mem.c
@@ -21,7 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/list.h> 22#include <linux/list.h>
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include "../core/hcd.h" 24#include <linux/usb/hcd.h>
25#include "fhci.h" 25#include "fhci.h"
26 26
27static void init_td(struct td *td) 27static void init_td(struct td *td)
diff --git a/drivers/usb/host/fhci-q.c b/drivers/usb/host/fhci-q.c
index f73c92359beb..03be7494a476 100644
--- a/drivers/usb/host/fhci-q.c
+++ b/drivers/usb/host/fhci-q.c
@@ -22,7 +22,7 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include "../core/hcd.h" 25#include <linux/usb/hcd.h>
26#include "fhci.h" 26#include "fhci.h"
27 27
28/* maps the hardware error code to the USB error code */ 28/* maps the hardware error code to the USB error code */
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c
index ff43747a614f..4f2cbdcc0273 100644
--- a/drivers/usb/host/fhci-sched.c
+++ b/drivers/usb/host/fhci-sched.c
@@ -24,9 +24,9 @@
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/usb/hcd.h>
27#include <asm/qe.h> 28#include <asm/qe.h>
28#include <asm/fsl_gtm.h> 29#include <asm/fsl_gtm.h>
29#include "../core/hcd.h"
30#include "fhci.h" 30#include "fhci.h"
31 31
32static void recycle_frame(struct fhci_usb *usb, struct packet *pkt) 32static void recycle_frame(struct fhci_usb *usb, struct packet *pkt)
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index 57013479d7f7..7be548ca2183 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -22,7 +22,7 @@
22#include <linux/list.h> 22#include <linux/list.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include "../core/hcd.h" 25#include <linux/usb/hcd.h>
26#include "fhci.h" 26#include "fhci.h"
27 27
28#define DUMMY_BD_BUFFER 0xdeadbeef 28#define DUMMY_BD_BUFFER 0xdeadbeef
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index 72dae1c5ab38..71c3caaea4c1 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -20,13 +20,14 @@
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/bug.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <linux/interrupt.h> 25#include <linux/interrupt.h>
25#include <linux/kfifo.h> 26#include <linux/kfifo.h>
26#include <linux/io.h> 27#include <linux/io.h>
27#include <linux/usb.h> 28#include <linux/usb.h>
29#include <linux/usb/hcd.h>
28#include <asm/qe.h> 30#include <asm/qe.h>
29#include "../core/hcd.h"
30 31
31#define USB_CLOCK 48000000 32#define USB_CLOCK 48000000
32 33
@@ -515,9 +516,13 @@ static inline int cq_put(struct kfifo *kfifo, void *p)
515 516
516static inline void *cq_get(struct kfifo *kfifo) 517static inline void *cq_get(struct kfifo *kfifo)
517{ 518{
518 void *p = NULL; 519 unsigned int sz;
520 void *p;
521
522 sz = kfifo_out(kfifo, (void *)&p, sizeof(p));
523 if (sz != sizeof(p))
524 return NULL;
519 525
520 kfifo_out(kfifo, (void *)&p, sizeof(p));
521 return p; 526 return p;
522} 527}
523 528
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
index 8a12f297645f..ca0e98d8e1f4 100644
--- a/drivers/usb/host/imx21-hcd.c
+++ b/drivers/usb/host/imx21-hcd.c
@@ -56,8 +56,8 @@
56#include <linux/platform_device.h> 56#include <linux/platform_device.h>
57#include <linux/slab.h> 57#include <linux/slab.h>
58#include <linux/usb.h> 58#include <linux/usb.h>
59#include <linux/usb/hcd.h>
59 60
60#include "../core/hcd.h"
61#include "imx21-hcd.h" 61#include "imx21-hcd.h"
62 62
63#ifdef DEBUG 63#ifdef DEBUG
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 92de71dc7729..d9e82123de2a 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -65,6 +65,7 @@
65#include <linux/slab.h> 65#include <linux/slab.h>
66#include <linux/usb.h> 66#include <linux/usb.h>
67#include <linux/usb/isp116x.h> 67#include <linux/usb/isp116x.h>
68#include <linux/usb/hcd.h>
68#include <linux/platform_device.h> 69#include <linux/platform_device.h>
69 70
70#include <asm/io.h> 71#include <asm/io.h>
@@ -72,7 +73,6 @@
72#include <asm/system.h> 73#include <asm/system.h>
73#include <asm/byteorder.h> 74#include <asm/byteorder.h>
74 75
75#include "../core/hcd.h"
76#include "isp116x.h" 76#include "isp116x.h"
77 77
78#define DRIVER_VERSION "03 Nov 2005" 78#define DRIVER_VERSION "03 Nov 2005"
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 217fb5170200..20a0dfe0fe36 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -77,6 +77,7 @@
77#include <linux/interrupt.h> 77#include <linux/interrupt.h>
78#include <linux/usb.h> 78#include <linux/usb.h>
79#include <linux/usb/isp1362.h> 79#include <linux/usb/isp1362.h>
80#include <linux/usb/hcd.h>
80#include <linux/platform_device.h> 81#include <linux/platform_device.h>
81#include <linux/pm.h> 82#include <linux/pm.h>
82#include <linux/io.h> 83#include <linux/io.h>
@@ -95,7 +96,6 @@ module_param(dbg_level, int, 0);
95#define STUB_DEBUG_FILE 96#define STUB_DEBUG_FILE
96#endif 97#endif
97 98
98#include "../core/hcd.h"
99#include "../core/usb.h" 99#include "../core/usb.h"
100#include "isp1362.h" 100#include "isp1362.h"
101 101
@@ -1265,7 +1265,7 @@ static int isp1362_urb_enqueue(struct usb_hcd *hcd,
1265 1265
1266 /* don't submit to a dead or disabled port */ 1266 /* don't submit to a dead or disabled port */
1267 if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) & 1267 if (!((isp1362_hcd->rhport[0] | isp1362_hcd->rhport[1]) &
1268 (1 << USB_PORT_FEAT_ENABLE)) || 1268 USB_PORT_STAT_ENABLE) ||
1269 !HC_IS_RUNNING(hcd->state)) { 1269 !HC_IS_RUNNING(hcd->state)) {
1270 kfree(ep); 1270 kfree(ep);
1271 retval = -ENODEV; 1271 retval = -ENODEV;
@@ -2217,7 +2217,7 @@ static void create_debug_file(struct isp1362_hcd *isp1362_hcd)
2217static void remove_debug_file(struct isp1362_hcd *isp1362_hcd) 2217static void remove_debug_file(struct isp1362_hcd *isp1362_hcd)
2218{ 2218{
2219 if (isp1362_hcd->pde) 2219 if (isp1362_hcd->pde)
2220 remove_proc_entry(proc_filename, 0); 2220 remove_proc_entry(proc_filename, NULL);
2221} 2221}
2222 2222
2223#endif 2223#endif
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 9f01293600b0..dbcafa29c775 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -14,6 +14,7 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/list.h> 15#include <linux/list.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
17#include <linux/usb/hcd.h>
17#include <linux/debugfs.h> 18#include <linux/debugfs.h>
18#include <linux/uaccess.h> 19#include <linux/uaccess.h>
19#include <linux/io.h> 20#include <linux/io.h>
@@ -21,7 +22,6 @@
21#include <asm/unaligned.h> 22#include <asm/unaligned.h>
22#include <asm/cacheflush.h> 23#include <asm/cacheflush.h>
23 24
24#include "../core/hcd.h"
25#include "isp1760-hcd.h" 25#include "isp1760-hcd.h"
26 26
27static struct kmem_cache *qtd_cachep; 27static struct kmem_cache *qtd_cachep;
@@ -111,7 +111,7 @@ struct isp1760_qh {
111 u32 ping; 111 u32 ping;
112}; 112};
113 113
114#define ehci_port_speed(priv, portsc) (1 << USB_PORT_FEAT_HIGHSPEED) 114#define ehci_port_speed(priv, portsc) USB_PORT_STAT_HIGH_SPEED
115 115
116static unsigned int isp1760_readl(__u32 __iomem *regs) 116static unsigned int isp1760_readl(__u32 __iomem *regs)
117{ 117{
@@ -713,12 +713,11 @@ static int check_error(struct ptd *ptd)
713 u32 dw3; 713 u32 dw3;
714 714
715 dw3 = le32_to_cpu(ptd->dw3); 715 dw3 = le32_to_cpu(ptd->dw3);
716 if (dw3 & DW3_HALT_BIT) 716 if (dw3 & DW3_HALT_BIT) {
717 error = -EPIPE; 717 error = -EPIPE;
718 718
719 if (dw3 & DW3_ERROR_BIT) { 719 if (dw3 & DW3_ERROR_BIT)
720 printk(KERN_ERR "error bit is set in DW3\n"); 720 pr_err("error bit is set in DW3\n");
721 error = -EPIPE;
722 } 721 }
723 722
724 if (dw3 & DW3_QTD_ACTIVE) { 723 if (dw3 & DW3_QTD_ACTIVE) {
@@ -1923,7 +1922,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1923 * Even if OWNER is set, so the port is owned by the 1922 * Even if OWNER is set, so the port is owned by the
1924 * companion controller, khubd needs to be able to clear 1923 * companion controller, khubd needs to be able to clear
1925 * the port-change status bits (especially 1924 * the port-change status bits (especially
1926 * USB_PORT_FEAT_C_CONNECTION). 1925 * USB_PORT_STAT_C_CONNECTION).
1927 */ 1926 */
1928 1927
1929 switch (wValue) { 1928 switch (wValue) {
@@ -1987,7 +1986,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
1987 1986
1988 /* wPortChange bits */ 1987 /* wPortChange bits */
1989 if (temp & PORT_CSC) 1988 if (temp & PORT_CSC)
1990 status |= 1 << USB_PORT_FEAT_C_CONNECTION; 1989 status |= USB_PORT_STAT_C_CONNECTION << 16;
1991 1990
1992 1991
1993 /* whoever resumes must GetPortStatus to complete it!! */ 1992 /* whoever resumes must GetPortStatus to complete it!! */
@@ -2007,7 +2006,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2007 /* resume completed? */ 2006 /* resume completed? */
2008 else if (time_after_eq(jiffies, 2007 else if (time_after_eq(jiffies,
2009 priv->reset_done)) { 2008 priv->reset_done)) {
2010 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 2009 status |= USB_PORT_STAT_C_SUSPEND << 16;
2011 priv->reset_done = 0; 2010 priv->reset_done = 0;
2012 2011
2013 /* stop resume signaling */ 2012 /* stop resume signaling */
@@ -2031,7 +2030,7 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2031 if ((temp & PORT_RESET) 2030 if ((temp & PORT_RESET)
2032 && time_after_eq(jiffies, 2031 && time_after_eq(jiffies,
2033 priv->reset_done)) { 2032 priv->reset_done)) {
2034 status |= 1 << USB_PORT_FEAT_C_RESET; 2033 status |= USB_PORT_STAT_C_RESET << 16;
2035 priv->reset_done = 0; 2034 priv->reset_done = 0;
2036 2035
2037 /* force reset to complete */ 2036 /* force reset to complete */
@@ -2062,18 +2061,18 @@ static int isp1760_hub_control(struct usb_hcd *hcd, u16 typeReq,
2062 printk(KERN_ERR "Warning: PORT_OWNER is set\n"); 2061 printk(KERN_ERR "Warning: PORT_OWNER is set\n");
2063 2062
2064 if (temp & PORT_CONNECT) { 2063 if (temp & PORT_CONNECT) {
2065 status |= 1 << USB_PORT_FEAT_CONNECTION; 2064 status |= USB_PORT_STAT_CONNECTION;
2066 /* status may be from integrated TT */ 2065 /* status may be from integrated TT */
2067 status |= ehci_port_speed(priv, temp); 2066 status |= ehci_port_speed(priv, temp);
2068 } 2067 }
2069 if (temp & PORT_PE) 2068 if (temp & PORT_PE)
2070 status |= 1 << USB_PORT_FEAT_ENABLE; 2069 status |= USB_PORT_STAT_ENABLE;
2071 if (temp & (PORT_SUSPEND|PORT_RESUME)) 2070 if (temp & (PORT_SUSPEND|PORT_RESUME))
2072 status |= 1 << USB_PORT_FEAT_SUSPEND; 2071 status |= USB_PORT_STAT_SUSPEND;
2073 if (temp & PORT_RESET) 2072 if (temp & PORT_RESET)
2074 status |= 1 << USB_PORT_FEAT_RESET; 2073 status |= USB_PORT_STAT_RESET;
2075 if (temp & PORT_POWER) 2074 if (temp & PORT_POWER)
2076 status |= 1 << USB_PORT_FEAT_POWER; 2075 status |= USB_PORT_STAT_POWER;
2077 2076
2078 put_unaligned(cpu_to_le32(status), (__le32 *) buf); 2077 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
2079 break; 2078 break;
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 4293cfd28d61..8f0259eaa2c7 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -13,8 +13,8 @@
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/usb/isp1760.h> 15#include <linux/usb/isp1760.h>
16#include <linux/usb/hcd.h>
16 17
17#include "../core/hcd.h"
18#include "isp1760-hcd.h" 18#include "isp1760-hcd.h"
19 19
20#ifdef CONFIG_PPC_OF 20#ifdef CONFIG_PPC_OF
@@ -36,7 +36,7 @@ static int of_isp1760_probe(struct of_device *dev,
36 struct resource memory; 36 struct resource memory;
37 struct of_irq oirq; 37 struct of_irq oirq;
38 int virq; 38 int virq;
39 u64 res_len; 39 resource_size_t res_len;
40 int ret; 40 int ret;
41 const unsigned int *prop; 41 const unsigned int *prop;
42 unsigned int devflags = 0; 42 unsigned int devflags = 0;
@@ -45,13 +45,12 @@ static int of_isp1760_probe(struct of_device *dev,
45 if (ret) 45 if (ret)
46 return -ENXIO; 46 return -ENXIO;
47 47
48 res = request_mem_region(memory.start, memory.end - memory.start + 1, 48 res_len = resource_size(&memory);
49 dev_name(&dev->dev)); 49
50 res = request_mem_region(memory.start, res_len, dev_name(&dev->dev));
50 if (!res) 51 if (!res)
51 return -EBUSY; 52 return -EBUSY;
52 53
53 res_len = memory.end - memory.start + 1;
54
55 if (of_irq_map_one(dp, 0, &oirq)) { 54 if (of_irq_map_one(dp, 0, &oirq)) {
56 ret = -ENODEV; 55 ret = -ENODEV;
57 goto release_reg; 56 goto release_reg;
@@ -92,7 +91,7 @@ static int of_isp1760_probe(struct of_device *dev,
92 return ret; 91 return ret;
93 92
94release_reg: 93release_reg:
95 release_mem_region(memory.start, memory.end - memory.start + 1); 94 release_mem_region(memory.start, res_len);
96 return ret; 95 return ret;
97} 96}
98 97
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index afe59be23645..fc576557d8a5 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -32,6 +32,7 @@
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/usb/otg.h> 34#include <linux/usb/otg.h>
35#include <linux/usb/hcd.h>
35#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
36#include <linux/dmapool.h> 37#include <linux/dmapool.h>
37#include <linux/workqueue.h> 38#include <linux/workqueue.h>
@@ -43,7 +44,6 @@
43#include <asm/unaligned.h> 44#include <asm/unaligned.h>
44#include <asm/byteorder.h> 45#include <asm/byteorder.h>
45 46
46#include "../core/hcd.h"
47 47
48#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell" 48#define DRIVER_AUTHOR "Roman Weissgaerber, David Brownell"
49#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver" 49#define DRIVER_DESC "USB 1.1 'Open' Host Controller (OHCI) Driver"
@@ -1006,9 +1006,14 @@ MODULE_LICENSE ("GPL");
1006#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver 1006#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1007#endif 1007#endif
1008 1008
1009#ifdef CONFIG_ARCH_OMAP 1009#ifdef CONFIG_USB_OHCI_HCD_OMAP1
1010#include "ohci-omap.c" 1010#include "ohci-omap.c"
1011#define PLATFORM_DRIVER ohci_hcd_omap_driver 1011#define OMAP1_PLATFORM_DRIVER ohci_hcd_omap_driver
1012#endif
1013
1014#ifdef CONFIG_USB_OHCI_HCD_OMAP3
1015#include "ohci-omap3.c"
1016#define OMAP3_PLATFORM_DRIVER ohci_hcd_omap3_driver
1012#endif 1017#endif
1013 1018
1014#ifdef CONFIG_ARCH_LH7A404 1019#ifdef CONFIG_ARCH_LH7A404
@@ -1092,6 +1097,8 @@ MODULE_LICENSE ("GPL");
1092 1097
1093#if !defined(PCI_DRIVER) && \ 1098#if !defined(PCI_DRIVER) && \
1094 !defined(PLATFORM_DRIVER) && \ 1099 !defined(PLATFORM_DRIVER) && \
1100 !defined(OMAP1_PLATFORM_DRIVER) && \
1101 !defined(OMAP3_PLATFORM_DRIVER) && \
1095 !defined(OF_PLATFORM_DRIVER) && \ 1102 !defined(OF_PLATFORM_DRIVER) && \
1096 !defined(SA1111_DRIVER) && \ 1103 !defined(SA1111_DRIVER) && \
1097 !defined(PS3_SYSTEM_BUS_DRIVER) && \ 1104 !defined(PS3_SYSTEM_BUS_DRIVER) && \
@@ -1133,6 +1140,18 @@ static int __init ohci_hcd_mod_init(void)
1133 goto error_platform; 1140 goto error_platform;
1134#endif 1141#endif
1135 1142
1143#ifdef OMAP1_PLATFORM_DRIVER
1144 retval = platform_driver_register(&OMAP1_PLATFORM_DRIVER);
1145 if (retval < 0)
1146 goto error_omap1_platform;
1147#endif
1148
1149#ifdef OMAP3_PLATFORM_DRIVER
1150 retval = platform_driver_register(&OMAP3_PLATFORM_DRIVER);
1151 if (retval < 0)
1152 goto error_omap3_platform;
1153#endif
1154
1136#ifdef OF_PLATFORM_DRIVER 1155#ifdef OF_PLATFORM_DRIVER
1137 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER); 1156 retval = of_register_platform_driver(&OF_PLATFORM_DRIVER);
1138 if (retval < 0) 1157 if (retval < 0)
@@ -1200,6 +1219,14 @@ static int __init ohci_hcd_mod_init(void)
1200 platform_driver_unregister(&PLATFORM_DRIVER); 1219 platform_driver_unregister(&PLATFORM_DRIVER);
1201 error_platform: 1220 error_platform:
1202#endif 1221#endif
1222#ifdef OMAP1_PLATFORM_DRIVER
1223 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1224 error_omap1_platform:
1225#endif
1226#ifdef OMAP3_PLATFORM_DRIVER
1227 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1228 error_omap3_platform:
1229#endif
1203#ifdef PS3_SYSTEM_BUS_DRIVER 1230#ifdef PS3_SYSTEM_BUS_DRIVER
1204 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1231 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1205 error_ps3: 1232 error_ps3:
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
new file mode 100644
index 000000000000..2cc8a504b18c
--- /dev/null
+++ b/drivers/usb/host/ohci-omap3.c
@@ -0,0 +1,735 @@
1/*
2 * ohci-omap3.c - driver for OHCI on OMAP3 and later processors
3 *
4 * Bus Glue for OMAP3 USBHOST 3 port OHCI controller
5 * This controller is also used in later OMAPs and AM35x chips
6 *
7 * Copyright (C) 2007-2010 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 *
11 * Based on ehci-omap.c and some other ohci glue layers
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * TODO (last updated Mar 10th, 2010):
28 * - add kernel-doc
29 * - Factor out code common to EHCI to a separate file
30 * - Make EHCI and OHCI coexist together
31 * - needs newer silicon versions to actually work
32 * - the last one to be loaded currently steps on the other's toes
33 * - Add hooks for configuring transceivers, etc. at init/exit
34 * - Add aggressive clock-management code
35 */
36
37#include <linux/platform_device.h>
38#include <linux/clk.h>
39
40#include <plat/usb.h>
41
42/*
43 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
44 * Use ohci_omap_readl()/ohci_omap_writel() functions
45 */
46
47/* TLL Register Set */
48#define OMAP_USBTLL_REVISION (0x00)
49#define OMAP_USBTLL_SYSCONFIG (0x10)
50#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
51#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
52#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
53#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
54#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
55
56#define OMAP_USBTLL_SYSSTATUS (0x14)
57#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
58
59#define OMAP_USBTLL_IRQSTATUS (0x18)
60#define OMAP_USBTLL_IRQENABLE (0x1C)
61
62#define OMAP_TLL_SHARED_CONF (0x30)
63#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
64#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
65#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
66#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
67#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
68
69#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
70#define OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT 24
71#define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11)
72#define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10)
73#define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9)
74#define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8)
75#define OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS (1 << 1)
76#define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0)
77
78#define OMAP_TLL_CHANNEL_COUNT 3
79
80/* UHH Register Set */
81#define OMAP_UHH_REVISION (0x00)
82#define OMAP_UHH_SYSCONFIG (0x10)
83#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
84#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
85#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
86#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
87#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
88#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
89
90#define OMAP_UHH_SYSSTATUS (0x14)
91#define OMAP_UHH_SYSSTATUS_UHHRESETDONE (1 << 0)
92#define OMAP_UHH_SYSSTATUS_OHCIRESETDONE (1 << 1)
93#define OMAP_UHH_SYSSTATUS_EHCIRESETDONE (1 << 2)
94#define OMAP_UHH_HOSTCONFIG (0x40)
95#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
96#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
97#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
98#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
99#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
100#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
101#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
102#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
103#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
104#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
105#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
106
107#define OMAP_UHH_DEBUG_CSR (0x44)
108
109/*-------------------------------------------------------------------------*/
110
111static inline void ohci_omap_writel(void __iomem *base, u32 reg, u32 val)
112{
113 __raw_writel(val, base + reg);
114}
115
116static inline u32 ohci_omap_readl(void __iomem *base, u32 reg)
117{
118 return __raw_readl(base + reg);
119}
120
121static inline void ohci_omap_writeb(void __iomem *base, u8 reg, u8 val)
122{
123 __raw_writeb(val, base + reg);
124}
125
126static inline u8 ohci_omap_readb(void __iomem *base, u8 reg)
127{
128 return __raw_readb(base + reg);
129}
130
131/*-------------------------------------------------------------------------*/
132
133struct ohci_hcd_omap3 {
134 struct ohci_hcd *ohci;
135 struct device *dev;
136
137 struct clk *usbhost_ick;
138 struct clk *usbhost2_120m_fck;
139 struct clk *usbhost1_48m_fck;
140 struct clk *usbtll_fck;
141 struct clk *usbtll_ick;
142
143 /* port_mode: TLL/PHY, 2/3/4/6-PIN, DP-DM/DAT-SE0 */
144 enum ohci_omap3_port_mode port_mode[OMAP3_HS_USB_PORTS];
145 void __iomem *uhh_base;
146 void __iomem *tll_base;
147 void __iomem *ohci_base;
148
149 unsigned es2_compatibility:1;
150};
151
152/*-------------------------------------------------------------------------*/
153
154static void ohci_omap3_clock_power(struct ohci_hcd_omap3 *omap, int on)
155{
156 if (on) {
157 clk_enable(omap->usbtll_ick);
158 clk_enable(omap->usbtll_fck);
159 clk_enable(omap->usbhost_ick);
160 clk_enable(omap->usbhost1_48m_fck);
161 clk_enable(omap->usbhost2_120m_fck);
162 } else {
163 clk_disable(omap->usbhost2_120m_fck);
164 clk_disable(omap->usbhost1_48m_fck);
165 clk_disable(omap->usbhost_ick);
166 clk_disable(omap->usbtll_fck);
167 clk_disable(omap->usbtll_ick);
168 }
169}
170
171static int ohci_omap3_init(struct usb_hcd *hcd)
172{
173 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
174
175 return ohci_init(hcd_to_ohci(hcd));
176}
177
178
179/*-------------------------------------------------------------------------*/
180
181static int ohci_omap3_start(struct usb_hcd *hcd)
182{
183 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
184 int ret;
185
186 /*
187 * RemoteWakeupConnected has to be set explicitly before
188 * calling ohci_run. The reset value of RWC is 0.
189 */
190 ohci->hc_control = OHCI_CTRL_RWC;
191 writel(OHCI_CTRL_RWC, &ohci->regs->control);
192
193 ret = ohci_run(ohci);
194
195 if (ret < 0) {
196 dev_err(hcd->self.controller, "can't start\n");
197 ohci_stop(hcd);
198 }
199
200 return ret;
201}
202
203/*-------------------------------------------------------------------------*/
204
205/*
206 * convert the port-mode enum to a value we can use in the FSLSMODE
207 * field of USBTLL_CHANNEL_CONF
208 */
209static unsigned ohci_omap3_fslsmode(enum ohci_omap3_port_mode mode)
210{
211 switch (mode) {
212 case OMAP_OHCI_PORT_MODE_UNUSED:
213 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DATSE0:
214 return 0x0;
215
216 case OMAP_OHCI_PORT_MODE_PHY_6PIN_DPDM:
217 return 0x1;
218
219 case OMAP_OHCI_PORT_MODE_PHY_3PIN_DATSE0:
220 return 0x2;
221
222 case OMAP_OHCI_PORT_MODE_PHY_4PIN_DPDM:
223 return 0x3;
224
225 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DATSE0:
226 return 0x4;
227
228 case OMAP_OHCI_PORT_MODE_TLL_6PIN_DPDM:
229 return 0x5;
230
231 case OMAP_OHCI_PORT_MODE_TLL_3PIN_DATSE0:
232 return 0x6;
233
234 case OMAP_OHCI_PORT_MODE_TLL_4PIN_DPDM:
235 return 0x7;
236
237 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DATSE0:
238 return 0xA;
239
240 case OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM:
241 return 0xB;
242 default:
243 pr_warning("Invalid port mode, using default\n");
244 return 0x0;
245 }
246}
247
248static void ohci_omap3_tll_config(struct ohci_hcd_omap3 *omap)
249{
250 u32 reg;
251 int i;
252
253 /* Program TLL SHARED CONF */
254 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
255 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
256 reg &= ~OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN;
257 reg |= OMAP_TLL_SHARED_CONF_USB_DIVRATION;
258 reg |= OMAP_TLL_SHARED_CONF_FCLK_IS_ON;
259 ohci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
260
261 /* Program each TLL channel */
262 /*
263 * REVISIT: Only the 3-pin and 4-pin PHY modes have
264 * actually been tested.
265 */
266 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
267
268 /* Enable only those channels that are actually used */
269 if (omap->port_mode[i] == OMAP_OHCI_PORT_MODE_UNUSED)
270 continue;
271
272 reg = ohci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
273 reg |= ohci_omap3_fslsmode(omap->port_mode[i])
274 << OMAP_TLL_CHANNEL_CONF_FSLSMODE_SHIFT;
275 reg |= OMAP_TLL_CHANNEL_CONF_CHANMODE_FSLS;
276 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
277 ohci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
278 }
279}
280
281/* omap3_start_ohci
282 * - Start the TI USBHOST controller
283 */
284static int omap3_start_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
285{
286 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
287 u32 reg = 0;
288 int ret = 0;
289
290 dev_dbg(omap->dev, "starting TI OHCI USB Controller\n");
291
292 /* Get all the clock handles we need */
293 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
294 if (IS_ERR(omap->usbhost_ick)) {
295 dev_err(omap->dev, "could not get usbhost_ick\n");
296 ret = PTR_ERR(omap->usbhost_ick);
297 goto err_host_ick;
298 }
299
300 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
301 if (IS_ERR(omap->usbhost2_120m_fck)) {
302 dev_err(omap->dev, "could not get usbhost_120m_fck\n");
303 ret = PTR_ERR(omap->usbhost2_120m_fck);
304 goto err_host_120m_fck;
305 }
306
307 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
308 if (IS_ERR(omap->usbhost1_48m_fck)) {
309 dev_err(omap->dev, "could not get usbhost_48m_fck\n");
310 ret = PTR_ERR(omap->usbhost1_48m_fck);
311 goto err_host_48m_fck;
312 }
313
314 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
315 if (IS_ERR(omap->usbtll_fck)) {
316 dev_err(omap->dev, "could not get usbtll_fck\n");
317 ret = PTR_ERR(omap->usbtll_fck);
318 goto err_tll_fck;
319 }
320
321 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
322 if (IS_ERR(omap->usbtll_ick)) {
323 dev_err(omap->dev, "could not get usbtll_ick\n");
324 ret = PTR_ERR(omap->usbtll_ick);
325 goto err_tll_ick;
326 }
327
328 /* Now enable all the clocks in the correct order */
329 ohci_omap3_clock_power(omap, 1);
330
331 /* perform TLL soft reset, and wait until reset is complete */
332 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
333 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
334
335 /* Wait for TLL reset to complete */
336 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
337 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
338 cpu_relax();
339
340 if (time_after(jiffies, timeout)) {
341 dev_dbg(omap->dev, "operation timed out\n");
342 ret = -EINVAL;
343 goto err_sys_status;
344 }
345 }
346
347 dev_dbg(omap->dev, "TLL reset done\n");
348
349 /* (1<<3) = no idle mode only for initial debugging */
350 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
351 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
352 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
353 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
354
355
356 /* Put UHH in NoIdle/NoStandby mode */
357 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
358 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
359 | OMAP_UHH_SYSCONFIG_SIDLEMODE
360 | OMAP_UHH_SYSCONFIG_CACTIVITY
361 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
362 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
363 reg &= ~OMAP_UHH_SYSCONFIG_SOFTRESET;
364
365 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
366
367 reg = ohci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
368
369 /* setup ULPI bypass and burst configurations */
370 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
371 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
372 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
373 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
374
375 /*
376 * REVISIT: Pi_CONNECT_STATUS controls MStandby
377 * assertion and Swakeup generation - let us not
378 * worry about this for now. OMAP HWMOD framework
379 * might take care of this later. If not, we can
380 * update these registers when adding aggressive
381 * clock management code.
382 *
383 * For now, turn off all the Pi_CONNECT_STATUS bits
384 *
385 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
386 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
387 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
388 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
389 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
390 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
391 */
392 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
393 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
394 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
395
396 if (omap->es2_compatibility) {
397 /*
398 * All OHCI modes need to go through the TLL,
399 * unlike in the EHCI case. So use UTMI mode
400 * for all ports for OHCI, on ES2.x silicon
401 */
402 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n");
403 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
404 } else {
405 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
406 if (omap->port_mode[0] == OMAP_OHCI_PORT_MODE_UNUSED)
407 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
408 else
409 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
410
411 if (omap->port_mode[1] == OMAP_OHCI_PORT_MODE_UNUSED)
412 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
413 else
414 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
415
416 if (omap->port_mode[2] == OMAP_OHCI_PORT_MODE_UNUSED)
417 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
418 else
419 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
420
421 }
422 ohci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
423 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
424
425 ohci_omap3_tll_config(omap);
426
427 return 0;
428
429err_sys_status:
430 ohci_omap3_clock_power(omap, 0);
431 clk_put(omap->usbtll_ick);
432
433err_tll_ick:
434 clk_put(omap->usbtll_fck);
435
436err_tll_fck:
437 clk_put(omap->usbhost1_48m_fck);
438
439err_host_48m_fck:
440 clk_put(omap->usbhost2_120m_fck);
441
442err_host_120m_fck:
443 clk_put(omap->usbhost_ick);
444
445err_host_ick:
446 return ret;
447}
448
449static void omap3_stop_ohci(struct ohci_hcd_omap3 *omap, struct usb_hcd *hcd)
450{
451 unsigned long timeout = jiffies + msecs_to_jiffies(100);
452
453 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
454
455 /* Reset USBHOST for insmod/rmmod to work */
456 ohci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
457 OMAP_UHH_SYSCONFIG_SOFTRESET);
458 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
459 & OMAP_UHH_SYSSTATUS_UHHRESETDONE)) {
460 cpu_relax();
461
462 if (time_after(jiffies, timeout))
463 dev_dbg(omap->dev, "operation timed out\n");
464 }
465
466 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
467 & OMAP_UHH_SYSSTATUS_OHCIRESETDONE)) {
468 cpu_relax();
469
470 if (time_after(jiffies, timeout))
471 dev_dbg(omap->dev, "operation timed out\n");
472 }
473
474 while (!(ohci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
475 & OMAP_UHH_SYSSTATUS_EHCIRESETDONE)) {
476 cpu_relax();
477
478 if (time_after(jiffies, timeout))
479 dev_dbg(omap->dev, "operation timed out\n");
480 }
481
482 ohci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
483
484 while (!(ohci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
485 & (1 << 0))) {
486 cpu_relax();
487
488 if (time_after(jiffies, timeout))
489 dev_dbg(omap->dev, "operation timed out\n");
490 }
491
492 ohci_omap3_clock_power(omap, 0);
493
494 if (omap->usbtll_fck != NULL) {
495 clk_put(omap->usbtll_fck);
496 omap->usbtll_fck = NULL;
497 }
498
499 if (omap->usbhost_ick != NULL) {
500 clk_put(omap->usbhost_ick);
501 omap->usbhost_ick = NULL;
502 }
503
504 if (omap->usbhost1_48m_fck != NULL) {
505 clk_put(omap->usbhost1_48m_fck);
506 omap->usbhost1_48m_fck = NULL;
507 }
508
509 if (omap->usbhost2_120m_fck != NULL) {
510 clk_put(omap->usbhost2_120m_fck);
511 omap->usbhost2_120m_fck = NULL;
512 }
513
514 if (omap->usbtll_ick != NULL) {
515 clk_put(omap->usbtll_ick);
516 omap->usbtll_ick = NULL;
517 }
518
519 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
520}
521
522/*-------------------------------------------------------------------------*/
523
524static const struct hc_driver ohci_omap3_hc_driver = {
525 .description = hcd_name,
526 .product_desc = "OMAP3 OHCI Host Controller",
527 .hcd_priv_size = sizeof(struct ohci_hcd),
528
529 /*
530 * generic hardware linkage
531 */
532 .irq = ohci_irq,
533 .flags = HCD_USB11 | HCD_MEMORY,
534
535 /*
536 * basic lifecycle operations
537 */
538 .reset = ohci_omap3_init,
539 .start = ohci_omap3_start,
540 .stop = ohci_stop,
541 .shutdown = ohci_shutdown,
542
543 /*
544 * managing i/o requests and associated device resources
545 */
546 .urb_enqueue = ohci_urb_enqueue,
547 .urb_dequeue = ohci_urb_dequeue,
548 .endpoint_disable = ohci_endpoint_disable,
549
550 /*
551 * scheduling support
552 */
553 .get_frame_number = ohci_get_frame,
554
555 /*
556 * root hub support
557 */
558 .hub_status_data = ohci_hub_status_data,
559 .hub_control = ohci_hub_control,
560#ifdef CONFIG_PM
561 .bus_suspend = ohci_bus_suspend,
562 .bus_resume = ohci_bus_resume,
563#endif
564 .start_port_reset = ohci_start_port_reset,
565};
566
567/*-------------------------------------------------------------------------*/
568
569/*
570 * configure so an HC device and id are always provided
571 * always called with process context; sleeping is OK
572 */
573
574/**
575 * ohci_hcd_omap3_probe - initialize OMAP-based HCDs
576 *
577 * Allocates basic resources for this USB host controller, and
578 * then invokes the start() method for the HCD associated with it
579 * through the hotplug entry's driver_data.
580 */
581static int __devinit ohci_hcd_omap3_probe(struct platform_device *pdev)
582{
583 struct ohci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
584 struct ohci_hcd_omap3 *omap;
585 struct resource *res;
586 struct usb_hcd *hcd;
587 int ret = -ENODEV;
588 int irq;
589
590 if (usb_disabled())
591 goto err_disabled;
592
593 if (!pdata) {
594 dev_dbg(&pdev->dev, "missing platform_data\n");
595 goto err_pdata;
596 }
597
598 irq = platform_get_irq(pdev, 0);
599
600 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
601 if (!omap) {
602 ret = -ENOMEM;
603 goto err_disabled;
604 }
605
606 hcd = usb_create_hcd(&ohci_omap3_hc_driver, &pdev->dev,
607 dev_name(&pdev->dev));
608 if (!hcd) {
609 ret = -ENOMEM;
610 goto err_create_hcd;
611 }
612
613 platform_set_drvdata(pdev, omap);
614 omap->dev = &pdev->dev;
615 omap->port_mode[0] = pdata->port_mode[0];
616 omap->port_mode[1] = pdata->port_mode[1];
617 omap->port_mode[2] = pdata->port_mode[2];
618 omap->es2_compatibility = pdata->es2_compatibility;
619 omap->ohci = hcd_to_ohci(hcd);
620
621 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
622
623 hcd->rsrc_start = res->start;
624 hcd->rsrc_len = resource_size(res);
625
626 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
627 if (!hcd->regs) {
628 dev_err(&pdev->dev, "OHCI ioremap failed\n");
629 ret = -ENOMEM;
630 goto err_ioremap;
631 }
632
633 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
634 omap->uhh_base = ioremap(res->start, resource_size(res));
635 if (!omap->uhh_base) {
636 dev_err(&pdev->dev, "UHH ioremap failed\n");
637 ret = -ENOMEM;
638 goto err_uhh_ioremap;
639 }
640
641 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
642 omap->tll_base = ioremap(res->start, resource_size(res));
643 if (!omap->tll_base) {
644 dev_err(&pdev->dev, "TLL ioremap failed\n");
645 ret = -ENOMEM;
646 goto err_tll_ioremap;
647 }
648
649 ret = omap3_start_ohci(omap, hcd);
650 if (ret) {
651 dev_dbg(&pdev->dev, "failed to start ehci\n");
652 goto err_start;
653 }
654
655 ohci_hcd_init(omap->ohci);
656
657 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
658 if (ret) {
659 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
660 goto err_add_hcd;
661 }
662
663 return 0;
664
665err_add_hcd:
666 omap3_stop_ohci(omap, hcd);
667
668err_start:
669 iounmap(omap->tll_base);
670
671err_tll_ioremap:
672 iounmap(omap->uhh_base);
673
674err_uhh_ioremap:
675 iounmap(hcd->regs);
676
677err_ioremap:
678 usb_put_hcd(hcd);
679
680err_create_hcd:
681 kfree(omap);
682err_pdata:
683err_disabled:
684 return ret;
685}
686
687/*
688 * may be called without controller electrically present
689 * may be called with controller, bus, and devices active
690 */
691
692/**
693 * ohci_hcd_omap3_remove - shutdown processing for OHCI HCDs
694 * @pdev: USB Host Controller being removed
695 *
696 * Reverses the effect of ohci_hcd_omap3_probe(), first invoking
697 * the HCD's stop() method. It is always called from a thread
698 * context, normally "rmmod", "apmd", or something similar.
699 */
700static int __devexit ohci_hcd_omap3_remove(struct platform_device *pdev)
701{
702 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev);
703 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
704
705 usb_remove_hcd(hcd);
706 omap3_stop_ohci(omap, hcd);
707 iounmap(hcd->regs);
708 iounmap(omap->tll_base);
709 iounmap(omap->uhh_base);
710 usb_put_hcd(hcd);
711 kfree(omap);
712
713 return 0;
714}
715
716static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
717{
718 struct ohci_hcd_omap3 *omap = platform_get_drvdata(pdev);
719 struct usb_hcd *hcd = ohci_to_hcd(omap->ohci);
720
721 if (hcd->driver->shutdown)
722 hcd->driver->shutdown(hcd);
723}
724
725static struct platform_driver ohci_hcd_omap3_driver = {
726 .probe = ohci_hcd_omap3_probe,
727 .remove = __devexit_p(ohci_hcd_omap3_remove),
728 .shutdown = ohci_hcd_omap3_shutdown,
729 .driver = {
730 .name = "ohci-omap3",
731 },
732};
733
734MODULE_ALIAS("platform:ohci-omap3");
735MODULE_AUTHOR("Anand Gadiyar <gadiyar@ti.com>");
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index e62b30b3e429..f608dfd09a8a 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -34,12 +34,11 @@
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/usb/hcd.h>
37#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
38#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
39#include <linux/io.h> 40#include <linux/io.h>
40 41
41#include "../core/hcd.h"
42
43#include <asm/irq.h> 42#include <asm/irq.h>
44#include <asm/system.h> 43#include <asm/system.h>
45#include <asm/unaligned.h> 44#include <asm/unaligned.h>
@@ -3154,10 +3153,10 @@ static inline unsigned int oxu_port_speed(struct oxu_hcd *oxu,
3154 case 0: 3153 case 0:
3155 return 0; 3154 return 0;
3156 case 1: 3155 case 1:
3157 return 1 << USB_PORT_FEAT_LOWSPEED; 3156 return USB_PORT_STAT_LOW_SPEED;
3158 case 2: 3157 case 2:
3159 default: 3158 default:
3160 return 1 << USB_PORT_FEAT_HIGHSPEED; 3159 return USB_PORT_STAT_HIGH_SPEED;
3161 } 3160 }
3162} 3161}
3163 3162
@@ -3202,7 +3201,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
3202 * Even if OWNER is set, so the port is owned by the 3201 * Even if OWNER is set, so the port is owned by the
3203 * companion controller, khubd needs to be able to clear 3202 * companion controller, khubd needs to be able to clear
3204 * the port-change status bits (especially 3203 * the port-change status bits (especially
3205 * USB_PORT_FEAT_C_CONNECTION). 3204 * USB_PORT_STAT_C_CONNECTION).
3206 */ 3205 */
3207 3206
3208 switch (wValue) { 3207 switch (wValue) {
@@ -3264,11 +3263,11 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
3264 3263
3265 /* wPortChange bits */ 3264 /* wPortChange bits */
3266 if (temp & PORT_CSC) 3265 if (temp & PORT_CSC)
3267 status |= 1 << USB_PORT_FEAT_C_CONNECTION; 3266 status |= USB_PORT_STAT_C_CONNECTION << 16;
3268 if (temp & PORT_PEC) 3267 if (temp & PORT_PEC)
3269 status |= 1 << USB_PORT_FEAT_C_ENABLE; 3268 status |= USB_PORT_STAT_C_ENABLE << 16;
3270 if ((temp & PORT_OCC) && !ignore_oc) 3269 if ((temp & PORT_OCC) && !ignore_oc)
3271 status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; 3270 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
3272 3271
3273 /* whoever resumes must GetPortStatus to complete it!! */ 3272 /* whoever resumes must GetPortStatus to complete it!! */
3274 if (temp & PORT_RESUME) { 3273 if (temp & PORT_RESUME) {
@@ -3286,7 +3285,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
3286 /* resume completed? */ 3285 /* resume completed? */
3287 else if (time_after_eq(jiffies, 3286 else if (time_after_eq(jiffies,
3288 oxu->reset_done[wIndex])) { 3287 oxu->reset_done[wIndex])) {
3289 status |= 1 << USB_PORT_FEAT_C_SUSPEND; 3288 status |= USB_PORT_STAT_C_SUSPEND << 16;
3290 oxu->reset_done[wIndex] = 0; 3289 oxu->reset_done[wIndex] = 0;
3291 3290
3292 /* stop resume signaling */ 3291 /* stop resume signaling */
@@ -3309,7 +3308,7 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
3309 if ((temp & PORT_RESET) 3308 if ((temp & PORT_RESET)
3310 && time_after_eq(jiffies, 3309 && time_after_eq(jiffies,
3311 oxu->reset_done[wIndex])) { 3310 oxu->reset_done[wIndex])) {
3312 status |= 1 << USB_PORT_FEAT_C_RESET; 3311 status |= USB_PORT_STAT_C_RESET << 16;
3313 oxu->reset_done[wIndex] = 0; 3312 oxu->reset_done[wIndex] = 0;
3314 3313
3315 /* force reset to complete */ 3314 /* force reset to complete */
@@ -3348,20 +3347,20 @@ static int oxu_hub_control(struct usb_hcd *hcd, u16 typeReq,
3348 */ 3347 */
3349 3348
3350 if (temp & PORT_CONNECT) { 3349 if (temp & PORT_CONNECT) {
3351 status |= 1 << USB_PORT_FEAT_CONNECTION; 3350 status |= USB_PORT_STAT_CONNECTION;
3352 /* status may be from integrated TT */ 3351 /* status may be from integrated TT */
3353 status |= oxu_port_speed(oxu, temp); 3352 status |= oxu_port_speed(oxu, temp);
3354 } 3353 }
3355 if (temp & PORT_PE) 3354 if (temp & PORT_PE)
3356 status |= 1 << USB_PORT_FEAT_ENABLE; 3355 status |= USB_PORT_STAT_ENABLE;
3357 if (temp & (PORT_SUSPEND|PORT_RESUME)) 3356 if (temp & (PORT_SUSPEND|PORT_RESUME))
3358 status |= 1 << USB_PORT_FEAT_SUSPEND; 3357 status |= USB_PORT_STAT_SUSPEND;
3359 if (temp & PORT_OC) 3358 if (temp & PORT_OC)
3360 status |= 1 << USB_PORT_FEAT_OVER_CURRENT; 3359 status |= USB_PORT_STAT_OVERCURRENT;
3361 if (temp & PORT_RESET) 3360 if (temp & PORT_RESET)
3362 status |= 1 << USB_PORT_FEAT_RESET; 3361 status |= USB_PORT_STAT_RESET;
3363 if (temp & PORT_POWER) 3362 if (temp & PORT_POWER)
3364 status |= 1 << USB_PORT_FEAT_POWER; 3363 status |= USB_PORT_STAT_POWER;
3365 3364
3366#ifndef OXU_VERBOSE_DEBUG 3365#ifndef OXU_VERBOSE_DEBUG
3367 if (status & ~0xffff) /* only if wPortChange is interesting */ 3366 if (status & ~0xffff) /* only if wPortChange is interesting */
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index d478ffad59b4..6db57ab6079d 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -33,6 +33,7 @@
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/usb/hcd.h>
36#include <linux/platform_device.h> 37#include <linux/platform_device.h>
37#include <linux/io.h> 38#include <linux/io.h>
38#include <linux/mm.h> 39#include <linux/mm.h>
@@ -40,7 +41,6 @@
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include <asm/cacheflush.h> 42#include <asm/cacheflush.h>
42 43
43#include "../core/hcd.h"
44#include "r8a66597.h" 44#include "r8a66597.h"
45 45
46MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver"); 46MODULE_DESCRIPTION("R8A66597 USB Host Controller Driver");
@@ -1018,10 +1018,10 @@ static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
1018 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST; 1018 rh->old_syssts = r8a66597_read(r8a66597, get_syssts_reg(port)) & LNST;
1019 rh->scount = R8A66597_MAX_SAMPLING; 1019 rh->scount = R8A66597_MAX_SAMPLING;
1020 if (connect) 1020 if (connect)
1021 rh->port |= 1 << USB_PORT_FEAT_CONNECTION; 1021 rh->port |= USB_PORT_STAT_CONNECTION;
1022 else 1022 else
1023 rh->port &= ~(1 << USB_PORT_FEAT_CONNECTION); 1023 rh->port &= ~USB_PORT_STAT_CONNECTION;
1024 rh->port |= 1 << USB_PORT_FEAT_C_CONNECTION; 1024 rh->port |= USB_PORT_STAT_C_CONNECTION << 16;
1025 1025
1026 r8a66597_root_hub_start_polling(r8a66597); 1026 r8a66597_root_hub_start_polling(r8a66597);
1027} 1027}
@@ -1059,15 +1059,14 @@ static void r8a66597_usb_connect(struct r8a66597 *r8a66597, int port)
1059 u16 speed = get_rh_usb_speed(r8a66597, port); 1059 u16 speed = get_rh_usb_speed(r8a66597, port);
1060 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 1060 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1061 1061
1062 rh->port &= ~((1 << USB_PORT_FEAT_HIGHSPEED) | 1062 rh->port &= ~(USB_PORT_STAT_HIGH_SPEED | USB_PORT_STAT_LOW_SPEED);
1063 (1 << USB_PORT_FEAT_LOWSPEED));
1064 if (speed == HSMODE) 1063 if (speed == HSMODE)
1065 rh->port |= (1 << USB_PORT_FEAT_HIGHSPEED); 1064 rh->port |= USB_PORT_STAT_HIGH_SPEED;
1066 else if (speed == LSMODE) 1065 else if (speed == LSMODE)
1067 rh->port |= (1 << USB_PORT_FEAT_LOWSPEED); 1066 rh->port |= USB_PORT_STAT_LOW_SPEED;
1068 1067
1069 rh->port &= ~(1 << USB_PORT_FEAT_RESET); 1068 rh->port &= USB_PORT_STAT_RESET;
1070 rh->port |= 1 << USB_PORT_FEAT_ENABLE; 1069 rh->port |= USB_PORT_STAT_ENABLE;
1071} 1070}
1072 1071
1073/* this function must be called with interrupt disabled */ 1072/* this function must be called with interrupt disabled */
@@ -1706,7 +1705,7 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
1706 u16 tmp; 1705 u16 tmp;
1707 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 1706 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
1708 1707
1709 if (rh->port & (1 << USB_PORT_FEAT_RESET)) { 1708 if (rh->port & USB_PORT_STAT_RESET) {
1710 unsigned long dvstctr_reg = get_dvstctr_reg(port); 1709 unsigned long dvstctr_reg = get_dvstctr_reg(port);
1711 1710
1712 tmp = r8a66597_read(r8a66597, dvstctr_reg); 1711 tmp = r8a66597_read(r8a66597, dvstctr_reg);
@@ -1718,7 +1717,7 @@ static void r8a66597_root_hub_control(struct r8a66597 *r8a66597, int port)
1718 r8a66597_usb_connect(r8a66597, port); 1717 r8a66597_usb_connect(r8a66597, port);
1719 } 1718 }
1720 1719
1721 if (!(rh->port & (1 << USB_PORT_FEAT_CONNECTION))) { 1720 if (!(rh->port & USB_PORT_STAT_CONNECTION)) {
1722 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port)); 1721 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
1723 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port)); 1722 r8a66597_bset(r8a66597, ATTCHE, get_intenb_reg(port));
1724 } 1723 }
@@ -2186,7 +2185,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2186 2185
2187 switch (wValue) { 2186 switch (wValue) {
2188 case USB_PORT_FEAT_ENABLE: 2187 case USB_PORT_FEAT_ENABLE:
2189 rh->port &= ~(1 << USB_PORT_FEAT_POWER); 2188 rh->port &= ~USB_PORT_STAT_POWER;
2190 break; 2189 break;
2191 case USB_PORT_FEAT_SUSPEND: 2190 case USB_PORT_FEAT_SUSPEND:
2192 break; 2191 break;
@@ -2227,12 +2226,12 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2227 break; 2226 break;
2228 case USB_PORT_FEAT_POWER: 2227 case USB_PORT_FEAT_POWER:
2229 r8a66597_port_power(r8a66597, port, 1); 2228 r8a66597_port_power(r8a66597, port, 1);
2230 rh->port |= (1 << USB_PORT_FEAT_POWER); 2229 rh->port |= USB_PORT_STAT_POWER;
2231 break; 2230 break;
2232 case USB_PORT_FEAT_RESET: { 2231 case USB_PORT_FEAT_RESET: {
2233 struct r8a66597_device *dev = rh->dev; 2232 struct r8a66597_device *dev = rh->dev;
2234 2233
2235 rh->port |= (1 << USB_PORT_FEAT_RESET); 2234 rh->port |= USB_PORT_STAT_RESET;
2236 2235
2237 disable_r8a66597_pipe_all(r8a66597, dev); 2236 disable_r8a66597_pipe_all(r8a66597, dev);
2238 free_usb_address(r8a66597, dev, 1); 2237 free_usb_address(r8a66597, dev, 1);
@@ -2270,12 +2269,12 @@ static int r8a66597_bus_suspend(struct usb_hcd *hcd)
2270 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 2269 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2271 unsigned long dvstctr_reg = get_dvstctr_reg(port); 2270 unsigned long dvstctr_reg = get_dvstctr_reg(port);
2272 2271
2273 if (!(rh->port & (1 << USB_PORT_FEAT_ENABLE))) 2272 if (!(rh->port & USB_PORT_STAT_ENABLE))
2274 continue; 2273 continue;
2275 2274
2276 dbg("suspend port = %d", port); 2275 dbg("suspend port = %d", port);
2277 r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */ 2276 r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */
2278 rh->port |= 1 << USB_PORT_FEAT_SUSPEND; 2277 rh->port |= USB_PORT_STAT_SUSPEND;
2279 2278
2280 if (rh->dev->udev->do_remote_wakeup) { 2279 if (rh->dev->udev->do_remote_wakeup) {
2281 msleep(3); /* waiting last SOF */ 2280 msleep(3); /* waiting last SOF */
@@ -2301,12 +2300,12 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
2301 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 2300 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2302 unsigned long dvstctr_reg = get_dvstctr_reg(port); 2301 unsigned long dvstctr_reg = get_dvstctr_reg(port);
2303 2302
2304 if (!(rh->port & (1 << USB_PORT_FEAT_SUSPEND))) 2303 if (!(rh->port & USB_PORT_STAT_SUSPEND))
2305 continue; 2304 continue;
2306 2305
2307 dbg("resume port = %d", port); 2306 dbg("resume port = %d", port);
2308 rh->port &= ~(1 << USB_PORT_FEAT_SUSPEND); 2307 rh->port &= ~USB_PORT_STAT_SUSPEND;
2309 rh->port |= 1 << USB_PORT_FEAT_C_SUSPEND; 2308 rh->port |= USB_PORT_STAT_C_SUSPEND < 16;
2310 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); 2309 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
2311 msleep(50); 2310 msleep(50);
2312 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg); 2311 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 3b867a8af7b2..bcf9f0e809de 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -45,6 +45,7 @@
45#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/usb/sl811.h> 47#include <linux/usb/sl811.h>
48#include <linux/usb/hcd.h>
48#include <linux/platform_device.h> 49#include <linux/platform_device.h>
49 50
50#include <asm/io.h> 51#include <asm/io.h>
@@ -53,7 +54,6 @@
53#include <asm/byteorder.h> 54#include <asm/byteorder.h>
54#include <asm/unaligned.h> 55#include <asm/unaligned.h>
55 56
56#include "../core/hcd.h"
57#include "sl811.h" 57#include "sl811.h"
58 58
59 59
@@ -90,10 +90,10 @@ static void port_power(struct sl811 *sl811, int is_on)
90 90
91 /* hub is inactive unless the port is powered */ 91 /* hub is inactive unless the port is powered */
92 if (is_on) { 92 if (is_on) {
93 if (sl811->port1 & (1 << USB_PORT_FEAT_POWER)) 93 if (sl811->port1 & USB_PORT_STAT_POWER)
94 return; 94 return;
95 95
96 sl811->port1 = (1 << USB_PORT_FEAT_POWER); 96 sl811->port1 = USB_PORT_STAT_POWER;
97 sl811->irq_enable = SL11H_INTMASK_INSRMV; 97 sl811->irq_enable = SL11H_INTMASK_INSRMV;
98 } else { 98 } else {
99 sl811->port1 = 0; 99 sl811->port1 = 0;
@@ -407,7 +407,7 @@ static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
407 407
408static inline void start_transfer(struct sl811 *sl811) 408static inline void start_transfer(struct sl811 *sl811)
409{ 409{
410 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) 410 if (sl811->port1 & USB_PORT_STAT_SUSPEND)
411 return; 411 return;
412 if (sl811->active_a == NULL) { 412 if (sl811->active_a == NULL) {
413 sl811->active_a = start(sl811, SL811_EP_A(SL811_HOST_BUF)); 413 sl811->active_a = start(sl811, SL811_EP_A(SL811_HOST_BUF));
@@ -721,23 +721,23 @@ retry:
721 * force the reset and make khubd clean up later. 721 * force the reset and make khubd clean up later.
722 */ 722 */
723 if (irqstat & SL11H_INTMASK_RD) 723 if (irqstat & SL11H_INTMASK_RD)
724 sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION); 724 sl811->port1 &= ~USB_PORT_STAT_CONNECTION;
725 else 725 else
726 sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION; 726 sl811->port1 |= USB_PORT_STAT_CONNECTION;
727 727
728 sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION; 728 sl811->port1 |= USB_PORT_STAT_C_CONNECTION << 16;
729 729
730 } else if (irqstat & SL11H_INTMASK_RD) { 730 } else if (irqstat & SL11H_INTMASK_RD) {
731 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) { 731 if (sl811->port1 & USB_PORT_STAT_SUSPEND) {
732 DBG("wakeup\n"); 732 DBG("wakeup\n");
733 sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND; 733 sl811->port1 |= USB_PORT_STAT_C_SUSPEND << 16;
734 sl811->stat_wake++; 734 sl811->stat_wake++;
735 } else 735 } else
736 irqstat &= ~SL11H_INTMASK_RD; 736 irqstat &= ~SL11H_INTMASK_RD;
737 } 737 }
738 738
739 if (irqstat) { 739 if (irqstat) {
740 if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)) 740 if (sl811->port1 & USB_PORT_STAT_ENABLE)
741 start_transfer(sl811); 741 start_transfer(sl811);
742 ret = IRQ_HANDLED; 742 ret = IRQ_HANDLED;
743 if (retries--) 743 if (retries--)
@@ -819,7 +819,7 @@ static int sl811h_urb_enqueue(
819 spin_lock_irqsave(&sl811->lock, flags); 819 spin_lock_irqsave(&sl811->lock, flags);
820 820
821 /* don't submit to a dead or disabled port */ 821 /* don't submit to a dead or disabled port */
822 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)) 822 if (!(sl811->port1 & USB_PORT_STAT_ENABLE)
823 || !HC_IS_RUNNING(hcd->state)) { 823 || !HC_IS_RUNNING(hcd->state)) {
824 retval = -ENODEV; 824 retval = -ENODEV;
825 kfree(ep); 825 kfree(ep);
@@ -1119,9 +1119,9 @@ sl811h_timer(unsigned long _sl811)
1119 unsigned long flags; 1119 unsigned long flags;
1120 u8 irqstat; 1120 u8 irqstat;
1121 u8 signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE; 1121 u8 signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE;
1122 const u32 mask = (1 << USB_PORT_FEAT_CONNECTION) 1122 const u32 mask = USB_PORT_STAT_CONNECTION
1123 | (1 << USB_PORT_FEAT_ENABLE) 1123 | USB_PORT_STAT_ENABLE
1124 | (1 << USB_PORT_FEAT_LOWSPEED); 1124 | USB_PORT_STAT_LOW_SPEED;
1125 1125
1126 spin_lock_irqsave(&sl811->lock, flags); 1126 spin_lock_irqsave(&sl811->lock, flags);
1127 1127
@@ -1135,8 +1135,8 @@ sl811h_timer(unsigned long _sl811)
1135 switch (signaling) { 1135 switch (signaling) {
1136 case SL11H_CTL1MASK_SE0: 1136 case SL11H_CTL1MASK_SE0:
1137 DBG("end reset\n"); 1137 DBG("end reset\n");
1138 sl811->port1 = (1 << USB_PORT_FEAT_C_RESET) 1138 sl811->port1 = (USB_PORT_STAT_C_RESET << 16)
1139 | (1 << USB_PORT_FEAT_POWER); 1139 | USB_PORT_STAT_POWER;
1140 sl811->ctrl1 = 0; 1140 sl811->ctrl1 = 0;
1141 /* don't wrongly ack RD */ 1141 /* don't wrongly ack RD */
1142 if (irqstat & SL11H_INTMASK_INSRMV) 1142 if (irqstat & SL11H_INTMASK_INSRMV)
@@ -1144,7 +1144,7 @@ sl811h_timer(unsigned long _sl811)
1144 break; 1144 break;
1145 case SL11H_CTL1MASK_K: 1145 case SL11H_CTL1MASK_K:
1146 DBG("end resume\n"); 1146 DBG("end resume\n");
1147 sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND); 1147 sl811->port1 &= ~USB_PORT_STAT_SUSPEND;
1148 break; 1148 break;
1149 default: 1149 default:
1150 DBG("odd timer signaling: %02x\n", signaling); 1150 DBG("odd timer signaling: %02x\n", signaling);
@@ -1154,26 +1154,26 @@ sl811h_timer(unsigned long _sl811)
1154 1154
1155 if (irqstat & SL11H_INTMASK_RD) { 1155 if (irqstat & SL11H_INTMASK_RD) {
1156 /* usbcore nukes all pending transactions on disconnect */ 1156 /* usbcore nukes all pending transactions on disconnect */
1157 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) 1157 if (sl811->port1 & USB_PORT_STAT_CONNECTION)
1158 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION) 1158 sl811->port1 |= (USB_PORT_STAT_C_CONNECTION << 16)
1159 | (1 << USB_PORT_FEAT_C_ENABLE); 1159 | (USB_PORT_STAT_C_ENABLE << 16);
1160 sl811->port1 &= ~mask; 1160 sl811->port1 &= ~mask;
1161 sl811->irq_enable = SL11H_INTMASK_INSRMV; 1161 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1162 } else { 1162 } else {
1163 sl811->port1 |= mask; 1163 sl811->port1 |= mask;
1164 if (irqstat & SL11H_INTMASK_DP) 1164 if (irqstat & SL11H_INTMASK_DP)
1165 sl811->port1 &= ~(1 << USB_PORT_FEAT_LOWSPEED); 1165 sl811->port1 &= ~USB_PORT_STAT_LOW_SPEED;
1166 sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD; 1166 sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD;
1167 } 1167 }
1168 1168
1169 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) { 1169 if (sl811->port1 & USB_PORT_STAT_CONNECTION) {
1170 u8 ctrl2 = SL811HS_CTL2_INIT; 1170 u8 ctrl2 = SL811HS_CTL2_INIT;
1171 1171
1172 sl811->irq_enable |= SL11H_INTMASK_DONE_A; 1172 sl811->irq_enable |= SL11H_INTMASK_DONE_A;
1173#ifdef USE_B 1173#ifdef USE_B
1174 sl811->irq_enable |= SL11H_INTMASK_DONE_B; 1174 sl811->irq_enable |= SL11H_INTMASK_DONE_B;
1175#endif 1175#endif
1176 if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) { 1176 if (sl811->port1 & USB_PORT_STAT_LOW_SPEED) {
1177 sl811->ctrl1 |= SL11H_CTL1MASK_LSPD; 1177 sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
1178 ctrl2 |= SL811HS_CTL2MASK_DSWAP; 1178 ctrl2 |= SL811HS_CTL2MASK_DSWAP;
1179 } 1179 }
@@ -1233,7 +1233,7 @@ sl811h_hub_control(
1233 1233
1234 switch (wValue) { 1234 switch (wValue) {
1235 case USB_PORT_FEAT_ENABLE: 1235 case USB_PORT_FEAT_ENABLE:
1236 sl811->port1 &= (1 << USB_PORT_FEAT_POWER); 1236 sl811->port1 &= USB_PORT_STAT_POWER;
1237 sl811->ctrl1 = 0; 1237 sl811->ctrl1 = 0;
1238 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1); 1238 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1239 sl811->irq_enable = SL11H_INTMASK_INSRMV; 1239 sl811->irq_enable = SL11H_INTMASK_INSRMV;
@@ -1241,7 +1241,7 @@ sl811h_hub_control(
1241 sl811->irq_enable); 1241 sl811->irq_enable);
1242 break; 1242 break;
1243 case USB_PORT_FEAT_SUSPEND: 1243 case USB_PORT_FEAT_SUSPEND:
1244 if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))) 1244 if (!(sl811->port1 & USB_PORT_STAT_SUSPEND))
1245 break; 1245 break;
1246 1246
1247 /* 20 msec of resume/K signaling, other irqs blocked */ 1247 /* 20 msec of resume/K signaling, other irqs blocked */
@@ -1290,9 +1290,9 @@ sl811h_hub_control(
1290 goto error; 1290 goto error;
1291 switch (wValue) { 1291 switch (wValue) {
1292 case USB_PORT_FEAT_SUSPEND: 1292 case USB_PORT_FEAT_SUSPEND:
1293 if (sl811->port1 & (1 << USB_PORT_FEAT_RESET)) 1293 if (sl811->port1 & USB_PORT_STAT_RESET)
1294 goto error; 1294 goto error;
1295 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))) 1295 if (!(sl811->port1 & USB_PORT_STAT_ENABLE))
1296 goto error; 1296 goto error;
1297 1297
1298 DBG("suspend...\n"); 1298 DBG("suspend...\n");
@@ -1303,9 +1303,9 @@ sl811h_hub_control(
1303 port_power(sl811, 1); 1303 port_power(sl811, 1);
1304 break; 1304 break;
1305 case USB_PORT_FEAT_RESET: 1305 case USB_PORT_FEAT_RESET:
1306 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) 1306 if (sl811->port1 & USB_PORT_STAT_SUSPEND)
1307 goto error; 1307 goto error;
1308 if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER))) 1308 if (!(sl811->port1 & USB_PORT_STAT_POWER))
1309 break; 1309 break;
1310 1310
1311 /* 50 msec of reset/SE0 signaling, irqs blocked */ 1311 /* 50 msec of reset/SE0 signaling, irqs blocked */
@@ -1314,7 +1314,7 @@ sl811h_hub_control(
1314 sl811->irq_enable); 1314 sl811->irq_enable);
1315 sl811->ctrl1 = SL11H_CTL1MASK_SE0; 1315 sl811->ctrl1 = SL11H_CTL1MASK_SE0;
1316 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1); 1316 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1317 sl811->port1 |= (1 << USB_PORT_FEAT_RESET); 1317 sl811->port1 |= USB_PORT_STAT_RESET;
1318 mod_timer(&sl811->timer, jiffies 1318 mod_timer(&sl811->timer, jiffies
1319 + msecs_to_jiffies(50)); 1319 + msecs_to_jiffies(50));
1320 break; 1320 break;
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 228f2b070f2b..5b31bae92dbc 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -49,6 +49,7 @@
49#include <linux/list.h> 49#include <linux/list.h>
50#include <linux/interrupt.h> 50#include <linux/interrupt.h>
51#include <linux/usb.h> 51#include <linux/usb.h>
52#include <linux/usb/hcd.h>
52#include <linux/workqueue.h> 53#include <linux/workqueue.h>
53#include <linux/platform_device.h> 54#include <linux/platform_device.h>
54#include <linux/mutex.h> 55#include <linux/mutex.h>
@@ -56,7 +57,6 @@
56#include <asm/irq.h> 57#include <asm/irq.h>
57#include <asm/system.h> 58#include <asm/system.h>
58#include <asm/byteorder.h> 59#include <asm/byteorder.h>
59#include "../core/hcd.h"
60 60
61 /* FIXME ohci.h is ONLY for internal use by the OHCI driver. 61 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
62 * If you're going to try stuff like this, you need to split 62 * If you're going to try stuff like this, you need to split
@@ -1446,9 +1446,9 @@ static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1446 return; 1446 return;
1447 } else { 1447 } else {
1448 int retval; 1448 int retval;
1449 u8 address = u132->addr[endp->usb_addr].address;
1450 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1449 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1451 endp->queue_next]; 1450 endp->queue_next];
1451 address = u132->addr[endp->usb_addr].address;
1452 endp->active = 1; 1452 endp->active = 1;
1453 ring->curr_endp = endp; 1453 ring->curr_endp = endp;
1454 ring->in_use = 1; 1454 ring->in_use = 1;
@@ -3120,8 +3120,8 @@ static int __devinit u132_probe(struct platform_device *pdev)
3120 ftdi_elan_gone_away(pdev); 3120 ftdi_elan_gone_away(pdev);
3121 return -ENOMEM; 3121 return -ENOMEM;
3122 } else { 3122 } else {
3123 int retval = 0;
3124 struct u132 *u132 = hcd_to_u132(hcd); 3123 struct u132 *u132 = hcd_to_u132(hcd);
3124 retval = 0;
3125 hcd->rsrc_start = 0; 3125 hcd->rsrc_start = 0;
3126 mutex_lock(&u132_module_lock); 3126 mutex_lock(&u132_module_lock);
3127 list_add_tail(&u132->u132_list, &u132_static_list); 3127 list_add_tail(&u132->u132_list, &u132_static_list);
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 09197067fe6b..6637e52736dd 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -38,6 +38,7 @@
38#include <linux/dmapool.h> 38#include <linux/dmapool.h>
39#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
40#include <linux/usb.h> 40#include <linux/usb.h>
41#include <linux/usb/hcd.h>
41#include <linux/bitops.h> 42#include <linux/bitops.h>
42#include <linux/dmi.h> 43#include <linux/dmi.h>
43 44
@@ -46,7 +47,6 @@
46#include <asm/irq.h> 47#include <asm/irq.h>
47#include <asm/system.h> 48#include <asm/system.h>
48 49
49#include "../core/hcd.h"
50#include "uhci-hcd.h" 50#include "uhci-hcd.h"
51#include "pci-quirks.h" 51#include "pci-quirks.h"
52 52
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c
index c5305b599ca0..767af265e002 100644
--- a/drivers/usb/host/whci/debug.c
+++ b/drivers/usb/host/whci/debug.c
@@ -30,7 +30,7 @@ struct whc_dbg {
30 struct dentry *pzl_f; 30 struct dentry *pzl_f;
31}; 31};
32 32
33void qset_print(struct seq_file *s, struct whc_qset *qset) 33static void qset_print(struct seq_file *s, struct whc_qset *qset)
34{ 34{
35 static const char *qh_type[] = { 35 static const char *qh_type[] = {
36 "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", }; 36 "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", };
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index 141d049beb3e..ab5a14fbfeeb 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -443,7 +443,7 @@ static int qset_add_urb_sg(struct whc *whc, struct whc_qset *qset, struct urb *u
443 443
444 remaining = urb->transfer_buffer_length; 444 remaining = urb->transfer_buffer_length;
445 445
446 for_each_sg(urb->sg->sg, sg, urb->num_sgs, i) { 446 for_each_sg(urb->sg, sg, urb->num_sgs, i) {
447 dma_addr_t dma_addr; 447 dma_addr_t dma_addr;
448 size_t dma_remaining; 448 size_t dma_remaining;
449 dma_addr_t sp, ep; 449 dma_addr_t sp, ep;
@@ -561,7 +561,7 @@ static int qset_add_urb_sg_linearize(struct whc *whc, struct whc_qset *qset,
561 561
562 remaining = urb->transfer_buffer_length; 562 remaining = urb->transfer_buffer_length;
563 563
564 for_each_sg(urb->sg->sg, sg, urb->sg->nents, i) { 564 for_each_sg(urb->sg, sg, urb->num_sgs, i) {
565 size_t len; 565 size_t len;
566 size_t sg_remaining; 566 size_t sg_remaining;
567 void *orig; 567 void *orig;
@@ -646,7 +646,7 @@ int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb,
646 wurb->urb = urb; 646 wurb->urb = urb;
647 INIT_WORK(&wurb->dequeue_work, urb_dequeue_work); 647 INIT_WORK(&wurb->dequeue_work, urb_dequeue_work);
648 648
649 if (urb->sg) { 649 if (urb->num_sgs) {
650 ret = qset_add_urb_sg(whc, qset, urb, mem_flags); 650 ret = qset_add_urb_sg(whc, qset, urb, mem_flags);
651 if (ret == -EINVAL) { 651 if (ret == -EINVAL) {
652 qset_free_stds(qset, urb); 652 qset_free_stds(qset, urb);
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 105fa8b025bb..fcbf4abbf381 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -364,6 +364,30 @@ void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring)
364 xhci_debug_segment(xhci, seg); 364 xhci_debug_segment(xhci, seg);
365} 365}
366 366
367void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
368 unsigned int slot_id, unsigned int ep_index,
369 struct xhci_virt_ep *ep)
370{
371 int i;
372 struct xhci_ring *ring;
373
374 if (ep->ep_state & EP_HAS_STREAMS) {
375 for (i = 1; i < ep->stream_info->num_streams; i++) {
376 ring = ep->stream_info->stream_rings[i];
377 xhci_dbg(xhci, "Dev %d endpoint %d stream ID %d:\n",
378 slot_id, ep_index, i);
379 xhci_debug_segment(xhci, ring->deq_seg);
380 }
381 } else {
382 ring = ep->ring;
383 if (!ring)
384 return;
385 xhci_dbg(xhci, "Dev %d endpoint ring %d:\n",
386 slot_id, ep_index);
387 xhci_debug_segment(xhci, ring->deq_seg);
388 }
389}
390
367void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst) 391void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst)
368{ 392{
369 u32 addr = (u32) erst->erst_dma_addr; 393 u32 addr = (u32) erst->erst_dma_addr;
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 208b805b80eb..a1a7a9795536 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -64,15 +64,15 @@ static void xhci_hub_descriptor(struct xhci_hcd *xhci,
64static unsigned int xhci_port_speed(unsigned int port_status) 64static unsigned int xhci_port_speed(unsigned int port_status)
65{ 65{
66 if (DEV_LOWSPEED(port_status)) 66 if (DEV_LOWSPEED(port_status))
67 return 1 << USB_PORT_FEAT_LOWSPEED; 67 return USB_PORT_STAT_LOW_SPEED;
68 if (DEV_HIGHSPEED(port_status)) 68 if (DEV_HIGHSPEED(port_status))
69 return 1 << USB_PORT_FEAT_HIGHSPEED; 69 return USB_PORT_STAT_HIGH_SPEED;
70 if (DEV_SUPERSPEED(port_status)) 70 if (DEV_SUPERSPEED(port_status))
71 return 1 << USB_PORT_FEAT_SUPERSPEED; 71 return USB_PORT_STAT_SUPER_SPEED;
72 /* 72 /*
73 * FIXME: Yes, we should check for full speed, but the core uses that as 73 * FIXME: Yes, we should check for full speed, but the core uses that as
74 * a default in portspeed() in usb/core/hub.c (which is the only place 74 * a default in portspeed() in usb/core/hub.c (which is the only place
75 * USB_PORT_FEAT_*SPEED is used). 75 * USB_PORT_STAT_*_SPEED is used).
76 */ 76 */
77 return 0; 77 return 0;
78} 78}
@@ -205,27 +205,27 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
205 205
206 /* wPortChange bits */ 206 /* wPortChange bits */
207 if (temp & PORT_CSC) 207 if (temp & PORT_CSC)
208 status |= 1 << USB_PORT_FEAT_C_CONNECTION; 208 status |= USB_PORT_STAT_C_CONNECTION << 16;
209 if (temp & PORT_PEC) 209 if (temp & PORT_PEC)
210 status |= 1 << USB_PORT_FEAT_C_ENABLE; 210 status |= USB_PORT_STAT_C_ENABLE << 16;
211 if ((temp & PORT_OCC)) 211 if ((temp & PORT_OCC))
212 status |= 1 << USB_PORT_FEAT_C_OVER_CURRENT; 212 status |= USB_PORT_STAT_C_OVERCURRENT << 16;
213 /* 213 /*
214 * FIXME ignoring suspend, reset, and USB 2.1/3.0 specific 214 * FIXME ignoring suspend, reset, and USB 2.1/3.0 specific
215 * changes 215 * changes
216 */ 216 */
217 if (temp & PORT_CONNECT) { 217 if (temp & PORT_CONNECT) {
218 status |= 1 << USB_PORT_FEAT_CONNECTION; 218 status |= USB_PORT_STAT_CONNECTION;
219 status |= xhci_port_speed(temp); 219 status |= xhci_port_speed(temp);
220 } 220 }
221 if (temp & PORT_PE) 221 if (temp & PORT_PE)
222 status |= 1 << USB_PORT_FEAT_ENABLE; 222 status |= USB_PORT_STAT_ENABLE;
223 if (temp & PORT_OC) 223 if (temp & PORT_OC)
224 status |= 1 << USB_PORT_FEAT_OVER_CURRENT; 224 status |= USB_PORT_STAT_OVERCURRENT;
225 if (temp & PORT_RESET) 225 if (temp & PORT_RESET)
226 status |= 1 << USB_PORT_FEAT_RESET; 226 status |= USB_PORT_STAT_RESET;
227 if (temp & PORT_POWER) 227 if (temp & PORT_POWER)
228 status |= 1 << USB_PORT_FEAT_POWER; 228 status |= USB_PORT_STAT_POWER;
229 xhci_dbg(xhci, "Get port status returned 0x%x\n", status); 229 xhci_dbg(xhci, "Get port status returned 0x%x\n", status);
230 put_unaligned(cpu_to_le32(status), (__le32 *) buf); 230 put_unaligned(cpu_to_le32(status), (__le32 *) buf);
231 break; 231 break;
@@ -298,7 +298,6 @@ error:
298 * Returns 0 if the status hasn't changed, or the number of bytes in buf. 298 * Returns 0 if the status hasn't changed, or the number of bytes in buf.
299 * Ports are 0-indexed from the HCD point of view, 299 * Ports are 0-indexed from the HCD point of view,
300 * and 1-indexed from the USB core pointer of view. 300 * and 1-indexed from the USB core pointer of view.
301 * xHCI instances can have up to 127 ports, so FIXME if you see more than 15.
302 * 301 *
303 * Note that the status change bits will be cleared as soon as a port status 302 * Note that the status change bits will be cleared as soon as a port status
304 * change event is generated, so we use the saved status from that event. 303 * change event is generated, so we use the saved status from that event.
@@ -315,14 +314,9 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
315 ports = HCS_MAX_PORTS(xhci->hcs_params1); 314 ports = HCS_MAX_PORTS(xhci->hcs_params1);
316 315
317 /* Initial status is no changes */ 316 /* Initial status is no changes */
318 buf[0] = 0; 317 retval = (ports + 8) / 8;
318 memset(buf, 0, retval);
319 status = 0; 319 status = 0;
320 if (ports > 7) {
321 buf[1] = 0;
322 retval = 2;
323 } else {
324 retval = 1;
325 }
326 320
327 spin_lock_irqsave(&xhci->lock, flags); 321 spin_lock_irqsave(&xhci->lock, flags);
328 /* For each port, did anything change? If so, set that bit in buf. */ 322 /* For each port, did anything change? If so, set that bit in buf. */
@@ -331,10 +325,7 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
331 NUM_PORT_REGS*i; 325 NUM_PORT_REGS*i;
332 temp = xhci_readl(xhci, addr); 326 temp = xhci_readl(xhci, addr);
333 if (temp & (PORT_CSC | PORT_PEC | PORT_OCC)) { 327 if (temp & (PORT_CSC | PORT_PEC | PORT_OCC)) {
334 if (i < 7) 328 buf[(i + 1) / 8] |= 1 << (i + 1) % 8;
335 buf[0] |= 1 << (i + 1);
336 else
337 buf[1] |= 1 << (i - 7);
338 status = 1; 329 status = 1;
339 } 330 }
340 } 331 }
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index d64f5724bfc4..fd9e03afd91c 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -41,13 +41,13 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci, gfp_t flag
41 41
42 seg = kzalloc(sizeof *seg, flags); 42 seg = kzalloc(sizeof *seg, flags);
43 if (!seg) 43 if (!seg)
44 return 0; 44 return NULL;
45 xhci_dbg(xhci, "Allocating priv segment structure at %p\n", seg); 45 xhci_dbg(xhci, "Allocating priv segment structure at %p\n", seg);
46 46
47 seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma); 47 seg->trbs = dma_pool_alloc(xhci->segment_pool, flags, &dma);
48 if (!seg->trbs) { 48 if (!seg->trbs) {
49 kfree(seg); 49 kfree(seg);
50 return 0; 50 return NULL;
51 } 51 }
52 xhci_dbg(xhci, "// Allocating segment at %p (virtual) 0x%llx (DMA)\n", 52 xhci_dbg(xhci, "// Allocating segment at %p (virtual) 0x%llx (DMA)\n",
53 seg->trbs, (unsigned long long)dma); 53 seg->trbs, (unsigned long long)dma);
@@ -159,7 +159,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
159 ring = kzalloc(sizeof *(ring), flags); 159 ring = kzalloc(sizeof *(ring), flags);
160 xhci_dbg(xhci, "Allocating ring at %p\n", ring); 160 xhci_dbg(xhci, "Allocating ring at %p\n", ring);
161 if (!ring) 161 if (!ring)
162 return 0; 162 return NULL;
163 163
164 INIT_LIST_HEAD(&ring->td_list); 164 INIT_LIST_HEAD(&ring->td_list);
165 if (num_segs == 0) 165 if (num_segs == 0)
@@ -196,7 +196,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
196 196
197fail: 197fail:
198 xhci_ring_free(xhci, ring); 198 xhci_ring_free(xhci, ring);
199 return 0; 199 return NULL;
200} 200}
201 201
202void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci, 202void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
@@ -247,7 +247,7 @@ static void xhci_reinit_cached_ring(struct xhci_hcd *xhci,
247 247
248#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) 248#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
249 249
250struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, 250static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
251 int type, gfp_t flags) 251 int type, gfp_t flags)
252{ 252{
253 struct xhci_container_ctx *ctx = kzalloc(sizeof(*ctx), flags); 253 struct xhci_container_ctx *ctx = kzalloc(sizeof(*ctx), flags);
@@ -265,7 +265,7 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
265 return ctx; 265 return ctx;
266} 266}
267 267
268void xhci_free_container_ctx(struct xhci_hcd *xhci, 268static void xhci_free_container_ctx(struct xhci_hcd *xhci,
269 struct xhci_container_ctx *ctx) 269 struct xhci_container_ctx *ctx)
270{ 270{
271 if (!ctx) 271 if (!ctx)
@@ -304,6 +304,422 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
304 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); 304 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
305} 305}
306 306
307
308/***************** Streams structures manipulation *************************/
309
310void xhci_free_stream_ctx(struct xhci_hcd *xhci,
311 unsigned int num_stream_ctxs,
312 struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
313{
314 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
315
316 if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE)
317 pci_free_consistent(pdev,
318 sizeof(struct xhci_stream_ctx)*num_stream_ctxs,
319 stream_ctx, dma);
320 else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE)
321 return dma_pool_free(xhci->small_streams_pool,
322 stream_ctx, dma);
323 else
324 return dma_pool_free(xhci->medium_streams_pool,
325 stream_ctx, dma);
326}
327
328/*
329 * The stream context array for each endpoint with bulk streams enabled can
330 * vary in size, based on:
331 * - how many streams the endpoint supports,
332 * - the maximum primary stream array size the host controller supports,
333 * - and how many streams the device driver asks for.
334 *
335 * The stream context array must be a power of 2, and can be as small as
336 * 64 bytes or as large as 1MB.
337 */
338struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct xhci_hcd *xhci,
339 unsigned int num_stream_ctxs, dma_addr_t *dma,
340 gfp_t mem_flags)
341{
342 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
343
344 if (num_stream_ctxs > MEDIUM_STREAM_ARRAY_SIZE)
345 return pci_alloc_consistent(pdev,
346 sizeof(struct xhci_stream_ctx)*num_stream_ctxs,
347 dma);
348 else if (num_stream_ctxs <= SMALL_STREAM_ARRAY_SIZE)
349 return dma_pool_alloc(xhci->small_streams_pool,
350 mem_flags, dma);
351 else
352 return dma_pool_alloc(xhci->medium_streams_pool,
353 mem_flags, dma);
354}
355
356struct xhci_ring *xhci_dma_to_transfer_ring(
357 struct xhci_virt_ep *ep,
358 u64 address)
359{
360 if (ep->ep_state & EP_HAS_STREAMS)
361 return radix_tree_lookup(&ep->stream_info->trb_address_map,
362 address >> SEGMENT_SHIFT);
363 return ep->ring;
364}
365
366/* Only use this when you know stream_info is valid */
367#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
368static struct xhci_ring *dma_to_stream_ring(
369 struct xhci_stream_info *stream_info,
370 u64 address)
371{
372 return radix_tree_lookup(&stream_info->trb_address_map,
373 address >> SEGMENT_SHIFT);
374}
375#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */
376
377struct xhci_ring *xhci_stream_id_to_ring(
378 struct xhci_virt_device *dev,
379 unsigned int ep_index,
380 unsigned int stream_id)
381{
382 struct xhci_virt_ep *ep = &dev->eps[ep_index];
383
384 if (stream_id == 0)
385 return ep->ring;
386 if (!ep->stream_info)
387 return NULL;
388
389 if (stream_id > ep->stream_info->num_streams)
390 return NULL;
391 return ep->stream_info->stream_rings[stream_id];
392}
393
394struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
395 unsigned int slot_id, unsigned int ep_index,
396 unsigned int stream_id)
397{
398 struct xhci_virt_ep *ep;
399
400 ep = &xhci->devs[slot_id]->eps[ep_index];
401 /* Common case: no streams */
402 if (!(ep->ep_state & EP_HAS_STREAMS))
403 return ep->ring;
404
405 if (stream_id == 0) {
406 xhci_warn(xhci,
407 "WARN: Slot ID %u, ep index %u has streams, "
408 "but URB has no stream ID.\n",
409 slot_id, ep_index);
410 return NULL;
411 }
412
413 if (stream_id < ep->stream_info->num_streams)
414 return ep->stream_info->stream_rings[stream_id];
415
416 xhci_warn(xhci,
417 "WARN: Slot ID %u, ep index %u has "
418 "stream IDs 1 to %u allocated, "
419 "but stream ID %u is requested.\n",
420 slot_id, ep_index,
421 ep->stream_info->num_streams - 1,
422 stream_id);
423 return NULL;
424}
425
426/* Get the right ring for the given URB.
427 * If the endpoint supports streams, boundary check the URB's stream ID.
428 * If the endpoint doesn't support streams, return the singular endpoint ring.
429 */
430struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
431 struct urb *urb)
432{
433 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
434 xhci_get_endpoint_index(&urb->ep->desc), urb->stream_id);
435}
436
437#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
438static int xhci_test_radix_tree(struct xhci_hcd *xhci,
439 unsigned int num_streams,
440 struct xhci_stream_info *stream_info)
441{
442 u32 cur_stream;
443 struct xhci_ring *cur_ring;
444 u64 addr;
445
446 for (cur_stream = 1; cur_stream < num_streams; cur_stream++) {
447 struct xhci_ring *mapped_ring;
448 int trb_size = sizeof(union xhci_trb);
449
450 cur_ring = stream_info->stream_rings[cur_stream];
451 for (addr = cur_ring->first_seg->dma;
452 addr < cur_ring->first_seg->dma + SEGMENT_SIZE;
453 addr += trb_size) {
454 mapped_ring = dma_to_stream_ring(stream_info, addr);
455 if (cur_ring != mapped_ring) {
456 xhci_warn(xhci, "WARN: DMA address 0x%08llx "
457 "didn't map to stream ID %u; "
458 "mapped to ring %p\n",
459 (unsigned long long) addr,
460 cur_stream,
461 mapped_ring);
462 return -EINVAL;
463 }
464 }
465 /* One TRB after the end of the ring segment shouldn't return a
466 * pointer to the current ring (although it may be a part of a
467 * different ring).
468 */
469 mapped_ring = dma_to_stream_ring(stream_info, addr);
470 if (mapped_ring != cur_ring) {
471 /* One TRB before should also fail */
472 addr = cur_ring->first_seg->dma - trb_size;
473 mapped_ring = dma_to_stream_ring(stream_info, addr);
474 }
475 if (mapped_ring == cur_ring) {
476 xhci_warn(xhci, "WARN: Bad DMA address 0x%08llx "
477 "mapped to valid stream ID %u; "
478 "mapped ring = %p\n",
479 (unsigned long long) addr,
480 cur_stream,
481 mapped_ring);
482 return -EINVAL;
483 }
484 }
485 return 0;
486}
487#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */
488
489/*
490 * Change an endpoint's internal structure so it supports stream IDs. The
491 * number of requested streams includes stream 0, which cannot be used by device
492 * drivers.
493 *
494 * The number of stream contexts in the stream context array may be bigger than
495 * the number of streams the driver wants to use. This is because the number of
496 * stream context array entries must be a power of two.
497 *
498 * We need a radix tree for mapping physical addresses of TRBs to which stream
499 * ID they belong to. We need to do this because the host controller won't tell
500 * us which stream ring the TRB came from. We could store the stream ID in an
501 * event data TRB, but that doesn't help us for the cancellation case, since the
502 * endpoint may stop before it reaches that event data TRB.
503 *
504 * The radix tree maps the upper portion of the TRB DMA address to a ring
505 * segment that has the same upper portion of DMA addresses. For example, say I
506 * have segments of size 1KB, that are always 64-byte aligned. A segment may
507 * start at 0x10c91000 and end at 0x10c913f0. If I use the upper 10 bits, the
508 * key to the stream ID is 0x43244. I can use the DMA address of the TRB to
509 * pass the radix tree a key to get the right stream ID:
510 *
511 * 0x10c90fff >> 10 = 0x43243
512 * 0x10c912c0 >> 10 = 0x43244
513 * 0x10c91400 >> 10 = 0x43245
514 *
515 * Obviously, only those TRBs with DMA addresses that are within the segment
516 * will make the radix tree return the stream ID for that ring.
517 *
518 * Caveats for the radix tree:
519 *
520 * The radix tree uses an unsigned long as a key pair. On 32-bit systems, an
521 * unsigned long will be 32-bits; on a 64-bit system an unsigned long will be
522 * 64-bits. Since we only request 32-bit DMA addresses, we can use that as the
523 * key on 32-bit or 64-bit systems (it would also be fine if we asked for 64-bit
524 * PCI DMA addresses on a 64-bit system). There might be a problem on 32-bit
525 * extended systems (where the DMA address can be bigger than 32-bits),
526 * if we allow the PCI dma mask to be bigger than 32-bits. So don't do that.
527 */
528struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
529 unsigned int num_stream_ctxs,
530 unsigned int num_streams, gfp_t mem_flags)
531{
532 struct xhci_stream_info *stream_info;
533 u32 cur_stream;
534 struct xhci_ring *cur_ring;
535 unsigned long key;
536 u64 addr;
537 int ret;
538
539 xhci_dbg(xhci, "Allocating %u streams and %u "
540 "stream context array entries.\n",
541 num_streams, num_stream_ctxs);
542 if (xhci->cmd_ring_reserved_trbs == MAX_RSVD_CMD_TRBS) {
543 xhci_dbg(xhci, "Command ring has no reserved TRBs available\n");
544 return NULL;
545 }
546 xhci->cmd_ring_reserved_trbs++;
547
548 stream_info = kzalloc(sizeof(struct xhci_stream_info), mem_flags);
549 if (!stream_info)
550 goto cleanup_trbs;
551
552 stream_info->num_streams = num_streams;
553 stream_info->num_stream_ctxs = num_stream_ctxs;
554
555 /* Initialize the array of virtual pointers to stream rings. */
556 stream_info->stream_rings = kzalloc(
557 sizeof(struct xhci_ring *)*num_streams,
558 mem_flags);
559 if (!stream_info->stream_rings)
560 goto cleanup_info;
561
562 /* Initialize the array of DMA addresses for stream rings for the HW. */
563 stream_info->stream_ctx_array = xhci_alloc_stream_ctx(xhci,
564 num_stream_ctxs, &stream_info->ctx_array_dma,
565 mem_flags);
566 if (!stream_info->stream_ctx_array)
567 goto cleanup_ctx;
568 memset(stream_info->stream_ctx_array, 0,
569 sizeof(struct xhci_stream_ctx)*num_stream_ctxs);
570
571 /* Allocate everything needed to free the stream rings later */
572 stream_info->free_streams_command =
573 xhci_alloc_command(xhci, true, true, mem_flags);
574 if (!stream_info->free_streams_command)
575 goto cleanup_ctx;
576
577 INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC);
578
579 /* Allocate rings for all the streams that the driver will use,
580 * and add their segment DMA addresses to the radix tree.
581 * Stream 0 is reserved.
582 */
583 for (cur_stream = 1; cur_stream < num_streams; cur_stream++) {
584 stream_info->stream_rings[cur_stream] =
585 xhci_ring_alloc(xhci, 1, true, mem_flags);
586 cur_ring = stream_info->stream_rings[cur_stream];
587 if (!cur_ring)
588 goto cleanup_rings;
589 cur_ring->stream_id = cur_stream;
590 /* Set deq ptr, cycle bit, and stream context type */
591 addr = cur_ring->first_seg->dma |
592 SCT_FOR_CTX(SCT_PRI_TR) |
593 cur_ring->cycle_state;
594 stream_info->stream_ctx_array[cur_stream].stream_ring = addr;
595 xhci_dbg(xhci, "Setting stream %d ring ptr to 0x%08llx\n",
596 cur_stream, (unsigned long long) addr);
597
598 key = (unsigned long)
599 (cur_ring->first_seg->dma >> SEGMENT_SHIFT);
600 ret = radix_tree_insert(&stream_info->trb_address_map,
601 key, cur_ring);
602 if (ret) {
603 xhci_ring_free(xhci, cur_ring);
604 stream_info->stream_rings[cur_stream] = NULL;
605 goto cleanup_rings;
606 }
607 }
608 /* Leave the other unused stream ring pointers in the stream context
609 * array initialized to zero. This will cause the xHC to give us an
610 * error if the device asks for a stream ID we don't have setup (if it
611 * was any other way, the host controller would assume the ring is
612 * "empty" and wait forever for data to be queued to that stream ID).
613 */
614#if XHCI_DEBUG
615 /* Do a little test on the radix tree to make sure it returns the
616 * correct values.
617 */
618 if (xhci_test_radix_tree(xhci, num_streams, stream_info))
619 goto cleanup_rings;
620#endif
621
622 return stream_info;
623
624cleanup_rings:
625 for (cur_stream = 1; cur_stream < num_streams; cur_stream++) {
626 cur_ring = stream_info->stream_rings[cur_stream];
627 if (cur_ring) {
628 addr = cur_ring->first_seg->dma;
629 radix_tree_delete(&stream_info->trb_address_map,
630 addr >> SEGMENT_SHIFT);
631 xhci_ring_free(xhci, cur_ring);
632 stream_info->stream_rings[cur_stream] = NULL;
633 }
634 }
635 xhci_free_command(xhci, stream_info->free_streams_command);
636cleanup_ctx:
637 kfree(stream_info->stream_rings);
638cleanup_info:
639 kfree(stream_info);
640cleanup_trbs:
641 xhci->cmd_ring_reserved_trbs--;
642 return NULL;
643}
644/*
645 * Sets the MaxPStreams field and the Linear Stream Array field.
646 * Sets the dequeue pointer to the stream context array.
647 */
648void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
649 struct xhci_ep_ctx *ep_ctx,
650 struct xhci_stream_info *stream_info)
651{
652 u32 max_primary_streams;
653 /* MaxPStreams is the number of stream context array entries, not the
654 * number we're actually using. Must be in 2^(MaxPstreams + 1) format.
655 * fls(0) = 0, fls(0x1) = 1, fls(0x10) = 2, fls(0x100) = 3, etc.
656 */
657 max_primary_streams = fls(stream_info->num_stream_ctxs) - 2;
658 xhci_dbg(xhci, "Setting number of stream ctx array entries to %u\n",
659 1 << (max_primary_streams + 1));
660 ep_ctx->ep_info &= ~EP_MAXPSTREAMS_MASK;
661 ep_ctx->ep_info |= EP_MAXPSTREAMS(max_primary_streams);
662 ep_ctx->ep_info |= EP_HAS_LSA;
663 ep_ctx->deq = stream_info->ctx_array_dma;
664}
665
666/*
667 * Sets the MaxPStreams field and the Linear Stream Array field to 0.
668 * Reinstalls the "normal" endpoint ring (at its previous dequeue mark,
669 * not at the beginning of the ring).
670 */
671void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
672 struct xhci_ep_ctx *ep_ctx,
673 struct xhci_virt_ep *ep)
674{
675 dma_addr_t addr;
676 ep_ctx->ep_info &= ~EP_MAXPSTREAMS_MASK;
677 ep_ctx->ep_info &= ~EP_HAS_LSA;
678 addr = xhci_trb_virt_to_dma(ep->ring->deq_seg, ep->ring->dequeue);
679 ep_ctx->deq = addr | ep->ring->cycle_state;
680}
681
682/* Frees all stream contexts associated with the endpoint,
683 *
684 * Caller should fix the endpoint context streams fields.
685 */
686void xhci_free_stream_info(struct xhci_hcd *xhci,
687 struct xhci_stream_info *stream_info)
688{
689 int cur_stream;
690 struct xhci_ring *cur_ring;
691 dma_addr_t addr;
692
693 if (!stream_info)
694 return;
695
696 for (cur_stream = 1; cur_stream < stream_info->num_streams;
697 cur_stream++) {
698 cur_ring = stream_info->stream_rings[cur_stream];
699 if (cur_ring) {
700 addr = cur_ring->first_seg->dma;
701 radix_tree_delete(&stream_info->trb_address_map,
702 addr >> SEGMENT_SHIFT);
703 xhci_ring_free(xhci, cur_ring);
704 stream_info->stream_rings[cur_stream] = NULL;
705 }
706 }
707 xhci_free_command(xhci, stream_info->free_streams_command);
708 xhci->cmd_ring_reserved_trbs--;
709 if (stream_info->stream_ctx_array)
710 xhci_free_stream_ctx(xhci,
711 stream_info->num_stream_ctxs,
712 stream_info->stream_ctx_array,
713 stream_info->ctx_array_dma);
714
715 if (stream_info)
716 kfree(stream_info->stream_rings);
717 kfree(stream_info);
718}
719
720
721/***************** Device context manipulation *************************/
722
307static void xhci_init_endpoint_timer(struct xhci_hcd *xhci, 723static void xhci_init_endpoint_timer(struct xhci_hcd *xhci,
308 struct xhci_virt_ep *ep) 724 struct xhci_virt_ep *ep)
309{ 725{
@@ -328,9 +744,13 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
328 if (!dev) 744 if (!dev)
329 return; 745 return;
330 746
331 for (i = 0; i < 31; ++i) 747 for (i = 0; i < 31; ++i) {
332 if (dev->eps[i].ring) 748 if (dev->eps[i].ring)
333 xhci_ring_free(xhci, dev->eps[i].ring); 749 xhci_ring_free(xhci, dev->eps[i].ring);
750 if (dev->eps[i].stream_info)
751 xhci_free_stream_info(xhci,
752 dev->eps[i].stream_info);
753 }
334 754
335 if (dev->ring_cache) { 755 if (dev->ring_cache) {
336 for (i = 0; i < dev->num_rings_cached; i++) 756 for (i = 0; i < dev->num_rings_cached; i++)
@@ -344,7 +764,7 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
344 xhci_free_container_ctx(xhci, dev->out_ctx); 764 xhci_free_container_ctx(xhci, dev->out_ctx);
345 765
346 kfree(xhci->devs[slot_id]); 766 kfree(xhci->devs[slot_id]);
347 xhci->devs[slot_id] = 0; 767 xhci->devs[slot_id] = NULL;
348} 768}
349 769
350int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, 770int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
@@ -590,9 +1010,9 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
590static inline u32 xhci_get_endpoint_mult(struct usb_device *udev, 1010static inline u32 xhci_get_endpoint_mult(struct usb_device *udev,
591 struct usb_host_endpoint *ep) 1011 struct usb_host_endpoint *ep)
592{ 1012{
593 if (udev->speed != USB_SPEED_SUPER || !ep->ss_ep_comp) 1013 if (udev->speed != USB_SPEED_SUPER)
594 return 0; 1014 return 0;
595 return ep->ss_ep_comp->desc.bmAttributes; 1015 return ep->ss_ep_comp.bmAttributes;
596} 1016}
597 1017
598static inline u32 xhci_get_endpoint_type(struct usb_device *udev, 1018static inline u32 xhci_get_endpoint_type(struct usb_device *udev,
@@ -641,13 +1061,8 @@ static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
641 usb_endpoint_xfer_bulk(&ep->desc)) 1061 usb_endpoint_xfer_bulk(&ep->desc))
642 return 0; 1062 return 0;
643 1063
644 if (udev->speed == USB_SPEED_SUPER) { 1064 if (udev->speed == USB_SPEED_SUPER)
645 if (ep->ss_ep_comp) 1065 return ep->ss_ep_comp.wBytesPerInterval;
646 return ep->ss_ep_comp->desc.wBytesPerInterval;
647 xhci_warn(xhci, "WARN no SS endpoint companion descriptor.\n");
648 /* Assume no bursts, no multiple opportunities to send. */
649 return ep->desc.wMaxPacketSize;
650 }
651 1066
652 max_packet = ep->desc.wMaxPacketSize & 0x3ff; 1067 max_packet = ep->desc.wMaxPacketSize & 0x3ff;
653 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11; 1068 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11;
@@ -655,6 +1070,9 @@ static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
655 return max_packet * (max_burst + 1); 1070 return max_packet * (max_burst + 1);
656} 1071}
657 1072
1073/* Set up an endpoint with one ring segment. Do not allocate stream rings.
1074 * Drivers will have to call usb_alloc_streams() to do that.
1075 */
658int xhci_endpoint_init(struct xhci_hcd *xhci, 1076int xhci_endpoint_init(struct xhci_hcd *xhci,
659 struct xhci_virt_device *virt_dev, 1077 struct xhci_virt_device *virt_dev,
660 struct usb_device *udev, 1078 struct usb_device *udev,
@@ -708,12 +1126,9 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
708 max_packet = ep->desc.wMaxPacketSize; 1126 max_packet = ep->desc.wMaxPacketSize;
709 ep_ctx->ep_info2 |= MAX_PACKET(max_packet); 1127 ep_ctx->ep_info2 |= MAX_PACKET(max_packet);
710 /* dig out max burst from ep companion desc */ 1128 /* dig out max burst from ep companion desc */
711 if (!ep->ss_ep_comp) { 1129 max_packet = ep->ss_ep_comp.bMaxBurst;
712 xhci_warn(xhci, "WARN no SS endpoint companion descriptor.\n"); 1130 if (!max_packet)
713 max_packet = 0; 1131 xhci_warn(xhci, "WARN no SS endpoint bMaxBurst\n");
714 } else {
715 max_packet = ep->ss_ep_comp->desc.bMaxBurst;
716 }
717 ep_ctx->ep_info2 |= MAX_BURST(max_packet); 1132 ep_ctx->ep_info2 |= MAX_BURST(max_packet);
718 break; 1133 break;
719 case USB_SPEED_HIGH: 1134 case USB_SPEED_HIGH:
@@ -1003,6 +1418,16 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1003 xhci->device_pool = NULL; 1418 xhci->device_pool = NULL;
1004 xhci_dbg(xhci, "Freed device context pool\n"); 1419 xhci_dbg(xhci, "Freed device context pool\n");
1005 1420
1421 if (xhci->small_streams_pool)
1422 dma_pool_destroy(xhci->small_streams_pool);
1423 xhci->small_streams_pool = NULL;
1424 xhci_dbg(xhci, "Freed small stream array pool\n");
1425
1426 if (xhci->medium_streams_pool)
1427 dma_pool_destroy(xhci->medium_streams_pool);
1428 xhci->medium_streams_pool = NULL;
1429 xhci_dbg(xhci, "Freed medium stream array pool\n");
1430
1006 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr); 1431 xhci_write_64(xhci, 0, &xhci->op_regs->dcbaa_ptr);
1007 if (xhci->dcbaa) 1432 if (xhci->dcbaa)
1008 pci_free_consistent(pdev, sizeof(*xhci->dcbaa), 1433 pci_free_consistent(pdev, sizeof(*xhci->dcbaa),
@@ -1239,6 +1664,22 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1239 if (!xhci->segment_pool || !xhci->device_pool) 1664 if (!xhci->segment_pool || !xhci->device_pool)
1240 goto fail; 1665 goto fail;
1241 1666
1667 /* Linear stream context arrays don't have any boundary restrictions,
1668 * and only need to be 16-byte aligned.
1669 */
1670 xhci->small_streams_pool =
1671 dma_pool_create("xHCI 256 byte stream ctx arrays",
1672 dev, SMALL_STREAM_ARRAY_SIZE, 16, 0);
1673 xhci->medium_streams_pool =
1674 dma_pool_create("xHCI 1KB stream ctx arrays",
1675 dev, MEDIUM_STREAM_ARRAY_SIZE, 16, 0);
1676 /* Any stream context array bigger than MEDIUM_STREAM_ARRAY_SIZE
1677 * will be allocated with pci_alloc_consistent()
1678 */
1679
1680 if (!xhci->small_streams_pool || !xhci->medium_streams_pool)
1681 goto fail;
1682
1242 /* Set up the command ring to have one segments for now. */ 1683 /* Set up the command ring to have one segments for now. */
1243 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, true, flags); 1684 xhci->cmd_ring = xhci_ring_alloc(xhci, 1, true, flags);
1244 if (!xhci->cmd_ring) 1685 if (!xhci->cmd_ring)
@@ -1330,7 +1771,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
1330 */ 1771 */
1331 init_completion(&xhci->addr_dev); 1772 init_completion(&xhci->addr_dev);
1332 for (i = 0; i < MAX_HC_SLOTS; ++i) 1773 for (i = 0; i < MAX_HC_SLOTS; ++i)
1333 xhci->devs[i] = 0; 1774 xhci->devs[i] = NULL;
1334 1775
1335 if (scratchpad_alloc(xhci, flags)) 1776 if (scratchpad_alloc(xhci, flags))
1336 goto fail; 1777 goto fail;
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 417d37aff8d7..edffd81fc253 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -54,7 +54,7 @@ static int xhci_pci_setup(struct usb_hcd *hcd)
54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller); 54 struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
55 int retval; 55 int retval;
56 56
57 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 1; 57 hcd->self.sg_tablesize = TRBS_PER_SEGMENT - 2;
58 58
59 xhci->cap_regs = hcd->regs; 59 xhci->cap_regs = hcd->regs;
60 xhci->op_regs = hcd->regs + 60 xhci->op_regs = hcd->regs +
@@ -132,6 +132,8 @@ static const struct hc_driver xhci_pci_hc_driver = {
132 .urb_dequeue = xhci_urb_dequeue, 132 .urb_dequeue = xhci_urb_dequeue,
133 .alloc_dev = xhci_alloc_dev, 133 .alloc_dev = xhci_alloc_dev,
134 .free_dev = xhci_free_dev, 134 .free_dev = xhci_free_dev,
135 .alloc_streams = xhci_alloc_streams,
136 .free_streams = xhci_free_streams,
135 .add_endpoint = xhci_add_endpoint, 137 .add_endpoint = xhci_add_endpoint,
136 .drop_endpoint = xhci_drop_endpoint, 138 .drop_endpoint = xhci_drop_endpoint,
137 .endpoint_reset = xhci_endpoint_reset, 139 .endpoint_reset = xhci_endpoint_reset,
@@ -175,12 +177,12 @@ static struct pci_driver xhci_pci_driver = {
175 .shutdown = usb_hcd_pci_shutdown, 177 .shutdown = usb_hcd_pci_shutdown,
176}; 178};
177 179
178int xhci_register_pci() 180int xhci_register_pci(void)
179{ 181{
180 return pci_register_driver(&xhci_pci_driver); 182 return pci_register_driver(&xhci_pci_driver);
181} 183}
182 184
183void xhci_unregister_pci() 185void xhci_unregister_pci(void)
184{ 186{
185 pci_unregister_driver(&xhci_pci_driver); 187 pci_unregister_driver(&xhci_pci_driver);
186} 188}
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 85d7e8f2085e..36c858e5b529 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -112,6 +112,12 @@ static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring,
112 return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK); 112 return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK);
113} 113}
114 114
115static inline int enqueue_is_link_trb(struct xhci_ring *ring)
116{
117 struct xhci_link_trb *link = &ring->enqueue->link;
118 return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK));
119}
120
115/* Updates trb to point to the next TRB in the ring, and updates seg if the next 121/* Updates trb to point to the next TRB in the ring, and updates seg if the next
116 * TRB is in a new segment. This does not skip over link TRBs, and it does not 122 * TRB is in a new segment. This does not skip over link TRBs, and it does not
117 * effect the ring dequeue or enqueue pointers. 123 * effect the ring dequeue or enqueue pointers.
@@ -193,20 +199,15 @@ static void inc_enq(struct xhci_hcd *xhci, struct xhci_ring *ring, bool consumer
193 while (last_trb(xhci, ring, ring->enq_seg, next)) { 199 while (last_trb(xhci, ring, ring->enq_seg, next)) {
194 if (!consumer) { 200 if (!consumer) {
195 if (ring != xhci->event_ring) { 201 if (ring != xhci->event_ring) {
196 /* If we're not dealing with 0.95 hardware, 202 if (chain) {
197 * carry over the chain bit of the previous TRB 203 next->link.control |= TRB_CHAIN;
198 * (which may mean the chain bit is cleared). 204
199 */ 205 /* Give this link TRB to the hardware */
200 if (!xhci_link_trb_quirk(xhci)) { 206 wmb();
201 next->link.control &= ~TRB_CHAIN; 207 next->link.control ^= TRB_CYCLE;
202 next->link.control |= chain; 208 } else {
209 break;
203 } 210 }
204 /* Give this link TRB to the hardware */
205 wmb();
206 if (next->link.control & TRB_CYCLE)
207 next->link.control &= (u32) ~TRB_CYCLE;
208 else
209 next->link.control |= (u32) TRB_CYCLE;
210 } 211 }
211 /* Toggle the cycle bit after the last ring segment. */ 212 /* Toggle the cycle bit after the last ring segment. */
212 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) { 213 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
@@ -242,10 +243,34 @@ static int room_on_ring(struct xhci_hcd *xhci, struct xhci_ring *ring,
242 int i; 243 int i;
243 union xhci_trb *enq = ring->enqueue; 244 union xhci_trb *enq = ring->enqueue;
244 struct xhci_segment *enq_seg = ring->enq_seg; 245 struct xhci_segment *enq_seg = ring->enq_seg;
246 struct xhci_segment *cur_seg;
247 unsigned int left_on_ring;
248
249 /* If we are currently pointing to a link TRB, advance the
250 * enqueue pointer before checking for space */
251 while (last_trb(xhci, ring, enq_seg, enq)) {
252 enq_seg = enq_seg->next;
253 enq = enq_seg->trbs;
254 }
245 255
246 /* Check if ring is empty */ 256 /* Check if ring is empty */
247 if (enq == ring->dequeue) 257 if (enq == ring->dequeue) {
258 /* Can't use link trbs */
259 left_on_ring = TRBS_PER_SEGMENT - 1;
260 for (cur_seg = enq_seg->next; cur_seg != enq_seg;
261 cur_seg = cur_seg->next)
262 left_on_ring += TRBS_PER_SEGMENT - 1;
263
264 /* Always need one TRB free in the ring. */
265 left_on_ring -= 1;
266 if (num_trbs > left_on_ring) {
267 xhci_warn(xhci, "Not enough room on ring; "
268 "need %u TRBs, %u TRBs left\n",
269 num_trbs, left_on_ring);
270 return 0;
271 }
248 return 1; 272 return 1;
273 }
249 /* Make sure there's an extra empty TRB available */ 274 /* Make sure there's an extra empty TRB available */
250 for (i = 0; i <= num_trbs; ++i) { 275 for (i = 0; i <= num_trbs; ++i) {
251 if (enq == ring->dequeue) 276 if (enq == ring->dequeue)
@@ -295,7 +320,8 @@ void xhci_ring_cmd_db(struct xhci_hcd *xhci)
295 320
296static void ring_ep_doorbell(struct xhci_hcd *xhci, 321static void ring_ep_doorbell(struct xhci_hcd *xhci,
297 unsigned int slot_id, 322 unsigned int slot_id,
298 unsigned int ep_index) 323 unsigned int ep_index,
324 unsigned int stream_id)
299{ 325{
300 struct xhci_virt_ep *ep; 326 struct xhci_virt_ep *ep;
301 unsigned int ep_state; 327 unsigned int ep_state;
@@ -306,11 +332,16 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
306 ep_state = ep->ep_state; 332 ep_state = ep->ep_state;
307 /* Don't ring the doorbell for this endpoint if there are pending 333 /* Don't ring the doorbell for this endpoint if there are pending
308 * cancellations because the we don't want to interrupt processing. 334 * cancellations because the we don't want to interrupt processing.
335 * We don't want to restart any stream rings if there's a set dequeue
336 * pointer command pending because the device can choose to start any
337 * stream once the endpoint is on the HW schedule.
338 * FIXME - check all the stream rings for pending cancellations.
309 */ 339 */
310 if (!(ep_state & EP_HALT_PENDING) && !(ep_state & SET_DEQ_PENDING) 340 if (!(ep_state & EP_HALT_PENDING) && !(ep_state & SET_DEQ_PENDING)
311 && !(ep_state & EP_HALTED)) { 341 && !(ep_state & EP_HALTED)) {
312 field = xhci_readl(xhci, db_addr) & DB_MASK; 342 field = xhci_readl(xhci, db_addr) & DB_MASK;
313 xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); 343 field |= EPI_TO_DB(ep_index) | STREAM_ID_TO_DB(stream_id);
344 xhci_writel(xhci, field, db_addr);
314 /* Flush PCI posted writes - FIXME Matthew Wilcox says this 345 /* Flush PCI posted writes - FIXME Matthew Wilcox says this
315 * isn't time-critical and we shouldn't make the CPU wait for 346 * isn't time-critical and we shouldn't make the CPU wait for
316 * the flush. 347 * the flush.
@@ -319,6 +350,31 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
319 } 350 }
320} 351}
321 352
353/* Ring the doorbell for any rings with pending URBs */
354static void ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
355 unsigned int slot_id,
356 unsigned int ep_index)
357{
358 unsigned int stream_id;
359 struct xhci_virt_ep *ep;
360
361 ep = &xhci->devs[slot_id]->eps[ep_index];
362
363 /* A ring has pending URBs if its TD list is not empty */
364 if (!(ep->ep_state & EP_HAS_STREAMS)) {
365 if (!(list_empty(&ep->ring->td_list)))
366 ring_ep_doorbell(xhci, slot_id, ep_index, 0);
367 return;
368 }
369
370 for (stream_id = 1; stream_id < ep->stream_info->num_streams;
371 stream_id++) {
372 struct xhci_stream_info *stream_info = ep->stream_info;
373 if (!list_empty(&stream_info->stream_rings[stream_id]->td_list))
374 ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
375 }
376}
377
322/* 378/*
323 * Find the segment that trb is in. Start searching in start_seg. 379 * Find the segment that trb is in. Start searching in start_seg.
324 * If we must move past a segment that has a link TRB with a toggle cycle state 380 * If we must move past a segment that has a link TRB with a toggle cycle state
@@ -334,13 +390,14 @@ static struct xhci_segment *find_trb_seg(
334 while (cur_seg->trbs > trb || 390 while (cur_seg->trbs > trb ||
335 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) { 391 &cur_seg->trbs[TRBS_PER_SEGMENT - 1] < trb) {
336 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic; 392 generic_trb = &cur_seg->trbs[TRBS_PER_SEGMENT - 1].generic;
337 if (TRB_TYPE(generic_trb->field[3]) == TRB_LINK && 393 if ((generic_trb->field[3] & TRB_TYPE_BITMASK) ==
394 TRB_TYPE(TRB_LINK) &&
338 (generic_trb->field[3] & LINK_TOGGLE)) 395 (generic_trb->field[3] & LINK_TOGGLE))
339 *cycle_state = ~(*cycle_state) & 0x1; 396 *cycle_state = ~(*cycle_state) & 0x1;
340 cur_seg = cur_seg->next; 397 cur_seg = cur_seg->next;
341 if (cur_seg == start_seg) 398 if (cur_seg == start_seg)
342 /* Looped over the entire list. Oops! */ 399 /* Looped over the entire list. Oops! */
343 return 0; 400 return NULL;
344 } 401 }
345 return cur_seg; 402 return cur_seg;
346} 403}
@@ -361,14 +418,23 @@ static struct xhci_segment *find_trb_seg(
361 */ 418 */
362void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, 419void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
363 unsigned int slot_id, unsigned int ep_index, 420 unsigned int slot_id, unsigned int ep_index,
364 struct xhci_td *cur_td, struct xhci_dequeue_state *state) 421 unsigned int stream_id, struct xhci_td *cur_td,
422 struct xhci_dequeue_state *state)
365{ 423{
366 struct xhci_virt_device *dev = xhci->devs[slot_id]; 424 struct xhci_virt_device *dev = xhci->devs[slot_id];
367 struct xhci_ring *ep_ring = dev->eps[ep_index].ring; 425 struct xhci_ring *ep_ring;
368 struct xhci_generic_trb *trb; 426 struct xhci_generic_trb *trb;
369 struct xhci_ep_ctx *ep_ctx; 427 struct xhci_ep_ctx *ep_ctx;
370 dma_addr_t addr; 428 dma_addr_t addr;
371 429
430 ep_ring = xhci_triad_to_transfer_ring(xhci, slot_id,
431 ep_index, stream_id);
432 if (!ep_ring) {
433 xhci_warn(xhci, "WARN can't find new dequeue state "
434 "for invalid stream ID %u.\n",
435 stream_id);
436 return;
437 }
372 state->new_cycle_state = 0; 438 state->new_cycle_state = 0;
373 xhci_dbg(xhci, "Finding segment containing stopped TRB.\n"); 439 xhci_dbg(xhci, "Finding segment containing stopped TRB.\n");
374 state->new_deq_seg = find_trb_seg(cur_td->start_seg, 440 state->new_deq_seg = find_trb_seg(cur_td->start_seg,
@@ -390,7 +456,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
390 BUG(); 456 BUG();
391 457
392 trb = &state->new_deq_ptr->generic; 458 trb = &state->new_deq_ptr->generic;
393 if (TRB_TYPE(trb->field[3]) == TRB_LINK && 459 if ((trb->field[3] & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK) &&
394 (trb->field[3] & LINK_TOGGLE)) 460 (trb->field[3] & LINK_TOGGLE))
395 state->new_cycle_state = ~(state->new_cycle_state) & 0x1; 461 state->new_cycle_state = ~(state->new_cycle_state) & 0x1;
396 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr); 462 next_trb(xhci, ep_ring, &state->new_deq_seg, &state->new_deq_ptr);
@@ -448,11 +514,13 @@ static void td_to_noop(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
448} 514}
449 515
450static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, 516static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
451 unsigned int ep_index, struct xhci_segment *deq_seg, 517 unsigned int ep_index, unsigned int stream_id,
518 struct xhci_segment *deq_seg,
452 union xhci_trb *deq_ptr, u32 cycle_state); 519 union xhci_trb *deq_ptr, u32 cycle_state);
453 520
454void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, 521void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
455 unsigned int slot_id, unsigned int ep_index, 522 unsigned int slot_id, unsigned int ep_index,
523 unsigned int stream_id,
456 struct xhci_dequeue_state *deq_state) 524 struct xhci_dequeue_state *deq_state)
457{ 525{
458 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; 526 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
@@ -464,7 +532,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
464 deq_state->new_deq_ptr, 532 deq_state->new_deq_ptr,
465 (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr), 533 (unsigned long long)xhci_trb_virt_to_dma(deq_state->new_deq_seg, deq_state->new_deq_ptr),
466 deq_state->new_cycle_state); 534 deq_state->new_cycle_state);
467 queue_set_tr_deq(xhci, slot_id, ep_index, 535 queue_set_tr_deq(xhci, slot_id, ep_index, stream_id,
468 deq_state->new_deq_seg, 536 deq_state->new_deq_seg,
469 deq_state->new_deq_ptr, 537 deq_state->new_deq_ptr,
470 (u32) deq_state->new_cycle_state); 538 (u32) deq_state->new_cycle_state);
@@ -523,7 +591,7 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
523 struct xhci_ring *ep_ring; 591 struct xhci_ring *ep_ring;
524 struct xhci_virt_ep *ep; 592 struct xhci_virt_ep *ep;
525 struct list_head *entry; 593 struct list_head *entry;
526 struct xhci_td *cur_td = 0; 594 struct xhci_td *cur_td = NULL;
527 struct xhci_td *last_unlinked_td; 595 struct xhci_td *last_unlinked_td;
528 596
529 struct xhci_dequeue_state deq_state; 597 struct xhci_dequeue_state deq_state;
@@ -532,11 +600,10 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
532 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 600 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
533 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 601 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
534 ep = &xhci->devs[slot_id]->eps[ep_index]; 602 ep = &xhci->devs[slot_id]->eps[ep_index];
535 ep_ring = ep->ring;
536 603
537 if (list_empty(&ep->cancelled_td_list)) { 604 if (list_empty(&ep->cancelled_td_list)) {
538 xhci_stop_watchdog_timer_in_irq(xhci, ep); 605 xhci_stop_watchdog_timer_in_irq(xhci, ep);
539 ring_ep_doorbell(xhci, slot_id, ep_index); 606 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
540 return; 607 return;
541 } 608 }
542 609
@@ -550,15 +617,36 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
550 xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n", 617 xhci_dbg(xhci, "Cancelling TD starting at %p, 0x%llx (dma).\n",
551 cur_td->first_trb, 618 cur_td->first_trb,
552 (unsigned long long)xhci_trb_virt_to_dma(cur_td->start_seg, cur_td->first_trb)); 619 (unsigned long long)xhci_trb_virt_to_dma(cur_td->start_seg, cur_td->first_trb));
620 ep_ring = xhci_urb_to_transfer_ring(xhci, cur_td->urb);
621 if (!ep_ring) {
622 /* This shouldn't happen unless a driver is mucking
623 * with the stream ID after submission. This will
624 * leave the TD on the hardware ring, and the hardware
625 * will try to execute it, and may access a buffer
626 * that has already been freed. In the best case, the
627 * hardware will execute it, and the event handler will
628 * ignore the completion event for that TD, since it was
629 * removed from the td_list for that endpoint. In
630 * short, don't muck with the stream ID after
631 * submission.
632 */
633 xhci_warn(xhci, "WARN Cancelled URB %p "
634 "has invalid stream ID %u.\n",
635 cur_td->urb,
636 cur_td->urb->stream_id);
637 goto remove_finished_td;
638 }
553 /* 639 /*
554 * If we stopped on the TD we need to cancel, then we have to 640 * If we stopped on the TD we need to cancel, then we have to
555 * move the xHC endpoint ring dequeue pointer past this TD. 641 * move the xHC endpoint ring dequeue pointer past this TD.
556 */ 642 */
557 if (cur_td == ep->stopped_td) 643 if (cur_td == ep->stopped_td)
558 xhci_find_new_dequeue_state(xhci, slot_id, ep_index, cur_td, 644 xhci_find_new_dequeue_state(xhci, slot_id, ep_index,
559 &deq_state); 645 cur_td->urb->stream_id,
646 cur_td, &deq_state);
560 else 647 else
561 td_to_noop(xhci, ep_ring, cur_td); 648 td_to_noop(xhci, ep_ring, cur_td);
649remove_finished_td:
562 /* 650 /*
563 * The event handler won't see a completion for this TD anymore, 651 * The event handler won't see a completion for this TD anymore,
564 * so remove it from the endpoint ring's TD list. Keep it in 652 * so remove it from the endpoint ring's TD list. Keep it in
@@ -572,12 +660,16 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
572 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ 660 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */
573 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { 661 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
574 xhci_queue_new_dequeue_state(xhci, 662 xhci_queue_new_dequeue_state(xhci,
575 slot_id, ep_index, &deq_state); 663 slot_id, ep_index,
664 ep->stopped_td->urb->stream_id,
665 &deq_state);
576 xhci_ring_cmd_db(xhci); 666 xhci_ring_cmd_db(xhci);
577 } else { 667 } else {
578 /* Otherwise just ring the doorbell to restart the ring */ 668 /* Otherwise ring the doorbell(s) to restart queued transfers */
579 ring_ep_doorbell(xhci, slot_id, ep_index); 669 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
580 } 670 }
671 ep->stopped_td = NULL;
672 ep->stopped_trb = NULL;
581 673
582 /* 674 /*
583 * Drop the lock and complete the URBs in the cancelled TD list. 675 * Drop the lock and complete the URBs in the cancelled TD list.
@@ -734,6 +826,7 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
734{ 826{
735 unsigned int slot_id; 827 unsigned int slot_id;
736 unsigned int ep_index; 828 unsigned int ep_index;
829 unsigned int stream_id;
737 struct xhci_ring *ep_ring; 830 struct xhci_ring *ep_ring;
738 struct xhci_virt_device *dev; 831 struct xhci_virt_device *dev;
739 struct xhci_ep_ctx *ep_ctx; 832 struct xhci_ep_ctx *ep_ctx;
@@ -741,8 +834,19 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
741 834
742 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 835 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
743 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 836 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
837 stream_id = TRB_TO_STREAM_ID(trb->generic.field[2]);
744 dev = xhci->devs[slot_id]; 838 dev = xhci->devs[slot_id];
745 ep_ring = dev->eps[ep_index].ring; 839
840 ep_ring = xhci_stream_id_to_ring(dev, ep_index, stream_id);
841 if (!ep_ring) {
842 xhci_warn(xhci, "WARN Set TR deq ptr command for "
843 "freed stream ID %u\n",
844 stream_id);
845 /* XXX: Harmless??? */
846 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
847 return;
848 }
849
746 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index); 850 ep_ctx = xhci_get_ep_ctx(xhci, dev->out_ctx, ep_index);
747 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx); 851 slot_ctx = xhci_get_slot_ctx(xhci, dev->out_ctx);
748 852
@@ -787,7 +891,8 @@ static void handle_set_deq_completion(struct xhci_hcd *xhci,
787 } 891 }
788 892
789 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING; 893 dev->eps[ep_index].ep_state &= ~SET_DEQ_PENDING;
790 ring_ep_doorbell(xhci, slot_id, ep_index); 894 /* Restart any rings with pending URBs */
895 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
791} 896}
792 897
793static void handle_reset_ep_completion(struct xhci_hcd *xhci, 898static void handle_reset_ep_completion(struct xhci_hcd *xhci,
@@ -796,11 +901,9 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
796{ 901{
797 int slot_id; 902 int slot_id;
798 unsigned int ep_index; 903 unsigned int ep_index;
799 struct xhci_ring *ep_ring;
800 904
801 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 905 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
802 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]); 906 ep_index = TRB_TO_EP_INDEX(trb->generic.field[3]);
803 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
804 /* This command will only fail if the endpoint wasn't halted, 907 /* This command will only fail if the endpoint wasn't halted,
805 * but we don't care. 908 * but we don't care.
806 */ 909 */
@@ -818,9 +921,9 @@ static void handle_reset_ep_completion(struct xhci_hcd *xhci,
818 false); 921 false);
819 xhci_ring_cmd_db(xhci); 922 xhci_ring_cmd_db(xhci);
820 } else { 923 } else {
821 /* Clear our internal halted state and restart the ring */ 924 /* Clear our internal halted state and restart the ring(s) */
822 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED; 925 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED;
823 ring_ep_doorbell(xhci, slot_id, ep_index); 926 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
824 } 927 }
825} 928}
826 929
@@ -897,16 +1000,19 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
897 * Configure endpoint commands can come from the USB core 1000 * Configure endpoint commands can come from the USB core
898 * configuration or alt setting changes, or because the HW 1001 * configuration or alt setting changes, or because the HW
899 * needed an extra configure endpoint command after a reset 1002 * needed an extra configure endpoint command after a reset
900 * endpoint command. In the latter case, the xHCI driver is 1003 * endpoint command or streams were being configured.
901 * not waiting on the configure endpoint command. 1004 * If the command was for a halted endpoint, the xHCI driver
1005 * is not waiting on the configure endpoint command.
902 */ 1006 */
903 ctrl_ctx = xhci_get_input_control_ctx(xhci, 1007 ctrl_ctx = xhci_get_input_control_ctx(xhci,
904 virt_dev->in_ctx); 1008 virt_dev->in_ctx);
905 /* Input ctx add_flags are the endpoint index plus one */ 1009 /* Input ctx add_flags are the endpoint index plus one */
906 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1; 1010 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1;
907 /* A usb_set_interface() call directly after clearing a halted 1011 /* A usb_set_interface() call directly after clearing a halted
908 * condition may race on this quirky hardware. 1012 * condition may race on this quirky hardware. Not worth
909 * Not worth worrying about, since this is prototype hardware. 1013 * worrying about, since this is prototype hardware. Not sure
1014 * if this will work for streams, but streams support was
1015 * untested on this prototype.
910 */ 1016 */
911 if (xhci->quirks & XHCI_RESET_EP_QUIRK && 1017 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
912 ep_index != (unsigned int) -1 && 1018 ep_index != (unsigned int) -1 &&
@@ -919,10 +1025,10 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
919 xhci_dbg(xhci, "Completed config ep cmd - " 1025 xhci_dbg(xhci, "Completed config ep cmd - "
920 "last ep index = %d, state = %d\n", 1026 "last ep index = %d, state = %d\n",
921 ep_index, ep_state); 1027 ep_index, ep_state);
922 /* Clear our internal halted state and restart ring */ 1028 /* Clear internal halted state and restart ring(s) */
923 xhci->devs[slot_id]->eps[ep_index].ep_state &= 1029 xhci->devs[slot_id]->eps[ep_index].ep_state &=
924 ~EP_HALTED; 1030 ~EP_HALTED;
925 ring_ep_doorbell(xhci, slot_id, ep_index); 1031 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
926 break; 1032 break;
927 } 1033 }
928bandwidth_change: 1034bandwidth_change:
@@ -1018,7 +1124,7 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1018 1124
1019 do { 1125 do {
1020 if (start_dma == 0) 1126 if (start_dma == 0)
1021 return 0; 1127 return NULL;
1022 /* We may get an event for a Link TRB in the middle of a TD */ 1128 /* We may get an event for a Link TRB in the middle of a TD */
1023 end_seg_dma = xhci_trb_virt_to_dma(cur_seg, 1129 end_seg_dma = xhci_trb_virt_to_dma(cur_seg,
1024 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]); 1130 &cur_seg->trbs[TRBS_PER_SEGMENT - 1]);
@@ -1040,7 +1146,7 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1040 suspect_dma <= end_trb_dma)) 1146 suspect_dma <= end_trb_dma))
1041 return cur_seg; 1147 return cur_seg;
1042 } 1148 }
1043 return 0; 1149 return NULL;
1044 } else { 1150 } else {
1045 /* Might still be somewhere in this segment */ 1151 /* Might still be somewhere in this segment */
1046 if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma) 1152 if (suspect_dma >= start_dma && suspect_dma <= end_seg_dma)
@@ -1050,19 +1156,27 @@ struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1050 start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]); 1156 start_dma = xhci_trb_virt_to_dma(cur_seg, &cur_seg->trbs[0]);
1051 } while (cur_seg != start_seg); 1157 } while (cur_seg != start_seg);
1052 1158
1053 return 0; 1159 return NULL;
1054} 1160}
1055 1161
1056static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci, 1162static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci,
1057 unsigned int slot_id, unsigned int ep_index, 1163 unsigned int slot_id, unsigned int ep_index,
1164 unsigned int stream_id,
1058 struct xhci_td *td, union xhci_trb *event_trb) 1165 struct xhci_td *td, union xhci_trb *event_trb)
1059{ 1166{
1060 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index]; 1167 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
1061 ep->ep_state |= EP_HALTED; 1168 ep->ep_state |= EP_HALTED;
1062 ep->stopped_td = td; 1169 ep->stopped_td = td;
1063 ep->stopped_trb = event_trb; 1170 ep->stopped_trb = event_trb;
1171 ep->stopped_stream = stream_id;
1172
1064 xhci_queue_reset_ep(xhci, slot_id, ep_index); 1173 xhci_queue_reset_ep(xhci, slot_id, ep_index);
1065 xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index); 1174 xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index);
1175
1176 ep->stopped_td = NULL;
1177 ep->stopped_trb = NULL;
1178 ep->stopped_stream = 0;
1179
1066 xhci_ring_cmd_db(xhci); 1180 xhci_ring_cmd_db(xhci);
1067} 1181}
1068 1182
@@ -1119,11 +1233,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1119 struct xhci_ring *ep_ring; 1233 struct xhci_ring *ep_ring;
1120 unsigned int slot_id; 1234 unsigned int slot_id;
1121 int ep_index; 1235 int ep_index;
1122 struct xhci_td *td = 0; 1236 struct xhci_td *td = NULL;
1123 dma_addr_t event_dma; 1237 dma_addr_t event_dma;
1124 struct xhci_segment *event_seg; 1238 struct xhci_segment *event_seg;
1125 union xhci_trb *event_trb; 1239 union xhci_trb *event_trb;
1126 struct urb *urb = 0; 1240 struct urb *urb = NULL;
1127 int status = -EINPROGRESS; 1241 int status = -EINPROGRESS;
1128 struct xhci_ep_ctx *ep_ctx; 1242 struct xhci_ep_ctx *ep_ctx;
1129 u32 trb_comp_code; 1243 u32 trb_comp_code;
@@ -1140,10 +1254,11 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1140 ep_index = TRB_TO_EP_ID(event->flags) - 1; 1254 ep_index = TRB_TO_EP_ID(event->flags) - 1;
1141 xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index); 1255 xhci_dbg(xhci, "%s - ep index = %d\n", __func__, ep_index);
1142 ep = &xdev->eps[ep_index]; 1256 ep = &xdev->eps[ep_index];
1143 ep_ring = ep->ring; 1257 ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer);
1144 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1258 ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1145 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) { 1259 if (!ep_ring || (ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_DISABLED) {
1146 xhci_err(xhci, "ERROR Transfer event pointed to disabled endpoint\n"); 1260 xhci_err(xhci, "ERROR Transfer event for disabled endpoint "
1261 "or incorrect stream ring\n");
1147 return -ENODEV; 1262 return -ENODEV;
1148 } 1263 }
1149 1264
@@ -1274,7 +1389,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1274 td->urb->actual_length = 0; 1389 td->urb->actual_length = 0;
1275 1390
1276 xhci_cleanup_halted_endpoint(xhci, 1391 xhci_cleanup_halted_endpoint(xhci,
1277 slot_id, ep_index, td, event_trb); 1392 slot_id, ep_index, 0, td, event_trb);
1278 goto td_cleanup; 1393 goto td_cleanup;
1279 } 1394 }
1280 /* 1395 /*
@@ -1390,8 +1505,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1390 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; 1505 for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg;
1391 cur_trb != event_trb; 1506 cur_trb != event_trb;
1392 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) { 1507 next_trb(xhci, ep_ring, &cur_seg, &cur_trb)) {
1393 if (TRB_TYPE(cur_trb->generic.field[3]) != TRB_TR_NOOP && 1508 if ((cur_trb->generic.field[3] &
1394 TRB_TYPE(cur_trb->generic.field[3]) != TRB_LINK) 1509 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_TR_NOOP) &&
1510 (cur_trb->generic.field[3] &
1511 TRB_TYPE_BITMASK) != TRB_TYPE(TRB_LINK))
1395 td->urb->actual_length += 1512 td->urb->actual_length +=
1396 TRB_LEN(cur_trb->generic.field[2]); 1513 TRB_LEN(cur_trb->generic.field[2]);
1397 } 1514 }
@@ -1423,6 +1540,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1423 */ 1540 */
1424 ep->stopped_td = td; 1541 ep->stopped_td = td;
1425 ep->stopped_trb = event_trb; 1542 ep->stopped_trb = event_trb;
1543 ep->stopped_stream = ep_ring->stream_id;
1426 } else if (xhci_requires_manual_halt_cleanup(xhci, 1544 } else if (xhci_requires_manual_halt_cleanup(xhci,
1427 ep_ctx, trb_comp_code)) { 1545 ep_ctx, trb_comp_code)) {
1428 /* Other types of errors halt the endpoint, but the 1546 /* Other types of errors halt the endpoint, but the
@@ -1431,7 +1549,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1431 * xHCI hardware manually. 1549 * xHCI hardware manually.
1432 */ 1550 */
1433 xhci_cleanup_halted_endpoint(xhci, 1551 xhci_cleanup_halted_endpoint(xhci,
1434 slot_id, ep_index, td, event_trb); 1552 slot_id, ep_index, ep_ring->stream_id, td, event_trb);
1435 } else { 1553 } else {
1436 /* Update ring dequeue pointer */ 1554 /* Update ring dequeue pointer */
1437 while (ep_ring->dequeue != td->last_trb) 1555 while (ep_ring->dequeue != td->last_trb)
@@ -1621,20 +1739,66 @@ static int prepare_ring(struct xhci_hcd *xhci, struct xhci_ring *ep_ring,
1621 xhci_err(xhci, "ERROR no room on ep ring\n"); 1739 xhci_err(xhci, "ERROR no room on ep ring\n");
1622 return -ENOMEM; 1740 return -ENOMEM;
1623 } 1741 }
1742
1743 if (enqueue_is_link_trb(ep_ring)) {
1744 struct xhci_ring *ring = ep_ring;
1745 union xhci_trb *next;
1746
1747 xhci_dbg(xhci, "prepare_ring: pointing to link trb\n");
1748 next = ring->enqueue;
1749
1750 while (last_trb(xhci, ring, ring->enq_seg, next)) {
1751
1752 /* If we're not dealing with 0.95 hardware,
1753 * clear the chain bit.
1754 */
1755 if (!xhci_link_trb_quirk(xhci))
1756 next->link.control &= ~TRB_CHAIN;
1757 else
1758 next->link.control |= TRB_CHAIN;
1759
1760 wmb();
1761 next->link.control ^= (u32) TRB_CYCLE;
1762
1763 /* Toggle the cycle bit after the last ring segment. */
1764 if (last_trb_on_last_seg(xhci, ring, ring->enq_seg, next)) {
1765 ring->cycle_state = (ring->cycle_state ? 0 : 1);
1766 if (!in_interrupt()) {
1767 xhci_dbg(xhci, "queue_trb: Toggle cycle "
1768 "state for ring %p = %i\n",
1769 ring, (unsigned int)ring->cycle_state);
1770 }
1771 }
1772 ring->enq_seg = ring->enq_seg->next;
1773 ring->enqueue = ring->enq_seg->trbs;
1774 next = ring->enqueue;
1775 }
1776 }
1777
1624 return 0; 1778 return 0;
1625} 1779}
1626 1780
1627static int prepare_transfer(struct xhci_hcd *xhci, 1781static int prepare_transfer(struct xhci_hcd *xhci,
1628 struct xhci_virt_device *xdev, 1782 struct xhci_virt_device *xdev,
1629 unsigned int ep_index, 1783 unsigned int ep_index,
1784 unsigned int stream_id,
1630 unsigned int num_trbs, 1785 unsigned int num_trbs,
1631 struct urb *urb, 1786 struct urb *urb,
1632 struct xhci_td **td, 1787 struct xhci_td **td,
1633 gfp_t mem_flags) 1788 gfp_t mem_flags)
1634{ 1789{
1635 int ret; 1790 int ret;
1791 struct xhci_ring *ep_ring;
1636 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index); 1792 struct xhci_ep_ctx *ep_ctx = xhci_get_ep_ctx(xhci, xdev->out_ctx, ep_index);
1637 ret = prepare_ring(xhci, xdev->eps[ep_index].ring, 1793
1794 ep_ring = xhci_stream_id_to_ring(xdev, ep_index, stream_id);
1795 if (!ep_ring) {
1796 xhci_dbg(xhci, "Can't prepare ring for bad stream ID %u\n",
1797 stream_id);
1798 return -EINVAL;
1799 }
1800
1801 ret = prepare_ring(xhci, ep_ring,
1638 ep_ctx->ep_info & EP_STATE_MASK, 1802 ep_ctx->ep_info & EP_STATE_MASK,
1639 num_trbs, mem_flags); 1803 num_trbs, mem_flags);
1640 if (ret) 1804 if (ret)
@@ -1654,9 +1818,9 @@ static int prepare_transfer(struct xhci_hcd *xhci,
1654 (*td)->urb = urb; 1818 (*td)->urb = urb;
1655 urb->hcpriv = (void *) (*td); 1819 urb->hcpriv = (void *) (*td);
1656 /* Add this TD to the tail of the endpoint ring's TD list */ 1820 /* Add this TD to the tail of the endpoint ring's TD list */
1657 list_add_tail(&(*td)->td_list, &xdev->eps[ep_index].ring->td_list); 1821 list_add_tail(&(*td)->td_list, &ep_ring->td_list);
1658 (*td)->start_seg = xdev->eps[ep_index].ring->enq_seg; 1822 (*td)->start_seg = ep_ring->enq_seg;
1659 (*td)->first_trb = xdev->eps[ep_index].ring->enqueue; 1823 (*td)->first_trb = ep_ring->enqueue;
1660 1824
1661 return 0; 1825 return 0;
1662} 1826}
@@ -1672,7 +1836,7 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb)
1672 1836
1673 xhci_dbg(xhci, "count sg list trbs: \n"); 1837 xhci_dbg(xhci, "count sg list trbs: \n");
1674 num_trbs = 0; 1838 num_trbs = 0;
1675 for_each_sg(urb->sg->sg, sg, num_sgs, i) { 1839 for_each_sg(urb->sg, sg, num_sgs, i) {
1676 unsigned int previous_total_trbs = num_trbs; 1840 unsigned int previous_total_trbs = num_trbs;
1677 unsigned int len = sg_dma_len(sg); 1841 unsigned int len = sg_dma_len(sg);
1678 1842
@@ -1722,7 +1886,7 @@ static void check_trb_math(struct urb *urb, int num_trbs, int running_total)
1722} 1886}
1723 1887
1724static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id, 1888static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
1725 unsigned int ep_index, int start_cycle, 1889 unsigned int ep_index, unsigned int stream_id, int start_cycle,
1726 struct xhci_generic_trb *start_trb, struct xhci_td *td) 1890 struct xhci_generic_trb *start_trb, struct xhci_td *td)
1727{ 1891{
1728 /* 1892 /*
@@ -1731,7 +1895,7 @@ static void giveback_first_trb(struct xhci_hcd *xhci, int slot_id,
1731 */ 1895 */
1732 wmb(); 1896 wmb();
1733 start_trb->field[3] |= start_cycle; 1897 start_trb->field[3] |= start_cycle;
1734 ring_ep_doorbell(xhci, slot_id, ep_index); 1898 ring_ep_doorbell(xhci, slot_id, ep_index, stream_id);
1735} 1899}
1736 1900
1737/* 1901/*
@@ -1805,12 +1969,16 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1805 struct xhci_generic_trb *start_trb; 1969 struct xhci_generic_trb *start_trb;
1806 int start_cycle; 1970 int start_cycle;
1807 1971
1808 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 1972 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
1973 if (!ep_ring)
1974 return -EINVAL;
1975
1809 num_trbs = count_sg_trbs_needed(xhci, urb); 1976 num_trbs = count_sg_trbs_needed(xhci, urb);
1810 num_sgs = urb->num_sgs; 1977 num_sgs = urb->num_sgs;
1811 1978
1812 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id], 1979 trb_buff_len = prepare_transfer(xhci, xhci->devs[slot_id],
1813 ep_index, num_trbs, urb, &td, mem_flags); 1980 ep_index, urb->stream_id,
1981 num_trbs, urb, &td, mem_flags);
1814 if (trb_buff_len < 0) 1982 if (trb_buff_len < 0)
1815 return trb_buff_len; 1983 return trb_buff_len;
1816 /* 1984 /*
@@ -1831,7 +1999,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1831 * the amount of memory allocated for this scatter-gather list. 1999 * the amount of memory allocated for this scatter-gather list.
1832 * 3. TRBs buffers can't cross 64KB boundaries. 2000 * 3. TRBs buffers can't cross 64KB boundaries.
1833 */ 2001 */
1834 sg = urb->sg->sg; 2002 sg = urb->sg;
1835 addr = (u64) sg_dma_address(sg); 2003 addr = (u64) sg_dma_address(sg);
1836 this_sg_len = sg_dma_len(sg); 2004 this_sg_len = sg_dma_len(sg);
1837 trb_buff_len = TRB_MAX_BUFF_SIZE - 2005 trb_buff_len = TRB_MAX_BUFF_SIZE -
@@ -1919,7 +2087,8 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1919 } while (running_total < urb->transfer_buffer_length); 2087 } while (running_total < urb->transfer_buffer_length);
1920 2088
1921 check_trb_math(urb, num_trbs, running_total); 2089 check_trb_math(urb, num_trbs, running_total);
1922 giveback_first_trb(xhci, slot_id, ep_index, start_cycle, start_trb, td); 2090 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
2091 start_cycle, start_trb, td);
1923 return 0; 2092 return 0;
1924} 2093}
1925 2094
@@ -1938,10 +2107,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1938 int running_total, trb_buff_len, ret; 2107 int running_total, trb_buff_len, ret;
1939 u64 addr; 2108 u64 addr;
1940 2109
1941 if (urb->sg) 2110 if (urb->num_sgs)
1942 return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index); 2111 return queue_bulk_sg_tx(xhci, mem_flags, urb, slot_id, ep_index);
1943 2112
1944 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 2113 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
2114 if (!ep_ring)
2115 return -EINVAL;
1945 2116
1946 num_trbs = 0; 2117 num_trbs = 0;
1947 /* How much data is (potentially) left before the 64KB boundary? */ 2118 /* How much data is (potentially) left before the 64KB boundary? */
@@ -1968,7 +2139,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1968 (unsigned long long)urb->transfer_dma, 2139 (unsigned long long)urb->transfer_dma,
1969 num_trbs); 2140 num_trbs);
1970 2141
1971 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, 2142 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2143 ep_index, urb->stream_id,
1972 num_trbs, urb, &td, mem_flags); 2144 num_trbs, urb, &td, mem_flags);
1973 if (ret < 0) 2145 if (ret < 0)
1974 return ret; 2146 return ret;
@@ -2038,7 +2210,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2038 } while (running_total < urb->transfer_buffer_length); 2210 } while (running_total < urb->transfer_buffer_length);
2039 2211
2040 check_trb_math(urb, num_trbs, running_total); 2212 check_trb_math(urb, num_trbs, running_total);
2041 giveback_first_trb(xhci, slot_id, ep_index, start_cycle, start_trb, td); 2213 giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id,
2214 start_cycle, start_trb, td);
2042 return 0; 2215 return 0;
2043} 2216}
2044 2217
@@ -2055,7 +2228,9 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2055 u32 field, length_field; 2228 u32 field, length_field;
2056 struct xhci_td *td; 2229 struct xhci_td *td;
2057 2230
2058 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 2231 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
2232 if (!ep_ring)
2233 return -EINVAL;
2059 2234
2060 /* 2235 /*
2061 * Need to copy setup packet into setup TRB, so we can't use the setup 2236 * Need to copy setup packet into setup TRB, so we can't use the setup
@@ -2076,8 +2251,9 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2076 */ 2251 */
2077 if (urb->transfer_buffer_length > 0) 2252 if (urb->transfer_buffer_length > 0)
2078 num_trbs++; 2253 num_trbs++;
2079 ret = prepare_transfer(xhci, xhci->devs[slot_id], ep_index, num_trbs, 2254 ret = prepare_transfer(xhci, xhci->devs[slot_id],
2080 urb, &td, mem_flags); 2255 ep_index, urb->stream_id,
2256 num_trbs, urb, &td, mem_flags);
2081 if (ret < 0) 2257 if (ret < 0)
2082 return ret; 2258 return ret;
2083 2259
@@ -2132,7 +2308,8 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
2132 /* Event on completion */ 2308 /* Event on completion */
2133 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state); 2309 field | TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state);
2134 2310
2135 giveback_first_trb(xhci, slot_id, ep_index, start_cycle, start_trb, td); 2311 giveback_first_trb(xhci, slot_id, ep_index, 0,
2312 start_cycle, start_trb, td);
2136 return 0; 2313 return 0;
2137} 2314}
2138 2315
@@ -2244,12 +2421,14 @@ int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
2244 * This should not be used for endpoints that have streams enabled. 2421 * This should not be used for endpoints that have streams enabled.
2245 */ 2422 */
2246static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id, 2423static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
2247 unsigned int ep_index, struct xhci_segment *deq_seg, 2424 unsigned int ep_index, unsigned int stream_id,
2425 struct xhci_segment *deq_seg,
2248 union xhci_trb *deq_ptr, u32 cycle_state) 2426 union xhci_trb *deq_ptr, u32 cycle_state)
2249{ 2427{
2250 dma_addr_t addr; 2428 dma_addr_t addr;
2251 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id); 2429 u32 trb_slot_id = SLOT_ID_FOR_TRB(slot_id);
2252 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index); 2430 u32 trb_ep_index = EP_ID_FOR_TRB(ep_index);
2431 u32 trb_stream_id = STREAM_ID_FOR_TRB(stream_id);
2253 u32 type = TRB_TYPE(TRB_SET_DEQ); 2432 u32 type = TRB_TYPE(TRB_SET_DEQ);
2254 2433
2255 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr); 2434 addr = xhci_trb_virt_to_dma(deq_seg, deq_ptr);
@@ -2260,7 +2439,7 @@ static int queue_set_tr_deq(struct xhci_hcd *xhci, int slot_id,
2260 return 0; 2439 return 0;
2261 } 2440 }
2262 return queue_command(xhci, lower_32_bits(addr) | cycle_state, 2441 return queue_command(xhci, lower_32_bits(addr) | cycle_state,
2263 upper_32_bits(addr), 0, 2442 upper_32_bits(addr), trb_stream_id,
2264 trb_slot_id | trb_ep_index | type, false); 2443 trb_slot_id | trb_ep_index | type, false);
2265} 2444}
2266 2445
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 7e4277273908..40e0a0c221b8 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include <linux/irq.h> 23#include <linux/irq.h>
24#include <linux/log2.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
@@ -352,11 +353,7 @@ void xhci_event_ring_work(unsigned long arg)
352 if (!xhci->devs[i]) 353 if (!xhci->devs[i])
353 continue; 354 continue;
354 for (j = 0; j < 31; ++j) { 355 for (j = 0; j < 31; ++j) {
355 struct xhci_ring *ring = xhci->devs[i]->eps[j].ring; 356 xhci_dbg_ep_rings(xhci, i, j, &xhci->devs[i]->eps[j]);
356 if (!ring)
357 continue;
358 xhci_dbg(xhci, "Dev %d endpoint ring %d:\n", i, j);
359 xhci_debug_segment(xhci, ring->deq_seg);
360 } 357 }
361 } 358 }
362 359
@@ -726,8 +723,21 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
726 spin_lock_irqsave(&xhci->lock, flags); 723 spin_lock_irqsave(&xhci->lock, flags);
727 if (xhci->xhc_state & XHCI_STATE_DYING) 724 if (xhci->xhc_state & XHCI_STATE_DYING)
728 goto dying; 725 goto dying;
729 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 726 if (xhci->devs[slot_id]->eps[ep_index].ep_state &
730 slot_id, ep_index); 727 EP_GETTING_STREAMS) {
728 xhci_warn(xhci, "WARN: Can't enqueue URB while bulk ep "
729 "is transitioning to using streams.\n");
730 ret = -EINVAL;
731 } else if (xhci->devs[slot_id]->eps[ep_index].ep_state &
732 EP_GETTING_NO_STREAMS) {
733 xhci_warn(xhci, "WARN: Can't enqueue URB while bulk ep "
734 "is transitioning to "
735 "not having streams.\n");
736 ret = -EINVAL;
737 } else {
738 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
739 slot_id, ep_index);
740 }
731 spin_unlock_irqrestore(&xhci->lock, flags); 741 spin_unlock_irqrestore(&xhci->lock, flags);
732 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { 742 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
733 spin_lock_irqsave(&xhci->lock, flags); 743 spin_lock_irqsave(&xhci->lock, flags);
@@ -825,7 +835,12 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
825 xhci_debug_ring(xhci, xhci->event_ring); 835 xhci_debug_ring(xhci, xhci->event_ring);
826 ep_index = xhci_get_endpoint_index(&urb->ep->desc); 836 ep_index = xhci_get_endpoint_index(&urb->ep->desc);
827 ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index]; 837 ep = &xhci->devs[urb->dev->slot_id]->eps[ep_index];
828 ep_ring = ep->ring; 838 ep_ring = xhci_urb_to_transfer_ring(xhci, urb);
839 if (!ep_ring) {
840 ret = -EINVAL;
841 goto done;
842 }
843
829 xhci_dbg(xhci, "Endpoint ring:\n"); 844 xhci_dbg(xhci, "Endpoint ring:\n");
830 xhci_debug_ring(xhci, ep_ring); 845 xhci_debug_ring(xhci, ep_ring);
831 td = (struct xhci_td *) urb->hcpriv; 846 td = (struct xhci_td *) urb->hcpriv;
@@ -1369,7 +1384,7 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1369 * or it will attempt to resend it on the next doorbell ring. 1384 * or it will attempt to resend it on the next doorbell ring.
1370 */ 1385 */
1371 xhci_find_new_dequeue_state(xhci, udev->slot_id, 1386 xhci_find_new_dequeue_state(xhci, udev->slot_id,
1372 ep_index, ep->stopped_td, 1387 ep_index, ep->stopped_stream, ep->stopped_td,
1373 &deq_state); 1388 &deq_state);
1374 1389
1375 /* HW with the reset endpoint quirk will use the saved dequeue state to 1390 /* HW with the reset endpoint quirk will use the saved dequeue state to
@@ -1378,10 +1393,12 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1378 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) { 1393 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
1379 xhci_dbg(xhci, "Queueing new dequeue state\n"); 1394 xhci_dbg(xhci, "Queueing new dequeue state\n");
1380 xhci_queue_new_dequeue_state(xhci, udev->slot_id, 1395 xhci_queue_new_dequeue_state(xhci, udev->slot_id,
1381 ep_index, &deq_state); 1396 ep_index, ep->stopped_stream, &deq_state);
1382 } else { 1397 } else {
1383 /* Better hope no one uses the input context between now and the 1398 /* Better hope no one uses the input context between now and the
1384 * reset endpoint completion! 1399 * reset endpoint completion!
1400 * XXX: No idea how this hardware will react when stream rings
1401 * are enabled.
1385 */ 1402 */
1386 xhci_dbg(xhci, "Setting up input context for " 1403 xhci_dbg(xhci, "Setting up input context for "
1387 "configure endpoint command\n"); 1404 "configure endpoint command\n");
@@ -1438,12 +1455,391 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1438 kfree(virt_ep->stopped_td); 1455 kfree(virt_ep->stopped_td);
1439 xhci_ring_cmd_db(xhci); 1456 xhci_ring_cmd_db(xhci);
1440 } 1457 }
1458 virt_ep->stopped_td = NULL;
1459 virt_ep->stopped_trb = NULL;
1460 virt_ep->stopped_stream = 0;
1441 spin_unlock_irqrestore(&xhci->lock, flags); 1461 spin_unlock_irqrestore(&xhci->lock, flags);
1442 1462
1443 if (ret) 1463 if (ret)
1444 xhci_warn(xhci, "FIXME allocate a new ring segment\n"); 1464 xhci_warn(xhci, "FIXME allocate a new ring segment\n");
1445} 1465}
1446 1466
1467static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
1468 struct usb_device *udev, struct usb_host_endpoint *ep,
1469 unsigned int slot_id)
1470{
1471 int ret;
1472 unsigned int ep_index;
1473 unsigned int ep_state;
1474
1475 if (!ep)
1476 return -EINVAL;
1477 ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, __func__);
1478 if (ret <= 0)
1479 return -EINVAL;
1480 if (ep->ss_ep_comp.bmAttributes == 0) {
1481 xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion"
1482 " descriptor for ep 0x%x does not support streams\n",
1483 ep->desc.bEndpointAddress);
1484 return -EINVAL;
1485 }
1486
1487 ep_index = xhci_get_endpoint_index(&ep->desc);
1488 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1489 if (ep_state & EP_HAS_STREAMS ||
1490 ep_state & EP_GETTING_STREAMS) {
1491 xhci_warn(xhci, "WARN: SuperSpeed bulk endpoint 0x%x "
1492 "already has streams set up.\n",
1493 ep->desc.bEndpointAddress);
1494 xhci_warn(xhci, "Send email to xHCI maintainer and ask for "
1495 "dynamic stream context array reallocation.\n");
1496 return -EINVAL;
1497 }
1498 if (!list_empty(&xhci->devs[slot_id]->eps[ep_index].ring->td_list)) {
1499 xhci_warn(xhci, "Cannot setup streams for SuperSpeed bulk "
1500 "endpoint 0x%x; URBs are pending.\n",
1501 ep->desc.bEndpointAddress);
1502 return -EINVAL;
1503 }
1504 return 0;
1505}
1506
1507static void xhci_calculate_streams_entries(struct xhci_hcd *xhci,
1508 unsigned int *num_streams, unsigned int *num_stream_ctxs)
1509{
1510 unsigned int max_streams;
1511
1512 /* The stream context array size must be a power of two */
1513 *num_stream_ctxs = roundup_pow_of_two(*num_streams);
1514 /*
1515 * Find out how many primary stream array entries the host controller
1516 * supports. Later we may use secondary stream arrays (similar to 2nd
1517 * level page entries), but that's an optional feature for xHCI host
1518 * controllers. xHCs must support at least 4 stream IDs.
1519 */
1520 max_streams = HCC_MAX_PSA(xhci->hcc_params);
1521 if (*num_stream_ctxs > max_streams) {
1522 xhci_dbg(xhci, "xHCI HW only supports %u stream ctx entries.\n",
1523 max_streams);
1524 *num_stream_ctxs = max_streams;
1525 *num_streams = max_streams;
1526 }
1527}
1528
1529/* Returns an error code if one of the endpoint already has streams.
1530 * This does not change any data structures, it only checks and gathers
1531 * information.
1532 */
1533static int xhci_calculate_streams_and_bitmask(struct xhci_hcd *xhci,
1534 struct usb_device *udev,
1535 struct usb_host_endpoint **eps, unsigned int num_eps,
1536 unsigned int *num_streams, u32 *changed_ep_bitmask)
1537{
1538 unsigned int max_streams;
1539 unsigned int endpoint_flag;
1540 int i;
1541 int ret;
1542
1543 for (i = 0; i < num_eps; i++) {
1544 ret = xhci_check_streams_endpoint(xhci, udev,
1545 eps[i], udev->slot_id);
1546 if (ret < 0)
1547 return ret;
1548
1549 max_streams = USB_SS_MAX_STREAMS(
1550 eps[i]->ss_ep_comp.bmAttributes);
1551 if (max_streams < (*num_streams - 1)) {
1552 xhci_dbg(xhci, "Ep 0x%x only supports %u stream IDs.\n",
1553 eps[i]->desc.bEndpointAddress,
1554 max_streams);
1555 *num_streams = max_streams+1;
1556 }
1557
1558 endpoint_flag = xhci_get_endpoint_flag(&eps[i]->desc);
1559 if (*changed_ep_bitmask & endpoint_flag)
1560 return -EINVAL;
1561 *changed_ep_bitmask |= endpoint_flag;
1562 }
1563 return 0;
1564}
1565
1566static u32 xhci_calculate_no_streams_bitmask(struct xhci_hcd *xhci,
1567 struct usb_device *udev,
1568 struct usb_host_endpoint **eps, unsigned int num_eps)
1569{
1570 u32 changed_ep_bitmask = 0;
1571 unsigned int slot_id;
1572 unsigned int ep_index;
1573 unsigned int ep_state;
1574 int i;
1575
1576 slot_id = udev->slot_id;
1577 if (!xhci->devs[slot_id])
1578 return 0;
1579
1580 for (i = 0; i < num_eps; i++) {
1581 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1582 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
1583 /* Are streams already being freed for the endpoint? */
1584 if (ep_state & EP_GETTING_NO_STREAMS) {
1585 xhci_warn(xhci, "WARN Can't disable streams for "
1586 "endpoint 0x%x\n, "
1587 "streams are being disabled already.",
1588 eps[i]->desc.bEndpointAddress);
1589 return 0;
1590 }
1591 /* Are there actually any streams to free? */
1592 if (!(ep_state & EP_HAS_STREAMS) &&
1593 !(ep_state & EP_GETTING_STREAMS)) {
1594 xhci_warn(xhci, "WARN Can't disable streams for "
1595 "endpoint 0x%x\n, "
1596 "streams are already disabled!",
1597 eps[i]->desc.bEndpointAddress);
1598 xhci_warn(xhci, "WARN xhci_free_streams() called "
1599 "with non-streams endpoint\n");
1600 return 0;
1601 }
1602 changed_ep_bitmask |= xhci_get_endpoint_flag(&eps[i]->desc);
1603 }
1604 return changed_ep_bitmask;
1605}
1606
1607/*
1608 * The USB device drivers use this function (though the HCD interface in USB
1609 * core) to prepare a set of bulk endpoints to use streams. Streams are used to
1610 * coordinate mass storage command queueing across multiple endpoints (basically
1611 * a stream ID == a task ID).
1612 *
1613 * Setting up streams involves allocating the same size stream context array
1614 * for each endpoint and issuing a configure endpoint command for all endpoints.
1615 *
1616 * Don't allow the call to succeed if one endpoint only supports one stream
1617 * (which means it doesn't support streams at all).
1618 *
1619 * Drivers may get less stream IDs than they asked for, if the host controller
1620 * hardware or endpoints claim they can't support the number of requested
1621 * stream IDs.
1622 */
1623int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
1624 struct usb_host_endpoint **eps, unsigned int num_eps,
1625 unsigned int num_streams, gfp_t mem_flags)
1626{
1627 int i, ret;
1628 struct xhci_hcd *xhci;
1629 struct xhci_virt_device *vdev;
1630 struct xhci_command *config_cmd;
1631 unsigned int ep_index;
1632 unsigned int num_stream_ctxs;
1633 unsigned long flags;
1634 u32 changed_ep_bitmask = 0;
1635
1636 if (!eps)
1637 return -EINVAL;
1638
1639 /* Add one to the number of streams requested to account for
1640 * stream 0 that is reserved for xHCI usage.
1641 */
1642 num_streams += 1;
1643 xhci = hcd_to_xhci(hcd);
1644 xhci_dbg(xhci, "Driver wants %u stream IDs (including stream 0).\n",
1645 num_streams);
1646
1647 config_cmd = xhci_alloc_command(xhci, true, true, mem_flags);
1648 if (!config_cmd) {
1649 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n");
1650 return -ENOMEM;
1651 }
1652
1653 /* Check to make sure all endpoints are not already configured for
1654 * streams. While we're at it, find the maximum number of streams that
1655 * all the endpoints will support and check for duplicate endpoints.
1656 */
1657 spin_lock_irqsave(&xhci->lock, flags);
1658 ret = xhci_calculate_streams_and_bitmask(xhci, udev, eps,
1659 num_eps, &num_streams, &changed_ep_bitmask);
1660 if (ret < 0) {
1661 xhci_free_command(xhci, config_cmd);
1662 spin_unlock_irqrestore(&xhci->lock, flags);
1663 return ret;
1664 }
1665 if (num_streams <= 1) {
1666 xhci_warn(xhci, "WARN: endpoints can't handle "
1667 "more than one stream.\n");
1668 xhci_free_command(xhci, config_cmd);
1669 spin_unlock_irqrestore(&xhci->lock, flags);
1670 return -EINVAL;
1671 }
1672 vdev = xhci->devs[udev->slot_id];
1673 /* Mark each endpoint as being in transistion, so
1674 * xhci_urb_enqueue() will reject all URBs.
1675 */
1676 for (i = 0; i < num_eps; i++) {
1677 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1678 vdev->eps[ep_index].ep_state |= EP_GETTING_STREAMS;
1679 }
1680 spin_unlock_irqrestore(&xhci->lock, flags);
1681
1682 /* Setup internal data structures and allocate HW data structures for
1683 * streams (but don't install the HW structures in the input context
1684 * until we're sure all memory allocation succeeded).
1685 */
1686 xhci_calculate_streams_entries(xhci, &num_streams, &num_stream_ctxs);
1687 xhci_dbg(xhci, "Need %u stream ctx entries for %u stream IDs.\n",
1688 num_stream_ctxs, num_streams);
1689
1690 for (i = 0; i < num_eps; i++) {
1691 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1692 vdev->eps[ep_index].stream_info = xhci_alloc_stream_info(xhci,
1693 num_stream_ctxs,
1694 num_streams, mem_flags);
1695 if (!vdev->eps[ep_index].stream_info)
1696 goto cleanup;
1697 /* Set maxPstreams in endpoint context and update deq ptr to
1698 * point to stream context array. FIXME
1699 */
1700 }
1701
1702 /* Set up the input context for a configure endpoint command. */
1703 for (i = 0; i < num_eps; i++) {
1704 struct xhci_ep_ctx *ep_ctx;
1705
1706 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1707 ep_ctx = xhci_get_ep_ctx(xhci, config_cmd->in_ctx, ep_index);
1708
1709 xhci_endpoint_copy(xhci, config_cmd->in_ctx,
1710 vdev->out_ctx, ep_index);
1711 xhci_setup_streams_ep_input_ctx(xhci, ep_ctx,
1712 vdev->eps[ep_index].stream_info);
1713 }
1714 /* Tell the HW to drop its old copy of the endpoint context info
1715 * and add the updated copy from the input context.
1716 */
1717 xhci_setup_input_ctx_for_config_ep(xhci, config_cmd->in_ctx,
1718 vdev->out_ctx, changed_ep_bitmask, changed_ep_bitmask);
1719
1720 /* Issue and wait for the configure endpoint command */
1721 ret = xhci_configure_endpoint(xhci, udev, config_cmd,
1722 false, false);
1723
1724 /* xHC rejected the configure endpoint command for some reason, so we
1725 * leave the old ring intact and free our internal streams data
1726 * structure.
1727 */
1728 if (ret < 0)
1729 goto cleanup;
1730
1731 spin_lock_irqsave(&xhci->lock, flags);
1732 for (i = 0; i < num_eps; i++) {
1733 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1734 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS;
1735 xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n",
1736 udev->slot_id, ep_index);
1737 vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS;
1738 }
1739 xhci_free_command(xhci, config_cmd);
1740 spin_unlock_irqrestore(&xhci->lock, flags);
1741
1742 /* Subtract 1 for stream 0, which drivers can't use */
1743 return num_streams - 1;
1744
1745cleanup:
1746 /* If it didn't work, free the streams! */
1747 for (i = 0; i < num_eps; i++) {
1748 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1749 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info);
1750 vdev->eps[ep_index].stream_info = NULL;
1751 /* FIXME Unset maxPstreams in endpoint context and
1752 * update deq ptr to point to normal string ring.
1753 */
1754 vdev->eps[ep_index].ep_state &= ~EP_GETTING_STREAMS;
1755 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS;
1756 xhci_endpoint_zero(xhci, vdev, eps[i]);
1757 }
1758 xhci_free_command(xhci, config_cmd);
1759 return -ENOMEM;
1760}
1761
1762/* Transition the endpoint from using streams to being a "normal" endpoint
1763 * without streams.
1764 *
1765 * Modify the endpoint context state, submit a configure endpoint command,
1766 * and free all endpoint rings for streams if that completes successfully.
1767 */
1768int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1769 struct usb_host_endpoint **eps, unsigned int num_eps,
1770 gfp_t mem_flags)
1771{
1772 int i, ret;
1773 struct xhci_hcd *xhci;
1774 struct xhci_virt_device *vdev;
1775 struct xhci_command *command;
1776 unsigned int ep_index;
1777 unsigned long flags;
1778 u32 changed_ep_bitmask;
1779
1780 xhci = hcd_to_xhci(hcd);
1781 vdev = xhci->devs[udev->slot_id];
1782
1783 /* Set up a configure endpoint command to remove the streams rings */
1784 spin_lock_irqsave(&xhci->lock, flags);
1785 changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci,
1786 udev, eps, num_eps);
1787 if (changed_ep_bitmask == 0) {
1788 spin_unlock_irqrestore(&xhci->lock, flags);
1789 return -EINVAL;
1790 }
1791
1792 /* Use the xhci_command structure from the first endpoint. We may have
1793 * allocated too many, but the driver may call xhci_free_streams() for
1794 * each endpoint it grouped into one call to xhci_alloc_streams().
1795 */
1796 ep_index = xhci_get_endpoint_index(&eps[0]->desc);
1797 command = vdev->eps[ep_index].stream_info->free_streams_command;
1798 for (i = 0; i < num_eps; i++) {
1799 struct xhci_ep_ctx *ep_ctx;
1800
1801 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1802 ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index);
1803 xhci->devs[udev->slot_id]->eps[ep_index].ep_state |=
1804 EP_GETTING_NO_STREAMS;
1805
1806 xhci_endpoint_copy(xhci, command->in_ctx,
1807 vdev->out_ctx, ep_index);
1808 xhci_setup_no_streams_ep_input_ctx(xhci, ep_ctx,
1809 &vdev->eps[ep_index]);
1810 }
1811 xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx,
1812 vdev->out_ctx, changed_ep_bitmask, changed_ep_bitmask);
1813 spin_unlock_irqrestore(&xhci->lock, flags);
1814
1815 /* Issue and wait for the configure endpoint command,
1816 * which must succeed.
1817 */
1818 ret = xhci_configure_endpoint(xhci, udev, command,
1819 false, true);
1820
1821 /* xHC rejected the configure endpoint command for some reason, so we
1822 * leave the streams rings intact.
1823 */
1824 if (ret < 0)
1825 return ret;
1826
1827 spin_lock_irqsave(&xhci->lock, flags);
1828 for (i = 0; i < num_eps; i++) {
1829 ep_index = xhci_get_endpoint_index(&eps[i]->desc);
1830 xhci_free_stream_info(xhci, vdev->eps[ep_index].stream_info);
1831 vdev->eps[ep_index].stream_info = NULL;
1832 /* FIXME Unset maxPstreams in endpoint context and
1833 * update deq ptr to point to normal string ring.
1834 */
1835 vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS;
1836 vdev->eps[ep_index].ep_state &= ~EP_HAS_STREAMS;
1837 }
1838 spin_unlock_irqrestore(&xhci->lock, flags);
1839
1840 return 0;
1841}
1842
1447/* 1843/*
1448 * This submits a Reset Device Command, which will set the device state to 0, 1844 * This submits a Reset Device Command, which will set the device state to 0,
1449 * set the device address to 0, and disable all the endpoints except the default 1845 * set the device address to 0, and disable all the endpoints except the default
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index ea389e9a4931..dada2fb59261 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -26,8 +26,8 @@
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/timer.h> 27#include <linux/timer.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/usb/hcd.h>
29 30
30#include "../core/hcd.h"
31/* Code sharing between pci-quirks and xhci hcd */ 31/* Code sharing between pci-quirks and xhci hcd */
32#include "xhci-ext-caps.h" 32#include "xhci-ext-caps.h"
33 33
@@ -117,7 +117,7 @@ struct xhci_cap_regs {
117/* true: no secondary Stream ID Support */ 117/* true: no secondary Stream ID Support */
118#define HCC_NSS(p) ((p) & (1 << 7)) 118#define HCC_NSS(p) ((p) & (1 << 7))
119/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */ 119/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
120#define HCC_MAX_PSA (1 << ((((p) >> 12) & 0xf) + 1)) 120#define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1))
121/* Extended Capabilities pointer from PCI base - section 5.3.6 */ 121/* Extended Capabilities pointer from PCI base - section 5.3.6 */
122#define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p) 122#define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
123 123
@@ -444,6 +444,7 @@ struct xhci_doorbell_array {
444 444
445/* Endpoint Target - bits 0:7 */ 445/* Endpoint Target - bits 0:7 */
446#define EPI_TO_DB(p) (((p) + 1) & 0xff) 446#define EPI_TO_DB(p) (((p) + 1) & 0xff)
447#define STREAM_ID_TO_DB(p) (((p) & 0xffff) << 16)
447 448
448 449
449/** 450/**
@@ -585,6 +586,10 @@ struct xhci_ep_ctx {
585/* Interval - period between requests to an endpoint - 125u increments. */ 586/* Interval - period between requests to an endpoint - 125u increments. */
586#define EP_INTERVAL(p) ((p & 0xff) << 16) 587#define EP_INTERVAL(p) ((p & 0xff) << 16)
587#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) 588#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
589#define EP_MAXPSTREAMS_MASK (0x1f << 10)
590#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
591/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
592#define EP_HAS_LSA (1 << 15)
588 593
589/* ep_info2 bitmasks */ 594/* ep_info2 bitmasks */
590/* 595/*
@@ -648,8 +653,50 @@ struct xhci_command {
648/* add context bitmasks */ 653/* add context bitmasks */
649#define ADD_EP(x) (0x1 << x) 654#define ADD_EP(x) (0x1 << x)
650 655
656struct xhci_stream_ctx {
657 /* 64-bit stream ring address, cycle state, and stream type */
658 u64 stream_ring;
659 /* offset 0x14 - 0x1f reserved for HC internal use */
660 u32 reserved[2];
661};
662
663/* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */
664#define SCT_FOR_CTX(p) (((p) << 1) & 0x7)
665/* Secondary stream array type, dequeue pointer is to a transfer ring */
666#define SCT_SEC_TR 0
667/* Primary stream array type, dequeue pointer is to a transfer ring */
668#define SCT_PRI_TR 1
669/* Dequeue pointer is for a secondary stream array (SSA) with 8 entries */
670#define SCT_SSA_8 2
671#define SCT_SSA_16 3
672#define SCT_SSA_32 4
673#define SCT_SSA_64 5
674#define SCT_SSA_128 6
675#define SCT_SSA_256 7
676
677/* Assume no secondary streams for now */
678struct xhci_stream_info {
679 struct xhci_ring **stream_rings;
680 /* Number of streams, including stream 0 (which drivers can't use) */
681 unsigned int num_streams;
682 /* The stream context array may be bigger than
683 * the number of streams the driver asked for
684 */
685 struct xhci_stream_ctx *stream_ctx_array;
686 unsigned int num_stream_ctxs;
687 dma_addr_t ctx_array_dma;
688 /* For mapping physical TRB addresses to segments in stream rings */
689 struct radix_tree_root trb_address_map;
690 struct xhci_command *free_streams_command;
691};
692
693#define SMALL_STREAM_ARRAY_SIZE 256
694#define MEDIUM_STREAM_ARRAY_SIZE 1024
695
651struct xhci_virt_ep { 696struct xhci_virt_ep {
652 struct xhci_ring *ring; 697 struct xhci_ring *ring;
698 /* Related to endpoints that are configured to use stream IDs only */
699 struct xhci_stream_info *stream_info;
653 /* Temporary storage in case the configure endpoint command fails and we 700 /* Temporary storage in case the configure endpoint command fails and we
654 * have to restore the device state to the previous state 701 * have to restore the device state to the previous state
655 */ 702 */
@@ -658,11 +705,17 @@ struct xhci_virt_ep {
658#define SET_DEQ_PENDING (1 << 0) 705#define SET_DEQ_PENDING (1 << 0)
659#define EP_HALTED (1 << 1) /* For stall handling */ 706#define EP_HALTED (1 << 1) /* For stall handling */
660#define EP_HALT_PENDING (1 << 2) /* For URB cancellation */ 707#define EP_HALT_PENDING (1 << 2) /* For URB cancellation */
708/* Transitioning the endpoint to using streams, don't enqueue URBs */
709#define EP_GETTING_STREAMS (1 << 3)
710#define EP_HAS_STREAMS (1 << 4)
711/* Transitioning the endpoint to not using streams, don't enqueue URBs */
712#define EP_GETTING_NO_STREAMS (1 << 5)
661 /* ---- Related to URB cancellation ---- */ 713 /* ---- Related to URB cancellation ---- */
662 struct list_head cancelled_td_list; 714 struct list_head cancelled_td_list;
663 /* The TRB that was last reported in a stopped endpoint ring */ 715 /* The TRB that was last reported in a stopped endpoint ring */
664 union xhci_trb *stopped_trb; 716 union xhci_trb *stopped_trb;
665 struct xhci_td *stopped_td; 717 struct xhci_td *stopped_td;
718 unsigned int stopped_stream;
666 /* Watchdog timer for stop endpoint command to cancel URBs */ 719 /* Watchdog timer for stop endpoint command to cancel URBs */
667 struct timer_list stop_cmd_timer; 720 struct timer_list stop_cmd_timer;
668 int stop_cmds_pending; 721 int stop_cmds_pending;
@@ -710,14 +763,6 @@ struct xhci_device_context_array {
710 */ 763 */
711 764
712 765
713struct xhci_stream_ctx {
714 /* 64-bit stream ring address, cycle state, and stream type */
715 u64 stream_ring;
716 /* offset 0x14 - 0x1f reserved for HC internal use */
717 u32 reserved[2];
718};
719
720
721struct xhci_transfer_event { 766struct xhci_transfer_event {
722 /* 64-bit buffer address, or immediate data */ 767 /* 64-bit buffer address, or immediate data */
723 u64 buffer; 768 u64 buffer;
@@ -828,6 +873,10 @@ struct xhci_event_cmd {
828#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1) 873#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
829#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16) 874#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
830 875
876/* Set TR Dequeue Pointer command TRB fields */
877#define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16))
878#define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16)
879
831 880
832/* Port Status Change Event TRB fields */ 881/* Port Status Change Event TRB fields */
833/* Port ID - bits 31:24 */ 882/* Port ID - bits 31:24 */
@@ -952,6 +1001,10 @@ union xhci_trb {
952/* Allow two commands + a link TRB, along with any reserved command TRBs */ 1001/* Allow two commands + a link TRB, along with any reserved command TRBs */
953#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) 1002#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
954#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 1003#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
1004/* SEGMENT_SHIFT should be log2(SEGMENT_SIZE).
1005 * Change this if you change TRBS_PER_SEGMENT!
1006 */
1007#define SEGMENT_SHIFT 10
955/* TRB buffer pointers can't cross 64KB boundaries */ 1008/* TRB buffer pointers can't cross 64KB boundaries */
956#define TRB_MAX_BUFF_SHIFT 16 1009#define TRB_MAX_BUFF_SHIFT 16
957#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT) 1010#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
@@ -993,6 +1046,7 @@ struct xhci_ring {
993 * if we own the TRB (if we are the consumer). See section 4.9.1. 1046 * if we own the TRB (if we are the consumer). See section 4.9.1.
994 */ 1047 */
995 u32 cycle_state; 1048 u32 cycle_state;
1049 unsigned int stream_id;
996}; 1050};
997 1051
998struct xhci_erst_entry { 1052struct xhci_erst_entry {
@@ -1088,6 +1142,8 @@ struct xhci_hcd {
1088 /* DMA pools */ 1142 /* DMA pools */
1089 struct dma_pool *device_pool; 1143 struct dma_pool *device_pool;
1090 struct dma_pool *segment_pool; 1144 struct dma_pool *segment_pool;
1145 struct dma_pool *small_streams_pool;
1146 struct dma_pool *medium_streams_pool;
1091 1147
1092#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING 1148#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1093 /* Poll the rings - for debugging */ 1149 /* Poll the rings - for debugging */
@@ -1216,6 +1272,9 @@ void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
1216void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); 1272void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep);
1217char *xhci_get_slot_state(struct xhci_hcd *xhci, 1273char *xhci_get_slot_state(struct xhci_hcd *xhci,
1218 struct xhci_container_ctx *ctx); 1274 struct xhci_container_ctx *ctx);
1275void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
1276 unsigned int slot_id, unsigned int ep_index,
1277 struct xhci_virt_ep *ep);
1219 1278
1220/* xHCI memory management */ 1279/* xHCI memory management */
1221void xhci_mem_cleanup(struct xhci_hcd *xhci); 1280void xhci_mem_cleanup(struct xhci_hcd *xhci);
@@ -1242,6 +1301,29 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
1242void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci, 1301void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
1243 struct xhci_virt_device *virt_dev, 1302 struct xhci_virt_device *virt_dev,
1244 unsigned int ep_index); 1303 unsigned int ep_index);
1304struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
1305 unsigned int num_stream_ctxs,
1306 unsigned int num_streams, gfp_t flags);
1307void xhci_free_stream_info(struct xhci_hcd *xhci,
1308 struct xhci_stream_info *stream_info);
1309void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
1310 struct xhci_ep_ctx *ep_ctx,
1311 struct xhci_stream_info *stream_info);
1312void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
1313 struct xhci_ep_ctx *ep_ctx,
1314 struct xhci_virt_ep *ep);
1315struct xhci_ring *xhci_dma_to_transfer_ring(
1316 struct xhci_virt_ep *ep,
1317 u64 address);
1318struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
1319 struct urb *urb);
1320struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
1321 unsigned int slot_id, unsigned int ep_index,
1322 unsigned int stream_id);
1323struct xhci_ring *xhci_stream_id_to_ring(
1324 struct xhci_virt_device *dev,
1325 unsigned int ep_index,
1326 unsigned int stream_id);
1245struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 1327struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1246 bool allocate_in_ctx, bool allocate_completion, 1328 bool allocate_in_ctx, bool allocate_completion,
1247 gfp_t mem_flags); 1329 gfp_t mem_flags);
@@ -1266,6 +1348,12 @@ int xhci_get_frame(struct usb_hcd *hcd);
1266irqreturn_t xhci_irq(struct usb_hcd *hcd); 1348irqreturn_t xhci_irq(struct usb_hcd *hcd);
1267int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev); 1349int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1268void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev); 1350void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1351int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
1352 struct usb_host_endpoint **eps, unsigned int num_eps,
1353 unsigned int num_streams, gfp_t mem_flags);
1354int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1355 struct usb_host_endpoint **eps, unsigned int num_eps,
1356 gfp_t mem_flags);
1269int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev); 1357int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
1270int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, 1358int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1271 struct usb_tt *tt, gfp_t mem_flags); 1359 struct usb_tt *tt, gfp_t mem_flags);
@@ -1308,9 +1396,11 @@ int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1308int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); 1396int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
1309void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, 1397void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
1310 unsigned int slot_id, unsigned int ep_index, 1398 unsigned int slot_id, unsigned int ep_index,
1311 struct xhci_td *cur_td, struct xhci_dequeue_state *state); 1399 unsigned int stream_id, struct xhci_td *cur_td,
1400 struct xhci_dequeue_state *state);
1312void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, 1401void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
1313 unsigned int slot_id, unsigned int ep_index, 1402 unsigned int slot_id, unsigned int ep_index,
1403 unsigned int stream_id,
1314 struct xhci_dequeue_state *deq_state); 1404 struct xhci_dequeue_state *deq_state);
1315void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, 1405void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1316 struct usb_device *udev, unsigned int ep_index); 1406 struct usb_device *udev, unsigned int ep_index);
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 094f91cbc578..1fa6ce3e4a23 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -259,7 +259,7 @@ static int appledisplay_probe(struct usb_interface *iface,
259 } 259 }
260 260
261 /* Allocate buffer for interrupt data */ 261 /* Allocate buffer for interrupt data */
262 pdata->urbdata = usb_buffer_alloc(pdata->udev, ACD_URB_BUFFER_LEN, 262 pdata->urbdata = usb_alloc_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
263 GFP_KERNEL, &pdata->urb->transfer_dma); 263 GFP_KERNEL, &pdata->urb->transfer_dma);
264 if (!pdata->urbdata) { 264 if (!pdata->urbdata) {
265 retval = -ENOMEM; 265 retval = -ENOMEM;
@@ -316,7 +316,7 @@ error:
316 if (pdata->urb) { 316 if (pdata->urb) {
317 usb_kill_urb(pdata->urb); 317 usb_kill_urb(pdata->urb);
318 if (pdata->urbdata) 318 if (pdata->urbdata)
319 usb_buffer_free(pdata->udev, ACD_URB_BUFFER_LEN, 319 usb_free_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
320 pdata->urbdata, pdata->urb->transfer_dma); 320 pdata->urbdata, pdata->urb->transfer_dma);
321 usb_free_urb(pdata->urb); 321 usb_free_urb(pdata->urb);
322 } 322 }
@@ -337,7 +337,7 @@ static void appledisplay_disconnect(struct usb_interface *iface)
337 usb_kill_urb(pdata->urb); 337 usb_kill_urb(pdata->urb);
338 cancel_delayed_work(&pdata->work); 338 cancel_delayed_work(&pdata->work);
339 backlight_device_unregister(pdata->bd); 339 backlight_device_unregister(pdata->bd);
340 usb_buffer_free(pdata->udev, ACD_URB_BUFFER_LEN, 340 usb_free_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
341 pdata->urbdata, pdata->urb->transfer_dma); 341 pdata->urbdata, pdata->urb->transfer_dma);
342 usb_free_urb(pdata->urb); 342 usb_free_urb(pdata->urb);
343 kfree(pdata->msgdata); 343 kfree(pdata->msgdata);
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 1edb6d361896..82e16630a78b 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -73,7 +73,7 @@ static struct list_head ftdi_static_list;
73*/ 73*/
74#include "usb_u132.h" 74#include "usb_u132.h"
75#include <asm/io.h> 75#include <asm/io.h>
76#include "../core/hcd.h" 76#include <linux/usb/hcd.h>
77 77
78 /* FIXME ohci.h is ONLY for internal use by the OHCI driver. 78 /* FIXME ohci.h is ONLY for internal use by the OHCI driver.
79 * If you're going to try stuff like this, you need to split 79 * If you're going to try stuff like this, you need to split
@@ -734,7 +734,7 @@ static void ftdi_elan_write_bulk_callback(struct urb *urb)
734 dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %" 734 dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %"
735 "d\n", urb, status); 735 "d\n", urb, status);
736 } 736 }
737 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 737 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
738 urb->transfer_buffer, urb->transfer_dma); 738 urb->transfer_buffer, urb->transfer_dma);
739} 739}
740 740
@@ -795,7 +795,7 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
795 total_size); 795 total_size);
796 return -ENOMEM; 796 return -ENOMEM;
797 } 797 }
798 buf = usb_buffer_alloc(ftdi->udev, total_size, GFP_KERNEL, 798 buf = usb_alloc_coherent(ftdi->udev, total_size, GFP_KERNEL,
799 &urb->transfer_dma); 799 &urb->transfer_dma);
800 if (!buf) { 800 if (!buf) {
801 dev_err(&ftdi->udev->dev, "could not get a buffer to write %d c" 801 dev_err(&ftdi->udev->dev, "could not get a buffer to write %d c"
@@ -829,7 +829,7 @@ static int ftdi_elan_command_engine(struct usb_ftdi *ftdi)
829 dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write " 829 dev_err(&ftdi->udev->dev, "failed %d to submit urb %p to write "
830 "%d commands totaling %d bytes to the Uxxx\n", retval, 830 "%d commands totaling %d bytes to the Uxxx\n", retval,
831 urb, command_size, total_size); 831 urb, command_size, total_size);
832 usb_buffer_free(ftdi->udev, total_size, buf, urb->transfer_dma); 832 usb_free_coherent(ftdi->udev, total_size, buf, urb->transfer_dma);
833 usb_free_urb(urb); 833 usb_free_urb(urb);
834 return retval; 834 return retval;
835 } 835 }
@@ -1167,7 +1167,7 @@ static ssize_t ftdi_elan_write(struct file *file,
1167 retval = -ENOMEM; 1167 retval = -ENOMEM;
1168 goto error_1; 1168 goto error_1;
1169 } 1169 }
1170 buf = usb_buffer_alloc(ftdi->udev, count, GFP_KERNEL, 1170 buf = usb_alloc_coherent(ftdi->udev, count, GFP_KERNEL,
1171 &urb->transfer_dma); 1171 &urb->transfer_dma);
1172 if (!buf) { 1172 if (!buf) {
1173 retval = -ENOMEM; 1173 retval = -ENOMEM;
@@ -1192,7 +1192,7 @@ static ssize_t ftdi_elan_write(struct file *file,
1192exit: 1192exit:
1193 return count; 1193 return count;
1194error_3: 1194error_3:
1195 usb_buffer_free(ftdi->udev, count, buf, urb->transfer_dma); 1195 usb_free_coherent(ftdi->udev, count, buf, urb->transfer_dma);
1196error_2: 1196error_2:
1197 usb_free_urb(urb); 1197 usb_free_urb(urb);
1198error_1: 1198error_1:
@@ -1968,7 +1968,7 @@ static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi)
1968 "ence\n"); 1968 "ence\n");
1969 return -ENOMEM; 1969 return -ENOMEM;
1970 } 1970 }
1971 buf = usb_buffer_alloc(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); 1971 buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
1972 if (!buf) { 1972 if (!buf) {
1973 dev_err(&ftdi->udev->dev, "could not get a buffer for flush seq" 1973 dev_err(&ftdi->udev->dev, "could not get a buffer for flush seq"
1974 "uence\n"); 1974 "uence\n");
@@ -1985,7 +1985,7 @@ static int ftdi_elan_synchronize_flush(struct usb_ftdi *ftdi)
1985 if (retval) { 1985 if (retval) {
1986 dev_err(&ftdi->udev->dev, "failed to submit urb containing the " 1986 dev_err(&ftdi->udev->dev, "failed to submit urb containing the "
1987 "flush sequence\n"); 1987 "flush sequence\n");
1988 usb_buffer_free(ftdi->udev, i, buf, urb->transfer_dma); 1988 usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma);
1989 usb_free_urb(urb); 1989 usb_free_urb(urb);
1990 return -ENOMEM; 1990 return -ENOMEM;
1991 } 1991 }
@@ -2011,7 +2011,7 @@ static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi)
2011 "quence\n"); 2011 "quence\n");
2012 return -ENOMEM; 2012 return -ENOMEM;
2013 } 2013 }
2014 buf = usb_buffer_alloc(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma); 2014 buf = usb_alloc_coherent(ftdi->udev, I, GFP_KERNEL, &urb->transfer_dma);
2015 if (!buf) { 2015 if (!buf) {
2016 dev_err(&ftdi->udev->dev, "could not get a buffer for the reset" 2016 dev_err(&ftdi->udev->dev, "could not get a buffer for the reset"
2017 " sequence\n"); 2017 " sequence\n");
@@ -2030,7 +2030,7 @@ static int ftdi_elan_synchronize_reset(struct usb_ftdi *ftdi)
2030 if (retval) { 2030 if (retval) {
2031 dev_err(&ftdi->udev->dev, "failed to submit urb containing the " 2031 dev_err(&ftdi->udev->dev, "failed to submit urb containing the "
2032 "reset sequence\n"); 2032 "reset sequence\n");
2033 usb_buffer_free(ftdi->udev, i, buf, urb->transfer_dma); 2033 usb_free_coherent(ftdi->udev, i, buf, urb->transfer_dma);
2034 usb_free_urb(urb); 2034 usb_free_urb(urb);
2035 return -ENOMEM; 2035 return -ENOMEM;
2036 } 2036 }
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index d3c852363883..7dc9d3c69984 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -239,8 +239,8 @@ static void iowarrior_write_callback(struct urb *urb)
239 __func__, status); 239 __func__, status);
240 } 240 }
241 /* free up our allocated buffer */ 241 /* free up our allocated buffer */
242 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 242 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
243 urb->transfer_buffer, urb->transfer_dma); 243 urb->transfer_buffer, urb->transfer_dma);
244 /* tell a waiting writer the interrupt-out-pipe is available again */ 244 /* tell a waiting writer the interrupt-out-pipe is available again */
245 atomic_dec(&dev->write_busy); 245 atomic_dec(&dev->write_busy);
246 wake_up_interruptible(&dev->write_wait); 246 wake_up_interruptible(&dev->write_wait);
@@ -421,8 +421,8 @@ static ssize_t iowarrior_write(struct file *file,
421 dbg("%s Unable to allocate urb ", __func__); 421 dbg("%s Unable to allocate urb ", __func__);
422 goto error_no_urb; 422 goto error_no_urb;
423 } 423 }
424 buf = usb_buffer_alloc(dev->udev, dev->report_size, 424 buf = usb_alloc_coherent(dev->udev, dev->report_size,
425 GFP_KERNEL, &int_out_urb->transfer_dma); 425 GFP_KERNEL, &int_out_urb->transfer_dma);
426 if (!buf) { 426 if (!buf) {
427 retval = -ENOMEM; 427 retval = -ENOMEM;
428 dbg("%s Unable to allocate buffer ", __func__); 428 dbg("%s Unable to allocate buffer ", __func__);
@@ -459,8 +459,8 @@ static ssize_t iowarrior_write(struct file *file,
459 break; 459 break;
460 } 460 }
461error: 461error:
462 usb_buffer_free(dev->udev, dev->report_size, buf, 462 usb_free_coherent(dev->udev, dev->report_size, buf,
463 int_out_urb->transfer_dma); 463 int_out_urb->transfer_dma);
464error_no_buffer: 464error_no_buffer:
465 usb_free_urb(int_out_urb); 465 usb_free_urb(int_out_urb);
466error_no_urb: 466error_no_urb:
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index aae95a009bd5..30d930386b65 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -47,7 +47,6 @@
47#include <linux/spinlock.h> 47#include <linux/spinlock.h>
48#include <linux/kref.h> 48#include <linux/kref.h>
49#include <linux/usb.h> 49#include <linux/usb.h>
50#include <linux/smp_lock.h>
51#include <linux/vmalloc.h> 50#include <linux/vmalloc.h>
52 51
53#include "sisusb.h" 52#include "sisusb.h"
@@ -2416,14 +2415,11 @@ sisusb_open(struct inode *inode, struct file *file)
2416 struct usb_interface *interface; 2415 struct usb_interface *interface;
2417 int subminor = iminor(inode); 2416 int subminor = iminor(inode);
2418 2417
2419 lock_kernel();
2420 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) { 2418 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) {
2421 unlock_kernel();
2422 return -ENODEV; 2419 return -ENODEV;
2423 } 2420 }
2424 2421
2425 if (!(sisusb = usb_get_intfdata(interface))) { 2422 if (!(sisusb = usb_get_intfdata(interface))) {
2426 unlock_kernel();
2427 return -ENODEV; 2423 return -ENODEV;
2428 } 2424 }
2429 2425
@@ -2431,13 +2427,11 @@ sisusb_open(struct inode *inode, struct file *file)
2431 2427
2432 if (!sisusb->present || !sisusb->ready) { 2428 if (!sisusb->present || !sisusb->ready) {
2433 mutex_unlock(&sisusb->lock); 2429 mutex_unlock(&sisusb->lock);
2434 unlock_kernel();
2435 return -ENODEV; 2430 return -ENODEV;
2436 } 2431 }
2437 2432
2438 if (sisusb->isopen) { 2433 if (sisusb->isopen) {
2439 mutex_unlock(&sisusb->lock); 2434 mutex_unlock(&sisusb->lock);
2440 unlock_kernel();
2441 return -EBUSY; 2435 return -EBUSY;
2442 } 2436 }
2443 2437
@@ -2446,13 +2440,11 @@ sisusb_open(struct inode *inode, struct file *file)
2446 if (sisusb_init_gfxdevice(sisusb, 0)) { 2440 if (sisusb_init_gfxdevice(sisusb, 0)) {
2447 mutex_unlock(&sisusb->lock); 2441 mutex_unlock(&sisusb->lock);
2448 dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n"); 2442 dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n");
2449 unlock_kernel();
2450 return -EIO; 2443 return -EIO;
2451 } 2444 }
2452 } else { 2445 } else {
2453 mutex_unlock(&sisusb->lock); 2446 mutex_unlock(&sisusb->lock);
2454 dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n"); 2447 dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n");
2455 unlock_kernel();
2456 return -EIO; 2448 return -EIO;
2457 } 2449 }
2458 } 2450 }
@@ -2465,7 +2457,6 @@ sisusb_open(struct inode *inode, struct file *file)
2465 file->private_data = sisusb; 2457 file->private_data = sisusb;
2466 2458
2467 mutex_unlock(&sisusb->lock); 2459 mutex_unlock(&sisusb->lock);
2468 unlock_kernel();
2469 2460
2470 return 0; 2461 return 0;
2471} 2462}
@@ -2974,13 +2965,12 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2974 struct sisusb_usb_data *sisusb; 2965 struct sisusb_usb_data *sisusb;
2975 struct sisusb_info x; 2966 struct sisusb_info x;
2976 struct sisusb_command y; 2967 struct sisusb_command y;
2977 int retval = 0; 2968 long retval = 0;
2978 u32 __user *argp = (u32 __user *)arg; 2969 u32 __user *argp = (u32 __user *)arg;
2979 2970
2980 if (!(sisusb = (struct sisusb_usb_data *)file->private_data)) 2971 if (!(sisusb = (struct sisusb_usb_data *)file->private_data))
2981 return -ENODEV; 2972 return -ENODEV;
2982 2973
2983 lock_kernel();
2984 mutex_lock(&sisusb->lock); 2974 mutex_lock(&sisusb->lock);
2985 2975
2986 /* Sanity check */ 2976 /* Sanity check */
@@ -3039,7 +3029,6 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3039 3029
3040err_out: 3030err_out:
3041 mutex_unlock(&sisusb->lock); 3031 mutex_unlock(&sisusb->lock);
3042 unlock_kernel();
3043 return retval; 3032 return retval;
3044} 3033}
3045 3034
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
index b271b0557a1f..411e605f448a 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -1187,9 +1187,9 @@ sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1187 * And so is the hi_font_mask. 1187 * And so is the hi_font_mask.
1188 */ 1188 */
1189 for (i = 0; i < MAX_NR_CONSOLES; i++) { 1189 for (i = 0; i < MAX_NR_CONSOLES; i++) {
1190 struct vc_data *c = vc_cons[i].d; 1190 struct vc_data *d = vc_cons[i].d;
1191 if (c && c->vc_sw == &sisusb_con) 1191 if (d && d->vc_sw == &sisusb_con)
1192 c->vc_hi_font_mask = ch512 ? 0x0800 : 0; 1192 d->vc_hi_font_mask = ch512 ? 0x0800 : 0;
1193 } 1193 }
1194 1194
1195 sisusb->current_font_512 = ch512; 1195 sisusb->current_font_512 = ch512;
@@ -1249,7 +1249,7 @@ sisusbcon_do_font_op(struct sisusb_usb_data *sisusb, int set, int slot,
1249 mutex_unlock(&sisusb->lock); 1249 mutex_unlock(&sisusb->lock);
1250 1250
1251 if (dorecalc && c) { 1251 if (dorecalc && c) {
1252 int i, rows = c->vc_scan_lines / fh; 1252 int rows = c->vc_scan_lines / fh;
1253 1253
1254 /* Now adjust our consoles' size */ 1254 /* Now adjust our consoles' size */
1255 1255
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 90aede90553e..7828c764b323 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -205,8 +205,8 @@ static void lcd_write_bulk_callback(struct urb *urb)
205 } 205 }
206 206
207 /* free up our allocated buffer */ 207 /* free up our allocated buffer */
208 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 208 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
209 urb->transfer_buffer, urb->transfer_dma); 209 urb->transfer_buffer, urb->transfer_dma);
210 up(&dev->limit_sem); 210 up(&dev->limit_sem);
211} 211}
212 212
@@ -234,7 +234,7 @@ static ssize_t lcd_write(struct file *file, const char __user * user_buffer, siz
234 goto err_no_buf; 234 goto err_no_buf;
235 } 235 }
236 236
237 buf = usb_buffer_alloc(dev->udev, count, GFP_KERNEL, &urb->transfer_dma); 237 buf = usb_alloc_coherent(dev->udev, count, GFP_KERNEL, &urb->transfer_dma);
238 if (!buf) { 238 if (!buf) {
239 retval = -ENOMEM; 239 retval = -ENOMEM;
240 goto error; 240 goto error;
@@ -268,7 +268,7 @@ exit:
268error_unanchor: 268error_unanchor:
269 usb_unanchor_urb(urb); 269 usb_unanchor_urb(urb);
270error: 270error:
271 usb_buffer_free(dev->udev, count, buf, urb->transfer_dma); 271 usb_free_coherent(dev->udev, count, buf, urb->transfer_dma);
272 usb_free_urb(urb); 272 usb_free_urb(urb);
273err_no_buf: 273err_no_buf:
274 up(&dev->limit_sem); 274 up(&dev->limit_sem);
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index a21cce6f7403..16dffe99d9f1 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -202,7 +202,7 @@ static struct urb *simple_alloc_urb (
202 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 202 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
203 if (usb_pipein (pipe)) 203 if (usb_pipein (pipe))
204 urb->transfer_flags |= URB_SHORT_NOT_OK; 204 urb->transfer_flags |= URB_SHORT_NOT_OK;
205 urb->transfer_buffer = usb_buffer_alloc (udev, bytes, GFP_KERNEL, 205 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL,
206 &urb->transfer_dma); 206 &urb->transfer_dma);
207 if (!urb->transfer_buffer) { 207 if (!urb->transfer_buffer) {
208 usb_free_urb (urb); 208 usb_free_urb (urb);
@@ -272,8 +272,8 @@ static inline int simple_check_buf(struct usbtest_dev *tdev, struct urb *urb)
272 272
273static void simple_free_urb (struct urb *urb) 273static void simple_free_urb (struct urb *urb)
274{ 274{
275 usb_buffer_free (urb->dev, urb->transfer_buffer_length, 275 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
276 urb->transfer_buffer, urb->transfer_dma); 276 urb->transfer_buffer, urb->transfer_dma);
277 usb_free_urb (urb); 277 usb_free_urb (urb);
278} 278}
279 279
@@ -977,15 +977,13 @@ test_ctrl_queue (struct usbtest_dev *dev, struct usbtest_param *param)
977 if (!u) 977 if (!u)
978 goto cleanup; 978 goto cleanup;
979 979
980 reqp = usb_buffer_alloc (udev, sizeof *reqp, GFP_KERNEL, 980 reqp = kmalloc(sizeof *reqp, GFP_KERNEL);
981 &u->setup_dma);
982 if (!reqp) 981 if (!reqp)
983 goto cleanup; 982 goto cleanup;
984 reqp->setup = req; 983 reqp->setup = req;
985 reqp->number = i % NUM_SUBCASES; 984 reqp->number = i % NUM_SUBCASES;
986 reqp->expected = expected; 985 reqp->expected = expected;
987 u->setup_packet = (char *) &reqp->setup; 986 u->setup_packet = (char *) &reqp->setup;
988 u->transfer_flags |= URB_NO_SETUP_DMA_MAP;
989 987
990 u->context = &context; 988 u->context = &context;
991 u->complete = ctrl_complete; 989 u->complete = ctrl_complete;
@@ -1017,10 +1015,7 @@ cleanup:
1017 if (!urb [i]) 1015 if (!urb [i])
1018 continue; 1016 continue;
1019 urb [i]->dev = udev; 1017 urb [i]->dev = udev;
1020 if (urb [i]->setup_packet) 1018 kfree(urb[i]->setup_packet);
1021 usb_buffer_free (udev, sizeof (struct usb_ctrlrequest),
1022 urb [i]->setup_packet,
1023 urb [i]->setup_dma);
1024 simple_free_urb (urb [i]); 1019 simple_free_urb (urb [i]);
1025 } 1020 }
1026 kfree (urb); 1021 kfree (urb);
@@ -1421,7 +1416,7 @@ static struct urb *iso_alloc_urb (
1421 1416
1422 urb->number_of_packets = packets; 1417 urb->number_of_packets = packets;
1423 urb->transfer_buffer_length = bytes; 1418 urb->transfer_buffer_length = bytes;
1424 urb->transfer_buffer = usb_buffer_alloc (udev, bytes, GFP_KERNEL, 1419 urb->transfer_buffer = usb_alloc_coherent (udev, bytes, GFP_KERNEL,
1425 &urb->transfer_dma); 1420 &urb->transfer_dma);
1426 if (!urb->transfer_buffer) { 1421 if (!urb->transfer_buffer) {
1427 usb_free_urb (urb); 1422 usb_free_urb (urb);
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index ddf7f9a1b336..e7fa3644ba6a 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -416,13 +416,13 @@ static unsigned int mon_bin_get_data(const struct mon_reader_bin *rp,
416 416
417 } else { 417 } else {
418 /* If IOMMU coalescing occurred, we cannot trust sg_page */ 418 /* If IOMMU coalescing occurred, we cannot trust sg_page */
419 if (urb->sg->nents != urb->num_sgs) { 419 if (urb->transfer_flags & URB_DMA_SG_COMBINED) {
420 *flag = 'D'; 420 *flag = 'D';
421 return length; 421 return length;
422 } 422 }
423 423
424 /* Copy up to the first non-addressable segment */ 424 /* Copy up to the first non-addressable segment */
425 for_each_sg(urb->sg->sg, sg, urb->num_sgs, i) { 425 for_each_sg(urb->sg, sg, urb->num_sgs, i) {
426 if (length == 0 || PageHighMem(sg_page(sg))) 426 if (length == 0 || PageHighMem(sg_page(sg)))
427 break; 427 break;
428 this_len = min_t(unsigned int, sg->length, length); 428 this_len = min_t(unsigned int, sg->length, length);
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index e4af18b93c7d..812dc288bb8c 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -9,12 +9,13 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/usb/hcd.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/notifier.h> 14#include <linux/notifier.h>
14#include <linux/mutex.h> 15#include <linux/mutex.h>
15 16
16#include "usb_mon.h" 17#include "usb_mon.h"
17#include "../core/hcd.h" 18
18 19
19static void mon_stop(struct mon_bus *mbus); 20static void mon_stop(struct mon_bus *mbus);
20static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus); 21static void mon_dissolve(struct mon_bus *mbus, struct usb_bus *ubus);
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 4d0be130f49b..a545d65f6e57 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -159,11 +159,9 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
159 if (src == NULL) 159 if (src == NULL)
160 return 'Z'; /* '0' would be not as pretty. */ 160 return 'Z'; /* '0' would be not as pretty. */
161 } else { 161 } else {
162 struct scatterlist *sg = urb->sg->sg; 162 struct scatterlist *sg = urb->sg;
163 163
164 /* If IOMMU coalescing occurred, we cannot trust sg_page */ 164 if (PageHighMem(sg_page(sg)))
165 if (urb->sg->nents != urb->num_sgs ||
166 PageHighMem(sg_page(sg)))
167 return 'D'; 165 return 'D';
168 166
169 /* For the text interface we copy only the first sg buffer */ 167 /* For the text interface we copy only the first sg buffer */
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 07fe490b44d8..cfd38edfcf9e 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -38,6 +38,7 @@ config USB_MUSB_SOC
38 default y if ARCH_DAVINCI 38 default y if ARCH_DAVINCI
39 default y if ARCH_OMAP2430 39 default y if ARCH_OMAP2430
40 default y if ARCH_OMAP3 40 default y if ARCH_OMAP3
41 default y if ARCH_OMAP4
41 default y if (BF54x && !BF544) 42 default y if (BF54x && !BF544)
42 default y if (BF52x && !BF522 && !BF523) 43 default y if (BF52x && !BF522 && !BF523)
43 44
@@ -50,6 +51,9 @@ comment "OMAP 243x high speed USB support"
50comment "OMAP 343x high speed USB support" 51comment "OMAP 343x high speed USB support"
51 depends on USB_MUSB_HDRC && ARCH_OMAP3 52 depends on USB_MUSB_HDRC && ARCH_OMAP3
52 53
54comment "OMAP 44xx high speed USB support"
55 depends on USB_MUSB_HDRC && ARCH_OMAP4
56
53comment "Blackfin high speed USB Support" 57comment "Blackfin high speed USB Support"
54 depends on USB_MUSB_HDRC && ((BF54x && !BF544) || (BF52x && !BF522 && !BF523)) 58 depends on USB_MUSB_HDRC && ((BF54x && !BF544) || (BF52x && !BF522 && !BF523))
55 59
@@ -153,7 +157,7 @@ config MUSB_PIO_ONLY
153config USB_INVENTRA_DMA 157config USB_INVENTRA_DMA
154 bool 158 bool
155 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY 159 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
156 default ARCH_OMAP2430 || ARCH_OMAP3 || BLACKFIN 160 default ARCH_OMAP2430 || ARCH_OMAP3 || BLACKFIN || ARCH_OMAP4
157 help 161 help
158 Enable DMA transfers using Mentor's engine. 162 Enable DMA transfers using Mentor's engine.
159 163
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index 3a485dabebbb..9705f716386e 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -22,6 +22,10 @@ ifeq ($(CONFIG_ARCH_OMAP3430),y)
22 musb_hdrc-objs += omap2430.o 22 musb_hdrc-objs += omap2430.o
23endif 23endif
24 24
25ifeq ($(CONFIG_ARCH_OMAP4),y)
26 musb_hdrc-objs += omap2430.o
27endif
28
25ifeq ($(CONFIG_BF54x),y) 29ifeq ($(CONFIG_BF54x),y)
26 musb_hdrc-objs += blackfin.o 30 musb_hdrc-objs += blackfin.o
27endif 31endif
@@ -38,6 +42,10 @@ ifeq ($(CONFIG_USB_MUSB_HDRC_HCD),y)
38 musb_hdrc-objs += musb_virthub.o musb_host.o 42 musb_hdrc-objs += musb_virthub.o musb_host.o
39endif 43endif
40 44
45ifeq ($(CONFIG_DEBUG_FS),y)
46 musb_hdrc-objs += musb_debugfs.o
47endif
48
41# the kconfig must guarantee that only one of the 49# the kconfig must guarantee that only one of the
42# possible I/O schemes will be enabled at a time ... 50# possible I/O schemes will be enabled at a time ...
43# PIO only, or DMA (several potential schemes). 51# PIO only, or DMA (several potential schemes).
@@ -64,12 +72,6 @@ endif
64 72
65################################################################################ 73################################################################################
66 74
67# FIXME remove all these extra "-DMUSB_* things, stick to CONFIG_*
68
69ifeq ($(CONFIG_USB_INVENTRA_MUSB_HAS_AHB_ID),y)
70 EXTRA_CFLAGS += -DMUSB_AHB_ID
71endif
72
73# Debugging 75# Debugging
74 76
75ifeq ($(CONFIG_USB_MUSB_DEBUG),y) 77ifeq ($(CONFIG_USB_MUSB_DEBUG),y)
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index ec8d324237f6..b611420a8050 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -170,6 +170,13 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
170 retval = musb_interrupt(musb); 170 retval = musb_interrupt(musb);
171 } 171 }
172 172
173 /* Start sampling ID pin, when plug is removed from MUSB */
174 if (is_otg_enabled(musb) && (musb->xceiv->state == OTG_STATE_B_IDLE
175 || musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
176 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
177 musb->a_wait_bcon = TIMER_DELAY;
178 }
179
173 spin_unlock_irqrestore(&musb->lock, flags); 180 spin_unlock_irqrestore(&musb->lock, flags);
174 181
175 return retval; 182 return retval;
@@ -180,6 +187,7 @@ static void musb_conn_timer_handler(unsigned long _musb)
180 struct musb *musb = (void *)_musb; 187 struct musb *musb = (void *)_musb;
181 unsigned long flags; 188 unsigned long flags;
182 u16 val; 189 u16 val;
190 static u8 toggle;
183 191
184 spin_lock_irqsave(&musb->lock, flags); 192 spin_lock_irqsave(&musb->lock, flags);
185 switch (musb->xceiv->state) { 193 switch (musb->xceiv->state) {
@@ -187,10 +195,44 @@ static void musb_conn_timer_handler(unsigned long _musb)
187 case OTG_STATE_A_WAIT_BCON: 195 case OTG_STATE_A_WAIT_BCON:
188 /* Start a new session */ 196 /* Start a new session */
189 val = musb_readw(musb->mregs, MUSB_DEVCTL); 197 val = musb_readw(musb->mregs, MUSB_DEVCTL);
198 val &= ~MUSB_DEVCTL_SESSION;
199 musb_writew(musb->mregs, MUSB_DEVCTL, val);
190 val |= MUSB_DEVCTL_SESSION; 200 val |= MUSB_DEVCTL_SESSION;
191 musb_writew(musb->mregs, MUSB_DEVCTL, val); 201 musb_writew(musb->mregs, MUSB_DEVCTL, val);
202 /* Check if musb is host or peripheral. */
203 val = musb_readw(musb->mregs, MUSB_DEVCTL);
204
205 if (!(val & MUSB_DEVCTL_BDEVICE)) {
206 gpio_set_value(musb->config->gpio_vrsel, 1);
207 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
208 } else {
209 gpio_set_value(musb->config->gpio_vrsel, 0);
210 /* Ignore VBUSERROR and SUSPEND IRQ */
211 val = musb_readb(musb->mregs, MUSB_INTRUSBE);
212 val &= ~MUSB_INTR_VBUSERROR;
213 musb_writeb(musb->mregs, MUSB_INTRUSBE, val);
192 214
215 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR;
216 musb_writeb(musb->mregs, MUSB_INTRUSB, val);
217 if (is_otg_enabled(musb))
218 musb->xceiv->state = OTG_STATE_B_IDLE;
219 else
220 musb_writeb(musb->mregs, MUSB_POWER, MUSB_POWER_HSENAB);
221 }
222 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
223 break;
224 case OTG_STATE_B_IDLE:
225
226 if (!is_peripheral_enabled(musb))
227 break;
228 /* Start a new session. It seems that MUSB needs taking
229 * some time to recognize the type of the plug inserted?
230 */
231 val = musb_readw(musb->mregs, MUSB_DEVCTL);
232 val |= MUSB_DEVCTL_SESSION;
233 musb_writew(musb->mregs, MUSB_DEVCTL, val);
193 val = musb_readw(musb->mregs, MUSB_DEVCTL); 234 val = musb_readw(musb->mregs, MUSB_DEVCTL);
235
194 if (!(val & MUSB_DEVCTL_BDEVICE)) { 236 if (!(val & MUSB_DEVCTL_BDEVICE)) {
195 gpio_set_value(musb->config->gpio_vrsel, 1); 237 gpio_set_value(musb->config->gpio_vrsel, 1);
196 musb->xceiv->state = OTG_STATE_A_WAIT_BCON; 238 musb->xceiv->state = OTG_STATE_A_WAIT_BCON;
@@ -205,12 +247,27 @@ static void musb_conn_timer_handler(unsigned long _musb)
205 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR; 247 val = MUSB_INTR_SUSPEND | MUSB_INTR_VBUSERROR;
206 musb_writeb(musb->mregs, MUSB_INTRUSB, val); 248 musb_writeb(musb->mregs, MUSB_INTRUSB, val);
207 249
208 val = MUSB_POWER_HSENAB; 250 /* Toggle the Soft Conn bit, so that we can response to
209 musb_writeb(musb->mregs, MUSB_POWER, val); 251 * the inserting of either A-plug or B-plug.
252 */
253 if (toggle) {
254 val = musb_readb(musb->mregs, MUSB_POWER);
255 val &= ~MUSB_POWER_SOFTCONN;
256 musb_writeb(musb->mregs, MUSB_POWER, val);
257 toggle = 0;
258 } else {
259 val = musb_readb(musb->mregs, MUSB_POWER);
260 val |= MUSB_POWER_SOFTCONN;
261 musb_writeb(musb->mregs, MUSB_POWER, val);
262 toggle = 1;
263 }
264 /* The delay time is set to 1/4 second by default,
265 * shortening it, if accelerating A-plug detection
266 * is needed in OTG mode.
267 */
268 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY / 4);
210 } 269 }
211 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
212 break; 270 break;
213
214 default: 271 default:
215 DBG(1, "%s state not handled\n", otg_state_string(musb)); 272 DBG(1, "%s state not handled\n", otg_state_string(musb));
216 break; 273 break;
@@ -222,7 +279,7 @@ static void musb_conn_timer_handler(unsigned long _musb)
222 279
223void musb_platform_enable(struct musb *musb) 280void musb_platform_enable(struct musb *musb)
224{ 281{
225 if (is_host_enabled(musb)) { 282 if (!is_otg_enabled(musb) && is_host_enabled(musb)) {
226 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 283 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
227 musb->a_wait_bcon = TIMER_DELAY; 284 musb->a_wait_bcon = TIMER_DELAY;
228 } 285 }
@@ -232,16 +289,12 @@ void musb_platform_disable(struct musb *musb)
232{ 289{
233} 290}
234 291
235static void bfin_vbus_power(struct musb *musb, int is_on, int sleeping)
236{
237}
238
239static void bfin_set_vbus(struct musb *musb, int is_on) 292static void bfin_set_vbus(struct musb *musb, int is_on)
240{ 293{
241 if (is_on) 294 int value = musb->config->gpio_vrsel_active;
242 gpio_set_value(musb->config->gpio_vrsel, 1); 295 if (!is_on)
243 else 296 value = !value;
244 gpio_set_value(musb->config->gpio_vrsel, 0); 297 gpio_set_value(musb->config->gpio_vrsel, value);
245 298
246 DBG(1, "VBUS %s, devctl %02x " 299 DBG(1, "VBUS %s, devctl %02x "
247 /* otg %3x conf %08x prcm %08x */ "\n", 300 /* otg %3x conf %08x prcm %08x */ "\n",
@@ -256,7 +309,7 @@ static int bfin_set_power(struct otg_transceiver *x, unsigned mA)
256 309
257void musb_platform_try_idle(struct musb *musb, unsigned long timeout) 310void musb_platform_try_idle(struct musb *musb, unsigned long timeout)
258{ 311{
259 if (is_host_enabled(musb)) 312 if (!is_otg_enabled(musb) && is_host_enabled(musb))
260 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY); 313 mod_timer(&musb_conn_timer, jiffies + TIMER_DELAY);
261} 314}
262 315
@@ -270,7 +323,7 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
270 return -EIO; 323 return -EIO;
271} 324}
272 325
273int __init musb_platform_init(struct musb *musb) 326int __init musb_platform_init(struct musb *musb, void *board_data)
274{ 327{
275 328
276 /* 329 /*
@@ -339,23 +392,10 @@ int __init musb_platform_init(struct musb *musb)
339 return 0; 392 return 0;
340} 393}
341 394
342int musb_platform_suspend(struct musb *musb)
343{
344 return 0;
345}
346
347int musb_platform_resume(struct musb *musb)
348{
349 return 0;
350}
351
352
353int musb_platform_exit(struct musb *musb) 395int musb_platform_exit(struct musb *musb)
354{ 396{
355 397
356 bfin_vbus_power(musb, 0 /*off*/, 1);
357 gpio_free(musb->config->gpio_vrsel); 398 gpio_free(musb->config->gpio_vrsel);
358 musb_platform_suspend(musb);
359 399
360 return 0; 400 return 0;
361} 401}
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index ce2e16fee0df..57624361c1de 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -376,7 +376,7 @@ int musb_platform_set_mode(struct musb *musb, u8 mode)
376 return -EIO; 376 return -EIO;
377} 377}
378 378
379int __init musb_platform_init(struct musb *musb) 379int __init musb_platform_init(struct musb *musb, void *board_data)
380{ 380{
381 void __iomem *tibase = musb->ctrl_base; 381 void __iomem *tibase = musb->ctrl_base;
382 u32 revision; 382 u32 revision;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 705cc4ad8737..fad70bc83555 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -149,6 +149,87 @@ static inline struct musb *dev_to_musb(struct device *dev)
149 149
150/*-------------------------------------------------------------------------*/ 150/*-------------------------------------------------------------------------*/
151 151
152#ifndef CONFIG_BLACKFIN
153static int musb_ulpi_read(struct otg_transceiver *otg, u32 offset)
154{
155 void __iomem *addr = otg->io_priv;
156 int i = 0;
157 u8 r;
158 u8 power;
159
160 /* Make sure the transceiver is not in low power mode */
161 power = musb_readb(addr, MUSB_POWER);
162 power &= ~MUSB_POWER_SUSPENDM;
163 musb_writeb(addr, MUSB_POWER, power);
164
165 /* REVISIT: musbhdrc_ulpi_an.pdf recommends setting the
166 * ULPICarKitControlDisableUTMI after clearing POWER_SUSPENDM.
167 */
168
169 musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)offset);
170 musb_writeb(addr, MUSB_ULPI_REG_CONTROL,
171 MUSB_ULPI_REG_REQ | MUSB_ULPI_RDN_WR);
172
173 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
174 & MUSB_ULPI_REG_CMPLT)) {
175 i++;
176 if (i == 10000) {
177 DBG(3, "ULPI read timed out\n");
178 return -ETIMEDOUT;
179 }
180
181 }
182 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
183 r &= ~MUSB_ULPI_REG_CMPLT;
184 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
185
186 return musb_readb(addr, MUSB_ULPI_REG_DATA);
187}
188
189static int musb_ulpi_write(struct otg_transceiver *otg,
190 u32 offset, u32 data)
191{
192 void __iomem *addr = otg->io_priv;
193 int i = 0;
194 u8 r = 0;
195 u8 power;
196
197 /* Make sure the transceiver is not in low power mode */
198 power = musb_readb(addr, MUSB_POWER);
199 power &= ~MUSB_POWER_SUSPENDM;
200 musb_writeb(addr, MUSB_POWER, power);
201
202 musb_writeb(addr, MUSB_ULPI_REG_ADDR, (u8)offset);
203 musb_writeb(addr, MUSB_ULPI_REG_DATA, (u8)data);
204 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, MUSB_ULPI_REG_REQ);
205
206 while (!(musb_readb(addr, MUSB_ULPI_REG_CONTROL)
207 & MUSB_ULPI_REG_CMPLT)) {
208 i++;
209 if (i == 10000) {
210 DBG(3, "ULPI write timed out\n");
211 return -ETIMEDOUT;
212 }
213 }
214
215 r = musb_readb(addr, MUSB_ULPI_REG_CONTROL);
216 r &= ~MUSB_ULPI_REG_CMPLT;
217 musb_writeb(addr, MUSB_ULPI_REG_CONTROL, r);
218
219 return 0;
220}
221#else
222#define musb_ulpi_read(a, b) NULL
223#define musb_ulpi_write(a, b, c) NULL
224#endif
225
226static struct otg_io_access_ops musb_ulpi_access = {
227 .read = musb_ulpi_read,
228 .write = musb_ulpi_write,
229};
230
231/*-------------------------------------------------------------------------*/
232
152#if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN) 233#if !defined(CONFIG_USB_TUSB6010) && !defined(CONFIG_BLACKFIN)
153 234
154/* 235/*
@@ -353,8 +434,7 @@ void musb_hnp_stop(struct musb *musb)
353 * which cause occasional OPT A "Did not receive reset after connect" 434 * which cause occasional OPT A "Did not receive reset after connect"
354 * errors. 435 * errors.
355 */ 436 */
356 musb->port1_status &= 437 musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16);
357 ~(1 << USB_PORT_FEAT_C_CONNECTION);
358} 438}
359 439
360#endif 440#endif
@@ -530,8 +610,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
530 musb_writeb(mbase, MUSB_DEVCTL, devctl); 610 musb_writeb(mbase, MUSB_DEVCTL, devctl);
531 } else { 611 } else {
532 musb->port1_status |= 612 musb->port1_status |=
533 (1 << USB_PORT_FEAT_OVER_CURRENT) 613 USB_PORT_STAT_OVERCURRENT
534 | (1 << USB_PORT_FEAT_C_OVER_CURRENT); 614 | (USB_PORT_STAT_C_OVERCURRENT << 16);
535 } 615 }
536 break; 616 break;
537 default: 617 default:
@@ -986,7 +1066,8 @@ static void musb_shutdown(struct platform_device *pdev)
986 * more than selecting one of a bunch of predefined configurations. 1066 * more than selecting one of a bunch of predefined configurations.
987 */ 1067 */
988#if defined(CONFIG_USB_TUSB6010) || \ 1068#if defined(CONFIG_USB_TUSB6010) || \
989 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) 1069 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) \
1070 || defined(CONFIG_ARCH_OMAP4)
990static ushort __initdata fifo_mode = 4; 1071static ushort __initdata fifo_mode = 4;
991#else 1072#else
992static ushort __initdata fifo_mode = 2; 1073static ushort __initdata fifo_mode = 2;
@@ -996,24 +1077,13 @@ static ushort __initdata fifo_mode = 2;
996module_param(fifo_mode, ushort, 0); 1077module_param(fifo_mode, ushort, 0);
997MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration"); 1078MODULE_PARM_DESC(fifo_mode, "initial endpoint configuration");
998 1079
999
1000enum fifo_style { FIFO_RXTX, FIFO_TX, FIFO_RX } __attribute__ ((packed));
1001enum buf_mode { BUF_SINGLE, BUF_DOUBLE } __attribute__ ((packed));
1002
1003struct fifo_cfg {
1004 u8 hw_ep_num;
1005 enum fifo_style style;
1006 enum buf_mode mode;
1007 u16 maxpacket;
1008};
1009
1010/* 1080/*
1011 * tables defining fifo_mode values. define more if you like. 1081 * tables defining fifo_mode values. define more if you like.
1012 * for host side, make sure both halves of ep1 are set up. 1082 * for host side, make sure both halves of ep1 are set up.
1013 */ 1083 */
1014 1084
1015/* mode 0 - fits in 2KB */ 1085/* mode 0 - fits in 2KB */
1016static struct fifo_cfg __initdata mode_0_cfg[] = { 1086static struct musb_fifo_cfg __initdata mode_0_cfg[] = {
1017{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1087{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1018{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1088{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1019{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, }, 1089{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, },
@@ -1022,7 +1092,7 @@ static struct fifo_cfg __initdata mode_0_cfg[] = {
1022}; 1092};
1023 1093
1024/* mode 1 - fits in 4KB */ 1094/* mode 1 - fits in 4KB */
1025static struct fifo_cfg __initdata mode_1_cfg[] = { 1095static struct musb_fifo_cfg __initdata mode_1_cfg[] = {
1026{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1096{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1027{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1097{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1028{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1098{ .hw_ep_num = 2, .style = FIFO_RXTX, .maxpacket = 512, .mode = BUF_DOUBLE, },
@@ -1031,7 +1101,7 @@ static struct fifo_cfg __initdata mode_1_cfg[] = {
1031}; 1101};
1032 1102
1033/* mode 2 - fits in 4KB */ 1103/* mode 2 - fits in 4KB */
1034static struct fifo_cfg __initdata mode_2_cfg[] = { 1104static struct musb_fifo_cfg __initdata mode_2_cfg[] = {
1035{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1105{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1036{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1106{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1037{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 1107{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
@@ -1041,7 +1111,7 @@ static struct fifo_cfg __initdata mode_2_cfg[] = {
1041}; 1111};
1042 1112
1043/* mode 3 - fits in 4KB */ 1113/* mode 3 - fits in 4KB */
1044static struct fifo_cfg __initdata mode_3_cfg[] = { 1114static struct musb_fifo_cfg __initdata mode_3_cfg[] = {
1045{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1115{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1046{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, }, 1116{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, .mode = BUF_DOUBLE, },
1047{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 1117{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
@@ -1051,7 +1121,7 @@ static struct fifo_cfg __initdata mode_3_cfg[] = {
1051}; 1121};
1052 1122
1053/* mode 4 - fits in 16KB */ 1123/* mode 4 - fits in 16KB */
1054static struct fifo_cfg __initdata mode_4_cfg[] = { 1124static struct musb_fifo_cfg __initdata mode_4_cfg[] = {
1055{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1125{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1056{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1126{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1057{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 1127{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
@@ -1082,7 +1152,7 @@ static struct fifo_cfg __initdata mode_4_cfg[] = {
1082}; 1152};
1083 1153
1084/* mode 5 - fits in 8KB */ 1154/* mode 5 - fits in 8KB */
1085static struct fifo_cfg __initdata mode_5_cfg[] = { 1155static struct musb_fifo_cfg __initdata mode_5_cfg[] = {
1086{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 1156{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1087{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 1157{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1088{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, }, 1158{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
@@ -1120,7 +1190,7 @@ static struct fifo_cfg __initdata mode_5_cfg[] = {
1120 */ 1190 */
1121static int __init 1191static int __init
1122fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep, 1192fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
1123 const struct fifo_cfg *cfg, u16 offset) 1193 const struct musb_fifo_cfg *cfg, u16 offset)
1124{ 1194{
1125 void __iomem *mbase = musb->mregs; 1195 void __iomem *mbase = musb->mregs;
1126 int size = 0; 1196 int size = 0;
@@ -1191,17 +1261,23 @@ fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep,
1191 return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0)); 1261 return offset + (maxpacket << ((c_size & MUSB_FIFOSZ_DPB) ? 1 : 0));
1192} 1262}
1193 1263
1194static struct fifo_cfg __initdata ep0_cfg = { 1264static struct musb_fifo_cfg __initdata ep0_cfg = {
1195 .style = FIFO_RXTX, .maxpacket = 64, 1265 .style = FIFO_RXTX, .maxpacket = 64,
1196}; 1266};
1197 1267
1198static int __init ep_config_from_table(struct musb *musb) 1268static int __init ep_config_from_table(struct musb *musb)
1199{ 1269{
1200 const struct fifo_cfg *cfg; 1270 const struct musb_fifo_cfg *cfg;
1201 unsigned i, n; 1271 unsigned i, n;
1202 int offset; 1272 int offset;
1203 struct musb_hw_ep *hw_ep = musb->endpoints; 1273 struct musb_hw_ep *hw_ep = musb->endpoints;
1204 1274
1275 if (musb->config->fifo_cfg) {
1276 cfg = musb->config->fifo_cfg;
1277 n = musb->config->fifo_cfg_size;
1278 goto done;
1279 }
1280
1205 switch (fifo_mode) { 1281 switch (fifo_mode) {
1206 default: 1282 default:
1207 fifo_mode = 0; 1283 fifo_mode = 0;
@@ -1236,6 +1312,7 @@ static int __init ep_config_from_table(struct musb *musb)
1236 musb_driver_name, fifo_mode); 1312 musb_driver_name, fifo_mode);
1237 1313
1238 1314
1315done:
1239 offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0); 1316 offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0);
1240 /* assert(offset > 0) */ 1317 /* assert(offset > 0) */
1241 1318
@@ -1461,7 +1538,8 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1461 1538
1462/*-------------------------------------------------------------------------*/ 1539/*-------------------------------------------------------------------------*/
1463 1540
1464#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) 1541#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) || \
1542 defined(CONFIG_ARCH_OMAP4)
1465 1543
1466static irqreturn_t generic_interrupt(int irq, void *__hci) 1544static irqreturn_t generic_interrupt(int irq, void *__hci)
1467{ 1545{
@@ -1948,7 +2026,7 @@ bad_config:
1948 * isp1504, non-OTG, etc) mostly hooking up through ULPI. 2026 * isp1504, non-OTG, etc) mostly hooking up through ULPI.
1949 */ 2027 */
1950 musb->isr = generic_interrupt; 2028 musb->isr = generic_interrupt;
1951 status = musb_platform_init(musb); 2029 status = musb_platform_init(musb, plat->board_data);
1952 if (status < 0) 2030 if (status < 0)
1953 goto fail2; 2031 goto fail2;
1954 2032
@@ -1957,6 +2035,11 @@ bad_config:
1957 goto fail3; 2035 goto fail3;
1958 } 2036 }
1959 2037
2038 if (!musb->xceiv->io_ops) {
2039 musb->xceiv->io_priv = musb->mregs;
2040 musb->xceiv->io_ops = &musb_ulpi_access;
2041 }
2042
1960#ifndef CONFIG_MUSB_PIO_ONLY 2043#ifndef CONFIG_MUSB_PIO_ONLY
1961 if (use_dma && dev->dma_mask) { 2044 if (use_dma && dev->dma_mask) {
1962 struct dma_controller *c; 2045 struct dma_controller *c;
@@ -2057,10 +2140,14 @@ bad_config:
2057 if (status < 0) 2140 if (status < 0)
2058 goto fail3; 2141 goto fail3;
2059 2142
2143 status = musb_init_debugfs(musb);
2144 if (status < 0)
2145 goto fail4;
2146
2060#ifdef CONFIG_SYSFS 2147#ifdef CONFIG_SYSFS
2061 status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group); 2148 status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
2062 if (status) 2149 if (status)
2063 goto fail4; 2150 goto fail5;
2064#endif 2151#endif
2065 2152
2066 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n", 2153 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n",
@@ -2077,6 +2164,9 @@ bad_config:
2077 2164
2078 return 0; 2165 return 0;
2079 2166
2167fail5:
2168 musb_exit_debugfs(musb);
2169
2080fail4: 2170fail4:
2081 if (!is_otg_enabled(musb) && is_host_enabled(musb)) 2171 if (!is_otg_enabled(musb) && is_host_enabled(musb))
2082 usb_remove_hcd(musb_to_hcd(musb)); 2172 usb_remove_hcd(musb_to_hcd(musb));
@@ -2153,6 +2243,7 @@ static int __exit musb_remove(struct platform_device *pdev)
2153 * - Peripheral mode: peripheral is deactivated (or never-activated) 2243 * - Peripheral mode: peripheral is deactivated (or never-activated)
2154 * - OTG mode: both roles are deactivated (or never-activated) 2244 * - OTG mode: both roles are deactivated (or never-activated)
2155 */ 2245 */
2246 musb_exit_debugfs(musb);
2156 musb_shutdown(pdev); 2247 musb_shutdown(pdev);
2157#ifdef CONFIG_USB_MUSB_HDRC_HCD 2248#ifdef CONFIG_USB_MUSB_HDRC_HCD
2158 if (musb->board_mode == MUSB_HOST) 2249 if (musb->board_mode == MUSB_HOST)
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index ac17b004909b..b22d02dea7d3 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -69,7 +69,7 @@ struct musb_ep;
69#include "musb_regs.h" 69#include "musb_regs.h"
70 70
71#include "musb_gadget.h" 71#include "musb_gadget.h"
72#include "../core/hcd.h" 72#include <linux/usb/hcd.h>
73#include "musb_host.h" 73#include "musb_host.h"
74 74
75 75
@@ -213,7 +213,8 @@ enum musb_g_ep0_state {
213 */ 213 */
214 214
215#if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \ 215#if defined(CONFIG_ARCH_DAVINCI) || defined(CONFIG_ARCH_OMAP2430) \
216 || defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_BLACKFIN) 216 || defined(CONFIG_ARCH_OMAP3430) || defined(CONFIG_BLACKFIN) \
217 || defined(CONFIG_ARCH_OMAP4)
217/* REVISIT indexed access seemed to 218/* REVISIT indexed access seemed to
218 * misbehave (on DaVinci) for at least peripheral IN ... 219 * misbehave (on DaVinci) for at least peripheral IN ...
219 */ 220 */
@@ -596,7 +597,8 @@ extern void musb_hnp_stop(struct musb *musb);
596extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode); 597extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode);
597 598
598#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \ 599#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \
599 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) 600 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3) || \
601 defined(CONFIG_ARCH_OMAP4)
600extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout); 602extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout);
601#else 603#else
602#define musb_platform_try_idle(x, y) do {} while (0) 604#define musb_platform_try_idle(x, y) do {} while (0)
@@ -608,7 +610,7 @@ extern int musb_platform_get_vbus_status(struct musb *musb);
608#define musb_platform_get_vbus_status(x) 0 610#define musb_platform_get_vbus_status(x) 0
609#endif 611#endif
610 612
611extern int __init musb_platform_init(struct musb *musb); 613extern int __init musb_platform_init(struct musb *musb, void *board_data);
612extern int musb_platform_exit(struct musb *musb); 614extern int musb_platform_exit(struct musb *musb);
613 615
614#endif /* __MUSB_CORE_H__ */ 616#endif /* __MUSB_CORE_H__ */
diff --git a/drivers/usb/musb/musb_debug.h b/drivers/usb/musb/musb_debug.h
index 9fc1db44c72c..d73afdbde3ee 100644
--- a/drivers/usb/musb/musb_debug.h
+++ b/drivers/usb/musb/musb_debug.h
@@ -59,4 +59,17 @@ static inline int _dbg_level(unsigned l)
59 59
60extern const char *otg_state_string(struct musb *); 60extern const char *otg_state_string(struct musb *);
61 61
62#ifdef CONFIG_DEBUG_FS
63extern int musb_init_debugfs(struct musb *musb);
64extern void musb_exit_debugfs(struct musb *musb);
65#else
66static inline int musb_init_debugfs(struct musb *musb)
67{
68 return 0;
69}
70static inline void musb_exit_debugfs(struct musb *musb)
71{
72}
73#endif
74
62#endif /* __MUSB_LINUX_DEBUG_H__ */ 75#endif /* __MUSB_LINUX_DEBUG_H__ */
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
new file mode 100644
index 000000000000..bba76af0c0c6
--- /dev/null
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -0,0 +1,294 @@
1/*
2 * MUSB OTG driver debugfs support
3 *
4 * Copyright 2010 Nokia Corporation
5 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/sched.h>
37#include <linux/init.h>
38#include <linux/list.h>
39#include <linux/kobject.h>
40#include <linux/platform_device.h>
41#include <linux/io.h>
42#include <linux/debugfs.h>
43#include <linux/seq_file.h>
44
45#ifdef CONFIG_ARM
46#include <mach/hardware.h>
47#include <mach/memory.h>
48#include <asm/mach-types.h>
49#endif
50
51#include <asm/uaccess.h>
52
53#include "musb_core.h"
54#include "musb_debug.h"
55
56#ifdef CONFIG_ARCH_DAVINCI
57#include "davinci.h"
58#endif
59
60struct musb_register_map {
61 char *name;
62 unsigned offset;
63 unsigned size;
64};
65
66static const struct musb_register_map musb_regmap[] = {
67 { "FAddr", 0x00, 8 },
68 { "Power", 0x01, 8 },
69 { "Frame", 0x0c, 16 },
70 { "Index", 0x0e, 8 },
71 { "Testmode", 0x0f, 8 },
72 { "TxMaxPp", 0x10, 16 },
73 { "TxCSRp", 0x12, 16 },
74 { "RxMaxPp", 0x14, 16 },
75 { "RxCSR", 0x16, 16 },
76 { "RxCount", 0x18, 16 },
77 { "ConfigData", 0x1f, 8 },
78 { "DevCtl", 0x60, 8 },
79 { "MISC", 0x61, 8 },
80 { "TxFIFOsz", 0x62, 8 },
81 { "RxFIFOsz", 0x63, 8 },
82 { "TxFIFOadd", 0x64, 16 },
83 { "RxFIFOadd", 0x66, 16 },
84 { "VControl", 0x68, 32 },
85 { "HWVers", 0x6C, 16 },
86 { "EPInfo", 0x78, 8 },
87 { "RAMInfo", 0x79, 8 },
88 { "LinkInfo", 0x7A, 8 },
89 { "VPLen", 0x7B, 8 },
90 { "HS_EOF1", 0x7C, 8 },
91 { "FS_EOF1", 0x7D, 8 },
92 { "LS_EOF1", 0x7E, 8 },
93 { "SOFT_RST", 0x7F, 8 },
94 { "DMA_CNTLch0", 0x204, 16 },
95 { "DMA_ADDRch0", 0x208, 16 },
96 { "DMA_COUNTch0", 0x20C, 16 },
97 { "DMA_CNTLch1", 0x214, 16 },
98 { "DMA_ADDRch1", 0x218, 16 },
99 { "DMA_COUNTch1", 0x21C, 16 },
100 { "DMA_CNTLch2", 0x224, 16 },
101 { "DMA_ADDRch2", 0x228, 16 },
102 { "DMA_COUNTch2", 0x22C, 16 },
103 { "DMA_CNTLch3", 0x234, 16 },
104 { "DMA_ADDRch3", 0x238, 16 },
105 { "DMA_COUNTch3", 0x23C, 16 },
106 { "DMA_CNTLch4", 0x244, 16 },
107 { "DMA_ADDRch4", 0x248, 16 },
108 { "DMA_COUNTch4", 0x24C, 16 },
109 { "DMA_CNTLch5", 0x254, 16 },
110 { "DMA_ADDRch5", 0x258, 16 },
111 { "DMA_COUNTch5", 0x25C, 16 },
112 { "DMA_CNTLch6", 0x264, 16 },
113 { "DMA_ADDRch6", 0x268, 16 },
114 { "DMA_COUNTch6", 0x26C, 16 },
115 { "DMA_CNTLch7", 0x274, 16 },
116 { "DMA_ADDRch7", 0x278, 16 },
117 { "DMA_COUNTch7", 0x27C, 16 },
118 { } /* Terminating Entry */
119};
120
121static struct dentry *musb_debugfs_root;
122
123static int musb_regdump_show(struct seq_file *s, void *unused)
124{
125 struct musb *musb = s->private;
126 unsigned i;
127
128 seq_printf(s, "MUSB (M)HDRC Register Dump\n");
129
130 for (i = 0; i < ARRAY_SIZE(musb_regmap); i++) {
131 switch (musb_regmap[i].size) {
132 case 8:
133 seq_printf(s, "%-12s: %02x\n", musb_regmap[i].name,
134 musb_readb(musb->mregs, musb_regmap[i].offset));
135 break;
136 case 16:
137 seq_printf(s, "%-12s: %04x\n", musb_regmap[i].name,
138 musb_readw(musb->mregs, musb_regmap[i].offset));
139 break;
140 case 32:
141 seq_printf(s, "%-12s: %08x\n", musb_regmap[i].name,
142 musb_readl(musb->mregs, musb_regmap[i].offset));
143 break;
144 }
145 }
146
147 return 0;
148}
149
150static int musb_regdump_open(struct inode *inode, struct file *file)
151{
152 return single_open(file, musb_regdump_show, inode->i_private);
153}
154
155static int musb_test_mode_show(struct seq_file *s, void *unused)
156{
157 struct musb *musb = s->private;
158 unsigned test;
159
160 test = musb_readb(musb->mregs, MUSB_TESTMODE);
161
162 if (test & MUSB_TEST_FORCE_HOST)
163 seq_printf(s, "force host\n");
164
165 if (test & MUSB_TEST_FIFO_ACCESS)
166 seq_printf(s, "fifo access\n");
167
168 if (test & MUSB_TEST_FORCE_FS)
169 seq_printf(s, "force full-speed\n");
170
171 if (test & MUSB_TEST_FORCE_HS)
172 seq_printf(s, "force high-speed\n");
173
174 if (test & MUSB_TEST_PACKET)
175 seq_printf(s, "test packet\n");
176
177 if (test & MUSB_TEST_K)
178 seq_printf(s, "test K\n");
179
180 if (test & MUSB_TEST_J)
181 seq_printf(s, "test J\n");
182
183 if (test & MUSB_TEST_SE0_NAK)
184 seq_printf(s, "test SE0 NAK\n");
185
186 return 0;
187}
188
189static const struct file_operations musb_regdump_fops = {
190 .open = musb_regdump_open,
191 .read = seq_read,
192 .llseek = seq_lseek,
193 .release = single_release,
194};
195
196static int musb_test_mode_open(struct inode *inode, struct file *file)
197{
198 file->private_data = inode->i_private;
199
200 return single_open(file, musb_test_mode_show, inode->i_private);
201}
202
203static ssize_t musb_test_mode_write(struct file *file,
204 const char __user *ubuf, size_t count, loff_t *ppos)
205{
206 struct musb *musb = file->private_data;
207 u8 test = 0;
208 char buf[18];
209
210 memset(buf, 0x00, sizeof(buf));
211
212 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
213 return -EFAULT;
214
215 if (!strncmp(buf, "force host", 9))
216 test = MUSB_TEST_FORCE_HOST;
217
218 if (!strncmp(buf, "fifo access", 11))
219 test = MUSB_TEST_FIFO_ACCESS;
220
221 if (!strncmp(buf, "force full-speed", 15))
222 test = MUSB_TEST_FORCE_FS;
223
224 if (!strncmp(buf, "force high-speed", 15))
225 test = MUSB_TEST_FORCE_HS;
226
227 if (!strncmp(buf, "test packet", 10)) {
228 test = MUSB_TEST_PACKET;
229 musb_load_testpacket(musb);
230 }
231
232 if (!strncmp(buf, "test K", 6))
233 test = MUSB_TEST_K;
234
235 if (!strncmp(buf, "test J", 6))
236 test = MUSB_TEST_J;
237
238 if (!strncmp(buf, "test SE0 NAK", 12))
239 test = MUSB_TEST_SE0_NAK;
240
241 musb_writeb(musb->mregs, MUSB_TESTMODE, test);
242
243 return count;
244}
245
246static const struct file_operations musb_test_mode_fops = {
247 .open = musb_test_mode_open,
248 .write = musb_test_mode_write,
249 .read = seq_read,
250 .llseek = seq_lseek,
251 .release = single_release,
252};
253
254int __init musb_init_debugfs(struct musb *musb)
255{
256 struct dentry *root;
257 struct dentry *file;
258 int ret;
259
260 root = debugfs_create_dir("musb", NULL);
261 if (IS_ERR(root)) {
262 ret = PTR_ERR(root);
263 goto err0;
264 }
265
266 file = debugfs_create_file("regdump", S_IRUGO, root, musb,
267 &musb_regdump_fops);
268 if (IS_ERR(file)) {
269 ret = PTR_ERR(file);
270 goto err1;
271 }
272
273 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR,
274 root, musb, &musb_test_mode_fops);
275 if (IS_ERR(file)) {
276 ret = PTR_ERR(file);
277 goto err1;
278 }
279
280 musb_debugfs_root = root;
281
282 return 0;
283
284err1:
285 debugfs_remove_recursive(root);
286
287err0:
288 return ret;
289}
290
291void /* __init_or_exit */ musb_exit_debugfs(struct musb *musb)
292{
293 debugfs_remove_recursive(musb_debugfs_root);
294}
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 53d06451f820..21b9788d0243 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -351,6 +351,31 @@ __acquires(musb->lock)
351 musb->test_mode_nr = 351 musb->test_mode_nr =
352 MUSB_TEST_PACKET; 352 MUSB_TEST_PACKET;
353 break; 353 break;
354
355 case 0xc0:
356 /* TEST_FORCE_HS */
357 pr_debug("TEST_FORCE_HS\n");
358 musb->test_mode_nr =
359 MUSB_TEST_FORCE_HS;
360 break;
361 case 0xc1:
362 /* TEST_FORCE_FS */
363 pr_debug("TEST_FORCE_FS\n");
364 musb->test_mode_nr =
365 MUSB_TEST_FORCE_FS;
366 break;
367 case 0xc2:
368 /* TEST_FIFO_ACCESS */
369 pr_debug("TEST_FIFO_ACCESS\n");
370 musb->test_mode_nr =
371 MUSB_TEST_FIFO_ACCESS;
372 break;
373 case 0xc3:
374 /* TEST_FORCE_HOST */
375 pr_debug("TEST_FORCE_HOST\n");
376 musb->test_mode_nr =
377 MUSB_TEST_FORCE_HOST;
378 break;
354 default: 379 default:
355 goto stall; 380 goto stall;
356 } 381 }
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index fa55aacc385d..244267527a60 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -75,6 +75,10 @@
75/* MUSB ULPI VBUSCONTROL */ 75/* MUSB ULPI VBUSCONTROL */
76#define MUSB_ULPI_USE_EXTVBUS 0x01 76#define MUSB_ULPI_USE_EXTVBUS 0x01
77#define MUSB_ULPI_USE_EXTVBUSIND 0x02 77#define MUSB_ULPI_USE_EXTVBUSIND 0x02
78/* ULPI_REG_CONTROL */
79#define MUSB_ULPI_REG_REQ (1 << 0)
80#define MUSB_ULPI_REG_CMPLT (1 << 1)
81#define MUSB_ULPI_RDN_WR (1 << 2)
78 82
79/* TESTMODE */ 83/* TESTMODE */
80#define MUSB_TEST_FORCE_HOST 0x80 84#define MUSB_TEST_FORCE_HOST 0x80
@@ -251,6 +255,12 @@
251/* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */ 255/* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */
252#define MUSB_HWVERS 0x6C /* 8 bit */ 256#define MUSB_HWVERS 0x6C /* 8 bit */
253#define MUSB_ULPI_BUSCONTROL 0x70 /* 8 bit */ 257#define MUSB_ULPI_BUSCONTROL 0x70 /* 8 bit */
258#define MUSB_ULPI_INT_MASK 0x72 /* 8 bit */
259#define MUSB_ULPI_INT_SRC 0x73 /* 8 bit */
260#define MUSB_ULPI_REG_DATA 0x74 /* 8 bit */
261#define MUSB_ULPI_REG_ADDR 0x75 /* 8 bit */
262#define MUSB_ULPI_REG_CONTROL 0x76 /* 8 bit */
263#define MUSB_ULPI_RAW_DATA 0x77 /* 8 bit */
254 264
255#define MUSB_EPINFO 0x78 /* 8 bit */ 265#define MUSB_EPINFO 0x78 /* 8 bit */
256#define MUSB_RAMINFO 0x79 /* 8 bit */ 266#define MUSB_RAMINFO 0x79 /* 8 bit */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 7775e1c0a215..92e85e027cfb 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -183,8 +183,8 @@ static void musb_port_reset(struct musb *musb, bool do_reset)
183 183
184void musb_root_disconnect(struct musb *musb) 184void musb_root_disconnect(struct musb *musb)
185{ 185{
186 musb->port1_status = (1 << USB_PORT_FEAT_POWER) 186 musb->port1_status = USB_PORT_STAT_POWER
187 | (1 << USB_PORT_FEAT_C_CONNECTION); 187 | (USB_PORT_STAT_C_CONNECTION << 16);
188 188
189 usb_hcd_poll_rh_status(musb_to_hcd(musb)); 189 usb_hcd_poll_rh_status(musb_to_hcd(musb));
190 musb->is_active = 0; 190 musb->is_active = 0;
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h
index 613f95a058f7..f763d62f151c 100644
--- a/drivers/usb/musb/musbhsdma.h
+++ b/drivers/usb/musb/musbhsdma.h
@@ -102,26 +102,16 @@ static inline void musb_write_hsdma_addr(void __iomem *mbase,
102 102
103static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel) 103static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel)
104{ 104{
105 u32 count = musb_readw(mbase, 105 return musb_readl(mbase,
106 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH)); 106 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH));
107
108 count = count << 16;
109
110 count |= musb_readw(mbase,
111 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW));
112
113 return count;
114} 107}
115 108
116static inline void musb_write_hsdma_count(void __iomem *mbase, 109static inline void musb_write_hsdma_count(void __iomem *mbase,
117 u8 bchannel, u32 len) 110 u8 bchannel, u32 len)
118{ 111{
119 musb_writew(mbase, 112 musb_writel(mbase,
120 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_LOW),
121 ((u16)((u32) len & 0xFFFF)));
122 musb_writew(mbase,
123 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH), 113 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT_HIGH),
124 ((u16)(((u32) len >> 16) & 0xFFFF))); 114 len);
125} 115}
126 116
127#endif /* CONFIG_BLACKFIN */ 117#endif /* CONFIG_BLACKFIN */
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 82592633502f..e06d65e36bf7 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -32,17 +32,11 @@
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/io.h> 33#include <linux/io.h>
34 34
35#include <asm/mach-types.h>
36#include <mach/hardware.h>
37#include <plat/mux.h> 35#include <plat/mux.h>
38 36
39#include "musb_core.h" 37#include "musb_core.h"
40#include "omap2430.h" 38#include "omap2430.h"
41 39
42#ifdef CONFIG_ARCH_OMAP3430
43#define get_cpu_rev() 2
44#endif
45
46 40
47static struct timer_list musb_idle_timer; 41static struct timer_list musb_idle_timer;
48 42
@@ -145,10 +139,6 @@ void musb_platform_enable(struct musb *musb)
145void musb_platform_disable(struct musb *musb) 139void musb_platform_disable(struct musb *musb)
146{ 140{
147} 141}
148static void omap_vbus_power(struct musb *musb, int is_on, int sleeping)
149{
150}
151
152static void omap_set_vbus(struct musb *musb, int is_on) 142static void omap_set_vbus(struct musb *musb, int is_on)
153{ 143{
154 u8 devctl; 144 u8 devctl;
@@ -199,9 +189,10 @@ int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
199 return 0; 189 return 0;
200} 190}
201 191
202int __init musb_platform_init(struct musb *musb) 192int __init musb_platform_init(struct musb *musb, void *board_data)
203{ 193{
204 u32 l; 194 u32 l;
195 struct omap_musb_board_data *data = board_data;
205 196
206#if defined(CONFIG_ARCH_OMAP2430) 197#if defined(CONFIG_ARCH_OMAP2430)
207 omap_cfg_reg(AE5_2430_USB0HS_STP); 198 omap_cfg_reg(AE5_2430_USB0HS_STP);
@@ -235,7 +226,15 @@ int __init musb_platform_init(struct musb *musb)
235 musb_writel(musb->mregs, OTG_SYSCONFIG, l); 226 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
236 227
237 l = musb_readl(musb->mregs, OTG_INTERFSEL); 228 l = musb_readl(musb->mregs, OTG_INTERFSEL);
238 l |= ULPI_12PIN; 229
230 if (data->interface_type == MUSB_INTERFACE_UTMI) {
231 /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
232 l &= ~ULPI_12PIN; /* Disable ULPI */
233 l |= UTMI_8BIT; /* Enable UTMI */
234 } else {
235 l |= ULPI_12PIN;
236 }
237
239 musb_writel(musb->mregs, OTG_INTERFSEL, l); 238 musb_writel(musb->mregs, OTG_INTERFSEL, l);
240 239
241 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " 240 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
@@ -246,8 +245,6 @@ int __init musb_platform_init(struct musb *musb)
246 musb_readl(musb->mregs, OTG_INTERFSEL), 245 musb_readl(musb->mregs, OTG_INTERFSEL),
247 musb_readl(musb->mregs, OTG_SIMENABLE)); 246 musb_readl(musb->mregs, OTG_SIMENABLE));
248 247
249 omap_vbus_power(musb, musb->board_mode == MUSB_HOST, 1);
250
251 if (is_host_enabled(musb)) 248 if (is_host_enabled(musb))
252 musb->board_set_vbus = omap_set_vbus; 249 musb->board_set_vbus = omap_set_vbus;
253 250
@@ -272,7 +269,7 @@ void musb_platform_restore_context(struct musb *musb,
272} 269}
273#endif 270#endif
274 271
275int musb_platform_suspend(struct musb *musb) 272static int musb_platform_suspend(struct musb *musb)
276{ 273{
277 u32 l; 274 u32 l;
278 275
@@ -327,8 +324,6 @@ static int musb_platform_resume(struct musb *musb)
327int musb_platform_exit(struct musb *musb) 324int musb_platform_exit(struct musb *musb)
328{ 325{
329 326
330 omap_vbus_power(musb, 0 /*off*/, 1);
331
332 musb_platform_suspend(musb); 327 musb_platform_suspend(musb);
333 328
334 return 0; 329 return 0;
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 60d3938cafcf..05c077f8f9ac 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -1104,7 +1104,7 @@ err:
1104 return -ENODEV; 1104 return -ENODEV;
1105} 1105}
1106 1106
1107int __init musb_platform_init(struct musb *musb) 1107int __init musb_platform_init(struct musb *musb, void *board_data)
1108{ 1108{
1109 struct platform_device *pdev; 1109 struct platform_device *pdev;
1110 struct resource *mem; 1110 struct resource *mem;
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index 78a209709260..456969492410 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -1654,7 +1654,7 @@ static int __init isp_init(void)
1654{ 1654{
1655 return i2c_add_driver(&isp1301_driver); 1655 return i2c_add_driver(&isp1301_driver);
1656} 1656}
1657module_init(isp_init); 1657subsys_initcall(isp_init);
1658 1658
1659static void __exit isp_exit(void) 1659static void __exit isp_exit(void)
1660{ 1660{
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 223cdf46ccb7..0e8888588d4e 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -33,6 +33,7 @@
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/usb/ulpi.h>
36#include <linux/i2c/twl.h> 37#include <linux/i2c/twl.h>
37#include <linux/regulator/consumer.h> 38#include <linux/regulator/consumer.h>
38#include <linux/err.h> 39#include <linux/err.h>
@@ -41,81 +42,7 @@
41 42
42/* Register defines */ 43/* Register defines */
43 44
44#define VENDOR_ID_LO 0x00
45#define VENDOR_ID_HI 0x01
46#define PRODUCT_ID_LO 0x02
47#define PRODUCT_ID_HI 0x03
48
49#define FUNC_CTRL 0x04
50#define FUNC_CTRL_SET 0x05
51#define FUNC_CTRL_CLR 0x06
52#define FUNC_CTRL_SUSPENDM (1 << 6)
53#define FUNC_CTRL_RESET (1 << 5)
54#define FUNC_CTRL_OPMODE_MASK (3 << 3) /* bits 3 and 4 */
55#define FUNC_CTRL_OPMODE_NORMAL (0 << 3)
56#define FUNC_CTRL_OPMODE_NONDRIVING (1 << 3)
57#define FUNC_CTRL_OPMODE_DISABLE_BIT_NRZI (2 << 3)
58#define FUNC_CTRL_TERMSELECT (1 << 2)
59#define FUNC_CTRL_XCVRSELECT_MASK (3 << 0) /* bits 0 and 1 */
60#define FUNC_CTRL_XCVRSELECT_HS (0 << 0)
61#define FUNC_CTRL_XCVRSELECT_FS (1 << 0)
62#define FUNC_CTRL_XCVRSELECT_LS (2 << 0)
63#define FUNC_CTRL_XCVRSELECT_FS4LS (3 << 0)
64
65#define IFC_CTRL 0x07
66#define IFC_CTRL_SET 0x08
67#define IFC_CTRL_CLR 0x09
68#define IFC_CTRL_INTERFACE_PROTECT_DISABLE (1 << 7)
69#define IFC_CTRL_AUTORESUME (1 << 4)
70#define IFC_CTRL_CLOCKSUSPENDM (1 << 3)
71#define IFC_CTRL_CARKITMODE (1 << 2)
72#define IFC_CTRL_FSLSSERIALMODE_3PIN (1 << 1)
73
74#define TWL4030_OTG_CTRL 0x0A
75#define TWL4030_OTG_CTRL_SET 0x0B
76#define TWL4030_OTG_CTRL_CLR 0x0C
77#define TWL4030_OTG_CTRL_DRVVBUS (1 << 5)
78#define TWL4030_OTG_CTRL_CHRGVBUS (1 << 4)
79#define TWL4030_OTG_CTRL_DISCHRGVBUS (1 << 3)
80#define TWL4030_OTG_CTRL_DMPULLDOWN (1 << 2)
81#define TWL4030_OTG_CTRL_DPPULLDOWN (1 << 1)
82#define TWL4030_OTG_CTRL_IDPULLUP (1 << 0)
83
84#define USB_INT_EN_RISE 0x0D
85#define USB_INT_EN_RISE_SET 0x0E
86#define USB_INT_EN_RISE_CLR 0x0F
87#define USB_INT_EN_FALL 0x10
88#define USB_INT_EN_FALL_SET 0x11
89#define USB_INT_EN_FALL_CLR 0x12
90#define USB_INT_STS 0x13
91#define USB_INT_LATCH 0x14
92#define USB_INT_IDGND (1 << 4)
93#define USB_INT_SESSEND (1 << 3)
94#define USB_INT_SESSVALID (1 << 2)
95#define USB_INT_VBUSVALID (1 << 1)
96#define USB_INT_HOSTDISCONNECT (1 << 0)
97
98#define CARKIT_CTRL 0x19
99#define CARKIT_CTRL_SET 0x1A
100#define CARKIT_CTRL_CLR 0x1B
101#define CARKIT_CTRL_MICEN (1 << 6)
102#define CARKIT_CTRL_SPKRIGHTEN (1 << 5)
103#define CARKIT_CTRL_SPKLEFTEN (1 << 4)
104#define CARKIT_CTRL_RXDEN (1 << 3)
105#define CARKIT_CTRL_TXDEN (1 << 2)
106#define CARKIT_CTRL_IDGNDDRV (1 << 1)
107#define CARKIT_CTRL_CARKITPWR (1 << 0)
108#define CARKIT_PLS_CTRL 0x22
109#define CARKIT_PLS_CTRL_SET 0x23
110#define CARKIT_PLS_CTRL_CLR 0x24
111#define CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3)
112#define CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2)
113#define CARKIT_PLS_CTRL_RXPLSEN (1 << 1)
114#define CARKIT_PLS_CTRL_TXPLSEN (1 << 0)
115
116#define MCPC_CTRL 0x30 45#define MCPC_CTRL 0x30
117#define MCPC_CTRL_SET 0x31
118#define MCPC_CTRL_CLR 0x32
119#define MCPC_CTRL_RTSOL (1 << 7) 46#define MCPC_CTRL_RTSOL (1 << 7)
120#define MCPC_CTRL_EXTSWR (1 << 6) 47#define MCPC_CTRL_EXTSWR (1 << 6)
121#define MCPC_CTRL_EXTSWC (1 << 5) 48#define MCPC_CTRL_EXTSWC (1 << 5)
@@ -125,8 +52,6 @@
125#define MCPC_CTRL_HS_UART (1 << 0) 52#define MCPC_CTRL_HS_UART (1 << 0)
126 53
127#define MCPC_IO_CTRL 0x33 54#define MCPC_IO_CTRL 0x33
128#define MCPC_IO_CTRL_SET 0x34
129#define MCPC_IO_CTRL_CLR 0x35
130#define MCPC_IO_CTRL_MICBIASEN (1 << 5) 55#define MCPC_IO_CTRL_MICBIASEN (1 << 5)
131#define MCPC_IO_CTRL_CTS_NPU (1 << 4) 56#define MCPC_IO_CTRL_CTS_NPU (1 << 4)
132#define MCPC_IO_CTRL_RXD_PU (1 << 3) 57#define MCPC_IO_CTRL_RXD_PU (1 << 3)
@@ -135,19 +60,13 @@
135#define MCPC_IO_CTRL_RTSTYP (1 << 0) 60#define MCPC_IO_CTRL_RTSTYP (1 << 0)
136 61
137#define MCPC_CTRL2 0x36 62#define MCPC_CTRL2 0x36
138#define MCPC_CTRL2_SET 0x37
139#define MCPC_CTRL2_CLR 0x38
140#define MCPC_CTRL2_MCPC_CK_EN (1 << 0) 63#define MCPC_CTRL2_MCPC_CK_EN (1 << 0)
141 64
142#define OTHER_FUNC_CTRL 0x80 65#define OTHER_FUNC_CTRL 0x80
143#define OTHER_FUNC_CTRL_SET 0x81
144#define OTHER_FUNC_CTRL_CLR 0x82
145#define OTHER_FUNC_CTRL_BDIS_ACON_EN (1 << 4) 66#define OTHER_FUNC_CTRL_BDIS_ACON_EN (1 << 4)
146#define OTHER_FUNC_CTRL_FIVEWIRE_MODE (1 << 2) 67#define OTHER_FUNC_CTRL_FIVEWIRE_MODE (1 << 2)
147 68
148#define OTHER_IFC_CTRL 0x83 69#define OTHER_IFC_CTRL 0x83
149#define OTHER_IFC_CTRL_SET 0x84
150#define OTHER_IFC_CTRL_CLR 0x85
151#define OTHER_IFC_CTRL_OE_INT_EN (1 << 6) 70#define OTHER_IFC_CTRL_OE_INT_EN (1 << 6)
152#define OTHER_IFC_CTRL_CEA2011_MODE (1 << 5) 71#define OTHER_IFC_CTRL_CEA2011_MODE (1 << 5)
153#define OTHER_IFC_CTRL_FSLSSERIALMODE_4PIN (1 << 4) 72#define OTHER_IFC_CTRL_FSLSSERIALMODE_4PIN (1 << 4)
@@ -156,11 +75,7 @@
156#define OTHER_IFC_CTRL_ALT_INT_REROUTE (1 << 0) 75#define OTHER_IFC_CTRL_ALT_INT_REROUTE (1 << 0)
157 76
158#define OTHER_INT_EN_RISE 0x86 77#define OTHER_INT_EN_RISE 0x86
159#define OTHER_INT_EN_RISE_SET 0x87
160#define OTHER_INT_EN_RISE_CLR 0x88
161#define OTHER_INT_EN_FALL 0x89 78#define OTHER_INT_EN_FALL 0x89
162#define OTHER_INT_EN_FALL_SET 0x8A
163#define OTHER_INT_EN_FALL_CLR 0x8B
164#define OTHER_INT_STS 0x8C 79#define OTHER_INT_STS 0x8C
165#define OTHER_INT_LATCH 0x8D 80#define OTHER_INT_LATCH 0x8D
166#define OTHER_INT_VB_SESS_VLD (1 << 7) 81#define OTHER_INT_VB_SESS_VLD (1 << 7)
@@ -178,13 +93,9 @@
178#define ID_RES_GND (1 << 0) 93#define ID_RES_GND (1 << 0)
179 94
180#define POWER_CTRL 0xAC 95#define POWER_CTRL 0xAC
181#define POWER_CTRL_SET 0xAD
182#define POWER_CTRL_CLR 0xAE
183#define POWER_CTRL_OTG_ENAB (1 << 5) 96#define POWER_CTRL_OTG_ENAB (1 << 5)
184 97
185#define OTHER_IFC_CTRL2 0xAF 98#define OTHER_IFC_CTRL2 0xAF
186#define OTHER_IFC_CTRL2_SET 0xB0
187#define OTHER_IFC_CTRL2_CLR 0xB1
188#define OTHER_IFC_CTRL2_ULPI_STP_LOW (1 << 4) 99#define OTHER_IFC_CTRL2_ULPI_STP_LOW (1 << 4)
189#define OTHER_IFC_CTRL2_ULPI_TXEN_POL (1 << 3) 100#define OTHER_IFC_CTRL2_ULPI_TXEN_POL (1 << 3)
190#define OTHER_IFC_CTRL2_ULPI_4PIN_2430 (1 << 2) 101#define OTHER_IFC_CTRL2_ULPI_4PIN_2430 (1 << 2)
@@ -193,14 +104,10 @@
193#define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT2N (1 << 0) 104#define OTHER_IFC_CTRL2_USB_INT_OUTSEL_INT2N (1 << 0)
194 105
195#define REG_CTRL_EN 0xB2 106#define REG_CTRL_EN 0xB2
196#define REG_CTRL_EN_SET 0xB3
197#define REG_CTRL_EN_CLR 0xB4
198#define REG_CTRL_ERROR 0xB5 107#define REG_CTRL_ERROR 0xB5
199#define ULPI_I2C_CONFLICT_INTEN (1 << 0) 108#define ULPI_I2C_CONFLICT_INTEN (1 << 0)
200 109
201#define OTHER_FUNC_CTRL2 0xB8 110#define OTHER_FUNC_CTRL2 0xB8
202#define OTHER_FUNC_CTRL2_SET 0xB9
203#define OTHER_FUNC_CTRL2_CLR 0xBA
204#define OTHER_FUNC_CTRL2_VBAT_TIMER_EN (1 << 0) 111#define OTHER_FUNC_CTRL2_VBAT_TIMER_EN (1 << 0)
205 112
206/* following registers do not have separate _clr and _set registers */ 113/* following registers do not have separate _clr and _set registers */
@@ -328,13 +235,13 @@ static inline int twl4030_usb_read(struct twl4030_usb *twl, u8 address)
328static inline int 235static inline int
329twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits) 236twl4030_usb_set_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
330{ 237{
331 return twl4030_usb_write(twl, reg + 1, bits); 238 return twl4030_usb_write(twl, ULPI_SET(reg), bits);
332} 239}
333 240
334static inline int 241static inline int
335twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits) 242twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
336{ 243{
337 return twl4030_usb_write(twl, reg + 2, bits); 244 return twl4030_usb_write(twl, ULPI_CLR(reg), bits);
338} 245}
339 246
340/*-------------------------------------------------------------------------*/ 247/*-------------------------------------------------------------------------*/
@@ -393,11 +300,12 @@ static void twl4030_usb_set_mode(struct twl4030_usb *twl, int mode)
393 300
394 switch (mode) { 301 switch (mode) {
395 case T2_USB_MODE_ULPI: 302 case T2_USB_MODE_ULPI:
396 twl4030_usb_clear_bits(twl, IFC_CTRL, IFC_CTRL_CARKITMODE); 303 twl4030_usb_clear_bits(twl, ULPI_IFC_CTRL,
304 ULPI_IFC_CTRL_CARKITMODE);
397 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); 305 twl4030_usb_set_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
398 twl4030_usb_clear_bits(twl, FUNC_CTRL, 306 twl4030_usb_clear_bits(twl, ULPI_FUNC_CTRL,
399 FUNC_CTRL_XCVRSELECT_MASK | 307 ULPI_FUNC_CTRL_XCVRSEL_MASK |
400 FUNC_CTRL_OPMODE_MASK); 308 ULPI_FUNC_CTRL_OPMODE_MASK);
401 break; 309 break;
402 case -1: 310 case -1:
403 /* FIXME: power on defaults */ 311 /* FIXME: power on defaults */
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index 9010225e0d06..b1b346932946 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -29,28 +29,6 @@
29#include <linux/usb/otg.h> 29#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h> 30#include <linux/usb/ulpi.h>
31 31
32/* ULPI register addresses */
33#define ULPI_VID_LOW 0x00 /* Vendor ID low */
34#define ULPI_VID_HIGH 0x01 /* Vendor ID high */
35#define ULPI_PID_LOW 0x02 /* Product ID low */
36#define ULPI_PID_HIGH 0x03 /* Product ID high */
37#define ULPI_ITFCTL 0x07 /* Interface Control */
38#define ULPI_OTGCTL 0x0A /* OTG Control */
39
40/* add to above register address to access Set/Clear functions */
41#define ULPI_REG_SET 0x01
42#define ULPI_REG_CLEAR 0x02
43
44/* ULPI OTG Control Register bits */
45#define ID_PULL_UP (1 << 0) /* enable ID Pull Up */
46#define DP_PULL_DOWN (1 << 1) /* enable DP Pull Down */
47#define DM_PULL_DOWN (1 << 2) /* enable DM Pull Down */
48#define DISCHRG_VBUS (1 << 3) /* Discharge Vbus */
49#define CHRG_VBUS (1 << 4) /* Charge Vbus */
50#define DRV_VBUS (1 << 5) /* Drive Vbus */
51#define DRV_VBUS_EXT (1 << 6) /* Drive Vbus external */
52#define USE_EXT_VBUS_IND (1 << 7) /* Use ext. Vbus indicator */
53
54#define ULPI_ID(vendor, product) (((vendor) << 16) | (product)) 32#define ULPI_ID(vendor, product) (((vendor) << 16) | (product))
55 33
56#define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0) 34#define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0)
@@ -65,28 +43,28 @@ static int ulpi_set_flags(struct otg_transceiver *otg)
65 unsigned int flags = 0; 43 unsigned int flags = 0;
66 44
67 if (otg->flags & USB_OTG_PULLUP_ID) 45 if (otg->flags & USB_OTG_PULLUP_ID)
68 flags |= ID_PULL_UP; 46 flags |= ULPI_OTG_CTRL_ID_PULLUP;
69 47
70 if (otg->flags & USB_OTG_PULLDOWN_DM) 48 if (otg->flags & USB_OTG_PULLDOWN_DM)
71 flags |= DM_PULL_DOWN; 49 flags |= ULPI_OTG_CTRL_DM_PULLDOWN;
72 50
73 if (otg->flags & USB_OTG_PULLDOWN_DP) 51 if (otg->flags & USB_OTG_PULLDOWN_DP)
74 flags |= DP_PULL_DOWN; 52 flags |= ULPI_OTG_CTRL_DP_PULLDOWN;
75 53
76 if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR) 54 if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR)
77 flags |= USE_EXT_VBUS_IND; 55 flags |= ULPI_OTG_CTRL_EXTVBUSIND;
78 56
79 return otg_io_write(otg, flags, ULPI_OTGCTL + ULPI_REG_SET); 57 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL));
80} 58}
81 59
82static int ulpi_init(struct otg_transceiver *otg) 60static int ulpi_init(struct otg_transceiver *otg)
83{ 61{
84 int i, vid, pid; 62 int i, vid, pid;
85 63
86 vid = (otg_io_read(otg, ULPI_VID_HIGH) << 8) | 64 vid = (otg_io_read(otg, ULPI_VENDOR_ID_HIGH) << 8) |
87 otg_io_read(otg, ULPI_VID_LOW); 65 otg_io_read(otg, ULPI_VENDOR_ID_LOW);
88 pid = (otg_io_read(otg, ULPI_PID_HIGH) << 8) | 66 pid = (otg_io_read(otg, ULPI_PRODUCT_ID_HIGH) << 8) |
89 otg_io_read(otg, ULPI_PID_LOW); 67 otg_io_read(otg, ULPI_PRODUCT_ID_LOW);
90 68
91 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid); 69 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid);
92 70
@@ -100,19 +78,19 @@ static int ulpi_init(struct otg_transceiver *otg)
100 78
101static int ulpi_set_vbus(struct otg_transceiver *otg, bool on) 79static int ulpi_set_vbus(struct otg_transceiver *otg, bool on)
102{ 80{
103 unsigned int flags = otg_io_read(otg, ULPI_OTGCTL); 81 unsigned int flags = otg_io_read(otg, ULPI_OTG_CTRL);
104 82
105 flags &= ~(DRV_VBUS | DRV_VBUS_EXT); 83 flags &= ~(ULPI_OTG_CTRL_DRVVBUS | ULPI_OTG_CTRL_DRVVBUS_EXT);
106 84
107 if (on) { 85 if (on) {
108 if (otg->flags & USB_OTG_DRV_VBUS) 86 if (otg->flags & USB_OTG_DRV_VBUS)
109 flags |= DRV_VBUS; 87 flags |= ULPI_OTG_CTRL_DRVVBUS;
110 88
111 if (otg->flags & USB_OTG_DRV_VBUS_EXT) 89 if (otg->flags & USB_OTG_DRV_VBUS_EXT)
112 flags |= DRV_VBUS_EXT; 90 flags |= ULPI_OTG_CTRL_DRVVBUS_EXT;
113 } 91 }
114 92
115 return otg_io_write(otg, flags, ULPI_OTGCTL + ULPI_REG_SET); 93 return otg_io_write(otg, flags, ULPI_SET(ULPI_OTG_CTRL));
116} 94}
117 95
118struct otg_transceiver * 96struct otg_transceiver *
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index a0ecb42cb33a..bd8aab0ef1cf 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -425,6 +425,16 @@ config USB_SERIAL_MOS7720
425 To compile this driver as a module, choose M here: the 425 To compile this driver as a module, choose M here: the
426 module will be called mos7720. 426 module will be called mos7720.
427 427
428config USB_SERIAL_MOS7715_PARPORT
429 bool "Support for parallel port on the Moschip 7715"
430 depends on USB_SERIAL_MOS7720
431 depends on PARPORT=y || PARPORT=USB_SERIAL_MOS7720
432 select PARPORT_NOT_PC
433 ---help---
434 Say Y if you have a Moschip 7715 device and would like to use
435 the parallel port it provides. The port will register with
436 the parport subsystem as a low-level driver.
437
428config USB_SERIAL_MOS7840 438config USB_SERIAL_MOS7840
429 tristate "USB Moschip 7840/7820 USB Serial Driver" 439 tristate "USB Moschip 7840/7820 USB Serial Driver"
430 ---help--- 440 ---help---
@@ -485,6 +495,7 @@ config USB_SERIAL_QCAUX
485 495
486config USB_SERIAL_QUALCOMM 496config USB_SERIAL_QUALCOMM
487 tristate "USB Qualcomm Serial modem" 497 tristate "USB Qualcomm Serial modem"
498 select USB_SERIAL_WWAN
488 help 499 help
489 Say Y here if you have a Qualcomm USB modem device. These are 500 Say Y here if you have a Qualcomm USB modem device. These are
490 usually wireless cellular modems. 501 usually wireless cellular modems.
@@ -576,8 +587,12 @@ config USB_SERIAL_XIRCOM
576 To compile this driver as a module, choose M here: the 587 To compile this driver as a module, choose M here: the
577 module will be called keyspan_pda. 588 module will be called keyspan_pda.
578 589
590config USB_SERIAL_WWAN
591 tristate
592
579config USB_SERIAL_OPTION 593config USB_SERIAL_OPTION
580 tristate "USB driver for GSM and CDMA modems" 594 tristate "USB driver for GSM and CDMA modems"
595 select USB_SERIAL_WWAN
581 help 596 help
582 Say Y here if you have a GSM or CDMA modem that's connected to USB. 597 Say Y here if you have a GSM or CDMA modem that's connected to USB.
583 598
@@ -619,6 +634,14 @@ config USB_SERIAL_VIVOPAY_SERIAL
619 To compile this driver as a module, choose M here: the 634 To compile this driver as a module, choose M here: the
620 module will be called vivopay-serial. 635 module will be called vivopay-serial.
621 636
637config USB_SERIAL_ZIO
638 tristate "ZIO Motherboard USB serial interface driver"
639 help
640 Say Y here if you want to use ZIO Motherboard.
641
642 To compile this driver as a module, choose M here: the
643 module will be called zio.
644
622config USB_SERIAL_DEBUG 645config USB_SERIAL_DEBUG
623 tristate "USB Debugging Device" 646 tristate "USB Debugging Device"
624 help 647 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 83c9e431a568..e54c728c016e 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -52,9 +52,11 @@ obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o
52obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 52obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
53obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o 53obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o
54obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o 54obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o
55obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o
55obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 56obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
56obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 57obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
57obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 58obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
58obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 59obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o
59obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o 60obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o
61obj-$(CONFIG_USB_SERIAL_ZIO) += zio.o
60 62
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 4fd7af98b1ae..0db6ace16f7b 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -1,7 +1,9 @@
1/* 1/*
2 * AIRcable USB Bluetooth Dongle Driver. 2 * AIRcable USB Bluetooth Dongle Driver.
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
4 * Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com) 5 * Copyright (C) 2006 Manuel Francisco Naranjo (naranjo.manuel@gmail.com)
6 *
5 * This program is free software; you can redistribute it and/or modify it under 7 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License version 2 as published by the 8 * the terms of the GNU General Public License version 2 as published by the
7 * Free Software Foundation. 9 * Free Software Foundation.
@@ -42,10 +44,10 @@
42 * 44 *
43 */ 45 */
44 46
47#include <asm/unaligned.h>
45#include <linux/tty.h> 48#include <linux/tty.h>
46#include <linux/slab.h> 49#include <linux/slab.h>
47#include <linux/tty_flip.h> 50#include <linux/tty_flip.h>
48#include <linux/circ_buf.h>
49#include <linux/usb.h> 51#include <linux/usb.h>
50#include <linux/usb/serial.h> 52#include <linux/usb/serial.h>
51 53
@@ -55,16 +57,12 @@ static int debug;
55#define AIRCABLE_VID 0x16CA 57#define AIRCABLE_VID 0x16CA
56#define AIRCABLE_USB_PID 0x1502 58#define AIRCABLE_USB_PID 0x1502
57 59
58/* write buffer size defines */
59#define AIRCABLE_BUF_SIZE 2048
60
61/* Protocol Stuff */ 60/* Protocol Stuff */
62#define HCI_HEADER_LENGTH 0x4 61#define HCI_HEADER_LENGTH 0x4
63#define TX_HEADER_0 0x20 62#define TX_HEADER_0 0x20
64#define TX_HEADER_1 0x29 63#define TX_HEADER_1 0x29
65#define RX_HEADER_0 0x00 64#define RX_HEADER_0 0x00
66#define RX_HEADER_1 0x20 65#define RX_HEADER_1 0x20
67#define MAX_HCI_FRAMESIZE 60
68#define HCI_COMPLETE_FRAME 64 66#define HCI_COMPLETE_FRAME 64
69 67
70/* rx_flags */ 68/* rx_flags */
@@ -74,8 +72,8 @@ static int debug;
74/* 72/*
75 * Version Information 73 * Version Information
76 */ 74 */
77#define DRIVER_VERSION "v1.0b2" 75#define DRIVER_VERSION "v2.0"
78#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>" 76#define DRIVER_AUTHOR "Naranjo, Manuel Francisco <naranjo.manuel@gmail.com>, Johan Hovold <jhovold@gmail.com>"
79#define DRIVER_DESC "AIRcable USB Driver" 77#define DRIVER_DESC "AIRcable USB Driver"
80 78
81/* ID table that will be registered with USB core */ 79/* ID table that will be registered with USB core */
@@ -85,226 +83,21 @@ static const struct usb_device_id id_table[] = {
85}; 83};
86MODULE_DEVICE_TABLE(usb, id_table); 84MODULE_DEVICE_TABLE(usb, id_table);
87 85
88 86static int aircable_prepare_write_buffer(struct usb_serial_port *port,
89/* Internal Structure */ 87 void *dest, size_t size)
90struct aircable_private {
91 spinlock_t rx_lock; /* spinlock for the receive lines */
92 struct circ_buf *tx_buf; /* write buffer */
93 struct circ_buf *rx_buf; /* read buffer */
94 int rx_flags; /* for throttilng */
95 struct work_struct rx_work; /* work cue for the receiving line */
96 struct usb_serial_port *port; /* USB port with which associated */
97};
98
99/* Private methods */
100
101/* Circular Buffer Methods, code from ti_usb_3410_5052 used */
102/*
103 * serial_buf_clear
104 *
105 * Clear out all data in the circular buffer.
106 */
107static void serial_buf_clear(struct circ_buf *cb)
108{
109 cb->head = cb->tail = 0;
110}
111
112/*
113 * serial_buf_alloc
114 *
115 * Allocate a circular buffer and all associated memory.
116 */
117static struct circ_buf *serial_buf_alloc(void)
118{
119 struct circ_buf *cb;
120 cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL);
121 if (cb == NULL)
122 return NULL;
123 cb->buf = kmalloc(AIRCABLE_BUF_SIZE, GFP_KERNEL);
124 if (cb->buf == NULL) {
125 kfree(cb);
126 return NULL;
127 }
128 serial_buf_clear(cb);
129 return cb;
130}
131
132/*
133 * serial_buf_free
134 *
135 * Free the buffer and all associated memory.
136 */
137static void serial_buf_free(struct circ_buf *cb)
138{
139 kfree(cb->buf);
140 kfree(cb);
141}
142
143/*
144 * serial_buf_data_avail
145 *
146 * Return the number of bytes of data available in the circular
147 * buffer.
148 */
149static int serial_buf_data_avail(struct circ_buf *cb)
150{
151 return CIRC_CNT(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
152}
153
154/*
155 * serial_buf_put
156 *
157 * Copy data data from a user buffer and put it into the circular buffer.
158 * Restrict to the amount of space available.
159 *
160 * Return the number of bytes copied.
161 */
162static int serial_buf_put(struct circ_buf *cb, const char *buf, int count)
163{
164 int c, ret = 0;
165 while (1) {
166 c = CIRC_SPACE_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
167 if (count < c)
168 c = count;
169 if (c <= 0)
170 break;
171 memcpy(cb->buf + cb->head, buf, c);
172 cb->head = (cb->head + c) & (AIRCABLE_BUF_SIZE-1);
173 buf += c;
174 count -= c;
175 ret = c;
176 }
177 return ret;
178}
179
180/*
181 * serial_buf_get
182 *
183 * Get data from the circular buffer and copy to the given buffer.
184 * Restrict to the amount of data available.
185 *
186 * Return the number of bytes copied.
187 */
188static int serial_buf_get(struct circ_buf *cb, char *buf, int count)
189{
190 int c, ret = 0;
191 while (1) {
192 c = CIRC_CNT_TO_END(cb->head, cb->tail, AIRCABLE_BUF_SIZE);
193 if (count < c)
194 c = count;
195 if (c <= 0)
196 break;
197 memcpy(buf, cb->buf + cb->tail, c);
198 cb->tail = (cb->tail + c) & (AIRCABLE_BUF_SIZE-1);
199 buf += c;
200 count -= c;
201 ret = c;
202 }
203 return ret;
204}
205
206/* End of circula buffer methods */
207
208static void aircable_send(struct usb_serial_port *port)
209{ 88{
210 int count, result; 89 int count;
211 struct aircable_private *priv = usb_get_serial_port_data(port); 90 unsigned char *buf = dest;
212 unsigned char *buf;
213 __le16 *dbuf;
214 dbg("%s - port %d", __func__, port->number);
215 if (port->write_urb_busy)
216 return;
217
218 count = min(serial_buf_data_avail(priv->tx_buf), MAX_HCI_FRAMESIZE);
219 if (count == 0)
220 return;
221
222 buf = kzalloc(count + HCI_HEADER_LENGTH, GFP_ATOMIC);
223 if (!buf) {
224 dev_err(&port->dev, "%s- kzalloc(%d) failed.\n",
225 __func__, count + HCI_HEADER_LENGTH);
226 return;
227 }
228 91
92 count = kfifo_out_locked(&port->write_fifo, buf + HCI_HEADER_LENGTH,
93 size - HCI_HEADER_LENGTH, &port->lock);
229 buf[0] = TX_HEADER_0; 94 buf[0] = TX_HEADER_0;
230 buf[1] = TX_HEADER_1; 95 buf[1] = TX_HEADER_1;
231 dbuf = (__le16 *)&buf[2]; 96 put_unaligned_le16(count, &buf[2]);
232 *dbuf = cpu_to_le16((u16)count);
233 serial_buf_get(priv->tx_buf, buf + HCI_HEADER_LENGTH,
234 MAX_HCI_FRAMESIZE);
235
236 memcpy(port->write_urb->transfer_buffer, buf,
237 count + HCI_HEADER_LENGTH);
238
239 kfree(buf);
240 port->write_urb_busy = 1;
241 usb_serial_debug_data(debug, &port->dev, __func__,
242 count + HCI_HEADER_LENGTH,
243 port->write_urb->transfer_buffer);
244 port->write_urb->transfer_buffer_length = count + HCI_HEADER_LENGTH;
245 port->write_urb->dev = port->serial->dev;
246 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
247
248 if (result) {
249 dev_err(&port->dev,
250 "%s - failed submitting write urb, error %d\n",
251 __func__, result);
252 port->write_urb_busy = 0;
253 }
254 97
255 schedule_work(&port->work); 98 return count + HCI_HEADER_LENGTH;
256} 99}
257 100
258static void aircable_read(struct work_struct *work)
259{
260 struct aircable_private *priv =
261 container_of(work, struct aircable_private, rx_work);
262 struct usb_serial_port *port = priv->port;
263 struct tty_struct *tty;
264 unsigned char *data;
265 int count;
266 if (priv->rx_flags & THROTTLED) {
267 if (priv->rx_flags & ACTUALLY_THROTTLED)
268 schedule_work(&priv->rx_work);
269 return;
270 }
271
272 /* By now I will flush data to the tty in packages of no more than
273 * 64 bytes, to ensure I do not get throttled.
274 * Ask USB mailing list for better aproach.
275 */
276 tty = tty_port_tty_get(&port->port);
277
278 if (!tty) {
279 schedule_work(&priv->rx_work);
280 dev_err(&port->dev, "%s - No tty available\n", __func__);
281 return ;
282 }
283
284 count = min(64, serial_buf_data_avail(priv->rx_buf));
285
286 if (count <= 0)
287 goto out; /* We have finished sending everything. */
288
289 tty_prepare_flip_string(tty, &data, count);
290 if (!data) {
291 dev_err(&port->dev, "%s- kzalloc(%d) failed.",
292 __func__, count);
293 goto out;
294 }
295
296 serial_buf_get(priv->rx_buf, data, count);
297
298 tty_flip_buffer_push(tty);
299
300 if (serial_buf_data_avail(priv->rx_buf))
301 schedule_work(&priv->rx_work);
302out:
303 tty_kref_put(tty);
304 return;
305}
306/* End of private methods */
307
308static int aircable_probe(struct usb_serial *serial, 101static int aircable_probe(struct usb_serial *serial,
309 const struct usb_device_id *id) 102 const struct usb_device_id *id)
310{ 103{
@@ -330,247 +123,50 @@ static int aircable_probe(struct usb_serial *serial,
330 return 0; 123 return 0;
331} 124}
332 125
333static int aircable_attach(struct usb_serial *serial) 126static int aircable_process_packet(struct tty_struct *tty,
334{ 127 struct usb_serial_port *port, int has_headers,
335 struct usb_serial_port *port = serial->port[0]; 128 char *packet, int len)
336 struct aircable_private *priv;
337
338 priv = kzalloc(sizeof(struct aircable_private), GFP_KERNEL);
339 if (!priv) {
340 dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
341 sizeof(struct aircable_private));
342 return -ENOMEM;
343 }
344
345 /* Allocation of Circular Buffers */
346 priv->tx_buf = serial_buf_alloc();
347 if (priv->tx_buf == NULL) {
348 kfree(priv);
349 return -ENOMEM;
350 }
351
352 priv->rx_buf = serial_buf_alloc();
353 if (priv->rx_buf == NULL) {
354 kfree(priv->tx_buf);
355 kfree(priv);
356 return -ENOMEM;
357 }
358
359 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
360 priv->port = port;
361 INIT_WORK(&priv->rx_work, aircable_read);
362
363 usb_set_serial_port_data(serial->port[0], priv);
364
365 return 0;
366}
367
368static void aircable_release(struct usb_serial *serial)
369{ 129{
370 130 if (has_headers) {
371 struct usb_serial_port *port = serial->port[0]; 131 len -= HCI_HEADER_LENGTH;
372 struct aircable_private *priv = usb_get_serial_port_data(port); 132 packet += HCI_HEADER_LENGTH;
373
374 dbg("%s", __func__);
375
376 if (priv) {
377 serial_buf_free(priv->tx_buf);
378 serial_buf_free(priv->rx_buf);
379 kfree(priv);
380 } 133 }
381} 134 if (len <= 0) {
382 135 dbg("%s - malformed packet", __func__);
383static int aircable_write_room(struct tty_struct *tty) 136 return 0;
384{
385 struct usb_serial_port *port = tty->driver_data;
386 struct aircable_private *priv = usb_get_serial_port_data(port);
387 return serial_buf_data_avail(priv->tx_buf);
388}
389
390static int aircable_write(struct tty_struct *tty, struct usb_serial_port *port,
391 const unsigned char *source, int count)
392{
393 struct aircable_private *priv = usb_get_serial_port_data(port);
394 int temp;
395
396 dbg("%s - port %d, %d bytes", __func__, port->number, count);
397
398 usb_serial_debug_data(debug, &port->dev, __func__, count, source);
399
400 if (!count) {
401 dbg("%s - write request of 0 bytes", __func__);
402 return count;
403 } 137 }
404 138
405 temp = serial_buf_put(priv->tx_buf, source, count); 139 tty_insert_flip_string(tty, packet, len);
406
407 aircable_send(port);
408
409 if (count > AIRCABLE_BUF_SIZE)
410 count = AIRCABLE_BUF_SIZE;
411
412 return count;
413 140
141 return len;
414} 142}
415 143
416static void aircable_write_bulk_callback(struct urb *urb) 144static void aircable_process_read_urb(struct urb *urb)
417{ 145{
418 struct usb_serial_port *port = urb->context; 146 struct usb_serial_port *port = urb->context;
419 int status = urb->status; 147 char *data = (char *)urb->transfer_buffer;
420 int result;
421
422 dbg("%s - urb status: %d", __func__ , status);
423
424 /* This has been taken from cypress_m8.c cypress_write_int_callback */
425 switch (status) {
426 case 0:
427 /* success */
428 break;
429 case -ECONNRESET:
430 case -ENOENT:
431 case -ESHUTDOWN:
432 /* this urb is terminated, clean up */
433 dbg("%s - urb shutting down with status: %d",
434 __func__, status);
435 port->write_urb_busy = 0;
436 return;
437 default:
438 /* error in the urb, so we have to resubmit it */
439 dbg("%s - Overflow in write", __func__);
440 dbg("%s - nonzero write bulk status received: %d",
441 __func__, status);
442 port->write_urb->transfer_buffer_length = 1;
443 port->write_urb->dev = port->serial->dev;
444 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
445 if (result)
446 dev_err(&urb->dev->dev,
447 "%s - failed resubmitting write urb, error %d\n",
448 __func__, result);
449 else
450 return;
451 }
452
453 port->write_urb_busy = 0;
454
455 aircable_send(port);
456}
457
458static void aircable_read_bulk_callback(struct urb *urb)
459{
460 struct usb_serial_port *port = urb->context;
461 struct aircable_private *priv = usb_get_serial_port_data(port);
462 struct tty_struct *tty; 148 struct tty_struct *tty;
463 unsigned long no_packages, remaining, package_length, i; 149 int has_headers;
464 int result, shift = 0; 150 int count;
465 unsigned char *temp; 151 int len;
466 int status = urb->status; 152 int i;
467
468 dbg("%s - port %d", __func__, port->number);
469
470 if (status) {
471 dbg("%s - urb status = %d", __func__, status);
472 if (status == -EPROTO) {
473 dbg("%s - caught -EPROTO, resubmitting the urb",
474 __func__);
475 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
476 usb_rcvbulkpipe(port->serial->dev,
477 port->bulk_in_endpointAddress),
478 port->read_urb->transfer_buffer,
479 port->read_urb->transfer_buffer_length,
480 aircable_read_bulk_callback, port);
481
482 result = usb_submit_urb(urb, GFP_ATOMIC);
483 if (result)
484 dev_err(&urb->dev->dev,
485 "%s - failed resubmitting read urb, error %d\n",
486 __func__, result);
487 return;
488 }
489 dbg("%s - unable to handle the error, exiting.", __func__);
490 return;
491 }
492
493 usb_serial_debug_data(debug, &port->dev, __func__,
494 urb->actual_length, urb->transfer_buffer);
495 153
496 tty = tty_port_tty_get(&port->port); 154 tty = tty_port_tty_get(&port->port);
497 if (tty && urb->actual_length) { 155 if (!tty)
498 if (urb->actual_length <= 2) { 156 return;
499 /* This is an incomplete package */
500 serial_buf_put(priv->rx_buf, urb->transfer_buffer,
501 urb->actual_length);
502 } else {
503 temp = urb->transfer_buffer;
504 if (temp[0] == RX_HEADER_0)
505 shift = HCI_HEADER_LENGTH;
506
507 remaining = urb->actual_length;
508 no_packages = urb->actual_length / (HCI_COMPLETE_FRAME);
509
510 if (urb->actual_length % HCI_COMPLETE_FRAME != 0)
511 no_packages++;
512 157
513 for (i = 0; i < no_packages; i++) { 158 has_headers = (urb->actual_length > 2 && data[0] == RX_HEADER_0);
514 if (remaining > (HCI_COMPLETE_FRAME))
515 package_length = HCI_COMPLETE_FRAME;
516 else
517 package_length = remaining;
518 remaining -= package_length;
519 159
520 serial_buf_put(priv->rx_buf, 160 count = 0;
521 urb->transfer_buffer + shift + 161 for (i = 0; i < urb->actual_length; i += HCI_COMPLETE_FRAME) {
522 (HCI_COMPLETE_FRAME) * (i), 162 len = min_t(int, urb->actual_length - i, HCI_COMPLETE_FRAME);
523 package_length - shift); 163 count += aircable_process_packet(tty, port, has_headers,
524 } 164 &data[i], len);
525 }
526 aircable_read(&priv->rx_work);
527 } 165 }
528 tty_kref_put(tty);
529
530 /* Schedule the next read */
531 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
532 usb_rcvbulkpipe(port->serial->dev,
533 port->bulk_in_endpointAddress),
534 port->read_urb->transfer_buffer,
535 port->read_urb->transfer_buffer_length,
536 aircable_read_bulk_callback, port);
537
538 result = usb_submit_urb(urb, GFP_ATOMIC);
539 if (result && result != -EPERM)
540 dev_err(&urb->dev->dev,
541 "%s - failed resubmitting read urb, error %d\n",
542 __func__, result);
543}
544
545/* Based on ftdi_sio.c throttle */
546static void aircable_throttle(struct tty_struct *tty)
547{
548 struct usb_serial_port *port = tty->driver_data;
549 struct aircable_private *priv = usb_get_serial_port_data(port);
550 166
551 dbg("%s - port %d", __func__, port->number); 167 if (count)
552 168 tty_flip_buffer_push(tty);
553 spin_lock_irq(&priv->rx_lock); 169 tty_kref_put(tty);
554 priv->rx_flags |= THROTTLED;
555 spin_unlock_irq(&priv->rx_lock);
556}
557
558/* Based on ftdi_sio.c unthrottle */
559static void aircable_unthrottle(struct tty_struct *tty)
560{
561 struct usb_serial_port *port = tty->driver_data;
562 struct aircable_private *priv = usb_get_serial_port_data(port);
563 int actually_throttled;
564
565 dbg("%s - port %d", __func__, port->number);
566
567 spin_lock_irq(&priv->rx_lock);
568 actually_throttled = priv->rx_flags & ACTUALLY_THROTTLED;
569 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
570 spin_unlock_irq(&priv->rx_lock);
571
572 if (actually_throttled)
573 schedule_work(&priv->rx_work);
574} 170}
575 171
576static struct usb_driver aircable_driver = { 172static struct usb_driver aircable_driver = {
@@ -589,15 +185,12 @@ static struct usb_serial_driver aircable_device = {
589 .usb_driver = &aircable_driver, 185 .usb_driver = &aircable_driver,
590 .id_table = id_table, 186 .id_table = id_table,
591 .num_ports = 1, 187 .num_ports = 1,
592 .attach = aircable_attach, 188 .bulk_out_size = HCI_COMPLETE_FRAME,
593 .probe = aircable_probe, 189 .probe = aircable_probe,
594 .release = aircable_release, 190 .process_read_urb = aircable_process_read_urb,
595 .write = aircable_write, 191 .prepare_write_buffer = aircable_prepare_write_buffer,
596 .write_room = aircable_write_room, 192 .throttle = usb_serial_generic_throttle,
597 .write_bulk_callback = aircable_write_bulk_callback, 193 .unthrottle = usb_serial_generic_unthrottle,
598 .read_bulk_callback = aircable_read_bulk_callback,
599 .throttle = aircable_throttle,
600 .unthrottle = aircable_unthrottle,
601}; 194};
602 195
603static int __init aircable_init(void) 196static int __init aircable_init(void)
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 9b66bf19f751..4e41a2a39422 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -42,7 +42,7 @@ static int debug;
42 * Version information 42 * Version information
43 */ 43 */
44 44
45#define DRIVER_VERSION "v0.5" 45#define DRIVER_VERSION "v0.6"
46#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>" 46#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>"
47#define DRIVER_DESC "USB ARK3116 serial/IrDA driver" 47#define DRIVER_DESC "USB ARK3116 serial/IrDA driver"
48#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA" 48#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA"
@@ -355,14 +355,11 @@ static void ark3116_close(struct usb_serial_port *port)
355 /* deactivate interrupts */ 355 /* deactivate interrupts */
356 ark3116_write_reg(serial, UART_IER, 0); 356 ark3116_write_reg(serial, UART_IER, 0);
357 357
358 /* shutdown any bulk reads that might be going on */ 358 usb_serial_generic_close(port);
359 if (serial->num_bulk_out)
360 usb_kill_urb(port->write_urb);
361 if (serial->num_bulk_in)
362 usb_kill_urb(port->read_urb);
363 if (serial->num_interrupt_in) 359 if (serial->num_interrupt_in)
364 usb_kill_urb(port->interrupt_in_urb); 360 usb_kill_urb(port->interrupt_in_urb);
365 } 361 }
362
366} 363}
367 364
368static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) 365static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -675,87 +672,45 @@ static void ark3116_read_int_callback(struct urb *urb)
675 * error for the next block of data as well... 672 * error for the next block of data as well...
676 * For now, let's pretend this can't happen. 673 * For now, let's pretend this can't happen.
677 */ 674 */
678 675static void ark3116_process_read_urb(struct urb *urb)
679static void send_to_tty(struct tty_struct *tty,
680 const unsigned char *chars,
681 size_t size, char flag)
682{ 676{
683 if (size == 0) 677 struct usb_serial_port *port = urb->context;
684 return;
685 if (flag == TTY_NORMAL) {
686 tty_insert_flip_string(tty, chars, size);
687 } else {
688 int i;
689 for (i = 0; i < size; ++i)
690 tty_insert_flip_char(tty, chars[i], flag);
691 }
692}
693
694static void ark3116_read_bulk_callback(struct urb *urb)
695{
696 struct usb_serial_port *port = urb->context;
697 struct ark3116_private *priv = usb_get_serial_port_data(port); 678 struct ark3116_private *priv = usb_get_serial_port_data(port);
698 const __u8 *data = urb->transfer_buffer;
699 int status = urb->status;
700 struct tty_struct *tty; 679 struct tty_struct *tty;
680 unsigned char *data = urb->transfer_buffer;
681 char tty_flag = TTY_NORMAL;
701 unsigned long flags; 682 unsigned long flags;
702 int result;
703 char flag;
704 __u32 lsr; 683 __u32 lsr;
705 684
706 switch (status) { 685 /* update line status */
707 case -ECONNRESET: 686 spin_lock_irqsave(&priv->status_lock, flags);
708 case -ENOENT: 687 lsr = priv->lsr;
709 case -ESHUTDOWN: 688 priv->lsr &= ~UART_LSR_BRK_ERROR_BITS;
710 /* this urb is terminated, clean up */ 689 spin_unlock_irqrestore(&priv->status_lock, flags);
711 dbg("%s - urb shutting down with status: %d", 690
712 __func__, status); 691 if (!urb->actual_length)
713 return; 692 return;
714 default:
715 dbg("%s - nonzero urb status received: %d",
716 __func__, status);
717 break;
718 case 0: /* success */
719 693
720 spin_lock_irqsave(&priv->status_lock, flags); 694 tty = tty_port_tty_get(&port->port);
721 lsr = priv->lsr; 695 if (!tty)
722 /* clear error bits */ 696 return;
723 priv->lsr &= ~UART_LSR_BRK_ERROR_BITS; 697
724 spin_unlock_irqrestore(&priv->status_lock, flags); 698 if (lsr & UART_LSR_BRK_ERROR_BITS) {
725 699 if (lsr & UART_LSR_BI)
726 if (unlikely(lsr & UART_LSR_BI)) 700 tty_flag = TTY_BREAK;
727 flag = TTY_BREAK; 701 else if (lsr & UART_LSR_PE)
728 else if (unlikely(lsr & UART_LSR_PE)) 702 tty_flag = TTY_PARITY;
729 flag = TTY_PARITY; 703 else if (lsr & UART_LSR_FE)
730 else if (unlikely(lsr & UART_LSR_FE)) 704 tty_flag = TTY_FRAME;
731 flag = TTY_FRAME;
732 else
733 flag = TTY_NORMAL;
734
735 tty = tty_port_tty_get(&port->port);
736 if (tty) {
737 /* overrun is special, not associated with a char */
738 if (unlikely(lsr & UART_LSR_OE))
739 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
740 send_to_tty(tty, data, urb->actual_length, flag);
741 tty_flip_buffer_push(tty);
742 tty_kref_put(tty);
743 }
744 705
745 /* Throttle the device if requested by tty */ 706 /* overrun is special, not associated with a char */
746 spin_lock_irqsave(&port->lock, flags); 707 if (lsr & UART_LSR_OE)
747 port->throttled = port->throttle_req; 708 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
748 if (port->throttled) {
749 spin_unlock_irqrestore(&port->lock, flags);
750 return;
751 } else
752 spin_unlock_irqrestore(&port->lock, flags);
753 } 709 }
754 /* Continue reading from device */ 710 tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
755 result = usb_submit_urb(urb, GFP_ATOMIC); 711 urb->actual_length);
756 if (result) 712 tty_flip_buffer_push(tty);
757 dev_err(&urb->dev->dev, "%s - failed resubmitting" 713 tty_kref_put(tty);
758 " read urb, error %d\n", __func__, result);
759} 714}
760 715
761static struct usb_driver ark3116_driver = { 716static struct usb_driver ark3116_driver = {
@@ -785,7 +740,7 @@ static struct usb_serial_driver ark3116_device = {
785 .close = ark3116_close, 740 .close = ark3116_close,
786 .break_ctl = ark3116_break_ctl, 741 .break_ctl = ark3116_break_ctl,
787 .read_int_callback = ark3116_read_int_callback, 742 .read_int_callback = ark3116_read_int_callback,
788 .read_bulk_callback = ark3116_read_bulk_callback, 743 .process_read_urb = ark3116_process_read_urb,
789}; 744};
790 745
791static int __init ark3116_init(void) 746static int __init ark3116_init(void)
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 1295e44e3f1c..36df35295db2 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2000 William Greathouse (wgreathouse@smva.com) 4 * Copyright (C) 2000 William Greathouse (wgreathouse@smva.com)
5 * Copyright (C) 2000-2001 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 2000-2001 Greg Kroah-Hartman (greg@kroah.com)
6 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
6 * 7 *
7 * This program is largely derived from work by the linux-usb group 8 * This program is largely derived from work by the linux-usb group
8 * and associated source files. Please see the usb/serial files for 9 * and associated source files. Please see the usb/serial files for
@@ -84,7 +85,7 @@ static int debug;
84/* 85/*
85 * Version Information 86 * Version Information
86 */ 87 */
87#define DRIVER_VERSION "v1.2" 88#define DRIVER_VERSION "v1.3"
88#define DRIVER_AUTHOR "William Greathouse <wgreathouse@smva.com>" 89#define DRIVER_AUTHOR "William Greathouse <wgreathouse@smva.com>"
89#define DRIVER_DESC "USB Belkin Serial converter driver" 90#define DRIVER_DESC "USB Belkin Serial converter driver"
90 91
@@ -95,6 +96,7 @@ static int belkin_sa_open(struct tty_struct *tty,
95 struct usb_serial_port *port); 96 struct usb_serial_port *port);
96static void belkin_sa_close(struct usb_serial_port *port); 97static void belkin_sa_close(struct usb_serial_port *port);
97static void belkin_sa_read_int_callback(struct urb *urb); 98static void belkin_sa_read_int_callback(struct urb *urb);
99static void belkin_sa_process_read_urb(struct urb *urb);
98static void belkin_sa_set_termios(struct tty_struct *tty, 100static void belkin_sa_set_termios(struct tty_struct *tty,
99 struct usb_serial_port *port, struct ktermios * old); 101 struct usb_serial_port *port, struct ktermios * old);
100static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state); 102static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state);
@@ -112,7 +114,6 @@ static const struct usb_device_id id_table_combined[] = {
112 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) }, 114 { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) },
113 { } /* Terminating entry */ 115 { } /* Terminating entry */
114}; 116};
115
116MODULE_DEVICE_TABLE(usb, id_table_combined); 117MODULE_DEVICE_TABLE(usb, id_table_combined);
117 118
118static struct usb_driver belkin_driver = { 119static struct usb_driver belkin_driver = {
@@ -120,7 +121,7 @@ static struct usb_driver belkin_driver = {
120 .probe = usb_serial_probe, 121 .probe = usb_serial_probe,
121 .disconnect = usb_serial_disconnect, 122 .disconnect = usb_serial_disconnect,
122 .id_table = id_table_combined, 123 .id_table = id_table_combined,
123 .no_dynamic_id = 1, 124 .no_dynamic_id = 1,
124}; 125};
125 126
126/* All of the device info needed for the serial converters */ 127/* All of the device info needed for the serial converters */
@@ -136,7 +137,7 @@ static struct usb_serial_driver belkin_device = {
136 .open = belkin_sa_open, 137 .open = belkin_sa_open,
137 .close = belkin_sa_close, 138 .close = belkin_sa_close,
138 .read_int_callback = belkin_sa_read_int_callback, 139 .read_int_callback = belkin_sa_read_int_callback,
139 /* How we get the status info */ 140 .process_read_urb = belkin_sa_process_read_urb,
140 .set_termios = belkin_sa_set_termios, 141 .set_termios = belkin_sa_set_termios,
141 .break_ctl = belkin_sa_break_ctl, 142 .break_ctl = belkin_sa_break_ctl,
142 .tiocmget = belkin_sa_tiocmget, 143 .tiocmget = belkin_sa_tiocmget,
@@ -145,7 +146,6 @@ static struct usb_serial_driver belkin_device = {
145 .release = belkin_sa_release, 146 .release = belkin_sa_release,
146}; 147};
147 148
148
149struct belkin_sa_private { 149struct belkin_sa_private {
150 spinlock_t lock; 150 spinlock_t lock;
151 unsigned long control_state; 151 unsigned long control_state;
@@ -196,62 +196,43 @@ static int belkin_sa_startup(struct usb_serial *serial)
196 return 0; 196 return 0;
197} 197}
198 198
199
200static void belkin_sa_release(struct usb_serial *serial) 199static void belkin_sa_release(struct usb_serial *serial)
201{ 200{
202 struct belkin_sa_private *priv;
203 int i; 201 int i;
204 202
205 dbg("%s", __func__); 203 dbg("%s", __func__);
206 204
207 for (i = 0; i < serial->num_ports; ++i) { 205 for (i = 0; i < serial->num_ports; ++i)
208 /* My special items, the standard routines free my urbs */ 206 kfree(usb_get_serial_port_data(serial->port[i]));
209 priv = usb_get_serial_port_data(serial->port[i]);
210 kfree(priv);
211 }
212} 207}
213 208
214 209static int belkin_sa_open(struct tty_struct *tty,
215static int belkin_sa_open(struct tty_struct *tty,
216 struct usb_serial_port *port) 210 struct usb_serial_port *port)
217{ 211{
218 int retval = 0; 212 int retval;
219 213
220 dbg("%s port %d", __func__, port->number); 214 dbg("%s port %d", __func__, port->number);
221 215
222 /*Start reading from the device*/
223 /* TODO: Look at possibility of submitting multiple URBs to device to
224 * enhance buffering. Win trace shows 16 initial read URBs.
225 */
226 port->read_urb->dev = port->serial->dev;
227 retval = usb_submit_urb(port->read_urb, GFP_KERNEL);
228 if (retval) {
229 dev_err(&port->dev, "usb_submit_urb(read bulk) failed\n");
230 goto exit;
231 }
232
233 port->interrupt_in_urb->dev = port->serial->dev;
234 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 216 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
235 if (retval) { 217 if (retval) {
236 usb_kill_urb(port->read_urb);
237 dev_err(&port->dev, "usb_submit_urb(read int) failed\n"); 218 dev_err(&port->dev, "usb_submit_urb(read int) failed\n");
219 return retval;
238 } 220 }
239 221
240exit: 222 retval = usb_serial_generic_open(tty, port);
241 return retval; 223 if (retval)
242} /* belkin_sa_open */ 224 usb_kill_urb(port->interrupt_in_urb);
243 225
226 return retval;
227}
244 228
245static void belkin_sa_close(struct usb_serial_port *port) 229static void belkin_sa_close(struct usb_serial_port *port)
246{ 230{
247 dbg("%s port %d", __func__, port->number); 231 dbg("%s port %d", __func__, port->number);
248 232
249 /* shutdown our bulk reads and writes */ 233 usb_serial_generic_close(port);
250 usb_kill_urb(port->write_urb);
251 usb_kill_urb(port->read_urb);
252 usb_kill_urb(port->interrupt_in_urb); 234 usb_kill_urb(port->interrupt_in_urb);
253} /* belkin_sa_close */ 235}
254
255 236
256static void belkin_sa_read_int_callback(struct urb *urb) 237static void belkin_sa_read_int_callback(struct urb *urb)
257{ 238{
@@ -310,31 +291,7 @@ static void belkin_sa_read_int_callback(struct urb *urb)
310 else 291 else
311 priv->control_state &= ~TIOCM_CD; 292 priv->control_state &= ~TIOCM_CD;
312 293
313 /* Now to report any errors */
314 priv->last_lsr = data[BELKIN_SA_LSR_INDEX]; 294 priv->last_lsr = data[BELKIN_SA_LSR_INDEX];
315#if 0
316 /*
317 * fill in the flip buffer here, but I do not know the relation
318 * to the current/next receive buffer or characters. I need
319 * to look in to this before committing any code.
320 */
321 if (priv->last_lsr & BELKIN_SA_LSR_ERR) {
322 tty = tty_port_tty_get(&port->port);
323 /* Overrun Error */
324 if (priv->last_lsr & BELKIN_SA_LSR_OE) {
325 }
326 /* Parity Error */
327 if (priv->last_lsr & BELKIN_SA_LSR_PE) {
328 }
329 /* Framing Error */
330 if (priv->last_lsr & BELKIN_SA_LSR_FE) {
331 }
332 /* Break Indicator */
333 if (priv->last_lsr & BELKIN_SA_LSR_BI) {
334 }
335 tty_kref_put(tty);
336 }
337#endif
338 spin_unlock_irqrestore(&priv->lock, flags); 295 spin_unlock_irqrestore(&priv->lock, flags);
339exit: 296exit:
340 retval = usb_submit_urb(urb, GFP_ATOMIC); 297 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -343,6 +300,53 @@ exit:
343 "result %d\n", __func__, retval); 300 "result %d\n", __func__, retval);
344} 301}
345 302
303static void belkin_sa_process_read_urb(struct urb *urb)
304{
305 struct usb_serial_port *port = urb->context;
306 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
307 struct tty_struct *tty;
308 unsigned char *data = urb->transfer_buffer;
309 unsigned long flags;
310 unsigned char status;
311 char tty_flag;
312
313 /* Update line status */
314 tty_flag = TTY_NORMAL;
315
316 spin_lock_irqsave(&priv->lock, flags);
317 status = priv->last_lsr;
318 priv->last_lsr &= ~BELKIN_SA_LSR_ERR;
319 spin_unlock_irqrestore(&priv->lock, flags);
320
321 if (!urb->actual_length)
322 return;
323
324 tty = tty_port_tty_get(&port->port);
325 if (!tty)
326 return;
327
328 if (status & BELKIN_SA_LSR_ERR) {
329 /* Break takes precedence over parity, which takes precedence
330 * over framing errors. */
331 if (status & BELKIN_SA_LSR_BI)
332 tty_flag = TTY_BREAK;
333 else if (status & BELKIN_SA_LSR_PE)
334 tty_flag = TTY_PARITY;
335 else if (status & BELKIN_SA_LSR_FE)
336 tty_flag = TTY_FRAME;
337 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
338
339 /* Overrun is special, not associated with a char. */
340 if (status & BELKIN_SA_LSR_OE)
341 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
342 }
343
344 tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
345 urb->actual_length);
346 tty_flip_buffer_push(tty);
347 tty_kref_put(tty);
348}
349
346static void belkin_sa_set_termios(struct tty_struct *tty, 350static void belkin_sa_set_termios(struct tty_struct *tty,
347 struct usb_serial_port *port, struct ktermios *old_termios) 351 struct usb_serial_port *port, struct ktermios *old_termios)
348{ 352{
@@ -482,8 +486,7 @@ static void belkin_sa_set_termios(struct tty_struct *tty,
482 spin_lock_irqsave(&priv->lock, flags); 486 spin_lock_irqsave(&priv->lock, flags);
483 priv->control_state = control_state; 487 priv->control_state = control_state;
484 spin_unlock_irqrestore(&priv->lock, flags); 488 spin_unlock_irqrestore(&priv->lock, flags);
485} /* belkin_sa_set_termios */ 489}
486
487 490
488static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state) 491static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state)
489{ 492{
@@ -494,7 +497,6 @@ static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state)
494 dev_err(&port->dev, "Set break_ctl %d\n", break_state); 497 dev_err(&port->dev, "Set break_ctl %d\n", break_state);
495} 498}
496 499
497
498static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file) 500static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file)
499{ 501{
500 struct usb_serial_port *port = tty->driver_data; 502 struct usb_serial_port *port = tty->driver_data;
@@ -511,7 +513,6 @@ static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file)
511 return control_state; 513 return control_state;
512} 514}
513 515
514
515static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file, 516static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
516 unsigned int set, unsigned int clear) 517 unsigned int set, unsigned int clear)
517{ 518{
@@ -583,7 +584,6 @@ failed_usb_serial_register:
583 return retval; 584 return retval;
584} 585}
585 586
586
587static void __exit belkin_sa_exit (void) 587static void __exit belkin_sa_exit (void)
588{ 588{
589 usb_deregister(&belkin_driver); 589 usb_deregister(&belkin_driver);
diff --git a/drivers/usb/serial/belkin_sa.h b/drivers/usb/serial/belkin_sa.h
index c66a6730d38c..c74b58ab56f9 100644
--- a/drivers/usb/serial/belkin_sa.h
+++ b/drivers/usb/serial/belkin_sa.h
@@ -8,10 +8,10 @@
8 * and associated source files. Please see the usb/serial files for 8 * and associated source files. Please see the usb/serial files for
9 * individual credits and copyrights. 9 * individual credits and copyrights.
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 * 15 *
16 * See Documentation/usb/usb-serial.txt for more information on using this 16 * See Documentation/usb/usb-serial.txt for more information on using this
17 * driver 17 * driver
@@ -66,7 +66,7 @@
66#ifdef WHEN_I_LEARN_THIS 66#ifdef WHEN_I_LEARN_THIS
67#define BELKIN_SA_SET_MAGIC_REQUEST 17 /* I don't know, possibly flush */ 67#define BELKIN_SA_SET_MAGIC_REQUEST 17 /* I don't know, possibly flush */
68 /* (always in Wininit sequence before flow control) */ 68 /* (always in Wininit sequence before flow control) */
69#define BELKIN_SA_RESET xx /* Reset the port */ 69#define BELKIN_SA_RESET xx /* Reset the port */
70#define BELKIN_SA_GET_MODEM_STATUS xx /* Force return of modem status register */ 70#define BELKIN_SA_GET_MODEM_STATUS xx /* Force return of modem status register */
71#endif 71#endif
72 72
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 7e8e39818414..63f7cc45bcac 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -305,10 +305,7 @@ static void ch341_close(struct usb_serial_port *port)
305{ 305{
306 dbg("%s - port %d", __func__, port->number); 306 dbg("%s - port %d", __func__, port->number);
307 307
308 /* shutdown our urbs */ 308 usb_serial_generic_close(port);
309 dbg("%s - shutting down urbs", __func__);
310 usb_kill_urb(port->write_urb);
311 usb_kill_urb(port->read_urb);
312 usb_kill_urb(port->interrupt_in_urb); 309 usb_kill_urb(port->interrupt_in_urb);
313} 310}
314 311
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index f347da2ef00a..1ee6b2ab0f89 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -66,7 +66,7 @@ static int usb_console_setup(struct console *co, char *options)
66 struct usb_serial_port *port; 66 struct usb_serial_port *port;
67 int retval; 67 int retval;
68 struct tty_struct *tty = NULL; 68 struct tty_struct *tty = NULL;
69 struct ktermios *termios = NULL, dummy; 69 struct ktermios dummy;
70 70
71 dbg("%s", __func__); 71 dbg("%s", __func__);
72 72
@@ -141,15 +141,14 @@ static int usb_console_setup(struct console *co, char *options)
141 goto reset_open_count; 141 goto reset_open_count;
142 } 142 }
143 kref_init(&tty->kref); 143 kref_init(&tty->kref);
144 termios = kzalloc(sizeof(*termios), GFP_KERNEL); 144 tty_port_tty_set(&port->port, tty);
145 if (!termios) { 145 tty->driver = usb_serial_tty_driver;
146 tty->index = co->index;
147 if (tty_init_termios(tty)) {
146 retval = -ENOMEM; 148 retval = -ENOMEM;
147 err("no more memory"); 149 err("no more memory");
148 goto free_tty; 150 goto free_tty;
149 } 151 }
150 memset(&dummy, 0, sizeof(struct ktermios));
151 tty->termios = termios;
152 tty_port_tty_set(&port->port, tty);
153 } 152 }
154 153
155 /* only call the device specific open if this 154 /* only call the device specific open if this
@@ -161,16 +160,16 @@ static int usb_console_setup(struct console *co, char *options)
161 160
162 if (retval) { 161 if (retval) {
163 err("could not open USB console port"); 162 err("could not open USB console port");
164 goto free_termios; 163 goto fail;
165 } 164 }
166 165
167 if (serial->type->set_termios) { 166 if (serial->type->set_termios) {
168 termios->c_cflag = cflag; 167 tty->termios->c_cflag = cflag;
169 tty_termios_encode_baud_rate(termios, baud, baud); 168 tty_termios_encode_baud_rate(tty->termios, baud, baud);
169 memset(&dummy, 0, sizeof(struct ktermios));
170 serial->type->set_termios(tty, port, &dummy); 170 serial->type->set_termios(tty, port, &dummy);
171 171
172 tty_port_tty_set(&port->port, NULL); 172 tty_port_tty_set(&port->port, NULL);
173 kfree(termios);
174 kfree(tty); 173 kfree(tty);
175 } 174 }
176 set_bit(ASYNCB_INITIALIZED, &port->port.flags); 175 set_bit(ASYNCB_INITIALIZED, &port->port.flags);
@@ -180,14 +179,12 @@ static int usb_console_setup(struct console *co, char *options)
180 --port->port.count; 179 --port->port.count;
181 /* The console is special in terms of closing the device so 180 /* The console is special in terms of closing the device so
182 * indicate this port is now acting as a system console. */ 181 * indicate this port is now acting as a system console. */
183 port->console = 1;
184 port->port.console = 1; 182 port->port.console = 1;
185 183
186 mutex_unlock(&serial->disc_mutex); 184 mutex_unlock(&serial->disc_mutex);
187 return retval; 185 return retval;
188 186
189 free_termios: 187 fail:
190 kfree(termios);
191 tty_port_tty_set(&port->port, NULL); 188 tty_port_tty_set(&port->port, NULL);
192 free_tty: 189 free_tty:
193 kfree(tty); 190 kfree(tty);
@@ -217,7 +214,7 @@ static void usb_console_write(struct console *co,
217 214
218 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 215 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
219 216
220 if (!port->console) { 217 if (!port->port.console) {
221 dbg("%s - port not opened", __func__); 218 dbg("%s - port not opened", __func__);
222 return; 219 return;
223 } 220 }
@@ -313,7 +310,7 @@ void usb_serial_console_exit(void)
313{ 310{
314 if (usbcons_info.port) { 311 if (usbcons_info.port) {
315 unregister_console(&usbcons); 312 unregister_console(&usbcons);
316 usbcons_info.port->console = 0; 313 usbcons_info.port->port.console = 0;
317 usbcons_info.port = NULL; 314 usbcons_info.port = NULL;
318 } 315 }
319} 316}
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index ec9b0449ccf6..8b8c7976b4c0 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -34,7 +34,6 @@
34 * Function Prototypes 34 * Function Prototypes
35 */ 35 */
36static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); 36static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *);
37static void cp210x_cleanup(struct usb_serial_port *);
38static void cp210x_close(struct usb_serial_port *); 37static void cp210x_close(struct usb_serial_port *);
39static void cp210x_get_termios(struct tty_struct *, 38static void cp210x_get_termios(struct tty_struct *,
40 struct usb_serial_port *port); 39 struct usb_serial_port *port);
@@ -49,7 +48,6 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *,
49 unsigned int, unsigned int); 48 unsigned int, unsigned int);
50static void cp210x_break_ctl(struct tty_struct *, int); 49static void cp210x_break_ctl(struct tty_struct *, int);
51static int cp210x_startup(struct usb_serial *); 50static int cp210x_startup(struct usb_serial *);
52static void cp210x_disconnect(struct usb_serial *);
53static void cp210x_dtr_rts(struct usb_serial_port *p, int on); 51static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
54static int cp210x_carrier_raised(struct usb_serial_port *p); 52static int cp210x_carrier_raised(struct usb_serial_port *p);
55 53
@@ -61,6 +59,8 @@ static const struct usb_device_id id_table[] = {
61 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ 59 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */
62 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ 60 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
63 { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */ 61 { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */
62 { USB_DEVICE(0x0BED, 0x1100) }, /* MEI (TM) Cashflow-SC Bill/Voucher Acceptor */
63 { USB_DEVICE(0x0BED, 0x1101) }, /* MEI series 2000 Combo Acceptor */
64 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ 64 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
65 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ 65 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
66 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ 66 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */
@@ -72,9 +72,12 @@ static const struct usb_device_id id_table[] = {
72 { USB_DEVICE(0x10C4, 0x1601) }, /* Arkham Technology DS101 Adapter */ 72 { USB_DEVICE(0x10C4, 0x1601) }, /* Arkham Technology DS101 Adapter */
73 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ 73 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
74 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ 74 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
75 { USB_DEVICE(0x10C4, 0x8044) }, /* Cygnal Debug Adapter */
76 { USB_DEVICE(0x10C4, 0x804E) }, /* Software Bisque Paramount ME build-in converter */
75 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ 77 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
76 { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */ 78 { USB_DEVICE(0x10C4, 0x8054) }, /* Enfora GSM2228 */
77 { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */ 79 { USB_DEVICE(0x10C4, 0x8066) }, /* Argussoft In-System Programmer */
80 { USB_DEVICE(0x10C4, 0x806F) }, /* IMS USB to RS422 Converter Cable */
78 { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */ 81 { USB_DEVICE(0x10C4, 0x807A) }, /* Crumb128 board */
79 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */ 82 { USB_DEVICE(0x10C4, 0x80CA) }, /* Degree Controls Inc */
80 { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */ 83 { USB_DEVICE(0x10C4, 0x80DD) }, /* Tracient RFID */
@@ -82,12 +85,15 @@ static const struct usb_device_id id_table[] = {
82 { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */ 85 { USB_DEVICE(0x10C4, 0x8115) }, /* Arygon NFC/Mifare Reader */
83 { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */ 86 { USB_DEVICE(0x10C4, 0x813D) }, /* Burnside Telecom Deskmobile */
84 { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */ 87 { USB_DEVICE(0x10C4, 0x813F) }, /* Tams Master Easy Control */
88 { USB_DEVICE(0x10C4, 0x8149) }, /* West Mountain Radio Computerized Battery Analyzer */
85 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */ 89 { USB_DEVICE(0x10C4, 0x814A) }, /* West Mountain Radio RIGblaster P&P */
86 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */ 90 { USB_DEVICE(0x10C4, 0x814B) }, /* West Mountain Radio RIGtalk */
87 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */ 91 { USB_DEVICE(0x10C4, 0x815E) }, /* Helicomm IP-Link 1220-DVM */
92 { USB_DEVICE(0x10C4, 0x818B) }, /* AVIT Research USB to TTL */
88 { USB_DEVICE(0x10C4, 0x819F) }, /* MJS USB Toslink Switcher */ 93 { USB_DEVICE(0x10C4, 0x819F) }, /* MJS USB Toslink Switcher */
89 { USB_DEVICE(0x10C4, 0x81A6) }, /* ThinkOptics WavIt */ 94 { USB_DEVICE(0x10C4, 0x81A6) }, /* ThinkOptics WavIt */
90 { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */ 95 { USB_DEVICE(0x10C4, 0x81AC) }, /* MSD Dash Hawk */
96 { USB_DEVICE(0x10C4, 0x81AD) }, /* INSYS USB Modem */
91 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ 97 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
92 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ 98 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
93 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ 99 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
@@ -105,6 +111,7 @@ static const struct usb_device_id id_table[] = {
105 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ 111 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
106 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 112 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
107 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 113 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
114 { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */
108 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */ 115 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
109 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */ 116 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
110 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ 117 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
@@ -115,6 +122,8 @@ static const struct usb_device_id id_table[] = {
115 { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */ 122 { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */
116 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ 123 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
117 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 124 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
125 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */
126 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */
118 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 127 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
119 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ 128 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
120 { } /* Terminating Entry */ 129 { } /* Terminating Entry */
@@ -138,6 +147,8 @@ static struct usb_serial_driver cp210x_device = {
138 .usb_driver = &cp210x_driver, 147 .usb_driver = &cp210x_driver,
139 .id_table = id_table, 148 .id_table = id_table,
140 .num_ports = 1, 149 .num_ports = 1,
150 .bulk_in_size = 256,
151 .bulk_out_size = 256,
141 .open = cp210x_open, 152 .open = cp210x_open,
142 .close = cp210x_close, 153 .close = cp210x_close,
143 .break_ctl = cp210x_break_ctl, 154 .break_ctl = cp210x_break_ctl,
@@ -145,7 +156,6 @@ static struct usb_serial_driver cp210x_device = {
145 .tiocmget = cp210x_tiocmget, 156 .tiocmget = cp210x_tiocmget,
146 .tiocmset = cp210x_tiocmset, 157 .tiocmset = cp210x_tiocmset,
147 .attach = cp210x_startup, 158 .attach = cp210x_startup,
148 .disconnect = cp210x_disconnect,
149 .dtr_rts = cp210x_dtr_rts, 159 .dtr_rts = cp210x_dtr_rts,
150 .carrier_raised = cp210x_carrier_raised 160 .carrier_raised = cp210x_carrier_raised
151}; 161};
@@ -370,7 +380,6 @@ static unsigned int cp210x_quantise_baudrate(unsigned int baud) {
370 380
371static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) 381static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
372{ 382{
373 struct usb_serial *serial = port->serial;
374 int result; 383 int result;
375 384
376 dbg("%s - port %d", __func__, port->number); 385 dbg("%s - port %d", __func__, port->number);
@@ -381,49 +390,20 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
381 return -EPROTO; 390 return -EPROTO;
382 } 391 }
383 392
384 /* Start reading from the device */ 393 result = usb_serial_generic_open(tty, port);
385 usb_fill_bulk_urb(port->read_urb, serial->dev, 394 if (result)
386 usb_rcvbulkpipe(serial->dev,
387 port->bulk_in_endpointAddress),
388 port->read_urb->transfer_buffer,
389 port->read_urb->transfer_buffer_length,
390 serial->type->read_bulk_callback,
391 port);
392 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
393 if (result) {
394 dev_err(&port->dev, "%s - failed resubmitting read urb, "
395 "error %d\n", __func__, result);
396 return result; 395 return result;
397 }
398 396
399 /* Configure the termios structure */ 397 /* Configure the termios structure */
400 cp210x_get_termios(tty, port); 398 cp210x_get_termios(tty, port);
401 return 0; 399 return 0;
402} 400}
403 401
404static void cp210x_cleanup(struct usb_serial_port *port)
405{
406 struct usb_serial *serial = port->serial;
407
408 dbg("%s - port %d", __func__, port->number);
409
410 if (serial->dev) {
411 /* shutdown any bulk reads that might be going on */
412 if (serial->num_bulk_out)
413 usb_kill_urb(port->write_urb);
414 if (serial->num_bulk_in)
415 usb_kill_urb(port->read_urb);
416 }
417}
418
419static void cp210x_close(struct usb_serial_port *port) 402static void cp210x_close(struct usb_serial_port *port)
420{ 403{
421 dbg("%s - port %d", __func__, port->number); 404 dbg("%s - port %d", __func__, port->number);
422 405
423 /* shutdown our urbs */ 406 usb_serial_generic_close(port);
424 dbg("%s - shutting down urbs", __func__);
425 usb_kill_urb(port->write_urb);
426 usb_kill_urb(port->read_urb);
427 407
428 mutex_lock(&port->serial->disc_mutex); 408 mutex_lock(&port->serial->disc_mutex);
429 if (!port->serial->disconnected) 409 if (!port->serial->disconnected)
@@ -807,17 +787,6 @@ static int cp210x_startup(struct usb_serial *serial)
807 return 0; 787 return 0;
808} 788}
809 789
810static void cp210x_disconnect(struct usb_serial *serial)
811{
812 int i;
813
814 dbg("%s", __func__);
815
816 /* Stop reads and writes on all ports */
817 for (i = 0; i < serial->num_ports; ++i)
818 cp210x_cleanup(serial->port[i]);
819}
820
821static int __init cp210x_init(void) 790static int __init cp210x_init(void)
822{ 791{
823 int retval; 792 int retval;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index e23c77925e7a..f5d06746cc3b 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -64,6 +64,7 @@
64#include <linux/usb.h> 64#include <linux/usb.h>
65#include <linux/usb/serial.h> 65#include <linux/usb/serial.h>
66#include <linux/serial.h> 66#include <linux/serial.h>
67#include <linux/kfifo.h>
67#include <linux/delay.h> 68#include <linux/delay.h>
68#include <linux/uaccess.h> 69#include <linux/uaccess.h>
69#include <asm/unaligned.h> 70#include <asm/unaligned.h>
@@ -79,13 +80,12 @@ static int unstable_bauds;
79/* 80/*
80 * Version Information 81 * Version Information
81 */ 82 */
82#define DRIVER_VERSION "v1.09" 83#define DRIVER_VERSION "v1.10"
83#define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>" 84#define DRIVER_AUTHOR "Lonnie Mendez <dignome@gmail.com>, Neil Whelchel <koyama@firstlight.net>"
84#define DRIVER_DESC "Cypress USB to Serial Driver" 85#define DRIVER_DESC "Cypress USB to Serial Driver"
85 86
86/* write buffer size defines */ 87/* write buffer size defines */
87#define CYPRESS_BUF_SIZE 1024 88#define CYPRESS_BUF_SIZE 1024
88#define CYPRESS_CLOSING_WAIT (30*HZ)
89 89
90static const struct usb_device_id id_table_earthmate[] = { 90static const struct usb_device_id id_table_earthmate[] = {
91 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, 91 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
@@ -135,7 +135,7 @@ struct cypress_private {
135 int bytes_out; /* used for statistics */ 135 int bytes_out; /* used for statistics */
136 int cmd_count; /* used for statistics */ 136 int cmd_count; /* used for statistics */
137 int cmd_ctrl; /* always set this to 1 before issuing a command */ 137 int cmd_ctrl; /* always set this to 1 before issuing a command */
138 struct cypress_buf *buf; /* write buffer */ 138 struct kfifo write_fifo; /* write fifo */
139 int write_urb_in_use; /* write urb in use indicator */ 139 int write_urb_in_use; /* write urb in use indicator */
140 int write_urb_interval; /* interval to use for write urb */ 140 int write_urb_interval; /* interval to use for write urb */
141 int read_urb_interval; /* interval to use for read urb */ 141 int read_urb_interval; /* interval to use for read urb */
@@ -157,14 +157,6 @@ struct cypress_private {
157 struct ktermios tmp_termios; /* stores the old termios settings */ 157 struct ktermios tmp_termios; /* stores the old termios settings */
158}; 158};
159 159
160/* write buffer structure */
161struct cypress_buf {
162 unsigned int buf_size;
163 char *buf_buf;
164 char *buf_get;
165 char *buf_put;
166};
167
168/* function prototypes for the Cypress USB to serial device */ 160/* function prototypes for the Cypress USB to serial device */
169static int cypress_earthmate_startup(struct usb_serial *serial); 161static int cypress_earthmate_startup(struct usb_serial *serial);
170static int cypress_hidcom_startup(struct usb_serial *serial); 162static int cypress_hidcom_startup(struct usb_serial *serial);
@@ -190,17 +182,6 @@ static void cypress_unthrottle(struct tty_struct *tty);
190static void cypress_set_dead(struct usb_serial_port *port); 182static void cypress_set_dead(struct usb_serial_port *port);
191static void cypress_read_int_callback(struct urb *urb); 183static void cypress_read_int_callback(struct urb *urb);
192static void cypress_write_int_callback(struct urb *urb); 184static void cypress_write_int_callback(struct urb *urb);
193/* write buffer functions */
194static struct cypress_buf *cypress_buf_alloc(unsigned int size);
195static void cypress_buf_free(struct cypress_buf *cb);
196static void cypress_buf_clear(struct cypress_buf *cb);
197static unsigned int cypress_buf_data_avail(struct cypress_buf *cb);
198static unsigned int cypress_buf_space_avail(struct cypress_buf *cb);
199static unsigned int cypress_buf_put(struct cypress_buf *cb,
200 const char *buf, unsigned int count);
201static unsigned int cypress_buf_get(struct cypress_buf *cb,
202 char *buf, unsigned int count);
203
204 185
205static struct usb_serial_driver cypress_earthmate_device = { 186static struct usb_serial_driver cypress_earthmate_device = {
206 .driver = { 187 .driver = {
@@ -503,8 +484,7 @@ static int generic_startup(struct usb_serial *serial)
503 484
504 priv->comm_is_ok = !0; 485 priv->comm_is_ok = !0;
505 spin_lock_init(&priv->lock); 486 spin_lock_init(&priv->lock);
506 priv->buf = cypress_buf_alloc(CYPRESS_BUF_SIZE); 487 if (kfifo_alloc(&priv->write_fifo, CYPRESS_BUF_SIZE, GFP_KERNEL)) {
507 if (priv->buf == NULL) {
508 kfree(priv); 488 kfree(priv);
509 return -ENOMEM; 489 return -ENOMEM;
510 } 490 }
@@ -627,7 +607,7 @@ static void cypress_release(struct usb_serial *serial)
627 priv = usb_get_serial_port_data(serial->port[0]); 607 priv = usb_get_serial_port_data(serial->port[0]);
628 608
629 if (priv) { 609 if (priv) {
630 cypress_buf_free(priv->buf); 610 kfifo_free(&priv->write_fifo);
631 kfree(priv); 611 kfree(priv);
632 } 612 }
633} 613}
@@ -704,6 +684,7 @@ static void cypress_dtr_rts(struct usb_serial_port *port, int on)
704static void cypress_close(struct usb_serial_port *port) 684static void cypress_close(struct usb_serial_port *port)
705{ 685{
706 struct cypress_private *priv = usb_get_serial_port_data(port); 686 struct cypress_private *priv = usb_get_serial_port_data(port);
687 unsigned long flags;
707 688
708 dbg("%s - port %d", __func__, port->number); 689 dbg("%s - port %d", __func__, port->number);
709 690
@@ -713,12 +694,14 @@ static void cypress_close(struct usb_serial_port *port)
713 mutex_unlock(&port->serial->disc_mutex); 694 mutex_unlock(&port->serial->disc_mutex);
714 return; 695 return;
715 } 696 }
716 cypress_buf_clear(priv->buf); 697 spin_lock_irqsave(&priv->lock, flags);
698 kfifo_reset_out(&priv->write_fifo);
699 spin_unlock_irqrestore(&priv->lock, flags);
700
717 dbg("%s - stopping urbs", __func__); 701 dbg("%s - stopping urbs", __func__);
718 usb_kill_urb(port->interrupt_in_urb); 702 usb_kill_urb(port->interrupt_in_urb);
719 usb_kill_urb(port->interrupt_out_urb); 703 usb_kill_urb(port->interrupt_out_urb);
720 704
721
722 if (stats) 705 if (stats)
723 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 706 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
724 priv->bytes_in, priv->bytes_out, priv->cmd_count); 707 priv->bytes_in, priv->bytes_out, priv->cmd_count);
@@ -730,7 +713,6 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
730 const unsigned char *buf, int count) 713 const unsigned char *buf, int count)
731{ 714{
732 struct cypress_private *priv = usb_get_serial_port_data(port); 715 struct cypress_private *priv = usb_get_serial_port_data(port);
733 unsigned long flags;
734 716
735 dbg("%s - port %d, %d bytes", __func__, port->number, count); 717 dbg("%s - port %d, %d bytes", __func__, port->number, count);
736 718
@@ -745,9 +727,7 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
745 if (!count) 727 if (!count)
746 return count; 728 return count;
747 729
748 spin_lock_irqsave(&priv->lock, flags); 730 count = kfifo_in_locked(&priv->write_fifo, buf, count, &priv->lock);
749 count = cypress_buf_put(priv->buf, buf, count);
750 spin_unlock_irqrestore(&priv->lock, flags);
751 731
752finish: 732finish:
753 cypress_send(port); 733 cypress_send(port);
@@ -807,9 +787,10 @@ static void cypress_send(struct usb_serial_port *port)
807 } else 787 } else
808 spin_unlock_irqrestore(&priv->lock, flags); 788 spin_unlock_irqrestore(&priv->lock, flags);
809 789
810 count = cypress_buf_get(priv->buf, &port->interrupt_out_buffer[offset], 790 count = kfifo_out_locked(&priv->write_fifo,
811 port->interrupt_out_size-offset); 791 &port->interrupt_out_buffer[offset],
812 792 port->interrupt_out_size - offset,
793 &priv->lock);
813 if (count == 0) 794 if (count == 0)
814 return; 795 return;
815 796
@@ -875,7 +856,7 @@ static int cypress_write_room(struct tty_struct *tty)
875 dbg("%s - port %d", __func__, port->number); 856 dbg("%s - port %d", __func__, port->number);
876 857
877 spin_lock_irqsave(&priv->lock, flags); 858 spin_lock_irqsave(&priv->lock, flags);
878 room = cypress_buf_space_avail(priv->buf); 859 room = kfifo_avail(&priv->write_fifo);
879 spin_unlock_irqrestore(&priv->lock, flags); 860 spin_unlock_irqrestore(&priv->lock, flags);
880 861
881 dbg("%s - returns %d", __func__, room); 862 dbg("%s - returns %d", __func__, room);
@@ -1143,7 +1124,7 @@ static int cypress_chars_in_buffer(struct tty_struct *tty)
1143 dbg("%s - port %d", __func__, port->number); 1124 dbg("%s - port %d", __func__, port->number);
1144 1125
1145 spin_lock_irqsave(&priv->lock, flags); 1126 spin_lock_irqsave(&priv->lock, flags);
1146 chars = cypress_buf_data_avail(priv->buf); 1127 chars = kfifo_len(&priv->write_fifo);
1147 spin_unlock_irqrestore(&priv->lock, flags); 1128 spin_unlock_irqrestore(&priv->lock, flags);
1148 1129
1149 dbg("%s - returns %d", __func__, chars); 1130 dbg("%s - returns %d", __func__, chars);
@@ -1309,7 +1290,7 @@ static void cypress_read_int_callback(struct urb *urb)
1309 /* process read if there is data other than line status */ 1290 /* process read if there is data other than line status */
1310 if (tty && bytes > i) { 1291 if (tty && bytes > i) {
1311 tty_insert_flip_string_fixed_flag(tty, data + i, 1292 tty_insert_flip_string_fixed_flag(tty, data + i,
1312 bytes - i, tty_flag); 1293 tty_flag, bytes - i);
1313 tty_flip_buffer_push(tty); 1294 tty_flip_buffer_push(tty);
1314 } 1295 }
1315 1296
@@ -1397,193 +1378,6 @@ static void cypress_write_int_callback(struct urb *urb)
1397 1378
1398 1379
1399/***************************************************************************** 1380/*****************************************************************************
1400 * Write buffer functions - buffering code from pl2303 used
1401 *****************************************************************************/
1402
1403/*
1404 * cypress_buf_alloc
1405 *
1406 * Allocate a circular buffer and all associated memory.
1407 */
1408
1409static struct cypress_buf *cypress_buf_alloc(unsigned int size)
1410{
1411
1412 struct cypress_buf *cb;
1413
1414
1415 if (size == 0)
1416 return NULL;
1417
1418 cb = kmalloc(sizeof(struct cypress_buf), GFP_KERNEL);
1419 if (cb == NULL)
1420 return NULL;
1421
1422 cb->buf_buf = kmalloc(size, GFP_KERNEL);
1423 if (cb->buf_buf == NULL) {
1424 kfree(cb);
1425 return NULL;
1426 }
1427
1428 cb->buf_size = size;
1429 cb->buf_get = cb->buf_put = cb->buf_buf;
1430
1431 return cb;
1432
1433}
1434
1435
1436/*
1437 * cypress_buf_free
1438 *
1439 * Free the buffer and all associated memory.
1440 */
1441
1442static void cypress_buf_free(struct cypress_buf *cb)
1443{
1444 if (cb) {
1445 kfree(cb->buf_buf);
1446 kfree(cb);
1447 }
1448}
1449
1450
1451/*
1452 * cypress_buf_clear
1453 *
1454 * Clear out all data in the circular buffer.
1455 */
1456
1457static void cypress_buf_clear(struct cypress_buf *cb)
1458{
1459 if (cb != NULL)
1460 cb->buf_get = cb->buf_put;
1461 /* equivalent to a get of all data available */
1462}
1463
1464
1465/*
1466 * cypress_buf_data_avail
1467 *
1468 * Return the number of bytes of data available in the circular
1469 * buffer.
1470 */
1471
1472static unsigned int cypress_buf_data_avail(struct cypress_buf *cb)
1473{
1474 if (cb != NULL)
1475 return (cb->buf_size + cb->buf_put - cb->buf_get)
1476 % cb->buf_size;
1477 else
1478 return 0;
1479}
1480
1481
1482/*
1483 * cypress_buf_space_avail
1484 *
1485 * Return the number of bytes of space available in the circular
1486 * buffer.
1487 */
1488
1489static unsigned int cypress_buf_space_avail(struct cypress_buf *cb)
1490{
1491 if (cb != NULL)
1492 return (cb->buf_size + cb->buf_get - cb->buf_put - 1)
1493 % cb->buf_size;
1494 else
1495 return 0;
1496}
1497
1498
1499/*
1500 * cypress_buf_put
1501 *
1502 * Copy data data from a user buffer and put it into the circular buffer.
1503 * Restrict to the amount of space available.
1504 *
1505 * Return the number of bytes copied.
1506 */
1507
1508static unsigned int cypress_buf_put(struct cypress_buf *cb, const char *buf,
1509 unsigned int count)
1510{
1511
1512 unsigned int len;
1513
1514
1515 if (cb == NULL)
1516 return 0;
1517
1518 len = cypress_buf_space_avail(cb);
1519 if (count > len)
1520 count = len;
1521
1522 if (count == 0)
1523 return 0;
1524
1525 len = cb->buf_buf + cb->buf_size - cb->buf_put;
1526 if (count > len) {
1527 memcpy(cb->buf_put, buf, len);
1528 memcpy(cb->buf_buf, buf+len, count - len);
1529 cb->buf_put = cb->buf_buf + count - len;
1530 } else {
1531 memcpy(cb->buf_put, buf, count);
1532 if (count < len)
1533 cb->buf_put += count;
1534 else /* count == len */
1535 cb->buf_put = cb->buf_buf;
1536 }
1537
1538 return count;
1539
1540}
1541
1542
1543/*
1544 * cypress_buf_get
1545 *
1546 * Get data from the circular buffer and copy to the given buffer.
1547 * Restrict to the amount of data available.
1548 *
1549 * Return the number of bytes copied.
1550 */
1551
1552static unsigned int cypress_buf_get(struct cypress_buf *cb, char *buf,
1553 unsigned int count)
1554{
1555
1556 unsigned int len;
1557
1558
1559 if (cb == NULL)
1560 return 0;
1561
1562 len = cypress_buf_data_avail(cb);
1563 if (count > len)
1564 count = len;
1565
1566 if (count == 0)
1567 return 0;
1568
1569 len = cb->buf_buf + cb->buf_size - cb->buf_get;
1570 if (count > len) {
1571 memcpy(buf, cb->buf_get, len);
1572 memcpy(buf+len, cb->buf_buf, count - len);
1573 cb->buf_get = cb->buf_buf + count - len;
1574 } else {
1575 memcpy(buf, cb->buf_get, count);
1576 if (count < len)
1577 cb->buf_get += count;
1578 else /* count == len */
1579 cb->buf_get = cb->buf_buf;
1580 }
1581
1582 return count;
1583
1584}
1585
1586/*****************************************************************************
1587 * Module functions 1381 * Module functions
1588 *****************************************************************************/ 1382 *****************************************************************************/
1589 1383
diff --git a/drivers/usb/serial/cypress_m8.h b/drivers/usb/serial/cypress_m8.h
index 1fd360e04065..67cf60826884 100644
--- a/drivers/usb/serial/cypress_m8.h
+++ b/drivers/usb/serial/cypress_m8.h
@@ -1,27 +1,32 @@
1#ifndef CYPRESS_M8_H 1#ifndef CYPRESS_M8_H
2#define CYPRESS_M8_H 2#define CYPRESS_M8_H
3 3
4/* definitions and function prototypes used for the cypress USB to Serial controller */ 4/*
5 * definitions and function prototypes used for the cypress USB to Serial
6 * controller
7 */
5 8
6/* For sending our feature buffer - controlling serial communication states */ 9/*
7/* Linux HID has no support for serial devices so we do this through the driver */ 10 * For sending our feature buffer - controlling serial communication states.
8#define HID_REQ_GET_REPORT 0x01 11 * Linux HID has no support for serial devices so we do this through the driver
9#define HID_REQ_SET_REPORT 0x09 12 */
13#define HID_REQ_GET_REPORT 0x01
14#define HID_REQ_SET_REPORT 0x09
10 15
11/* List other cypress USB to Serial devices here, and add them to the id_table */ 16/* List other cypress USB to Serial devices here, and add them to the id_table */
12 17
13/* DeLorme Earthmate USB - a GPS device */ 18/* DeLorme Earthmate USB - a GPS device */
14#define VENDOR_ID_DELORME 0x1163 19#define VENDOR_ID_DELORME 0x1163
15#define PRODUCT_ID_EARTHMATEUSB 0x0100 20#define PRODUCT_ID_EARTHMATEUSB 0x0100
16#define PRODUCT_ID_EARTHMATEUSB_LT20 0x0200 21#define PRODUCT_ID_EARTHMATEUSB_LT20 0x0200
17 22
18/* Cypress HID->COM RS232 Adapter */ 23/* Cypress HID->COM RS232 Adapter */
19#define VENDOR_ID_CYPRESS 0x04b4 24#define VENDOR_ID_CYPRESS 0x04b4
20#define PRODUCT_ID_CYPHIDCOM 0x5500 25#define PRODUCT_ID_CYPHIDCOM 0x5500
21 26
22/* Powercom UPS, chip CY7C63723 */ 27/* Powercom UPS, chip CY7C63723 */
23#define VENDOR_ID_POWERCOM 0x0d9f 28#define VENDOR_ID_POWERCOM 0x0d9f
24#define PRODUCT_ID_UPS 0x0002 29#define PRODUCT_ID_UPS 0x0002
25 30
26/* Nokia CA-42 USB to serial cable */ 31/* Nokia CA-42 USB to serial cable */
27#define VENDOR_ID_DAZZLE 0x07d0 32#define VENDOR_ID_DAZZLE 0x07d0
@@ -29,17 +34,17 @@
29/* End of device listing */ 34/* End of device listing */
30 35
31/* Used for setting / requesting serial line settings */ 36/* Used for setting / requesting serial line settings */
32#define CYPRESS_SET_CONFIG 0x01 37#define CYPRESS_SET_CONFIG 0x01
33#define CYPRESS_GET_CONFIG 0x02 38#define CYPRESS_GET_CONFIG 0x02
34 39
35/* Used for throttle control */ 40/* Used for throttle control */
36#define THROTTLED 0x1 41#define THROTTLED 0x1
37#define ACTUALLY_THROTTLED 0x2 42#define ACTUALLY_THROTTLED 0x2
38 43
39/* chiptypes - used in case firmware differs from the generic form ... offering 44/*
40 * different baud speeds/etc. 45 * chiptypes - used in case firmware differs from the generic form ... offering
46 * different baud speeds/etc.
41 */ 47 */
42
43#define CT_EARTHMATE 0x01 48#define CT_EARTHMATE 0x01
44#define CT_CYPHIDCOM 0x02 49#define CT_CYPHIDCOM 0x02
45#define CT_CA42V2 0x03 50#define CT_CA42V2 0x03
@@ -50,15 +55,15 @@
50/* these are sent / read at byte 0 of the input/output hid reports */ 55/* these are sent / read at byte 0 of the input/output hid reports */
51/* You can find these values defined in the CY4601 USB to Serial design notes */ 56/* You can find these values defined in the CY4601 USB to Serial design notes */
52 57
53#define CONTROL_DTR 0x20 /* data terminal ready - flow control - host to device */ 58#define CONTROL_DTR 0x20 /* data terminal ready - flow control - host to device */
54#define UART_DSR 0x20 /* data set ready - flow control - device to host */ 59#define UART_DSR 0x20 /* data set ready - flow control - device to host */
55#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */ 60#define CONTROL_RTS 0x10 /* request to send - flow control - host to device */
56#define UART_CTS 0x10 /* clear to send - flow control - device to host */ 61#define UART_CTS 0x10 /* clear to send - flow control - device to host */
57#define UART_RI 0x10 /* ring indicator - modem - device to host */ 62#define UART_RI 0x10 /* ring indicator - modem - device to host */
58#define UART_CD 0x40 /* carrier detect - modem - device to host */ 63#define UART_CD 0x40 /* carrier detect - modem - device to host */
59#define CYP_ERROR 0x08 /* received from input report - device to host */ 64#define CYP_ERROR 0x08 /* received from input report - device to host */
60/* Note - the below has nothing to do with the "feature report" reset */ 65/* Note - the below has nothing to do with the "feature report" reset */
61#define CONTROL_RESET 0x08 /* sent with output report - host to device */ 66#define CONTROL_RESET 0x08 /* sent with output report - host to device */
62 67
63/* End of RS-232 protocol definitions */ 68/* End of RS-232 protocol definitions */
64 69
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 68b0aa5e516c..3edda3ed822a 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -1703,8 +1703,8 @@ static int digi_read_inb_callback(struct urb *urb)
1703 /* data length is len-1 (one byte of len is port_status) */ 1703 /* data length is len-1 (one byte of len is port_status) */
1704 --len; 1704 --len;
1705 if (len > 0) { 1705 if (len > 0) {
1706 tty_insert_flip_string_fixed_flag(tty, data, len, 1706 tty_insert_flip_string_fixed_flag(tty, data, flag,
1707 flag); 1707 len);
1708 tty_flip_buffer_push(tty); 1708 tty_flip_buffer_push(tty);
1709 } 1709 }
1710 } 1710 }
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 5f740a1eacab..504b5585ea45 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -13,44 +13,6 @@
13 * 13 *
14 * See Documentation/usb/usb-serial.txt for more information on using this 14 * See Documentation/usb/usb-serial.txt for more information on using this
15 * driver 15 * driver
16 *
17 * (07/16/2001) gb
18 * remove unused code in empeg_close() (thanks to Oliver Neukum for
19 * pointing this out) and rewrote empeg_set_termios().
20 *
21 * (05/30/2001) gkh
22 * switched from using spinlock to a semaphore, which fixes lots of
23 * problems.
24 *
25 * (04/08/2001) gb
26 * Identify version on module load.
27 *
28 * (01/22/2001) gb
29 * Added write_room() and chars_in_buffer() support.
30 *
31 * (12/21/2000) gb
32 * Moved termio stuff inside the port->active check.
33 * Moved MOD_DEC_USE_COUNT to end of empeg_close().
34 *
35 * (12/03/2000) gb
36 * Added tty->ldisc.set_termios(port, tty, NULL) to empeg_open().
37 * This notifies the tty driver that the termios have changed.
38 *
39 * (11/13/2000) gb
40 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
41 * empeg_open() (It only needs to be set once - Doh!)
42 *
43 * (11/11/2000) gb
44 * Updated to work with id_table structure.
45 *
46 * (11/04/2000) gb
47 * Forked this from visor.c, and hacked it up to work with an
48 * Empeg ltd. empeg-car player. Constructive criticism welcomed.
49 * I would like to say, 'Thank You' to Greg Kroah-Hartman for the
50 * use of his code, and for his guidance, advice and patience. :)
51 * A 'Thank You' is in order for John Ripley of Empeg ltd for his
52 * advice, and patience too.
53 *
54 */ 16 */
55 17
56#include <linux/kernel.h> 18#include <linux/kernel.h>
@@ -71,7 +33,7 @@ static int debug;
71/* 33/*
72 * Version Information 34 * Version Information
73 */ 35 */
74#define DRIVER_VERSION "v1.2" 36#define DRIVER_VERSION "v1.3"
75#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>" 37#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>"
76#define DRIVER_DESC "USB Empeg Mark I/II Driver" 38#define DRIVER_DESC "USB Empeg Mark I/II Driver"
77 39
@@ -79,19 +41,8 @@ static int debug;
79#define EMPEG_PRODUCT_ID 0x0001 41#define EMPEG_PRODUCT_ID 0x0001
80 42
81/* function prototypes for an empeg-car player */ 43/* function prototypes for an empeg-car player */
82static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port);
83static void empeg_close(struct usb_serial_port *port);
84static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
85 const unsigned char *buf,
86 int count);
87static int empeg_write_room(struct tty_struct *tty);
88static int empeg_chars_in_buffer(struct tty_struct *tty);
89static void empeg_throttle(struct tty_struct *tty);
90static void empeg_unthrottle(struct tty_struct *tty);
91static int empeg_startup(struct usb_serial *serial); 44static int empeg_startup(struct usb_serial *serial);
92static void empeg_init_termios(struct tty_struct *tty); 45static void empeg_init_termios(struct tty_struct *tty);
93static void empeg_write_bulk_callback(struct urb *urb);
94static void empeg_read_bulk_callback(struct urb *urb);
95 46
96static const struct usb_device_id id_table[] = { 47static const struct usb_device_id id_table[] = {
97 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, 48 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
@@ -105,7 +56,7 @@ static struct usb_driver empeg_driver = {
105 .probe = usb_serial_probe, 56 .probe = usb_serial_probe,
106 .disconnect = usb_serial_disconnect, 57 .disconnect = usb_serial_disconnect,
107 .id_table = id_table, 58 .id_table = id_table,
108 .no_dynamic_id = 1, 59 .no_dynamic_id = 1,
109}; 60};
110 61
111static struct usb_serial_driver empeg_device = { 62static struct usb_serial_driver empeg_device = {
@@ -114,291 +65,16 @@ static struct usb_serial_driver empeg_device = {
114 .name = "empeg", 65 .name = "empeg",
115 }, 66 },
116 .id_table = id_table, 67 .id_table = id_table,
117 .usb_driver = &empeg_driver, 68 .usb_driver = &empeg_driver,
118 .num_ports = 1, 69 .num_ports = 1,
119 .open = empeg_open, 70 .bulk_out_size = 256,
120 .close = empeg_close, 71 .throttle = usb_serial_generic_throttle,
121 .throttle = empeg_throttle, 72 .unthrottle = usb_serial_generic_unthrottle,
122 .unthrottle = empeg_unthrottle,
123 .attach = empeg_startup, 73 .attach = empeg_startup,
124 .init_termios = empeg_init_termios, 74 .init_termios = empeg_init_termios,
125 .write = empeg_write,
126 .write_room = empeg_write_room,
127 .chars_in_buffer = empeg_chars_in_buffer,
128 .write_bulk_callback = empeg_write_bulk_callback,
129 .read_bulk_callback = empeg_read_bulk_callback,
130}; 75};
131 76
132#define NUM_URBS 16 77static int empeg_startup(struct usb_serial *serial)
133#define URB_TRANSFER_BUFFER_SIZE 4096
134
135static struct urb *write_urb_pool[NUM_URBS];
136static spinlock_t write_urb_pool_lock;
137static int bytes_in;
138static int bytes_out;
139
140/******************************************************************************
141 * Empeg specific driver functions
142 ******************************************************************************/
143static int empeg_open(struct tty_struct *tty,struct usb_serial_port *port)
144{
145 struct usb_serial *serial = port->serial;
146 int result = 0;
147
148 dbg("%s - port %d", __func__, port->number);
149
150 bytes_in = 0;
151 bytes_out = 0;
152
153 /* Start reading from the device */
154 usb_fill_bulk_urb(
155 port->read_urb,
156 serial->dev,
157 usb_rcvbulkpipe(serial->dev,
158 port->bulk_in_endpointAddress),
159 port->read_urb->transfer_buffer,
160 port->read_urb->transfer_buffer_length,
161 empeg_read_bulk_callback,
162 port);
163
164 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
165
166 if (result)
167 dev_err(&port->dev,
168 "%s - failed submitting read urb, error %d\n",
169 __func__, result);
170
171 return result;
172}
173
174
175static void empeg_close(struct usb_serial_port *port)
176{
177 dbg("%s - port %d", __func__, port->number);
178
179 /* shutdown our bulk read */
180 usb_kill_urb(port->read_urb);
181 /* Uncomment the following line if you want to see some statistics in your syslog */
182 /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */
183}
184
185
186static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
187 const unsigned char *buf, int count)
188{
189 struct usb_serial *serial = port->serial;
190 struct urb *urb;
191 const unsigned char *current_position = buf;
192 unsigned long flags;
193 int status;
194 int i;
195 int bytes_sent = 0;
196 int transfer_size;
197
198 dbg("%s - port %d", __func__, port->number);
199
200 while (count > 0) {
201 /* try to find a free urb in our list of them */
202 urb = NULL;
203
204 spin_lock_irqsave(&write_urb_pool_lock, flags);
205
206 for (i = 0; i < NUM_URBS; ++i) {
207 if (write_urb_pool[i]->status != -EINPROGRESS) {
208 urb = write_urb_pool[i];
209 break;
210 }
211 }
212
213 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
214
215 if (urb == NULL) {
216 dbg("%s - no more free urbs", __func__);
217 goto exit;
218 }
219
220 if (urb->transfer_buffer == NULL) {
221 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
222 if (urb->transfer_buffer == NULL) {
223 dev_err(&port->dev,
224 "%s no more kernel memory...\n",
225 __func__);
226 goto exit;
227 }
228 }
229
230 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE);
231
232 memcpy(urb->transfer_buffer, current_position, transfer_size);
233
234 usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer);
235
236 /* build up our urb */
237 usb_fill_bulk_urb(
238 urb,
239 serial->dev,
240 usb_sndbulkpipe(serial->dev,
241 port->bulk_out_endpointAddress),
242 urb->transfer_buffer,
243 transfer_size,
244 empeg_write_bulk_callback,
245 port);
246
247 /* send it down the pipe */
248 status = usb_submit_urb(urb, GFP_ATOMIC);
249 if (status) {
250 dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status);
251 bytes_sent = status;
252 break;
253 }
254
255 current_position += transfer_size;
256 bytes_sent += transfer_size;
257 count -= transfer_size;
258 bytes_out += transfer_size;
259
260 }
261exit:
262 return bytes_sent;
263}
264
265
266static int empeg_write_room(struct tty_struct *tty)
267{
268 struct usb_serial_port *port = tty->driver_data;
269 unsigned long flags;
270 int i;
271 int room = 0;
272
273 dbg("%s - port %d", __func__, port->number);
274
275 spin_lock_irqsave(&write_urb_pool_lock, flags);
276 /* tally up the number of bytes available */
277 for (i = 0; i < NUM_URBS; ++i) {
278 if (write_urb_pool[i]->status != -EINPROGRESS)
279 room += URB_TRANSFER_BUFFER_SIZE;
280 }
281 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
282 dbg("%s - returns %d", __func__, room);
283 return room;
284
285}
286
287
288static int empeg_chars_in_buffer(struct tty_struct *tty)
289{
290 struct usb_serial_port *port = tty->driver_data;
291 unsigned long flags;
292 int i;
293 int chars = 0;
294
295 dbg("%s - port %d", __func__, port->number);
296
297 spin_lock_irqsave(&write_urb_pool_lock, flags);
298
299 /* tally up the number of bytes waiting */
300 for (i = 0; i < NUM_URBS; ++i) {
301 if (write_urb_pool[i]->status == -EINPROGRESS)
302 chars += URB_TRANSFER_BUFFER_SIZE;
303 }
304
305 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
306 dbg("%s - returns %d", __func__, chars);
307 return chars;
308}
309
310
311static void empeg_write_bulk_callback(struct urb *urb)
312{
313 struct usb_serial_port *port = urb->context;
314 int status = urb->status;
315
316 dbg("%s - port %d", __func__, port->number);
317
318 if (status) {
319 dbg("%s - nonzero write bulk status received: %d",
320 __func__, status);
321 return;
322 }
323
324 usb_serial_port_softint(port);
325}
326
327
328static void empeg_read_bulk_callback(struct urb *urb)
329{
330 struct usb_serial_port *port = urb->context;
331 struct tty_struct *tty;
332 unsigned char *data = urb->transfer_buffer;
333 int result;
334 int status = urb->status;
335
336 dbg("%s - port %d", __func__, port->number);
337
338 if (status) {
339 dbg("%s - nonzero read bulk status received: %d",
340 __func__, status);
341 return;
342 }
343
344 usb_serial_debug_data(debug, &port->dev, __func__,
345 urb->actual_length, data);
346 tty = tty_port_tty_get(&port->port);
347
348 if (urb->actual_length) {
349 tty_insert_flip_string(tty, data, urb->actual_length);
350 tty_flip_buffer_push(tty);
351 bytes_in += urb->actual_length;
352 }
353 tty_kref_put(tty);
354
355 /* Continue trying to always read */
356 usb_fill_bulk_urb(
357 port->read_urb,
358 port->serial->dev,
359 usb_rcvbulkpipe(port->serial->dev,
360 port->bulk_in_endpointAddress),
361 port->read_urb->transfer_buffer,
362 port->read_urb->transfer_buffer_length,
363 empeg_read_bulk_callback,
364 port);
365
366 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
367
368 if (result)
369 dev_err(&urb->dev->dev,
370 "%s - failed resubmitting read urb, error %d\n",
371 __func__, result);
372
373 return;
374
375}
376
377
378static void empeg_throttle(struct tty_struct *tty)
379{
380 struct usb_serial_port *port = tty->driver_data;
381 dbg("%s - port %d", __func__, port->number);
382 usb_kill_urb(port->read_urb);
383}
384
385
386static void empeg_unthrottle(struct tty_struct *tty)
387{
388 struct usb_serial_port *port = tty->driver_data;
389 int result;
390 dbg("%s - port %d", __func__, port->number);
391
392 port->read_urb->dev = port->serial->dev;
393 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
394 if (result)
395 dev_err(&port->dev,
396 "%s - failed submitting read urb, error %d\n",
397 __func__, result);
398}
399
400
401static int empeg_startup(struct usb_serial *serial)
402{ 78{
403 int r; 79 int r;
404 80
@@ -414,10 +90,8 @@ static int empeg_startup(struct usb_serial *serial)
414 90
415 /* continue on with initialization */ 91 /* continue on with initialization */
416 return r; 92 return r;
417
418} 93}
419 94
420
421static void empeg_init_termios(struct tty_struct *tty) 95static void empeg_init_termios(struct tty_struct *tty)
422{ 96{
423 struct ktermios *termios = tty->termios; 97 struct ktermios *termios = tty->termios;
@@ -462,77 +136,28 @@ static void empeg_init_termios(struct tty_struct *tty)
462 tty_encode_baud_rate(tty, 115200, 115200); 136 tty_encode_baud_rate(tty, 115200, 115200);
463} 137}
464 138
465
466static int __init empeg_init(void) 139static int __init empeg_init(void)
467{ 140{
468 struct urb *urb; 141 int retval;
469 int i, retval;
470
471 /* create our write urb pool and transfer buffers */
472 spin_lock_init(&write_urb_pool_lock);
473 for (i = 0; i < NUM_URBS; ++i) {
474 urb = usb_alloc_urb(0, GFP_KERNEL);
475 write_urb_pool[i] = urb;
476 if (urb == NULL) {
477 printk(KERN_ERR "empeg: No more urbs???\n");
478 continue;
479 }
480
481 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE,
482 GFP_KERNEL);
483 if (!urb->transfer_buffer) {
484 printk(KERN_ERR "empeg: %s - out of memory for urb "
485 "buffers.", __func__);
486 continue;
487 }
488 }
489 142
490 retval = usb_serial_register(&empeg_device); 143 retval = usb_serial_register(&empeg_device);
491 if (retval) 144 if (retval)
492 goto failed_usb_serial_register; 145 return retval;
493 retval = usb_register(&empeg_driver); 146 retval = usb_register(&empeg_driver);
494 if (retval) 147 if (retval) {
495 goto failed_usb_register; 148 usb_serial_deregister(&empeg_device);
496 149 return retval;
150 }
497 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 151 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
498 DRIVER_DESC "\n"); 152 DRIVER_DESC "\n");
499 153
500 return 0; 154 return 0;
501failed_usb_register:
502 usb_serial_deregister(&empeg_device);
503failed_usb_serial_register:
504 for (i = 0; i < NUM_URBS; ++i) {
505 if (write_urb_pool[i]) {
506 kfree(write_urb_pool[i]->transfer_buffer);
507 usb_free_urb(write_urb_pool[i]);
508 }
509 }
510 return retval;
511} 155}
512 156
513
514static void __exit empeg_exit(void) 157static void __exit empeg_exit(void)
515{ 158{
516 int i;
517 unsigned long flags;
518
519 usb_deregister(&empeg_driver); 159 usb_deregister(&empeg_driver);
520 usb_serial_deregister(&empeg_device); 160 usb_serial_deregister(&empeg_device);
521
522 spin_lock_irqsave(&write_urb_pool_lock, flags);
523
524 for (i = 0; i < NUM_URBS; ++i) {
525 if (write_urb_pool[i]) {
526 /* FIXME - uncomment the following usb_kill_urb call
527 * when the host controllers get fixed to set urb->dev
528 * = NULL after the urb is finished. Otherwise this
529 * call oopses. */
530 /* usb_kill_urb(write_urb_pool[i]); */
531 kfree(write_urb_pool[i]->transfer_buffer);
532 usb_free_urb(write_urb_pool[i]);
533 }
534 }
535 spin_unlock_irqrestore(&write_urb_pool_lock, flags);
536} 161}
537 162
538 163
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 1d7c4fac02e8..050211afc07e 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * USB FTDI SIO driver 2 * USB FTDI SIO driver
3 * 3 *
4 * Copyright (C) 2009 - 2010
5 * Johan Hovold (jhovold@gmail.com)
4 * Copyright (C) 1999 - 2001 6 * Copyright (C) 1999 - 2001
5 * Greg Kroah-Hartman (greg@kroah.com) 7 * Greg Kroah-Hartman (greg@kroah.com)
6 * Bill Ryder (bryder@sgi.com) 8 * Bill Ryder (bryder@sgi.com)
@@ -49,8 +51,8 @@
49/* 51/*
50 * Version Information 52 * Version Information
51 */ 53 */
52#define DRIVER_VERSION "v1.5.0" 54#define DRIVER_VERSION "v1.6.0"
53#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr" 55#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr, Johan Hovold <jhovold@gmail.com>"
54#define DRIVER_DESC "USB FTDI Serial Converters Driver" 56#define DRIVER_DESC "USB FTDI Serial Converters Driver"
55 57
56static int debug; 58static int debug;
@@ -59,7 +61,7 @@ static __u16 product;
59 61
60struct ftdi_private { 62struct ftdi_private {
61 struct kref kref; 63 struct kref kref;
62 ftdi_chip_type_t chip_type; 64 enum ftdi_chip_type chip_type;
63 /* type of device, either SIO or FT8U232AM */ 65 /* type of device, either SIO or FT8U232AM */
64 int baud_base; /* baud base clock for divisor setting */ 66 int baud_base; /* baud base clock for divisor setting */
65 int custom_divisor; /* custom_divisor kludge, this is for 67 int custom_divisor; /* custom_divisor kludge, this is for
@@ -69,10 +71,6 @@ struct ftdi_private {
69 /* the last data state set - needed for doing 71 /* the last data state set - needed for doing
70 * a break 72 * a break
71 */ 73 */
72 int write_offset; /* This is the offset in the usb data block to
73 * write the serial data - it varies between
74 * devices
75 */
76 int flags; /* some ASYNC_xxxx flags are supported */ 74 int flags; /* some ASYNC_xxxx flags are supported */
77 unsigned long last_dtr_rts; /* saved modem control outputs */ 75 unsigned long last_dtr_rts; /* saved modem control outputs */
78 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */ 76 wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
@@ -87,9 +85,6 @@ struct ftdi_private {
87 be enabled */ 85 be enabled */
88 86
89 unsigned int latency; /* latency setting in use */ 87 unsigned int latency; /* latency setting in use */
90 spinlock_t tx_lock; /* spinlock for transmit state */
91 unsigned long tx_outstanding_bytes;
92 unsigned long tx_outstanding_urbs;
93 unsigned short max_packet_size; 88 unsigned short max_packet_size;
94 struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */ 89 struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */
95}; 90};
@@ -768,9 +763,6 @@ static const char *ftdi_chip_name[] = {
768}; 763};
769 764
770 765
771/* Constants for read urb and write urb */
772#define BUFSZ 512
773
774/* Used for TIOCMIWAIT */ 766/* Used for TIOCMIWAIT */
775#define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD) 767#define FTDI_STATUS_B0_MASK (FTDI_RS0_CTS | FTDI_RS0_DSR | FTDI_RS0_RI | FTDI_RS0_RLSD)
776#define FTDI_STATUS_B1_MASK (FTDI_RS_BI) 768#define FTDI_STATUS_B1_MASK (FTDI_RS_BI)
@@ -787,13 +779,9 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port);
787static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); 779static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port);
788static void ftdi_close(struct usb_serial_port *port); 780static void ftdi_close(struct usb_serial_port *port);
789static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 781static void ftdi_dtr_rts(struct usb_serial_port *port, int on);
790static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, 782static void ftdi_process_read_urb(struct urb *urb);
791 const unsigned char *buf, int count); 783static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
792static int ftdi_write_room(struct tty_struct *tty); 784 void *dest, size_t size);
793static int ftdi_chars_in_buffer(struct tty_struct *tty);
794static void ftdi_write_bulk_callback(struct urb *urb);
795static void ftdi_read_bulk_callback(struct urb *urb);
796static void ftdi_process_read(struct usb_serial_port *port);
797static void ftdi_set_termios(struct tty_struct *tty, 785static void ftdi_set_termios(struct tty_struct *tty,
798 struct usb_serial_port *port, struct ktermios *old); 786 struct usb_serial_port *port, struct ktermios *old);
799static int ftdi_tiocmget(struct tty_struct *tty, struct file *file); 787static int ftdi_tiocmget(struct tty_struct *tty, struct file *file);
@@ -802,8 +790,6 @@ static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
802static int ftdi_ioctl(struct tty_struct *tty, struct file *file, 790static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
803 unsigned int cmd, unsigned long arg); 791 unsigned int cmd, unsigned long arg);
804static void ftdi_break_ctl(struct tty_struct *tty, int break_state); 792static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
805static void ftdi_throttle(struct tty_struct *tty);
806static void ftdi_unthrottle(struct tty_struct *tty);
807 793
808static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base); 794static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base);
809static unsigned short int ftdi_232am_baud_to_divisor(int baud); 795static unsigned short int ftdi_232am_baud_to_divisor(int baud);
@@ -821,19 +807,18 @@ static struct usb_serial_driver ftdi_sio_device = {
821 .usb_driver = &ftdi_driver, 807 .usb_driver = &ftdi_driver,
822 .id_table = id_table_combined, 808 .id_table = id_table_combined,
823 .num_ports = 1, 809 .num_ports = 1,
810 .bulk_in_size = 512,
811 .bulk_out_size = 256,
824 .probe = ftdi_sio_probe, 812 .probe = ftdi_sio_probe,
825 .port_probe = ftdi_sio_port_probe, 813 .port_probe = ftdi_sio_port_probe,
826 .port_remove = ftdi_sio_port_remove, 814 .port_remove = ftdi_sio_port_remove,
827 .open = ftdi_open, 815 .open = ftdi_open,
828 .close = ftdi_close, 816 .close = ftdi_close,
829 .dtr_rts = ftdi_dtr_rts, 817 .dtr_rts = ftdi_dtr_rts,
830 .throttle = ftdi_throttle, 818 .throttle = usb_serial_generic_throttle,
831 .unthrottle = ftdi_unthrottle, 819 .unthrottle = usb_serial_generic_unthrottle,
832 .write = ftdi_write, 820 .process_read_urb = ftdi_process_read_urb,
833 .write_room = ftdi_write_room, 821 .prepare_write_buffer = ftdi_prepare_write_buffer,
834 .chars_in_buffer = ftdi_chars_in_buffer,
835 .read_bulk_callback = ftdi_read_bulk_callback,
836 .write_bulk_callback = ftdi_write_bulk_callback,
837 .tiocmget = ftdi_tiocmget, 822 .tiocmget = ftdi_tiocmget,
838 .tiocmset = ftdi_tiocmset, 823 .tiocmset = ftdi_tiocmset,
839 .ioctl = ftdi_ioctl, 824 .ioctl = ftdi_ioctl,
@@ -849,9 +834,6 @@ static struct usb_serial_driver ftdi_sio_device = {
849#define HIGH 1 834#define HIGH 1
850#define LOW 0 835#define LOW 0
851 836
852/* number of outstanding urbs to prevent userspace DoS from happening */
853#define URB_UPPER_LIMIT 42
854
855/* 837/*
856 * *************************************************************************** 838 * ***************************************************************************
857 * Utility functions 839 * Utility functions
@@ -987,7 +969,7 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set,
987 969
988static __u32 get_ftdi_divisor(struct tty_struct *tty, 970static __u32 get_ftdi_divisor(struct tty_struct *tty,
989 struct usb_serial_port *port) 971 struct usb_serial_port *port)
990{ /* get_ftdi_divisor */ 972{
991 struct ftdi_private *priv = usb_get_serial_port_data(port); 973 struct ftdi_private *priv = usb_get_serial_port_data(port);
992 __u32 div_value = 0; 974 __u32 div_value = 0;
993 int div_okay = 1; 975 int div_okay = 1;
@@ -1211,12 +1193,11 @@ static int get_serial_info(struct usb_serial_port *port,
1211 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 1193 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1212 return -EFAULT; 1194 return -EFAULT;
1213 return 0; 1195 return 0;
1214} /* get_serial_info */ 1196}
1215
1216 1197
1217static int set_serial_info(struct tty_struct *tty, 1198static int set_serial_info(struct tty_struct *tty,
1218 struct usb_serial_port *port, struct serial_struct __user *newinfo) 1199 struct usb_serial_port *port, struct serial_struct __user *newinfo)
1219{ /* set_serial_info */ 1200{
1220 struct ftdi_private *priv = usb_get_serial_port_data(port); 1201 struct ftdi_private *priv = usb_get_serial_port_data(port);
1221 struct serial_struct new_serial; 1202 struct serial_struct new_serial;
1222 struct ftdi_private old_priv; 1203 struct ftdi_private old_priv;
@@ -1279,8 +1260,7 @@ check_and_exit:
1279 else 1260 else
1280 mutex_unlock(&priv->cfg_lock); 1261 mutex_unlock(&priv->cfg_lock);
1281 return 0; 1262 return 0;
1282 1263}
1283} /* set_serial_info */
1284 1264
1285 1265
1286/* Determine type of FTDI chip based on USB config and descriptor. */ 1266/* Determine type of FTDI chip based on USB config and descriptor. */
@@ -1294,7 +1274,6 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1294 1274
1295 /* Assume it is not the original SIO device for now. */ 1275 /* Assume it is not the original SIO device for now. */
1296 priv->baud_base = 48000000 / 2; 1276 priv->baud_base = 48000000 / 2;
1297 priv->write_offset = 0;
1298 1277
1299 version = le16_to_cpu(udev->descriptor.bcdDevice); 1278 version = le16_to_cpu(udev->descriptor.bcdDevice);
1300 interfaces = udev->actconfig->desc.bNumInterfaces; 1279 interfaces = udev->actconfig->desc.bNumInterfaces;
@@ -1336,7 +1315,6 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1336 /* Old device. Assume it's the original SIO. */ 1315 /* Old device. Assume it's the original SIO. */
1337 priv->chip_type = SIO; 1316 priv->chip_type = SIO;
1338 priv->baud_base = 12000000 / 16; 1317 priv->baud_base = 12000000 / 16;
1339 priv->write_offset = 1;
1340 } else if (version < 0x400) { 1318 } else if (version < 0x400) {
1341 /* Assume it's an FT8U232AM (or FT8U245AM) */ 1319 /* Assume it's an FT8U232AM (or FT8U245AM) */
1342 /* (It might be a BM because of the iSerialNumber bug, 1320 /* (It might be a BM because of the iSerialNumber bug,
@@ -1543,7 +1521,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1543 } 1521 }
1544 1522
1545 kref_init(&priv->kref); 1523 kref_init(&priv->kref);
1546 spin_lock_init(&priv->tx_lock);
1547 mutex_init(&priv->cfg_lock); 1524 mutex_init(&priv->cfg_lock);
1548 init_waitqueue_head(&priv->delta_msr_wait); 1525 init_waitqueue_head(&priv->delta_msr_wait);
1549 1526
@@ -1552,28 +1529,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1552 if (quirk && quirk->port_probe) 1529 if (quirk && quirk->port_probe)
1553 quirk->port_probe(priv); 1530 quirk->port_probe(priv);
1554 1531
1555 /* Increase the size of read buffers */
1556 kfree(port->bulk_in_buffer);
1557 port->bulk_in_buffer = kmalloc(BUFSZ, GFP_KERNEL);
1558 if (!port->bulk_in_buffer) {
1559 kfree(priv);
1560 return -ENOMEM;
1561 }
1562 if (port->read_urb) {
1563 port->read_urb->transfer_buffer = port->bulk_in_buffer;
1564 port->read_urb->transfer_buffer_length = BUFSZ;
1565 }
1566
1567 priv->port = port; 1532 priv->port = port;
1568
1569 /* Free port's existing write urb and transfer buffer. */
1570 if (port->write_urb) {
1571 usb_free_urb(port->write_urb);
1572 port->write_urb = NULL;
1573 }
1574 kfree(port->bulk_out_buffer);
1575 port->bulk_out_buffer = NULL;
1576
1577 usb_set_serial_port_data(port, priv); 1533 usb_set_serial_port_data(port, priv);
1578 1534
1579 ftdi_determine_type(port); 1535 ftdi_determine_type(port);
@@ -1594,7 +1550,7 @@ static void ftdi_USB_UIRT_setup(struct ftdi_private *priv)
1594 priv->flags |= ASYNC_SPD_CUST; 1550 priv->flags |= ASYNC_SPD_CUST;
1595 priv->custom_divisor = 77; 1551 priv->custom_divisor = 77;
1596 priv->force_baud = 38400; 1552 priv->force_baud = 38400;
1597} /* ftdi_USB_UIRT_setup */ 1553}
1598 1554
1599/* Setup for the HE-TIRA1 device, which requires hardwired 1555/* Setup for the HE-TIRA1 device, which requires hardwired
1600 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ 1556 * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */
@@ -1607,7 +1563,7 @@ static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv)
1607 priv->custom_divisor = 240; 1563 priv->custom_divisor = 240;
1608 priv->force_baud = 38400; 1564 priv->force_baud = 38400;
1609 priv->force_rtscts = 1; 1565 priv->force_rtscts = 1;
1610} /* ftdi_HE_TIRA1_setup */ 1566}
1611 1567
1612/* 1568/*
1613 * Module parameter to control latency timer for NDI FTDI-based USB devices. 1569 * Module parameter to control latency timer for NDI FTDI-based USB devices.
@@ -1700,31 +1656,10 @@ static int ftdi_sio_port_remove(struct usb_serial_port *port)
1700 return 0; 1656 return 0;
1701} 1657}
1702 1658
1703static int ftdi_submit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
1704{
1705 struct urb *urb = port->read_urb;
1706 struct usb_serial *serial = port->serial;
1707 int result;
1708
1709 usb_fill_bulk_urb(urb, serial->dev,
1710 usb_rcvbulkpipe(serial->dev,
1711 port->bulk_in_endpointAddress),
1712 urb->transfer_buffer,
1713 urb->transfer_buffer_length,
1714 ftdi_read_bulk_callback, port);
1715 result = usb_submit_urb(urb, mem_flags);
1716 if (result && result != -EPERM)
1717 dev_err(&port->dev,
1718 "%s - failed submitting read urb, error %d\n",
1719 __func__, result);
1720 return result;
1721}
1722
1723static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port) 1659static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1724{ /* ftdi_open */ 1660{
1725 struct usb_device *dev = port->serial->dev; 1661 struct usb_device *dev = port->serial->dev;
1726 struct ftdi_private *priv = usb_get_serial_port_data(port); 1662 struct ftdi_private *priv = usb_get_serial_port_data(port);
1727 unsigned long flags;
1728 int result; 1663 int result;
1729 1664
1730 dbg("%s", __func__); 1665 dbg("%s", __func__);
@@ -1746,20 +1681,13 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1746 if (tty) 1681 if (tty)
1747 ftdi_set_termios(tty, port, tty->termios); 1682 ftdi_set_termios(tty, port, tty->termios);
1748 1683
1749 /* Not throttled */
1750 spin_lock_irqsave(&port->lock, flags);
1751 port->throttled = 0;
1752 port->throttle_req = 0;
1753 spin_unlock_irqrestore(&port->lock, flags);
1754
1755 /* Start reading from the device */ 1684 /* Start reading from the device */
1756 result = ftdi_submit_read_urb(port, GFP_KERNEL); 1685 result = usb_serial_generic_open(tty, port);
1757 if (!result) 1686 if (!result)
1758 kref_get(&priv->kref); 1687 kref_get(&priv->kref);
1759 1688
1760 return result; 1689 return result;
1761} /* ftdi_open */ 1690}
1762
1763 1691
1764static void ftdi_dtr_rts(struct usb_serial_port *port, int on) 1692static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1765{ 1693{
@@ -1789,22 +1717,16 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1789 * usbserial:__serial_close only calls ftdi_close if the point is open 1717 * usbserial:__serial_close only calls ftdi_close if the point is open
1790 * 1718 *
1791 * This only gets called when it is the last close 1719 * This only gets called when it is the last close
1792 *
1793 *
1794 */ 1720 */
1795
1796static void ftdi_close(struct usb_serial_port *port) 1721static void ftdi_close(struct usb_serial_port *port)
1797{ /* ftdi_close */ 1722{
1798 struct ftdi_private *priv = usb_get_serial_port_data(port); 1723 struct ftdi_private *priv = usb_get_serial_port_data(port);
1799 1724
1800 dbg("%s", __func__); 1725 dbg("%s", __func__);
1801 1726
1802 /* shutdown our bulk read */ 1727 usb_serial_generic_close(port);
1803 usb_kill_urb(port->read_urb);
1804 kref_put(&priv->kref, ftdi_sio_priv_release); 1728 kref_put(&priv->kref, ftdi_sio_priv_release);
1805} /* ftdi_close */ 1729}
1806
1807
1808 1730
1809/* The SIO requires the first byte to have: 1731/* The SIO requires the first byte to have:
1810 * B0 1 1732 * B0 1
@@ -1813,211 +1735,39 @@ static void ftdi_close(struct usb_serial_port *port)
1813 * 1735 *
1814 * The new devices do not require this byte 1736 * The new devices do not require this byte
1815 */ 1737 */
1816static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, 1738static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
1817 const unsigned char *buf, int count) 1739 void *dest, size_t size)
1818{ /* ftdi_write */ 1740{
1819 struct ftdi_private *priv = usb_get_serial_port_data(port); 1741 struct ftdi_private *priv;
1820 struct urb *urb; 1742 int count;
1821 unsigned char *buffer;
1822 int data_offset ; /* will be 1 for the SIO and 0 otherwise */
1823 int status;
1824 int transfer_size;
1825 unsigned long flags; 1743 unsigned long flags;
1826 1744
1827 dbg("%s port %d, %d bytes", __func__, port->number, count); 1745 priv = usb_get_serial_port_data(port);
1828
1829 if (count == 0) {
1830 dbg("write request of 0 bytes");
1831 return 0;
1832 }
1833 spin_lock_irqsave(&priv->tx_lock, flags);
1834 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
1835 spin_unlock_irqrestore(&priv->tx_lock, flags);
1836 dbg("%s - write limit hit", __func__);
1837 return 0;
1838 }
1839 priv->tx_outstanding_urbs++;
1840 spin_unlock_irqrestore(&priv->tx_lock, flags);
1841
1842 data_offset = priv->write_offset;
1843 dbg("data_offset set to %d", data_offset);
1844
1845 /* Determine total transfer size */
1846 transfer_size = count;
1847 if (data_offset > 0) {
1848 /* Original sio needs control bytes too... */
1849 transfer_size += (data_offset *
1850 ((count + (priv->max_packet_size - 1 - data_offset)) /
1851 (priv->max_packet_size - data_offset)));
1852 }
1853
1854 buffer = kmalloc(transfer_size, GFP_ATOMIC);
1855 if (!buffer) {
1856 dev_err(&port->dev,
1857 "%s ran out of kernel memory for urb ...\n", __func__);
1858 count = -ENOMEM;
1859 goto error_no_buffer;
1860 }
1861
1862 urb = usb_alloc_urb(0, GFP_ATOMIC);
1863 if (!urb) {
1864 dev_err(&port->dev, "%s - no more free urbs\n", __func__);
1865 count = -ENOMEM;
1866 goto error_no_urb;
1867 }
1868 1746
1869 /* Copy data */ 1747 if (priv->chip_type == SIO) {
1870 if (data_offset > 0) { 1748 unsigned char *buffer = dest;
1871 /* Original sio requires control byte at start of 1749 int i, len, c;
1872 each packet. */ 1750
1873 int user_pktsz = priv->max_packet_size - data_offset; 1751 count = 0;
1874 int todo = count; 1752 spin_lock_irqsave(&port->lock, flags);
1875 unsigned char *first_byte = buffer; 1753 for (i = 0; i < size - 1; i += priv->max_packet_size) {
1876 const unsigned char *current_position = buf; 1754 len = min_t(int, size - i, priv->max_packet_size) - 1;
1877 1755 c = kfifo_out(&port->write_fifo, &buffer[i + 1], len);
1878 while (todo > 0) { 1756 if (!c)
1879 if (user_pktsz > todo) 1757 break;
1880 user_pktsz = todo; 1758 buffer[i] = (c << 2) + 1;
1881 /* Write the control byte at the front of the packet*/ 1759 count += c + 1;
1882 *first_byte = 1 | ((user_pktsz) << 2);
1883 /* Copy data for packet */
1884 memcpy(first_byte + data_offset,
1885 current_position, user_pktsz);
1886 first_byte += user_pktsz + data_offset;
1887 current_position += user_pktsz;
1888 todo -= user_pktsz;
1889 } 1760 }
1761 spin_unlock_irqrestore(&port->lock, flags);
1890 } else { 1762 } else {
1891 /* No control byte required. */ 1763 count = kfifo_out_locked(&port->write_fifo, dest, size,
1892 /* Copy in the data to send */ 1764 &port->lock);
1893 memcpy(buffer, buf, count);
1894 }
1895
1896 usb_serial_debug_data(debug, &port->dev, __func__,
1897 transfer_size, buffer);
1898
1899 /* fill the buffer and send it */
1900 usb_fill_bulk_urb(urb, port->serial->dev,
1901 usb_sndbulkpipe(port->serial->dev,
1902 port->bulk_out_endpointAddress),
1903 buffer, transfer_size,
1904 ftdi_write_bulk_callback, port);
1905
1906 status = usb_submit_urb(urb, GFP_ATOMIC);
1907 if (status) {
1908 dev_err(&port->dev,
1909 "%s - failed submitting write urb, error %d\n",
1910 __func__, status);
1911 count = status;
1912 goto error;
1913 } else {
1914 spin_lock_irqsave(&priv->tx_lock, flags);
1915 priv->tx_outstanding_bytes += count;
1916 spin_unlock_irqrestore(&priv->tx_lock, flags);
1917 } 1765 }
1918 1766
1919 /* we are done with this urb, so let the host driver
1920 * really free it when it is finished with it */
1921 usb_free_urb(urb);
1922
1923 dbg("%s write returning: %d", __func__, count);
1924 return count;
1925error:
1926 usb_free_urb(urb);
1927error_no_urb:
1928 kfree(buffer);
1929error_no_buffer:
1930 spin_lock_irqsave(&priv->tx_lock, flags);
1931 priv->tx_outstanding_urbs--;
1932 spin_unlock_irqrestore(&priv->tx_lock, flags);
1933 return count; 1767 return count;
1934} /* ftdi_write */
1935
1936
1937/* This function may get called when the device is closed */
1938
1939static void ftdi_write_bulk_callback(struct urb *urb)
1940{
1941 unsigned long flags;
1942 struct usb_serial_port *port = urb->context;
1943 struct ftdi_private *priv;
1944 int data_offset; /* will be 1 for the SIO and 0 otherwise */
1945 unsigned long countback;
1946 int status = urb->status;
1947
1948 /* free up the transfer buffer, as usb_free_urb() does not do this */
1949 kfree(urb->transfer_buffer);
1950
1951 dbg("%s - port %d", __func__, port->number);
1952
1953 priv = usb_get_serial_port_data(port);
1954 if (!priv) {
1955 dbg("%s - bad port private data pointer - exiting", __func__);
1956 return;
1957 }
1958 /* account for transferred data */
1959 countback = urb->transfer_buffer_length;
1960 data_offset = priv->write_offset;
1961 if (data_offset > 0) {
1962 /* Subtract the control bytes */
1963 countback -= (data_offset * DIV_ROUND_UP(countback, priv->max_packet_size));
1964 }
1965 spin_lock_irqsave(&priv->tx_lock, flags);
1966 --priv->tx_outstanding_urbs;
1967 priv->tx_outstanding_bytes -= countback;
1968 spin_unlock_irqrestore(&priv->tx_lock, flags);
1969
1970 if (status) {
1971 dbg("nonzero write bulk status received: %d", status);
1972 }
1973
1974 usb_serial_port_softint(port);
1975} /* ftdi_write_bulk_callback */
1976
1977
1978static int ftdi_write_room(struct tty_struct *tty)
1979{
1980 struct usb_serial_port *port = tty->driver_data;
1981 struct ftdi_private *priv = usb_get_serial_port_data(port);
1982 int room;
1983 unsigned long flags;
1984
1985 dbg("%s - port %d", __func__, port->number);
1986
1987 spin_lock_irqsave(&priv->tx_lock, flags);
1988 if (priv->tx_outstanding_urbs < URB_UPPER_LIMIT) {
1989 /*
1990 * We really can take anything the user throws at us
1991 * but let's pick a nice big number to tell the tty
1992 * layer that we have lots of free space
1993 */
1994 room = 2048;
1995 } else {
1996 room = 0;
1997 }
1998 spin_unlock_irqrestore(&priv->tx_lock, flags);
1999 return room;
2000} 1768}
2001 1769
2002static int ftdi_chars_in_buffer(struct tty_struct *tty) 1770#define FTDI_RS_ERR_MASK (FTDI_RS_BI | FTDI_RS_PE | FTDI_RS_FE | FTDI_RS_OE)
2003{
2004 struct usb_serial_port *port = tty->driver_data;
2005 struct ftdi_private *priv = usb_get_serial_port_data(port);
2006 int buffered;
2007 unsigned long flags;
2008
2009 dbg("%s - port %d", __func__, port->number);
2010
2011 spin_lock_irqsave(&priv->tx_lock, flags);
2012 buffered = (int)priv->tx_outstanding_bytes;
2013 spin_unlock_irqrestore(&priv->tx_lock, flags);
2014 if (buffered < 0) {
2015 dev_err(&port->dev, "%s outstanding tx bytes is negative!\n",
2016 __func__);
2017 buffered = 0;
2018 }
2019 return buffered;
2020}
2021 1771
2022static int ftdi_process_packet(struct tty_struct *tty, 1772static int ftdi_process_packet(struct tty_struct *tty,
2023 struct usb_serial_port *port, struct ftdi_private *priv, 1773 struct usb_serial_port *port, struct ftdi_private *priv,
@@ -2045,28 +1795,21 @@ static int ftdi_process_packet(struct tty_struct *tty,
2045 priv->prev_status = status; 1795 priv->prev_status = status;
2046 } 1796 }
2047 1797
2048 /*
2049 * Although the device uses a bitmask and hence can have multiple
2050 * errors on a packet - the order here sets the priority the error is
2051 * returned to the tty layer.
2052 */
2053 flag = TTY_NORMAL; 1798 flag = TTY_NORMAL;
2054 if (packet[1] & FTDI_RS_OE) { 1799 if (packet[1] & FTDI_RS_ERR_MASK) {
2055 flag = TTY_OVERRUN; 1800 /* Break takes precedence over parity, which takes precedence
2056 dbg("OVERRRUN error"); 1801 * over framing errors */
2057 } 1802 if (packet[1] & FTDI_RS_BI) {
2058 if (packet[1] & FTDI_RS_BI) { 1803 flag = TTY_BREAK;
2059 flag = TTY_BREAK; 1804 usb_serial_handle_break(port);
2060 dbg("BREAK received"); 1805 } else if (packet[1] & FTDI_RS_PE) {
2061 usb_serial_handle_break(port); 1806 flag = TTY_PARITY;
2062 } 1807 } else if (packet[1] & FTDI_RS_FE) {
2063 if (packet[1] & FTDI_RS_PE) { 1808 flag = TTY_FRAME;
2064 flag = TTY_PARITY; 1809 }
2065 dbg("PARITY error"); 1810 /* Overrun is special, not associated with a char */
2066 } 1811 if (packet[1] & FTDI_RS_OE)
2067 if (packet[1] & FTDI_RS_FE) { 1812 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2068 flag = TTY_FRAME;
2069 dbg("FRAMING error");
2070 } 1813 }
2071 1814
2072 len -= 2; 1815 len -= 2;
@@ -2074,20 +1817,21 @@ static int ftdi_process_packet(struct tty_struct *tty,
2074 return 0; /* status only */ 1817 return 0; /* status only */
2075 ch = packet + 2; 1818 ch = packet + 2;
2076 1819
2077 if (!(port->console && port->sysrq) && flag == TTY_NORMAL) 1820 if (port->port.console && port->sysrq) {
2078 tty_insert_flip_string(tty, ch, len);
2079 else {
2080 for (i = 0; i < len; i++, ch++) { 1821 for (i = 0; i < len; i++, ch++) {
2081 if (!usb_serial_handle_sysrq_char(tty, port, *ch)) 1822 if (!usb_serial_handle_sysrq_char(tty, port, *ch))
2082 tty_insert_flip_char(tty, *ch, flag); 1823 tty_insert_flip_char(tty, *ch, flag);
2083 } 1824 }
1825 } else {
1826 tty_insert_flip_string_fixed_flag(tty, ch, flag, len);
2084 } 1827 }
1828
2085 return len; 1829 return len;
2086} 1830}
2087 1831
2088static void ftdi_process_read(struct usb_serial_port *port) 1832static void ftdi_process_read_urb(struct urb *urb)
2089{ 1833{
2090 struct urb *urb = port->read_urb; 1834 struct usb_serial_port *port = urb->context;
2091 struct tty_struct *tty; 1835 struct tty_struct *tty;
2092 struct ftdi_private *priv = usb_get_serial_port_data(port); 1836 struct ftdi_private *priv = usb_get_serial_port_data(port);
2093 char *data = (char *)urb->transfer_buffer; 1837 char *data = (char *)urb->transfer_buffer;
@@ -2109,32 +1853,6 @@ static void ftdi_process_read(struct usb_serial_port *port)
2109 tty_kref_put(tty); 1853 tty_kref_put(tty);
2110} 1854}
2111 1855
2112static void ftdi_read_bulk_callback(struct urb *urb)
2113{
2114 struct usb_serial_port *port = urb->context;
2115 unsigned long flags;
2116
2117 dbg("%s - port %d", __func__, port->number);
2118
2119 if (urb->status) {
2120 dbg("%s - nonzero read bulk status received: %d",
2121 __func__, urb->status);
2122 return;
2123 }
2124
2125 usb_serial_debug_data(debug, &port->dev, __func__,
2126 urb->actual_length, urb->transfer_buffer);
2127 ftdi_process_read(port);
2128
2129 spin_lock_irqsave(&port->lock, flags);
2130 port->throttled = port->throttle_req;
2131 if (!port->throttled) {
2132 spin_unlock_irqrestore(&port->lock, flags);
2133 ftdi_submit_read_urb(port, GFP_ATOMIC);
2134 } else
2135 spin_unlock_irqrestore(&port->lock, flags);
2136}
2137
2138static void ftdi_break_ctl(struct tty_struct *tty, int break_state) 1856static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2139{ 1857{
2140 struct usb_serial_port *port = tty->driver_data; 1858 struct usb_serial_port *port = tty->driver_data;
@@ -2165,15 +1883,13 @@ static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2165 1883
2166} 1884}
2167 1885
2168
2169/* old_termios contains the original termios settings and tty->termios contains 1886/* old_termios contains the original termios settings and tty->termios contains
2170 * the new setting to be used 1887 * the new setting to be used
2171 * WARNING: set_termios calls this with old_termios in kernel space 1888 * WARNING: set_termios calls this with old_termios in kernel space
2172 */ 1889 */
2173
2174static void ftdi_set_termios(struct tty_struct *tty, 1890static void ftdi_set_termios(struct tty_struct *tty,
2175 struct usb_serial_port *port, struct ktermios *old_termios) 1891 struct usb_serial_port *port, struct ktermios *old_termios)
2176{ /* ftdi_termios */ 1892{
2177 struct usb_device *dev = port->serial->dev; 1893 struct usb_device *dev = port->serial->dev;
2178 struct ftdi_private *priv = usb_get_serial_port_data(port); 1894 struct ftdi_private *priv = usb_get_serial_port_data(port);
2179 struct ktermios *termios = tty->termios; 1895 struct ktermios *termios = tty->termios;
@@ -2401,7 +2117,6 @@ static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
2401 return update_mctrl(port, set, clear); 2117 return update_mctrl(port, set, clear);
2402} 2118}
2403 2119
2404
2405static int ftdi_ioctl(struct tty_struct *tty, struct file *file, 2120static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2406 unsigned int cmd, unsigned long arg) 2121 unsigned int cmd, unsigned long arg)
2407{ 2122{
@@ -2470,35 +2185,6 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
2470 return -ENOIOCTLCMD; 2185 return -ENOIOCTLCMD;
2471} 2186}
2472 2187
2473static void ftdi_throttle(struct tty_struct *tty)
2474{
2475 struct usb_serial_port *port = tty->driver_data;
2476 unsigned long flags;
2477
2478 dbg("%s - port %d", __func__, port->number);
2479
2480 spin_lock_irqsave(&port->lock, flags);
2481 port->throttle_req = 1;
2482 spin_unlock_irqrestore(&port->lock, flags);
2483}
2484
2485void ftdi_unthrottle(struct tty_struct *tty)
2486{
2487 struct usb_serial_port *port = tty->driver_data;
2488 int was_throttled;
2489 unsigned long flags;
2490
2491 dbg("%s - port %d", __func__, port->number);
2492
2493 spin_lock_irqsave(&port->lock, flags);
2494 was_throttled = port->throttled;
2495 port->throttled = port->throttle_req = 0;
2496 spin_unlock_irqrestore(&port->lock, flags);
2497
2498 if (was_throttled)
2499 ftdi_submit_read_urb(port, GFP_KERNEL);
2500}
2501
2502static int __init ftdi_init(void) 2188static int __init ftdi_init(void)
2503{ 2189{
2504 int retval; 2190 int retval;
@@ -2529,15 +2215,12 @@ failed_sio_register:
2529 return retval; 2215 return retval;
2530} 2216}
2531 2217
2532
2533static void __exit ftdi_exit(void) 2218static void __exit ftdi_exit(void)
2534{ 2219{
2535
2536 dbg("%s", __func__); 2220 dbg("%s", __func__);
2537 2221
2538 usb_deregister(&ftdi_driver); 2222 usb_deregister(&ftdi_driver);
2539 usb_serial_deregister(&ftdi_sio_device); 2223 usb_serial_deregister(&ftdi_sio_device);
2540
2541} 2224}
2542 2225
2543 2226
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index ff9bf80327a3..213fe3d61282 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -23,14 +23,16 @@
23 */ 23 */
24 24
25/* Commands */ 25/* Commands */
26#define FTDI_SIO_RESET 0 /* Reset the port */ 26#define FTDI_SIO_RESET 0 /* Reset the port */
27#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 27#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
28#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */ 28#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */
29#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */ 29#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */
30#define FTDI_SIO_SET_DATA 4 /* Set the data characteristics of the port */ 30#define FTDI_SIO_SET_DATA 4 /* Set the data characteristics of
31#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modem status register */ 31 the port */
32#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */ 32#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modem
33#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */ 33 status register */
34#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
35#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
34#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */ 36#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */
35#define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */ 37#define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */
36 38
@@ -52,7 +54,7 @@
52 */ 54 */
53 55
54/* Port Identifier Table */ 56/* Port Identifier Table */
55#define PIT_DEFAULT 0 /* SIOA */ 57#define PIT_DEFAULT 0 /* SIOA */
56#define PIT_SIOA 1 /* SIOA */ 58#define PIT_SIOA 1 /* SIOA */
57/* The device this driver is tested with one has only one port */ 59/* The device this driver is tested with one has only one port */
58#define PIT_SIOB 2 /* SIOB */ 60#define PIT_SIOB 2 /* SIOB */
@@ -103,20 +105,21 @@
103 * wLength: 0 105 * wLength: 0
104 * Data: None 106 * Data: None
105 * The BaudDivisor values are calculated as follows: 107 * The BaudDivisor values are calculated as follows:
106 * - BaseClock is either 12000000 or 48000000 depending on the device. FIXME: I wish 108 * - BaseClock is either 12000000 or 48000000 depending on the device.
107 * I knew how to detect old chips to select proper base clock! 109 * FIXME: I wish I knew how to detect old chips to select proper base clock!
108 * - BaudDivisor is a fixed point number encoded in a funny way. 110 * - BaudDivisor is a fixed point number encoded in a funny way.
109 * (--WRONG WAY OF THINKING--) 111 * (--WRONG WAY OF THINKING--)
110 * BaudDivisor is a fixed point number encoded with following bit weighs: 112 * BaudDivisor is a fixed point number encoded with following bit weighs:
111 * (-2)(-1)(13..0). It is a radical with a denominator of 4, so values 113 * (-2)(-1)(13..0). It is a radical with a denominator of 4, so values
112 * end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...). 114 * end with 0.0 (00...), 0.25 (10...), 0.5 (01...), and 0.75 (11...).
113 * (--THE REALITY--) 115 * (--THE REALITY--)
114 * The both-bits-set has quite different meaning from 0.75 - the chip designers 116 * The both-bits-set has quite different meaning from 0.75 - the chip
115 * have decided it to mean 0.125 instead of 0.75. 117 * designers have decided it to mean 0.125 instead of 0.75.
116 * This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates 118 * This info looked up in FTDI application note "FT8U232 DEVICES \ Data Rates
117 * and Flow Control Consideration for USB to RS232". 119 * and Flow Control Consideration for USB to RS232".
118 * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should 120 * - BaudDivisor = (BaseClock / 16) / BaudRate, where the (=) operation should
119 * automagically re-encode the resulting value to take fractions into consideration. 121 * automagically re-encode the resulting value to take fractions into
122 * consideration.
120 * As all values are integers, some bit twiddling is in order: 123 * As all values are integers, some bit twiddling is in order:
121 * BaudDivisor = (BaseClock / 16 / BaudRate) | 124 * BaudDivisor = (BaseClock / 16 / BaudRate) |
122 * (((BaseClock / 2 / BaudRate) & 4) ? 0x4000 // 0.5 125 * (((BaseClock / 2 / BaudRate) & 4) ? 0x4000 // 0.5
@@ -146,7 +149,7 @@
146 * not supported by the FT8U232AM). 149 * not supported by the FT8U232AM).
147 */ 150 */
148 151
149typedef enum { 152enum ftdi_chip_type {
150 SIO = 1, 153 SIO = 1,
151 FT8U232AM = 2, 154 FT8U232AM = 2,
152 FT232BM = 3, 155 FT232BM = 3,
@@ -154,37 +157,36 @@ typedef enum {
154 FT232RL = 5, 157 FT232RL = 5,
155 FT2232H = 6, 158 FT2232H = 6,
156 FT4232H = 7 159 FT4232H = 7
157} ftdi_chip_type_t; 160};
158 161
159typedef enum { 162enum ftdi_sio_baudrate {
160 ftdi_sio_b300 = 0, 163 ftdi_sio_b300 = 0,
161 ftdi_sio_b600 = 1, 164 ftdi_sio_b600 = 1,
162 ftdi_sio_b1200 = 2, 165 ftdi_sio_b1200 = 2,
163 ftdi_sio_b2400 = 3, 166 ftdi_sio_b2400 = 3,
164 ftdi_sio_b4800 = 4, 167 ftdi_sio_b4800 = 4,
165 ftdi_sio_b9600 = 5, 168 ftdi_sio_b9600 = 5,
166 ftdi_sio_b19200 = 6, 169 ftdi_sio_b19200 = 6,
167 ftdi_sio_b38400 = 7, 170 ftdi_sio_b38400 = 7,
168 ftdi_sio_b57600 = 8, 171 ftdi_sio_b57600 = 8,
169 ftdi_sio_b115200 = 9 172 ftdi_sio_b115200 = 9
170} FTDI_SIO_baudrate_t; 173};
171 174
172/* 175/*
173 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor values 176 * The ftdi_8U232AM_xxMHz_byyy constants have been removed. The encoded divisor
174 * are calculated internally. 177 * values are calculated internally.
175 */ 178 */
176 179#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA
177#define FTDI_SIO_SET_DATA_REQUEST FTDI_SIO_SET_DATA 180#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40
178#define FTDI_SIO_SET_DATA_REQUEST_TYPE 0x40 181#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8)
179#define FTDI_SIO_SET_DATA_PARITY_NONE (0x0 << 8) 182#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8)
180#define FTDI_SIO_SET_DATA_PARITY_ODD (0x1 << 8) 183#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8)
181#define FTDI_SIO_SET_DATA_PARITY_EVEN (0x2 << 8) 184#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8)
182#define FTDI_SIO_SET_DATA_PARITY_MARK (0x3 << 8) 185#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8)
183#define FTDI_SIO_SET_DATA_PARITY_SPACE (0x4 << 8) 186#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11)
184#define FTDI_SIO_SET_DATA_STOP_BITS_1 (0x0 << 11) 187#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11)
185#define FTDI_SIO_SET_DATA_STOP_BITS_15 (0x1 << 11) 188#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11)
186#define FTDI_SIO_SET_DATA_STOP_BITS_2 (0x2 << 11) 189#define FTDI_SIO_SET_BREAK (0x1 << 14)
187#define FTDI_SIO_SET_BREAK (0x1 << 14)
188/* FTDI_SIO_SET_DATA */ 190/* FTDI_SIO_SET_DATA */
189 191
190/* 192/*
@@ -287,8 +289,8 @@ typedef enum {
287 * 289 *
288 * A value of zero in the hIndex field disables handshaking 290 * A value of zero in the hIndex field disables handshaking
289 * 291 *
290 * If Xon/Xoff handshaking is specified, the hValue field should contain the XOFF character 292 * If Xon/Xoff handshaking is specified, the hValue field should contain the
291 * and the lValue field contains the XON character. 293 * XOFF character and the lValue field contains the XON character.
292 */ 294 */
293 295
294/* 296/*
@@ -373,7 +375,10 @@ typedef enum {
373 375
374/* FTDI_SIO_SET_ERROR_CHAR */ 376/* FTDI_SIO_SET_ERROR_CHAR */
375 377
376/* Set the parity error replacement character for the specified communications port */ 378/*
379 * Set the parity error replacement character for the specified communications
380 * port
381 */
377 382
378/* 383/*
379 * BmRequestType: 0100 0000b 384 * BmRequestType: 0100 0000b
@@ -496,9 +501,10 @@ typedef enum {
496 * 501 *
497 * IN Endpoint 502 * IN Endpoint
498 * 503 *
499 * The device reserves the first two bytes of data on this endpoint to contain the current 504 * The device reserves the first two bytes of data on this endpoint to contain
500 * values of the modem and line status registers. In the absence of data, the device 505 * the current values of the modem and line status registers. In the absence of
501 * generates a message consisting of these two status bytes every 40 ms 506 * data, the device generates a message consisting of these two status bytes
507 * every 40 ms
502 * 508 *
503 * Byte 0: Modem Status 509 * Byte 0: Modem Status
504 * 510 *
@@ -530,21 +536,21 @@ typedef enum {
530#define FTDI_RS0_RI (1 << 6) 536#define FTDI_RS0_RI (1 << 6)
531#define FTDI_RS0_RLSD (1 << 7) 537#define FTDI_RS0_RLSD (1 << 7)
532 538
533#define FTDI_RS_DR 1 539#define FTDI_RS_DR 1
534#define FTDI_RS_OE (1<<1) 540#define FTDI_RS_OE (1<<1)
535#define FTDI_RS_PE (1<<2) 541#define FTDI_RS_PE (1<<2)
536#define FTDI_RS_FE (1<<3) 542#define FTDI_RS_FE (1<<3)
537#define FTDI_RS_BI (1<<4) 543#define FTDI_RS_BI (1<<4)
538#define FTDI_RS_THRE (1<<5) 544#define FTDI_RS_THRE (1<<5)
539#define FTDI_RS_TEMT (1<<6) 545#define FTDI_RS_TEMT (1<<6)
540#define FTDI_RS_FIFO (1<<7) 546#define FTDI_RS_FIFO (1<<7)
541 547
542/* 548/*
543 * OUT Endpoint 549 * OUT Endpoint
544 * 550 *
545 * This device reserves the first bytes of data on this endpoint contain the length 551 * This device reserves the first bytes of data on this endpoint contain the
546 * and port identifier of the message. For the FTDI USB Serial converter the port 552 * length and port identifier of the message. For the FTDI USB Serial converter
547 * identifier is always 1. 553 * the port identifier is always 1.
548 * 554 *
549 * Byte 0: Line Status 555 * Byte 0: Line Status
550 * 556 *
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 75482cbc3998..94d86c3febcb 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -275,8 +275,8 @@
275/* 275/*
276 * Hameg HO820 and HO870 interface (using VID 0x0403) 276 * Hameg HO820 and HO870 interface (using VID 0x0403)
277 */ 277 */
278#define HAMEG_HO820_PID 0xed74 278#define HAMEG_HO820_PID 0xed74
279#define HAMEG_HO870_PID 0xed71 279#define HAMEG_HO870_PID 0xed71
280 280
281/* 281/*
282 * MaxStream devices www.maxstream.net 282 * MaxStream devices www.maxstream.net
@@ -289,14 +289,14 @@
289 * and Mike Studer (K6EEP) <k6eep@hamsoftware.org>. 289 * and Mike Studer (K6EEP) <k6eep@hamsoftware.org>.
290 * Ian Abbott <abbotti@mev.co.uk> added a few more from the driver INF file. 290 * Ian Abbott <abbotti@mev.co.uk> added a few more from the driver INF file.
291 */ 291 */
292#define FTDI_MHAM_KW_PID 0xEEE8 /* USB-KW interface */ 292#define FTDI_MHAM_KW_PID 0xEEE8 /* USB-KW interface */
293#define FTDI_MHAM_YS_PID 0xEEE9 /* USB-YS interface */ 293#define FTDI_MHAM_YS_PID 0xEEE9 /* USB-YS interface */
294#define FTDI_MHAM_Y6_PID 0xEEEA /* USB-Y6 interface */ 294#define FTDI_MHAM_Y6_PID 0xEEEA /* USB-Y6 interface */
295#define FTDI_MHAM_Y8_PID 0xEEEB /* USB-Y8 interface */ 295#define FTDI_MHAM_Y8_PID 0xEEEB /* USB-Y8 interface */
296#define FTDI_MHAM_IC_PID 0xEEEC /* USB-IC interface */ 296#define FTDI_MHAM_IC_PID 0xEEEC /* USB-IC interface */
297#define FTDI_MHAM_DB9_PID 0xEEED /* USB-DB9 interface */ 297#define FTDI_MHAM_DB9_PID 0xEEED /* USB-DB9 interface */
298#define FTDI_MHAM_RS232_PID 0xEEEE /* USB-RS232 interface */ 298#define FTDI_MHAM_RS232_PID 0xEEEE /* USB-RS232 interface */
299#define FTDI_MHAM_Y9_PID 0xEEEF /* USB-Y9 interface */ 299#define FTDI_MHAM_Y9_PID 0xEEEF /* USB-Y9 interface */
300 300
301/* Domintell products http://www.domintell.com */ 301/* Domintell products http://www.domintell.com */
302#define FTDI_DOMINTELL_DGQG_PID 0xEF50 /* Master */ 302#define FTDI_DOMINTELL_DGQG_PID 0xEF50 /* Master */
@@ -483,9 +483,9 @@
483 * Blackfin gnICE JTAG 483 * Blackfin gnICE JTAG
484 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice 484 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice
485 */ 485 */
486#define ADI_VID 0x0456 486#define ADI_VID 0x0456
487#define ADI_GNICE_PID 0xF000 487#define ADI_GNICE_PID 0xF000
488#define ADI_GNICEPLUS_PID 0xF001 488#define ADI_GNICEPLUS_PID 0xF001
489 489
490/* 490/*
491 * RATOC REX-USB60F 491 * RATOC REX-USB60F
@@ -611,13 +611,13 @@
611#define SEALEVEL_2802_7_PID 0X2872 /* SeaLINK+8/485 (2802) Port 7 */ 611#define SEALEVEL_2802_7_PID 0X2872 /* SeaLINK+8/485 (2802) Port 7 */
612#define SEALEVEL_2802_8_PID 0X2882 /* SeaLINK+8/485 (2802) Port 8 */ 612#define SEALEVEL_2802_8_PID 0X2882 /* SeaLINK+8/485 (2802) Port 8 */
613#define SEALEVEL_2803_1_PID 0X2813 /* SeaLINK+8 (2803) Port 1 */ 613#define SEALEVEL_2803_1_PID 0X2813 /* SeaLINK+8 (2803) Port 1 */
614#define SEALEVEL_2803_2_PID 0X2823 /* SeaLINK+8 (2803) Port 2 */ 614#define SEALEVEL_2803_2_PID 0X2823 /* SeaLINK+8 (2803) Port 2 */
615#define SEALEVEL_2803_3_PID 0X2833 /* SeaLINK+8 (2803) Port 3 */ 615#define SEALEVEL_2803_3_PID 0X2833 /* SeaLINK+8 (2803) Port 3 */
616#define SEALEVEL_2803_4_PID 0X2843 /* SeaLINK+8 (2803) Port 4 */ 616#define SEALEVEL_2803_4_PID 0X2843 /* SeaLINK+8 (2803) Port 4 */
617#define SEALEVEL_2803_5_PID 0X2853 /* SeaLINK+8 (2803) Port 5 */ 617#define SEALEVEL_2803_5_PID 0X2853 /* SeaLINK+8 (2803) Port 5 */
618#define SEALEVEL_2803_6_PID 0X2863 /* SeaLINK+8 (2803) Port 6 */ 618#define SEALEVEL_2803_6_PID 0X2863 /* SeaLINK+8 (2803) Port 6 */
619#define SEALEVEL_2803_7_PID 0X2873 /* SeaLINK+8 (2803) Port 7 */ 619#define SEALEVEL_2803_7_PID 0X2873 /* SeaLINK+8 (2803) Port 7 */
620#define SEALEVEL_2803_8_PID 0X2883 /* SeaLINK+8 (2803) Port 8 */ 620#define SEALEVEL_2803_8_PID 0X2883 /* SeaLINK+8 (2803) Port 8 */
621 621
622/* 622/*
623 * JETI SPECTROMETER SPECBOS 1201 623 * JETI SPECTROMETER SPECBOS 1201
@@ -1013,7 +1013,7 @@
1013 */ 1013 */
1014#define EVOLUTION_VID 0xDEEE /* Vendor ID */ 1014#define EVOLUTION_VID 0xDEEE /* Vendor ID */
1015#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */ 1015#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */
1016#define EVO_8U232AM_PID 0x02FF /* Evolution robotics RCM2 (FT232AM)*/ 1016#define EVO_8U232AM_PID 0x02FF /* Evolution robotics RCM2 (FT232AM)*/
1017#define EVO_HYBRID_PID 0x0302 /* Evolution robotics RCM4 PID (FT232BM)*/ 1017#define EVO_HYBRID_PID 0x0302 /* Evolution robotics RCM4 PID (FT232BM)*/
1018#define EVO_RCM4_PID 0x0303 /* Evolution robotics RCM4 PID */ 1018#define EVO_RCM4_PID 0x0303 /* Evolution robotics RCM4 PID */
1019 1019
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index f804acb138ec..a817ced82835 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * USB Serial Converter Generic functions 2 * USB Serial Converter Generic functions
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
4 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -12,6 +13,7 @@
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/errno.h> 14#include <linux/errno.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/sysrq.h>
15#include <linux/tty.h> 17#include <linux/tty.h>
16#include <linux/tty_flip.h> 18#include <linux/tty_flip.h>
17#include <linux/module.h> 19#include <linux/module.h>
@@ -117,7 +119,6 @@ void usb_serial_generic_deregister(void)
117 119
118int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port) 120int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
119{ 121{
120 struct usb_serial *serial = port->serial;
121 int result = 0; 122 int result = 0;
122 unsigned long flags; 123 unsigned long flags;
123 124
@@ -130,23 +131,8 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
130 spin_unlock_irqrestore(&port->lock, flags); 131 spin_unlock_irqrestore(&port->lock, flags);
131 132
132 /* if we have a bulk endpoint, start reading from it */ 133 /* if we have a bulk endpoint, start reading from it */
133 if (port->bulk_in_size) { 134 if (port->bulk_in_size)
134 /* Start reading from the device */ 135 result = usb_serial_generic_submit_read_urb(port, GFP_KERNEL);
135 usb_fill_bulk_urb(port->read_urb, serial->dev,
136 usb_rcvbulkpipe(serial->dev,
137 port->bulk_in_endpointAddress),
138 port->read_urb->transfer_buffer,
139 port->read_urb->transfer_buffer_length,
140 ((serial->type->read_bulk_callback) ?
141 serial->type->read_bulk_callback :
142 usb_serial_generic_read_bulk_callback),
143 port);
144 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
145 if (result)
146 dev_err(&port->dev,
147 "%s - failed resubmitting read urb, error %d\n",
148 __func__, result);
149 }
150 136
151 return result; 137 return result;
152} 138}
@@ -155,13 +141,22 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_open);
155static void generic_cleanup(struct usb_serial_port *port) 141static void generic_cleanup(struct usb_serial_port *port)
156{ 142{
157 struct usb_serial *serial = port->serial; 143 struct usb_serial *serial = port->serial;
144 unsigned long flags;
145 int i;
158 146
159 dbg("%s - port %d", __func__, port->number); 147 dbg("%s - port %d", __func__, port->number);
160 148
161 if (serial->dev) { 149 if (serial->dev) {
162 /* shutdown any bulk transfers that might be going on */ 150 /* shutdown any bulk transfers that might be going on */
163 if (port->bulk_out_size) 151 if (port->bulk_out_size) {
164 usb_kill_urb(port->write_urb); 152 usb_kill_urb(port->write_urb);
153 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
154 usb_kill_urb(port->write_urbs[i]);
155
156 spin_lock_irqsave(&port->lock, flags);
157 kfifo_reset_out(&port->write_fifo);
158 spin_unlock_irqrestore(&port->lock, flags);
159 }
165 if (port->bulk_in_size) 160 if (port->bulk_in_size)
166 usb_kill_urb(port->read_urb); 161 usb_kill_urb(port->read_urb);
167 } 162 }
@@ -172,146 +167,68 @@ void usb_serial_generic_close(struct usb_serial_port *port)
172 dbg("%s - port %d", __func__, port->number); 167 dbg("%s - port %d", __func__, port->number);
173 generic_cleanup(port); 168 generic_cleanup(port);
174} 169}
170EXPORT_SYMBOL_GPL(usb_serial_generic_close);
175 171
176static int usb_serial_multi_urb_write(struct tty_struct *tty, 172int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
177 struct usb_serial_port *port, const unsigned char *buf, int count) 173 void *dest, size_t size)
178{ 174{
179 unsigned long flags; 175 return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock);
180 struct urb *urb;
181 unsigned char *buffer;
182 int status;
183 int towrite;
184 int bwrite = 0;
185
186 dbg("%s - port %d", __func__, port->number);
187
188 if (count == 0)
189 dbg("%s - write request of 0 bytes", __func__);
190
191 while (count > 0) {
192 towrite = (count > port->bulk_out_size) ?
193 port->bulk_out_size : count;
194 spin_lock_irqsave(&port->lock, flags);
195 if (port->urbs_in_flight >
196 port->serial->type->max_in_flight_urbs) {
197 spin_unlock_irqrestore(&port->lock, flags);
198 dbg("%s - write limit hit", __func__);
199 return bwrite;
200 }
201 port->tx_bytes_flight += towrite;
202 port->urbs_in_flight++;
203 spin_unlock_irqrestore(&port->lock, flags);
204
205 buffer = kmalloc(towrite, GFP_ATOMIC);
206 if (!buffer) {
207 dev_err(&port->dev,
208 "%s ran out of kernel memory for urb ...\n", __func__);
209 goto error_no_buffer;
210 }
211
212 urb = usb_alloc_urb(0, GFP_ATOMIC);
213 if (!urb) {
214 dev_err(&port->dev, "%s - no more free urbs\n",
215 __func__);
216 goto error_no_urb;
217 }
218
219 /* Copy data */
220 memcpy(buffer, buf + bwrite, towrite);
221 usb_serial_debug_data(debug, &port->dev, __func__,
222 towrite, buffer);
223 /* fill the buffer and send it */
224 usb_fill_bulk_urb(urb, port->serial->dev,
225 usb_sndbulkpipe(port->serial->dev,
226 port->bulk_out_endpointAddress),
227 buffer, towrite,
228 usb_serial_generic_write_bulk_callback, port);
229
230 status = usb_submit_urb(urb, GFP_ATOMIC);
231 if (status) {
232 dev_err(&port->dev,
233 "%s - failed submitting write urb, error %d\n",
234 __func__, status);
235 goto error;
236 }
237
238 /* This urb is the responsibility of the host driver now */
239 usb_free_urb(urb);
240 dbg("%s write: %d", __func__, towrite);
241 count -= towrite;
242 bwrite += towrite;
243 }
244 return bwrite;
245
246error:
247 usb_free_urb(urb);
248error_no_urb:
249 kfree(buffer);
250error_no_buffer:
251 spin_lock_irqsave(&port->lock, flags);
252 port->urbs_in_flight--;
253 port->tx_bytes_flight -= towrite;
254 spin_unlock_irqrestore(&port->lock, flags);
255 return bwrite;
256} 176}
257 177
258/** 178/**
259 * usb_serial_generic_write_start - kick off an URB write 179 * usb_serial_generic_write_start - kick off an URB write
260 * @port: Pointer to the &struct usb_serial_port data 180 * @port: Pointer to the &struct usb_serial_port data
261 * 181 *
262 * Returns the number of bytes queued on success. This will be zero if there 182 * Returns zero on success, or a negative errno value
263 * was nothing to send. Otherwise, it returns a negative errno value
264 */ 183 */
265static int usb_serial_generic_write_start(struct usb_serial_port *port) 184static int usb_serial_generic_write_start(struct usb_serial_port *port)
266{ 185{
267 struct usb_serial *serial = port->serial; 186 struct urb *urb;
268 unsigned char *data; 187 int count, result;
269 int result;
270 int count;
271 unsigned long flags; 188 unsigned long flags;
272 bool start_io; 189 int i;
273 190
274 /* Atomically determine whether we can and need to start a USB 191 if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags))
275 * operation. */ 192 return 0;
193retry:
276 spin_lock_irqsave(&port->lock, flags); 194 spin_lock_irqsave(&port->lock, flags);
277 if (port->write_urb_busy) 195 if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) {
278 start_io = false; 196 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
279 else { 197 spin_unlock_irqrestore(&port->lock, flags);
280 start_io = (kfifo_len(&port->write_fifo) != 0); 198 return 0;
281 port->write_urb_busy = start_io;
282 } 199 }
200 i = (int)find_first_bit(&port->write_urbs_free,
201 ARRAY_SIZE(port->write_urbs));
283 spin_unlock_irqrestore(&port->lock, flags); 202 spin_unlock_irqrestore(&port->lock, flags);
284 203
285 if (!start_io) 204 urb = port->write_urbs[i];
286 return 0; 205 count = port->serial->type->prepare_write_buffer(port,
287 206 urb->transfer_buffer,
288 data = port->write_urb->transfer_buffer; 207 port->bulk_out_size);
289 count = kfifo_out_locked(&port->write_fifo, data, port->bulk_out_size, &port->lock); 208 urb->transfer_buffer_length = count;
290 usb_serial_debug_data(debug, &port->dev, __func__, count, data); 209 usb_serial_debug_data(debug, &port->dev, __func__, count,
291 210 urb->transfer_buffer);
292 /* set up our urb */ 211 result = usb_submit_urb(urb, GFP_ATOMIC);
293 usb_fill_bulk_urb(port->write_urb, serial->dev,
294 usb_sndbulkpipe(serial->dev,
295 port->bulk_out_endpointAddress),
296 port->write_urb->transfer_buffer, count,
297 ((serial->type->write_bulk_callback) ?
298 serial->type->write_bulk_callback :
299 usb_serial_generic_write_bulk_callback),
300 port);
301
302 /* send the data out the bulk port */
303 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
304 if (result) { 212 if (result) {
305 dev_err(&port->dev, 213 dev_err(&port->dev, "%s - error submitting urb: %d\n",
306 "%s - failed submitting write urb, error %d\n",
307 __func__, result); 214 __func__, result);
308 /* don't have to grab the lock here, as we will 215 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
309 retry if != 0 */ 216 return result;
310 port->write_urb_busy = 0; 217 }
311 } else 218 clear_bit(i, &port->write_urbs_free);
312 result = count;
313 219
314 return result; 220 spin_lock_irqsave(&port->lock, flags);
221 port->tx_bytes += count;
222 spin_unlock_irqrestore(&port->lock, flags);
223
224 /* Try sending off another urb, unless in irq context (in which case
225 * there will be no free urb). */
226 if (!in_irq())
227 goto retry;
228
229 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
230
231 return 0;
315} 232}
316 233
317/** 234/**
@@ -328,7 +245,6 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port)
328int usb_serial_generic_write(struct tty_struct *tty, 245int usb_serial_generic_write(struct tty_struct *tty,
329 struct usb_serial_port *port, const unsigned char *buf, int count) 246 struct usb_serial_port *port, const unsigned char *buf, int count)
330{ 247{
331 struct usb_serial *serial = port->serial;
332 int result; 248 int result;
333 249
334 dbg("%s - port %d", __func__, port->number); 250 dbg("%s - port %d", __func__, port->number);
@@ -337,31 +253,23 @@ int usb_serial_generic_write(struct tty_struct *tty,
337 if (!port->bulk_out_size) 253 if (!port->bulk_out_size)
338 return -ENODEV; 254 return -ENODEV;
339 255
340 if (count == 0) { 256 if (!count)
341 dbg("%s - write request of 0 bytes", __func__);
342 return 0; 257 return 0;
343 }
344
345 if (serial->type->max_in_flight_urbs)
346 return usb_serial_multi_urb_write(tty, port,
347 buf, count);
348 258
349 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); 259 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
350 result = usb_serial_generic_write_start(port); 260 result = usb_serial_generic_write_start(port);
261 if (result)
262 return result;
351 263
352 if (result >= 0) 264 return count;
353 result = count;
354
355 return result;
356} 265}
357EXPORT_SYMBOL_GPL(usb_serial_generic_write); 266EXPORT_SYMBOL_GPL(usb_serial_generic_write);
358 267
359int usb_serial_generic_write_room(struct tty_struct *tty) 268int usb_serial_generic_write_room(struct tty_struct *tty)
360{ 269{
361 struct usb_serial_port *port = tty->driver_data; 270 struct usb_serial_port *port = tty->driver_data;
362 struct usb_serial *serial = port->serial;
363 unsigned long flags; 271 unsigned long flags;
364 int room = 0; 272 int room;
365 273
366 dbg("%s - port %d", __func__, port->number); 274 dbg("%s - port %d", __func__, port->number);
367 275
@@ -369,14 +277,7 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
369 return 0; 277 return 0;
370 278
371 spin_lock_irqsave(&port->lock, flags); 279 spin_lock_irqsave(&port->lock, flags);
372 if (serial->type->max_in_flight_urbs) { 280 room = kfifo_avail(&port->write_fifo);
373 if (port->urbs_in_flight < serial->type->max_in_flight_urbs)
374 room = port->bulk_out_size *
375 (serial->type->max_in_flight_urbs -
376 port->urbs_in_flight);
377 } else {
378 room = kfifo_avail(&port->write_fifo);
379 }
380 spin_unlock_irqrestore(&port->lock, flags); 281 spin_unlock_irqrestore(&port->lock, flags);
381 282
382 dbg("%s - returns %d", __func__, room); 283 dbg("%s - returns %d", __func__, room);
@@ -386,7 +287,6 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
386int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) 287int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
387{ 288{
388 struct usb_serial_port *port = tty->driver_data; 289 struct usb_serial_port *port = tty->driver_data;
389 struct usb_serial *serial = port->serial;
390 unsigned long flags; 290 unsigned long flags;
391 int chars; 291 int chars;
392 292
@@ -396,61 +296,47 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
396 return 0; 296 return 0;
397 297
398 spin_lock_irqsave(&port->lock, flags); 298 spin_lock_irqsave(&port->lock, flags);
399 if (serial->type->max_in_flight_urbs) 299 chars = kfifo_len(&port->write_fifo) + port->tx_bytes;
400 chars = port->tx_bytes_flight;
401 else
402 chars = kfifo_len(&port->write_fifo);
403 spin_unlock_irqrestore(&port->lock, flags); 300 spin_unlock_irqrestore(&port->lock, flags);
404 301
405 dbg("%s - returns %d", __func__, chars); 302 dbg("%s - returns %d", __func__, chars);
406 return chars; 303 return chars;
407} 304}
408 305
409 306int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
410void usb_serial_generic_resubmit_read_urb(struct usb_serial_port *port, 307 gfp_t mem_flags)
411 gfp_t mem_flags)
412{ 308{
413 struct urb *urb = port->read_urb;
414 struct usb_serial *serial = port->serial;
415 int result; 309 int result;
416 310
417 /* Continue reading from device */ 311 result = usb_submit_urb(port->read_urb, mem_flags);
418 usb_fill_bulk_urb(urb, serial->dev,
419 usb_rcvbulkpipe(serial->dev,
420 port->bulk_in_endpointAddress),
421 urb->transfer_buffer,
422 urb->transfer_buffer_length,
423 ((serial->type->read_bulk_callback) ?
424 serial->type->read_bulk_callback :
425 usb_serial_generic_read_bulk_callback), port);
426
427 result = usb_submit_urb(urb, mem_flags);
428 if (result && result != -EPERM) { 312 if (result && result != -EPERM) {
429 dev_err(&port->dev, 313 dev_err(&port->dev, "%s - error submitting urb: %d\n",
430 "%s - failed resubmitting read urb, error %d\n",
431 __func__, result); 314 __func__, result);
432 } 315 }
316 return result;
433} 317}
434EXPORT_SYMBOL_GPL(usb_serial_generic_resubmit_read_urb); 318EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb);
435 319
436/* Push data to tty layer and resubmit the bulk read URB */ 320void usb_serial_generic_process_read_urb(struct urb *urb)
437static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
438{ 321{
439 struct urb *urb = port->read_urb; 322 struct usb_serial_port *port = urb->context;
440 struct tty_struct *tty = tty_port_tty_get(&port->port); 323 struct tty_struct *tty;
441 char *ch = (char *)urb->transfer_buffer; 324 char *ch = (char *)urb->transfer_buffer;
442 int i; 325 int i;
443 326
327 if (!urb->actual_length)
328 return;
329
330 tty = tty_port_tty_get(&port->port);
444 if (!tty) 331 if (!tty)
445 goto done; 332 return;
446 333
447 /* The per character mucking around with sysrq path it too slow for 334 /* The per character mucking around with sysrq path it too slow for
448 stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases 335 stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases
449 where the USB serial is not a console anyway */ 336 where the USB serial is not a console anyway */
450 if (!port->console || !port->sysrq) 337 if (!port->port.console || !port->sysrq)
451 tty_insert_flip_string(tty, ch, urb->actual_length); 338 tty_insert_flip_string(tty, ch, urb->actual_length);
452 else { 339 else {
453 /* Push data to tty */
454 for (i = 0; i < urb->actual_length; i++, ch++) { 340 for (i = 0; i < urb->actual_length; i++, ch++) {
455 if (!usb_serial_handle_sysrq_char(tty, port, *ch)) 341 if (!usb_serial_handle_sysrq_char(tty, port, *ch))
456 tty_insert_flip_char(tty, *ch, TTY_NORMAL); 342 tty_insert_flip_char(tty, *ch, TTY_NORMAL);
@@ -458,9 +344,8 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
458 } 344 }
459 tty_flip_buffer_push(tty); 345 tty_flip_buffer_push(tty);
460 tty_kref_put(tty); 346 tty_kref_put(tty);
461done:
462 usb_serial_generic_resubmit_read_urb(port, GFP_ATOMIC);
463} 347}
348EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb);
464 349
465void usb_serial_generic_read_bulk_callback(struct urb *urb) 350void usb_serial_generic_read_bulk_callback(struct urb *urb)
466{ 351{
@@ -479,13 +364,14 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
479 364
480 usb_serial_debug_data(debug, &port->dev, __func__, 365 usb_serial_debug_data(debug, &port->dev, __func__,
481 urb->actual_length, data); 366 urb->actual_length, data);
367 port->serial->type->process_read_urb(urb);
482 368
483 /* Throttle the device if requested by tty */ 369 /* Throttle the device if requested by tty */
484 spin_lock_irqsave(&port->lock, flags); 370 spin_lock_irqsave(&port->lock, flags);
485 port->throttled = port->throttle_req; 371 port->throttled = port->throttle_req;
486 if (!port->throttled) { 372 if (!port->throttled) {
487 spin_unlock_irqrestore(&port->lock, flags); 373 spin_unlock_irqrestore(&port->lock, flags);
488 flush_and_resubmit_read_urb(port); 374 usb_serial_generic_submit_read_urb(port, GFP_ATOMIC);
489 } else 375 } else
490 spin_unlock_irqrestore(&port->lock, flags); 376 spin_unlock_irqrestore(&port->lock, flags);
491} 377}
@@ -496,30 +382,29 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
496 unsigned long flags; 382 unsigned long flags;
497 struct usb_serial_port *port = urb->context; 383 struct usb_serial_port *port = urb->context;
498 int status = urb->status; 384 int status = urb->status;
385 int i;
499 386
500 dbg("%s - port %d", __func__, port->number); 387 dbg("%s - port %d", __func__, port->number);
501 388
502 if (port->serial->type->max_in_flight_urbs) { 389 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
503 kfree(urb->transfer_buffer); 390 if (port->write_urbs[i] == urb)
391 break;
392
393 spin_lock_irqsave(&port->lock, flags);
394 port->tx_bytes -= urb->transfer_buffer_length;
395 set_bit(i, &port->write_urbs_free);
396 spin_unlock_irqrestore(&port->lock, flags);
397
398 if (status) {
399 dbg("%s - non-zero urb status: %d", __func__, status);
504 400
505 spin_lock_irqsave(&port->lock, flags); 401 spin_lock_irqsave(&port->lock, flags);
506 --port->urbs_in_flight; 402 kfifo_reset_out(&port->write_fifo);
507 port->tx_bytes_flight -= urb->transfer_buffer_length;
508 if (port->urbs_in_flight < 0)
509 port->urbs_in_flight = 0;
510 spin_unlock_irqrestore(&port->lock, flags); 403 spin_unlock_irqrestore(&port->lock, flags);
511 } else { 404 } else {
512 port->write_urb_busy = 0; 405 usb_serial_generic_write_start(port);
513
514 if (status)
515 kfifo_reset_out(&port->write_fifo);
516 else
517 usb_serial_generic_write_start(port);
518 } 406 }
519 407
520 if (status)
521 dbg("%s - non-zero urb status: %d", __func__, status);
522
523 usb_serial_port_softint(port); 408 usb_serial_port_softint(port);
524} 409}
525EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 410EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
@@ -537,31 +422,31 @@ void usb_serial_generic_throttle(struct tty_struct *tty)
537 port->throttle_req = 1; 422 port->throttle_req = 1;
538 spin_unlock_irqrestore(&port->lock, flags); 423 spin_unlock_irqrestore(&port->lock, flags);
539} 424}
425EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);
540 426
541void usb_serial_generic_unthrottle(struct tty_struct *tty) 427void usb_serial_generic_unthrottle(struct tty_struct *tty)
542{ 428{
543 struct usb_serial_port *port = tty->driver_data; 429 struct usb_serial_port *port = tty->driver_data;
544 int was_throttled; 430 int was_throttled;
545 unsigned long flags;
546 431
547 dbg("%s - port %d", __func__, port->number); 432 dbg("%s - port %d", __func__, port->number);
548 433
549 /* Clear the throttle flags */ 434 /* Clear the throttle flags */
550 spin_lock_irqsave(&port->lock, flags); 435 spin_lock_irq(&port->lock);
551 was_throttled = port->throttled; 436 was_throttled = port->throttled;
552 port->throttled = port->throttle_req = 0; 437 port->throttled = port->throttle_req = 0;
553 spin_unlock_irqrestore(&port->lock, flags); 438 spin_unlock_irq(&port->lock);
554 439
555 if (was_throttled) { 440 if (was_throttled)
556 /* Resume reading from device */ 441 usb_serial_generic_submit_read_urb(port, GFP_KERNEL);
557 flush_and_resubmit_read_urb(port);
558 }
559} 442}
443EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
560 444
445#ifdef CONFIG_MAGIC_SYSRQ
561int usb_serial_handle_sysrq_char(struct tty_struct *tty, 446int usb_serial_handle_sysrq_char(struct tty_struct *tty,
562 struct usb_serial_port *port, unsigned int ch) 447 struct usb_serial_port *port, unsigned int ch)
563{ 448{
564 if (port->sysrq && port->console) { 449 if (port->sysrq && port->port.console) {
565 if (ch && time_before(jiffies, port->sysrq)) { 450 if (ch && time_before(jiffies, port->sysrq)) {
566 handle_sysrq(ch, tty); 451 handle_sysrq(ch, tty);
567 port->sysrq = 0; 452 port->sysrq = 0;
@@ -571,6 +456,13 @@ int usb_serial_handle_sysrq_char(struct tty_struct *tty,
571 } 456 }
572 return 0; 457 return 0;
573} 458}
459#else
460int usb_serial_handle_sysrq_char(struct tty_struct *tty,
461 struct usb_serial_port *port, unsigned int ch)
462{
463 return 0;
464}
465#endif
574EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); 466EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
575 467
576int usb_serial_handle_break(struct usb_serial_port *port) 468int usb_serial_handle_break(struct usb_serial_port *port)
@@ -600,7 +492,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
600 c++; 492 c++;
601 } 493 }
602 494
603 if (port->write_urb) { 495 if (port->bulk_out_size) {
604 r = usb_serial_generic_write_start(port); 496 r = usb_serial_generic_write_start(port);
605 if (r < 0) 497 if (r < 0)
606 c++; 498 c++;
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 3ef8df0ef888..76e6fb3aab7a 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -3020,7 +3020,7 @@ static int edge_startup(struct usb_serial *serial)
3020 3020
3021 /* set up our port private structures */ 3021 /* set up our port private structures */
3022 for (i = 0; i < serial->num_ports; ++i) { 3022 for (i = 0; i < serial->num_ports; ++i) {
3023 edge_port = kmalloc(sizeof(struct edgeport_port), GFP_KERNEL); 3023 edge_port = kzalloc(sizeof(struct edgeport_port), GFP_KERNEL);
3024 if (edge_port == NULL) { 3024 if (edge_port == NULL) {
3025 dev_err(&serial->dev->dev, "%s - Out of memory\n", 3025 dev_err(&serial->dev->dev, "%s - Out of memory\n",
3026 __func__); 3026 __func__);
@@ -3033,7 +3033,6 @@ static int edge_startup(struct usb_serial *serial)
3033 kfree(edge_serial); 3033 kfree(edge_serial);
3034 return -ENOMEM; 3034 return -ENOMEM;
3035 } 3035 }
3036 memset(edge_port, 0, sizeof(struct edgeport_port));
3037 spin_lock_init(&edge_port->ep_lock); 3036 spin_lock_init(&edge_port->ep_lock);
3038 edge_port->port = serial->port[i]; 3037 edge_port->port = serial->port[i];
3039 usb_set_serial_port_data(serial->port[i], edge_port); 3038 usb_set_serial_port_data(serial->port[i], edge_port);
diff --git a/drivers/usb/serial/io_edgeport.h b/drivers/usb/serial/io_edgeport.h
index cb201c1f67f9..dced7ec65470 100644
--- a/drivers/usb/serial/io_edgeport.h
+++ b/drivers/usb/serial/io_edgeport.h
@@ -34,15 +34,15 @@
34 34
35 35
36 36
37/* The following table is used to map the USBx port number to 37/* The following table is used to map the USBx port number to
38 * the device serial number (or physical USB path), */ 38 * the device serial number (or physical USB path), */
39#define MAX_EDGEPORTS 64 39#define MAX_EDGEPORTS 64
40 40
41struct comMapper { 41struct comMapper {
42 char SerialNumber[MAX_SERIALNUMBER_LEN+1]; /* Serial number/usb path */ 42 char SerialNumber[MAX_SERIALNUMBER_LEN+1]; /* Serial number/usb path */
43 int numPorts; /* Number of ports */ 43 int numPorts; /* Number of ports */
44 int Original[MAX_RS232_PORTS]; /* Port numbers set by IOCTL */ 44 int Original[MAX_RS232_PORTS]; /* Port numbers set by IOCTL */
45 int Port[MAX_RS232_PORTS]; /* Actual used port numbers */ 45 int Port[MAX_RS232_PORTS]; /* Actual used port numbers */
46}; 46};
47 47
48 48
@@ -51,7 +51,7 @@ struct comMapper {
51/* /proc/edgeport Interface 51/* /proc/edgeport Interface
52 * This interface uses read/write/lseek interface to talk to the edgeport driver 52 * This interface uses read/write/lseek interface to talk to the edgeport driver
53 * the following read functions are supported: */ 53 * the following read functions are supported: */
54#define PROC_GET_MAPPING_TO_PATH 1 54#define PROC_GET_MAPPING_TO_PATH 1
55#define PROC_GET_COM_ENTRY 2 55#define PROC_GET_COM_ENTRY 2
56#define PROC_GET_EDGE_MANUF_DESCRIPTOR 3 56#define PROC_GET_EDGE_MANUF_DESCRIPTOR 3
57#define PROC_GET_BOOT_DESCRIPTOR 4 57#define PROC_GET_BOOT_DESCRIPTOR 4
@@ -64,7 +64,7 @@ struct comMapper {
64 64
65 65
66/* the following write functions are supported: */ 66/* the following write functions are supported: */
67#define PROC_SET_COM_MAPPING 1 67#define PROC_SET_COM_MAPPING 1
68#define PROC_SET_COM_ENTRY 2 68#define PROC_SET_COM_ENTRY 2
69 69
70 70
@@ -97,8 +97,8 @@ struct edgeport_product_info {
97 __u8 BoardRev; /* PCB revision level (chg only if s/w visible) */ 97 __u8 BoardRev; /* PCB revision level (chg only if s/w visible) */
98 98
99 __u8 BootMajorVersion; /* Boot Firmware version: xx. */ 99 __u8 BootMajorVersion; /* Boot Firmware version: xx. */
100 __u8 BootMinorVersion; /* yy. */ 100 __u8 BootMinorVersion; /* yy. */
101 __le16 BootBuildNumber; /* zzzz (LE format) */ 101 __le16 BootBuildNumber; /* zzzz (LE format) */
102 102
103 __u8 FirmwareMajorVersion; /* Operational Firmware version:xx. */ 103 __u8 FirmwareMajorVersion; /* Operational Firmware version:xx. */
104 __u8 FirmwareMinorVersion; /* yy. */ 104 __u8 FirmwareMinorVersion; /* yy. */
diff --git a/drivers/usb/serial/io_ionsp.h b/drivers/usb/serial/io_ionsp.h
index 092e03d2dfc4..5cc591bae54d 100644
--- a/drivers/usb/serial/io_ionsp.h
+++ b/drivers/usb/serial/io_ionsp.h
@@ -89,10 +89,10 @@ All 16-bit fields are sent in little-endian (Intel) format.
89// 89//
90 90
91struct int_status_pkt { 91struct int_status_pkt {
92 __u16 RxBytesAvail; // Additional bytes available to 92 __u16 RxBytesAvail; // Additional bytes available to
93 // be read from Bulk IN pipe 93 // be read from Bulk IN pipe
94 __u16 TxCredits[ MAX_RS232_PORTS ]; // Additional space available in 94 __u16 TxCredits[MAX_RS232_PORTS]; // Additional space available in
95 // given port's TxBuffer 95 // given port's TxBuffer
96}; 96};
97 97
98 98
@@ -115,24 +115,24 @@ struct int_status_pkt {
115#define IOSP_CMD_STAT_BIT 0x80 // If set, this is command/status header 115#define IOSP_CMD_STAT_BIT 0x80 // If set, this is command/status header
116 116
117#define IS_CMD_STAT_HDR(Byte1) ((Byte1) & IOSP_CMD_STAT_BIT) 117#define IS_CMD_STAT_HDR(Byte1) ((Byte1) & IOSP_CMD_STAT_BIT)
118#define IS_DATA_HDR(Byte1) (! IS_CMD_STAT_HDR(Byte1)) 118#define IS_DATA_HDR(Byte1) (!IS_CMD_STAT_HDR(Byte1))
119 119
120#define IOSP_GET_HDR_PORT(Byte1) ((__u8) ((Byte1) & IOSP_PORT_MASK)) 120#define IOSP_GET_HDR_PORT(Byte1) ((__u8) ((Byte1) & IOSP_PORT_MASK))
121#define IOSP_GET_HDR_DATA_LEN(Byte1, Byte2) ((__u16) ( ((__u16)((Byte1) & 0x78)) << 5) | (Byte2)) 121#define IOSP_GET_HDR_DATA_LEN(Byte1, Byte2) ((__u16) (((__u16)((Byte1) & 0x78)) << 5) | (Byte2))
122#define IOSP_GET_STATUS_CODE(Byte1) ((__u8) (((Byte1) & 0x78) >> 3)) 122#define IOSP_GET_STATUS_CODE(Byte1) ((__u8) (((Byte1) & 0x78) >> 3))
123 123
124 124
125// 125//
126// These macros build the 1st and 2nd bytes for a data header 126// These macros build the 1st and 2nd bytes for a data header
127// 127//
128#define IOSP_BUILD_DATA_HDR1(Port, Len) ((__u8) (((Port) | ((__u8) (((__u16) (Len)) >> 5) & 0x78 )))) 128#define IOSP_BUILD_DATA_HDR1(Port, Len) ((__u8) (((Port) | ((__u8) (((__u16) (Len)) >> 5) & 0x78))))
129#define IOSP_BUILD_DATA_HDR2(Port, Len) ((__u8) (Len)) 129#define IOSP_BUILD_DATA_HDR2(Port, Len) ((__u8) (Len))
130 130
131 131
132// 132//
133// These macros build the 1st and 2nd bytes for a command header 133// These macros build the 1st and 2nd bytes for a command header
134// 134//
135#define IOSP_BUILD_CMD_HDR1(Port, Cmd) ((__u8) ( IOSP_CMD_STAT_BIT | (Port) | ((__u8) ((Cmd) << 3)) )) 135#define IOSP_BUILD_CMD_HDR1(Port, Cmd) ((__u8) (IOSP_CMD_STAT_BIT | (Port) | ((__u8) ((Cmd) << 3))))
136 136
137 137
138//-------------------------------------------------------------- 138//--------------------------------------------------------------
@@ -194,24 +194,25 @@ struct int_status_pkt {
194// Define macros to simplify building of IOSP cmds 194// Define macros to simplify building of IOSP cmds
195// 195//
196 196
197#define MAKE_CMD_WRITE_REG(ppBuf, pLen, Port, Reg, Val) \ 197#define MAKE_CMD_WRITE_REG(ppBuf, pLen, Port, Reg, Val) \
198 do { \ 198do { \
199 (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1( (Port), IOSP_WRITE_UART_REG(Reg) ); \ 199 (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1((Port), \
200 (*(ppBuf))[1] = (Val); \ 200 IOSP_WRITE_UART_REG(Reg)); \
201 \ 201 (*(ppBuf))[1] = (Val); \
202 *ppBuf += 2; \ 202 \
203 *pLen += 2; \ 203 *ppBuf += 2; \
204 } while (0) 204 *pLen += 2; \
205} while (0)
205 206
206#define MAKE_CMD_EXT_CMD(ppBuf, pLen, Port, ExtCmd, Param) \ 207#define MAKE_CMD_EXT_CMD(ppBuf, pLen, Port, ExtCmd, Param) \
207 do { \ 208do { \
208 (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1( (Port), IOSP_EXT_CMD ); \ 209 (*(ppBuf))[0] = IOSP_BUILD_CMD_HDR1((Port), IOSP_EXT_CMD); \
209 (*(ppBuf))[1] = (ExtCmd); \ 210 (*(ppBuf))[1] = (ExtCmd); \
210 (*(ppBuf))[2] = (Param); \ 211 (*(ppBuf))[2] = (Param); \
211 \ 212 \
212 *ppBuf += 3; \ 213 *ppBuf += 3; \
213 *pLen += 3; \ 214 *pLen += 3; \
214 } while (0) 215} while (0)
215 216
216 217
217 218
@@ -310,16 +311,16 @@ struct int_status_pkt {
310// 311//
311// IOSP_CMD_RX_CHECK_REQ 312// IOSP_CMD_RX_CHECK_REQ
312// 313//
313// This command is used to assist in the implementation of the 314// This command is used to assist in the implementation of the
314// IOCTL_SERIAL_PURGE Windows IOCTL. 315// IOCTL_SERIAL_PURGE Windows IOCTL.
315// This IOSP command tries to place a marker at the end of the RX 316// This IOSP command tries to place a marker at the end of the RX
316// queue in the Edgeport. If the Edgeport RX queue is full then 317// queue in the Edgeport. If the Edgeport RX queue is full then
317// the Check will be discarded. 318// the Check will be discarded.
318// It is up to the device driver to timeout waiting for the 319// It is up to the device driver to timeout waiting for the
319// RX_CHECK_RSP. If a RX_CHECK_RSP is received, the driver is 320// RX_CHECK_RSP. If a RX_CHECK_RSP is received, the driver is
320// sure that all data has been received from the edgeport and 321// sure that all data has been received from the edgeport and
321// may now purge any internal RX buffers. 322// may now purge any internal RX buffers.
322// Note tat the sequence numbers may be used to detect lost 323// Note tat the sequence numbers may be used to detect lost
323// CHECK_REQs. 324// CHECK_REQs.
324 325
325// Example for Port 0 326// Example for Port 0
@@ -341,7 +342,7 @@ struct int_status_pkt {
341// 342//
342// 1ssssPPP P1P1P1P1 [ P2P2P2P2P2 ]... 343// 1ssssPPP P1P1P1P1 [ P2P2P2P2P2 ]...
343// 344//
344// ssss: 00-07 2-byte status. ssss identifies which UART register 345// ssss: 00-07 2-byte status. ssss identifies which UART register
345// has changed value, and the new value is in P1. 346// has changed value, and the new value is in P1.
346// Note that the ssss values do not correspond to the 347// Note that the ssss values do not correspond to the
347// 16554 register numbers given in 16554.H. Instead, 348// 16554 register numbers given in 16554.H. Instead,
@@ -383,14 +384,14 @@ struct int_status_pkt {
383// returns this in order to report 384// returns this in order to report
384// changes in modem status lines 385// changes in modem status lines
385// (CTS, DSR, RI, CD) 386// (CTS, DSR, RI, CD)
386// 387//
387 388
388// 0x02 // Available for future expansion 389// 0x02 // Available for future expansion
389// 0x03 // 390// 0x03 //
390// 0x04 // 391// 0x04 //
391// 0x05 // 392// 0x05 //
392// 0x06 // 393// 0x06 //
393// 0x07 // 394// 0x07 //
394 395
395 396
396/**************************************************** 397/****************************************************
@@ -400,7 +401,7 @@ struct int_status_pkt {
400#define IOSP_STATUS_LSR_DATA 0x08 // P1 is new value of LSR register (same as STATUS_LSR) 401#define IOSP_STATUS_LSR_DATA 0x08 // P1 is new value of LSR register (same as STATUS_LSR)
401 402
402// P2 is errored character read from 403// P2 is errored character read from
403// RxFIFO after LSR reported an error. 404// RxFIFO after LSR reported an error.
404 405
405#define IOSP_EXT_STATUS 0x09 // P1 is status/response code, param in P2. 406#define IOSP_EXT_STATUS 0x09 // P1 is status/response code, param in P2.
406 407
@@ -408,7 +409,7 @@ struct int_status_pkt {
408// Response Codes (P1 values) for 3-byte status messages 409// Response Codes (P1 values) for 3-byte status messages
409 410
410#define IOSP_EXT_STATUS_CHASE_RSP 0 // Reply to CHASE_PORT cmd. P2 is outcome: 411#define IOSP_EXT_STATUS_CHASE_RSP 0 // Reply to CHASE_PORT cmd. P2 is outcome:
411#define IOSP_EXT_STATUS_CHASE_PASS 0 // P2 = 0: All Tx data drained successfully 412#define IOSP_EXT_STATUS_CHASE_PASS 0 // P2 = 0: All Tx data drained successfully
412#define IOSP_EXT_STATUS_CHASE_FAIL 1 // P2 = 1: Timed out (stuck due to flow 413#define IOSP_EXT_STATUS_CHASE_FAIL 1 // P2 = 1: Timed out (stuck due to flow
413 414
414// control from remote device). 415// control from remote device).
@@ -446,9 +447,9 @@ struct int_status_pkt {
446// Macros to parse status messages 447// Macros to parse status messages
447// 448//
448 449
449#define IOSP_GET_STATUS_LEN(code) ( (code) < 8 ? 2 : ((code) < 0x0A ? 3 : 4) ) 450#define IOSP_GET_STATUS_LEN(code) ((code) < 8 ? 2 : ((code) < 0x0A ? 3 : 4))
450 451
451#define IOSP_STATUS_IS_2BYTE(code) ( (code) < 0x08 ) 452#define IOSP_STATUS_IS_2BYTE(code) ((code) < 0x08)
452#define IOSP_STATUS_IS_3BYTE(code) ( ((code) >= 0x08) && ((code) <= 0x0B) ) 453#define IOSP_STATUS_IS_3BYTE(code) (((code) >= 0x08) && ((code) <= 0x0B))
453#define IOSP_STATUS_IS_4BYTE(code) ( ((code) >= 0x0C) && ((code) <= 0x0D) ) 454#define IOSP_STATUS_IS_4BYTE(code) (((code) >= 0x0C) && ((code) <= 0x0D))
454 455
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index aa876f71f228..0fca2659206f 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -36,6 +36,7 @@
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38#include <linux/serial.h> 38#include <linux/serial.h>
39#include <linux/kfifo.h>
39#include <linux/ioctl.h> 40#include <linux/ioctl.h>
40#include <linux/firmware.h> 41#include <linux/firmware.h>
41#include <linux/uaccess.h> 42#include <linux/uaccess.h>
@@ -56,10 +57,6 @@
56#define EPROM_PAGE_SIZE 64 57#define EPROM_PAGE_SIZE 64
57 58
58 59
59struct edgeport_uart_buf_desc {
60 __u32 count; /* Number of bytes currently in buffer */
61};
62
63/* different hardware types */ 60/* different hardware types */
64#define HARDWARE_TYPE_930 0 61#define HARDWARE_TYPE_930 0
65#define HARDWARE_TYPE_TIUMP 1 62#define HARDWARE_TYPE_TIUMP 1
@@ -87,14 +84,6 @@ struct product_info {
87 __u8 hardware_type; /* Type of hardware */ 84 __u8 hardware_type; /* Type of hardware */
88} __attribute__((packed)); 85} __attribute__((packed));
89 86
90/* circular buffer */
91struct edge_buf {
92 unsigned int buf_size;
93 char *buf_buf;
94 char *buf_get;
95 char *buf_put;
96};
97
98struct edgeport_port { 87struct edgeport_port {
99 __u16 uart_base; 88 __u16 uart_base;
100 __u16 dma_address; 89 __u16 dma_address;
@@ -108,7 +97,6 @@ struct edgeport_port {
108 int baud_rate; 97 int baud_rate;
109 int close_pending; 98 int close_pending;
110 int lsr_event; 99 int lsr_event;
111 struct edgeport_uart_buf_desc tx;
112 struct async_icount icount; 100 struct async_icount icount;
113 wait_queue_head_t delta_msr_wait; /* for handling sleeping while 101 wait_queue_head_t delta_msr_wait; /* for handling sleeping while
114 waiting for msr change to 102 waiting for msr change to
@@ -119,7 +107,7 @@ struct edgeport_port {
119 spinlock_t ep_lock; 107 spinlock_t ep_lock;
120 int ep_read_urb_state; 108 int ep_read_urb_state;
121 int ep_write_urb_in_use; 109 int ep_write_urb_in_use;
122 struct edge_buf *ep_out_buf; 110 struct kfifo write_fifo;
123}; 111};
124 112
125struct edgeport_serial { 113struct edgeport_serial {
@@ -249,17 +237,6 @@ static void edge_send(struct tty_struct *tty);
249static int edge_create_sysfs_attrs(struct usb_serial_port *port); 237static int edge_create_sysfs_attrs(struct usb_serial_port *port);
250static int edge_remove_sysfs_attrs(struct usb_serial_port *port); 238static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
251 239
252/* circular buffer */
253static struct edge_buf *edge_buf_alloc(unsigned int size);
254static void edge_buf_free(struct edge_buf *eb);
255static void edge_buf_clear(struct edge_buf *eb);
256static unsigned int edge_buf_data_avail(struct edge_buf *eb);
257static unsigned int edge_buf_space_avail(struct edge_buf *eb);
258static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
259 unsigned int count);
260static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
261 unsigned int count);
262
263 240
264static int ti_vread_sync(struct usb_device *dev, __u8 request, 241static int ti_vread_sync(struct usb_device *dev, __u8 request,
265 __u16 value, __u16 index, u8 *data, int size) 242 __u16 value, __u16 index, u8 *data, int size)
@@ -590,7 +567,7 @@ static void chase_port(struct edgeport_port *port, unsigned long timeout,
590 add_wait_queue(&tty->write_wait, &wait); 567 add_wait_queue(&tty->write_wait, &wait);
591 for (;;) { 568 for (;;) {
592 set_current_state(TASK_INTERRUPTIBLE); 569 set_current_state(TASK_INTERRUPTIBLE);
593 if (edge_buf_data_avail(port->ep_out_buf) == 0 570 if (kfifo_len(&port->write_fifo) == 0
594 || timeout == 0 || signal_pending(current) 571 || timeout == 0 || signal_pending(current)
595 || !usb_get_intfdata(port->port->serial->interface)) 572 || !usb_get_intfdata(port->port->serial->interface))
596 /* disconnect */ 573 /* disconnect */
@@ -602,7 +579,7 @@ static void chase_port(struct edgeport_port *port, unsigned long timeout,
602 set_current_state(TASK_RUNNING); 579 set_current_state(TASK_RUNNING);
603 remove_wait_queue(&tty->write_wait, &wait); 580 remove_wait_queue(&tty->write_wait, &wait);
604 if (flush) 581 if (flush)
605 edge_buf_clear(port->ep_out_buf); 582 kfifo_reset_out(&port->write_fifo);
606 spin_unlock_irqrestore(&port->ep_lock, flags); 583 spin_unlock_irqrestore(&port->ep_lock, flags);
607 tty_kref_put(tty); 584 tty_kref_put(tty);
608 585
@@ -2089,7 +2066,6 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
2089 const unsigned char *data, int count) 2066 const unsigned char *data, int count)
2090{ 2067{
2091 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2068 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2092 unsigned long flags;
2093 2069
2094 dbg("%s - port %d", __func__, port->number); 2070 dbg("%s - port %d", __func__, port->number);
2095 2071
@@ -2103,10 +2079,8 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
2103 if (edge_port->close_pending == 1) 2079 if (edge_port->close_pending == 1)
2104 return -ENODEV; 2080 return -ENODEV;
2105 2081
2106 spin_lock_irqsave(&edge_port->ep_lock, flags); 2082 count = kfifo_in_locked(&edge_port->write_fifo, data, count,
2107 count = edge_buf_put(edge_port->ep_out_buf, data, count); 2083 &edge_port->ep_lock);
2108 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2109
2110 edge_send(tty); 2084 edge_send(tty);
2111 2085
2112 return count; 2086 return count;
@@ -2129,7 +2103,7 @@ static void edge_send(struct tty_struct *tty)
2129 return; 2103 return;
2130 } 2104 }
2131 2105
2132 count = edge_buf_get(edge_port->ep_out_buf, 2106 count = kfifo_out(&edge_port->write_fifo,
2133 port->write_urb->transfer_buffer, 2107 port->write_urb->transfer_buffer,
2134 port->bulk_out_size); 2108 port->bulk_out_size);
2135 2109
@@ -2185,7 +2159,7 @@ static int edge_write_room(struct tty_struct *tty)
2185 return 0; 2159 return 0;
2186 2160
2187 spin_lock_irqsave(&edge_port->ep_lock, flags); 2161 spin_lock_irqsave(&edge_port->ep_lock, flags);
2188 room = edge_buf_space_avail(edge_port->ep_out_buf); 2162 room = kfifo_avail(&edge_port->write_fifo);
2189 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2163 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2190 2164
2191 dbg("%s - returns %d", __func__, room); 2165 dbg("%s - returns %d", __func__, room);
@@ -2207,7 +2181,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty)
2207 return 0; 2181 return 0;
2208 2182
2209 spin_lock_irqsave(&edge_port->ep_lock, flags); 2183 spin_lock_irqsave(&edge_port->ep_lock, flags);
2210 chars = edge_buf_data_avail(edge_port->ep_out_buf); 2184 chars = kfifo_len(&edge_port->write_fifo);
2211 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2185 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
2212 2186
2213 dbg("%s - returns %d", __func__, chars); 2187 dbg("%s - returns %d", __func__, chars);
@@ -2664,8 +2638,8 @@ static int edge_startup(struct usb_serial *serial)
2664 goto cleanup; 2638 goto cleanup;
2665 } 2639 }
2666 spin_lock_init(&edge_port->ep_lock); 2640 spin_lock_init(&edge_port->ep_lock);
2667 edge_port->ep_out_buf = edge_buf_alloc(EDGE_OUT_BUF_SIZE); 2641 if (kfifo_alloc(&edge_port->write_fifo, EDGE_OUT_BUF_SIZE,
2668 if (edge_port->ep_out_buf == NULL) { 2642 GFP_KERNEL)) {
2669 dev_err(&serial->dev->dev, "%s - Out of memory\n", 2643 dev_err(&serial->dev->dev, "%s - Out of memory\n",
2670 __func__); 2644 __func__);
2671 kfree(edge_port); 2645 kfree(edge_port);
@@ -2682,7 +2656,7 @@ static int edge_startup(struct usb_serial *serial)
2682cleanup: 2656cleanup:
2683 for (--i; i >= 0; --i) { 2657 for (--i; i >= 0; --i) {
2684 edge_port = usb_get_serial_port_data(serial->port[i]); 2658 edge_port = usb_get_serial_port_data(serial->port[i]);
2685 edge_buf_free(edge_port->ep_out_buf); 2659 kfifo_free(&edge_port->write_fifo);
2686 kfree(edge_port); 2660 kfree(edge_port);
2687 usb_set_serial_port_data(serial->port[i], NULL); 2661 usb_set_serial_port_data(serial->port[i], NULL);
2688 } 2662 }
@@ -2713,7 +2687,7 @@ static void edge_release(struct usb_serial *serial)
2713 2687
2714 for (i = 0; i < serial->num_ports; ++i) { 2688 for (i = 0; i < serial->num_ports; ++i) {
2715 edge_port = usb_get_serial_port_data(serial->port[i]); 2689 edge_port = usb_get_serial_port_data(serial->port[i]);
2716 edge_buf_free(edge_port->ep_out_buf); 2690 kfifo_free(&edge_port->write_fifo);
2717 kfree(edge_port); 2691 kfree(edge_port);
2718 } 2692 }
2719 kfree(usb_get_serial_data(serial)); 2693 kfree(usb_get_serial_data(serial));
@@ -2763,182 +2737,6 @@ static int edge_remove_sysfs_attrs(struct usb_serial_port *port)
2763} 2737}
2764 2738
2765 2739
2766/* Circular Buffer */
2767
2768/*
2769 * edge_buf_alloc
2770 *
2771 * Allocate a circular buffer and all associated memory.
2772 */
2773
2774static struct edge_buf *edge_buf_alloc(unsigned int size)
2775{
2776 struct edge_buf *eb;
2777
2778
2779 if (size == 0)
2780 return NULL;
2781
2782 eb = kmalloc(sizeof(struct edge_buf), GFP_KERNEL);
2783 if (eb == NULL)
2784 return NULL;
2785
2786 eb->buf_buf = kmalloc(size, GFP_KERNEL);
2787 if (eb->buf_buf == NULL) {
2788 kfree(eb);
2789 return NULL;
2790 }
2791
2792 eb->buf_size = size;
2793 eb->buf_get = eb->buf_put = eb->buf_buf;
2794
2795 return eb;
2796}
2797
2798
2799/*
2800 * edge_buf_free
2801 *
2802 * Free the buffer and all associated memory.
2803 */
2804
2805static void edge_buf_free(struct edge_buf *eb)
2806{
2807 if (eb) {
2808 kfree(eb->buf_buf);
2809 kfree(eb);
2810 }
2811}
2812
2813
2814/*
2815 * edge_buf_clear
2816 *
2817 * Clear out all data in the circular buffer.
2818 */
2819
2820static void edge_buf_clear(struct edge_buf *eb)
2821{
2822 if (eb != NULL)
2823 eb->buf_get = eb->buf_put;
2824 /* equivalent to a get of all data available */
2825}
2826
2827
2828/*
2829 * edge_buf_data_avail
2830 *
2831 * Return the number of bytes of data available in the circular
2832 * buffer.
2833 */
2834
2835static unsigned int edge_buf_data_avail(struct edge_buf *eb)
2836{
2837 if (eb == NULL)
2838 return 0;
2839 return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
2840}
2841
2842
2843/*
2844 * edge_buf_space_avail
2845 *
2846 * Return the number of bytes of space available in the circular
2847 * buffer.
2848 */
2849
2850static unsigned int edge_buf_space_avail(struct edge_buf *eb)
2851{
2852 if (eb == NULL)
2853 return 0;
2854 return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
2855}
2856
2857
2858/*
2859 * edge_buf_put
2860 *
2861 * Copy data data from a user buffer and put it into the circular buffer.
2862 * Restrict to the amount of space available.
2863 *
2864 * Return the number of bytes copied.
2865 */
2866
2867static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
2868 unsigned int count)
2869{
2870 unsigned int len;
2871
2872
2873 if (eb == NULL)
2874 return 0;
2875
2876 len = edge_buf_space_avail(eb);
2877 if (count > len)
2878 count = len;
2879
2880 if (count == 0)
2881 return 0;
2882
2883 len = eb->buf_buf + eb->buf_size - eb->buf_put;
2884 if (count > len) {
2885 memcpy(eb->buf_put, buf, len);
2886 memcpy(eb->buf_buf, buf+len, count - len);
2887 eb->buf_put = eb->buf_buf + count - len;
2888 } else {
2889 memcpy(eb->buf_put, buf, count);
2890 if (count < len)
2891 eb->buf_put += count;
2892 else /* count == len */
2893 eb->buf_put = eb->buf_buf;
2894 }
2895
2896 return count;
2897}
2898
2899
2900/*
2901 * edge_buf_get
2902 *
2903 * Get data from the circular buffer and copy to the given buffer.
2904 * Restrict to the amount of data available.
2905 *
2906 * Return the number of bytes copied.
2907 */
2908
2909static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
2910 unsigned int count)
2911{
2912 unsigned int len;
2913
2914
2915 if (eb == NULL)
2916 return 0;
2917
2918 len = edge_buf_data_avail(eb);
2919 if (count > len)
2920 count = len;
2921
2922 if (count == 0)
2923 return 0;
2924
2925 len = eb->buf_buf + eb->buf_size - eb->buf_get;
2926 if (count > len) {
2927 memcpy(buf, eb->buf_get, len);
2928 memcpy(buf+len, eb->buf_buf, count - len);
2929 eb->buf_get = eb->buf_buf + count - len;
2930 } else {
2931 memcpy(buf, eb->buf_get, count);
2932 if (count < len)
2933 eb->buf_get += count;
2934 else /* count == len */
2935 eb->buf_get = eb->buf_buf;
2936 }
2937
2938 return count;
2939}
2940
2941
2942static struct usb_serial_driver edgeport_1port_device = { 2740static struct usb_serial_driver edgeport_1port_device = {
2943 .driver = { 2741 .driver = {
2944 .owner = THIS_MODULE, 2742 .owner = THIS_MODULE,
diff --git a/drivers/usb/serial/io_ti.h b/drivers/usb/serial/io_ti.h
index cab84f2256b9..1bd67b24f916 100644
--- a/drivers/usb/serial/io_ti.h
+++ b/drivers/usb/serial/io_ti.h
@@ -1,4 +1,4 @@
1/***************************************************************************** 1/*****************************************************************************
2 * 2 *
3 * Copyright (C) 1997-2002 Inside Out Networks, Inc. 3 * Copyright (C) 1997-2002 Inside Out Networks, Inc.
4 * 4 *
@@ -22,10 +22,10 @@
22#define DTK_ADDR_SPACE_I2C_TYPE_II 0x82 /* Addr is placed in I2C area */ 22#define DTK_ADDR_SPACE_I2C_TYPE_II 0x82 /* Addr is placed in I2C area */
23#define DTK_ADDR_SPACE_I2C_TYPE_III 0x83 /* Addr is placed in I2C area */ 23#define DTK_ADDR_SPACE_I2C_TYPE_III 0x83 /* Addr is placed in I2C area */
24 24
25// UART Defines 25/* UART Defines */
26#define UMPMEM_BASE_UART1 0xFFA0 /* UMP UART1 base address */ 26#define UMPMEM_BASE_UART1 0xFFA0 /* UMP UART1 base address */
27#define UMPMEM_BASE_UART2 0xFFB0 /* UMP UART2 base address */ 27#define UMPMEM_BASE_UART2 0xFFB0 /* UMP UART2 base address */
28#define UMPMEM_OFFS_UART_LSR 0x05 /* UMP UART LSR register offset */ 28#define UMPMEM_OFFS_UART_LSR 0x05 /* UMP UART LSR register offset */
29 29
30/* Bits per character */ 30/* Bits per character */
31#define UMP_UART_CHAR5BITS 0x00 31#define UMP_UART_CHAR5BITS 0x00
@@ -54,7 +54,7 @@
54#define UMP_UART_LSR_RX_MASK 0x10 54#define UMP_UART_LSR_RX_MASK 0x10
55#define UMP_UART_LSR_TX_MASK 0x20 55#define UMP_UART_LSR_TX_MASK 0x20
56 56
57#define UMP_UART_LSR_DATA_MASK ( LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK ) 57#define UMP_UART_LSR_DATA_MASK (LSR_PAR_ERR | LSR_FRM_ERR | LSR_BREAK)
58 58
59/* Port Settings Constants) */ 59/* Port Settings Constants) */
60#define UMP_MASK_UART_FLAGS_RTS_FLOW 0x0001 60#define UMP_MASK_UART_FLAGS_RTS_FLOW 0x0001
@@ -79,50 +79,57 @@
79#define UMP_PORT_DIR_OUT 0x01 79#define UMP_PORT_DIR_OUT 0x01
80#define UMP_PORT_DIR_IN 0x02 80#define UMP_PORT_DIR_IN 0x02
81 81
82// Address of Port 0 82/* Address of Port 0 */
83#define UMPM_UART1_PORT 0x03 83#define UMPM_UART1_PORT 0x03
84 84
85// Commands 85/* Commands */
86#define UMPC_SET_CONFIG 0x05 86#define UMPC_SET_CONFIG 0x05
87#define UMPC_OPEN_PORT 0x06 87#define UMPC_OPEN_PORT 0x06
88#define UMPC_CLOSE_PORT 0x07 88#define UMPC_CLOSE_PORT 0x07
89#define UMPC_START_PORT 0x08 89#define UMPC_START_PORT 0x08
90#define UMPC_STOP_PORT 0x09 90#define UMPC_STOP_PORT 0x09
91#define UMPC_TEST_PORT 0x0A 91#define UMPC_TEST_PORT 0x0A
92#define UMPC_PURGE_PORT 0x0B 92#define UMPC_PURGE_PORT 0x0B
93 93
94#define UMPC_COMPLETE_READ 0x80 // Force the Firmware to complete the current Read 94/* Force the Firmware to complete the current Read */
95#define UMPC_HARDWARE_RESET 0x81 // Force UMP back into BOOT Mode 95#define UMPC_COMPLETE_READ 0x80
96#define UMPC_COPY_DNLD_TO_I2C 0x82 // Copy current download image to type 0xf2 record in 16k I2C 96/* Force UMP back into BOOT Mode */
97 // firmware will change 0xff record to type 2 record when complete 97#define UMPC_HARDWARE_RESET 0x81
98/*
99 * Copy current download image to type 0xf2 record in 16k I2C
100 * firmware will change 0xff record to type 2 record when complete
101 */
102#define UMPC_COPY_DNLD_TO_I2C 0x82
98 103
99 // Special function register commands 104/*
100 // wIndex is register address 105 * Special function register commands
101 // wValue is MSB/LSB mask/data 106 * wIndex is register address
102#define UMPC_WRITE_SFR 0x83 // Write SFR Register 107 * wValue is MSB/LSB mask/data
108 */
109#define UMPC_WRITE_SFR 0x83 /* Write SFR Register */
103 110
104 // wIndex is register address 111/* wIndex is register address */
105#define UMPC_READ_SFR 0x84 // Read SRF Register 112#define UMPC_READ_SFR 0x84 /* Read SRF Register */
106 113
107 // Set or Clear DTR (wValue bit 0 Set/Clear) wIndex ModuleID (port) 114/* Set or Clear DTR (wValue bit 0 Set/Clear) wIndex ModuleID (port) */
108#define UMPC_SET_CLR_DTR 0x85 115#define UMPC_SET_CLR_DTR 0x85
109 116
110 // Set or Clear RTS (wValue bit 0 Set/Clear) wIndex ModuleID (port) 117/* Set or Clear RTS (wValue bit 0 Set/Clear) wIndex ModuleID (port) */
111#define UMPC_SET_CLR_RTS 0x86 118#define UMPC_SET_CLR_RTS 0x86
112 119
113 // Set or Clear LOOPBACK (wValue bit 0 Set/Clear) wIndex ModuleID (port) 120/* Set or Clear LOOPBACK (wValue bit 0 Set/Clear) wIndex ModuleID (port) */
114#define UMPC_SET_CLR_LOOPBACK 0x87 121#define UMPC_SET_CLR_LOOPBACK 0x87
115 122
116 // Set or Clear BREAK (wValue bit 0 Set/Clear) wIndex ModuleID (port) 123/* Set or Clear BREAK (wValue bit 0 Set/Clear) wIndex ModuleID (port) */
117#define UMPC_SET_CLR_BREAK 0x88 124#define UMPC_SET_CLR_BREAK 0x88
118 125
119 // Read MSR wIndex ModuleID (port) 126/* Read MSR wIndex ModuleID (port) */
120#define UMPC_READ_MSR 0x89 127#define UMPC_READ_MSR 0x89
121 128
122 /* Toolkit commands */ 129/* Toolkit commands */
123 /* Read-write group */ 130/* Read-write group */
124#define UMPC_MEMORY_READ 0x92 131#define UMPC_MEMORY_READ 0x92
125#define UMPC_MEMORY_WRITE 0x93 132#define UMPC_MEMORY_WRITE 0x93
126 133
127/* 134/*
128 * UMP DMA Definitions 135 * UMP DMA Definitions
@@ -130,8 +137,7 @@
130#define UMPD_OEDB1_ADDRESS 0xFF08 137#define UMPD_OEDB1_ADDRESS 0xFF08
131#define UMPD_OEDB2_ADDRESS 0xFF10 138#define UMPD_OEDB2_ADDRESS 0xFF10
132 139
133struct out_endpoint_desc_block 140struct out_endpoint_desc_block {
134{
135 __u8 Configuration; 141 __u8 Configuration;
136 __u8 XBufAddr; 142 __u8 XBufAddr;
137 __u8 XByteCount; 143 __u8 XByteCount;
@@ -147,8 +153,8 @@ struct out_endpoint_desc_block
147 * TYPE DEFINITIONS 153 * TYPE DEFINITIONS
148 * Structures for Firmware commands 154 * Structures for Firmware commands
149 */ 155 */
150struct ump_uart_config /* UART settings */ 156/* UART settings */
151{ 157struct ump_uart_config {
152 __u16 wBaudRate; /* Baud rate */ 158 __u16 wBaudRate; /* Baud rate */
153 __u16 wFlags; /* Bitmap mask of flags */ 159 __u16 wFlags; /* Bitmap mask of flags */
154 __u8 bDataBits; /* 5..8 - data bits per character */ 160 __u8 bDataBits; /* 5..8 - data bits per character */
@@ -165,8 +171,8 @@ struct ump_uart_config /* UART settings */
165 * TYPE DEFINITIONS 171 * TYPE DEFINITIONS
166 * Structures for USB interrupts 172 * Structures for USB interrupts
167 */ 173 */
168struct ump_interrupt /* Interrupt packet structure */ 174/* Interrupt packet structure */
169{ 175struct ump_interrupt {
170 __u8 bICode; /* Interrupt code (interrupt num) */ 176 __u8 bICode; /* Interrupt code (interrupt num) */
171 __u8 bIInfo; /* Interrupt information */ 177 __u8 bIInfo; /* Interrupt information */
172} __attribute__((packed)); 178} __attribute__((packed));
diff --git a/drivers/usb/serial/io_usbvend.h b/drivers/usb/serial/io_usbvend.h
index 8e1a491e52a9..51f83fbb73bb 100644
--- a/drivers/usb/serial/io_usbvend.h
+++ b/drivers/usb/serial/io_usbvend.h
@@ -26,7 +26,7 @@
26 26
27// 27//
28// Definitions of USB product IDs 28// Definitions of USB product IDs
29// 29//
30 30
31#define USB_VENDOR_ID_ION 0x1608 // Our VID 31#define USB_VENDOR_ID_ION 0x1608 // Our VID
32#define USB_VENDOR_ID_TI 0x0451 // TI VID 32#define USB_VENDOR_ID_TI 0x0451 // TI VID
@@ -54,7 +54,7 @@
54// Product IDs - assigned to match middle digit of serial number (No longer true) 54// Product IDs - assigned to match middle digit of serial number (No longer true)
55 55
56#define ION_DEVICE_ID_80251_NETCHIP 0x020 // This bit is set in the PID if this edgeport hardware$ 56#define ION_DEVICE_ID_80251_NETCHIP 0x020 // This bit is set in the PID if this edgeport hardware$
57 // is based on the 80251+Netchip. 57 // is based on the 80251+Netchip.
58 58
59#define ION_DEVICE_ID_GENERATION_1 0x00 // Value for 930 based edgeports 59#define ION_DEVICE_ID_GENERATION_1 0x00 // Value for 930 based edgeports
60#define ION_DEVICE_ID_GENERATION_2 0x01 // Value for 80251+Netchip. 60#define ION_DEVICE_ID_GENERATION_2 0x01 // Value for 80251+Netchip.
@@ -134,7 +134,7 @@
134#define ION_DEVICE_ID_TI_EDGEPORT_416 0x0212 // Edgeport/416 134#define ION_DEVICE_ID_TI_EDGEPORT_416 0x0212 // Edgeport/416
135#define ION_DEVICE_ID_TI_EDGEPORT_1 0x0215 // Edgeport/1 RS232 135#define ION_DEVICE_ID_TI_EDGEPORT_1 0x0215 // Edgeport/1 RS232
136#define ION_DEVICE_ID_TI_EDGEPORT_42 0x0217 // Edgeport/42 4 hub 2 RS232 136#define ION_DEVICE_ID_TI_EDGEPORT_42 0x0217 // Edgeport/42 4 hub 2 RS232
137#define ION_DEVICE_ID_TI_EDGEPORT_22I 0x021A // Edgeport/22I is an Edgeport/4 with ports 1&2 RS422 and ports 3&4 RS232 137#define ION_DEVICE_ID_TI_EDGEPORT_22I 0x021A // Edgeport/22I is an Edgeport/4 with ports 1&2 RS422 and ports 3&4 RS232
138#define ION_DEVICE_ID_TI_EDGEPORT_2C 0x021B // Edgeport/2c RS232 138#define ION_DEVICE_ID_TI_EDGEPORT_2C 0x021B // Edgeport/2c RS232
139#define ION_DEVICE_ID_TI_EDGEPORT_221C 0x021C // Edgeport/221c is a TI based Edgeport/2 with lucent chip and 139#define ION_DEVICE_ID_TI_EDGEPORT_221C 0x021C // Edgeport/221c is a TI based Edgeport/2 with lucent chip and
140 // 2 external hub ports - Large I2C 140 // 2 external hub ports - Large I2C
@@ -142,7 +142,7 @@
142 // 2 external hub ports - Large I2C 142 // 2 external hub ports - Large I2C
143#define ION_DEVICE_ID_TI_EDGEPORT_21C 0x021E // Edgeport/21c is a TI based Edgeport/2 with lucent chip 143#define ION_DEVICE_ID_TI_EDGEPORT_21C 0x021E // Edgeport/21c is a TI based Edgeport/2 with lucent chip
144 144
145// Generation 3 devices -- 3410 based edgport/1 (256 byte I2C) 145// Generation 3 devices -- 3410 based edgport/1 (256 byte I2C)
146#define ION_DEVICE_ID_TI_TI3410_EDGEPORT_1 0x0240 // Edgeport/1 RS232 146#define ION_DEVICE_ID_TI_TI3410_EDGEPORT_1 0x0240 // Edgeport/1 RS232
147#define ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I 0x0241 // Edgeport/1i- RS422 model 147#define ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I 0x0241 // Edgeport/1i- RS422 model
148 148
@@ -176,7 +176,7 @@
176 // Default to /P function 176 // Default to /P function
177 177
178#define ION_DEVICE_ID_PLUS_PWR_HP4CD 0x30C // 5052 Plus Power HubPort/4CD+ (for Dell) 178#define ION_DEVICE_ID_PLUS_PWR_HP4CD 0x30C // 5052 Plus Power HubPort/4CD+ (for Dell)
179#define ION_DEVICE_ID_PLUS_PWR_HP4C 0x30D // 5052 Plus Power HubPort/4C+ 179#define ION_DEVICE_ID_PLUS_PWR_HP4C 0x30D // 5052 Plus Power HubPort/4C+
180#define ION_DEVICE_ID_PLUS_PWR_PCI 0x30E // 3410 Plus Power PCI Host Controller 4 port 180#define ION_DEVICE_ID_PLUS_PWR_PCI 0x30E // 3410 Plus Power PCI Host Controller 4 port
181 181
182 182
@@ -217,17 +217,17 @@
217#define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device 217#define ION_DEVICE_ID_MT4X56USB 0x1403 // OEM device
218 218
219 219
220#define GENERATION_ID_FROM_USB_PRODUCT_ID( ProductId ) \ 220#define GENERATION_ID_FROM_USB_PRODUCT_ID(ProductId) \
221 ( (__u16) ((ProductId >> 8) & (ION_GENERATION_MASK)) ) 221 ((__u16) ((ProductId >> 8) & (ION_GENERATION_MASK)))
222 222
223#define MAKE_USB_PRODUCT_ID( OemId, DeviceId ) \ 223#define MAKE_USB_PRODUCT_ID(OemId, DeviceId) \
224 ( (__u16) (((OemId) << 10) || (DeviceId)) ) 224 ((__u16) (((OemId) << 10) || (DeviceId)))
225 225
226#define DEVICE_ID_FROM_USB_PRODUCT_ID( ProductId ) \ 226#define DEVICE_ID_FROM_USB_PRODUCT_ID(ProductId) \
227 ( (__u16) ((ProductId) & (EDGEPORT_DEVICE_ID_MASK)) ) 227 ((__u16) ((ProductId) & (EDGEPORT_DEVICE_ID_MASK)))
228 228
229#define OEM_ID_FROM_USB_PRODUCT_ID( ProductId ) \ 229#define OEM_ID_FROM_USB_PRODUCT_ID(ProductId) \
230 ( (__u16) (((ProductId) >> 10) & 0x3F) ) 230 ((__u16) (((ProductId) >> 10) & 0x3F))
231 231
232// 232//
233// Definitions of parameters for download code. Note that these are 233// Definitions of parameters for download code. Note that these are
@@ -237,7 +237,7 @@
237 237
238// TxCredits value below which driver won't bother sending (to prevent too many small writes). 238// TxCredits value below which driver won't bother sending (to prevent too many small writes).
239// Send only if above 25% 239// Send only if above 25%
240#define EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(InitialCredit, MaxPacketSize) (max( ((InitialCredit) / 4), (MaxPacketSize) )) 240#define EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(InitialCredit, MaxPacketSize) (max(((InitialCredit) / 4), (MaxPacketSize)))
241 241
242#define EDGE_FW_BULK_MAX_PACKET_SIZE 64 // Max Packet Size for Bulk In Endpoint (EP1) 242#define EDGE_FW_BULK_MAX_PACKET_SIZE 64 // Max Packet Size for Bulk In Endpoint (EP1)
243#define EDGE_FW_BULK_READ_BUFFER_SIZE 1024 // Size to use for Bulk reads 243#define EDGE_FW_BULK_READ_BUFFER_SIZE 1024 // Size to use for Bulk reads
@@ -263,7 +263,7 @@
263// wValue = 16-bit address 263// wValue = 16-bit address
264// wIndex = unused (though we could put segment 00: or FF: here) 264// wIndex = unused (though we could put segment 00: or FF: here)
265// wLength = # bytes to read/write (max 64) 265// wLength = # bytes to read/write (max 64)
266// 266//
267 267
268#define USB_REQUEST_ION_RESET_DEVICE 0 // Warm reboot Edgeport, retaining USB address 268#define USB_REQUEST_ION_RESET_DEVICE 0 // Warm reboot Edgeport, retaining USB address
269#define USB_REQUEST_ION_GET_EPIC_DESC 1 // Get Edgeport Compatibility Descriptor 269#define USB_REQUEST_ION_GET_EPIC_DESC 1 // Get Edgeport Compatibility Descriptor
@@ -278,7 +278,7 @@
278#define USB_REQUEST_ION_ENABLE_SUSPEND 9 // Enable/Disable suspend feature 278#define USB_REQUEST_ION_ENABLE_SUSPEND 9 // Enable/Disable suspend feature
279 // (wValue != 0: Enable; wValue = 0: Disable) 279 // (wValue != 0: Enable; wValue = 0: Disable)
280 280
281#define USB_REQUEST_ION_SEND_IOSP 10 // Send an IOSP command to the edgeport over the control pipe 281#define USB_REQUEST_ION_SEND_IOSP 10 // Send an IOSP command to the edgeport over the control pipe
282#define USB_REQUEST_ION_RECV_IOSP 11 // Receive an IOSP command from the edgeport over the control pipe 282#define USB_REQUEST_ION_RECV_IOSP 11 // Receive an IOSP command from the edgeport over the control pipe
283 283
284 284
@@ -301,8 +301,7 @@
301// this is a "real" Edgeport. 301// this is a "real" Edgeport.
302// 302//
303 303
304struct edge_compatibility_bits 304struct edge_compatibility_bits {
305{
306 // This __u32 defines which Vendor-specific commands/functionality 305 // This __u32 defines which Vendor-specific commands/functionality
307 // the device supports on the default EP0 pipe. 306 // the device supports on the default EP0 pipe.
308 307
@@ -334,24 +333,22 @@ struct edge_compatibility_bits
334 __u32 TrueEdgeport : 1; // 0001 Set if device is a 'real' Edgeport 333 __u32 TrueEdgeport : 1; // 0001 Set if device is a 'real' Edgeport
335 // (Used only by driver, NEVER set by an EPiC device) 334 // (Used only by driver, NEVER set by an EPiC device)
336 __u32 GenUnused : 31; // Available for future expansion, must be 0 335 __u32 GenUnused : 31; // Available for future expansion, must be 0
337
338}; 336};
339 337
340#define EDGE_COMPATIBILITY_MASK0 0x0001 338#define EDGE_COMPATIBILITY_MASK0 0x0001
341#define EDGE_COMPATIBILITY_MASK1 0x3FFF 339#define EDGE_COMPATIBILITY_MASK1 0x3FFF
342#define EDGE_COMPATIBILITY_MASK2 0x0001 340#define EDGE_COMPATIBILITY_MASK2 0x0001
343 341
344struct edge_compatibility_descriptor 342struct edge_compatibility_descriptor {
345{
346 __u8 Length; // Descriptor Length (per USB spec) 343 __u8 Length; // Descriptor Length (per USB spec)
347 __u8 DescType; // Descriptor Type (per USB spec, =DEVICE type) 344 __u8 DescType; // Descriptor Type (per USB spec, =DEVICE type)
348 __u8 EpicVer; // Version of EPiC spec supported 345 __u8 EpicVer; // Version of EPiC spec supported
349 // (Currently must be 1) 346 // (Currently must be 1)
350 __u8 NumPorts; // Number of serial ports supported 347 __u8 NumPorts; // Number of serial ports supported
351 __u8 iDownloadFile; // Index of string containing download code filename 348 __u8 iDownloadFile; // Index of string containing download code filename
352 // 0=no download, FF=download compiled into driver. 349 // 0=no download, FF=download compiled into driver.
353 __u8 Unused[ 3 ]; // Available for future expansion, must be 0 350 __u8 Unused[3]; // Available for future expansion, must be 0
354 // (Currently must be 0). 351 // (Currently must be 0).
355 __u8 MajorVersion; // Firmware version: xx. 352 __u8 MajorVersion; // Firmware version: xx.
356 __u8 MinorVersion; // yy. 353 __u8 MinorVersion; // yy.
357 __le16 BuildNumber; // zzzz (LE format) 354 __le16 BuildNumber; // zzzz (LE format)
@@ -359,9 +356,7 @@ struct edge_compatibility_descriptor
359 // The following structure contains __u32s, with each bit 356 // The following structure contains __u32s, with each bit
360 // specifying whether the EPiC device supports the given 357 // specifying whether the EPiC device supports the given
361 // command or functionality. 358 // command or functionality.
362
363 struct edge_compatibility_bits Supports; 359 struct edge_compatibility_bits Supports;
364
365}; 360};
366 361
367// Values for iDownloadFile 362// Values for iDownloadFile
@@ -391,8 +386,8 @@ struct edge_compatibility_descriptor
391 386
392// Define the max block size that may be read or written 387// Define the max block size that may be read or written
393// in a read/write RAM/ROM command. 388// in a read/write RAM/ROM command.
394#define MAX_SIZE_REQ_ION_READ_MEM ( (__u16) 64 ) 389#define MAX_SIZE_REQ_ION_READ_MEM ((__u16)64)
395#define MAX_SIZE_REQ_ION_WRITE_MEM ( (__u16) 64 ) 390#define MAX_SIZE_REQ_ION_WRITE_MEM ((__u16)64)
396 391
397 392
398// 393//
@@ -545,7 +540,7 @@ struct edge_boot_descriptor {
545 __u8 MajorVersion; // C6 Firmware version: xx. 540 __u8 MajorVersion; // C6 Firmware version: xx.
546 __u8 MinorVersion; // C7 yy. 541 __u8 MinorVersion; // C7 yy.
547 __le16 BuildNumber; // C8 zzzz (LE format) 542 __le16 BuildNumber; // C8 zzzz (LE format)
548 543
549 __u16 EnumRootDescTable; // CA Root of ROM-based descriptor table 544 __u16 EnumRootDescTable; // CA Root of ROM-based descriptor table
550 __u8 NumDescTypes; // CC Number of supported descriptor types 545 __u8 NumDescTypes; // CC Number of supported descriptor types
551 546
@@ -597,41 +592,36 @@ struct edge_boot_descriptor {
597#define I2C_DESC_TYPE_ION 0 // Not defined by TI 592#define I2C_DESC_TYPE_ION 0 // Not defined by TI
598 593
599 594
600struct ti_i2c_desc 595struct ti_i2c_desc {
601{
602 __u8 Type; // Type of descriptor 596 __u8 Type; // Type of descriptor
603 __u16 Size; // Size of data only not including header 597 __u16 Size; // Size of data only not including header
604 __u8 CheckSum; // Checksum (8 bit sum of data only) 598 __u8 CheckSum; // Checksum (8 bit sum of data only)
605 __u8 Data[0]; // Data starts here 599 __u8 Data[0]; // Data starts here
606}__attribute__((packed)); 600} __attribute__((packed));
607 601
608// for 5152 devices only (type 2 record) 602// for 5152 devices only (type 2 record)
609// for 3410 the version is stored in the WATCHPORT_FIRMWARE_VERSION descriptor 603// for 3410 the version is stored in the WATCHPORT_FIRMWARE_VERSION descriptor
610struct ti_i2c_firmware_rec 604struct ti_i2c_firmware_rec {
611{
612 __u8 Ver_Major; // Firmware Major version number 605 __u8 Ver_Major; // Firmware Major version number
613 __u8 Ver_Minor; // Firmware Minor version number 606 __u8 Ver_Minor; // Firmware Minor version number
614 __u8 Data[0]; // Download starts here 607 __u8 Data[0]; // Download starts here
615}__attribute__((packed)); 608} __attribute__((packed));
616 609
617 610
618struct watchport_firmware_version 611struct watchport_firmware_version {
619{
620// Added 2 bytes for version number 612// Added 2 bytes for version number
621 __u8 Version_Major; // Download Version (for Watchport) 613 __u8 Version_Major; // Download Version (for Watchport)
622 __u8 Version_Minor; 614 __u8 Version_Minor;
623}__attribute__((packed)); 615} __attribute__((packed));
624 616
625 617
626// Structure of header of download image in fw_down.h 618// Structure of header of download image in fw_down.h
627struct ti_i2c_image_header 619struct ti_i2c_image_header {
628{
629 __le16 Length; 620 __le16 Length;
630 __u8 CheckSum; 621 __u8 CheckSum;
631}__attribute__((packed)); 622} __attribute__((packed));
632 623
633struct ti_basic_descriptor 624struct ti_basic_descriptor {
634{
635 __u8 Power; // Self powered 625 __u8 Power; // Self powered
636 // bit 7: 1 - power switching supported 626 // bit 7: 1 - power switching supported
637 // 0 - power switching not supported 627 // 0 - power switching not supported
@@ -663,9 +653,9 @@ struct ti_basic_descriptor
663#define TI_I2C_SIZE_MASK 0x1f // 5 bits 653#define TI_I2C_SIZE_MASK 0x1f // 5 bits
664#define TI_GET_I2C_SIZE(x) ((((x) & TI_I2C_SIZE_MASK)+1)*256) 654#define TI_GET_I2C_SIZE(x) ((((x) & TI_I2C_SIZE_MASK)+1)*256)
665 655
666#define TI_MAX_I2C_SIZE ( 16 * 1024 ) 656#define TI_MAX_I2C_SIZE (16 * 1024)
667 657
668#define TI_MANUF_VERSION_0 0 658#define TI_MANUF_VERSION_0 0
669 659
670// IonConig2 flags 660// IonConig2 flags
671#define TI_CONFIG2_RS232 0x01 661#define TI_CONFIG2_RS232 0x01
@@ -676,8 +666,7 @@ struct ti_basic_descriptor
676#define TI_CONFIG2_WATCHPORT 0x10 666#define TI_CONFIG2_WATCHPORT 0x10
677 667
678 668
679struct edge_ti_manuf_descriptor 669struct edge_ti_manuf_descriptor {
680{
681 __u8 IonConfig; // Config byte for ION manufacturing use 670 __u8 IonConfig; // Config byte for ION manufacturing use
682 __u8 IonConfig2; // Expansion 671 __u8 IonConfig2; // Expansion
683 __u8 Version; // Version 672 __u8 Version; // Version
@@ -688,7 +677,7 @@ struct edge_ti_manuf_descriptor
688 __u8 HubConfig2; // Used to configure the Hub 677 __u8 HubConfig2; // Used to configure the Hub
689 __u8 TotalPorts; // Total Number of Com Ports for the entire device (All UMPs) 678 __u8 TotalPorts; // Total Number of Com Ports for the entire device (All UMPs)
690 __u8 Reserved; // Reserved 679 __u8 Reserved; // Reserved
691}__attribute__((packed)); 680} __attribute__((packed));
692 681
693 682
694#endif // if !defined(_USBVEND_H) 683#endif // if !defined(_USBVEND_H)
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 3fea9298eb15..28913fa95fb7 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -56,7 +56,6 @@
56#include <linux/uaccess.h> 56#include <linux/uaccess.h>
57#include <linux/usb.h> 57#include <linux/usb.h>
58#include <linux/usb/serial.h> 58#include <linux/usb/serial.h>
59#include "ipaq.h"
60 59
61#define KP_RETRIES 100 60#define KP_RETRIES 100
62 61
@@ -64,7 +63,7 @@
64 * Version Information 63 * Version Information
65 */ 64 */
66 65
67#define DRIVER_VERSION "v0.5" 66#define DRIVER_VERSION "v1.0"
68#define DRIVER_AUTHOR "Ganesh Varadarajan <ganesh@veritas.com>" 67#define DRIVER_AUTHOR "Ganesh Varadarajan <ganesh@veritas.com>"
69#define DRIVER_DESC "USB PocketPC PDA driver" 68#define DRIVER_DESC "USB PocketPC PDA driver"
70 69
@@ -76,20 +75,8 @@ static int initial_wait;
76/* Function prototypes for an ipaq */ 75/* Function prototypes for an ipaq */
77static int ipaq_open(struct tty_struct *tty, 76static int ipaq_open(struct tty_struct *tty,
78 struct usb_serial_port *port); 77 struct usb_serial_port *port);
79static void ipaq_close(struct usb_serial_port *port);
80static int ipaq_calc_num_ports(struct usb_serial *serial); 78static int ipaq_calc_num_ports(struct usb_serial *serial);
81static int ipaq_startup(struct usb_serial *serial); 79static int ipaq_startup(struct usb_serial *serial);
82static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
83 const unsigned char *buf, int count);
84static int ipaq_write_bulk(struct usb_serial_port *port,
85 const unsigned char *buf, int count);
86static void ipaq_write_gather(struct usb_serial_port *port);
87static void ipaq_read_bulk_callback(struct urb *urb);
88static void ipaq_write_bulk_callback(struct urb *urb);
89static int ipaq_write_room(struct tty_struct *tty);
90static int ipaq_chars_in_buffer(struct tty_struct *tty);
91static void ipaq_destroy_lists(struct usb_serial_port *port);
92
93 80
94static struct usb_device_id ipaq_id_table [] = { 81static struct usb_device_id ipaq_id_table [] = {
95 /* The first entry is a placeholder for the insmod-specified device */ 82 /* The first entry is a placeholder for the insmod-specified device */
@@ -558,7 +545,7 @@ static struct usb_driver ipaq_driver = {
558 .probe = usb_serial_probe, 545 .probe = usb_serial_probe,
559 .disconnect = usb_serial_disconnect, 546 .disconnect = usb_serial_disconnect,
560 .id_table = ipaq_id_table, 547 .id_table = ipaq_id_table,
561 .no_dynamic_id = 1, 548 .no_dynamic_id = 1,
562}; 549};
563 550
564 551
@@ -569,91 +556,24 @@ static struct usb_serial_driver ipaq_device = {
569 .name = "ipaq", 556 .name = "ipaq",
570 }, 557 },
571 .description = "PocketPC PDA", 558 .description = "PocketPC PDA",
572 .usb_driver = &ipaq_driver, 559 .usb_driver = &ipaq_driver,
573 .id_table = ipaq_id_table, 560 .id_table = ipaq_id_table,
561 .bulk_in_size = 256,
562 .bulk_out_size = 256,
574 .open = ipaq_open, 563 .open = ipaq_open,
575 .close = ipaq_close,
576 .attach = ipaq_startup, 564 .attach = ipaq_startup,
577 .calc_num_ports = ipaq_calc_num_ports, 565 .calc_num_ports = ipaq_calc_num_ports,
578 .write = ipaq_write,
579 .write_room = ipaq_write_room,
580 .chars_in_buffer = ipaq_chars_in_buffer,
581 .read_bulk_callback = ipaq_read_bulk_callback,
582 .write_bulk_callback = ipaq_write_bulk_callback,
583}; 566};
584 567
585static spinlock_t write_list_lock;
586static int bytes_in;
587static int bytes_out;
588
589static int ipaq_open(struct tty_struct *tty, 568static int ipaq_open(struct tty_struct *tty,
590 struct usb_serial_port *port) 569 struct usb_serial_port *port)
591{ 570{
592 struct usb_serial *serial = port->serial; 571 struct usb_serial *serial = port->serial;
593 struct ipaq_private *priv; 572 int result = 0;
594 struct ipaq_packet *pkt;
595 int i, result = 0;
596 int retries = connect_retries; 573 int retries = connect_retries;
597 574
598 dbg("%s - port %d", __func__, port->number); 575 dbg("%s - port %d", __func__, port->number);
599 576
600 bytes_in = 0;
601 bytes_out = 0;
602 priv = kmalloc(sizeof(struct ipaq_private), GFP_KERNEL);
603 if (priv == NULL) {
604 dev_err(&port->dev, "%s - Out of memory\n", __func__);
605 return -ENOMEM;
606 }
607 usb_set_serial_port_data(port, priv);
608 priv->active = 0;
609 priv->queue_len = 0;
610 priv->free_len = 0;
611 INIT_LIST_HEAD(&priv->queue);
612 INIT_LIST_HEAD(&priv->freelist);
613
614 for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) {
615 pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL);
616 if (pkt == NULL)
617 goto enomem;
618
619 pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL);
620 if (pkt->data == NULL) {
621 kfree(pkt);
622 goto enomem;
623 }
624 pkt->len = 0;
625 pkt->written = 0;
626 INIT_LIST_HEAD(&pkt->list);
627 list_add(&pkt->list, &priv->freelist);
628 priv->free_len += PACKET_SIZE;
629 }
630
631 /*
632 * Lose the small buffers usbserial provides. Make larger ones.
633 */
634
635 kfree(port->bulk_in_buffer);
636 kfree(port->bulk_out_buffer);
637 /* make sure the generic serial code knows */
638 port->bulk_out_buffer = NULL;
639
640 port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
641 if (port->bulk_in_buffer == NULL)
642 goto enomem;
643
644 port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL);
645 if (port->bulk_out_buffer == NULL) {
646 /* the buffer is useless, free it */
647 kfree(port->bulk_in_buffer);
648 port->bulk_in_buffer = NULL;
649 goto enomem;
650 }
651 port->read_urb->transfer_buffer = port->bulk_in_buffer;
652 port->write_urb->transfer_buffer = port->bulk_out_buffer;
653 port->read_urb->transfer_buffer_length = URBDATA_SIZE;
654 port->bulk_out_size = port->write_urb->transfer_buffer_length
655 = URBDATA_SIZE;
656
657 msleep(1000*initial_wait); 577 msleep(1000*initial_wait);
658 578
659 /* 579 /*
@@ -663,7 +583,6 @@ static int ipaq_open(struct tty_struct *tty,
663 * through. Since this has a reasonably high failure rate, we retry 583 * through. Since this has a reasonably high failure rate, we retry
664 * several times. 584 * several times.
665 */ 585 */
666
667 while (retries--) { 586 while (retries--) {
668 result = usb_control_msg(serial->dev, 587 result = usb_control_msg(serial->dev,
669 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, 588 usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21,
@@ -673,269 +592,15 @@ static int ipaq_open(struct tty_struct *tty,
673 592
674 msleep(1000); 593 msleep(1000);
675 } 594 }
676
677 if (!retries && result) { 595 if (!retries && result) {
678 dev_err(&port->dev, "%s - failed doing control urb, error %d\n", __func__, result); 596 dev_err(&port->dev, "%s - failed doing control urb, error %d\n",
679 goto error; 597 __func__, result);
680 } 598 return result;
681
682 /* Start reading from the device */
683 usb_fill_bulk_urb(port->read_urb, serial->dev,
684 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
685 port->read_urb->transfer_buffer,
686 port->read_urb->transfer_buffer_length,
687 ipaq_read_bulk_callback, port);
688
689 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
690 if (result) {
691 dev_err(&port->dev,
692 "%s - failed submitting read urb, error %d\n",
693 __func__, result);
694 goto error;
695 }
696
697 return 0;
698
699enomem:
700 result = -ENOMEM;
701 dev_err(&port->dev, "%s - Out of memory\n", __func__);
702error:
703 ipaq_destroy_lists(port);
704 kfree(priv);
705 return result;
706}
707
708
709static void ipaq_close(struct usb_serial_port *port)
710{
711 struct ipaq_private *priv = usb_get_serial_port_data(port);
712
713 dbg("%s - port %d", __func__, port->number);
714
715 /*
716 * shut down bulk read and write
717 */
718 usb_kill_urb(port->write_urb);
719 usb_kill_urb(port->read_urb);
720 ipaq_destroy_lists(port);
721 kfree(priv);
722 usb_set_serial_port_data(port, NULL);
723
724 /* Uncomment the following line if you want to see some statistics
725 * in your syslog */
726 /* info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out); */
727}
728
729static void ipaq_read_bulk_callback(struct urb *urb)
730{
731 struct usb_serial_port *port = urb->context;
732 struct tty_struct *tty;
733 unsigned char *data = urb->transfer_buffer;
734 int result;
735 int status = urb->status;
736
737 dbg("%s - port %d", __func__, port->number);
738
739 if (status) {
740 dbg("%s - nonzero read bulk status received: %d",
741 __func__, status);
742 return;
743 }
744
745 usb_serial_debug_data(debug, &port->dev, __func__,
746 urb->actual_length, data);
747
748 tty = tty_port_tty_get(&port->port);
749 if (tty && urb->actual_length) {
750 tty_insert_flip_string(tty, data, urb->actual_length);
751 tty_flip_buffer_push(tty);
752 bytes_in += urb->actual_length;
753 }
754 tty_kref_put(tty);
755
756 /* Continue trying to always read */
757 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
758 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
759 port->read_urb->transfer_buffer,
760 port->read_urb->transfer_buffer_length,
761 ipaq_read_bulk_callback, port);
762 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
763 if (result)
764 dev_err(&port->dev,
765 "%s - failed resubmitting read urb, error %d\n",
766 __func__, result);
767 return;
768}
769
770static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
771 const unsigned char *buf, int count)
772{
773 const unsigned char *current_position = buf;
774 int bytes_sent = 0;
775 int transfer_size;
776
777 dbg("%s - port %d", __func__, port->number);
778
779 while (count > 0) {
780 transfer_size = min(count, PACKET_SIZE);
781 if (ipaq_write_bulk(port, current_position, transfer_size))
782 break;
783 current_position += transfer_size;
784 bytes_sent += transfer_size;
785 count -= transfer_size;
786 bytes_out += transfer_size;
787 } 599 }
788 600
789 return bytes_sent; 601 return usb_serial_generic_open(tty, port);
790} 602}
791 603
792static int ipaq_write_bulk(struct usb_serial_port *port,
793 const unsigned char *buf, int count)
794{
795 struct ipaq_private *priv = usb_get_serial_port_data(port);
796 struct ipaq_packet *pkt = NULL;
797 int result = 0;
798 unsigned long flags;
799
800 if (priv->free_len <= 0) {
801 dbg("%s - we're stuffed", __func__);
802 return -EAGAIN;
803 }
804
805 spin_lock_irqsave(&write_list_lock, flags);
806 if (!list_empty(&priv->freelist)) {
807 pkt = list_entry(priv->freelist.next, struct ipaq_packet, list);
808 list_del(&pkt->list);
809 priv->free_len -= PACKET_SIZE;
810 }
811 spin_unlock_irqrestore(&write_list_lock, flags);
812 if (pkt == NULL) {
813 dbg("%s - we're stuffed", __func__);
814 return -EAGAIN;
815 }
816
817 memcpy(pkt->data, buf, count);
818 usb_serial_debug_data(debug, &port->dev, __func__, count, pkt->data);
819
820 pkt->len = count;
821 pkt->written = 0;
822 spin_lock_irqsave(&write_list_lock, flags);
823 list_add_tail(&pkt->list, &priv->queue);
824 priv->queue_len += count;
825 if (priv->active == 0) {
826 priv->active = 1;
827 ipaq_write_gather(port);
828 spin_unlock_irqrestore(&write_list_lock, flags);
829 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
830 if (result)
831 dev_err(&port->dev,
832 "%s - failed submitting write urb, error %d\n",
833 __func__, result);
834 } else {
835 spin_unlock_irqrestore(&write_list_lock, flags);
836 }
837 return result;
838}
839
840static void ipaq_write_gather(struct usb_serial_port *port)
841{
842 struct ipaq_private *priv = usb_get_serial_port_data(port);
843 struct usb_serial *serial = port->serial;
844 int count, room;
845 struct ipaq_packet *pkt, *tmp;
846 struct urb *urb = port->write_urb;
847
848 room = URBDATA_SIZE;
849 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
850 count = min(room, (int)(pkt->len - pkt->written));
851 memcpy(urb->transfer_buffer + (URBDATA_SIZE - room),
852 pkt->data + pkt->written, count);
853 room -= count;
854 pkt->written += count;
855 priv->queue_len -= count;
856 if (pkt->written == pkt->len) {
857 list_move(&pkt->list, &priv->freelist);
858 priv->free_len += PACKET_SIZE;
859 }
860 if (room == 0)
861 break;
862 }
863
864 count = URBDATA_SIZE - room;
865 usb_fill_bulk_urb(port->write_urb, serial->dev,
866 usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
867 port->write_urb->transfer_buffer, count,
868 ipaq_write_bulk_callback, port);
869 return;
870}
871
872static void ipaq_write_bulk_callback(struct urb *urb)
873{
874 struct usb_serial_port *port = urb->context;
875 struct ipaq_private *priv = usb_get_serial_port_data(port);
876 unsigned long flags;
877 int result;
878 int status = urb->status;
879
880 dbg("%s - port %d", __func__, port->number);
881
882 if (status) {
883 dbg("%s - nonzero write bulk status received: %d",
884 __func__, status);
885 return;
886 }
887
888 spin_lock_irqsave(&write_list_lock, flags);
889 if (!list_empty(&priv->queue)) {
890 ipaq_write_gather(port);
891 spin_unlock_irqrestore(&write_list_lock, flags);
892 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
893 if (result)
894 dev_err(&port->dev,
895 "%s - failed submitting write urb, error %d\n",
896 __func__, result);
897 } else {
898 priv->active = 0;
899 spin_unlock_irqrestore(&write_list_lock, flags);
900 }
901
902 usb_serial_port_softint(port);
903}
904
905static int ipaq_write_room(struct tty_struct *tty)
906{
907 struct usb_serial_port *port = tty->driver_data;
908 struct ipaq_private *priv = usb_get_serial_port_data(port);
909
910 dbg("%s - freelen %d", __func__, priv->free_len);
911 return priv->free_len;
912}
913
914static int ipaq_chars_in_buffer(struct tty_struct *tty)
915{
916 struct usb_serial_port *port = tty->driver_data;
917 struct ipaq_private *priv = usb_get_serial_port_data(port);
918
919 dbg("%s - queuelen %d", __func__, priv->queue_len);
920 return priv->queue_len;
921}
922
923static void ipaq_destroy_lists(struct usb_serial_port *port)
924{
925 struct ipaq_private *priv = usb_get_serial_port_data(port);
926 struct ipaq_packet *pkt, *tmp;
927
928 list_for_each_entry_safe(pkt, tmp, &priv->queue, list) {
929 kfree(pkt->data);
930 kfree(pkt);
931 }
932 list_for_each_entry_safe(pkt, tmp, &priv->freelist, list) {
933 kfree(pkt->data);
934 kfree(pkt);
935 }
936}
937
938
939static int ipaq_calc_num_ports(struct usb_serial *serial) 604static int ipaq_calc_num_ports(struct usb_serial *serial)
940{ 605{
941 /* 606 /*
@@ -994,7 +659,6 @@ static int ipaq_startup(struct usb_serial *serial)
994static int __init ipaq_init(void) 659static int __init ipaq_init(void)
995{ 660{
996 int retval; 661 int retval;
997 spin_lock_init(&write_list_lock);
998 retval = usb_serial_register(&ipaq_device); 662 retval = usb_serial_register(&ipaq_device);
999 if (retval) 663 if (retval)
1000 goto failed_usb_serial_register; 664 goto failed_usb_serial_register;
@@ -1015,7 +679,6 @@ failed_usb_serial_register:
1015 return retval; 679 return retval;
1016} 680}
1017 681
1018
1019static void __exit ipaq_exit(void) 682static void __exit ipaq_exit(void)
1020{ 683{
1021 usb_deregister(&ipaq_driver); 684 usb_deregister(&ipaq_driver);
diff --git a/drivers/usb/serial/ipaq.h b/drivers/usb/serial/ipaq.h
deleted file mode 100644
index 2b9035918b85..000000000000
--- a/drivers/usb/serial/ipaq.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2 * USB Compaq iPAQ driver
3 *
4 * Copyright (C) 2001 - 2002
5 * Ganesh Varadarajan <ganesh@veritas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 */
13
14#ifndef __LINUX_USB_SERIAL_IPAQ_H
15#define __LINUX_USB_SERIAL_IPAQ_H
16
17/*
18 * Since we can't queue our bulk write urbs (don't know why - it just
19 * doesn't work), we can send down only one write urb at a time. The simplistic
20 * approach taken by the generic usbserial driver will work, but it's not good
21 * for performance. Therefore, we buffer upto URBDATA_QUEUE_MAX bytes of write
22 * requests coming from the line discipline. This is done by chaining them
23 * in lists of struct ipaq_packet, each packet holding a maximum of
24 * PACKET_SIZE bytes.
25 *
26 * ipaq_write() can be called from bottom half context; hence we can't
27 * allocate memory for packets there. So we initialize a pool of packets at
28 * the first open and maintain a freelist.
29 *
30 * The value of PACKET_SIZE was empirically determined by
31 * checking the maximum write sizes sent down by the ppp ldisc.
32 * URBDATA_QUEUE_MAX is set to 64K, which is the maximum TCP window size.
33 */
34
35struct ipaq_packet {
36 char *data;
37 size_t len;
38 size_t written;
39 struct list_head list;
40};
41
42struct ipaq_private {
43 int active;
44 int queue_len;
45 int free_len;
46 struct list_head queue;
47 struct list_head freelist;
48};
49
50#define URBDATA_SIZE 4096
51#define URBDATA_QUEUE_MAX (64 * 1024)
52#define PACKET_SIZE 256
53
54#endif
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index e1d07840cee6..ca77e88836bd 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -34,7 +34,6 @@
34 * DCD, DTR, RTS, CTS which are currently faked. 34 * DCD, DTR, RTS, CTS which are currently faked.
35 * It's good enough for PPP at this point. It's based off all kinds of 35 * It's good enough for PPP at this point. It's based off all kinds of
36 * code found in usb/serial and usb/class 36 * code found in usb/serial and usb/class
37 *
38 */ 37 */
39 38
40#include <linux/kernel.h> 39#include <linux/kernel.h>
@@ -52,7 +51,7 @@
52/* 51/*
53 * Version Information 52 * Version Information
54 */ 53 */
55#define DRIVER_VERSION "v0.3" 54#define DRIVER_VERSION "v0.4"
56#define DRIVER_AUTHOR "Roelf Diedericks" 55#define DRIVER_AUTHOR "Roelf Diedericks"
57#define DRIVER_DESC "IPWireless tty driver" 56#define DRIVER_DESC "IPWireless tty driver"
58 57
@@ -65,8 +64,6 @@
65/* Message sizes */ 64/* Message sizes */
66#define EVENT_BUFFER_SIZE 0xFF 65#define EVENT_BUFFER_SIZE 0xFF
67#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff)) 66#define CHAR2INT16(c1, c0) (((u32)((c1) & 0xff) << 8) + (u32)((c0) & 0xff))
68#define NUM_BULK_URBS 24
69#define NUM_CONTROL_URBS 16
70 67
71/* vendor/product pairs that are known work with this driver*/ 68/* vendor/product pairs that are known work with this driver*/
72#define IPW_VID 0x0bc3 69#define IPW_VID 0x0bc3
@@ -151,47 +148,6 @@ static struct usb_driver usb_ipw_driver = {
151 148
152static int debug; 149static int debug;
153 150
154static void ipw_read_bulk_callback(struct urb *urb)
155{
156 struct usb_serial_port *port = urb->context;
157 unsigned char *data = urb->transfer_buffer;
158 struct tty_struct *tty;
159 int result;
160 int status = urb->status;
161
162 dbg("%s - port %d", __func__, port->number);
163
164 if (status) {
165 dbg("%s - nonzero read bulk status received: %d",
166 __func__, status);
167 return;
168 }
169
170 usb_serial_debug_data(debug, &port->dev, __func__,
171 urb->actual_length, data);
172
173 tty = tty_port_tty_get(&port->port);
174 if (tty && urb->actual_length) {
175 tty_insert_flip_string(tty, data, urb->actual_length);
176 tty_flip_buffer_push(tty);
177 }
178 tty_kref_put(tty);
179
180 /* Continue trying to always read */
181 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
182 usb_rcvbulkpipe(port->serial->dev,
183 port->bulk_in_endpointAddress),
184 port->read_urb->transfer_buffer,
185 port->read_urb->transfer_buffer_length,
186 ipw_read_bulk_callback, port);
187 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
188 if (result)
189 dev_err(&port->dev,
190 "%s - failed resubmitting read urb, error %d\n",
191 __func__, result);
192 return;
193}
194
195static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port) 151static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
196{ 152{
197 struct usb_device *dev = port->serial->dev; 153 struct usb_device *dev = port->serial->dev;
@@ -229,15 +185,7 @@ static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
229 185
230 /*--2: Start reading from the device */ 186 /*--2: Start reading from the device */
231 dbg("%s: setting up bulk read callback", __func__); 187 dbg("%s: setting up bulk read callback", __func__);
232 usb_fill_bulk_urb(port->read_urb, dev, 188 usb_serial_generic_open(tty, port);
233 usb_rcvbulkpipe(dev, port->bulk_in_endpointAddress),
234 port->bulk_in_buffer,
235 port->bulk_in_size,
236 ipw_read_bulk_callback, port);
237 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
238 if (result < 0)
239 dbg("%s - usb_submit_urb(read bulk) failed with status %d",
240 __func__, result);
241 189
242 /*--3: Tell the modem to open the floodgates on the rx bulk channel */ 190 /*--3: Tell the modem to open the floodgates on the rx bulk channel */
243 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__); 191 dbg("%s:asking modem for RxRead (RXBULK_ON)", __func__);
@@ -267,35 +215,6 @@ static int ipw_open(struct tty_struct *tty, struct usb_serial_port *port)
267 dev_err(&port->dev, 215 dev_err(&port->dev,
268 "initial flowcontrol failed (error = %d)\n", result); 216 "initial flowcontrol failed (error = %d)\n", result);
269 217
270
271 /*--5: raise the dtr */
272 dbg("%s:raising dtr", __func__);
273 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
274 IPW_SIO_SET_PIN,
275 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
276 IPW_PIN_SETDTR,
277 0,
278 NULL,
279 0,
280 200000);
281 if (result < 0)
282 dev_err(&port->dev,
283 "setting dtr failed (error = %d)\n", result);
284
285 /*--6: raise the rts */
286 dbg("%s:raising rts", __func__);
287 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
288 IPW_SIO_SET_PIN,
289 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
290 IPW_PIN_SETRTS,
291 0,
292 NULL,
293 0,
294 200000);
295 if (result < 0)
296 dev_err(&port->dev,
297 "setting dtr failed (error = %d)\n", result);
298
299 kfree(buf_flow_init); 218 kfree(buf_flow_init);
300 return 0; 219 return 0;
301} 220}
@@ -305,8 +224,8 @@ static void ipw_dtr_rts(struct usb_serial_port *port, int on)
305 struct usb_device *dev = port->serial->dev; 224 struct usb_device *dev = port->serial->dev;
306 int result; 225 int result;
307 226
308 /*--1: drop the dtr */ 227 dbg("%s: on = %d", __func__, on);
309 dbg("%s:dropping dtr", __func__); 228
310 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 229 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
311 IPW_SIO_SET_PIN, 230 IPW_SIO_SET_PIN,
312 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 231 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
@@ -316,22 +235,20 @@ static void ipw_dtr_rts(struct usb_serial_port *port, int on)
316 0, 235 0,
317 200000); 236 200000);
318 if (result < 0) 237 if (result < 0)
319 dev_err(&port->dev, "dropping dtr failed (error = %d)\n", 238 dev_err(&port->dev, "setting dtr failed (error = %d)\n",
320 result); 239 result);
321 240
322 /*--2: drop the rts */
323 dbg("%s:dropping rts", __func__);
324 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 241 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
325 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | 242 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
326 USB_RECIP_INTERFACE | USB_DIR_OUT, 243 USB_RECIP_INTERFACE | USB_DIR_OUT,
327 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS, 244 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS,
328 0, 245 0,
329 NULL, 246 NULL,
330 0, 247 0,
331 200000); 248 200000);
332 if (result < 0) 249 if (result < 0)
333 dev_err(&port->dev, 250 dev_err(&port->dev, "setting rts failed (error = %d)\n",
334 "dropping rts failed (error = %d)\n", result); 251 result);
335} 252}
336 253
337static void ipw_close(struct usb_serial_port *port) 254static void ipw_close(struct usb_serial_port *port)
@@ -368,83 +285,7 @@ static void ipw_close(struct usb_serial_port *port)
368 dev_err(&port->dev, 285 dev_err(&port->dev,
369 "Disabling bulk RxRead failed (error = %d)\n", result); 286 "Disabling bulk RxRead failed (error = %d)\n", result);
370 287
371 /* shutdown any in-flight urbs that we know about */ 288 usb_serial_generic_close(port);
372 usb_kill_urb(port->read_urb);
373 usb_kill_urb(port->write_urb);
374}
375
376static void ipw_write_bulk_callback(struct urb *urb)
377{
378 struct usb_serial_port *port = urb->context;
379 int status = urb->status;
380
381 dbg("%s", __func__);
382
383 port->write_urb_busy = 0;
384
385 if (status)
386 dbg("%s - nonzero write bulk status received: %d",
387 __func__, status);
388
389 usb_serial_port_softint(port);
390}
391
392static int ipw_write(struct tty_struct *tty, struct usb_serial_port *port,
393 const unsigned char *buf, int count)
394{
395 struct usb_device *dev = port->serial->dev;
396 int ret;
397
398 dbg("%s: TOP: count=%d, in_interrupt=%ld", __func__,
399 count, in_interrupt());
400
401 if (count == 0) {
402 dbg("%s - write request of 0 bytes", __func__);
403 return 0;
404 }
405
406 spin_lock_bh(&port->lock);
407 if (port->write_urb_busy) {
408 spin_unlock_bh(&port->lock);
409 dbg("%s - already writing", __func__);
410 return 0;
411 }
412 port->write_urb_busy = 1;
413 spin_unlock_bh(&port->lock);
414
415 count = min(count, port->bulk_out_size);
416 memcpy(port->bulk_out_buffer, buf, count);
417
418 dbg("%s count now:%d", __func__, count);
419
420 usb_fill_bulk_urb(port->write_urb, dev,
421 usb_sndbulkpipe(dev, port->bulk_out_endpointAddress),
422 port->write_urb->transfer_buffer,
423 count,
424 ipw_write_bulk_callback,
425 port);
426
427 ret = usb_submit_urb(port->write_urb, GFP_ATOMIC);
428 if (ret != 0) {
429 port->write_urb_busy = 0;
430 dbg("%s - usb_submit_urb(write bulk) failed with error = %d",
431 __func__, ret);
432 return ret;
433 }
434
435 dbg("%s returning %d", __func__, count);
436 return count;
437}
438
439static int ipw_probe(struct usb_serial_port *port)
440{
441 return 0;
442}
443
444static int ipw_disconnect(struct usb_serial_port *port)
445{
446 usb_set_serial_port_data(port, NULL);
447 return 0;
448} 289}
449 290
450static struct usb_serial_driver ipw_device = { 291static struct usb_serial_driver ipw_device = {
@@ -453,17 +294,12 @@ static struct usb_serial_driver ipw_device = {
453 .name = "ipw", 294 .name = "ipw",
454 }, 295 },
455 .description = "IPWireless converter", 296 .description = "IPWireless converter",
456 .usb_driver = &usb_ipw_driver, 297 .usb_driver = &usb_ipw_driver,
457 .id_table = usb_ipw_ids, 298 .id_table = usb_ipw_ids,
458 .num_ports = 1, 299 .num_ports = 1,
459 .open = ipw_open, 300 .open = ipw_open,
460 .close = ipw_close, 301 .close = ipw_close,
461 .dtr_rts = ipw_dtr_rts, 302 .dtr_rts = ipw_dtr_rts,
462 .port_probe = ipw_probe,
463 .port_remove = ipw_disconnect,
464 .write = ipw_write,
465 .write_bulk_callback = ipw_write_bulk_callback,
466 .read_bulk_callback = ipw_read_bulk_callback,
467}; 303};
468 304
469 305
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 4a0f51974232..ccbce4066d04 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com) 4 * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com) 5 * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com)
6 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -72,8 +73,8 @@
72/* 73/*
73 * Version Information 74 * Version Information
74 */ 75 */
75#define DRIVER_VERSION "v0.4" 76#define DRIVER_VERSION "v0.5"
76#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>" 77#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Johan Hovold <jhovold@gmail.com>"
77#define DRIVER_DESC "USB IR Dongle driver" 78#define DRIVER_DESC "USB IR Dongle driver"
78 79
79static int debug; 80static int debug;
@@ -87,11 +88,9 @@ static int xbof = -1;
87 88
88static int ir_startup (struct usb_serial *serial); 89static int ir_startup (struct usb_serial *serial);
89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port); 90static int ir_open(struct tty_struct *tty, struct usb_serial_port *port);
90static void ir_close(struct usb_serial_port *port); 91static int ir_prepare_write_buffer(struct usb_serial_port *port,
91static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, 92 void *dest, size_t size);
92 const unsigned char *buf, int count); 93static void ir_process_read_urb(struct urb *urb);
93static void ir_write_bulk_callback (struct urb *urb);
94static void ir_read_bulk_callback (struct urb *urb);
95static void ir_set_termios(struct tty_struct *tty, 94static void ir_set_termios(struct tty_struct *tty,
96 struct usb_serial_port *port, struct ktermios *old_termios); 95 struct usb_serial_port *port, struct ktermios *old_termios);
97 96
@@ -130,10 +129,8 @@ static struct usb_serial_driver ir_device = {
130 .set_termios = ir_set_termios, 129 .set_termios = ir_set_termios,
131 .attach = ir_startup, 130 .attach = ir_startup,
132 .open = ir_open, 131 .open = ir_open,
133 .close = ir_close, 132 .prepare_write_buffer = ir_prepare_write_buffer,
134 .write = ir_write, 133 .process_read_urb = ir_process_read_urb,
135 .write_bulk_callback = ir_write_bulk_callback,
136 .read_bulk_callback = ir_read_bulk_callback,
137}; 134};
138 135
139static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc) 136static inline void irda_usb_dump_class_desc(struct usb_irda_cs_descriptor *desc)
@@ -198,7 +195,6 @@ error:
198 return NULL; 195 return NULL;
199} 196}
200 197
201
202static u8 ir_xbof_change(u8 xbof) 198static u8 ir_xbof_change(u8 xbof)
203{ 199{
204 u8 result; 200 u8 result;
@@ -237,7 +233,6 @@ static u8 ir_xbof_change(u8 xbof)
237 return(result); 233 return(result);
238} 234}
239 235
240
241static int ir_startup(struct usb_serial *serial) 236static int ir_startup(struct usb_serial *serial)
242{ 237{
243 struct usb_irda_cs_descriptor *irda_desc; 238 struct usb_irda_cs_descriptor *irda_desc;
@@ -297,83 +292,22 @@ static int ir_startup(struct usb_serial *serial)
297 292
298static int ir_open(struct tty_struct *tty, struct usb_serial_port *port) 293static int ir_open(struct tty_struct *tty, struct usb_serial_port *port)
299{ 294{
300 char *buffer; 295 int i;
301 int result = 0;
302 296
303 dbg("%s - port %d", __func__, port->number); 297 dbg("%s - port %d", __func__, port->number);
304 298
305 if (buffer_size) { 299 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
306 /* override the default buffer sizes */ 300 port->write_urbs[i]->transfer_flags = URB_ZERO_PACKET;
307 buffer = kmalloc(buffer_size, GFP_KERNEL);
308 if (!buffer) {
309 dev_err(&port->dev, "%s - out of memory.\n", __func__);
310 return -ENOMEM;
311 }
312 kfree(port->read_urb->transfer_buffer);
313 port->read_urb->transfer_buffer = buffer;
314 port->read_urb->transfer_buffer_length = buffer_size;
315
316 buffer = kmalloc(buffer_size, GFP_KERNEL);
317 if (!buffer) {
318 dev_err(&port->dev, "%s - out of memory.\n", __func__);
319 return -ENOMEM;
320 }
321 kfree(port->write_urb->transfer_buffer);
322 port->write_urb->transfer_buffer = buffer;
323 port->write_urb->transfer_buffer_length = buffer_size;
324 port->bulk_out_size = buffer_size;
325 }
326 301
327 /* Start reading from the device */ 302 /* Start reading from the device */
328 usb_fill_bulk_urb( 303 return usb_serial_generic_open(tty, port);
329 port->read_urb,
330 port->serial->dev,
331 usb_rcvbulkpipe(port->serial->dev,
332 port->bulk_in_endpointAddress),
333 port->read_urb->transfer_buffer,
334 port->read_urb->transfer_buffer_length,
335 ir_read_bulk_callback,
336 port);
337 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
338 if (result)
339 dev_err(&port->dev,
340 "%s - failed submitting read urb, error %d\n",
341 __func__, result);
342
343 return result;
344} 304}
345 305
346static void ir_close(struct usb_serial_port *port) 306static int ir_prepare_write_buffer(struct usb_serial_port *port,
307 void *dest, size_t size)
347{ 308{
348 dbg("%s - port %d", __func__, port->number); 309 unsigned char *buf = dest;
349 310 int count;
350 /* shutdown our bulk read */
351 usb_kill_urb(port->read_urb);
352}
353
354static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
355 const unsigned char *buf, int count)
356{
357 unsigned char *transfer_buffer;
358 int result;
359 int transfer_size;
360
361 dbg("%s - port = %d, count = %d", __func__, port->number, count);
362
363 if (count == 0)
364 return 0;
365
366 spin_lock_bh(&port->lock);
367 if (port->write_urb_busy) {
368 spin_unlock_bh(&port->lock);
369 dbg("%s - already writing", __func__);
370 return 0;
371 }
372 port->write_urb_busy = 1;
373 spin_unlock_bh(&port->lock);
374
375 transfer_buffer = port->write_urb->transfer_buffer;
376 transfer_size = min(count, port->bulk_out_size - 1);
377 311
378 /* 312 /*
379 * The first byte of the packet we send to the device contains an 313 * The first byte of the packet we send to the device contains an
@@ -382,119 +316,57 @@ static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
382 * 316 *
383 * See section 5.4.2.2 of the USB IrDA spec. 317 * See section 5.4.2.2 of the USB IrDA spec.
384 */ 318 */
385 *transfer_buffer = ir_xbof | ir_baud; 319 *buf = ir_xbof | ir_baud;
386 ++transfer_buffer;
387
388 memcpy(transfer_buffer, buf, transfer_size);
389 320
390 usb_fill_bulk_urb( 321 count = kfifo_out_locked(&port->write_fifo, buf + 1, size - 1,
391 port->write_urb, 322 &port->lock);
392 port->serial->dev, 323 return count + 1;
393 usb_sndbulkpipe(port->serial->dev,
394 port->bulk_out_endpointAddress),
395 port->write_urb->transfer_buffer,
396 transfer_size + 1,
397 ir_write_bulk_callback,
398 port);
399
400 port->write_urb->transfer_flags = URB_ZERO_PACKET;
401
402 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
403 if (result) {
404 port->write_urb_busy = 0;
405 dev_err(&port->dev,
406 "%s - failed submitting write urb, error %d\n",
407 __func__, result);
408 } else
409 result = transfer_size;
410
411 return result;
412} 324}
413 325
414static void ir_write_bulk_callback(struct urb *urb) 326static void ir_process_read_urb(struct urb *urb)
415{ 327{
416 struct usb_serial_port *port = urb->context; 328 struct usb_serial_port *port = urb->context;
417 int status = urb->status; 329 unsigned char *data = urb->transfer_buffer;
418 330 struct tty_struct *tty;
419 dbg("%s - port %d", __func__, port->number);
420 331
421 port->write_urb_busy = 0; 332 if (!urb->actual_length)
422 if (status) {
423 dbg("%s - nonzero write bulk status received: %d",
424 __func__, status);
425 return; 333 return;
426 } 334 /*
335 * The first byte of the packet we get from the device
336 * contains a busy indicator and baud rate change.
337 * See section 5.4.1.2 of the USB IrDA spec.
338 */
339 if (*data & 0x0f)
340 ir_baud = *data & 0x0f;
427 341
428 usb_serial_debug_data( 342 if (urb->actual_length == 1)
429 debug, 343 return;
430 &port->dev,
431 __func__,
432 urb->actual_length,
433 urb->transfer_buffer);
434 344
435 usb_serial_port_softint(port); 345 tty = tty_port_tty_get(&port->port);
346 if (!tty)
347 return;
348 tty_insert_flip_string(tty, data + 1, urb->actual_length - 1);
349 tty_flip_buffer_push(tty);
350 tty_kref_put(tty);
436} 351}
437 352
438static void ir_read_bulk_callback(struct urb *urb) 353static void ir_set_termios_callback(struct urb *urb)
439{ 354{
440 struct usb_serial_port *port = urb->context; 355 struct usb_serial_port *port = urb->context;
441 struct tty_struct *tty;
442 unsigned char *data = urb->transfer_buffer;
443 int result;
444 int status = urb->status; 356 int status = urb->status;
445 357
446 dbg("%s - port %d", __func__, port->number); 358 dbg("%s - port %d", __func__, port->number);
447 359
448 switch (status) { 360 kfree(urb->transfer_buffer);
449 case 0: /* Successful */ 361
450 /* 362 if (status)
451 * The first byte of the packet we get from the device 363 dbg("%s - non-zero urb status: %d", __func__, status);
452 * contains a busy indicator and baud rate change.
453 * See section 5.4.1.2 of the USB IrDA spec.
454 */
455 if ((*data & 0x0f) > 0)
456 ir_baud = *data & 0x0f;
457 usb_serial_debug_data(debug, &port->dev, __func__,
458 urb->actual_length, data);
459 tty = tty_port_tty_get(&port->port);
460 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
461 tty_flip_buffer_push(tty);
462 tty_kref_put(tty);
463
464 /*
465 * No break here.
466 * We want to resubmit the urb so we can read
467 * again.
468 */
469
470 case -EPROTO: /* taking inspiration from pl2303.c */
471 /* Continue trying to always read */
472 usb_fill_bulk_urb(
473 port->read_urb,
474 port->serial->dev,
475 usb_rcvbulkpipe(port->serial->dev,
476 port->bulk_in_endpointAddress),
477 port->read_urb->transfer_buffer,
478 port->read_urb->transfer_buffer_length,
479 ir_read_bulk_callback,
480 port);
481
482 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
483 if (result)
484 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
485 __func__, result);
486 break ;
487 default:
488 dbg("%s - nonzero read bulk status received: %d",
489 __func__, status);
490 break ;
491 }
492 return;
493} 364}
494 365
495static void ir_set_termios(struct tty_struct *tty, 366static void ir_set_termios(struct tty_struct *tty,
496 struct usb_serial_port *port, struct ktermios *old_termios) 367 struct usb_serial_port *port, struct ktermios *old_termios)
497{ 368{
369 struct urb *urb;
498 unsigned char *transfer_buffer; 370 unsigned char *transfer_buffer;
499 int result; 371 int result;
500 speed_t baud; 372 speed_t baud;
@@ -548,41 +420,63 @@ static void ir_set_termios(struct tty_struct *tty,
548 else 420 else
549 ir_xbof = ir_xbof_change(xbof) ; 421 ir_xbof = ir_xbof_change(xbof) ;
550 422
551 /* FIXME need to check to see if our write urb is busy right 423 /* Only speed changes are supported */
552 * now, or use a urb pool. 424 tty_termios_copy_hw(tty->termios, old_termios);
553 * 425 tty_encode_baud_rate(tty, baud, baud);
426
427 /*
554 * send the baud change out on an "empty" data packet 428 * send the baud change out on an "empty" data packet
555 */ 429 */
556 transfer_buffer = port->write_urb->transfer_buffer; 430 urb = usb_alloc_urb(0, GFP_KERNEL);
431 if (!urb) {
432 dev_err(&port->dev, "%s - no more urbs\n", __func__);
433 return;
434 }
435 transfer_buffer = kmalloc(1, GFP_KERNEL);
436 if (!transfer_buffer) {
437 dev_err(&port->dev, "%s - out of memory\n", __func__);
438 goto err_buf;
439 }
440
557 *transfer_buffer = ir_xbof | ir_baud; 441 *transfer_buffer = ir_xbof | ir_baud;
558 442
559 usb_fill_bulk_urb( 443 usb_fill_bulk_urb(
560 port->write_urb, 444 urb,
561 port->serial->dev, 445 port->serial->dev,
562 usb_sndbulkpipe(port->serial->dev, 446 usb_sndbulkpipe(port->serial->dev,
563 port->bulk_out_endpointAddress), 447 port->bulk_out_endpointAddress),
564 port->write_urb->transfer_buffer, 448 transfer_buffer,
565 1, 449 1,
566 ir_write_bulk_callback, 450 ir_set_termios_callback,
567 port); 451 port);
568 452
569 port->write_urb->transfer_flags = URB_ZERO_PACKET; 453 urb->transfer_flags = URB_ZERO_PACKET;
570 454
571 result = usb_submit_urb(port->write_urb, GFP_KERNEL); 455 result = usb_submit_urb(urb, GFP_KERNEL);
572 if (result) 456 if (result) {
573 dev_err(&port->dev, 457 dev_err(&port->dev, "%s - failed to submit urb: %d\n",
574 "%s - failed submitting write urb, error %d\n", 458 __func__, result);
575 __func__, result); 459 goto err_subm;
460 }
576 461
577 /* Only speed changes are supported */ 462 usb_free_urb(urb);
578 tty_termios_copy_hw(tty->termios, old_termios); 463
579 tty_encode_baud_rate(tty, baud, baud); 464 return;
465err_subm:
466 kfree(transfer_buffer);
467err_buf:
468 usb_free_urb(urb);
580} 469}
581 470
582static int __init ir_init(void) 471static int __init ir_init(void)
583{ 472{
584 int retval; 473 int retval;
585 474
475 if (buffer_size) {
476 ir_device.bulk_in_size = buffer_size;
477 ir_device.bulk_out_size = buffer_size;
478 }
479
586 retval = usb_serial_register(&ir_device); 480 retval = usb_serial_register(&ir_device);
587 if (retval) 481 if (retval)
588 goto failed_usb_serial_register; 482 goto failed_usb_serial_register;
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 43f13cf2f016..74551cb2e8ee 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -1044,34 +1044,6 @@ static int iuu_open(struct tty_struct *tty, struct usb_serial_port *port)
1044 if (buf == NULL) 1044 if (buf == NULL)
1045 return -ENOMEM; 1045 return -ENOMEM;
1046 1046
1047 /* fixup the endpoint buffer size */
1048 kfree(port->bulk_out_buffer);
1049 port->bulk_out_buffer = kmalloc(512, GFP_KERNEL);
1050 port->bulk_out_size = 512;
1051 kfree(port->bulk_in_buffer);
1052 port->bulk_in_buffer = kmalloc(512, GFP_KERNEL);
1053 port->bulk_in_size = 512;
1054
1055 if (!port->bulk_out_buffer || !port->bulk_in_buffer) {
1056 kfree(port->bulk_out_buffer);
1057 kfree(port->bulk_in_buffer);
1058 kfree(buf);
1059 return -ENOMEM;
1060 }
1061
1062 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
1063 usb_sndbulkpipe(port->serial->dev,
1064 port->bulk_out_endpointAddress),
1065 port->bulk_out_buffer, 512,
1066 NULL, NULL);
1067
1068
1069 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
1070 usb_rcvbulkpipe(port->serial->dev,
1071 port->bulk_in_endpointAddress),
1072 port->bulk_in_buffer, 512,
1073 NULL, NULL);
1074
1075 priv->poll = 0; 1047 priv->poll = 0;
1076 1048
1077 /* initialize writebuf */ 1049 /* initialize writebuf */
@@ -1277,6 +1249,8 @@ static struct usb_serial_driver iuu_device = {
1277 }, 1249 },
1278 .id_table = id_table, 1250 .id_table = id_table,
1279 .num_ports = 1, 1251 .num_ports = 1,
1252 .bulk_in_size = 512,
1253 .bulk_out_size = 512,
1280 .port_probe = iuu_create_sysfs_attrs, 1254 .port_probe = iuu_create_sysfs_attrs,
1281 .port_remove = iuu_remove_sysfs_attrs, 1255 .port_remove = iuu_remove_sysfs_attrs,
1282 .open = iuu_open, 1256 .open = iuu_open,
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 8eef91ba4b1c..cdbe8bf7f674 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * KLSI KL5KUSB105 chip RS232 converter driver 2 * KLSI KL5KUSB105 chip RS232 converter driver
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
4 * Copyright (C) 2001 Utz-Uwe Haus <haus@uuhaus.de> 5 * Copyright (C) 2001 Utz-Uwe Haus <haus@uuhaus.de>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -34,17 +35,6 @@
34 * implement handshaking or decide that we do not support it 35 * implement handshaking or decide that we do not support it
35 */ 36 */
36 37
37/* History:
38 * 0.3a - implemented pools of write URBs
39 * 0.3 - alpha version for public testing
40 * 0.2 - TIOCMGET works, so autopilot(1) can be used!
41 * 0.1 - can be used to do pilot-xfer -p /dev/ttyUSB0 -l
42 *
43 * The driver skeleton is mainly based on mct_u232.c and various other
44 * pieces of code shamelessly copied from the drivers/usb/serial/ directory.
45 */
46
47
48#include <linux/kernel.h> 38#include <linux/kernel.h>
49#include <linux/errno.h> 39#include <linux/errno.h>
50#include <linux/init.h> 40#include <linux/init.h>
@@ -64,8 +54,8 @@ static int debug;
64/* 54/*
65 * Version Information 55 * Version Information
66 */ 56 */
67#define DRIVER_VERSION "v0.3a" 57#define DRIVER_VERSION "v0.4"
68#define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>" 58#define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>, Johan Hovold <jhovold@gmail.com>"
69#define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver" 59#define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver"
70 60
71 61
@@ -73,23 +63,17 @@ static int debug;
73 * Function prototypes 63 * Function prototypes
74 */ 64 */
75static int klsi_105_startup(struct usb_serial *serial); 65static int klsi_105_startup(struct usb_serial *serial);
76static void klsi_105_disconnect(struct usb_serial *serial);
77static void klsi_105_release(struct usb_serial *serial); 66static void klsi_105_release(struct usb_serial *serial);
78static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port); 67static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port);
79static void klsi_105_close(struct usb_serial_port *port); 68static void klsi_105_close(struct usb_serial_port *port);
80static int klsi_105_write(struct tty_struct *tty,
81 struct usb_serial_port *port, const unsigned char *buf, int count);
82static void klsi_105_write_bulk_callback(struct urb *urb);
83static int klsi_105_chars_in_buffer(struct tty_struct *tty);
84static int klsi_105_write_room(struct tty_struct *tty);
85static void klsi_105_read_bulk_callback(struct urb *urb);
86static void klsi_105_set_termios(struct tty_struct *tty, 69static void klsi_105_set_termios(struct tty_struct *tty,
87 struct usb_serial_port *port, struct ktermios *old); 70 struct usb_serial_port *port, struct ktermios *old);
88static void klsi_105_throttle(struct tty_struct *tty);
89static void klsi_105_unthrottle(struct tty_struct *tty);
90static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file); 71static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file);
91static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file, 72static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
92 unsigned int set, unsigned int clear); 73 unsigned int set, unsigned int clear);
74static void klsi_105_process_read_urb(struct urb *urb);
75static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
76 void *dest, size_t size);
93 77
94/* 78/*
95 * All of the device info needed for the KLSI converters. 79 * All of the device info needed for the KLSI converters.
@@ -107,7 +91,7 @@ static struct usb_driver kl5kusb105d_driver = {
107 .probe = usb_serial_probe, 91 .probe = usb_serial_probe,
108 .disconnect = usb_serial_disconnect, 92 .disconnect = usb_serial_disconnect,
109 .id_table = id_table, 93 .id_table = id_table,
110 .no_dynamic_id = 1, 94 .no_dynamic_id = 1,
111}; 95};
112 96
113static struct usb_serial_driver kl5kusb105d_device = { 97static struct usb_serial_driver kl5kusb105d_device = {
@@ -115,26 +99,23 @@ static struct usb_serial_driver kl5kusb105d_device = {
115 .owner = THIS_MODULE, 99 .owner = THIS_MODULE,
116 .name = "kl5kusb105d", 100 .name = "kl5kusb105d",
117 }, 101 },
118 .description = "KL5KUSB105D / PalmConnect", 102 .description = "KL5KUSB105D / PalmConnect",
119 .usb_driver = &kl5kusb105d_driver, 103 .usb_driver = &kl5kusb105d_driver,
120 .id_table = id_table, 104 .id_table = id_table,
121 .num_ports = 1, 105 .num_ports = 1,
122 .open = klsi_105_open, 106 .bulk_out_size = 64,
123 .close = klsi_105_close, 107 .open = klsi_105_open,
124 .write = klsi_105_write, 108 .close = klsi_105_close,
125 .write_bulk_callback = klsi_105_write_bulk_callback, 109 .set_termios = klsi_105_set_termios,
126 .chars_in_buffer = klsi_105_chars_in_buffer, 110 /*.break_ctl = klsi_105_break_ctl,*/
127 .write_room = klsi_105_write_room, 111 .tiocmget = klsi_105_tiocmget,
128 .read_bulk_callback = klsi_105_read_bulk_callback, 112 .tiocmset = klsi_105_tiocmset,
129 .set_termios = klsi_105_set_termios, 113 .attach = klsi_105_startup,
130 /*.break_ctl = klsi_105_break_ctl,*/ 114 .release = klsi_105_release,
131 .tiocmget = klsi_105_tiocmget, 115 .throttle = usb_serial_generic_throttle,
132 .tiocmset = klsi_105_tiocmset, 116 .unthrottle = usb_serial_generic_unthrottle,
133 .attach = klsi_105_startup, 117 .process_read_urb = klsi_105_process_read_urb,
134 .disconnect = klsi_105_disconnect, 118 .prepare_write_buffer = klsi_105_prepare_write_buffer,
135 .release = klsi_105_release,
136 .throttle = klsi_105_throttle,
137 .unthrottle = klsi_105_unthrottle,
138}; 119};
139 120
140struct klsi_105_port_settings { 121struct klsi_105_port_settings {
@@ -145,18 +126,11 @@ struct klsi_105_port_settings {
145 __u8 unknown2; 126 __u8 unknown2;
146} __attribute__ ((packed)); 127} __attribute__ ((packed));
147 128
148/* we implement a pool of NUM_URBS urbs per usb_serial */
149#define NUM_URBS 1
150#define URB_TRANSFER_BUFFER_SIZE 64
151struct klsi_105_private { 129struct klsi_105_private {
152 struct klsi_105_port_settings cfg; 130 struct klsi_105_port_settings cfg;
153 struct ktermios termios; 131 struct ktermios termios;
154 unsigned long line_state; /* modem line settings */ 132 unsigned long line_state; /* modem line settings */
155 /* write pool */
156 struct urb *write_urb_pool[NUM_URBS];
157 spinlock_t lock; 133 spinlock_t lock;
158 unsigned long bytes_in;
159 unsigned long bytes_out;
160}; 134};
161 135
162 136
@@ -189,7 +163,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
189 settings->pktlen, settings->baudrate, settings->databits, 163 settings->pktlen, settings->baudrate, settings->databits,
190 settings->unknown1, settings->unknown2); 164 settings->unknown1, settings->unknown2);
191 return rc; 165 return rc;
192} /* klsi_105_chg_port_settings */ 166}
193 167
194/* translate a 16-bit status value from the device to linux's TIO bits */ 168/* translate a 16-bit status value from the device to linux's TIO bits */
195static unsigned long klsi_105_status2linestate(const __u16 status) 169static unsigned long klsi_105_status2linestate(const __u16 status)
@@ -202,6 +176,7 @@ static unsigned long klsi_105_status2linestate(const __u16 status)
202 176
203 return res; 177 return res;
204} 178}
179
205/* 180/*
206 * Read line control via vendor command and return result through 181 * Read line control via vendor command and return result through
207 * *line_state_p 182 * *line_state_p
@@ -258,7 +233,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
258static int klsi_105_startup(struct usb_serial *serial) 233static int klsi_105_startup(struct usb_serial *serial)
259{ 234{
260 struct klsi_105_private *priv; 235 struct klsi_105_private *priv;
261 int i, j; 236 int i;
262 237
263 /* check if we support the product id (see keyspan.c) 238 /* check if we support the product id (see keyspan.c)
264 * FIXME 239 * FIXME
@@ -282,29 +257,9 @@ static int klsi_105_startup(struct usb_serial *serial)
282 257
283 priv->line_state = 0; 258 priv->line_state = 0;
284 259
285 priv->bytes_in = 0;
286 priv->bytes_out = 0;
287 usb_set_serial_port_data(serial->port[i], priv); 260 usb_set_serial_port_data(serial->port[i], priv);
288 261
289 spin_lock_init(&priv->lock); 262 spin_lock_init(&priv->lock);
290 for (j = 0; j < NUM_URBS; j++) {
291 struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
292
293 priv->write_urb_pool[j] = urb;
294 if (urb == NULL) {
295 dev_err(&serial->dev->dev, "No more urbs???\n");
296 goto err_cleanup;
297 }
298
299 urb->transfer_buffer =
300 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
301 if (!urb->transfer_buffer) {
302 dev_err(&serial->dev->dev,
303 "%s - out of memory for urb buffers.\n",
304 __func__);
305 goto err_cleanup;
306 }
307 }
308 263
309 /* priv->termios is left uninitalized until port opening */ 264 /* priv->termios is left uninitalized until port opening */
310 init_waitqueue_head(&serial->port[i]->write_wait); 265 init_waitqueue_head(&serial->port[i]->write_wait);
@@ -315,44 +270,11 @@ static int klsi_105_startup(struct usb_serial *serial)
315err_cleanup: 270err_cleanup:
316 for (; i >= 0; i--) { 271 for (; i >= 0; i--) {
317 priv = usb_get_serial_port_data(serial->port[i]); 272 priv = usb_get_serial_port_data(serial->port[i]);
318 for (j = 0; j < NUM_URBS; j++) { 273 kfree(priv);
319 if (priv->write_urb_pool[j]) {
320 kfree(priv->write_urb_pool[j]->transfer_buffer);
321 usb_free_urb(priv->write_urb_pool[j]);
322 }
323 }
324 usb_set_serial_port_data(serial->port[i], NULL); 274 usb_set_serial_port_data(serial->port[i], NULL);
325 } 275 }
326 return -ENOMEM; 276 return -ENOMEM;
327} /* klsi_105_startup */ 277}
328
329
330static void klsi_105_disconnect(struct usb_serial *serial)
331{
332 int i;
333
334 dbg("%s", __func__);
335
336 /* stop reads and writes on all ports */
337 for (i = 0; i < serial->num_ports; ++i) {
338 struct klsi_105_private *priv =
339 usb_get_serial_port_data(serial->port[i]);
340
341 if (priv) {
342 /* kill our write urb pool */
343 int j;
344 struct urb **write_urbs = priv->write_urb_pool;
345
346 for (j = 0; j < NUM_URBS; j++) {
347 if (write_urbs[j]) {
348 usb_kill_urb(write_urbs[j]);
349 usb_free_urb(write_urbs[j]);
350 }
351 }
352 }
353 }
354} /* klsi_105_disconnect */
355
356 278
357static void klsi_105_release(struct usb_serial *serial) 279static void klsi_105_release(struct usb_serial *serial)
358{ 280{
@@ -360,13 +282,9 @@ static void klsi_105_release(struct usb_serial *serial)
360 282
361 dbg("%s", __func__); 283 dbg("%s", __func__);
362 284
363 for (i = 0; i < serial->num_ports; ++i) { 285 for (i = 0; i < serial->num_ports; ++i)
364 struct klsi_105_private *priv = 286 kfree(usb_get_serial_port_data(serial->port[i]));
365 usb_get_serial_port_data(serial->port[i]); 287}
366
367 kfree(priv);
368 }
369} /* klsi_105_release */
370 288
371static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port) 289static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
372{ 290{
@@ -416,18 +334,8 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
416 spin_unlock_irqrestore(&priv->lock, flags); 334 spin_unlock_irqrestore(&priv->lock, flags);
417 335
418 /* READ_ON and urb submission */ 336 /* READ_ON and urb submission */
419 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 337 rc = usb_serial_generic_open(tty, port);
420 usb_rcvbulkpipe(port->serial->dev,
421 port->bulk_in_endpointAddress),
422 port->read_urb->transfer_buffer,
423 port->read_urb->transfer_buffer_length,
424 klsi_105_read_bulk_callback,
425 port);
426
427 rc = usb_submit_urb(port->read_urb, GFP_KERNEL);
428 if (rc) { 338 if (rc) {
429 dev_err(&port->dev, "%s - failed submitting read urb, "
430 "error %d\n", __func__, rc);
431 retval = rc; 339 retval = rc;
432 goto exit; 340 goto exit;
433 } 341 }
@@ -460,12 +368,10 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
460exit: 368exit:
461 kfree(cfg); 369 kfree(cfg);
462 return retval; 370 return retval;
463} /* klsi_105_open */ 371}
464
465 372
466static void klsi_105_close(struct usb_serial_port *port) 373static void klsi_105_close(struct usb_serial_port *port)
467{ 374{
468 struct klsi_105_private *priv = usb_get_serial_port_data(port);
469 int rc; 375 int rc;
470 376
471 dbg("%s port %d", __func__, port->number); 377 dbg("%s port %d", __func__, port->number);
@@ -488,239 +394,62 @@ static void klsi_105_close(struct usb_serial_port *port)
488 mutex_unlock(&port->serial->disc_mutex); 394 mutex_unlock(&port->serial->disc_mutex);
489 395
490 /* shutdown our bulk reads and writes */ 396 /* shutdown our bulk reads and writes */
491 usb_kill_urb(port->write_urb); 397 usb_serial_generic_close(port);
492 usb_kill_urb(port->read_urb); 398
493 /* unlink our write pool */
494 /* FIXME */
495 /* wgg - do I need this? I think so. */ 399 /* wgg - do I need this? I think so. */
496 usb_kill_urb(port->interrupt_in_urb); 400 usb_kill_urb(port->interrupt_in_urb);
497 dev_info(&port->serial->dev->dev, 401}
498 "port stats: %ld bytes in, %ld bytes out\n",
499 priv->bytes_in, priv->bytes_out);
500} /* klsi_105_close */
501
502 402
503/* We need to write a complete 64-byte data block and encode the 403/* We need to write a complete 64-byte data block and encode the
504 * number actually sent in the first double-byte, LSB-order. That 404 * number actually sent in the first double-byte, LSB-order. That
505 * leaves at most 62 bytes of payload. 405 * leaves at most 62 bytes of payload.
506 */ 406 */
507#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ 407#define KLSI_HDR_LEN 2
508 408static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
509 409 void *dest, size_t size)
510static int klsi_105_write(struct tty_struct *tty,
511 struct usb_serial_port *port, const unsigned char *buf, int count)
512{ 410{
513 struct klsi_105_private *priv = usb_get_serial_port_data(port); 411 unsigned char *buf = dest;
514 int result, size; 412 int count;
515 int bytes_sent = 0;
516
517 dbg("%s - port %d", __func__, port->number);
518
519 while (count > 0) {
520 /* try to find a free urb (write 0 bytes if none) */
521 struct urb *urb = NULL;
522 unsigned long flags;
523 int i;
524 /* since the pool is per-port we might not need
525 the spin lock !? */
526 spin_lock_irqsave(&priv->lock, flags);
527 for (i = 0; i < NUM_URBS; i++) {
528 if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
529 urb = priv->write_urb_pool[i];
530 dbg("%s - using pool URB %d", __func__, i);
531 break;
532 }
533 }
534 spin_unlock_irqrestore(&priv->lock, flags);
535
536 if (urb == NULL) {
537 dbg("%s - no more free urbs", __func__);
538 goto exit;
539 }
540
541 if (urb->transfer_buffer == NULL) {
542 urb->transfer_buffer =
543 kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
544 if (urb->transfer_buffer == NULL) {
545 dev_err(&port->dev,
546 "%s - no more kernel memory...\n",
547 __func__);
548 goto exit;
549 }
550 }
551
552 size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
553 size = min(size, URB_TRANSFER_BUFFER_SIZE -
554 KLSI_105_DATA_OFFSET);
555
556 memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
557
558 /* write payload size into transfer buffer */
559 ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
560 ((__u8 *)urb->transfer_buffer)[1] = (__u8) ((size & 0xFF00)>>8);
561
562 /* set up our urb */
563 usb_fill_bulk_urb(urb, port->serial->dev,
564 usb_sndbulkpipe(port->serial->dev,
565 port->bulk_out_endpointAddress),
566 urb->transfer_buffer,
567 URB_TRANSFER_BUFFER_SIZE,
568 klsi_105_write_bulk_callback,
569 port);
570
571 /* send the data out the bulk port */
572 result = usb_submit_urb(urb, GFP_ATOMIC);
573 if (result) {
574 dev_err(&port->dev,
575 "%s - failed submitting write urb, error %d\n",
576 __func__, result);
577 goto exit;
578 }
579 buf += size;
580 bytes_sent += size;
581 count -= size;
582 }
583exit:
584 /* lockless, but it's for debug info only... */
585 priv->bytes_out += bytes_sent;
586
587 return bytes_sent; /* that's how much we wrote */
588} /* klsi_105_write */
589
590static void klsi_105_write_bulk_callback(struct urb *urb)
591{
592 struct usb_serial_port *port = urb->context;
593 int status = urb->status;
594
595 dbg("%s - port %d", __func__, port->number);
596
597 if (status) {
598 dbg("%s - nonzero write bulk status received: %d", __func__,
599 status);
600 return;
601 }
602 413
603 usb_serial_port_softint(port); 414 count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
604} /* klsi_105_write_bulk_completion_callback */ 415 &port->lock);
416 put_unaligned_le16(count, buf);
605 417
606 418 return count + KLSI_HDR_LEN;
607/* return number of characters currently in the writing process */
608static int klsi_105_chars_in_buffer(struct tty_struct *tty)
609{
610 struct usb_serial_port *port = tty->driver_data;
611 int chars = 0;
612 int i;
613 unsigned long flags;
614 struct klsi_105_private *priv = usb_get_serial_port_data(port);
615
616 spin_lock_irqsave(&priv->lock, flags);
617
618 for (i = 0; i < NUM_URBS; ++i) {
619 if (priv->write_urb_pool[i]->status == -EINPROGRESS)
620 chars += URB_TRANSFER_BUFFER_SIZE;
621 }
622
623 spin_unlock_irqrestore(&priv->lock, flags);
624
625 dbg("%s - returns %d", __func__, chars);
626 return chars;
627} 419}
628 420
629static int klsi_105_write_room(struct tty_struct *tty) 421/* The data received is preceded by a length double-byte in LSB-first order.
630{ 422 */
631 struct usb_serial_port *port = tty->driver_data; 423static void klsi_105_process_read_urb(struct urb *urb)
632 unsigned long flags;
633 int i;
634 int room = 0;
635 struct klsi_105_private *priv = usb_get_serial_port_data(port);
636
637 spin_lock_irqsave(&priv->lock, flags);
638 for (i = 0; i < NUM_URBS; ++i) {
639 if (priv->write_urb_pool[i]->status != -EINPROGRESS)
640 room += URB_TRANSFER_BUFFER_SIZE;
641 }
642
643 spin_unlock_irqrestore(&priv->lock, flags);
644
645 dbg("%s - returns %d", __func__, room);
646 return room;
647}
648
649
650
651static void klsi_105_read_bulk_callback(struct urb *urb)
652{ 424{
653 struct usb_serial_port *port = urb->context; 425 struct usb_serial_port *port = urb->context;
654 struct klsi_105_private *priv = usb_get_serial_port_data(port);
655 struct tty_struct *tty;
656 unsigned char *data = urb->transfer_buffer; 426 unsigned char *data = urb->transfer_buffer;
657 int rc; 427 struct tty_struct *tty;
658 int status = urb->status; 428 unsigned len;
659 429
660 dbg("%s - port %d", __func__, port->number); 430 /* empty urbs seem to happen, we ignore them */
431 if (!urb->actual_length)
432 return;
661 433
662 /* The urb might have been killed. */ 434 if (urb->actual_length <= KLSI_HDR_LEN) {
663 if (status) { 435 dbg("%s - malformed packet", __func__);
664 dbg("%s - nonzero read bulk status received: %d", __func__,
665 status);
666 return; 436 return;
667 } 437 }
668 438
669 /* The data received is again preceded by a length double-byte in LSB- 439 tty = tty_port_tty_get(&port->port);
670 * first order (see klsi_105_write() ) 440 if (!tty)
671 */ 441 return;
672 if (urb->actual_length == 0) {
673 /* empty urbs seem to happen, we ignore them */
674 /* dbg("%s - emtpy URB", __func__); */
675 ;
676 } else if (urb->actual_length <= 2) {
677 dbg("%s - size %d URB not understood", __func__,
678 urb->actual_length);
679 usb_serial_debug_data(debug, &port->dev, __func__,
680 urb->actual_length, data);
681 } else {
682 int bytes_sent = ((__u8 *) data)[0] +
683 ((unsigned int) ((__u8 *) data)[1] << 8);
684 tty = tty_port_tty_get(&port->port);
685 /* we should immediately resubmit the URB, before attempting
686 * to pass the data on to the tty layer. But that needs locking
687 * against re-entry an then mixed-up data because of
688 * intermixed tty_flip_buffer_push()s
689 * FIXME
690 */
691 usb_serial_debug_data(debug, &port->dev, __func__,
692 urb->actual_length, data);
693
694 if (bytes_sent + 2 > urb->actual_length) {
695 dbg("%s - trying to read more data than available"
696 " (%d vs. %d)", __func__,
697 bytes_sent+2, urb->actual_length);
698 /* cap at implied limit */
699 bytes_sent = urb->actual_length - 2;
700 }
701
702 tty_insert_flip_string(tty, data + 2, bytes_sent);
703 tty_flip_buffer_push(tty);
704 tty_kref_put(tty);
705 442
706 /* again lockless, but debug info only */ 443 len = get_unaligned_le16(data);
707 priv->bytes_in += bytes_sent; 444 if (len > urb->actual_length - KLSI_HDR_LEN) {
445 dbg("%s - packet length mismatch", __func__);
446 len = urb->actual_length - KLSI_HDR_LEN;
708 } 447 }
709 /* Continue trying to always read */
710 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
711 usb_rcvbulkpipe(port->serial->dev,
712 port->bulk_in_endpointAddress),
713 port->read_urb->transfer_buffer,
714 port->read_urb->transfer_buffer_length,
715 klsi_105_read_bulk_callback,
716 port);
717 rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
718 if (rc)
719 dev_err(&port->dev,
720 "%s - failed resubmitting read urb, error %d\n",
721 __func__, rc);
722} /* klsi_105_read_bulk_callback */
723 448
449 tty_insert_flip_string(tty, data + KLSI_HDR_LEN, len);
450 tty_flip_buffer_push(tty);
451 tty_kref_put(tty);
452}
724 453
725static void klsi_105_set_termios(struct tty_struct *tty, 454static void klsi_105_set_termios(struct tty_struct *tty,
726 struct usb_serial_port *port, 455 struct usb_serial_port *port,
@@ -887,8 +616,7 @@ static void klsi_105_set_termios(struct tty_struct *tty,
887 klsi_105_chg_port_settings(port, cfg); 616 klsi_105_chg_port_settings(port, cfg);
888err: 617err:
889 kfree(cfg); 618 kfree(cfg);
890} /* klsi_105_set_termios */ 619}
891
892 620
893#if 0 621#if 0
894static void mct_u232_break_ctl(struct tty_struct *tty, int break_state) 622static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
@@ -906,7 +634,7 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
906 lcr |= MCT_U232_SET_BREAK; 634 lcr |= MCT_U232_SET_BREAK;
907 635
908 mct_u232_set_line_ctrl(serial, lcr); 636 mct_u232_set_line_ctrl(serial, lcr);
909} /* mct_u232_break_ctl */ 637}
910#endif 638#endif
911 639
912static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file) 640static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
@@ -962,29 +690,6 @@ static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
962 return retval; 690 return retval;
963} 691}
964 692
965static void klsi_105_throttle(struct tty_struct *tty)
966{
967 struct usb_serial_port *port = tty->driver_data;
968 dbg("%s - port %d", __func__, port->number);
969 usb_kill_urb(port->read_urb);
970}
971
972static void klsi_105_unthrottle(struct tty_struct *tty)
973{
974 struct usb_serial_port *port = tty->driver_data;
975 int result;
976
977 dbg("%s - port %d", __func__, port->number);
978
979 port->read_urb->dev = port->serial->dev;
980 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
981 if (result)
982 dev_err(&port->dev,
983 "%s - failed submitting read urb, error %d\n",
984 __func__, result);
985}
986
987
988 693
989static int __init klsi_105_init(void) 694static int __init klsi_105_init(void)
990{ 695{
@@ -1005,7 +710,6 @@ failed_usb_serial_register:
1005 return retval; 710 return retval;
1006} 711}
1007 712
1008
1009static void __exit klsi_105_exit(void) 713static void __exit klsi_105_exit(void)
1010{ 714{
1011 usb_deregister(&kl5kusb105d_driver); 715 usb_deregister(&kl5kusb105d_driver);
@@ -1023,5 +727,3 @@ MODULE_LICENSE("GPL");
1023 727
1024module_param(debug, bool, S_IRUGO | S_IWUSR); 728module_param(debug, bool, S_IRUGO | S_IWUSR);
1025MODULE_PARM_DESC(debug, "enable extensive debugging messages"); 729MODULE_PARM_DESC(debug, "enable extensive debugging messages");
1026
1027/* vim: set sts=8 ts=8 sw=8: */
diff --git a/drivers/usb/serial/kl5kusb105.h b/drivers/usb/serial/kl5kusb105.h
index 1231d9e78398..22a90badc86b 100644
--- a/drivers/usb/serial/kl5kusb105.h
+++ b/drivers/usb/serial/kl5kusb105.h
@@ -17,16 +17,16 @@
17/* baud rates */ 17/* baud rates */
18 18
19enum { 19enum {
20 kl5kusb105a_sio_b115200 = 0, 20 kl5kusb105a_sio_b115200 = 0,
21 kl5kusb105a_sio_b57600 = 1, 21 kl5kusb105a_sio_b57600 = 1,
22 kl5kusb105a_sio_b38400 = 2, 22 kl5kusb105a_sio_b38400 = 2,
23 kl5kusb105a_sio_b19200 = 4, 23 kl5kusb105a_sio_b19200 = 4,
24 kl5kusb105a_sio_b14400 = 5, 24 kl5kusb105a_sio_b14400 = 5,
25 kl5kusb105a_sio_b9600 = 6, 25 kl5kusb105a_sio_b9600 = 6,
26 kl5kusb105a_sio_b4800 = 8, /* unchecked */ 26 kl5kusb105a_sio_b4800 = 8, /* unchecked */
27 kl5kusb105a_sio_b2400 = 9, /* unchecked */ 27 kl5kusb105a_sio_b2400 = 9, /* unchecked */
28 kl5kusb105a_sio_b1200 = 0xa, /* unchecked */ 28 kl5kusb105a_sio_b1200 = 0xa, /* unchecked */
29 kl5kusb105a_sio_b600 = 0xb /* unchecked */ 29 kl5kusb105a_sio_b600 = 0xb /* unchecked */
30}; 30};
31 31
32/* data bits */ 32/* data bits */
@@ -53,17 +53,16 @@ enum {
53#define KL5KUSB105A_CTS ((1<<5) | (1<<4)) 53#define KL5KUSB105A_CTS ((1<<5) | (1<<4))
54 54
55#define KL5KUSB105A_WANTS_TO_SEND 0x30 55#define KL5KUSB105A_WANTS_TO_SEND 0x30
56//#define KL5KUSB105A_DTR /* Data Terminal Ready */ 56#if 0
57//#define KL5KUSB105A_CTS /* Clear To Send */ 57#define KL5KUSB105A_DTR /* Data Terminal Ready */
58//#define KL5KUSB105A_CD /* Carrier Detect */ 58#define KL5KUSB105A_CTS /* Clear To Send */
59//#define KL5KUSB105A_DSR /* Data Set Ready */ 59#define KL5KUSB105A_CD /* Carrier Detect */
60//#define KL5KUSB105A_RxD /* Receive pin */ 60#define KL5KUSB105A_DSR /* Data Set Ready */
61 61#define KL5KUSB105A_RxD /* Receive pin */
62//#define KL5KUSB105A_LE 62
63//#define KL5KUSB105A_RTS 63#define KL5KUSB105A_LE
64//#define KL5KUSB105A_ST 64#define KL5KUSB105A_RTS
65//#define KL5KUSB105A_SR 65#define KL5KUSB105A_ST
66//#define KL5KUSB105A_RI /* Ring Indicator */ 66#define KL5KUSB105A_SR
67 67#define KL5KUSB105A_RI /* Ring Indicator */
68/* vim: set ts=8 sts=8: */ 68#endif
69
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index c113a2a0e10c..bd5bd8589e04 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -345,7 +345,8 @@ static void kobil_close(struct usb_serial_port *port)
345 345
346 /* FIXME: Add rts/dtr methods */ 346 /* FIXME: Add rts/dtr methods */
347 if (port->write_urb) { 347 if (port->write_urb) {
348 usb_kill_urb(port->write_urb); 348 usb_poison_urb(port->write_urb);
349 kfree(port->write_urb->transfer_buffer);
349 usb_free_urb(port->write_urb); 350 usb_free_urb(port->write_urb);
350 port->write_urb = NULL; 351 port->write_urb = NULL;
351 } 352 }
diff --git a/drivers/usb/serial/kobil_sct.h b/drivers/usb/serial/kobil_sct.h
index a51fbb5ae45c..be207f7156fe 100644
--- a/drivers/usb/serial/kobil_sct.h
+++ b/drivers/usb/serial/kobil_sct.h
@@ -23,38 +23,55 @@
23#define SUSBCR_SSL_SETDTR 0x0004 23#define SUSBCR_SSL_SETDTR 0x0004
24#define SUSBCR_SSL_CLRDTR 0x0010 24#define SUSBCR_SSL_CLRDTR 0x0010
25 25
26#define SUSBCR_SSL_PURGE_TXABORT 0x0100 // Kill the pending/current writes to the comm port. 26/* Kill the pending/current writes to the comm port. */
27#define SUSBCR_SSL_PURGE_RXABORT 0x0200 // Kill the pending/current reads to the comm port. 27#define SUSBCR_SSL_PURGE_TXABORT 0x0100
28#define SUSBCR_SSL_PURGE_TXCLEAR 0x0400 // Kill the transmit queue if there. 28/* Kill the pending/current reads to the comm port. */
29#define SUSBCR_SSL_PURGE_RXCLEAR 0x0800 // Kill the typeahead buffer if there. 29#define SUSBCR_SSL_PURGE_RXABORT 0x0200
30/* Kill the transmit queue if there. */
31#define SUSBCR_SSL_PURGE_TXCLEAR 0x0400
32/* Kill the typeahead buffer if there. */
33#define SUSBCR_SSL_PURGE_RXCLEAR 0x0800
30 34
31#define SUSBCRequest_GetStatusLineState 4 35#define SUSBCRequest_GetStatusLineState 4
32#define SUSBCR_GSL_RXCHAR 0x0001 // Any Character received 36/* Any Character received */
33#define SUSBCR_GSL_TXEMPTY 0x0004 // Transmitt Queue Empty 37#define SUSBCR_GSL_RXCHAR 0x0001
34#define SUSBCR_GSL_CTS 0x0008 // CTS changed state 38/* Transmitt Queue Empty */
35#define SUSBCR_GSL_DSR 0x0010 // DSR changed state 39#define SUSBCR_GSL_TXEMPTY 0x0004
36#define SUSBCR_GSL_RLSD 0x0020 // RLSD changed state 40/* CTS changed state */
37#define SUSBCR_GSL_BREAK 0x0040 // BREAK received 41#define SUSBCR_GSL_CTS 0x0008
38#define SUSBCR_GSL_ERR 0x0080 // Line status error occurred 42/* DSR changed state */
39#define SUSBCR_GSL_RING 0x0100 // Ring signal detected 43#define SUSBCR_GSL_DSR 0x0010
44/* RLSD changed state */
45#define SUSBCR_GSL_RLSD 0x0020
46/* BREAK received */
47#define SUSBCR_GSL_BREAK 0x0040
48/* Line status error occurred */
49#define SUSBCR_GSL_ERR 0x0080
50/* Ring signal detected */
51#define SUSBCR_GSL_RING 0x0100
40 52
41#define SUSBCRequest_Misc 8 53#define SUSBCRequest_Misc 8
42#define SUSBCR_MSC_ResetReader 0x0001 // use a predefined reset sequence 54/* use a predefined reset sequence */
43#define SUSBCR_MSC_ResetAllQueues 0x0002 // use a predefined sequence to reset the internal queues 55#define SUSBCR_MSC_ResetReader 0x0001
56/* use a predefined sequence to reset the internal queues */
57#define SUSBCR_MSC_ResetAllQueues 0x0002
44 58
45#define SUSBCRequest_GetMisc 0x10 59#define SUSBCRequest_GetMisc 0x10
46#define SUSBCR_MSC_GetFWVersion 0x0001 /* get the firmware version from device, 60
47 coded like this 0xHHLLBBPP 61/*
48 with HH = Firmware Version High Byte 62 * get the firmware version from device, coded like this 0xHHLLBBPP with
49 LL = Firmware Version Low Byte 63 * HH = Firmware Version High Byte
50 BB = Build Number 64 * LL = Firmware Version Low Byte
51 PP = Further Attributes 65 * BB = Build Number
52 */ 66 * PP = Further Attributes
53 67 */
54#define SUSBCR_MSC_GetHWVersion 0x0002 /* get the hardware version from device 68#define SUSBCR_MSC_GetFWVersion 0x0001
55 coded like this 0xHHLLPPRR 69
56 with HH = Software Version High Byte 70/*
57 LL = Software Version Low Byte 71 * get the hardware version from device coded like this 0xHHLLPPRR with
58 PP = Further Attributes 72 * HH = Software Version High Byte
59 RR = Reserved for the hardware ID 73 * LL = Software Version Low Byte
60 */ 74 * PP = Further Attributes
75 * RR = Reserved for the hardware ID
76 */
77#define SUSBCR_MSC_GetHWVersion 0x0002
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 2849f8c32015..7aa01b95b1d4 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -549,12 +549,9 @@ static void mct_u232_close(struct usb_serial_port *port)
549{ 549{
550 dbg("%s port %d", __func__, port->number); 550 dbg("%s port %d", __func__, port->number);
551 551
552 if (port->serial->dev) { 552 usb_serial_generic_close(port);
553 /* shutdown our urbs */ 553 if (port->serial->dev)
554 usb_kill_urb(port->write_urb);
555 usb_kill_urb(port->read_urb);
556 usb_kill_urb(port->interrupt_in_urb); 554 usb_kill_urb(port->interrupt_in_urb);
557 }
558} /* mct_u232_close */ 555} /* mct_u232_close */
559 556
560 557
diff --git a/drivers/usb/serial/mct_u232.h b/drivers/usb/serial/mct_u232.h
index 7417d5ce1e23..3a3f5e6b8f96 100644
--- a/drivers/usb/serial/mct_u232.h
+++ b/drivers/usb/serial/mct_u232.h
@@ -42,36 +42,44 @@
42#define MCT_U232_SET_REQUEST_TYPE 0x40 42#define MCT_U232_SET_REQUEST_TYPE 0x40
43#define MCT_U232_GET_REQUEST_TYPE 0xc0 43#define MCT_U232_GET_REQUEST_TYPE 0xc0
44 44
45#define MCT_U232_GET_MODEM_STAT_REQUEST 2 /* Get Modem Status Register (MSR) */ 45/* Get Modem Status Register (MSR) */
46#define MCT_U232_GET_MODEM_STAT_SIZE 1 46#define MCT_U232_GET_MODEM_STAT_REQUEST 2
47#define MCT_U232_GET_MODEM_STAT_SIZE 1
47 48
48#define MCT_U232_GET_LINE_CTRL_REQUEST 6 /* Get Line Control Register (LCR) */ 49/* Get Line Control Register (LCR) */
49#define MCT_U232_GET_LINE_CTRL_SIZE 1 /* ... not used by this driver */ 50/* ... not used by this driver */
51#define MCT_U232_GET_LINE_CTRL_REQUEST 6
52#define MCT_U232_GET_LINE_CTRL_SIZE 1
50 53
51#define MCT_U232_SET_BAUD_RATE_REQUEST 5 /* Set Baud Rate Divisor */ 54/* Set Baud Rate Divisor */
52#define MCT_U232_SET_BAUD_RATE_SIZE 4 55#define MCT_U232_SET_BAUD_RATE_REQUEST 5
56#define MCT_U232_SET_BAUD_RATE_SIZE 4
53 57
54#define MCT_U232_SET_LINE_CTRL_REQUEST 7 /* Set Line Control Register (LCR) */ 58/* Set Line Control Register (LCR) */
55#define MCT_U232_SET_LINE_CTRL_SIZE 1 59#define MCT_U232_SET_LINE_CTRL_REQUEST 7
60#define MCT_U232_SET_LINE_CTRL_SIZE 1
56 61
57#define MCT_U232_SET_MODEM_CTRL_REQUEST 10 /* Set Modem Control Register (MCR) */ 62/* Set Modem Control Register (MCR) */
58#define MCT_U232_SET_MODEM_CTRL_SIZE 1 63#define MCT_U232_SET_MODEM_CTRL_REQUEST 10
64#define MCT_U232_SET_MODEM_CTRL_SIZE 1
59 65
60/* This USB device request code is not well understood. It is transmitted by 66/*
61 the MCT-supplied Windows driver whenever the baud rate changes. 67 * This USB device request code is not well understood. It is transmitted by
62*/ 68 * the MCT-supplied Windows driver whenever the baud rate changes.
63#define MCT_U232_SET_UNKNOWN1_REQUEST 11 /* Unknown functionality */ 69 */
64#define MCT_U232_SET_UNKNOWN1_SIZE 1 70#define MCT_U232_SET_UNKNOWN1_REQUEST 11 /* Unknown functionality */
71#define MCT_U232_SET_UNKNOWN1_SIZE 1
65 72
66/* This USB device request code appears to control whether CTS is required 73/*
67 during transmission. 74 * This USB device request code appears to control whether CTS is required
68 75 * during transmission.
69 Sending a zero byte allows data transmission to a device which is not 76 *
70 asserting CTS. Sending a '1' byte will cause transmission to be deferred 77 * Sending a zero byte allows data transmission to a device which is not
71 until the device asserts CTS. 78 * asserting CTS. Sending a '1' byte will cause transmission to be deferred
72*/ 79 * until the device asserts CTS.
73#define MCT_U232_SET_CTS_REQUEST 12 80 */
74#define MCT_U232_SET_CTS_SIZE 1 81#define MCT_U232_SET_CTS_REQUEST 12
82#define MCT_U232_SET_CTS_SIZE 1
75 83
76#define MCT_U232_MAX_SIZE 4 /* of MCT_XXX_SIZE */ 84#define MCT_U232_MAX_SIZE 4 /* of MCT_XXX_SIZE */
77 85
@@ -81,7 +89,8 @@
81 * and "Intel solution". They are the regular MCT and "Sitecom" for us. 89 * and "Intel solution". They are the regular MCT and "Sitecom" for us.
82 * This is pointless to document in the header, see the code for the bits. 90 * This is pointless to document in the header, see the code for the bits.
83 */ 91 */
84static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value, speed_t *result); 92static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
93 speed_t value, speed_t *result);
85 94
86/* 95/*
87 * Line Control Register (LCR) 96 * Line Control Register (LCR)
@@ -125,16 +134,16 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
125/* 134/*
126 * Line Status Register (LSR) 135 * Line Status Register (LSR)
127 */ 136 */
128#define MCT_U232_LSR_INDEX 1 /* data[index] */ 137#define MCT_U232_LSR_INDEX 1 /* data[index] */
129#define MCT_U232_LSR_ERR 0x80 /* OE | PE | FE | BI */ 138#define MCT_U232_LSR_ERR 0x80 /* OE | PE | FE | BI */
130#define MCT_U232_LSR_TEMT 0x40 /* transmit register empty */ 139#define MCT_U232_LSR_TEMT 0x40 /* transmit register empty */
131#define MCT_U232_LSR_THRE 0x20 /* transmit holding register empty */ 140#define MCT_U232_LSR_THRE 0x20 /* transmit holding register empty */
132#define MCT_U232_LSR_BI 0x10 /* break indicator */ 141#define MCT_U232_LSR_BI 0x10 /* break indicator */
133#define MCT_U232_LSR_FE 0x08 /* framing error */ 142#define MCT_U232_LSR_FE 0x08 /* framing error */
134#define MCT_U232_LSR_OE 0x02 /* overrun error */ 143#define MCT_U232_LSR_OE 0x02 /* overrun error */
135#define MCT_U232_LSR_PE 0x04 /* parity error */ 144#define MCT_U232_LSR_PE 0x04 /* parity error */
136#define MCT_U232_LSR_OE 0x02 /* overrun error */ 145#define MCT_U232_LSR_OE 0x02 /* overrun error */
137#define MCT_U232_LSR_DR 0x01 /* receive data ready */ 146#define MCT_U232_LSR_DR 0x01 /* receive data ready */
138 147
139 148
140/* ----------------------------------------------------------------------------- 149/* -----------------------------------------------------------------------------
@@ -143,10 +152,10 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
143 * 152 *
144 * The technical details of the device have been acquired be using "SniffUSB" 153 * The technical details of the device have been acquired be using "SniffUSB"
145 * and the vendor-supplied device driver (version 2.3A) under Windows98. To 154 * and the vendor-supplied device driver (version 2.3A) under Windows98. To
146 * identify the USB vendor-specific requests and to assign them to terminal 155 * identify the USB vendor-specific requests and to assign them to terminal
147 * settings (flow control, baud rate, etc.) the program "SerialSettings" from 156 * settings (flow control, baud rate, etc.) the program "SerialSettings" from
148 * William G. Greathouse has been proven to be very useful. I also used the 157 * William G. Greathouse has been proven to be very useful. I also used the
149 * Win98 "HyperTerminal" and "usb-robot" on Linux for testing. The results and 158 * Win98 "HyperTerminal" and "usb-robot" on Linux for testing. The results and
150 * observations are summarized below: 159 * observations are summarized below:
151 * 160 *
152 * The USB requests seem to be directly mapped to the registers of a 8250, 161 * The USB requests seem to be directly mapped to the registers of a 8250,
@@ -186,33 +195,33 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
186 * Data: LCR (see below) 195 * Data: LCR (see below)
187 * 196 *
188 * Bit 7: Divisor Latch Access Bit (DLAB). When set, access to the data 197 * Bit 7: Divisor Latch Access Bit (DLAB). When set, access to the data
189 * transmit/receive register (THR/RBR) and the Interrupt Enable Register 198 * transmit/receive register (THR/RBR) and the Interrupt Enable Register
190 * (IER) is disabled. Any access to these ports is now redirected to the 199 * (IER) is disabled. Any access to these ports is now redirected to the
191 * Divisor Latch Registers. Setting this bit, loading the Divisor 200 * Divisor Latch Registers. Setting this bit, loading the Divisor
192 * Registers, and clearing DLAB should be done with interrupts disabled. 201 * Registers, and clearing DLAB should be done with interrupts disabled.
193 * Bit 6: Set Break. When set to "1", the transmitter begins to transmit 202 * Bit 6: Set Break. When set to "1", the transmitter begins to transmit
194 * continuous Spacing until this bit is set to "0". This overrides any 203 * continuous Spacing until this bit is set to "0". This overrides any
195 * bits of characters that are being transmitted. 204 * bits of characters that are being transmitted.
196 * Bit 5: Stick Parity. When parity is enabled, setting this bit causes parity 205 * Bit 5: Stick Parity. When parity is enabled, setting this bit causes parity
197 * to always be "1" or "0", based on the value of Bit 4. 206 * to always be "1" or "0", based on the value of Bit 4.
198 * Bit 4: Even Parity Select (EPS). When parity is enabled and Bit 5 is "0", 207 * Bit 4: Even Parity Select (EPS). When parity is enabled and Bit 5 is "0",
199 * setting this bit causes even parity to be transmitted and expected. 208 * setting this bit causes even parity to be transmitted and expected.
200 * Otherwise, odd parity is used. 209 * Otherwise, odd parity is used.
201 * Bit 3: Parity Enable (PEN). When set to "1", a parity bit is inserted 210 * Bit 3: Parity Enable (PEN). When set to "1", a parity bit is inserted
202 * between the last bit of the data and the Stop Bit. The UART will also 211 * between the last bit of the data and the Stop Bit. The UART will also
203 * expect parity to be present in the received data. 212 * expect parity to be present in the received data.
204 * Bit 2: Number of Stop Bits (STB). If set to "1" and using 5-bit data words, 213 * Bit 2: Number of Stop Bits (STB). If set to "1" and using 5-bit data words,
205 * 1.5 Stop Bits are transmitted and expected in each data word. For 214 * 1.5 Stop Bits are transmitted and expected in each data word. For
206 * 6, 7 and 8-bit data words, 2 Stop Bits are transmitted and expected. 215 * 6, 7 and 8-bit data words, 2 Stop Bits are transmitted and expected.
207 * When this bit is set to "0", one Stop Bit is used on each data word. 216 * When this bit is set to "0", one Stop Bit is used on each data word.
208 * Bit 1: Word Length Select Bit #1 (WLSB1) 217 * Bit 1: Word Length Select Bit #1 (WLSB1)
209 * Bit 0: Word Length Select Bit #0 (WLSB0) 218 * Bit 0: Word Length Select Bit #0 (WLSB0)
210 * Together these bits specify the number of bits in each data word. 219 * Together these bits specify the number of bits in each data word.
211 * 1 0 Word Length 220 * 1 0 Word Length
212 * 0 0 5 Data Bits 221 * 0 0 5 Data Bits
213 * 0 1 6 Data Bits 222 * 0 1 6 Data Bits
214 * 1 0 7 Data Bits 223 * 1 0 7 Data Bits
215 * 1 1 8 Data Bits 224 * 1 1 8 Data Bits
216 * 225 *
217 * SniffUSB observations: Bit 7 seems not to be used. There seem to be two bugs 226 * SniffUSB observations: Bit 7 seems not to be used. There seem to be two bugs
218 * in the Win98 driver: the break does not work (bit 6 is not asserted) and the 227 * in the Win98 driver: the break does not work (bit 6 is not asserted) and the
@@ -234,20 +243,20 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
234 * Bit 6: Reserved, always 0. 243 * Bit 6: Reserved, always 0.
235 * Bit 5: Reserved, always 0. 244 * Bit 5: Reserved, always 0.
236 * Bit 4: Loop-Back Enable. When set to "1", the UART transmitter and receiver 245 * Bit 4: Loop-Back Enable. When set to "1", the UART transmitter and receiver
237 * are internally connected together to allow diagnostic operations. In 246 * are internally connected together to allow diagnostic operations. In
238 * addition, the UART modem control outputs are connected to the UART 247 * addition, the UART modem control outputs are connected to the UART
239 * modem control inputs. CTS is connected to RTS, DTR is connected to 248 * modem control inputs. CTS is connected to RTS, DTR is connected to
240 * DSR, OUT1 is connected to RI, and OUT 2 is connected to DCD. 249 * DSR, OUT1 is connected to RI, and OUT 2 is connected to DCD.
241 * Bit 3: OUT 2. An auxiliary output that the host processor may set high or 250 * Bit 3: OUT 2. An auxiliary output that the host processor may set high or
242 * low. In the IBM PC serial adapter (and most clones), OUT 2 is used 251 * low. In the IBM PC serial adapter (and most clones), OUT 2 is used
243 * to tri-state (disable) the interrupt signal from the 252 * to tri-state (disable) the interrupt signal from the
244 * 8250/16450/16550 UART. 253 * 8250/16450/16550 UART.
245 * Bit 2: OUT 1. An auxiliary output that the host processor may set high or 254 * Bit 2: OUT 1. An auxiliary output that the host processor may set high or
246 * low. This output is not used on the IBM PC serial adapter. 255 * low. This output is not used on the IBM PC serial adapter.
247 * Bit 1: Request to Send (RTS). When set to "1", the output of the UART -RTS 256 * Bit 1: Request to Send (RTS). When set to "1", the output of the UART -RTS
248 * line is Low (Active). 257 * line is Low (Active).
249 * Bit 0: Data Terminal Ready (DTR). When set to "1", the output of the UART 258 * Bit 0: Data Terminal Ready (DTR). When set to "1", the output of the UART
250 * -DTR line is Low (Active). 259 * -DTR line is Low (Active).
251 * 260 *
252 * SniffUSB observations: Bit 2 and 4 seem not to be used but bit 3 has been 261 * SniffUSB observations: Bit 2 and 4 seem not to be used but bit 3 has been
253 * seen _always_ set. 262 * seen _always_ set.
@@ -264,22 +273,22 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
264 * Data: MSR (see below) 273 * Data: MSR (see below)
265 * 274 *
266 * Bit 7: Data Carrier Detect (CD). Reflects the state of the DCD line on the 275 * Bit 7: Data Carrier Detect (CD). Reflects the state of the DCD line on the
267 * UART. 276 * UART.
268 * Bit 6: Ring Indicator (RI). Reflects the state of the RI line on the UART. 277 * Bit 6: Ring Indicator (RI). Reflects the state of the RI line on the UART.
269 * Bit 5: Data Set Ready (DSR). Reflects the state of the DSR line on the UART. 278 * Bit 5: Data Set Ready (DSR). Reflects the state of the DSR line on the UART.
270 * Bit 4: Clear To Send (CTS). Reflects the state of the CTS line on the UART. 279 * Bit 4: Clear To Send (CTS). Reflects the state of the CTS line on the UART.
271 * Bit 3: Delta Data Carrier Detect (DDCD). Set to "1" if the -DCD line has 280 * Bit 3: Delta Data Carrier Detect (DDCD). Set to "1" if the -DCD line has
272 * changed state one more more times since the last time the MSR was 281 * changed state one more more times since the last time the MSR was
273 * read by the host. 282 * read by the host.
274 * Bit 2: Trailing Edge Ring Indicator (TERI). Set to "1" if the -RI line has 283 * Bit 2: Trailing Edge Ring Indicator (TERI). Set to "1" if the -RI line has
275 * had a low to high transition since the last time the MSR was read by 284 * had a low to high transition since the last time the MSR was read by
276 * the host. 285 * the host.
277 * Bit 1: Delta Data Set Ready (DDSR). Set to "1" if the -DSR line has changed 286 * Bit 1: Delta Data Set Ready (DDSR). Set to "1" if the -DSR line has changed
278 * state one more more times since the last time the MSR was read by the 287 * state one more more times since the last time the MSR was read by the
279 * host. 288 * host.
280 * Bit 0: Delta Clear To Send (DCTS). Set to "1" if the -CTS line has changed 289 * Bit 0: Delta Clear To Send (DCTS). Set to "1" if the -CTS line has changed
281 * state one more times since the last time the MSR was read by the 290 * state one more times since the last time the MSR was read by the
282 * host. 291 * host.
283 * 292 *
284 * SniffUSB observations: the MSR is also returned as first byte on the 293 * SniffUSB observations: the MSR is also returned as first byte on the
285 * interrupt-in endpoint 0x83 to signal changes of modem status lines. The USB 294 * interrupt-in endpoint 0x83 to signal changes of modem status lines. The USB
@@ -290,31 +299,34 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
290 * -------------------------- 299 * --------------------------
291 * 300 *
292 * Bit 7 Error in Receiver FIFO. On the 8250/16450 UART, this bit is zero. 301 * Bit 7 Error in Receiver FIFO. On the 8250/16450 UART, this bit is zero.
293 * This bit is set to "1" when any of the bytes in the FIFO have one or 302 * This bit is set to "1" when any of the bytes in the FIFO have one
294 * more of the following error conditions: PE, FE, or BI. 303 * or more of the following error conditions: PE, FE, or BI.
295 * Bit 6 Transmitter Empty (TEMT). When set to "1", there are no words 304 * Bit 6 Transmitter Empty (TEMT). When set to "1", there are no words
296 * remaining in the transmit FIFO or the transmit shift register. The 305 * remaining in the transmit FIFO or the transmit shift register. The
297 * transmitter is completely idle. 306 * transmitter is completely idle.
298 * Bit 5 Transmitter Holding Register Empty (THRE). When set to "1", the FIFO 307 * Bit 5 Transmitter Holding Register Empty (THRE). When set to "1", the
299 * (or holding register) now has room for at least one additional word 308 * FIFO (or holding register) now has room for at least one additional
300 * to transmit. The transmitter may still be transmitting when this bit 309 * word to transmit. The transmitter may still be transmitting when
301 * is set to "1". 310 * this bit is set to "1".
302 * Bit 4 Break Interrupt (BI). The receiver has detected a Break signal. 311 * Bit 4 Break Interrupt (BI). The receiver has detected a Break signal.
303 * Bit 3 Framing Error (FE). A Start Bit was detected but the Stop Bit did not 312 * Bit 3 Framing Error (FE). A Start Bit was detected but the Stop Bit did
304 * appear at the expected time. The received word is probably garbled. 313 * not appear at the expected time. The received word is probably
305 * Bit 2 Parity Error (PE). The parity bit was incorrect for the word received. 314 * garbled.
306 * Bit 1 Overrun Error (OE). A new word was received and there was no room in 315 * Bit 2 Parity Error (PE). The parity bit was incorrect for the word
307 * the receive buffer. The newly-arrived word in the shift register is 316 * received.
308 * discarded. On 8250/16450 UARTs, the word in the holding register is 317 * Bit 1 Overrun Error (OE). A new word was received and there was no room
309 * discarded and the newly- arrived word is put in the holding register. 318 * in the receive buffer. The newly-arrived word in the shift register
319 * is discarded. On 8250/16450 UARTs, the word in the holding register
320 * is discarded and the newly- arrived word is put in the holding
321 * register.
310 * Bit 0 Data Ready (DR). One or more words are in the receive FIFO that the 322 * Bit 0 Data Ready (DR). One or more words are in the receive FIFO that the
311 * host may read. A word must be completely received and moved from the 323 * host may read. A word must be completely received and moved from
312 * shift register into the FIFO (or holding register for 8250/16450 324 * the shift register into the FIFO (or holding register for
313 * designs) before this bit is set. 325 * 8250/16450 designs) before this bit is set.
314 * 326 *
315 * SniffUSB observations: the LSR is returned as second byte on the interrupt-in 327 * SniffUSB observations: the LSR is returned as second byte on the
316 * endpoint 0x83 to signal error conditions. Such errors have been seen with 328 * interrupt-in endpoint 0x83 to signal error conditions. Such errors have
317 * minicom/zmodem transfers (CRC errors). 329 * been seen with minicom/zmodem transfers (CRC errors).
318 * 330 *
319 * 331 *
320 * Unknown #1 332 * Unknown #1
@@ -364,16 +376,16 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
364 * -------------- 376 * --------------
365 * 377 *
366 * SniffUSB observations: the bulk-out endpoint 0x1 and interrupt-in endpoint 378 * SniffUSB observations: the bulk-out endpoint 0x1 and interrupt-in endpoint
367 * 0x81 is used to transmit and receive characters. The second interrupt-in 379 * 0x81 is used to transmit and receive characters. The second interrupt-in
368 * endpoint 0x83 signals exceptional conditions like modem line changes and 380 * endpoint 0x83 signals exceptional conditions like modem line changes and
369 * errors. The first byte returned is the MSR and the second byte the LSR. 381 * errors. The first byte returned is the MSR and the second byte the LSR.
370 * 382 *
371 * 383 *
372 * Other observations 384 * Other observations
373 * ------------------ 385 * ------------------
374 * 386 *
375 * Queued bulk transfers like used in visor.c did not work. 387 * Queued bulk transfers like used in visor.c did not work.
376 * 388 *
377 * 389 *
378 * Properties of the USB device used (as found in /var/log/messages) 390 * Properties of the USB device used (as found in /var/log/messages)
379 * ----------------------------------------------------------------- 391 * -----------------------------------------------------------------
@@ -411,26 +423,26 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
411 * bInterface Class:SubClass:Protocol = 00:00:00 423 * bInterface Class:SubClass:Protocol = 00:00:00
412 * iInterface = 00 424 * iInterface = 00
413 * Endpoint: 425 * Endpoint:
414 * bLength = 7 426 * bLength = 7
415 * bDescriptorType = 05 427 * bDescriptorType = 05
416 * bEndpointAddress = 81 (in) 428 * bEndpointAddress = 81 (in)
417 * bmAttributes = 03 (Interrupt) 429 * bmAttributes = 03 (Interrupt)
418 * wMaxPacketSize = 0040 430 * wMaxPacketSize = 0040
419 * bInterval = 02 431 * bInterval = 02
420 * Endpoint: 432 * Endpoint:
421 * bLength = 7 433 * bLength = 7
422 * bDescriptorType = 05 434 * bDescriptorType = 05
423 * bEndpointAddress = 01 (out) 435 * bEndpointAddress = 01 (out)
424 * bmAttributes = 02 (Bulk) 436 * bmAttributes = 02 (Bulk)
425 * wMaxPacketSize = 0040 437 * wMaxPacketSize = 0040
426 * bInterval = 00 438 * bInterval = 00
427 * Endpoint: 439 * Endpoint:
428 * bLength = 7 440 * bLength = 7
429 * bDescriptorType = 05 441 * bDescriptorType = 05
430 * bEndpointAddress = 83 (in) 442 * bEndpointAddress = 83 (in)
431 * bmAttributes = 03 (Interrupt) 443 * bmAttributes = 03 (Interrupt)
432 * wMaxPacketSize = 0002 444 * wMaxPacketSize = 0002
433 * bInterval = 02 445 * bInterval = 02
434 * 446 *
435 * 447 *
436 * Hardware details (added by Martin Hamilton, 2001/12/06) 448 * Hardware details (added by Martin Hamilton, 2001/12/06)
@@ -440,7 +452,7 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
440 * adaptor, which turns out to simply be a re-badged U232-P9. We 452 * adaptor, which turns out to simply be a re-badged U232-P9. We
441 * know this because there is a sticky label on the circuit board 453 * know this because there is a sticky label on the circuit board
442 * which says "U232-P9" ;-) 454 * which says "U232-P9" ;-)
443 * 455 *
444 * The circuit board inside the adaptor contains a Philips PDIUSBD12 456 * The circuit board inside the adaptor contains a Philips PDIUSBD12
445 * USB endpoint chip and a Philips P87C52UBAA microcontroller with 457 * USB endpoint chip and a Philips P87C52UBAA microcontroller with
446 * embedded UART. Exhaustive documentation for these is available at: 458 * embedded UART. Exhaustive documentation for these is available at:
@@ -449,7 +461,7 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial, speed_t value
449 * http://www.semiconductors.philips.com/pip/pdiusbd12 461 * http://www.semiconductors.philips.com/pip/pdiusbd12
450 * 462 *
451 * Thanks to Julian Highfield for the pointer to the Philips database. 463 * Thanks to Julian Highfield for the pointer to the Philips database.
452 * 464 *
453 */ 465 */
454 466
455#endif /* __LINUX_USB_SERIAL_MCT_U232_H */ 467#endif /* __LINUX_USB_SERIAL_MCT_U232_H */
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 0d47f2c4d59f..30922a7e3347 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -34,21 +34,18 @@
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/usb/serial.h> 35#include <linux/usb/serial.h>
36#include <linux/uaccess.h> 36#include <linux/uaccess.h>
37 37#include <linux/parport.h>
38 38
39/* 39/*
40 * Version Information 40 * Version Information
41 */ 41 */
42#define DRIVER_VERSION "1.0.0.4F" 42#define DRIVER_VERSION "2.1"
43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd." 43#define DRIVER_AUTHOR "Aspire Communications pvt Ltd."
44#define DRIVER_DESC "Moschip USB Serial Driver" 44#define DRIVER_DESC "Moschip USB Serial Driver"
45 45
46/* default urb timeout */ 46/* default urb timeout */
47#define MOS_WDR_TIMEOUT (HZ * 5) 47#define MOS_WDR_TIMEOUT (HZ * 5)
48 48
49#define MOS_PORT1 0x0200
50#define MOS_PORT2 0x0300
51#define MOS_VENREG 0x0000
52#define MOS_MAX_PORT 0x02 49#define MOS_MAX_PORT 0x02
53#define MOS_WRITE 0x0E 50#define MOS_WRITE 0x0E
54#define MOS_READ 0x0D 51#define MOS_READ 0x0D
@@ -63,7 +60,7 @@
63#define NUM_URBS 16 /* URB Count */ 60#define NUM_URBS 16 /* URB Count */
64#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 61#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
65 62
66/* This structure holds all of the local port information */ 63/* This structure holds all of the local serial port information */
67struct moschip_port { 64struct moschip_port {
68 __u8 shadowLCR; /* last LCR value received */ 65 __u8 shadowLCR; /* last LCR value received */
69 __u8 shadowMCR; /* last MCR value received */ 66 __u8 shadowMCR; /* last MCR value received */
@@ -74,11 +71,6 @@ struct moschip_port {
74 struct urb *write_urb_pool[NUM_URBS]; 71 struct urb *write_urb_pool[NUM_URBS];
75}; 72};
76 73
77/* This structure holds all of the individual serial device information */
78struct moschip_serial {
79 int interrupt_started;
80};
81
82static int debug; 74static int debug;
83 75
84static struct usb_serial_driver moschip7720_2port_driver; 76static struct usb_serial_driver moschip7720_2port_driver;
@@ -94,6 +86,658 @@ static const struct usb_device_id moschip_port_id_table[] = {
94}; 86};
95MODULE_DEVICE_TABLE(usb, moschip_port_id_table); 87MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
96 88
89#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
90
91/* initial values for parport regs */
92#define DCR_INIT_VAL 0x0c /* SLCTIN, nINIT */
93#define ECR_INIT_VAL 0x00 /* SPP mode */
94
95struct urbtracker {
96 struct mos7715_parport *mos_parport;
97 struct list_head urblist_entry;
98 struct kref ref_count;
99 struct urb *urb;
100};
101
102enum mos7715_pp_modes {
103 SPP = 0<<5,
104 PS2 = 1<<5, /* moschip calls this 'NIBBLE' mode */
105 PPF = 2<<5, /* moschip calls this 'CB-FIFO mode */
106};
107
108struct mos7715_parport {
109 struct parport *pp; /* back to containing struct */
110 struct kref ref_count; /* to instance of this struct */
111 struct list_head deferred_urbs; /* list deferred async urbs */
112 struct list_head active_urbs; /* list async urbs in flight */
113 spinlock_t listlock; /* protects list access */
114 bool msg_pending; /* usb sync call pending */
115 struct completion syncmsg_compl; /* usb sync call completed */
116 struct tasklet_struct urb_tasklet; /* for sending deferred urbs */
117 struct usb_serial *serial; /* back to containing struct */
118 __u8 shadowECR; /* parallel port regs... */
119 __u8 shadowDCR;
120 atomic_t shadowDSR; /* updated in int-in callback */
121};
122
123/* lock guards against dereferencing NULL ptr in parport ops callbacks */
124static DEFINE_SPINLOCK(release_lock);
125
126#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
127
128static const unsigned int dummy; /* for clarity in register access fns */
129
130enum mos_regs {
131 THR, /* serial port regs */
132 RHR,
133 IER,
134 FCR,
135 ISR,
136 LCR,
137 MCR,
138 LSR,
139 MSR,
140 SPR,
141 DLL,
142 DLM,
143 DPR, /* parallel port regs */
144 DSR,
145 DCR,
146 ECR,
147 SP1_REG, /* device control regs */
148 SP2_REG, /* serial port 2 (7720 only) */
149 PP_REG,
150 SP_CONTROL_REG,
151};
152
153/*
154 * Return the correct value for the Windex field of the setup packet
155 * for a control endpoint message. See the 7715 datasheet.
156 */
157static inline __u16 get_reg_index(enum mos_regs reg)
158{
159 static const __u16 mos7715_index_lookup_table[] = {
160 0x00, /* THR */
161 0x00, /* RHR */
162 0x01, /* IER */
163 0x02, /* FCR */
164 0x02, /* ISR */
165 0x03, /* LCR */
166 0x04, /* MCR */
167 0x05, /* LSR */
168 0x06, /* MSR */
169 0x07, /* SPR */
170 0x00, /* DLL */
171 0x01, /* DLM */
172 0x00, /* DPR */
173 0x01, /* DSR */
174 0x02, /* DCR */
175 0x0a, /* ECR */
176 0x01, /* SP1_REG */
177 0x02, /* SP2_REG (7720 only) */
178 0x04, /* PP_REG (7715 only) */
179 0x08, /* SP_CONTROL_REG */
180 };
181 return mos7715_index_lookup_table[reg];
182}
183
184/*
185 * Return the correct value for the upper byte of the Wvalue field of
186 * the setup packet for a control endpoint message.
187 */
188static inline __u16 get_reg_value(enum mos_regs reg,
189 unsigned int serial_portnum)
190{
191 if (reg >= SP1_REG) /* control reg */
192 return 0x0000;
193
194 else if (reg >= DPR) /* parallel port reg (7715 only) */
195 return 0x0100;
196
197 else /* serial port reg */
198 return (serial_portnum + 2) << 8;
199}
200
201/*
202 * Write data byte to the specified device register. The data is embedded in
203 * the value field of the setup packet. serial_portnum is ignored for registers
204 * not specific to a particular serial port.
205 */
206static int write_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
207 enum mos_regs reg, __u8 data)
208{
209 struct usb_device *usbdev = serial->dev;
210 unsigned int pipe = usb_sndctrlpipe(usbdev, 0);
211 __u8 request = (__u8)0x0e;
212 __u8 requesttype = (__u8)0x40;
213 __u16 index = get_reg_index(reg);
214 __u16 value = get_reg_value(reg, serial_portnum) + data;
215 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
216 index, NULL, 0, MOS_WDR_TIMEOUT);
217 if (status < 0)
218 dev_err(&usbdev->dev,
219 "mos7720: usb_control_msg() failed: %d", status);
220 return status;
221}
222
223/*
224 * Read data byte from the specified device register. The data returned by the
225 * device is embedded in the value field of the setup packet. serial_portnum is
226 * ignored for registers that are not specific to a particular serial port.
227 */
228static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
229 enum mos_regs reg, __u8 *data)
230{
231 struct usb_device *usbdev = serial->dev;
232 unsigned int pipe = usb_rcvctrlpipe(usbdev, 0);
233 __u8 request = (__u8)0x0d;
234 __u8 requesttype = (__u8)0xc0;
235 __u16 index = get_reg_index(reg);
236 __u16 value = get_reg_value(reg, serial_portnum);
237 int status = usb_control_msg(usbdev, pipe, request, requesttype, value,
238 index, data, 1, MOS_WDR_TIMEOUT);
239 if (status < 0)
240 dev_err(&usbdev->dev,
241 "mos7720: usb_control_msg() failed: %d", status);
242 return status;
243}
244
245#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
246
247static inline int mos7715_change_mode(struct mos7715_parport *mos_parport,
248 enum mos7715_pp_modes mode)
249{
250 mos_parport->shadowECR = mode;
251 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
252 return 0;
253}
254
255static void destroy_mos_parport(struct kref *kref)
256{
257 struct mos7715_parport *mos_parport =
258 container_of(kref, struct mos7715_parport, ref_count);
259
260 dbg("%s called", __func__);
261 kfree(mos_parport);
262}
263
264static void destroy_urbtracker(struct kref *kref)
265{
266 struct urbtracker *urbtrack =
267 container_of(kref, struct urbtracker, ref_count);
268 struct mos7715_parport *mos_parport = urbtrack->mos_parport;
269 dbg("%s called", __func__);
270 usb_free_urb(urbtrack->urb);
271 kfree(urbtrack);
272 kref_put(&mos_parport->ref_count, destroy_mos_parport);
273}
274
275/*
276 * This runs as a tasklet when sending an urb in a non-blocking parallel
277 * port callback had to be deferred because the disconnect mutex could not be
278 * obtained at the time.
279 */
280static void send_deferred_urbs(unsigned long _mos_parport)
281{
282 int ret_val;
283 unsigned long flags;
284 struct mos7715_parport *mos_parport = (void *)_mos_parport;
285 struct urbtracker *urbtrack;
286 struct list_head *cursor, *next;
287
288 dbg("%s called", __func__);
289
290 /* if release function ran, game over */
291 if (unlikely(mos_parport->serial == NULL))
292 return;
293
294 /* try again to get the mutex */
295 if (!mutex_trylock(&mos_parport->serial->disc_mutex)) {
296 dbg("%s: rescheduling tasklet", __func__);
297 tasklet_schedule(&mos_parport->urb_tasklet);
298 return;
299 }
300
301 /* if device disconnected, game over */
302 if (unlikely(mos_parport->serial->disconnected)) {
303 mutex_unlock(&mos_parport->serial->disc_mutex);
304 return;
305 }
306
307 spin_lock_irqsave(&mos_parport->listlock, flags);
308 if (list_empty(&mos_parport->deferred_urbs)) {
309 spin_unlock_irqrestore(&mos_parport->listlock, flags);
310 mutex_unlock(&mos_parport->serial->disc_mutex);
311 dbg("%s: deferred_urbs list empty", __func__);
312 return;
313 }
314
315 /* move contents of deferred_urbs list to active_urbs list and submit */
316 list_for_each_safe(cursor, next, &mos_parport->deferred_urbs)
317 list_move_tail(cursor, &mos_parport->active_urbs);
318 list_for_each_entry(urbtrack, &mos_parport->active_urbs,
319 urblist_entry) {
320 ret_val = usb_submit_urb(urbtrack->urb, GFP_ATOMIC);
321 dbg("%s: urb submitted", __func__);
322 if (ret_val) {
323 dev_err(&mos_parport->serial->dev->dev,
324 "usb_submit_urb() failed: %d", ret_val);
325 list_del(&urbtrack->urblist_entry);
326 kref_put(&urbtrack->ref_count, destroy_urbtracker);
327 }
328 }
329 spin_unlock_irqrestore(&mos_parport->listlock, flags);
330 mutex_unlock(&mos_parport->serial->disc_mutex);
331}
332
333/* callback for parallel port control urbs submitted asynchronously */
334static void async_complete(struct urb *urb)
335{
336 struct urbtracker *urbtrack = urb->context;
337 int status = urb->status;
338 dbg("%s called", __func__);
339 if (unlikely(status))
340 dbg("%s - nonzero urb status received: %d", __func__, status);
341
342 /* remove the urbtracker from the active_urbs list */
343 spin_lock(&urbtrack->mos_parport->listlock);
344 list_del(&urbtrack->urblist_entry);
345 spin_unlock(&urbtrack->mos_parport->listlock);
346 kref_put(&urbtrack->ref_count, destroy_urbtracker);
347}
348
349static int write_parport_reg_nonblock(struct mos7715_parport *mos_parport,
350 enum mos_regs reg, __u8 data)
351{
352 struct urbtracker *urbtrack;
353 int ret_val;
354 unsigned long flags;
355 struct usb_ctrlrequest setup;
356 struct usb_serial *serial = mos_parport->serial;
357 struct usb_device *usbdev = serial->dev;
358 dbg("%s called", __func__);
359
360 /* create and initialize the control urb and containing urbtracker */
361 urbtrack = kmalloc(sizeof(struct urbtracker), GFP_ATOMIC);
362 if (urbtrack == NULL) {
363 dev_err(&usbdev->dev, "out of memory");
364 return -ENOMEM;
365 }
366 kref_get(&mos_parport->ref_count);
367 urbtrack->mos_parport = mos_parport;
368 urbtrack->urb = usb_alloc_urb(0, GFP_ATOMIC);
369 if (urbtrack->urb == NULL) {
370 dev_err(&usbdev->dev, "out of urbs");
371 kfree(urbtrack);
372 return -ENOMEM;
373 }
374 setup.bRequestType = (__u8)0x40;
375 setup.bRequest = (__u8)0x0e;
376 setup.wValue = get_reg_value(reg, dummy);
377 setup.wIndex = get_reg_index(reg);
378 setup.wLength = 0;
379 usb_fill_control_urb(urbtrack->urb, usbdev,
380 usb_sndctrlpipe(usbdev, 0),
381 (unsigned char *)&setup,
382 NULL, 0, async_complete, urbtrack);
383 kref_init(&urbtrack->ref_count);
384 INIT_LIST_HEAD(&urbtrack->urblist_entry);
385
386 /*
387 * get the disconnect mutex, or add tracker to the deferred_urbs list
388 * and schedule a tasklet to try again later
389 */
390 if (!mutex_trylock(&serial->disc_mutex)) {
391 spin_lock_irqsave(&mos_parport->listlock, flags);
392 list_add_tail(&urbtrack->urblist_entry,
393 &mos_parport->deferred_urbs);
394 spin_unlock_irqrestore(&mos_parport->listlock, flags);
395 tasklet_schedule(&mos_parport->urb_tasklet);
396 dbg("tasklet scheduled");
397 return 0;
398 }
399
400 /* bail if device disconnected */
401 if (serial->disconnected) {
402 kref_put(&urbtrack->ref_count, destroy_urbtracker);
403 mutex_unlock(&serial->disc_mutex);
404 return -ENODEV;
405 }
406
407 /* add the tracker to the active_urbs list and submit */
408 spin_lock_irqsave(&mos_parport->listlock, flags);
409 list_add_tail(&urbtrack->urblist_entry, &mos_parport->active_urbs);
410 spin_unlock_irqrestore(&mos_parport->listlock, flags);
411 ret_val = usb_submit_urb(urbtrack->urb, GFP_ATOMIC);
412 mutex_unlock(&serial->disc_mutex);
413 if (ret_val) {
414 dev_err(&usbdev->dev,
415 "%s: submit_urb() failed: %d", __func__, ret_val);
416 spin_lock_irqsave(&mos_parport->listlock, flags);
417 list_del(&urbtrack->urblist_entry);
418 spin_unlock_irqrestore(&mos_parport->listlock, flags);
419 kref_put(&urbtrack->ref_count, destroy_urbtracker);
420 return ret_val;
421 }
422 return 0;
423}
424
425/*
426 * This is the the common top part of all parallel port callback operations that
427 * send synchronous messages to the device. This implements convoluted locking
428 * that avoids two scenarios: (1) a port operation is called after usbserial
429 * has called our release function, at which point struct mos7715_parport has
430 * been destroyed, and (2) the device has been disconnected, but usbserial has
431 * not called the release function yet because someone has a serial port open.
432 * The shared release_lock prevents the first, and the mutex and disconnected
433 * flag maintained by usbserial covers the second. We also use the msg_pending
434 * flag to ensure that all synchronous usb messgage calls have completed before
435 * our release function can return.
436 */
437static int parport_prologue(struct parport *pp)
438{
439 struct mos7715_parport *mos_parport;
440
441 spin_lock(&release_lock);
442 mos_parport = pp->private_data;
443 if (unlikely(mos_parport == NULL)) {
444 /* release fn called, port struct destroyed */
445 spin_unlock(&release_lock);
446 return -1;
447 }
448 mos_parport->msg_pending = true; /* synch usb call pending */
449 INIT_COMPLETION(mos_parport->syncmsg_compl);
450 spin_unlock(&release_lock);
451
452 mutex_lock(&mos_parport->serial->disc_mutex);
453 if (mos_parport->serial->disconnected) {
454 /* device disconnected */
455 mutex_unlock(&mos_parport->serial->disc_mutex);
456 mos_parport->msg_pending = false;
457 complete(&mos_parport->syncmsg_compl);
458 return -1;
459 }
460
461 return 0;
462}
463
464/*
465 * This is the the common bottom part of all parallel port functions that send
466 * synchronous messages to the device.
467 */
468static inline void parport_epilogue(struct parport *pp)
469{
470 struct mos7715_parport *mos_parport = pp->private_data;
471 mutex_unlock(&mos_parport->serial->disc_mutex);
472 mos_parport->msg_pending = false;
473 complete(&mos_parport->syncmsg_compl);
474}
475
476static void parport_mos7715_write_data(struct parport *pp, unsigned char d)
477{
478 struct mos7715_parport *mos_parport = pp->private_data;
479 dbg("%s called: %2.2x", __func__, d);
480 if (parport_prologue(pp) < 0)
481 return;
482 mos7715_change_mode(mos_parport, SPP);
483 write_mos_reg(mos_parport->serial, dummy, DPR, (__u8)d);
484 parport_epilogue(pp);
485}
486
487static unsigned char parport_mos7715_read_data(struct parport *pp)
488{
489 struct mos7715_parport *mos_parport = pp->private_data;
490 unsigned char d;
491 dbg("%s called", __func__);
492 if (parport_prologue(pp) < 0)
493 return 0;
494 read_mos_reg(mos_parport->serial, dummy, DPR, &d);
495 parport_epilogue(pp);
496 return d;
497}
498
499static void parport_mos7715_write_control(struct parport *pp, unsigned char d)
500{
501 struct mos7715_parport *mos_parport = pp->private_data;
502 __u8 data;
503 dbg("%s called: %2.2x", __func__, d);
504 if (parport_prologue(pp) < 0)
505 return;
506 data = ((__u8)d & 0x0f) | (mos_parport->shadowDCR & 0xf0);
507 write_mos_reg(mos_parport->serial, dummy, DCR, data);
508 mos_parport->shadowDCR = data;
509 parport_epilogue(pp);
510}
511
512static unsigned char parport_mos7715_read_control(struct parport *pp)
513{
514 struct mos7715_parport *mos_parport = pp->private_data;
515 __u8 dcr;
516 dbg("%s called", __func__);
517 spin_lock(&release_lock);
518 mos_parport = pp->private_data;
519 if (unlikely(mos_parport == NULL)) {
520 spin_unlock(&release_lock);
521 return 0;
522 }
523 dcr = mos_parport->shadowDCR & 0x0f;
524 spin_unlock(&release_lock);
525 return dcr;
526}
527
528static unsigned char parport_mos7715_frob_control(struct parport *pp,
529 unsigned char mask,
530 unsigned char val)
531{
532 struct mos7715_parport *mos_parport = pp->private_data;
533 __u8 dcr;
534 dbg("%s called", __func__);
535 mask &= 0x0f;
536 val &= 0x0f;
537 if (parport_prologue(pp) < 0)
538 return 0;
539 mos_parport->shadowDCR = (mos_parport->shadowDCR & (~mask)) ^ val;
540 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
541 dcr = mos_parport->shadowDCR & 0x0f;
542 parport_epilogue(pp);
543 return dcr;
544}
545
546static unsigned char parport_mos7715_read_status(struct parport *pp)
547{
548 unsigned char status;
549 struct mos7715_parport *mos_parport = pp->private_data;
550 dbg("%s called", __func__);
551 spin_lock(&release_lock);
552 mos_parport = pp->private_data;
553 if (unlikely(mos_parport == NULL)) { /* release called */
554 spin_unlock(&release_lock);
555 return 0;
556 }
557 status = atomic_read(&mos_parport->shadowDSR) & 0xf8;
558 spin_unlock(&release_lock);
559 return status;
560}
561
562static void parport_mos7715_enable_irq(struct parport *pp)
563{
564 dbg("%s called", __func__);
565}
566static void parport_mos7715_disable_irq(struct parport *pp)
567{
568 dbg("%s called", __func__);
569}
570
571static void parport_mos7715_data_forward(struct parport *pp)
572{
573 struct mos7715_parport *mos_parport = pp->private_data;
574 dbg("%s called", __func__);
575 if (parport_prologue(pp) < 0)
576 return;
577 mos7715_change_mode(mos_parport, PS2);
578 mos_parport->shadowDCR &= ~0x20;
579 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
580 parport_epilogue(pp);
581}
582
583static void parport_mos7715_data_reverse(struct parport *pp)
584{
585 struct mos7715_parport *mos_parport = pp->private_data;
586 dbg("%s called", __func__);
587 if (parport_prologue(pp) < 0)
588 return;
589 mos7715_change_mode(mos_parport, PS2);
590 mos_parport->shadowDCR |= 0x20;
591 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
592 parport_epilogue(pp);
593}
594
595static void parport_mos7715_init_state(struct pardevice *dev,
596 struct parport_state *s)
597{
598 dbg("%s called", __func__);
599 s->u.pc.ctr = DCR_INIT_VAL;
600 s->u.pc.ecr = ECR_INIT_VAL;
601}
602
603/* N.B. Parport core code requires that this function not block */
604static void parport_mos7715_save_state(struct parport *pp,
605 struct parport_state *s)
606{
607 struct mos7715_parport *mos_parport;
608 dbg("%s called", __func__);
609 spin_lock(&release_lock);
610 mos_parport = pp->private_data;
611 if (unlikely(mos_parport == NULL)) { /* release called */
612 spin_unlock(&release_lock);
613 return;
614 }
615 s->u.pc.ctr = mos_parport->shadowDCR;
616 s->u.pc.ecr = mos_parport->shadowECR;
617 spin_unlock(&release_lock);
618}
619
620/* N.B. Parport core code requires that this function not block */
621static void parport_mos7715_restore_state(struct parport *pp,
622 struct parport_state *s)
623{
624 struct mos7715_parport *mos_parport;
625 dbg("%s called", __func__);
626 spin_lock(&release_lock);
627 mos_parport = pp->private_data;
628 if (unlikely(mos_parport == NULL)) { /* release called */
629 spin_unlock(&release_lock);
630 return;
631 }
632 write_parport_reg_nonblock(mos_parport, DCR, mos_parport->shadowDCR);
633 write_parport_reg_nonblock(mos_parport, ECR, mos_parport->shadowECR);
634 spin_unlock(&release_lock);
635}
636
637static size_t parport_mos7715_write_compat(struct parport *pp,
638 const void *buffer,
639 size_t len, int flags)
640{
641 int retval;
642 struct mos7715_parport *mos_parport = pp->private_data;
643 int actual_len;
644 dbg("%s called: %u chars", __func__, (unsigned int)len);
645 if (parport_prologue(pp) < 0)
646 return 0;
647 mos7715_change_mode(mos_parport, PPF);
648 retval = usb_bulk_msg(mos_parport->serial->dev,
649 usb_sndbulkpipe(mos_parport->serial->dev, 2),
650 (void *)buffer, len, &actual_len,
651 MOS_WDR_TIMEOUT);
652 parport_epilogue(pp);
653 if (retval) {
654 dev_err(&mos_parport->serial->dev->dev,
655 "mos7720: usb_bulk_msg() failed: %d", retval);
656 return 0;
657 }
658 return actual_len;
659}
660
661static struct parport_operations parport_mos7715_ops = {
662 .owner = THIS_MODULE,
663 .write_data = parport_mos7715_write_data,
664 .read_data = parport_mos7715_read_data,
665
666 .write_control = parport_mos7715_write_control,
667 .read_control = parport_mos7715_read_control,
668 .frob_control = parport_mos7715_frob_control,
669
670 .read_status = parport_mos7715_read_status,
671
672 .enable_irq = parport_mos7715_enable_irq,
673 .disable_irq = parport_mos7715_disable_irq,
674
675 .data_forward = parport_mos7715_data_forward,
676 .data_reverse = parport_mos7715_data_reverse,
677
678 .init_state = parport_mos7715_init_state,
679 .save_state = parport_mos7715_save_state,
680 .restore_state = parport_mos7715_restore_state,
681
682 .compat_write_data = parport_mos7715_write_compat,
683
684 .nibble_read_data = parport_ieee1284_read_nibble,
685 .byte_read_data = parport_ieee1284_read_byte,
686};
687
688/*
689 * Allocate and initialize parallel port control struct, initialize
690 * the parallel port hardware device, and register with the parport subsystem.
691 */
692static int mos7715_parport_init(struct usb_serial *serial)
693{
694 struct mos7715_parport *mos_parport;
695
696 /* allocate and initialize parallel port control struct */
697 mos_parport = kzalloc(sizeof(struct mos7715_parport), GFP_KERNEL);
698 if (mos_parport == NULL) {
699 dbg("mos7715_parport_init: kzalloc failed");
700 return -ENOMEM;
701 }
702 mos_parport->msg_pending = false;
703 kref_init(&mos_parport->ref_count);
704 spin_lock_init(&mos_parport->listlock);
705 INIT_LIST_HEAD(&mos_parport->active_urbs);
706 INIT_LIST_HEAD(&mos_parport->deferred_urbs);
707 usb_set_serial_data(serial, mos_parport); /* hijack private pointer */
708 mos_parport->serial = serial;
709 tasklet_init(&mos_parport->urb_tasklet, send_deferred_urbs,
710 (unsigned long) mos_parport);
711 init_completion(&mos_parport->syncmsg_compl);
712
713 /* cycle parallel port reset bit */
714 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x80);
715 write_mos_reg(mos_parport->serial, dummy, PP_REG, (__u8)0x00);
716
717 /* initialize device registers */
718 mos_parport->shadowDCR = DCR_INIT_VAL;
719 write_mos_reg(mos_parport->serial, dummy, DCR, mos_parport->shadowDCR);
720 mos_parport->shadowECR = ECR_INIT_VAL;
721 write_mos_reg(mos_parport->serial, dummy, ECR, mos_parport->shadowECR);
722
723 /* register with parport core */
724 mos_parport->pp = parport_register_port(0, PARPORT_IRQ_NONE,
725 PARPORT_DMA_NONE,
726 &parport_mos7715_ops);
727 if (mos_parport->pp == NULL) {
728 dev_err(&serial->interface->dev,
729 "Could not register parport\n");
730 kref_put(&mos_parport->ref_count, destroy_mos_parport);
731 return -EIO;
732 }
733 mos_parport->pp->private_data = mos_parport;
734 mos_parport->pp->modes = PARPORT_MODE_COMPAT | PARPORT_MODE_PCSPP;
735 mos_parport->pp->dev = &serial->interface->dev;
736 parport_announce_port(mos_parport->pp);
737
738 return 0;
739}
740#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
97 741
98/* 742/*
99 * mos7720_interrupt_callback 743 * mos7720_interrupt_callback
@@ -109,8 +753,6 @@ static void mos7720_interrupt_callback(struct urb *urb)
109 __u8 sp1; 753 __u8 sp1;
110 __u8 sp2; 754 __u8 sp2;
111 755
112 dbg(" : Entering");
113
114 switch (status) { 756 switch (status) {
115 case 0: 757 case 0:
116 /* success */ 758 /* success */
@@ -161,7 +803,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
161 dbg("Serial Port 1: Receiver time out"); 803 dbg("Serial Port 1: Receiver time out");
162 break; 804 break;
163 case SERIAL_IIR_MS: 805 case SERIAL_IIR_MS:
164 dbg("Serial Port 1: Modem status change"); 806 /* dbg("Serial Port 1: Modem status change"); */
165 break; 807 break;
166 } 808 }
167 809
@@ -174,7 +816,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
174 dbg("Serial Port 2: Receiver time out"); 816 dbg("Serial Port 2: Receiver time out");
175 break; 817 break;
176 case SERIAL_IIR_MS: 818 case SERIAL_IIR_MS:
177 dbg("Serial Port 2: Modem status change"); 819 /* dbg("Serial Port 2: Modem status change"); */
178 break; 820 break;
179 } 821 }
180 } 822 }
@@ -208,6 +850,7 @@ static void mos7715_interrupt_callback(struct urb *urb)
208 case -ECONNRESET: 850 case -ECONNRESET:
209 case -ENOENT: 851 case -ENOENT:
210 case -ESHUTDOWN: 852 case -ESHUTDOWN:
853 case -ENODEV:
211 /* this urb is terminated, clean up */ 854 /* this urb is terminated, clean up */
212 dbg("%s - urb shutting down with status: %d", __func__, 855 dbg("%s - urb shutting down with status: %d", __func__,
213 status); 856 status);
@@ -243,11 +886,21 @@ static void mos7715_interrupt_callback(struct urb *urb)
243 dbg("Serial Port: Receiver time out"); 886 dbg("Serial Port: Receiver time out");
244 break; 887 break;
245 case SERIAL_IIR_MS: 888 case SERIAL_IIR_MS:
246 dbg("Serial Port: Modem status change"); 889 /* dbg("Serial Port: Modem status change"); */
247 break; 890 break;
248 } 891 }
249 } 892 }
250 893
894#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
895 { /* update local copy of DSR reg */
896 struct usb_serial_port *port = urb->context;
897 struct mos7715_parport *mos_parport = port->serial->private;
898 if (unlikely(mos_parport == NULL))
899 return;
900 atomic_set(&mos_parport->shadowDSR, data[2]);
901 }
902#endif
903
251exit: 904exit:
252 result = usb_submit_urb(urb, GFP_ATOMIC); 905 result = usb_submit_urb(urb, GFP_ATOMIC);
253 if (result) 906 if (result)
@@ -267,7 +920,6 @@ static void mos7720_bulk_in_callback(struct urb *urb)
267 int retval; 920 int retval;
268 unsigned char *data ; 921 unsigned char *data ;
269 struct usb_serial_port *port; 922 struct usb_serial_port *port;
270 struct moschip_port *mos7720_port;
271 struct tty_struct *tty; 923 struct tty_struct *tty;
272 int status = urb->status; 924 int status = urb->status;
273 925
@@ -276,13 +928,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
276 return; 928 return;
277 } 929 }
278 930
279 mos7720_port = urb->context; 931 port = urb->context;
280 if (!mos7720_port) {
281 dbg("NULL mos7720_port pointer");
282 return ;
283 }
284
285 port = mos7720_port->port;
286 932
287 dbg("Entering...%s", __func__); 933 dbg("Entering...%s", __func__);
288 934
@@ -332,8 +978,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
332 return ; 978 return ;
333 } 979 }
334 980
335 dbg("Entering .........");
336
337 tty = tty_port_tty_get(&mos7720_port->port->port); 981 tty = tty_port_tty_get(&mos7720_port->port->port);
338 982
339 if (tty && mos7720_port->open) 983 if (tty && mos7720_port->open)
@@ -342,56 +986,6 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
342} 986}
343 987
344/* 988/*
345 * send_mos_cmd
346 * this function will be used for sending command to device
347 */
348static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
349 __u16 index, u8 *data)
350{
351 int status;
352 u8 *buf;
353 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
354
355 if (value < MOS_MAX_PORT) {
356 if (product == MOSCHIP_DEVICE_ID_7715)
357 value = 0x0200; /* identifies the 7715's serial port */
358 else
359 value = value*0x100+0x200;
360 } else {
361 value = 0x0000;
362 if ((product == MOSCHIP_DEVICE_ID_7715) &&
363 (index != 0x08)) {
364 dbg("serial->product== MOSCHIP_DEVICE_ID_7715");
365 /* index = 0x01 ; */
366 }
367 }
368
369 if (request == MOS_WRITE) {
370 value = value + *data;
371 status = usb_control_msg(serial->dev,
372 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
373 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
374 } else {
375 buf = kmalloc(1, GFP_KERNEL);
376 if (!buf) {
377 status = -ENOMEM;
378 goto out;
379 }
380 status = usb_control_msg(serial->dev,
381 usb_rcvctrlpipe(serial->dev, 0), MOS_READ,
382 0xc0, value, index, buf, 1, MOS_WDR_TIMEOUT);
383 *data = *buf;
384 kfree(buf);
385 }
386out:
387 if (status < 0)
388 dbg("Command Write failed Value %x index %x", value, index);
389
390 return status;
391}
392
393
394/*
395 * mos77xx_probe 989 * mos77xx_probe
396 * this function installs the appropriate read interrupt endpoint callback 990 * this function installs the appropriate read interrupt endpoint callback
397 * depending on whether the device is a 7720 or 7715, thus avoiding costly 991 * depending on whether the device is a 7720 or 7715, thus avoiding costly
@@ -424,11 +1018,10 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
424 struct usb_serial *serial; 1018 struct usb_serial *serial;
425 struct usb_serial_port *port0; 1019 struct usb_serial_port *port0;
426 struct urb *urb; 1020 struct urb *urb;
427 struct moschip_serial *mos7720_serial;
428 struct moschip_port *mos7720_port; 1021 struct moschip_port *mos7720_port;
429 int response; 1022 int response;
430 int port_number; 1023 int port_number;
431 char data; 1024 __u8 data;
432 int allocated_urbs = 0; 1025 int allocated_urbs = 0;
433 int j; 1026 int j;
434 1027
@@ -440,11 +1033,6 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
440 1033
441 port0 = serial->port[0]; 1034 port0 = serial->port[0];
442 1035
443 mos7720_serial = usb_get_serial_data(serial);
444
445 if (mos7720_serial == NULL || port0 == NULL)
446 return -ENODEV;
447
448 usb_clear_halt(serial->dev, port->write_urb->pipe); 1036 usb_clear_halt(serial->dev, port->write_urb->pipe);
449 usb_clear_halt(serial->dev, port->read_urb->pipe); 1037 usb_clear_halt(serial->dev, port->read_urb->pipe);
450 1038
@@ -489,103 +1077,36 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
489 * 0x08 : SP1/2 Control Reg 1077 * 0x08 : SP1/2 Control Reg
490 */ 1078 */
491 port_number = port->number - port->serial->minor; 1079 port_number = port->number - port->serial->minor;
492 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 1080 read_mos_reg(serial, port_number, LSR, &data);
1081
493 dbg("SS::%p LSR:%x", mos7720_port, data); 1082 dbg("SS::%p LSR:%x", mos7720_port, data);
494 1083
495 dbg("Check:Sending Command .........."); 1084 dbg("Check:Sending Command ..........");
496 1085
497 data = 0x02; 1086 write_mos_reg(serial, dummy, SP1_REG, 0x02);
498 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x01, &data); 1087 write_mos_reg(serial, dummy, SP2_REG, 0x02);
499 data = 0x02;
500 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x02, &data);
501 1088
502 data = 0x00; 1089 write_mos_reg(serial, port_number, IER, 0x00);
503 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1090 write_mos_reg(serial, port_number, FCR, 0x00);
504 data = 0x00;
505 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data);
506 1091
507 data = 0xCF; 1092 write_mos_reg(serial, port_number, FCR, 0xcf);
508 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1093 mos7720_port->shadowLCR = 0x03;
509 data = 0x03; 1094 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
510 mos7720_port->shadowLCR = data; 1095 mos7720_port->shadowMCR = 0x0b;
511 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1096 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
512 data = 0x0b;
513 mos7720_port->shadowMCR = data;
514 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
515 data = 0x0b;
516 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
517
518 data = 0x00;
519 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
520 data = 0x00;
521 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
522
523/* data = 0x00;
524 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, port_number + 1, &data);
525 data = 0x03;
526 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data);
527 data = 0x00;
528 send_mos_cmd(port->serial, MOS_WRITE, MOS_MAX_PORT,
529 port_number + 1, &data);
530*/
531 data = 0x00;
532 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
533 1097
1098 write_mos_reg(serial, port_number, SP_CONTROL_REG, 0x00);
1099 read_mos_reg(serial, dummy, SP_CONTROL_REG, &data);
534 data = data | (port->number - port->serial->minor + 1); 1100 data = data | (port->number - port->serial->minor + 1);
535 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1101 write_mos_reg(serial, dummy, SP_CONTROL_REG, data);
1102 mos7720_port->shadowLCR = 0x83;
1103 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1104 write_mos_reg(serial, port_number, THR, 0x0c);
1105 write_mos_reg(serial, port_number, IER, 0x00);
1106 mos7720_port->shadowLCR = 0x03;
1107 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1108 write_mos_reg(serial, port_number, IER, 0x0c);
536 1109
537 data = 0x83;
538 mos7720_port->shadowLCR = data;
539 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
540 data = 0x0c;
541 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
542 data = 0x00;
543 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
544 data = 0x03;
545 mos7720_port->shadowLCR = data;
546 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
547 data = 0x0c;
548 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
549 data = 0x0c;
550 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
551
552 /* see if we've set up our endpoint info yet *
553 * (can't set it up in mos7720_startup as the *
554 * structures were not set up at that time.) */
555 if (!mos7720_serial->interrupt_started) {
556 dbg("Interrupt buffer NULL !!!");
557
558 /* not set up yet, so do it now */
559 mos7720_serial->interrupt_started = 1;
560
561 dbg("To Submit URB !!!");
562
563 /* set up our interrupt urb */
564 usb_fill_int_urb(port0->interrupt_in_urb, serial->dev,
565 usb_rcvintpipe(serial->dev,
566 port->interrupt_in_endpointAddress),
567 port0->interrupt_in_buffer,
568 port0->interrupt_in_urb->transfer_buffer_length,
569 mos7720_interrupt_callback, mos7720_port,
570 port0->interrupt_in_urb->interval);
571
572 /* start interrupt read for this mos7720 this interrupt *
573 * will continue as long as the mos7720 is connected */
574 dbg("Submit URB over !!!");
575 response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
576 if (response)
577 dev_err(&port->dev,
578 "%s - Error %d submitting control urb\n",
579 __func__, response);
580 }
581
582 /* set up our bulk in urb */
583 usb_fill_bulk_urb(port->read_urb, serial->dev,
584 usb_rcvbulkpipe(serial->dev,
585 port->bulk_in_endpointAddress),
586 port->bulk_in_buffer,
587 port->read_urb->transfer_buffer_length,
588 mos7720_bulk_in_callback, mos7720_port);
589 response = usb_submit_urb(port->read_urb, GFP_KERNEL); 1110 response = usb_submit_urb(port->read_urb, GFP_KERNEL);
590 if (response) 1111 if (response)
591 dev_err(&port->dev, "%s - Error %d submitting read urb\n", 1112 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
@@ -640,7 +1161,6 @@ static void mos7720_close(struct usb_serial_port *port)
640{ 1161{
641 struct usb_serial *serial; 1162 struct usb_serial *serial;
642 struct moschip_port *mos7720_port; 1163 struct moschip_port *mos7720_port;
643 char data;
644 int j; 1164 int j;
645 1165
646 dbg("mos7720_close:entering..."); 1166 dbg("mos7720_close:entering...");
@@ -673,13 +1193,10 @@ static void mos7720_close(struct usb_serial_port *port)
673 /* these commands must not be issued if the device has 1193 /* these commands must not be issued if the device has
674 * been disconnected */ 1194 * been disconnected */
675 if (!serial->disconnected) { 1195 if (!serial->disconnected) {
676 data = 0x00; 1196 write_mos_reg(serial, port->number - port->serial->minor,
677 send_mos_cmd(serial, MOS_WRITE, 1197 MCR, 0x00);
678 port->number - port->serial->minor, 0x04, &data); 1198 write_mos_reg(serial, port->number - port->serial->minor,
679 1199 IER, 0x00);
680 data = 0x00;
681 send_mos_cmd(serial, MOS_WRITE,
682 port->number - port->serial->minor, 0x01, &data);
683 } 1200 }
684 mutex_unlock(&serial->disc_mutex); 1201 mutex_unlock(&serial->disc_mutex);
685 mos7720_port->open = 0; 1202 mos7720_port->open = 0;
@@ -708,8 +1225,8 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
708 data = mos7720_port->shadowLCR & ~UART_LCR_SBC; 1225 data = mos7720_port->shadowLCR & ~UART_LCR_SBC;
709 1226
710 mos7720_port->shadowLCR = data; 1227 mos7720_port->shadowLCR = data;
711 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1228 write_mos_reg(serial, port->number - port->serial->minor,
712 0x03, &data); 1229 LCR, mos7720_port->shadowLCR);
713 1230
714 return; 1231 return;
715} 1232}
@@ -854,9 +1371,8 @@ static void mos7720_throttle(struct tty_struct *tty)
854 /* if we are implementing RTS/CTS, toggle that line */ 1371 /* if we are implementing RTS/CTS, toggle that line */
855 if (tty->termios->c_cflag & CRTSCTS) { 1372 if (tty->termios->c_cflag & CRTSCTS) {
856 mos7720_port->shadowMCR &= ~UART_MCR_RTS; 1373 mos7720_port->shadowMCR &= ~UART_MCR_RTS;
857 status = send_mos_cmd(port->serial, MOS_WRITE, 1374 write_mos_reg(port->serial, port->number - port->serial->minor,
858 port->number - port->serial->minor, 1375 MCR, mos7720_port->shadowMCR);
859 UART_MCR, &mos7720_port->shadowMCR);
860 if (status != 0) 1376 if (status != 0)
861 return; 1377 return;
862 } 1378 }
@@ -889,22 +1405,21 @@ static void mos7720_unthrottle(struct tty_struct *tty)
889 /* if we are implementing RTS/CTS, toggle that line */ 1405 /* if we are implementing RTS/CTS, toggle that line */
890 if (tty->termios->c_cflag & CRTSCTS) { 1406 if (tty->termios->c_cflag & CRTSCTS) {
891 mos7720_port->shadowMCR |= UART_MCR_RTS; 1407 mos7720_port->shadowMCR |= UART_MCR_RTS;
892 status = send_mos_cmd(port->serial, MOS_WRITE, 1408 write_mos_reg(port->serial, port->number - port->serial->minor,
893 port->number - port->serial->minor, 1409 MCR, mos7720_port->shadowMCR);
894 UART_MCR, &mos7720_port->shadowMCR);
895 if (status != 0) 1410 if (status != 0)
896 return; 1411 return;
897 } 1412 }
898} 1413}
899 1414
1415/* FIXME: this function does not work */
900static int set_higher_rates(struct moschip_port *mos7720_port, 1416static int set_higher_rates(struct moschip_port *mos7720_port,
901 unsigned int baud) 1417 unsigned int baud)
902{ 1418{
903 unsigned char data;
904 struct usb_serial_port *port; 1419 struct usb_serial_port *port;
905 struct usb_serial *serial; 1420 struct usb_serial *serial;
906 int port_number; 1421 int port_number;
907 1422 enum mos_regs sp_reg;
908 if (mos7720_port == NULL) 1423 if (mos7720_port == NULL)
909 return -EINVAL; 1424 return -EINVAL;
910 1425
@@ -917,58 +1432,35 @@ static int set_higher_rates(struct moschip_port *mos7720_port,
917 dbg("Sending Setting Commands .........."); 1432 dbg("Sending Setting Commands ..........");
918 port_number = port->number - port->serial->minor; 1433 port_number = port->number - port->serial->minor;
919 1434
920 data = 0x000; 1435 write_mos_reg(serial, port_number, IER, 0x00);
921 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data); 1436 write_mos_reg(serial, port_number, FCR, 0x00);
922 data = 0x000; 1437 write_mos_reg(serial, port_number, FCR, 0xcf);
923 send_mos_cmd(serial, MOS_WRITE, port_number, 0x02, &data); 1438 mos7720_port->shadowMCR = 0x0b;
924 data = 0x0CF; 1439 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
925 send_mos_cmd(serial, MOS_WRITE, port->number, 0x02, &data); 1440 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x00);
926 data = 0x00b;
927 mos7720_port->shadowMCR = data;
928 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
929 data = 0x00b;
930 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
931
932 data = 0x000;
933 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data);
934 data = 0x000;
935 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data);
936
937 1441
938 /*********************************************** 1442 /***********************************************
939 * Set for higher rates * 1443 * Set for higher rates *
940 ***********************************************/ 1444 ***********************************************/
941 1445 /* writing baud rate verbatum into uart clock field clearly not right */
942 data = baud * 0x10; 1446 if (port_number == 0)
943 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, port_number + 1, &data); 1447 sp_reg = SP1_REG;
944 1448 else
945 data = 0x003; 1449 sp_reg = SP2_REG;
946 send_mos_cmd(serial, MOS_READ, MOS_MAX_PORT, 0x08, &data); 1450 write_mos_reg(serial, dummy, sp_reg, baud * 0x10);
947 data = 0x003; 1451 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x03);
948 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 0x08, &data); 1452 mos7720_port->shadowMCR = 0x2b;
949 1453 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
950 data = 0x02b;
951 mos7720_port->shadowMCR = data;
952 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
953 data = 0x02b;
954 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
955 1454
956 /*********************************************** 1455 /***********************************************
957 * Set DLL/DLM 1456 * Set DLL/DLM
958 ***********************************************/ 1457 ***********************************************/
959 1458 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
960 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1459 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
961 mos7720_port->shadowLCR = data; 1460 write_mos_reg(serial, port_number, DLL, 0x01);
962 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data); 1461 write_mos_reg(serial, port_number, DLM, 0x00);
963 1462 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
964 data = 0x001; /* DLL */ 1463 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
965 send_mos_cmd(serial, MOS_WRITE, port_number, 0x00, &data);
966 data = 0x000; /* DLM */
967 send_mos_cmd(serial, MOS_WRITE, port_number, 0x01, &data);
968
969 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
970 mos7720_port->shadowLCR = data;
971 send_mos_cmd(serial, MOS_WRITE, port_number, 0x03, &data);
972 1464
973 return 0; 1465 return 0;
974} 1466}
@@ -1056,7 +1548,6 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1056 struct usb_serial *serial; 1548 struct usb_serial *serial;
1057 int divisor; 1549 int divisor;
1058 int status; 1550 int status;
1059 unsigned char data;
1060 unsigned char number; 1551 unsigned char number;
1061 1552
1062 if (mos7720_port == NULL) 1553 if (mos7720_port == NULL)
@@ -1078,21 +1569,16 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1078 } 1569 }
1079 1570
1080 /* Enable access to divisor latch */ 1571 /* Enable access to divisor latch */
1081 data = mos7720_port->shadowLCR | UART_LCR_DLAB; 1572 mos7720_port->shadowLCR = mos7720_port->shadowLCR | UART_LCR_DLAB;
1082 mos7720_port->shadowLCR = data; 1573 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1083 send_mos_cmd(serial, MOS_WRITE, number, UART_LCR, &data);
1084 1574
1085 /* Write the divisor */ 1575 /* Write the divisor */
1086 data = ((unsigned char)(divisor & 0xff)); 1576 write_mos_reg(serial, number, DLL, (__u8)(divisor & 0xff));
1087 send_mos_cmd(serial, MOS_WRITE, number, 0x00, &data); 1577 write_mos_reg(serial, number, DLM, (__u8)((divisor & 0xff00) >> 8));
1088
1089 data = ((unsigned char)((divisor & 0xff00) >> 8));
1090 send_mos_cmd(serial, MOS_WRITE, number, 0x01, &data);
1091 1578
1092 /* Disable access to divisor latch */ 1579 /* Disable access to divisor latch */
1093 data = mos7720_port->shadowLCR & ~UART_LCR_DLAB; 1580 mos7720_port->shadowLCR = mos7720_port->shadowLCR & ~UART_LCR_DLAB;
1094 mos7720_port->shadowLCR = data; 1581 write_mos_reg(serial, number, LCR, mos7720_port->shadowLCR);
1095 send_mos_cmd(serial, MOS_WRITE, number, 0x03, &data);
1096 1582
1097 return status; 1583 return status;
1098} 1584}
@@ -1117,7 +1603,6 @@ static void change_port_settings(struct tty_struct *tty,
1117 __u8 lStop; 1603 __u8 lStop;
1118 int status; 1604 int status;
1119 int port_number; 1605 int port_number;
1120 char data;
1121 1606
1122 if (mos7720_port == NULL) 1607 if (mos7720_port == NULL)
1123 return ; 1608 return ;
@@ -1196,30 +1681,19 @@ static void change_port_settings(struct tty_struct *tty,
1196 1681
1197 /* Update the LCR with the correct value */ 1682 /* Update the LCR with the correct value */
1198 mos7720_port->shadowLCR &= 1683 mos7720_port->shadowLCR &=
1199 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK); 1684 ~(LCR_BITS_MASK | LCR_STOP_MASK | LCR_PAR_MASK);
1200 mos7720_port->shadowLCR |= (lData | lParity | lStop); 1685 mos7720_port->shadowLCR |= (lData | lParity | lStop);
1201 1686
1202 1687
1203 /* Disable Interrupts */ 1688 /* Disable Interrupts */
1204 data = 0x00; 1689 write_mos_reg(serial, port_number, IER, 0x00);
1205 send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor, 1690 write_mos_reg(serial, port_number, FCR, 0x00);
1206 UART_IER, &data); 1691 write_mos_reg(serial, port_number, FCR, 0xcf);
1207
1208 data = 0x00;
1209 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1210
1211 data = 0xcf;
1212 send_mos_cmd(serial, MOS_WRITE, port_number, UART_FCR, &data);
1213 1692
1214 /* Send the updated LCR value to the mos7720 */ 1693 /* Send the updated LCR value to the mos7720 */
1215 data = mos7720_port->shadowLCR; 1694 write_mos_reg(serial, port_number, LCR, mos7720_port->shadowLCR);
1216 send_mos_cmd(serial, MOS_WRITE, port_number, UART_LCR, &data); 1695 mos7720_port->shadowMCR = 0x0b;
1217 1696 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1218 data = 0x00b;
1219 mos7720_port->shadowMCR = data;
1220 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1221 data = 0x00b;
1222 send_mos_cmd(serial, MOS_WRITE, port_number, 0x04, &data);
1223 1697
1224 /* set up the MCR register and send it to the mos7720 */ 1698 /* set up the MCR register and send it to the mos7720 */
1225 mos7720_port->shadowMCR = UART_MCR_OUT2; 1699 mos7720_port->shadowMCR = UART_MCR_OUT2;
@@ -1230,21 +1704,15 @@ static void change_port_settings(struct tty_struct *tty,
1230 mos7720_port->shadowMCR |= (UART_MCR_XONANY); 1704 mos7720_port->shadowMCR |= (UART_MCR_XONANY);
1231 /* To set hardware flow control to the specified * 1705 /* To set hardware flow control to the specified *
1232 * serial port, in SP1/2_CONTROL_REG */ 1706 * serial port, in SP1/2_CONTROL_REG */
1233 if (port->number) { 1707 if (port->number)
1234 data = 0x001; 1708 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x01);
1235 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT, 1709 else
1236 0x08, &data); 1710 write_mos_reg(serial, dummy, SP_CONTROL_REG, 0x02);
1237 } else { 1711
1238 data = 0x002; 1712 } else
1239 send_mos_cmd(serial, MOS_WRITE, MOS_MAX_PORT,
1240 0x08, &data);
1241 }
1242 } else {
1243 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY); 1713 mos7720_port->shadowMCR &= ~(UART_MCR_XONANY);
1244 }
1245 1714
1246 data = mos7720_port->shadowMCR; 1715 write_mos_reg(serial, port_number, MCR, mos7720_port->shadowMCR);
1247 send_mos_cmd(serial, MOS_WRITE, port_number, UART_MCR, &data);
1248 1716
1249 /* Determine divisor based on baud rate */ 1717 /* Determine divisor based on baud rate */
1250 baud = tty_get_baud_rate(tty); 1718 baud = tty_get_baud_rate(tty);
@@ -1257,8 +1725,7 @@ static void change_port_settings(struct tty_struct *tty,
1257 if (baud >= 230400) { 1725 if (baud >= 230400) {
1258 set_higher_rates(mos7720_port, baud); 1726 set_higher_rates(mos7720_port, baud);
1259 /* Enable Interrupts */ 1727 /* Enable Interrupts */
1260 data = 0x0c; 1728 write_mos_reg(serial, port_number, IER, 0x0c);
1261 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1262 return; 1729 return;
1263 } 1730 }
1264 1731
@@ -1269,8 +1736,7 @@ static void change_port_settings(struct tty_struct *tty,
1269 if (cflag & CBAUD) 1736 if (cflag & CBAUD)
1270 tty_encode_baud_rate(tty, baud, baud); 1737 tty_encode_baud_rate(tty, baud, baud);
1271 /* Enable Interrupts */ 1738 /* Enable Interrupts */
1272 data = 0x0c; 1739 write_mos_reg(serial, port_number, IER, 0x0c);
1273 send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
1274 1740
1275 if (port->read_urb->status != -EINPROGRESS) { 1741 if (port->read_urb->status != -EINPROGRESS) {
1276 port->read_urb->dev = serial->dev; 1742 port->read_urb->dev = serial->dev;
@@ -1308,7 +1774,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1308 return; 1774 return;
1309 } 1775 }
1310 1776
1311 dbg("setting termios - ASPIRE"); 1777 dbg("%s\n", "setting termios - ASPIRE");
1312 1778
1313 cflag = tty->termios->c_cflag; 1779 cflag = tty->termios->c_cflag;
1314 1780
@@ -1326,7 +1792,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1326 change_port_settings(tty, mos7720_port, old_termios); 1792 change_port_settings(tty, mos7720_port, old_termios);
1327 1793
1328 if (!port->read_urb) { 1794 if (!port->read_urb) {
1329 dbg("URB KILLED !!!!!"); 1795 dbg("%s", "URB KILLED !!!!!");
1330 return; 1796 return;
1331 } 1797 }
1332 1798
@@ -1361,8 +1827,7 @@ static int get_lsr_info(struct tty_struct *tty,
1361 1827
1362 count = mos7720_chars_in_buffer(tty); 1828 count = mos7720_chars_in_buffer(tty);
1363 if (count == 0) { 1829 if (count == 0) {
1364 send_mos_cmd(port->serial, MOS_READ, port_number, 1830 read_mos_reg(port->serial, port_number, LSR, &data);
1365 UART_LSR, &data);
1366 if ((data & (UART_LSR_TEMT | UART_LSR_THRE)) 1831 if ((data & (UART_LSR_TEMT | UART_LSR_THRE))
1367 == (UART_LSR_TEMT | UART_LSR_THRE)) { 1832 == (UART_LSR_TEMT | UART_LSR_THRE)) {
1368 dbg("%s -- Empty", __func__); 1833 dbg("%s -- Empty", __func__);
@@ -1400,13 +1865,11 @@ static int mos7720_tiocmget(struct tty_struct *tty, struct file *file)
1400} 1865}
1401 1866
1402static int mos7720_tiocmset(struct tty_struct *tty, struct file *file, 1867static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1403 unsigned int set, unsigned int clear) 1868 unsigned int set, unsigned int clear)
1404{ 1869{
1405 struct usb_serial_port *port = tty->driver_data; 1870 struct usb_serial_port *port = tty->driver_data;
1406 struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1871 struct moschip_port *mos7720_port = usb_get_serial_port_data(port);
1407 unsigned int mcr ; 1872 unsigned int mcr ;
1408 unsigned char lmcr;
1409
1410 dbg("%s - port %d", __func__, port->number); 1873 dbg("%s - port %d", __func__, port->number);
1411 dbg("he was at tiocmget"); 1874 dbg("he was at tiocmget");
1412 1875
@@ -1427,10 +1890,8 @@ static int mos7720_tiocmset(struct tty_struct *tty, struct file *file,
1427 mcr &= ~UART_MCR_LOOP; 1890 mcr &= ~UART_MCR_LOOP;
1428 1891
1429 mos7720_port->shadowMCR = mcr; 1892 mos7720_port->shadowMCR = mcr;
1430 lmcr = mos7720_port->shadowMCR; 1893 write_mos_reg(port->serial, port->number - port->serial->minor,
1431 1894 MCR, mos7720_port->shadowMCR);
1432 send_mos_cmd(port->serial, MOS_WRITE,
1433 port->number - port->serial->minor, UART_MCR, &lmcr);
1434 1895
1435 return 0; 1896 return 0;
1436} 1897}
@@ -1440,7 +1901,6 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1440{ 1901{
1441 unsigned int mcr ; 1902 unsigned int mcr ;
1442 unsigned int arg; 1903 unsigned int arg;
1443 unsigned char data;
1444 1904
1445 struct usb_serial_port *port; 1905 struct usb_serial_port *port;
1446 1906
@@ -1475,10 +1935,8 @@ static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1475 } 1935 }
1476 1936
1477 mos7720_port->shadowMCR = mcr; 1937 mos7720_port->shadowMCR = mcr;
1478 1938 write_mos_reg(port->serial, port->number - port->serial->minor,
1479 data = mos7720_port->shadowMCR; 1939 MCR, mos7720_port->shadowMCR);
1480 send_mos_cmd(port->serial, MOS_WRITE,
1481 port->number - port->serial->minor, UART_MCR, &data);
1482 1940
1483 return 0; 1941 return 0;
1484} 1942}
@@ -1590,12 +2048,12 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1590 2048
1591static int mos7720_startup(struct usb_serial *serial) 2049static int mos7720_startup(struct usb_serial *serial)
1592{ 2050{
1593 struct moschip_serial *mos7720_serial;
1594 struct moschip_port *mos7720_port; 2051 struct moschip_port *mos7720_port;
1595 struct usb_device *dev; 2052 struct usb_device *dev;
1596 int i; 2053 int i;
1597 char data; 2054 char data;
1598 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 2055 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
2056 int ret_val;
1599 2057
1600 dbg("%s: Entering ..........", __func__); 2058 dbg("%s: Entering ..........", __func__);
1601 2059
@@ -1606,15 +2064,6 @@ static int mos7720_startup(struct usb_serial *serial)
1606 2064
1607 dev = serial->dev; 2065 dev = serial->dev;
1608 2066
1609 /* create our private serial structure */
1610 mos7720_serial = kzalloc(sizeof(struct moschip_serial), GFP_KERNEL);
1611 if (mos7720_serial == NULL) {
1612 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1613 return -ENOMEM;
1614 }
1615
1616 usb_set_serial_data(serial, mos7720_serial);
1617
1618 /* 2067 /*
1619 * The 7715 uses the first bulk in/out endpoint pair for the parallel 2068 * The 7715 uses the first bulk in/out endpoint pair for the parallel
1620 * port, and the second for the serial port. Because the usbserial core 2069 * port, and the second for the serial port. Because the usbserial core
@@ -1638,16 +2087,12 @@ static int mos7720_startup(struct usb_serial *serial)
1638 serial->port[1]->interrupt_in_buffer = NULL; 2087 serial->port[1]->interrupt_in_buffer = NULL;
1639 } 2088 }
1640 2089
1641 /* we set up the pointers to the endpoints in the mos7720_open *
1642 * function, as the structures aren't created yet. */
1643 2090
1644 /* set up port private structures */ 2091 /* set up serial port private structures */
1645 for (i = 0; i < serial->num_ports; ++i) { 2092 for (i = 0; i < serial->num_ports; ++i) {
1646 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL); 2093 mos7720_port = kzalloc(sizeof(struct moschip_port), GFP_KERNEL);
1647 if (mos7720_port == NULL) { 2094 if (mos7720_port == NULL) {
1648 dev_err(&dev->dev, "%s - Out of memory\n", __func__); 2095 dev_err(&dev->dev, "%s - Out of memory\n", __func__);
1649 usb_set_serial_data(serial, NULL);
1650 kfree(mos7720_serial);
1651 return -ENOMEM; 2096 return -ENOMEM;
1652 } 2097 }
1653 2098
@@ -1669,12 +2114,22 @@ static int mos7720_startup(struct usb_serial *serial)
1669 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 2114 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1670 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ); 2115 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5*HZ);
1671 2116
1672 /* LSR For Port 1 */ 2117 /* start the interrupt urb */
1673 send_mos_cmd(serial, MOS_READ, 0x00, UART_LSR, &data); 2118 ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL);
1674 dbg("LSR:%x", data); 2119 if (ret_val)
2120 dev_err(&dev->dev,
2121 "%s - Error %d submitting control urb\n",
2122 __func__, ret_val);
1675 2123
1676 /* LSR For Port 2 */ 2124#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
1677 send_mos_cmd(serial, MOS_READ, 0x01, UART_LSR, &data); 2125 if (product == MOSCHIP_DEVICE_ID_7715) {
2126 ret_val = mos7715_parport_init(serial);
2127 if (ret_val < 0)
2128 return ret_val;
2129 }
2130#endif
2131 /* LSR For Port 1 */
2132 read_mos_reg(serial, 0, LSR, &data);
1678 dbg("LSR:%x", data); 2133 dbg("LSR:%x", data);
1679 2134
1680 return 0; 2135 return 0;
@@ -1684,12 +2139,47 @@ static void mos7720_release(struct usb_serial *serial)
1684{ 2139{
1685 int i; 2140 int i;
1686 2141
2142#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
2143 /* close the parallel port */
2144
2145 if (le16_to_cpu(serial->dev->descriptor.idProduct)
2146 == MOSCHIP_DEVICE_ID_7715) {
2147 struct urbtracker *urbtrack;
2148 unsigned long flags;
2149 struct mos7715_parport *mos_parport =
2150 usb_get_serial_data(serial);
2151
2152 /* prevent NULL ptr dereference in port callbacks */
2153 spin_lock(&release_lock);
2154 mos_parport->pp->private_data = NULL;
2155 spin_unlock(&release_lock);
2156
2157 /* wait for synchronous usb calls to return */
2158 if (mos_parport->msg_pending)
2159 wait_for_completion_timeout(&mos_parport->syncmsg_compl,
2160 MOS_WDR_TIMEOUT);
2161
2162 parport_remove_port(mos_parport->pp);
2163 usb_set_serial_data(serial, NULL);
2164 mos_parport->serial = NULL;
2165
2166 /* if tasklet currently scheduled, wait for it to complete */
2167 tasklet_kill(&mos_parport->urb_tasklet);
2168
2169 /* unlink any urbs sent by the tasklet */
2170 spin_lock_irqsave(&mos_parport->listlock, flags);
2171 list_for_each_entry(urbtrack,
2172 &mos_parport->active_urbs,
2173 urblist_entry)
2174 usb_unlink_urb(urbtrack->urb);
2175 spin_unlock_irqrestore(&mos_parport->listlock, flags);
2176
2177 kref_put(&mos_parport->ref_count, destroy_mos_parport);
2178 }
2179#endif
1687 /* free private structure allocated for serial port */ 2180 /* free private structure allocated for serial port */
1688 for (i = 0; i < serial->num_ports; ++i) 2181 for (i = 0; i < serial->num_ports; ++i)
1689 kfree(usb_get_serial_port_data(serial->port[i])); 2182 kfree(usb_get_serial_port_data(serial->port[i]));
1690
1691 /* free private structure allocated for serial device */
1692 kfree(usb_get_serial_data(serial));
1693} 2183}
1694 2184
1695static struct usb_driver usb_driver = { 2185static struct usb_driver usb_driver = {
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 2fda1c0182b7..f8424d1bfc1b 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -26,7 +26,6 @@
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/tty.h> 29#include <linux/tty.h>
31#include <linux/tty_driver.h> 30#include <linux/tty_driver.h>
32#include <linux/tty_flip.h> 31#include <linux/tty_flip.h>
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 84d0edad8e4f..e280ad8e12f7 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -42,35 +42,14 @@
42#include <linux/bitops.h> 42#include <linux/bitops.h>
43#include <linux/usb.h> 43#include <linux/usb.h>
44#include <linux/usb/serial.h> 44#include <linux/usb/serial.h>
45#include "usb-wwan.h"
45 46
46/* Function prototypes */ 47/* Function prototypes */
47static int option_probe(struct usb_serial *serial, 48static int option_probe(struct usb_serial *serial,
48 const struct usb_device_id *id); 49 const struct usb_device_id *id);
49static int option_open(struct tty_struct *tty, struct usb_serial_port *port); 50static int option_send_setup(struct usb_serial_port *port);
50static void option_close(struct usb_serial_port *port);
51static void option_dtr_rts(struct usb_serial_port *port, int on);
52
53static int option_startup(struct usb_serial *serial);
54static void option_disconnect(struct usb_serial *serial);
55static void option_release(struct usb_serial *serial);
56static int option_write_room(struct tty_struct *tty);
57
58static void option_instat_callback(struct urb *urb); 51static void option_instat_callback(struct urb *urb);
59 52
60static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
61 const unsigned char *buf, int count);
62static int option_chars_in_buffer(struct tty_struct *tty);
63static void option_set_termios(struct tty_struct *tty,
64 struct usb_serial_port *port, struct ktermios *old);
65static int option_tiocmget(struct tty_struct *tty, struct file *file);
66static int option_tiocmset(struct tty_struct *tty, struct file *file,
67 unsigned int set, unsigned int clear);
68static int option_send_setup(struct usb_serial_port *port);
69#ifdef CONFIG_PM
70static int option_suspend(struct usb_serial *serial, pm_message_t message);
71static int option_resume(struct usb_serial *serial);
72#endif
73
74/* Vendor and product IDs */ 53/* Vendor and product IDs */
75#define OPTION_VENDOR_ID 0x0AF0 54#define OPTION_VENDOR_ID 0x0AF0
76#define OPTION_PRODUCT_COLT 0x5000 55#define OPTION_PRODUCT_COLT 0x5000
@@ -380,6 +359,10 @@ static int option_resume(struct usb_serial *serial);
380 359
381#define CINTERION_VENDOR_ID 0x0681 360#define CINTERION_VENDOR_ID 0x0681
382 361
362/* Olivetti products */
363#define OLIVETTI_VENDOR_ID 0x0b3c
364#define OLIVETTI_PRODUCT_OLICARD100 0xc000
365
383/* some devices interfaces need special handling due to a number of reasons */ 366/* some devices interfaces need special handling due to a number of reasons */
384enum option_blacklist_reason { 367enum option_blacklist_reason {
385 OPTION_BLACKLIST_NONE = 0, 368 OPTION_BLACKLIST_NONE = 0,
@@ -675,6 +658,180 @@ static const struct usb_device_id option_ids[] = {
675 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0160, 0xff, 0xff, 0xff) }, 658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0160, 0xff, 0xff, 0xff) },
676 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0161, 0xff, 0xff, 0xff) }, 659 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0161, 0xff, 0xff, 0xff) },
677 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0162, 0xff, 0xff, 0xff) }, 660 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0162, 0xff, 0xff, 0xff) },
661 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1008, 0xff, 0xff, 0xff) },
662 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1010, 0xff, 0xff, 0xff) },
663 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1012, 0xff, 0xff, 0xff) },
664 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1057, 0xff, 0xff, 0xff) },
665 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1058, 0xff, 0xff, 0xff) },
666 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1059, 0xff, 0xff, 0xff) },
667 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1060, 0xff, 0xff, 0xff) },
668 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1061, 0xff, 0xff, 0xff) },
669 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1062, 0xff, 0xff, 0xff) },
670 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1063, 0xff, 0xff, 0xff) },
671 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1064, 0xff, 0xff, 0xff) },
672 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1065, 0xff, 0xff, 0xff) },
673 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1066, 0xff, 0xff, 0xff) },
674 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1067, 0xff, 0xff, 0xff) },
675 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1068, 0xff, 0xff, 0xff) },
676 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1069, 0xff, 0xff, 0xff) },
677 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1070, 0xff, 0xff, 0xff) },
678 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1071, 0xff, 0xff, 0xff) },
679 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1072, 0xff, 0xff, 0xff) },
680 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1073, 0xff, 0xff, 0xff) },
681 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1074, 0xff, 0xff, 0xff) },
682 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1075, 0xff, 0xff, 0xff) },
683 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1076, 0xff, 0xff, 0xff) },
684 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1077, 0xff, 0xff, 0xff) },
685 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1078, 0xff, 0xff, 0xff) },
686 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1079, 0xff, 0xff, 0xff) },
687 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1080, 0xff, 0xff, 0xff) },
688 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1081, 0xff, 0xff, 0xff) },
689 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1082, 0xff, 0xff, 0xff) },
690 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1083, 0xff, 0xff, 0xff) },
691 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1084, 0xff, 0xff, 0xff) },
692 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1085, 0xff, 0xff, 0xff) },
693 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1086, 0xff, 0xff, 0xff) },
694 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1087, 0xff, 0xff, 0xff) },
695 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1088, 0xff, 0xff, 0xff) },
696 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1089, 0xff, 0xff, 0xff) },
697 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1090, 0xff, 0xff, 0xff) },
698 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1091, 0xff, 0xff, 0xff) },
699 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1092, 0xff, 0xff, 0xff) },
700 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1093, 0xff, 0xff, 0xff) },
701 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1094, 0xff, 0xff, 0xff) },
702 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1095, 0xff, 0xff, 0xff) },
703 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1096, 0xff, 0xff, 0xff) },
704 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1097, 0xff, 0xff, 0xff) },
705 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1098, 0xff, 0xff, 0xff) },
706 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1099, 0xff, 0xff, 0xff) },
707 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1100, 0xff, 0xff, 0xff) },
708 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1101, 0xff, 0xff, 0xff) },
709 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1102, 0xff, 0xff, 0xff) },
710 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1103, 0xff, 0xff, 0xff) },
711 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1104, 0xff, 0xff, 0xff) },
712 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1105, 0xff, 0xff, 0xff) },
713 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1106, 0xff, 0xff, 0xff) },
714 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1107, 0xff, 0xff, 0xff) },
715 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1108, 0xff, 0xff, 0xff) },
716 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1109, 0xff, 0xff, 0xff) },
717 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1110, 0xff, 0xff, 0xff) },
718 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1111, 0xff, 0xff, 0xff) },
719 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1112, 0xff, 0xff, 0xff) },
720 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1113, 0xff, 0xff, 0xff) },
721 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1114, 0xff, 0xff, 0xff) },
722 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1115, 0xff, 0xff, 0xff) },
723 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1116, 0xff, 0xff, 0xff) },
724 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1117, 0xff, 0xff, 0xff) },
725 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1118, 0xff, 0xff, 0xff) },
726 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1119, 0xff, 0xff, 0xff) },
727 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1120, 0xff, 0xff, 0xff) },
728 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1121, 0xff, 0xff, 0xff) },
729 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1122, 0xff, 0xff, 0xff) },
730 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1123, 0xff, 0xff, 0xff) },
731 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1124, 0xff, 0xff, 0xff) },
732 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1125, 0xff, 0xff, 0xff) },
733 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1126, 0xff, 0xff, 0xff) },
734 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1127, 0xff, 0xff, 0xff) },
735 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1128, 0xff, 0xff, 0xff) },
736 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1129, 0xff, 0xff, 0xff) },
737 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1130, 0xff, 0xff, 0xff) },
738 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1131, 0xff, 0xff, 0xff) },
739 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1132, 0xff, 0xff, 0xff) },
740 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1133, 0xff, 0xff, 0xff) },
741 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1134, 0xff, 0xff, 0xff) },
742 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1135, 0xff, 0xff, 0xff) },
743 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1136, 0xff, 0xff, 0xff) },
744 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1137, 0xff, 0xff, 0xff) },
745 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1138, 0xff, 0xff, 0xff) },
746 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1139, 0xff, 0xff, 0xff) },
747 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1140, 0xff, 0xff, 0xff) },
748 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1141, 0xff, 0xff, 0xff) },
749 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1142, 0xff, 0xff, 0xff) },
750 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1143, 0xff, 0xff, 0xff) },
751 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1144, 0xff, 0xff, 0xff) },
752 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1145, 0xff, 0xff, 0xff) },
753 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1146, 0xff, 0xff, 0xff) },
754 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1147, 0xff, 0xff, 0xff) },
755 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1148, 0xff, 0xff, 0xff) },
756 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1149, 0xff, 0xff, 0xff) },
757 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1150, 0xff, 0xff, 0xff) },
758 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1151, 0xff, 0xff, 0xff) },
759 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1152, 0xff, 0xff, 0xff) },
760 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1153, 0xff, 0xff, 0xff) },
761 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1154, 0xff, 0xff, 0xff) },
762 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1155, 0xff, 0xff, 0xff) },
763 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1156, 0xff, 0xff, 0xff) },
764 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1157, 0xff, 0xff, 0xff) },
765 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1158, 0xff, 0xff, 0xff) },
766 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1159, 0xff, 0xff, 0xff) },
767 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1160, 0xff, 0xff, 0xff) },
768 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1161, 0xff, 0xff, 0xff) },
769 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1162, 0xff, 0xff, 0xff) },
770 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1163, 0xff, 0xff, 0xff) },
771 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1164, 0xff, 0xff, 0xff) },
772 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1165, 0xff, 0xff, 0xff) },
773 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1166, 0xff, 0xff, 0xff) },
774 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1167, 0xff, 0xff, 0xff) },
775 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1168, 0xff, 0xff, 0xff) },
776 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1169, 0xff, 0xff, 0xff) },
777 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1170, 0xff, 0xff, 0xff) },
778 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1244, 0xff, 0xff, 0xff) },
779 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1245, 0xff, 0xff, 0xff) },
780 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1246, 0xff, 0xff, 0xff) },
781 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1247, 0xff, 0xff, 0xff) },
782 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1248, 0xff, 0xff, 0xff) },
783 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1249, 0xff, 0xff, 0xff) },
784 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1250, 0xff, 0xff, 0xff) },
785 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1251, 0xff, 0xff, 0xff) },
786 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1252, 0xff, 0xff, 0xff) },
787 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1253, 0xff, 0xff, 0xff) },
788 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1254, 0xff, 0xff, 0xff) },
789 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1255, 0xff, 0xff, 0xff) },
790 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1256, 0xff, 0xff, 0xff) },
791 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1257, 0xff, 0xff, 0xff) },
792 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1258, 0xff, 0xff, 0xff) },
793 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1259, 0xff, 0xff, 0xff) },
794 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1260, 0xff, 0xff, 0xff) },
795 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1261, 0xff, 0xff, 0xff) },
796 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1262, 0xff, 0xff, 0xff) },
797 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1263, 0xff, 0xff, 0xff) },
798 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1264, 0xff, 0xff, 0xff) },
799 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1265, 0xff, 0xff, 0xff) },
800 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1266, 0xff, 0xff, 0xff) },
801 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1267, 0xff, 0xff, 0xff) },
802 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1268, 0xff, 0xff, 0xff) },
803 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1269, 0xff, 0xff, 0xff) },
804 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1270, 0xff, 0xff, 0xff) },
805 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1271, 0xff, 0xff, 0xff) },
806 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1272, 0xff, 0xff, 0xff) },
807 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1273, 0xff, 0xff, 0xff) },
808 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1274, 0xff, 0xff, 0xff) },
809 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1275, 0xff, 0xff, 0xff) },
810 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1276, 0xff, 0xff, 0xff) },
811 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1277, 0xff, 0xff, 0xff) },
812 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1278, 0xff, 0xff, 0xff) },
813 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1279, 0xff, 0xff, 0xff) },
814 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1280, 0xff, 0xff, 0xff) },
815 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1281, 0xff, 0xff, 0xff) },
816 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1282, 0xff, 0xff, 0xff) },
817 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1283, 0xff, 0xff, 0xff) },
818 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1284, 0xff, 0xff, 0xff) },
819 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1285, 0xff, 0xff, 0xff) },
820 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1286, 0xff, 0xff, 0xff) },
821 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1287, 0xff, 0xff, 0xff) },
822 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1288, 0xff, 0xff, 0xff) },
823 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1289, 0xff, 0xff, 0xff) },
824 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1290, 0xff, 0xff, 0xff) },
825 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1291, 0xff, 0xff, 0xff) },
826 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1292, 0xff, 0xff, 0xff) },
827 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1293, 0xff, 0xff, 0xff) },
828 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1294, 0xff, 0xff, 0xff) },
829 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1295, 0xff, 0xff, 0xff) },
830 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1296, 0xff, 0xff, 0xff) },
831 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1297, 0xff, 0xff, 0xff) },
832 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1298, 0xff, 0xff, 0xff) },
833 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1299, 0xff, 0xff, 0xff) },
834 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1300, 0xff, 0xff, 0xff) },
678 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0014, 0xff, 0xff, 0xff) }, /* ZTE CDMA products */ 835 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0014, 0xff, 0xff, 0xff) }, /* ZTE CDMA products */
679 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0027, 0xff, 0xff, 0xff) }, 836 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0027, 0xff, 0xff, 0xff) },
680 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0059, 0xff, 0xff, 0xff) }, 837 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0059, 0xff, 0xff, 0xff) },
@@ -726,6 +883,8 @@ static const struct usb_device_id option_ids[] = {
726 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1012)}, 883 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1012)},
727 884
728 { USB_DEVICE(CINTERION_VENDOR_ID, 0x0047) }, 885 { USB_DEVICE(CINTERION_VENDOR_ID, 0x0047) },
886
887 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) },
729 { } /* Terminating entry */ 888 { } /* Terminating entry */
730}; 889};
731MODULE_DEVICE_TABLE(usb, option_ids); 890MODULE_DEVICE_TABLE(usb, option_ids);
@@ -757,22 +916,22 @@ static struct usb_serial_driver option_1port_device = {
757 .id_table = option_ids, 916 .id_table = option_ids,
758 .num_ports = 1, 917 .num_ports = 1,
759 .probe = option_probe, 918 .probe = option_probe,
760 .open = option_open, 919 .open = usb_wwan_open,
761 .close = option_close, 920 .close = usb_wwan_close,
762 .dtr_rts = option_dtr_rts, 921 .dtr_rts = usb_wwan_dtr_rts,
763 .write = option_write, 922 .write = usb_wwan_write,
764 .write_room = option_write_room, 923 .write_room = usb_wwan_write_room,
765 .chars_in_buffer = option_chars_in_buffer, 924 .chars_in_buffer = usb_wwan_chars_in_buffer,
766 .set_termios = option_set_termios, 925 .set_termios = usb_wwan_set_termios,
767 .tiocmget = option_tiocmget, 926 .tiocmget = usb_wwan_tiocmget,
768 .tiocmset = option_tiocmset, 927 .tiocmset = usb_wwan_tiocmset,
769 .attach = option_startup, 928 .attach = usb_wwan_startup,
770 .disconnect = option_disconnect, 929 .disconnect = usb_wwan_disconnect,
771 .release = option_release, 930 .release = usb_wwan_release,
772 .read_int_callback = option_instat_callback, 931 .read_int_callback = option_instat_callback,
773#ifdef CONFIG_PM 932#ifdef CONFIG_PM
774 .suspend = option_suspend, 933 .suspend = usb_wwan_suspend,
775 .resume = option_resume, 934 .resume = usb_wwan_resume,
776#endif 935#endif
777}; 936};
778 937
@@ -785,13 +944,6 @@ static int debug;
785#define IN_BUFLEN 4096 944#define IN_BUFLEN 4096
786#define OUT_BUFLEN 4096 945#define OUT_BUFLEN 4096
787 946
788struct option_intf_private {
789 spinlock_t susp_lock;
790 unsigned int suspended:1;
791 int in_flight;
792 struct option_blacklist_info *blacklist_info;
793};
794
795struct option_port_private { 947struct option_port_private {
796 /* Input endpoints and buffer for this port */ 948 /* Input endpoints and buffer for this port */
797 struct urb *in_urbs[N_IN_URB]; 949 struct urb *in_urbs[N_IN_URB];
@@ -848,8 +1000,7 @@ module_exit(option_exit);
848static int option_probe(struct usb_serial *serial, 1000static int option_probe(struct usb_serial *serial,
849 const struct usb_device_id *id) 1001 const struct usb_device_id *id)
850{ 1002{
851 struct option_intf_private *data; 1003 struct usb_wwan_intf_private *data;
852
853 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ 1004 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */
854 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && 1005 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID &&
855 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && 1006 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 &&
@@ -862,11 +1013,13 @@ static int option_probe(struct usb_serial *serial,
862 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) 1013 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff)
863 return -ENODEV; 1014 return -ENODEV;
864 1015
865 data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL); 1016 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL);
1017
866 if (!data) 1018 if (!data)
867 return -ENOMEM; 1019 return -ENOMEM;
1020 data->send_setup = option_send_setup;
868 spin_lock_init(&data->susp_lock); 1021 spin_lock_init(&data->susp_lock);
869 data->blacklist_info = (struct option_blacklist_info*) id->driver_info; 1022 data->private = (void *)id->driver_info;
870 return 0; 1023 return 0;
871} 1024}
872 1025
@@ -887,194 +1040,6 @@ static enum option_blacklist_reason is_blacklisted(const u8 ifnum,
887 return OPTION_BLACKLIST_NONE; 1040 return OPTION_BLACKLIST_NONE;
888} 1041}
889 1042
890static void option_set_termios(struct tty_struct *tty,
891 struct usb_serial_port *port, struct ktermios *old_termios)
892{
893 dbg("%s", __func__);
894 /* Doesn't support option setting */
895 tty_termios_copy_hw(tty->termios, old_termios);
896 option_send_setup(port);
897}
898
899static int option_tiocmget(struct tty_struct *tty, struct file *file)
900{
901 struct usb_serial_port *port = tty->driver_data;
902 unsigned int value;
903 struct option_port_private *portdata;
904
905 portdata = usb_get_serial_port_data(port);
906
907 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
908 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
909 ((portdata->cts_state) ? TIOCM_CTS : 0) |
910 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
911 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
912 ((portdata->ri_state) ? TIOCM_RNG : 0);
913
914 return value;
915}
916
917static int option_tiocmset(struct tty_struct *tty, struct file *file,
918 unsigned int set, unsigned int clear)
919{
920 struct usb_serial_port *port = tty->driver_data;
921 struct option_port_private *portdata;
922
923 portdata = usb_get_serial_port_data(port);
924
925 /* FIXME: what locks portdata fields ? */
926 if (set & TIOCM_RTS)
927 portdata->rts_state = 1;
928 if (set & TIOCM_DTR)
929 portdata->dtr_state = 1;
930
931 if (clear & TIOCM_RTS)
932 portdata->rts_state = 0;
933 if (clear & TIOCM_DTR)
934 portdata->dtr_state = 0;
935 return option_send_setup(port);
936}
937
938/* Write */
939static int option_write(struct tty_struct *tty, struct usb_serial_port *port,
940 const unsigned char *buf, int count)
941{
942 struct option_port_private *portdata;
943 struct option_intf_private *intfdata;
944 int i;
945 int left, todo;
946 struct urb *this_urb = NULL; /* spurious */
947 int err;
948 unsigned long flags;
949
950 portdata = usb_get_serial_port_data(port);
951 intfdata = port->serial->private;
952
953 dbg("%s: write (%d chars)", __func__, count);
954
955 i = 0;
956 left = count;
957 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
958 todo = left;
959 if (todo > OUT_BUFLEN)
960 todo = OUT_BUFLEN;
961
962 this_urb = portdata->out_urbs[i];
963 if (test_and_set_bit(i, &portdata->out_busy)) {
964 if (time_before(jiffies,
965 portdata->tx_start_time[i] + 10 * HZ))
966 continue;
967 usb_unlink_urb(this_urb);
968 continue;
969 }
970 dbg("%s: endpoint %d buf %d", __func__,
971 usb_pipeendpoint(this_urb->pipe), i);
972
973 err = usb_autopm_get_interface_async(port->serial->interface);
974 if (err < 0)
975 break;
976
977 /* send the data */
978 memcpy(this_urb->transfer_buffer, buf, todo);
979 this_urb->transfer_buffer_length = todo;
980
981 spin_lock_irqsave(&intfdata->susp_lock, flags);
982 if (intfdata->suspended) {
983 usb_anchor_urb(this_urb, &portdata->delayed);
984 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
985 } else {
986 intfdata->in_flight++;
987 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
988 err = usb_submit_urb(this_urb, GFP_ATOMIC);
989 if (err) {
990 dbg("usb_submit_urb %p (write bulk) failed "
991 "(%d)", this_urb, err);
992 clear_bit(i, &portdata->out_busy);
993 spin_lock_irqsave(&intfdata->susp_lock, flags);
994 intfdata->in_flight--;
995 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
996 continue;
997 }
998 }
999
1000 portdata->tx_start_time[i] = jiffies;
1001 buf += todo;
1002 left -= todo;
1003 }
1004
1005 count -= left;
1006 dbg("%s: wrote (did %d)", __func__, count);
1007 return count;
1008}
1009
1010static void option_indat_callback(struct urb *urb)
1011{
1012 int err;
1013 int endpoint;
1014 struct usb_serial_port *port;
1015 struct tty_struct *tty;
1016 unsigned char *data = urb->transfer_buffer;
1017 int status = urb->status;
1018
1019 dbg("%s: %p", __func__, urb);
1020
1021 endpoint = usb_pipeendpoint(urb->pipe);
1022 port = urb->context;
1023
1024 if (status) {
1025 dbg("%s: nonzero status: %d on endpoint %02x.",
1026 __func__, status, endpoint);
1027 } else {
1028 tty = tty_port_tty_get(&port->port);
1029 if (urb->actual_length) {
1030 tty_insert_flip_string(tty, data, urb->actual_length);
1031 tty_flip_buffer_push(tty);
1032 } else
1033 dbg("%s: empty read urb received", __func__);
1034 tty_kref_put(tty);
1035
1036 /* Resubmit urb so we continue receiving */
1037 if (status != -ESHUTDOWN) {
1038 err = usb_submit_urb(urb, GFP_ATOMIC);
1039 if (err && err != -EPERM)
1040 printk(KERN_ERR "%s: resubmit read urb failed. "
1041 "(%d)", __func__, err);
1042 else
1043 usb_mark_last_busy(port->serial->dev);
1044 }
1045
1046 }
1047 return;
1048}
1049
1050static void option_outdat_callback(struct urb *urb)
1051{
1052 struct usb_serial_port *port;
1053 struct option_port_private *portdata;
1054 struct option_intf_private *intfdata;
1055 int i;
1056
1057 dbg("%s", __func__);
1058
1059 port = urb->context;
1060 intfdata = port->serial->private;
1061
1062 usb_serial_port_softint(port);
1063 usb_autopm_put_interface_async(port->serial->interface);
1064 portdata = usb_get_serial_port_data(port);
1065 spin_lock(&intfdata->susp_lock);
1066 intfdata->in_flight--;
1067 spin_unlock(&intfdata->susp_lock);
1068
1069 for (i = 0; i < N_OUT_URB; ++i) {
1070 if (portdata->out_urbs[i] == urb) {
1071 smp_mb__before_clear_bit();
1072 clear_bit(i, &portdata->out_busy);
1073 break;
1074 }
1075 }
1076}
1077
1078static void option_instat_callback(struct urb *urb) 1043static void option_instat_callback(struct urb *urb)
1079{ 1044{
1080 int err; 1045 int err;
@@ -1131,183 +1096,6 @@ static void option_instat_callback(struct urb *urb)
1131 } 1096 }
1132} 1097}
1133 1098
1134static int option_write_room(struct tty_struct *tty)
1135{
1136 struct usb_serial_port *port = tty->driver_data;
1137 struct option_port_private *portdata;
1138 int i;
1139 int data_len = 0;
1140 struct urb *this_urb;
1141
1142 portdata = usb_get_serial_port_data(port);
1143
1144 for (i = 0; i < N_OUT_URB; i++) {
1145 this_urb = portdata->out_urbs[i];
1146 if (this_urb && !test_bit(i, &portdata->out_busy))
1147 data_len += OUT_BUFLEN;
1148 }
1149
1150 dbg("%s: %d", __func__, data_len);
1151 return data_len;
1152}
1153
1154static int option_chars_in_buffer(struct tty_struct *tty)
1155{
1156 struct usb_serial_port *port = tty->driver_data;
1157 struct option_port_private *portdata;
1158 int i;
1159 int data_len = 0;
1160 struct urb *this_urb;
1161
1162 portdata = usb_get_serial_port_data(port);
1163
1164 for (i = 0; i < N_OUT_URB; i++) {
1165 this_urb = portdata->out_urbs[i];
1166 /* FIXME: This locking is insufficient as this_urb may
1167 go unused during the test */
1168 if (this_urb && test_bit(i, &portdata->out_busy))
1169 data_len += this_urb->transfer_buffer_length;
1170 }
1171 dbg("%s: %d", __func__, data_len);
1172 return data_len;
1173}
1174
1175static int option_open(struct tty_struct *tty, struct usb_serial_port *port)
1176{
1177 struct option_port_private *portdata;
1178 struct option_intf_private *intfdata;
1179 struct usb_serial *serial = port->serial;
1180 int i, err;
1181 struct urb *urb;
1182
1183 portdata = usb_get_serial_port_data(port);
1184 intfdata = serial->private;
1185
1186 dbg("%s", __func__);
1187
1188 /* Start reading from the IN endpoint */
1189 for (i = 0; i < N_IN_URB; i++) {
1190 urb = portdata->in_urbs[i];
1191 if (!urb)
1192 continue;
1193 err = usb_submit_urb(urb, GFP_KERNEL);
1194 if (err) {
1195 dbg("%s: submit urb %d failed (%d) %d",
1196 __func__, i, err,
1197 urb->transfer_buffer_length);
1198 }
1199 }
1200
1201 option_send_setup(port);
1202
1203 serial->interface->needs_remote_wakeup = 1;
1204 spin_lock_irq(&intfdata->susp_lock);
1205 portdata->opened = 1;
1206 spin_unlock_irq(&intfdata->susp_lock);
1207 usb_autopm_put_interface(serial->interface);
1208
1209 return 0;
1210}
1211
1212static void option_dtr_rts(struct usb_serial_port *port, int on)
1213{
1214 struct usb_serial *serial = port->serial;
1215 struct option_port_private *portdata;
1216
1217 dbg("%s", __func__);
1218 portdata = usb_get_serial_port_data(port);
1219 mutex_lock(&serial->disc_mutex);
1220 portdata->rts_state = on;
1221 portdata->dtr_state = on;
1222 if (serial->dev)
1223 option_send_setup(port);
1224 mutex_unlock(&serial->disc_mutex);
1225}
1226
1227
1228static void option_close(struct usb_serial_port *port)
1229{
1230 int i;
1231 struct usb_serial *serial = port->serial;
1232 struct option_port_private *portdata;
1233 struct option_intf_private *intfdata = port->serial->private;
1234
1235 dbg("%s", __func__);
1236 portdata = usb_get_serial_port_data(port);
1237
1238 if (serial->dev) {
1239 /* Stop reading/writing urbs */
1240 spin_lock_irq(&intfdata->susp_lock);
1241 portdata->opened = 0;
1242 spin_unlock_irq(&intfdata->susp_lock);
1243
1244 for (i = 0; i < N_IN_URB; i++)
1245 usb_kill_urb(portdata->in_urbs[i]);
1246 for (i = 0; i < N_OUT_URB; i++)
1247 usb_kill_urb(portdata->out_urbs[i]);
1248 usb_autopm_get_interface(serial->interface);
1249 serial->interface->needs_remote_wakeup = 0;
1250 }
1251}
1252
1253/* Helper functions used by option_setup_urbs */
1254static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
1255 int dir, void *ctx, char *buf, int len,
1256 void (*callback)(struct urb *))
1257{
1258 struct urb *urb;
1259
1260 if (endpoint == -1)
1261 return NULL; /* endpoint not needed */
1262
1263 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1264 if (urb == NULL) {
1265 dbg("%s: alloc for endpoint %d failed.", __func__, endpoint);
1266 return NULL;
1267 }
1268
1269 /* Fill URB using supplied data. */
1270 usb_fill_bulk_urb(urb, serial->dev,
1271 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1272 buf, len, callback, ctx);
1273
1274 return urb;
1275}
1276
1277/* Setup urbs */
1278static void option_setup_urbs(struct usb_serial *serial)
1279{
1280 int i, j;
1281 struct usb_serial_port *port;
1282 struct option_port_private *portdata;
1283
1284 dbg("%s", __func__);
1285
1286 for (i = 0; i < serial->num_ports; i++) {
1287 port = serial->port[i];
1288 portdata = usb_get_serial_port_data(port);
1289
1290 /* Do indat endpoints first */
1291 for (j = 0; j < N_IN_URB; ++j) {
1292 portdata->in_urbs[j] = option_setup_urb(serial,
1293 port->bulk_in_endpointAddress,
1294 USB_DIR_IN, port,
1295 portdata->in_buffer[j],
1296 IN_BUFLEN, option_indat_callback);
1297 }
1298
1299 /* outdat endpoints */
1300 for (j = 0; j < N_OUT_URB; ++j) {
1301 portdata->out_urbs[j] = option_setup_urb(serial,
1302 port->bulk_out_endpointAddress,
1303 USB_DIR_OUT, port,
1304 portdata->out_buffer[j],
1305 OUT_BUFLEN, option_outdat_callback);
1306 }
1307 }
1308}
1309
1310
1311/** send RTS/DTR state to the port. 1099/** send RTS/DTR state to the port.
1312 * 1100 *
1313 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 1101 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
@@ -1316,15 +1104,16 @@ static void option_setup_urbs(struct usb_serial *serial)
1316static int option_send_setup(struct usb_serial_port *port) 1104static int option_send_setup(struct usb_serial_port *port)
1317{ 1105{
1318 struct usb_serial *serial = port->serial; 1106 struct usb_serial *serial = port->serial;
1319 struct option_intf_private *intfdata = 1107 struct usb_wwan_intf_private *intfdata =
1320 (struct option_intf_private *) serial->private; 1108 (struct usb_wwan_intf_private *) serial->private;
1321 struct option_port_private *portdata; 1109 struct option_port_private *portdata;
1322 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 1110 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
1323 int val = 0; 1111 int val = 0;
1324 dbg("%s", __func__); 1112 dbg("%s", __func__);
1325 1113
1326 if (is_blacklisted(ifNum, intfdata->blacklist_info) == 1114 if (is_blacklisted(ifNum,
1327 OPTION_BLACKLIST_SENDSETUP) { 1115 (struct option_blacklist_info *) intfdata->private)
1116 == OPTION_BLACKLIST_SENDSETUP) {
1328 dbg("No send_setup on blacklisted interface #%d\n", ifNum); 1117 dbg("No send_setup on blacklisted interface #%d\n", ifNum);
1329 return -EIO; 1118 return -EIO;
1330 } 1119 }
@@ -1341,224 +1130,6 @@ static int option_send_setup(struct usb_serial_port *port)
1341 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); 1130 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1342} 1131}
1343 1132
1344static int option_startup(struct usb_serial *serial)
1345{
1346 int i, j, err;
1347 struct usb_serial_port *port;
1348 struct option_port_private *portdata;
1349 u8 *buffer;
1350
1351 dbg("%s", __func__);
1352
1353 /* Now setup per port private data */
1354 for (i = 0; i < serial->num_ports; i++) {
1355 port = serial->port[i];
1356 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
1357 if (!portdata) {
1358 dbg("%s: kmalloc for option_port_private (%d) failed!.",
1359 __func__, i);
1360 return 1;
1361 }
1362 init_usb_anchor(&portdata->delayed);
1363
1364 for (j = 0; j < N_IN_URB; j++) {
1365 buffer = (u8 *)__get_free_page(GFP_KERNEL);
1366 if (!buffer)
1367 goto bail_out_error;
1368 portdata->in_buffer[j] = buffer;
1369 }
1370
1371 for (j = 0; j < N_OUT_URB; j++) {
1372 buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
1373 if (!buffer)
1374 goto bail_out_error2;
1375 portdata->out_buffer[j] = buffer;
1376 }
1377
1378 usb_set_serial_port_data(port, portdata);
1379
1380 if (!port->interrupt_in_urb)
1381 continue;
1382 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
1383 if (err)
1384 dbg("%s: submit irq_in urb failed %d",
1385 __func__, err);
1386 }
1387 option_setup_urbs(serial);
1388 return 0;
1389
1390bail_out_error2:
1391 for (j = 0; j < N_OUT_URB; j++)
1392 kfree(portdata->out_buffer[j]);
1393bail_out_error:
1394 for (j = 0; j < N_IN_URB; j++)
1395 if (portdata->in_buffer[j])
1396 free_page((unsigned long)portdata->in_buffer[j]);
1397 kfree(portdata);
1398 return 1;
1399}
1400
1401static void stop_read_write_urbs(struct usb_serial *serial)
1402{
1403 int i, j;
1404 struct usb_serial_port *port;
1405 struct option_port_private *portdata;
1406
1407 /* Stop reading/writing urbs */
1408 for (i = 0; i < serial->num_ports; ++i) {
1409 port = serial->port[i];
1410 portdata = usb_get_serial_port_data(port);
1411 for (j = 0; j < N_IN_URB; j++)
1412 usb_kill_urb(portdata->in_urbs[j]);
1413 for (j = 0; j < N_OUT_URB; j++)
1414 usb_kill_urb(portdata->out_urbs[j]);
1415 }
1416}
1417
1418static void option_disconnect(struct usb_serial *serial)
1419{
1420 dbg("%s", __func__);
1421
1422 stop_read_write_urbs(serial);
1423}
1424
1425static void option_release(struct usb_serial *serial)
1426{
1427 int i, j;
1428 struct usb_serial_port *port;
1429 struct option_port_private *portdata;
1430
1431 dbg("%s", __func__);
1432
1433 /* Now free them */
1434 for (i = 0; i < serial->num_ports; ++i) {
1435 port = serial->port[i];
1436 portdata = usb_get_serial_port_data(port);
1437
1438 for (j = 0; j < N_IN_URB; j++) {
1439 if (portdata->in_urbs[j]) {
1440 usb_free_urb(portdata->in_urbs[j]);
1441 free_page((unsigned long)
1442 portdata->in_buffer[j]);
1443 portdata->in_urbs[j] = NULL;
1444 }
1445 }
1446 for (j = 0; j < N_OUT_URB; j++) {
1447 if (portdata->out_urbs[j]) {
1448 usb_free_urb(portdata->out_urbs[j]);
1449 kfree(portdata->out_buffer[j]);
1450 portdata->out_urbs[j] = NULL;
1451 }
1452 }
1453 }
1454
1455 /* Now free per port private data */
1456 for (i = 0; i < serial->num_ports; i++) {
1457 port = serial->port[i];
1458 kfree(usb_get_serial_port_data(port));
1459 }
1460}
1461
1462#ifdef CONFIG_PM
1463static int option_suspend(struct usb_serial *serial, pm_message_t message)
1464{
1465 struct option_intf_private *intfdata = serial->private;
1466 int b;
1467
1468 dbg("%s entered", __func__);
1469
1470 if (message.event & PM_EVENT_AUTO) {
1471 spin_lock_irq(&intfdata->susp_lock);
1472 b = intfdata->in_flight;
1473 spin_unlock_irq(&intfdata->susp_lock);
1474
1475 if (b)
1476 return -EBUSY;
1477 }
1478
1479 spin_lock_irq(&intfdata->susp_lock);
1480 intfdata->suspended = 1;
1481 spin_unlock_irq(&intfdata->susp_lock);
1482 stop_read_write_urbs(serial);
1483
1484 return 0;
1485}
1486
1487static void play_delayed(struct usb_serial_port *port)
1488{
1489 struct option_intf_private *data;
1490 struct option_port_private *portdata;
1491 struct urb *urb;
1492 int err;
1493
1494 portdata = usb_get_serial_port_data(port);
1495 data = port->serial->private;
1496 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
1497 err = usb_submit_urb(urb, GFP_ATOMIC);
1498 if (!err)
1499 data->in_flight++;
1500 }
1501}
1502
1503static int option_resume(struct usb_serial *serial)
1504{
1505 int i, j;
1506 struct usb_serial_port *port;
1507 struct option_intf_private *intfdata = serial->private;
1508 struct option_port_private *portdata;
1509 struct urb *urb;
1510 int err = 0;
1511
1512 dbg("%s entered", __func__);
1513 /* get the interrupt URBs resubmitted unconditionally */
1514 for (i = 0; i < serial->num_ports; i++) {
1515 port = serial->port[i];
1516 if (!port->interrupt_in_urb) {
1517 dbg("%s: No interrupt URB for port %d", __func__, i);
1518 continue;
1519 }
1520 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
1521 dbg("Submitted interrupt URB for port %d (result %d)", i, err);
1522 if (err < 0) {
1523 err("%s: Error %d for interrupt URB of port%d",
1524 __func__, err, i);
1525 goto err_out;
1526 }
1527 }
1528
1529 for (i = 0; i < serial->num_ports; i++) {
1530 /* walk all ports */
1531 port = serial->port[i];
1532 portdata = usb_get_serial_port_data(port);
1533
1534 /* skip closed ports */
1535 spin_lock_irq(&intfdata->susp_lock);
1536 if (!portdata->opened) {
1537 spin_unlock_irq(&intfdata->susp_lock);
1538 continue;
1539 }
1540
1541 for (j = 0; j < N_IN_URB; j++) {
1542 urb = portdata->in_urbs[j];
1543 err = usb_submit_urb(urb, GFP_ATOMIC);
1544 if (err < 0) {
1545 err("%s: Error %d for bulk URB %d",
1546 __func__, err, i);
1547 spin_unlock_irq(&intfdata->susp_lock);
1548 goto err_out;
1549 }
1550 }
1551 play_delayed(port);
1552 spin_unlock_irq(&intfdata->susp_lock);
1553 }
1554 spin_lock_irq(&intfdata->susp_lock);
1555 intfdata->suspended = 0;
1556 spin_unlock_irq(&intfdata->susp_lock);
1557err_out:
1558 return err;
1559}
1560#endif
1561
1562MODULE_AUTHOR(DRIVER_AUTHOR); 1133MODULE_AUTHOR(DRIVER_AUTHOR);
1563MODULE_DESCRIPTION(DRIVER_DESC); 1134MODULE_DESCRIPTION(DRIVER_DESC);
1564MODULE_VERSION(DRIVER_VERSION); 1135MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index deeacdea05db..e199b0f4f99c 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -51,12 +51,13 @@
51#include <linux/usb.h> 51#include <linux/usb.h>
52#include <linux/usb/serial.h> 52#include <linux/usb/serial.h>
53#include <linux/uaccess.h> 53#include <linux/uaccess.h>
54#include <linux/kfifo.h>
54#include "oti6858.h" 55#include "oti6858.h"
55 56
56#define OTI6858_DESCRIPTION \ 57#define OTI6858_DESCRIPTION \
57 "Ours Technology Inc. OTi-6858 USB to serial adapter driver" 58 "Ours Technology Inc. OTi-6858 USB to serial adapter driver"
58#define OTI6858_AUTHOR "Tomasz Michal Lukaszewski <FIXME@FIXME>" 59#define OTI6858_AUTHOR "Tomasz Michal Lukaszewski <FIXME@FIXME>"
59#define OTI6858_VERSION "0.1" 60#define OTI6858_VERSION "0.2"
60 61
61static const struct usb_device_id id_table[] = { 62static const struct usb_device_id id_table[] = {
62 { USB_DEVICE(OTI6858_VENDOR_ID, OTI6858_PRODUCT_ID) }, 63 { USB_DEVICE(OTI6858_VENDOR_ID, OTI6858_PRODUCT_ID) },
@@ -75,18 +76,6 @@ static struct usb_driver oti6858_driver = {
75 76
76static int debug; 77static int debug;
77 78
78
79/* buffering code, copied from pl2303 driver */
80#define PL2303_BUF_SIZE 1024
81#define PL2303_TMP_BUF_SIZE 1024
82
83struct oti6858_buf {
84 unsigned int buf_size;
85 char *buf_buf;
86 char *buf_get;
87 char *buf_put;
88};
89
90/* requests */ 79/* requests */
91#define OTI6858_REQ_GET_STATUS (USB_DIR_IN | USB_TYPE_VENDOR | 0x00) 80#define OTI6858_REQ_GET_STATUS (USB_DIR_IN | USB_TYPE_VENDOR | 0x00)
92#define OTI6858_REQ_T_GET_STATUS 0x01 81#define OTI6858_REQ_T_GET_STATUS 0x01
@@ -161,18 +150,6 @@ static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
161static int oti6858_startup(struct usb_serial *serial); 150static int oti6858_startup(struct usb_serial *serial);
162static void oti6858_release(struct usb_serial *serial); 151static void oti6858_release(struct usb_serial *serial);
163 152
164/* functions operating on buffers */
165static struct oti6858_buf *oti6858_buf_alloc(unsigned int size);
166static void oti6858_buf_free(struct oti6858_buf *pb);
167static void oti6858_buf_clear(struct oti6858_buf *pb);
168static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb);
169static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb);
170static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
171 unsigned int count);
172static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
173 unsigned int count);
174
175
176/* device info */ 153/* device info */
177static struct usb_serial_driver oti6858_device = { 154static struct usb_serial_driver oti6858_device = {
178 .driver = { 155 .driver = {
@@ -201,7 +178,6 @@ static struct usb_serial_driver oti6858_device = {
201struct oti6858_private { 178struct oti6858_private {
202 spinlock_t lock; 179 spinlock_t lock;
203 180
204 struct oti6858_buf *buf;
205 struct oti6858_control_pkt status; 181 struct oti6858_control_pkt status;
206 182
207 struct { 183 struct {
@@ -295,7 +271,7 @@ static void setup_line(struct work_struct *work)
295 } 271 }
296} 272}
297 273
298void send_data(struct work_struct *work) 274static void send_data(struct work_struct *work)
299{ 275{
300 struct oti6858_private *priv = container_of(work, 276 struct oti6858_private *priv = container_of(work,
301 struct oti6858_private, delayed_write_work.work); 277 struct oti6858_private, delayed_write_work.work);
@@ -314,9 +290,12 @@ void send_data(struct work_struct *work)
314 return; 290 return;
315 } 291 }
316 priv->flags.write_urb_in_use = 1; 292 priv->flags.write_urb_in_use = 1;
317
318 count = oti6858_buf_data_avail(priv->buf);
319 spin_unlock_irqrestore(&priv->lock, flags); 293 spin_unlock_irqrestore(&priv->lock, flags);
294
295 spin_lock_irqsave(&port->lock, flags);
296 count = kfifo_len(&port->write_fifo);
297 spin_unlock_irqrestore(&port->lock, flags);
298
320 if (count > port->bulk_out_size) 299 if (count > port->bulk_out_size)
321 count = port->bulk_out_size; 300 count = port->bulk_out_size;
322 301
@@ -350,10 +329,9 @@ void send_data(struct work_struct *work)
350 return; 329 return;
351 } 330 }
352 331
353 spin_lock_irqsave(&priv->lock, flags); 332 count = kfifo_out_locked(&port->write_fifo,
354 oti6858_buf_get(priv->buf, port->write_urb->transfer_buffer, count); 333 port->write_urb->transfer_buffer,
355 spin_unlock_irqrestore(&priv->lock, flags); 334 count, &port->lock);
356
357 port->write_urb->transfer_buffer_length = count; 335 port->write_urb->transfer_buffer_length = count;
358 port->write_urb->dev = port->serial->dev; 336 port->write_urb->dev = port->serial->dev;
359 result = usb_submit_urb(port->write_urb, GFP_NOIO); 337 result = usb_submit_urb(port->write_urb, GFP_NOIO);
@@ -376,11 +354,6 @@ static int oti6858_startup(struct usb_serial *serial)
376 priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL); 354 priv = kzalloc(sizeof(struct oti6858_private), GFP_KERNEL);
377 if (!priv) 355 if (!priv)
378 break; 356 break;
379 priv->buf = oti6858_buf_alloc(PL2303_BUF_SIZE);
380 if (priv->buf == NULL) {
381 kfree(priv);
382 break;
383 }
384 357
385 spin_lock_init(&priv->lock); 358 spin_lock_init(&priv->lock);
386 init_waitqueue_head(&priv->intr_wait); 359 init_waitqueue_head(&priv->intr_wait);
@@ -397,7 +370,6 @@ static int oti6858_startup(struct usb_serial *serial)
397 370
398 for (--i; i >= 0; --i) { 371 for (--i; i >= 0; --i) {
399 priv = usb_get_serial_port_data(serial->port[i]); 372 priv = usb_get_serial_port_data(serial->port[i]);
400 oti6858_buf_free(priv->buf);
401 kfree(priv); 373 kfree(priv);
402 usb_set_serial_port_data(serial->port[i], NULL); 374 usb_set_serial_port_data(serial->port[i], NULL);
403 } 375 }
@@ -407,17 +379,12 @@ static int oti6858_startup(struct usb_serial *serial)
407static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port, 379static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
408 const unsigned char *buf, int count) 380 const unsigned char *buf, int count)
409{ 381{
410 struct oti6858_private *priv = usb_get_serial_port_data(port);
411 unsigned long flags;
412
413 dbg("%s(port = %d, count = %d)", __func__, port->number, count); 382 dbg("%s(port = %d, count = %d)", __func__, port->number, count);
414 383
415 if (!count) 384 if (!count)
416 return count; 385 return count;
417 386
418 spin_lock_irqsave(&priv->lock, flags); 387 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
419 count = oti6858_buf_put(priv->buf, buf, count);
420 spin_unlock_irqrestore(&priv->lock, flags);
421 388
422 return count; 389 return count;
423} 390}
@@ -425,15 +392,14 @@ static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
425static int oti6858_write_room(struct tty_struct *tty) 392static int oti6858_write_room(struct tty_struct *tty)
426{ 393{
427 struct usb_serial_port *port = tty->driver_data; 394 struct usb_serial_port *port = tty->driver_data;
428 struct oti6858_private *priv = usb_get_serial_port_data(port);
429 int room = 0; 395 int room = 0;
430 unsigned long flags; 396 unsigned long flags;
431 397
432 dbg("%s(port = %d)", __func__, port->number); 398 dbg("%s(port = %d)", __func__, port->number);
433 399
434 spin_lock_irqsave(&priv->lock, flags); 400 spin_lock_irqsave(&port->lock, flags);
435 room = oti6858_buf_space_avail(priv->buf); 401 room = kfifo_avail(&port->write_fifo);
436 spin_unlock_irqrestore(&priv->lock, flags); 402 spin_unlock_irqrestore(&port->lock, flags);
437 403
438 return room; 404 return room;
439} 405}
@@ -441,15 +407,14 @@ static int oti6858_write_room(struct tty_struct *tty)
441static int oti6858_chars_in_buffer(struct tty_struct *tty) 407static int oti6858_chars_in_buffer(struct tty_struct *tty)
442{ 408{
443 struct usb_serial_port *port = tty->driver_data; 409 struct usb_serial_port *port = tty->driver_data;
444 struct oti6858_private *priv = usb_get_serial_port_data(port);
445 int chars = 0; 410 int chars = 0;
446 unsigned long flags; 411 unsigned long flags;
447 412
448 dbg("%s(port = %d)", __func__, port->number); 413 dbg("%s(port = %d)", __func__, port->number);
449 414
450 spin_lock_irqsave(&priv->lock, flags); 415 spin_lock_irqsave(&port->lock, flags);
451 chars = oti6858_buf_data_avail(priv->buf); 416 chars = kfifo_len(&port->write_fifo);
452 spin_unlock_irqrestore(&priv->lock, flags); 417 spin_unlock_irqrestore(&port->lock, flags);
453 418
454 return chars; 419 return chars;
455} 420}
@@ -640,10 +605,10 @@ static void oti6858_close(struct usb_serial_port *port)
640 605
641 dbg("%s(port = %d)", __func__, port->number); 606 dbg("%s(port = %d)", __func__, port->number);
642 607
643 spin_lock_irqsave(&priv->lock, flags); 608 spin_lock_irqsave(&port->lock, flags);
644 /* clear out any remaining data in the buffer */ 609 /* clear out any remaining data in the buffer */
645 oti6858_buf_clear(priv->buf); 610 kfifo_reset_out(&port->write_fifo);
646 spin_unlock_irqrestore(&priv->lock, flags); 611 spin_unlock_irqrestore(&port->lock, flags);
647 612
648 dbg("%s(): after buf_clear()", __func__); 613 dbg("%s(): after buf_clear()", __func__);
649 614
@@ -785,18 +750,12 @@ static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
785 750
786static void oti6858_release(struct usb_serial *serial) 751static void oti6858_release(struct usb_serial *serial)
787{ 752{
788 struct oti6858_private *priv;
789 int i; 753 int i;
790 754
791 dbg("%s()", __func__); 755 dbg("%s()", __func__);
792 756
793 for (i = 0; i < serial->num_ports; ++i) { 757 for (i = 0; i < serial->num_ports; ++i)
794 priv = usb_get_serial_port_data(serial->port[i]); 758 kfree(usb_get_serial_port_data(serial->port[i]));
795 if (priv) {
796 oti6858_buf_free(priv->buf);
797 kfree(priv);
798 }
799 }
800} 759}
801 760
802static void oti6858_read_int_callback(struct urb *urb) 761static void oti6858_read_int_callback(struct urb *urb)
@@ -889,10 +848,14 @@ static void oti6858_read_int_callback(struct urb *urb)
889 } 848 }
890 } else if (!transient) { 849 } else if (!transient) {
891 unsigned long flags; 850 unsigned long flags;
851 int count;
852
853 spin_lock_irqsave(&port->lock, flags);
854 count = kfifo_len(&port->write_fifo);
855 spin_unlock_irqrestore(&port->lock, flags);
892 856
893 spin_lock_irqsave(&priv->lock, flags); 857 spin_lock_irqsave(&priv->lock, flags);
894 if (priv->flags.write_urb_in_use == 0 858 if (priv->flags.write_urb_in_use == 0 && count != 0) {
895 && oti6858_buf_data_avail(priv->buf) != 0) {
896 schedule_delayed_work(&priv->delayed_write_work, 0); 859 schedule_delayed_work(&priv->delayed_write_work, 0);
897 resubmit = 0; 860 resubmit = 0;
898 } 861 }
@@ -1014,165 +977,6 @@ static void oti6858_write_bulk_callback(struct urb *urb)
1014 } 977 }
1015} 978}
1016 979
1017
1018/*
1019 * oti6858_buf_alloc
1020 *
1021 * Allocate a circular buffer and all associated memory.
1022 */
1023static struct oti6858_buf *oti6858_buf_alloc(unsigned int size)
1024{
1025 struct oti6858_buf *pb;
1026
1027 if (size == 0)
1028 return NULL;
1029
1030 pb = kmalloc(sizeof(struct oti6858_buf), GFP_KERNEL);
1031 if (pb == NULL)
1032 return NULL;
1033
1034 pb->buf_buf = kmalloc(size, GFP_KERNEL);
1035 if (pb->buf_buf == NULL) {
1036 kfree(pb);
1037 return NULL;
1038 }
1039
1040 pb->buf_size = size;
1041 pb->buf_get = pb->buf_put = pb->buf_buf;
1042
1043 return pb;
1044}
1045
1046/*
1047 * oti6858_buf_free
1048 *
1049 * Free the buffer and all associated memory.
1050 */
1051static void oti6858_buf_free(struct oti6858_buf *pb)
1052{
1053 if (pb) {
1054 kfree(pb->buf_buf);
1055 kfree(pb);
1056 }
1057}
1058
1059/*
1060 * oti6858_buf_clear
1061 *
1062 * Clear out all data in the circular buffer.
1063 */
1064static void oti6858_buf_clear(struct oti6858_buf *pb)
1065{
1066 if (pb != NULL) {
1067 /* equivalent to a get of all data available */
1068 pb->buf_get = pb->buf_put;
1069 }
1070}
1071
1072/*
1073 * oti6858_buf_data_avail
1074 *
1075 * Return the number of bytes of data available in the circular
1076 * buffer.
1077 */
1078static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb)
1079{
1080 if (pb == NULL)
1081 return 0;
1082 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
1083}
1084
1085/*
1086 * oti6858_buf_space_avail
1087 *
1088 * Return the number of bytes of space available in the circular
1089 * buffer.
1090 */
1091static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb)
1092{
1093 if (pb == NULL)
1094 return 0;
1095 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
1096}
1097
1098/*
1099 * oti6858_buf_put
1100 *
1101 * Copy data data from a user buffer and put it into the circular buffer.
1102 * Restrict to the amount of space available.
1103 *
1104 * Return the number of bytes copied.
1105 */
1106static unsigned int oti6858_buf_put(struct oti6858_buf *pb, const char *buf,
1107 unsigned int count)
1108{
1109 unsigned int len;
1110
1111 if (pb == NULL)
1112 return 0;
1113
1114 len = oti6858_buf_space_avail(pb);
1115 if (count > len)
1116 count = len;
1117
1118 if (count == 0)
1119 return 0;
1120
1121 len = pb->buf_buf + pb->buf_size - pb->buf_put;
1122 if (count > len) {
1123 memcpy(pb->buf_put, buf, len);
1124 memcpy(pb->buf_buf, buf+len, count - len);
1125 pb->buf_put = pb->buf_buf + count - len;
1126 } else {
1127 memcpy(pb->buf_put, buf, count);
1128 if (count < len)
1129 pb->buf_put += count;
1130 else /* count == len */
1131 pb->buf_put = pb->buf_buf;
1132 }
1133
1134 return count;
1135}
1136
1137/*
1138 * oti6858_buf_get
1139 *
1140 * Get data from the circular buffer and copy to the given buffer.
1141 * Restrict to the amount of data available.
1142 *
1143 * Return the number of bytes copied.
1144 */
1145static unsigned int oti6858_buf_get(struct oti6858_buf *pb, char *buf,
1146 unsigned int count)
1147{
1148 unsigned int len;
1149
1150 if (pb == NULL)
1151 return 0;
1152
1153 len = oti6858_buf_data_avail(pb);
1154 if (count > len)
1155 count = len;
1156
1157 if (count == 0)
1158 return 0;
1159
1160 len = pb->buf_buf + pb->buf_size - pb->buf_get;
1161 if (count > len) {
1162 memcpy(buf, pb->buf_get, len);
1163 memcpy(buf+len, pb->buf_buf, count - len);
1164 pb->buf_get = pb->buf_buf + count - len;
1165 } else {
1166 memcpy(buf, pb->buf_get, count);
1167 if (count < len)
1168 pb->buf_get += count;
1169 else /* count == len */
1170 pb->buf_get = pb->buf_buf;
1171 }
1172
1173 return count;
1174}
1175
1176/* module description and (de)initialization */ 980/* module description and (de)initialization */
1177 981
1178static int __init oti6858_init(void) 982static int __init oti6858_init(void)
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index c28b1607eacc..6b6001822279 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -40,16 +40,6 @@ static int debug;
40 40
41#define PL2303_CLOSING_WAIT (30*HZ) 41#define PL2303_CLOSING_WAIT (30*HZ)
42 42
43#define PL2303_BUF_SIZE 1024
44#define PL2303_TMP_BUF_SIZE 1024
45
46struct pl2303_buf {
47 unsigned int buf_size;
48 char *buf_buf;
49 char *buf_get;
50 char *buf_put;
51};
52
53static const struct usb_device_id id_table[] = { 43static const struct usb_device_id id_table[] = {
54 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, 44 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
55 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, 45 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
@@ -157,173 +147,12 @@ enum pl2303_type {
157 147
158struct pl2303_private { 148struct pl2303_private {
159 spinlock_t lock; 149 spinlock_t lock;
160 struct pl2303_buf *buf;
161 int write_urb_in_use;
162 wait_queue_head_t delta_msr_wait; 150 wait_queue_head_t delta_msr_wait;
163 u8 line_control; 151 u8 line_control;
164 u8 line_status; 152 u8 line_status;
165 enum pl2303_type type; 153 enum pl2303_type type;
166}; 154};
167 155
168/*
169 * pl2303_buf_alloc
170 *
171 * Allocate a circular buffer and all associated memory.
172 */
173static struct pl2303_buf *pl2303_buf_alloc(unsigned int size)
174{
175 struct pl2303_buf *pb;
176
177 if (size == 0)
178 return NULL;
179
180 pb = kmalloc(sizeof(struct pl2303_buf), GFP_KERNEL);
181 if (pb == NULL)
182 return NULL;
183
184 pb->buf_buf = kmalloc(size, GFP_KERNEL);
185 if (pb->buf_buf == NULL) {
186 kfree(pb);
187 return NULL;
188 }
189
190 pb->buf_size = size;
191 pb->buf_get = pb->buf_put = pb->buf_buf;
192
193 return pb;
194}
195
196/*
197 * pl2303_buf_free
198 *
199 * Free the buffer and all associated memory.
200 */
201static void pl2303_buf_free(struct pl2303_buf *pb)
202{
203 if (pb) {
204 kfree(pb->buf_buf);
205 kfree(pb);
206 }
207}
208
209/*
210 * pl2303_buf_clear
211 *
212 * Clear out all data in the circular buffer.
213 */
214static void pl2303_buf_clear(struct pl2303_buf *pb)
215{
216 if (pb != NULL)
217 pb->buf_get = pb->buf_put;
218 /* equivalent to a get of all data available */
219}
220
221/*
222 * pl2303_buf_data_avail
223 *
224 * Return the number of bytes of data available in the circular
225 * buffer.
226 */
227static unsigned int pl2303_buf_data_avail(struct pl2303_buf *pb)
228{
229 if (pb == NULL)
230 return 0;
231
232 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
233}
234
235/*
236 * pl2303_buf_space_avail
237 *
238 * Return the number of bytes of space available in the circular
239 * buffer.
240 */
241static unsigned int pl2303_buf_space_avail(struct pl2303_buf *pb)
242{
243 if (pb == NULL)
244 return 0;
245
246 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
247}
248
249/*
250 * pl2303_buf_put
251 *
252 * Copy data data from a user buffer and put it into the circular buffer.
253 * Restrict to the amount of space available.
254 *
255 * Return the number of bytes copied.
256 */
257static unsigned int pl2303_buf_put(struct pl2303_buf *pb, const char *buf,
258 unsigned int count)
259{
260 unsigned int len;
261
262 if (pb == NULL)
263 return 0;
264
265 len = pl2303_buf_space_avail(pb);
266 if (count > len)
267 count = len;
268
269 if (count == 0)
270 return 0;
271
272 len = pb->buf_buf + pb->buf_size - pb->buf_put;
273 if (count > len) {
274 memcpy(pb->buf_put, buf, len);
275 memcpy(pb->buf_buf, buf+len, count - len);
276 pb->buf_put = pb->buf_buf + count - len;
277 } else {
278 memcpy(pb->buf_put, buf, count);
279 if (count < len)
280 pb->buf_put += count;
281 else /* count == len */
282 pb->buf_put = pb->buf_buf;
283 }
284
285 return count;
286}
287
288/*
289 * pl2303_buf_get
290 *
291 * Get data from the circular buffer and copy to the given buffer.
292 * Restrict to the amount of data available.
293 *
294 * Return the number of bytes copied.
295 */
296static unsigned int pl2303_buf_get(struct pl2303_buf *pb, char *buf,
297 unsigned int count)
298{
299 unsigned int len;
300
301 if (pb == NULL)
302 return 0;
303
304 len = pl2303_buf_data_avail(pb);
305 if (count > len)
306 count = len;
307
308 if (count == 0)
309 return 0;
310
311 len = pb->buf_buf + pb->buf_size - pb->buf_get;
312 if (count > len) {
313 memcpy(buf, pb->buf_get, len);
314 memcpy(buf+len, pb->buf_buf, count - len);
315 pb->buf_get = pb->buf_buf + count - len;
316 } else {
317 memcpy(buf, pb->buf_get, count);
318 if (count < len)
319 pb->buf_get += count;
320 else /* count == len */
321 pb->buf_get = pb->buf_buf;
322 }
323
324 return count;
325}
326
327static int pl2303_vendor_read(__u16 value, __u16 index, 156static int pl2303_vendor_read(__u16 value, __u16 index,
328 struct usb_serial *serial, unsigned char *buf) 157 struct usb_serial *serial, unsigned char *buf)
329{ 158{
@@ -372,11 +201,6 @@ static int pl2303_startup(struct usb_serial *serial)
372 if (!priv) 201 if (!priv)
373 goto cleanup; 202 goto cleanup;
374 spin_lock_init(&priv->lock); 203 spin_lock_init(&priv->lock);
375 priv->buf = pl2303_buf_alloc(PL2303_BUF_SIZE);
376 if (priv->buf == NULL) {
377 kfree(priv);
378 goto cleanup;
379 }
380 init_waitqueue_head(&priv->delta_msr_wait); 204 init_waitqueue_head(&priv->delta_msr_wait);
381 priv->type = type; 205 priv->type = type;
382 usb_set_serial_port_data(serial->port[i], priv); 206 usb_set_serial_port_data(serial->port[i], priv);
@@ -404,7 +228,6 @@ cleanup:
404 kfree(buf); 228 kfree(buf);
405 for (--i; i >= 0; --i) { 229 for (--i; i >= 0; --i) {
406 priv = usb_get_serial_port_data(serial->port[i]); 230 priv = usb_get_serial_port_data(serial->port[i]);
407 pl2303_buf_free(priv->buf);
408 kfree(priv); 231 kfree(priv);
409 usb_set_serial_port_data(serial->port[i], NULL); 232 usb_set_serial_port_data(serial->port[i], NULL);
410 } 233 }
@@ -422,102 +245,6 @@ static int set_control_lines(struct usb_device *dev, u8 value)
422 return retval; 245 return retval;
423} 246}
424 247
425static void pl2303_send(struct usb_serial_port *port)
426{
427 int count, result;
428 struct pl2303_private *priv = usb_get_serial_port_data(port);
429 unsigned long flags;
430
431 dbg("%s - port %d", __func__, port->number);
432
433 spin_lock_irqsave(&priv->lock, flags);
434
435 if (priv->write_urb_in_use) {
436 spin_unlock_irqrestore(&priv->lock, flags);
437 return;
438 }
439
440 count = pl2303_buf_get(priv->buf, port->write_urb->transfer_buffer,
441 port->bulk_out_size);
442
443 if (count == 0) {
444 spin_unlock_irqrestore(&priv->lock, flags);
445 return;
446 }
447
448 priv->write_urb_in_use = 1;
449
450 spin_unlock_irqrestore(&priv->lock, flags);
451
452 usb_serial_debug_data(debug, &port->dev, __func__, count,
453 port->write_urb->transfer_buffer);
454
455 port->write_urb->transfer_buffer_length = count;
456 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
457 if (result) {
458 dev_err(&port->dev, "%s - failed submitting write urb,"
459 " error %d\n", __func__, result);
460 priv->write_urb_in_use = 0;
461 /* TODO: reschedule pl2303_send */
462 }
463
464 usb_serial_port_softint(port);
465}
466
467static int pl2303_write(struct tty_struct *tty, struct usb_serial_port *port,
468 const unsigned char *buf, int count)
469{
470 struct pl2303_private *priv = usb_get_serial_port_data(port);
471 unsigned long flags;
472
473 dbg("%s - port %d, %d bytes", __func__, port->number, count);
474
475 if (!count)
476 return count;
477
478 spin_lock_irqsave(&priv->lock, flags);
479 count = pl2303_buf_put(priv->buf, buf, count);
480 spin_unlock_irqrestore(&priv->lock, flags);
481
482 pl2303_send(port);
483
484 return count;
485}
486
487static int pl2303_write_room(struct tty_struct *tty)
488{
489 struct usb_serial_port *port = tty->driver_data;
490 struct pl2303_private *priv = usb_get_serial_port_data(port);
491 int room = 0;
492 unsigned long flags;
493
494 dbg("%s - port %d", __func__, port->number);
495
496 spin_lock_irqsave(&priv->lock, flags);
497 room = pl2303_buf_space_avail(priv->buf);
498 spin_unlock_irqrestore(&priv->lock, flags);
499
500 dbg("%s - returns %d", __func__, room);
501 return room;
502}
503
504static int pl2303_chars_in_buffer(struct tty_struct *tty)
505{
506 struct usb_serial_port *port = tty->driver_data;
507 struct pl2303_private *priv = usb_get_serial_port_data(port);
508 int chars = 0;
509 unsigned long flags;
510
511 dbg("%s - port %d", __func__, port->number);
512
513 spin_lock_irqsave(&priv->lock, flags);
514 chars = pl2303_buf_data_avail(priv->buf);
515 spin_unlock_irqrestore(&priv->lock, flags);
516
517 dbg("%s - returns %d", __func__, chars);
518 return chars;
519}
520
521static void pl2303_set_termios(struct tty_struct *tty, 248static void pl2303_set_termios(struct tty_struct *tty,
522 struct usb_serial_port *port, struct ktermios *old_termios) 249 struct usb_serial_port *port, struct ktermios *old_termios)
523{ 250{
@@ -729,22 +456,10 @@ static void pl2303_dtr_rts(struct usb_serial_port *port, int on)
729 456
730static void pl2303_close(struct usb_serial_port *port) 457static void pl2303_close(struct usb_serial_port *port)
731{ 458{
732 struct pl2303_private *priv = usb_get_serial_port_data(port);
733 unsigned long flags;
734
735 dbg("%s - port %d", __func__, port->number); 459 dbg("%s - port %d", __func__, port->number);
736 460
737 spin_lock_irqsave(&priv->lock, flags); 461 usb_serial_generic_close(port);
738 /* clear out any remaining data in the buffer */
739 pl2303_buf_clear(priv->buf);
740 spin_unlock_irqrestore(&priv->lock, flags);
741
742 /* shutdown our urbs */
743 dbg("%s - shutting down urbs", __func__);
744 usb_kill_urb(port->write_urb);
745 usb_kill_urb(port->read_urb);
746 usb_kill_urb(port->interrupt_in_urb); 462 usb_kill_urb(port->interrupt_in_urb);
747
748} 463}
749 464
750static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) 465static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -770,10 +485,8 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
770 pl2303_set_termios(tty, port, &tmp_termios); 485 pl2303_set_termios(tty, port, &tmp_termios);
771 486
772 dbg("%s - submitting read urb", __func__); 487 dbg("%s - submitting read urb", __func__);
773 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 488 result = usb_serial_generic_submit_read_urb(port, GFP_KERNEL);
774 if (result) { 489 if (result) {
775 dev_err(&port->dev, "%s - failed submitting read urb,"
776 " error %d\n", __func__, result);
777 pl2303_close(port); 490 pl2303_close(port);
778 return -EPROTO; 491 return -EPROTO;
779 } 492 }
@@ -953,10 +666,7 @@ static void pl2303_release(struct usb_serial *serial)
953 666
954 for (i = 0; i < serial->num_ports; ++i) { 667 for (i = 0; i < serial->num_ports; ++i) {
955 priv = usb_get_serial_port_data(serial->port[i]); 668 priv = usb_get_serial_port_data(serial->port[i]);
956 if (priv) { 669 kfree(priv);
957 pl2303_buf_free(priv->buf);
958 kfree(priv);
959 }
960 } 670 }
961} 671}
962 672
@@ -1037,13 +747,31 @@ exit:
1037 __func__, retval); 747 __func__, retval);
1038} 748}
1039 749
1040static void pl2303_push_data(struct tty_struct *tty, 750static void pl2303_process_read_urb(struct urb *urb)
1041 struct usb_serial_port *port, struct urb *urb,
1042 u8 line_status)
1043{ 751{
752 struct usb_serial_port *port = urb->context;
753 struct pl2303_private *priv = usb_get_serial_port_data(port);
754 struct tty_struct *tty;
1044 unsigned char *data = urb->transfer_buffer; 755 unsigned char *data = urb->transfer_buffer;
1045 /* get tty_flag from status */
1046 char tty_flag = TTY_NORMAL; 756 char tty_flag = TTY_NORMAL;
757 unsigned long flags;
758 u8 line_status;
759 int i;
760
761 /* update line status */
762 spin_lock_irqsave(&priv->lock, flags);
763 line_status = priv->line_status;
764 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
765 spin_unlock_irqrestore(&priv->lock, flags);
766 wake_up_interruptible(&priv->delta_msr_wait);
767
768 if (!urb->actual_length)
769 return;
770
771 tty = tty_port_tty_get(&port->port);
772 if (!tty)
773 return;
774
1047 /* break takes precedence over parity, */ 775 /* break takes precedence over parity, */
1048 /* which takes precedence over framing errors */ 776 /* which takes precedence over framing errors */
1049 if (line_status & UART_BREAK_ERROR) 777 if (line_status & UART_BREAK_ERROR)
@@ -1058,107 +786,17 @@ static void pl2303_push_data(struct tty_struct *tty,
1058 if (line_status & UART_OVERRUN_ERROR) 786 if (line_status & UART_OVERRUN_ERROR)
1059 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 787 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1060 788
1061 if (tty_flag == TTY_NORMAL && !(port->console && port->sysrq)) 789 if (port->port.console && port->sysrq) {
1062 tty_insert_flip_string(tty, data, urb->actual_length);
1063 else {
1064 int i;
1065 for (i = 0; i < urb->actual_length; ++i) 790 for (i = 0; i < urb->actual_length; ++i)
1066 if (!usb_serial_handle_sysrq_char(tty, port, data[i])) 791 if (!usb_serial_handle_sysrq_char(tty, port, data[i]))
1067 tty_insert_flip_char(tty, data[i], tty_flag); 792 tty_insert_flip_char(tty, data[i], tty_flag);
793 } else {
794 tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
795 urb->actual_length);
1068 } 796 }
1069 tty_flip_buffer_push(tty);
1070}
1071
1072static void pl2303_read_bulk_callback(struct urb *urb)
1073{
1074 struct usb_serial_port *port = urb->context;
1075 struct pl2303_private *priv = usb_get_serial_port_data(port);
1076 struct tty_struct *tty;
1077 unsigned long flags;
1078 int result;
1079 int status = urb->status;
1080 u8 line_status;
1081
1082 dbg("%s - port %d", __func__, port->number);
1083
1084 if (status) {
1085 dbg("%s - urb status = %d", __func__, status);
1086 if (status == -EPROTO) {
1087 /* PL2303 mysteriously fails with -EPROTO reschedule
1088 * the read */
1089 dbg("%s - caught -EPROTO, resubmitting the urb",
1090 __func__);
1091 result = usb_submit_urb(urb, GFP_ATOMIC);
1092 if (result)
1093 dev_err(&urb->dev->dev, "%s - failed"
1094 " resubmitting read urb, error %d\n",
1095 __func__, result);
1096 return;
1097 }
1098 dbg("%s - unable to handle the error, exiting.", __func__);
1099 return;
1100 }
1101
1102 usb_serial_debug_data(debug, &port->dev, __func__,
1103 urb->actual_length, urb->transfer_buffer);
1104
1105 spin_lock_irqsave(&priv->lock, flags);
1106 line_status = priv->line_status;
1107 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
1108 spin_unlock_irqrestore(&priv->lock, flags);
1109 wake_up_interruptible(&priv->delta_msr_wait);
1110 797
1111 tty = tty_port_tty_get(&port->port); 798 tty_flip_buffer_push(tty);
1112 if (tty && urb->actual_length) {
1113 pl2303_push_data(tty, port, urb, line_status);
1114 }
1115 tty_kref_put(tty); 799 tty_kref_put(tty);
1116 /* Schedule the next read _if_ we are still open */
1117 result = usb_submit_urb(urb, GFP_ATOMIC);
1118 if (result && result != -EPERM)
1119 dev_err(&urb->dev->dev, "%s - failed resubmitting"
1120 " read urb, error %d\n", __func__, result);
1121}
1122
1123static void pl2303_write_bulk_callback(struct urb *urb)
1124{
1125 struct usb_serial_port *port = urb->context;
1126 struct pl2303_private *priv = usb_get_serial_port_data(port);
1127 int result;
1128 int status = urb->status;
1129
1130 dbg("%s - port %d", __func__, port->number);
1131
1132 switch (status) {
1133 case 0:
1134 /* success */
1135 break;
1136 case -ECONNRESET:
1137 case -ENOENT:
1138 case -ESHUTDOWN:
1139 /* this urb is terminated, clean up */
1140 dbg("%s - urb shutting down with status: %d", __func__,
1141 status);
1142 priv->write_urb_in_use = 0;
1143 return;
1144 default:
1145 /* error in the urb, so we have to resubmit it */
1146 dbg("%s - Overflow in write", __func__);
1147 dbg("%s - nonzero write bulk status received: %d", __func__,
1148 status);
1149 port->write_urb->transfer_buffer_length = 1;
1150 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1151 if (result)
1152 dev_err(&urb->dev->dev, "%s - failed resubmitting write"
1153 " urb, error %d\n", __func__, result);
1154 else
1155 return;
1156 }
1157
1158 priv->write_urb_in_use = 0;
1159
1160 /* send any buffered data */
1161 pl2303_send(port);
1162} 800}
1163 801
1164/* All of the device info needed for the PL2303 SIO serial converter */ 802/* All of the device info needed for the PL2303 SIO serial converter */
@@ -1170,21 +808,19 @@ static struct usb_serial_driver pl2303_device = {
1170 .id_table = id_table, 808 .id_table = id_table,
1171 .usb_driver = &pl2303_driver, 809 .usb_driver = &pl2303_driver,
1172 .num_ports = 1, 810 .num_ports = 1,
811 .bulk_in_size = 256,
812 .bulk_out_size = 256,
1173 .open = pl2303_open, 813 .open = pl2303_open,
1174 .close = pl2303_close, 814 .close = pl2303_close,
1175 .dtr_rts = pl2303_dtr_rts, 815 .dtr_rts = pl2303_dtr_rts,
1176 .carrier_raised = pl2303_carrier_raised, 816 .carrier_raised = pl2303_carrier_raised,
1177 .write = pl2303_write,
1178 .ioctl = pl2303_ioctl, 817 .ioctl = pl2303_ioctl,
1179 .break_ctl = pl2303_break_ctl, 818 .break_ctl = pl2303_break_ctl,
1180 .set_termios = pl2303_set_termios, 819 .set_termios = pl2303_set_termios,
1181 .tiocmget = pl2303_tiocmget, 820 .tiocmget = pl2303_tiocmget,
1182 .tiocmset = pl2303_tiocmset, 821 .tiocmset = pl2303_tiocmset,
1183 .read_bulk_callback = pl2303_read_bulk_callback, 822 .process_read_urb = pl2303_process_read_urb,
1184 .read_int_callback = pl2303_read_int_callback, 823 .read_int_callback = pl2303_read_int_callback,
1185 .write_bulk_callback = pl2303_write_bulk_callback,
1186 .write_room = pl2303_write_room,
1187 .chars_in_buffer = pl2303_chars_in_buffer,
1188 .attach = pl2303_startup, 824 .attach = pl2303_startup,
1189 .release = pl2303_release, 825 .release = pl2303_release,
1190}; 826};
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 23c09b38b9ec..a871645389dd 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -5,7 +5,7 @@
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or 6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. 7 * (at your option) any later version.
8 * 8 *
9 */ 9 */
10 10
11#define BENQ_VENDOR_ID 0x04a5 11#define BENQ_VENDOR_ID 0x04a5
@@ -137,5 +137,5 @@
137#define SANWA_PRODUCT_ID 0x0001 137#define SANWA_PRODUCT_ID 0x0001
138 138
139/* ADLINK ND-6530 RS232,RS485 and RS422 adapter */ 139/* ADLINK ND-6530 RS232,RS485 and RS422 adapter */
140#define ADLINK_VENDOR_ID 0x0b63 140#define ADLINK_VENDOR_ID 0x0b63
141#define ADLINK_ND6530_PRODUCT_ID 0x6530 141#define ADLINK_ND6530_PRODUCT_ID 0x6530
diff --git a/drivers/usb/serial/qcaux.c b/drivers/usb/serial/qcaux.c
index 7e3bea23600b..214a3e504292 100644
--- a/drivers/usb/serial/qcaux.c
+++ b/drivers/usb/serial/qcaux.c
@@ -50,6 +50,10 @@
50#define SANYO_VENDOR_ID 0x0474 50#define SANYO_VENDOR_ID 0x0474
51#define SANYO_PRODUCT_KATANA_LX 0x0754 /* SCP-3800 (Katana LX) */ 51#define SANYO_PRODUCT_KATANA_LX 0x0754 /* SCP-3800 (Katana LX) */
52 52
53/* Samsung devices */
54#define SAMSUNG_VENDOR_ID 0x04e8
55#define SAMSUNG_PRODUCT_U520 0x6640 /* SCH-U520 */
56
53static struct usb_device_id id_table[] = { 57static struct usb_device_id id_table[] = {
54 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5740, 0xff, 0x00, 0x00) }, 58 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5740, 0xff, 0x00, 0x00) },
55 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5750, 0xff, 0x00, 0x00) }, 59 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_PC5750, 0xff, 0x00, 0x00) },
@@ -61,6 +65,7 @@ static struct usb_device_id id_table[] = {
61 { USB_DEVICE_AND_INTERFACE_INFO(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CDX650, 0xff, 0xff, 0x00) }, 65 { USB_DEVICE_AND_INTERFACE_INFO(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CDX650, 0xff, 0xff, 0x00) },
62 { USB_DEVICE_AND_INTERFACE_INFO(LG_VENDOR_ID, LG_PRODUCT_VX4400_6000, 0xff, 0xff, 0x00) }, 66 { USB_DEVICE_AND_INTERFACE_INFO(LG_VENDOR_ID, LG_PRODUCT_VX4400_6000, 0xff, 0xff, 0x00) },
63 { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) }, 67 { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) },
68 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_U520, 0xff, 0x00, 0x00) },
64 { }, 69 { },
65}; 70};
66MODULE_DEVICE_TABLE(usb, id_table); 71MODULE_DEVICE_TABLE(usb, id_table);
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index 53a2d5a935a2..04bb759536bb 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -15,6 +15,8 @@
15#include <linux/tty_flip.h> 15#include <linux/tty_flip.h>
16#include <linux/usb.h> 16#include <linux/usb.h>
17#include <linux/usb/serial.h> 17#include <linux/usb/serial.h>
18#include <linux/slab.h>
19#include "usb-wwan.h"
18 20
19#define DRIVER_AUTHOR "Qualcomm Inc" 21#define DRIVER_AUTHOR "Qualcomm Inc"
20#define DRIVER_DESC "Qualcomm USB Serial driver" 22#define DRIVER_DESC "Qualcomm USB Serial driver"
@@ -76,6 +78,8 @@ static const struct usb_device_id id_table[] = {
76 {USB_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ 78 {USB_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
77 {USB_DEVICE(0x16d8, 0x8001)}, /* CMDTech Gobi 2000 QDL device (VU922) */ 79 {USB_DEVICE(0x16d8, 0x8001)}, /* CMDTech Gobi 2000 QDL device (VU922) */
78 {USB_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */ 80 {USB_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */
81 {USB_DEVICE(0x05c6, 0x9204)}, /* Gobi 2000 QDL device */
82 {USB_DEVICE(0x05c6, 0x9205)}, /* Gobi 2000 Modem device */
79 { } /* Terminating entry */ 83 { } /* Terminating entry */
80}; 84};
81MODULE_DEVICE_TABLE(usb, id_table); 85MODULE_DEVICE_TABLE(usb, id_table);
@@ -92,6 +96,8 @@ static struct usb_driver qcdriver = {
92 96
93static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) 97static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
94{ 98{
99 struct usb_wwan_intf_private *data;
100 struct usb_host_interface *intf = serial->interface->cur_altsetting;
95 int retval = -ENODEV; 101 int retval = -ENODEV;
96 __u8 nintf; 102 __u8 nintf;
97 __u8 ifnum; 103 __u8 ifnum;
@@ -100,33 +106,45 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
100 106
101 nintf = serial->dev->actconfig->desc.bNumInterfaces; 107 nintf = serial->dev->actconfig->desc.bNumInterfaces;
102 dbg("Num Interfaces = %d", nintf); 108 dbg("Num Interfaces = %d", nintf);
103 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 109 ifnum = intf->desc.bInterfaceNumber;
104 dbg("This Interface = %d", ifnum); 110 dbg("This Interface = %d", ifnum);
105 111
112 data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private),
113 GFP_KERNEL);
114 if (!data)
115 return -ENOMEM;
116
117 spin_lock_init(&data->susp_lock);
118
106 switch (nintf) { 119 switch (nintf) {
107 case 1: 120 case 1:
108 /* QDL mode */ 121 /* QDL mode */
109 if (serial->interface->num_altsetting == 2) { 122 /* Gobi 2000 has a single altsetting, older ones have two */
110 struct usb_host_interface *intf; 123 if (serial->interface->num_altsetting == 2)
111
112 intf = &serial->interface->altsetting[1]; 124 intf = &serial->interface->altsetting[1];
113 if (intf->desc.bNumEndpoints == 2) { 125 else if (serial->interface->num_altsetting > 2)
114 if (usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) && 126 break;
115 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) { 127
116 dbg("QDL port found"); 128 if (intf->desc.bNumEndpoints == 2 &&
117 retval = usb_set_interface(serial->dev, ifnum, 1); 129 usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
118 if (retval < 0) { 130 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
119 dev_err(&serial->dev->dev, 131 dbg("QDL port found");
120 "Could not set interface, error %d\n", 132
121 retval); 133 if (serial->interface->num_altsetting == 1)
122 retval = -ENODEV; 134 return 0;
123 } 135
124 return retval; 136 retval = usb_set_interface(serial->dev, ifnum, 1);
125 } 137 if (retval < 0) {
138 dev_err(&serial->dev->dev,
139 "Could not set interface, error %d\n",
140 retval);
141 retval = -ENODEV;
126 } 142 }
143 return retval;
127 } 144 }
128 break; 145 break;
129 146
147 case 3:
130 case 4: 148 case 4:
131 /* Composite mode */ 149 /* Composite mode */
132 if (ifnum == 2) { 150 if (ifnum == 2) {
@@ -161,6 +179,18 @@ static struct usb_serial_driver qcdevice = {
161 .usb_driver = &qcdriver, 179 .usb_driver = &qcdriver,
162 .num_ports = 1, 180 .num_ports = 1,
163 .probe = qcprobe, 181 .probe = qcprobe,
182 .open = usb_wwan_open,
183 .close = usb_wwan_close,
184 .write = usb_wwan_write,
185 .write_room = usb_wwan_write_room,
186 .chars_in_buffer = usb_wwan_chars_in_buffer,
187 .attach = usb_wwan_startup,
188 .disconnect = usb_wwan_disconnect,
189 .release = usb_wwan_release,
190#ifdef CONFIG_PM
191 .suspend = usb_wwan_suspend,
192 .resume = usb_wwan_resume,
193#endif
164}; 194};
165 195
166static int __init qcinit(void) 196static int __init qcinit(void)
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 43a0cadd5782..a36e2313eed0 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Safe Encapsulated USB Serial Driver 2 * Safe Encapsulated USB Serial Driver
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
4 * Copyright (C) 2001 Lineo 5 * Copyright (C) 2001 Lineo
5 * Copyright (C) 2001 Hewlett-Packard 6 * Copyright (C) 2001 Hewlett-Packard
6 * 7 *
@@ -84,8 +85,8 @@ static int debug;
84static int safe = 1; 85static int safe = 1;
85static int padded = CONFIG_USB_SERIAL_SAFE_PADDED; 86static int padded = CONFIG_USB_SERIAL_SAFE_PADDED;
86 87
87#define DRIVER_VERSION "v0.0b" 88#define DRIVER_VERSION "v0.1"
88#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com" 89#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com, Johan Hovold <jhovold@gmail.com>"
89#define DRIVER_DESC "USB Safe Encapsulated Serial" 90#define DRIVER_DESC "USB Safe Encapsulated Serial"
90 91
91MODULE_AUTHOR(DRIVER_AUTHOR); 92MODULE_AUTHOR(DRIVER_AUTHOR);
@@ -212,191 +213,80 @@ static __u16 __inline__ fcs_compute10(unsigned char *sp, int len, __u16 fcs)
212 return fcs; 213 return fcs;
213} 214}
214 215
215static void safe_read_bulk_callback(struct urb *urb) 216static void safe_process_read_urb(struct urb *urb)
216{ 217{
217 struct usb_serial_port *port = urb->context; 218 struct usb_serial_port *port = urb->context;
218 unsigned char *data = urb->transfer_buffer; 219 unsigned char *data = urb->transfer_buffer;
219 unsigned char length = urb->actual_length; 220 unsigned char length = urb->actual_length;
221 int actual_length;
220 struct tty_struct *tty; 222 struct tty_struct *tty;
221 int result; 223 __u16 fcs;
222 int status = urb->status;
223 224
224 dbg("%s", __func__); 225 if (!length)
225
226 if (status) {
227 dbg("%s - nonzero read bulk status received: %d",
228 __func__, status);
229 return; 226 return;
230 }
231 227
232 dbg("safe_read_bulk_callback length: %d",
233 port->read_urb->actual_length);
234#ifdef ECHO_RCV
235 {
236 int i;
237 unsigned char *cp = port->read_urb->transfer_buffer;
238 for (i = 0; i < port->read_urb->actual_length; i++) {
239 if ((i % 32) == 0)
240 printk("\nru[%02x] ", i);
241 printk("%02x ", *cp++);
242 }
243 printk("\n");
244 }
245#endif
246 tty = tty_port_tty_get(&port->port); 228 tty = tty_port_tty_get(&port->port);
247 if (safe) { 229 if (!tty)
248 __u16 fcs; 230 return;
249 fcs = fcs_compute10(data, length, CRC10_INITFCS);
250 if (!fcs) {
251 int actual_length = data[length - 2] >> 2;
252 if (actual_length <= (length - 2)) {
253 dev_info(&urb->dev->dev, "%s - actual: %d\n",
254 __func__, actual_length);
255 tty_insert_flip_string(tty,
256 data, actual_length);
257 tty_flip_buffer_push(tty);
258 } else {
259 dev_err(&port->dev,
260 "%s - inconsistent lengths %d:%d\n",
261 __func__, actual_length, length);
262 }
263 } else {
264 dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs);
265 }
266 } else {
267 tty_insert_flip_string(tty, data, length);
268 tty_flip_buffer_push(tty);
269 }
270 tty_kref_put(tty);
271
272 /* Continue trying to always read */
273 usb_fill_bulk_urb(urb, port->serial->dev,
274 usb_rcvbulkpipe(port->serial->dev,
275 port->bulk_in_endpointAddress),
276 urb->transfer_buffer, urb->transfer_buffer_length,
277 safe_read_bulk_callback, port);
278
279 result = usb_submit_urb(urb, GFP_ATOMIC);
280 if (result)
281 dev_err(&port->dev,
282 "%s - failed resubmitting read urb, error %d\n",
283 __func__, result);
284 /* FIXME: Need a mechanism to retry later if this happens */
285}
286
287static int safe_write(struct tty_struct *tty, struct usb_serial_port *port,
288 const unsigned char *buf, int count)
289{
290 unsigned char *data;
291 int result;
292 int i;
293 int packet_length;
294
295 dbg("safe_write port: %p %d urb: %p count: %d",
296 port, port->number, port->write_urb, count);
297
298 if (!port->write_urb) {
299 dbg("%s - write urb NULL", __func__);
300 return 0;
301 }
302
303 dbg("safe_write write_urb: %d transfer_buffer_length",
304 port->write_urb->transfer_buffer_length);
305
306 if (!port->write_urb->transfer_buffer_length) {
307 dbg("%s - write urb transfer_buffer_length zero", __func__);
308 return 0;
309 }
310 if (count == 0) {
311 dbg("%s - write request of 0 bytes", __func__);
312 return 0;
313 }
314 spin_lock_bh(&port->lock);
315 if (port->write_urb_busy) {
316 spin_unlock_bh(&port->lock);
317 dbg("%s - already writing", __func__);
318 return 0;
319 }
320 port->write_urb_busy = 1;
321 spin_unlock_bh(&port->lock);
322
323 packet_length = port->bulk_out_size; /* get max packetsize */
324
325 i = packet_length - (safe ? 2 : 0); /* get bytes to send */
326 count = (count > i) ? i : count;
327
328
329 /* get the data into the transfer buffer */
330 data = port->write_urb->transfer_buffer;
331 memset(data, '0', packet_length);
332
333 memcpy(data, buf, count);
334
335 if (safe) {
336 __u16 fcs;
337
338 /* pad if necessary */
339 if (!padded)
340 packet_length = count + 2;
341 /* set count */
342 data[packet_length - 2] = count << 2;
343 data[packet_length - 1] = 0;
344 231
345 /* compute fcs and insert into trailer */ 232 if (!safe)
346 fcs = fcs_compute10(data, packet_length, CRC10_INITFCS); 233 goto out;
347 data[packet_length - 2] |= fcs >> 8;
348 data[packet_length - 1] |= fcs & 0xff;
349 234
350 /* set length to send */ 235 fcs = fcs_compute10(data, length, CRC10_INITFCS);
351 port->write_urb->transfer_buffer_length = packet_length; 236 if (fcs) {
352 } else { 237 dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs);
353 port->write_urb->transfer_buffer_length = count; 238 goto err;
354 } 239 }
355 240
356 usb_serial_debug_data(debug, &port->dev, __func__, count, 241 actual_length = data[length - 2] >> 2;
357 port->write_urb->transfer_buffer); 242 if (actual_length > (length - 2)) {
358#ifdef ECHO_TX 243 dev_err(&port->dev, "%s - inconsistent lengths %d:%d\n",
359 { 244 __func__, actual_length, length);
360 int i; 245 goto err;
361 unsigned char *cp = port->write_urb->transfer_buffer;
362 for (i = 0; i < port->write_urb->transfer_buffer_length; i++) {
363 if ((i % 32) == 0)
364 printk("\nsu[%02x] ", i);
365 printk("%02x ", *cp++);
366 }
367 printk("\n");
368 }
369#endif
370 port->write_urb->dev = port->serial->dev;
371 result = usb_submit_urb(port->write_urb, GFP_KERNEL);
372 if (result) {
373 port->write_urb_busy = 0;
374 dev_err(&port->dev,
375 "%s - failed submitting write urb, error %d\n",
376 __func__, result);
377 return 0;
378 } 246 }
379 dbg("%s urb: %p submitted", __func__, port->write_urb); 247 dev_info(&urb->dev->dev, "%s - actual: %d\n", __func__, actual_length);
380 248 length = actual_length;
381 return count; 249out:
250 tty_insert_flip_string(tty, data, length);
251 tty_flip_buffer_push(tty);
252err:
253 tty_kref_put(tty);
382} 254}
383 255
384static int safe_write_room(struct tty_struct *tty) 256static int safe_prepare_write_buffer(struct usb_serial_port *port,
257 void *dest, size_t size)
385{ 258{
386 struct usb_serial_port *port = tty->driver_data; 259 unsigned char *buf = dest;
387 int room = 0; /* Default: no room */ 260 int count;
388 unsigned long flags; 261 int trailer_len;
262 int pkt_len;
263 __u16 fcs;
264
265 trailer_len = safe ? 2 : 0;
266
267 count = kfifo_out_locked(&port->write_fifo, buf, size - trailer_len,
268 &port->lock);
269 if (!safe)
270 return count;
271
272 /* pad if necessary */
273 if (padded) {
274 pkt_len = size;
275 memset(buf + count, '0', pkt_len - count - trailer_len);
276 } else {
277 pkt_len = count + trailer_len;
278 }
389 279
390 dbg("%s", __func__); 280 /* set count */
281 buf[pkt_len - 2] = count << 2;
282 buf[pkt_len - 1] = 0;
391 283
392 spin_lock_irqsave(&port->lock, flags); 284 /* compute fcs and insert into trailer */
393 if (port->write_urb_busy) 285 fcs = fcs_compute10(buf, pkt_len, CRC10_INITFCS);
394 room = port->bulk_out_size - (safe ? 2 : 0); 286 buf[pkt_len - 2] |= fcs >> 8;
395 spin_unlock_irqrestore(&port->lock, flags); 287 buf[pkt_len - 1] |= fcs & 0xff;
396 288
397 if (room) 289 return pkt_len;
398 dbg("safe_write_room returns %d", room);
399 return room;
400} 290}
401 291
402static int safe_startup(struct usb_serial *serial) 292static int safe_startup(struct usb_serial *serial)
@@ -421,9 +311,8 @@ static struct usb_serial_driver safe_device = {
421 .id_table = id_table, 311 .id_table = id_table,
422 .usb_driver = &safe_driver, 312 .usb_driver = &safe_driver,
423 .num_ports = 1, 313 .num_ports = 1,
424 .write = safe_write, 314 .process_read_urb = safe_process_read_urb,
425 .write_room = safe_write_room, 315 .prepare_write_buffer = safe_prepare_write_buffer,
426 .read_bulk_callback = safe_read_bulk_callback,
427 .attach = safe_startup, 316 .attach = safe_startup,
428}; 317};
429 318
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 5d39191e7244..329d311a35d9 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * spcp8x5 USB to serial adaptor driver 2 * spcp8x5 USB to serial adaptor driver
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
4 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn) 5 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn)
5 * Copyright (C) 2006 S1 Corp. 6 * Copyright (C) 2006 S1 Corp.
6 * 7 *
@@ -29,7 +30,7 @@
29 30
30 31
31/* Version Information */ 32/* Version Information */
32#define DRIVER_VERSION "v0.04" 33#define DRIVER_VERSION "v0.10"
33#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver" 34#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
34 35
35static int debug; 36static int debug;
@@ -64,11 +65,6 @@ struct spcp8x5_usb_ctrl_arg {
64 u16 length; 65 u16 length;
65}; 66};
66 67
67/* wait 30s before close */
68#define SPCP8x5_CLOSING_WAIT (30*HZ)
69
70#define SPCP8x5_BUF_SIZE 1024
71
72 68
73/* spcp8x5 spec register define */ 69/* spcp8x5 spec register define */
74#define MCR_CONTROL_LINE_RTS 0x02 70#define MCR_CONTROL_LINE_RTS 0x02
@@ -155,133 +151,6 @@ enum spcp8x5_type {
155 SPCP835_TYPE, 151 SPCP835_TYPE,
156}; 152};
157 153
158/* 1st in 1st out buffer 4 driver */
159struct ringbuf {
160 unsigned int buf_size;
161 char *buf_buf;
162 char *buf_get;
163 char *buf_put;
164};
165
166/* alloc the ring buf and alloc the buffer itself */
167static inline struct ringbuf *alloc_ringbuf(unsigned int size)
168{
169 struct ringbuf *pb;
170
171 if (size == 0)
172 return NULL;
173
174 pb = kmalloc(sizeof(*pb), GFP_KERNEL);
175 if (pb == NULL)
176 return NULL;
177
178 pb->buf_buf = kmalloc(size, GFP_KERNEL);
179 if (pb->buf_buf == NULL) {
180 kfree(pb);
181 return NULL;
182 }
183
184 pb->buf_size = size;
185 pb->buf_get = pb->buf_put = pb->buf_buf;
186
187 return pb;
188}
189
190/* free the ring buf and the buffer itself */
191static inline void free_ringbuf(struct ringbuf *pb)
192{
193 if (pb != NULL) {
194 kfree(pb->buf_buf);
195 kfree(pb);
196 }
197}
198
199/* clear pipo , juest repoint the pointer here */
200static inline void clear_ringbuf(struct ringbuf *pb)
201{
202 if (pb != NULL)
203 pb->buf_get = pb->buf_put;
204}
205
206/* get the number of data in the pipo */
207static inline unsigned int ringbuf_avail_data(struct ringbuf *pb)
208{
209 if (pb == NULL)
210 return 0;
211 return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size;
212}
213
214/* get the number of space in the pipo */
215static inline unsigned int ringbuf_avail_space(struct ringbuf *pb)
216{
217 if (pb == NULL)
218 return 0;
219 return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size;
220}
221
222/* put count data into pipo */
223static unsigned int put_ringbuf(struct ringbuf *pb, const char *buf,
224 unsigned int count)
225{
226 unsigned int len;
227
228 if (pb == NULL)
229 return 0;
230
231 len = ringbuf_avail_space(pb);
232 if (count > len)
233 count = len;
234
235 if (count == 0)
236 return 0;
237
238 len = pb->buf_buf + pb->buf_size - pb->buf_put;
239 if (count > len) {
240 memcpy(pb->buf_put, buf, len);
241 memcpy(pb->buf_buf, buf+len, count - len);
242 pb->buf_put = pb->buf_buf + count - len;
243 } else {
244 memcpy(pb->buf_put, buf, count);
245 if (count < len)
246 pb->buf_put += count;
247 else /* count == len */
248 pb->buf_put = pb->buf_buf;
249 }
250 return count;
251}
252
253/* get count data from pipo */
254static unsigned int get_ringbuf(struct ringbuf *pb, char *buf,
255 unsigned int count)
256{
257 unsigned int len;
258
259 if (pb == NULL || buf == NULL)
260 return 0;
261
262 len = ringbuf_avail_data(pb);
263 if (count > len)
264 count = len;
265
266 if (count == 0)
267 return 0;
268
269 len = pb->buf_buf + pb->buf_size - pb->buf_get;
270 if (count > len) {
271 memcpy(buf, pb->buf_get, len);
272 memcpy(buf+len, pb->buf_buf, count - len);
273 pb->buf_get = pb->buf_buf + count - len;
274 } else {
275 memcpy(buf, pb->buf_get, count);
276 if (count < len)
277 pb->buf_get += count;
278 else /* count == len */
279 pb->buf_get = pb->buf_buf;
280 }
281
282 return count;
283}
284
285static struct usb_driver spcp8x5_driver = { 154static struct usb_driver spcp8x5_driver = {
286 .name = "spcp8x5", 155 .name = "spcp8x5",
287 .probe = usb_serial_probe, 156 .probe = usb_serial_probe,
@@ -293,8 +162,6 @@ static struct usb_driver spcp8x5_driver = {
293 162
294struct spcp8x5_private { 163struct spcp8x5_private {
295 spinlock_t lock; 164 spinlock_t lock;
296 struct ringbuf *buf;
297 int write_urb_in_use;
298 enum spcp8x5_type type; 165 enum spcp8x5_type type;
299 wait_queue_head_t delta_msr_wait; 166 wait_queue_head_t delta_msr_wait;
300 u8 line_control; 167 u8 line_control;
@@ -330,24 +197,15 @@ static int spcp8x5_startup(struct usb_serial *serial)
330 goto cleanup; 197 goto cleanup;
331 198
332 spin_lock_init(&priv->lock); 199 spin_lock_init(&priv->lock);
333 priv->buf = alloc_ringbuf(SPCP8x5_BUF_SIZE);
334 if (priv->buf == NULL)
335 goto cleanup2;
336
337 init_waitqueue_head(&priv->delta_msr_wait); 200 init_waitqueue_head(&priv->delta_msr_wait);
338 priv->type = type; 201 priv->type = type;
339 usb_set_serial_port_data(serial->port[i] , priv); 202 usb_set_serial_port_data(serial->port[i] , priv);
340
341 } 203 }
342 204
343 return 0; 205 return 0;
344
345cleanup2:
346 kfree(priv);
347cleanup: 206cleanup:
348 for (--i; i >= 0; --i) { 207 for (--i; i >= 0; --i) {
349 priv = usb_get_serial_port_data(serial->port[i]); 208 priv = usb_get_serial_port_data(serial->port[i]);
350 free_ringbuf(priv->buf);
351 kfree(priv); 209 kfree(priv);
352 usb_set_serial_port_data(serial->port[i] , NULL); 210 usb_set_serial_port_data(serial->port[i] , NULL);
353 } 211 }
@@ -358,15 +216,9 @@ cleanup:
358static void spcp8x5_release(struct usb_serial *serial) 216static void spcp8x5_release(struct usb_serial *serial)
359{ 217{
360 int i; 218 int i;
361 struct spcp8x5_private *priv;
362 219
363 for (i = 0; i < serial->num_ports; i++) { 220 for (i = 0; i < serial->num_ports; i++)
364 priv = usb_get_serial_port_data(serial->port[i]); 221 kfree(usb_get_serial_port_data(serial->port[i]));
365 if (priv) {
366 free_ringbuf(priv->buf);
367 kfree(priv);
368 }
369 }
370} 222}
371 223
372/* set the modem control line of the device. 224/* set the modem control line of the device.
@@ -470,33 +322,6 @@ static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
470 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 322 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
471} 323}
472 324
473/* close the serial port. We should wait for data sending to device 1st and
474 * then kill all urb. */
475static void spcp8x5_close(struct usb_serial_port *port)
476{
477 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
478 unsigned long flags;
479 int result;
480
481 dbg("%s - port %d", __func__, port->number);
482
483 spin_lock_irqsave(&priv->lock, flags);
484 /* clear out any remaining data in the buffer */
485 clear_ringbuf(priv->buf);
486 spin_unlock_irqrestore(&priv->lock, flags);
487
488 /* kill urb */
489 if (port->write_urb != NULL) {
490 result = usb_unlink_urb(port->write_urb);
491 if (result)
492 dev_dbg(&port->dev,
493 "usb_unlink_urb(write_urb) = %d\n", result);
494 }
495 result = usb_unlink_urb(port->read_urb);
496 if (result)
497 dev_dbg(&port->dev, "usb_unlink_urb(read_urb) = %d\n", result);
498}
499
500static void spcp8x5_init_termios(struct tty_struct *tty) 325static void spcp8x5_init_termios(struct tty_struct *tty)
501{ 326{
502 /* for the 1st time call this function */ 327 /* for the 1st time call this function */
@@ -620,7 +445,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
620} 445}
621 446
622/* open the serial port. do some usb system call. set termios and get the line 447/* open the serial port. do some usb system call. set termios and get the line
623 * status of the device. then submit the read urb */ 448 * status of the device. */
624static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port) 449static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
625{ 450{
626 struct ktermios tmp_termios; 451 struct ktermios tmp_termios;
@@ -655,52 +480,21 @@ static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
655 priv->line_status = status & 0xf0 ; 480 priv->line_status = status & 0xf0 ;
656 spin_unlock_irqrestore(&priv->lock, flags); 481 spin_unlock_irqrestore(&priv->lock, flags);
657 482
658 dbg("%s - submitting read urb", __func__);
659 port->read_urb->dev = serial->dev;
660 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
661 if (ret) {
662 spcp8x5_close(port);
663 return -EPROTO;
664 }
665 port->port.drain_delay = 256; 483 port->port.drain_delay = 256;
666 return 0; 484
485 return usb_serial_generic_open(tty, port);
667} 486}
668 487
669/* bulk read call back function. check the status of the urb. if transfer 488static void spcp8x5_process_read_urb(struct urb *urb)
670 * failed return. then update the status and the tty send data to tty subsys.
671 * submit urb again.
672 */
673static void spcp8x5_read_bulk_callback(struct urb *urb)
674{ 489{
675 struct usb_serial_port *port = urb->context; 490 struct usb_serial_port *port = urb->context;
676 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 491 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
677 struct tty_struct *tty; 492 struct tty_struct *tty;
678 unsigned char *data = urb->transfer_buffer; 493 unsigned char *data = urb->transfer_buffer;
679 unsigned long flags; 494 unsigned long flags;
680 int result = urb->status;
681 u8 status; 495 u8 status;
682 char tty_flag; 496 char tty_flag;
683 497
684 dev_dbg(&port->dev, "start, result = %d, urb->actual_length = %d\n,",
685 result, urb->actual_length);
686
687 /* check the urb status */
688 if (result) {
689 if (result == -EPROTO) {
690 /* spcp8x5 mysteriously fails with -EPROTO */
691 /* reschedule the read */
692 urb->dev = port->serial->dev;
693 result = usb_submit_urb(urb , GFP_ATOMIC);
694 if (result)
695 dev_dbg(&port->dev,
696 "failed submitting read urb %d\n",
697 result);
698 return;
699 }
700 dev_dbg(&port->dev, "unable to handle the error, exiting.\n");
701 return;
702 }
703
704 /* get tty_flag from status */ 498 /* get tty_flag from status */
705 tty_flag = TTY_NORMAL; 499 tty_flag = TTY_NORMAL;
706 500
@@ -711,141 +505,33 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
711 /* wake up the wait for termios */ 505 /* wake up the wait for termios */
712 wake_up_interruptible(&priv->delta_msr_wait); 506 wake_up_interruptible(&priv->delta_msr_wait);
713 507
714 /* break takes precedence over parity, which takes precedence over 508 if (!urb->actual_length)
715 * framing errors */
716 if (status & UART_BREAK_ERROR)
717 tty_flag = TTY_BREAK;
718 else if (status & UART_PARITY_ERROR)
719 tty_flag = TTY_PARITY;
720 else if (status & UART_FRAME_ERROR)
721 tty_flag = TTY_FRAME;
722 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
723
724 tty = tty_port_tty_get(&port->port);
725 if (tty && urb->actual_length) {
726 /* overrun is special, not associated with a char */
727 if (status & UART_OVERRUN_ERROR)
728 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
729 tty_insert_flip_string_fixed_flag(tty, data,
730 urb->actual_length, tty_flag);
731 tty_flip_buffer_push(tty);
732 }
733 tty_kref_put(tty);
734
735 /* Schedule the next read */
736 urb->dev = port->serial->dev;
737 result = usb_submit_urb(urb , GFP_ATOMIC);
738 if (result)
739 dev_dbg(&port->dev, "failed submitting read urb %d\n", result);
740}
741
742/* get data from ring buffer and then write to usb bus */
743static void spcp8x5_send(struct usb_serial_port *port)
744{
745 int count, result;
746 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
747 unsigned long flags;
748
749 spin_lock_irqsave(&priv->lock, flags);
750
751 if (priv->write_urb_in_use) {
752 dev_dbg(&port->dev, "write urb still used\n");
753 spin_unlock_irqrestore(&priv->lock, flags);
754 return; 509 return;
755 }
756
757 /* send the 1st urb for writting */
758 memset(port->write_urb->transfer_buffer , 0x00 , port->bulk_out_size);
759 count = get_ringbuf(priv->buf, port->write_urb->transfer_buffer,
760 port->bulk_out_size);
761 510
762 if (count == 0) { 511 tty = tty_port_tty_get(&port->port);
763 spin_unlock_irqrestore(&priv->lock, flags); 512 if (!tty)
764 return; 513 return;
765 }
766
767 /* update the urb status */
768 priv->write_urb_in_use = 1;
769
770 spin_unlock_irqrestore(&priv->lock, flags);
771
772 port->write_urb->transfer_buffer_length = count;
773 port->write_urb->dev = port->serial->dev;
774
775 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
776 if (result) {
777 dev_dbg(&port->dev, "failed submitting write urb, error %d\n",
778 result);
779 priv->write_urb_in_use = 0;
780 /* TODO: reschedule spcp8x5_send */
781 }
782
783
784 schedule_work(&port->work);
785}
786 514
787/* this is the call back function for write urb. NOTE we should not sleep in 515 if (status & UART_STATE_TRANSIENT_MASK) {
788 * this routine. check the urb return code and then submit the write urb again 516 /* break takes precedence over parity, which takes precedence
789 * to hold the write loop */ 517 * over framing errors */
790static void spcp8x5_write_bulk_callback(struct urb *urb) 518 if (status & UART_BREAK_ERROR)
791{ 519 tty_flag = TTY_BREAK;
792 struct usb_serial_port *port = urb->context; 520 else if (status & UART_PARITY_ERROR)
793 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 521 tty_flag = TTY_PARITY;
794 int result; 522 else if (status & UART_FRAME_ERROR)
795 int status = urb->status; 523 tty_flag = TTY_FRAME;
524 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
796 525
797 switch (status) { 526 /* overrun is special, not associated with a char */
798 case 0: 527 if (status & UART_OVERRUN_ERROR)
799 /* success */ 528 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
800 break;
801 case -ECONNRESET:
802 case -ENOENT:
803 case -ESHUTDOWN:
804 /* this urb is terminated, clean up */
805 dev_dbg(&port->dev, "urb shutting down with status: %d\n",
806 status);
807 priv->write_urb_in_use = 0;
808 return;
809 default:
810 /* error in the urb, so we have to resubmit it */
811 dbg("%s - Overflow in write", __func__);
812 dbg("%s - nonzero write bulk status received: %d",
813 __func__, status);
814 port->write_urb->transfer_buffer_length = 1;
815 port->write_urb->dev = port->serial->dev;
816 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
817 if (result)
818 dev_dbg(&port->dev,
819 "failed resubmitting write urb %d\n", result);
820 else
821 return;
822 } 529 }
823 530
824 priv->write_urb_in_use = 0; 531 tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
825 532 urb->actual_length);
826 /* send any buffered data */ 533 tty_flip_buffer_push(tty);
827 spcp8x5_send(port); 534 tty_kref_put(tty);
828}
829
830/* write data to ring buffer. and then start the write transfer */
831static int spcp8x5_write(struct tty_struct *tty, struct usb_serial_port *port,
832 const unsigned char *buf, int count)
833{
834 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
835 unsigned long flags;
836
837 dev_dbg(&port->dev, "%d bytes\n", count);
838
839 if (!count)
840 return count;
841
842 spin_lock_irqsave(&priv->lock, flags);
843 count = put_ringbuf(priv->buf, buf, count);
844 spin_unlock_irqrestore(&priv->lock, flags);
845
846 spcp8x5_send(port);
847
848 return count;
849} 535}
850 536
851static int spcp8x5_wait_modem_info(struct usb_serial_port *port, 537static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
@@ -953,36 +639,6 @@ static int spcp8x5_tiocmget(struct tty_struct *tty, struct file *file)
953 return result; 639 return result;
954} 640}
955 641
956/* get the avail space room in ring buffer */
957static int spcp8x5_write_room(struct tty_struct *tty)
958{
959 struct usb_serial_port *port = tty->driver_data;
960 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
961 int room = 0;
962 unsigned long flags;
963
964 spin_lock_irqsave(&priv->lock, flags);
965 room = ringbuf_avail_space(priv->buf);
966 spin_unlock_irqrestore(&priv->lock, flags);
967
968 return room;
969}
970
971/* get the number of avail data in write ring buffer */
972static int spcp8x5_chars_in_buffer(struct tty_struct *tty)
973{
974 struct usb_serial_port *port = tty->driver_data;
975 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
976 int chars = 0;
977 unsigned long flags;
978
979 spin_lock_irqsave(&priv->lock, flags);
980 chars = ringbuf_avail_data(priv->buf);
981 spin_unlock_irqrestore(&priv->lock, flags);
982
983 return chars;
984}
985
986/* All of the device info needed for the spcp8x5 SIO serial converter */ 642/* All of the device info needed for the spcp8x5 SIO serial converter */
987static struct usb_serial_driver spcp8x5_device = { 643static struct usb_serial_driver spcp8x5_device = {
988 .driver = { 644 .driver = {
@@ -992,21 +648,16 @@ static struct usb_serial_driver spcp8x5_device = {
992 .id_table = id_table, 648 .id_table = id_table,
993 .num_ports = 1, 649 .num_ports = 1,
994 .open = spcp8x5_open, 650 .open = spcp8x5_open,
995 .close = spcp8x5_close,
996 .dtr_rts = spcp8x5_dtr_rts, 651 .dtr_rts = spcp8x5_dtr_rts,
997 .carrier_raised = spcp8x5_carrier_raised, 652 .carrier_raised = spcp8x5_carrier_raised,
998 .write = spcp8x5_write,
999 .set_termios = spcp8x5_set_termios, 653 .set_termios = spcp8x5_set_termios,
1000 .init_termios = spcp8x5_init_termios, 654 .init_termios = spcp8x5_init_termios,
1001 .ioctl = spcp8x5_ioctl, 655 .ioctl = spcp8x5_ioctl,
1002 .tiocmget = spcp8x5_tiocmget, 656 .tiocmget = spcp8x5_tiocmget,
1003 .tiocmset = spcp8x5_tiocmset, 657 .tiocmset = spcp8x5_tiocmset,
1004 .write_room = spcp8x5_write_room,
1005 .read_bulk_callback = spcp8x5_read_bulk_callback,
1006 .write_bulk_callback = spcp8x5_write_bulk_callback,
1007 .chars_in_buffer = spcp8x5_chars_in_buffer,
1008 .attach = spcp8x5_startup, 658 .attach = spcp8x5_startup,
1009 .release = spcp8x5_release, 659 .release = spcp8x5_release,
660 .process_read_urb = spcp8x5_process_read_urb,
1010}; 661};
1011 662
1012static int __init spcp8x5_init(void) 663static int __init spcp8x5_init(void)
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index e1bfda33f5b9..90979a1f5311 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -30,7 +30,7 @@
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/ioctl.h> 31#include <linux/ioctl.h>
32#include <linux/serial.h> 32#include <linux/serial.h>
33#include <linux/circ_buf.h> 33#include <linux/kfifo.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/uaccess.h> 35#include <linux/uaccess.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
@@ -40,7 +40,7 @@
40 40
41/* Defines */ 41/* Defines */
42 42
43#define TI_DRIVER_VERSION "v0.9" 43#define TI_DRIVER_VERSION "v0.10"
44#define TI_DRIVER_AUTHOR "Al Borchers <alborchers@steinerpoint.com>" 44#define TI_DRIVER_AUTHOR "Al Borchers <alborchers@steinerpoint.com>"
45#define TI_DRIVER_DESC "TI USB 3410/5052 Serial Driver" 45#define TI_DRIVER_DESC "TI USB 3410/5052 Serial Driver"
46 46
@@ -82,7 +82,7 @@ struct ti_port {
82 spinlock_t tp_lock; 82 spinlock_t tp_lock;
83 int tp_read_urb_state; 83 int tp_read_urb_state;
84 int tp_write_urb_in_use; 84 int tp_write_urb_in_use;
85 struct circ_buf *tp_write_buf; 85 struct kfifo write_fifo;
86}; 86};
87 87
88struct ti_device { 88struct ti_device {
@@ -144,15 +144,6 @@ static int ti_write_byte(struct ti_device *tdev, unsigned long addr,
144 144
145static int ti_download_firmware(struct ti_device *tdev); 145static int ti_download_firmware(struct ti_device *tdev);
146 146
147/* circular buffer */
148static struct circ_buf *ti_buf_alloc(void);
149static void ti_buf_free(struct circ_buf *cb);
150static void ti_buf_clear(struct circ_buf *cb);
151static int ti_buf_data_avail(struct circ_buf *cb);
152static int ti_buf_space_avail(struct circ_buf *cb);
153static int ti_buf_put(struct circ_buf *cb, const char *buf, int count);
154static int ti_buf_get(struct circ_buf *cb, char *buf, int count);
155
156 147
157/* Data */ 148/* Data */
158 149
@@ -450,8 +441,8 @@ static int ti_startup(struct usb_serial *serial)
450 tport->tp_closing_wait = closing_wait; 441 tport->tp_closing_wait = closing_wait;
451 init_waitqueue_head(&tport->tp_msr_wait); 442 init_waitqueue_head(&tport->tp_msr_wait);
452 init_waitqueue_head(&tport->tp_write_wait); 443 init_waitqueue_head(&tport->tp_write_wait);
453 tport->tp_write_buf = ti_buf_alloc(); 444 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE,
454 if (tport->tp_write_buf == NULL) { 445 GFP_KERNEL)) {
455 dev_err(&dev->dev, "%s - out of memory\n", __func__); 446 dev_err(&dev->dev, "%s - out of memory\n", __func__);
456 kfree(tport); 447 kfree(tport);
457 status = -ENOMEM; 448 status = -ENOMEM;
@@ -468,7 +459,7 @@ static int ti_startup(struct usb_serial *serial)
468free_tports: 459free_tports:
469 for (--i; i >= 0; --i) { 460 for (--i; i >= 0; --i) {
470 tport = usb_get_serial_port_data(serial->port[i]); 461 tport = usb_get_serial_port_data(serial->port[i]);
471 ti_buf_free(tport->tp_write_buf); 462 kfifo_free(&tport->write_fifo);
472 kfree(tport); 463 kfree(tport);
473 usb_set_serial_port_data(serial->port[i], NULL); 464 usb_set_serial_port_data(serial->port[i], NULL);
474 } 465 }
@@ -490,7 +481,7 @@ static void ti_release(struct usb_serial *serial)
490 for (i = 0; i < serial->num_ports; ++i) { 481 for (i = 0; i < serial->num_ports; ++i) {
491 tport = usb_get_serial_port_data(serial->port[i]); 482 tport = usb_get_serial_port_data(serial->port[i]);
492 if (tport) { 483 if (tport) {
493 ti_buf_free(tport->tp_write_buf); 484 kfifo_free(&tport->write_fifo);
494 kfree(tport); 485 kfree(tport);
495 } 486 }
496 } 487 }
@@ -701,7 +692,6 @@ static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
701 const unsigned char *data, int count) 692 const unsigned char *data, int count)
702{ 693{
703 struct ti_port *tport = usb_get_serial_port_data(port); 694 struct ti_port *tport = usb_get_serial_port_data(port);
704 unsigned long flags;
705 695
706 dbg("%s - port %d", __func__, port->number); 696 dbg("%s - port %d", __func__, port->number);
707 697
@@ -713,10 +703,8 @@ static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
713 if (tport == NULL || !tport->tp_is_open) 703 if (tport == NULL || !tport->tp_is_open)
714 return -ENODEV; 704 return -ENODEV;
715 705
716 spin_lock_irqsave(&tport->tp_lock, flags); 706 count = kfifo_in_locked(&tport->write_fifo, data, count,
717 count = ti_buf_put(tport->tp_write_buf, data, count); 707 &tport->tp_lock);
718 spin_unlock_irqrestore(&tport->tp_lock, flags);
719
720 ti_send(tport); 708 ti_send(tport);
721 709
722 return count; 710 return count;
@@ -736,7 +724,7 @@ static int ti_write_room(struct tty_struct *tty)
736 return 0; 724 return 0;
737 725
738 spin_lock_irqsave(&tport->tp_lock, flags); 726 spin_lock_irqsave(&tport->tp_lock, flags);
739 room = ti_buf_space_avail(tport->tp_write_buf); 727 room = kfifo_avail(&tport->write_fifo);
740 spin_unlock_irqrestore(&tport->tp_lock, flags); 728 spin_unlock_irqrestore(&tport->tp_lock, flags);
741 729
742 dbg("%s - returns %d", __func__, room); 730 dbg("%s - returns %d", __func__, room);
@@ -757,7 +745,7 @@ static int ti_chars_in_buffer(struct tty_struct *tty)
757 return 0; 745 return 0;
758 746
759 spin_lock_irqsave(&tport->tp_lock, flags); 747 spin_lock_irqsave(&tport->tp_lock, flags);
760 chars = ti_buf_data_avail(tport->tp_write_buf); 748 chars = kfifo_len(&tport->write_fifo);
761 spin_unlock_irqrestore(&tport->tp_lock, flags); 749 spin_unlock_irqrestore(&tport->tp_lock, flags);
762 750
763 dbg("%s - returns %d", __func__, chars); 751 dbg("%s - returns %d", __func__, chars);
@@ -1309,7 +1297,7 @@ static void ti_send(struct ti_port *tport)
1309 if (tport->tp_write_urb_in_use) 1297 if (tport->tp_write_urb_in_use)
1310 goto unlock; 1298 goto unlock;
1311 1299
1312 count = ti_buf_get(tport->tp_write_buf, 1300 count = kfifo_out(&tport->write_fifo,
1313 port->write_urb->transfer_buffer, 1301 port->write_urb->transfer_buffer,
1314 port->bulk_out_size); 1302 port->bulk_out_size);
1315 1303
@@ -1504,7 +1492,7 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1504 add_wait_queue(&tport->tp_write_wait, &wait); 1492 add_wait_queue(&tport->tp_write_wait, &wait);
1505 for (;;) { 1493 for (;;) {
1506 set_current_state(TASK_INTERRUPTIBLE); 1494 set_current_state(TASK_INTERRUPTIBLE);
1507 if (ti_buf_data_avail(tport->tp_write_buf) == 0 1495 if (kfifo_len(&tport->write_fifo) == 0
1508 || timeout == 0 || signal_pending(current) 1496 || timeout == 0 || signal_pending(current)
1509 || tdev->td_urb_error 1497 || tdev->td_urb_error
1510 || port->serial->disconnected) /* disconnect */ 1498 || port->serial->disconnected) /* disconnect */
@@ -1518,7 +1506,7 @@ static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1518 1506
1519 /* flush any remaining data in the buffer */ 1507 /* flush any remaining data in the buffer */
1520 if (flush) 1508 if (flush)
1521 ti_buf_clear(tport->tp_write_buf); 1509 kfifo_reset_out(&tport->write_fifo);
1522 1510
1523 spin_unlock_irq(&tport->tp_lock); 1511 spin_unlock_irq(&tport->tp_lock);
1524 1512
@@ -1761,142 +1749,3 @@ static int ti_download_firmware(struct ti_device *tdev)
1761 1749
1762 return 0; 1750 return 0;
1763} 1751}
1764
1765
1766/* Circular Buffer Functions */
1767
1768/*
1769 * ti_buf_alloc
1770 *
1771 * Allocate a circular buffer and all associated memory.
1772 */
1773
1774static struct circ_buf *ti_buf_alloc(void)
1775{
1776 struct circ_buf *cb;
1777
1778 cb = kmalloc(sizeof(struct circ_buf), GFP_KERNEL);
1779 if (cb == NULL)
1780 return NULL;
1781
1782 cb->buf = kmalloc(TI_WRITE_BUF_SIZE, GFP_KERNEL);
1783 if (cb->buf == NULL) {
1784 kfree(cb);
1785 return NULL;
1786 }
1787
1788 ti_buf_clear(cb);
1789
1790 return cb;
1791}
1792
1793
1794/*
1795 * ti_buf_free
1796 *
1797 * Free the buffer and all associated memory.
1798 */
1799
1800static void ti_buf_free(struct circ_buf *cb)
1801{
1802 kfree(cb->buf);
1803 kfree(cb);
1804}
1805
1806
1807/*
1808 * ti_buf_clear
1809 *
1810 * Clear out all data in the circular buffer.
1811 */
1812
1813static void ti_buf_clear(struct circ_buf *cb)
1814{
1815 cb->head = cb->tail = 0;
1816}
1817
1818
1819/*
1820 * ti_buf_data_avail
1821 *
1822 * Return the number of bytes of data available in the circular
1823 * buffer.
1824 */
1825
1826static int ti_buf_data_avail(struct circ_buf *cb)
1827{
1828 return CIRC_CNT(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1829}
1830
1831
1832/*
1833 * ti_buf_space_avail
1834 *
1835 * Return the number of bytes of space available in the circular
1836 * buffer.
1837 */
1838
1839static int ti_buf_space_avail(struct circ_buf *cb)
1840{
1841 return CIRC_SPACE(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1842}
1843
1844
1845/*
1846 * ti_buf_put
1847 *
1848 * Copy data data from a user buffer and put it into the circular buffer.
1849 * Restrict to the amount of space available.
1850 *
1851 * Return the number of bytes copied.
1852 */
1853
1854static int ti_buf_put(struct circ_buf *cb, const char *buf, int count)
1855{
1856 int c, ret = 0;
1857
1858 while (1) {
1859 c = CIRC_SPACE_TO_END(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1860 if (count < c)
1861 c = count;
1862 if (c <= 0)
1863 break;
1864 memcpy(cb->buf + cb->head, buf, c);
1865 cb->head = (cb->head + c) & (TI_WRITE_BUF_SIZE-1);
1866 buf += c;
1867 count -= c;
1868 ret += c;
1869 }
1870
1871 return ret;
1872}
1873
1874
1875/*
1876 * ti_buf_get
1877 *
1878 * Get data from the circular buffer and copy to the given buffer.
1879 * Restrict to the amount of data available.
1880 *
1881 * Return the number of bytes copied.
1882 */
1883
1884static int ti_buf_get(struct circ_buf *cb, char *buf, int count)
1885{
1886 int c, ret = 0;
1887
1888 while (1) {
1889 c = CIRC_CNT_TO_END(cb->head, cb->tail, TI_WRITE_BUF_SIZE);
1890 if (count < c)
1891 c = count;
1892 if (c <= 0)
1893 break;
1894 memcpy(buf, cb->buf + cb->tail, c);
1895 cb->tail = (cb->tail + c) & (TI_WRITE_BUF_SIZE-1);
1896 buf += c;
1897 count -= c;
1898 ret += c;
1899 }
1900
1901 return ret;
1902}
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 3873660d8217..941c2d409f85 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -289,7 +289,7 @@ static void serial_down(struct tty_port *tport)
289 * The console is magical. Do not hang up the console hardware 289 * The console is magical. Do not hang up the console hardware
290 * or there will be tears. 290 * or there will be tears.
291 */ 291 */
292 if (port->console) 292 if (port->port.console)
293 return; 293 return;
294 if (drv->close) 294 if (drv->close)
295 drv->close(port); 295 drv->close(port);
@@ -328,7 +328,7 @@ static void serial_cleanup(struct tty_struct *tty)
328 /* The console is magical. Do not hang up the console hardware 328 /* The console is magical. Do not hang up the console hardware
329 * or there will be tears. 329 * or there will be tears.
330 */ 330 */
331 if (port->console) 331 if (port->port.console)
332 return; 332 return;
333 333
334 dbg("%s - port %d", __func__, port->number); 334 dbg("%s - port %d", __func__, port->number);
@@ -548,8 +548,12 @@ static void usb_serial_port_work(struct work_struct *work)
548 548
549static void kill_traffic(struct usb_serial_port *port) 549static void kill_traffic(struct usb_serial_port *port)
550{ 550{
551 int i;
552
551 usb_kill_urb(port->read_urb); 553 usb_kill_urb(port->read_urb);
552 usb_kill_urb(port->write_urb); 554 usb_kill_urb(port->write_urb);
555 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
556 usb_kill_urb(port->write_urbs[i]);
553 /* 557 /*
554 * This is tricky. 558 * This is tricky.
555 * Some drivers submit the read_urb in the 559 * Some drivers submit the read_urb in the
@@ -568,6 +572,7 @@ static void kill_traffic(struct usb_serial_port *port)
568static void port_release(struct device *dev) 572static void port_release(struct device *dev)
569{ 573{
570 struct usb_serial_port *port = to_usb_serial_port(dev); 574 struct usb_serial_port *port = to_usb_serial_port(dev);
575 int i;
571 576
572 dbg ("%s - %s", __func__, dev_name(dev)); 577 dbg ("%s - %s", __func__, dev_name(dev));
573 578
@@ -582,6 +587,10 @@ static void port_release(struct device *dev)
582 usb_free_urb(port->write_urb); 587 usb_free_urb(port->write_urb);
583 usb_free_urb(port->interrupt_in_urb); 588 usb_free_urb(port->interrupt_in_urb);
584 usb_free_urb(port->interrupt_out_urb); 589 usb_free_urb(port->interrupt_out_urb);
590 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) {
591 usb_free_urb(port->write_urbs[i]);
592 kfree(port->bulk_out_buffers[i]);
593 }
585 kfifo_free(&port->write_fifo); 594 kfifo_free(&port->write_fifo);
586 kfree(port->bulk_in_buffer); 595 kfree(port->bulk_in_buffer);
587 kfree(port->bulk_out_buffer); 596 kfree(port->bulk_out_buffer);
@@ -901,7 +910,9 @@ int usb_serial_probe(struct usb_interface *interface,
901 dev_err(&interface->dev, "No free urbs available\n"); 910 dev_err(&interface->dev, "No free urbs available\n");
902 goto probe_error; 911 goto probe_error;
903 } 912 }
904 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 913 buffer_size = serial->type->bulk_in_size;
914 if (!buffer_size)
915 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
905 port->bulk_in_size = buffer_size; 916 port->bulk_in_size = buffer_size;
906 port->bulk_in_endpointAddress = endpoint->bEndpointAddress; 917 port->bulk_in_endpointAddress = endpoint->bEndpointAddress;
907 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); 918 port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL);
@@ -918,6 +929,8 @@ int usb_serial_probe(struct usb_interface *interface,
918 } 929 }
919 930
920 for (i = 0; i < num_bulk_out; ++i) { 931 for (i = 0; i < num_bulk_out; ++i) {
932 int j;
933
921 endpoint = bulk_out_endpoint[i]; 934 endpoint = bulk_out_endpoint[i];
922 port = serial->port[i]; 935 port = serial->port[i];
923 port->write_urb = usb_alloc_urb(0, GFP_KERNEL); 936 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -927,7 +940,9 @@ int usb_serial_probe(struct usb_interface *interface,
927 } 940 }
928 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) 941 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL))
929 goto probe_error; 942 goto probe_error;
930 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 943 buffer_size = serial->type->bulk_out_size;
944 if (!buffer_size)
945 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
931 port->bulk_out_size = buffer_size; 946 port->bulk_out_size = buffer_size;
932 port->bulk_out_endpointAddress = endpoint->bEndpointAddress; 947 port->bulk_out_endpointAddress = endpoint->bEndpointAddress;
933 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); 948 port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
@@ -941,6 +956,28 @@ int usb_serial_probe(struct usb_interface *interface,
941 endpoint->bEndpointAddress), 956 endpoint->bEndpointAddress),
942 port->bulk_out_buffer, buffer_size, 957 port->bulk_out_buffer, buffer_size,
943 serial->type->write_bulk_callback, port); 958 serial->type->write_bulk_callback, port);
959 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) {
960 set_bit(j, &port->write_urbs_free);
961 port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
962 if (!port->write_urbs[j]) {
963 dev_err(&interface->dev,
964 "No free urbs available\n");
965 goto probe_error;
966 }
967 port->bulk_out_buffers[j] = kmalloc(buffer_size,
968 GFP_KERNEL);
969 if (!port->bulk_out_buffers[j]) {
970 dev_err(&interface->dev,
971 "Couldn't allocate bulk_out_buffer\n");
972 goto probe_error;
973 }
974 usb_fill_bulk_urb(port->write_urbs[j], dev,
975 usb_sndbulkpipe(dev,
976 endpoint->bEndpointAddress),
977 port->bulk_out_buffers[j], buffer_size,
978 serial->type->write_bulk_callback,
979 port);
980 }
944 } 981 }
945 982
946 if (serial->type->read_int_callback) { 983 if (serial->type->read_int_callback) {
@@ -1294,6 +1331,8 @@ static void fixup_generic(struct usb_serial_driver *device)
1294 set_to_generic_if_null(device, write_bulk_callback); 1331 set_to_generic_if_null(device, write_bulk_callback);
1295 set_to_generic_if_null(device, disconnect); 1332 set_to_generic_if_null(device, disconnect);
1296 set_to_generic_if_null(device, release); 1333 set_to_generic_if_null(device, release);
1334 set_to_generic_if_null(device, process_read_urb);
1335 set_to_generic_if_null(device, prepare_write_buffer);
1297} 1336}
1298 1337
1299int usb_serial_register(struct usb_serial_driver *driver) 1338int usb_serial_register(struct usb_serial_driver *driver)
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h
new file mode 100644
index 000000000000..2be298a1305b
--- /dev/null
+++ b/drivers/usb/serial/usb-wwan.h
@@ -0,0 +1,67 @@
1/*
2 * Definitions for USB serial mobile broadband cards
3 */
4
5#ifndef __LINUX_USB_USB_WWAN
6#define __LINUX_USB_USB_WWAN
7
8extern void usb_wwan_dtr_rts(struct usb_serial_port *port, int on);
9extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port);
10extern void usb_wwan_close(struct usb_serial_port *port);
11extern int usb_wwan_startup(struct usb_serial *serial);
12extern void usb_wwan_disconnect(struct usb_serial *serial);
13extern void usb_wwan_release(struct usb_serial *serial);
14extern int usb_wwan_write_room(struct tty_struct *tty);
15extern void usb_wwan_set_termios(struct tty_struct *tty,
16 struct usb_serial_port *port,
17 struct ktermios *old);
18extern int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file);
19extern int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file,
20 unsigned int set, unsigned int clear);
21extern int usb_wwan_send_setup(struct usb_serial_port *port);
22extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
23 const unsigned char *buf, int count);
24extern int usb_wwan_chars_in_buffer(struct tty_struct *tty);
25#ifdef CONFIG_PM
26extern int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message);
27extern int usb_wwan_resume(struct usb_serial *serial);
28#endif
29
30/* per port private data */
31
32#define N_IN_URB 4
33#define N_OUT_URB 4
34#define IN_BUFLEN 4096
35#define OUT_BUFLEN 4096
36
37struct usb_wwan_intf_private {
38 spinlock_t susp_lock;
39 unsigned int suspended:1;
40 int in_flight;
41 int (*send_setup) (struct usb_serial_port *port);
42 void *private;
43};
44
45struct usb_wwan_port_private {
46 /* Input endpoints and buffer for this port */
47 struct urb *in_urbs[N_IN_URB];
48 u8 *in_buffer[N_IN_URB];
49 /* Output endpoints and buffer for this port */
50 struct urb *out_urbs[N_OUT_URB];
51 u8 *out_buffer[N_OUT_URB];
52 unsigned long out_busy; /* Bit vector of URBs in use */
53 int opened;
54 struct usb_anchor delayed;
55
56 /* Settings for the port */
57 int rts_state; /* Handshaking pins (outputs) */
58 int dtr_state;
59 int cts_state; /* Handshaking pins (inputs) */
60 int dsr_state;
61 int dcd_state;
62 int ri_state;
63
64 unsigned long tx_start_time[N_OUT_URB];
65};
66
67#endif /* __LINUX_USB_USB_WWAN */
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index 28026b47344a..f2ed6a31be77 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -16,7 +16,6 @@
16#include <linux/usb.h> 16#include <linux/usb.h>
17#include <linux/usb/serial.h> 17#include <linux/usb/serial.h>
18 18
19#define URB_DEBUG_MAX_IN_FLIGHT_URBS 4000
20#define USB_DEBUG_MAX_PACKET_SIZE 8 19#define USB_DEBUG_MAX_PACKET_SIZE 8
21#define USB_DEBUG_BRK_SIZE 8 20#define USB_DEBUG_BRK_SIZE 8
22static char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = { 21static char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
@@ -44,12 +43,6 @@ static struct usb_driver debug_driver = {
44 .no_dynamic_id = 1, 43 .no_dynamic_id = 1,
45}; 44};
46 45
47static int usb_debug_open(struct tty_struct *tty, struct usb_serial_port *port)
48{
49 port->bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE;
50 return usb_serial_generic_open(tty, port);
51}
52
53/* This HW really does not support a serial break, so one will be 46/* This HW really does not support a serial break, so one will be
54 * emulated when ever the break state is set to true. 47 * emulated when ever the break state is set to true.
55 */ 48 */
@@ -69,7 +62,7 @@ static void usb_debug_read_bulk_callback(struct urb *urb)
69 memcmp(urb->transfer_buffer, USB_DEBUG_BRK, 62 memcmp(urb->transfer_buffer, USB_DEBUG_BRK,
70 USB_DEBUG_BRK_SIZE) == 0) { 63 USB_DEBUG_BRK_SIZE) == 0) {
71 usb_serial_handle_break(port); 64 usb_serial_handle_break(port);
72 usb_serial_generic_resubmit_read_urb(port, GFP_ATOMIC); 65 usb_serial_generic_submit_read_urb(port, GFP_ATOMIC);
73 return; 66 return;
74 } 67 }
75 68
@@ -83,8 +76,7 @@ static struct usb_serial_driver debug_device = {
83 }, 76 },
84 .id_table = id_table, 77 .id_table = id_table,
85 .num_ports = 1, 78 .num_ports = 1,
86 .open = usb_debug_open, 79 .bulk_out_size = USB_DEBUG_MAX_PACKET_SIZE,
87 .max_in_flight_urbs = URB_DEBUG_MAX_IN_FLIGHT_URBS,
88 .break_ctl = usb_debug_break_ctl, 80 .break_ctl = usb_debug_break_ctl,
89 .read_bulk_callback = usb_debug_read_bulk_callback, 81 .read_bulk_callback = usb_debug_read_bulk_callback,
90}; 82};
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
new file mode 100644
index 000000000000..0c70b4a621bb
--- /dev/null
+++ b/drivers/usb/serial/usb_wwan.c
@@ -0,0 +1,665 @@
1/*
2 USB Driver layer for GSM modems
3
4 Copyright (C) 2005 Matthias Urlichs <smurf@smurf.noris.de>
5
6 This driver is free software; you can redistribute it and/or modify
7 it under the terms of Version 2 of the GNU General Public License as
8 published by the Free Software Foundation.
9
10 Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
11
12 History: see the git log.
13
14 Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
15
16 This driver exists because the "normal" serial driver doesn't work too well
17 with GSM modems. Issues:
18 - data loss -- one single Receive URB is not nearly enough
19 - controlling the baud rate doesn't make sense
20*/
21
22#define DRIVER_VERSION "v0.7.2"
23#define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
24#define DRIVER_DESC "USB Driver for GSM modems"
25
26#include <linux/kernel.h>
27#include <linux/jiffies.h>
28#include <linux/errno.h>
29#include <linux/slab.h>
30#include <linux/tty.h>
31#include <linux/tty_flip.h>
32#include <linux/module.h>
33#include <linux/bitops.h>
34#include <linux/usb.h>
35#include <linux/usb/serial.h>
36#include "usb-wwan.h"
37
38static int debug;
39
40void usb_wwan_dtr_rts(struct usb_serial_port *port, int on)
41{
42 struct usb_serial *serial = port->serial;
43 struct usb_wwan_port_private *portdata;
44
45 struct usb_wwan_intf_private *intfdata;
46
47 dbg("%s", __func__);
48
49 intfdata = port->serial->private;
50
51 if (!intfdata->send_setup)
52 return;
53
54 portdata = usb_get_serial_port_data(port);
55 mutex_lock(&serial->disc_mutex);
56 portdata->rts_state = on;
57 portdata->dtr_state = on;
58 if (serial->dev)
59 intfdata->send_setup(port);
60 mutex_unlock(&serial->disc_mutex);
61}
62EXPORT_SYMBOL(usb_wwan_dtr_rts);
63
64void usb_wwan_set_termios(struct tty_struct *tty,
65 struct usb_serial_port *port,
66 struct ktermios *old_termios)
67{
68 struct usb_wwan_intf_private *intfdata = port->serial->private;
69
70 dbg("%s", __func__);
71
72 /* Doesn't support option setting */
73 tty_termios_copy_hw(tty->termios, old_termios);
74
75 if (intfdata->send_setup)
76 intfdata->send_setup(port);
77}
78EXPORT_SYMBOL(usb_wwan_set_termios);
79
80int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file)
81{
82 struct usb_serial_port *port = tty->driver_data;
83 unsigned int value;
84 struct usb_wwan_port_private *portdata;
85
86 portdata = usb_get_serial_port_data(port);
87
88 value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
89 ((portdata->dtr_state) ? TIOCM_DTR : 0) |
90 ((portdata->cts_state) ? TIOCM_CTS : 0) |
91 ((portdata->dsr_state) ? TIOCM_DSR : 0) |
92 ((portdata->dcd_state) ? TIOCM_CAR : 0) |
93 ((portdata->ri_state) ? TIOCM_RNG : 0);
94
95 return value;
96}
97EXPORT_SYMBOL(usb_wwan_tiocmget);
98
99int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file,
100 unsigned int set, unsigned int clear)
101{
102 struct usb_serial_port *port = tty->driver_data;
103 struct usb_wwan_port_private *portdata;
104 struct usb_wwan_intf_private *intfdata;
105
106 portdata = usb_get_serial_port_data(port);
107 intfdata = port->serial->private;
108
109 if (!intfdata->send_setup)
110 return -EINVAL;
111
112 /* FIXME: what locks portdata fields ? */
113 if (set & TIOCM_RTS)
114 portdata->rts_state = 1;
115 if (set & TIOCM_DTR)
116 portdata->dtr_state = 1;
117
118 if (clear & TIOCM_RTS)
119 portdata->rts_state = 0;
120 if (clear & TIOCM_DTR)
121 portdata->dtr_state = 0;
122 return intfdata->send_setup(port);
123}
124EXPORT_SYMBOL(usb_wwan_tiocmset);
125
126/* Write */
127int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
128 const unsigned char *buf, int count)
129{
130 struct usb_wwan_port_private *portdata;
131 struct usb_wwan_intf_private *intfdata;
132 int i;
133 int left, todo;
134 struct urb *this_urb = NULL; /* spurious */
135 int err;
136 unsigned long flags;
137
138 portdata = usb_get_serial_port_data(port);
139 intfdata = port->serial->private;
140
141 dbg("%s: write (%d chars)", __func__, count);
142
143 i = 0;
144 left = count;
145 for (i = 0; left > 0 && i < N_OUT_URB; i++) {
146 todo = left;
147 if (todo > OUT_BUFLEN)
148 todo = OUT_BUFLEN;
149
150 this_urb = portdata->out_urbs[i];
151 if (test_and_set_bit(i, &portdata->out_busy)) {
152 if (time_before(jiffies,
153 portdata->tx_start_time[i] + 10 * HZ))
154 continue;
155 usb_unlink_urb(this_urb);
156 continue;
157 }
158 dbg("%s: endpoint %d buf %d", __func__,
159 usb_pipeendpoint(this_urb->pipe), i);
160
161 err = usb_autopm_get_interface_async(port->serial->interface);
162 if (err < 0)
163 break;
164
165 /* send the data */
166 memcpy(this_urb->transfer_buffer, buf, todo);
167 this_urb->transfer_buffer_length = todo;
168
169 spin_lock_irqsave(&intfdata->susp_lock, flags);
170 if (intfdata->suspended) {
171 usb_anchor_urb(this_urb, &portdata->delayed);
172 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
173 } else {
174 intfdata->in_flight++;
175 spin_unlock_irqrestore(&intfdata->susp_lock, flags);
176 err = usb_submit_urb(this_urb, GFP_ATOMIC);
177 if (err) {
178 dbg("usb_submit_urb %p (write bulk) failed "
179 "(%d)", this_urb, err);
180 clear_bit(i, &portdata->out_busy);
181 spin_lock_irqsave(&intfdata->susp_lock, flags);
182 intfdata->in_flight--;
183 spin_unlock_irqrestore(&intfdata->susp_lock,
184 flags);
185 continue;
186 }
187 }
188
189 portdata->tx_start_time[i] = jiffies;
190 buf += todo;
191 left -= todo;
192 }
193
194 count -= left;
195 dbg("%s: wrote (did %d)", __func__, count);
196 return count;
197}
198EXPORT_SYMBOL(usb_wwan_write);
199
200static void usb_wwan_indat_callback(struct urb *urb)
201{
202 int err;
203 int endpoint;
204 struct usb_serial_port *port;
205 struct tty_struct *tty;
206 unsigned char *data = urb->transfer_buffer;
207 int status = urb->status;
208
209 dbg("%s: %p", __func__, urb);
210
211 endpoint = usb_pipeendpoint(urb->pipe);
212 port = urb->context;
213
214 if (status) {
215 dbg("%s: nonzero status: %d on endpoint %02x.",
216 __func__, status, endpoint);
217 } else {
218 tty = tty_port_tty_get(&port->port);
219 if (urb->actual_length) {
220 tty_insert_flip_string(tty, data, urb->actual_length);
221 tty_flip_buffer_push(tty);
222 } else
223 dbg("%s: empty read urb received", __func__);
224 tty_kref_put(tty);
225
226 /* Resubmit urb so we continue receiving */
227 if (status != -ESHUTDOWN) {
228 err = usb_submit_urb(urb, GFP_ATOMIC);
229 if (err && err != -EPERM)
230 printk(KERN_ERR "%s: resubmit read urb failed. "
231 "(%d)", __func__, err);
232 else
233 usb_mark_last_busy(port->serial->dev);
234 }
235
236 }
237 return;
238}
239
240static void usb_wwan_outdat_callback(struct urb *urb)
241{
242 struct usb_serial_port *port;
243 struct usb_wwan_port_private *portdata;
244 struct usb_wwan_intf_private *intfdata;
245 int i;
246
247 dbg("%s", __func__);
248
249 port = urb->context;
250 intfdata = port->serial->private;
251
252 usb_serial_port_softint(port);
253 usb_autopm_put_interface_async(port->serial->interface);
254 portdata = usb_get_serial_port_data(port);
255 spin_lock(&intfdata->susp_lock);
256 intfdata->in_flight--;
257 spin_unlock(&intfdata->susp_lock);
258
259 for (i = 0; i < N_OUT_URB; ++i) {
260 if (portdata->out_urbs[i] == urb) {
261 smp_mb__before_clear_bit();
262 clear_bit(i, &portdata->out_busy);
263 break;
264 }
265 }
266}
267
268int usb_wwan_write_room(struct tty_struct *tty)
269{
270 struct usb_serial_port *port = tty->driver_data;
271 struct usb_wwan_port_private *portdata;
272 int i;
273 int data_len = 0;
274 struct urb *this_urb;
275
276 portdata = usb_get_serial_port_data(port);
277
278 for (i = 0; i < N_OUT_URB; i++) {
279 this_urb = portdata->out_urbs[i];
280 if (this_urb && !test_bit(i, &portdata->out_busy))
281 data_len += OUT_BUFLEN;
282 }
283
284 dbg("%s: %d", __func__, data_len);
285 return data_len;
286}
287EXPORT_SYMBOL(usb_wwan_write_room);
288
289int usb_wwan_chars_in_buffer(struct tty_struct *tty)
290{
291 struct usb_serial_port *port = tty->driver_data;
292 struct usb_wwan_port_private *portdata;
293 int i;
294 int data_len = 0;
295 struct urb *this_urb;
296
297 portdata = usb_get_serial_port_data(port);
298
299 for (i = 0; i < N_OUT_URB; i++) {
300 this_urb = portdata->out_urbs[i];
301 /* FIXME: This locking is insufficient as this_urb may
302 go unused during the test */
303 if (this_urb && test_bit(i, &portdata->out_busy))
304 data_len += this_urb->transfer_buffer_length;
305 }
306 dbg("%s: %d", __func__, data_len);
307 return data_len;
308}
309EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
310
311int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
312{
313 struct usb_wwan_port_private *portdata;
314 struct usb_wwan_intf_private *intfdata;
315 struct usb_serial *serial = port->serial;
316 int i, err;
317 struct urb *urb;
318
319 portdata = usb_get_serial_port_data(port);
320 intfdata = serial->private;
321
322 dbg("%s", __func__);
323
324 /* Start reading from the IN endpoint */
325 for (i = 0; i < N_IN_URB; i++) {
326 urb = portdata->in_urbs[i];
327 if (!urb)
328 continue;
329 err = usb_submit_urb(urb, GFP_KERNEL);
330 if (err) {
331 dbg("%s: submit urb %d failed (%d) %d",
332 __func__, i, err, urb->transfer_buffer_length);
333 }
334 }
335
336 if (intfdata->send_setup)
337 intfdata->send_setup(port);
338
339 serial->interface->needs_remote_wakeup = 1;
340 spin_lock_irq(&intfdata->susp_lock);
341 portdata->opened = 1;
342 spin_unlock_irq(&intfdata->susp_lock);
343 usb_autopm_put_interface(serial->interface);
344
345 return 0;
346}
347EXPORT_SYMBOL(usb_wwan_open);
348
349void usb_wwan_close(struct usb_serial_port *port)
350{
351 int i;
352 struct usb_serial *serial = port->serial;
353 struct usb_wwan_port_private *portdata;
354 struct usb_wwan_intf_private *intfdata = port->serial->private;
355
356 dbg("%s", __func__);
357 portdata = usb_get_serial_port_data(port);
358
359 if (serial->dev) {
360 /* Stop reading/writing urbs */
361 spin_lock_irq(&intfdata->susp_lock);
362 portdata->opened = 0;
363 spin_unlock_irq(&intfdata->susp_lock);
364
365 for (i = 0; i < N_IN_URB; i++)
366 usb_kill_urb(portdata->in_urbs[i]);
367 for (i = 0; i < N_OUT_URB; i++)
368 usb_kill_urb(portdata->out_urbs[i]);
369 usb_autopm_get_interface(serial->interface);
370 serial->interface->needs_remote_wakeup = 0;
371 }
372}
373EXPORT_SYMBOL(usb_wwan_close);
374
375/* Helper functions used by usb_wwan_setup_urbs */
376static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint,
377 int dir, void *ctx, char *buf, int len,
378 void (*callback) (struct urb *))
379{
380 struct urb *urb;
381
382 if (endpoint == -1)
383 return NULL; /* endpoint not needed */
384
385 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
386 if (urb == NULL) {
387 dbg("%s: alloc for endpoint %d failed.", __func__, endpoint);
388 return NULL;
389 }
390
391 /* Fill URB using supplied data. */
392 usb_fill_bulk_urb(urb, serial->dev,
393 usb_sndbulkpipe(serial->dev, endpoint) | dir,
394 buf, len, callback, ctx);
395
396 return urb;
397}
398
399/* Setup urbs */
400static void usb_wwan_setup_urbs(struct usb_serial *serial)
401{
402 int i, j;
403 struct usb_serial_port *port;
404 struct usb_wwan_port_private *portdata;
405
406 dbg("%s", __func__);
407
408 for (i = 0; i < serial->num_ports; i++) {
409 port = serial->port[i];
410 portdata = usb_get_serial_port_data(port);
411
412 /* Do indat endpoints first */
413 for (j = 0; j < N_IN_URB; ++j) {
414 portdata->in_urbs[j] = usb_wwan_setup_urb(serial,
415 port->
416 bulk_in_endpointAddress,
417 USB_DIR_IN,
418 port,
419 portdata->
420 in_buffer[j],
421 IN_BUFLEN,
422 usb_wwan_indat_callback);
423 }
424
425 /* outdat endpoints */
426 for (j = 0; j < N_OUT_URB; ++j) {
427 portdata->out_urbs[j] = usb_wwan_setup_urb(serial,
428 port->
429 bulk_out_endpointAddress,
430 USB_DIR_OUT,
431 port,
432 portdata->
433 out_buffer
434 [j],
435 OUT_BUFLEN,
436 usb_wwan_outdat_callback);
437 }
438 }
439}
440
441int usb_wwan_startup(struct usb_serial *serial)
442{
443 int i, j, err;
444 struct usb_serial_port *port;
445 struct usb_wwan_port_private *portdata;
446 u8 *buffer;
447
448 dbg("%s", __func__);
449
450 /* Now setup per port private data */
451 for (i = 0; i < serial->num_ports; i++) {
452 port = serial->port[i];
453 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
454 if (!portdata) {
455 dbg("%s: kmalloc for usb_wwan_port_private (%d) failed!.",
456 __func__, i);
457 return 1;
458 }
459 init_usb_anchor(&portdata->delayed);
460
461 for (j = 0; j < N_IN_URB; j++) {
462 buffer = (u8 *) __get_free_page(GFP_KERNEL);
463 if (!buffer)
464 goto bail_out_error;
465 portdata->in_buffer[j] = buffer;
466 }
467
468 for (j = 0; j < N_OUT_URB; j++) {
469 buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
470 if (!buffer)
471 goto bail_out_error2;
472 portdata->out_buffer[j] = buffer;
473 }
474
475 usb_set_serial_port_data(port, portdata);
476
477 if (!port->interrupt_in_urb)
478 continue;
479 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
480 if (err)
481 dbg("%s: submit irq_in urb failed %d", __func__, err);
482 }
483 usb_wwan_setup_urbs(serial);
484 return 0;
485
486bail_out_error2:
487 for (j = 0; j < N_OUT_URB; j++)
488 kfree(portdata->out_buffer[j]);
489bail_out_error:
490 for (j = 0; j < N_IN_URB; j++)
491 if (portdata->in_buffer[j])
492 free_page((unsigned long)portdata->in_buffer[j]);
493 kfree(portdata);
494 return 1;
495}
496EXPORT_SYMBOL(usb_wwan_startup);
497
498static void stop_read_write_urbs(struct usb_serial *serial)
499{
500 int i, j;
501 struct usb_serial_port *port;
502 struct usb_wwan_port_private *portdata;
503
504 /* Stop reading/writing urbs */
505 for (i = 0; i < serial->num_ports; ++i) {
506 port = serial->port[i];
507 portdata = usb_get_serial_port_data(port);
508 for (j = 0; j < N_IN_URB; j++)
509 usb_kill_urb(portdata->in_urbs[j]);
510 for (j = 0; j < N_OUT_URB; j++)
511 usb_kill_urb(portdata->out_urbs[j]);
512 }
513}
514
515void usb_wwan_disconnect(struct usb_serial *serial)
516{
517 dbg("%s", __func__);
518
519 stop_read_write_urbs(serial);
520}
521EXPORT_SYMBOL(usb_wwan_disconnect);
522
523void usb_wwan_release(struct usb_serial *serial)
524{
525 int i, j;
526 struct usb_serial_port *port;
527 struct usb_wwan_port_private *portdata;
528
529 dbg("%s", __func__);
530
531 /* Now free them */
532 for (i = 0; i < serial->num_ports; ++i) {
533 port = serial->port[i];
534 portdata = usb_get_serial_port_data(port);
535
536 for (j = 0; j < N_IN_URB; j++) {
537 usb_free_urb(portdata->in_urbs[j]);
538 free_page((unsigned long)
539 portdata->in_buffer[j]);
540 portdata->in_urbs[j] = NULL;
541 }
542 for (j = 0; j < N_OUT_URB; j++) {
543 usb_free_urb(portdata->out_urbs[j]);
544 kfree(portdata->out_buffer[j]);
545 portdata->out_urbs[j] = NULL;
546 }
547 }
548
549 /* Now free per port private data */
550 for (i = 0; i < serial->num_ports; i++) {
551 port = serial->port[i];
552 kfree(usb_get_serial_port_data(port));
553 }
554}
555EXPORT_SYMBOL(usb_wwan_release);
556
557#ifdef CONFIG_PM
558int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
559{
560 struct usb_wwan_intf_private *intfdata = serial->private;
561 int b;
562
563 dbg("%s entered", __func__);
564
565 if (message.event & PM_EVENT_AUTO) {
566 spin_lock_irq(&intfdata->susp_lock);
567 b = intfdata->in_flight;
568 spin_unlock_irq(&intfdata->susp_lock);
569
570 if (b)
571 return -EBUSY;
572 }
573
574 spin_lock_irq(&intfdata->susp_lock);
575 intfdata->suspended = 1;
576 spin_unlock_irq(&intfdata->susp_lock);
577 stop_read_write_urbs(serial);
578
579 return 0;
580}
581EXPORT_SYMBOL(usb_wwan_suspend);
582
583static void play_delayed(struct usb_serial_port *port)
584{
585 struct usb_wwan_intf_private *data;
586 struct usb_wwan_port_private *portdata;
587 struct urb *urb;
588 int err;
589
590 portdata = usb_get_serial_port_data(port);
591 data = port->serial->private;
592 while ((urb = usb_get_from_anchor(&portdata->delayed))) {
593 err = usb_submit_urb(urb, GFP_ATOMIC);
594 if (!err)
595 data->in_flight++;
596 }
597}
598
599int usb_wwan_resume(struct usb_serial *serial)
600{
601 int i, j;
602 struct usb_serial_port *port;
603 struct usb_wwan_intf_private *intfdata = serial->private;
604 struct usb_wwan_port_private *portdata;
605 struct urb *urb;
606 int err = 0;
607
608 dbg("%s entered", __func__);
609 /* get the interrupt URBs resubmitted unconditionally */
610 for (i = 0; i < serial->num_ports; i++) {
611 port = serial->port[i];
612 if (!port->interrupt_in_urb) {
613 dbg("%s: No interrupt URB for port %d", __func__, i);
614 continue;
615 }
616 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
617 dbg("Submitted interrupt URB for port %d (result %d)", i, err);
618 if (err < 0) {
619 err("%s: Error %d for interrupt URB of port%d",
620 __func__, err, i);
621 goto err_out;
622 }
623 }
624
625 for (i = 0; i < serial->num_ports; i++) {
626 /* walk all ports */
627 port = serial->port[i];
628 portdata = usb_get_serial_port_data(port);
629
630 /* skip closed ports */
631 spin_lock_irq(&intfdata->susp_lock);
632 if (!portdata->opened) {
633 spin_unlock_irq(&intfdata->susp_lock);
634 continue;
635 }
636
637 for (j = 0; j < N_IN_URB; j++) {
638 urb = portdata->in_urbs[j];
639 err = usb_submit_urb(urb, GFP_ATOMIC);
640 if (err < 0) {
641 err("%s: Error %d for bulk URB %d",
642 __func__, err, i);
643 spin_unlock_irq(&intfdata->susp_lock);
644 goto err_out;
645 }
646 }
647 play_delayed(port);
648 spin_unlock_irq(&intfdata->susp_lock);
649 }
650 spin_lock_irq(&intfdata->susp_lock);
651 intfdata->suspended = 0;
652 spin_unlock_irq(&intfdata->susp_lock);
653err_out:
654 return err;
655}
656EXPORT_SYMBOL(usb_wwan_resume);
657#endif
658
659MODULE_AUTHOR(DRIVER_AUTHOR);
660MODULE_DESCRIPTION(DRIVER_DESC);
661MODULE_VERSION(DRIVER_VERSION);
662MODULE_LICENSE("GPL");
663
664module_param(debug, bool, S_IRUGO | S_IWUSR);
665MODULE_PARM_DESC(debug, "Debug messages");
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 094942707c7d..eb76aaef4268 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -38,17 +38,9 @@
38/* function prototypes for a handspring visor */ 38/* function prototypes for a handspring visor */
39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port); 39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port);
40static void visor_close(struct usb_serial_port *port); 40static void visor_close(struct usb_serial_port *port);
41static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
42 const unsigned char *buf, int count);
43static int visor_write_room(struct tty_struct *tty);
44static void visor_throttle(struct tty_struct *tty);
45static void visor_unthrottle(struct tty_struct *tty);
46static int visor_probe(struct usb_serial *serial, 41static int visor_probe(struct usb_serial *serial,
47 const struct usb_device_id *id); 42 const struct usb_device_id *id);
48static int visor_calc_num_ports(struct usb_serial *serial); 43static int visor_calc_num_ports(struct usb_serial *serial);
49static void visor_release(struct usb_serial *serial);
50static void visor_write_bulk_callback(struct urb *urb);
51static void visor_read_bulk_callback(struct urb *urb);
52static void visor_read_int_callback(struct urb *urb); 44static void visor_read_int_callback(struct urb *urb);
53static int clie_3_5_startup(struct usb_serial *serial); 45static int clie_3_5_startup(struct usb_serial *serial);
54static int treo_attach(struct usb_serial *serial); 46static int treo_attach(struct usb_serial *serial);
@@ -194,18 +186,14 @@ static struct usb_serial_driver handspring_device = {
194 .usb_driver = &visor_driver, 186 .usb_driver = &visor_driver,
195 .id_table = id_table, 187 .id_table = id_table,
196 .num_ports = 2, 188 .num_ports = 2,
189 .bulk_out_size = 256,
197 .open = visor_open, 190 .open = visor_open,
198 .close = visor_close, 191 .close = visor_close,
199 .throttle = visor_throttle, 192 .throttle = usb_serial_generic_throttle,
200 .unthrottle = visor_unthrottle, 193 .unthrottle = usb_serial_generic_unthrottle,
201 .attach = treo_attach, 194 .attach = treo_attach,
202 .probe = visor_probe, 195 .probe = visor_probe,
203 .calc_num_ports = visor_calc_num_ports, 196 .calc_num_ports = visor_calc_num_ports,
204 .release = visor_release,
205 .write = visor_write,
206 .write_room = visor_write_room,
207 .write_bulk_callback = visor_write_bulk_callback,
208 .read_bulk_callback = visor_read_bulk_callback,
209 .read_int_callback = visor_read_int_callback, 197 .read_int_callback = visor_read_int_callback,
210}; 198};
211 199
@@ -219,18 +207,14 @@ static struct usb_serial_driver clie_5_device = {
219 .usb_driver = &visor_driver, 207 .usb_driver = &visor_driver,
220 .id_table = clie_id_5_table, 208 .id_table = clie_id_5_table,
221 .num_ports = 2, 209 .num_ports = 2,
210 .bulk_out_size = 256,
222 .open = visor_open, 211 .open = visor_open,
223 .close = visor_close, 212 .close = visor_close,
224 .throttle = visor_throttle, 213 .throttle = usb_serial_generic_throttle,
225 .unthrottle = visor_unthrottle, 214 .unthrottle = usb_serial_generic_unthrottle,
226 .attach = clie_5_attach, 215 .attach = clie_5_attach,
227 .probe = visor_probe, 216 .probe = visor_probe,
228 .calc_num_ports = visor_calc_num_ports, 217 .calc_num_ports = visor_calc_num_ports,
229 .release = visor_release,
230 .write = visor_write,
231 .write_room = visor_write_room,
232 .write_bulk_callback = visor_write_bulk_callback,
233 .read_bulk_callback = visor_read_bulk_callback,
234 .read_int_callback = visor_read_int_callback, 218 .read_int_callback = visor_read_int_callback,
235}; 219};
236 220
@@ -244,39 +228,19 @@ static struct usb_serial_driver clie_3_5_device = {
244 .usb_driver = &visor_driver, 228 .usb_driver = &visor_driver,
245 .id_table = clie_id_3_5_table, 229 .id_table = clie_id_3_5_table,
246 .num_ports = 1, 230 .num_ports = 1,
231 .bulk_out_size = 256,
247 .open = visor_open, 232 .open = visor_open,
248 .close = visor_close, 233 .close = visor_close,
249 .throttle = visor_throttle, 234 .throttle = usb_serial_generic_throttle,
250 .unthrottle = visor_unthrottle, 235 .unthrottle = usb_serial_generic_unthrottle,
251 .attach = clie_3_5_startup, 236 .attach = clie_3_5_startup,
252 .write = visor_write,
253 .write_room = visor_write_room,
254 .write_bulk_callback = visor_write_bulk_callback,
255 .read_bulk_callback = visor_read_bulk_callback,
256}; 237};
257 238
258struct visor_private {
259 spinlock_t lock;
260 int bytes_in;
261 int bytes_out;
262 int outstanding_urbs;
263 unsigned char throttled;
264 unsigned char actually_throttled;
265};
266
267/* number of outstanding urbs to prevent userspace DoS from happening */
268#define URB_UPPER_LIMIT 42
269
270static int stats;
271
272/****************************************************************************** 239/******************************************************************************
273 * Handspring Visor specific driver functions 240 * Handspring Visor specific driver functions
274 ******************************************************************************/ 241 ******************************************************************************/
275static int visor_open(struct tty_struct *tty, struct usb_serial_port *port) 242static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
276{ 243{
277 struct usb_serial *serial = port->serial;
278 struct visor_private *priv = usb_get_serial_port_data(port);
279 unsigned long flags;
280 int result = 0; 244 int result = 0;
281 245
282 dbg("%s - port %d", __func__, port->number); 246 dbg("%s - port %d", __func__, port->number);
@@ -287,26 +251,10 @@ static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
287 return -ENODEV; 251 return -ENODEV;
288 } 252 }
289 253
290 spin_lock_irqsave(&priv->lock, flags);
291 priv->bytes_in = 0;
292 priv->bytes_out = 0;
293 priv->throttled = 0;
294 spin_unlock_irqrestore(&priv->lock, flags);
295
296 /* Start reading from the device */ 254 /* Start reading from the device */
297 usb_fill_bulk_urb(port->read_urb, serial->dev, 255 result = usb_serial_generic_open(tty, port);
298 usb_rcvbulkpipe(serial->dev, 256 if (result)
299 port->bulk_in_endpointAddress),
300 port->read_urb->transfer_buffer,
301 port->read_urb->transfer_buffer_length,
302 visor_read_bulk_callback, port);
303 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
304 if (result) {
305 dev_err(&port->dev,
306 "%s - failed submitting read urb, error %d\n",
307 __func__, result);
308 goto exit; 257 goto exit;
309 }
310 258
311 if (port->interrupt_in_urb) { 259 if (port->interrupt_in_urb) {
312 dbg("%s - adding interrupt input for treo", __func__); 260 dbg("%s - adding interrupt input for treo", __func__);
@@ -323,13 +271,12 @@ exit:
323 271
324static void visor_close(struct usb_serial_port *port) 272static void visor_close(struct usb_serial_port *port)
325{ 273{
326 struct visor_private *priv = usb_get_serial_port_data(port);
327 unsigned char *transfer_buffer; 274 unsigned char *transfer_buffer;
328 275
329 dbg("%s - port %d", __func__, port->number); 276 dbg("%s - port %d", __func__, port->number);
330 277
331 /* shutdown our urbs */ 278 /* shutdown our urbs */
332 usb_kill_urb(port->read_urb); 279 usb_serial_generic_close(port);
333 usb_kill_urb(port->interrupt_in_urb); 280 usb_kill_urb(port->interrupt_in_urb);
334 281
335 mutex_lock(&port->serial->disc_mutex); 282 mutex_lock(&port->serial->disc_mutex);
@@ -346,192 +293,6 @@ static void visor_close(struct usb_serial_port *port)
346 } 293 }
347 } 294 }
348 mutex_unlock(&port->serial->disc_mutex); 295 mutex_unlock(&port->serial->disc_mutex);
349
350 if (stats)
351 dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",
352 priv->bytes_in, priv->bytes_out);
353}
354
355
356static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
357 const unsigned char *buf, int count)
358{
359 struct visor_private *priv = usb_get_serial_port_data(port);
360 struct usb_serial *serial = port->serial;
361 struct urb *urb;
362 unsigned char *buffer;
363 unsigned long flags;
364 int status;
365
366 dbg("%s - port %d", __func__, port->number);
367
368 spin_lock_irqsave(&priv->lock, flags);
369 if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
370 spin_unlock_irqrestore(&priv->lock, flags);
371 dbg("%s - write limit hit", __func__);
372 return 0;
373 }
374 priv->outstanding_urbs++;
375 spin_unlock_irqrestore(&priv->lock, flags);
376
377 buffer = kmalloc(count, GFP_ATOMIC);
378 if (!buffer) {
379 dev_err(&port->dev, "out of memory\n");
380 count = -ENOMEM;
381 goto error_no_buffer;
382 }
383
384 urb = usb_alloc_urb(0, GFP_ATOMIC);
385 if (!urb) {
386 dev_err(&port->dev, "no more free urbs\n");
387 count = -ENOMEM;
388 goto error_no_urb;
389 }
390
391 memcpy(buffer, buf, count);
392
393 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
394
395 usb_fill_bulk_urb(urb, serial->dev,
396 usb_sndbulkpipe(serial->dev,
397 port->bulk_out_endpointAddress),
398 buffer, count,
399 visor_write_bulk_callback, port);
400
401 /* send it down the pipe */
402 status = usb_submit_urb(urb, GFP_ATOMIC);
403 if (status) {
404 dev_err(&port->dev,
405 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
406 __func__, status);
407 count = status;
408 goto error;
409 } else {
410 spin_lock_irqsave(&priv->lock, flags);
411 priv->bytes_out += count;
412 spin_unlock_irqrestore(&priv->lock, flags);
413 }
414
415 /* we are done with this urb, so let the host driver
416 * really free it when it is finished with it */
417 usb_free_urb(urb);
418
419 return count;
420error:
421 usb_free_urb(urb);
422error_no_urb:
423 kfree(buffer);
424error_no_buffer:
425 spin_lock_irqsave(&priv->lock, flags);
426 --priv->outstanding_urbs;
427 spin_unlock_irqrestore(&priv->lock, flags);
428 return count;
429}
430
431
432static int visor_write_room(struct tty_struct *tty)
433{
434 struct usb_serial_port *port = tty->driver_data;
435 struct visor_private *priv = usb_get_serial_port_data(port);
436 unsigned long flags;
437
438 dbg("%s - port %d", __func__, port->number);
439
440 /*
441 * We really can take anything the user throws at us
442 * but let's pick a nice big number to tell the tty
443 * layer that we have lots of free space, unless we don't.
444 */
445
446 spin_lock_irqsave(&priv->lock, flags);
447 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
448 spin_unlock_irqrestore(&priv->lock, flags);
449 dbg("%s - write limit hit", __func__);
450 return 0;
451 }
452 spin_unlock_irqrestore(&priv->lock, flags);
453
454 return 2048;
455}
456
457
458static void visor_write_bulk_callback(struct urb *urb)
459{
460 struct usb_serial_port *port = urb->context;
461 struct visor_private *priv = usb_get_serial_port_data(port);
462 int status = urb->status;
463 unsigned long flags;
464
465 /* free up the transfer buffer, as usb_free_urb() does not do this */
466 kfree(urb->transfer_buffer);
467
468 dbg("%s - port %d", __func__, port->number);
469
470 if (status)
471 dbg("%s - nonzero write bulk status received: %d",
472 __func__, status);
473
474 spin_lock_irqsave(&priv->lock, flags);
475 --priv->outstanding_urbs;
476 spin_unlock_irqrestore(&priv->lock, flags);
477
478 usb_serial_port_softint(port);
479}
480
481
482static void visor_read_bulk_callback(struct urb *urb)
483{
484 struct usb_serial_port *port = urb->context;
485 struct visor_private *priv = usb_get_serial_port_data(port);
486 unsigned char *data = urb->transfer_buffer;
487 int status = urb->status;
488 struct tty_struct *tty;
489 int result;
490 int available_room = 0;
491
492 dbg("%s - port %d", __func__, port->number);
493
494 if (status) {
495 dbg("%s - nonzero read bulk status received: %d",
496 __func__, status);
497 return;
498 }
499
500 usb_serial_debug_data(debug, &port->dev, __func__,
501 urb->actual_length, data);
502
503 if (urb->actual_length) {
504 tty = tty_port_tty_get(&port->port);
505 if (tty) {
506 tty_insert_flip_string(tty, data,
507 urb->actual_length);
508 tty_flip_buffer_push(tty);
509 tty_kref_put(tty);
510 }
511 spin_lock(&priv->lock);
512 if (tty)
513 priv->bytes_in += available_room;
514
515 } else {
516 spin_lock(&priv->lock);
517 }
518
519 /* Continue trying to always read if we should */
520 if (!priv->throttled) {
521 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
522 usb_rcvbulkpipe(port->serial->dev,
523 port->bulk_in_endpointAddress),
524 port->read_urb->transfer_buffer,
525 port->read_urb->transfer_buffer_length,
526 visor_read_bulk_callback, port);
527 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
528 if (result)
529 dev_err(&port->dev,
530 "%s - failed resubmitting read urb, error %d\n",
531 __func__, result);
532 } else
533 priv->actually_throttled = 1;
534 spin_unlock(&priv->lock);
535} 296}
536 297
537static void visor_read_int_callback(struct urb *urb) 298static void visor_read_int_callback(struct urb *urb)
@@ -575,41 +336,6 @@ exit:
575 __func__, result); 336 __func__, result);
576} 337}
577 338
578static void visor_throttle(struct tty_struct *tty)
579{
580 struct usb_serial_port *port = tty->driver_data;
581 struct visor_private *priv = usb_get_serial_port_data(port);
582
583 dbg("%s - port %d", __func__, port->number);
584 spin_lock_irq(&priv->lock);
585 priv->throttled = 1;
586 spin_unlock_irq(&priv->lock);
587}
588
589
590static void visor_unthrottle(struct tty_struct *tty)
591{
592 struct usb_serial_port *port = tty->driver_data;
593 struct visor_private *priv = usb_get_serial_port_data(port);
594 int result, was_throttled;
595
596 dbg("%s - port %d", __func__, port->number);
597 spin_lock_irq(&priv->lock);
598 priv->throttled = 0;
599 was_throttled = priv->actually_throttled;
600 priv->actually_throttled = 0;
601 spin_unlock_irq(&priv->lock);
602
603 if (was_throttled) {
604 port->read_urb->dev = port->serial->dev;
605 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
606 if (result)
607 dev_err(&port->dev,
608 "%s - failed submitting read urb, error %d\n",
609 __func__, result);
610 }
611}
612
613static int palm_os_3_probe(struct usb_serial *serial, 339static int palm_os_3_probe(struct usb_serial *serial,
614 const struct usb_device_id *id) 340 const struct usb_device_id *id)
615{ 341{
@@ -777,28 +503,6 @@ static int visor_calc_num_ports(struct usb_serial *serial)
777 return num_ports; 503 return num_ports;
778} 504}
779 505
780static int generic_startup(struct usb_serial *serial)
781{
782 struct usb_serial_port **ports = serial->port;
783 struct visor_private *priv;
784 int i;
785
786 for (i = 0; i < serial->num_ports; ++i) {
787 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
788 if (!priv) {
789 while (i-- != 0) {
790 priv = usb_get_serial_port_data(ports[i]);
791 usb_set_serial_port_data(ports[i], NULL);
792 kfree(priv);
793 }
794 return -ENOMEM;
795 }
796 spin_lock_init(&priv->lock);
797 usb_set_serial_port_data(ports[i], priv);
798 }
799 return 0;
800}
801
802static int clie_3_5_startup(struct usb_serial *serial) 506static int clie_3_5_startup(struct usb_serial *serial)
803{ 507{
804 struct device *dev = &serial->dev->dev; 508 struct device *dev = &serial->dev->dev;
@@ -849,7 +553,7 @@ static int clie_3_5_startup(struct usb_serial *serial)
849 goto out; 553 goto out;
850 } 554 }
851 555
852 result = generic_startup(serial); 556 result = 0;
853out: 557out:
854 kfree(data); 558 kfree(data);
855 559
@@ -867,7 +571,7 @@ static int treo_attach(struct usb_serial *serial)
867 (le16_to_cpu(serial->dev->descriptor.idVendor) 571 (le16_to_cpu(serial->dev->descriptor.idVendor)
868 == KYOCERA_VENDOR_ID)) || 572 == KYOCERA_VENDOR_ID)) ||
869 (serial->num_interrupt_in == 0)) 573 (serial->num_interrupt_in == 0))
870 goto generic_startup; 574 return 0;
871 575
872 dbg("%s", __func__); 576 dbg("%s", __func__);
873 577
@@ -897,8 +601,7 @@ static int treo_attach(struct usb_serial *serial)
897 COPY_PORT(serial->port[1], swap_port); 601 COPY_PORT(serial->port[1], swap_port);
898 kfree(swap_port); 602 kfree(swap_port);
899 603
900generic_startup: 604 return 0;
901 return generic_startup(serial);
902} 605}
903 606
904static int clie_5_attach(struct usb_serial *serial) 607static int clie_5_attach(struct usb_serial *serial)
@@ -921,20 +624,7 @@ static int clie_5_attach(struct usb_serial *serial)
921 serial->port[0]->bulk_out_endpointAddress = 624 serial->port[0]->bulk_out_endpointAddress =
922 serial->port[1]->bulk_out_endpointAddress; 625 serial->port[1]->bulk_out_endpointAddress;
923 626
924 return generic_startup(serial); 627 return 0;
925}
926
927static void visor_release(struct usb_serial *serial)
928{
929 struct visor_private *priv;
930 int i;
931
932 dbg("%s", __func__);
933
934 for (i = 0; i < serial->num_ports; i++) {
935 priv = usb_get_serial_port_data(serial->port[i]);
936 kfree(priv);
937 }
938} 628}
939 629
940static int __init visor_init(void) 630static int __init visor_init(void)
@@ -1018,8 +708,6 @@ MODULE_LICENSE("GPL");
1018 708
1019module_param(debug, bool, S_IRUGO | S_IWUSR); 709module_param(debug, bool, S_IRUGO | S_IWUSR);
1020MODULE_PARM_DESC(debug, "Debug enabled or not"); 710MODULE_PARM_DESC(debug, "Debug enabled or not");
1021module_param(stats, bool, S_IRUGO | S_IWUSR);
1022MODULE_PARM_DESC(stats, "Enables statistics or not");
1023 711
1024module_param(vendor, ushort, 0); 712module_param(vendor, ushort, 0);
1025MODULE_PARM_DESC(vendor, "User specified vendor ID"); 713MODULE_PARM_DESC(vendor, "User specified vendor ID");
diff --git a/drivers/usb/serial/visor.h b/drivers/usb/serial/visor.h
index 57229cf66477..88db4d06aefb 100644
--- a/drivers/usb/serial/visor.h
+++ b/drivers/usb/serial/visor.h
@@ -9,8 +9,9 @@
9 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * See Documentation/usb/usb-serial.txt for more information on using this driver 12 * See Documentation/usb/usb-serial.txt for more information on using this
13 * 13 * driver.
14 *
14 */ 15 */
15 16
16#ifndef __LINUX_USB_SERIAL_VISOR_H 17#ifndef __LINUX_USB_SERIAL_VISOR_H
@@ -65,7 +66,7 @@
65#define ACEECA_MEZ1000_ID 0x0001 66#define ACEECA_MEZ1000_ID 0x0001
66 67
67#define KYOCERA_VENDOR_ID 0x0C88 68#define KYOCERA_VENDOR_ID 0x0C88
68#define KYOCERA_7135_ID 0x0021 69#define KYOCERA_7135_ID 0x0021
69 70
70#define FOSSIL_VENDOR_ID 0x0E67 71#define FOSSIL_VENDOR_ID 0x0E67
71#define FOSSIL_ABACUS_ID 0x0002 72#define FOSSIL_ABACUS_ID 0x0002
@@ -145,7 +146,7 @@ struct visor_connection_info {
145 * The maximum number of connections currently supported is 2 146 * The maximum number of connections currently supported is 2
146 */ 147 */
147struct palm_ext_connection_info { 148struct palm_ext_connection_info {
148 __u8 num_ports; 149 __u8 num_ports;
149 __u8 endpoint_numbers_different; 150 __u8 endpoint_numbers_different;
150 __le16 reserved1; 151 __le16 reserved1;
151 struct { 152 struct {
diff --git a/drivers/usb/serial/zio.c b/drivers/usb/serial/zio.c
new file mode 100644
index 000000000000..f57967278833
--- /dev/null
+++ b/drivers/usb/serial/zio.c
@@ -0,0 +1,64 @@
1/*
2 * ZIO Motherboard USB driver
3 *
4 * Copyright (C) 2010 Zilogic Systems <code@zilogic.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/tty.h>
14#include <linux/module.h>
15#include <linux/usb.h>
16#include <linux/usb/serial.h>
17#include <linux/uaccess.h>
18
19static const struct usb_device_id id_table[] = {
20 { USB_DEVICE(0x1CBE, 0x0103) },
21 { },
22};
23MODULE_DEVICE_TABLE(usb, id_table);
24
25static struct usb_driver zio_driver = {
26 .name = "zio",
27 .probe = usb_serial_probe,
28 .disconnect = usb_serial_disconnect,
29 .id_table = id_table,
30 .no_dynamic_id = 1,
31};
32
33static struct usb_serial_driver zio_device = {
34 .driver = {
35 .owner = THIS_MODULE,
36 .name = "zio",
37 },
38 .id_table = id_table,
39 .usb_driver = &zio_driver,
40 .num_ports = 1,
41};
42
43static int __init zio_init(void)
44{
45 int retval;
46
47 retval = usb_serial_register(&zio_device);
48 if (retval)
49 return retval;
50 retval = usb_register(&zio_driver);
51 if (retval)
52 usb_serial_deregister(&zio_device);
53 return retval;
54}
55
56static void __exit zio_exit(void)
57{
58 usb_deregister(&zio_driver);
59 usb_serial_deregister(&zio_device);
60}
61
62module_init(zio_init);
63module_exit(zio_exit);
64MODULE_LICENSE("GPL");
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index fdba2f69d4c9..e9cbc1467f76 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -490,13 +490,13 @@ static int isd200_action( struct us_data *us, int action,
490 void* pointer, int value ) 490 void* pointer, int value )
491{ 491{
492 union ata_cdb ata; 492 union ata_cdb ata;
493 struct scsi_device srb_dev; 493 /* static to prevent this large struct being placed on the valuable stack */
494 static struct scsi_device srb_dev;
494 struct isd200_info *info = (struct isd200_info *)us->extra; 495 struct isd200_info *info = (struct isd200_info *)us->extra;
495 struct scsi_cmnd *srb = &info->srb; 496 struct scsi_cmnd *srb = &info->srb;
496 int status; 497 int status;
497 498
498 memset(&ata, 0, sizeof(ata)); 499 memset(&ata, 0, sizeof(ata));
499 memset(&srb_dev, 0, sizeof(srb_dev));
500 srb->cmnd = info->cmnd; 500 srb->cmnd = info->cmnd;
501 srb->device = &srb_dev; 501 srb->device = &srb_dev;
502 ++srb->serial_number; 502 ++srb->serial_number;
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 198bb3ed95b2..1943be5a2914 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -201,8 +201,8 @@ static int onetouch_connect_input(struct us_data *ss)
201 if (!onetouch || !input_dev) 201 if (!onetouch || !input_dev)
202 goto fail1; 202 goto fail1;
203 203
204 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, 204 onetouch->data = usb_alloc_coherent(udev, ONETOUCH_PKT_LEN,
205 GFP_KERNEL, &onetouch->data_dma); 205 GFP_KERNEL, &onetouch->data_dma);
206 if (!onetouch->data) 206 if (!onetouch->data)
207 goto fail1; 207 goto fail1;
208 208
@@ -264,8 +264,8 @@ static int onetouch_connect_input(struct us_data *ss)
264 return 0; 264 return 0;
265 265
266 fail3: usb_free_urb(onetouch->irq); 266 fail3: usb_free_urb(onetouch->irq);
267 fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN, 267 fail2: usb_free_coherent(udev, ONETOUCH_PKT_LEN,
268 onetouch->data, onetouch->data_dma); 268 onetouch->data, onetouch->data_dma);
269 fail1: kfree(onetouch); 269 fail1: kfree(onetouch);
270 input_free_device(input_dev); 270 input_free_device(input_dev);
271 return error; 271 return error;
@@ -279,8 +279,8 @@ static void onetouch_release_input(void *onetouch_)
279 usb_kill_urb(onetouch->irq); 279 usb_kill_urb(onetouch->irq);
280 input_unregister_device(onetouch->dev); 280 input_unregister_device(onetouch->dev);
281 usb_free_urb(onetouch->irq); 281 usb_free_urb(onetouch->irq);
282 usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, 282 usb_free_coherent(onetouch->udev, ONETOUCH_PKT_LEN,
283 onetouch->data, onetouch->data_dma); 283 onetouch->data, onetouch->data_dma);
284 } 284 }
285} 285}
286 286
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index f253edec3bb8..44716427c51c 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -147,11 +147,9 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
147 * hasn't been mapped for DMA. Yes, this is clunky, but it's 147 * hasn't been mapped for DMA. Yes, this is clunky, but it's
148 * easier than always having the caller tell us whether the 148 * easier than always having the caller tell us whether the
149 * transfer buffer has already been mapped. */ 149 * transfer buffer has already been mapped. */
150 us->current_urb->transfer_flags = URB_NO_SETUP_DMA_MAP;
151 if (us->current_urb->transfer_buffer == us->iobuf) 150 if (us->current_urb->transfer_buffer == us->iobuf)
152 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 151 us->current_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
153 us->current_urb->transfer_dma = us->iobuf_dma; 152 us->current_urb->transfer_dma = us->iobuf_dma;
154 us->current_urb->setup_dma = us->cr_dma;
155 153
156 /* submit the URB */ 154 /* submit the URB */
157 status = usb_submit_urb(us->current_urb, GFP_NOIO); 155 status = usb_submit_urb(us->current_urb, GFP_NOIO);
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index ccf1dbbb87ef..2c897eefadde 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -365,15 +365,6 @@ UNUSUAL_DEV( 0x04cb, 0x0100, 0x0000, 0x2210,
365 "FinePix 1400Zoom", 365 "FinePix 1400Zoom",
366 US_SC_UFI, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY | US_FL_SINGLE_LUN), 366 US_SC_UFI, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY | US_FL_SINGLE_LUN),
367 367
368/* Reported by Peter Wächtler <pwaechtler@loewe-komp.de>
369 * The device needs the flags only.
370 */
371UNUSUAL_DEV( 0x04ce, 0x0002, 0x0074, 0x0074,
372 "ScanLogic",
373 "SL11R-IDE",
374 US_SC_DEVICE, US_PR_DEVICE, NULL,
375 US_FL_FIX_INQUIRY),
376
377/* Reported by Ondrej Zary <linux@rainbow-software.org> 368/* Reported by Ondrej Zary <linux@rainbow-software.org>
378 * The device reports one sector more and breaks when that sector is accessed 369 * The device reports one sector more and breaks when that sector is accessed
379 */ 370 */
@@ -1853,6 +1844,21 @@ UNUSUAL_DEV( 0x1652, 0x6600, 0x0201, 0x0201,
1853 US_SC_DEVICE, US_PR_DEVICE, NULL, 1844 US_SC_DEVICE, US_PR_DEVICE, NULL,
1854 US_FL_IGNORE_RESIDUE ), 1845 US_FL_IGNORE_RESIDUE ),
1855 1846
1847/* Reported by Hans de Goede <hdegoede@redhat.com>
1848 * These Appotech controllers are found in Picture Frames, they provide a
1849 * (buggy) emulation of a cdrom drive which contains the windows software
1850 * Uploading of pictures happens over the corresponding /dev/sg device. */
1851UNUSUAL_DEV( 0x1908, 0x1315, 0x0000, 0x0000,
1852 "BUILDWIN",
1853 "Photo Frame",
1854 US_SC_DEVICE, US_PR_DEVICE, NULL,
1855 US_FL_BAD_SENSE ),
1856UNUSUAL_DEV( 0x1908, 0x1320, 0x0000, 0x0000,
1857 "BUILDWIN",
1858 "Photo Frame",
1859 US_SC_DEVICE, US_PR_DEVICE, NULL,
1860 US_FL_BAD_SENSE ),
1861
1856UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001, 1862UNUSUAL_DEV( 0x2116, 0x0320, 0x0001, 0x0001,
1857 "ST", 1863 "ST",
1858 "2A", 1864 "2A",
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index bbeeb92a2131..a7d0bf9d92a7 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -407,15 +407,14 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf)
407 /* Store our private data in the interface */ 407 /* Store our private data in the interface */
408 usb_set_intfdata(intf, us); 408 usb_set_intfdata(intf, us);
409 409
410 /* Allocate the device-related DMA-mapped buffers */ 410 /* Allocate the control/setup and DMA-mapped buffers */
411 us->cr = usb_buffer_alloc(us->pusb_dev, sizeof(*us->cr), 411 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL);
412 GFP_KERNEL, &us->cr_dma);
413 if (!us->cr) { 412 if (!us->cr) {
414 US_DEBUGP("usb_ctrlrequest allocation failed\n"); 413 US_DEBUGP("usb_ctrlrequest allocation failed\n");
415 return -ENOMEM; 414 return -ENOMEM;
416 } 415 }
417 416
418 us->iobuf = usb_buffer_alloc(us->pusb_dev, US_IOBUF_SIZE, 417 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE,
419 GFP_KERNEL, &us->iobuf_dma); 418 GFP_KERNEL, &us->iobuf_dma);
420 if (!us->iobuf) { 419 if (!us->iobuf) {
421 US_DEBUGP("I/O buffer allocation failed\n"); 420 US_DEBUGP("I/O buffer allocation failed\n");
@@ -499,9 +498,6 @@ static void adjust_quirks(struct us_data *us)
499 } 498 }
500 } 499 }
501 us->fflags = (us->fflags & ~mask) | f; 500 us->fflags = (us->fflags & ~mask) | f;
502 dev_info(&us->pusb_intf->dev, "Quirks match for "
503 "vid %04x pid %04x: %x\n",
504 vid, pid, f);
505} 501}
506 502
507/* Get the unusual_devs entries and the string descriptors */ 503/* Get the unusual_devs entries and the string descriptors */
@@ -511,6 +507,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
511 struct usb_device *dev = us->pusb_dev; 507 struct usb_device *dev = us->pusb_dev;
512 struct usb_interface_descriptor *idesc = 508 struct usb_interface_descriptor *idesc =
513 &us->pusb_intf->cur_altsetting->desc; 509 &us->pusb_intf->cur_altsetting->desc;
510 struct device *pdev = &us->pusb_intf->dev;
514 511
515 /* Store the entries */ 512 /* Store the entries */
516 us->unusual_dev = unusual_dev; 513 us->unusual_dev = unusual_dev;
@@ -524,7 +521,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
524 adjust_quirks(us); 521 adjust_quirks(us);
525 522
526 if (us->fflags & US_FL_IGNORE_DEVICE) { 523 if (us->fflags & US_FL_IGNORE_DEVICE) {
527 printk(KERN_INFO USB_STORAGE "device ignored\n"); 524 dev_info(pdev, "device ignored\n");
528 return -ENODEV; 525 return -ENODEV;
529 } 526 }
530 527
@@ -535,6 +532,12 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
535 if (dev->speed != USB_SPEED_HIGH) 532 if (dev->speed != USB_SPEED_HIGH)
536 us->fflags &= ~US_FL_GO_SLOW; 533 us->fflags &= ~US_FL_GO_SLOW;
537 534
535 if (us->fflags)
536 dev_info(pdev, "Quirks match for vid %04x pid %04x: %lx\n",
537 le16_to_cpu(dev->descriptor.idVendor),
538 le16_to_cpu(dev->descriptor.idProduct),
539 us->fflags);
540
538 /* Log a message if a non-generic unusual_dev entry contains an 541 /* Log a message if a non-generic unusual_dev entry contains an
539 * unnecessary subclass or protocol override. This may stimulate 542 * unnecessary subclass or protocol override. This may stimulate
540 * reports from users that will help us remove unneeded entries 543 * reports from users that will help us remove unneeded entries
@@ -555,20 +558,20 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id,
555 us->protocol == idesc->bInterfaceProtocol) 558 us->protocol == idesc->bInterfaceProtocol)
556 msg += 2; 559 msg += 2;
557 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE)) 560 if (msg >= 0 && !(us->fflags & US_FL_NEED_OVERRIDE))
558 printk(KERN_NOTICE USB_STORAGE "This device " 561 dev_notice(pdev, "This device "
559 "(%04x,%04x,%04x S %02x P %02x)" 562 "(%04x,%04x,%04x S %02x P %02x)"
560 " has %s in unusual_devs.h (kernel" 563 " has %s in unusual_devs.h (kernel"
561 " %s)\n" 564 " %s)\n"
562 " Please send a copy of this message to " 565 " Please send a copy of this message to "
563 "<linux-usb@vger.kernel.org> and " 566 "<linux-usb@vger.kernel.org> and "
564 "<usb-storage@lists.one-eyed-alien.net>\n", 567 "<usb-storage@lists.one-eyed-alien.net>\n",
565 le16_to_cpu(ddesc->idVendor), 568 le16_to_cpu(ddesc->idVendor),
566 le16_to_cpu(ddesc->idProduct), 569 le16_to_cpu(ddesc->idProduct),
567 le16_to_cpu(ddesc->bcdDevice), 570 le16_to_cpu(ddesc->bcdDevice),
568 idesc->bInterfaceSubClass, 571 idesc->bInterfaceSubClass,
569 idesc->bInterfaceProtocol, 572 idesc->bInterfaceProtocol,
570 msgs[msg], 573 msgs[msg],
571 utsname()->release); 574 utsname()->release);
572 } 575 }
573 576
574 return 0; 577 return 0;
@@ -718,8 +721,8 @@ static int usb_stor_acquire_resources(struct us_data *us)
718 /* Start up our control thread */ 721 /* Start up our control thread */
719 th = kthread_run(usb_stor_control_thread, us, "usb-storage"); 722 th = kthread_run(usb_stor_control_thread, us, "usb-storage");
720 if (IS_ERR(th)) { 723 if (IS_ERR(th)) {
721 printk(KERN_WARNING USB_STORAGE 724 dev_warn(&us->pusb_intf->dev,
722 "Unable to start control thread\n"); 725 "Unable to start control thread\n");
723 return PTR_ERR(th); 726 return PTR_ERR(th);
724 } 727 }
725 us->ctl_thread = th; 728 us->ctl_thread = th;
@@ -757,13 +760,9 @@ static void dissociate_dev(struct us_data *us)
757{ 760{
758 US_DEBUGP("-- %s\n", __func__); 761 US_DEBUGP("-- %s\n", __func__);
759 762
760 /* Free the device-related DMA-mapped buffers */ 763 /* Free the buffers */
761 if (us->cr) 764 kfree(us->cr);
762 usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr, 765 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
763 us->cr_dma);
764 if (us->iobuf)
765 usb_buffer_free(us->pusb_dev, US_IOBUF_SIZE, us->iobuf,
766 us->iobuf_dma);
767 766
768 /* Remove our private data from the interface */ 767 /* Remove our private data from the interface */
769 usb_set_intfdata(us->pusb_intf, NULL); 768 usb_set_intfdata(us->pusb_intf, NULL);
@@ -816,13 +815,14 @@ static void release_everything(struct us_data *us)
816static int usb_stor_scan_thread(void * __us) 815static int usb_stor_scan_thread(void * __us)
817{ 816{
818 struct us_data *us = (struct us_data *)__us; 817 struct us_data *us = (struct us_data *)__us;
818 struct device *dev = &us->pusb_intf->dev;
819 819
820 dev_dbg(&us->pusb_intf->dev, "device found\n"); 820 dev_dbg(dev, "device found\n");
821 821
822 set_freezable(); 822 set_freezable();
823 /* Wait for the timeout to expire or for a disconnect */ 823 /* Wait for the timeout to expire or for a disconnect */
824 if (delay_use > 0) { 824 if (delay_use > 0) {
825 dev_dbg(&us->pusb_intf->dev, "waiting for device to settle " 825 dev_dbg(dev, "waiting for device to settle "
826 "before scanning\n"); 826 "before scanning\n");
827 wait_event_freezable_timeout(us->delay_wait, 827 wait_event_freezable_timeout(us->delay_wait,
828 test_bit(US_FLIDX_DONT_SCAN, &us->dflags), 828 test_bit(US_FLIDX_DONT_SCAN, &us->dflags),
@@ -840,7 +840,7 @@ static int usb_stor_scan_thread(void * __us)
840 mutex_unlock(&us->dev_mutex); 840 mutex_unlock(&us->dev_mutex);
841 } 841 }
842 scsi_scan_host(us_to_host(us)); 842 scsi_scan_host(us_to_host(us));
843 dev_dbg(&us->pusb_intf->dev, "scan complete\n"); 843 dev_dbg(dev, "scan complete\n");
844 844
845 /* Should we unbind if no devices were detected? */ 845 /* Should we unbind if no devices were detected? */
846 } 846 }
@@ -876,8 +876,8 @@ int usb_stor_probe1(struct us_data **pus,
876 */ 876 */
877 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); 877 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
878 if (!host) { 878 if (!host) {
879 printk(KERN_WARNING USB_STORAGE 879 dev_warn(&intf->dev,
880 "Unable to allocate the scsi host\n"); 880 "Unable to allocate the scsi host\n");
881 return -ENOMEM; 881 return -ENOMEM;
882 } 882 }
883 883
@@ -925,6 +925,7 @@ int usb_stor_probe2(struct us_data *us)
925{ 925{
926 struct task_struct *th; 926 struct task_struct *th;
927 int result; 927 int result;
928 struct device *dev = &us->pusb_intf->dev;
928 929
929 /* Make sure the transport and protocol have both been set */ 930 /* Make sure the transport and protocol have both been set */
930 if (!us->transport || !us->proto_handler) { 931 if (!us->transport || !us->proto_handler) {
@@ -949,18 +950,18 @@ int usb_stor_probe2(struct us_data *us)
949 goto BadDevice; 950 goto BadDevice;
950 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s", 951 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
951 dev_name(&us->pusb_intf->dev)); 952 dev_name(&us->pusb_intf->dev));
952 result = scsi_add_host(us_to_host(us), &us->pusb_intf->dev); 953 result = scsi_add_host(us_to_host(us), dev);
953 if (result) { 954 if (result) {
954 printk(KERN_WARNING USB_STORAGE 955 dev_warn(dev,
955 "Unable to add the scsi host\n"); 956 "Unable to add the scsi host\n");
956 goto BadDevice; 957 goto BadDevice;
957 } 958 }
958 959
959 /* Start up the thread for delayed SCSI-device scanning */ 960 /* Start up the thread for delayed SCSI-device scanning */
960 th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan"); 961 th = kthread_create(usb_stor_scan_thread, us, "usb-stor-scan");
961 if (IS_ERR(th)) { 962 if (IS_ERR(th)) {
962 printk(KERN_WARNING USB_STORAGE 963 dev_warn(dev,
963 "Unable to start the device-scanning thread\n"); 964 "Unable to start the device-scanning thread\n");
964 complete(&us->scanning_done); 965 complete(&us->scanning_done);
965 quiesce_and_remove_host(us); 966 quiesce_and_remove_host(us);
966 result = PTR_ERR(th); 967 result = PTR_ERR(th);
@@ -1046,12 +1047,12 @@ static int __init usb_stor_init(void)
1046{ 1047{
1047 int retval; 1048 int retval;
1048 1049
1049 printk(KERN_INFO "Initializing USB Mass Storage driver...\n"); 1050 pr_info("Initializing USB Mass Storage driver...\n");
1050 1051
1051 /* register the driver, return usb_register return code if error */ 1052 /* register the driver, return usb_register return code if error */
1052 retval = usb_register(&usb_storage_driver); 1053 retval = usb_register(&usb_storage_driver);
1053 if (retval == 0) { 1054 if (retval == 0) {
1054 printk(KERN_INFO "USB Mass Storage support registered.\n"); 1055 pr_info("USB Mass Storage support registered.\n");
1055 usb_usual_set_present(USB_US_TYPE_STOR); 1056 usb_usual_set_present(USB_US_TYPE_STOR);
1056 } 1057 }
1057 return retval; 1058 return retval;
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 69717134231b..89d3bfff98df 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -139,8 +139,7 @@ struct us_data {
139 struct usb_ctrlrequest *cr; /* control requests */ 139 struct usb_ctrlrequest *cr; /* control requests */
140 struct usb_sg_request current_sg; /* scatter-gather req. */ 140 struct usb_sg_request current_sg; /* scatter-gather req. */
141 unsigned char *iobuf; /* I/O buffer */ 141 unsigned char *iobuf; /* I/O buffer */
142 dma_addr_t cr_dma; /* buffer DMA addresses */ 142 dma_addr_t iobuf_dma; /* buffer DMA addresses */
143 dma_addr_t iobuf_dma;
144 struct task_struct *ctl_thread; /* the control thread */ 143 struct task_struct *ctl_thread; /* the control thread */
145 144
146 /* mutual exclusion and synchronization structures */ 145 /* mutual exclusion and synchronization structures */
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index 61522787f39c..d110588b56f1 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -387,8 +387,8 @@ static void skel_write_bulk_callback(struct urb *urb)
387 } 387 }
388 388
389 /* free up our allocated buffer */ 389 /* free up our allocated buffer */
390 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 390 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
391 urb->transfer_buffer, urb->transfer_dma); 391 urb->transfer_buffer, urb->transfer_dma);
392 up(&dev->limit_sem); 392 up(&dev->limit_sem);
393} 393}
394 394
@@ -442,8 +442,8 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
442 goto error; 442 goto error;
443 } 443 }
444 444
445 buf = usb_buffer_alloc(dev->udev, writesize, GFP_KERNEL, 445 buf = usb_alloc_coherent(dev->udev, writesize, GFP_KERNEL,
446 &urb->transfer_dma); 446 &urb->transfer_dma);
447 if (!buf) { 447 if (!buf) {
448 retval = -ENOMEM; 448 retval = -ENOMEM;
449 goto error; 449 goto error;
@@ -491,7 +491,7 @@ error_unanchor:
491 usb_unanchor_urb(urb); 491 usb_unanchor_urb(urb);
492error: 492error:
493 if (urb) { 493 if (urb) {
494 usb_buffer_free(dev->udev, writesize, buf, urb->transfer_dma); 494 usb_free_coherent(dev->udev, writesize, buf, urb->transfer_dma);
495 usb_free_urb(urb); 495 usb_free_urb(urb);
496 } 496 }
497 up(&dev->limit_sem); 497 up(&dev->limit_sem);
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 608d61a105f6..84b744c428a4 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -474,8 +474,6 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
474 struct wa_xfer_ctl *xfer_ctl = 474 struct wa_xfer_ctl *xfer_ctl =
475 container_of(xfer_hdr0, struct wa_xfer_ctl, hdr); 475 container_of(xfer_hdr0, struct wa_xfer_ctl, hdr);
476 xfer_ctl->bmAttribute = xfer->is_inbound ? 1 : 0; 476 xfer_ctl->bmAttribute = xfer->is_inbound ? 1 : 0;
477 BUG_ON(xfer->urb->transfer_flags & URB_NO_SETUP_DMA_MAP
478 && xfer->urb->setup_packet == NULL);
479 memcpy(&xfer_ctl->baSetupData, xfer->urb->setup_packet, 477 memcpy(&xfer_ctl->baSetupData, xfer->urb->setup_packet,
480 sizeof(xfer_ctl->baSetupData)); 478 sizeof(xfer_ctl->baSetupData));
481 break; 479 break;
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h
index 759cda55f7c3..3d94c4247f46 100644
--- a/drivers/usb/wusbcore/wusbhc.h
+++ b/drivers/usb/wusbcore/wusbhc.h
@@ -58,9 +58,7 @@
58#include <linux/mutex.h> 58#include <linux/mutex.h>
59#include <linux/kref.h> 59#include <linux/kref.h>
60#include <linux/workqueue.h> 60#include <linux/workqueue.h>
61/* FIXME: Yes, I know: BAD--it's not my fault the USB HC iface is not 61#include <linux/usb/hcd.h>
62 * public */
63#include <linux/../../drivers/usb/core/hcd.h>
64#include <linux/uwb.h> 62#include <linux/uwb.h>
65#include <linux/usb/wusb.h> 63#include <linux/usb/wusb.h>
66 64
diff --git a/drivers/watchdog/pcwd_usb.c b/drivers/watchdog/pcwd_usb.c
index 8e4eacc5bb52..748a74bd85e7 100644
--- a/drivers/watchdog/pcwd_usb.c
+++ b/drivers/watchdog/pcwd_usb.c
@@ -600,8 +600,8 @@ static inline void usb_pcwd_delete(struct usb_pcwd_private *usb_pcwd)
600{ 600{
601 usb_free_urb(usb_pcwd->intr_urb); 601 usb_free_urb(usb_pcwd->intr_urb);
602 if (usb_pcwd->intr_buffer != NULL) 602 if (usb_pcwd->intr_buffer != NULL)
603 usb_buffer_free(usb_pcwd->udev, usb_pcwd->intr_size, 603 usb_free_coherent(usb_pcwd->udev, usb_pcwd->intr_size,
604 usb_pcwd->intr_buffer, usb_pcwd->intr_dma); 604 usb_pcwd->intr_buffer, usb_pcwd->intr_dma);
605 kfree(usb_pcwd); 605 kfree(usb_pcwd);
606} 606}
607 607
@@ -671,7 +671,7 @@ static int usb_pcwd_probe(struct usb_interface *interface,
671 le16_to_cpu(endpoint->wMaxPacketSize) : 8); 671 le16_to_cpu(endpoint->wMaxPacketSize) : 8);
672 672
673 /* set up the memory buffer's */ 673 /* set up the memory buffer's */
674 usb_pcwd->intr_buffer = usb_buffer_alloc(udev, usb_pcwd->intr_size, 674 usb_pcwd->intr_buffer = usb_alloc_coherent(udev, usb_pcwd->intr_size,
675 GFP_ATOMIC, &usb_pcwd->intr_dma); 675 GFP_ATOMIC, &usb_pcwd->intr_dma);
676 if (!usb_pcwd->intr_buffer) { 676 if (!usb_pcwd->intr_buffer) {
677 printk(KERN_ERR PFX "Out of memory\n"); 677 printk(KERN_ERR PFX "Out of memory\n");
diff --git a/fs/timerfd.c b/fs/timerfd.c
index 98158de91d24..b86ab8eff79a 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -110,31 +110,14 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
110 struct timerfd_ctx *ctx = file->private_data; 110 struct timerfd_ctx *ctx = file->private_data;
111 ssize_t res; 111 ssize_t res;
112 u64 ticks = 0; 112 u64 ticks = 0;
113 DECLARE_WAITQUEUE(wait, current);
114 113
115 if (count < sizeof(ticks)) 114 if (count < sizeof(ticks))
116 return -EINVAL; 115 return -EINVAL;
117 spin_lock_irq(&ctx->wqh.lock); 116 spin_lock_irq(&ctx->wqh.lock);
118 res = -EAGAIN; 117 if (file->f_flags & O_NONBLOCK)
119 if (!ctx->ticks && !(file->f_flags & O_NONBLOCK)) { 118 res = -EAGAIN;
120 __add_wait_queue(&ctx->wqh, &wait); 119 else
121 for (res = 0;;) { 120 res = wait_event_interruptible_locked_irq(ctx->wqh, ctx->ticks);
122 set_current_state(TASK_INTERRUPTIBLE);
123 if (ctx->ticks) {
124 res = 0;
125 break;
126 }
127 if (signal_pending(current)) {
128 res = -ERESTARTSYS;
129 break;
130 }
131 spin_unlock_irq(&ctx->wqh.lock);
132 schedule();
133 spin_lock_irq(&ctx->wqh.lock);
134 }
135 __remove_wait_queue(&ctx->wqh, &wait);
136 __set_current_state(TASK_RUNNING);
137 }
138 if (ctx->ticks) { 121 if (ctx->ticks) {
139 ticks = ctx->ticks; 122 ticks = ctx->ticks;
140 if (ctx->expired && ctx->tintv.tv64) { 123 if (ctx->expired && ctx->tintv.tv64) {
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 739f1fd1cc15..d5922a877994 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -45,27 +45,14 @@ struct wusb_dev;
45 45
46struct ep_device; 46struct ep_device;
47 47
48/* For SS devices */
49/**
50 * struct usb_host_ss_ep_comp - Valid for SuperSpeed devices only
51 * @desc: endpoint companion descriptor, wMaxPacketSize in native byteorder
52 * @extra: descriptors following this endpoint companion descriptor
53 * @extralen: how many bytes of "extra" are valid
54 */
55struct usb_host_ss_ep_comp {
56 struct usb_ss_ep_comp_descriptor desc;
57 unsigned char *extra; /* Extra descriptors */
58 int extralen;
59};
60
61/** 48/**
62 * struct usb_host_endpoint - host-side endpoint descriptor and queue 49 * struct usb_host_endpoint - host-side endpoint descriptor and queue
63 * @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder 50 * @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder
51 * @ss_ep_comp: SuperSpeed companion descriptor for this endpoint
64 * @urb_list: urbs queued to this endpoint; maintained by usbcore 52 * @urb_list: urbs queued to this endpoint; maintained by usbcore
65 * @hcpriv: for use by HCD; typically holds hardware dma queue head (QH) 53 * @hcpriv: for use by HCD; typically holds hardware dma queue head (QH)
66 * with one or more transfer descriptors (TDs) per urb 54 * with one or more transfer descriptors (TDs) per urb
67 * @ep_dev: ep_device for sysfs info 55 * @ep_dev: ep_device for sysfs info
68 * @ss_ep_comp: companion descriptor information for this endpoint
69 * @extra: descriptors following this endpoint in the configuration 56 * @extra: descriptors following this endpoint in the configuration
70 * @extralen: how many bytes of "extra" are valid 57 * @extralen: how many bytes of "extra" are valid
71 * @enabled: URBs may be submitted to this endpoint 58 * @enabled: URBs may be submitted to this endpoint
@@ -74,11 +61,11 @@ struct usb_host_ss_ep_comp {
74 * descriptor within an active interface in a given USB configuration. 61 * descriptor within an active interface in a given USB configuration.
75 */ 62 */
76struct usb_host_endpoint { 63struct usb_host_endpoint {
77 struct usb_endpoint_descriptor desc; 64 struct usb_endpoint_descriptor desc;
65 struct usb_ss_ep_comp_descriptor ss_ep_comp;
78 struct list_head urb_list; 66 struct list_head urb_list;
79 void *hcpriv; 67 void *hcpriv;
80 struct ep_device *ep_dev; /* For sysfs info */ 68 struct ep_device *ep_dev; /* For sysfs info */
81 struct usb_host_ss_ep_comp *ss_ep_comp; /* For SS devices */
82 69
83 unsigned char *extra; /* Extra descriptors */ 70 unsigned char *extra; /* Extra descriptors */
84 int extralen; 71 int extralen;
@@ -109,8 +96,8 @@ enum usb_interface_condition {
109/** 96/**
110 * struct usb_interface - what usb device drivers talk to 97 * struct usb_interface - what usb device drivers talk to
111 * @altsetting: array of interface structures, one for each alternate 98 * @altsetting: array of interface structures, one for each alternate
112 * setting that may be selected. Each one includes a set of 99 * setting that may be selected. Each one includes a set of
113 * endpoint configurations. They will be in no particular order. 100 * endpoint configurations. They will be in no particular order.
114 * @cur_altsetting: the current altsetting. 101 * @cur_altsetting: the current altsetting.
115 * @num_altsetting: number of altsettings defined. 102 * @num_altsetting: number of altsettings defined.
116 * @intf_assoc: interface association descriptor 103 * @intf_assoc: interface association descriptor
@@ -197,8 +184,6 @@ struct usb_interface {
197 struct work_struct reset_ws; /* for resets in atomic context */ 184 struct work_struct reset_ws; /* for resets in atomic context */
198}; 185};
199#define to_usb_interface(d) container_of(d, struct usb_interface, dev) 186#define to_usb_interface(d) container_of(d, struct usb_interface, dev)
200#define interface_to_usbdev(intf) \
201 container_of(intf->dev.parent, struct usb_device, dev)
202 187
203static inline void *usb_get_intfdata(struct usb_interface *intf) 188static inline void *usb_get_intfdata(struct usb_interface *intf)
204{ 189{
@@ -215,7 +200,7 @@ void usb_put_intf(struct usb_interface *intf);
215 200
216/* this maximum is arbitrary */ 201/* this maximum is arbitrary */
217#define USB_MAXINTERFACES 32 202#define USB_MAXINTERFACES 32
218#define USB_MAXIADS USB_MAXINTERFACES/2 203#define USB_MAXIADS (USB_MAXINTERFACES/2)
219 204
220/** 205/**
221 * struct usb_interface_cache - long-term representation of a device interface 206 * struct usb_interface_cache - long-term representation of a device interface
@@ -425,7 +410,6 @@ struct usb_tt;
425 * @connect_time: time device was first connected 410 * @connect_time: time device was first connected
426 * @do_remote_wakeup: remote wakeup should be enabled 411 * @do_remote_wakeup: remote wakeup should be enabled
427 * @reset_resume: needs reset instead of resume 412 * @reset_resume: needs reset instead of resume
428 * @autosuspend_disabled: autosuspend disabled by the user
429 * @wusb_dev: if this is a Wireless USB device, link to the WUSB 413 * @wusb_dev: if this is a Wireless USB device, link to the WUSB
430 * specific data for the device. 414 * specific data for the device.
431 * @slot_id: Slot ID assigned by xHCI 415 * @slot_id: Slot ID assigned by xHCI
@@ -436,7 +420,7 @@ struct usb_tt;
436 */ 420 */
437struct usb_device { 421struct usb_device {
438 int devnum; 422 int devnum;
439 char devpath [16]; 423 char devpath[16];
440 u32 route; 424 u32 route;
441 enum usb_device_state state; 425 enum usb_device_state state;
442 enum usb_device_speed speed; 426 enum usb_device_speed speed;
@@ -469,7 +453,7 @@ struct usb_device {
469 unsigned persist_enabled:1; 453 unsigned persist_enabled:1;
470 unsigned have_langid:1; 454 unsigned have_langid:1;
471 unsigned authorized:1; 455 unsigned authorized:1;
472 unsigned authenticated:1; 456 unsigned authenticated:1;
473 unsigned wusb:1; 457 unsigned wusb:1;
474 int string_langid; 458 int string_langid;
475 459
@@ -501,13 +485,17 @@ struct usb_device {
501 485
502 unsigned do_remote_wakeup:1; 486 unsigned do_remote_wakeup:1;
503 unsigned reset_resume:1; 487 unsigned reset_resume:1;
504 unsigned autosuspend_disabled:1;
505#endif 488#endif
506 struct wusb_dev *wusb_dev; 489 struct wusb_dev *wusb_dev;
507 int slot_id; 490 int slot_id;
508}; 491};
509#define to_usb_device(d) container_of(d, struct usb_device, dev) 492#define to_usb_device(d) container_of(d, struct usb_device, dev)
510 493
494static inline struct usb_device *interface_to_usbdev(struct usb_interface *intf)
495{
496 return to_usb_device(intf->dev.parent);
497}
498
511extern struct usb_device *usb_get_dev(struct usb_device *dev); 499extern struct usb_device *usb_get_dev(struct usb_device *dev);
512extern void usb_put_dev(struct usb_device *dev); 500extern void usb_put_dev(struct usb_device *dev);
513 501
@@ -522,12 +510,11 @@ extern int usb_lock_device_for_reset(struct usb_device *udev,
522extern int usb_reset_device(struct usb_device *dev); 510extern int usb_reset_device(struct usb_device *dev);
523extern void usb_queue_reset_device(struct usb_interface *dev); 511extern void usb_queue_reset_device(struct usb_interface *dev);
524 512
525extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id);
526 513
527/* USB autosuspend and autoresume */ 514/* USB autosuspend and autoresume */
528#ifdef CONFIG_USB_SUSPEND 515#ifdef CONFIG_USB_SUSPEND
529extern int usb_enable_autosuspend(struct usb_device *udev); 516extern void usb_enable_autosuspend(struct usb_device *udev);
530extern int usb_disable_autosuspend(struct usb_device *udev); 517extern void usb_disable_autosuspend(struct usb_device *udev);
531 518
532extern int usb_autopm_get_interface(struct usb_interface *intf); 519extern int usb_autopm_get_interface(struct usb_interface *intf);
533extern void usb_autopm_put_interface(struct usb_interface *intf); 520extern void usb_autopm_put_interface(struct usb_interface *intf);
@@ -572,6 +559,16 @@ static inline void usb_mark_last_busy(struct usb_device *udev)
572/* for drivers using iso endpoints */ 559/* for drivers using iso endpoints */
573extern int usb_get_current_frame_number(struct usb_device *usb_dev); 560extern int usb_get_current_frame_number(struct usb_device *usb_dev);
574 561
562/* Sets up a group of bulk endpoints to support multiple stream IDs. */
563extern int usb_alloc_streams(struct usb_interface *interface,
564 struct usb_host_endpoint **eps, unsigned int num_eps,
565 unsigned int num_streams, gfp_t mem_flags);
566
567/* Reverts a group of bulk endpoints back to not using stream IDs. */
568extern void usb_free_streams(struct usb_interface *interface,
569 struct usb_host_endpoint **eps, unsigned int num_eps,
570 gfp_t mem_flags);
571
575/* used these for multi-interface device registration */ 572/* used these for multi-interface device registration */
576extern int usb_driver_claim_interface(struct usb_driver *driver, 573extern int usb_driver_claim_interface(struct usb_driver *driver,
577 struct usb_interface *iface, void *priv); 574 struct usb_interface *iface, void *priv);
@@ -667,7 +664,7 @@ static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size)
667 * This macro is used to create a struct usb_device_id that matches a 664 * This macro is used to create a struct usb_device_id that matches a
668 * specific device. 665 * specific device.
669 */ 666 */
670#define USB_DEVICE(vend,prod) \ 667#define USB_DEVICE(vend, prod) \
671 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ 668 .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
672 .idVendor = (vend), \ 669 .idVendor = (vend), \
673 .idProduct = (prod) 670 .idProduct = (prod)
@@ -958,17 +955,25 @@ extern int usb_disabled(void);
958#define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame 955#define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame
959 * ignored */ 956 * ignored */
960#define URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */ 957#define URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */
961#define URB_NO_SETUP_DMA_MAP 0x0008 /* urb->setup_dma valid on submit */
962#define URB_NO_FSBR 0x0020 /* UHCI-specific */ 958#define URB_NO_FSBR 0x0020 /* UHCI-specific */
963#define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */ 959#define URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
964#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt 960#define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt
965 * needed */ 961 * needed */
966#define URB_FREE_BUFFER 0x0100 /* Free transfer buffer with the URB */ 962#define URB_FREE_BUFFER 0x0100 /* Free transfer buffer with the URB */
967 963
964/* The following flags are used internally by usbcore and HCDs */
968#define URB_DIR_IN 0x0200 /* Transfer from device to host */ 965#define URB_DIR_IN 0x0200 /* Transfer from device to host */
969#define URB_DIR_OUT 0 966#define URB_DIR_OUT 0
970#define URB_DIR_MASK URB_DIR_IN 967#define URB_DIR_MASK URB_DIR_IN
971 968
969#define URB_DMA_MAP_SINGLE 0x00010000 /* Non-scatter-gather mapping */
970#define URB_DMA_MAP_PAGE 0x00020000 /* HCD-unsupported S-G */
971#define URB_DMA_MAP_SG 0x00040000 /* HCD-supported S-G */
972#define URB_MAP_LOCAL 0x00080000 /* HCD-local-memory mapping */
973#define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */
974#define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */
975#define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */
976
972struct usb_iso_packet_descriptor { 977struct usb_iso_packet_descriptor {
973 unsigned int offset; 978 unsigned int offset;
974 unsigned int length; /* expected length */ 979 unsigned int length; /* expected length */
@@ -1045,12 +1050,8 @@ typedef void (*usb_complete_t)(struct urb *);
1045 * @setup_packet: Only used for control transfers, this points to eight bytes 1050 * @setup_packet: Only used for control transfers, this points to eight bytes
1046 * of setup data. Control transfers always start by sending this data 1051 * of setup data. Control transfers always start by sending this data
1047 * to the device. Then transfer_buffer is read or written, if needed. 1052 * to the device. Then transfer_buffer is read or written, if needed.
1048 * @setup_dma: For control transfers with URB_NO_SETUP_DMA_MAP set, the 1053 * @setup_dma: DMA pointer for the setup packet. The caller must not use
1049 * device driver has provided this DMA address for the setup packet. 1054 * this field; setup_packet must point to a valid buffer.
1050 * The host controller driver should use this in preference to
1051 * setup_packet, but the HCD may chose to ignore the address if it must
1052 * copy the setup packet into internal structures. Therefore, setup_packet
1053 * must always point to a valid buffer.
1054 * @start_frame: Returns the initial frame for isochronous transfers. 1055 * @start_frame: Returns the initial frame for isochronous transfers.
1055 * @number_of_packets: Lists the number of ISO transfer buffers. 1056 * @number_of_packets: Lists the number of ISO transfer buffers.
1056 * @interval: Specifies the polling interval for interrupt or isochronous 1057 * @interval: Specifies the polling interval for interrupt or isochronous
@@ -1082,13 +1083,14 @@ typedef void (*usb_complete_t)(struct urb *);
1082 * bounce buffer or talking to an IOMMU), 1083 * bounce buffer or talking to an IOMMU),
1083 * although they're cheap on commodity x86 and ppc hardware. 1084 * although they're cheap on commodity x86 and ppc hardware.
1084 * 1085 *
1085 * Alternatively, drivers may pass the URB_NO_xxx_DMA_MAP transfer flags, 1086 * Alternatively, drivers may pass the URB_NO_TRANSFER_DMA_MAP transfer flag,
1086 * which tell the host controller driver that no such mapping is needed since 1087 * which tells the host controller driver that no such mapping is needed for
1088 * the transfer_buffer since
1087 * the device driver is DMA-aware. For example, a device driver might 1089 * the device driver is DMA-aware. For example, a device driver might
1088 * allocate a DMA buffer with usb_alloc_coherent() or call usb_buffer_map(). 1090 * allocate a DMA buffer with usb_alloc_coherent() or call usb_buffer_map().
1089 * When these transfer flags are provided, host controller drivers will 1091 * When this transfer flag is provided, host controller drivers will
1090 * attempt to use the dma addresses found in the transfer_dma and/or 1092 * attempt to use the dma address found in the transfer_dma
1091 * setup_dma fields rather than determining a dma address themselves. 1093 * field rather than determining a dma address themselves.
1092 * 1094 *
1093 * Note that transfer_buffer must still be set if the controller 1095 * Note that transfer_buffer must still be set if the controller
1094 * does not support DMA (as indicated by bus.uses_dma) and when talking 1096 * does not support DMA (as indicated by bus.uses_dma) and when talking
@@ -1111,11 +1113,9 @@ typedef void (*usb_complete_t)(struct urb *);
1111 * should always terminate with a short packet, even if it means adding an 1113 * should always terminate with a short packet, even if it means adding an
1112 * extra zero length packet. 1114 * extra zero length packet.
1113 * 1115 *
1114 * Control URBs must provide a setup_packet. The setup_packet and 1116 * Control URBs must provide a valid pointer in the setup_packet field.
1115 * transfer_buffer may each be mapped for DMA or not, independently of 1117 * Unlike the transfer_buffer, the setup_packet may not be mapped for DMA
1116 * the other. The transfer_flags bits URB_NO_TRANSFER_DMA_MAP and 1118 * beforehand.
1117 * URB_NO_SETUP_DMA_MAP indicate which buffers have already been mapped.
1118 * URB_NO_SETUP_DMA_MAP is ignored for non-control URBs.
1119 * 1119 *
1120 * Interrupt URBs must provide an interval, saying how often (in milliseconds 1120 * Interrupt URBs must provide an interval, saying how often (in milliseconds
1121 * or, for highspeed devices, 125 microsecond units) 1121 * or, for highspeed devices, 125 microsecond units)
@@ -1186,14 +1186,15 @@ struct urb {
1186 * current owner */ 1186 * current owner */
1187 struct list_head anchor_list; /* the URB may be anchored */ 1187 struct list_head anchor_list; /* the URB may be anchored */
1188 struct usb_anchor *anchor; 1188 struct usb_anchor *anchor;
1189 struct usb_device *dev; /* (in) pointer to associated device */ 1189 struct usb_device *dev; /* (in) pointer to associated device */
1190 struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */ 1190 struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */
1191 unsigned int pipe; /* (in) pipe information */ 1191 unsigned int pipe; /* (in) pipe information */
1192 unsigned int stream_id; /* (in) stream ID */
1192 int status; /* (return) non-ISO status */ 1193 int status; /* (return) non-ISO status */
1193 unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ 1194 unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/
1194 void *transfer_buffer; /* (in) associated data buffer */ 1195 void *transfer_buffer; /* (in) associated data buffer */
1195 dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */ 1196 dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */
1196 struct usb_sg_request *sg; /* (in) scatter gather buffer list */ 1197 struct scatterlist *sg; /* (in) scatter gather buffer list */
1197 int num_sgs; /* (in) number of entries in the sg list */ 1198 int num_sgs; /* (in) number of entries in the sg list */
1198 u32 transfer_buffer_length; /* (in) data buffer length */ 1199 u32 transfer_buffer_length; /* (in) data buffer length */
1199 u32 actual_length; /* (return) actual transfer length */ 1200 u32 actual_length; /* (return) actual transfer length */
@@ -1371,18 +1372,6 @@ void *usb_alloc_coherent(struct usb_device *dev, size_t size,
1371void usb_free_coherent(struct usb_device *dev, size_t size, 1372void usb_free_coherent(struct usb_device *dev, size_t size,
1372 void *addr, dma_addr_t dma); 1373 void *addr, dma_addr_t dma);
1373 1374
1374/* Compatible macros while we switch over */
1375static inline void *usb_buffer_alloc(struct usb_device *dev, size_t size,
1376 gfp_t mem_flags, dma_addr_t *dma)
1377{
1378 return usb_alloc_coherent(dev, size, mem_flags, dma);
1379}
1380static inline void usb_buffer_free(struct usb_device *dev, size_t size,
1381 void *addr, dma_addr_t dma)
1382{
1383 return usb_free_coherent(dev, size, addr, dma);
1384}
1385
1386#if 0 1375#if 0
1387struct urb *usb_buffer_map(struct urb *urb); 1376struct urb *usb_buffer_map(struct urb *urb);
1388void usb_buffer_dmasync(struct urb *urb); 1377void usb_buffer_dmasync(struct urb *urb);
@@ -1467,8 +1456,6 @@ struct usb_sg_request {
1467 1456
1468 struct usb_device *dev; 1457 struct usb_device *dev;
1469 int pipe; 1458 int pipe;
1470 struct scatterlist *sg;
1471 int nents;
1472 1459
1473 int entries; 1460 int entries;
1474 struct urb **urbs; 1461 struct urb **urbs;
@@ -1536,23 +1523,31 @@ static inline unsigned int __create_pipe(struct usb_device *dev,
1536} 1523}
1537 1524
1538/* Create various pipes... */ 1525/* Create various pipes... */
1539#define usb_sndctrlpipe(dev,endpoint) \ 1526#define usb_sndctrlpipe(dev, endpoint) \
1540 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint)) 1527 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint))
1541#define usb_rcvctrlpipe(dev,endpoint) \ 1528#define usb_rcvctrlpipe(dev, endpoint) \
1542 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) 1529 ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1543#define usb_sndisocpipe(dev,endpoint) \ 1530#define usb_sndisocpipe(dev, endpoint) \
1544 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint)) 1531 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint))
1545#define usb_rcvisocpipe(dev,endpoint) \ 1532#define usb_rcvisocpipe(dev, endpoint) \
1546 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) 1533 ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1547#define usb_sndbulkpipe(dev,endpoint) \ 1534#define usb_sndbulkpipe(dev, endpoint) \
1548 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint)) 1535 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint))
1549#define usb_rcvbulkpipe(dev,endpoint) \ 1536#define usb_rcvbulkpipe(dev, endpoint) \
1550 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) 1537 ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1551#define usb_sndintpipe(dev,endpoint) \ 1538#define usb_sndintpipe(dev, endpoint) \
1552 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint)) 1539 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint))
1553#define usb_rcvintpipe(dev,endpoint) \ 1540#define usb_rcvintpipe(dev, endpoint) \
1554 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) 1541 ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN)
1555 1542
1543static inline struct usb_host_endpoint *
1544usb_pipe_endpoint(struct usb_device *dev, unsigned int pipe)
1545{
1546 struct usb_host_endpoint **eps;
1547 eps = usb_pipein(pipe) ? dev->ep_in : dev->ep_out;
1548 return eps[usb_pipeendpoint(pipe)];
1549}
1550
1556/*-------------------------------------------------------------------------*/ 1551/*-------------------------------------------------------------------------*/
1557 1552
1558static inline __u16 1553static inline __u16
diff --git a/include/linux/usb/Kbuild b/include/linux/usb/Kbuild
index 29fd73b0bffc..51410e0200cf 100644
--- a/include/linux/usb/Kbuild
+++ b/include/linux/usb/Kbuild
@@ -1,6 +1,7 @@
1header-y += audio.h 1header-y += audio.h
2header-y += cdc.h 2header-y += cdc.h
3header-y += ch9.h 3header-y += ch9.h
4header-y += ch11.h
4header-y += gadgetfs.h 5header-y += gadgetfs.h
5header-y += midi.h 6header-y += midi.h
6header-y += g_printer.h 7header-y += g_printer.h
diff --git a/include/linux/usb/atmel_usba_udc.h b/include/linux/usb/atmel_usba_udc.h
index baf41c8616e9..ba99af275a31 100644
--- a/include/linux/usb/atmel_usba_udc.h
+++ b/include/linux/usb/atmel_usba_udc.h
@@ -15,7 +15,7 @@ struct usba_ep_data {
15 15
16struct usba_platform_data { 16struct usba_platform_data {
17 int vbus_pin; 17 int vbus_pin;
18 int vbus_pin_inverted; 18 int vbus_pin_inverted;
19 int num_ep; 19 int num_ep;
20 struct usba_ep_data ep[0]; 20 struct usba_ep_data ep[0];
21}; 21};
diff --git a/include/linux/usb/audio.h b/include/linux/usb/audio.h
index c0ef18dc2da7..5d646c388752 100644
--- a/include/linux/usb/audio.h
+++ b/include/linux/usb/audio.h
@@ -101,7 +101,7 @@ struct uac_ac_header_descriptor_v1 {
101#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n)) 101#define UAC_DT_AC_HEADER_SIZE(n) (8 + (n))
102 102
103/* As above, but more useful for defining your own descriptors: */ 103/* As above, but more useful for defining your own descriptors: */
104#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \ 104#define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \
105struct uac_ac_header_descriptor_v1_##n { \ 105struct uac_ac_header_descriptor_v1_##n { \
106 __u8 bLength; \ 106 __u8 bLength; \
107 __u8 bDescriptorType; \ 107 __u8 bDescriptorType; \
@@ -169,7 +169,7 @@ struct uac_output_terminal_descriptor_v1 {
169#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) 169#define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2)
170 170
171/* As above, but more useful for defining your own descriptors: */ 171/* As above, but more useful for defining your own descriptors: */
172#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \ 172#define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \
173struct uac_feature_unit_descriptor_##ch { \ 173struct uac_feature_unit_descriptor_##ch { \
174 __u8 bLength; \ 174 __u8 bLength; \
175 __u8 bDescriptorType; \ 175 __u8 bDescriptorType; \
@@ -378,7 +378,7 @@ struct uac_format_type_i_discrete_descriptor {
378 __u8 tSamFreq[][3]; 378 __u8 tSamFreq[][3];
379} __attribute__ ((packed)); 379} __attribute__ ((packed));
380 380
381#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \ 381#define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \
382struct uac_format_type_i_discrete_descriptor_##n { \ 382struct uac_format_type_i_discrete_descriptor_##n { \
383 __u8 bLength; \ 383 __u8 bLength; \
384 __u8 bDescriptorType; \ 384 __u8 bDescriptorType; \
diff --git a/include/linux/usb/cdc.h b/include/linux/usb/cdc.h
index c24124a42ce5..c117a68d04a7 100644
--- a/include/linux/usb/cdc.h
+++ b/include/linux/usb/cdc.h
@@ -18,6 +18,7 @@
18#define USB_CDC_SUBCLASS_MDLM 0x0a 18#define USB_CDC_SUBCLASS_MDLM 0x0a
19#define USB_CDC_SUBCLASS_OBEX 0x0b 19#define USB_CDC_SUBCLASS_OBEX 0x0b
20#define USB_CDC_SUBCLASS_EEM 0x0c 20#define USB_CDC_SUBCLASS_EEM 0x0c
21#define USB_CDC_SUBCLASS_NCM 0x0d
21 22
22#define USB_CDC_PROTO_NONE 0 23#define USB_CDC_PROTO_NONE 0
23 24
@@ -49,6 +50,7 @@
49#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */ 50#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */
50#define USB_CDC_DMM_TYPE 0x14 51#define USB_CDC_DMM_TYPE 0x14
51#define USB_CDC_OBEX_TYPE 0x15 52#define USB_CDC_OBEX_TYPE 0x15
53#define USB_CDC_NCM_TYPE 0x1a
52 54
53/* "Header Functional Descriptor" from CDC spec 5.2.3.1 */ 55/* "Header Functional Descriptor" from CDC spec 5.2.3.1 */
54struct usb_cdc_header_desc { 56struct usb_cdc_header_desc {
@@ -174,6 +176,15 @@ struct usb_cdc_obex_desc {
174 __le16 bcdVersion; 176 __le16 bcdVersion;
175} __attribute__ ((packed)); 177} __attribute__ ((packed));
176 178
179/* "NCM Control Model Functional Descriptor" */
180struct usb_cdc_ncm_desc {
181 __u8 bLength;
182 __u8 bDescriptorType;
183 __u8 bDescriptorSubType;
184
185 __le16 bcdNcmVersion;
186 __u8 bmNetworkCapabilities;
187} __attribute__ ((packed));
177/*-------------------------------------------------------------------------*/ 188/*-------------------------------------------------------------------------*/
178 189
179/* 190/*
@@ -197,6 +208,17 @@ struct usb_cdc_obex_desc {
197#define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42 208#define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42
198#define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43 209#define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43
199#define USB_CDC_GET_ETHERNET_STATISTIC 0x44 210#define USB_CDC_GET_ETHERNET_STATISTIC 0x44
211#define USB_CDC_GET_NTB_PARAMETERS 0x80
212#define USB_CDC_GET_NET_ADDRESS 0x81
213#define USB_CDC_SET_NET_ADDRESS 0x82
214#define USB_CDC_GET_NTB_FORMAT 0x83
215#define USB_CDC_SET_NTB_FORMAT 0x84
216#define USB_CDC_GET_NTB_INPUT_SIZE 0x85
217#define USB_CDC_SET_NTB_INPUT_SIZE 0x86
218#define USB_CDC_GET_MAX_DATAGRAM_SIZE 0x87
219#define USB_CDC_SET_MAX_DATAGRAM_SIZE 0x88
220#define USB_CDC_GET_CRC_MODE 0x89
221#define USB_CDC_SET_CRC_MODE 0x8a
200 222
201/* Line Coding Structure from CDC spec 6.2.13 */ 223/* Line Coding Structure from CDC spec 6.2.13 */
202struct usb_cdc_line_coding { 224struct usb_cdc_line_coding {
@@ -247,4 +269,76 @@ struct usb_cdc_notification {
247 __le16 wLength; 269 __le16 wLength;
248} __attribute__ ((packed)); 270} __attribute__ ((packed));
249 271
272/*-------------------------------------------------------------------------*/
273
274/*
275 * Class Specific structures and constants
276 *
277 * CDC NCM parameter structure, CDC NCM subclass 6.2.1
278 *
279 */
280
281struct usb_cdc_ncm_ntb_parameter {
282 __le16 wLength;
283 __le16 bmNtbFormatSupported;
284 __le32 dwNtbInMaxSize;
285 __le16 wNdpInDivisor;
286 __le16 wNdpInPayloadRemainder;
287 __le16 wNdpInAlignment;
288 __le16 wPadding1;
289 __le32 dwNtbOutMaxSize;
290 __le16 wNdpOutDivisor;
291 __le16 wNdpOutPayloadRemainder;
292 __le16 wNdpOutAlignment;
293 __le16 wPadding2;
294} __attribute__ ((packed));
295
296/*
297 * CDC NCM transfer headers, CDC NCM subclass 3.2
298 */
299
300#define NCM_NTH16_SIGN 0x484D434E /* NCMH */
301#define NCM_NTH32_SIGN 0x686D636E /* ncmh */
302
303struct usb_cdc_ncm_nth16 {
304 __le32 dwSignature;
305 __le16 wHeaderLength;
306 __le16 wSequence;
307 __le16 wBlockLength;
308 __le16 wFpIndex;
309} __attribute__ ((packed));
310
311struct usb_cdc_ncm_nth32 {
312 __le32 dwSignature;
313 __le16 wHeaderLength;
314 __le16 wSequence;
315 __le32 dwBlockLength;
316 __le32 dwFpIndex;
317} __attribute__ ((packed));
318
319/*
320 * CDC NCM datagram pointers, CDC NCM subclass 3.3
321 */
322
323#define NCM_NDP16_CRC_SIGN 0x314D434E /* NCM1 */
324#define NCM_NDP16_NOCRC_SIGN 0x304D434E /* NCM0 */
325#define NCM_NDP32_CRC_SIGN 0x316D636E /* ncm1 */
326#define NCM_NDP32_NOCRC_SIGN 0x306D636E /* ncm0 */
327
328struct usb_cdc_ncm_ndp16 {
329 __le32 dwSignature;
330 __le16 wLength;
331 __le16 wNextFpIndex;
332 __u8 data[0];
333} __attribute__ ((packed));
334
335struct usb_cdc_ncm_ndp32 {
336 __le32 dwSignature;
337 __le16 wLength;
338 __le16 wReserved6;
339 __le32 dwNextFpIndex;
340 __le32 dwReserved12;
341 __u8 data[0];
342} __attribute__ ((packed));
343
250#endif /* __LINUX_USB_CDC_H */ 344#endif /* __LINUX_USB_CDC_H */
diff --git a/drivers/usb/core/hub.h b/include/linux/usb/ch11.h
index de8081f065ed..119194c85d10 100644
--- a/drivers/usb/core/hub.h
+++ b/include/linux/usb/ch11.h
@@ -1,16 +1,15 @@
1#ifndef __LINUX_HUB_H
2#define __LINUX_HUB_H
3
4/* 1/*
5 * Hub protocol and driver data structures. 2 * This file holds Hub protocol constants and data structures that are
3 * defined in chapter 11 (Hub Specification) of the USB 2.0 specification.
6 * 4 *
7 * Some of these are known to the "virtual root hub" code 5 * It is used/shared between the USB core, the HCDs and couple of other USB
8 * in host controller drivers. 6 * drivers.
9 */ 7 */
10 8
11#include <linux/list.h> 9#ifndef __LINUX_CH11_H
12#include <linux/workqueue.h> 10#define __LINUX_CH11_H
13#include <linux/compiler.h> /* likely()/unlikely() */ 11
12#include <linux/types.h> /* __u8 etc */
14 13
15/* 14/*
16 * Hub request types 15 * Hub request types
@@ -46,11 +45,7 @@
46#define USB_PORT_FEAT_RESET 4 45#define USB_PORT_FEAT_RESET 4
47#define USB_PORT_FEAT_L1 5 /* L1 suspend */ 46#define USB_PORT_FEAT_L1 5 /* L1 suspend */
48#define USB_PORT_FEAT_POWER 8 47#define USB_PORT_FEAT_POWER 8
49#define USB_PORT_FEAT_LOWSPEED 9 48#define USB_PORT_FEAT_LOWSPEED 9 /* Should never be used */
50/* This value was never in Table 11-17 */
51#define USB_PORT_FEAT_HIGHSPEED 10
52/* This value is also fake */
53#define USB_PORT_FEAT_SUPERSPEED 11
54#define USB_PORT_FEAT_C_CONNECTION 16 49#define USB_PORT_FEAT_C_CONNECTION 16
55#define USB_PORT_FEAT_C_ENABLE 17 50#define USB_PORT_FEAT_C_ENABLE 17
56#define USB_PORT_FEAT_C_SUSPEND 18 51#define USB_PORT_FEAT_C_SUSPEND 18
@@ -86,6 +81,7 @@ struct usb_port_status {
86#define USB_PORT_STAT_TEST 0x0800 81#define USB_PORT_STAT_TEST 0x0800
87#define USB_PORT_STAT_INDICATOR 0x1000 82#define USB_PORT_STAT_INDICATOR 0x1000
88/* bits 13 to 15 are reserved */ 83/* bits 13 to 15 are reserved */
84#define USB_PORT_STAT_SUPER_SPEED 0x8000 /* Linux-internal */
89 85
90/* 86/*
91 * wPortChange bit field 87 * wPortChange bit field
@@ -162,44 +158,10 @@ enum hub_led_mode {
162 INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF 158 INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF
163} __attribute__ ((packed)); 159} __attribute__ ((packed));
164 160
165struct usb_device;
166
167/* Transaction Translator Think Times, in bits */ 161/* Transaction Translator Think Times, in bits */
168#define HUB_TTTT_8_BITS 0x00 162#define HUB_TTTT_8_BITS 0x00
169#define HUB_TTTT_16_BITS 0x20 163#define HUB_TTTT_16_BITS 0x20
170#define HUB_TTTT_24_BITS 0x40 164#define HUB_TTTT_24_BITS 0x40
171#define HUB_TTTT_32_BITS 0x60 165#define HUB_TTTT_32_BITS 0x60
172 166
173/* 167#endif /* __LINUX_CH11_H */
174 * As of USB 2.0, full/low speed devices are segregated into trees.
175 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
176 * The other type grows from high speed hubs when they connect to
177 * full/low speed devices using "Transaction Translators" (TTs).
178 *
179 * TTs should only be known to the hub driver, and high speed bus
180 * drivers (only EHCI for now). They affect periodic scheduling and
181 * sometimes control/bulk error recovery.
182 */
183struct usb_tt {
184 struct usb_device *hub; /* upstream highspeed hub */
185 int multi; /* true means one TT per port */
186 unsigned think_time; /* think time in ns */
187
188 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
189 spinlock_t lock;
190 struct list_head clear_list; /* of usb_tt_clear */
191 struct work_struct clear_work;
192};
193
194struct usb_tt_clear {
195 struct list_head clear_list;
196 unsigned tt;
197 u16 devinfo;
198 struct usb_hcd *hcd;
199 struct usb_host_endpoint *ep;
200};
201
202extern int usb_hub_clear_tt_buffer(struct urb *urb);
203extern void usb_ep0_reinit(struct usb_device *);
204
205#endif /* __LINUX_HUB_H */
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index e58369ff8168..da2ed77d3e8d 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -191,6 +191,8 @@ struct usb_ctrlrequest {
191#define USB_DT_WIRE_ADAPTER 0x21 191#define USB_DT_WIRE_ADAPTER 0x21
192#define USB_DT_RPIPE 0x22 192#define USB_DT_RPIPE 0x22
193#define USB_DT_CS_RADIO_CONTROL 0x23 193#define USB_DT_CS_RADIO_CONTROL 0x23
194/* From the T10 UAS specification */
195#define USB_DT_PIPE_USAGE 0x24
194/* From the USB 3.0 spec */ 196/* From the USB 3.0 spec */
195#define USB_DT_SS_ENDPOINT_COMP 0x30 197#define USB_DT_SS_ENDPOINT_COMP 0x30
196 198
@@ -475,7 +477,7 @@ static inline int usb_endpoint_xfer_isoc(
475static inline int usb_endpoint_is_bulk_in( 477static inline int usb_endpoint_is_bulk_in(
476 const struct usb_endpoint_descriptor *epd) 478 const struct usb_endpoint_descriptor *epd)
477{ 479{
478 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd)); 480 return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
479} 481}
480 482
481/** 483/**
@@ -488,7 +490,7 @@ static inline int usb_endpoint_is_bulk_in(
488static inline int usb_endpoint_is_bulk_out( 490static inline int usb_endpoint_is_bulk_out(
489 const struct usb_endpoint_descriptor *epd) 491 const struct usb_endpoint_descriptor *epd)
490{ 492{
491 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd)); 493 return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
492} 494}
493 495
494/** 496/**
@@ -501,7 +503,7 @@ static inline int usb_endpoint_is_bulk_out(
501static inline int usb_endpoint_is_int_in( 503static inline int usb_endpoint_is_int_in(
502 const struct usb_endpoint_descriptor *epd) 504 const struct usb_endpoint_descriptor *epd)
503{ 505{
504 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd)); 506 return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
505} 507}
506 508
507/** 509/**
@@ -514,7 +516,7 @@ static inline int usb_endpoint_is_int_in(
514static inline int usb_endpoint_is_int_out( 516static inline int usb_endpoint_is_int_out(
515 const struct usb_endpoint_descriptor *epd) 517 const struct usb_endpoint_descriptor *epd)
516{ 518{
517 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd)); 519 return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd);
518} 520}
519 521
520/** 522/**
@@ -527,7 +529,7 @@ static inline int usb_endpoint_is_int_out(
527static inline int usb_endpoint_is_isoc_in( 529static inline int usb_endpoint_is_isoc_in(
528 const struct usb_endpoint_descriptor *epd) 530 const struct usb_endpoint_descriptor *epd)
529{ 531{
530 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd)); 532 return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd);
531} 533}
532 534
533/** 535/**
@@ -540,7 +542,7 @@ static inline int usb_endpoint_is_isoc_in(
540static inline int usb_endpoint_is_isoc_out( 542static inline int usb_endpoint_is_isoc_out(
541 const struct usb_endpoint_descriptor *epd) 543 const struct usb_endpoint_descriptor *epd)
542{ 544{
543 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd)); 545 return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
544} 546}
545 547
546/*-------------------------------------------------------------------------*/ 548/*-------------------------------------------------------------------------*/
@@ -556,6 +558,8 @@ struct usb_ss_ep_comp_descriptor {
556} __attribute__ ((packed)); 558} __attribute__ ((packed));
557 559
558#define USB_DT_SS_EP_COMP_SIZE 6 560#define USB_DT_SS_EP_COMP_SIZE 6
561/* Bits 4:0 of bmAttributes if this is a bulk endpoint */
562#define USB_SS_MAX_STREAMS(p) (1 << (p & 0x1f))
559 563
560/*-------------------------------------------------------------------------*/ 564/*-------------------------------------------------------------------------*/
561 565
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 738ea1a691cb..139353efad34 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -326,6 +326,7 @@ struct usb_composite_dev {
326 326
327 /* private: */ 327 /* private: */
328 /* internals */ 328 /* internals */
329 unsigned int suspended:1;
329 struct usb_device_descriptor desc; 330 struct usb_device_descriptor desc;
330 struct list_head configs; 331 struct list_head configs;
331 struct usb_composite_driver *driver; 332 struct usb_composite_driver *driver;
diff --git a/include/linux/usb/ehci_def.h b/include/linux/usb/ehci_def.h
index af4b86f3aca3..80287af2a738 100644
--- a/include/linux/usb/ehci_def.h
+++ b/include/linux/usb/ehci_def.h
@@ -45,7 +45,7 @@ struct ehci_caps {
45#define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */ 45#define HCC_CANPARK(p) ((p)&(1 << 2)) /* true: can park on async qh */
46#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/ 46#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1)) /* true: periodic_size changes*/
47#define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */ 47#define HCC_64BIT_ADDR(p) ((p)&(1)) /* true: can use 64-bit addr */
48 u8 portroute [8]; /* nibbles for routing - offset 0xC */ 48 u8 portroute[8]; /* nibbles for routing - offset 0xC */
49} __attribute__ ((packed)); 49} __attribute__ ((packed));
50 50
51 51
@@ -92,14 +92,14 @@ struct ehci_regs {
92 /* ASYNCLISTADDR: offset 0x18 */ 92 /* ASYNCLISTADDR: offset 0x18 */
93 u32 async_next; /* address of next async queue head */ 93 u32 async_next; /* address of next async queue head */
94 94
95 u32 reserved [9]; 95 u32 reserved[9];
96 96
97 /* CONFIGFLAG: offset 0x40 */ 97 /* CONFIGFLAG: offset 0x40 */
98 u32 configured_flag; 98 u32 configured_flag;
99#define FLAG_CF (1<<0) /* true: we'll support "high speed" */ 99#define FLAG_CF (1<<0) /* true: we'll support "high speed" */
100 100
101 /* PORTSC: offset 0x44 */ 101 /* PORTSC: offset 0x44 */
102 u32 port_status [0]; /* up to N_PORTS */ 102 u32 port_status[0]; /* up to N_PORTS */
103/* 31:23 reserved */ 103/* 31:23 reserved */
104#define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */ 104#define PORT_WKOC_E (1<<22) /* wake on overcurrent (enable) */
105#define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */ 105#define PORT_WKDISC_E (1<<21) /* wake on disconnect (enable) */
diff --git a/include/linux/usb/functionfs.h b/include/linux/usb/functionfs.h
new file mode 100644
index 000000000000..a34a2a043b21
--- /dev/null
+++ b/include/linux/usb/functionfs.h
@@ -0,0 +1,199 @@
1#ifndef __LINUX_FUNCTIONFS_H__
2#define __LINUX_FUNCTIONFS_H__ 1
3
4
5#include <linux/types.h>
6#include <linux/ioctl.h>
7
8#include <linux/usb/ch9.h>
9
10
11enum {
12 FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13 FUNCTIONFS_STRINGS_MAGIC = 2
14};
15
16
17#ifndef __KERNEL__
18
19/* Descriptor of an non-audio endpoint */
20struct usb_endpoint_descriptor_no_audio {
21 __u8 bLength;
22 __u8 bDescriptorType;
23
24 __u8 bEndpointAddress;
25 __u8 bmAttributes;
26 __le16 wMaxPacketSize;
27 __u8 bInterval;
28} __attribute__((packed));
29
30
31/*
32 * All numbers must be in little endian order.
33 */
34
35struct usb_functionfs_descs_head {
36 __le32 magic;
37 __le32 length;
38 __le32 fs_count;
39 __le32 hs_count;
40} __attribute__((packed));
41
42/*
43 * Descriptors format:
44 *
45 * | off | name | type | description |
46 * |-----+-----------+--------------+--------------------------------------|
47 * | 0 | magic | LE32 | FUNCTIONFS_{FS,HS}_DESCRIPTORS_MAGIC |
48 * | 4 | lenght | LE32 | length of the whole data chunk |
49 * | 8 | fs_count | LE32 | number of full-speed descriptors |
50 * | 12 | hs_count | LE32 | number of high-speed descriptors |
51 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
52 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
53 *
54 * descs are just valid USB descriptors and have the following format:
55 *
56 * | off | name | type | description |
57 * |-----+-----------------+------+--------------------------|
58 * | 0 | bLength | U8 | length of the descriptor |
59 * | 1 | bDescriptorType | U8 | descriptor type |
60 * | 2 | payload | | descriptor's payload |
61 */
62
63struct usb_functionfs_strings_head {
64 __le32 magic;
65 __le32 length;
66 __le32 str_count;
67 __le32 lang_count;
68} __attribute__((packed));
69
70/*
71 * Strings format:
72 *
73 * | off | name | type | description |
74 * |-----+------------+-----------------------+----------------------------|
75 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
76 * | 4 | length | LE32 | length of the data chunk |
77 * | 8 | str_count | LE32 | number of strings |
78 * | 12 | lang_count | LE32 | number of languages |
79 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
80 *
81 * For each language there is one stringtab entry (ie. there are lang_count
82 * stringtab entires). Each StringTab has following format:
83 *
84 * | off | name | type | description |
85 * |-----+---------+-------------------+------------------------------------|
86 * | 0 | lang | LE16 | language code |
87 * | 2 | strings | String[str_count] | array of strings in given language |
88 *
89 * For each string ther is one strings entry (ie. there are str_count
90 * string entries). Each String is a NUL terminated string encoded in
91 * UTF-8.
92 */
93
94#endif
95
96
97/*
98 * Events are delivered on the ep0 file descriptor, when the user mode driver
99 * reads from this file descriptor after writing the descriptors. Don't
100 * stop polling this descriptor.
101 */
102
103enum usb_functionfs_event_type {
104 FUNCTIONFS_BIND,
105 FUNCTIONFS_UNBIND,
106
107 FUNCTIONFS_ENABLE,
108 FUNCTIONFS_DISABLE,
109
110 FUNCTIONFS_SETUP,
111
112 FUNCTIONFS_SUSPEND,
113 FUNCTIONFS_RESUME
114};
115
116/* NOTE: this structure must stay the same size and layout on
117 * both 32-bit and 64-bit kernels.
118 */
119struct usb_functionfs_event {
120 union {
121 /* SETUP: packet; DATA phase i/o precedes next event
122 *(setup.bmRequestType & USB_DIR_IN) flags direction */
123 struct usb_ctrlrequest setup;
124 } __attribute__((packed)) u;
125
126 /* enum usb_functionfs_event_type */
127 __u8 type;
128 __u8 _pad[3];
129} __attribute__((packed));
130
131
132/* Endpoint ioctls */
133/* The same as in gadgetfs */
134
135/* IN transfers may be reported to the gadget driver as complete
136 * when the fifo is loaded, before the host reads the data;
137 * OUT transfers may be reported to the host's "client" driver as
138 * complete when they're sitting in the FIFO unread.
139 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
140 * (needed for precise fault handling, when the hardware allows it)
141 */
142#define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
143
144/* discards any unclaimed data in the fifo. */
145#define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
146
147/* resets endpoint halt+toggle; used to implement set_interface.
148 * some hardware (like pxa2xx) can't support this.
149 */
150#define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
151
152/* Specific for functionfs */
153
154/*
155 * Returns reverse mapping of an interface. Called on EP0. If there
156 * is no such interface returns -EDOM. If function is not active
157 * returns -ENODEV.
158 */
159#define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
160
161/*
162 * Returns real bEndpointAddress of an endpoint. If function is not
163 * active returns -ENODEV.
164 */
165#define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
166
167
168#ifdef __KERNEL__
169
170struct ffs_data;
171struct usb_composite_dev;
172struct usb_configuration;
173
174
175static int functionfs_init(void) __attribute__((warn_unused_result));
176static void functionfs_cleanup(void);
177
178static int functionfs_bind(struct ffs_data *ffs, struct usb_composite_dev *cdev)
179 __attribute__((warn_unused_result, nonnull));
180static void functionfs_unbind(struct ffs_data *ffs)
181 __attribute__((nonnull));
182
183static int functionfs_add(struct usb_composite_dev *cdev,
184 struct usb_configuration *c,
185 struct ffs_data *ffs)
186 __attribute__((warn_unused_result, nonnull));
187
188
189static int functionfs_ready_callback(struct ffs_data *ffs)
190 __attribute__((warn_unused_result, nonnull));
191static void functionfs_closed_callback(struct ffs_data *ffs)
192 __attribute__((nonnull));
193static int functionfs_check_dev_callback(const char *dev_name)
194 __attribute__((warn_unused_result, nonnull));
195
196
197#endif
198
199#endif
diff --git a/include/linux/usb/g_hid.h b/include/linux/usb/g_hid.h
new file mode 100644
index 000000000000..50f5745df28c
--- /dev/null
+++ b/include/linux/usb/g_hid.h
@@ -0,0 +1,32 @@
1/*
2 * g_hid.h -- Header file for USB HID gadget driver
3 *
4 * Copyright (C) 2010 Fabien Chouteau <fabien.chouteau@barco.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __LINUX_USB_G_HID_H
22#define __LINUX_USB_G_HID_H
23
24struct hidg_func_descriptor {
25 unsigned char subclass;
26 unsigned char protocol;
27 unsigned short report_length;
28 unsigned short report_desc_length;
29 unsigned char report_desc[];
30};
31
32#endif /* __LINUX_USB_G_HID_H */
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index f4b7ca516cdd..d3ef42d7d2f0 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -494,9 +494,13 @@ static inline void set_gadget_data(struct usb_gadget *gadget, void *data)
494 { dev_set_drvdata(&gadget->dev, data); } 494 { dev_set_drvdata(&gadget->dev, data); }
495static inline void *get_gadget_data(struct usb_gadget *gadget) 495static inline void *get_gadget_data(struct usb_gadget *gadget)
496 { return dev_get_drvdata(&gadget->dev); } 496 { return dev_get_drvdata(&gadget->dev); }
497static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev)
498{
499 return container_of(dev, struct usb_gadget, dev);
500}
497 501
498/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ 502/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */
499#define gadget_for_each_ep(tmp,gadget) \ 503#define gadget_for_each_ep(tmp, gadget) \
500 list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) 504 list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)
501 505
502 506
diff --git a/include/linux/usb/gadgetfs.h b/include/linux/usb/gadgetfs.h
index 612102e4d75e..0bb12e0d4f8f 100644
--- a/include/linux/usb/gadgetfs.h
+++ b/include/linux/usb/gadgetfs.h
@@ -19,7 +19,7 @@
19#define __LINUX_USB_GADGETFS_H 19#define __LINUX_USB_GADGETFS_H
20 20
21#include <linux/types.h> 21#include <linux/types.h>
22#include <asm/ioctl.h> 22#include <linux/ioctl.h>
23 23
24#include <linux/usb/ch9.h> 24#include <linux/usb/ch9.h>
25 25
diff --git a/drivers/usb/core/hcd.h b/include/linux/usb/hcd.h
index a3cdb09734ab..2e3a4ea1a3da 100644
--- a/drivers/usb/core/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -126,7 +126,7 @@ struct usb_hcd {
126 126
127 127
128#define HCD_BUFFER_POOLS 4 128#define HCD_BUFFER_POOLS 4
129 struct dma_pool *pool [HCD_BUFFER_POOLS]; 129 struct dma_pool *pool[HCD_BUFFER_POOLS];
130 130
131 int state; 131 int state;
132# define __ACTIVE 0x01 132# define __ACTIVE 0x01
@@ -219,12 +219,12 @@ struct hc_driver {
219 struct urb *urb, int status); 219 struct urb *urb, int status);
220 220
221 /* hw synch, freeing endpoint resources that urb_dequeue can't */ 221 /* hw synch, freeing endpoint resources that urb_dequeue can't */
222 void (*endpoint_disable)(struct usb_hcd *hcd, 222 void (*endpoint_disable)(struct usb_hcd *hcd,
223 struct usb_host_endpoint *ep); 223 struct usb_host_endpoint *ep);
224 224
225 /* (optional) reset any endpoint state such as sequence number 225 /* (optional) reset any endpoint state such as sequence number
226 and current window */ 226 and current window */
227 void (*endpoint_reset)(struct usb_hcd *hcd, 227 void (*endpoint_reset)(struct usb_hcd *hcd,
228 struct usb_host_endpoint *ep); 228 struct usb_host_endpoint *ep);
229 229
230 /* root hub support */ 230 /* root hub support */
@@ -250,21 +250,33 @@ struct hc_driver {
250 int (*alloc_dev)(struct usb_hcd *, struct usb_device *); 250 int (*alloc_dev)(struct usb_hcd *, struct usb_device *);
251 /* Called by usb_disconnect to free HC device structures */ 251 /* Called by usb_disconnect to free HC device structures */
252 void (*free_dev)(struct usb_hcd *, struct usb_device *); 252 void (*free_dev)(struct usb_hcd *, struct usb_device *);
253 /* Change a group of bulk endpoints to support multiple stream IDs */
254 int (*alloc_streams)(struct usb_hcd *hcd, struct usb_device *udev,
255 struct usb_host_endpoint **eps, unsigned int num_eps,
256 unsigned int num_streams, gfp_t mem_flags);
257 /* Reverts a group of bulk endpoints back to not using stream IDs.
258 * Can fail if we run out of memory.
259 */
260 int (*free_streams)(struct usb_hcd *hcd, struct usb_device *udev,
261 struct usb_host_endpoint **eps, unsigned int num_eps,
262 gfp_t mem_flags);
253 263
254 /* Bandwidth computation functions */ 264 /* Bandwidth computation functions */
255 /* Note that add_endpoint() can only be called once per endpoint before 265 /* Note that add_endpoint() can only be called once per endpoint before
256 * check_bandwidth() or reset_bandwidth() must be called. 266 * check_bandwidth() or reset_bandwidth() must be called.
257 * drop_endpoint() can only be called once per endpoint also. 267 * drop_endpoint() can only be called once per endpoint also.
258 * A call to xhci_drop_endpoint() followed by a call to xhci_add_endpoint() will 268 * A call to xhci_drop_endpoint() followed by a call to
259 * add the endpoint to the schedule with possibly new parameters denoted by a 269 * xhci_add_endpoint() will add the endpoint to the schedule with
260 * different endpoint descriptor in usb_host_endpoint. 270 * possibly new parameters denoted by a different endpoint descriptor
261 * A call to xhci_add_endpoint() followed by a call to xhci_drop_endpoint() is 271 * in usb_host_endpoint. A call to xhci_add_endpoint() followed by a
262 * not allowed. 272 * call to xhci_drop_endpoint() is not allowed.
263 */ 273 */
264 /* Allocate endpoint resources and add them to a new schedule */ 274 /* Allocate endpoint resources and add them to a new schedule */
265 int (*add_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *); 275 int (*add_endpoint)(struct usb_hcd *, struct usb_device *,
276 struct usb_host_endpoint *);
266 /* Drop an endpoint from a new schedule */ 277 /* Drop an endpoint from a new schedule */
267 int (*drop_endpoint)(struct usb_hcd *, struct usb_device *, struct usb_host_endpoint *); 278 int (*drop_endpoint)(struct usb_hcd *, struct usb_device *,
279 struct usb_host_endpoint *);
268 /* Check that a new hardware configuration, set using 280 /* Check that a new hardware configuration, set using
269 * endpoint_enable and endpoint_disable, does not exceed bus 281 * endpoint_enable and endpoint_disable, does not exceed bus
270 * bandwidth. This must be called before any set configuration 282 * bandwidth. This must be called before any set configuration
@@ -374,7 +386,42 @@ extern void usb_destroy_configuration(struct usb_device *dev);
374 * HCD Root Hub support 386 * HCD Root Hub support
375 */ 387 */
376 388
377#include "hub.h" 389#include <linux/usb/ch11.h>
390
391/*
392 * As of USB 2.0, full/low speed devices are segregated into trees.
393 * One type grows from USB 1.1 host controllers (OHCI, UHCI etc).
394 * The other type grows from high speed hubs when they connect to
395 * full/low speed devices using "Transaction Translators" (TTs).
396 *
397 * TTs should only be known to the hub driver, and high speed bus
398 * drivers (only EHCI for now). They affect periodic scheduling and
399 * sometimes control/bulk error recovery.
400 */
401
402struct usb_device;
403
404struct usb_tt {
405 struct usb_device *hub; /* upstream highspeed hub */
406 int multi; /* true means one TT per port */
407 unsigned think_time; /* think time in ns */
408
409 /* for control/bulk error recovery (CLEAR_TT_BUFFER) */
410 spinlock_t lock;
411 struct list_head clear_list; /* of usb_tt_clear */
412 struct work_struct clear_work;
413};
414
415struct usb_tt_clear {
416 struct list_head clear_list;
417 unsigned tt;
418 u16 devinfo;
419 struct usb_hcd *hcd;
420 struct usb_host_endpoint *ep;
421};
422
423extern int usb_hub_clear_tt_buffer(struct urb *urb);
424extern void usb_ep0_reinit(struct usb_device *);
378 425
379/* (shifted) direction/type/recipient from the USB 2.0 spec, table 9.2 */ 426/* (shifted) direction/type/recipient from the USB 2.0 spec, table 9.2 */
380#define DeviceRequest \ 427#define DeviceRequest \
@@ -439,8 +486,8 @@ extern void usb_destroy_configuration(struct usb_device *dev);
439#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \ 486#define HS_NSECS_ISO(bytes) (((38 * 8 * 2083) \
440 + (2083UL * (3 + BitTime(bytes))))/1000 \ 487 + (2083UL * (3 + BitTime(bytes))))/1000 \
441 + USB2_HOST_DELAY) 488 + USB2_HOST_DELAY)
442#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes)) 489#define HS_USECS(bytes) NS_TO_US(HS_NSECS(bytes))
443#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes)) 490#define HS_USECS_ISO(bytes) NS_TO_US(HS_NSECS_ISO(bytes))
444 491
445extern long usb_calc_bus_time(int speed, int is_input, 492extern long usb_calc_bus_time(int speed, int is_input,
446 int isoc, int bytecount); 493 int isoc, int bytecount);
@@ -551,7 +598,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
551 598
552/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ 599/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */
553/* bleech -- resurfaced in 2.4.11 or 2.4.12 */ 600/* bleech -- resurfaced in 2.4.11 or 2.4.12 */
554#define bitmap DeviceRemovable 601#define bitmap DeviceRemovable
555 602
556 603
557/*-------------------------------------------------------------------------*/ 604/*-------------------------------------------------------------------------*/
diff --git a/include/linux/usb/langwell_udc.h b/include/linux/usb/langwell_udc.h
index c949178a6530..2d2d1bbad9d2 100644
--- a/include/linux/usb/langwell_udc.h
+++ b/include/linux/usb/langwell_udc.h
@@ -181,7 +181,7 @@ struct langwell_op_regs {
181#define PORTS_PIC (BIT(15) | BIT(14)) /* port indicator control */ 181#define PORTS_PIC (BIT(15) | BIT(14)) /* port indicator control */
182#define PORTS_PO BIT(13) /* port owner */ 182#define PORTS_PO BIT(13) /* port owner */
183#define PORTS_PP BIT(12) /* port power */ 183#define PORTS_PP BIT(12) /* port power */
184#define PORTS_LS (BIT(11) | BIT(10)) /* line status */ 184#define PORTS_LS (BIT(11) | BIT(10)) /* line status */
185#define PORTS_SLP BIT(9) /* suspend using L1 */ 185#define PORTS_SLP BIT(9) /* suspend using L1 */
186#define PORTS_PR BIT(8) /* port reset */ 186#define PORTS_PR BIT(8) /* port reset */
187#define PORTS_SUSP BIT(7) /* suspend */ 187#define PORTS_SUSP BIT(7) /* suspend */
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 7acef0234c0e..ee2dd1d506ed 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -22,12 +22,47 @@ enum musb_mode {
22 22
23struct clk; 23struct clk;
24 24
25enum musb_fifo_style {
26 FIFO_RXTX,
27 FIFO_TX,
28 FIFO_RX
29} __attribute__ ((packed));
30
31enum musb_buf_mode {
32 BUF_SINGLE,
33 BUF_DOUBLE
34} __attribute__ ((packed));
35
36struct musb_fifo_cfg {
37 u8 hw_ep_num;
38 enum musb_fifo_style style;
39 enum musb_buf_mode mode;
40 u16 maxpacket;
41};
42
43#define MUSB_EP_FIFO(ep, st, m, pkt) \
44{ \
45 .hw_ep_num = ep, \
46 .style = st, \
47 .mode = m, \
48 .maxpacket = pkt, \
49}
50
51#define MUSB_EP_FIFO_SINGLE(ep, st, pkt) \
52 MUSB_EP_FIFO(ep, st, BUF_SINGLE, pkt)
53
54#define MUSB_EP_FIFO_DOUBLE(ep, st, pkt) \
55 MUSB_EP_FIFO(ep, st, BUF_DOUBLE, pkt)
56
25struct musb_hdrc_eps_bits { 57struct musb_hdrc_eps_bits {
26 const char name[16]; 58 const char name[16];
27 u8 bits; 59 u8 bits;
28}; 60};
29 61
30struct musb_hdrc_config { 62struct musb_hdrc_config {
63 struct musb_fifo_cfg *fifo_cfg; /* board fifo configuration */
64 unsigned fifo_cfg_size; /* size of the fifo configuration */
65
31 /* MUSB configuration-specific details */ 66 /* MUSB configuration-specific details */
32 unsigned multipoint:1; /* multipoint device */ 67 unsigned multipoint:1; /* multipoint device */
33 unsigned dyn_fifo:1 __deprecated; /* supports dynamic fifo sizing */ 68 unsigned dyn_fifo:1 __deprecated; /* supports dynamic fifo sizing */
@@ -51,8 +86,9 @@ struct musb_hdrc_config {
51 86
52 struct musb_hdrc_eps_bits *eps_bits __deprecated; 87 struct musb_hdrc_eps_bits *eps_bits __deprecated;
53#ifdef CONFIG_BLACKFIN 88#ifdef CONFIG_BLACKFIN
54 /* A GPIO controlling VRSEL in Blackfin */ 89 /* A GPIO controlling VRSEL in Blackfin */
55 unsigned int gpio_vrsel; 90 unsigned int gpio_vrsel;
91 unsigned int gpio_vrsel_active;
56#endif 92#endif
57 93
58}; 94};
diff --git a/include/linux/usb/ncm.h b/include/linux/usb/ncm.h
new file mode 100644
index 000000000000..006d1064c8b2
--- /dev/null
+++ b/include/linux/usb/ncm.h
@@ -0,0 +1,114 @@
1/*
2 * USB CDC NCM auxiliary definitions
3 */
4
5#ifndef __LINUX_USB_NCM_H
6#define __LINUX_USB_NCM_H
7
8#include <linux/types.h>
9#include <linux/usb/cdc.h>
10#include <asm/unaligned.h>
11
12#define NCM_NTB_MIN_IN_SIZE 2048
13#define NCM_NTB_MIN_OUT_SIZE 2048
14
15#define NCM_CONTROL_TIMEOUT (5 * 1000)
16
17/* bmNetworkCapabilities */
18
19#define NCM_NCAP_ETH_FILTER (1 << 0)
20#define NCM_NCAP_NET_ADDRESS (1 << 1)
21#define NCM_NCAP_ENCAP_COMM (1 << 2)
22#define NCM_NCAP_MAX_DGRAM (1 << 3)
23#define NCM_NCAP_CRC_MODE (1 << 4)
24
25/*
26 * Here are options for NCM Datagram Pointer table (NDP) parser.
27 * There are 2 different formats: NDP16 and NDP32 in the spec (ch. 3),
28 * in NDP16 offsets and sizes fields are 1 16bit word wide,
29 * in NDP32 -- 2 16bit words wide. Also signatures are different.
30 * To make the parser code the same, put the differences in the structure,
31 * and switch pointers to the structures when the format is changed.
32 */
33
34struct ndp_parser_opts {
35 u32 nth_sign;
36 u32 ndp_sign;
37 unsigned nth_size;
38 unsigned ndp_size;
39 unsigned ndplen_align;
40 /* sizes in u16 units */
41 unsigned dgram_item_len; /* index or length */
42 unsigned block_length;
43 unsigned fp_index;
44 unsigned reserved1;
45 unsigned reserved2;
46 unsigned next_fp_index;
47};
48
49#define INIT_NDP16_OPTS { \
50 .nth_sign = NCM_NTH16_SIGN, \
51 .ndp_sign = NCM_NDP16_NOCRC_SIGN, \
52 .nth_size = sizeof(struct usb_cdc_ncm_nth16), \
53 .ndp_size = sizeof(struct usb_cdc_ncm_ndp16), \
54 .ndplen_align = 4, \
55 .dgram_item_len = 1, \
56 .block_length = 1, \
57 .fp_index = 1, \
58 .reserved1 = 0, \
59 .reserved2 = 0, \
60 .next_fp_index = 1, \
61 }
62
63
64#define INIT_NDP32_OPTS { \
65 .nth_sign = NCM_NTH32_SIGN, \
66 .ndp_sign = NCM_NDP32_NOCRC_SIGN, \
67 .nth_size = sizeof(struct usb_cdc_ncm_nth32), \
68 .ndp_size = sizeof(struct usb_cdc_ncm_ndp32), \
69 .ndplen_align = 8, \
70 .dgram_item_len = 2, \
71 .block_length = 2, \
72 .fp_index = 2, \
73 .reserved1 = 1, \
74 .reserved2 = 2, \
75 .next_fp_index = 2, \
76 }
77
78static inline void put_ncm(__le16 **p, unsigned size, unsigned val)
79{
80 switch (size) {
81 case 1:
82 put_unaligned_le16((u16)val, *p);
83 break;
84 case 2:
85 put_unaligned_le32((u32)val, *p);
86
87 break;
88 default:
89 BUG();
90 }
91
92 *p += size;
93}
94
95static inline unsigned get_ncm(__le16 **p, unsigned size)
96{
97 unsigned tmp;
98
99 switch (size) {
100 case 1:
101 tmp = get_unaligned_le16(*p);
102 break;
103 case 2:
104 tmp = get_unaligned_le32(*p);
105 break;
106 default:
107 BUG();
108 }
109
110 *p += size;
111 return tmp;
112}
113
114#endif /* __LINUX_USB_NCM_H */
diff --git a/include/linux/usb/net2280.h b/include/linux/usb/net2280.h
index 96ca549a778d..148b8fa5b1a2 100644
--- a/include/linux/usb/net2280.h
+++ b/include/linux/usb/net2280.h
@@ -353,7 +353,7 @@ struct net2280_dma_regs { /* [11.7] */
353#define DMA_TRANSACTION_DONE_INTERRUPT 24 353#define DMA_TRANSACTION_DONE_INTERRUPT 24
354#define DMA_ABORT 1 354#define DMA_ABORT 1
355#define DMA_START 0 355#define DMA_START 0
356 u32 _unused0 [2]; 356 u32 _unused0[2];
357 /* offset 0x0190, 0x01b0, 0x01d0, 0x01f0, */ 357 /* offset 0x0190, 0x01b0, 0x01d0, 0x01f0, */
358 u32 dmacount; 358 u32 dmacount;
359#define VALID_BIT 31 359#define VALID_BIT 31
@@ -374,7 +374,7 @@ struct net2280_dep_regs { /* [11.8] */
374 u32 dep_cfg; 374 u32 dep_cfg;
375 /* offset 0x0204, 0x0214, 0x224, 0x234, 0x244 */ 375 /* offset 0x0204, 0x0214, 0x224, 0x234, 0x244 */
376 u32 dep_rsp; 376 u32 dep_rsp;
377 u32 _unused [2]; 377 u32 _unused[2];
378} __attribute__ ((packed)); 378} __attribute__ ((packed));
379 379
380/* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs 380/* configurable endpoint registers, BAR0 + 0x0300 ... array of seven structs
@@ -437,7 +437,7 @@ struct net2280_ep_regs { /* [11.9] */
437 /* offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 */ 437 /* offset 0x0310, 0x0330, 0x0350, 0x0370, 0x0390, 0x03b0, 0x03d0 */
438 u32 ep_avail; 438 u32 ep_avail;
439 u32 ep_data; 439 u32 ep_data;
440 u32 _unused0 [2]; 440 u32 _unused0[2];
441} __attribute__ ((packed)); 441} __attribute__ ((packed));
442 442
443#endif /* __LINUX_USB_NET2280_H */ 443#endif /* __LINUX_USB_NET2280_H */
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index 0a555dd131fc..16b7f3347545 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -22,4 +22,8 @@
22/*device will morph if reset, don't use reset for handling errors */ 22/*device will morph if reset, don't use reset for handling errors */
23#define USB_QUIRK_RESET_MORPHS 0x00000010 23#define USB_QUIRK_RESET_MORPHS 0x00000010
24 24
25/* device has more interface descriptions than the bNumInterfaces count,
26 and can't handle talking to these interfaces */
27#define USB_QUIRK_HONOR_BNUMINTERFACES 0x00000020
28
25#endif /* __LINUX_USB_QUIRKS_H */ 29#endif /* __LINUX_USB_QUIRKS_H */
diff --git a/include/linux/usb/rndis_host.h b/include/linux/usb/rndis_host.h
index 1ef1ebc2b04f..05ef52861988 100644
--- a/include/linux/usb/rndis_host.h
+++ b/include/linux/usb/rndis_host.h
@@ -34,10 +34,10 @@
34struct rndis_msg_hdr { 34struct rndis_msg_hdr {
35 __le32 msg_type; /* RNDIS_MSG_* */ 35 __le32 msg_type; /* RNDIS_MSG_* */
36 __le32 msg_len; 36 __le32 msg_len;
37 // followed by data that varies between messages 37 /* followed by data that varies between messages */
38 __le32 request_id; 38 __le32 request_id;
39 __le32 status; 39 __le32 status;
40 // ... and more 40 /* ... and more */
41} __attribute__ ((packed)); 41} __attribute__ ((packed));
42 42
43/* MS-Windows uses this strange size, but RNDIS spec says 1024 minimum */ 43/* MS-Windows uses this strange size, but RNDIS spec says 1024 minimum */
@@ -92,67 +92,67 @@ struct rndis_msg_hdr {
92 92
93struct rndis_data_hdr { 93struct rndis_data_hdr {
94 __le32 msg_type; /* RNDIS_MSG_PACKET */ 94 __le32 msg_type; /* RNDIS_MSG_PACKET */
95 __le32 msg_len; // rndis_data_hdr + data_len + pad 95 __le32 msg_len; /* rndis_data_hdr + data_len + pad */
96 __le32 data_offset; // 36 -- right after header 96 __le32 data_offset; /* 36 -- right after header */
97 __le32 data_len; // ... real packet size 97 __le32 data_len; /* ... real packet size */
98 98
99 __le32 oob_data_offset; // zero 99 __le32 oob_data_offset; /* zero */
100 __le32 oob_data_len; // zero 100 __le32 oob_data_len; /* zero */
101 __le32 num_oob; // zero 101 __le32 num_oob; /* zero */
102 __le32 packet_data_offset; // zero 102 __le32 packet_data_offset; /* zero */
103 103
104 __le32 packet_data_len; // zero 104 __le32 packet_data_len; /* zero */
105 __le32 vc_handle; // zero 105 __le32 vc_handle; /* zero */
106 __le32 reserved; // zero 106 __le32 reserved; /* zero */
107} __attribute__ ((packed)); 107} __attribute__ ((packed));
108 108
109struct rndis_init { /* OUT */ 109struct rndis_init { /* OUT */
110 // header and: 110 /* header and: */
111 __le32 msg_type; /* RNDIS_MSG_INIT */ 111 __le32 msg_type; /* RNDIS_MSG_INIT */
112 __le32 msg_len; // 24 112 __le32 msg_len; /* 24 */
113 __le32 request_id; 113 __le32 request_id;
114 __le32 major_version; // of rndis (1.0) 114 __le32 major_version; /* of rndis (1.0) */
115 __le32 minor_version; 115 __le32 minor_version;
116 __le32 max_transfer_size; 116 __le32 max_transfer_size;
117} __attribute__ ((packed)); 117} __attribute__ ((packed));
118 118
119struct rndis_init_c { /* IN */ 119struct rndis_init_c { /* IN */
120 // header and: 120 /* header and: */
121 __le32 msg_type; /* RNDIS_MSG_INIT_C */ 121 __le32 msg_type; /* RNDIS_MSG_INIT_C */
122 __le32 msg_len; 122 __le32 msg_len;
123 __le32 request_id; 123 __le32 request_id;
124 __le32 status; 124 __le32 status;
125 __le32 major_version; // of rndis (1.0) 125 __le32 major_version; /* of rndis (1.0) */
126 __le32 minor_version; 126 __le32 minor_version;
127 __le32 device_flags; 127 __le32 device_flags;
128 __le32 medium; // zero == 802.3 128 __le32 medium; /* zero == 802.3 */
129 __le32 max_packets_per_message; 129 __le32 max_packets_per_message;
130 __le32 max_transfer_size; 130 __le32 max_transfer_size;
131 __le32 packet_alignment; // max 7; (1<<n) bytes 131 __le32 packet_alignment; /* max 7; (1<<n) bytes */
132 __le32 af_list_offset; // zero 132 __le32 af_list_offset; /* zero */
133 __le32 af_list_size; // zero 133 __le32 af_list_size; /* zero */
134} __attribute__ ((packed)); 134} __attribute__ ((packed));
135 135
136struct rndis_halt { /* OUT (no reply) */ 136struct rndis_halt { /* OUT (no reply) */
137 // header and: 137 /* header and: */
138 __le32 msg_type; /* RNDIS_MSG_HALT */ 138 __le32 msg_type; /* RNDIS_MSG_HALT */
139 __le32 msg_len; 139 __le32 msg_len;
140 __le32 request_id; 140 __le32 request_id;
141} __attribute__ ((packed)); 141} __attribute__ ((packed));
142 142
143struct rndis_query { /* OUT */ 143struct rndis_query { /* OUT */
144 // header and: 144 /* header and: */
145 __le32 msg_type; /* RNDIS_MSG_QUERY */ 145 __le32 msg_type; /* RNDIS_MSG_QUERY */
146 __le32 msg_len; 146 __le32 msg_len;
147 __le32 request_id; 147 __le32 request_id;
148 __le32 oid; 148 __le32 oid;
149 __le32 len; 149 __le32 len;
150 __le32 offset; 150 __le32 offset;
151/*?*/ __le32 handle; // zero 151/*?*/ __le32 handle; /* zero */
152} __attribute__ ((packed)); 152} __attribute__ ((packed));
153 153
154struct rndis_query_c { /* IN */ 154struct rndis_query_c { /* IN */
155 // header and: 155 /* header and: */
156 __le32 msg_type; /* RNDIS_MSG_QUERY_C */ 156 __le32 msg_type; /* RNDIS_MSG_QUERY_C */
157 __le32 msg_len; 157 __le32 msg_len;
158 __le32 request_id; 158 __le32 request_id;
@@ -162,18 +162,18 @@ struct rndis_query_c { /* IN */
162} __attribute__ ((packed)); 162} __attribute__ ((packed));
163 163
164struct rndis_set { /* OUT */ 164struct rndis_set { /* OUT */
165 // header and: 165 /* header and: */
166 __le32 msg_type; /* RNDIS_MSG_SET */ 166 __le32 msg_type; /* RNDIS_MSG_SET */
167 __le32 msg_len; 167 __le32 msg_len;
168 __le32 request_id; 168 __le32 request_id;
169 __le32 oid; 169 __le32 oid;
170 __le32 len; 170 __le32 len;
171 __le32 offset; 171 __le32 offset;
172/*?*/ __le32 handle; // zero 172/*?*/ __le32 handle; /* zero */
173} __attribute__ ((packed)); 173} __attribute__ ((packed));
174 174
175struct rndis_set_c { /* IN */ 175struct rndis_set_c { /* IN */
176 // header and: 176 /* header and: */
177 __le32 msg_type; /* RNDIS_MSG_SET_C */ 177 __le32 msg_type; /* RNDIS_MSG_SET_C */
178 __le32 msg_len; 178 __le32 msg_len;
179 __le32 request_id; 179 __le32 request_id;
@@ -181,14 +181,14 @@ struct rndis_set_c { /* IN */
181} __attribute__ ((packed)); 181} __attribute__ ((packed));
182 182
183struct rndis_reset { /* IN */ 183struct rndis_reset { /* IN */
184 // header and: 184 /* header and: */
185 __le32 msg_type; /* RNDIS_MSG_RESET */ 185 __le32 msg_type; /* RNDIS_MSG_RESET */
186 __le32 msg_len; 186 __le32 msg_len;
187 __le32 reserved; 187 __le32 reserved;
188} __attribute__ ((packed)); 188} __attribute__ ((packed));
189 189
190struct rndis_reset_c { /* OUT */ 190struct rndis_reset_c { /* OUT */
191 // header and: 191 /* header and: */
192 __le32 msg_type; /* RNDIS_MSG_RESET_C */ 192 __le32 msg_type; /* RNDIS_MSG_RESET_C */
193 __le32 msg_len; 193 __le32 msg_len;
194 __le32 status; 194 __le32 status;
@@ -196,7 +196,7 @@ struct rndis_reset_c { /* OUT */
196} __attribute__ ((packed)); 196} __attribute__ ((packed));
197 197
198struct rndis_indicate { /* IN (unrequested) */ 198struct rndis_indicate { /* IN (unrequested) */
199 // header and: 199 /* header and: */
200 __le32 msg_type; /* RNDIS_MSG_INDICATE */ 200 __le32 msg_type; /* RNDIS_MSG_INDICATE */
201 __le32 msg_len; 201 __le32 msg_len;
202 __le32 status; 202 __le32 status;
@@ -208,14 +208,14 @@ struct rndis_indicate { /* IN (unrequested) */
208} __attribute__ ((packed)); 208} __attribute__ ((packed));
209 209
210struct rndis_keepalive { /* OUT (optionally IN) */ 210struct rndis_keepalive { /* OUT (optionally IN) */
211 // header and: 211 /* header and: */
212 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */ 212 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */
213 __le32 msg_len; 213 __le32 msg_len;
214 __le32 request_id; 214 __le32 request_id;
215} __attribute__ ((packed)); 215} __attribute__ ((packed));
216 216
217struct rndis_keepalive_c { /* IN (optionally OUT) */ 217struct rndis_keepalive_c { /* IN (optionally OUT) */
218 // header and: 218 /* header and: */
219 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */ 219 __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */
220 __le32 msg_len; 220 __le32 msg_len;
221 __le32 request_id; 221 __le32 request_id;
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 0a458b861933..84a4c44c208b 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -35,6 +35,9 @@ enum port_dev_state {
35 PORT_UNREGISTERING, 35 PORT_UNREGISTERING,
36}; 36};
37 37
38/* USB serial flags */
39#define USB_SERIAL_WRITE_BUSY 0
40
38/** 41/**
39 * usb_serial_port: structure for the specific ports of a device. 42 * usb_serial_port: structure for the specific ports of a device.
40 * @serial: pointer back to the struct usb_serial owner of this port. 43 * @serial: pointer back to the struct usb_serial owner of this port.
@@ -49,7 +52,7 @@ enum port_dev_state {
49 * @interrupt_out_size: the size of the interrupt_out_buffer, in bytes. 52 * @interrupt_out_size: the size of the interrupt_out_buffer, in bytes.
50 * @interrupt_out_urb: pointer to the interrupt out struct urb for this port. 53 * @interrupt_out_urb: pointer to the interrupt out struct urb for this port.
51 * @interrupt_out_endpointAddress: endpoint address for the interrupt out pipe 54 * @interrupt_out_endpointAddress: endpoint address for the interrupt out pipe
52 * for this port. 55 * for this port.
53 * @bulk_in_buffer: pointer to the bulk in buffer for this port. 56 * @bulk_in_buffer: pointer to the bulk in buffer for this port.
54 * @bulk_in_size: the size of the bulk_in_buffer, in bytes. 57 * @bulk_in_size: the size of the bulk_in_buffer, in bytes.
55 * @read_urb: pointer to the bulk in struct urb for this port. 58 * @read_urb: pointer to the bulk in struct urb for this port.
@@ -60,13 +63,17 @@ enum port_dev_state {
60 * @write_urb: pointer to the bulk out struct urb for this port. 63 * @write_urb: pointer to the bulk out struct urb for this port.
61 * @write_fifo: kfifo used to buffer outgoing data 64 * @write_fifo: kfifo used to buffer outgoing data
62 * @write_urb_busy: port`s writing status 65 * @write_urb_busy: port`s writing status
66 * @bulk_out_buffers: pointers to the bulk out buffers for this port
67 * @write_urbs: pointers to the bulk out urbs for this port
68 * @write_urbs_free: status bitmap the for bulk out urbs
69 * @tx_bytes: number of bytes currently in host stack queues
63 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this 70 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this
64 * port. 71 * port.
72 * @flags: usb serial port flags
65 * @write_wait: a wait_queue_head_t used by the port. 73 * @write_wait: a wait_queue_head_t used by the port.
66 * @work: work queue entry for the line discipline waking up. 74 * @work: work queue entry for the line discipline waking up.
67 * @throttled: nonzero if the read urb is inactive to throttle the device 75 * @throttled: nonzero if the read urb is inactive to throttle the device
68 * @throttle_req: nonzero if the tty wants to throttle us 76 * @throttle_req: nonzero if the tty wants to throttle us
69 * @console: attached usb serial console
70 * @dev: pointer to the serial device 77 * @dev: pointer to the serial device
71 * 78 *
72 * This structure is used by the usb-serial core and drivers for the specific 79 * This structure is used by the usb-serial core and drivers for the specific
@@ -97,16 +104,19 @@ struct usb_serial_port {
97 struct urb *write_urb; 104 struct urb *write_urb;
98 struct kfifo write_fifo; 105 struct kfifo write_fifo;
99 int write_urb_busy; 106 int write_urb_busy;
107
108 unsigned char *bulk_out_buffers[2];
109 struct urb *write_urbs[2];
110 unsigned long write_urbs_free;
100 __u8 bulk_out_endpointAddress; 111 __u8 bulk_out_endpointAddress;
101 112
102 int tx_bytes_flight; 113 int tx_bytes;
103 int urbs_in_flight;
104 114
115 unsigned long flags;
105 wait_queue_head_t write_wait; 116 wait_queue_head_t write_wait;
106 struct work_struct work; 117 struct work_struct work;
107 char throttled; 118 char throttled;
108 char throttle_req; 119 char throttle_req;
109 char console;
110 unsigned long sysrq; /* sysrq timeout */ 120 unsigned long sysrq; /* sysrq timeout */
111 struct device dev; 121 struct device dev;
112 enum port_dev_state dev_state; 122 enum port_dev_state dev_state;
@@ -181,6 +191,8 @@ static inline void usb_set_serial_data(struct usb_serial *serial, void *data)
181 * @id_table: pointer to a list of usb_device_id structures that define all 191 * @id_table: pointer to a list of usb_device_id structures that define all
182 * of the devices this structure can support. 192 * of the devices this structure can support.
183 * @num_ports: the number of different ports this device will have. 193 * @num_ports: the number of different ports this device will have.
194 * @bulk_in_size: bytes to allocate for bulk-in buffer (0 = end-point size)
195 * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size)
184 * @calc_num_ports: pointer to a function to determine how many ports this 196 * @calc_num_ports: pointer to a function to determine how many ports this
185 * device has dynamically. It will be called after the probe() 197 * device has dynamically. It will be called after the probe()
186 * callback is called, but before attach() 198 * callback is called, but before attach()
@@ -223,7 +235,9 @@ struct usb_serial_driver {
223 struct device_driver driver; 235 struct device_driver driver;
224 struct usb_driver *usb_driver; 236 struct usb_driver *usb_driver;
225 struct usb_dynids dynids; 237 struct usb_dynids dynids;
226 int max_in_flight_urbs; 238
239 size_t bulk_in_size;
240 size_t bulk_out_size;
227 241
228 int (*probe)(struct usb_serial *serial, const struct usb_device_id *id); 242 int (*probe)(struct usb_serial *serial, const struct usb_device_id *id);
229 int (*attach)(struct usb_serial *serial); 243 int (*attach)(struct usb_serial *serial);
@@ -269,6 +283,11 @@ struct usb_serial_driver {
269 void (*write_int_callback)(struct urb *urb); 283 void (*write_int_callback)(struct urb *urb);
270 void (*read_bulk_callback)(struct urb *urb); 284 void (*read_bulk_callback)(struct urb *urb);
271 void (*write_bulk_callback)(struct urb *urb); 285 void (*write_bulk_callback)(struct urb *urb);
286 /* Called by the generic read bulk callback */
287 void (*process_read_urb)(struct urb *urb);
288 /* Called by the generic write implementation */
289 int (*prepare_write_buffer)(struct usb_serial_port *port,
290 void *dest, size_t size);
272}; 291};
273#define to_usb_serial_driver(d) \ 292#define to_usb_serial_driver(d) \
274 container_of(d, struct usb_serial_driver, driver) 293 container_of(d, struct usb_serial_driver, driver)
@@ -318,8 +337,11 @@ extern void usb_serial_generic_disconnect(struct usb_serial *serial);
318extern void usb_serial_generic_release(struct usb_serial *serial); 337extern void usb_serial_generic_release(struct usb_serial *serial);
319extern int usb_serial_generic_register(int debug); 338extern int usb_serial_generic_register(int debug);
320extern void usb_serial_generic_deregister(void); 339extern void usb_serial_generic_deregister(void);
321extern void usb_serial_generic_resubmit_read_urb(struct usb_serial_port *port, 340extern int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
322 gfp_t mem_flags); 341 gfp_t mem_flags);
342extern void usb_serial_generic_process_read_urb(struct urb *urb);
343extern int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
344 void *dest, size_t size);
323extern int usb_serial_handle_sysrq_char(struct tty_struct *tty, 345extern int usb_serial_handle_sysrq_char(struct tty_struct *tty,
324 struct usb_serial_port *port, 346 struct usb_serial_port *port,
325 unsigned int ch); 347 unsigned int ch);
diff --git a/include/linux/usb/ulpi.h b/include/linux/usb/ulpi.h
index 20675c6ebc4d..2369d07c3c87 100644
--- a/include/linux/usb/ulpi.h
+++ b/include/linux/usb/ulpi.h
@@ -1,6 +1,146 @@
1/*
2 * ulpi.h -- ULPI defines and function prorotypes
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * This software is distributed under the terms of the GNU General
7 * Public License ("GPL") as published by the Free Software Foundation,
8 * version 2 of that License.
9 */
10
1#ifndef __LINUX_USB_ULPI_H 11#ifndef __LINUX_USB_ULPI_H
2#define __LINUX_USB_ULPI_H 12#define __LINUX_USB_ULPI_H
3 13
14/*-------------------------------------------------------------------------*/
15
16/*
17 * Macros for Set and Clear
18 * See ULPI 1.1 specification to find the registers with Set and Clear offsets
19 */
20#define ULPI_SET(a) (a + 1)
21#define ULPI_CLR(a) (a + 2)
22
23/*-------------------------------------------------------------------------*/
24
25/*
26 * Register Map
27 */
28#define ULPI_VENDOR_ID_LOW 0x00
29#define ULPI_VENDOR_ID_HIGH 0x01
30#define ULPI_PRODUCT_ID_LOW 0x02
31#define ULPI_PRODUCT_ID_HIGH 0x03
32#define ULPI_FUNC_CTRL 0x04
33#define ULPI_IFC_CTRL 0x07
34#define ULPI_OTG_CTRL 0x0a
35#define ULPI_USB_INT_EN_RISE 0x0d
36#define ULPI_USB_INT_EN_FALL 0x10
37#define ULPI_USB_INT_STS 0x13
38#define ULPI_USB_INT_LATCH 0x14
39#define ULPI_DEBUG 0x15
40#define ULPI_SCRATCH 0x16
41/* Optional Carkit Registers */
42#define ULPI_CARCIT_CTRL 0x19
43#define ULPI_CARCIT_INT_DELAY 0x1c
44#define ULPI_CARCIT_INT_EN 0x1d
45#define ULPI_CARCIT_INT_STS 0x20
46#define ULPI_CARCIT_INT_LATCH 0x21
47#define ULPI_CARCIT_PLS_CTRL 0x22
48/* Other Optional Registers */
49#define ULPI_TX_POS_WIDTH 0x25
50#define ULPI_TX_NEG_WIDTH 0x26
51#define ULPI_POLARITY_RECOVERY 0x27
52/* Access Extended Register Set */
53#define ULPI_ACCESS_EXTENDED 0x2f
54/* Vendor Specific */
55#define ULPI_VENDOR_SPECIFIC 0x30
56/* Extended Registers */
57#define ULPI_EXT_VENDOR_SPECIFIC 0x80
58
59/*-------------------------------------------------------------------------*/
60
61/* Function Control */
62#define ULPI_FUNC_CTRL_XCVRSEL (1 << 0)
63#define ULPI_FUNC_CTRL_XCVRSEL_MASK (3 << 0)
64#define ULPI_FUNC_CTRL_HIGH_SPEED (0 << 0)
65#define ULPI_FUNC_CTRL_FULL_SPEED (1 << 0)
66#define ULPI_FUNC_CTRL_LOW_SPEED (2 << 0)
67#define ULPI_FUNC_CTRL_FS4LS (3 << 0)
68#define ULPI_FUNC_CTRL_TERMSELECT (1 << 2)
69#define ULPI_FUNC_CTRL_OPMODE (1 << 3)
70#define ULPI_FUNC_CTRL_OPMODE_MASK (3 << 3)
71#define ULPI_FUNC_CTRL_OPMODE_NORMAL (0 << 3)
72#define ULPI_FUNC_CTRL_OPMODE_NONDRIVING (1 << 3)
73#define ULPI_FUNC_CTRL_OPMODE_DISABLE_NRZI (2 << 3)
74#define ULPI_FUNC_CTRL_OPMODE_NOSYNC_NOEOP (3 << 3)
75#define ULPI_FUNC_CTRL_RESET (1 << 5)
76#define ULPI_FUNC_CTRL_SUSPENDM (1 << 6)
77
78/* Interface Control */
79#define ULPI_IFC_CTRL_6_PIN_SERIAL_MODE (1 << 0)
80#define ULPI_IFC_CTRL_3_PIN_SERIAL_MODE (1 << 1)
81#define ULPI_IFC_CTRL_CARKITMODE (1 << 2)
82#define ULPI_IFC_CTRL_CLOCKSUSPENDM (1 << 3)
83#define ULPI_IFC_CTRL_AUTORESUME (1 << 4)
84#define ULPI_IFC_CTRL_EXTERNAL_VBUS (1 << 5)
85#define ULPI_IFC_CTRL_PASSTHRU (1 << 6)
86#define ULPI_IFC_CTRL_PROTECT_IFC_DISABLE (1 << 7)
87
88/* OTG Control */
89#define ULPI_OTG_CTRL_ID_PULLUP (1 << 0)
90#define ULPI_OTG_CTRL_DP_PULLDOWN (1 << 1)
91#define ULPI_OTG_CTRL_DM_PULLDOWN (1 << 2)
92#define ULPI_OTG_CTRL_DISCHRGVBUS (1 << 3)
93#define ULPI_OTG_CTRL_CHRGVBUS (1 << 4)
94#define ULPI_OTG_CTRL_DRVVBUS (1 << 5)
95#define ULPI_OTG_CTRL_DRVVBUS_EXT (1 << 6)
96#define ULPI_OTG_CTRL_EXTVBUSIND (1 << 7)
97
98/* USB Interrupt Enable Rising,
99 * USB Interrupt Enable Falling,
100 * USB Interrupt Status and
101 * USB Interrupt Latch
102 */
103#define ULPI_INT_HOST_DISCONNECT (1 << 0)
104#define ULPI_INT_VBUS_VALID (1 << 1)
105#define ULPI_INT_SESS_VALID (1 << 2)
106#define ULPI_INT_SESS_END (1 << 3)
107#define ULPI_INT_IDGRD (1 << 4)
108
109/* Debug */
110#define ULPI_DEBUG_LINESTATE0 (1 << 0)
111#define ULPI_DEBUG_LINESTATE1 (1 << 1)
112
113/* Carkit Control */
114#define ULPI_CARKIT_CTRL_CARKITPWR (1 << 0)
115#define ULPI_CARKIT_CTRL_IDGNDDRV (1 << 1)
116#define ULPI_CARKIT_CTRL_TXDEN (1 << 2)
117#define ULPI_CARKIT_CTRL_RXDEN (1 << 3)
118#define ULPI_CARKIT_CTRL_SPKLEFTEN (1 << 4)
119#define ULPI_CARKIT_CTRL_SPKRIGHTEN (1 << 5)
120#define ULPI_CARKIT_CTRL_MICEN (1 << 6)
121
122/* Carkit Interrupt Enable */
123#define ULPI_CARKIT_INT_EN_IDFLOAT_RISE (1 << 0)
124#define ULPI_CARKIT_INT_EN_IDFLOAT_FALL (1 << 1)
125#define ULPI_CARKIT_INT_EN_CARINTDET (1 << 2)
126#define ULPI_CARKIT_INT_EN_DP_RISE (1 << 3)
127#define ULPI_CARKIT_INT_EN_DP_FALL (1 << 4)
128
129/* Carkit Interrupt Status and
130 * Carkit Interrupt Latch
131 */
132#define ULPI_CARKIT_INT_IDFLOAT (1 << 0)
133#define ULPI_CARKIT_INT_CARINTDET (1 << 1)
134#define ULPI_CARKIT_INT_DP (1 << 2)
135
136/* Carkit Pulse Control*/
137#define ULPI_CARKIT_PLS_CTRL_TXPLSEN (1 << 0)
138#define ULPI_CARKIT_PLS_CTRL_RXPLSEN (1 << 1)
139#define ULPI_CARKIT_PLS_CTRL_SPKRLEFT_BIASEN (1 << 2)
140#define ULPI_CARKIT_PLS_CTRL_SPKRRIGHT_BIASEN (1 << 3)
141
142/*-------------------------------------------------------------------------*/
143
4struct otg_transceiver *otg_ulpi_create(struct otg_io_access_ops *ops, 144struct otg_transceiver *otg_ulpi_create(struct otg_io_access_ops *ops,
5 unsigned int flags); 145 unsigned int flags);
6 146
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index df1e83dd9a54..7ae27a473818 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -43,7 +43,7 @@ struct usbnet {
43 /* protocol/interface state */ 43 /* protocol/interface state */
44 struct net_device *net; 44 struct net_device *net;
45 int msg_enable; 45 int msg_enable;
46 unsigned long data [5]; 46 unsigned long data[5];
47 u32 xid; 47 u32 xid;
48 u32 hard_mtu; /* count any extra framing */ 48 u32 hard_mtu; /* count any extra framing */
49 size_t rx_urb_size; /* size for rx urbs */ 49 size_t rx_urb_size; /* size for rx urbs */
@@ -148,8 +148,8 @@ struct driver_info {
148 * much everything except custom framing and chip-specific stuff. 148 * much everything except custom framing and chip-specific stuff.
149 */ 149 */
150extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *); 150extern int usbnet_probe(struct usb_interface *, const struct usb_device_id *);
151extern int usbnet_suspend (struct usb_interface *, pm_message_t ); 151extern int usbnet_suspend(struct usb_interface *, pm_message_t);
152extern int usbnet_resume (struct usb_interface *); 152extern int usbnet_resume(struct usb_interface *);
153extern void usbnet_disconnect(struct usb_interface *); 153extern void usbnet_disconnect(struct usb_interface *);
154 154
155 155
@@ -165,8 +165,8 @@ struct cdc_state {
165 struct usb_interface *data; 165 struct usb_interface *data;
166}; 166};
167 167
168extern int usbnet_generic_cdc_bind (struct usbnet *, struct usb_interface *); 168extern int usbnet_generic_cdc_bind(struct usbnet *, struct usb_interface *);
169extern void usbnet_cdc_unbind (struct usbnet *, struct usb_interface *); 169extern void usbnet_cdc_unbind(struct usbnet *, struct usb_interface *);
170 170
171/* CDC and RNDIS support the same host-chosen packet filters for IN transfers */ 171/* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
172#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ 172#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
@@ -189,29 +189,31 @@ struct skb_data { /* skb->cb is one of these */
189 size_t length; 189 size_t length;
190}; 190};
191 191
192extern int usbnet_open (struct net_device *net); 192extern int usbnet_open(struct net_device *net);
193extern int usbnet_stop (struct net_device *net); 193extern int usbnet_stop(struct net_device *net);
194extern netdev_tx_t usbnet_start_xmit (struct sk_buff *skb, 194extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,
195 struct net_device *net); 195 struct net_device *net);
196extern void usbnet_tx_timeout (struct net_device *net); 196extern void usbnet_tx_timeout(struct net_device *net);
197extern int usbnet_change_mtu (struct net_device *net, int new_mtu); 197extern int usbnet_change_mtu(struct net_device *net, int new_mtu);
198 198
199extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *); 199extern int usbnet_get_endpoints(struct usbnet *, struct usb_interface *);
200extern int usbnet_get_ethernet_addr(struct usbnet *, int); 200extern int usbnet_get_ethernet_addr(struct usbnet *, int);
201extern void usbnet_defer_kevent (struct usbnet *, int); 201extern void usbnet_defer_kevent(struct usbnet *, int);
202extern void usbnet_skb_return (struct usbnet *, struct sk_buff *); 202extern void usbnet_skb_return(struct usbnet *, struct sk_buff *);
203extern void usbnet_unlink_rx_urbs(struct usbnet *); 203extern void usbnet_unlink_rx_urbs(struct usbnet *);
204 204
205extern void usbnet_pause_rx(struct usbnet *); 205extern void usbnet_pause_rx(struct usbnet *);
206extern void usbnet_resume_rx(struct usbnet *); 206extern void usbnet_resume_rx(struct usbnet *);
207extern void usbnet_purge_paused_rxq(struct usbnet *); 207extern void usbnet_purge_paused_rxq(struct usbnet *);
208 208
209extern int usbnet_get_settings (struct net_device *net, struct ethtool_cmd *cmd); 209extern int usbnet_get_settings(struct net_device *net,
210extern int usbnet_set_settings (struct net_device *net, struct ethtool_cmd *cmd); 210 struct ethtool_cmd *cmd);
211extern u32 usbnet_get_link (struct net_device *net); 211extern int usbnet_set_settings(struct net_device *net,
212extern u32 usbnet_get_msglevel (struct net_device *); 212 struct ethtool_cmd *cmd);
213extern void usbnet_set_msglevel (struct net_device *, u32); 213extern u32 usbnet_get_link(struct net_device *net);
214extern void usbnet_get_drvinfo (struct net_device *, struct ethtool_drvinfo *); 214extern u32 usbnet_get_msglevel(struct net_device *);
215extern void usbnet_set_msglevel(struct net_device *, u32);
216extern void usbnet_get_drvinfo(struct net_device *, struct ethtool_drvinfo *);
215extern int usbnet_nway_reset(struct net_device *net); 217extern int usbnet_nway_reset(struct net_device *net);
216 218
217#endif /* __LINUX_USB_USBNET_H */ 219#endif /* __LINUX_USB_USBNET_H */
diff --git a/include/linux/usb/wusb-wa.h b/include/linux/usb/wusb-wa.h
index fb7c359bdfba..f9dec37f617b 100644
--- a/include/linux/usb/wusb-wa.h
+++ b/include/linux/usb/wusb-wa.h
@@ -87,7 +87,7 @@ enum rpipe_crs {
87 * FIXME: explain rpipes 87 * FIXME: explain rpipes
88 */ 88 */
89struct usb_rpipe_descriptor { 89struct usb_rpipe_descriptor {
90 u8 bLength; 90 u8 bLength;
91 u8 bDescriptorType; 91 u8 bDescriptorType;
92 __le16 wRPipeIndex; 92 __le16 wRPipeIndex;
93 __le16 wRequests; 93 __le16 wRequests;
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 76d96d035ea0..0836ccc57121 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -376,6 +376,155 @@ do { \
376 __ret; \ 376 __ret; \
377}) 377})
378 378
379
380#define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \
381({ \
382 int __ret = 0; \
383 DEFINE_WAIT(__wait); \
384 if (exclusive) \
385 __wait.flags |= WQ_FLAG_EXCLUSIVE; \
386 do { \
387 if (likely(list_empty(&__wait.task_list))) \
388 __add_wait_queue_tail(&(wq), &__wait); \
389 set_current_state(TASK_INTERRUPTIBLE); \
390 if (signal_pending(current)) { \
391 __ret = -ERESTARTSYS; \
392 break; \
393 } \
394 if (irq) \
395 spin_unlock_irq(&(wq).lock); \
396 else \
397 spin_unlock(&(wq).lock); \
398 schedule(); \
399 if (irq) \
400 spin_lock_irq(&(wq).lock); \
401 else \
402 spin_lock(&(wq).lock); \
403 } while (!(condition)); \
404 __remove_wait_queue(&(wq), &__wait); \
405 __set_current_state(TASK_RUNNING); \
406 __ret; \
407})
408
409
410/**
411 * wait_event_interruptible_locked - sleep until a condition gets true
412 * @wq: the waitqueue to wait on
413 * @condition: a C expression for the event to wait for
414 *
415 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
416 * @condition evaluates to true or a signal is received.
417 * The @condition is checked each time the waitqueue @wq is woken up.
418 *
419 * It must be called with wq.lock being held. This spinlock is
420 * unlocked while sleeping but @condition testing is done while lock
421 * is held and when this macro exits the lock is held.
422 *
423 * The lock is locked/unlocked using spin_lock()/spin_unlock()
424 * functions which must match the way they are locked/unlocked outside
425 * of this macro.
426 *
427 * wake_up_locked() has to be called after changing any variable that could
428 * change the result of the wait condition.
429 *
430 * The function will return -ERESTARTSYS if it was interrupted by a
431 * signal and 0 if @condition evaluated to true.
432 */
433#define wait_event_interruptible_locked(wq, condition) \
434 ((condition) \
435 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0))
436
437/**
438 * wait_event_interruptible_locked_irq - sleep until a condition gets true
439 * @wq: the waitqueue to wait on
440 * @condition: a C expression for the event to wait for
441 *
442 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
443 * @condition evaluates to true or a signal is received.
444 * The @condition is checked each time the waitqueue @wq is woken up.
445 *
446 * It must be called with wq.lock being held. This spinlock is
447 * unlocked while sleeping but @condition testing is done while lock
448 * is held and when this macro exits the lock is held.
449 *
450 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
451 * functions which must match the way they are locked/unlocked outside
452 * of this macro.
453 *
454 * wake_up_locked() has to be called after changing any variable that could
455 * change the result of the wait condition.
456 *
457 * The function will return -ERESTARTSYS if it was interrupted by a
458 * signal and 0 if @condition evaluated to true.
459 */
460#define wait_event_interruptible_locked_irq(wq, condition) \
461 ((condition) \
462 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1))
463
464/**
465 * wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true
466 * @wq: the waitqueue to wait on
467 * @condition: a C expression for the event to wait for
468 *
469 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
470 * @condition evaluates to true or a signal is received.
471 * The @condition is checked each time the waitqueue @wq is woken up.
472 *
473 * It must be called with wq.lock being held. This spinlock is
474 * unlocked while sleeping but @condition testing is done while lock
475 * is held and when this macro exits the lock is held.
476 *
477 * The lock is locked/unlocked using spin_lock()/spin_unlock()
478 * functions which must match the way they are locked/unlocked outside
479 * of this macro.
480 *
481 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
482 * set thus when other process waits process on the list if this
483 * process is awaken further processes are not considered.
484 *
485 * wake_up_locked() has to be called after changing any variable that could
486 * change the result of the wait condition.
487 *
488 * The function will return -ERESTARTSYS if it was interrupted by a
489 * signal and 0 if @condition evaluated to true.
490 */
491#define wait_event_interruptible_exclusive_locked(wq, condition) \
492 ((condition) \
493 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0))
494
495/**
496 * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true
497 * @wq: the waitqueue to wait on
498 * @condition: a C expression for the event to wait for
499 *
500 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
501 * @condition evaluates to true or a signal is received.
502 * The @condition is checked each time the waitqueue @wq is woken up.
503 *
504 * It must be called with wq.lock being held. This spinlock is
505 * unlocked while sleeping but @condition testing is done while lock
506 * is held and when this macro exits the lock is held.
507 *
508 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
509 * functions which must match the way they are locked/unlocked outside
510 * of this macro.
511 *
512 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
513 * set thus when other process waits process on the list if this
514 * process is awaken further processes are not considered.
515 *
516 * wake_up_locked() has to be called after changing any variable that could
517 * change the result of the wait condition.
518 *
519 * The function will return -ERESTARTSYS if it was interrupted by a
520 * signal and 0 if @condition evaluated to true.
521 */
522#define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
523 ((condition) \
524 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
525
526
527
379#define __wait_event_killable(wq, condition, ret) \ 528#define __wait_event_killable(wq, condition, ret) \
380do { \ 529do { \
381 DEFINE_WAIT(__wait); \ 530 DEFINE_WAIT(__wait); \
diff --git a/kernel/sched.c b/kernel/sched.c
index 1d93cd0ae4d3..d9c0368eeb21 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -3851,6 +3851,7 @@ void __wake_up_locked(wait_queue_head_t *q, unsigned int mode)
3851{ 3851{
3852 __wake_up_common(q, mode, 1, 0, NULL); 3852 __wake_up_common(q, mode, 1, 0, NULL);
3853} 3853}
3854EXPORT_SYMBOL_GPL(__wake_up_locked);
3854 3855
3855void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key) 3856void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key)
3856{ 3857{
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index 2c1558c327bb..8b1e4b124a9f 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -1048,8 +1048,8 @@ static struct snd_rawmidi_ops snd_usbmidi_input_ops = {
1048static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb, 1048static void free_urb_and_buffer(struct snd_usb_midi *umidi, struct urb *urb,
1049 unsigned int buffer_length) 1049 unsigned int buffer_length)
1050{ 1050{
1051 usb_buffer_free(umidi->dev, buffer_length, 1051 usb_free_coherent(umidi->dev, buffer_length,
1052 urb->transfer_buffer, urb->transfer_dma); 1052 urb->transfer_buffer, urb->transfer_dma);
1053 usb_free_urb(urb); 1053 usb_free_urb(urb);
1054} 1054}
1055 1055
@@ -1100,8 +1100,8 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi* umidi,
1100 pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep); 1100 pipe = usb_rcvbulkpipe(umidi->dev, ep_info->in_ep);
1101 length = usb_maxpacket(umidi->dev, pipe, 0); 1101 length = usb_maxpacket(umidi->dev, pipe, 0);
1102 for (i = 0; i < INPUT_URBS; ++i) { 1102 for (i = 0; i < INPUT_URBS; ++i) {
1103 buffer = usb_buffer_alloc(umidi->dev, length, GFP_KERNEL, 1103 buffer = usb_alloc_coherent(umidi->dev, length, GFP_KERNEL,
1104 &ep->urbs[i]->transfer_dma); 1104 &ep->urbs[i]->transfer_dma);
1105 if (!buffer) { 1105 if (!buffer) {
1106 snd_usbmidi_in_endpoint_delete(ep); 1106 snd_usbmidi_in_endpoint_delete(ep);
1107 return -ENOMEM; 1107 return -ENOMEM;
@@ -1191,9 +1191,9 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi,
1191 break; 1191 break;
1192 } 1192 }
1193 for (i = 0; i < OUTPUT_URBS; ++i) { 1193 for (i = 0; i < OUTPUT_URBS; ++i) {
1194 buffer = usb_buffer_alloc(umidi->dev, 1194 buffer = usb_alloc_coherent(umidi->dev,
1195 ep->max_transfer, GFP_KERNEL, 1195 ep->max_transfer, GFP_KERNEL,
1196 &ep->urbs[i].urb->transfer_dma); 1196 &ep->urbs[i].urb->transfer_dma);
1197 if (!buffer) { 1197 if (!buffer) {
1198 snd_usbmidi_out_endpoint_delete(ep); 1198 snd_usbmidi_out_endpoint_delete(ep);
1199 return -ENOMEM; 1199 return -ENOMEM;
diff --git a/sound/usb/misc/ua101.c b/sound/usb/misc/ua101.c
index 796d8b25ee89..fb5d68fa7ff4 100644
--- a/sound/usb/misc/ua101.c
+++ b/sound/usb/misc/ua101.c
@@ -42,7 +42,7 @@ MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101},{Edirol,UA-1000}}");
42/* 42/*
43 * This magic value optimizes memory usage efficiency for the UA-101's packet 43 * This magic value optimizes memory usage efficiency for the UA-101's packet
44 * sizes at all sample rates, taking into account the stupid cache pool sizes 44 * sizes at all sample rates, taking into account the stupid cache pool sizes
45 * that usb_buffer_alloc() uses. 45 * that usb_alloc_coherent() uses.
46 */ 46 */
47#define DEFAULT_QUEUE_LENGTH 21 47#define DEFAULT_QUEUE_LENGTH 21
48 48
@@ -1057,7 +1057,7 @@ static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1057 (unsigned int)MAX_QUEUE_LENGTH); 1057 (unsigned int)MAX_QUEUE_LENGTH);
1058 1058
1059 /* 1059 /*
1060 * The cache pool sizes used by usb_buffer_alloc() (128, 512, 2048) are 1060 * The cache pool sizes used by usb_alloc_coherent() (128, 512, 2048) are
1061 * quite bad when used with the packet sizes of this device (e.g. 280, 1061 * quite bad when used with the packet sizes of this device (e.g. 280,
1062 * 520, 624). Therefore, we allocate and subdivide entire pages, using 1062 * 520, 624). Therefore, we allocate and subdivide entire pages, using
1063 * a smaller buffer only for the last chunk. 1063 * a smaller buffer only for the last chunk.
@@ -1068,8 +1068,8 @@ static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1068 packets = min(remaining_packets, packets_per_page); 1068 packets = min(remaining_packets, packets_per_page);
1069 size = packets * stream->max_packet_bytes; 1069 size = packets * stream->max_packet_bytes;
1070 stream->buffers[i].addr = 1070 stream->buffers[i].addr =
1071 usb_buffer_alloc(ua->dev, size, GFP_KERNEL, 1071 usb_alloc_coherent(ua->dev, size, GFP_KERNEL,
1072 &stream->buffers[i].dma); 1072 &stream->buffers[i].dma);
1073 if (!stream->buffers[i].addr) 1073 if (!stream->buffers[i].addr)
1074 return -ENOMEM; 1074 return -ENOMEM;
1075 stream->buffers[i].size = size; 1075 stream->buffers[i].size = size;
@@ -1089,10 +1089,10 @@ static void free_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1089 unsigned int i; 1089 unsigned int i;
1090 1090
1091 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) 1091 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i)
1092 usb_buffer_free(ua->dev, 1092 usb_free_coherent(ua->dev,
1093 stream->buffers[i].size, 1093 stream->buffers[i].size,
1094 stream->buffers[i].addr, 1094 stream->buffers[i].addr,
1095 stream->buffers[i].dma); 1095 stream->buffers[i].dma);
1096} 1096}
1097 1097
1098static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream, 1098static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
new file mode 100644
index 000000000000..bbe2e3a2ea62
--- /dev/null
+++ b/tools/usb/ffs-test.c
@@ -0,0 +1,554 @@
1/*
2 * ffs-test.c.c -- user mode filesystem api for usb composite function
3 *
4 * Copyright (C) 2010 Samsung Electronics
5 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/* $(CROSS_COMPILE)cc -Wall -Wextra -g -o ffs-test ffs-test.c -lpthread */
23
24
25#define _BSD_SOURCE /* for endian.h */
26
27#include <endian.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <pthread.h>
31#include <stdarg.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <sys/ioctl.h>
36#include <sys/stat.h>
37#include <sys/types.h>
38#include <unistd.h>
39
40#include <linux/usb/functionfs.h>
41
42
43/******************** Little Endian Handling ********************************/
44
45#define cpu_to_le16(x) htole16(x)
46#define cpu_to_le32(x) htole32(x)
47#define le32_to_cpu(x) le32toh(x)
48#define le16_to_cpu(x) le16toh(x)
49
50static inline __u16 get_unaligned_le16(const void *_ptr)
51{
52 const __u8 *ptr = _ptr;
53 return ptr[0] | (ptr[1] << 8);
54}
55
56static inline __u32 get_unaligned_le32(const void *_ptr)
57{
58 const __u8 *ptr = _ptr;
59 return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
60}
61
62static inline void put_unaligned_le16(__u16 val, void *_ptr)
63{
64 __u8 *ptr = _ptr;
65 *ptr++ = val;
66 *ptr++ = val >> 8;
67}
68
69static inline void put_unaligned_le32(__u32 val, void *_ptr)
70{
71 __u8 *ptr = _ptr;
72 *ptr++ = val;
73 *ptr++ = val >> 8;
74 *ptr++ = val >> 16;
75 *ptr++ = val >> 24;
76}
77
78
79/******************** Messages and Errors ***********************************/
80
81static const char argv0[] = "ffs-test";
82
83static unsigned verbosity = 7;
84
85static void _msg(unsigned level, const char *fmt, ...)
86{
87 if (level < 2)
88 level = 2;
89 else if (level > 7)
90 level = 7;
91
92 if (level <= verbosity) {
93 static const char levels[8][6] = {
94 [2] = "crit:",
95 [3] = "err: ",
96 [4] = "warn:",
97 [5] = "note:",
98 [6] = "info:",
99 [7] = "dbg: "
100 };
101
102 int _errno = errno;
103 va_list ap;
104
105 fprintf(stderr, "%s: %s ", argv0, levels[level]);
106 va_start(ap, fmt);
107 vfprintf(stderr, fmt, ap);
108 va_end(ap);
109
110 if (fmt[strlen(fmt) - 1] != '\n') {
111 char buffer[128];
112 strerror_r(_errno, buffer, sizeof buffer);
113 fprintf(stderr, ": (-%d) %s\n", _errno, buffer);
114 }
115
116 fflush(stderr);
117 }
118}
119
120#define die(...) (_msg(2, __VA_ARGS__), exit(1))
121#define err(...) _msg(3, __VA_ARGS__)
122#define warn(...) _msg(4, __VA_ARGS__)
123#define note(...) _msg(5, __VA_ARGS__)
124#define info(...) _msg(6, __VA_ARGS__)
125#define debug(...) _msg(7, __VA_ARGS__)
126
127#define die_on(cond, ...) do { \
128 if (cond) \
129 die(__VA_ARGS__); \
130 } while (0)
131
132
133/******************** Descriptors and Strings *******************************/
134
135static const struct {
136 struct usb_functionfs_descs_head header;
137 struct {
138 struct usb_interface_descriptor intf;
139 struct usb_endpoint_descriptor_no_audio sink;
140 struct usb_endpoint_descriptor_no_audio source;
141 } __attribute__((packed)) fs_descs, hs_descs;
142} __attribute__((packed)) descriptors = {
143 .header = {
144 .magic = cpu_to_le32(FUNCTIONFS_DESCRIPTORS_MAGIC),
145 .length = cpu_to_le32(sizeof descriptors),
146 .fs_count = 3,
147 .hs_count = 3,
148 },
149 .fs_descs = {
150 .intf = {
151 .bLength = sizeof descriptors.fs_descs.intf,
152 .bDescriptorType = USB_DT_INTERFACE,
153 .bNumEndpoints = 2,
154 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
155 .iInterface = 1,
156 },
157 .sink = {
158 .bLength = sizeof descriptors.fs_descs.sink,
159 .bDescriptorType = USB_DT_ENDPOINT,
160 .bEndpointAddress = 1 | USB_DIR_IN,
161 .bmAttributes = USB_ENDPOINT_XFER_BULK,
162 /* .wMaxPacketSize = autoconfiguration (kernel) */
163 },
164 .source = {
165 .bLength = sizeof descriptors.fs_descs.source,
166 .bDescriptorType = USB_DT_ENDPOINT,
167 .bEndpointAddress = 2 | USB_DIR_OUT,
168 .bmAttributes = USB_ENDPOINT_XFER_BULK,
169 /* .wMaxPacketSize = autoconfiguration (kernel) */
170 },
171 },
172 .hs_descs = {
173 .intf = {
174 .bLength = sizeof descriptors.fs_descs.intf,
175 .bDescriptorType = USB_DT_INTERFACE,
176 .bNumEndpoints = 2,
177 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
178 .iInterface = 1,
179 },
180 .sink = {
181 .bLength = sizeof descriptors.hs_descs.sink,
182 .bDescriptorType = USB_DT_ENDPOINT,
183 .bEndpointAddress = 1 | USB_DIR_IN,
184 .bmAttributes = USB_ENDPOINT_XFER_BULK,
185 .wMaxPacketSize = cpu_to_le16(512),
186 },
187 .source = {
188 .bLength = sizeof descriptors.hs_descs.source,
189 .bDescriptorType = USB_DT_ENDPOINT,
190 .bEndpointAddress = 2 | USB_DIR_OUT,
191 .bmAttributes = USB_ENDPOINT_XFER_BULK,
192 .wMaxPacketSize = cpu_to_le16(512),
193 .bInterval = 1, /* NAK every 1 uframe */
194 },
195 },
196};
197
198
199#define STR_INTERFACE_ "Source/Sink"
200
201static const struct {
202 struct usb_functionfs_strings_head header;
203 struct {
204 __le16 code;
205 const char str1[sizeof STR_INTERFACE_];
206 } __attribute__((packed)) lang0;
207} __attribute__((packed)) strings = {
208 .header = {
209 .magic = cpu_to_le32(FUNCTIONFS_STRINGS_MAGIC),
210 .length = cpu_to_le32(sizeof strings),
211 .str_count = cpu_to_le32(1),
212 .lang_count = cpu_to_le32(1),
213 },
214 .lang0 = {
215 cpu_to_le16(0x0409), /* en-us */
216 STR_INTERFACE_,
217 },
218};
219
220#define STR_INTERFACE strings.lang0.str1
221
222
223/******************** Files and Threads Handling ****************************/
224
225struct thread;
226
227static ssize_t read_wrap(struct thread *t, void *buf, size_t nbytes);
228static ssize_t write_wrap(struct thread *t, const void *buf, size_t nbytes);
229static ssize_t ep0_consume(struct thread *t, const void *buf, size_t nbytes);
230static ssize_t fill_in_buf(struct thread *t, void *buf, size_t nbytes);
231static ssize_t empty_out_buf(struct thread *t, const void *buf, size_t nbytes);
232
233
234static struct thread {
235 const char *const filename;
236 size_t buf_size;
237
238 ssize_t (*in)(struct thread *, void *, size_t);
239 const char *const in_name;
240
241 ssize_t (*out)(struct thread *, const void *, size_t);
242 const char *const out_name;
243
244 int fd;
245 pthread_t id;
246 void *buf;
247 ssize_t status;
248} threads[] = {
249 {
250 "ep0", 4 * sizeof(struct usb_functionfs_event),
251 read_wrap, NULL,
252 ep0_consume, "<consume>",
253 0, 0, NULL, 0
254 },
255 {
256 "ep1", 8 * 1024,
257 fill_in_buf, "<in>",
258 write_wrap, NULL,
259 0, 0, NULL, 0
260 },
261 {
262 "ep2", 8 * 1024,
263 read_wrap, NULL,
264 empty_out_buf, "<out>",
265 0, 0, NULL, 0
266 },
267};
268
269
270static void init_thread(struct thread *t)
271{
272 t->buf = malloc(t->buf_size);
273 die_on(!t->buf, "malloc");
274
275 t->fd = open(t->filename, O_RDWR);
276 die_on(t->fd < 0, "%s", t->filename);
277}
278
279static void cleanup_thread(void *arg)
280{
281 struct thread *t = arg;
282 int ret, fd;
283
284 fd = t->fd;
285 if (t->fd < 0)
286 return;
287 t->fd = -1;
288
289 /* test the FIFO ioctls (non-ep0 code paths) */
290 if (t != threads) {
291 ret = ioctl(fd, FUNCTIONFS_FIFO_STATUS);
292 if (ret < 0) {
293 /* ENODEV reported after disconnect */
294 if (errno != ENODEV)
295 err("%s: get fifo status", t->filename);
296 } else if (ret) {
297 warn("%s: unclaimed = %d\n", t->filename, ret);
298 if (ioctl(fd, FUNCTIONFS_FIFO_FLUSH) < 0)
299 err("%s: fifo flush", t->filename);
300 }
301 }
302
303 if (close(fd) < 0)
304 err("%s: close", t->filename);
305
306 free(t->buf);
307 t->buf = NULL;
308}
309
310static void *start_thread_helper(void *arg)
311{
312 const char *name, *op, *in_name, *out_name;
313 struct thread *t = arg;
314 ssize_t ret;
315
316 info("%s: starts\n", t->filename);
317 in_name = t->in_name ? t->in_name : t->filename;
318 out_name = t->out_name ? t->out_name : t->filename;
319
320 pthread_cleanup_push(cleanup_thread, arg);
321
322 for (;;) {
323 pthread_testcancel();
324
325 ret = t->in(t, t->buf, t->buf_size);
326 if (ret > 0) {
327 ret = t->out(t, t->buf, t->buf_size);
328 name = out_name;
329 op = "write";
330 } else {
331 name = in_name;
332 op = "read";
333 }
334
335 if (ret > 0) {
336 /* nop */
337 } else if (!ret) {
338 debug("%s: %s: EOF", name, op);
339 break;
340 } else if (errno == EINTR || errno == EAGAIN) {
341 debug("%s: %s", name, op);
342 } else {
343 warn("%s: %s", name, op);
344 break;
345 }
346 }
347
348 pthread_cleanup_pop(1);
349
350 t->status = ret;
351 info("%s: ends\n", t->filename);
352 return NULL;
353}
354
355static void start_thread(struct thread *t)
356{
357 debug("%s: starting\n", t->filename);
358
359 die_on(pthread_create(&t->id, NULL, start_thread_helper, t) < 0,
360 "pthread_create(%s)", t->filename);
361}
362
363static void join_thread(struct thread *t)
364{
365 int ret = pthread_join(t->id, NULL);
366
367 if (ret < 0)
368 err("%s: joining thread", t->filename);
369 else
370 debug("%s: joined\n", t->filename);
371}
372
373
374static ssize_t read_wrap(struct thread *t, void *buf, size_t nbytes)
375{
376 return read(t->fd, buf, nbytes);
377}
378
379static ssize_t write_wrap(struct thread *t, const void *buf, size_t nbytes)
380{
381 return write(t->fd, buf, nbytes);
382}
383
384
385/******************** Empty/Fill buffer routines ****************************/
386
387/* 0 -- stream of zeros, 1 -- i % 63, 2 -- pipe */
388enum pattern { PAT_ZERO, PAT_SEQ, PAT_PIPE };
389static enum pattern pattern;
390
391static ssize_t
392fill_in_buf(struct thread *ignore, void *buf, size_t nbytes)
393{
394 size_t i;
395 __u8 *p;
396
397 (void)ignore;
398
399 switch (pattern) {
400 case PAT_ZERO:
401 memset(buf, 0, nbytes);
402 break;
403
404 case PAT_SEQ:
405 for (p = buf, i = 0; i < nbytes; ++i, ++p)
406 *p = i % 63;
407 break;
408
409 case PAT_PIPE:
410 return fread(buf, 1, nbytes, stdin);
411 }
412
413 return nbytes;
414}
415
416static ssize_t
417empty_out_buf(struct thread *ignore, const void *buf, size_t nbytes)
418{
419 const __u8 *p;
420 __u8 expected;
421 ssize_t ret;
422 size_t len;
423
424 (void)ignore;
425
426 switch (pattern) {
427 case PAT_ZERO:
428 expected = 0;
429 for (p = buf, len = 0; len < nbytes; ++p, ++len)
430 if (*p)
431 goto invalid;
432 break;
433
434 case PAT_SEQ:
435 for (p = buf, len = 0; len < nbytes; ++p, ++len)
436 if (*p != len % 63) {
437 expected = len % 63;
438 goto invalid;
439 }
440 break;
441
442 case PAT_PIPE:
443 ret = fwrite(buf, nbytes, 1, stdout);
444 if (ret > 0)
445 fflush(stdout);
446 break;
447
448invalid:
449 err("bad OUT byte %zd, expected %02x got %02x\n",
450 len, expected, *p);
451 for (p = buf, len = 0; len < nbytes; ++p, ++len) {
452 if (0 == (len % 32))
453 fprintf(stderr, "%4d:", len);
454 fprintf(stderr, " %02x", *p);
455 if (31 == (len % 32))
456 fprintf(stderr, "\n");
457 }
458 fflush(stderr);
459 errno = EILSEQ;
460 return -1;
461 }
462
463 return len;
464}
465
466
467/******************** Endpoints routines ************************************/
468
469static void handle_setup(const struct usb_ctrlrequest *setup)
470{
471 printf("bRequestType = %d\n", setup->bRequestType);
472 printf("bRequest = %d\n", setup->bRequest);
473 printf("wValue = %d\n", le16_to_cpu(setup->wValue));
474 printf("wIndex = %d\n", le16_to_cpu(setup->wIndex));
475 printf("wLength = %d\n", le16_to_cpu(setup->wLength));
476}
477
478static ssize_t
479ep0_consume(struct thread *ignore, const void *buf, size_t nbytes)
480{
481 static const char *const names[] = {
482 [FUNCTIONFS_BIND] = "BIND",
483 [FUNCTIONFS_UNBIND] = "UNBIND",
484 [FUNCTIONFS_ENABLE] = "ENABLE",
485 [FUNCTIONFS_DISABLE] = "DISABLE",
486 [FUNCTIONFS_SETUP] = "SETUP",
487 [FUNCTIONFS_SUSPEND] = "SUSPEND",
488 [FUNCTIONFS_RESUME] = "RESUME",
489 };
490
491 const struct usb_functionfs_event *event = buf;
492 size_t n;
493
494 (void)ignore;
495
496 for (n = nbytes / sizeof *event; n; --n, ++event)
497 switch (event->type) {
498 case FUNCTIONFS_BIND:
499 case FUNCTIONFS_UNBIND:
500 case FUNCTIONFS_ENABLE:
501 case FUNCTIONFS_DISABLE:
502 case FUNCTIONFS_SETUP:
503 case FUNCTIONFS_SUSPEND:
504 case FUNCTIONFS_RESUME:
505 printf("Event %s\n", names[event->type]);
506 if (event->type == FUNCTIONFS_SETUP)
507 handle_setup(&event->u.setup);
508 break;
509
510 default:
511 printf("Event %03u (unknown)\n", event->type);
512 }
513
514 return nbytes;
515}
516
517static void ep0_init(struct thread *t)
518{
519 ssize_t ret;
520
521 info("%s: writing descriptors\n", t->filename);
522 ret = write(t->fd, &descriptors, sizeof descriptors);
523 die_on(ret < 0, "%s: write: descriptors", t->filename);
524
525 info("%s: writing strings\n", t->filename);
526 ret = write(t->fd, &strings, sizeof strings);
527 die_on(ret < 0, "%s: write: strings", t->filename);
528}
529
530
531/******************** Main **************************************************/
532
533int main(void)
534{
535 unsigned i;
536
537 /* XXX TODO: Argument parsing missing */
538
539 init_thread(threads);
540 ep0_init(threads);
541
542 for (i = 1; i < sizeof threads / sizeof *threads; ++i)
543 init_thread(threads + i);
544
545 for (i = 1; i < sizeof threads / sizeof *threads; ++i)
546 start_thread(threads + i);
547
548 start_thread_helper(threads);
549
550 for (i = 1; i < sizeof threads / sizeof *threads; ++i)
551 join_thread(threads + i);
552
553 return 0;
554}
diff --git a/tools/usb/testusb.c b/tools/usb/testusb.c
new file mode 100644
index 000000000000..f08e89463842
--- /dev/null
+++ b/tools/usb/testusb.c
@@ -0,0 +1,547 @@
1/* $(CROSS_COMPILE)cc -Wall -Wextra -g -lpthread -o testusb testusb.c */
2
3/*
4 * Copyright (c) 2002 by David Brownell
5 * Copyright (c) 2010 by Samsung Electronics
6 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * 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 Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23/*
24 * This program issues ioctls to perform the tests implemented by the
25 * kernel driver. It can generate a variety of transfer patterns; you
26 * should make sure to test both regular streaming and mixes of
27 * transfer sizes (including short transfers).
28 *
29 * For more information on how this can be used and on USB testing
30 * refer to <URL:http://www.linux-usb.org/usbtest/>.
31 */
32
33#include <stdio.h>
34#include <string.h>
35#include <ftw.h>
36#include <stdlib.h>
37#include <pthread.h>
38#include <unistd.h>
39#include <errno.h>
40#include <limits.h>
41
42#include <sys/types.h>
43#include <sys/stat.h>
44#include <fcntl.h>
45
46#include <sys/ioctl.h>
47#include <linux/usbdevice_fs.h>
48
49/*-------------------------------------------------------------------------*/
50
51#define TEST_CASES 30
52
53// FIXME make these public somewhere; usbdevfs.h?
54
55struct usbtest_param {
56 // inputs
57 unsigned test_num; /* 0..(TEST_CASES-1) */
58 unsigned iterations;
59 unsigned length;
60 unsigned vary;
61 unsigned sglen;
62
63 // outputs
64 struct timeval duration;
65};
66#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
67
68/*-------------------------------------------------------------------------*/
69
70/* #include <linux/usb_ch9.h> */
71
72#define USB_DT_DEVICE 0x01
73#define USB_DT_INTERFACE 0x04
74
75#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
76#define USB_CLASS_VENDOR_SPEC 0xff
77
78
79struct usb_device_descriptor {
80 __u8 bLength;
81 __u8 bDescriptorType;
82 __u16 bcdUSB;
83 __u8 bDeviceClass;
84 __u8 bDeviceSubClass;
85 __u8 bDeviceProtocol;
86 __u8 bMaxPacketSize0;
87 __u16 idVendor;
88 __u16 idProduct;
89 __u16 bcdDevice;
90 __u8 iManufacturer;
91 __u8 iProduct;
92 __u8 iSerialNumber;
93 __u8 bNumConfigurations;
94} __attribute__ ((packed));
95
96struct usb_interface_descriptor {
97 __u8 bLength;
98 __u8 bDescriptorType;
99
100 __u8 bInterfaceNumber;
101 __u8 bAlternateSetting;
102 __u8 bNumEndpoints;
103 __u8 bInterfaceClass;
104 __u8 bInterfaceSubClass;
105 __u8 bInterfaceProtocol;
106 __u8 iInterface;
107} __attribute__ ((packed));
108
109enum usb_device_speed {
110 USB_SPEED_UNKNOWN = 0, /* enumerating */
111 USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
112 USB_SPEED_HIGH /* usb 2.0 */
113};
114
115/*-------------------------------------------------------------------------*/
116
117static char *speed (enum usb_device_speed s)
118{
119 switch (s) {
120 case USB_SPEED_UNKNOWN: return "unknown";
121 case USB_SPEED_LOW: return "low";
122 case USB_SPEED_FULL: return "full";
123 case USB_SPEED_HIGH: return "high";
124 default: return "??";
125 }
126}
127
128struct testdev {
129 struct testdev *next;
130 char *name;
131 pthread_t thread;
132 enum usb_device_speed speed;
133 unsigned ifnum : 8;
134 unsigned forever : 1;
135 int test;
136
137 struct usbtest_param param;
138};
139static struct testdev *testdevs;
140
141static int testdev_ffs_ifnum(FILE *fd)
142{
143 union {
144 char buf[255];
145 struct usb_interface_descriptor intf;
146 } u;
147
148 for (;;) {
149 if (fread(u.buf, 1, 1, fd) != 1)
150 return -1;
151 if (fread(u.buf + 1, (unsigned char)u.buf[0] - 1, 1, fd) != 1)
152 return -1;
153
154 if (u.intf.bLength == sizeof u.intf
155 && u.intf.bDescriptorType == USB_DT_INTERFACE
156 && u.intf.bNumEndpoints == 2
157 && u.intf.bInterfaceClass == USB_CLASS_VENDOR_SPEC
158 && u.intf.bInterfaceSubClass == 0
159 && u.intf.bInterfaceProtocol == 0)
160 return (unsigned char)u.intf.bInterfaceNumber;
161 }
162}
163
164static int testdev_ifnum(FILE *fd)
165{
166 struct usb_device_descriptor dev;
167
168 if (fread(&dev, sizeof dev, 1, fd) != 1)
169 return -1;
170
171 if (dev.bLength != sizeof dev || dev.bDescriptorType != USB_DT_DEVICE)
172 return -1;
173
174 /* FX2 with (tweaked) bulksrc firmware */
175 if (dev.idVendor == 0x0547 && dev.idProduct == 0x1002)
176 return 0;
177
178 /*----------------------------------------------------*/
179
180 /* devices that start up using the EZ-USB default device and
181 * which we can use after loading simple firmware. hotplug
182 * can fxload it, and then run this test driver.
183 *
184 * we return false positives in two cases:
185 * - the device has a "real" driver (maybe usb-serial) that
186 * renumerates. the device should vanish quickly.
187 * - the device doesn't have the test firmware installed.
188 */
189
190 /* generic EZ-USB FX controller */
191 if (dev.idVendor == 0x0547 && dev.idProduct == 0x2235)
192 return 0;
193
194 /* generic EZ-USB FX2 controller */
195 if (dev.idVendor == 0x04b4 && dev.idProduct == 0x8613)
196 return 0;
197
198 /* CY3671 development board with EZ-USB FX */
199 if (dev.idVendor == 0x0547 && dev.idProduct == 0x0080)
200 return 0;
201
202 /* Keyspan 19Qi uses an21xx (original EZ-USB) */
203 if (dev.idVendor == 0x06cd && dev.idProduct == 0x010b)
204 return 0;
205
206 /*----------------------------------------------------*/
207
208 /* "gadget zero", Linux-USB test software */
209 if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a0)
210 return 0;
211
212 /* user mode subset of that */
213 if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a4)
214 return testdev_ffs_ifnum(fd);
215 /* return 0; */
216
217 /* iso version of usermode code */
218 if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4a3)
219 return 0;
220
221 /* some GPL'd test firmware uses these IDs */
222
223 if (dev.idVendor == 0xfff0 && dev.idProduct == 0xfff0)
224 return 0;
225
226 /*----------------------------------------------------*/
227
228 /* iBOT2 high speed webcam */
229 if (dev.idVendor == 0x0b62 && dev.idProduct == 0x0059)
230 return 0;
231
232 /*----------------------------------------------------*/
233
234 /* the FunctionFS gadget can have the source/sink interface
235 * anywhere. We look for an interface descriptor that match
236 * what we expect. We ignore configuratiens thou. */
237
238 if (dev.idVendor == 0x0525 && dev.idProduct == 0xa4ac
239 && (dev.bDeviceClass == USB_CLASS_PER_INTERFACE
240 || dev.bDeviceClass == USB_CLASS_VENDOR_SPEC))
241 return testdev_ffs_ifnum(fd);
242
243 return -1;
244}
245
246static int find_testdev(const char *name, const struct stat *sb, int flag)
247{
248 FILE *fd;
249 int ifnum;
250 struct testdev *entry;
251
252 (void)sb; /* unused */
253
254 if (flag != FTW_F)
255 return 0;
256 /* ignore /proc/bus/usb/{devices,drivers} */
257 if (strrchr(name, '/')[1] == 'd')
258 return 0;
259
260 fd = fopen(name, "rb");
261 if (!fd) {
262 perror(name);
263 return 0;
264 }
265
266 ifnum = testdev_ifnum(fd);
267 fclose(fd);
268 if (ifnum < 0)
269 return 0;
270
271 entry = calloc(1, sizeof *entry);
272 if (!entry)
273 goto nomem;
274
275 entry->name = strdup(name);
276 if (!entry->name) {
277 free(entry);
278nomem:
279 perror("malloc");
280 return 0;
281 }
282
283 entry->ifnum = ifnum;
284
285 /* FIXME ask usbfs what speed; update USBDEVFS_CONNECTINFO so
286 * it tells about high speed etc */
287
288 fprintf(stderr, "%s speed\t%s\t%u\n",
289 speed(entry->speed), entry->name, entry->ifnum);
290
291 entry->next = testdevs;
292 testdevs = entry;
293 return 0;
294}
295
296static int
297usbdev_ioctl (int fd, int ifno, unsigned request, void *param)
298{
299 struct usbdevfs_ioctl wrapper;
300
301 wrapper.ifno = ifno;
302 wrapper.ioctl_code = request;
303 wrapper.data = param;
304
305 return ioctl (fd, USBDEVFS_IOCTL, &wrapper);
306}
307
308static void *handle_testdev (void *arg)
309{
310 struct testdev *dev = arg;
311 int fd, i;
312 int status;
313
314 if ((fd = open (dev->name, O_RDWR)) < 0) {
315 perror ("can't open dev file r/w");
316 return 0;
317 }
318
319restart:
320 for (i = 0; i < TEST_CASES; i++) {
321 if (dev->test != -1 && dev->test != i)
322 continue;
323 dev->param.test_num = i;
324
325 status = usbdev_ioctl (fd, dev->ifnum,
326 USBTEST_REQUEST, &dev->param);
327 if (status < 0 && errno == EOPNOTSUPP)
328 continue;
329
330 /* FIXME need a "syslog it" option for background testing */
331
332 /* NOTE: each thread emits complete lines; no fragments! */
333 if (status < 0) {
334 char buf [80];
335 int err = errno;
336
337 if (strerror_r (errno, buf, sizeof buf)) {
338 snprintf (buf, sizeof buf, "error %d", err);
339 errno = err;
340 }
341 printf ("%s test %d --> %d (%s)\n",
342 dev->name, i, errno, buf);
343 } else
344 printf ("%s test %d, %4d.%.06d secs\n", dev->name, i,
345 (int) dev->param.duration.tv_sec,
346 (int) dev->param.duration.tv_usec);
347
348 fflush (stdout);
349 }
350 if (dev->forever)
351 goto restart;
352
353 close (fd);
354 return arg;
355}
356
357static const char *usbfs_dir_find(void)
358{
359 static char usbfs_path_0[] = "/dev/usb/devices";
360 static char usbfs_path_1[] = "/proc/bus/usb/devices";
361
362 static char *const usbfs_paths[] = {
363 usbfs_path_0, usbfs_path_1
364 };
365
366 static char *const *
367 end = usbfs_paths + sizeof usbfs_paths / sizeof *usbfs_paths;
368
369 char *const *it = usbfs_paths;
370 do {
371 int fd = open(*it, O_RDONLY);
372 close(fd);
373 if (fd >= 0) {
374 strrchr(*it, '/')[0] = '\0';
375 return *it;
376 }
377 } while (++it != end);
378
379 return NULL;
380}
381
382static int parse_num(unsigned *num, const char *str)
383{
384 unsigned long val;
385 char *end;
386
387 errno = 0;
388 val = strtoul(str, &end, 0);
389 if (errno || *end || val > UINT_MAX)
390 return -1;
391 *num = val;
392 return 0;
393}
394
395int main (int argc, char **argv)
396{
397
398 int c;
399 struct testdev *entry;
400 char *device;
401 const char *usbfs_dir = NULL;
402 int all = 0, forever = 0, not = 0;
403 int test = -1 /* all */;
404 struct usbtest_param param;
405
406 /* pick defaults that works with all speeds, without short packets.
407 *
408 * Best per-frame data rates:
409 * high speed, bulk 512 * 13 * 8 = 53248
410 * interrupt 1024 * 3 * 8 = 24576
411 * full speed, bulk/intr 64 * 19 = 1216
412 * interrupt 64 * 1 = 64
413 * low speed, interrupt 8 * 1 = 8
414 */
415 param.iterations = 1000;
416 param.length = 512;
417 param.vary = 512;
418 param.sglen = 32;
419
420 /* for easy use when hotplugging */
421 device = getenv ("DEVICE");
422
423 while ((c = getopt (argc, argv, "D:aA:c:g:hns:t:v:")) != EOF)
424 switch (c) {
425 case 'D': /* device, if only one */
426 device = optarg;
427 continue;
428 case 'A': /* use all devices with specified usbfs dir */
429 usbfs_dir = optarg;
430 /* FALL THROUGH */
431 case 'a': /* use all devices */
432 device = NULL;
433 all = 1;
434 continue;
435 case 'c': /* count iterations */
436 if (parse_num(&param.iterations, optarg))
437 goto usage;
438 continue;
439 case 'g': /* scatter/gather entries */
440 if (parse_num(&param.sglen, optarg))
441 goto usage;
442 continue;
443 case 'l': /* loop forever */
444 forever = 1;
445 continue;
446 case 'n': /* no test running! */
447 not = 1;
448 continue;
449 case 's': /* size of packet */
450 if (parse_num(&param.length, optarg))
451 goto usage;
452 continue;
453 case 't': /* run just one test */
454 test = atoi (optarg);
455 if (test < 0)
456 goto usage;
457 continue;
458 case 'v': /* vary packet size by ... */
459 if (parse_num(&param.vary, optarg))
460 goto usage;
461 continue;
462 case '?':
463 case 'h':
464 default:
465usage:
466 fprintf (stderr, "usage: %s [-n] [-D dev | -a | -A usbfs-dir]\n"
467 "\t[-c iterations] [-t testnum]\n"
468 "\t[-s packetsize] [-g sglen] [-v vary]\n",
469 argv [0]);
470 return 1;
471 }
472 if (optind != argc)
473 goto usage;
474 if (!all && !device) {
475 fprintf (stderr, "must specify '-a' or '-D dev', "
476 "or DEVICE=/proc/bus/usb/BBB/DDD in env\n");
477 goto usage;
478 }
479
480 /* Find usbfs mount point */
481 if (!usbfs_dir) {
482 usbfs_dir = usbfs_dir_find();
483 if (!usbfs_dir) {
484 fputs ("usbfs files are missing\n", stderr);
485 return -1;
486 }
487 }
488
489 /* collect and list the test devices */
490 if (ftw (usbfs_dir, find_testdev, 3) != 0) {
491 fputs ("ftw failed; is usbfs missing?\n", stderr);
492 return -1;
493 }
494
495 /* quit, run single test, or create test threads */
496 if (!testdevs && !device) {
497 fputs ("no test devices recognized\n", stderr);
498 return -1;
499 }
500 if (not)
501 return 0;
502 if (testdevs && testdevs->next == 0 && !device)
503 device = testdevs->name;
504 for (entry = testdevs; entry; entry = entry->next) {
505 int status;
506
507 entry->param = param;
508 entry->forever = forever;
509 entry->test = test;
510
511 if (device) {
512 if (strcmp (entry->name, device))
513 continue;
514 return handle_testdev (entry) != entry;
515 }
516 status = pthread_create (&entry->thread, 0, handle_testdev, entry);
517 if (status) {
518 perror ("pthread_create");
519 continue;
520 }
521 }
522 if (device) {
523 struct testdev dev;
524
525 /* kernel can recognize test devices we don't */
526 fprintf (stderr, "%s: %s may see only control tests\n",
527 argv [0], device);
528
529 memset (&dev, 0, sizeof dev);
530 dev.name = device;
531 dev.param = param;
532 dev.forever = forever;
533 dev.test = test;
534 return handle_testdev (&dev) != &dev;
535 }
536
537 /* wait for tests to complete */
538 for (entry = testdevs; entry; entry = entry->next) {
539 void *retval;
540
541 if (pthread_join (entry->thread, &retval))
542 perror ("pthread_join");
543 /* testing errors discarded! */
544 }
545
546 return 0;
547}