aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/Kconfig4
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/atm/cxacru.c192
-rw-r--r--drivers/usb/atm/speedtch.c1
-rw-r--r--drivers/usb/atm/ueagle-atm.c10
-rw-r--r--drivers/usb/atm/usbatm.c3
-rw-r--r--drivers/usb/atm/usbatm.h15
-rw-r--r--drivers/usb/c67x00/c67x00-drv.c9
-rw-r--r--drivers/usb/c67x00/c67x00-sched.c1
-rw-r--r--drivers/usb/class/cdc-acm.c143
-rw-r--r--drivers/usb/class/cdc-acm.h2
-rw-r--r--drivers/usb/class/cdc-wdm.c136
-rw-r--r--drivers/usb/class/usblp.c22
-rw-r--r--drivers/usb/class/usbtmc.c59
-rw-r--r--drivers/usb/core/Kconfig6
-rw-r--r--drivers/usb/core/devices.c87
-rw-r--r--drivers/usb/core/devio.c290
-rw-r--r--drivers/usb/core/driver.c1101
-rw-r--r--drivers/usb/core/endpoint.c2
-rw-r--r--drivers/usb/core/file.c4
-rw-r--r--drivers/usb/core/generic.c4
-rw-r--r--drivers/usb/core/hcd-pci.c129
-rw-r--r--drivers/usb/core/hcd.c125
-rw-r--r--drivers/usb/core/hcd.h34
-rw-r--r--drivers/usb/core/hub.c301
-rw-r--r--drivers/usb/core/inode.c5
-rw-r--r--drivers/usb/core/message.c96
-rw-r--r--drivers/usb/core/quirks.c18
-rw-r--r--drivers/usb/core/sysfs.c156
-rw-r--r--drivers/usb/core/urb.c30
-rw-r--r--drivers/usb/core/usb.c130
-rw-r--r--drivers/usb/core/usb.h44
-rw-r--r--drivers/usb/early/ehci-dbgp.c70
-rw-r--r--drivers/usb/gadget/Kconfig70
-rw-r--r--drivers/usb/gadget/Makefile6
-rw-r--r--drivers/usb/gadget/at91_udc.c25
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c10
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h1
-rw-r--r--drivers/usb/gadget/audio.c116
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c1
-rw-r--r--drivers/usb/gadget/composite.c59
-rw-r--r--drivers/usb/gadget/config.c1
-rw-r--r--drivers/usb/gadget/epautoconf.c24
-rw-r--r--drivers/usb/gadget/ether.c14
-rw-r--r--drivers/usb/gadget/f_acm.c39
-rw-r--r--drivers/usb/gadget/f_audio.c98
-rw-r--r--drivers/usb/gadget/f_ecm.c8
-rw-r--r--drivers/usb/gadget/f_eem.c4
-rw-r--r--drivers/usb/gadget/f_loopback.c1
-rw-r--r--drivers/usb/gadget/f_mass_storage.c3098
-rw-r--r--drivers/usb/gadget/f_obex.c1
-rw-r--r--drivers/usb/gadget/f_phonet.c1
-rw-r--r--drivers/usb/gadget/f_rndis.c40
-rw-r--r--drivers/usb/gadget/f_serial.c1
-rw-r--r--drivers/usb/gadget/f_sourcesink.c1
-rw-r--r--drivers/usb/gadget/f_subset.c1
-rw-r--r--drivers/usb/gadget/file_storage.c891
-rw-r--r--drivers/usb/gadget/fsl_mx3_udc.c31
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c2
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.h15
-rw-r--r--drivers/usb/gadget/gadget_chips.h67
-rw-r--r--drivers/usb/gadget/gmidi.c8
-rw-r--r--drivers/usb/gadget/goku_udc.c4
-rw-r--r--drivers/usb/gadget/imx_udc.c1
-rw-r--r--drivers/usb/gadget/inode.c39
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c1
-rw-r--r--drivers/usb/gadget/m66592-udc.c1
-rw-r--r--drivers/usb/gadget/mass_storage.c246
-rw-r--r--drivers/usb/gadget/multi.c356
-rw-r--r--drivers/usb/gadget/nokia.c259
-rw-r--r--drivers/usb/gadget/omap_udc.c25
-rw-r--r--drivers/usb/gadget/printer.c18
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c4
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c138
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h6
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c2
-rw-r--r--drivers/usb/gadget/rndis.c1
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c22
-rw-r--r--drivers/usb/gadget/storage_common.c778
-rw-r--r--drivers/usb/gadget/u_audio.c13
-rw-r--r--drivers/usb/gadget/u_audio.h2
-rw-r--r--drivers/usb/gadget/u_ether.c6
-rw-r--r--drivers/usb/gadget/u_ether.h9
-rw-r--r--drivers/usb/gadget/u_serial.c1
-rw-r--r--drivers/usb/gadget/zero.c7
-rw-r--r--drivers/usb/host/Kconfig33
-rw-r--r--drivers/usb/host/Makefile6
-rw-r--r--drivers/usb/host/ehci-atmel.c2
-rw-r--r--drivers/usb/host/ehci-au1xxx.c8
-rw-r--r--drivers/usb/host/ehci-fsl.c97
-rw-r--r--drivers/usb/host/ehci-hcd.c31
-rw-r--r--drivers/usb/host/ehci-hub.c37
-rw-r--r--drivers/usb/host/ehci-mem.c2
-rw-r--r--drivers/usb/host/ehci-mxc.c296
-rw-r--r--drivers/usb/host/ehci-omap.c794
-rw-r--r--drivers/usb/host/ehci-orion.c8
-rw-r--r--drivers/usb/host/ehci-ppc-of.c14
-rw-r--r--drivers/usb/host/ehci-q.c43
-rw-r--r--drivers/usb/host/ehci-sched.c114
-rw-r--r--drivers/usb/host/ehci-xilinx-of.c300
-rw-r--r--drivers/usb/host/ehci.h10
-rw-r--r--drivers/usb/host/fhci-hcd.c8
-rw-r--r--drivers/usb/host/fhci-mem.c1
-rw-r--r--drivers/usb/host/fhci-q.c1
-rw-r--r--drivers/usb/host/fhci-sched.c12
-rw-r--r--drivers/usb/host/fhci-tds.c42
-rw-r--r--drivers/usb/host/fhci.h16
-rw-r--r--drivers/usb/host/hwa-hc.c1
-rw-r--r--drivers/usb/host/imx21-dbg.c527
-rw-r--r--drivers/usb/host/imx21-hcd.c1790
-rw-r--r--drivers/usb/host/imx21-hcd.h436
-rw-r--r--drivers/usb/host/isp116x-hcd.c1
-rw-r--r--drivers/usb/host/isp1362-hcd.c66
-rw-r--r--drivers/usb/host/isp1362.h4
-rw-r--r--drivers/usb/host/isp1760-hcd.c16
-rw-r--r--drivers/usb/host/isp1760-if.c2
-rw-r--r--drivers/usb/host/ohci-at91.c12
-rw-r--r--drivers/usb/host/ohci-au1xxx.c2
-rw-r--r--drivers/usb/host/ohci-da8xx.c456
-rw-r--r--drivers/usb/host/ohci-dbg.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c5
-rw-r--r--drivers/usb/host/ohci-hub.c2
-rw-r--r--drivers/usb/host/ohci-lh7a404.c11
-rw-r--r--drivers/usb/host/ohci-omap.c6
-rw-r--r--drivers/usb/host/ohci-pnx4008.c14
-rw-r--r--drivers/usb/host/ohci-ppc-of.c10
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c8
-rw-r--r--drivers/usb/host/ohci-pxa27x.c2
-rw-r--r--drivers/usb/host/ohci-q.c1
-rw-r--r--drivers/usb/host/ohci-sa1111.c8
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c6
-rw-r--r--drivers/usb/host/r8a66597-hcd.c81
-rw-r--r--drivers/usb/host/sl811-hcd.c11
-rw-r--r--drivers/usb/host/sl811_cs.c49
-rw-r--r--drivers/usb/host/uhci-debug.c1
-rw-r--r--drivers/usb/host/uhci-hcd.c16
-rw-r--r--drivers/usb/host/uhci-hub.c2
-rw-r--r--drivers/usb/host/whci/asl.c1
-rw-r--r--drivers/usb/host/whci/debug.c21
-rw-r--r--drivers/usb/host/whci/hcd.c1
-rw-r--r--drivers/usb/host/whci/init.c1
-rw-r--r--drivers/usb/host/whci/pzl.c1
-rw-r--r--drivers/usb/host/whci/qset.c351
-rw-r--r--drivers/usb/host/whci/whcd.h9
-rw-r--r--drivers/usb/host/whci/whci-hc.h14
-rw-r--r--drivers/usb/host/xhci-dbg.c19
-rw-r--r--drivers/usb/host/xhci-ext-caps.h7
-rw-r--r--drivers/usb/host/xhci-hub.c65
-rw-r--r--drivers/usb/host/xhci-mem.c373
-rw-r--r--drivers/usb/host/xhci-pci.c3
-rw-r--r--drivers/usb/host/xhci-ring.c371
-rw-r--r--drivers/usb/host/xhci.c (renamed from drivers/usb/host/xhci-hcd.c)255
-rw-r--r--drivers/usb/host/xhci.h52
-rw-r--r--drivers/usb/image/mdc800.c2
-rw-r--r--drivers/usb/image/microtek.c4
-rw-r--r--drivers/usb/misc/Kconfig25
-rw-r--r--drivers/usb/misc/Makefile2
-rw-r--r--drivers/usb/misc/adutux.c8
-rw-r--r--drivers/usb/misc/appledisplay.c18
-rw-r--r--drivers/usb/misc/berry_charge.c183
-rw-r--r--drivers/usb/misc/cypress_cy7c63.c3
-rw-r--r--drivers/usb/misc/cytherm.c3
-rw-r--r--drivers/usb/misc/emi26.c2
-rw-r--r--drivers/usb/misc/emi62.c4
-rw-r--r--drivers/usb/misc/ftdi-elan.c11
-rw-r--r--drivers/usb/misc/idmouse.c2
-rw-r--r--drivers/usb/misc/iowarrior.c6
-rw-r--r--drivers/usb/misc/isight_firmware.c5
-rw-r--r--drivers/usb/misc/ldusb.c4
-rw-r--r--drivers/usb/misc/legousbtower.c13
-rw-r--r--drivers/usb/misc/rio500.c11
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c21
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_con.c1
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_init.c1
-rw-r--r--drivers/usb/misc/trancevibrator.c3
-rw-r--r--drivers/usb/misc/usblcd.c7
-rw-r--r--drivers/usb/misc/usbled.c2
-rw-r--r--drivers/usb/misc/usbsevseg.c17
-rw-r--r--drivers/usb/misc/usbtest.c13
-rw-r--r--drivers/usb/misc/uss720.c3
-rw-r--r--drivers/usb/misc/vstusb.c783
-rw-r--r--drivers/usb/mon/mon_bin.c59
-rw-r--r--drivers/usb/mon/mon_main.c1
-rw-r--r--drivers/usb/mon/mon_stat.c1
-rw-r--r--drivers/usb/mon/mon_text.c30
-rw-r--r--drivers/usb/musb/Kconfig13
-rw-r--r--drivers/usb/musb/Makefile2
-rw-r--r--drivers/usb/musb/blackfin.c153
-rw-r--r--drivers/usb/musb/blackfin.h39
-rw-r--r--drivers/usb/musb/cppi_dma.c40
-rw-r--r--drivers/usb/musb/davinci.c7
-rw-r--r--drivers/usb/musb/musb_core.c672
-rw-r--r--drivers/usb/musb/musb_core.h68
-rw-r--r--drivers/usb/musb/musb_dma.h11
-rw-r--r--drivers/usb/musb/musb_gadget.c222
-rw-r--r--drivers/usb/musb/musb_gadget.h4
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c84
-rw-r--r--drivers/usb/musb/musb_host.c47
-rw-r--r--drivers/usb/musb/musb_regs.h135
-rw-r--r--drivers/usb/musb/musb_virthub.c1
-rw-r--r--drivers/usb/musb/musbhsdma.c38
-rw-r--r--drivers/usb/musb/musbhsdma.h17
-rw-r--r--drivers/usb/musb/omap2430.c54
-rw-r--r--drivers/usb/musb/omap2430.h34
-rw-r--r--drivers/usb/musb/tusb6010.c15
-rw-r--r--drivers/usb/musb/tusb6010_omap.c29
-rw-r--r--drivers/usb/otg/Kconfig10
-rw-r--r--drivers/usb/otg/Makefile1
-rw-r--r--drivers/usb/otg/gpio_vbus.c1
-rw-r--r--drivers/usb/otg/isp1301_omap.c8
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c1
-rw-r--r--drivers/usb/otg/twl4030-usb.c86
-rw-r--r--drivers/usb/otg/ulpi.c137
-rw-r--r--drivers/usb/serial/Kconfig19
-rw-r--r--drivers/usb/serial/Makefile2
-rw-r--r--drivers/usb/serial/aircable.c37
-rw-r--r--drivers/usb/serial/ark3116.c977
-rw-r--r--drivers/usb/serial/belkin_sa.c2
-rw-r--r--drivers/usb/serial/bus.c1
-rw-r--r--drivers/usb/serial/ch341.c28
-rw-r--r--drivers/usb/serial/console.c1
-rw-r--r--drivers/usb/serial/cp210x.c12
-rw-r--r--drivers/usb/serial/cyberjack.c5
-rw-r--r--drivers/usb/serial/cypress_m8.c84
-rw-r--r--drivers/usb/serial/digi_acceleport.c38
-rw-r--r--drivers/usb/serial/empeg.c3
-rw-r--r--drivers/usb/serial/ftdi_sio.c256
-rw-r--r--drivers/usb/serial/ftdi_sio.h951
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h1026
-rw-r--r--drivers/usb/serial/funsoft.c2
-rw-r--r--drivers/usb/serial/garmin_gps.c3
-rw-r--r--drivers/usb/serial/generic.c76
-rw-r--r--drivers/usb/serial/hp4x.c2
-rw-r--r--drivers/usb/serial/io_edgeport.c69
-rw-r--r--drivers/usb/serial/io_tables.h10
-rw-r--r--drivers/usb/serial/io_ti.c75
-rw-r--r--drivers/usb/serial/ipaq.c1
-rw-r--r--drivers/usb/serial/ipw.c3
-rw-r--r--drivers/usb/serial/ir-usb.c13
-rw-r--r--drivers/usb/serial/iuu_phoenix.c2
-rw-r--r--drivers/usb/serial/keyspan.c57
-rw-r--r--drivers/usb/serial/keyspan.h10
-rw-r--r--drivers/usb/serial/keyspan_pda.c60
-rw-r--r--drivers/usb/serial/kl5kusb105.c66
-rw-r--r--drivers/usb/serial/kobil_sct.c25
-rw-r--r--drivers/usb/serial/mct_u232.c57
-rw-r--r--drivers/usb/serial/mct_u232.h2
-rw-r--r--drivers/usb/serial/mos7720.c185
-rw-r--r--drivers/usb/serial/mos7840.c56
-rw-r--r--drivers/usb/serial/moto_modem.c2
-rw-r--r--drivers/usb/serial/navman.c4
-rw-r--r--drivers/usb/serial/omninet.c8
-rw-r--r--drivers/usb/serial/opticon.c27
-rw-r--r--drivers/usb/serial/option.c177
-rw-r--r--drivers/usb/serial/oti6858.c36
-rw-r--r--drivers/usb/serial/pl2303.c40
-rw-r--r--drivers/usb/serial/pl2303.h5
-rw-r--r--drivers/usb/serial/qcaux.c106
-rw-r--r--drivers/usb/serial/qcserial.c31
-rw-r--r--drivers/usb/serial/safe_serial.c2
-rw-r--r--drivers/usb/serial/siemens_mpi.c2
-rw-r--r--drivers/usb/serial/sierra.c153
-rw-r--r--drivers/usb/serial/spcp8x5.c27
-rw-r--r--drivers/usb/serial/symbolserial.c15
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c29
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.h3
-rw-r--r--drivers/usb/serial/usb-serial.c105
-rw-r--r--drivers/usb/serial/usb_debug.c3
-rw-r--r--drivers/usb/serial/visor.c40
-rw-r--r--drivers/usb/serial/vivopay-serial.c76
-rw-r--r--drivers/usb/serial/whiteheat.c24
-rw-r--r--drivers/usb/storage/alauda.c1
-rw-r--r--drivers/usb/storage/karma.c1
-rw-r--r--drivers/usb/storage/onetouch.c2
-rw-r--r--drivers/usb/storage/option_ms.c1
-rw-r--r--drivers/usb/storage/scsiglue.c20
-rw-r--r--drivers/usb/storage/shuttle_usbat.c15
-rw-r--r--drivers/usb/storage/sierra_ms.c1
-rw-r--r--drivers/usb/storage/transport.c25
-rw-r--r--drivers/usb/storage/unusual_devs.h127
-rw-r--r--drivers/usb/storage/usb.c48
-rw-r--r--drivers/usb/storage/usb.h1
-rw-r--r--drivers/usb/usb-skeleton.c6
-rw-r--r--drivers/usb/wusbcore/cbaf.c3
-rw-r--r--drivers/usb/wusbcore/crypto.c3
-rw-r--r--drivers/usb/wusbcore/devconnect.c12
-rw-r--r--drivers/usb/wusbcore/mmc.c3
-rw-r--r--drivers/usb/wusbcore/rh.c1
-rw-r--r--drivers/usb/wusbcore/security.c7
-rw-r--r--drivers/usb/wusbcore/wa-hc.c1
-rw-r--r--drivers/usb/wusbcore/wa-nep.c1
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c1
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c5
-rw-r--r--drivers/usb/wusbcore/wusbhc.c32
-rw-r--r--drivers/usb/wusbcore/wusbhc.h3
295 files changed, 18743 insertions, 6657 deletions
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 240750881d28..6a58cb1330c1 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -21,6 +21,7 @@ config USB_ARCH_HAS_HCD
21 default y if USB_ARCH_HAS_EHCI 21 default y if USB_ARCH_HAS_EHCI
22 default y if PCMCIA && !M32R # sl811_cs 22 default y if PCMCIA && !M32R # sl811_cs
23 default y if ARM # SL-811 23 default y if ARM # SL-811
24 default y if BLACKFIN # SL-811
24 default y if SUPERH # r8a66597-hcd 25 default y if SUPERH # r8a66597-hcd
25 default PCI 26 default PCI
26 27
@@ -39,6 +40,7 @@ config USB_ARCH_HAS_OHCI
39 default y if ARCH_PNX4008 && I2C 40 default y if ARCH_PNX4008 && I2C
40 default y if MFD_TC6393XB 41 default y if MFD_TC6393XB
41 default y if ARCH_W90X900 42 default y if ARCH_W90X900
43 default y if ARCH_DAVINCI_DA8XX
42 # PPC: 44 # PPC:
43 default y if STB03xxx 45 default y if STB03xxx
44 default y if PPC_MPC52xx 46 default y if PPC_MPC52xx
@@ -60,6 +62,8 @@ config USB_ARCH_HAS_EHCI
60 default y if ARCH_IXP4XX 62 default y if ARCH_IXP4XX
61 default y if ARCH_W90X900 63 default y if ARCH_W90X900
62 default y if ARCH_AT91SAM9G45 64 default y if ARCH_AT91SAM9G45
65 default y if ARCH_MXC
66 default y if ARCH_OMAP3
63 default PCI 67 default PCI
64 68
65# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. 69# ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface.
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index be3c9b80bc9f..80b4008c89ba 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_USB_U132_HCD) += host/
21obj-$(CONFIG_USB_R8A66597_HCD) += host/ 21obj-$(CONFIG_USB_R8A66597_HCD) += host/
22obj-$(CONFIG_USB_HWA_HCD) += host/ 22obj-$(CONFIG_USB_HWA_HCD) += host/
23obj-$(CONFIG_USB_ISP1760_HCD) += host/ 23obj-$(CONFIG_USB_ISP1760_HCD) += host/
24obj-$(CONFIG_USB_IMX21_HCD) += host/
24 25
25obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ 26obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
26 27
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 56802d2e994b..c89990f5e018 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -5,6 +5,7 @@
5 * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan 5 * Copyright (C) 2004 David Woodhouse, Duncan Sands, Roman Kagan
6 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru) 6 * Copyright (C) 2005 Duncan Sands, Roman Kagan (rkagan % mail ! ru)
7 * Copyright (C) 2007 Simon Arlott 7 * Copyright (C) 2007 Simon Arlott
8 * Copyright (C) 2009 Simon Arlott
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free 11 * under the terms of the GNU General Public License as published by the Free
@@ -43,7 +44,7 @@
43#include "usbatm.h" 44#include "usbatm.h"
44 45
45#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott" 46#define DRIVER_AUTHOR "Roman Kagan, David Woodhouse, Duncan Sands, Simon Arlott"
46#define DRIVER_VERSION "0.3" 47#define DRIVER_VERSION "0.4"
47#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver" 48#define DRIVER_DESC "Conexant AccessRunner ADSL USB modem driver"
48 49
49static const char cxacru_driver_name[] = "cxacru"; 50static const char cxacru_driver_name[] = "cxacru";
@@ -52,6 +53,7 @@ static const char cxacru_driver_name[] = "cxacru";
52#define CXACRU_EP_DATA 0x02 /* Bulk in/out */ 53#define CXACRU_EP_DATA 0x02 /* Bulk in/out */
53 54
54#define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */ 55#define CMD_PACKET_SIZE 64 /* Should be maxpacket(ep)? */
56#define CMD_MAX_CONFIG ((CMD_PACKET_SIZE / 4 - 1) / 2)
55 57
56/* Addresses */ 58/* Addresses */
57#define PLLFCLK_ADDR 0x00350068 59#define PLLFCLK_ADDR 0x00350068
@@ -105,6 +107,26 @@ enum cxacru_cm_request {
105 CM_REQUEST_MAX, 107 CM_REQUEST_MAX,
106}; 108};
107 109
110/* commands for interaction with the flash memory
111 *
112 * read: response is the contents of the first 60 bytes of flash memory
113 * write: request contains the 60 bytes of data to write to flash memory
114 * response is the contents of the first 60 bytes of flash memory
115 *
116 * layout: PP PP VV VV MM MM MM MM MM MM ?? ?? SS SS SS SS SS SS SS SS
117 * SS SS SS SS SS SS SS SS 00 00 00 00 00 00 00 00 00 00 00 00
118 * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
119 *
120 * P: le16 USB Product ID
121 * V: le16 USB Vendor ID
122 * M: be48 MAC Address
123 * S: le16 ASCII Serial Number
124 */
125enum cxacru_cm_flash {
126 CM_FLASH_READ = 0xa1,
127 CM_FLASH_WRITE = 0xa2
128};
129
108/* reply codes to the commands above */ 130/* reply codes to the commands above */
109enum cxacru_cm_status { 131enum cxacru_cm_status {
110 CM_STATUS_UNDEFINED, 132 CM_STATUS_UNDEFINED,
@@ -196,23 +218,32 @@ static DEVICE_ATTR(_name, S_IRUGO, cxacru_sysfs_show_##_name, NULL)
196static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \ 218static DEVICE_ATTR(_name, S_IWUSR | S_IRUGO, \
197 cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name) 219 cxacru_sysfs_show_##_name, cxacru_sysfs_store_##_name)
198 220
221#define CXACRU_SET_INIT(_name) \
222static DEVICE_ATTR(_name, S_IWUSR, \
223 NULL, cxacru_sysfs_store_##_name)
224
199#define CXACRU_ATTR_INIT(_value, _type, _name) \ 225#define CXACRU_ATTR_INIT(_value, _type, _name) \
200static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \ 226static ssize_t cxacru_sysfs_show_##_name(struct device *dev, \
201 struct device_attribute *attr, char *buf) \ 227 struct device_attribute *attr, char *buf) \
202{ \ 228{ \
203 struct usb_interface *intf = to_usb_interface(dev); \ 229 struct cxacru_data *instance = to_usbatm_driver_data(\
204 struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); \ 230 to_usb_interface(dev)); \
205 struct cxacru_data *instance = usbatm_instance->driver_data; \ 231\
232 if (instance == NULL) \
233 return -ENODEV; \
234\
206 return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \ 235 return cxacru_sysfs_showattr_##_type(instance->card_info[_value], buf); \
207} \ 236} \
208CXACRU__ATTR_INIT(_name) 237CXACRU__ATTR_INIT(_name)
209 238
210#define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name) 239#define CXACRU_ATTR_CREATE(_v, _t, _name) CXACRU_DEVICE_CREATE_FILE(_name)
211#define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name) 240#define CXACRU_CMD_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
241#define CXACRU_SET_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
212#define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name) 242#define CXACRU__ATTR_CREATE(_name) CXACRU_DEVICE_CREATE_FILE(_name)
213 243
214#define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name) 244#define CXACRU_ATTR_REMOVE(_v, _t, _name) CXACRU_DEVICE_REMOVE_FILE(_name)
215#define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name) 245#define CXACRU_CMD_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
246#define CXACRU_SET_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
216#define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name) 247#define CXACRU__ATTR_REMOVE(_name) CXACRU_DEVICE_REMOVE_FILE(_name)
217 248
218static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf) 249static ssize_t cxacru_sysfs_showattr_u32(u32 value, char *buf)
@@ -267,12 +298,12 @@ static ssize_t cxacru_sysfs_showattr_LINE(u32 value, char *buf)
267static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf) 298static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
268{ 299{
269 static char *str[] = { 300 static char *str[] = {
270 NULL, 301 "",
271 "ANSI T1.413", 302 "ANSI T1.413",
272 "ITU-T G.992.1 (G.DMT)", 303 "ITU-T G.992.1 (G.DMT)",
273 "ITU-T G.992.2 (G.LITE)" 304 "ITU-T G.992.2 (G.LITE)"
274 }; 305 };
275 if (unlikely(value >= ARRAY_SIZE(str) || str[value] == NULL)) 306 if (unlikely(value >= ARRAY_SIZE(str)))
276 return snprintf(buf, PAGE_SIZE, "%u\n", value); 307 return snprintf(buf, PAGE_SIZE, "%u\n", value);
277 return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); 308 return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
278} 309}
@@ -288,22 +319,28 @@ static ssize_t cxacru_sysfs_showattr_MODU(u32 value, char *buf)
288static ssize_t cxacru_sysfs_show_mac_address(struct device *dev, 319static ssize_t cxacru_sysfs_show_mac_address(struct device *dev,
289 struct device_attribute *attr, char *buf) 320 struct device_attribute *attr, char *buf)
290{ 321{
291 struct usb_interface *intf = to_usb_interface(dev); 322 struct cxacru_data *instance = to_usbatm_driver_data(
292 struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); 323 to_usb_interface(dev));
293 struct atm_dev *atm_dev = usbatm_instance->atm_dev;
294 324
295 return snprintf(buf, PAGE_SIZE, "%pM\n", atm_dev->esi); 325 if (instance == NULL || instance->usbatm->atm_dev == NULL)
326 return -ENODEV;
327
328 return snprintf(buf, PAGE_SIZE, "%pM\n",
329 instance->usbatm->atm_dev->esi);
296} 330}
297 331
298static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev, 332static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
299 struct device_attribute *attr, char *buf) 333 struct device_attribute *attr, char *buf)
300{ 334{
301 struct usb_interface *intf = to_usb_interface(dev);
302 struct usbatm_data *usbatm_instance = usb_get_intfdata(intf);
303 struct cxacru_data *instance = usbatm_instance->driver_data;
304 u32 value = instance->card_info[CXINF_LINE_STARTABLE];
305
306 static char *str[] = { "running", "stopped" }; 335 static char *str[] = { "running", "stopped" };
336 struct cxacru_data *instance = to_usbatm_driver_data(
337 to_usb_interface(dev));
338 u32 value;
339
340 if (instance == NULL)
341 return -ENODEV;
342
343 value = instance->card_info[CXINF_LINE_STARTABLE];
307 if (unlikely(value >= ARRAY_SIZE(str))) 344 if (unlikely(value >= ARRAY_SIZE(str)))
308 return snprintf(buf, PAGE_SIZE, "%u\n", value); 345 return snprintf(buf, PAGE_SIZE, "%u\n", value);
309 return snprintf(buf, PAGE_SIZE, "%s\n", str[value]); 346 return snprintf(buf, PAGE_SIZE, "%s\n", str[value]);
@@ -312,9 +349,8 @@ static ssize_t cxacru_sysfs_show_adsl_state(struct device *dev,
312static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev, 349static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
313 struct device_attribute *attr, const char *buf, size_t count) 350 struct device_attribute *attr, const char *buf, size_t count)
314{ 351{
315 struct usb_interface *intf = to_usb_interface(dev); 352 struct cxacru_data *instance = to_usbatm_driver_data(
316 struct usbatm_data *usbatm_instance = usb_get_intfdata(intf); 353 to_usb_interface(dev));
317 struct cxacru_data *instance = usbatm_instance->driver_data;
318 int ret; 354 int ret;
319 int poll = -1; 355 int poll = -1;
320 char str_cmd[8]; 356 char str_cmd[8];
@@ -328,13 +364,16 @@ static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
328 return -EINVAL; 364 return -EINVAL;
329 ret = 0; 365 ret = 0;
330 366
367 if (instance == NULL)
368 return -ENODEV;
369
331 if (mutex_lock_interruptible(&instance->adsl_state_serialize)) 370 if (mutex_lock_interruptible(&instance->adsl_state_serialize))
332 return -ERESTARTSYS; 371 return -ERESTARTSYS;
333 372
334 if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) { 373 if (!strcmp(str_cmd, "stop") || !strcmp(str_cmd, "restart")) {
335 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0); 374 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_STOP, NULL, 0, NULL, 0);
336 if (ret < 0) { 375 if (ret < 0) {
337 atm_err(usbatm_instance, "change adsl state:" 376 atm_err(instance->usbatm, "change adsl state:"
338 " CHIP_ADSL_LINE_STOP returned %d\n", ret); 377 " CHIP_ADSL_LINE_STOP returned %d\n", ret);
339 378
340 ret = -EIO; 379 ret = -EIO;
@@ -354,7 +393,7 @@ static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
354 if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) { 393 if (!strcmp(str_cmd, "start") || !strcmp(str_cmd, "restart")) {
355 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0); 394 ret = cxacru_cm(instance, CM_REQUEST_CHIP_ADSL_LINE_START, NULL, 0, NULL, 0);
356 if (ret < 0) { 395 if (ret < 0) {
357 atm_err(usbatm_instance, "change adsl state:" 396 atm_err(instance->usbatm, "change adsl state:"
358 " CHIP_ADSL_LINE_START returned %d\n", ret); 397 " CHIP_ADSL_LINE_START returned %d\n", ret);
359 398
360 ret = -EIO; 399 ret = -EIO;
@@ -407,6 +446,72 @@ static ssize_t cxacru_sysfs_store_adsl_state(struct device *dev,
407 return ret; 446 return ret;
408} 447}
409 448
449/* CM_REQUEST_CARD_DATA_GET times out, so no show attribute */
450
451static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
452 struct device_attribute *attr, const char *buf, size_t count)
453{
454 struct cxacru_data *instance = to_usbatm_driver_data(
455 to_usb_interface(dev));
456 int len = strlen(buf);
457 int ret, pos, num;
458 __le32 data[CMD_PACKET_SIZE / 4];
459
460 if (!capable(CAP_NET_ADMIN))
461 return -EACCES;
462
463 if (instance == NULL)
464 return -ENODEV;
465
466 pos = 0;
467 num = 0;
468 while (pos < len) {
469 int tmp;
470 u32 index;
471 u32 value;
472
473 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
474 if (ret < 2)
475 return -EINVAL;
476 if (index < 0 || index > 0x7f)
477 return -EINVAL;
478 pos += tmp;
479
480 /* skip trailing newline */
481 if (buf[pos] == '\n' && pos == len-1)
482 pos++;
483
484 data[num * 2 + 1] = cpu_to_le32(index);
485 data[num * 2 + 2] = cpu_to_le32(value);
486 num++;
487
488 /* send config values when data buffer is full
489 * or no more data
490 */
491 if (pos >= len || num >= CMD_MAX_CONFIG) {
492 char log[CMD_MAX_CONFIG * 12 + 1]; /* %02x=%08x */
493
494 data[0] = cpu_to_le32(num);
495 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
496 (u8 *) data, 4 + num * 8, NULL, 0);
497 if (ret < 0) {
498 atm_err(instance->usbatm,
499 "set card data returned %d\n", ret);
500 return -EIO;
501 }
502
503 for (tmp = 0; tmp < num; tmp++)
504 snprintf(log + tmp*12, 13, " %02x=%08x",
505 le32_to_cpu(data[tmp * 2 + 1]),
506 le32_to_cpu(data[tmp * 2 + 2]));
507 atm_info(instance->usbatm, "config%s\n", log);
508 num = 0;
509 }
510 }
511
512 return len;
513}
514
410/* 515/*
411 * All device attributes are included in CXACRU_ALL_FILES 516 * All device attributes are included in CXACRU_ALL_FILES
412 * so that the same list can be used multiple times: 517 * so that the same list can be used multiple times:
@@ -442,7 +547,8 @@ CXACRU_ATTR_##_action(CXINF_MODULATION, MODU, modulation); \
442CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \ 547CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND, u32, adsl_headend); \
443CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \ 548CXACRU_ATTR_##_action(CXINF_ADSL_HEADEND_ENVIRONMENT, u32, adsl_headend_environment); \
444CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \ 549CXACRU_ATTR_##_action(CXINF_CONTROLLER_VERSION, u32, adsl_controller_version); \
445CXACRU_CMD_##_action( adsl_state); 550CXACRU_CMD_##_action( adsl_state); \
551CXACRU_SET_##_action( adsl_config);
446 552
447CXACRU_ALL_FILES(INIT); 553CXACRU_ALL_FILES(INIT);
448 554
@@ -596,7 +702,7 @@ static int cxacru_cm_get_array(struct cxacru_data *instance, enum cxacru_cm_requ
596 len = ret / 4; 702 len = ret / 4;
597 for (offb = 0; offb < len; ) { 703 for (offb = 0; offb < len; ) {
598 int l = le32_to_cpu(buf[offb++]); 704 int l = le32_to_cpu(buf[offb++]);
599 if (l > stride || l > (len - offb) / 2) { 705 if (l < 0 || l > stride || l > (len - offb) / 2) {
600 if (printk_ratelimit()) 706 if (printk_ratelimit())
601 usb_err(instance->usbatm, "invalid data length from cm %#x: %d\n", 707 usb_err(instance->usbatm, "invalid data length from cm %#x: %d\n",
602 cm, l); 708 cm, l);
@@ -649,9 +755,6 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
649{ 755{
650 struct cxacru_data *instance = usbatm_instance->driver_data; 756 struct cxacru_data *instance = usbatm_instance->driver_data;
651 struct usb_interface *intf = usbatm_instance->usb_intf; 757 struct usb_interface *intf = usbatm_instance->usb_intf;
652 /*
653 struct atm_dev *atm_dev = usbatm_instance->atm_dev;
654 */
655 int ret; 758 int ret;
656 int start_polling = 1; 759 int start_polling = 1;
657 760
@@ -697,6 +800,9 @@ static int cxacru_atm_start(struct usbatm_data *usbatm_instance,
697 mutex_unlock(&instance->poll_state_serialize); 800 mutex_unlock(&instance->poll_state_serialize);
698 mutex_unlock(&instance->adsl_state_serialize); 801 mutex_unlock(&instance->adsl_state_serialize);
699 802
803 printk(KERN_INFO "%s%d: %s %pM\n", atm_dev->type, atm_dev->number,
804 usbatm_instance->description, atm_dev->esi);
805
700 if (start_polling) 806 if (start_polling)
701 cxacru_poll_status(&instance->poll_work.work); 807 cxacru_poll_status(&instance->poll_work.work);
702 return 0; 808 return 0;
@@ -873,11 +979,9 @@ cleanup:
873 979
874static void cxacru_upload_firmware(struct cxacru_data *instance, 980static void cxacru_upload_firmware(struct cxacru_data *instance,
875 const struct firmware *fw, 981 const struct firmware *fw,
876 const struct firmware *bp, 982 const struct firmware *bp)
877 const struct firmware *cf)
878{ 983{
879 int ret; 984 int ret;
880 int off;
881 struct usbatm_data *usbatm = instance->usbatm; 985 struct usbatm_data *usbatm = instance->usbatm;
882 struct usb_device *usb_dev = usbatm->usb_dev; 986 struct usb_device *usb_dev = usbatm->usb_dev;
883 __le16 signature[] = { usb_dev->descriptor.idVendor, 987 __le16 signature[] = { usb_dev->descriptor.idVendor,
@@ -911,6 +1015,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
911 } 1015 }
912 1016
913 /* Firmware */ 1017 /* Firmware */
1018 usb_info(usbatm, "loading firmware\n");
914 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size); 1019 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, FW_ADDR, fw->data, fw->size);
915 if (ret) { 1020 if (ret) {
916 usb_err(usbatm, "Firmware upload failed: %d\n", ret); 1021 usb_err(usbatm, "Firmware upload failed: %d\n", ret);
@@ -919,6 +1024,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
919 1024
920 /* Boot ROM patch */ 1025 /* Boot ROM patch */
921 if (instance->modem_type->boot_rom_patch) { 1026 if (instance->modem_type->boot_rom_patch) {
1027 usb_info(usbatm, "loading boot ROM patch\n");
922 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size); 1028 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_ADDR, bp->data, bp->size);
923 if (ret) { 1029 if (ret) {
924 usb_err(usbatm, "Boot ROM patching failed: %d\n", ret); 1030 usb_err(usbatm, "Boot ROM patching failed: %d\n", ret);
@@ -933,6 +1039,7 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
933 return; 1039 return;
934 } 1040 }
935 1041
1042 usb_info(usbatm, "starting device\n");
936 if (instance->modem_type->boot_rom_patch) { 1043 if (instance->modem_type->boot_rom_patch) {
937 val = cpu_to_le32(BR_ADDR); 1044 val = cpu_to_le32(BR_ADDR);
938 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4); 1045 ret = cxacru_fw(usb_dev, FW_WRITE_MEM, 0x2, 0x0, BR_STACK_ADDR, (u8 *) &val, 4);
@@ -958,26 +1065,6 @@ static void cxacru_upload_firmware(struct cxacru_data *instance,
958 usb_err(usbatm, "modem failed to initialize: %d\n", ret); 1065 usb_err(usbatm, "modem failed to initialize: %d\n", ret);
959 return; 1066 return;
960 } 1067 }
961
962 /* Load config data (le32), doing one packet at a time */
963 if (cf)
964 for (off = 0; off < cf->size / 4; ) {
965 __le32 buf[CMD_PACKET_SIZE / 4 - 1];
966 int i, len = min_t(int, cf->size / 4 - off, CMD_PACKET_SIZE / 4 / 2 - 1);
967 buf[0] = cpu_to_le32(len);
968 for (i = 0; i < len; i++, off++) {
969 buf[i * 2 + 1] = cpu_to_le32(off);
970 memcpy(buf + i * 2 + 2, cf->data + off * 4, 4);
971 }
972 ret = cxacru_cm(instance, CM_REQUEST_CARD_DATA_SET,
973 (u8 *) buf, len, NULL, 0);
974 if (ret < 0) {
975 usb_err(usbatm, "load config data failed: %d\n", ret);
976 return;
977 }
978 }
979
980 msleep_interruptible(4000);
981} 1068}
982 1069
983static int cxacru_find_firmware(struct cxacru_data *instance, 1070static int cxacru_find_firmware(struct cxacru_data *instance,
@@ -1003,7 +1090,7 @@ static int cxacru_find_firmware(struct cxacru_data *instance,
1003static int cxacru_heavy_init(struct usbatm_data *usbatm_instance, 1090static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
1004 struct usb_interface *usb_intf) 1091 struct usb_interface *usb_intf)
1005{ 1092{
1006 const struct firmware *fw, *bp, *cf; 1093 const struct firmware *fw, *bp;
1007 struct cxacru_data *instance = usbatm_instance->driver_data; 1094 struct cxacru_data *instance = usbatm_instance->driver_data;
1008 1095
1009 int ret = cxacru_find_firmware(instance, "fw", &fw); 1096 int ret = cxacru_find_firmware(instance, "fw", &fw);
@@ -1021,13 +1108,8 @@ static int cxacru_heavy_init(struct usbatm_data *usbatm_instance,
1021 } 1108 }
1022 } 1109 }
1023 1110
1024 if (cxacru_find_firmware(instance, "cf", &cf)) /* optional */ 1111 cxacru_upload_firmware(instance, fw, bp);
1025 cf = NULL;
1026
1027 cxacru_upload_firmware(instance, fw, bp, cf);
1028 1112
1029 if (cf)
1030 release_firmware(cf);
1031 if (instance->modem_type->boot_rom_patch) 1113 if (instance->modem_type->boot_rom_patch)
1032 release_firmware(bp); 1114 release_firmware(bp);
1033 release_firmware(fw); 1115 release_firmware(fw);
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 3e862401a638..1e9ba4bdffef 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -27,7 +27,6 @@
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/firmware.h> 29#include <linux/firmware.h>
30#include <linux/gfp.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/module.h> 32#include <linux/module.h>
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index d171b563e94c..25f01b536f67 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -66,6 +66,7 @@
66#include <linux/kthread.h> 66#include <linux/kthread.h>
67#include <linux/mutex.h> 67#include <linux/mutex.h>
68#include <linux/freezer.h> 68#include <linux/freezer.h>
69#include <linux/slab.h>
69 70
70#include <asm/unaligned.h> 71#include <asm/unaligned.h>
71 72
@@ -667,12 +668,12 @@ static void uea_upload_pre_firmware(const struct firmware *fw_entry, void *conte
667 else 668 else
668 uea_info(usb, "firmware uploaded\n"); 669 uea_info(usb, "firmware uploaded\n");
669 670
670 uea_leaves(usb); 671 goto err;
671 return;
672 672
673err_fw_corrupted: 673err_fw_corrupted:
674 uea_err(usb, "firmware is corrupted\n"); 674 uea_err(usb, "firmware is corrupted\n");
675err: 675err:
676 release_firmware(fw_entry);
676 uea_leaves(usb); 677 uea_leaves(usb);
677} 678}
678 679
@@ -705,7 +706,8 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)
705 break; 706 break;
706 } 707 }
707 708
708 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev, usb, uea_upload_pre_firmware); 709 ret = request_firmware_nowait(THIS_MODULE, 1, fw_name, &usb->dev,
710 GFP_KERNEL, usb, uea_upload_pre_firmware);
709 if (ret) 711 if (ret)
710 uea_err(usb, "firmware %s is not available\n", fw_name); 712 uea_err(usb, "firmware %s is not available\n", fw_name);
711 else 713 else
@@ -1958,7 +1960,7 @@ static void uea_dispatch_cmv_e1(struct uea_softc *sc, struct intr_pkt *intr)
1958 goto bad1; 1960 goto bad1;
1959 1961
1960 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to 1962 /* FIXME : ADI930 reply wrong preambule (func = 2, sub = 2) to
1961 * the first MEMACESS cmv. Ignore it... 1963 * the first MEMACCESS cmv. Ignore it...
1962 */ 1964 */
1963 if (cmv->bFunction != dsc->function) { 1965 if (cmv->bFunction != dsc->function) {
1964 if (UEA_CHIP_VERSION(sc) == ADI930 1966 if (UEA_CHIP_VERSION(sc) == ADI930
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index fbea8563df1e..9b53e8df4648 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -1333,6 +1333,7 @@ void usbatm_usb_disconnect(struct usb_interface *intf)
1333 if (instance->atm_dev) { 1333 if (instance->atm_dev) {
1334 sysfs_remove_link(&instance->atm_dev->class_dev.kobj, "device"); 1334 sysfs_remove_link(&instance->atm_dev->class_dev.kobj, "device");
1335 atm_dev_deregister(instance->atm_dev); 1335 atm_dev_deregister(instance->atm_dev);
1336 instance->atm_dev = NULL;
1336 } 1337 }
1337 1338
1338 usbatm_put_instance(instance); /* taken in usbatm_usb_probe */ 1339 usbatm_put_instance(instance); /* taken in usbatm_usb_probe */
@@ -1348,7 +1349,7 @@ static int __init usbatm_usb_init(void)
1348{ 1349{
1349 dbg("%s: driver version %s", __func__, DRIVER_VERSION); 1350 dbg("%s: driver version %s", __func__, DRIVER_VERSION);
1350 1351
1351 if (sizeof(struct usbatm_control) > sizeof(((struct sk_buff *) 0)->cb)) { 1352 if (sizeof(struct usbatm_control) > FIELD_SIZEOF(struct sk_buff, cb)) {
1352 printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name); 1353 printk(KERN_ERR "%s unusable with this kernel!\n", usbatm_driver_name);
1353 return -EIO; 1354 return -EIO;
1354 } 1355 }
diff --git a/drivers/usb/atm/usbatm.h b/drivers/usb/atm/usbatm.h
index f6f4508a9d42..0863f85fcc26 100644
--- a/drivers/usb/atm/usbatm.h
+++ b/drivers/usb/atm/usbatm.h
@@ -204,4 +204,19 @@ struct usbatm_data {
204 struct urb *urbs[0]; 204 struct urb *urbs[0];
205}; 205};
206 206
207static inline void *to_usbatm_driver_data(struct usb_interface *intf)
208{
209 struct usbatm_data *usbatm_instance;
210
211 if (intf == NULL)
212 return NULL;
213
214 usbatm_instance = usb_get_intfdata(intf);
215
216 if (usbatm_instance == NULL) /* set NULL before unbind() */
217 return NULL;
218
219 return usbatm_instance->driver_data; /* set NULL after unbind() */
220}
221
207#endif /* _USBATM_H_ */ 222#endif /* _USBATM_H_ */
diff --git a/drivers/usb/c67x00/c67x00-drv.c b/drivers/usb/c67x00/c67x00-drv.c
index 5633bc5c8bf2..b6d49234e521 100644
--- a/drivers/usb/c67x00/c67x00-drv.c
+++ b/drivers/usb/c67x00/c67x00-drv.c
@@ -37,6 +37,7 @@
37#include <linux/device.h> 37#include <linux/device.h>
38#include <linux/io.h> 38#include <linux/io.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/slab.h>
40#include <linux/usb.h> 41#include <linux/usb.h>
41#include <linux/usb/c67x00.h> 42#include <linux/usb/c67x00.h>
42 43
@@ -137,13 +138,13 @@ static int __devinit c67x00_drv_probe(struct platform_device *pdev)
137 if (!c67x00) 138 if (!c67x00)
138 return -ENOMEM; 139 return -ENOMEM;
139 140
140 if (!request_mem_region(res->start, res->end - res->start + 1, 141 if (!request_mem_region(res->start, resource_size(res),
141 pdev->name)) { 142 pdev->name)) {
142 dev_err(&pdev->dev, "Memory region busy\n"); 143 dev_err(&pdev->dev, "Memory region busy\n");
143 ret = -EBUSY; 144 ret = -EBUSY;
144 goto request_mem_failed; 145 goto request_mem_failed;
145 } 146 }
146 c67x00->hpi.base = ioremap(res->start, res->end - res->start + 1); 147 c67x00->hpi.base = ioremap(res->start, resource_size(res));
147 if (!c67x00->hpi.base) { 148 if (!c67x00->hpi.base) {
148 dev_err(&pdev->dev, "Unable to map HPI registers\n"); 149 dev_err(&pdev->dev, "Unable to map HPI registers\n");
149 ret = -EIO; 150 ret = -EIO;
@@ -182,7 +183,7 @@ static int __devinit c67x00_drv_probe(struct platform_device *pdev)
182 request_irq_failed: 183 request_irq_failed:
183 iounmap(c67x00->hpi.base); 184 iounmap(c67x00->hpi.base);
184 map_failed: 185 map_failed:
185 release_mem_region(res->start, res->end - res->start + 1); 186 release_mem_region(res->start, resource_size(res));
186 request_mem_failed: 187 request_mem_failed:
187 kfree(c67x00); 188 kfree(c67x00);
188 189
@@ -208,7 +209,7 @@ static int __devexit c67x00_drv_remove(struct platform_device *pdev)
208 209
209 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 210 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
210 if (res) 211 if (res)
211 release_mem_region(res->start, res->end - res->start + 1); 212 release_mem_region(res->start, resource_size(res));
212 213
213 kfree(c67x00); 214 kfree(c67x00);
214 215
diff --git a/drivers/usb/c67x00/c67x00-sched.c b/drivers/usb/c67x00/c67x00-sched.c
index 85dfe2965661..f6b3c253f3fa 100644
--- a/drivers/usb/c67x00/c67x00-sched.c
+++ b/drivers/usb/c67x00/c67x00-sched.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/kthread.h> 24#include <linux/kthread.h>
25#include <linux/slab.h>
25 26
26#include "c67x00.h" 27#include "c67x00.h"
27#include "c67x00-hcd.h" 28#include "c67x00-hcd.h"
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index e4eca7810bcf..5e1a253b08a0 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -170,6 +170,7 @@ static void acm_write_done(struct acm *acm, struct acm_wb *wb)
170{ 170{
171 wb->use = 0; 171 wb->use = 0;
172 acm->transmitting--; 172 acm->transmitting--;
173 usb_autopm_put_interface_async(acm->control);
173} 174}
174 175
175/* 176/*
@@ -211,9 +212,12 @@ static int acm_write_start(struct acm *acm, int wbn)
211 } 212 }
212 213
213 dbg("%s susp_count: %d", __func__, acm->susp_count); 214 dbg("%s susp_count: %d", __func__, acm->susp_count);
215 usb_autopm_get_interface_async(acm->control);
214 if (acm->susp_count) { 216 if (acm->susp_count) {
215 acm->delayed_wb = wb; 217 if (!acm->delayed_wb)
216 schedule_work(&acm->waker); 218 acm->delayed_wb = wb;
219 else
220 usb_autopm_put_interface_async(acm->control);
217 spin_unlock_irqrestore(&acm->write_lock, flags); 221 spin_unlock_irqrestore(&acm->write_lock, flags);
218 return 0; /* A white lie */ 222 return 0; /* A white lie */
219 } 223 }
@@ -424,7 +428,6 @@ next_buffer:
424 throttled = acm->throttle; 428 throttled = acm->throttle;
425 spin_unlock_irqrestore(&acm->throttle_lock, flags); 429 spin_unlock_irqrestore(&acm->throttle_lock, flags);
426 if (!throttled) { 430 if (!throttled) {
427 tty_buffer_request_room(tty, buf->size);
428 tty_insert_flip_string(tty, buf->base, buf->size); 431 tty_insert_flip_string(tty, buf->base, buf->size);
429 tty_flip_buffer_push(tty); 432 tty_flip_buffer_push(tty);
430 } else { 433 } else {
@@ -534,23 +537,6 @@ static void acm_softint(struct work_struct *work)
534 tty_kref_put(tty); 537 tty_kref_put(tty);
535} 538}
536 539
537static void acm_waker(struct work_struct *waker)
538{
539 struct acm *acm = container_of(waker, struct acm, waker);
540 int rv;
541
542 rv = usb_autopm_get_interface(acm->control);
543 if (rv < 0) {
544 dev_err(&acm->dev->dev, "Autopm failure in %s\n", __func__);
545 return;
546 }
547 if (acm->delayed_wb) {
548 acm_start_wb(acm, acm->delayed_wb);
549 acm->delayed_wb = NULL;
550 }
551 usb_autopm_put_interface(acm->control);
552}
553
554/* 540/*
555 * TTY handlers 541 * TTY handlers
556 */ 542 */
@@ -566,7 +552,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
566 552
567 acm = acm_table[tty->index]; 553 acm = acm_table[tty->index];
568 if (!acm || !acm->dev) 554 if (!acm || !acm->dev)
569 goto err_out; 555 goto out;
570 else 556 else
571 rv = 0; 557 rv = 0;
572 558
@@ -582,8 +568,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
582 568
583 mutex_lock(&acm->mutex); 569 mutex_lock(&acm->mutex);
584 if (acm->port.count++) { 570 if (acm->port.count++) {
571 mutex_unlock(&acm->mutex);
585 usb_autopm_put_interface(acm->control); 572 usb_autopm_put_interface(acm->control);
586 goto done; 573 goto out;
587 } 574 }
588 575
589 acm->ctrlurb->dev = acm->dev; 576 acm->ctrlurb->dev = acm->dev;
@@ -612,18 +599,18 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
612 set_bit(ASYNCB_INITIALIZED, &acm->port.flags); 599 set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
613 rv = tty_port_block_til_ready(&acm->port, tty, filp); 600 rv = tty_port_block_til_ready(&acm->port, tty, filp);
614 tasklet_schedule(&acm->urb_task); 601 tasklet_schedule(&acm->urb_task);
615done: 602
616 mutex_unlock(&acm->mutex); 603 mutex_unlock(&acm->mutex);
617err_out: 604out:
618 mutex_unlock(&open_mutex); 605 mutex_unlock(&open_mutex);
619 return rv; 606 return rv;
620 607
621full_bailout: 608full_bailout:
622 usb_kill_urb(acm->ctrlurb); 609 usb_kill_urb(acm->ctrlurb);
623bail_out: 610bail_out:
624 usb_autopm_put_interface(acm->control);
625 acm->port.count--; 611 acm->port.count--;
626 mutex_unlock(&acm->mutex); 612 mutex_unlock(&acm->mutex);
613 usb_autopm_put_interface(acm->control);
627early_bail: 614early_bail:
628 mutex_unlock(&open_mutex); 615 mutex_unlock(&open_mutex);
629 tty_port_tty_set(&acm->port, NULL); 616 tty_port_tty_set(&acm->port, NULL);
@@ -1023,7 +1010,7 @@ static int acm_probe(struct usb_interface *intf,
1023 case USB_CDC_CALL_MANAGEMENT_TYPE: 1010 case USB_CDC_CALL_MANAGEMENT_TYPE:
1024 call_management_function = buffer[3]; 1011 call_management_function = buffer[3];
1025 call_interface_num = buffer[4]; 1012 call_interface_num = buffer[4];
1026 if ((call_management_function & 3) != 3) 1013 if ( (quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3)
1027 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); 1014 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
1028 break; 1015 break;
1029 default: 1016 default:
@@ -1178,7 +1165,6 @@ made_compressed_probe:
1178 acm->urb_task.func = acm_rx_tasklet; 1165 acm->urb_task.func = acm_rx_tasklet;
1179 acm->urb_task.data = (unsigned long) acm; 1166 acm->urb_task.data = (unsigned long) acm;
1180 INIT_WORK(&acm->work, acm_softint); 1167 INIT_WORK(&acm->work, acm_softint);
1181 INIT_WORK(&acm->waker, acm_waker);
1182 init_waitqueue_head(&acm->drain_wait); 1168 init_waitqueue_head(&acm->drain_wait);
1183 spin_lock_init(&acm->throttle_lock); 1169 spin_lock_init(&acm->throttle_lock);
1184 spin_lock_init(&acm->write_lock); 1170 spin_lock_init(&acm->write_lock);
@@ -1343,7 +1329,6 @@ static void stop_data_traffic(struct acm *acm)
1343 tasklet_enable(&acm->urb_task); 1329 tasklet_enable(&acm->urb_task);
1344 1330
1345 cancel_work_sync(&acm->work); 1331 cancel_work_sync(&acm->work);
1346 cancel_work_sync(&acm->waker);
1347} 1332}
1348 1333
1349static void acm_disconnect(struct usb_interface *intf) 1334static void acm_disconnect(struct usb_interface *intf)
@@ -1435,6 +1420,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1435static int acm_resume(struct usb_interface *intf) 1420static int acm_resume(struct usb_interface *intf)
1436{ 1421{
1437 struct acm *acm = usb_get_intfdata(intf); 1422 struct acm *acm = usb_get_intfdata(intf);
1423 struct acm_wb *wb;
1438 int rv = 0; 1424 int rv = 0;
1439 int cnt; 1425 int cnt;
1440 1426
@@ -1449,6 +1435,21 @@ static int acm_resume(struct usb_interface *intf)
1449 mutex_lock(&acm->mutex); 1435 mutex_lock(&acm->mutex);
1450 if (acm->port.count) { 1436 if (acm->port.count) {
1451 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); 1437 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
1438
1439 spin_lock_irq(&acm->write_lock);
1440 if (acm->delayed_wb) {
1441 wb = acm->delayed_wb;
1442 acm->delayed_wb = NULL;
1443 spin_unlock_irq(&acm->write_lock);
1444 acm_start_wb(acm, wb);
1445 } else {
1446 spin_unlock_irq(&acm->write_lock);
1447 }
1448
1449 /*
1450 * delayed error checking because we must
1451 * do the write path at all cost
1452 */
1452 if (rv < 0) 1453 if (rv < 0)
1453 goto err_out; 1454 goto err_out;
1454 1455
@@ -1460,12 +1461,35 @@ err_out:
1460 return rv; 1461 return rv;
1461} 1462}
1462 1463
1464static int acm_reset_resume(struct usb_interface *intf)
1465{
1466 struct acm *acm = usb_get_intfdata(intf);
1467 struct tty_struct *tty;
1468
1469 mutex_lock(&acm->mutex);
1470 if (acm->port.count) {
1471 tty = tty_port_tty_get(&acm->port);
1472 if (tty) {
1473 tty_hangup(tty);
1474 tty_kref_put(tty);
1475 }
1476 }
1477 mutex_unlock(&acm->mutex);
1478 return acm_resume(intf);
1479}
1480
1463#endif /* CONFIG_PM */ 1481#endif /* CONFIG_PM */
1482
1483#define NOKIA_PCSUITE_ACM_INFO(x) \
1484 USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
1485 USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
1486 USB_CDC_ACM_PROTO_VENDOR)
1487
1464/* 1488/*
1465 * USB driver structure. 1489 * USB driver structure.
1466 */ 1490 */
1467 1491
1468static struct usb_device_id acm_ids[] = { 1492static const struct usb_device_id acm_ids[] = {
1469 /* quirky and broken devices */ 1493 /* quirky and broken devices */
1470 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */ 1494 { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
1471 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ 1495 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
@@ -1518,6 +1542,65 @@ static struct usb_device_id acm_ids[] = {
1518 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ 1542 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1519 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ 1543 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1520 }, 1544 },
1545 { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
1546 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1547 },
1548
1549 /* Nokia S60 phones expose two ACM channels. The first is
1550 * a modem and is picked up by the standard AT-command
1551 * information below. The second is 'vendor-specific' but
1552 * is treated as a serial device at the S60 end, so we want
1553 * to expose it on Linux too. */
1554 { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
1555 { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
1556 { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
1557 { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
1558 { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
1559 { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
1560 { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
1561 { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
1562 { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
1563 { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
1564 { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
1565 { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
1566 { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
1567 { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
1568 { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
1569 { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
1570 { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
1571 { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
1572 { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
1573 { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
1574 { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
1575 { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
1576 { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
1577 { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
1578 { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
1579 { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
1580 { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
1581 { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
1582 { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
1583 { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
1584 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
1585 { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
1586 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1587 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
1588 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
1589 { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
1590 { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
1591 { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
1592 { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
1593 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
1594 { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
1595 { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
1596 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
1597
1598 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
1599
1600 /* Support Lego NXT using pbLua firmware */
1601 { USB_DEVICE(0x0694, 0xff00),
1602 .driver_info = NOT_A_MODEM,
1603 },
1521 1604
1522 /* control interfaces with various AT-command sets */ 1605 /* control interfaces with various AT-command sets */
1523 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1606 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
@@ -1533,7 +1616,6 @@ static struct usb_device_id acm_ids[] = {
1533 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1616 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1534 USB_CDC_ACM_PROTO_AT_CDMA) }, 1617 USB_CDC_ACM_PROTO_AT_CDMA) },
1535 1618
1536 /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
1537 { } 1619 { }
1538}; 1620};
1539 1621
@@ -1546,6 +1628,7 @@ static struct usb_driver acm_driver = {
1546#ifdef CONFIG_PM 1628#ifdef CONFIG_PM
1547 .suspend = acm_suspend, 1629 .suspend = acm_suspend,
1548 .resume = acm_resume, 1630 .resume = acm_resume,
1631 .reset_resume = acm_reset_resume,
1549#endif 1632#endif
1550 .id_table = acm_ids, 1633 .id_table = acm_ids,
1551#ifdef CONFIG_PM 1634#ifdef CONFIG_PM
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index c4a0ee8ffccf..4a8e87ec6ce9 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -112,7 +112,6 @@ struct acm {
112 struct mutex mutex; 112 struct mutex mutex;
113 struct usb_cdc_line_coding line; /* bits, stop, parity */ 113 struct usb_cdc_line_coding line; /* bits, stop, parity */
114 struct work_struct work; /* work queue entry for line discipline waking up */ 114 struct work_struct work; /* work queue entry for line discipline waking up */
115 struct work_struct waker;
116 wait_queue_head_t drain_wait; /* close processing */ 115 wait_queue_head_t drain_wait; /* close processing */
117 struct tasklet_struct urb_task; /* rx processing */ 116 struct tasklet_struct urb_task; /* rx processing */
118 spinlock_t throttle_lock; /* synchronize throtteling and read callback */ 117 spinlock_t throttle_lock; /* synchronize throtteling and read callback */
@@ -137,3 +136,4 @@ struct acm {
137#define NO_UNION_NORMAL 1 136#define NO_UNION_NORMAL 1
138#define SINGLE_RX_URB 2 137#define SINGLE_RX_URB 2
139#define NO_CAP_LINE 4 138#define NO_CAP_LINE 4
139#define NOT_A_MODEM 8
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 3e564bfe17d1..189141ca4e05 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -31,7 +31,7 @@
31#define DRIVER_AUTHOR "Oliver Neukum" 31#define DRIVER_AUTHOR "Oliver Neukum"
32#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management" 32#define DRIVER_DESC "USB Abstract Control Model driver for USB WCM Device Management"
33 33
34static struct usb_device_id wdm_ids[] = { 34static const struct usb_device_id wdm_ids[] = {
35 { 35 {
36 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS | 36 .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
37 USB_DEVICE_ID_MATCH_INT_SUBCLASS, 37 USB_DEVICE_ID_MATCH_INT_SUBCLASS,
@@ -52,7 +52,8 @@ MODULE_DEVICE_TABLE (usb, wdm_ids);
52#define WDM_READ 4 52#define WDM_READ 4
53#define WDM_INT_STALL 5 53#define WDM_INT_STALL 5
54#define WDM_POLL_RUNNING 6 54#define WDM_POLL_RUNNING 6
55 55#define WDM_RESPONDING 7
56#define WDM_SUSPENDING 8
56 57
57#define WDM_MAX 16 58#define WDM_MAX 16
58 59
@@ -87,9 +88,7 @@ struct wdm_device {
87 int count; 88 int count;
88 dma_addr_t shandle; 89 dma_addr_t shandle;
89 dma_addr_t ihandle; 90 dma_addr_t ihandle;
90 struct mutex wlock; 91 struct mutex lock;
91 struct mutex rlock;
92 struct mutex plock;
93 wait_queue_head_t wait; 92 wait_queue_head_t wait;
94 struct work_struct rxwork; 93 struct work_struct rxwork;
95 int werr; 94 int werr;
@@ -117,21 +116,22 @@ static void wdm_in_callback(struct urb *urb)
117 int status = urb->status; 116 int status = urb->status;
118 117
119 spin_lock(&desc->iuspin); 118 spin_lock(&desc->iuspin);
119 clear_bit(WDM_RESPONDING, &desc->flags);
120 120
121 if (status) { 121 if (status) {
122 switch (status) { 122 switch (status) {
123 case -ENOENT: 123 case -ENOENT:
124 dev_dbg(&desc->intf->dev, 124 dev_dbg(&desc->intf->dev,
125 "nonzero urb status received: -ENOENT"); 125 "nonzero urb status received: -ENOENT");
126 break; 126 goto skip_error;
127 case -ECONNRESET: 127 case -ECONNRESET:
128 dev_dbg(&desc->intf->dev, 128 dev_dbg(&desc->intf->dev,
129 "nonzero urb status received: -ECONNRESET"); 129 "nonzero urb status received: -ECONNRESET");
130 break; 130 goto skip_error;
131 case -ESHUTDOWN: 131 case -ESHUTDOWN:
132 dev_dbg(&desc->intf->dev, 132 dev_dbg(&desc->intf->dev,
133 "nonzero urb status received: -ESHUTDOWN"); 133 "nonzero urb status received: -ESHUTDOWN");
134 break; 134 goto skip_error;
135 case -EPIPE: 135 case -EPIPE:
136 dev_err(&desc->intf->dev, 136 dev_err(&desc->intf->dev,
137 "nonzero urb status received: -EPIPE\n"); 137 "nonzero urb status received: -EPIPE\n");
@@ -147,6 +147,7 @@ static void wdm_in_callback(struct urb *urb)
147 desc->reslength = urb->actual_length; 147 desc->reslength = urb->actual_length;
148 memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength); 148 memmove(desc->ubuf + desc->length, desc->inbuf, desc->reslength);
149 desc->length += desc->reslength; 149 desc->length += desc->reslength;
150skip_error:
150 wake_up(&desc->wait); 151 wake_up(&desc->wait);
151 152
152 set_bit(WDM_READ, &desc->flags); 153 set_bit(WDM_READ, &desc->flags);
@@ -229,13 +230,16 @@ static void wdm_int_callback(struct urb *urb)
229 desc->response->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 230 desc->response->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
230 spin_lock(&desc->iuspin); 231 spin_lock(&desc->iuspin);
231 clear_bit(WDM_READ, &desc->flags); 232 clear_bit(WDM_READ, &desc->flags);
232 if (!test_bit(WDM_DISCONNECTING, &desc->flags)) { 233 set_bit(WDM_RESPONDING, &desc->flags);
234 if (!test_bit(WDM_DISCONNECTING, &desc->flags)
235 && !test_bit(WDM_SUSPENDING, &desc->flags)) {
233 rv = usb_submit_urb(desc->response, GFP_ATOMIC); 236 rv = usb_submit_urb(desc->response, GFP_ATOMIC);
234 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d", 237 dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
235 __func__, rv); 238 __func__, rv);
236 } 239 }
237 spin_unlock(&desc->iuspin); 240 spin_unlock(&desc->iuspin);
238 if (rv < 0) { 241 if (rv < 0) {
242 clear_bit(WDM_RESPONDING, &desc->flags);
239 if (rv == -EPERM) 243 if (rv == -EPERM)
240 return; 244 return;
241 if (rv == -ENOMEM) { 245 if (rv == -ENOMEM) {
@@ -305,14 +309,38 @@ static ssize_t wdm_write
305 if (we < 0) 309 if (we < 0)
306 return -EIO; 310 return -EIO;
307 311
308 r = mutex_lock_interruptible(&desc->wlock); /* concurrent writes */ 312 desc->outbuf = buf = kmalloc(count, GFP_KERNEL);
313 if (!buf) {
314 rv = -ENOMEM;
315 goto outnl;
316 }
317
318 r = copy_from_user(buf, buffer, count);
319 if (r > 0) {
320 kfree(buf);
321 rv = -EFAULT;
322 goto outnl;
323 }
324
325 /* concurrent writes and disconnect */
326 r = mutex_lock_interruptible(&desc->lock);
309 rv = -ERESTARTSYS; 327 rv = -ERESTARTSYS;
310 if (r) 328 if (r) {
329 kfree(buf);
311 goto outnl; 330 goto outnl;
331 }
332
333 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
334 kfree(buf);
335 rv = -ENODEV;
336 goto outnp;
337 }
312 338
313 r = usb_autopm_get_interface(desc->intf); 339 r = usb_autopm_get_interface(desc->intf);
314 if (r < 0) 340 if (r < 0) {
341 kfree(buf);
315 goto outnp; 342 goto outnp;
343 }
316 344
317 if (!file->f_flags && O_NONBLOCK) 345 if (!file->f_flags && O_NONBLOCK)
318 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE, 346 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
@@ -320,24 +348,8 @@ static ssize_t wdm_write
320 else 348 else
321 if (test_bit(WDM_IN_USE, &desc->flags)) 349 if (test_bit(WDM_IN_USE, &desc->flags))
322 r = -EAGAIN; 350 r = -EAGAIN;
323 if (r < 0) 351 if (r < 0) {
324 goto out;
325
326 if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
327 rv = -ENODEV;
328 goto out;
329 }
330
331 desc->outbuf = buf = kmalloc(count, GFP_KERNEL);
332 if (!buf) {
333 rv = -ENOMEM;
334 goto out;
335 }
336
337 r = copy_from_user(buf, buffer, count);
338 if (r > 0) {
339 kfree(buf); 352 kfree(buf);
340 rv = -EFAULT;
341 goto out; 353 goto out;
342 } 354 }
343 355
@@ -374,7 +386,7 @@ static ssize_t wdm_write
374out: 386out:
375 usb_autopm_put_interface(desc->intf); 387 usb_autopm_put_interface(desc->intf);
376outnp: 388outnp:
377 mutex_unlock(&desc->wlock); 389 mutex_unlock(&desc->lock);
378outnl: 390outnl:
379 return rv < 0 ? rv : count; 391 return rv < 0 ? rv : count;
380} 392}
@@ -387,7 +399,7 @@ static ssize_t wdm_read
387 struct wdm_device *desc = file->private_data; 399 struct wdm_device *desc = file->private_data;
388 400
389 401
390 rv = mutex_lock_interruptible(&desc->rlock); /*concurrent reads */ 402 rv = mutex_lock_interruptible(&desc->lock); /*concurrent reads */
391 if (rv < 0) 403 if (rv < 0)
392 return -ERESTARTSYS; 404 return -ERESTARTSYS;
393 405
@@ -424,11 +436,8 @@ retry:
424 spin_lock_irq(&desc->iuspin); 436 spin_lock_irq(&desc->iuspin);
425 437
426 if (desc->rerr) { /* read completed, error happened */ 438 if (desc->rerr) { /* read completed, error happened */
427 int t = desc->rerr;
428 desc->rerr = 0; 439 desc->rerr = 0;
429 spin_unlock_irq(&desc->iuspin); 440 spin_unlock_irq(&desc->iuspin);
430 dev_err(&desc->intf->dev,
431 "reading had resulted in %d\n", t);
432 rv = -EIO; 441 rv = -EIO;
433 goto err; 442 goto err;
434 } 443 }
@@ -465,9 +474,7 @@ retry:
465 rv = cntr; 474 rv = cntr;
466 475
467err: 476err:
468 mutex_unlock(&desc->rlock); 477 mutex_unlock(&desc->lock);
469 if (rv < 0 && rv != -EAGAIN)
470 dev_err(&desc->intf->dev, "wdm_read: exit error\n");
471 return rv; 478 return rv;
472} 479}
473 480
@@ -533,7 +540,7 @@ static int wdm_open(struct inode *inode, struct file *file)
533 } 540 }
534 intf->needs_remote_wakeup = 1; 541 intf->needs_remote_wakeup = 1;
535 542
536 mutex_lock(&desc->plock); 543 mutex_lock(&desc->lock);
537 if (!desc->count++) { 544 if (!desc->count++) {
538 rv = usb_submit_urb(desc->validity, GFP_KERNEL); 545 rv = usb_submit_urb(desc->validity, GFP_KERNEL);
539 if (rv < 0) { 546 if (rv < 0) {
@@ -544,7 +551,7 @@ static int wdm_open(struct inode *inode, struct file *file)
544 } else { 551 } else {
545 rv = 0; 552 rv = 0;
546 } 553 }
547 mutex_unlock(&desc->plock); 554 mutex_unlock(&desc->lock);
548 usb_autopm_put_interface(desc->intf); 555 usb_autopm_put_interface(desc->intf);
549out: 556out:
550 mutex_unlock(&wdm_mutex); 557 mutex_unlock(&wdm_mutex);
@@ -556,9 +563,9 @@ static int wdm_release(struct inode *inode, struct file *file)
556 struct wdm_device *desc = file->private_data; 563 struct wdm_device *desc = file->private_data;
557 564
558 mutex_lock(&wdm_mutex); 565 mutex_lock(&wdm_mutex);
559 mutex_lock(&desc->plock); 566 mutex_lock(&desc->lock);
560 desc->count--; 567 desc->count--;
561 mutex_unlock(&desc->plock); 568 mutex_unlock(&desc->lock);
562 569
563 if (!desc->count) { 570 if (!desc->count) {
564 dev_dbg(&desc->intf->dev, "wdm_release: cleanup"); 571 dev_dbg(&desc->intf->dev, "wdm_release: cleanup");
@@ -655,9 +662,7 @@ next_desc:
655 desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL); 662 desc = kzalloc(sizeof(struct wdm_device), GFP_KERNEL);
656 if (!desc) 663 if (!desc)
657 goto out; 664 goto out;
658 mutex_init(&desc->wlock); 665 mutex_init(&desc->lock);
659 mutex_init(&desc->rlock);
660 mutex_init(&desc->plock);
661 spin_lock_init(&desc->iuspin); 666 spin_lock_init(&desc->iuspin);
662 init_waitqueue_head(&desc->wait); 667 init_waitqueue_head(&desc->wait);
663 desc->wMaxCommand = maxcom; 668 desc->wMaxCommand = maxcom;
@@ -771,14 +776,17 @@ static void wdm_disconnect(struct usb_interface *intf)
771 /* to terminate pending flushes */ 776 /* to terminate pending flushes */
772 clear_bit(WDM_IN_USE, &desc->flags); 777 clear_bit(WDM_IN_USE, &desc->flags);
773 spin_unlock_irqrestore(&desc->iuspin, flags); 778 spin_unlock_irqrestore(&desc->iuspin, flags);
774 cancel_work_sync(&desc->rxwork); 779 mutex_lock(&desc->lock);
775 kill_urbs(desc); 780 kill_urbs(desc);
781 cancel_work_sync(&desc->rxwork);
782 mutex_unlock(&desc->lock);
776 wake_up_all(&desc->wait); 783 wake_up_all(&desc->wait);
777 if (!desc->count) 784 if (!desc->count)
778 cleanup(desc); 785 cleanup(desc);
779 mutex_unlock(&wdm_mutex); 786 mutex_unlock(&wdm_mutex);
780} 787}
781 788
789#ifdef CONFIG_PM
782static int wdm_suspend(struct usb_interface *intf, pm_message_t message) 790static int wdm_suspend(struct usb_interface *intf, pm_message_t message)
783{ 791{
784 struct wdm_device *desc = usb_get_intfdata(intf); 792 struct wdm_device *desc = usb_get_intfdata(intf);
@@ -786,22 +794,30 @@ static int wdm_suspend(struct usb_interface *intf, pm_message_t message)
786 794
787 dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor); 795 dev_dbg(&desc->intf->dev, "wdm%d_suspend\n", intf->minor);
788 796
789 mutex_lock(&desc->plock); 797 /* if this is an autosuspend the caller does the locking */
790#ifdef CONFIG_PM 798 if (!(message.event & PM_EVENT_AUTO))
799 mutex_lock(&desc->lock);
800 spin_lock_irq(&desc->iuspin);
801
791 if ((message.event & PM_EVENT_AUTO) && 802 if ((message.event & PM_EVENT_AUTO) &&
792 test_bit(WDM_IN_USE, &desc->flags)) { 803 (test_bit(WDM_IN_USE, &desc->flags)
804 || test_bit(WDM_RESPONDING, &desc->flags))) {
805 spin_unlock_irq(&desc->iuspin);
793 rv = -EBUSY; 806 rv = -EBUSY;
794 } else { 807 } else {
795#endif 808
796 cancel_work_sync(&desc->rxwork); 809 set_bit(WDM_SUSPENDING, &desc->flags);
810 spin_unlock_irq(&desc->iuspin);
811 /* callback submits work - order is essential */
797 kill_urbs(desc); 812 kill_urbs(desc);
798#ifdef CONFIG_PM 813 cancel_work_sync(&desc->rxwork);
799 } 814 }
800#endif 815 if (!(message.event & PM_EVENT_AUTO))
801 mutex_unlock(&desc->plock); 816 mutex_unlock(&desc->lock);
802 817
803 return rv; 818 return rv;
804} 819}
820#endif
805 821
806static int recover_from_urb_loss(struct wdm_device *desc) 822static int recover_from_urb_loss(struct wdm_device *desc)
807{ 823{
@@ -815,23 +831,27 @@ static int recover_from_urb_loss(struct wdm_device *desc)
815 } 831 }
816 return rv; 832 return rv;
817} 833}
834
835#ifdef CONFIG_PM
818static int wdm_resume(struct usb_interface *intf) 836static int wdm_resume(struct usb_interface *intf)
819{ 837{
820 struct wdm_device *desc = usb_get_intfdata(intf); 838 struct wdm_device *desc = usb_get_intfdata(intf);
821 int rv; 839 int rv;
822 840
823 dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor); 841 dev_dbg(&desc->intf->dev, "wdm%d_resume\n", intf->minor);
824 mutex_lock(&desc->plock); 842
843 clear_bit(WDM_SUSPENDING, &desc->flags);
825 rv = recover_from_urb_loss(desc); 844 rv = recover_from_urb_loss(desc);
826 mutex_unlock(&desc->plock); 845
827 return rv; 846 return rv;
828} 847}
848#endif
829 849
830static int wdm_pre_reset(struct usb_interface *intf) 850static int wdm_pre_reset(struct usb_interface *intf)
831{ 851{
832 struct wdm_device *desc = usb_get_intfdata(intf); 852 struct wdm_device *desc = usb_get_intfdata(intf);
833 853
834 mutex_lock(&desc->plock); 854 mutex_lock(&desc->lock);
835 return 0; 855 return 0;
836} 856}
837 857
@@ -841,7 +861,7 @@ static int wdm_post_reset(struct usb_interface *intf)
841 int rv; 861 int rv;
842 862
843 rv = recover_from_urb_loss(desc); 863 rv = recover_from_urb_loss(desc);
844 mutex_unlock(&desc->plock); 864 mutex_unlock(&desc->lock);
845 return 0; 865 return 0;
846} 866}
847 867
@@ -849,9 +869,11 @@ static struct usb_driver wdm_driver = {
849 .name = "cdc_wdm", 869 .name = "cdc_wdm",
850 .probe = wdm_probe, 870 .probe = wdm_probe,
851 .disconnect = wdm_disconnect, 871 .disconnect = wdm_disconnect,
872#ifdef CONFIG_PM
852 .suspend = wdm_suspend, 873 .suspend = wdm_suspend,
853 .resume = wdm_resume, 874 .resume = wdm_resume,
854 .reset_resume = wdm_resume, 875 .reset_resume = wdm_resume,
876#endif
855 .pre_reset = wdm_pre_reset, 877 .pre_reset = wdm_pre_reset,
856 .post_reset = wdm_post_reset, 878 .post_reset = wdm_post_reset,
857 .id_table = wdm_ids, 879 .id_table = wdm_ids,
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 9bc112ee7803..93b5f85d7ceb 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -163,7 +163,6 @@ struct usblp {
163 unsigned char used; /* True if open */ 163 unsigned char used; /* True if open */
164 unsigned char present; /* True if not disconnected */ 164 unsigned char present; /* True if not disconnected */
165 unsigned char bidir; /* interface is bidirectional */ 165 unsigned char bidir; /* interface is bidirectional */
166 unsigned char sleeping; /* interface is suspended */
167 unsigned char no_paper; /* Paper Out happened */ 166 unsigned char no_paper; /* Paper Out happened */
168 unsigned char *device_id_string; /* IEEE 1284 DEVICE ID string (ptr) */ 167 unsigned char *device_id_string; /* IEEE 1284 DEVICE ID string (ptr) */
169 /* first 2 bytes are (big-endian) length */ 168 /* first 2 bytes are (big-endian) length */
@@ -191,7 +190,6 @@ static void usblp_dump(struct usblp *usblp) {
191 dbg("quirks=%d", usblp->quirks); 190 dbg("quirks=%d", usblp->quirks);
192 dbg("used=%d", usblp->used); 191 dbg("used=%d", usblp->used);
193 dbg("bidir=%d", usblp->bidir); 192 dbg("bidir=%d", usblp->bidir);
194 dbg("sleeping=%d", usblp->sleeping);
195 dbg("device_id_string=\"%s\"", 193 dbg("device_id_string=\"%s\"",
196 usblp->device_id_string ? 194 usblp->device_id_string ?
197 usblp->device_id_string + 2 : 195 usblp->device_id_string + 2 :
@@ -376,7 +374,7 @@ static int usblp_check_status(struct usblp *usblp, int err)
376 374
377static int handle_bidir (struct usblp *usblp) 375static int handle_bidir (struct usblp *usblp)
378{ 376{
379 if (usblp->bidir && usblp->used && !usblp->sleeping) { 377 if (usblp->bidir && usblp->used) {
380 if (usblp_submit_read(usblp) < 0) 378 if (usblp_submit_read(usblp) < 0)
381 return -EIO; 379 return -EIO;
382 } 380 }
@@ -503,11 +501,6 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
503 goto done; 501 goto done;
504 } 502 }
505 503
506 if (usblp->sleeping) {
507 retval = -ENODEV;
508 goto done;
509 }
510
511 dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd), 504 dbg("usblp_ioctl: cmd=0x%x (%c nr=%d len=%d dir=%d)", cmd, _IOC_TYPE(cmd),
512 _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd) ); 505 _IOC_NR(cmd), _IOC_SIZE(cmd), _IOC_DIR(cmd) );
513 506
@@ -914,8 +907,6 @@ static int usblp_wtest(struct usblp *usblp, int nonblock)
914 return 0; 907 return 0;
915 } 908 }
916 spin_unlock_irqrestore(&usblp->lock, flags); 909 spin_unlock_irqrestore(&usblp->lock, flags);
917 if (usblp->sleeping)
918 return -ENODEV;
919 if (nonblock) 910 if (nonblock)
920 return -EAGAIN; 911 return -EAGAIN;
921 return 1; 912 return 1;
@@ -968,8 +959,6 @@ static int usblp_rtest(struct usblp *usblp, int nonblock)
968 return 0; 959 return 0;
969 } 960 }
970 spin_unlock_irqrestore(&usblp->lock, flags); 961 spin_unlock_irqrestore(&usblp->lock, flags);
971 if (usblp->sleeping)
972 return -ENODEV;
973 if (nonblock) 962 if (nonblock)
974 return -EAGAIN; 963 return -EAGAIN;
975 return 1; 964 return 1;
@@ -1377,12 +1366,10 @@ static void usblp_disconnect(struct usb_interface *intf)
1377 mutex_unlock (&usblp_mutex); 1366 mutex_unlock (&usblp_mutex);
1378} 1367}
1379 1368
1380static int usblp_suspend (struct usb_interface *intf, pm_message_t message) 1369static int usblp_suspend(struct usb_interface *intf, pm_message_t message)
1381{ 1370{
1382 struct usblp *usblp = usb_get_intfdata (intf); 1371 struct usblp *usblp = usb_get_intfdata (intf);
1383 1372
1384 /* we take no more IO */
1385 usblp->sleeping = 1;
1386 usblp_unlink_urbs(usblp); 1373 usblp_unlink_urbs(usblp);
1387#if 0 /* XXX Do we want this? What if someone is reading, should we fail? */ 1374#if 0 /* XXX Do we want this? What if someone is reading, should we fail? */
1388 /* not strictly necessary, but just in case */ 1375 /* not strictly necessary, but just in case */
@@ -1393,18 +1380,17 @@ static int usblp_suspend (struct usb_interface *intf, pm_message_t message)
1393 return 0; 1380 return 0;
1394} 1381}
1395 1382
1396static int usblp_resume (struct usb_interface *intf) 1383static int usblp_resume(struct usb_interface *intf)
1397{ 1384{
1398 struct usblp *usblp = usb_get_intfdata (intf); 1385 struct usblp *usblp = usb_get_intfdata (intf);
1399 int r; 1386 int r;
1400 1387
1401 usblp->sleeping = 0;
1402 r = handle_bidir (usblp); 1388 r = handle_bidir (usblp);
1403 1389
1404 return r; 1390 return r;
1405} 1391}
1406 1392
1407static struct usb_device_id usblp_ids [] = { 1393static const struct usb_device_id usblp_ids[] = {
1408 { USB_DEVICE_INFO(7, 1, 1) }, 1394 { USB_DEVICE_INFO(7, 1, 1) },
1409 { USB_DEVICE_INFO(7, 1, 2) }, 1395 { USB_DEVICE_INFO(7, 1, 2) },
1410 { USB_DEVICE_INFO(7, 1, 3) }, 1396 { USB_DEVICE_INFO(7, 1, 3) },
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 2473cf0c6b1d..3e7c1b800ebb 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -1,5 +1,5 @@
1/** 1/**
2 * drivers/usb/class/usbtmc.c - USB Test & Measurment class driver 2 * drivers/usb/class/usbtmc.c - USB Test & Measurement class driver
3 * 3 *
4 * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany 4 * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany
5 * Copyright (C) 2008 Novell, Inc. 5 * Copyright (C) 2008 Novell, Inc.
@@ -25,6 +25,7 @@
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/uaccess.h> 26#include <linux/uaccess.h>
27#include <linux/kref.h> 27#include <linux/kref.h>
28#include <linux/slab.h>
28#include <linux/mutex.h> 29#include <linux/mutex.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30#include <linux/usb/tmc.h> 31#include <linux/usb/tmc.h>
@@ -48,7 +49,7 @@
48 */ 49 */
49#define USBTMC_MAX_READS_TO_CLEAR_BULK_IN 100 50#define USBTMC_MAX_READS_TO_CLEAR_BULK_IN 100
50 51
51static struct usb_device_id usbtmc_devices[] = { 52static const struct usb_device_id usbtmc_devices[] = {
52 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 0), }, 53 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 0), },
53 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 1), }, 54 { USB_INTERFACE_INFO(USB_CLASS_APP_SPEC, 3, 1), },
54 { 0, } /* terminating entry */ 55 { 0, } /* terminating entry */
@@ -347,13 +348,8 @@ usbtmc_abort_bulk_out_check_status:
347 goto exit; 348 goto exit;
348 349
349usbtmc_abort_bulk_out_clear_halt: 350usbtmc_abort_bulk_out_clear_halt:
350 rv = usb_control_msg(data->usb_dev, 351 rv = usb_clear_halt(data->usb_dev,
351 usb_sndctrlpipe(data->usb_dev, 0), 352 usb_sndbulkpipe(data->usb_dev, data->bulk_out));
352 USB_REQ_CLEAR_FEATURE,
353 USB_DIR_OUT | USB_TYPE_STANDARD |
354 USB_RECIP_ENDPOINT,
355 USB_ENDPOINT_HALT, data->bulk_out, buffer,
356 0, USBTMC_TIMEOUT);
357 353
358 if (rv < 0) { 354 if (rv < 0) {
359 dev_err(dev, "usb_control_msg returned %d\n", rv); 355 dev_err(dev, "usb_control_msg returned %d\n", rv);
@@ -562,10 +558,16 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
562 n_bytes = roundup(12 + this_part, 4); 558 n_bytes = roundup(12 + this_part, 4);
563 memset(buffer + 12 + this_part, 0, n_bytes - (12 + this_part)); 559 memset(buffer + 12 + this_part, 0, n_bytes - (12 + this_part));
564 560
565 retval = usb_bulk_msg(data->usb_dev, 561 do {
566 usb_sndbulkpipe(data->usb_dev, 562 retval = usb_bulk_msg(data->usb_dev,
567 data->bulk_out), 563 usb_sndbulkpipe(data->usb_dev,
568 buffer, n_bytes, &actual, USBTMC_TIMEOUT); 564 data->bulk_out),
565 buffer, n_bytes,
566 &actual, USBTMC_TIMEOUT);
567 if (retval != 0)
568 break;
569 n_bytes -= actual;
570 } while (n_bytes);
569 571
570 data->bTag_last_write = data->bTag; 572 data->bTag_last_write = data->bTag;
571 data->bTag++; 573 data->bTag++;
@@ -702,14 +704,8 @@ usbtmc_clear_check_status:
702 704
703usbtmc_clear_bulk_out_halt: 705usbtmc_clear_bulk_out_halt:
704 706
705 rv = usb_control_msg(data->usb_dev, 707 rv = usb_clear_halt(data->usb_dev,
706 usb_sndctrlpipe(data->usb_dev, 0), 708 usb_sndbulkpipe(data->usb_dev, data->bulk_out));
707 USB_REQ_CLEAR_FEATURE,
708 USB_DIR_OUT | USB_TYPE_STANDARD |
709 USB_RECIP_ENDPOINT,
710 USB_ENDPOINT_HALT,
711 data->bulk_out, buffer, 0,
712 USBTMC_TIMEOUT);
713 if (rv < 0) { 709 if (rv < 0) {
714 dev_err(dev, "usb_control_msg returned %d\n", rv); 710 dev_err(dev, "usb_control_msg returned %d\n", rv);
715 goto exit; 711 goto exit;
@@ -730,13 +726,8 @@ static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data *data)
730 if (!buffer) 726 if (!buffer)
731 return -ENOMEM; 727 return -ENOMEM;
732 728
733 rv = usb_control_msg(data->usb_dev, 729 rv = usb_clear_halt(data->usb_dev,
734 usb_sndctrlpipe(data->usb_dev, 0), 730 usb_sndbulkpipe(data->usb_dev, data->bulk_out));
735 USB_REQ_CLEAR_FEATURE,
736 USB_DIR_OUT | USB_TYPE_STANDARD |
737 USB_RECIP_ENDPOINT,
738 USB_ENDPOINT_HALT, data->bulk_out,
739 buffer, 0, USBTMC_TIMEOUT);
740 731
741 if (rv < 0) { 732 if (rv < 0) {
742 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", 733 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n",
@@ -759,12 +750,8 @@ static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data *data)
759 if (!buffer) 750 if (!buffer)
760 return -ENOMEM; 751 return -ENOMEM;
761 752
762 rv = usb_control_msg(data->usb_dev, usb_sndctrlpipe(data->usb_dev, 0), 753 rv = usb_clear_halt(data->usb_dev,
763 USB_REQ_CLEAR_FEATURE, 754 usb_rcvbulkpipe(data->usb_dev, data->bulk_in));
764 USB_DIR_OUT | USB_TYPE_STANDARD |
765 USB_RECIP_ENDPOINT,
766 USB_ENDPOINT_HALT, data->bulk_in, buffer, 0,
767 USBTMC_TIMEOUT);
768 755
769 if (rv < 0) { 756 if (rv < 0) {
770 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", 757 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n",
@@ -1109,13 +1096,13 @@ static void usbtmc_disconnect(struct usb_interface *intf)
1109 kref_put(&data->kref, usbtmc_delete); 1096 kref_put(&data->kref, usbtmc_delete);
1110} 1097}
1111 1098
1112static int usbtmc_suspend (struct usb_interface *intf, pm_message_t message) 1099static int usbtmc_suspend(struct usb_interface *intf, pm_message_t message)
1113{ 1100{
1114 /* this driver does not have pending URBs */ 1101 /* this driver does not have pending URBs */
1115 return 0; 1102 return 0;
1116} 1103}
1117 1104
1118static int usbtmc_resume (struct usb_interface *intf) 1105static int usbtmc_resume(struct usb_interface *intf)
1119{ 1106{
1120 return 0; 1107 return 0;
1121} 1108}
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index ad925946f869..7e594449600e 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -91,8 +91,8 @@ config USB_DYNAMIC_MINORS
91 If you are unsure about this, say N here. 91 If you are unsure about this, say N here.
92 92
93config USB_SUSPEND 93config USB_SUSPEND
94 bool "USB selective suspend/resume and wakeup" 94 bool "USB runtime power management (suspend/resume and wakeup)"
95 depends on USB && PM 95 depends on USB && PM_RUNTIME
96 help 96 help
97 If you say Y here, you can use driver calls or the sysfs 97 If you say Y here, you can use driver calls or the sysfs
98 "power/level" file to suspend or resume individual USB 98 "power/level" file to suspend or resume individual USB
@@ -109,7 +109,7 @@ config USB_SUSPEND
109config USB_OTG 109config USB_OTG
110 bool 110 bool
111 depends on USB && EXPERIMENTAL 111 depends on USB && EXPERIMENTAL
112 select USB_SUSPEND 112 depends on USB_SUSPEND
113 default n 113 default n
114 114
115 115
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 96f11715cd26..19bc03a9fecf 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -50,7 +50,7 @@
50 50
51#include <linux/fs.h> 51#include <linux/fs.h>
52#include <linux/mm.h> 52#include <linux/mm.h>
53#include <linux/slab.h> 53#include <linux/gfp.h>
54#include <linux/poll.h> 54#include <linux/poll.h>
55#include <linux/usb.h> 55#include <linux/usb.h>
56#include <linux/smp_lock.h> 56#include <linux/smp_lock.h>
@@ -117,12 +117,20 @@ static const char *format_endpt =
117 * However, these will come from functions that return ptrs to each of them. 117 * However, these will come from functions that return ptrs to each of them.
118 */ 118 */
119 119
120static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq); 120/*
121static unsigned int conndiscevcnt; 121 * Wait for an connect/disconnect event to happen. We initialize
122 122 * the event counter with an odd number, and each event will increment
123/* this struct stores the poll state for <mountpoint>/devices pollers */ 123 * the event counter by two, so it will always _stay_ odd. That means
124struct usb_device_status { 124 * that it will never be zero, so "event 0" will never match a current
125 unsigned int lastev; 125 * event, and thus 'poll' will always trigger as readable for the first
126 * time it gets called.
127 */
128static struct device_connect_event {
129 atomic_t count;
130 wait_queue_head_t wait;
131} device_event = {
132 .count = ATOMIC_INIT(1),
133 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(device_event.wait)
126}; 134};
127 135
128struct class_info { 136struct class_info {
@@ -156,8 +164,8 @@ static const struct class_info clas_info[] =
156 164
157void usbfs_conn_disc_event(void) 165void usbfs_conn_disc_event(void)
158{ 166{
159 conndiscevcnt++; 167 atomic_add(2, &device_event.count);
160 wake_up(&deviceconndiscwq); 168 wake_up(&device_event.wait);
161} 169}
162 170
163static const char *class_decode(const int class) 171static const char *class_decode(const int class)
@@ -494,7 +502,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
494 return 0; 502 return 0;
495 /* allocate 2^1 pages = 8K (on i386); 503 /* allocate 2^1 pages = 8K (on i386);
496 * should be more than enough for one device */ 504 * should be more than enough for one device */
497 pages_start = (char *)__get_free_pages(GFP_KERNEL, 1); 505 pages_start = (char *)__get_free_pages(GFP_NOIO, 1);
498 if (!pages_start) 506 if (!pages_start)
499 return -ENOMEM; 507 return -ENOMEM;
500 508
@@ -629,55 +637,16 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
629static unsigned int usb_device_poll(struct file *file, 637static unsigned int usb_device_poll(struct file *file,
630 struct poll_table_struct *wait) 638 struct poll_table_struct *wait)
631{ 639{
632 struct usb_device_status *st = file->private_data; 640 unsigned int event_count;
633 unsigned int mask = 0;
634
635 lock_kernel();
636 if (!st) {
637 st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
638
639 /* we may have dropped BKL -
640 * need to check for having lost the race */
641 if (file->private_data) {
642 kfree(st);
643 st = file->private_data;
644 goto lost_race;
645 }
646 /* we haven't lost - check for allocation failure now */
647 if (!st) {
648 unlock_kernel();
649 return POLLIN;
650 }
651 641
652 /* 642 poll_wait(file, &device_event.wait, wait);
653 * need to prevent the module from being unloaded, since
654 * proc_unregister does not call the release method and
655 * we would have a memory leak
656 */
657 st->lastev = conndiscevcnt;
658 file->private_data = st;
659 mask = POLLIN;
660 }
661lost_race:
662 if (file->f_mode & FMODE_READ)
663 poll_wait(file, &deviceconndiscwq, wait);
664 if (st->lastev != conndiscevcnt)
665 mask |= POLLIN;
666 st->lastev = conndiscevcnt;
667 unlock_kernel();
668 return mask;
669}
670 643
671static int usb_device_open(struct inode *inode, struct file *file) 644 event_count = atomic_read(&device_event.count);
672{ 645 if (file->f_version != event_count) {
673 file->private_data = NULL; 646 file->f_version = event_count;
674 return 0; 647 return POLLIN | POLLRDNORM;
675} 648 }
676 649
677static int usb_device_release(struct inode *inode, struct file *file)
678{
679 kfree(file->private_data);
680 file->private_data = NULL;
681 return 0; 650 return 0;
682} 651}
683 652
@@ -685,7 +654,7 @@ static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig)
685{ 654{
686 loff_t ret; 655 loff_t ret;
687 656
688 lock_kernel(); 657 mutex_lock(&file->f_dentry->d_inode->i_mutex);
689 658
690 switch (orig) { 659 switch (orig) {
691 case 0: 660 case 0:
@@ -701,7 +670,7 @@ static loff_t usb_device_lseek(struct file *file, loff_t offset, int orig)
701 ret = -EINVAL; 670 ret = -EINVAL;
702 } 671 }
703 672
704 unlock_kernel(); 673 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
705 return ret; 674 return ret;
706} 675}
707 676
@@ -709,6 +678,4 @@ const struct file_operations usbfs_devices_fops = {
709 .llseek = usb_device_lseek, 678 .llseek = usb_device_lseek,
710 .read = usb_device_read, 679 .read = usb_device_read,
711 .poll = usb_device_poll, 680 .poll = usb_device_poll,
712 .open = usb_device_open,
713 .release = usb_device_release,
714}; 681};
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 181f78c84105..3466fdc5bb11 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -122,7 +122,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
122{ 122{
123 loff_t ret; 123 loff_t ret;
124 124
125 lock_kernel(); 125 mutex_lock(&file->f_dentry->d_inode->i_mutex);
126 126
127 switch (orig) { 127 switch (orig) {
128 case 0: 128 case 0:
@@ -138,7 +138,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t offset, int orig)
138 ret = -EINVAL; 138 ret = -EINVAL;
139 } 139 }
140 140
141 unlock_kernel(); 141 mutex_unlock(&file->f_dentry->d_inode->i_mutex);
142 return ret; 142 return ret;
143} 143}
144 144
@@ -310,7 +310,8 @@ static struct async *async_getpending(struct dev_state *ps,
310 310
311static void snoop_urb(struct usb_device *udev, 311static void snoop_urb(struct usb_device *udev,
312 void __user *userurb, int pipe, unsigned length, 312 void __user *userurb, int pipe, unsigned length,
313 int timeout_or_status, enum snoop_when when) 313 int timeout_or_status, enum snoop_when when,
314 unsigned char *data, unsigned data_len)
314{ 315{
315 static const char *types[] = {"isoc", "int", "ctrl", "bulk"}; 316 static const char *types[] = {"isoc", "int", "ctrl", "bulk"};
316 static const char *dirs[] = {"out", "in"}; 317 static const char *dirs[] = {"out", "in"};
@@ -344,6 +345,11 @@ static void snoop_urb(struct usb_device *udev,
344 "status %d\n", 345 "status %d\n",
345 ep, t, d, length, timeout_or_status); 346 ep, t, d, length, timeout_or_status);
346 } 347 }
348
349 if (data && data_len > 0) {
350 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_NONE, 32, 1,
351 data, data_len, 1);
352 }
347} 353}
348 354
349#define AS_CONTINUATION 1 355#define AS_CONTINUATION 1
@@ -410,7 +416,9 @@ static void async_completed(struct urb *urb)
410 } 416 }
411 snoop(&urb->dev->dev, "urb complete\n"); 417 snoop(&urb->dev->dev, "urb complete\n");
412 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length, 418 snoop_urb(urb->dev, as->userurb, urb->pipe, urb->actual_length,
413 as->status, COMPLETE); 419 as->status, COMPLETE,
420 ((urb->transfer_flags & URB_DIR_MASK) == USB_DIR_OUT) ?
421 NULL : urb->transfer_buffer, urb->actual_length);
414 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET && 422 if (as->status < 0 && as->bulk_addr && as->status != -ECONNRESET &&
415 as->status != -ENOENT) 423 as->status != -ENOENT)
416 cancel_bulk_urbs(ps, as->bulk_addr); 424 cancel_bulk_urbs(ps, as->bulk_addr);
@@ -653,20 +661,20 @@ static int usbdev_open(struct inode *inode, struct file *file)
653 const struct cred *cred = current_cred(); 661 const struct cred *cred = current_cred();
654 int ret; 662 int ret;
655 663
656 lock_kernel();
657 /* Protect against simultaneous removal or release */
658 mutex_lock(&usbfs_mutex);
659
660 ret = -ENOMEM; 664 ret = -ENOMEM;
661 ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL); 665 ps = kmalloc(sizeof(struct dev_state), GFP_KERNEL);
662 if (!ps) 666 if (!ps)
663 goto out; 667 goto out_free_ps;
664 668
665 ret = -ENODEV; 669 ret = -ENODEV;
666 670
671 /* Protect against simultaneous removal or release */
672 mutex_lock(&usbfs_mutex);
673
667 /* usbdev device-node */ 674 /* usbdev device-node */
668 if (imajor(inode) == USB_DEVICE_MAJOR) 675 if (imajor(inode) == USB_DEVICE_MAJOR)
669 dev = usbdev_lookup_by_devt(inode->i_rdev); 676 dev = usbdev_lookup_by_devt(inode->i_rdev);
677
670#ifdef CONFIG_USB_DEVICEFS 678#ifdef CONFIG_USB_DEVICEFS
671 /* procfs file */ 679 /* procfs file */
672 if (!dev) { 680 if (!dev) {
@@ -678,13 +686,19 @@ static int usbdev_open(struct inode *inode, struct file *file)
678 dev = NULL; 686 dev = NULL;
679 } 687 }
680#endif 688#endif
681 if (!dev || dev->state == USB_STATE_NOTATTACHED) 689 mutex_unlock(&usbfs_mutex);
682 goto out; 690
691 if (!dev)
692 goto out_free_ps;
693
694 usb_lock_device(dev);
695 if (dev->state == USB_STATE_NOTATTACHED)
696 goto out_unlock_device;
697
683 ret = usb_autoresume_device(dev); 698 ret = usb_autoresume_device(dev);
684 if (ret) 699 if (ret)
685 goto out; 700 goto out_unlock_device;
686 701
687 ret = 0;
688 ps->dev = dev; 702 ps->dev = dev;
689 ps->file = file; 703 ps->file = file;
690 spin_lock_init(&ps->lock); 704 spin_lock_init(&ps->lock);
@@ -702,15 +716,16 @@ static int usbdev_open(struct inode *inode, struct file *file)
702 smp_wmb(); 716 smp_wmb();
703 list_add_tail(&ps->list, &dev->filelist); 717 list_add_tail(&ps->list, &dev->filelist);
704 file->private_data = ps; 718 file->private_data = ps;
719 usb_unlock_device(dev);
705 snoop(&dev->dev, "opened by process %d: %s\n", task_pid_nr(current), 720 snoop(&dev->dev, "opened by process %d: %s\n", task_pid_nr(current),
706 current->comm); 721 current->comm);
707 out: 722 return ret;
708 if (ret) { 723
709 kfree(ps); 724 out_unlock_device:
710 usb_put_dev(dev); 725 usb_unlock_device(dev);
711 } 726 usb_put_dev(dev);
712 mutex_unlock(&usbfs_mutex); 727 out_free_ps:
713 unlock_kernel(); 728 kfree(ps);
714 return ret; 729 return ret;
715} 730}
716 731
@@ -724,10 +739,7 @@ static int usbdev_release(struct inode *inode, struct file *file)
724 usb_lock_device(dev); 739 usb_lock_device(dev);
725 usb_hub_release_all_ports(dev, ps); 740 usb_hub_release_all_ports(dev, ps);
726 741
727 /* Protect against simultaneous open */
728 mutex_lock(&usbfs_mutex);
729 list_del_init(&ps->list); 742 list_del_init(&ps->list);
730 mutex_unlock(&usbfs_mutex);
731 743
732 for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed); 744 for (ifnum = 0; ps->ifclaimed && ifnum < 8*sizeof(ps->ifclaimed);
733 ifnum++) { 745 ifnum++) {
@@ -770,6 +782,13 @@ static int proc_control(struct dev_state *ps, void __user *arg)
770 if (!tbuf) 782 if (!tbuf)
771 return -ENOMEM; 783 return -ENOMEM;
772 tmo = ctrl.timeout; 784 tmo = ctrl.timeout;
785 snoop(&dev->dev, "control urb: bRequestType=%02x "
786 "bRequest=%02x wValue=%04x "
787 "wIndex=%04x wLength=%04x\n",
788 ctrl.bRequestType, ctrl.bRequest,
789 __le16_to_cpup(&ctrl.wValue),
790 __le16_to_cpup(&ctrl.wIndex),
791 __le16_to_cpup(&ctrl.wLength));
773 if (ctrl.bRequestType & 0x80) { 792 if (ctrl.bRequestType & 0x80) {
774 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data, 793 if (ctrl.wLength && !access_ok(VERIFY_WRITE, ctrl.data,
775 ctrl.wLength)) { 794 ctrl.wLength)) {
@@ -777,15 +796,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
777 return -EINVAL; 796 return -EINVAL;
778 } 797 }
779 pipe = usb_rcvctrlpipe(dev, 0); 798 pipe = usb_rcvctrlpipe(dev, 0);
780 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); 799 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT, NULL, 0);
781 800
782 usb_unlock_device(dev); 801 usb_unlock_device(dev);
783 i = usb_control_msg(dev, pipe, ctrl.bRequest, 802 i = usb_control_msg(dev, pipe, ctrl.bRequest,
784 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 803 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
785 tbuf, ctrl.wLength, tmo); 804 tbuf, ctrl.wLength, tmo);
786 usb_lock_device(dev); 805 usb_lock_device(dev);
787 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); 806 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE,
788 807 tbuf, i);
789 if ((i > 0) && ctrl.wLength) { 808 if ((i > 0) && ctrl.wLength) {
790 if (copy_to_user(ctrl.data, tbuf, i)) { 809 if (copy_to_user(ctrl.data, tbuf, i)) {
791 free_page((unsigned long)tbuf); 810 free_page((unsigned long)tbuf);
@@ -800,14 +819,15 @@ static int proc_control(struct dev_state *ps, void __user *arg)
800 } 819 }
801 } 820 }
802 pipe = usb_sndctrlpipe(dev, 0); 821 pipe = usb_sndctrlpipe(dev, 0);
803 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT); 822 snoop_urb(dev, NULL, pipe, ctrl.wLength, tmo, SUBMIT,
823 tbuf, ctrl.wLength);
804 824
805 usb_unlock_device(dev); 825 usb_unlock_device(dev);
806 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest, 826 i = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ctrl.bRequest,
807 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex, 827 ctrl.bRequestType, ctrl.wValue, ctrl.wIndex,
808 tbuf, ctrl.wLength, tmo); 828 tbuf, ctrl.wLength, tmo);
809 usb_lock_device(dev); 829 usb_lock_device(dev);
810 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE); 830 snoop_urb(dev, NULL, pipe, max(i, 0), min(i, 0), COMPLETE, NULL, 0);
811 } 831 }
812 free_page((unsigned long)tbuf); 832 free_page((unsigned long)tbuf);
813 if (i < 0 && i != -EPIPE) { 833 if (i < 0 && i != -EPIPE) {
@@ -853,12 +873,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
853 kfree(tbuf); 873 kfree(tbuf);
854 return -EINVAL; 874 return -EINVAL;
855 } 875 }
856 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); 876 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT, NULL, 0);
857 877
858 usb_unlock_device(dev); 878 usb_unlock_device(dev);
859 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 879 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
860 usb_lock_device(dev); 880 usb_lock_device(dev);
861 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); 881 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE, tbuf, len2);
862 882
863 if (!i && len2) { 883 if (!i && len2) {
864 if (copy_to_user(bulk.data, tbuf, len2)) { 884 if (copy_to_user(bulk.data, tbuf, len2)) {
@@ -873,12 +893,12 @@ static int proc_bulk(struct dev_state *ps, void __user *arg)
873 return -EFAULT; 893 return -EFAULT;
874 } 894 }
875 } 895 }
876 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT); 896 snoop_urb(dev, NULL, pipe, len1, tmo, SUBMIT, tbuf, len1);
877 897
878 usb_unlock_device(dev); 898 usb_unlock_device(dev);
879 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo); 899 i = usb_bulk_msg(dev, pipe, tbuf, len1, &len2, tmo);
880 usb_lock_device(dev); 900 usb_lock_device(dev);
881 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE); 901 snoop_urb(dev, NULL, pipe, len2, i, COMPLETE, NULL, 0);
882 } 902 }
883 kfree(tbuf); 903 kfree(tbuf);
884 if (i < 0) 904 if (i < 0)
@@ -1097,6 +1117,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1097 is_in = 0; 1117 is_in = 0;
1098 uurb->endpoint &= ~USB_DIR_IN; 1118 uurb->endpoint &= ~USB_DIR_IN;
1099 } 1119 }
1120 snoop(&ps->dev->dev, "control urb: bRequestType=%02x "
1121 "bRequest=%02x wValue=%04x "
1122 "wIndex=%04x wLength=%04x\n",
1123 dr->bRequestType, dr->bRequest,
1124 __le16_to_cpup(&dr->wValue),
1125 __le16_to_cpup(&dr->wIndex),
1126 __le16_to_cpup(&dr->wLength));
1100 break; 1127 break;
1101 1128
1102 case USBDEVFS_URB_TYPE_BULK: 1129 case USBDEVFS_URB_TYPE_BULK:
@@ -1104,13 +1131,25 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1104 case USB_ENDPOINT_XFER_CONTROL: 1131 case USB_ENDPOINT_XFER_CONTROL:
1105 case USB_ENDPOINT_XFER_ISOC: 1132 case USB_ENDPOINT_XFER_ISOC:
1106 return -EINVAL; 1133 return -EINVAL;
1107 /* allow single-shot interrupt transfers, at bogus rates */ 1134 case USB_ENDPOINT_XFER_INT:
1135 /* allow single-shot interrupt transfers */
1136 uurb->type = USBDEVFS_URB_TYPE_INTERRUPT;
1137 goto interrupt_urb;
1108 } 1138 }
1109 uurb->number_of_packets = 0; 1139 uurb->number_of_packets = 0;
1110 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE) 1140 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1111 return -EINVAL; 1141 return -EINVAL;
1112 break; 1142 break;
1113 1143
1144 case USBDEVFS_URB_TYPE_INTERRUPT:
1145 if (!usb_endpoint_xfer_int(&ep->desc))
1146 return -EINVAL;
1147 interrupt_urb:
1148 uurb->number_of_packets = 0;
1149 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1150 return -EINVAL;
1151 break;
1152
1114 case USBDEVFS_URB_TYPE_ISO: 1153 case USBDEVFS_URB_TYPE_ISO:
1115 /* arbitrary limit */ 1154 /* arbitrary limit */
1116 if (uurb->number_of_packets < 1 || 1155 if (uurb->number_of_packets < 1 ||
@@ -1143,14 +1182,6 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1143 uurb->buffer_length = totlen; 1182 uurb->buffer_length = totlen;
1144 break; 1183 break;
1145 1184
1146 case USBDEVFS_URB_TYPE_INTERRUPT:
1147 uurb->number_of_packets = 0;
1148 if (!usb_endpoint_xfer_int(&ep->desc))
1149 return -EINVAL;
1150 if (uurb->buffer_length > MAX_USBFS_BUFFER_SIZE)
1151 return -EINVAL;
1152 break;
1153
1154 default: 1185 default:
1155 return -EINVAL; 1186 return -EINVAL;
1156 } 1187 }
@@ -1176,6 +1207,13 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1176 free_async(as); 1207 free_async(as);
1177 return -ENOMEM; 1208 return -ENOMEM;
1178 } 1209 }
1210 /* Isochronous input data may end up being discontiguous
1211 * if some of the packets are short. Clear the buffer so
1212 * that the gaps don't leak kernel data to userspace.
1213 */
1214 if (is_in && uurb->type == USBDEVFS_URB_TYPE_ISO)
1215 memset(as->urb->transfer_buffer, 0,
1216 uurb->buffer_length);
1179 } 1217 }
1180 as->urb->dev = ps->dev; 1218 as->urb->dev = ps->dev;
1181 as->urb->pipe = (uurb->type << 30) | 1219 as->urb->pipe = (uurb->type << 30) |
@@ -1236,7 +1274,9 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1236 } 1274 }
1237 } 1275 }
1238 snoop_urb(ps->dev, as->userurb, as->urb->pipe, 1276 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1239 as->urb->transfer_buffer_length, 0, SUBMIT); 1277 as->urb->transfer_buffer_length, 0, SUBMIT,
1278 is_in ? NULL : as->urb->transfer_buffer,
1279 uurb->buffer_length);
1240 async_newpending(as); 1280 async_newpending(as);
1241 1281
1242 if (usb_endpoint_xfer_bulk(&ep->desc)) { 1282 if (usb_endpoint_xfer_bulk(&ep->desc)) {
@@ -1274,7 +1314,7 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
1274 dev_printk(KERN_DEBUG, &ps->dev->dev, 1314 dev_printk(KERN_DEBUG, &ps->dev->dev,
1275 "usbfs: usb_submit_urb returned %d\n", ret); 1315 "usbfs: usb_submit_urb returned %d\n", ret);
1276 snoop_urb(ps->dev, as->userurb, as->urb->pipe, 1316 snoop_urb(ps->dev, as->userurb, as->urb->pipe,
1277 0, ret, COMPLETE); 1317 0, ret, COMPLETE, NULL, 0);
1278 async_removepending(as); 1318 async_removepending(as);
1279 free_async(as); 1319 free_async(as);
1280 return ret; 1320 return ret;
@@ -1312,10 +1352,14 @@ static int processcompl(struct async *as, void __user * __user *arg)
1312 void __user *addr = as->userurb; 1352 void __user *addr = as->userurb;
1313 unsigned int i; 1353 unsigned int i;
1314 1354
1315 if (as->userbuffer) 1355 if (as->userbuffer && urb->actual_length) {
1316 if (copy_to_user(as->userbuffer, urb->transfer_buffer, 1356 if (urb->number_of_packets > 0) /* Isochronous */
1317 urb->transfer_buffer_length)) 1357 i = urb->transfer_buffer_length;
1358 else /* Non-Isoc */
1359 i = urb->actual_length;
1360 if (copy_to_user(as->userbuffer, urb->transfer_buffer, i))
1318 goto err_out; 1361 goto err_out;
1362 }
1319 if (put_user(as->status, &userurb->status)) 1363 if (put_user(as->status, &userurb->status))
1320 goto err_out; 1364 goto err_out;
1321 if (put_user(urb->actual_length, &userurb->actual_length)) 1365 if (put_user(urb->actual_length, &userurb->actual_length))
@@ -1334,14 +1378,11 @@ static int processcompl(struct async *as, void __user * __user *arg)
1334 } 1378 }
1335 } 1379 }
1336 1380
1337 free_async(as);
1338
1339 if (put_user(addr, (void __user * __user *)arg)) 1381 if (put_user(addr, (void __user * __user *)arg))
1340 return -EFAULT; 1382 return -EFAULT;
1341 return 0; 1383 return 0;
1342 1384
1343err_out: 1385err_out:
1344 free_async(as);
1345 return -EFAULT; 1386 return -EFAULT;
1346} 1387}
1347 1388
@@ -1371,8 +1412,11 @@ static struct async *reap_as(struct dev_state *ps)
1371static int proc_reapurb(struct dev_state *ps, void __user *arg) 1412static int proc_reapurb(struct dev_state *ps, void __user *arg)
1372{ 1413{
1373 struct async *as = reap_as(ps); 1414 struct async *as = reap_as(ps);
1374 if (as) 1415 if (as) {
1375 return processcompl(as, (void __user * __user *)arg); 1416 int retval = processcompl(as, (void __user * __user *)arg);
1417 free_async(as);
1418 return retval;
1419 }
1376 if (signal_pending(current)) 1420 if (signal_pending(current))
1377 return -EINTR; 1421 return -EINTR;
1378 return -EIO; 1422 return -EIO;
@@ -1380,14 +1424,59 @@ static int proc_reapurb(struct dev_state *ps, void __user *arg)
1380 1424
1381static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg) 1425static int proc_reapurbnonblock(struct dev_state *ps, void __user *arg)
1382{ 1426{
1427 int retval;
1383 struct async *as; 1428 struct async *as;
1384 1429
1385 if (!(as = async_getcompleted(ps))) 1430 as = async_getcompleted(ps);
1386 return -EAGAIN; 1431 retval = -EAGAIN;
1387 return processcompl(as, (void __user * __user *)arg); 1432 if (as) {
1433 retval = processcompl(as, (void __user * __user *)arg);
1434 free_async(as);
1435 }
1436 return retval;
1388} 1437}
1389 1438
1390#ifdef CONFIG_COMPAT 1439#ifdef CONFIG_COMPAT
1440static int proc_control_compat(struct dev_state *ps,
1441 struct usbdevfs_ctrltransfer32 __user *p32)
1442{
1443 struct usbdevfs_ctrltransfer __user *p;
1444 __u32 udata;
1445 p = compat_alloc_user_space(sizeof(*p));
1446 if (copy_in_user(p, p32, (sizeof(*p32) - sizeof(compat_caddr_t))) ||
1447 get_user(udata, &p32->data) ||
1448 put_user(compat_ptr(udata), &p->data))
1449 return -EFAULT;
1450 return proc_control(ps, p);
1451}
1452
1453static int proc_bulk_compat(struct dev_state *ps,
1454 struct usbdevfs_bulktransfer32 __user *p32)
1455{
1456 struct usbdevfs_bulktransfer __user *p;
1457 compat_uint_t n;
1458 compat_caddr_t addr;
1459
1460 p = compat_alloc_user_space(sizeof(*p));
1461
1462 if (get_user(n, &p32->ep) || put_user(n, &p->ep) ||
1463 get_user(n, &p32->len) || put_user(n, &p->len) ||
1464 get_user(n, &p32->timeout) || put_user(n, &p->timeout) ||
1465 get_user(addr, &p32->data) || put_user(compat_ptr(addr), &p->data))
1466 return -EFAULT;
1467
1468 return proc_bulk(ps, p);
1469}
1470static int proc_disconnectsignal_compat(struct dev_state *ps, void __user *arg)
1471{
1472 struct usbdevfs_disconnectsignal32 ds;
1473
1474 if (copy_from_user(&ds, arg, sizeof(ds)))
1475 return -EFAULT;
1476 ps->discsignr = ds.signr;
1477 ps->disccontext = compat_ptr(ds.context);
1478 return 0;
1479}
1391 1480
1392static int get_urb32(struct usbdevfs_urb *kurb, 1481static int get_urb32(struct usbdevfs_urb *kurb,
1393 struct usbdevfs_urb32 __user *uurb) 1482 struct usbdevfs_urb32 __user *uurb)
@@ -1435,9 +1524,9 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
1435 void __user *addr = as->userurb; 1524 void __user *addr = as->userurb;
1436 unsigned int i; 1525 unsigned int i;
1437 1526
1438 if (as->userbuffer) 1527 if (as->userbuffer && urb->actual_length)
1439 if (copy_to_user(as->userbuffer, urb->transfer_buffer, 1528 if (copy_to_user(as->userbuffer, urb->transfer_buffer,
1440 urb->transfer_buffer_length)) 1529 urb->actual_length))
1441 return -EFAULT; 1530 return -EFAULT;
1442 if (put_user(as->status, &userurb->status)) 1531 if (put_user(as->status, &userurb->status))
1443 return -EFAULT; 1532 return -EFAULT;
@@ -1457,7 +1546,6 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
1457 } 1546 }
1458 } 1547 }
1459 1548
1460 free_async(as);
1461 if (put_user(ptr_to_compat(addr), (u32 __user *)arg)) 1549 if (put_user(ptr_to_compat(addr), (u32 __user *)arg))
1462 return -EFAULT; 1550 return -EFAULT;
1463 return 0; 1551 return 0;
@@ -1466,8 +1554,11 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
1466static int proc_reapurb_compat(struct dev_state *ps, void __user *arg) 1554static int proc_reapurb_compat(struct dev_state *ps, void __user *arg)
1467{ 1555{
1468 struct async *as = reap_as(ps); 1556 struct async *as = reap_as(ps);
1469 if (as) 1557 if (as) {
1470 return processcompl_compat(as, (void __user * __user *)arg); 1558 int retval = processcompl_compat(as, (void __user * __user *)arg);
1559 free_async(as);
1560 return retval;
1561 }
1471 if (signal_pending(current)) 1562 if (signal_pending(current))
1472 return -EINTR; 1563 return -EINTR;
1473 return -EIO; 1564 return -EIO;
@@ -1475,13 +1566,19 @@ static int proc_reapurb_compat(struct dev_state *ps, void __user *arg)
1475 1566
1476static int proc_reapurbnonblock_compat(struct dev_state *ps, void __user *arg) 1567static int proc_reapurbnonblock_compat(struct dev_state *ps, void __user *arg)
1477{ 1568{
1569 int retval;
1478 struct async *as; 1570 struct async *as;
1479 1571
1480 if (!(as = async_getcompleted(ps))) 1572 retval = -EAGAIN;
1481 return -EAGAIN; 1573 as = async_getcompleted(ps);
1482 return processcompl_compat(as, (void __user * __user *)arg); 1574 if (as) {
1575 retval = processcompl_compat(as, (void __user * __user *)arg);
1576 free_async(as);
1577 }
1578 return retval;
1483} 1579}
1484 1580
1581
1485#endif 1582#endif
1486 1583
1487static int proc_disconnectsignal(struct dev_state *ps, void __user *arg) 1584static int proc_disconnectsignal(struct dev_state *ps, void __user *arg)
@@ -1575,7 +1672,10 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1575 if (driver == NULL || driver->ioctl == NULL) { 1672 if (driver == NULL || driver->ioctl == NULL) {
1576 retval = -ENOTTY; 1673 retval = -ENOTTY;
1577 } else { 1674 } else {
1675 /* keep API that guarantees BKL */
1676 lock_kernel();
1578 retval = driver->ioctl(intf, ctl->ioctl_code, buf); 1677 retval = driver->ioctl(intf, ctl->ioctl_code, buf);
1678 unlock_kernel();
1579 if (retval == -ENOIOCTLCMD) 1679 if (retval == -ENOIOCTLCMD)
1580 retval = -ENOTTY; 1680 retval = -ENOTTY;
1581 } 1681 }
@@ -1648,16 +1748,17 @@ static int proc_release_port(struct dev_state *ps, void __user *arg)
1648 * are assuming that somehow the configuration has been prevented from 1748 * are assuming that somehow the configuration has been prevented from
1649 * changing. But there's no mechanism to ensure that... 1749 * changing. But there's no mechanism to ensure that...
1650 */ 1750 */
1651static int usbdev_ioctl(struct inode *inode, struct file *file, 1751static long usbdev_do_ioctl(struct file *file, unsigned int cmd,
1652 unsigned int cmd, unsigned long arg) 1752 void __user *p)
1653{ 1753{
1654 struct dev_state *ps = file->private_data; 1754 struct dev_state *ps = file->private_data;
1755 struct inode *inode = file->f_path.dentry->d_inode;
1655 struct usb_device *dev = ps->dev; 1756 struct usb_device *dev = ps->dev;
1656 void __user *p = (void __user *)arg;
1657 int ret = -ENOTTY; 1757 int ret = -ENOTTY;
1658 1758
1659 if (!(file->f_mode & FMODE_WRITE)) 1759 if (!(file->f_mode & FMODE_WRITE))
1660 return -EPERM; 1760 return -EPERM;
1761
1661 usb_lock_device(dev); 1762 usb_lock_device(dev);
1662 if (!connected(ps)) { 1763 if (!connected(ps)) {
1663 usb_unlock_device(dev); 1764 usb_unlock_device(dev);
@@ -1726,6 +1827,24 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1726 break; 1827 break;
1727 1828
1728#ifdef CONFIG_COMPAT 1829#ifdef CONFIG_COMPAT
1830 case USBDEVFS_CONTROL32:
1831 snoop(&dev->dev, "%s: CONTROL32\n", __func__);
1832 ret = proc_control_compat(ps, p);
1833 if (ret >= 0)
1834 inode->i_mtime = CURRENT_TIME;
1835 break;
1836
1837 case USBDEVFS_BULK32:
1838 snoop(&dev->dev, "%s: BULK32\n", __func__);
1839 ret = proc_bulk_compat(ps, p);
1840 if (ret >= 0)
1841 inode->i_mtime = CURRENT_TIME;
1842 break;
1843
1844 case USBDEVFS_DISCSIGNAL32:
1845 snoop(&dev->dev, "%s: DISCSIGNAL32\n", __func__);
1846 ret = proc_disconnectsignal_compat(ps, p);
1847 break;
1729 1848
1730 case USBDEVFS_SUBMITURB32: 1849 case USBDEVFS_SUBMITURB32:
1731 snoop(&dev->dev, "%s: SUBMITURB32\n", __func__); 1850 snoop(&dev->dev, "%s: SUBMITURB32\n", __func__);
@@ -1745,7 +1864,7 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1745 break; 1864 break;
1746 1865
1747 case USBDEVFS_IOCTL32: 1866 case USBDEVFS_IOCTL32:
1748 snoop(&dev->dev, "%s: IOCTL\n", __func__); 1867 snoop(&dev->dev, "%s: IOCTL32\n", __func__);
1749 ret = proc_ioctl_compat(ps, ptr_to_compat(p)); 1868 ret = proc_ioctl_compat(ps, ptr_to_compat(p));
1750 break; 1869 break;
1751#endif 1870#endif
@@ -1801,6 +1920,28 @@ static int usbdev_ioctl(struct inode *inode, struct file *file,
1801 return ret; 1920 return ret;
1802} 1921}
1803 1922
1923static long usbdev_ioctl(struct file *file, unsigned int cmd,
1924 unsigned long arg)
1925{
1926 int ret;
1927
1928 ret = usbdev_do_ioctl(file, cmd, (void __user *)arg);
1929
1930 return ret;
1931}
1932
1933#ifdef CONFIG_COMPAT
1934static long usbdev_compat_ioctl(struct file *file, unsigned int cmd,
1935 unsigned long arg)
1936{
1937 int ret;
1938
1939 ret = usbdev_do_ioctl(file, cmd, compat_ptr(arg));
1940
1941 return ret;
1942}
1943#endif
1944
1804/* No kernel lock - fine */ 1945/* No kernel lock - fine */
1805static unsigned int usbdev_poll(struct file *file, 1946static unsigned int usbdev_poll(struct file *file,
1806 struct poll_table_struct *wait) 1947 struct poll_table_struct *wait)
@@ -1817,13 +1958,16 @@ static unsigned int usbdev_poll(struct file *file,
1817} 1958}
1818 1959
1819const struct file_operations usbdev_file_operations = { 1960const struct file_operations usbdev_file_operations = {
1820 .owner = THIS_MODULE, 1961 .owner = THIS_MODULE,
1821 .llseek = usbdev_lseek, 1962 .llseek = usbdev_lseek,
1822 .read = usbdev_read, 1963 .read = usbdev_read,
1823 .poll = usbdev_poll, 1964 .poll = usbdev_poll,
1824 .ioctl = usbdev_ioctl, 1965 .unlocked_ioctl = usbdev_ioctl,
1825 .open = usbdev_open, 1966#ifdef CONFIG_COMPAT
1826 .release = usbdev_release, 1967 .compat_ioctl = usbdev_compat_ioctl,
1968#endif
1969 .open = usbdev_open,
1970 .release = usbdev_release,
1827}; 1971};
1828 1972
1829static void usbdev_remove(struct usb_device *udev) 1973static void usbdev_remove(struct usb_device *udev)
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 4f864472c5c4..2f3dc4cdf79b 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -23,9 +23,10 @@
23 */ 23 */
24 24
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/slab.h>
26#include <linux/usb.h> 27#include <linux/usb.h>
27#include <linux/usb/quirks.h> 28#include <linux/usb/quirks.h>
28#include <linux/workqueue.h> 29#include <linux/pm_runtime.h>
29#include "hcd.h" 30#include "hcd.h"
30#include "usb.h" 31#include "usb.h"
31 32
@@ -83,6 +84,47 @@ static ssize_t store_new_id(struct device_driver *driver,
83} 84}
84static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id); 85static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
85 86
87/**
88 * store_remove_id - remove a USB device ID from this driver
89 * @driver: target device driver
90 * @buf: buffer for scanning device ID data
91 * @count: input size
92 *
93 * Removes a dynamic usb device ID from this driver.
94 */
95static ssize_t
96store_remove_id(struct device_driver *driver, const char *buf, size_t count)
97{
98 struct usb_dynid *dynid, *n;
99 struct usb_driver *usb_driver = to_usb_driver(driver);
100 u32 idVendor = 0;
101 u32 idProduct = 0;
102 int fields = 0;
103 int retval = 0;
104
105 fields = sscanf(buf, "%x %x", &idVendor, &idProduct);
106 if (fields < 2)
107 return -EINVAL;
108
109 spin_lock(&usb_driver->dynids.lock);
110 list_for_each_entry_safe(dynid, n, &usb_driver->dynids.list, node) {
111 struct usb_device_id *id = &dynid->id;
112 if ((id->idVendor == idVendor) &&
113 (id->idProduct == idProduct)) {
114 list_del(&dynid->node);
115 kfree(dynid);
116 retval = 0;
117 break;
118 }
119 }
120 spin_unlock(&usb_driver->dynids.lock);
121
122 if (retval)
123 return retval;
124 return count;
125}
126static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id);
127
86static int usb_create_newid_file(struct usb_driver *usb_drv) 128static int usb_create_newid_file(struct usb_driver *usb_drv)
87{ 129{
88 int error = 0; 130 int error = 0;
@@ -107,6 +149,21 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)
107 &driver_attr_new_id); 149 &driver_attr_new_id);
108} 150}
109 151
152static int
153usb_create_removeid_file(struct usb_driver *drv)
154{
155 int error = 0;
156 if (drv->probe != NULL)
157 error = driver_create_file(&drv->drvwrap.driver,
158 &driver_attr_remove_id);
159 return error;
160}
161
162static void usb_remove_removeid_file(struct usb_driver *drv)
163{
164 driver_remove_file(&drv->drvwrap.driver, &driver_attr_remove_id);
165}
166
110static void usb_free_dynids(struct usb_driver *usb_drv) 167static void usb_free_dynids(struct usb_driver *usb_drv)
111{ 168{
112 struct usb_dynid *dynid, *n; 169 struct usb_dynid *dynid, *n;
@@ -128,6 +185,16 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)
128{ 185{
129} 186}
130 187
188static int
189usb_create_removeid_file(struct usb_driver *drv)
190{
191 return 0;
192}
193
194static void usb_remove_removeid_file(struct usb_driver *drv)
195{
196}
197
131static inline void usb_free_dynids(struct usb_driver *usb_drv) 198static inline void usb_free_dynids(struct usb_driver *usb_drv)
132{ 199{
133} 200}
@@ -155,7 +222,7 @@ static int usb_probe_device(struct device *dev)
155{ 222{
156 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); 223 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
157 struct usb_device *udev = to_usb_device(dev); 224 struct usb_device *udev = to_usb_device(dev);
158 int error = -ENODEV; 225 int error = 0;
159 226
160 dev_dbg(dev, "%s\n", __func__); 227 dev_dbg(dev, "%s\n", __func__);
161 228
@@ -164,18 +231,23 @@ static int usb_probe_device(struct device *dev)
164 /* The device should always appear to be in use 231 /* The device should always appear to be in use
165 * unless the driver suports autosuspend. 232 * unless the driver suports autosuspend.
166 */ 233 */
167 udev->pm_usage_cnt = !(udriver->supports_autosuspend); 234 if (!udriver->supports_autosuspend)
235 error = usb_autoresume_device(udev);
168 236
169 error = udriver->probe(udev); 237 if (!error)
238 error = udriver->probe(udev);
170 return error; 239 return error;
171} 240}
172 241
173/* called from driver core with dev locked */ 242/* called from driver core with dev locked */
174static int usb_unbind_device(struct device *dev) 243static int usb_unbind_device(struct device *dev)
175{ 244{
245 struct usb_device *udev = to_usb_device(dev);
176 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); 246 struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
177 247
178 udriver->disconnect(to_usb_device(dev)); 248 udriver->disconnect(udev);
249 if (!udriver->supports_autosuspend)
250 usb_autosuspend_device(udev);
179 return 0; 251 return 0;
180} 252}
181 253
@@ -208,60 +280,62 @@ static int usb_probe_interface(struct device *dev)
208 intf->needs_binding = 0; 280 intf->needs_binding = 0;
209 281
210 if (usb_device_is_owned(udev)) 282 if (usb_device_is_owned(udev))
211 return -ENODEV; 283 return error;
212 284
213 if (udev->authorized == 0) { 285 if (udev->authorized == 0) {
214 dev_err(&intf->dev, "Device is not authorized for usage\n"); 286 dev_err(&intf->dev, "Device is not authorized for usage\n");
215 return -ENODEV; 287 return error;
216 } 288 }
217 289
218 id = usb_match_id(intf, driver->id_table); 290 id = usb_match_id(intf, driver->id_table);
219 if (!id) 291 if (!id)
220 id = usb_match_dynamic_id(intf, driver); 292 id = usb_match_dynamic_id(intf, driver);
221 if (id) { 293 if (!id)
222 dev_dbg(dev, "%s - got id\n", __func__); 294 return error;
223
224 error = usb_autoresume_device(udev);
225 if (error)
226 return error;
227
228 /* Interface "power state" doesn't correspond to any hardware
229 * state whatsoever. We use it to record when it's bound to
230 * a driver that may start I/0: it's not frozen/quiesced.
231 */
232 mark_active(intf);
233 intf->condition = USB_INTERFACE_BINDING;
234 295
235 /* The interface should always appear to be in use 296 dev_dbg(dev, "%s - got id\n", __func__);
236 * unless the driver suports autosuspend.
237 */
238 atomic_set(&intf->pm_usage_cnt, !driver->supports_autosuspend);
239 297
240 /* Carry out a deferred switch to altsetting 0 */ 298 error = usb_autoresume_device(udev);
241 if (intf->needs_altsetting0) { 299 if (error)
242 error = usb_set_interface(udev, intf->altsetting[0]. 300 return error;
243 desc.bInterfaceNumber, 0);
244 if (error < 0)
245 goto err;
246 301
247 intf->needs_altsetting0 = 0; 302 intf->condition = USB_INTERFACE_BINDING;
248 }
249 303
250 error = driver->probe(intf, id); 304 /* Probed interfaces are initially active. They are
251 if (error) 305 * runtime-PM-enabled only if the driver has autosuspend support.
306 * They are sensitive to their children's power states.
307 */
308 pm_runtime_set_active(dev);
309 pm_suspend_ignore_children(dev, false);
310 if (driver->supports_autosuspend)
311 pm_runtime_enable(dev);
312
313 /* Carry out a deferred switch to altsetting 0 */
314 if (intf->needs_altsetting0) {
315 error = usb_set_interface(udev, intf->altsetting[0].
316 desc.bInterfaceNumber, 0);
317 if (error < 0)
252 goto err; 318 goto err;
253 319 intf->needs_altsetting0 = 0;
254 intf->condition = USB_INTERFACE_BOUND;
255 usb_autosuspend_device(udev);
256 } 320 }
257 321
322 error = driver->probe(intf, id);
323 if (error)
324 goto err;
325
326 intf->condition = USB_INTERFACE_BOUND;
327 usb_autosuspend_device(udev);
258 return error; 328 return error;
259 329
260err: 330 err:
261 mark_quiesced(intf);
262 intf->needs_remote_wakeup = 0; 331 intf->needs_remote_wakeup = 0;
263 intf->condition = USB_INTERFACE_UNBOUND; 332 intf->condition = USB_INTERFACE_UNBOUND;
264 usb_cancel_queued_reset(intf); 333 usb_cancel_queued_reset(intf);
334
335 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
336 pm_runtime_disable(dev);
337 pm_runtime_set_suspended(dev);
338
265 usb_autosuspend_device(udev); 339 usb_autosuspend_device(udev);
266 return error; 340 return error;
267} 341}
@@ -311,9 +385,17 @@ static int usb_unbind_interface(struct device *dev)
311 usb_set_intfdata(intf, NULL); 385 usb_set_intfdata(intf, NULL);
312 386
313 intf->condition = USB_INTERFACE_UNBOUND; 387 intf->condition = USB_INTERFACE_UNBOUND;
314 mark_quiesced(intf);
315 intf->needs_remote_wakeup = 0; 388 intf->needs_remote_wakeup = 0;
316 389
390 /* Unbound interfaces are always runtime-PM-disabled and -suspended */
391 pm_runtime_disable(dev);
392 pm_runtime_set_suspended(dev);
393
394 /* Undo any residual pm_autopm_get_interface_* calls */
395 for (r = atomic_read(&intf->pm_usage_cnt); r > 0; --r)
396 usb_autopm_put_interface_no_suspend(intf);
397 atomic_set(&intf->pm_usage_cnt, 0);
398
317 if (!error) 399 if (!error)
318 usb_autosuspend_device(udev); 400 usb_autosuspend_device(udev);
319 401
@@ -344,7 +426,6 @@ int usb_driver_claim_interface(struct usb_driver *driver,
344 struct usb_interface *iface, void *priv) 426 struct usb_interface *iface, void *priv)
345{ 427{
346 struct device *dev = &iface->dev; 428 struct device *dev = &iface->dev;
347 struct usb_device *udev = interface_to_usbdev(iface);
348 int retval = 0; 429 int retval = 0;
349 430
350 if (dev->driver) 431 if (dev->driver)
@@ -354,11 +435,16 @@ int usb_driver_claim_interface(struct usb_driver *driver,
354 usb_set_intfdata(iface, priv); 435 usb_set_intfdata(iface, priv);
355 iface->needs_binding = 0; 436 iface->needs_binding = 0;
356 437
357 usb_pm_lock(udev);
358 iface->condition = USB_INTERFACE_BOUND; 438 iface->condition = USB_INTERFACE_BOUND;
359 mark_active(iface); 439
360 atomic_set(&iface->pm_usage_cnt, !driver->supports_autosuspend); 440 /* Claimed interfaces are initially inactive (suspended). They are
361 usb_pm_unlock(udev); 441 * runtime-PM-enabled only if the driver has autosuspend support.
442 * They are sensitive to their children's power states.
443 */
444 pm_runtime_set_suspended(dev);
445 pm_suspend_ignore_children(dev, false);
446 if (driver->supports_autosuspend)
447 pm_runtime_enable(dev);
362 448
363 /* if interface was already added, bind now; else let 449 /* if interface was already added, bind now; else let
364 * the future device_add() bind it, bypassing probe() 450 * the future device_add() bind it, bypassing probe()
@@ -404,10 +490,10 @@ void usb_driver_release_interface(struct usb_driver *driver,
404 if (device_is_registered(dev)) { 490 if (device_is_registered(dev)) {
405 device_release_driver(dev); 491 device_release_driver(dev);
406 } else { 492 } else {
407 down(&dev->sem); 493 device_lock(dev);
408 usb_unbind_interface(dev); 494 usb_unbind_interface(dev);
409 dev->driver = NULL; 495 dev->driver = NULL;
410 up(&dev->sem); 496 device_unlock(dev);
411 } 497 }
412} 498}
413EXPORT_SYMBOL_GPL(usb_driver_release_interface); 499EXPORT_SYMBOL_GPL(usb_driver_release_interface);
@@ -625,9 +711,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
625{ 711{
626 struct usb_device *usb_dev; 712 struct usb_device *usb_dev;
627 713
628 /* driver is often null here; dev_dbg() would oops */
629 pr_debug("usb %s: uevent\n", dev_name(dev));
630
631 if (is_usb_device(dev)) { 714 if (is_usb_device(dev)) {
632 usb_dev = to_usb_device(dev); 715 usb_dev = to_usb_device(dev);
633 } else if (is_usb_interface(dev)) { 716 } else if (is_usb_interface(dev)) {
@@ -639,6 +722,7 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
639 } 722 }
640 723
641 if (usb_dev->devnum < 0) { 724 if (usb_dev->devnum < 0) {
725 /* driver is often null here; dev_dbg() would oops */
642 pr_debug("usb %s: already deleted?\n", dev_name(dev)); 726 pr_debug("usb %s: already deleted?\n", dev_name(dev));
643 return -ENODEV; 727 return -ENODEV;
644 } 728 }
@@ -774,19 +858,34 @@ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,
774 INIT_LIST_HEAD(&new_driver->dynids.list); 858 INIT_LIST_HEAD(&new_driver->dynids.list);
775 859
776 retval = driver_register(&new_driver->drvwrap.driver); 860 retval = driver_register(&new_driver->drvwrap.driver);
861 if (retval)
862 goto out;
777 863
778 if (!retval) { 864 usbfs_update_special();
779 pr_info("%s: registered new interface driver %s\n", 865
866 retval = usb_create_newid_file(new_driver);
867 if (retval)
868 goto out_newid;
869
870 retval = usb_create_removeid_file(new_driver);
871 if (retval)
872 goto out_removeid;
873
874 pr_info("%s: registered new interface driver %s\n",
780 usbcore_name, new_driver->name); 875 usbcore_name, new_driver->name);
781 usbfs_update_special();
782 usb_create_newid_file(new_driver);
783 } else {
784 printk(KERN_ERR "%s: error %d registering interface "
785 " driver %s\n",
786 usbcore_name, retval, new_driver->name);
787 }
788 876
877out:
789 return retval; 878 return retval;
879
880out_removeid:
881 usb_remove_newid_file(new_driver);
882out_newid:
883 driver_unregister(&new_driver->drvwrap.driver);
884
885 printk(KERN_ERR "%s: error %d registering interface "
886 " driver %s\n",
887 usbcore_name, retval, new_driver->name);
888 goto out;
790} 889}
791EXPORT_SYMBOL_GPL(usb_register_driver); 890EXPORT_SYMBOL_GPL(usb_register_driver);
792 891
@@ -806,6 +905,7 @@ void usb_deregister(struct usb_driver *driver)
806 pr_info("%s: deregistering interface driver %s\n", 905 pr_info("%s: deregistering interface driver %s\n",
807 usbcore_name, driver->name); 906 usbcore_name, driver->name);
808 907
908 usb_remove_removeid_file(driver);
809 usb_remove_newid_file(driver); 909 usb_remove_newid_file(driver);
810 usb_free_dynids(driver); 910 usb_free_dynids(driver);
811 driver_unregister(&driver->drvwrap.driver); 911 driver_unregister(&driver->drvwrap.driver);
@@ -901,7 +1001,6 @@ static void do_unbind_rebind(struct usb_device *udev, int action)
901 } 1001 }
902} 1002}
903 1003
904/* Caller has locked udev's pm_mutex */
905static int usb_suspend_device(struct usb_device *udev, pm_message_t msg) 1004static int usb_suspend_device(struct usb_device *udev, pm_message_t msg)
906{ 1005{
907 struct usb_device_driver *udriver; 1006 struct usb_device_driver *udriver;
@@ -925,7 +1024,6 @@ static int usb_suspend_device(struct usb_device *udev, pm_message_t msg)
925 return status; 1024 return status;
926} 1025}
927 1026
928/* Caller has locked udev's pm_mutex */
929static int usb_resume_device(struct usb_device *udev, pm_message_t msg) 1027static int usb_resume_device(struct usb_device *udev, pm_message_t msg)
930{ 1028{
931 struct usb_device_driver *udriver; 1029 struct usb_device_driver *udriver;
@@ -940,6 +1038,14 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg)
940 goto done; 1038 goto done;
941 } 1039 }
942 1040
1041 /* Non-root devices on a full/low-speed bus must wait for their
1042 * companion high-speed root hub, in case a handoff is needed.
1043 */
1044 if (!(msg.event & PM_EVENT_AUTO) && udev->parent &&
1045 udev->bus->hs_companion)
1046 device_pm_wait_for_dev(&udev->dev,
1047 &udev->bus->hs_companion->root_hub->dev);
1048
943 if (udev->quirks & USB_QUIRK_RESET_RESUME) 1049 if (udev->quirks & USB_QUIRK_RESET_RESUME)
944 udev->reset_resume = 1; 1050 udev->reset_resume = 1;
945 1051
@@ -948,32 +1054,23 @@ static int usb_resume_device(struct usb_device *udev, pm_message_t msg)
948 1054
949 done: 1055 done:
950 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); 1056 dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status);
951 if (status == 0)
952 udev->autoresume_disabled = 0;
953 return status; 1057 return status;
954} 1058}
955 1059
956/* Caller has locked intf's usb_device's pm mutex */
957static int usb_suspend_interface(struct usb_device *udev, 1060static int usb_suspend_interface(struct usb_device *udev,
958 struct usb_interface *intf, pm_message_t msg) 1061 struct usb_interface *intf, pm_message_t msg)
959{ 1062{
960 struct usb_driver *driver; 1063 struct usb_driver *driver;
961 int status = 0; 1064 int status = 0;
962 1065
963 /* with no hardware, USB interfaces only use FREEZE and ON states */ 1066 if (udev->state == USB_STATE_NOTATTACHED ||
964 if (udev->state == USB_STATE_NOTATTACHED || !is_active(intf)) 1067 intf->condition == USB_INTERFACE_UNBOUND)
965 goto done;
966
967 /* This can happen; see usb_driver_release_interface() */
968 if (intf->condition == USB_INTERFACE_UNBOUND)
969 goto done; 1068 goto done;
970 driver = to_usb_driver(intf->dev.driver); 1069 driver = to_usb_driver(intf->dev.driver);
971 1070
972 if (driver->suspend) { 1071 if (driver->suspend) {
973 status = driver->suspend(intf, msg); 1072 status = driver->suspend(intf, msg);
974 if (status == 0) 1073 if (status && !(msg.event & PM_EVENT_AUTO))
975 mark_quiesced(intf);
976 else if (!(msg.event & PM_EVENT_AUTO))
977 dev_err(&intf->dev, "%s error %d\n", 1074 dev_err(&intf->dev, "%s error %d\n",
978 "suspend", status); 1075 "suspend", status);
979 } else { 1076 } else {
@@ -981,7 +1078,6 @@ static int usb_suspend_interface(struct usb_device *udev,
981 intf->needs_binding = 1; 1078 intf->needs_binding = 1;
982 dev_warn(&intf->dev, "no %s for driver %s?\n", 1079 dev_warn(&intf->dev, "no %s for driver %s?\n",
983 "suspend", driver->name); 1080 "suspend", driver->name);
984 mark_quiesced(intf);
985 } 1081 }
986 1082
987 done: 1083 done:
@@ -989,14 +1085,13 @@ static int usb_suspend_interface(struct usb_device *udev,
989 return status; 1085 return status;
990} 1086}
991 1087
992/* Caller has locked intf's usb_device's pm_mutex */
993static int usb_resume_interface(struct usb_device *udev, 1088static int usb_resume_interface(struct usb_device *udev,
994 struct usb_interface *intf, pm_message_t msg, int reset_resume) 1089 struct usb_interface *intf, pm_message_t msg, int reset_resume)
995{ 1090{
996 struct usb_driver *driver; 1091 struct usb_driver *driver;
997 int status = 0; 1092 int status = 0;
998 1093
999 if (udev->state == USB_STATE_NOTATTACHED || is_active(intf)) 1094 if (udev->state == USB_STATE_NOTATTACHED)
1000 goto done; 1095 goto done;
1001 1096
1002 /* Don't let autoresume interfere with unbinding */ 1097 /* Don't let autoresume interfere with unbinding */
@@ -1047,90 +1142,11 @@ static int usb_resume_interface(struct usb_device *udev,
1047 1142
1048done: 1143done:
1049 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); 1144 dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status);
1050 if (status == 0 && intf->condition == USB_INTERFACE_BOUND)
1051 mark_active(intf);
1052 1145
1053 /* Later we will unbind the driver and/or reprobe, if necessary */ 1146 /* Later we will unbind the driver and/or reprobe, if necessary */
1054 return status; 1147 return status;
1055} 1148}
1056 1149
1057#ifdef CONFIG_USB_SUSPEND
1058
1059/* Internal routine to check whether we may autosuspend a device. */
1060static int autosuspend_check(struct usb_device *udev, int reschedule)
1061{
1062 int i;
1063 struct usb_interface *intf;
1064 unsigned long suspend_time, j;
1065
1066 /* For autosuspend, fail fast if anything is in use or autosuspend
1067 * is disabled. Also fail if any interfaces require remote wakeup
1068 * but it isn't available.
1069 */
1070 if (udev->pm_usage_cnt > 0)
1071 return -EBUSY;
1072 if (udev->autosuspend_delay < 0 || udev->autosuspend_disabled)
1073 return -EPERM;
1074
1075 suspend_time = udev->last_busy + udev->autosuspend_delay;
1076 if (udev->actconfig) {
1077 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1078 intf = udev->actconfig->interface[i];
1079 if (!is_active(intf))
1080 continue;
1081 if (atomic_read(&intf->pm_usage_cnt) > 0)
1082 return -EBUSY;
1083 if (intf->needs_remote_wakeup &&
1084 !udev->do_remote_wakeup) {
1085 dev_dbg(&udev->dev, "remote wakeup needed "
1086 "for autosuspend\n");
1087 return -EOPNOTSUPP;
1088 }
1089
1090 /* Don't allow autosuspend if the device will need
1091 * a reset-resume and any of its interface drivers
1092 * doesn't include support.
1093 */
1094 if (udev->quirks & USB_QUIRK_RESET_RESUME) {
1095 struct usb_driver *driver;
1096
1097 driver = to_usb_driver(intf->dev.driver);
1098 if (!driver->reset_resume ||
1099 intf->needs_remote_wakeup)
1100 return -EOPNOTSUPP;
1101 }
1102 }
1103 }
1104
1105 /* If everything is okay but the device hasn't been idle for long
1106 * enough, queue a delayed autosuspend request. If the device
1107 * _has_ been idle for long enough and the reschedule flag is set,
1108 * likewise queue a delayed (1 second) autosuspend request.
1109 */
1110 j = jiffies;
1111 if (time_before(j, suspend_time))
1112 reschedule = 1;
1113 else
1114 suspend_time = j + HZ;
1115 if (reschedule) {
1116 if (!timer_pending(&udev->autosuspend.timer)) {
1117 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1118 round_jiffies_up_relative(suspend_time - j));
1119 }
1120 return -EAGAIN;
1121 }
1122 return 0;
1123}
1124
1125#else
1126
1127static inline int autosuspend_check(struct usb_device *udev, int reschedule)
1128{
1129 return 0;
1130}
1131
1132#endif /* CONFIG_USB_SUSPEND */
1133
1134/** 1150/**
1135 * usb_suspend_both - suspend a USB device and its interfaces 1151 * usb_suspend_both - suspend a USB device and its interfaces
1136 * @udev: the usb_device to suspend 1152 * @udev: the usb_device to suspend
@@ -1142,52 +1158,29 @@ static inline int autosuspend_check(struct usb_device *udev, int reschedule)
1142 * all the interfaces which were suspended are resumed so that they remain 1158 * all the interfaces which were suspended are resumed so that they remain
1143 * in the same state as the device. 1159 * in the same state as the device.
1144 * 1160 *
1145 * If an autosuspend is in progress the routine checks first to make sure 1161 * Autosuspend requests originating from a child device or an interface
1146 * that neither the device itself or any of its active interfaces is in use 1162 * driver may be made without the protection of @udev's device lock, but
1147 * (pm_usage_cnt is greater than 0). If they are, the autosuspend fails. 1163 * all other suspend calls will hold the lock. Usbcore will insure that
1148 * 1164 * method calls do not arrive during bind, unbind, or reset operations.
1149 * If the suspend succeeds, the routine recursively queues an autosuspend 1165 * However drivers must be prepared to handle suspend calls arriving at
1150 * request for @udev's parent device, thereby propagating the change up 1166 * unpredictable times.
1151 * the device tree. If all of the parent's children are now suspended,
1152 * the parent will autosuspend in turn.
1153 *
1154 * The suspend method calls are subject to mutual exclusion under control
1155 * of @udev's pm_mutex. Many of these calls are also under the protection
1156 * of @udev's device lock (including all requests originating outside the
1157 * USB subsystem), but autosuspend requests generated by a child device or
1158 * interface driver may not be. Usbcore will insure that the method calls
1159 * do not arrive during bind, unbind, or reset operations. However, drivers
1160 * must be prepared to handle suspend calls arriving at unpredictable times.
1161 * The only way to block such calls is to do an autoresume (preventing
1162 * autosuspends) while holding @udev's device lock (preventing outside
1163 * suspends).
1164 *
1165 * The caller must hold @udev->pm_mutex.
1166 * 1167 *
1167 * This routine can run only in process context. 1168 * This routine can run only in process context.
1168 */ 1169 */
1169static int usb_suspend_both(struct usb_device *udev, pm_message_t msg) 1170static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1170{ 1171{
1171 int status = 0; 1172 int status = 0;
1172 int i = 0; 1173 int i = 0, n = 0;
1173 struct usb_interface *intf; 1174 struct usb_interface *intf;
1174 struct usb_device *parent = udev->parent;
1175 1175
1176 if (udev->state == USB_STATE_NOTATTACHED || 1176 if (udev->state == USB_STATE_NOTATTACHED ||
1177 udev->state == USB_STATE_SUSPENDED) 1177 udev->state == USB_STATE_SUSPENDED)
1178 goto done; 1178 goto done;
1179 1179
1180 udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
1181
1182 if (msg.event & PM_EVENT_AUTO) {
1183 status = autosuspend_check(udev, 0);
1184 if (status < 0)
1185 goto done;
1186 }
1187
1188 /* Suspend all the interfaces and then udev itself */ 1180 /* Suspend all the interfaces and then udev itself */
1189 if (udev->actconfig) { 1181 if (udev->actconfig) {
1190 for (; i < udev->actconfig->desc.bNumInterfaces; i++) { 1182 n = udev->actconfig->desc.bNumInterfaces;
1183 for (i = n - 1; i >= 0; --i) {
1191 intf = udev->actconfig->interface[i]; 1184 intf = udev->actconfig->interface[i];
1192 status = usb_suspend_interface(udev, intf, msg); 1185 status = usb_suspend_interface(udev, intf, msg);
1193 if (status != 0) 1186 if (status != 0)
@@ -1199,35 +1192,21 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1199 1192
1200 /* If the suspend failed, resume interfaces that did get suspended */ 1193 /* If the suspend failed, resume interfaces that did get suspended */
1201 if (status != 0) { 1194 if (status != 0) {
1202 pm_message_t msg2; 1195 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME);
1203 1196 while (++i < n) {
1204 msg2.event = msg.event ^ (PM_EVENT_SUSPEND | PM_EVENT_RESUME);
1205 while (--i >= 0) {
1206 intf = udev->actconfig->interface[i]; 1197 intf = udev->actconfig->interface[i];
1207 usb_resume_interface(udev, intf, msg2, 0); 1198 usb_resume_interface(udev, intf, msg, 0);
1208 } 1199 }
1209 1200
1210 /* Try another autosuspend when the interfaces aren't busy */ 1201 /* If the suspend succeeded then prevent any more URB submissions
1211 if (msg.event & PM_EVENT_AUTO) 1202 * and flush any outstanding URBs.
1212 autosuspend_check(udev, status == -EBUSY);
1213
1214 /* If the suspend succeeded then prevent any more URB submissions,
1215 * flush any outstanding URBs, and propagate the suspend up the tree.
1216 */ 1203 */
1217 } else { 1204 } else {
1218 cancel_delayed_work(&udev->autosuspend);
1219 udev->can_submit = 0; 1205 udev->can_submit = 0;
1220 for (i = 0; i < 16; ++i) { 1206 for (i = 0; i < 16; ++i) {
1221 usb_hcd_flush_endpoint(udev, udev->ep_out[i]); 1207 usb_hcd_flush_endpoint(udev, udev->ep_out[i]);
1222 usb_hcd_flush_endpoint(udev, udev->ep_in[i]); 1208 usb_hcd_flush_endpoint(udev, udev->ep_in[i]);
1223 } 1209 }
1224
1225 /* If this is just a FREEZE or a PRETHAW, udev might
1226 * not really be suspended. Only true suspends get
1227 * propagated up the device tree.
1228 */
1229 if (parent && udev->state == USB_STATE_SUSPENDED)
1230 usb_autosuspend_device(parent);
1231 } 1210 }
1232 1211
1233 done: 1212 done:
@@ -1244,23 +1223,12 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1244 * the resume method for @udev and then calls the resume methods for all 1223 * the resume method for @udev and then calls the resume methods for all
1245 * the interface drivers in @udev. 1224 * the interface drivers in @udev.
1246 * 1225 *
1247 * Before starting the resume, the routine calls itself recursively for 1226 * Autoresume requests originating from a child device or an interface
1248 * the parent device of @udev, thereby propagating the change up the device 1227 * driver may be made without the protection of @udev's device lock, but
1249 * tree and assuring that @udev will be able to resume. If the parent is 1228 * all other resume calls will hold the lock. Usbcore will insure that
1250 * unable to resume successfully, the routine fails. 1229 * method calls do not arrive during bind, unbind, or reset operations.
1251 * 1230 * However drivers must be prepared to handle resume calls arriving at
1252 * The resume method calls are subject to mutual exclusion under control 1231 * unpredictable times.
1253 * of @udev's pm_mutex. Many of these calls are also under the protection
1254 * of @udev's device lock (including all requests originating outside the
1255 * USB subsystem), but autoresume requests generated by a child device or
1256 * interface driver may not be. Usbcore will insure that the method calls
1257 * do not arrive during bind, unbind, or reset operations. However, drivers
1258 * must be prepared to handle resume calls arriving at unpredictable times.
1259 * The only way to block such calls is to do an autoresume (preventing
1260 * other autoresumes) while holding @udev's device lock (preventing outside
1261 * resumes).
1262 *
1263 * The caller must hold @udev->pm_mutex.
1264 * 1232 *
1265 * This routine can run only in process context. 1233 * This routine can run only in process context.
1266 */ 1234 */
@@ -1269,53 +1237,18 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
1269 int status = 0; 1237 int status = 0;
1270 int i; 1238 int i;
1271 struct usb_interface *intf; 1239 struct usb_interface *intf;
1272 struct usb_device *parent = udev->parent;
1273 1240
1274 cancel_delayed_work(&udev->autosuspend);
1275 if (udev->state == USB_STATE_NOTATTACHED) { 1241 if (udev->state == USB_STATE_NOTATTACHED) {
1276 status = -ENODEV; 1242 status = -ENODEV;
1277 goto done; 1243 goto done;
1278 } 1244 }
1279 udev->can_submit = 1; 1245 udev->can_submit = 1;
1280 1246
1281 /* Propagate the resume up the tree, if necessary */ 1247 /* Resume the device */
1282 if (udev->state == USB_STATE_SUSPENDED) { 1248 if (udev->state == USB_STATE_SUSPENDED || udev->reset_resume)
1283 if ((msg.event & PM_EVENT_AUTO) &&
1284 udev->autoresume_disabled) {
1285 status = -EPERM;
1286 goto done;
1287 }
1288 if (parent) {
1289 status = usb_autoresume_device(parent);
1290 if (status == 0) {
1291 status = usb_resume_device(udev, msg);
1292 if (status || udev->state ==
1293 USB_STATE_NOTATTACHED) {
1294 usb_autosuspend_device(parent);
1295
1296 /* It's possible usb_resume_device()
1297 * failed after the port was
1298 * unsuspended, causing udev to be
1299 * logically disconnected. We don't
1300 * want usb_disconnect() to autosuspend
1301 * the parent again, so tell it that
1302 * udev disconnected while still
1303 * suspended. */
1304 if (udev->state ==
1305 USB_STATE_NOTATTACHED)
1306 udev->discon_suspended = 1;
1307 }
1308 }
1309 } else {
1310
1311 /* We can't progagate beyond the USB subsystem,
1312 * so if a root hub's controller is suspended
1313 * then we're stuck. */
1314 status = usb_resume_device(udev, msg);
1315 }
1316 } else if (udev->reset_resume)
1317 status = usb_resume_device(udev, msg); 1249 status = usb_resume_device(udev, msg);
1318 1250
1251 /* Resume the interfaces */
1319 if (status == 0 && udev->actconfig) { 1252 if (status == 0 && udev->actconfig) {
1320 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 1253 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1321 intf = udev->actconfig->interface[i]; 1254 intf = udev->actconfig->interface[i];
@@ -1331,56 +1264,128 @@ static int usb_resume_both(struct usb_device *udev, pm_message_t msg)
1331 return status; 1264 return status;
1332} 1265}
1333 1266
1334#ifdef CONFIG_USB_SUSPEND 1267static void choose_wakeup(struct usb_device *udev, pm_message_t msg)
1268{
1269 int w, i;
1270 struct usb_interface *intf;
1335 1271
1336/* Internal routine to adjust a device's usage counter and change 1272 /* Remote wakeup is needed only when we actually go to sleep.
1337 * its autosuspend state. 1273 * For things like FREEZE and QUIESCE, if the device is already
1338 */ 1274 * autosuspended then its current wakeup setting is okay.
1339static int usb_autopm_do_device(struct usb_device *udev, int inc_usage_cnt) 1275 */
1276 if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_QUIESCE) {
1277 if (udev->state != USB_STATE_SUSPENDED)
1278 udev->do_remote_wakeup = 0;
1279 return;
1280 }
1281
1282 /* If remote wakeup is permitted, see whether any interface drivers
1283 * actually want it.
1284 */
1285 w = 0;
1286 if (device_may_wakeup(&udev->dev) && udev->actconfig) {
1287 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1288 intf = udev->actconfig->interface[i];
1289 w |= intf->needs_remote_wakeup;
1290 }
1291 }
1292
1293 /* If the device is autosuspended with the wrong wakeup setting,
1294 * autoresume now so the setting can be changed.
1295 */
1296 if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup)
1297 pm_runtime_resume(&udev->dev);
1298 udev->do_remote_wakeup = w;
1299}
1300
1301/* The device lock is held by the PM core */
1302int usb_suspend(struct device *dev, pm_message_t msg)
1340{ 1303{
1341 int status = 0; 1304 struct usb_device *udev = to_usb_device(dev);
1342 1305
1343 usb_pm_lock(udev); 1306 do_unbind_rebind(udev, DO_UNBIND);
1344 udev->auto_pm = 1; 1307 choose_wakeup(udev, msg);
1345 udev->pm_usage_cnt += inc_usage_cnt; 1308 return usb_suspend_both(udev, msg);
1346 WARN_ON(udev->pm_usage_cnt < 0); 1309}
1347 if (inc_usage_cnt) 1310
1348 udev->last_busy = jiffies; 1311/* The device lock is held by the PM core */
1349 if (inc_usage_cnt >= 0 && udev->pm_usage_cnt > 0) { 1312int usb_resume(struct device *dev, pm_message_t msg)
1350 if (udev->state == USB_STATE_SUSPENDED) 1313{
1351 status = usb_resume_both(udev, PMSG_AUTO_RESUME); 1314 struct usb_device *udev = to_usb_device(dev);
1352 if (status != 0) 1315 int status;
1353 udev->pm_usage_cnt -= inc_usage_cnt; 1316
1354 else if (inc_usage_cnt) 1317 /* For PM complete calls, all we do is rebind interfaces */
1318 if (msg.event == PM_EVENT_ON) {
1319 if (udev->state != USB_STATE_NOTATTACHED)
1320 do_unbind_rebind(udev, DO_REBIND);
1321 status = 0;
1322
1323 /* For all other calls, take the device back to full power and
1324 * tell the PM core in case it was autosuspended previously.
1325 */
1326 } else {
1327 status = usb_resume_both(udev, msg);
1328 if (status == 0) {
1329 pm_runtime_disable(dev);
1330 pm_runtime_set_active(dev);
1331 pm_runtime_enable(dev);
1355 udev->last_busy = jiffies; 1332 udev->last_busy = jiffies;
1356 } else if (inc_usage_cnt <= 0 && udev->pm_usage_cnt <= 0) { 1333 }
1357 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1358 } 1334 }
1359 usb_pm_unlock(udev); 1335
1336 /* Avoid PM error messages for devices disconnected while suspended
1337 * as we'll display regular disconnect messages just a bit later.
1338 */
1339 if (status == -ENODEV)
1340 status = 0;
1360 return status; 1341 return status;
1361} 1342}
1362 1343
1363/* usb_autosuspend_work - callback routine to autosuspend a USB device */ 1344#endif /* CONFIG_PM */
1364void usb_autosuspend_work(struct work_struct *work)
1365{
1366 struct usb_device *udev =
1367 container_of(work, struct usb_device, autosuspend.work);
1368 1345
1369 usb_autopm_do_device(udev, 0); 1346#ifdef CONFIG_USB_SUSPEND
1347
1348/**
1349 * usb_enable_autosuspend - allow a USB device to be autosuspended
1350 * @udev: the USB device which may be autosuspended
1351 *
1352 * This routine allows @udev to be autosuspended. An autosuspend won't
1353 * take place until the autosuspend_delay has elapsed and all the other
1354 * necessary conditions are satisfied.
1355 *
1356 * The caller must hold @udev's device lock.
1357 */
1358int usb_enable_autosuspend(struct usb_device *udev)
1359{
1360 if (udev->autosuspend_disabled) {
1361 udev->autosuspend_disabled = 0;
1362 usb_autosuspend_device(udev);
1363 }
1364 return 0;
1370} 1365}
1366EXPORT_SYMBOL_GPL(usb_enable_autosuspend);
1371 1367
1372/* usb_autoresume_work - callback routine to autoresume a USB device */ 1368/**
1373void usb_autoresume_work(struct work_struct *work) 1369 * usb_disable_autosuspend - prevent a USB device from being autosuspended
1370 * @udev: the USB device which may not be autosuspended
1371 *
1372 * This routine prevents @udev from being autosuspended and wakes it up
1373 * if it is already autosuspended.
1374 *
1375 * The caller must hold @udev's device lock.
1376 */
1377int usb_disable_autosuspend(struct usb_device *udev)
1374{ 1378{
1375 struct usb_device *udev = 1379 int rc = 0;
1376 container_of(work, struct usb_device, autoresume);
1377 1380
1378 /* Wake it up, let the drivers do their thing, and then put it 1381 if (!udev->autosuspend_disabled) {
1379 * back to sleep. 1382 rc = usb_autoresume_device(udev);
1380 */ 1383 if (rc == 0)
1381 if (usb_autopm_do_device(udev, 1) == 0) 1384 udev->autosuspend_disabled = 1;
1382 usb_autopm_do_device(udev, -1); 1385 }
1386 return rc;
1383} 1387}
1388EXPORT_SYMBOL_GPL(usb_disable_autosuspend);
1384 1389
1385/** 1390/**
1386 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces 1391 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces
@@ -1390,15 +1395,11 @@ void usb_autoresume_work(struct work_struct *work)
1390 * @udev and wants to allow it to autosuspend. Examples would be when 1395 * @udev and wants to allow it to autosuspend. Examples would be when
1391 * @udev's device file in usbfs is closed or after a configuration change. 1396 * @udev's device file in usbfs is closed or after a configuration change.
1392 * 1397 *
1393 * @udev's usage counter is decremented. If it or any of the usage counters 1398 * @udev's usage counter is decremented; if it drops to 0 and all the
1394 * for an active interface is greater than 0, no autosuspend request will be 1399 * interfaces are inactive then a delayed autosuspend will be attempted.
1395 * queued. (If an interface driver does not support autosuspend then its 1400 * The attempt may fail (see autosuspend_check()).
1396 * usage counter is permanently positive.) Furthermore, if an interface
1397 * driver requires remote-wakeup capability during autosuspend but remote
1398 * wakeup is disabled, the autosuspend will fail.
1399 * 1401 *
1400 * Often the caller will hold @udev's device lock, but this is not 1402 * The caller must hold @udev's device lock.
1401 * necessary.
1402 * 1403 *
1403 * This routine can run only in process context. 1404 * This routine can run only in process context.
1404 */ 1405 */
@@ -1406,9 +1407,11 @@ void usb_autosuspend_device(struct usb_device *udev)
1406{ 1407{
1407 int status; 1408 int status;
1408 1409
1409 status = usb_autopm_do_device(udev, -1); 1410 udev->last_busy = jiffies;
1410 dev_vdbg(&udev->dev, "%s: cnt %d\n", 1411 status = pm_runtime_put_sync(&udev->dev);
1411 __func__, udev->pm_usage_cnt); 1412 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
1413 __func__, atomic_read(&udev->dev.power.usage_count),
1414 status);
1412} 1415}
1413 1416
1414/** 1417/**
@@ -1418,17 +1421,22 @@ void usb_autosuspend_device(struct usb_device *udev)
1418 * This routine should be called when a core subsystem thinks @udev may 1421 * This routine should be called when a core subsystem thinks @udev may
1419 * be ready to autosuspend. 1422 * be ready to autosuspend.
1420 * 1423 *
1421 * @udev's usage counter left unchanged. If it or any of the usage counters 1424 * @udev's usage counter left unchanged. If it is 0 and all the interfaces
1422 * for an active interface is greater than 0, or autosuspend is not allowed 1425 * are inactive then an autosuspend will be attempted. The attempt may
1423 * for any other reason, no autosuspend request will be queued. 1426 * fail or be delayed.
1427 *
1428 * The caller must hold @udev's device lock.
1424 * 1429 *
1425 * This routine can run only in process context. 1430 * This routine can run only in process context.
1426 */ 1431 */
1427void usb_try_autosuspend_device(struct usb_device *udev) 1432void usb_try_autosuspend_device(struct usb_device *udev)
1428{ 1433{
1429 usb_autopm_do_device(udev, 0); 1434 int status;
1430 dev_vdbg(&udev->dev, "%s: cnt %d\n", 1435
1431 __func__, udev->pm_usage_cnt); 1436 status = pm_runtime_idle(&udev->dev);
1437 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
1438 __func__, atomic_read(&udev->dev.power.usage_count),
1439 status);
1432} 1440}
1433 1441
1434/** 1442/**
@@ -1437,16 +1445,15 @@ void usb_try_autosuspend_device(struct usb_device *udev)
1437 * 1445 *
1438 * This routine should be called when a core subsystem wants to use @udev 1446 * This routine should be called when a core subsystem wants to use @udev
1439 * and needs to guarantee that it is not suspended. No autosuspend will 1447 * and needs to guarantee that it is not suspended. No autosuspend will
1440 * occur until usb_autosuspend_device is called. (Note that this will not 1448 * occur until usb_autosuspend_device() is called. (Note that this will
1441 * prevent suspend events originating in the PM core.) Examples would be 1449 * not prevent suspend events originating in the PM core.) Examples would
1442 * when @udev's device file in usbfs is opened or when a remote-wakeup 1450 * be when @udev's device file in usbfs is opened or when a remote-wakeup
1443 * request is received. 1451 * request is received.
1444 * 1452 *
1445 * @udev's usage counter is incremented to prevent subsequent autosuspends. 1453 * @udev's usage counter is incremented to prevent subsequent autosuspends.
1446 * However if the autoresume fails then the usage counter is re-decremented. 1454 * However if the autoresume fails then the usage counter is re-decremented.
1447 * 1455 *
1448 * Often the caller will hold @udev's device lock, but this is not 1456 * The caller must hold @udev's device lock.
1449 * necessary (and attempting it might cause deadlock).
1450 * 1457 *
1451 * This routine can run only in process context. 1458 * This routine can run only in process context.
1452 */ 1459 */
@@ -1454,43 +1461,14 @@ int usb_autoresume_device(struct usb_device *udev)
1454{ 1461{
1455 int status; 1462 int status;
1456 1463
1457 status = usb_autopm_do_device(udev, 1); 1464 status = pm_runtime_get_sync(&udev->dev);
1458 dev_vdbg(&udev->dev, "%s: status %d cnt %d\n", 1465 if (status < 0)
1459 __func__, status, udev->pm_usage_cnt); 1466 pm_runtime_put_sync(&udev->dev);
1460 return status; 1467 dev_vdbg(&udev->dev, "%s: cnt %d -> %d\n",
1461} 1468 __func__, atomic_read(&udev->dev.power.usage_count),
1462 1469 status);
1463/* Internal routine to adjust an interface's usage counter and change 1470 if (status > 0)
1464 * its device's autosuspend state. 1471 status = 0;
1465 */
1466static int usb_autopm_do_interface(struct usb_interface *intf,
1467 int inc_usage_cnt)
1468{
1469 struct usb_device *udev = interface_to_usbdev(intf);
1470 int status = 0;
1471
1472 usb_pm_lock(udev);
1473 if (intf->condition == USB_INTERFACE_UNBOUND)
1474 status = -ENODEV;
1475 else {
1476 udev->auto_pm = 1;
1477 atomic_add(inc_usage_cnt, &intf->pm_usage_cnt);
1478 udev->last_busy = jiffies;
1479 if (inc_usage_cnt >= 0 &&
1480 atomic_read(&intf->pm_usage_cnt) > 0) {
1481 if (udev->state == USB_STATE_SUSPENDED)
1482 status = usb_resume_both(udev,
1483 PMSG_AUTO_RESUME);
1484 if (status != 0)
1485 atomic_sub(inc_usage_cnt, &intf->pm_usage_cnt);
1486 else
1487 udev->last_busy = jiffies;
1488 } else if (inc_usage_cnt <= 0 &&
1489 atomic_read(&intf->pm_usage_cnt) <= 0) {
1490 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1491 }
1492 }
1493 usb_pm_unlock(udev);
1494 return status; 1472 return status;
1495} 1473}
1496 1474
@@ -1504,34 +1482,25 @@ static int usb_autopm_do_interface(struct usb_interface *intf,
1504 * closed. 1482 * closed.
1505 * 1483 *
1506 * The routine decrements @intf's usage counter. When the counter reaches 1484 * The routine decrements @intf's usage counter. When the counter reaches
1507 * 0, a delayed autosuspend request for @intf's device is queued. When 1485 * 0, a delayed autosuspend request for @intf's device is attempted. The
1508 * the delay expires, if @intf->pm_usage_cnt is still <= 0 along with all 1486 * attempt may fail (see autosuspend_check()).
1509 * the other usage counters for the sibling interfaces and @intf's
1510 * usb_device, the device and all its interfaces will be autosuspended.
1511 *
1512 * Note that @intf->pm_usage_cnt is owned by the interface driver. The
1513 * core will not change its value other than the increment and decrement
1514 * in usb_autopm_get_interface and usb_autopm_put_interface. The driver
1515 * may use this simple counter-oriented discipline or may set the value
1516 * any way it likes.
1517 * 1487 *
1518 * If the driver has set @intf->needs_remote_wakeup then autosuspend will 1488 * If the driver has set @intf->needs_remote_wakeup then autosuspend will
1519 * take place only if the device's remote-wakeup facility is enabled. 1489 * take place only if the device's remote-wakeup facility is enabled.
1520 * 1490 *
1521 * Suspend method calls queued by this routine can arrive at any time
1522 * while @intf is resumed and its usage counter is equal to 0. They are
1523 * not protected by the usb_device's lock but only by its pm_mutex.
1524 * Drivers must provide their own synchronization.
1525 *
1526 * This routine can run only in process context. 1491 * This routine can run only in process context.
1527 */ 1492 */
1528void usb_autopm_put_interface(struct usb_interface *intf) 1493void usb_autopm_put_interface(struct usb_interface *intf)
1529{ 1494{
1530 int status; 1495 struct usb_device *udev = interface_to_usbdev(intf);
1496 int status;
1531 1497
1532 status = usb_autopm_do_interface(intf, -1); 1498 udev->last_busy = jiffies;
1533 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1499 atomic_dec(&intf->pm_usage_cnt);
1534 __func__, status, atomic_read(&intf->pm_usage_cnt)); 1500 status = pm_runtime_put_sync(&intf->dev);
1501 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
1502 __func__, atomic_read(&intf->dev.power.usage_count),
1503 status);
1535} 1504}
1536EXPORT_SYMBOL_GPL(usb_autopm_put_interface); 1505EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1537 1506
@@ -1539,11 +1508,11 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1539 * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter 1508 * usb_autopm_put_interface_async - decrement a USB interface's PM-usage counter
1540 * @intf: the usb_interface whose counter should be decremented 1509 * @intf: the usb_interface whose counter should be decremented
1541 * 1510 *
1542 * This routine does essentially the same thing as 1511 * This routine does much the same thing as usb_autopm_put_interface():
1543 * usb_autopm_put_interface(): it decrements @intf's usage counter and 1512 * It decrements @intf's usage counter and schedules a delayed
1544 * queues a delayed autosuspend request if the counter is <= 0. The 1513 * autosuspend request if the counter is <= 0. The difference is that it
1545 * difference is that it does not acquire the device's pm_mutex; 1514 * does not perform any synchronization; callers should hold a private
1546 * callers must handle all synchronization issues themselves. 1515 * lock and handle all synchronization issues themselves.
1547 * 1516 *
1548 * Typically a driver would call this routine during an URB's completion 1517 * Typically a driver would call this routine during an URB's completion
1549 * handler, if no more URBs were pending. 1518 * handler, if no more URBs were pending.
@@ -1553,28 +1522,58 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1553void usb_autopm_put_interface_async(struct usb_interface *intf) 1522void usb_autopm_put_interface_async(struct usb_interface *intf)
1554{ 1523{
1555 struct usb_device *udev = interface_to_usbdev(intf); 1524 struct usb_device *udev = interface_to_usbdev(intf);
1525 unsigned long last_busy;
1556 int status = 0; 1526 int status = 0;
1557 1527
1558 if (intf->condition == USB_INTERFACE_UNBOUND) { 1528 last_busy = udev->last_busy;
1559 status = -ENODEV; 1529 udev->last_busy = jiffies;
1560 } else { 1530 atomic_dec(&intf->pm_usage_cnt);
1561 udev->last_busy = jiffies; 1531 pm_runtime_put_noidle(&intf->dev);
1562 atomic_dec(&intf->pm_usage_cnt); 1532
1563 if (udev->autosuspend_disabled || udev->autosuspend_delay < 0) 1533 if (!udev->autosuspend_disabled) {
1564 status = -EPERM; 1534 /* Optimization: Don't schedule a delayed autosuspend if
1565 else if (atomic_read(&intf->pm_usage_cnt) <= 0 && 1535 * the timer is already running and the expiration time
1566 !timer_pending(&udev->autosuspend.timer)) { 1536 * wouldn't change.
1567 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend, 1537 *
1538 * We have to use the interface's timer. Attempts to
1539 * schedule a suspend for the device would fail because
1540 * the interface is still active.
1541 */
1542 if (intf->dev.power.timer_expires == 0 ||
1543 round_jiffies_up(last_busy) !=
1544 round_jiffies_up(jiffies)) {
1545 status = pm_schedule_suspend(&intf->dev,
1546 jiffies_to_msecs(
1568 round_jiffies_up_relative( 1547 round_jiffies_up_relative(
1569 udev->autosuspend_delay)); 1548 udev->autosuspend_delay)));
1570 } 1549 }
1571 } 1550 }
1572 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1551 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
1573 __func__, status, atomic_read(&intf->pm_usage_cnt)); 1552 __func__, atomic_read(&intf->dev.power.usage_count),
1553 status);
1574} 1554}
1575EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); 1555EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async);
1576 1556
1577/** 1557/**
1558 * usb_autopm_put_interface_no_suspend - decrement a USB interface's PM-usage counter
1559 * @intf: the usb_interface whose counter should be decremented
1560 *
1561 * This routine decrements @intf's usage counter but does not carry out an
1562 * autosuspend.
1563 *
1564 * This routine can run in atomic context.
1565 */
1566void usb_autopm_put_interface_no_suspend(struct usb_interface *intf)
1567{
1568 struct usb_device *udev = interface_to_usbdev(intf);
1569
1570 udev->last_busy = jiffies;
1571 atomic_dec(&intf->pm_usage_cnt);
1572 pm_runtime_put_noidle(&intf->dev);
1573}
1574EXPORT_SYMBOL_GPL(usb_autopm_put_interface_no_suspend);
1575
1576/**
1578 * usb_autopm_get_interface - increment a USB interface's PM-usage counter 1577 * usb_autopm_get_interface - increment a USB interface's PM-usage counter
1579 * @intf: the usb_interface whose counter should be incremented 1578 * @intf: the usb_interface whose counter should be incremented
1580 * 1579 *
@@ -1586,25 +1585,8 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async);
1586 * or @intf is unbound. A typical example would be a character-device 1585 * or @intf is unbound. A typical example would be a character-device
1587 * driver when its device file is opened. 1586 * driver when its device file is opened.
1588 * 1587 *
1589 * 1588 * @intf's usage counter is incremented to prevent subsequent autosuspends.
1590 * The routine increments @intf's usage counter. (However if the 1589 * However if the autoresume fails then the counter is re-decremented.
1591 * autoresume fails then the counter is re-decremented.) So long as the
1592 * counter is greater than 0, autosuspend will not be allowed for @intf
1593 * or its usb_device. When the driver is finished using @intf it should
1594 * call usb_autopm_put_interface() to decrement the usage counter and
1595 * queue a delayed autosuspend request (if the counter is <= 0).
1596 *
1597 *
1598 * Note that @intf->pm_usage_cnt is owned by the interface driver. The
1599 * core will not change its value other than the increment and decrement
1600 * in usb_autopm_get_interface and usb_autopm_put_interface. The driver
1601 * may use this simple counter-oriented discipline or may set the value
1602 * any way it likes.
1603 *
1604 * Resume method calls generated by this routine can arrive at any time
1605 * while @intf is suspended. They are not protected by the usb_device's
1606 * lock but only by its pm_mutex. Drivers must provide their own
1607 * synchronization.
1608 * 1590 *
1609 * This routine can run only in process context. 1591 * This routine can run only in process context.
1610 */ 1592 */
@@ -1612,9 +1594,16 @@ int usb_autopm_get_interface(struct usb_interface *intf)
1612{ 1594{
1613 int status; 1595 int status;
1614 1596
1615 status = usb_autopm_do_interface(intf, 1); 1597 status = pm_runtime_get_sync(&intf->dev);
1616 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1598 if (status < 0)
1617 __func__, status, atomic_read(&intf->pm_usage_cnt)); 1599 pm_runtime_put_sync(&intf->dev);
1600 else
1601 atomic_inc(&intf->pm_usage_cnt);
1602 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
1603 __func__, atomic_read(&intf->dev.power.usage_count),
1604 status);
1605 if (status > 0)
1606 status = 0;
1618 return status; 1607 return status;
1619} 1608}
1620EXPORT_SYMBOL_GPL(usb_autopm_get_interface); 1609EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
@@ -1624,175 +1613,207 @@ EXPORT_SYMBOL_GPL(usb_autopm_get_interface);
1624 * @intf: the usb_interface whose counter should be incremented 1613 * @intf: the usb_interface whose counter should be incremented
1625 * 1614 *
1626 * This routine does much the same thing as 1615 * This routine does much the same thing as
1627 * usb_autopm_get_interface(): it increments @intf's usage counter and 1616 * usb_autopm_get_interface(): It increments @intf's usage counter and
1628 * queues an autoresume request if the result is > 0. The differences 1617 * queues an autoresume request if the device is suspended. The
1629 * are that it does not acquire the device's pm_mutex (callers must 1618 * differences are that it does not perform any synchronization (callers
1630 * handle all synchronization issues themselves), and it does not 1619 * should hold a private lock and handle all synchronization issues
1631 * autoresume the device directly (it only queues a request). After a 1620 * themselves), and it does not autoresume the device directly (it only
1632 * successful call, the device will generally not yet be resumed. 1621 * queues a request). After a successful call, the device may not yet be
1622 * resumed.
1633 * 1623 *
1634 * This routine can run in atomic context. 1624 * This routine can run in atomic context.
1635 */ 1625 */
1636int usb_autopm_get_interface_async(struct usb_interface *intf) 1626int usb_autopm_get_interface_async(struct usb_interface *intf)
1637{ 1627{
1638 struct usb_device *udev = interface_to_usbdev(intf); 1628 int status = 0;
1639 int status = 0; 1629 enum rpm_status s;
1640 1630
1641 if (intf->condition == USB_INTERFACE_UNBOUND) 1631 /* Don't request a resume unless the interface is already suspending
1642 status = -ENODEV; 1632 * or suspended. Doing so would force a running suspend timer to be
1643 else if (udev->autoresume_disabled) 1633 * cancelled.
1644 status = -EPERM; 1634 */
1645 else { 1635 pm_runtime_get_noresume(&intf->dev);
1636 s = ACCESS_ONCE(intf->dev.power.runtime_status);
1637 if (s == RPM_SUSPENDING || s == RPM_SUSPENDED)
1638 status = pm_request_resume(&intf->dev);
1639
1640 if (status < 0 && status != -EINPROGRESS)
1641 pm_runtime_put_noidle(&intf->dev);
1642 else
1646 atomic_inc(&intf->pm_usage_cnt); 1643 atomic_inc(&intf->pm_usage_cnt);
1647 if (atomic_read(&intf->pm_usage_cnt) > 0 && 1644 dev_vdbg(&intf->dev, "%s: cnt %d -> %d\n",
1648 udev->state == USB_STATE_SUSPENDED) 1645 __func__, atomic_read(&intf->dev.power.usage_count),
1649 queue_work(ksuspend_usb_wq, &udev->autoresume); 1646 status);
1650 } 1647 if (status > 0)
1651 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1648 status = 0;
1652 __func__, status, atomic_read(&intf->pm_usage_cnt));
1653 return status; 1649 return status;
1654} 1650}
1655EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async); 1651EXPORT_SYMBOL_GPL(usb_autopm_get_interface_async);
1656 1652
1657/** 1653/**
1658 * usb_autopm_set_interface - set a USB interface's autosuspend state 1654 * usb_autopm_get_interface_no_resume - increment a USB interface's PM-usage counter
1659 * @intf: the usb_interface whose state should be set 1655 * @intf: the usb_interface whose counter should be incremented
1660 * 1656 *
1661 * This routine sets the autosuspend state of @intf's device according 1657 * This routine increments @intf's usage counter but does not carry out an
1662 * to @intf's usage counter, which the caller must have set previously. 1658 * autoresume.
1663 * If the counter is <= 0, the device is autosuspended (if it isn't 1659 *
1664 * already suspended and if nothing else prevents the autosuspend). If 1660 * This routine can run in atomic context.
1665 * the counter is > 0, the device is autoresumed (if it isn't already
1666 * awake).
1667 */ 1661 */
1668int usb_autopm_set_interface(struct usb_interface *intf) 1662void usb_autopm_get_interface_no_resume(struct usb_interface *intf)
1669{ 1663{
1670 int status; 1664 struct usb_device *udev = interface_to_usbdev(intf);
1671 1665
1672 status = usb_autopm_do_interface(intf, 0); 1666 udev->last_busy = jiffies;
1673 dev_vdbg(&intf->dev, "%s: status %d cnt %d\n", 1667 atomic_inc(&intf->pm_usage_cnt);
1674 __func__, status, atomic_read(&intf->pm_usage_cnt)); 1668 pm_runtime_get_noresume(&intf->dev);
1675 return status;
1676} 1669}
1677EXPORT_SYMBOL_GPL(usb_autopm_set_interface); 1670EXPORT_SYMBOL_GPL(usb_autopm_get_interface_no_resume);
1678 1671
1679#else 1672/* Internal routine to check whether we may autosuspend a device. */
1673static int autosuspend_check(struct usb_device *udev)
1674{
1675 int i;
1676 struct usb_interface *intf;
1677 unsigned long suspend_time, j;
1680 1678
1681void usb_autosuspend_work(struct work_struct *work) 1679 /* Fail if autosuspend is disabled, or any interfaces are in use, or
1682{} 1680 * any interface drivers require remote wakeup but it isn't available.
1681 */
1682 udev->do_remote_wakeup = device_may_wakeup(&udev->dev);
1683 if (udev->actconfig) {
1684 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
1685 intf = udev->actconfig->interface[i];
1683 1686
1684void usb_autoresume_work(struct work_struct *work) 1687 /* We don't need to check interfaces that are
1685{} 1688 * disabled for runtime PM. Either they are unbound
1689 * or else their drivers don't support autosuspend
1690 * and so they are permanently active.
1691 */
1692 if (intf->dev.power.disable_depth)
1693 continue;
1694 if (atomic_read(&intf->dev.power.usage_count) > 0)
1695 return -EBUSY;
1696 if (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 }
1686 1702
1687#endif /* CONFIG_USB_SUSPEND */ 1703 /* Don't allow autosuspend if the device will need
1704 * a reset-resume and any of its interface drivers
1705 * doesn't include support or needs remote wakeup.
1706 */
1707 if (udev->quirks & USB_QUIRK_RESET_RESUME) {
1708 struct usb_driver *driver;
1688 1709
1689/** 1710 driver = to_usb_driver(intf->dev.driver);
1690 * usb_external_suspend_device - external suspend of a USB device and its interfaces 1711 if (!driver->reset_resume ||
1691 * @udev: the usb_device to suspend 1712 intf->needs_remote_wakeup)
1692 * @msg: Power Management message describing this state transition 1713 return -EOPNOTSUPP;
1693 * 1714 }
1694 * This routine handles external suspend requests: ones not generated 1715 }
1695 * internally by a USB driver (autosuspend) but rather coming from the user 1716 }
1696 * (via sysfs) or the PM core (system sleep). The suspend will be carried
1697 * out regardless of @udev's usage counter or those of its interfaces,
1698 * and regardless of whether or not remote wakeup is enabled. Of course,
1699 * interface drivers still have the option of failing the suspend (if
1700 * there are unsuspended children, for example).
1701 *
1702 * The caller must hold @udev's device lock.
1703 */
1704int usb_external_suspend_device(struct usb_device *udev, pm_message_t msg)
1705{
1706 int status;
1707 1717
1708 do_unbind_rebind(udev, DO_UNBIND); 1718 /* If everything is okay but the device hasn't been idle for long
1709 usb_pm_lock(udev); 1719 * enough, queue a delayed autosuspend request.
1710 udev->auto_pm = 0; 1720 */
1711 status = usb_suspend_both(udev, msg); 1721 j = ACCESS_ONCE(jiffies);
1712 usb_pm_unlock(udev); 1722 suspend_time = udev->last_busy + udev->autosuspend_delay;
1713 return status; 1723 if (time_before(j, suspend_time)) {
1724 pm_schedule_suspend(&udev->dev, jiffies_to_msecs(
1725 round_jiffies_up_relative(suspend_time - j)));
1726 return -EAGAIN;
1727 }
1728 return 0;
1714} 1729}
1715 1730
1716/** 1731static int usb_runtime_suspend(struct device *dev)
1717 * usb_external_resume_device - external resume of a USB device and its interfaces
1718 * @udev: the usb_device to resume
1719 * @msg: Power Management message describing this state transition
1720 *
1721 * This routine handles external resume requests: ones not generated
1722 * internally by a USB driver (autoresume) but rather coming from the user
1723 * (via sysfs), the PM core (system resume), or the device itself (remote
1724 * wakeup). @udev's usage counter is unaffected.
1725 *
1726 * The caller must hold @udev's device lock.
1727 */
1728int usb_external_resume_device(struct usb_device *udev, pm_message_t msg)
1729{ 1732{
1730 int status; 1733 int status = 0;
1731 1734
1732 usb_pm_lock(udev); 1735 /* A USB device can be suspended if it passes the various autosuspend
1733 udev->auto_pm = 0; 1736 * checks. Runtime suspend for a USB device means suspending all the
1734 status = usb_resume_both(udev, msg); 1737 * interfaces and then the device itself.
1735 udev->last_busy = jiffies; 1738 */
1736 usb_pm_unlock(udev); 1739 if (is_usb_device(dev)) {
1737 if (status == 0) 1740 struct usb_device *udev = to_usb_device(dev);
1738 do_unbind_rebind(udev, DO_REBIND);
1739 1741
1740 /* Now that the device is awake, we can start trying to autosuspend 1742 if (autosuspend_check(udev) != 0)
1741 * it again. */ 1743 return -EAGAIN;
1742 if (status == 0)
1743 usb_try_autosuspend_device(udev);
1744 return status;
1745}
1746 1744
1747int usb_suspend(struct device *dev, pm_message_t msg) 1745 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1748{
1749 struct usb_device *udev;
1750 1746
1751 udev = to_usb_device(dev); 1747 /* If an interface fails the suspend, adjust the last_busy
1748 * time so that we don't get another suspend attempt right
1749 * away.
1750 */
1751 if (status) {
1752 udev->last_busy = jiffies +
1753 (udev->autosuspend_delay == 0 ?
1754 HZ/2 : 0);
1755 }
1752 1756
1753 /* If udev is already suspended, we can skip this suspend and 1757 /* Prevent the parent from suspending immediately after */
1754 * we should also skip the upcoming system resume. High-speed 1758 else if (udev->parent) {
1755 * root hubs are an exception; they need to resume whenever the 1759 udev->parent->last_busy = jiffies;
1756 * system wakes up in order for USB-PERSIST port handover to work 1760 }
1757 * properly.
1758 */
1759 if (udev->state == USB_STATE_SUSPENDED) {
1760 if (udev->parent || udev->speed != USB_SPEED_HIGH)
1761 udev->skip_sys_resume = 1;
1762 return 0;
1763 } 1761 }
1764 1762
1765 udev->skip_sys_resume = 0; 1763 /* Runtime suspend for a USB interface doesn't mean anything. */
1766 return usb_external_suspend_device(udev, msg); 1764 return status;
1767} 1765}
1768 1766
1769int usb_resume(struct device *dev, pm_message_t msg) 1767static int usb_runtime_resume(struct device *dev)
1770{ 1768{
1771 struct usb_device *udev; 1769 /* Runtime resume for a USB device means resuming both the device
1772 int status; 1770 * and all its interfaces.
1771 */
1772 if (is_usb_device(dev)) {
1773 struct usb_device *udev = to_usb_device(dev);
1774 int status;
1775
1776 status = usb_resume_both(udev, PMSG_AUTO_RESUME);
1777 udev->last_busy = jiffies;
1778 return status;
1779 }
1773 1780
1774 udev = to_usb_device(dev); 1781 /* Runtime resume for a USB interface doesn't mean anything. */
1782 return 0;
1783}
1775 1784
1776 /* If udev->skip_sys_resume is set then udev was already suspended 1785static int usb_runtime_idle(struct device *dev)
1777 * when the system sleep started, so we don't want to resume it 1786{
1778 * during this system wakeup. 1787 /* An idle USB device can be suspended if it passes the various
1788 * autosuspend checks. An idle interface can be suspended at
1789 * any time.
1779 */ 1790 */
1780 if (udev->skip_sys_resume) 1791 if (is_usb_device(dev)) {
1781 return 0; 1792 struct usb_device *udev = to_usb_device(dev);
1782 status = usb_external_resume_device(udev, msg);
1783 1793
1784 /* Avoid PM error messages for devices disconnected while suspended 1794 if (autosuspend_check(udev) != 0)
1785 * as we'll display regular disconnect messages just a bit later. 1795 return 0;
1786 */ 1796 }
1787 if (status == -ENODEV) 1797
1788 return 0; 1798 pm_runtime_suspend(dev);
1789 return status; 1799 return 0;
1790} 1800}
1791 1801
1792#endif /* CONFIG_PM */ 1802static struct dev_pm_ops usb_bus_pm_ops = {
1803 .runtime_suspend = usb_runtime_suspend,
1804 .runtime_resume = usb_runtime_resume,
1805 .runtime_idle = usb_runtime_idle,
1806};
1807
1808#else
1809
1810#define usb_bus_pm_ops (*(struct dev_pm_ops *) NULL)
1811
1812#endif /* CONFIG_USB_SUSPEND */
1793 1813
1794struct bus_type usb_bus_type = { 1814struct bus_type usb_bus_type = {
1795 .name = "usb", 1815 .name = "usb",
1796 .match = usb_device_match, 1816 .match = usb_device_match,
1797 .uevent = usb_uevent, 1817 .uevent = usb_uevent,
1818 .pm = &usb_bus_pm_ops,
1798}; 1819};
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index fdfaa7885515..4f84a41ee7a8 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/slab.h>
14#include <linux/idr.h> 15#include <linux/idr.h>
15#include <linux/usb.h> 16#include <linux/usb.h>
16#include "usb.h" 17#include "usb.h"
@@ -186,6 +187,7 @@ int usb_create_ep_devs(struct device *parent,
186 ep_dev->dev.parent = parent; 187 ep_dev->dev.parent = parent;
187 ep_dev->dev.release = ep_device_release; 188 ep_dev->dev.release = ep_device_release;
188 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress); 189 dev_set_name(&ep_dev->dev, "ep_%02x", endpoint->desc.bEndpointAddress);
190 device_enable_async_suspend(&ep_dev->dev);
189 191
190 retval = device_register(&ep_dev->dev); 192 retval = device_register(&ep_dev->dev);
191 if (retval) 193 if (retval)
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 222ee07ea680..f06f5dbc8cdc 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/errno.h> 19#include <linux/errno.h>
20#include <linux/rwsem.h> 20#include <linux/rwsem.h>
21#include <linux/slab.h>
21#include <linux/smp_lock.h> 22#include <linux/smp_lock.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23 24
@@ -34,7 +35,6 @@ static int usb_open(struct inode * inode, struct file * file)
34 int err = -ENODEV; 35 int err = -ENODEV;
35 const struct file_operations *old_fops, *new_fops = NULL; 36 const struct file_operations *old_fops, *new_fops = NULL;
36 37
37 lock_kernel();
38 down_read(&minor_rwsem); 38 down_read(&minor_rwsem);
39 c = usb_minors[minor]; 39 c = usb_minors[minor];
40 40
@@ -53,7 +53,6 @@ static int usb_open(struct inode * inode, struct file * file)
53 fops_put(old_fops); 53 fops_put(old_fops);
54 done: 54 done:
55 up_read(&minor_rwsem); 55 up_read(&minor_rwsem);
56 unlock_kernel();
57 return err; 56 return err;
58} 57}
59 58
@@ -99,6 +98,7 @@ static int init_usb_class(void)
99 printk(KERN_ERR "class_create failed for usb devices\n"); 98 printk(KERN_ERR "class_create failed for usb devices\n");
100 kfree(usb_class); 99 kfree(usb_class);
101 usb_class = NULL; 100 usb_class = NULL;
101 goto exit;
102 } 102 }
103 usb_class->class->devnode = usb_devnode; 103 usb_class->class->devnode = usb_devnode;
104 104
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 05e6d313961e..2c95153c0f24 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -120,7 +120,7 @@ int usb_choose_configuration(struct usb_device *udev)
120 * than a vendor-specific driver. */ 120 * than a vendor-specific driver. */
121 else if (udev->descriptor.bDeviceClass != 121 else if (udev->descriptor.bDeviceClass !=
122 USB_CLASS_VENDOR_SPEC && 122 USB_CLASS_VENDOR_SPEC &&
123 (!desc || desc->bInterfaceClass != 123 (desc && desc->bInterfaceClass !=
124 USB_CLASS_VENDOR_SPEC)) { 124 USB_CLASS_VENDOR_SPEC)) {
125 best = c; 125 best = c;
126 break; 126 break;
@@ -139,7 +139,7 @@ int usb_choose_configuration(struct usb_device *udev)
139 139
140 if (best) { 140 if (best) {
141 i = best->desc.bConfigurationValue; 141 i = best->desc.bConfigurationValue;
142 dev_info(&udev->dev, 142 dev_dbg(&udev->dev,
143 "configuration #%d chosen from %d choice%s\n", 143 "configuration #%d chosen from %d choice%s\n",
144 i, num_configs, plural(num_configs)); 144 i, num_configs, plural(num_configs));
145 } else { 145 } else {
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 91f2885b6ee1..15286533c15a 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/pm_runtime.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23 24
24#include <asm/io.h> 25#include <asm/io.h>
@@ -37,6 +38,122 @@
37 38
38/* 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 */
39 40
41#ifdef CONFIG_PM_SLEEP
42
43/* Coordinate handoffs between EHCI and companion controllers
44 * during system resume
45 */
46
47static DEFINE_MUTEX(companions_mutex);
48
49#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI
50#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI
51#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI
52
53enum companion_action {
54 SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS
55};
56
57static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd,
58 enum companion_action action)
59{
60 struct pci_dev *companion;
61 struct usb_hcd *companion_hcd;
62 unsigned int slot = PCI_SLOT(pdev->devfn);
63
64 /* Iterate through other PCI functions in the same slot.
65 * If pdev is OHCI or UHCI then we are looking for EHCI, and
66 * vice versa.
67 */
68 companion = NULL;
69 for (;;) {
70 companion = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, companion);
71 if (!companion)
72 break;
73 if (companion->bus != pdev->bus ||
74 PCI_SLOT(companion->devfn) != slot)
75 continue;
76
77 companion_hcd = pci_get_drvdata(companion);
78 if (!companion_hcd)
79 continue;
80
81 /* For SET_HS_COMPANION, store a pointer to the EHCI bus in
82 * the OHCI/UHCI companion bus structure.
83 * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus
84 * in the OHCI/UHCI companion bus structure.
85 * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI
86 * companion controllers have fully resumed.
87 */
88
89 if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) &&
90 companion->class == CL_EHCI) {
91 /* action must be SET_HS_COMPANION */
92 dev_dbg(&companion->dev, "HS companion for %s\n",
93 dev_name(&pdev->dev));
94 hcd->self.hs_companion = &companion_hcd->self;
95
96 } else if (pdev->class == CL_EHCI &&
97 (companion->class == CL_OHCI ||
98 companion->class == CL_UHCI)) {
99 switch (action) {
100 case SET_HS_COMPANION:
101 dev_dbg(&pdev->dev, "HS companion for %s\n",
102 dev_name(&companion->dev));
103 companion_hcd->self.hs_companion = &hcd->self;
104 break;
105 case CLEAR_HS_COMPANION:
106 companion_hcd->self.hs_companion = NULL;
107 break;
108 case WAIT_FOR_COMPANIONS:
109 device_pm_wait_for_dev(&pdev->dev,
110 &companion->dev);
111 break;
112 }
113 }
114 }
115}
116
117static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd)
118{
119 mutex_lock(&companions_mutex);
120 dev_set_drvdata(&pdev->dev, hcd);
121 companion_common(pdev, hcd, SET_HS_COMPANION);
122 mutex_unlock(&companions_mutex);
123}
124
125static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd)
126{
127 mutex_lock(&companions_mutex);
128 dev_set_drvdata(&pdev->dev, NULL);
129
130 /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */
131 if (pdev->class == CL_OHCI || pdev->class == CL_UHCI)
132 hcd->self.hs_companion = NULL;
133
134 /* Otherwise search for companion buses and clear their pointers */
135 else
136 companion_common(pdev, hcd, CLEAR_HS_COMPANION);
137 mutex_unlock(&companions_mutex);
138}
139
140static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd)
141{
142 /* Only EHCI controllers need to wait.
143 * No locking is needed because a controller cannot be resumed
144 * while one of its companions is getting unbound.
145 */
146 if (pdev->class == CL_EHCI)
147 companion_common(pdev, hcd, WAIT_FOR_COMPANIONS);
148}
149
150#else /* !CONFIG_PM_SLEEP */
151
152static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {}
153static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {}
154static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {}
155
156#endif /* !CONFIG_PM_SLEEP */
40 157
41/*-------------------------------------------------------------------------*/ 158/*-------------------------------------------------------------------------*/
42 159
@@ -123,7 +240,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
123 if (region == PCI_ROM_RESOURCE) { 240 if (region == PCI_ROM_RESOURCE) {
124 dev_dbg(&dev->dev, "no i/o regions available\n"); 241 dev_dbg(&dev->dev, "no i/o regions available\n");
125 retval = -EBUSY; 242 retval = -EBUSY;
126 goto err1; 243 goto err2;
127 } 244 }
128 } 245 }
129 246
@@ -132,6 +249,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
132 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); 249 retval = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
133 if (retval != 0) 250 if (retval != 0)
134 goto err4; 251 goto err4;
252 set_hs_companion(dev, hcd);
135 return retval; 253 return retval;
136 254
137 err4: 255 err4:
@@ -142,6 +260,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
142 } else 260 } else
143 release_region(hcd->rsrc_start, hcd->rsrc_len); 261 release_region(hcd->rsrc_start, hcd->rsrc_len);
144 err2: 262 err2:
263 clear_hs_companion(dev, hcd);
145 usb_put_hcd(hcd); 264 usb_put_hcd(hcd);
146 err1: 265 err1:
147 pci_disable_device(dev); 266 pci_disable_device(dev);
@@ -180,6 +299,7 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
180 } else { 299 } else {
181 release_region(hcd->rsrc_start, hcd->rsrc_len); 300 release_region(hcd->rsrc_start, hcd->rsrc_len);
182 } 301 }
302 clear_hs_companion(dev, hcd);
183 usb_put_hcd(hcd); 303 usb_put_hcd(hcd);
184 pci_disable_device(dev); 304 pci_disable_device(dev);
185} 305}
@@ -344,6 +464,11 @@ static int resume_common(struct device *dev, bool hibernated)
344 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 464 clear_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
345 465
346 if (hcd->driver->pci_resume) { 466 if (hcd->driver->pci_resume) {
467 /* This call should be made only during system resume,
468 * not during runtime resume.
469 */
470 wait_for_companions(pci_dev, hcd);
471
347 retval = hcd->driver->pci_resume(hcd, hibernated); 472 retval = hcd->driver->pci_resume(hcd, hibernated);
348 if (retval) { 473 if (retval) {
349 dev_err(dev, "PCI post-resume error %d!\n", retval); 474 dev_err(dev, "PCI post-resume error %d!\n", retval);
@@ -363,7 +488,7 @@ static int hcd_pci_restore(struct device *dev)
363 return resume_common(dev, true); 488 return resume_common(dev, true);
364} 489}
365 490
366struct dev_pm_ops usb_hcd_pci_pm_ops = { 491const struct dev_pm_ops usb_hcd_pci_pm_ops = {
367 .suspend = hcd_pci_suspend, 492 .suspend = hcd_pci_suspend,
368 .suspend_noirq = hcd_pci_suspend_noirq, 493 .suspend_noirq = hcd_pci_suspend_noirq,
369 .resume_noirq = hcd_pci_resume_noirq, 494 .resume_noirq = hcd_pci_resume_noirq,
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 34de475f016e..2f8cedda8007 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -38,6 +38,8 @@
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 43
42#include <linux/usb.h> 44#include <linux/usb.h>
43 45
@@ -140,7 +142,7 @@ static const u8 usb3_rh_dev_descriptor[18] = {
140 0x09, /* __u8 bMaxPacketSize0; 2^9 = 512 Bytes */ 142 0x09, /* __u8 bMaxPacketSize0; 2^9 = 512 Bytes */
141 143
142 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */ 144 0x6b, 0x1d, /* __le16 idVendor; Linux Foundation */
143 0x02, 0x00, /* __le16 idProduct; device 0x0002 */ 145 0x03, 0x00, /* __le16 idProduct; device 0x0003 */
144 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */ 146 KERNEL_VER, KERNEL_REL, /* __le16 bcdDevice */
145 147
146 0x03, /* __u8 iManufacturer; */ 148 0x03, /* __u8 iManufacturer; */
@@ -1275,13 +1277,16 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1275 1277
1276 if (usb_endpoint_xfer_control(&urb->ep->desc) 1278 if (usb_endpoint_xfer_control(&urb->ep->desc)
1277 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) { 1279 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) {
1278 if (hcd->self.uses_dma) 1280 if (hcd->self.uses_dma) {
1279 urb->setup_dma = dma_map_single( 1281 urb->setup_dma = dma_map_single(
1280 hcd->self.controller, 1282 hcd->self.controller,
1281 urb->setup_packet, 1283 urb->setup_packet,
1282 sizeof(struct usb_ctrlrequest), 1284 sizeof(struct usb_ctrlrequest),
1283 DMA_TO_DEVICE); 1285 DMA_TO_DEVICE);
1284 else if (hcd->driver->flags & HCD_LOCAL_MEM) 1286 if (dma_mapping_error(hcd->self.controller,
1287 urb->setup_dma))
1288 return -EAGAIN;
1289 } else if (hcd->driver->flags & HCD_LOCAL_MEM)
1285 ret = hcd_alloc_coherent( 1290 ret = hcd_alloc_coherent(
1286 urb->dev->bus, mem_flags, 1291 urb->dev->bus, mem_flags,
1287 &urb->setup_dma, 1292 &urb->setup_dma,
@@ -1293,13 +1298,16 @@ static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
1293 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 1298 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
1294 if (ret == 0 && urb->transfer_buffer_length != 0 1299 if (ret == 0 && urb->transfer_buffer_length != 0
1295 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) { 1300 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1296 if (hcd->self.uses_dma) 1301 if (hcd->self.uses_dma) {
1297 urb->transfer_dma = dma_map_single ( 1302 urb->transfer_dma = dma_map_single (
1298 hcd->self.controller, 1303 hcd->self.controller,
1299 urb->transfer_buffer, 1304 urb->transfer_buffer,
1300 urb->transfer_buffer_length, 1305 urb->transfer_buffer_length,
1301 dir); 1306 dir);
1302 else if (hcd->driver->flags & HCD_LOCAL_MEM) { 1307 if (dma_mapping_error(hcd->self.controller,
1308 urb->transfer_dma))
1309 return -EAGAIN;
1310 } else if (hcd->driver->flags & HCD_LOCAL_MEM) {
1303 ret = hcd_alloc_coherent( 1311 ret = hcd_alloc_coherent(
1304 urb->dev->bus, mem_flags, 1312 urb->dev->bus, mem_flags,
1305 &urb->transfer_dma, 1313 &urb->transfer_dma,
@@ -1589,19 +1597,34 @@ rescan:
1589 } 1597 }
1590} 1598}
1591 1599
1592/* Check whether a new configuration or alt setting for an interface 1600/**
1593 * will exceed the bandwidth for the bus (or the host controller resources). 1601 * usb_hcd_alloc_bandwidth - check whether a new bandwidth setting exceeds
1594 * Only pass in a non-NULL config or interface, not both! 1602 * the bus bandwidth
1595 * Passing NULL for both new_config and new_intf means the device will be 1603 * @udev: target &usb_device
1596 * de-configured by issuing a set configuration 0 command. 1604 * @new_config: new configuration to install
1605 * @cur_alt: the current alternate interface setting
1606 * @new_alt: alternate interface setting that is being installed
1607 *
1608 * To change configurations, pass in the new configuration in new_config,
1609 * and pass NULL for cur_alt and new_alt.
1610 *
1611 * To reset a device's configuration (put the device in the ADDRESSED state),
1612 * pass in NULL for new_config, cur_alt, and new_alt.
1613 *
1614 * To change alternate interface settings, pass in NULL for new_config,
1615 * pass in the current alternate interface setting in cur_alt,
1616 * and pass in the new alternate interface setting in new_alt.
1617 *
1618 * Returns an error if the requested bandwidth change exceeds the
1619 * bus bandwidth or host controller internal resources.
1597 */ 1620 */
1598int usb_hcd_check_bandwidth(struct usb_device *udev, 1621int usb_hcd_alloc_bandwidth(struct usb_device *udev,
1599 struct usb_host_config *new_config, 1622 struct usb_host_config *new_config,
1600 struct usb_interface *new_intf) 1623 struct usb_host_interface *cur_alt,
1624 struct usb_host_interface *new_alt)
1601{ 1625{
1602 int num_intfs, i, j; 1626 int num_intfs, i, j;
1603 struct usb_interface_cache *intf_cache; 1627 struct usb_host_interface *alt = NULL;
1604 struct usb_host_interface *alt = 0;
1605 int ret = 0; 1628 int ret = 0;
1606 struct usb_hcd *hcd; 1629 struct usb_hcd *hcd;
1607 struct usb_host_endpoint *ep; 1630 struct usb_host_endpoint *ep;
@@ -1611,7 +1634,7 @@ int usb_hcd_check_bandwidth(struct usb_device *udev,
1611 return 0; 1634 return 0;
1612 1635
1613 /* Configuration is being removed - set configuration 0 */ 1636 /* Configuration is being removed - set configuration 0 */
1614 if (!new_config && !new_intf) { 1637 if (!new_config && !cur_alt) {
1615 for (i = 1; i < 16; ++i) { 1638 for (i = 1; i < 16; ++i) {
1616 ep = udev->ep_out[i]; 1639 ep = udev->ep_out[i];
1617 if (ep) 1640 if (ep)
@@ -1648,19 +1671,17 @@ int usb_hcd_check_bandwidth(struct usb_device *udev,
1648 } 1671 }
1649 } 1672 }
1650 for (i = 0; i < num_intfs; ++i) { 1673 for (i = 0; i < num_intfs; ++i) {
1674 struct usb_host_interface *first_alt;
1675 int iface_num;
1676
1677 first_alt = &new_config->intf_cache[i]->altsetting[0];
1678 iface_num = first_alt->desc.bInterfaceNumber;
1679 /* Set up endpoints for alternate interface setting 0 */
1680 alt = usb_find_alt_setting(new_config, iface_num, 0);
1681 if (!alt)
1682 /* No alt setting 0? Pick the first setting. */
1683 alt = first_alt;
1651 1684
1652 /* Dig the endpoints for alt setting 0 out of the
1653 * interface cache for this interface
1654 */
1655 intf_cache = new_config->intf_cache[i];
1656 for (j = 0; j < intf_cache->num_altsetting; j++) {
1657 if (intf_cache->altsetting[j].desc.bAlternateSetting == 0)
1658 alt = &intf_cache->altsetting[j];
1659 }
1660 if (!alt) {
1661 printk(KERN_DEBUG "Did not find alt setting 0 for intf %d\n", i);
1662 continue;
1663 }
1664 for (j = 0; j < alt->desc.bNumEndpoints; j++) { 1685 for (j = 0; j < alt->desc.bNumEndpoints; j++) {
1665 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]); 1686 ret = hcd->driver->add_endpoint(hcd, udev, &alt->endpoint[j]);
1666 if (ret < 0) 1687 if (ret < 0)
@@ -1668,6 +1689,40 @@ int usb_hcd_check_bandwidth(struct usb_device *udev,
1668 } 1689 }
1669 } 1690 }
1670 } 1691 }
1692 if (cur_alt && new_alt) {
1693 struct usb_interface *iface = usb_ifnum_to_if(udev,
1694 cur_alt->desc.bInterfaceNumber);
1695
1696 if (iface->resetting_device) {
1697 /*
1698 * The USB core just reset the device, so the xHCI host
1699 * and the device will think alt setting 0 is installed.
1700 * However, the USB core will pass in the alternate
1701 * setting installed before the reset as cur_alt. Dig
1702 * out the alternate setting 0 structure, or the first
1703 * alternate setting if a broken device doesn't have alt
1704 * setting 0.
1705 */
1706 cur_alt = usb_altnum_to_altsetting(iface, 0);
1707 if (!cur_alt)
1708 cur_alt = &iface->altsetting[0];
1709 }
1710
1711 /* Drop all the endpoints in the current alt setting */
1712 for (i = 0; i < cur_alt->desc.bNumEndpoints; i++) {
1713 ret = hcd->driver->drop_endpoint(hcd, udev,
1714 &cur_alt->endpoint[i]);
1715 if (ret < 0)
1716 goto reset;
1717 }
1718 /* Add all the endpoints in the new alt setting */
1719 for (i = 0; i < new_alt->desc.bNumEndpoints; i++) {
1720 ret = hcd->driver->add_endpoint(hcd, udev,
1721 &new_alt->endpoint[i]);
1722 if (ret < 0)
1723 goto reset;
1724 }
1725 }
1671 ret = hcd->driver->check_bandwidth(hcd, udev); 1726 ret = hcd->driver->check_bandwidth(hcd, udev);
1672reset: 1727reset:
1673 if (ret < 0) 1728 if (ret < 0)
@@ -1804,6 +1859,10 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
1804 return status; 1859 return status;
1805} 1860}
1806 1861
1862#endif /* CONFIG_PM */
1863
1864#ifdef CONFIG_USB_SUSPEND
1865
1807/* Workqueue routine for root-hub remote wakeup */ 1866/* Workqueue routine for root-hub remote wakeup */
1808static void hcd_resume_work(struct work_struct *work) 1867static void hcd_resume_work(struct work_struct *work)
1809{ 1868{
@@ -1811,8 +1870,7 @@ static void hcd_resume_work(struct work_struct *work)
1811 struct usb_device *udev = hcd->self.root_hub; 1870 struct usb_device *udev = hcd->self.root_hub;
1812 1871
1813 usb_lock_device(udev); 1872 usb_lock_device(udev);
1814 usb_mark_last_busy(udev); 1873 usb_remote_wakeup(udev);
1815 usb_external_resume_device(udev, PMSG_REMOTE_RESUME);
1816 usb_unlock_device(udev); 1874 usb_unlock_device(udev);
1817} 1875}
1818 1876
@@ -1831,12 +1889,12 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
1831 1889
1832 spin_lock_irqsave (&hcd_root_hub_lock, flags); 1890 spin_lock_irqsave (&hcd_root_hub_lock, flags);
1833 if (hcd->rh_registered) 1891 if (hcd->rh_registered)
1834 queue_work(ksuspend_usb_wq, &hcd->wakeup_work); 1892 queue_work(pm_wq, &hcd->wakeup_work);
1835 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 1893 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
1836} 1894}
1837EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); 1895EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
1838 1896
1839#endif 1897#endif /* CONFIG_USB_SUSPEND */
1840 1898
1841/*-------------------------------------------------------------------------*/ 1899/*-------------------------------------------------------------------------*/
1842 1900
@@ -1981,9 +2039,10 @@ struct usb_hcd *usb_create_hcd (const struct hc_driver *driver,
1981 init_timer(&hcd->rh_timer); 2039 init_timer(&hcd->rh_timer);
1982 hcd->rh_timer.function = rh_timer_func; 2040 hcd->rh_timer.function = rh_timer_func;
1983 hcd->rh_timer.data = (unsigned long) hcd; 2041 hcd->rh_timer.data = (unsigned long) hcd;
1984#ifdef CONFIG_PM 2042#ifdef CONFIG_USB_SUSPEND
1985 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); 2043 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
1986#endif 2044#endif
2045 mutex_init(&hcd->bandwidth_mutex);
1987 2046
1988 hcd->driver = driver; 2047 hcd->driver = driver;
1989 hcd->product_desc = (driver->product_desc) ? driver->product_desc : 2048 hcd->product_desc = (driver->product_desc) ? driver->product_desc :
@@ -2180,7 +2239,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2180 hcd->rh_registered = 0; 2239 hcd->rh_registered = 0;
2181 spin_unlock_irq (&hcd_root_hub_lock); 2240 spin_unlock_irq (&hcd_root_hub_lock);
2182 2241
2183#ifdef CONFIG_PM 2242#ifdef CONFIG_USB_SUSPEND
2184 cancel_work_sync(&hcd->wakeup_work); 2243 cancel_work_sync(&hcd->wakeup_work);
2185#endif 2244#endif
2186 2245
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 79782a1c43f6..a3cdb09734ab 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -80,7 +80,7 @@ struct usb_hcd {
80 80
81 struct timer_list rh_timer; /* drives root-hub polling */ 81 struct timer_list rh_timer; /* drives root-hub polling */
82 struct urb *status_urb; /* the current status urb */ 82 struct urb *status_urb; /* the current status urb */
83#ifdef CONFIG_PM 83#ifdef CONFIG_USB_SUSPEND
84 struct work_struct wakeup_work; /* for remote wakeup */ 84 struct work_struct wakeup_work; /* for remote wakeup */
85#endif 85#endif
86 86
@@ -111,6 +111,20 @@ struct usb_hcd {
111 u64 rsrc_len; /* memory/io resource length */ 111 u64 rsrc_len; /* memory/io resource length */
112 unsigned power_budget; /* in mA, 0 = no limit */ 112 unsigned power_budget; /* in mA, 0 = no limit */
113 113
114 /* bandwidth_mutex should be taken before adding or removing
115 * any new bus bandwidth constraints:
116 * 1. Before adding a configuration for a new device.
117 * 2. Before removing the configuration to put the device into
118 * the addressed state.
119 * 3. Before selecting a different configuration.
120 * 4. Before selecting an alternate interface setting.
121 *
122 * bandwidth_mutex should be dropped after a successful control message
123 * to the device, or resetting the bandwidth after a failed attempt.
124 */
125 struct mutex bandwidth_mutex;
126
127
114#define HCD_BUFFER_POOLS 4 128#define HCD_BUFFER_POOLS 4
115 struct dma_pool *pool [HCD_BUFFER_POOLS]; 129 struct dma_pool *pool [HCD_BUFFER_POOLS];
116 130
@@ -234,7 +248,7 @@ struct hc_driver {
234 /* xHCI specific functions */ 248 /* xHCI specific functions */
235 /* Called by usb_alloc_dev to alloc HC device structures */ 249 /* Called by usb_alloc_dev to alloc HC device structures */
236 int (*alloc_dev)(struct usb_hcd *, struct usb_device *); 250 int (*alloc_dev)(struct usb_hcd *, struct usb_device *);
237 /* Called by usb_release_dev to free HC device structures */ 251 /* Called by usb_disconnect to free HC device structures */
238 void (*free_dev)(struct usb_hcd *, struct usb_device *); 252 void (*free_dev)(struct usb_hcd *, struct usb_device *);
239 253
240 /* Bandwidth computation functions */ 254 /* Bandwidth computation functions */
@@ -272,6 +286,7 @@ struct hc_driver {
272 */ 286 */
273 int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev, 287 int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev,
274 struct usb_tt *tt, gfp_t mem_flags); 288 struct usb_tt *tt, gfp_t mem_flags);
289 int (*reset_device)(struct usb_hcd *, struct usb_device *);
275}; 290};
276 291
277extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); 292extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
@@ -290,9 +305,10 @@ extern void usb_hcd_disable_endpoint(struct usb_device *udev,
290extern void usb_hcd_reset_endpoint(struct usb_device *udev, 305extern void usb_hcd_reset_endpoint(struct usb_device *udev,
291 struct usb_host_endpoint *ep); 306 struct usb_host_endpoint *ep);
292extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); 307extern void usb_hcd_synchronize_unlinks(struct usb_device *udev);
293extern int usb_hcd_check_bandwidth(struct usb_device *udev, 308extern int usb_hcd_alloc_bandwidth(struct usb_device *udev,
294 struct usb_host_config *new_config, 309 struct usb_host_config *new_config,
295 struct usb_interface *new_intf); 310 struct usb_host_interface *old_alt,
311 struct usb_host_interface *new_alt);
296extern int usb_hcd_get_frame_number(struct usb_device *udev); 312extern int usb_hcd_get_frame_number(struct usb_device *udev);
297 313
298extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver, 314extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
@@ -315,7 +331,7 @@ extern void usb_hcd_pci_remove(struct pci_dev *dev);
315extern void usb_hcd_pci_shutdown(struct pci_dev *dev); 331extern void usb_hcd_pci_shutdown(struct pci_dev *dev);
316 332
317#ifdef CONFIG_PM_SLEEP 333#ifdef CONFIG_PM_SLEEP
318extern struct dev_pm_ops usb_hcd_pci_pm_ops; 334extern const struct dev_pm_ops usb_hcd_pci_pm_ops;
319#endif 335#endif
320#endif /* CONFIG_PCI */ 336#endif /* CONFIG_PCI */
321 337
@@ -448,16 +464,20 @@ extern int usb_find_interface_driver(struct usb_device *dev,
448#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) 464#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
449 465
450#ifdef CONFIG_PM 466#ifdef CONFIG_PM
451extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
452extern void usb_root_hub_lost_power(struct usb_device *rhdev); 467extern void usb_root_hub_lost_power(struct usb_device *rhdev);
453extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); 468extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg);
454extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); 469extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg);
470#endif /* CONFIG_PM */
471
472#ifdef CONFIG_USB_SUSPEND
473extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
455#else 474#else
456static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) 475static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
457{ 476{
458 return; 477 return;
459} 478}
460#endif /* CONFIG_PM */ 479#endif /* CONFIG_USB_SUSPEND */
480
461 481
462/* 482/*
463 * USB device fs stuff 483 * USB device fs stuff
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 0f857e645058..0940ccd6f4f4 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -22,6 +22,7 @@
22#include <linux/kthread.h> 22#include <linux/kthread.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/freezer.h> 24#include <linux/freezer.h>
25#include <linux/pm_runtime.h>
25 26
26#include <asm/uaccess.h> 27#include <asm/uaccess.h>
27#include <asm/byteorder.h> 28#include <asm/byteorder.h>
@@ -45,7 +46,6 @@ struct usb_hub {
45 46
46 /* buffer for urb ... with extra space in case of babble */ 47 /* buffer for urb ... with extra space in case of babble */
47 char (*buffer)[8]; 48 char (*buffer)[8];
48 dma_addr_t buffer_dma; /* DMA address for buffer */
49 union { 49 union {
50 struct usb_hub_status hub; 50 struct usb_hub_status hub;
51 struct usb_port_status port; 51 struct usb_port_status port;
@@ -61,6 +61,8 @@ struct usb_hub {
61 status change */ 61 status change */
62 unsigned long busy_bits[1]; /* ports being reset or 62 unsigned long busy_bits[1]; /* ports being reset or
63 resumed */ 63 resumed */
64 unsigned long removed_bits[1]; /* ports with a "removed"
65 device present */
64#if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */ 66#if USB_MAXCHILDREN > 31 /* 8*sizeof(unsigned long) - 1 */
65#error event_bits[] is too short! 67#error event_bits[] is too short!
66#endif 68#endif
@@ -374,12 +376,13 @@ static void kick_khubd(struct usb_hub *hub)
374{ 376{
375 unsigned long flags; 377 unsigned long flags;
376 378
377 /* Suppress autosuspend until khubd runs */
378 atomic_set(&to_usb_interface(hub->intfdev)->pm_usage_cnt, 1);
379
380 spin_lock_irqsave(&hub_event_lock, flags); 379 spin_lock_irqsave(&hub_event_lock, flags);
381 if (!hub->disconnected && list_empty(&hub->event_list)) { 380 if (!hub->disconnected && list_empty(&hub->event_list)) {
382 list_add_tail(&hub->event_list, &hub_event_list); 381 list_add_tail(&hub->event_list, &hub_event_list);
382
383 /* Suppress autosuspend until khubd runs */
384 usb_autopm_get_interface_no_resume(
385 to_usb_interface(hub->intfdev));
383 wake_up(&khubd_wait); 386 wake_up(&khubd_wait);
384 } 387 }
385 spin_unlock_irqrestore(&hub_event_lock, flags); 388 spin_unlock_irqrestore(&hub_event_lock, flags);
@@ -636,8 +639,35 @@ static void hub_port_logical_disconnect(struct usb_hub *hub, int port1)
636 kick_khubd(hub); 639 kick_khubd(hub);
637} 640}
638 641
642/**
643 * usb_remove_device - disable a device's port on its parent hub
644 * @udev: device to be disabled and removed
645 * Context: @udev locked, must be able to sleep.
646 *
647 * After @udev's port has been disabled, khubd is notified and it will
648 * see that the device has been disconnected. When the device is
649 * physically unplugged and something is plugged in, the events will
650 * be received and processed normally.
651 */
652int usb_remove_device(struct usb_device *udev)
653{
654 struct usb_hub *hub;
655 struct usb_interface *intf;
656
657 if (!udev->parent) /* Can't remove a root hub */
658 return -EINVAL;
659 hub = hdev_to_hub(udev->parent);
660 intf = to_usb_interface(hub->intfdev);
661
662 usb_autopm_get_interface(intf);
663 set_bit(udev->portnum, hub->removed_bits);
664 hub_port_logical_disconnect(hub, udev->portnum);
665 usb_autopm_put_interface(intf);
666 return 0;
667}
668
639enum hub_activation_type { 669enum hub_activation_type {
640 HUB_INIT, HUB_INIT2, HUB_INIT3, 670 HUB_INIT, HUB_INIT2, HUB_INIT3, /* INITs must come first */
641 HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME, 671 HUB_POST_RESET, HUB_RESUME, HUB_RESET_RESUME,
642}; 672};
643 673
@@ -682,8 +712,8 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
682 msecs_to_jiffies(delay)); 712 msecs_to_jiffies(delay));
683 713
684 /* Suppress autosuspend until init is done */ 714 /* Suppress autosuspend until init is done */
685 atomic_set(&to_usb_interface(hub->intfdev)-> 715 usb_autopm_get_interface_no_resume(
686 pm_usage_cnt, 1); 716 to_usb_interface(hub->intfdev));
687 return; /* Continues at init2: below */ 717 return; /* Continues at init2: below */
688 } else { 718 } else {
689 hub_power_on(hub, true); 719 hub_power_on(hub, true);
@@ -731,6 +761,13 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
731 USB_PORT_FEAT_C_ENABLE); 761 USB_PORT_FEAT_C_ENABLE);
732 } 762 }
733 763
764 /* We can forget about a "removed" device when there's a
765 * physical disconnect or the connect status changes.
766 */
767 if (!(portstatus & USB_PORT_STAT_CONNECTION) ||
768 (portchange & USB_PORT_STAT_C_CONNECTION))
769 clear_bit(port1, hub->removed_bits);
770
734 if (!udev || udev->state == USB_STATE_NOTATTACHED) { 771 if (!udev || udev->state == USB_STATE_NOTATTACHED) {
735 /* Tell khubd to disconnect the device or 772 /* Tell khubd to disconnect the device or
736 * check for a new connection 773 * check for a new connection
@@ -792,6 +829,10 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
792 829
793 /* Scan all ports that need attention */ 830 /* Scan all ports that need attention */
794 kick_khubd(hub); 831 kick_khubd(hub);
832
833 /* Allow autosuspend if it was suppressed */
834 if (type <= HUB_INIT3)
835 usb_autopm_put_interface_async(to_usb_interface(hub->intfdev));
795} 836}
796 837
797/* Implement the continuations for the delays above */ 838/* Implement the continuations for the delays above */
@@ -869,8 +910,7 @@ static int hub_configure(struct usb_hub *hub,
869 int maxp, ret; 910 int maxp, ret;
870 char *message = "out of memory"; 911 char *message = "out of memory";
871 912
872 hub->buffer = usb_buffer_alloc(hdev, sizeof(*hub->buffer), GFP_KERNEL, 913 hub->buffer = kmalloc(sizeof(*hub->buffer), GFP_KERNEL);
873 &hub->buffer_dma);
874 if (!hub->buffer) { 914 if (!hub->buffer) {
875 ret = -ENOMEM; 915 ret = -ENOMEM;
876 goto fail; 916 goto fail;
@@ -1111,8 +1151,6 @@ static int hub_configure(struct usb_hub *hub,
1111 1151
1112 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq, 1152 usb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq,
1113 hub, endpoint->bInterval); 1153 hub, endpoint->bInterval);
1114 hub->urb->transfer_dma = hub->buffer_dma;
1115 hub->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1116 1154
1117 /* maybe cycle the hub leds */ 1155 /* maybe cycle the hub leds */
1118 if (hub->has_indicators && blinkenlights) 1156 if (hub->has_indicators && blinkenlights)
@@ -1144,7 +1182,10 @@ static void hub_disconnect(struct usb_interface *intf)
1144 1182
1145 /* Take the hub off the event list and don't let it be added again */ 1183 /* Take the hub off the event list and don't let it be added again */
1146 spin_lock_irq(&hub_event_lock); 1184 spin_lock_irq(&hub_event_lock);
1147 list_del_init(&hub->event_list); 1185 if (!list_empty(&hub->event_list)) {
1186 list_del_init(&hub->event_list);
1187 usb_autopm_put_interface_no_suspend(intf);
1188 }
1148 hub->disconnected = 1; 1189 hub->disconnected = 1;
1149 spin_unlock_irq(&hub_event_lock); 1190 spin_unlock_irq(&hub_event_lock);
1150 1191
@@ -1162,8 +1203,7 @@ static void hub_disconnect(struct usb_interface *intf)
1162 kfree(hub->port_owners); 1203 kfree(hub->port_owners);
1163 kfree(hub->descriptor); 1204 kfree(hub->descriptor);
1164 kfree(hub->status); 1205 kfree(hub->status);
1165 usb_buffer_free(hub->hdev, sizeof(*hub->buffer), hub->buffer, 1206 kfree(hub->buffer);
1166 hub->buffer_dma);
1167 1207
1168 kref_put(&hub->kref, hub_release); 1208 kref_put(&hub->kref, hub_release);
1169} 1209}
@@ -1178,6 +1218,9 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
1178 desc = intf->cur_altsetting; 1218 desc = intf->cur_altsetting;
1179 hdev = interface_to_usbdev(intf); 1219 hdev = interface_to_usbdev(intf);
1180 1220
1221 /* Hubs have proper suspend/resume support */
1222 usb_enable_autosuspend(hdev);
1223
1181 if (hdev->level == MAX_TOPO_LEVEL) { 1224 if (hdev->level == MAX_TOPO_LEVEL) {
1182 dev_err(&intf->dev, 1225 dev_err(&intf->dev,
1183 "Unsupported bus topology: hub nested too deep\n"); 1226 "Unsupported bus topology: hub nested too deep\n");
@@ -1356,10 +1399,8 @@ static void recursively_mark_NOTATTACHED(struct usb_device *udev)
1356 if (udev->children[i]) 1399 if (udev->children[i])
1357 recursively_mark_NOTATTACHED(udev->children[i]); 1400 recursively_mark_NOTATTACHED(udev->children[i]);
1358 } 1401 }
1359 if (udev->state == USB_STATE_SUSPENDED) { 1402 if (udev->state == USB_STATE_SUSPENDED)
1360 udev->discon_suspended = 1;
1361 udev->active_duration -= jiffies; 1403 udev->active_duration -= jiffies;
1362 }
1363 udev->state = USB_STATE_NOTATTACHED; 1404 udev->state = USB_STATE_NOTATTACHED;
1364} 1405}
1365 1406
@@ -1402,11 +1443,11 @@ void usb_set_device_state(struct usb_device *udev,
1402 || new_state == USB_STATE_SUSPENDED) 1443 || new_state == USB_STATE_SUSPENDED)
1403 ; /* No change to wakeup settings */ 1444 ; /* No change to wakeup settings */
1404 else if (new_state == USB_STATE_CONFIGURED) 1445 else if (new_state == USB_STATE_CONFIGURED)
1405 device_init_wakeup(&udev->dev, 1446 device_set_wakeup_capable(&udev->dev,
1406 (udev->actconfig->desc.bmAttributes 1447 (udev->actconfig->desc.bmAttributes
1407 & USB_CONFIG_ATT_WAKEUP)); 1448 & USB_CONFIG_ATT_WAKEUP));
1408 else 1449 else
1409 device_init_wakeup(&udev->dev, 0); 1450 device_set_wakeup_capable(&udev->dev, 0);
1410 } 1451 }
1411 if (udev->state == USB_STATE_SUSPENDED && 1452 if (udev->state == USB_STATE_SUSPENDED &&
1412 new_state != USB_STATE_SUSPENDED) 1453 new_state != USB_STATE_SUSPENDED)
@@ -1483,31 +1524,15 @@ static void update_address(struct usb_device *udev, int devnum)
1483 udev->devnum = devnum; 1524 udev->devnum = devnum;
1484} 1525}
1485 1526
1486#ifdef CONFIG_USB_SUSPEND 1527static void hub_free_dev(struct usb_device *udev)
1487
1488static void usb_stop_pm(struct usb_device *udev)
1489{ 1528{
1490 /* Synchronize with the ksuspend thread to prevent any more 1529 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1491 * autosuspend requests from being submitted, and decrement
1492 * the parent's count of unsuspended children.
1493 */
1494 usb_pm_lock(udev);
1495 if (udev->parent && !udev->discon_suspended)
1496 usb_autosuspend_device(udev->parent);
1497 usb_pm_unlock(udev);
1498 1530
1499 /* Stop any autosuspend or autoresume requests already submitted */ 1531 /* Root hubs aren't real devices, so don't free HCD resources */
1500 cancel_delayed_work_sync(&udev->autosuspend); 1532 if (hcd->driver->free_dev && udev->parent)
1501 cancel_work_sync(&udev->autoresume); 1533 hcd->driver->free_dev(hcd, udev);
1502} 1534}
1503 1535
1504#else
1505
1506static inline void usb_stop_pm(struct usb_device *udev)
1507{ }
1508
1509#endif
1510
1511/** 1536/**
1512 * usb_disconnect - disconnect a device (usbcore-internal) 1537 * usb_disconnect - disconnect a device (usbcore-internal)
1513 * @pdev: pointer to device being disconnected 1538 * @pdev: pointer to device being disconnected
@@ -1576,7 +1601,7 @@ void usb_disconnect(struct usb_device **pdev)
1576 *pdev = NULL; 1601 *pdev = NULL;
1577 spin_unlock_irq(&device_state_lock); 1602 spin_unlock_irq(&device_state_lock);
1578 1603
1579 usb_stop_pm(udev); 1604 hub_free_dev(udev);
1580 1605
1581 put_device(&udev->dev); 1606 put_device(&udev->dev);
1582} 1607}
@@ -1612,12 +1637,12 @@ static inline void announce_device(struct usb_device *udev) { }
1612#endif 1637#endif
1613 1638
1614/** 1639/**
1615 * usb_configure_device_otg - FIXME (usbcore-internal) 1640 * usb_enumerate_device_otg - FIXME (usbcore-internal)
1616 * @udev: newly addressed device (in ADDRESS state) 1641 * @udev: newly addressed device (in ADDRESS state)
1617 * 1642 *
1618 * Do configuration for On-The-Go devices 1643 * Finish enumeration for On-The-Go devices
1619 */ 1644 */
1620static int usb_configure_device_otg(struct usb_device *udev) 1645static int usb_enumerate_device_otg(struct usb_device *udev)
1621{ 1646{
1622 int err = 0; 1647 int err = 0;
1623 1648
@@ -1630,7 +1655,7 @@ static int usb_configure_device_otg(struct usb_device *udev)
1630 if (!udev->bus->is_b_host 1655 if (!udev->bus->is_b_host
1631 && udev->config 1656 && udev->config
1632 && udev->parent == udev->bus->root_hub) { 1657 && udev->parent == udev->bus->root_hub) {
1633 struct usb_otg_descriptor *desc = 0; 1658 struct usb_otg_descriptor *desc = NULL;
1634 struct usb_bus *bus = udev->bus; 1659 struct usb_bus *bus = udev->bus;
1635 1660
1636 /* descriptor may appear anywhere in config */ 1661 /* descriptor may appear anywhere in config */
@@ -1688,7 +1713,7 @@ fail:
1688 1713
1689 1714
1690/** 1715/**
1691 * usb_configure_device - Detect and probe device intfs/otg (usbcore-internal) 1716 * usb_enumerate_device - Read device configs/intfs/otg (usbcore-internal)
1692 * @udev: newly addressed device (in ADDRESS state) 1717 * @udev: newly addressed device (in ADDRESS state)
1693 * 1718 *
1694 * This is only called by usb_new_device() and usb_authorize_device() 1719 * This is only called by usb_new_device() and usb_authorize_device()
@@ -1699,7 +1724,7 @@ fail:
1699 * the string descriptors, as they will be errored out by the device 1724 * the string descriptors, as they will be errored out by the device
1700 * until it has been authorized. 1725 * until it has been authorized.
1701 */ 1726 */
1702static int usb_configure_device(struct usb_device *udev) 1727static int usb_enumerate_device(struct usb_device *udev)
1703{ 1728{
1704 int err; 1729 int err;
1705 1730
@@ -1723,7 +1748,7 @@ static int usb_configure_device(struct usb_device *udev)
1723 udev->descriptor.iManufacturer); 1748 udev->descriptor.iManufacturer);
1724 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber); 1749 udev->serial = usb_cache_string(udev, udev->descriptor.iSerialNumber);
1725 } 1750 }
1726 err = usb_configure_device_otg(udev); 1751 err = usb_enumerate_device_otg(udev);
1727fail: 1752fail:
1728 return err; 1753 return err;
1729} 1754}
@@ -1733,8 +1758,8 @@ fail:
1733 * usb_new_device - perform initial device setup (usbcore-internal) 1758 * usb_new_device - perform initial device setup (usbcore-internal)
1734 * @udev: newly addressed device (in ADDRESS state) 1759 * @udev: newly addressed device (in ADDRESS state)
1735 * 1760 *
1736 * This is called with devices which have been enumerated, but not yet 1761 * This is called with devices which have been detected but not fully
1737 * configured. The device descriptor is available, but not descriptors 1762 * enumerated. The device descriptor is available, but not descriptors
1738 * for any device configuration. The caller must have locked either 1763 * for any device configuration. The caller must have locked either
1739 * the parent hub (if udev is a normal device) or else the 1764 * the parent hub (if udev is a normal device) or else the
1740 * usb_bus_list_lock (if udev is a root hub). The parent's pointer to 1765 * usb_bus_list_lock (if udev is a root hub). The parent's pointer to
@@ -1753,12 +1778,21 @@ int usb_new_device(struct usb_device *udev)
1753{ 1778{
1754 int err; 1779 int err;
1755 1780
1756 /* Increment the parent's count of unsuspended children */ 1781 if (udev->parent) {
1757 if (udev->parent) 1782 /* Initialize non-root-hub device wakeup to disabled;
1758 usb_autoresume_device(udev->parent); 1783 * device (un)configuration controls wakeup capable
1784 * sysfs power/wakeup controls wakeup enabled/disabled
1785 */
1786 device_init_wakeup(&udev->dev, 0);
1787 device_set_wakeup_enable(&udev->dev, 1);
1788 }
1789
1790 /* Tell the runtime-PM framework the device is active */
1791 pm_runtime_set_active(&udev->dev);
1792 pm_runtime_enable(&udev->dev);
1759 1793
1760 usb_detect_quirks(udev); /* Determine quirks */ 1794 usb_detect_quirks(udev);
1761 err = usb_configure_device(udev); /* detect & probe dev/intfs */ 1795 err = usb_enumerate_device(udev); /* Read descriptors */
1762 if (err < 0) 1796 if (err < 0)
1763 goto fail; 1797 goto fail;
1764 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n", 1798 dev_dbg(&udev->dev, "udev %d, busnum %d, minor = %d\n",
@@ -1771,6 +1805,7 @@ int usb_new_device(struct usb_device *udev)
1771 /* Tell the world! */ 1805 /* Tell the world! */
1772 announce_device(udev); 1806 announce_device(udev);
1773 1807
1808 device_enable_async_suspend(&udev->dev);
1774 /* Register the device. The device driver is responsible 1809 /* Register the device. The device driver is responsible
1775 * for configuring the device and invoking the add-device 1810 * for configuring the device and invoking the add-device
1776 * notifier chain (used by usbfs and possibly others). 1811 * notifier chain (used by usbfs and possibly others).
@@ -1786,7 +1821,8 @@ int usb_new_device(struct usb_device *udev)
1786 1821
1787fail: 1822fail:
1788 usb_set_device_state(udev, USB_STATE_NOTATTACHED); 1823 usb_set_device_state(udev, USB_STATE_NOTATTACHED);
1789 usb_stop_pm(udev); 1824 pm_runtime_disable(&udev->dev);
1825 pm_runtime_set_suspended(&udev->dev);
1790 return err; 1826 return err;
1791} 1827}
1792 1828
@@ -1803,21 +1839,23 @@ fail:
1803 */ 1839 */
1804int usb_deauthorize_device(struct usb_device *usb_dev) 1840int usb_deauthorize_device(struct usb_device *usb_dev)
1805{ 1841{
1806 unsigned cnt;
1807 usb_lock_device(usb_dev); 1842 usb_lock_device(usb_dev);
1808 if (usb_dev->authorized == 0) 1843 if (usb_dev->authorized == 0)
1809 goto out_unauthorized; 1844 goto out_unauthorized;
1845
1810 usb_dev->authorized = 0; 1846 usb_dev->authorized = 0;
1811 usb_set_configuration(usb_dev, -1); 1847 usb_set_configuration(usb_dev, -1);
1848
1849 kfree(usb_dev->product);
1812 usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL); 1850 usb_dev->product = kstrdup("n/a (unauthorized)", GFP_KERNEL);
1851 kfree(usb_dev->manufacturer);
1813 usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL); 1852 usb_dev->manufacturer = kstrdup("n/a (unauthorized)", GFP_KERNEL);
1853 kfree(usb_dev->serial);
1814 usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL); 1854 usb_dev->serial = kstrdup("n/a (unauthorized)", GFP_KERNEL);
1815 kfree(usb_dev->config); 1855
1816 usb_dev->config = NULL; 1856 usb_destroy_configuration(usb_dev);
1817 for (cnt = 0; cnt < usb_dev->descriptor.bNumConfigurations; cnt++)
1818 kfree(usb_dev->rawdescriptors[cnt]);
1819 usb_dev->descriptor.bNumConfigurations = 0; 1857 usb_dev->descriptor.bNumConfigurations = 0;
1820 kfree(usb_dev->rawdescriptors); 1858
1821out_unauthorized: 1859out_unauthorized:
1822 usb_unlock_device(usb_dev); 1860 usb_unlock_device(usb_dev);
1823 return 0; 1861 return 0;
@@ -1827,15 +1865,11 @@ out_unauthorized:
1827int usb_authorize_device(struct usb_device *usb_dev) 1865int usb_authorize_device(struct usb_device *usb_dev)
1828{ 1866{
1829 int result = 0, c; 1867 int result = 0, c;
1868
1830 usb_lock_device(usb_dev); 1869 usb_lock_device(usb_dev);
1831 if (usb_dev->authorized == 1) 1870 if (usb_dev->authorized == 1)
1832 goto out_authorized; 1871 goto out_authorized;
1833 kfree(usb_dev->product); 1872
1834 usb_dev->product = NULL;
1835 kfree(usb_dev->manufacturer);
1836 usb_dev->manufacturer = NULL;
1837 kfree(usb_dev->serial);
1838 usb_dev->serial = NULL;
1839 result = usb_autoresume_device(usb_dev); 1873 result = usb_autoresume_device(usb_dev);
1840 if (result < 0) { 1874 if (result < 0) {
1841 dev_err(&usb_dev->dev, 1875 dev_err(&usb_dev->dev,
@@ -1848,10 +1882,18 @@ int usb_authorize_device(struct usb_device *usb_dev)
1848 "authorization: %d\n", result); 1882 "authorization: %d\n", result);
1849 goto error_device_descriptor; 1883 goto error_device_descriptor;
1850 } 1884 }
1885
1886 kfree(usb_dev->product);
1887 usb_dev->product = NULL;
1888 kfree(usb_dev->manufacturer);
1889 usb_dev->manufacturer = NULL;
1890 kfree(usb_dev->serial);
1891 usb_dev->serial = NULL;
1892
1851 usb_dev->authorized = 1; 1893 usb_dev->authorized = 1;
1852 result = usb_configure_device(usb_dev); 1894 result = usb_enumerate_device(usb_dev);
1853 if (result < 0) 1895 if (result < 0)
1854 goto error_configure; 1896 goto error_enumerate;
1855 /* Choose and set the configuration. This registers the interfaces 1897 /* Choose and set the configuration. This registers the interfaces
1856 * with the driver core and lets interface drivers bind to them. 1898 * with the driver core and lets interface drivers bind to them.
1857 */ 1899 */
@@ -1866,8 +1908,10 @@ int usb_authorize_device(struct usb_device *usb_dev)
1866 } 1908 }
1867 } 1909 }
1868 dev_info(&usb_dev->dev, "authorized to connect\n"); 1910 dev_info(&usb_dev->dev, "authorized to connect\n");
1869error_configure: 1911
1912error_enumerate:
1870error_device_descriptor: 1913error_device_descriptor:
1914 usb_autosuspend_device(usb_dev);
1871error_autoresume: 1915error_autoresume:
1872out_authorized: 1916out_authorized:
1873 usb_unlock_device(usb_dev); // complements locktree 1917 usb_unlock_device(usb_dev); // complements locktree
@@ -1927,7 +1971,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
1927 if (!(portstatus & USB_PORT_STAT_RESET) && 1971 if (!(portstatus & USB_PORT_STAT_RESET) &&
1928 (portstatus & USB_PORT_STAT_ENABLE)) { 1972 (portstatus & USB_PORT_STAT_ENABLE)) {
1929 if (hub_is_wusb(hub)) 1973 if (hub_is_wusb(hub))
1930 udev->speed = USB_SPEED_VARIABLE; 1974 udev->speed = USB_SPEED_WIRELESS;
1931 else if (portstatus & USB_PORT_STAT_HIGH_SPEED) 1975 else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
1932 udev->speed = USB_SPEED_HIGH; 1976 udev->speed = USB_SPEED_HIGH;
1933 else if (portstatus & USB_PORT_STAT_LOW_SPEED) 1977 else if (portstatus & USB_PORT_STAT_LOW_SPEED)
@@ -1953,7 +1997,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1953 struct usb_device *udev, unsigned int delay) 1997 struct usb_device *udev, unsigned int delay)
1954{ 1998{
1955 int i, status; 1999 int i, status;
2000 struct usb_hcd *hcd;
1956 2001
2002 hcd = bus_to_hcd(udev->bus);
1957 /* Block EHCI CF initialization during the port reset. 2003 /* Block EHCI CF initialization during the port reset.
1958 * Some companion controllers don't like it when they mix. 2004 * Some companion controllers don't like it when they mix.
1959 */ 2005 */
@@ -1981,6 +2027,14 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
1981 /* TRSTRCY = 10 ms; plus some extra */ 2027 /* TRSTRCY = 10 ms; plus some extra */
1982 msleep(10 + 40); 2028 msleep(10 + 40);
1983 update_address(udev, 0); 2029 update_address(udev, 0);
2030 if (hcd->driver->reset_device) {
2031 status = hcd->driver->reset_device(hcd, udev);
2032 if (status < 0) {
2033 dev_err(&udev->dev, "Cannot reset "
2034 "HCD device state\n");
2035 break;
2036 }
2037 }
1984 /* FALL THROUGH */ 2038 /* FALL THROUGH */
1985 case -ENOTCONN: 2039 case -ENOTCONN:
1986 case -ENODEV: 2040 case -ENODEV:
@@ -2123,9 +2177,13 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2123 USB_DEVICE_REMOTE_WAKEUP, 0, 2177 USB_DEVICE_REMOTE_WAKEUP, 0,
2124 NULL, 0, 2178 NULL, 0,
2125 USB_CTRL_SET_TIMEOUT); 2179 USB_CTRL_SET_TIMEOUT);
2126 if (status) 2180 if (status) {
2127 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n", 2181 dev_dbg(&udev->dev, "won't remote wakeup, status %d\n",
2128 status); 2182 status);
2183 /* bail if autosuspend is requested */
2184 if (msg.event & PM_EVENT_AUTO)
2185 return status;
2186 }
2129 } 2187 }
2130 2188
2131 /* see 7.1.7.6 */ 2189 /* see 7.1.7.6 */
@@ -2134,7 +2192,8 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2134 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", 2192 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
2135 port1, status); 2193 port1, status);
2136 /* paranoia: "should not happen" */ 2194 /* paranoia: "should not happen" */
2137 (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 2195 if (udev->do_remote_wakeup)
2196 (void) usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
2138 USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE, 2197 USB_REQ_CLEAR_FEATURE, USB_RECIP_DEVICE,
2139 USB_DEVICE_REMOTE_WAKEUP, 0, 2198 USB_DEVICE_REMOTE_WAKEUP, 0,
2140 NULL, 0, 2199 NULL, 0,
@@ -2321,14 +2380,17 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2321} 2380}
2322 2381
2323/* caller has locked udev */ 2382/* caller has locked udev */
2324static int remote_wakeup(struct usb_device *udev) 2383int usb_remote_wakeup(struct usb_device *udev)
2325{ 2384{
2326 int status = 0; 2385 int status = 0;
2327 2386
2328 if (udev->state == USB_STATE_SUSPENDED) { 2387 if (udev->state == USB_STATE_SUSPENDED) {
2329 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); 2388 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-");
2330 usb_mark_last_busy(udev); 2389 status = usb_autoresume_device(udev);
2331 status = usb_external_resume_device(udev, PMSG_REMOTE_RESUME); 2390 if (status == 0) {
2391 /* Let the drivers do their thing, then... */
2392 usb_autosuspend_device(udev);
2393 }
2332 } 2394 }
2333 return status; 2395 return status;
2334} 2396}
@@ -2365,11 +2427,6 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
2365 return status; 2427 return status;
2366} 2428}
2367 2429
2368static inline int remote_wakeup(struct usb_device *udev)
2369{
2370 return 0;
2371}
2372
2373#endif 2430#endif
2374 2431
2375static int hub_suspend(struct usb_interface *intf, pm_message_t msg) 2432static int hub_suspend(struct usb_interface *intf, pm_message_t msg)
@@ -2436,11 +2493,6 @@ EXPORT_SYMBOL_GPL(usb_root_hub_lost_power);
2436 2493
2437#else /* CONFIG_PM */ 2494#else /* CONFIG_PM */
2438 2495
2439static inline int remote_wakeup(struct usb_device *udev)
2440{
2441 return 0;
2442}
2443
2444#define hub_suspend NULL 2496#define hub_suspend NULL
2445#define hub_resume NULL 2497#define hub_resume NULL
2446#define hub_reset_resume NULL 2498#define hub_reset_resume NULL
@@ -2585,14 +2637,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2585 2637
2586 mutex_lock(&usb_address0_mutex); 2638 mutex_lock(&usb_address0_mutex);
2587 2639
2588 if ((hcd->driver->flags & HCD_USB3) && udev->config) { 2640 if (!udev->config && oldspeed == USB_SPEED_SUPER) {
2589 /* FIXME this will need special handling by the xHCI driver. */
2590 dev_dbg(&udev->dev,
2591 "xHCI reset of configured device "
2592 "not supported yet.\n");
2593 retval = -EINVAL;
2594 goto fail;
2595 } else if (!udev->config && oldspeed == USB_SPEED_SUPER) {
2596 /* Don't reset USB 3.0 devices during an initial setup */ 2641 /* Don't reset USB 3.0 devices during an initial setup */
2597 usb_set_device_state(udev, USB_STATE_DEFAULT); 2642 usb_set_device_state(udev, USB_STATE_DEFAULT);
2598 } else { 2643 } else {
@@ -2618,7 +2663,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2618 */ 2663 */
2619 switch (udev->speed) { 2664 switch (udev->speed) {
2620 case USB_SPEED_SUPER: 2665 case USB_SPEED_SUPER:
2621 case USB_SPEED_VARIABLE: /* fixed at 512 */ 2666 case USB_SPEED_WIRELESS: /* fixed at 512 */
2622 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512); 2667 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
2623 break; 2668 break;
2624 case USB_SPEED_HIGH: /* fixed at 64 */ 2669 case USB_SPEED_HIGH: /* fixed at 64 */
@@ -2646,7 +2691,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2646 case USB_SPEED_SUPER: 2691 case USB_SPEED_SUPER:
2647 speed = "super"; 2692 speed = "super";
2648 break; 2693 break;
2649 case USB_SPEED_VARIABLE: 2694 case USB_SPEED_WIRELESS:
2650 speed = "variable"; 2695 speed = "variable";
2651 type = "Wireless "; 2696 type = "Wireless ";
2652 break; 2697 break;
@@ -2946,7 +2991,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2946 /* For a suspended device, treat this as a 2991 /* For a suspended device, treat this as a
2947 * remote wakeup event. 2992 * remote wakeup event.
2948 */ 2993 */
2949 status = remote_wakeup(udev); 2994 status = usb_remote_wakeup(udev);
2950#endif 2995#endif
2951 2996
2952 } else { 2997 } else {
@@ -2965,6 +3010,13 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2965 usb_disconnect(&hdev->children[port1-1]); 3010 usb_disconnect(&hdev->children[port1-1]);
2966 clear_bit(port1, hub->change_bits); 3011 clear_bit(port1, hub->change_bits);
2967 3012
3013 /* We can forget about a "removed" device when there's a physical
3014 * disconnect or the connect status changes.
3015 */
3016 if (!(portstatus & USB_PORT_STAT_CONNECTION) ||
3017 (portchange & USB_PORT_STAT_C_CONNECTION))
3018 clear_bit(port1, hub->removed_bits);
3019
2968 if (portchange & (USB_PORT_STAT_C_CONNECTION | 3020 if (portchange & (USB_PORT_STAT_C_CONNECTION |
2969 USB_PORT_STAT_C_ENABLE)) { 3021 USB_PORT_STAT_C_ENABLE)) {
2970 status = hub_port_debounce(hub, port1); 3022 status = hub_port_debounce(hub, port1);
@@ -2978,8 +3030,11 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
2978 } 3030 }
2979 } 3031 }
2980 3032
2981 /* Return now if debouncing failed or nothing is connected */ 3033 /* Return now if debouncing failed or nothing is connected or
2982 if (!(portstatus & USB_PORT_STAT_CONNECTION)) { 3034 * the device was "removed".
3035 */
3036 if (!(portstatus & USB_PORT_STAT_CONNECTION) ||
3037 test_bit(port1, hub->removed_bits)) {
2983 3038
2984 /* maybe switch power back on (e.g. root hub was reset) */ 3039 /* maybe switch power back on (e.g. root hub was reset) */
2985 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2 3040 if ((wHubCharacteristics & HUB_CHAR_LPSM) < 2
@@ -3122,6 +3177,7 @@ loop_disable:
3122loop: 3177loop:
3123 usb_ep0_reinit(udev); 3178 usb_ep0_reinit(udev);
3124 release_address(udev); 3179 release_address(udev);
3180 hub_free_dev(udev);
3125 usb_put_dev(udev); 3181 usb_put_dev(udev);
3126 if ((status == -ENOTCONN) || (status == -ENOTSUPP)) 3182 if ((status == -ENOTCONN) || (status == -ENOTSUPP))
3127 break; 3183 break;
@@ -3189,7 +3245,7 @@ static void hub_events(void)
3189 * disconnected while waiting for the lock to succeed. */ 3245 * disconnected while waiting for the lock to succeed. */
3190 usb_lock_device(hdev); 3246 usb_lock_device(hdev);
3191 if (unlikely(hub->disconnected)) 3247 if (unlikely(hub->disconnected))
3192 goto loop; 3248 goto loop_disconnected;
3193 3249
3194 /* If the hub has died, clean up after it */ 3250 /* If the hub has died, clean up after it */
3195 if (hdev->state == USB_STATE_NOTATTACHED) { 3251 if (hdev->state == USB_STATE_NOTATTACHED) {
@@ -3278,8 +3334,11 @@ static void hub_events(void)
3278 USB_PORT_FEAT_C_SUSPEND); 3334 USB_PORT_FEAT_C_SUSPEND);
3279 udev = hdev->children[i-1]; 3335 udev = hdev->children[i-1];
3280 if (udev) { 3336 if (udev) {
3337 /* TRSMRCY = 10 msec */
3338 msleep(10);
3339
3281 usb_lock_device(udev); 3340 usb_lock_device(udev);
3282 ret = remote_wakeup(hdev-> 3341 ret = usb_remote_wakeup(hdev->
3283 children[i-1]); 3342 children[i-1]);
3284 usb_unlock_device(udev); 3343 usb_unlock_device(udev);
3285 if (ret < 0) 3344 if (ret < 0)
@@ -3338,11 +3397,15 @@ static void hub_events(void)
3338 } 3397 }
3339 } 3398 }
3340 3399
3341loop_autopm: 3400 loop_autopm:
3342 /* Allow autosuspend if we're not going to run again */ 3401 /* Balance the usb_autopm_get_interface() above */
3343 if (list_empty(&hub->event_list)) 3402 usb_autopm_put_interface_no_suspend(intf);
3344 usb_autopm_enable(intf); 3403 loop:
3345loop: 3404 /* Balance the usb_autopm_get_interface_no_resume() in
3405 * kick_khubd() and allow autosuspend.
3406 */
3407 usb_autopm_put_interface(intf);
3408 loop_disconnected:
3346 usb_unlock_device(hdev); 3409 usb_unlock_device(hdev);
3347 kref_put(&hub->kref, hub_release); 3410 kref_put(&hub->kref, hub_release);
3348 3411
@@ -3369,7 +3432,7 @@ static int hub_thread(void *__unused)
3369 return 0; 3432 return 0;
3370} 3433}
3371 3434
3372static struct usb_device_id hub_id_table [] = { 3435static const struct usb_device_id hub_id_table[] = {
3373 { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS, 3436 { .match_flags = USB_DEVICE_ID_MATCH_DEV_CLASS,
3374 .bDeviceClass = USB_CLASS_HUB}, 3437 .bDeviceClass = USB_CLASS_HUB},
3375 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS, 3438 { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
@@ -3534,6 +3597,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3534{ 3597{
3535 struct usb_device *parent_hdev = udev->parent; 3598 struct usb_device *parent_hdev = udev->parent;
3536 struct usb_hub *parent_hub; 3599 struct usb_hub *parent_hub;
3600 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
3537 struct usb_device_descriptor descriptor = udev->descriptor; 3601 struct usb_device_descriptor descriptor = udev->descriptor;
3538 int i, ret = 0; 3602 int i, ret = 0;
3539 int port1 = udev->portnum; 3603 int port1 = udev->portnum;
@@ -3577,6 +3641,16 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3577 /* Restore the device's previous configuration */ 3641 /* Restore the device's previous configuration */
3578 if (!udev->actconfig) 3642 if (!udev->actconfig)
3579 goto done; 3643 goto done;
3644
3645 mutex_lock(&hcd->bandwidth_mutex);
3646 ret = usb_hcd_alloc_bandwidth(udev, udev->actconfig, NULL, NULL);
3647 if (ret < 0) {
3648 dev_warn(&udev->dev,
3649 "Busted HC? Not enough HCD resources for "
3650 "old configuration.\n");
3651 mutex_unlock(&hcd->bandwidth_mutex);
3652 goto re_enumerate;
3653 }
3580 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3654 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3581 USB_REQ_SET_CONFIGURATION, 0, 3655 USB_REQ_SET_CONFIGURATION, 0,
3582 udev->actconfig->desc.bConfigurationValue, 0, 3656 udev->actconfig->desc.bConfigurationValue, 0,
@@ -3585,8 +3659,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3585 dev_err(&udev->dev, 3659 dev_err(&udev->dev,
3586 "can't restore configuration #%d (error=%d)\n", 3660 "can't restore configuration #%d (error=%d)\n",
3587 udev->actconfig->desc.bConfigurationValue, ret); 3661 udev->actconfig->desc.bConfigurationValue, ret);
3662 mutex_unlock(&hcd->bandwidth_mutex);
3588 goto re_enumerate; 3663 goto re_enumerate;
3589 } 3664 }
3665 mutex_unlock(&hcd->bandwidth_mutex);
3590 usb_set_device_state(udev, USB_STATE_CONFIGURED); 3666 usb_set_device_state(udev, USB_STATE_CONFIGURED);
3591 3667
3592 /* Put interfaces back into the same altsettings as before. 3668 /* Put interfaces back into the same altsettings as before.
@@ -3596,7 +3672,8 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3596 * endpoint state. 3672 * endpoint state.
3597 */ 3673 */
3598 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 3674 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
3599 struct usb_interface *intf = udev->actconfig->interface[i]; 3675 struct usb_host_config *config = udev->actconfig;
3676 struct usb_interface *intf = config->interface[i];
3600 struct usb_interface_descriptor *desc; 3677 struct usb_interface_descriptor *desc;
3601 3678
3602 desc = &intf->cur_altsetting->desc; 3679 desc = &intf->cur_altsetting->desc;
@@ -3605,8 +3682,14 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3605 usb_enable_interface(udev, intf, true); 3682 usb_enable_interface(udev, intf, true);
3606 ret = 0; 3683 ret = 0;
3607 } else { 3684 } else {
3685 /* Let the bandwidth allocation function know that this
3686 * device has been reset, and it will have to use
3687 * alternate setting 0 as the current alternate setting.
3688 */
3689 intf->resetting_device = 1;
3608 ret = usb_set_interface(udev, desc->bInterfaceNumber, 3690 ret = usb_set_interface(udev, desc->bInterfaceNumber,
3609 desc->bAlternateSetting); 3691 desc->bAlternateSetting);
3692 intf->resetting_device = 0;
3610 } 3693 }
3611 if (ret < 0) { 3694 if (ret < 0) {
3612 dev_err(&udev->dev, "failed to restore interface %d " 3695 dev_err(&udev->dev, "failed to restore interface %d "
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index 97b40ce133f0..111a01a747fc 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -380,6 +380,7 @@ static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
380 mutex_lock(&inode->i_mutex); 380 mutex_lock(&inode->i_mutex);
381 dentry_unhash(dentry); 381 dentry_unhash(dentry);
382 if (usbfs_empty(dentry)) { 382 if (usbfs_empty(dentry)) {
383 dont_mount(dentry);
383 drop_nlink(dentry->d_inode); 384 drop_nlink(dentry->d_inode);
384 drop_nlink(dentry->d_inode); 385 drop_nlink(dentry->d_inode);
385 dput(dentry); 386 dput(dentry);
@@ -515,13 +516,13 @@ static int fs_create_by_name (const char *name, mode_t mode,
515 *dentry = NULL; 516 *dentry = NULL;
516 mutex_lock(&parent->d_inode->i_mutex); 517 mutex_lock(&parent->d_inode->i_mutex);
517 *dentry = lookup_one_len(name, parent, strlen(name)); 518 *dentry = lookup_one_len(name, parent, strlen(name));
518 if (!IS_ERR(dentry)) { 519 if (!IS_ERR(*dentry)) {
519 if ((mode & S_IFMT) == S_IFDIR) 520 if ((mode & S_IFMT) == S_IFDIR)
520 error = usbfs_mkdir (parent->d_inode, *dentry, mode); 521 error = usbfs_mkdir (parent->d_inode, *dentry, mode);
521 else 522 else
522 error = usbfs_create (parent->d_inode, *dentry, mode); 523 error = usbfs_create (parent->d_inode, *dentry, mode);
523 } else 524 } else
524 error = PTR_ERR(dentry); 525 error = PTR_ERR(*dentry);
525 mutex_unlock(&parent->d_inode->i_mutex); 526 mutex_unlock(&parent->d_inode->i_mutex);
526 527
527 return error; 528 return error;
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index da718e84d58d..cd220277c6c3 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -393,13 +393,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
393 if (io->entries <= 0) 393 if (io->entries <= 0)
394 return io->entries; 394 return io->entries;
395 395
396 /* If we're running on an xHCI host controller, queue the whole scatter 396 if (dev->bus->sg_tablesize > 0) {
397 * gather list with one call to urb_enqueue(). This is only for bulk,
398 * as that endpoint type does not care how the data gets broken up
399 * across frames.
400 */
401 if (usb_pipebulk(pipe) &&
402 bus_to_hcd(dev->bus)->driver->flags & HCD_USB3) {
403 io->urbs = kmalloc(sizeof *io->urbs, mem_flags); 397 io->urbs = kmalloc(sizeof *io->urbs, mem_flags);
404 use_sg = true; 398 use_sg = true;
405 } else { 399 } else {
@@ -409,7 +403,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
409 if (!io->urbs) 403 if (!io->urbs)
410 goto nomem; 404 goto nomem;
411 405
412 urb_flags = URB_NO_INTERRUPT; 406 urb_flags = 0;
413 if (dma) 407 if (dma)
414 urb_flags |= URB_NO_TRANSFER_DMA_MAP; 408 urb_flags |= URB_NO_TRANSFER_DMA_MAP;
415 if (usb_pipein(pipe)) 409 if (usb_pipein(pipe))
@@ -441,6 +435,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
441 io->urbs[0]->num_sgs = io->entries; 435 io->urbs[0]->num_sgs = io->entries;
442 io->entries = 1; 436 io->entries = 1;
443 } else { 437 } else {
438 urb_flags |= URB_NO_INTERRUPT;
444 for_each_sg(sg, sg, io->entries, i) { 439 for_each_sg(sg, sg, io->entries, i) {
445 unsigned len; 440 unsigned len;
446 441
@@ -911,11 +906,11 @@ char *usb_cache_string(struct usb_device *udev, int index)
911 if (index <= 0) 906 if (index <= 0)
912 return NULL; 907 return NULL;
913 908
914 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_KERNEL); 909 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
915 if (buf) { 910 if (buf) {
916 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE); 911 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
917 if (len > 0) { 912 if (len > 0) {
918 smallbuf = kmalloc(++len, GFP_KERNEL); 913 smallbuf = kmalloc(++len, GFP_NOIO);
919 if (!smallbuf) 914 if (!smallbuf)
920 return buf; 915 return buf;
921 memcpy(smallbuf, buf, len); 916 memcpy(smallbuf, buf, len);
@@ -1303,6 +1298,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1303{ 1298{
1304 struct usb_interface *iface; 1299 struct usb_interface *iface;
1305 struct usb_host_interface *alt; 1300 struct usb_host_interface *alt;
1301 struct usb_hcd *hcd = bus_to_hcd(dev->bus);
1306 int ret; 1302 int ret;
1307 int manual = 0; 1303 int manual = 0;
1308 unsigned int epaddr; 1304 unsigned int epaddr;
@@ -1320,11 +1316,23 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1320 1316
1321 alt = usb_altnum_to_altsetting(iface, alternate); 1317 alt = usb_altnum_to_altsetting(iface, alternate);
1322 if (!alt) { 1318 if (!alt) {
1323 dev_warn(&dev->dev, "selecting invalid altsetting %d", 1319 dev_warn(&dev->dev, "selecting invalid altsetting %d\n",
1324 alternate); 1320 alternate);
1325 return -EINVAL; 1321 return -EINVAL;
1326 } 1322 }
1327 1323
1324 /* Make sure we have enough bandwidth for this alternate interface.
1325 * Remove the current alt setting and add the new alt setting.
1326 */
1327 mutex_lock(&hcd->bandwidth_mutex);
1328 ret = usb_hcd_alloc_bandwidth(dev, NULL, iface->cur_altsetting, alt);
1329 if (ret < 0) {
1330 dev_info(&dev->dev, "Not enough bandwidth for altsetting %d\n",
1331 alternate);
1332 mutex_unlock(&hcd->bandwidth_mutex);
1333 return ret;
1334 }
1335
1328 if (dev->quirks & USB_QUIRK_NO_SET_INTF) 1336 if (dev->quirks & USB_QUIRK_NO_SET_INTF)
1329 ret = -EPIPE; 1337 ret = -EPIPE;
1330 else 1338 else
@@ -1340,8 +1348,13 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
1340 "manual set_interface for iface %d, alt %d\n", 1348 "manual set_interface for iface %d, alt %d\n",
1341 interface, alternate); 1349 interface, alternate);
1342 manual = 1; 1350 manual = 1;
1343 } else if (ret < 0) 1351 } else if (ret < 0) {
1352 /* Re-instate the old alt setting */
1353 usb_hcd_alloc_bandwidth(dev, NULL, alt, iface->cur_altsetting);
1354 mutex_unlock(&hcd->bandwidth_mutex);
1344 return ret; 1355 return ret;
1356 }
1357 mutex_unlock(&hcd->bandwidth_mutex);
1345 1358
1346 /* FIXME drivers shouldn't need to replicate/bugfix the logic here 1359 /* FIXME drivers shouldn't need to replicate/bugfix the logic here
1347 * when they implement async or easily-killable versions of this or 1360 * when they implement async or easily-killable versions of this or
@@ -1423,6 +1436,7 @@ int usb_reset_configuration(struct usb_device *dev)
1423{ 1436{
1424 int i, retval; 1437 int i, retval;
1425 struct usb_host_config *config; 1438 struct usb_host_config *config;
1439 struct usb_hcd *hcd = bus_to_hcd(dev->bus);
1426 1440
1427 if (dev->state == USB_STATE_SUSPENDED) 1441 if (dev->state == USB_STATE_SUSPENDED)
1428 return -EHOSTUNREACH; 1442 return -EHOSTUNREACH;
@@ -1438,12 +1452,46 @@ int usb_reset_configuration(struct usb_device *dev)
1438 } 1452 }
1439 1453
1440 config = dev->actconfig; 1454 config = dev->actconfig;
1455 retval = 0;
1456 mutex_lock(&hcd->bandwidth_mutex);
1457 /* Make sure we have enough bandwidth for each alternate setting 0 */
1458 for (i = 0; i < config->desc.bNumInterfaces; i++) {
1459 struct usb_interface *intf = config->interface[i];
1460 struct usb_host_interface *alt;
1461
1462 alt = usb_altnum_to_altsetting(intf, 0);
1463 if (!alt)
1464 alt = &intf->altsetting[0];
1465 if (alt != intf->cur_altsetting)
1466 retval = usb_hcd_alloc_bandwidth(dev, NULL,
1467 intf->cur_altsetting, alt);
1468 if (retval < 0)
1469 break;
1470 }
1471 /* If not, reinstate the old alternate settings */
1472 if (retval < 0) {
1473reset_old_alts:
1474 for (i--; i >= 0; i--) {
1475 struct usb_interface *intf = config->interface[i];
1476 struct usb_host_interface *alt;
1477
1478 alt = usb_altnum_to_altsetting(intf, 0);
1479 if (!alt)
1480 alt = &intf->altsetting[0];
1481 if (alt != intf->cur_altsetting)
1482 usb_hcd_alloc_bandwidth(dev, NULL,
1483 alt, intf->cur_altsetting);
1484 }
1485 mutex_unlock(&hcd->bandwidth_mutex);
1486 return retval;
1487 }
1441 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1488 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1442 USB_REQ_SET_CONFIGURATION, 0, 1489 USB_REQ_SET_CONFIGURATION, 0,
1443 config->desc.bConfigurationValue, 0, 1490 config->desc.bConfigurationValue, 0,
1444 NULL, 0, USB_CTRL_SET_TIMEOUT); 1491 NULL, 0, USB_CTRL_SET_TIMEOUT);
1445 if (retval < 0) 1492 if (retval < 0)
1446 return retval; 1493 goto reset_old_alts;
1494 mutex_unlock(&hcd->bandwidth_mutex);
1447 1495
1448 /* re-init hc/hcd interface/endpoint state */ 1496 /* re-init hc/hcd interface/endpoint state */
1449 for (i = 0; i < config->desc.bNumInterfaces; i++) { 1497 for (i = 0; i < config->desc.bNumInterfaces; i++) {
@@ -1585,7 +1633,7 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
1585 * 1633 *
1586 * See usb_queue_reset_device() for more details 1634 * See usb_queue_reset_device() for more details
1587 */ 1635 */
1588void __usb_queue_reset_device(struct work_struct *ws) 1636static void __usb_queue_reset_device(struct work_struct *ws)
1589{ 1637{
1590 int rc; 1638 int rc;
1591 struct usb_interface *iface = 1639 struct usb_interface *iface =
@@ -1652,6 +1700,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1652 int i, ret; 1700 int i, ret;
1653 struct usb_host_config *cp = NULL; 1701 struct usb_host_config *cp = NULL;
1654 struct usb_interface **new_interfaces = NULL; 1702 struct usb_interface **new_interfaces = NULL;
1703 struct usb_hcd *hcd = bus_to_hcd(dev->bus);
1655 int n, nintf; 1704 int n, nintf;
1656 1705
1657 if (dev->authorized == 0 || configuration == -1) 1706 if (dev->authorized == 0 || configuration == -1)
@@ -1682,7 +1731,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1682 if (cp) { 1731 if (cp) {
1683 nintf = cp->desc.bNumInterfaces; 1732 nintf = cp->desc.bNumInterfaces;
1684 new_interfaces = kmalloc(nintf * sizeof(*new_interfaces), 1733 new_interfaces = kmalloc(nintf * sizeof(*new_interfaces),
1685 GFP_KERNEL); 1734 GFP_NOIO);
1686 if (!new_interfaces) { 1735 if (!new_interfaces) {
1687 dev_err(&dev->dev, "Out of memory\n"); 1736 dev_err(&dev->dev, "Out of memory\n");
1688 return -ENOMEM; 1737 return -ENOMEM;
@@ -1691,7 +1740,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
1691 for (; n < nintf; ++n) { 1740 for (; n < nintf; ++n) {
1692 new_interfaces[n] = kzalloc( 1741 new_interfaces[n] = kzalloc(
1693 sizeof(struct usb_interface), 1742 sizeof(struct usb_interface),
1694 GFP_KERNEL); 1743 GFP_NOIO);
1695 if (!new_interfaces[n]) { 1744 if (!new_interfaces[n]) {
1696 dev_err(&dev->dev, "Out of memory\n"); 1745 dev_err(&dev->dev, "Out of memory\n");
1697 ret = -ENOMEM; 1746 ret = -ENOMEM;
@@ -1721,12 +1770,11 @@ free_interfaces:
1721 * host controller will not allow submissions to dropped endpoints. If 1770 * host controller will not allow submissions to dropped endpoints. If
1722 * this call fails, the device state is unchanged. 1771 * this call fails, the device state is unchanged.
1723 */ 1772 */
1724 if (cp) 1773 mutex_lock(&hcd->bandwidth_mutex);
1725 ret = usb_hcd_check_bandwidth(dev, cp, NULL); 1774 ret = usb_hcd_alloc_bandwidth(dev, cp, NULL, NULL);
1726 else
1727 ret = usb_hcd_check_bandwidth(dev, NULL, NULL);
1728 if (ret < 0) { 1775 if (ret < 0) {
1729 usb_autosuspend_device(dev); 1776 usb_autosuspend_device(dev);
1777 mutex_unlock(&hcd->bandwidth_mutex);
1730 goto free_interfaces; 1778 goto free_interfaces;
1731 } 1779 }
1732 1780
@@ -1752,10 +1800,12 @@ free_interfaces:
1752 dev->actconfig = cp; 1800 dev->actconfig = cp;
1753 if (!cp) { 1801 if (!cp) {
1754 usb_set_device_state(dev, USB_STATE_ADDRESS); 1802 usb_set_device_state(dev, USB_STATE_ADDRESS);
1755 usb_hcd_check_bandwidth(dev, NULL, NULL); 1803 usb_hcd_alloc_bandwidth(dev, NULL, NULL, NULL);
1756 usb_autosuspend_device(dev); 1804 usb_autosuspend_device(dev);
1805 mutex_unlock(&hcd->bandwidth_mutex);
1757 goto free_interfaces; 1806 goto free_interfaces;
1758 } 1807 }
1808 mutex_unlock(&hcd->bandwidth_mutex);
1759 usb_set_device_state(dev, USB_STATE_CONFIGURED); 1809 usb_set_device_state(dev, USB_STATE_CONFIGURED);
1760 1810
1761 /* Initialize the new interface structures and the 1811 /* Initialize the new interface structures and the
@@ -1793,7 +1843,6 @@ free_interfaces:
1793 intf->dev.dma_mask = dev->dev.dma_mask; 1843 intf->dev.dma_mask = dev->dev.dma_mask;
1794 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); 1844 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device);
1795 device_initialize(&intf->dev); 1845 device_initialize(&intf->dev);
1796 mark_quiesced(intf);
1797 dev_set_name(&intf->dev, "%d-%s:%d.%d", 1846 dev_set_name(&intf->dev, "%d-%s:%d.%d",
1798 dev->bus->busnum, dev->devpath, 1847 dev->bus->busnum, dev->devpath,
1799 configuration, alt->desc.bInterfaceNumber); 1848 configuration, alt->desc.bInterfaceNumber);
@@ -1817,6 +1866,7 @@ free_interfaces:
1817 "adding %s (config #%d, interface %d)\n", 1866 "adding %s (config #%d, interface %d)\n",
1818 dev_name(&intf->dev), configuration, 1867 dev_name(&intf->dev), configuration,
1819 intf->cur_altsetting->desc.bInterfaceNumber); 1868 intf->cur_altsetting->desc.bInterfaceNumber);
1869 device_enable_async_suspend(&intf->dev);
1820 ret = device_add(&intf->dev); 1870 ret = device_add(&intf->dev);
1821 if (ret != 0) { 1871 if (ret != 0) {
1822 dev_err(&dev->dev, "device_add(%s) --> %d\n", 1872 dev_err(&dev->dev, "device_add(%s) --> %d\n",
@@ -1890,7 +1940,7 @@ static void cancel_async_set_config(struct usb_device *udev)
1890 * routine gets around the normal restrictions by using a work thread to 1940 * routine gets around the normal restrictions by using a work thread to
1891 * submit the change-config request. 1941 * submit the change-config request.
1892 * 1942 *
1893 * Returns 0 if the request was succesfully queued, error code otherwise. 1943 * Returns 0 if the request was successfully queued, error code otherwise.
1894 * The caller has no way to know whether the queued request will eventually 1944 * The caller has no way to know whether the queued request will eventually
1895 * succeed. 1945 * succeed.
1896 */ 1946 */
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index ab93918d9207..f073c5cb4e7b 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -103,10 +103,19 @@ void usb_detect_quirks(struct usb_device *udev)
103 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 103 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
104 udev->quirks); 104 udev->quirks);
105 105
106 /* By default, disable autosuspend for all non-hubs */
107#ifdef CONFIG_USB_SUSPEND 106#ifdef CONFIG_USB_SUSPEND
108 if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) 107
109 udev->autosuspend_disabled = 1; 108 /* By default, disable autosuspend for all devices. The hub driver
109 * will enable it for hubs.
110 */
111 usb_disable_autosuspend(udev);
112
113 /* Autosuspend can also be disabled if the initial autosuspend_delay
114 * is negative.
115 */
116 if (udev->autosuspend_delay < 0)
117 usb_autoresume_device(udev);
118
110#endif 119#endif
111 120
112 /* For the present, all devices default to USB-PERSIST enabled */ 121 /* For the present, all devices default to USB-PERSIST enabled */
@@ -120,6 +129,7 @@ void usb_detect_quirks(struct usb_device *udev)
120 * for all devices. It will affect things like hub resets 129 * for all devices. It will affect things like hub resets
121 * and EMF-related port disables. 130 * and EMF-related port disables.
122 */ 131 */
123 udev->persist_enabled = 1; 132 if (!(udev->quirks & USB_QUIRK_RESET_MORPHS))
133 udev->persist_enabled = 1;
124#endif /* CONFIG_PM */ 134#endif /* CONFIG_PM */
125} 135}
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 7ec3041ae79e..43c002e3a9aa 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -82,9 +82,13 @@ static ssize_t show_##name(struct device *dev, \
82 struct device_attribute *attr, char *buf) \ 82 struct device_attribute *attr, char *buf) \
83{ \ 83{ \
84 struct usb_device *udev; \ 84 struct usb_device *udev; \
85 int retval; \
85 \ 86 \
86 udev = to_usb_device(dev); \ 87 udev = to_usb_device(dev); \
87 return sprintf(buf, "%s\n", udev->name); \ 88 usb_lock_device(udev); \
89 retval = sprintf(buf, "%s\n", udev->name); \
90 usb_unlock_device(udev); \
91 return retval; \
88} \ 92} \
89static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 93static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
90 94
@@ -111,6 +115,12 @@ show_speed(struct device *dev, struct device_attribute *attr, char *buf)
111 case USB_SPEED_HIGH: 115 case USB_SPEED_HIGH:
112 speed = "480"; 116 speed = "480";
113 break; 117 break;
118 case USB_SPEED_WIRELESS:
119 speed = "480";
120 break;
121 case USB_SPEED_SUPER:
122 speed = "5000";
123 break;
114 default: 124 default:
115 speed = "unknown"; 125 speed = "unknown";
116 } 126 }
@@ -139,6 +149,16 @@ show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
139static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL); 149static DEVICE_ATTR(devnum, S_IRUGO, show_devnum, NULL);
140 150
141static ssize_t 151static ssize_t
152show_devpath(struct device *dev, struct device_attribute *attr, char *buf)
153{
154 struct usb_device *udev;
155
156 udev = to_usb_device(dev);
157 return sprintf(buf, "%s\n", udev->devpath);
158}
159static DEVICE_ATTR(devpath, S_IRUGO, show_devpath, NULL);
160
161static ssize_t
142show_version(struct device *dev, struct device_attribute *attr, char *buf) 162show_version(struct device *dev, struct device_attribute *attr, char *buf)
143{ 163{
144 struct usb_device *udev; 164 struct usb_device *udev;
@@ -171,6 +191,36 @@ show_quirks(struct device *dev, struct device_attribute *attr, char *buf)
171static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL); 191static DEVICE_ATTR(quirks, S_IRUGO, show_quirks, NULL);
172 192
173static ssize_t 193static ssize_t
194show_avoid_reset_quirk(struct device *dev, struct device_attribute *attr, char *buf)
195{
196 struct usb_device *udev;
197
198 udev = to_usb_device(dev);
199 return sprintf(buf, "%d\n", !!(udev->quirks & USB_QUIRK_RESET_MORPHS));
200}
201
202static ssize_t
203set_avoid_reset_quirk(struct device *dev, struct device_attribute *attr,
204 const char *buf, size_t count)
205{
206 struct usb_device *udev = to_usb_device(dev);
207 int config;
208
209 if (sscanf(buf, "%d", &config) != 1 || config < 0 || config > 1)
210 return -EINVAL;
211 usb_lock_device(udev);
212 if (config)
213 udev->quirks |= USB_QUIRK_RESET_MORPHS;
214 else
215 udev->quirks &= ~USB_QUIRK_RESET_MORPHS;
216 usb_unlock_device(udev);
217 return count;
218}
219
220static DEVICE_ATTR(avoid_reset_quirk, S_IRUGO | S_IWUSR,
221 show_avoid_reset_quirk, set_avoid_reset_quirk);
222
223static ssize_t
174show_urbnum(struct device *dev, struct device_attribute *attr, char *buf) 224show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
175{ 225{
176 struct usb_device *udev; 226 struct usb_device *udev;
@@ -206,9 +256,10 @@ set_persist(struct device *dev, struct device_attribute *attr,
206 256
207 if (sscanf(buf, "%d", &value) != 1) 257 if (sscanf(buf, "%d", &value) != 1)
208 return -EINVAL; 258 return -EINVAL;
209 usb_pm_lock(udev); 259
260 usb_lock_device(udev);
210 udev->persist_enabled = !!value; 261 udev->persist_enabled = !!value;
211 usb_pm_unlock(udev); 262 usb_unlock_device(udev);
212 return count; 263 return count;
213} 264}
214 265
@@ -295,20 +346,34 @@ set_autosuspend(struct device *dev, struct device_attribute *attr,
295 const char *buf, size_t count) 346 const char *buf, size_t count)
296{ 347{
297 struct usb_device *udev = to_usb_device(dev); 348 struct usb_device *udev = to_usb_device(dev);
298 int value; 349 int value, old_delay;
350 int rc;
299 351
300 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ || 352 if (sscanf(buf, "%d", &value) != 1 || value >= INT_MAX/HZ ||
301 value <= - INT_MAX/HZ) 353 value <= - INT_MAX/HZ)
302 return -EINVAL; 354 return -EINVAL;
303 value *= HZ; 355 value *= HZ;
304 356
357 usb_lock_device(udev);
358 old_delay = udev->autosuspend_delay;
305 udev->autosuspend_delay = value; 359 udev->autosuspend_delay = value;
306 if (value >= 0) 360
307 usb_try_autosuspend_device(udev); 361 if (old_delay < 0) { /* Autosuspend wasn't allowed */
308 else { 362 if (value >= 0)
309 if (usb_autoresume_device(udev) == 0)
310 usb_autosuspend_device(udev); 363 usb_autosuspend_device(udev);
364 } else { /* Autosuspend was allowed */
365 if (value < 0) {
366 rc = usb_autoresume_device(udev);
367 if (rc < 0) {
368 count = rc;
369 udev->autosuspend_delay = old_delay;
370 }
371 } else {
372 usb_try_autosuspend_device(udev);
373 }
311 } 374 }
375
376 usb_unlock_device(udev);
312 return count; 377 return count;
313} 378}
314 379
@@ -317,7 +382,6 @@ static DEVICE_ATTR(autosuspend, S_IRUGO | S_IWUSR,
317 382
318static const char on_string[] = "on"; 383static const char on_string[] = "on";
319static const char auto_string[] = "auto"; 384static const char auto_string[] = "auto";
320static const char suspend_string[] = "suspend";
321 385
322static ssize_t 386static ssize_t
323show_level(struct device *dev, struct device_attribute *attr, char *buf) 387show_level(struct device *dev, struct device_attribute *attr, char *buf)
@@ -325,13 +389,8 @@ show_level(struct device *dev, struct device_attribute *attr, char *buf)
325 struct usb_device *udev = to_usb_device(dev); 389 struct usb_device *udev = to_usb_device(dev);
326 const char *p = auto_string; 390 const char *p = auto_string;
327 391
328 if (udev->state == USB_STATE_SUSPENDED) { 392 if (udev->state != USB_STATE_SUSPENDED && udev->autosuspend_disabled)
329 if (udev->autoresume_disabled) 393 p = on_string;
330 p = suspend_string;
331 } else {
332 if (udev->autosuspend_disabled)
333 p = on_string;
334 }
335 return sprintf(buf, "%s\n", p); 394 return sprintf(buf, "%s\n", p);
336} 395}
337 396
@@ -342,45 +401,25 @@ set_level(struct device *dev, struct device_attribute *attr,
342 struct usb_device *udev = to_usb_device(dev); 401 struct usb_device *udev = to_usb_device(dev);
343 int len = count; 402 int len = count;
344 char *cp; 403 char *cp;
345 int rc = 0; 404 int rc;
346 int old_autosuspend_disabled, old_autoresume_disabled;
347 405
348 cp = memchr(buf, '\n', count); 406 cp = memchr(buf, '\n', count);
349 if (cp) 407 if (cp)
350 len = cp - buf; 408 len = cp - buf;
351 409
352 usb_lock_device(udev); 410 usb_lock_device(udev);
353 old_autosuspend_disabled = udev->autosuspend_disabled;
354 old_autoresume_disabled = udev->autoresume_disabled;
355 411
356 /* Setting the flags without calling usb_pm_lock is a subject to
357 * races, but who cares...
358 */
359 if (len == sizeof on_string - 1 && 412 if (len == sizeof on_string - 1 &&
360 strncmp(buf, on_string, len) == 0) { 413 strncmp(buf, on_string, len) == 0)
361 udev->autosuspend_disabled = 1; 414 rc = usb_disable_autosuspend(udev);
362 udev->autoresume_disabled = 0; 415
363 rc = usb_external_resume_device(udev, PMSG_USER_RESUME); 416 else if (len == sizeof auto_string - 1 &&
364 417 strncmp(buf, auto_string, len) == 0)
365 } else if (len == sizeof auto_string - 1 && 418 rc = usb_enable_autosuspend(udev);
366 strncmp(buf, auto_string, len) == 0) { 419
367 udev->autosuspend_disabled = 0; 420 else
368 udev->autoresume_disabled = 0;
369 rc = usb_external_resume_device(udev, PMSG_USER_RESUME);
370
371 } else if (len == sizeof suspend_string - 1 &&
372 strncmp(buf, suspend_string, len) == 0) {
373 udev->autosuspend_disabled = 0;
374 udev->autoresume_disabled = 1;
375 rc = usb_external_suspend_device(udev, PMSG_USER_SUSPEND);
376
377 } else
378 rc = -EINVAL; 421 rc = -EINVAL;
379 422
380 if (rc) {
381 udev->autosuspend_disabled = old_autosuspend_disabled;
382 udev->autoresume_disabled = old_autoresume_disabled;
383 }
384 usb_unlock_device(udev); 423 usb_unlock_device(udev);
385 return (rc < 0 ? rc : count); 424 return (rc < 0 ? rc : count);
386} 425}
@@ -508,6 +547,28 @@ static ssize_t usb_dev_authorized_store(struct device *dev,
508static DEVICE_ATTR(authorized, 0644, 547static DEVICE_ATTR(authorized, 0644,
509 usb_dev_authorized_show, usb_dev_authorized_store); 548 usb_dev_authorized_show, usb_dev_authorized_store);
510 549
550/* "Safely remove a device" */
551static ssize_t usb_remove_store(struct device *dev,
552 struct device_attribute *attr,
553 const char *buf, size_t count)
554{
555 struct usb_device *udev = to_usb_device(dev);
556 int rc = 0;
557
558 usb_lock_device(udev);
559 if (udev->state != USB_STATE_NOTATTACHED) {
560
561 /* To avoid races, first unconfigure and then remove */
562 usb_set_configuration(udev, -1);
563 rc = usb_remove_device(udev);
564 }
565 if (rc == 0)
566 rc = count;
567 usb_unlock_device(udev);
568 return rc;
569}
570static DEVICE_ATTR(remove, 0200, NULL, usb_remove_store);
571
511 572
512static struct attribute *dev_attrs[] = { 573static struct attribute *dev_attrs[] = {
513 /* current configuration's attributes */ 574 /* current configuration's attributes */
@@ -516,8 +577,8 @@ static struct attribute *dev_attrs[] = {
516 &dev_attr_bConfigurationValue.attr, 577 &dev_attr_bConfigurationValue.attr,
517 &dev_attr_bmAttributes.attr, 578 &dev_attr_bmAttributes.attr,
518 &dev_attr_bMaxPower.attr, 579 &dev_attr_bMaxPower.attr,
519 &dev_attr_urbnum.attr,
520 /* device attributes */ 580 /* device attributes */
581 &dev_attr_urbnum.attr,
521 &dev_attr_idVendor.attr, 582 &dev_attr_idVendor.attr,
522 &dev_attr_idProduct.attr, 583 &dev_attr_idProduct.attr,
523 &dev_attr_bcdDevice.attr, 584 &dev_attr_bcdDevice.attr,
@@ -529,10 +590,13 @@ static struct attribute *dev_attrs[] = {
529 &dev_attr_speed.attr, 590 &dev_attr_speed.attr,
530 &dev_attr_busnum.attr, 591 &dev_attr_busnum.attr,
531 &dev_attr_devnum.attr, 592 &dev_attr_devnum.attr,
593 &dev_attr_devpath.attr,
532 &dev_attr_version.attr, 594 &dev_attr_version.attr,
533 &dev_attr_maxchild.attr, 595 &dev_attr_maxchild.attr,
534 &dev_attr_quirks.attr, 596 &dev_attr_quirks.attr,
597 &dev_attr_avoid_reset_quirk.attr,
535 &dev_attr_authorized.attr, 598 &dev_attr_authorized.attr,
599 &dev_attr_remove.attr,
536 NULL, 600 NULL,
537}; 601};
538static struct attribute_group dev_attr_grp = { 602static struct attribute_group dev_attr_grp = {
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 0885d4abdc62..45a32dadb406 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -387,6 +387,13 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
387 { 387 {
388 unsigned int orig_flags = urb->transfer_flags; 388 unsigned int orig_flags = urb->transfer_flags;
389 unsigned int allowed; 389 unsigned int allowed;
390 static int pipetypes[4] = {
391 PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
392 };
393
394 /* Check that the pipe's type matches the endpoint's type */
395 if (usb_pipetype(urb->pipe) != pipetypes[xfertype])
396 return -EPIPE; /* The most suitable error code :-) */
390 397
391 /* enforce simple/standard policy */ 398 /* enforce simple/standard policy */
392 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP | 399 allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP |
@@ -429,8 +436,16 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
429 case USB_ENDPOINT_XFER_ISOC: 436 case USB_ENDPOINT_XFER_ISOC:
430 case USB_ENDPOINT_XFER_INT: 437 case USB_ENDPOINT_XFER_INT:
431 /* too small? */ 438 /* too small? */
432 if (urb->interval <= 0) 439 switch (dev->speed) {
433 return -EINVAL; 440 case USB_SPEED_WIRELESS:
441 if (urb->interval < 6)
442 return -EINVAL;
443 break;
444 default:
445 if (urb->interval <= 0)
446 return -EINVAL;
447 break;
448 }
434 /* too big? */ 449 /* too big? */
435 switch (dev->speed) { 450 switch (dev->speed) {
436 case USB_SPEED_SUPER: /* units are 125us */ 451 case USB_SPEED_SUPER: /* units are 125us */
@@ -438,6 +453,11 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
438 if (urb->interval > (1 << 15)) 453 if (urb->interval > (1 << 15))
439 return -EINVAL; 454 return -EINVAL;
440 max = 1 << 15; 455 max = 1 << 15;
456 break;
457 case USB_SPEED_WIRELESS:
458 if (urb->interval > 16)
459 return -EINVAL;
460 break;
441 case USB_SPEED_HIGH: /* units are microframes */ 461 case USB_SPEED_HIGH: /* units are microframes */
442 /* NOTE usb handles 2^15 */ 462 /* NOTE usb handles 2^15 */
443 if (urb->interval > (1024 * 8)) 463 if (urb->interval > (1024 * 8))
@@ -461,8 +481,10 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
461 default: 481 default:
462 return -EINVAL; 482 return -EINVAL;
463 } 483 }
464 /* Round down to a power of 2, no more than max */ 484 if (dev->speed != USB_SPEED_WIRELESS) {
465 urb->interval = min(max, 1 << ilog2(urb->interval)); 485 /* Round down to a power of 2, no more than max */
486 urb->interval = min(max, 1 << ilog2(urb->interval));
487 }
466 } 488 }
467 489
468 return usb_hcd_submit_urb(urb, mem_flags); 490 return usb_hcd_submit_urb(urb, mem_flags);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index b1b85abb9a2d..0561430f2ede 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -49,9 +49,6 @@ const char *usbcore_name = "usbcore";
49 49
50static int nousb; /* Disable USB when built into kernel image */ 50static int nousb; /* Disable USB when built into kernel image */
51 51
52/* Workqueue for autosuspend and for remote wakeup of root hubs */
53struct workqueue_struct *ksuspend_usb_wq;
54
55#ifdef CONFIG_USB_SUSPEND 52#ifdef CONFIG_USB_SUSPEND
56static int usb_autosuspend_delay = 2; /* Default delay value, 53static int usb_autosuspend_delay = 2; /* Default delay value,
57 * in seconds */ 54 * in seconds */
@@ -64,6 +61,43 @@ MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
64 61
65 62
66/** 63/**
64 * usb_find_alt_setting() - Given a configuration, find the alternate setting
65 * for the given interface.
66 * @config: the configuration to search (not necessarily the current config).
67 * @iface_num: interface number to search in
68 * @alt_num: alternate interface setting number to search for.
69 *
70 * Search the configuration's interface cache for the given alt setting.
71 */
72struct usb_host_interface *usb_find_alt_setting(
73 struct usb_host_config *config,
74 unsigned int iface_num,
75 unsigned int alt_num)
76{
77 struct usb_interface_cache *intf_cache = NULL;
78 int i;
79
80 for (i = 0; i < config->desc.bNumInterfaces; i++) {
81 if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber
82 == iface_num) {
83 intf_cache = config->intf_cache[i];
84 break;
85 }
86 }
87 if (!intf_cache)
88 return NULL;
89 for (i = 0; i < intf_cache->num_altsetting; i++)
90 if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num)
91 return &intf_cache->altsetting[i];
92
93 printk(KERN_DEBUG "Did not find alt setting %u for intf %u, "
94 "config %u\n", alt_num, iface_num,
95 config->desc.bConfigurationValue);
96 return NULL;
97}
98EXPORT_SYMBOL_GPL(usb_find_alt_setting);
99
100/**
67 * usb_ifnum_to_if - get the interface object with a given interface number 101 * usb_ifnum_to_if - get the interface object with a given interface number
68 * @dev: the device whose current configuration is considered 102 * @dev: the device whose current configuration is considered
69 * @ifnum: the desired interface 103 * @ifnum: the desired interface
@@ -132,7 +166,7 @@ EXPORT_SYMBOL_GPL(usb_altnum_to_altsetting);
132 166
133struct find_interface_arg { 167struct find_interface_arg {
134 int minor; 168 int minor;
135 struct usb_interface *interface; 169 struct device_driver *drv;
136}; 170};
137 171
138static int __find_interface(struct device *dev, void *data) 172static int __find_interface(struct device *dev, void *data)
@@ -143,12 +177,10 @@ static int __find_interface(struct device *dev, void *data)
143 if (!is_usb_interface(dev)) 177 if (!is_usb_interface(dev))
144 return 0; 178 return 0;
145 179
180 if (dev->driver != arg->drv)
181 return 0;
146 intf = to_usb_interface(dev); 182 intf = to_usb_interface(dev);
147 if (intf->minor != -1 && intf->minor == arg->minor) { 183 return intf->minor == arg->minor;
148 arg->interface = intf;
149 return 1;
150 }
151 return 0;
152} 184}
153 185
154/** 186/**
@@ -156,21 +188,24 @@ static int __find_interface(struct device *dev, void *data)
156 * @drv: the driver whose current configuration is considered 188 * @drv: the driver whose current configuration is considered
157 * @minor: the minor number of the desired device 189 * @minor: the minor number of the desired device
158 * 190 *
159 * This walks the driver device list and returns a pointer to the interface 191 * This walks the bus device list and returns a pointer to the interface
160 * with the matching minor. Note, this only works for devices that share the 192 * with the matching minor and driver. Note, this only works for devices
161 * USB major number. 193 * that share the USB major number.
162 */ 194 */
163struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor) 195struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor)
164{ 196{
165 struct find_interface_arg argb; 197 struct find_interface_arg argb;
166 int retval; 198 struct device *dev;
167 199
168 argb.minor = minor; 200 argb.minor = minor;
169 argb.interface = NULL; 201 argb.drv = &drv->drvwrap.driver;
170 /* eat the error, it will be in argb.interface */ 202
171 retval = driver_for_each_device(&drv->drvwrap.driver, NULL, &argb, 203 dev = bus_find_device(&usb_bus_type, NULL, &argb, __find_interface);
172 __find_interface); 204
173 return argb.interface; 205 /* Drop reference count from bus_find_device */
206 put_device(dev);
207
208 return dev ? to_usb_interface(dev) : NULL;
174} 209}
175EXPORT_SYMBOL_GPL(usb_find_interface); 210EXPORT_SYMBOL_GPL(usb_find_interface);
176 211
@@ -190,9 +225,6 @@ static void usb_release_dev(struct device *dev)
190 hcd = bus_to_hcd(udev->bus); 225 hcd = bus_to_hcd(udev->bus);
191 226
192 usb_destroy_configuration(udev); 227 usb_destroy_configuration(udev);
193 /* Root hubs aren't real devices, so don't free HCD resources */
194 if (hcd->driver->free_dev && udev->parent)
195 hcd->driver->free_dev(hcd, udev);
196 usb_put_hcd(hcd); 228 usb_put_hcd(hcd);
197 kfree(udev->product); 229 kfree(udev->product);
198 kfree(udev->manufacturer); 230 kfree(udev->manufacturer);
@@ -226,23 +258,6 @@ static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
226 258
227#ifdef CONFIG_PM 259#ifdef CONFIG_PM
228 260
229static int ksuspend_usb_init(void)
230{
231 /* This workqueue is supposed to be both freezable and
232 * singlethreaded. Its job doesn't justify running on more
233 * than one CPU.
234 */
235 ksuspend_usb_wq = create_freezeable_workqueue("ksuspend_usbd");
236 if (!ksuspend_usb_wq)
237 return -ENOMEM;
238 return 0;
239}
240
241static void ksuspend_usb_cleanup(void)
242{
243 destroy_workqueue(ksuspend_usb_wq);
244}
245
246/* USB device Power-Management thunks. 261/* USB device Power-Management thunks.
247 * There's no need to distinguish here between quiescing a USB device 262 * There's no need to distinguish here between quiescing a USB device
248 * and powering it down; the generic_suspend() routine takes care of 263 * and powering it down; the generic_suspend() routine takes care of
@@ -258,7 +273,7 @@ static int usb_dev_prepare(struct device *dev)
258static void usb_dev_complete(struct device *dev) 273static void usb_dev_complete(struct device *dev)
259{ 274{
260 /* Currently used only for rebinding interfaces */ 275 /* Currently used only for rebinding interfaces */
261 usb_resume(dev, PMSG_RESUME); /* Message event is meaningless */ 276 usb_resume(dev, PMSG_ON); /* FIXME: change to PMSG_COMPLETE */
262} 277}
263 278
264static int usb_dev_suspend(struct device *dev) 279static int usb_dev_suspend(struct device *dev)
@@ -291,7 +306,7 @@ static int usb_dev_restore(struct device *dev)
291 return usb_resume(dev, PMSG_RESTORE); 306 return usb_resume(dev, PMSG_RESTORE);
292} 307}
293 308
294static struct dev_pm_ops usb_device_pm_ops = { 309static const struct dev_pm_ops usb_device_pm_ops = {
295 .prepare = usb_dev_prepare, 310 .prepare = usb_dev_prepare,
296 .complete = usb_dev_complete, 311 .complete = usb_dev_complete,
297 .suspend = usb_dev_suspend, 312 .suspend = usb_dev_suspend,
@@ -304,9 +319,7 @@ static struct dev_pm_ops usb_device_pm_ops = {
304 319
305#else 320#else
306 321
307#define ksuspend_usb_init() 0 322#define usb_device_pm_ops (*(struct dev_pm_ops *) NULL)
308#define ksuspend_usb_cleanup() do {} while (0)
309#define usb_device_pm_ops (*(struct dev_pm_ops *)0)
310 323
311#endif /* CONFIG_PM */ 324#endif /* CONFIG_PM */
312 325
@@ -434,9 +447,6 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
434 INIT_LIST_HEAD(&dev->filelist); 447 INIT_LIST_HEAD(&dev->filelist);
435 448
436#ifdef CONFIG_PM 449#ifdef CONFIG_PM
437 mutex_init(&dev->pm_mutex);
438 INIT_DELAYED_WORK(&dev->autosuspend, usb_autosuspend_work);
439 INIT_WORK(&dev->autoresume, usb_autoresume_work);
440 dev->autosuspend_delay = usb_autosuspend_delay * HZ; 450 dev->autosuspend_delay = usb_autosuspend_delay * HZ;
441 dev->connect_time = jiffies; 451 dev->connect_time = jiffies;
442 dev->active_duration = -jiffies; 452 dev->active_duration = -jiffies;
@@ -708,7 +718,7 @@ int __usb_get_extra_descriptor(char *buffer, unsigned size,
708EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor); 718EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor);
709 719
710/** 720/**
711 * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP 721 * usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
712 * @dev: device the buffer will be used with 722 * @dev: device the buffer will be used with
713 * @size: requested buffer size 723 * @size: requested buffer size
714 * @mem_flags: affect whether allocation may block 724 * @mem_flags: affect whether allocation may block
@@ -727,30 +737,30 @@ EXPORT_SYMBOL_GPL(__usb_get_extra_descriptor);
727 * architectures where CPU caches are not DMA-coherent. On systems without 737 * architectures where CPU caches are not DMA-coherent. On systems without
728 * bus-snooping caches, these buffers are uncached. 738 * bus-snooping caches, these buffers are uncached.
729 * 739 *
730 * When the buffer is no longer used, free it with usb_buffer_free(). 740 * When the buffer is no longer used, free it with usb_free_coherent().
731 */ 741 */
732void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags, 742void *usb_alloc_coherent(struct usb_device *dev, size_t size, gfp_t mem_flags,
733 dma_addr_t *dma) 743 dma_addr_t *dma)
734{ 744{
735 if (!dev || !dev->bus) 745 if (!dev || !dev->bus)
736 return NULL; 746 return NULL;
737 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); 747 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma);
738} 748}
739EXPORT_SYMBOL_GPL(usb_buffer_alloc); 749EXPORT_SYMBOL_GPL(usb_alloc_coherent);
740 750
741/** 751/**
742 * usb_buffer_free - free memory allocated with usb_buffer_alloc() 752 * usb_free_coherent - free memory allocated with usb_alloc_coherent()
743 * @dev: device the buffer was used with 753 * @dev: device the buffer was used with
744 * @size: requested buffer size 754 * @size: requested buffer size
745 * @addr: CPU address of buffer 755 * @addr: CPU address of buffer
746 * @dma: DMA address of buffer 756 * @dma: DMA address of buffer
747 * 757 *
748 * This reclaims an I/O buffer, letting it be reused. The memory must have 758 * This reclaims an I/O buffer, letting it be reused. The memory must have
749 * been allocated using usb_buffer_alloc(), and the parameters must match 759 * been allocated using usb_alloc_coherent(), and the parameters must match
750 * those provided in that allocation request. 760 * those provided in that allocation request.
751 */ 761 */
752void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, 762void usb_free_coherent(struct usb_device *dev, size_t size, void *addr,
753 dma_addr_t dma) 763 dma_addr_t dma)
754{ 764{
755 if (!dev || !dev->bus) 765 if (!dev || !dev->bus)
756 return; 766 return;
@@ -758,7 +768,7 @@ void usb_buffer_free(struct usb_device *dev, size_t size, void *addr,
758 return; 768 return;
759 hcd_buffer_free(dev->bus, size, addr, dma); 769 hcd_buffer_free(dev->bus, size, addr, dma);
760} 770}
761EXPORT_SYMBOL_GPL(usb_buffer_free); 771EXPORT_SYMBOL_GPL(usb_free_coherent);
762 772
763/** 773/**
764 * usb_buffer_map - create DMA mapping(s) for an urb 774 * usb_buffer_map - create DMA mapping(s) for an urb
@@ -1038,7 +1048,7 @@ static struct notifier_block usb_bus_nb = {
1038struct dentry *usb_debug_root; 1048struct dentry *usb_debug_root;
1039EXPORT_SYMBOL_GPL(usb_debug_root); 1049EXPORT_SYMBOL_GPL(usb_debug_root);
1040 1050
1041struct dentry *usb_debug_devices; 1051static struct dentry *usb_debug_devices;
1042 1052
1043static int usb_debugfs_init(void) 1053static int usb_debugfs_init(void)
1044{ 1054{
@@ -1079,9 +1089,6 @@ static int __init usb_init(void)
1079 if (retval) 1089 if (retval)
1080 goto out; 1090 goto out;
1081 1091
1082 retval = ksuspend_usb_init();
1083 if (retval)
1084 goto out;
1085 retval = bus_register(&usb_bus_type); 1092 retval = bus_register(&usb_bus_type);
1086 if (retval) 1093 if (retval)
1087 goto bus_register_failed; 1094 goto bus_register_failed;
@@ -1121,7 +1128,7 @@ major_init_failed:
1121bus_notifier_failed: 1128bus_notifier_failed:
1122 bus_unregister(&usb_bus_type); 1129 bus_unregister(&usb_bus_type);
1123bus_register_failed: 1130bus_register_failed:
1124 ksuspend_usb_cleanup(); 1131 usb_debugfs_cleanup();
1125out: 1132out:
1126 return retval; 1133 return retval;
1127} 1134}
@@ -1143,7 +1150,6 @@ static void __exit usb_exit(void)
1143 usb_hub_cleanup(); 1150 usb_hub_cleanup();
1144 bus_unregister_notifier(&usb_bus_type, &usb_bus_nb); 1151 bus_unregister_notifier(&usb_bus_type, &usb_bus_nb);
1145 bus_unregister(&usb_bus_type); 1152 bus_unregister(&usb_bus_type);
1146 ksuspend_usb_cleanup();
1147 usb_debugfs_cleanup(); 1153 usb_debugfs_cleanup();
1148} 1154}
1149 1155
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 9a8b15e6377a..cd882203ad34 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -24,6 +24,7 @@ extern void usb_disable_device(struct usb_device *dev, int skip_ep0);
24extern int usb_deauthorize_device(struct usb_device *); 24extern int usb_deauthorize_device(struct usb_device *);
25extern int usb_authorize_device(struct usb_device *); 25extern int usb_authorize_device(struct usb_device *);
26extern void usb_detect_quirks(struct usb_device *udev); 26extern void usb_detect_quirks(struct usb_device *udev);
27extern int usb_remove_device(struct usb_device *udev);
27 28
28extern int usb_get_device_descriptor(struct usb_device *dev, 29extern int usb_get_device_descriptor(struct usb_device *dev,
29 unsigned int size); 30 unsigned int size);
@@ -54,24 +55,8 @@ extern void usb_major_cleanup(void);
54extern int usb_suspend(struct device *dev, pm_message_t msg); 55extern int usb_suspend(struct device *dev, pm_message_t msg);
55extern int usb_resume(struct device *dev, pm_message_t msg); 56extern int usb_resume(struct device *dev, pm_message_t msg);
56 57
57extern void usb_autosuspend_work(struct work_struct *work);
58extern void usb_autoresume_work(struct work_struct *work);
59extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg); 58extern int usb_port_suspend(struct usb_device *dev, pm_message_t msg);
60extern int usb_port_resume(struct usb_device *dev, pm_message_t msg); 59extern int usb_port_resume(struct usb_device *dev, pm_message_t msg);
61extern int usb_external_suspend_device(struct usb_device *udev,
62 pm_message_t msg);
63extern int usb_external_resume_device(struct usb_device *udev,
64 pm_message_t msg);
65
66static inline void usb_pm_lock(struct usb_device *udev)
67{
68 mutex_lock_nested(&udev->pm_mutex, udev->level);
69}
70
71static inline void usb_pm_unlock(struct usb_device *udev)
72{
73 mutex_unlock(&udev->pm_mutex);
74}
75 60
76#else 61#else
77 62
@@ -85,9 +70,6 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
85 return 0; 70 return 0;
86} 71}
87 72
88static inline void usb_pm_lock(struct usb_device *udev) {}
89static inline void usb_pm_unlock(struct usb_device *udev) {}
90
91#endif 73#endif
92 74
93#ifdef CONFIG_USB_SUSPEND 75#ifdef CONFIG_USB_SUSPEND
@@ -95,6 +77,7 @@ static inline void usb_pm_unlock(struct usb_device *udev) {}
95extern void usb_autosuspend_device(struct usb_device *udev); 77extern void usb_autosuspend_device(struct usb_device *udev);
96extern void usb_try_autosuspend_device(struct usb_device *udev); 78extern void usb_try_autosuspend_device(struct usb_device *udev);
97extern int usb_autoresume_device(struct usb_device *udev); 79extern int usb_autoresume_device(struct usb_device *udev);
80extern int usb_remote_wakeup(struct usb_device *dev);
98 81
99#else 82#else
100 83
@@ -105,9 +88,13 @@ static inline int usb_autoresume_device(struct usb_device *udev)
105 return 0; 88 return 0;
106} 89}
107 90
91static inline int usb_remote_wakeup(struct usb_device *udev)
92{
93 return 0;
94}
95
108#endif 96#endif
109 97
110extern struct workqueue_struct *ksuspend_usb_wq;
111extern struct bus_type usb_bus_type; 98extern struct bus_type usb_bus_type;
112extern struct device_type usb_device_type; 99extern struct device_type usb_device_type;
113extern struct device_type usb_if_device_type; 100extern struct device_type usb_if_device_type;
@@ -137,23 +124,6 @@ static inline int is_usb_device_driver(struct device_driver *drv)
137 for_devices; 124 for_devices;
138} 125}
139 126
140/* Interfaces and their "power state" are owned by usbcore */
141
142static inline void mark_active(struct usb_interface *f)
143{
144 f->is_active = 1;
145}
146
147static inline void mark_quiesced(struct usb_interface *f)
148{
149 f->is_active = 0;
150}
151
152static inline int is_active(const struct usb_interface *f)
153{
154 return f->is_active;
155}
156
157 127
158/* for labeling diagnostics */ 128/* for labeling diagnostics */
159extern const char *usbcore_name; 129extern const char *usbcore_name;
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
index 1206a26ef893..6e98a3697844 100644
--- a/drivers/usb/early/ehci-dbgp.c
+++ b/drivers/usb/early/ehci-dbgp.c
@@ -66,8 +66,6 @@ static struct ehci_dev ehci_dev;
66 66
67#define USB_DEBUG_DEVNUM 127 67#define USB_DEBUG_DEVNUM 127
68 68
69#define DBGP_DATA_TOGGLE 0x8800
70
71#ifdef DBGP_DEBUG 69#ifdef DBGP_DEBUG
72#define dbgp_printk printk 70#define dbgp_printk printk
73static void dbgp_ehci_status(char *str) 71static void dbgp_ehci_status(char *str)
@@ -88,11 +86,6 @@ static inline void dbgp_ehci_status(char *str) { }
88static inline void dbgp_printk(const char *fmt, ...) { } 86static inline void dbgp_printk(const char *fmt, ...) { }
89#endif 87#endif
90 88
91static inline u32 dbgp_pid_update(u32 x, u32 tok)
92{
93 return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff);
94}
95
96static inline u32 dbgp_len_update(u32 x, u32 len) 89static inline u32 dbgp_len_update(u32 x, u32 len)
97{ 90{
98 return (x & ~0x0f) | (len & 0x0f); 91 return (x & ~0x0f) | (len & 0x0f);
@@ -136,6 +129,19 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
136 129
137#define DBGP_MAX_PACKET 8 130#define DBGP_MAX_PACKET 8
138#define DBGP_TIMEOUT (250 * 1000) 131#define DBGP_TIMEOUT (250 * 1000)
132#define DBGP_LOOPS 1000
133
134static inline u32 dbgp_pid_write_update(u32 x, u32 tok)
135{
136 static int data0 = USB_PID_DATA1;
137 data0 ^= USB_PID_DATA_TOGGLE;
138 return (x & 0xffff0000) | (data0 << 8) | (tok & 0xff);
139}
140
141static inline u32 dbgp_pid_read_update(u32 x, u32 tok)
142{
143 return (x & 0xffff0000) | (USB_PID_DATA0 << 8) | (tok & 0xff);
144}
139 145
140static int dbgp_wait_until_complete(void) 146static int dbgp_wait_until_complete(void)
141{ 147{
@@ -180,7 +186,7 @@ static int dbgp_wait_until_done(unsigned ctrl)
180{ 186{
181 u32 pids, lpid; 187 u32 pids, lpid;
182 int ret; 188 int ret;
183 int loop = 3; 189 int loop = DBGP_LOOPS;
184 190
185retry: 191retry:
186 writel(ctrl | DBGP_GO, &ehci_debug->control); 192 writel(ctrl | DBGP_GO, &ehci_debug->control);
@@ -197,6 +203,8 @@ retry:
197 */ 203 */
198 if (ret == -DBGP_TIMEOUT && !dbgp_not_safe) 204 if (ret == -DBGP_TIMEOUT && !dbgp_not_safe)
199 dbgp_not_safe = 1; 205 dbgp_not_safe = 1;
206 if (ret == -DBGP_ERR_BAD && --loop > 0)
207 goto retry;
200 return ret; 208 return ret;
201 } 209 }
202 210
@@ -245,12 +253,20 @@ static inline void dbgp_get_data(void *buf, int size)
245 bytes[i] = (hi >> (8*(i - 4))) & 0xff; 253 bytes[i] = (hi >> (8*(i - 4))) & 0xff;
246} 254}
247 255
248static int dbgp_out(u32 addr, const char *bytes, int size) 256static int dbgp_bulk_write(unsigned devnum, unsigned endpoint,
257 const char *bytes, int size)
249{ 258{
259 int ret;
260 u32 addr;
250 u32 pids, ctrl; 261 u32 pids, ctrl;
251 262
263 if (size > DBGP_MAX_PACKET)
264 return -1;
265
266 addr = DBGP_EPADDR(devnum, endpoint);
267
252 pids = readl(&ehci_debug->pids); 268 pids = readl(&ehci_debug->pids);
253 pids = dbgp_pid_update(pids, USB_PID_OUT); 269 pids = dbgp_pid_write_update(pids, USB_PID_OUT);
254 270
255 ctrl = readl(&ehci_debug->control); 271 ctrl = readl(&ehci_debug->control);
256 ctrl = dbgp_len_update(ctrl, size); 272 ctrl = dbgp_len_update(ctrl, size);
@@ -260,34 +276,7 @@ static int dbgp_out(u32 addr, const char *bytes, int size)
260 dbgp_set_data(bytes, size); 276 dbgp_set_data(bytes, size);
261 writel(addr, &ehci_debug->address); 277 writel(addr, &ehci_debug->address);
262 writel(pids, &ehci_debug->pids); 278 writel(pids, &ehci_debug->pids);
263 return dbgp_wait_until_done(ctrl); 279 ret = dbgp_wait_until_done(ctrl);
264}
265
266static int dbgp_bulk_write(unsigned devnum, unsigned endpoint,
267 const char *bytes, int size)
268{
269 int ret;
270 int loops = 5;
271 u32 addr;
272 if (size > DBGP_MAX_PACKET)
273 return -1;
274
275 addr = DBGP_EPADDR(devnum, endpoint);
276try_again:
277 if (loops--) {
278 ret = dbgp_out(addr, bytes, size);
279 if (ret == -DBGP_ERR_BAD) {
280 int try_loops = 3;
281 do {
282 /* Emit a dummy packet to re-sync communication
283 * with the debug device */
284 if (dbgp_out(addr, "12345678", 8) >= 0) {
285 udelay(2);
286 goto try_again;
287 }
288 } while (try_loops--);
289 }
290 }
291 280
292 return ret; 281 return ret;
293} 282}
@@ -304,7 +293,7 @@ static int dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data,
304 addr = DBGP_EPADDR(devnum, endpoint); 293 addr = DBGP_EPADDR(devnum, endpoint);
305 294
306 pids = readl(&ehci_debug->pids); 295 pids = readl(&ehci_debug->pids);
307 pids = dbgp_pid_update(pids, USB_PID_IN); 296 pids = dbgp_pid_read_update(pids, USB_PID_IN);
308 297
309 ctrl = readl(&ehci_debug->control); 298 ctrl = readl(&ehci_debug->control);
310 ctrl = dbgp_len_update(ctrl, size); 299 ctrl = dbgp_len_update(ctrl, size);
@@ -362,7 +351,6 @@ static int dbgp_control_msg(unsigned devnum, int requesttype,
362 return dbgp_bulk_read(devnum, 0, data, size); 351 return dbgp_bulk_read(devnum, 0, data, size);
363} 352}
364 353
365
366/* Find a PCI capability */ 354/* Find a PCI capability */
367static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap) 355static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap)
368{ 356{
@@ -613,7 +601,7 @@ err:
613} 601}
614EXPORT_SYMBOL_GPL(dbgp_external_startup); 602EXPORT_SYMBOL_GPL(dbgp_external_startup);
615 603
616static int __init ehci_reset_port(int port) 604static int ehci_reset_port(int port)
617{ 605{
618 u32 portsc; 606 u32 portsc;
619 u32 delay_time, delay; 607 u32 delay_time, delay;
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a18e3c5dd82e..11a3e0fa4331 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -732,6 +732,24 @@ config USB_FILE_STORAGE_TEST
732 behavior of USB Mass Storage hosts. Not needed for 732 behavior of USB Mass Storage hosts. Not needed for
733 normal operation. 733 normal operation.
734 734
735config USB_MASS_STORAGE
736 tristate "Mass Storage Gadget"
737 depends on BLOCK
738 help
739 The Mass Storage Gadget acts as a USB Mass Storage disk drive.
740 As its storage repository it can use a regular file or a block
741 device (in much the same way as the "loop" device driver),
742 specified as a module parameter or sysfs option.
743
744 This is heavily based on File-backed Storage Gadget and in most
745 cases you will want to use FSG instead. This gadget is mostly
746 here to test the functionality of the Mass Storage Function
747 which may be used with composite framework.
748
749 Say "y" to link the driver statically, or "m" to build
750 a dynamically linked module called "g_mass_storage". If unsure,
751 consider File-backed Storage Gadget.
752
735config USB_G_SERIAL 753config USB_G_SERIAL
736 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)" 754 tristate "Serial Gadget (with CDC ACM and CDC OBEX support)"
737 help 755 help
@@ -794,6 +812,58 @@ config USB_CDC_COMPOSITE
794 Say "y" to link the driver statically, or "m" to build a 812 Say "y" to link the driver statically, or "m" to build a
795 dynamically linked module. 813 dynamically linked module.
796 814
815config USB_G_NOKIA
816 tristate "Nokia composite gadget"
817 depends on PHONET
818 help
819 The Nokia composite gadget provides support for acm, obex
820 and phonet in only one composite gadget driver.
821
822 It's only really useful for N900 hardware. If you're building
823 a kernel for N900, say Y or M here. If unsure, say N.
824
825config USB_G_MULTI
826 tristate "Multifunction Composite Gadget (EXPERIMENTAL)"
827 depends on BLOCK && NET
828 help
829 The Multifunction Composite Gadget provides Ethernet (RNDIS
830 and/or CDC Ethernet), mass storage and ACM serial link
831 interfaces.
832
833 You will be asked to choose which of the two configurations is
834 to be available in the gadget. At least one configuration must
835 be chosen to make the gadget usable. Selecting more than one
836 configuration will prevent Windows from automatically detecting
837 the gadget as a composite gadget, so an INF file will be needed to
838 use the gadget.
839
840 Say "y" to link the driver statically, or "m" to build a
841 dynamically linked module called "g_multi".
842
843config USB_G_MULTI_RNDIS
844 bool "RNDIS + CDC Serial + Storage configuration"
845 depends on USB_G_MULTI
846 default y
847 help
848 This option enables a configuration with RNDIS, CDC Serial and
849 Mass Storage functions available in the Multifunction Composite
850 Gadget. This is the configuration dedicated for Windows since RNDIS
851 is Microsoft's protocol.
852
853 If unsure, say "y".
854
855config USB_G_MULTI_CDC
856 bool "CDC Ethernet + CDC Serial + Storage configuration"
857 depends on USB_G_MULTI
858 default n
859 help
860 This option enables a configuration with CDC Ethernet (ECM), CDC
861 Serial and Mass Storage functions available in the Multifunction
862 Composite Gadget.
863
864 If unsure, say "y".
865
866
797# put drivers that need isochronous transfer support (for audio 867# put drivers that need isochronous transfer support (for audio
798# or video class gadget drivers), or specific hardware, here. 868# or video class gadget drivers), or specific hardware, here.
799 869
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 9d7b87c52e9f..43b51da8d727 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -39,16 +39,22 @@ g_serial-objs := serial.o
39g_midi-objs := gmidi.o 39g_midi-objs := gmidi.o
40gadgetfs-objs := inode.o 40gadgetfs-objs := inode.o
41g_file_storage-objs := file_storage.o 41g_file_storage-objs := file_storage.o
42g_mass_storage-objs := mass_storage.o
42g_printer-objs := printer.o 43g_printer-objs := printer.o
43g_cdc-objs := cdc2.o 44g_cdc-objs := cdc2.o
45g_multi-objs := multi.o
46g_nokia-objs := nokia.o
44 47
45obj-$(CONFIG_USB_ZERO) += g_zero.o 48obj-$(CONFIG_USB_ZERO) += g_zero.o
46obj-$(CONFIG_USB_AUDIO) += g_audio.o 49obj-$(CONFIG_USB_AUDIO) += g_audio.o
47obj-$(CONFIG_USB_ETH) += g_ether.o 50obj-$(CONFIG_USB_ETH) += g_ether.o
48obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 51obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
49obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o 52obj-$(CONFIG_USB_FILE_STORAGE) += g_file_storage.o
53obj-$(CONFIG_USB_MASS_STORAGE) += g_mass_storage.o
50obj-$(CONFIG_USB_G_SERIAL) += g_serial.o 54obj-$(CONFIG_USB_G_SERIAL) += g_serial.o
51obj-$(CONFIG_USB_G_PRINTER) += g_printer.o 55obj-$(CONFIG_USB_G_PRINTER) += g_printer.o
52obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o 56obj-$(CONFIG_USB_MIDI_GADGET) += g_midi.o
53obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o 57obj-$(CONFIG_USB_CDC_COMPOSITE) += g_cdc.o
58obj-$(CONFIG_USB_G_MULTI) += g_multi.o
59obj-$(CONFIG_USB_G_NOKIA) += g_nokia.o
54 60
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 66450a1abc22..df1bae9b048e 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -892,7 +892,7 @@ static void pullup(struct at91_udc *udc, int is_on)
892 892
893 txvc |= AT91_UDP_TXVC_PUON; 893 txvc |= AT91_UDP_TXVC_PUON;
894 at91_udp_write(udc, AT91_UDP_TXVC, txvc); 894 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
895 } else if (cpu_is_at91sam9261()) { 895 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
896 u32 usbpucr; 896 u32 usbpucr;
897 897
898 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR); 898 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
@@ -910,7 +910,7 @@ static void pullup(struct at91_udc *udc, int is_on)
910 910
911 txvc &= ~AT91_UDP_TXVC_PUON; 911 txvc &= ~AT91_UDP_TXVC_PUON;
912 at91_udp_write(udc, AT91_UDP_TXVC, txvc); 912 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
913 } else if (cpu_is_at91sam9261()) { 913 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
914 u32 usbpucr; 914 u32 usbpucr;
915 915
916 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR); 916 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
@@ -1370,6 +1370,12 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1370{ 1370{
1371 struct at91_udc *udc = _udc; 1371 struct at91_udc *udc = _udc;
1372 u32 rescans = 5; 1372 u32 rescans = 5;
1373 int disable_clock = 0;
1374
1375 if (!udc->clocked) {
1376 clk_on(udc);
1377 disable_clock = 1;
1378 }
1373 1379
1374 while (rescans--) { 1380 while (rescans--) {
1375 u32 status; 1381 u32 status;
@@ -1458,6 +1464,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1458 } 1464 }
1459 } 1465 }
1460 1466
1467 if (disable_clock)
1468 clk_off(udc);
1469
1461 return IRQ_HANDLED; 1470 return IRQ_HANDLED;
1462} 1471}
1463 1472
@@ -1656,9 +1665,7 @@ static int __init at91udc_probe(struct platform_device *pdev)
1656 if (!res) 1665 if (!res)
1657 return -ENXIO; 1666 return -ENXIO;
1658 1667
1659 if (!request_mem_region(res->start, 1668 if (!request_mem_region(res->start, resource_size(res), driver_name)) {
1660 res->end - res->start + 1,
1661 driver_name)) {
1662 DBG("someone's using UDC memory\n"); 1669 DBG("someone's using UDC memory\n");
1663 return -EBUSY; 1670 return -EBUSY;
1664 } 1671 }
@@ -1692,14 +1699,14 @@ static int __init at91udc_probe(struct platform_device *pdev)
1692 udc->ep[3].maxpacket = 64; 1699 udc->ep[3].maxpacket = 64;
1693 udc->ep[4].maxpacket = 512; 1700 udc->ep[4].maxpacket = 512;
1694 udc->ep[5].maxpacket = 512; 1701 udc->ep[5].maxpacket = 512;
1695 } else if (cpu_is_at91sam9261()) { 1702 } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
1696 udc->ep[3].maxpacket = 64; 1703 udc->ep[3].maxpacket = 64;
1697 } else if (cpu_is_at91sam9263()) { 1704 } else if (cpu_is_at91sam9263()) {
1698 udc->ep[0].maxpacket = 64; 1705 udc->ep[0].maxpacket = 64;
1699 udc->ep[3].maxpacket = 64; 1706 udc->ep[3].maxpacket = 64;
1700 } 1707 }
1701 1708
1702 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1); 1709 udc->udp_baseaddr = ioremap(res->start, resource_size(res));
1703 if (!udc->udp_baseaddr) { 1710 if (!udc->udp_baseaddr) {
1704 retval = -ENOMEM; 1711 retval = -ENOMEM;
1705 goto fail0a; 1712 goto fail0a;
@@ -1781,7 +1788,7 @@ fail0a:
1781 if (cpu_is_at91rm9200()) 1788 if (cpu_is_at91rm9200())
1782 gpio_free(udc->board.pullup_pin); 1789 gpio_free(udc->board.pullup_pin);
1783fail0: 1790fail0:
1784 release_mem_region(res->start, res->end - res->start + 1); 1791 release_mem_region(res->start, resource_size(res));
1785 DBG("%s probe failed, %d\n", driver_name, retval); 1792 DBG("%s probe failed, %d\n", driver_name, retval);
1786 return retval; 1793 return retval;
1787} 1794}
@@ -1813,7 +1820,7 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1813 gpio_free(udc->board.pullup_pin); 1820 gpio_free(udc->board.pullup_pin);
1814 1821
1815 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1822 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1816 release_mem_region(res->start, res->end - res->start + 1); 1823 release_mem_region(res->start, resource_size(res));
1817 1824
1818 clk_put(udc->iclk); 1825 clk_put(udc->iclk);
1819 clk_put(udc->fclk); 1826 clk_put(udc->fclk);
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 4e970cf0e29a..75a256f3d45b 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -12,6 +12,7 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/slab.h>
15#include <linux/device.h> 16#include <linux/device.h>
16#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
17#include <linux/list.h> 18#include <linux/list.h>
@@ -320,7 +321,7 @@ static inline void usba_cleanup_debugfs(struct usba_udc *udc)
320static int vbus_is_present(struct usba_udc *udc) 321static int vbus_is_present(struct usba_udc *udc)
321{ 322{
322 if (gpio_is_valid(udc->vbus_pin)) 323 if (gpio_is_valid(udc->vbus_pin))
323 return gpio_get_value(udc->vbus_pin); 324 return gpio_get_value(udc->vbus_pin) ^ udc->vbus_pin_inverted;
324 325
325 /* No Vbus detection: Assume always present */ 326 /* No Vbus detection: Assume always present */
326 return 1; 327 return 1;
@@ -1763,7 +1764,7 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
1763 if (!udc->driver) 1764 if (!udc->driver)
1764 goto out; 1765 goto out;
1765 1766
1766 vbus = gpio_get_value(udc->vbus_pin); 1767 vbus = vbus_is_present(udc);
1767 if (vbus != udc->vbus_prev) { 1768 if (vbus != udc->vbus_prev) {
1768 if (vbus) { 1769 if (vbus) {
1769 toggle_bias(1); 1770 toggle_bias(1);
@@ -1914,14 +1915,14 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1914 udc->vbus_pin = -ENODEV; 1915 udc->vbus_pin = -ENODEV;
1915 1916
1916 ret = -ENOMEM; 1917 ret = -ENOMEM;
1917 udc->regs = ioremap(regs->start, regs->end - regs->start + 1); 1918 udc->regs = ioremap(regs->start, resource_size(regs));
1918 if (!udc->regs) { 1919 if (!udc->regs) {
1919 dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n"); 1920 dev_err(&pdev->dev, "Unable to map I/O memory, aborting.\n");
1920 goto err_map_regs; 1921 goto err_map_regs;
1921 } 1922 }
1922 dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n", 1923 dev_info(&pdev->dev, "MMIO registers at 0x%08lx mapped at %p\n",
1923 (unsigned long)regs->start, udc->regs); 1924 (unsigned long)regs->start, udc->regs);
1924 udc->fifo = ioremap(fifo->start, fifo->end - fifo->start + 1); 1925 udc->fifo = ioremap(fifo->start, resource_size(fifo));
1925 if (!udc->fifo) { 1926 if (!udc->fifo) {
1926 dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n"); 1927 dev_err(&pdev->dev, "Unable to map FIFO, aborting.\n");
1927 goto err_map_fifo; 1928 goto err_map_fifo;
@@ -2000,6 +2001,7 @@ static int __init usba_udc_probe(struct platform_device *pdev)
2000 if (gpio_is_valid(pdata->vbus_pin)) { 2001 if (gpio_is_valid(pdata->vbus_pin)) {
2001 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { 2002 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
2002 udc->vbus_pin = pdata->vbus_pin; 2003 udc->vbus_pin = pdata->vbus_pin;
2004 udc->vbus_pin_inverted = pdata->vbus_pin_inverted;
2003 2005
2004 ret = request_irq(gpio_to_irq(udc->vbus_pin), 2006 ret = request_irq(gpio_to_irq(udc->vbus_pin),
2005 usba_vbus_irq, 0, 2007 usba_vbus_irq, 0,
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
index f7baea307f0d..88a2e07a11a8 100644
--- a/drivers/usb/gadget/atmel_usba_udc.h
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -323,6 +323,7 @@ struct usba_udc {
323 struct platform_device *pdev; 323 struct platform_device *pdev;
324 int irq; 324 int irq;
325 int vbus_pin; 325 int vbus_pin;
326 int vbus_pin_inverted;
326 struct clk *pclk; 327 struct clk *pclk;
327 struct clk *hclk; 328 struct clk *hclk;
328 329
diff --git a/drivers/usb/gadget/audio.c b/drivers/usb/gadget/audio.c
index a3a0f4a27ef0..a62af7b59094 100644
--- a/drivers/usb/gadget/audio.c
+++ b/drivers/usb/gadget/audio.c
@@ -89,120 +89,6 @@ static const struct usb_descriptor_header *otg_desc[] = {
89 89
90/*-------------------------------------------------------------------------*/ 90/*-------------------------------------------------------------------------*/
91 91
92/**
93 * Handle USB audio endpoint set/get command in setup class request
94 */
95
96static int audio_set_endpoint_req(struct usb_configuration *c,
97 const struct usb_ctrlrequest *ctrl)
98{
99 struct usb_composite_dev *cdev = c->cdev;
100 int value = -EOPNOTSUPP;
101 u16 ep = le16_to_cpu(ctrl->wIndex);
102 u16 len = le16_to_cpu(ctrl->wLength);
103 u16 w_value = le16_to_cpu(ctrl->wValue);
104
105 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n",
106 ctrl->bRequest, w_value, len, ep);
107
108 switch (ctrl->bRequest) {
109 case UAC_SET_CUR:
110 value = 0;
111 break;
112
113 case UAC_SET_MIN:
114 break;
115
116 case UAC_SET_MAX:
117 break;
118
119 case UAC_SET_RES:
120 break;
121
122 case UAC_SET_MEM:
123 break;
124
125 default:
126 break;
127 }
128
129 return value;
130}
131
132static int audio_get_endpoint_req(struct usb_configuration *c,
133 const struct usb_ctrlrequest *ctrl)
134{
135 struct usb_composite_dev *cdev = c->cdev;
136 int value = -EOPNOTSUPP;
137 u8 ep = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF);
138 u16 len = le16_to_cpu(ctrl->wLength);
139 u16 w_value = le16_to_cpu(ctrl->wValue);
140
141 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n",
142 ctrl->bRequest, w_value, len, ep);
143
144 switch (ctrl->bRequest) {
145 case UAC_GET_CUR:
146 case UAC_GET_MIN:
147 case UAC_GET_MAX:
148 case UAC_GET_RES:
149 value = 3;
150 break;
151 case UAC_GET_MEM:
152 break;
153 default:
154 break;
155 }
156
157 return value;
158}
159
160static int
161audio_setup(struct usb_configuration *c, const struct usb_ctrlrequest *ctrl)
162{
163 struct usb_composite_dev *cdev = c->cdev;
164 struct usb_request *req = cdev->req;
165 int value = -EOPNOTSUPP;
166 u16 w_index = le16_to_cpu(ctrl->wIndex);
167 u16 w_value = le16_to_cpu(ctrl->wValue);
168 u16 w_length = le16_to_cpu(ctrl->wLength);
169
170 /* composite driver infrastructure handles everything except
171 * Audio class messages; interface activation uses set_alt().
172 */
173 switch (ctrl->bRequestType) {
174 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
175 value = audio_set_endpoint_req(c, ctrl);
176 break;
177
178 case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
179 value = audio_get_endpoint_req(c, ctrl);
180 break;
181
182 default:
183 ERROR(cdev, "Invalid control req%02x.%02x v%04x i%04x l%d\n",
184 ctrl->bRequestType, ctrl->bRequest,
185 w_value, w_index, w_length);
186 }
187
188 /* respond with data transfer or status phase? */
189 if (value >= 0) {
190 DBG(cdev, "Audio req%02x.%02x v%04x i%04x l%d\n",
191 ctrl->bRequestType, ctrl->bRequest,
192 w_value, w_index, w_length);
193 req->zero = 0;
194 req->length = value;
195 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
196 if (value < 0)
197 ERROR(cdev, "Audio response on err %d\n", value);
198 }
199
200 /* device either stalls (value < 0) or reports success */
201 return value;
202}
203
204/*-------------------------------------------------------------------------*/
205
206static int __init audio_do_config(struct usb_configuration *c) 92static int __init audio_do_config(struct usb_configuration *c)
207{ 93{
208 /* FIXME alloc iConfiguration string, set it in c->strings */ 94 /* FIXME alloc iConfiguration string, set it in c->strings */
@@ -220,7 +106,6 @@ static int __init audio_do_config(struct usb_configuration *c)
220static struct usb_configuration audio_config_driver = { 106static struct usb_configuration audio_config_driver = {
221 .label = DRIVER_DESC, 107 .label = DRIVER_DESC,
222 .bind = audio_do_config, 108 .bind = audio_do_config,
223 .setup = audio_setup,
224 .bConfigurationValue = 1, 109 .bConfigurationValue = 1,
225 /* .iConfiguration = DYNAMIC */ 110 /* .iConfiguration = DYNAMIC */
226 .bmAttributes = USB_CONFIG_ATT_SELFPOWER, 111 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
@@ -273,6 +158,7 @@ fail:
273 158
274static int __exit audio_unbind(struct usb_composite_dev *cdev) 159static int __exit audio_unbind(struct usb_composite_dev *cdev)
275{ 160{
161 gaudio_cleanup();
276 return 0; 162 return 0;
277} 163}
278 164
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index c7cb87a6fee2..699695128e33 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -62,6 +62,7 @@
62#include <linux/kernel.h> 62#include <linux/kernel.h>
63#include <linux/module.h> 63#include <linux/module.h>
64#include <linux/pci.h> 64#include <linux/pci.h>
65#include <linux/slab.h>
65#include <linux/usb/ch9.h> 66#include <linux/usb/ch9.h>
66#include <linux/usb/gadget.h> 67#include <linux/usb/gadget.h>
67 68
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index d05397ec8a18..09289bb1e20f 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -373,6 +373,8 @@ static void reset_config(struct usb_composite_dev *cdev)
373 list_for_each_entry(f, &cdev->config->functions, list) { 373 list_for_each_entry(f, &cdev->config->functions, list) {
374 if (f->disable) 374 if (f->disable)
375 f->disable(f); 375 f->disable(f);
376
377 bitmap_zero(f->endpoints, 32);
376 } 378 }
377 cdev->config = NULL; 379 cdev->config = NULL;
378} 380}
@@ -418,10 +420,35 @@ static int set_config(struct usb_composite_dev *cdev,
418 /* Initialize all interfaces by setting them to altsetting zero. */ 420 /* Initialize all interfaces by setting them to altsetting zero. */
419 for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) { 421 for (tmp = 0; tmp < MAX_CONFIG_INTERFACES; tmp++) {
420 struct usb_function *f = c->interface[tmp]; 422 struct usb_function *f = c->interface[tmp];
423 struct usb_descriptor_header **descriptors;
421 424
422 if (!f) 425 if (!f)
423 break; 426 break;
424 427
428 /*
429 * Record which endpoints are used by the function. This is used
430 * to dispatch control requests targeted at that endpoint to the
431 * function's setup callback instead of the current
432 * configuration's setup callback.
433 */
434 if (gadget->speed == USB_SPEED_HIGH)
435 descriptors = f->hs_descriptors;
436 else
437 descriptors = f->descriptors;
438
439 for (; *descriptors; ++descriptors) {
440 struct usb_endpoint_descriptor *ep;
441 int addr;
442
443 if ((*descriptors)->bDescriptorType != USB_DT_ENDPOINT)
444 continue;
445
446 ep = (struct usb_endpoint_descriptor *)*descriptors;
447 addr = ((ep->bEndpointAddress & 0x80) >> 3)
448 | (ep->bEndpointAddress & 0x0f);
449 set_bit(addr, f->endpoints);
450 }
451
425 result = f->set_alt(f, tmp, 0); 452 result = f->set_alt(f, tmp, 0);
426 if (result < 0) { 453 if (result < 0) {
427 DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n", 454 DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
@@ -688,6 +715,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
688 u16 w_value = le16_to_cpu(ctrl->wValue); 715 u16 w_value = le16_to_cpu(ctrl->wValue);
689 u16 w_length = le16_to_cpu(ctrl->wLength); 716 u16 w_length = le16_to_cpu(ctrl->wLength);
690 struct usb_function *f = NULL; 717 struct usb_function *f = NULL;
718 u8 endp;
691 719
692 /* partial re-init of the response message; the function or the 720 /* partial re-init of the response message; the function or the
693 * gadget might need to intercept e.g. a control-OUT completion 721 * gadget might need to intercept e.g. a control-OUT completion
@@ -800,23 +828,33 @@ unknown:
800 ctrl->bRequestType, ctrl->bRequest, 828 ctrl->bRequestType, ctrl->bRequest,
801 w_value, w_index, w_length); 829 w_value, w_index, w_length);
802 830
803 /* functions always handle their interfaces ... punt other 831 /* functions always handle their interfaces and endpoints...
804 * recipients (endpoint, other, WUSB, ...) to the current 832 * punt other recipients (other, WUSB, ...) to the current
805 * configuration code. 833 * configuration code.
806 * 834 *
807 * REVISIT it could make sense to let the composite device 835 * REVISIT it could make sense to let the composite device
808 * take such requests too, if that's ever needed: to work 836 * take such requests too, if that's ever needed: to work
809 * in config 0, etc. 837 * in config 0, etc.
810 */ 838 */
811 if ((ctrl->bRequestType & USB_RECIP_MASK) 839 switch (ctrl->bRequestType & USB_RECIP_MASK) {
812 == USB_RECIP_INTERFACE) { 840 case USB_RECIP_INTERFACE:
813 f = cdev->config->interface[intf]; 841 f = cdev->config->interface[intf];
814 if (f && f->setup) 842 break;
815 value = f->setup(f, ctrl); 843
816 else 844 case USB_RECIP_ENDPOINT:
845 endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f);
846 list_for_each_entry(f, &cdev->config->functions, list) {
847 if (test_bit(endp, f->endpoints))
848 break;
849 }
850 if (&f->list == &cdev->config->functions)
817 f = NULL; 851 f = NULL;
852 break;
818 } 853 }
819 if (value < 0 && !f) { 854
855 if (f && f->setup)
856 value = f->setup(f, ctrl);
857 else {
820 struct usb_configuration *c; 858 struct usb_configuration *c;
821 859
822 c = cdev->config; 860 c = cdev->config;
@@ -1054,7 +1092,8 @@ static struct usb_gadget_driver composite_driver = {
1054 .speed = USB_SPEED_HIGH, 1092 .speed = USB_SPEED_HIGH,
1055 1093
1056 .bind = composite_bind, 1094 .bind = composite_bind,
1057 .unbind = __exit_p(composite_unbind), 1095 /* .unbind = __exit_p(composite_unbind), */
1096 .unbind = composite_unbind,
1058 1097
1059 .setup = composite_setup, 1098 .setup = composite_setup,
1060 .disconnect = composite_disconnect, 1099 .disconnect = composite_disconnect,
@@ -1103,7 +1142,7 @@ int __init usb_composite_register(struct usb_composite_driver *driver)
1103 * This function is used to unregister drivers using the composite 1142 * This function is used to unregister drivers using the composite
1104 * driver framework. 1143 * driver framework.
1105 */ 1144 */
1106void __exit usb_composite_unregister(struct usb_composite_driver *driver) 1145void /* __exit */ usb_composite_unregister(struct usb_composite_driver *driver)
1107{ 1146{
1108 if (composite != driver) 1147 if (composite != driver)
1109 return; 1148 return;
diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c
index e1191b9a316a..47e8e722682c 100644
--- a/drivers/usb/gadget/config.c
+++ b/drivers/usb/gadget/config.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/slab.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/list.h> 24#include <linux/list.h>
24#include <linux/string.h> 25#include <linux/string.h>
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index cd0914ec898e..3568de210f79 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -265,16 +265,24 @@ struct usb_ep * __init usb_ep_autoconfig (
265 return ep; 265 return ep;
266 } 266 }
267 267
268 } else if (gadget_is_sh (gadget) && USB_ENDPOINT_XFER_INT == type) { 268#ifdef CONFIG_BLACKFIN
269 /* single buffering is enough; maybe 8 byte fifo is too */ 269 } else if (gadget_is_musbhdrc(gadget)) {
270 ep = find_ep (gadget, "ep3in-bulk"); 270 if ((USB_ENDPOINT_XFER_BULK == type) ||
271 if (ep && ep_matches (gadget, ep, desc)) 271 (USB_ENDPOINT_XFER_ISOC == type)) {
272 return ep; 272 if (USB_DIR_IN & desc->bEndpointAddress)
273 273 ep = find_ep (gadget, "ep5in");
274 } else if (gadget_is_mq11xx (gadget) && USB_ENDPOINT_XFER_INT == type) { 274 else
275 ep = find_ep (gadget, "ep1-bulk"); 275 ep = find_ep (gadget, "ep6out");
276 } else if (USB_ENDPOINT_XFER_INT == type) {
277 if (USB_DIR_IN & desc->bEndpointAddress)
278 ep = find_ep(gadget, "ep1in");
279 else
280 ep = find_ep(gadget, "ep2out");
281 } else
282 ep = NULL;
276 if (ep && ep_matches (gadget, ep, desc)) 283 if (ep && ep_matches (gadget, ep, desc))
277 return ep; 284 return ep;
285#endif
278 } 286 }
279 287
280 /* Second, look at endpoints until an unclaimed one looks usable */ 288 /* Second, look at endpoints until an unclaimed one looks usable */
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 167cb2a8ecef..400f80372d93 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -25,6 +25,14 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/utsname.h> 26#include <linux/utsname.h>
27 27
28
29#if defined USB_ETH_RNDIS
30# undef USB_ETH_RNDIS
31#endif
32#ifdef CONFIG_USB_ETH_RNDIS
33# define USB_ETH_RNDIS y
34#endif
35
28#include "u_ether.h" 36#include "u_ether.h"
29 37
30 38
@@ -66,7 +74,7 @@
66#define DRIVER_DESC "Ethernet Gadget" 74#define DRIVER_DESC "Ethernet Gadget"
67#define DRIVER_VERSION "Memorial Day 2008" 75#define DRIVER_VERSION "Memorial Day 2008"
68 76
69#ifdef CONFIG_USB_ETH_RNDIS 77#ifdef USB_ETH_RNDIS
70#define PREFIX "RNDIS/" 78#define PREFIX "RNDIS/"
71#else 79#else
72#define PREFIX "" 80#define PREFIX ""
@@ -87,7 +95,7 @@
87 95
88static inline bool has_rndis(void) 96static inline bool has_rndis(void)
89{ 97{
90#ifdef CONFIG_USB_ETH_RNDIS 98#ifdef USB_ETH_RNDIS
91 return true; 99 return true;
92#else 100#else
93 return false; 101 return false;
@@ -110,7 +118,7 @@ static inline bool has_rndis(void)
110 118
111#include "f_ecm.c" 119#include "f_ecm.c"
112#include "f_subset.c" 120#include "f_subset.c"
113#ifdef CONFIG_USB_ETH_RNDIS 121#ifdef USB_ETH_RNDIS
114#include "f_rndis.c" 122#include "f_rndis.c"
115#include "rndis.c" 123#include "rndis.c"
116#endif 124#endif
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 7953948bfe4a..400e1ebe6976 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -4,6 +4,8 @@
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com) 4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 by David Brownell 5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation 6 * Copyright (C) 2008 by Nokia Corporation
7 * Copyright (C) 2009 by Samsung Electronics
8 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
7 * 9 *
8 * This software is distributed under the terms of the GNU General 10 * This software is distributed under the terms of the GNU General
9 * Public License ("GPL") as published by the Free Software Foundation, 11 * Public License ("GPL") as published by the Free Software Foundation,
@@ -12,6 +14,7 @@
12 14
13/* #define VERBOSE_DEBUG */ 15/* #define VERBOSE_DEBUG */
14 16
17#include <linux/slab.h>
15#include <linux/kernel.h> 18#include <linux/kernel.h>
16#include <linux/device.h> 19#include <linux/device.h>
17 20
@@ -99,6 +102,20 @@ static inline struct f_acm *port_to_acm(struct gserial *p)
99 102
100/* interface and class descriptors: */ 103/* interface and class descriptors: */
101 104
105static struct usb_interface_assoc_descriptor
106acm_iad_descriptor = {
107 .bLength = sizeof acm_iad_descriptor,
108 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
109
110 /* .bFirstInterface = DYNAMIC, */
111 .bInterfaceCount = 2, // control + data
112 .bFunctionClass = USB_CLASS_COMM,
113 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
114 .bFunctionProtocol = USB_CDC_PROTO_NONE,
115 /* .iFunction = DYNAMIC */
116};
117
118
102static struct usb_interface_descriptor acm_control_interface_desc __initdata = { 119static struct usb_interface_descriptor acm_control_interface_desc __initdata = {
103 .bLength = USB_DT_INTERFACE_SIZE, 120 .bLength = USB_DT_INTERFACE_SIZE,
104 .bDescriptorType = USB_DT_INTERFACE, 121 .bDescriptorType = USB_DT_INTERFACE,
@@ -178,6 +195,7 @@ static struct usb_endpoint_descriptor acm_fs_out_desc __initdata = {
178}; 195};
179 196
180static struct usb_descriptor_header *acm_fs_function[] __initdata = { 197static struct usb_descriptor_header *acm_fs_function[] __initdata = {
198 (struct usb_descriptor_header *) &acm_iad_descriptor,
181 (struct usb_descriptor_header *) &acm_control_interface_desc, 199 (struct usb_descriptor_header *) &acm_control_interface_desc,
182 (struct usb_descriptor_header *) &acm_header_desc, 200 (struct usb_descriptor_header *) &acm_header_desc,
183 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor, 201 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
@@ -216,6 +234,7 @@ static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
216}; 234};
217 235
218static struct usb_descriptor_header *acm_hs_function[] __initdata = { 236static struct usb_descriptor_header *acm_hs_function[] __initdata = {
237 (struct usb_descriptor_header *) &acm_iad_descriptor,
219 (struct usb_descriptor_header *) &acm_control_interface_desc, 238 (struct usb_descriptor_header *) &acm_control_interface_desc,
220 (struct usb_descriptor_header *) &acm_header_desc, 239 (struct usb_descriptor_header *) &acm_header_desc,
221 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor, 240 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
@@ -232,11 +251,13 @@ static struct usb_descriptor_header *acm_hs_function[] __initdata = {
232 251
233#define ACM_CTRL_IDX 0 252#define ACM_CTRL_IDX 0
234#define ACM_DATA_IDX 1 253#define ACM_DATA_IDX 1
254#define ACM_IAD_IDX 2
235 255
236/* static strings, in UTF-8 */ 256/* static strings, in UTF-8 */
237static struct usb_string acm_string_defs[] = { 257static struct usb_string acm_string_defs[] = {
238 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)", 258 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
239 [ACM_DATA_IDX].s = "CDC ACM Data", 259 [ACM_DATA_IDX].s = "CDC ACM Data",
260 [ACM_IAD_IDX ].s = "CDC Serial",
240 { /* ZEROES END LIST */ }, 261 { /* ZEROES END LIST */ },
241}; 262};
242 263
@@ -432,7 +453,7 @@ static void acm_disable(struct usb_function *f)
432 * @length: size of data 453 * @length: size of data
433 * Context: irqs blocked, acm->lock held, acm_notify_req non-null 454 * Context: irqs blocked, acm->lock held, acm_notify_req non-null
434 * 455 *
435 * Returns zero on sucess or a negative errno. 456 * Returns zero on success or a negative errno.
436 * 457 *
437 * See section 6.3.5 of the CDC 1.1 specification for information 458 * See section 6.3.5 of the CDC 1.1 specification for information
438 * about the only notification we issue: SerialState change. 459 * about the only notification we issue: SerialState change.
@@ -563,6 +584,7 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
563 if (status < 0) 584 if (status < 0)
564 goto fail; 585 goto fail;
565 acm->ctrl_id = status; 586 acm->ctrl_id = status;
587 acm_iad_descriptor.bFirstInterface = status;
566 588
567 acm_control_interface_desc.bInterfaceNumber = status; 589 acm_control_interface_desc.bInterfaceNumber = status;
568 acm_union_desc .bMasterInterface0 = status; 590 acm_union_desc .bMasterInterface0 = status;
@@ -681,14 +703,6 @@ acm_unbind(struct usb_configuration *c, struct usb_function *f)
681/* Some controllers can't support CDC ACM ... */ 703/* Some controllers can't support CDC ACM ... */
682static inline bool can_support_cdc(struct usb_configuration *c) 704static inline bool can_support_cdc(struct usb_configuration *c)
683{ 705{
684 /* SH3 doesn't support multiple interfaces */
685 if (gadget_is_sh(c->cdev->gadget))
686 return false;
687
688 /* sa1100 doesn't have a third interrupt endpoint */
689 if (gadget_is_sa1100(c->cdev->gadget))
690 return false;
691
692 /* everything else is *probably* fine ... */ 706 /* everything else is *probably* fine ... */
693 return true; 707 return true;
694} 708}
@@ -732,6 +746,13 @@ int __init acm_bind_config(struct usb_configuration *c, u8 port_num)
732 acm_string_defs[ACM_DATA_IDX].id = status; 746 acm_string_defs[ACM_DATA_IDX].id = status;
733 747
734 acm_data_interface_desc.iInterface = status; 748 acm_data_interface_desc.iInterface = status;
749
750 status = usb_string_id(c->cdev);
751 if (status < 0)
752 return status;
753 acm_string_defs[ACM_IAD_IDX].id = status;
754
755 acm_iad_descriptor.iFunction = status;
735 } 756 }
736 757
737 /* allocate and initialize one new instance */ 758 /* allocate and initialize one new instance */
diff --git a/drivers/usb/gadget/f_audio.c b/drivers/usb/gadget/f_audio.c
index 98e9bb977291..43bf44514c41 100644
--- a/drivers/usb/gadget/f_audio.c
+++ b/drivers/usb/gadget/f_audio.c
@@ -9,6 +9,7 @@
9 * Licensed under the GPL-2 or later. 9 * Licensed under the GPL-2 or later.
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/device.h> 14#include <linux/device.h>
14#include <asm/atomic.h> 15#include <asm/atomic.h>
@@ -56,13 +57,16 @@ static struct usb_interface_descriptor ac_interface_desc __initdata = {
56DECLARE_UAC_AC_HEADER_DESCRIPTOR(2); 57DECLARE_UAC_AC_HEADER_DESCRIPTOR(2);
57 58
58#define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES) 59#define UAC_DT_AC_HEADER_LENGTH UAC_DT_AC_HEADER_SIZE(F_AUDIO_NUM_INTERFACES)
60/* 1 input terminal, 1 output terminal and 1 feature unit */
61#define UAC_DT_TOTAL_LENGTH (UAC_DT_AC_HEADER_LENGTH + UAC_DT_INPUT_TERMINAL_SIZE \
62 + UAC_DT_OUTPUT_TERMINAL_SIZE + UAC_DT_FEATURE_UNIT_SIZE(0))
59/* B.3.2 Class-Specific AC Interface Descriptor */ 63/* B.3.2 Class-Specific AC Interface Descriptor */
60static struct uac_ac_header_descriptor_2 ac_header_desc = { 64static struct uac_ac_header_descriptor_v1_2 ac_header_desc = {
61 .bLength = UAC_DT_AC_HEADER_LENGTH, 65 .bLength = UAC_DT_AC_HEADER_LENGTH,
62 .bDescriptorType = USB_DT_CS_INTERFACE, 66 .bDescriptorType = USB_DT_CS_INTERFACE,
63 .bDescriptorSubtype = UAC_HEADER, 67 .bDescriptorSubtype = UAC_HEADER,
64 .bcdADC = __constant_cpu_to_le16(0x0100), 68 .bcdADC = __constant_cpu_to_le16(0x0100),
65 .wTotalLength = __constant_cpu_to_le16(UAC_DT_AC_HEADER_LENGTH), 69 .wTotalLength = __constant_cpu_to_le16(UAC_DT_TOTAL_LENGTH),
66 .bInCollection = F_AUDIO_NUM_INTERFACES, 70 .bInCollection = F_AUDIO_NUM_INTERFACES,
67 .baInterfaceNr = { 71 .baInterfaceNr = {
68 [0] = F_AUDIO_AC_INTERFACE, 72 [0] = F_AUDIO_AC_INTERFACE,
@@ -121,7 +125,7 @@ static struct usb_audio_control_selector feature_unit = {
121}; 125};
122 126
123#define OUTPUT_TERMINAL_ID 3 127#define OUTPUT_TERMINAL_ID 3
124static struct uac_output_terminal_descriptor output_terminal_desc = { 128static struct uac_output_terminal_descriptor_v1 output_terminal_desc = {
125 .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE, 129 .bLength = UAC_DT_OUTPUT_TERMINAL_SIZE,
126 .bDescriptorType = USB_DT_CS_INTERFACE, 130 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL, 131 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
@@ -151,7 +155,7 @@ static struct usb_interface_descriptor as_interface_alt_1_desc = {
151}; 155};
152 156
153/* B.4.2 Class-Specific AS Interface Descriptor */ 157/* B.4.2 Class-Specific AS Interface Descriptor */
154static struct uac_as_header_descriptor as_header_desc = { 158static struct uac_as_header_descriptor_v1 as_header_desc = {
155 .bLength = UAC_DT_AS_HEADER_SIZE, 159 .bLength = UAC_DT_AS_HEADER_SIZE,
156 .bDescriptorType = USB_DT_CS_INTERFACE, 160 .bDescriptorType = USB_DT_CS_INTERFACE,
157 .bDescriptorSubtype = UAC_AS_GENERAL, 161 .bDescriptorSubtype = UAC_AS_GENERAL,
@@ -252,12 +256,12 @@ static struct f_audio_buf *f_audio_buffer_alloc(int buf_size)
252 256
253 copy_buf = kzalloc(sizeof *copy_buf, GFP_ATOMIC); 257 copy_buf = kzalloc(sizeof *copy_buf, GFP_ATOMIC);
254 if (!copy_buf) 258 if (!copy_buf)
255 return (struct f_audio_buf *)-ENOMEM; 259 return ERR_PTR(-ENOMEM);
256 260
257 copy_buf->buf = kzalloc(buf_size, GFP_ATOMIC); 261 copy_buf->buf = kzalloc(buf_size, GFP_ATOMIC);
258 if (!copy_buf->buf) { 262 if (!copy_buf->buf) {
259 kfree(copy_buf); 263 kfree(copy_buf);
260 return (struct f_audio_buf *)-ENOMEM; 264 return ERR_PTR(-ENOMEM);
261 } 265 }
262 266
263 return copy_buf; 267 return copy_buf;
@@ -332,7 +336,7 @@ static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
332 list_add_tail(&copy_buf->list, &audio->play_queue); 336 list_add_tail(&copy_buf->list, &audio->play_queue);
333 schedule_work(&audio->playback_work); 337 schedule_work(&audio->playback_work);
334 copy_buf = f_audio_buffer_alloc(audio_buf_size); 338 copy_buf = f_audio_buffer_alloc(audio_buf_size);
335 if (copy_buf < 0) 339 if (IS_ERR(copy_buf))
336 return -ENOMEM; 340 return -ENOMEM;
337 } 341 }
338 342
@@ -445,6 +449,70 @@ static int audio_get_intf_req(struct usb_function *f,
445 return len; 449 return len;
446} 450}
447 451
452static int audio_set_endpoint_req(struct usb_function *f,
453 const struct usb_ctrlrequest *ctrl)
454{
455 struct usb_composite_dev *cdev = f->config->cdev;
456 int value = -EOPNOTSUPP;
457 u16 ep = le16_to_cpu(ctrl->wIndex);
458 u16 len = le16_to_cpu(ctrl->wLength);
459 u16 w_value = le16_to_cpu(ctrl->wValue);
460
461 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n",
462 ctrl->bRequest, w_value, len, ep);
463
464 switch (ctrl->bRequest) {
465 case UAC_SET_CUR:
466 value = 0;
467 break;
468
469 case UAC_SET_MIN:
470 break;
471
472 case UAC_SET_MAX:
473 break;
474
475 case UAC_SET_RES:
476 break;
477
478 case UAC_SET_MEM:
479 break;
480
481 default:
482 break;
483 }
484
485 return value;
486}
487
488static int audio_get_endpoint_req(struct usb_function *f,
489 const struct usb_ctrlrequest *ctrl)
490{
491 struct usb_composite_dev *cdev = f->config->cdev;
492 int value = -EOPNOTSUPP;
493 u8 ep = ((le16_to_cpu(ctrl->wIndex) >> 8) & 0xFF);
494 u16 len = le16_to_cpu(ctrl->wLength);
495 u16 w_value = le16_to_cpu(ctrl->wValue);
496
497 DBG(cdev, "bRequest 0x%x, w_value 0x%04x, len %d, endpoint %d\n",
498 ctrl->bRequest, w_value, len, ep);
499
500 switch (ctrl->bRequest) {
501 case UAC_GET_CUR:
502 case UAC_GET_MIN:
503 case UAC_GET_MAX:
504 case UAC_GET_RES:
505 value = 3;
506 break;
507 case UAC_GET_MEM:
508 break;
509 default:
510 break;
511 }
512
513 return value;
514}
515
448static int 516static int
449f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) 517f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
450{ 518{
@@ -455,8 +523,8 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
455 u16 w_value = le16_to_cpu(ctrl->wValue); 523 u16 w_value = le16_to_cpu(ctrl->wValue);
456 u16 w_length = le16_to_cpu(ctrl->wLength); 524 u16 w_length = le16_to_cpu(ctrl->wLength);
457 525
458 /* composite driver infrastructure handles everything except 526 /* composite driver infrastructure handles everything; interface
459 * Audio class messages; interface activation uses set_alt(). 527 * activation uses set_alt().
460 */ 528 */
461 switch (ctrl->bRequestType) { 529 switch (ctrl->bRequestType) {
462 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: 530 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE:
@@ -467,6 +535,14 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
467 value = audio_get_intf_req(f, ctrl); 535 value = audio_get_intf_req(f, ctrl);
468 break; 536 break;
469 537
538 case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
539 value = audio_set_endpoint_req(f, ctrl);
540 break;
541
542 case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_ENDPOINT:
543 value = audio_get_endpoint_req(f, ctrl);
544 break;
545
470 default: 546 default:
471 ERROR(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n", 547 ERROR(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
472 ctrl->bRequestType, ctrl->bRequest, 548 ctrl->bRequestType, ctrl->bRequest,
@@ -504,6 +580,8 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
504 usb_ep_enable(out_ep, audio->out_desc); 580 usb_ep_enable(out_ep, audio->out_desc);
505 out_ep->driver_data = audio; 581 out_ep->driver_data = audio;
506 audio->copy_buf = f_audio_buffer_alloc(audio_buf_size); 582 audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
583 if (IS_ERR(audio->copy_buf))
584 return -ENOMEM;
507 585
508 /* 586 /*
509 * allocate a bunch of read buffers 587 * allocate a bunch of read buffers
@@ -715,7 +793,7 @@ int __init audio_bind_config(struct usb_configuration *c)
715 return status; 793 return status;
716 794
717add_fail: 795add_fail:
718 gaudio_cleanup(&audio->card); 796 gaudio_cleanup();
719setup_fail: 797setup_fail:
720 kfree(audio); 798 kfree(audio);
721 return status; 799 return status;
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index ecf5bdd0ae06..4e595324c614 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -21,6 +21,7 @@
21 21
22/* #define VERBOSE_DEBUG */ 22/* #define VERBOSE_DEBUG */
23 23
24#include <linux/slab.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/device.h> 26#include <linux/device.h>
26#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
@@ -497,12 +498,9 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
497 struct net_device *net; 498 struct net_device *net;
498 499
499 /* Enable zlps by default for ECM conformance; 500 /* Enable zlps by default for ECM conformance;
500 * override for musb_hdrc (avoids txdma ovhead) 501 * override for musb_hdrc (avoids txdma ovhead).
501 * and sa1100 (can't).
502 */ 502 */
503 ecm->port.is_zlp_ok = !( 503 ecm->port.is_zlp_ok = !(gadget_is_musbhdrc(cdev->gadget)
504 gadget_is_sa1100(cdev->gadget)
505 || gadget_is_musbhdrc(cdev->gadget)
506 ); 504 );
507 ecm->port.cdc_filter = DEFAULT_FILTER; 505 ecm->port.cdc_filter = DEFAULT_FILTER;
508 DBG(cdev, "activate ecm\n"); 506 DBG(cdev, "activate ecm\n");
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index 0a577d5694fd..38226e9a371d 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -24,6 +24,7 @@
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <linux/crc32.h> 26#include <linux/crc32.h>
27#include <linux/slab.h>
27 28
28#include "u_ether.h" 29#include "u_ether.h"
29 30
@@ -358,7 +359,7 @@ done:
358 * b15: bmType (0 == data) 359 * b15: bmType (0 == data)
359 */ 360 */
360 len = skb->len; 361 len = skb->len;
361 put_unaligned_le16((len & 0x3FFF) | BIT(14), skb_push(skb, 2)); 362 put_unaligned_le16(len & 0x3FFF, skb_push(skb, 2));
362 363
363 /* add a zero-length EEM packet, if needed */ 364 /* add a zero-length EEM packet, if needed */
364 if (padlen) 365 if (padlen)
@@ -464,7 +465,6 @@ static int eem_unwrap(struct gether *port,
464 } 465 }
465 466
466 /* validate CRC */ 467 /* validate CRC */
467 crc = get_unaligned_le32(skb->data + len - ETH_FCS_LEN);
468 if (header & BIT(14)) { 468 if (header & BIT(14)) {
469 crc = get_unaligned_le32(skb->data + len 469 crc = get_unaligned_le32(skb->data + len
470 - ETH_FCS_LEN); 470 - ETH_FCS_LEN);
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 6cb29d3df575..e91d1b16d9be 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -21,6 +21,7 @@
21 21
22/* #define VERBOSE_DEBUG */ 22/* #define VERBOSE_DEBUG */
23 23
24#include <linux/slab.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/device.h> 26#include <linux/device.h>
26 27
diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
new file mode 100644
index 000000000000..f4911c09022e
--- /dev/null
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -0,0 +1,3098 @@
1/*
2 * f_mass_storage.c -- Mass Storage USB Composite Function
3 *
4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyright (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The names of the above-listed copyright holders may not be used
19 * to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * ALTERNATIVELY, this software may be distributed under the terms of the
23 * GNU General Public License ("GPL") as published by the Free Software
24 * Foundation, either version 2 of that License or (at your option) any
25 * later version.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39
40
41/*
42 * The Mass Storage Function acts as a USB Mass Storage device,
43 * appearing to the host as a disk drive or as a CD-ROM drive. In
44 * addition to providing an example of a genuinely useful composite
45 * function for a USB device, it also illustrates a technique of
46 * double-buffering for increased throughput.
47 *
48 * Function supports multiple logical units (LUNs). Backing storage
49 * for each LUN is provided by a regular file or a block device.
50 * Access for each LUN can be limited to read-only. Moreover, the
51 * function can indicate that LUN is removable and/or CD-ROM. (The
52 * later implies read-only access.)
53 *
54 * MSF is configured by specifying a fsg_config structure. It has the
55 * following fields:
56 *
57 * nluns Number of LUNs function have (anywhere from 1
58 * to FSG_MAX_LUNS which is 8).
59 * luns An array of LUN configuration values. This
60 * should be filled for each LUN that
61 * function will include (ie. for "nluns"
62 * LUNs). Each element of the array has
63 * the following fields:
64 * ->filename The path to the backing file for the LUN.
65 * Required if LUN is not marked as
66 * removable.
67 * ->ro Flag specifying access to the LUN shall be
68 * read-only. This is implied if CD-ROM
69 * emulation is enabled as well as when
70 * it was impossible to open "filename"
71 * in R/W mode.
72 * ->removable Flag specifying that LUN shall be indicated as
73 * being removable.
74 * ->cdrom Flag specifying that LUN shall be reported as
75 * being a CD-ROM.
76 *
77 * lun_name_format A printf-like format for names of the LUN
78 * devices. This determines how the
79 * directory in sysfs will be named.
80 * Unless you are using several MSFs in
81 * a single gadget (as opposed to single
82 * MSF in many configurations) you may
83 * leave it as NULL (in which case
84 * "lun%d" will be used). In the format
85 * you can use "%d" to index LUNs for
86 * MSF's with more than one LUN. (Beware
87 * that there is only one integer given
88 * as an argument for the format and
89 * specifying invalid format may cause
90 * unspecified behaviour.)
91 * thread_name Name of the kernel thread process used by the
92 * MSF. You can safely set it to NULL
93 * (in which case default "file-storage"
94 * will be used).
95 *
96 * vendor_name
97 * product_name
98 * release Information used as a reply to INQUIRY
99 * request. To use default set to NULL,
100 * NULL, 0xffff respectively. The first
101 * field should be 8 and the second 16
102 * characters or less.
103 *
104 * can_stall Set to permit function to halt bulk endpoints.
105 * Disabled on some USB devices known not
106 * to work correctly. You should set it
107 * to true.
108 *
109 * If "removable" is not set for a LUN then a backing file must be
110 * specified. If it is set, then NULL filename means the LUN's medium
111 * is not loaded (an empty string as "filename" in the fsg_config
112 * structure causes error). The CD-ROM emulation includes a single
113 * data track and no audio tracks; hence there need be only one
114 * backing file per LUN. Note also that the CD-ROM block length is
115 * set to 512 rather than the more common value 2048.
116 *
117 *
118 * MSF includes support for module parameters. If gadget using it
119 * decides to use it, the following module parameters will be
120 * available:
121 *
122 * file=filename[,filename...]
123 * Names of the files or block devices used for
124 * backing storage.
125 * ro=b[,b...] Default false, boolean for read-only access.
126 * removable=b[,b...]
127 * Default true, boolean for removable media.
128 * cdrom=b[,b...] Default false, boolean for whether to emulate
129 * a CD-ROM drive.
130 * luns=N Default N = number of filenames, number of
131 * LUNs to support.
132 * stall Default determined according to the type of
133 * USB device controller (usually true),
134 * boolean to permit the driver to halt
135 * bulk endpoints.
136 *
137 * The module parameters may be prefixed with some string. You need
138 * to consult gadget's documentation or source to verify whether it is
139 * using those module parameters and if it does what are the prefixes
140 * (look for FSG_MODULE_PARAMETERS() macro usage, what's inside it is
141 * the prefix).
142 *
143 *
144 * Requirements are modest; only a bulk-in and a bulk-out endpoint are
145 * needed. The memory requirement amounts to two 16K buffers, size
146 * configurable by a parameter. Support is included for both
147 * full-speed and high-speed operation.
148 *
149 * Note that the driver is slightly non-portable in that it assumes a
150 * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
151 * interrupt-in endpoints. With most device controllers this isn't an
152 * issue, but there may be some with hardware restrictions that prevent
153 * a buffer from being used by more than one endpoint.
154 *
155 *
156 * The pathnames of the backing files and the ro settings are
157 * available in the attribute files "file" and "ro" in the lun<n> (or
158 * to be more precise in a directory which name comes from
159 * "lun_name_format" option!) subdirectory of the gadget's sysfs
160 * directory. If the "removable" option is set, writing to these
161 * files will simulate ejecting/loading the medium (writing an empty
162 * line means eject) and adjusting a write-enable tab. Changes to the
163 * ro setting are not allowed when the medium is loaded or if CD-ROM
164 * emulation is being used.
165 *
166 *
167 * 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
169 * Brownell. The driver's SCSI command interface was based on the
170 * "Information technology - Small Computer System Interface - 2"
171 * document from X3T9.2 Project 375D, Revision 10L, 7-SEP-93,
172 * available at <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>.
173 * The single exception is opcode 0x23 (READ FORMAT CAPACITIES), which
174 * was based on the "Universal Serial Bus Mass Storage Class UFI
175 * Command Specification" document, Revision 1.0, December 14, 1998,
176 * available at
177 * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
178 */
179
180
181/*
182 * Driver Design
183 *
184 * The MSF is fairly straightforward. There is a main kernel
185 * thread that handles most of the work. Interrupt routines field
186 * callbacks from the controller driver: bulk- and interrupt-request
187 * completion notifications, endpoint-0 events, and disconnect events.
188 * Completion events are passed to the main thread by wakeup calls. Many
189 * ep0 requests are handled at interrupt time, but SetInterface,
190 * SetConfiguration, and device reset requests are forwarded to the
191 * thread in the form of "exceptions" using SIGUSR1 signals (since they
192 * should interrupt any ongoing file I/O operations).
193 *
194 * The thread's main routine implements the standard command/data/status
195 * parts of a SCSI interaction. It and its subroutines are full of tests
196 * for pending signals/exceptions -- all this polling is necessary since
197 * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
198 * indication that the driver really wants to be running in userspace.)
199 * An important point is that so long as the thread is alive it keeps an
200 * open reference to the backing file. This will prevent unmounting
201 * the backing file's underlying filesystem and could cause problems
202 * during system shutdown, for example. To prevent such problems, the
203 * thread catches INT, TERM, and KILL signals and converts them into
204 * an EXIT exception.
205 *
206 * In normal operation the main thread is started during the gadget's
207 * fsg_bind() callback and stopped during fsg_unbind(). But it can
208 * also exit when it receives a signal, and there's no point leaving
209 * the gadget running when the thread is dead. At of this moment, MSF
210 * provides no way to deregister the gadget when thread dies -- maybe
211 * a callback functions is needed.
212 *
213 * To provide maximum throughput, the driver uses a circular pipeline of
214 * buffer heads (struct fsg_buffhd). In principle the pipeline can be
215 * arbitrarily long; in practice the benefits don't justify having more
216 * than 2 stages (i.e., double buffering). But it helps to think of the
217 * pipeline as being a long one. Each buffer head contains a bulk-in and
218 * a bulk-out request pointer (since the buffer can be used for both
219 * output and input -- directions always are given from the host's
220 * point of view) as well as a pointer to the buffer and various state
221 * variables.
222 *
223 * Use of the pipeline follows a simple protocol. There is a variable
224 * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
225 * At any time that buffer head may still be in use from an earlier
226 * request, so each buffer head has a state variable indicating whether
227 * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
228 * buffer head to be EMPTY, filling the buffer either by file I/O or by
229 * USB I/O (during which the buffer head is BUSY), and marking the buffer
230 * head FULL when the I/O is complete. Then the buffer will be emptied
231 * (again possibly by USB I/O, during which it is marked BUSY) and
232 * finally marked EMPTY again (possibly by a completion routine).
233 *
234 * A module parameter tells the driver to avoid stalling the bulk
235 * endpoints wherever the transport specification allows. This is
236 * necessary for some UDCs like the SuperH, which cannot reliably clear a
237 * halt on a bulk endpoint. However, under certain circumstances the
238 * Bulk-only specification requires a stall. In such cases the driver
239 * will halt the endpoint and set a flag indicating that it should clear
240 * the halt in software during the next device reset. Hopefully this
241 * will permit everything to work correctly. Furthermore, although the
242 * specification allows the bulk-out endpoint to halt when the host sends
243 * too much data, implementing this would cause an unavoidable race.
244 * The driver will always use the "no-stall" approach for OUT transfers.
245 *
246 * One subtle point concerns sending status-stage responses for ep0
247 * requests. Some of these requests, such as device reset, can involve
248 * interrupting an ongoing file I/O operation, which might take an
249 * arbitrarily long time. During that delay the host might give up on
250 * the original ep0 request and issue a new one. When that happens the
251 * driver should not notify the host about completion of the original
252 * request, as the host will no longer be waiting for it. So the driver
253 * assigns to each ep0 request a unique tag, and it keeps track of the
254 * tag value of the request associated with a long-running exception
255 * (device-reset, interface-change, or configuration-change). When the
256 * exception handler is finished, the status-stage response is submitted
257 * only if the current ep0 request tag is equal to the exception request
258 * tag. Thus only the most recently received ep0 request will get a
259 * status-stage response.
260 *
261 * Warning: This driver source file is too long. It ought to be split up
262 * into a header file plus about 3 separate .c files, to handle the details
263 * of the Gadget, USB Mass Storage, and SCSI protocols.
264 */
265
266
267/* #define VERBOSE_DEBUG */
268/* #define DUMP_MSGS */
269
270
271#include <linux/blkdev.h>
272#include <linux/completion.h>
273#include <linux/dcache.h>
274#include <linux/delay.h>
275#include <linux/device.h>
276#include <linux/fcntl.h>
277#include <linux/file.h>
278#include <linux/fs.h>
279#include <linux/kref.h>
280#include <linux/kthread.h>
281#include <linux/limits.h>
282#include <linux/rwsem.h>
283#include <linux/slab.h>
284#include <linux/spinlock.h>
285#include <linux/string.h>
286#include <linux/freezer.h>
287#include <linux/utsname.h>
288
289#include <linux/usb/ch9.h>
290#include <linux/usb/gadget.h>
291
292#include "gadget_chips.h"
293
294
295
296/*------------------------------------------------------------------------*/
297
298#define FSG_DRIVER_DESC "Mass Storage Function"
299#define FSG_DRIVER_VERSION "2009/09/11"
300
301static const char fsg_string_interface[] = "Mass Storage";
302
303
304#define FSG_NO_INTR_EP 1
305#define FSG_BUFFHD_STATIC_BUFFER 1
306#define FSG_NO_DEVICE_STRINGS 1
307#define FSG_NO_OTG 1
308#define FSG_NO_INTR_EP 1
309
310#include "storage_common.c"
311
312
313/*-------------------------------------------------------------------------*/
314
315struct fsg_dev;
316
317
318/* Data shared by all the FSG instances. */
319struct fsg_common {
320 struct usb_gadget *gadget;
321 struct fsg_dev *fsg;
322 struct fsg_dev *prev_fsg;
323
324 /* filesem protects: backing files in use */
325 struct rw_semaphore filesem;
326
327 /* lock protects: state, all the req_busy's */
328 spinlock_t lock;
329
330 struct usb_ep *ep0; /* Copy of gadget->ep0 */
331 struct usb_request *ep0req; /* Copy of cdev->req */
332 unsigned int ep0_req_tag;
333 const char *ep0req_name;
334
335 struct fsg_buffhd *next_buffhd_to_fill;
336 struct fsg_buffhd *next_buffhd_to_drain;
337 struct fsg_buffhd buffhds[FSG_NUM_BUFFERS];
338
339 int cmnd_size;
340 u8 cmnd[MAX_COMMAND_SIZE];
341
342 unsigned int nluns;
343 unsigned int lun;
344 struct fsg_lun *luns;
345 struct fsg_lun *curlun;
346
347 unsigned int bulk_out_maxpacket;
348 enum fsg_state state; /* For exception handling */
349 unsigned int exception_req_tag;
350
351 u8 config, new_config;
352 enum data_direction data_dir;
353 u32 data_size;
354 u32 data_size_from_cmnd;
355 u32 tag;
356 u32 residue;
357 u32 usb_amount_left;
358
359 unsigned int can_stall:1;
360 unsigned int free_storage_on_release:1;
361 unsigned int phase_error:1;
362 unsigned int short_packet_received:1;
363 unsigned int bad_lun_okay:1;
364 unsigned int running:1;
365
366 int thread_wakeup_needed;
367 struct completion thread_notifier;
368 struct task_struct *thread_task;
369
370 /* Callback function to call when thread exits. */
371 int (*thread_exits)(struct fsg_common *common);
372 /* Gadget's private data. */
373 void *private_data;
374
375 /* Vendor (8 chars), product (16 chars), release (4
376 * hexadecimal digits) and NUL byte */
377 char inquiry_string[8 + 16 + 4 + 1];
378
379 struct kref ref;
380};
381
382
383struct fsg_config {
384 unsigned nluns;
385 struct fsg_lun_config {
386 const char *filename;
387 char ro;
388 char removable;
389 char cdrom;
390 } luns[FSG_MAX_LUNS];
391
392 const char *lun_name_format;
393 const char *thread_name;
394
395 /* Callback function to call when thread exits. If no
396 * callback is set or it returns value lower then zero MSF
397 * will force eject all LUNs it operates on (including those
398 * marked as non-removable or with prevent_medium_removal flag
399 * set). */
400 int (*thread_exits)(struct fsg_common *common);
401 /* Gadget's private data. */
402 void *private_data;
403
404 const char *vendor_name; /* 8 characters or less */
405 const char *product_name; /* 16 characters or less */
406 u16 release;
407
408 char can_stall;
409};
410
411
412struct fsg_dev {
413 struct usb_function function;
414 struct usb_gadget *gadget; /* Copy of cdev->gadget */
415 struct fsg_common *common;
416
417 u16 interface_number;
418
419 unsigned int bulk_in_enabled:1;
420 unsigned int bulk_out_enabled:1;
421
422 unsigned long atomic_bitflags;
423#define IGNORE_BULK_OUT 0
424
425 struct usb_ep *bulk_in;
426 struct usb_ep *bulk_out;
427};
428
429
430static inline int __fsg_is_set(struct fsg_common *common,
431 const char *func, unsigned line)
432{
433 if (common->fsg)
434 return 1;
435 ERROR(common, "common->fsg is NULL in %s at %u\n", func, line);
436 return 0;
437}
438
439#define fsg_is_set(common) likely(__fsg_is_set(common, __func__, __LINE__))
440
441
442static inline struct fsg_dev *fsg_from_func(struct usb_function *f)
443{
444 return container_of(f, struct fsg_dev, function);
445}
446
447
448typedef void (*fsg_routine_t)(struct fsg_dev *);
449
450static int exception_in_progress(struct fsg_common *common)
451{
452 return common->state > FSG_STATE_IDLE;
453}
454
455/* Make bulk-out requests be divisible by the maxpacket size */
456static void set_bulk_out_req_length(struct fsg_common *common,
457 struct fsg_buffhd *bh, unsigned int length)
458{
459 unsigned int rem;
460
461 bh->bulk_out_intended_length = length;
462 rem = length % common->bulk_out_maxpacket;
463 if (rem > 0)
464 length += common->bulk_out_maxpacket - rem;
465 bh->outreq->length = length;
466}
467
468/*-------------------------------------------------------------------------*/
469
470static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
471{
472 const char *name;
473
474 if (ep == fsg->bulk_in)
475 name = "bulk-in";
476 else if (ep == fsg->bulk_out)
477 name = "bulk-out";
478 else
479 name = ep->name;
480 DBG(fsg, "%s set halt\n", name);
481 return usb_ep_set_halt(ep);
482}
483
484
485/*-------------------------------------------------------------------------*/
486
487/* These routines may be called in process context or in_irq */
488
489/* Caller must hold fsg->lock */
490static void wakeup_thread(struct fsg_common *common)
491{
492 /* Tell the main thread that something has happened */
493 common->thread_wakeup_needed = 1;
494 if (common->thread_task)
495 wake_up_process(common->thread_task);
496}
497
498
499static void raise_exception(struct fsg_common *common, enum fsg_state new_state)
500{
501 unsigned long flags;
502
503 /* Do nothing if a higher-priority exception is already in progress.
504 * If a lower-or-equal priority exception is in progress, preempt it
505 * and notify the main thread by sending it a signal. */
506 spin_lock_irqsave(&common->lock, flags);
507 if (common->state <= new_state) {
508 common->exception_req_tag = common->ep0_req_tag;
509 common->state = new_state;
510 if (common->thread_task)
511 send_sig_info(SIGUSR1, SEND_SIG_FORCED,
512 common->thread_task);
513 }
514 spin_unlock_irqrestore(&common->lock, flags);
515}
516
517
518/*-------------------------------------------------------------------------*/
519
520static int ep0_queue(struct fsg_common *common)
521{
522 int rc;
523
524 rc = usb_ep_queue(common->ep0, common->ep0req, GFP_ATOMIC);
525 common->ep0->driver_data = common;
526 if (rc != 0 && rc != -ESHUTDOWN) {
527 /* We can't do much more than wait for a reset */
528 WARNING(common, "error in submission: %s --> %d\n",
529 common->ep0->name, rc);
530 }
531 return rc;
532}
533
534/*-------------------------------------------------------------------------*/
535
536/* Bulk and interrupt endpoint completion handlers.
537 * These always run in_irq. */
538
539static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
540{
541 struct fsg_common *common = ep->driver_data;
542 struct fsg_buffhd *bh = req->context;
543
544 if (req->status || req->actual != req->length)
545 DBG(common, "%s --> %d, %u/%u\n", __func__,
546 req->status, req->actual, req->length);
547 if (req->status == -ECONNRESET) /* Request was cancelled */
548 usb_ep_fifo_flush(ep);
549
550 /* Hold the lock while we update the request and buffer states */
551 smp_wmb();
552 spin_lock(&common->lock);
553 bh->inreq_busy = 0;
554 bh->state = BUF_STATE_EMPTY;
555 wakeup_thread(common);
556 spin_unlock(&common->lock);
557}
558
559static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
560{
561 struct fsg_common *common = ep->driver_data;
562 struct fsg_buffhd *bh = req->context;
563
564 dump_msg(common, "bulk-out", req->buf, req->actual);
565 if (req->status || req->actual != bh->bulk_out_intended_length)
566 DBG(common, "%s --> %d, %u/%u\n", __func__,
567 req->status, req->actual,
568 bh->bulk_out_intended_length);
569 if (req->status == -ECONNRESET) /* Request was cancelled */
570 usb_ep_fifo_flush(ep);
571
572 /* Hold the lock while we update the request and buffer states */
573 smp_wmb();
574 spin_lock(&common->lock);
575 bh->outreq_busy = 0;
576 bh->state = BUF_STATE_FULL;
577 wakeup_thread(common);
578 spin_unlock(&common->lock);
579}
580
581
582/*-------------------------------------------------------------------------*/
583
584/* Ep0 class-specific handlers. These always run in_irq. */
585
586static int fsg_setup(struct usb_function *f,
587 const struct usb_ctrlrequest *ctrl)
588{
589 struct fsg_dev *fsg = fsg_from_func(f);
590 struct usb_request *req = fsg->common->ep0req;
591 u16 w_index = le16_to_cpu(ctrl->wIndex);
592 u16 w_value = le16_to_cpu(ctrl->wValue);
593 u16 w_length = le16_to_cpu(ctrl->wLength);
594
595 if (!fsg->common->config)
596 return -EOPNOTSUPP;
597
598 switch (ctrl->bRequest) {
599
600 case USB_BULK_RESET_REQUEST:
601 if (ctrl->bRequestType !=
602 (USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
603 break;
604 if (w_index != fsg->interface_number || w_value != 0)
605 return -EDOM;
606
607 /* Raise an exception to stop the current operation
608 * and reinitialize our state. */
609 DBG(fsg, "bulk reset request\n");
610 raise_exception(fsg->common, FSG_STATE_RESET);
611 return DELAYED_STATUS;
612
613 case USB_BULK_GET_MAX_LUN_REQUEST:
614 if (ctrl->bRequestType !=
615 (USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
616 break;
617 if (w_index != fsg->interface_number || w_value != 0)
618 return -EDOM;
619 VDBG(fsg, "get max LUN\n");
620 *(u8 *) req->buf = fsg->common->nluns - 1;
621
622 /* Respond with data/status */
623 req->length = min((u16)1, w_length);
624 fsg->common->ep0req_name =
625 ctrl->bRequestType & USB_DIR_IN ? "ep0-in" : "ep0-out";
626 return ep0_queue(fsg->common);
627 }
628
629 VDBG(fsg,
630 "unknown class-specific control req "
631 "%02x.%02x v%04x i%04x l%u\n",
632 ctrl->bRequestType, ctrl->bRequest,
633 le16_to_cpu(ctrl->wValue), w_index, w_length);
634 return -EOPNOTSUPP;
635}
636
637
638/*-------------------------------------------------------------------------*/
639
640/* All the following routines run in process context */
641
642
643/* Use this for bulk or interrupt transfers, not ep0 */
644static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
645 struct usb_request *req, int *pbusy,
646 enum fsg_buffer_state *state)
647{
648 int rc;
649
650 if (ep == fsg->bulk_in)
651 dump_msg(fsg, "bulk-in", req->buf, req->length);
652
653 spin_lock_irq(&fsg->common->lock);
654 *pbusy = 1;
655 *state = BUF_STATE_BUSY;
656 spin_unlock_irq(&fsg->common->lock);
657 rc = usb_ep_queue(ep, req, GFP_KERNEL);
658 if (rc != 0) {
659 *pbusy = 0;
660 *state = BUF_STATE_EMPTY;
661
662 /* We can't do much more than wait for a reset */
663
664 /* Note: currently the net2280 driver fails zero-length
665 * submissions if DMA is enabled. */
666 if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
667 req->length == 0))
668 WARNING(fsg, "error in submission: %s --> %d\n",
669 ep->name, rc);
670 }
671}
672
673#define START_TRANSFER_OR(common, ep_name, req, pbusy, state) \
674 if (fsg_is_set(common)) \
675 start_transfer((common)->fsg, (common)->fsg->ep_name, \
676 req, pbusy, state); \
677 else
678
679#define START_TRANSFER(common, ep_name, req, pbusy, state) \
680 START_TRANSFER_OR(common, ep_name, req, pbusy, state) (void)0
681
682
683
684static int sleep_thread(struct fsg_common *common)
685{
686 int rc = 0;
687
688 /* Wait until a signal arrives or we are woken up */
689 for (;;) {
690 try_to_freeze();
691 set_current_state(TASK_INTERRUPTIBLE);
692 if (signal_pending(current)) {
693 rc = -EINTR;
694 break;
695 }
696 if (common->thread_wakeup_needed)
697 break;
698 schedule();
699 }
700 __set_current_state(TASK_RUNNING);
701 common->thread_wakeup_needed = 0;
702 return rc;
703}
704
705
706/*-------------------------------------------------------------------------*/
707
708static int do_read(struct fsg_common *common)
709{
710 struct fsg_lun *curlun = common->curlun;
711 u32 lba;
712 struct fsg_buffhd *bh;
713 int rc;
714 u32 amount_left;
715 loff_t file_offset, file_offset_tmp;
716 unsigned int amount;
717 unsigned int partial_page;
718 ssize_t nread;
719
720 /* Get the starting Logical Block Address and check that it's
721 * not too big */
722 if (common->cmnd[0] == SC_READ_6)
723 lba = get_unaligned_be24(&common->cmnd[1]);
724 else {
725 lba = get_unaligned_be32(&common->cmnd[2]);
726
727 /* We allow DPO (Disable Page Out = don't save data in the
728 * cache) and FUA (Force Unit Access = don't read from the
729 * cache), but we don't implement them. */
730 if ((common->cmnd[1] & ~0x18) != 0) {
731 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
732 return -EINVAL;
733 }
734 }
735 if (lba >= curlun->num_sectors) {
736 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
737 return -EINVAL;
738 }
739 file_offset = ((loff_t) lba) << 9;
740
741 /* Carry out the file reads */
742 amount_left = common->data_size_from_cmnd;
743 if (unlikely(amount_left == 0))
744 return -EIO; /* No default reply */
745
746 for (;;) {
747
748 /* Figure out how much we need to read:
749 * Try to read the remaining amount.
750 * But don't read more than the buffer size.
751 * And don't try to read past the end of the file.
752 * Finally, if we're not at a page boundary, don't read past
753 * the next page.
754 * If this means reading 0 then we were asked to read past
755 * the end of file. */
756 amount = min(amount_left, FSG_BUFLEN);
757 amount = min((loff_t) amount,
758 curlun->file_length - file_offset);
759 partial_page = file_offset & (PAGE_CACHE_SIZE - 1);
760 if (partial_page > 0)
761 amount = min(amount, (unsigned int) PAGE_CACHE_SIZE -
762 partial_page);
763
764 /* Wait for the next buffer to become available */
765 bh = common->next_buffhd_to_fill;
766 while (bh->state != BUF_STATE_EMPTY) {
767 rc = sleep_thread(common);
768 if (rc)
769 return rc;
770 }
771
772 /* If we were asked to read past the end of file,
773 * end with an empty buffer. */
774 if (amount == 0) {
775 curlun->sense_data =
776 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
777 curlun->sense_data_info = file_offset >> 9;
778 curlun->info_valid = 1;
779 bh->inreq->length = 0;
780 bh->state = BUF_STATE_FULL;
781 break;
782 }
783
784 /* Perform the read */
785 file_offset_tmp = file_offset;
786 nread = vfs_read(curlun->filp,
787 (char __user *) bh->buf,
788 amount, &file_offset_tmp);
789 VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
790 (unsigned long long) file_offset,
791 (int) nread);
792 if (signal_pending(current))
793 return -EINTR;
794
795 if (nread < 0) {
796 LDBG(curlun, "error in file read: %d\n",
797 (int) nread);
798 nread = 0;
799 } else if (nread < amount) {
800 LDBG(curlun, "partial file read: %d/%u\n",
801 (int) nread, amount);
802 nread -= (nread & 511); /* Round down to a block */
803 }
804 file_offset += nread;
805 amount_left -= nread;
806 common->residue -= nread;
807 bh->inreq->length = nread;
808 bh->state = BUF_STATE_FULL;
809
810 /* If an error occurred, report it and its position */
811 if (nread < amount) {
812 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
813 curlun->sense_data_info = file_offset >> 9;
814 curlun->info_valid = 1;
815 break;
816 }
817
818 if (amount_left == 0)
819 break; /* No more left to read */
820
821 /* Send this buffer and go read some more */
822 bh->inreq->zero = 0;
823 START_TRANSFER_OR(common, bulk_in, bh->inreq,
824 &bh->inreq_busy, &bh->state)
825 /* Don't know what to do if
826 * common->fsg is NULL */
827 return -EIO;
828 common->next_buffhd_to_fill = bh->next;
829 }
830
831 return -EIO; /* No default reply */
832}
833
834
835/*-------------------------------------------------------------------------*/
836
837static int do_write(struct fsg_common *common)
838{
839 struct fsg_lun *curlun = common->curlun;
840 u32 lba;
841 struct fsg_buffhd *bh;
842 int get_some_more;
843 u32 amount_left_to_req, amount_left_to_write;
844 loff_t usb_offset, file_offset, file_offset_tmp;
845 unsigned int amount;
846 unsigned int partial_page;
847 ssize_t nwritten;
848 int rc;
849
850 if (curlun->ro) {
851 curlun->sense_data = SS_WRITE_PROTECTED;
852 return -EINVAL;
853 }
854 spin_lock(&curlun->filp->f_lock);
855 curlun->filp->f_flags &= ~O_SYNC; /* Default is not to wait */
856 spin_unlock(&curlun->filp->f_lock);
857
858 /* Get the starting Logical Block Address and check that it's
859 * not too big */
860 if (common->cmnd[0] == SC_WRITE_6)
861 lba = get_unaligned_be24(&common->cmnd[1]);
862 else {
863 lba = get_unaligned_be32(&common->cmnd[2]);
864
865 /* We allow DPO (Disable Page Out = don't save data in the
866 * cache) and FUA (Force Unit Access = write directly to the
867 * medium). We don't implement DPO; we implement FUA by
868 * performing synchronous output. */
869 if (common->cmnd[1] & ~0x18) {
870 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
871 return -EINVAL;
872 }
873 if (common->cmnd[1] & 0x08) { /* FUA */
874 spin_lock(&curlun->filp->f_lock);
875 curlun->filp->f_flags |= O_SYNC;
876 spin_unlock(&curlun->filp->f_lock);
877 }
878 }
879 if (lba >= curlun->num_sectors) {
880 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
881 return -EINVAL;
882 }
883
884 /* Carry out the file writes */
885 get_some_more = 1;
886 file_offset = usb_offset = ((loff_t) lba) << 9;
887 amount_left_to_req = common->data_size_from_cmnd;
888 amount_left_to_write = common->data_size_from_cmnd;
889
890 while (amount_left_to_write > 0) {
891
892 /* Queue a request for more data from the host */
893 bh = common->next_buffhd_to_fill;
894 if (bh->state == BUF_STATE_EMPTY && get_some_more) {
895
896 /* Figure out how much we want to get:
897 * Try to get the remaining amount.
898 * But don't get more than the buffer size.
899 * And don't try to go past the end of the file.
900 * If we're not at a page boundary,
901 * don't go past the next page.
902 * If this means getting 0, then we were asked
903 * to write past the end of file.
904 * Finally, round down to a block boundary. */
905 amount = min(amount_left_to_req, FSG_BUFLEN);
906 amount = min((loff_t) amount, curlun->file_length -
907 usb_offset);
908 partial_page = usb_offset & (PAGE_CACHE_SIZE - 1);
909 if (partial_page > 0)
910 amount = min(amount,
911 (unsigned int) PAGE_CACHE_SIZE - partial_page);
912
913 if (amount == 0) {
914 get_some_more = 0;
915 curlun->sense_data =
916 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
917 curlun->sense_data_info = usb_offset >> 9;
918 curlun->info_valid = 1;
919 continue;
920 }
921 amount -= (amount & 511);
922 if (amount == 0) {
923
924 /* Why were we were asked to transfer a
925 * partial block? */
926 get_some_more = 0;
927 continue;
928 }
929
930 /* Get the next buffer */
931 usb_offset += amount;
932 common->usb_amount_left -= amount;
933 amount_left_to_req -= amount;
934 if (amount_left_to_req == 0)
935 get_some_more = 0;
936
937 /* amount is always divisible by 512, hence by
938 * the bulk-out maxpacket size */
939 bh->outreq->length = amount;
940 bh->bulk_out_intended_length = amount;
941 bh->outreq->short_not_ok = 1;
942 START_TRANSFER_OR(common, bulk_out, bh->outreq,
943 &bh->outreq_busy, &bh->state)
944 /* Don't know what to do if
945 * common->fsg is NULL */
946 return -EIO;
947 common->next_buffhd_to_fill = bh->next;
948 continue;
949 }
950
951 /* Write the received data to the backing file */
952 bh = common->next_buffhd_to_drain;
953 if (bh->state == BUF_STATE_EMPTY && !get_some_more)
954 break; /* We stopped early */
955 if (bh->state == BUF_STATE_FULL) {
956 smp_rmb();
957 common->next_buffhd_to_drain = bh->next;
958 bh->state = BUF_STATE_EMPTY;
959
960 /* Did something go wrong with the transfer? */
961 if (bh->outreq->status != 0) {
962 curlun->sense_data = SS_COMMUNICATION_FAILURE;
963 curlun->sense_data_info = file_offset >> 9;
964 curlun->info_valid = 1;
965 break;
966 }
967
968 amount = bh->outreq->actual;
969 if (curlun->file_length - file_offset < amount) {
970 LERROR(curlun,
971 "write %u @ %llu beyond end %llu\n",
972 amount, (unsigned long long) file_offset,
973 (unsigned long long) curlun->file_length);
974 amount = curlun->file_length - file_offset;
975 }
976
977 /* Perform the write */
978 file_offset_tmp = file_offset;
979 nwritten = vfs_write(curlun->filp,
980 (char __user *) bh->buf,
981 amount, &file_offset_tmp);
982 VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
983 (unsigned long long) file_offset,
984 (int) nwritten);
985 if (signal_pending(current))
986 return -EINTR; /* Interrupted! */
987
988 if (nwritten < 0) {
989 LDBG(curlun, "error in file write: %d\n",
990 (int) nwritten);
991 nwritten = 0;
992 } else if (nwritten < amount) {
993 LDBG(curlun, "partial file write: %d/%u\n",
994 (int) nwritten, amount);
995 nwritten -= (nwritten & 511);
996 /* Round down to a block */
997 }
998 file_offset += nwritten;
999 amount_left_to_write -= nwritten;
1000 common->residue -= nwritten;
1001
1002 /* If an error occurred, report it and its position */
1003 if (nwritten < amount) {
1004 curlun->sense_data = SS_WRITE_ERROR;
1005 curlun->sense_data_info = file_offset >> 9;
1006 curlun->info_valid = 1;
1007 break;
1008 }
1009
1010 /* Did the host decide to stop early? */
1011 if (bh->outreq->actual != bh->outreq->length) {
1012 common->short_packet_received = 1;
1013 break;
1014 }
1015 continue;
1016 }
1017
1018 /* Wait for something to happen */
1019 rc = sleep_thread(common);
1020 if (rc)
1021 return rc;
1022 }
1023
1024 return -EIO; /* No default reply */
1025}
1026
1027
1028/*-------------------------------------------------------------------------*/
1029
1030static int do_synchronize_cache(struct fsg_common *common)
1031{
1032 struct fsg_lun *curlun = common->curlun;
1033 int rc;
1034
1035 /* We ignore the requested LBA and write out all file's
1036 * dirty data buffers. */
1037 rc = fsg_lun_fsync_sub(curlun);
1038 if (rc)
1039 curlun->sense_data = SS_WRITE_ERROR;
1040 return 0;
1041}
1042
1043
1044/*-------------------------------------------------------------------------*/
1045
1046static void invalidate_sub(struct fsg_lun *curlun)
1047{
1048 struct file *filp = curlun->filp;
1049 struct inode *inode = filp->f_path.dentry->d_inode;
1050 unsigned long rc;
1051
1052 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
1053 VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
1054}
1055
1056static int do_verify(struct fsg_common *common)
1057{
1058 struct fsg_lun *curlun = common->curlun;
1059 u32 lba;
1060 u32 verification_length;
1061 struct fsg_buffhd *bh = common->next_buffhd_to_fill;
1062 loff_t file_offset, file_offset_tmp;
1063 u32 amount_left;
1064 unsigned int amount;
1065 ssize_t nread;
1066
1067 /* Get the starting Logical Block Address and check that it's
1068 * not too big */
1069 lba = get_unaligned_be32(&common->cmnd[2]);
1070 if (lba >= curlun->num_sectors) {
1071 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1072 return -EINVAL;
1073 }
1074
1075 /* We allow DPO (Disable Page Out = don't save data in the
1076 * cache) but we don't implement it. */
1077 if (common->cmnd[1] & ~0x10) {
1078 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1079 return -EINVAL;
1080 }
1081
1082 verification_length = get_unaligned_be16(&common->cmnd[7]);
1083 if (unlikely(verification_length == 0))
1084 return -EIO; /* No default reply */
1085
1086 /* Prepare to carry out the file verify */
1087 amount_left = verification_length << 9;
1088 file_offset = ((loff_t) lba) << 9;
1089
1090 /* Write out all the dirty buffers before invalidating them */
1091 fsg_lun_fsync_sub(curlun);
1092 if (signal_pending(current))
1093 return -EINTR;
1094
1095 invalidate_sub(curlun);
1096 if (signal_pending(current))
1097 return -EINTR;
1098
1099 /* Just try to read the requested blocks */
1100 while (amount_left > 0) {
1101
1102 /* Figure out how much we need to read:
1103 * Try to read the remaining amount, but not more than
1104 * the buffer size.
1105 * And don't try to read past the end of the file.
1106 * If this means reading 0 then we were asked to read
1107 * past the end of file. */
1108 amount = min(amount_left, FSG_BUFLEN);
1109 amount = min((loff_t) amount,
1110 curlun->file_length - file_offset);
1111 if (amount == 0) {
1112 curlun->sense_data =
1113 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1114 curlun->sense_data_info = file_offset >> 9;
1115 curlun->info_valid = 1;
1116 break;
1117 }
1118
1119 /* Perform the read */
1120 file_offset_tmp = file_offset;
1121 nread = vfs_read(curlun->filp,
1122 (char __user *) bh->buf,
1123 amount, &file_offset_tmp);
1124 VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
1125 (unsigned long long) file_offset,
1126 (int) nread);
1127 if (signal_pending(current))
1128 return -EINTR;
1129
1130 if (nread < 0) {
1131 LDBG(curlun, "error in file verify: %d\n",
1132 (int) nread);
1133 nread = 0;
1134 } else if (nread < amount) {
1135 LDBG(curlun, "partial file verify: %d/%u\n",
1136 (int) nread, amount);
1137 nread -= (nread & 511); /* Round down to a sector */
1138 }
1139 if (nread == 0) {
1140 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
1141 curlun->sense_data_info = file_offset >> 9;
1142 curlun->info_valid = 1;
1143 break;
1144 }
1145 file_offset += nread;
1146 amount_left -= nread;
1147 }
1148 return 0;
1149}
1150
1151
1152/*-------------------------------------------------------------------------*/
1153
1154static int do_inquiry(struct fsg_common *common, struct fsg_buffhd *bh)
1155{
1156 struct fsg_lun *curlun = common->curlun;
1157 u8 *buf = (u8 *) bh->buf;
1158
1159 if (!curlun) { /* Unsupported LUNs are okay */
1160 common->bad_lun_okay = 1;
1161 memset(buf, 0, 36);
1162 buf[0] = 0x7f; /* Unsupported, no device-type */
1163 buf[4] = 31; /* Additional length */
1164 return 36;
1165 }
1166
1167 buf[0] = curlun->cdrom ? TYPE_CDROM : TYPE_DISK;
1168 buf[1] = curlun->removable ? 0x80 : 0;
1169 buf[2] = 2; /* ANSI SCSI level 2 */
1170 buf[3] = 2; /* SCSI-2 INQUIRY data format */
1171 buf[4] = 31; /* Additional length */
1172 buf[5] = 0; /* No special options */
1173 buf[6] = 0;
1174 buf[7] = 0;
1175 memcpy(buf + 8, common->inquiry_string, sizeof common->inquiry_string);
1176 return 36;
1177}
1178
1179
1180static int do_request_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1181{
1182 struct fsg_lun *curlun = common->curlun;
1183 u8 *buf = (u8 *) bh->buf;
1184 u32 sd, sdinfo;
1185 int valid;
1186
1187 /*
1188 * From the SCSI-2 spec., section 7.9 (Unit attention condition):
1189 *
1190 * If a REQUEST SENSE command is received from an initiator
1191 * with a pending unit attention condition (before the target
1192 * generates the contingent allegiance condition), then the
1193 * target shall either:
1194 * a) report any pending sense data and preserve the unit
1195 * attention condition on the logical unit, or,
1196 * b) report the unit attention condition, may discard any
1197 * pending sense data, and clear the unit attention
1198 * condition on the logical unit for that initiator.
1199 *
1200 * FSG normally uses option a); enable this code to use option b).
1201 */
1202#if 0
1203 if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
1204 curlun->sense_data = curlun->unit_attention_data;
1205 curlun->unit_attention_data = SS_NO_SENSE;
1206 }
1207#endif
1208
1209 if (!curlun) { /* Unsupported LUNs are okay */
1210 common->bad_lun_okay = 1;
1211 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
1212 sdinfo = 0;
1213 valid = 0;
1214 } else {
1215 sd = curlun->sense_data;
1216 sdinfo = curlun->sense_data_info;
1217 valid = curlun->info_valid << 7;
1218 curlun->sense_data = SS_NO_SENSE;
1219 curlun->sense_data_info = 0;
1220 curlun->info_valid = 0;
1221 }
1222
1223 memset(buf, 0, 18);
1224 buf[0] = valid | 0x70; /* Valid, current error */
1225 buf[2] = SK(sd);
1226 put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
1227 buf[7] = 18 - 8; /* Additional sense length */
1228 buf[12] = ASC(sd);
1229 buf[13] = ASCQ(sd);
1230 return 18;
1231}
1232
1233
1234static int do_read_capacity(struct fsg_common *common, struct fsg_buffhd *bh)
1235{
1236 struct fsg_lun *curlun = common->curlun;
1237 u32 lba = get_unaligned_be32(&common->cmnd[2]);
1238 int pmi = common->cmnd[8];
1239 u8 *buf = (u8 *) bh->buf;
1240
1241 /* Check the PMI and LBA fields */
1242 if (pmi > 1 || (pmi == 0 && lba != 0)) {
1243 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1244 return -EINVAL;
1245 }
1246
1247 put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
1248 /* Max logical block */
1249 put_unaligned_be32(512, &buf[4]); /* Block length */
1250 return 8;
1251}
1252
1253
1254static int do_read_header(struct fsg_common *common, struct fsg_buffhd *bh)
1255{
1256 struct fsg_lun *curlun = common->curlun;
1257 int msf = common->cmnd[1] & 0x02;
1258 u32 lba = get_unaligned_be32(&common->cmnd[2]);
1259 u8 *buf = (u8 *) bh->buf;
1260
1261 if (common->cmnd[1] & ~0x02) { /* Mask away MSF */
1262 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1263 return -EINVAL;
1264 }
1265 if (lba >= curlun->num_sectors) {
1266 curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1267 return -EINVAL;
1268 }
1269
1270 memset(buf, 0, 8);
1271 buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
1272 store_cdrom_address(&buf[4], msf, lba);
1273 return 8;
1274}
1275
1276
1277static int do_read_toc(struct fsg_common *common, struct fsg_buffhd *bh)
1278{
1279 struct fsg_lun *curlun = common->curlun;
1280 int msf = common->cmnd[1] & 0x02;
1281 int start_track = common->cmnd[6];
1282 u8 *buf = (u8 *) bh->buf;
1283
1284 if ((common->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
1285 start_track > 1) {
1286 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1287 return -EINVAL;
1288 }
1289
1290 memset(buf, 0, 20);
1291 buf[1] = (20-2); /* TOC data length */
1292 buf[2] = 1; /* First track number */
1293 buf[3] = 1; /* Last track number */
1294 buf[5] = 0x16; /* Data track, copying allowed */
1295 buf[6] = 0x01; /* Only track is number 1 */
1296 store_cdrom_address(&buf[8], msf, 0);
1297
1298 buf[13] = 0x16; /* Lead-out track is data */
1299 buf[14] = 0xAA; /* Lead-out track number */
1300 store_cdrom_address(&buf[16], msf, curlun->num_sectors);
1301 return 20;
1302}
1303
1304
1305static int do_mode_sense(struct fsg_common *common, struct fsg_buffhd *bh)
1306{
1307 struct fsg_lun *curlun = common->curlun;
1308 int mscmnd = common->cmnd[0];
1309 u8 *buf = (u8 *) bh->buf;
1310 u8 *buf0 = buf;
1311 int pc, page_code;
1312 int changeable_values, all_pages;
1313 int valid_page = 0;
1314 int len, limit;
1315
1316 if ((common->cmnd[1] & ~0x08) != 0) { /* Mask away DBD */
1317 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1318 return -EINVAL;
1319 }
1320 pc = common->cmnd[2] >> 6;
1321 page_code = common->cmnd[2] & 0x3f;
1322 if (pc == 3) {
1323 curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
1324 return -EINVAL;
1325 }
1326 changeable_values = (pc == 1);
1327 all_pages = (page_code == 0x3f);
1328
1329 /* Write the mode parameter header. Fixed values are: default
1330 * medium type, no cache control (DPOFUA), and no block descriptors.
1331 * The only variable value is the WriteProtect bit. We will fill in
1332 * the mode data length later. */
1333 memset(buf, 0, 8);
1334 if (mscmnd == SC_MODE_SENSE_6) {
1335 buf[2] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1336 buf += 4;
1337 limit = 255;
1338 } else { /* SC_MODE_SENSE_10 */
1339 buf[3] = (curlun->ro ? 0x80 : 0x00); /* WP, DPOFUA */
1340 buf += 8;
1341 limit = 65535; /* Should really be FSG_BUFLEN */
1342 }
1343
1344 /* No block descriptors */
1345
1346 /* The mode pages, in numerical order. The only page we support
1347 * is the Caching page. */
1348 if (page_code == 0x08 || all_pages) {
1349 valid_page = 1;
1350 buf[0] = 0x08; /* Page code */
1351 buf[1] = 10; /* Page length */
1352 memset(buf+2, 0, 10); /* None of the fields are changeable */
1353
1354 if (!changeable_values) {
1355 buf[2] = 0x04; /* Write cache enable, */
1356 /* Read cache not disabled */
1357 /* No cache retention priorities */
1358 put_unaligned_be16(0xffff, &buf[4]);
1359 /* Don't disable prefetch */
1360 /* Minimum prefetch = 0 */
1361 put_unaligned_be16(0xffff, &buf[8]);
1362 /* Maximum prefetch */
1363 put_unaligned_be16(0xffff, &buf[10]);
1364 /* Maximum prefetch ceiling */
1365 }
1366 buf += 12;
1367 }
1368
1369 /* Check that a valid page was requested and the mode data length
1370 * isn't too long. */
1371 len = buf - buf0;
1372 if (!valid_page || len > limit) {
1373 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1374 return -EINVAL;
1375 }
1376
1377 /* Store the mode data length */
1378 if (mscmnd == SC_MODE_SENSE_6)
1379 buf0[0] = len - 1;
1380 else
1381 put_unaligned_be16(len - 2, buf0);
1382 return len;
1383}
1384
1385
1386static int do_start_stop(struct fsg_common *common)
1387{
1388 if (!common->curlun) {
1389 return -EINVAL;
1390 } else if (!common->curlun->removable) {
1391 common->curlun->sense_data = SS_INVALID_COMMAND;
1392 return -EINVAL;
1393 }
1394 return 0;
1395}
1396
1397
1398static int do_prevent_allow(struct fsg_common *common)
1399{
1400 struct fsg_lun *curlun = common->curlun;
1401 int prevent;
1402
1403 if (!common->curlun) {
1404 return -EINVAL;
1405 } else if (!common->curlun->removable) {
1406 common->curlun->sense_data = SS_INVALID_COMMAND;
1407 return -EINVAL;
1408 }
1409
1410 prevent = common->cmnd[4] & 0x01;
1411 if ((common->cmnd[4] & ~0x01) != 0) { /* Mask away Prevent */
1412 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1413 return -EINVAL;
1414 }
1415
1416 if (curlun->prevent_medium_removal && !prevent)
1417 fsg_lun_fsync_sub(curlun);
1418 curlun->prevent_medium_removal = prevent;
1419 return 0;
1420}
1421
1422
1423static int do_read_format_capacities(struct fsg_common *common,
1424 struct fsg_buffhd *bh)
1425{
1426 struct fsg_lun *curlun = common->curlun;
1427 u8 *buf = (u8 *) bh->buf;
1428
1429 buf[0] = buf[1] = buf[2] = 0;
1430 buf[3] = 8; /* Only the Current/Maximum Capacity Descriptor */
1431 buf += 4;
1432
1433 put_unaligned_be32(curlun->num_sectors, &buf[0]);
1434 /* Number of blocks */
1435 put_unaligned_be32(512, &buf[4]); /* Block length */
1436 buf[4] = 0x02; /* Current capacity */
1437 return 12;
1438}
1439
1440
1441static int do_mode_select(struct fsg_common *common, struct fsg_buffhd *bh)
1442{
1443 struct fsg_lun *curlun = common->curlun;
1444
1445 /* We don't support MODE SELECT */
1446 if (curlun)
1447 curlun->sense_data = SS_INVALID_COMMAND;
1448 return -EINVAL;
1449}
1450
1451
1452/*-------------------------------------------------------------------------*/
1453
1454static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
1455{
1456 int rc;
1457
1458 rc = fsg_set_halt(fsg, fsg->bulk_in);
1459 if (rc == -EAGAIN)
1460 VDBG(fsg, "delayed bulk-in endpoint halt\n");
1461 while (rc != 0) {
1462 if (rc != -EAGAIN) {
1463 WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
1464 rc = 0;
1465 break;
1466 }
1467
1468 /* Wait for a short time and then try again */
1469 if (msleep_interruptible(100) != 0)
1470 return -EINTR;
1471 rc = usb_ep_set_halt(fsg->bulk_in);
1472 }
1473 return rc;
1474}
1475
1476static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
1477{
1478 int rc;
1479
1480 DBG(fsg, "bulk-in set wedge\n");
1481 rc = usb_ep_set_wedge(fsg->bulk_in);
1482 if (rc == -EAGAIN)
1483 VDBG(fsg, "delayed bulk-in endpoint wedge\n");
1484 while (rc != 0) {
1485 if (rc != -EAGAIN) {
1486 WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
1487 rc = 0;
1488 break;
1489 }
1490
1491 /* Wait for a short time and then try again */
1492 if (msleep_interruptible(100) != 0)
1493 return -EINTR;
1494 rc = usb_ep_set_wedge(fsg->bulk_in);
1495 }
1496 return rc;
1497}
1498
1499static int pad_with_zeros(struct fsg_dev *fsg)
1500{
1501 struct fsg_buffhd *bh = fsg->common->next_buffhd_to_fill;
1502 u32 nkeep = bh->inreq->length;
1503 u32 nsend;
1504 int rc;
1505
1506 bh->state = BUF_STATE_EMPTY; /* For the first iteration */
1507 fsg->common->usb_amount_left = nkeep + fsg->common->residue;
1508 while (fsg->common->usb_amount_left > 0) {
1509
1510 /* Wait for the next buffer to be free */
1511 while (bh->state != BUF_STATE_EMPTY) {
1512 rc = sleep_thread(fsg->common);
1513 if (rc)
1514 return rc;
1515 }
1516
1517 nsend = min(fsg->common->usb_amount_left, FSG_BUFLEN);
1518 memset(bh->buf + nkeep, 0, nsend - nkeep);
1519 bh->inreq->length = nsend;
1520 bh->inreq->zero = 0;
1521 start_transfer(fsg, fsg->bulk_in, bh->inreq,
1522 &bh->inreq_busy, &bh->state);
1523 bh = fsg->common->next_buffhd_to_fill = bh->next;
1524 fsg->common->usb_amount_left -= nsend;
1525 nkeep = 0;
1526 }
1527 return 0;
1528}
1529
1530static int throw_away_data(struct fsg_common *common)
1531{
1532 struct fsg_buffhd *bh;
1533 u32 amount;
1534 int rc;
1535
1536 for (bh = common->next_buffhd_to_drain;
1537 bh->state != BUF_STATE_EMPTY || common->usb_amount_left > 0;
1538 bh = common->next_buffhd_to_drain) {
1539
1540 /* Throw away the data in a filled buffer */
1541 if (bh->state == BUF_STATE_FULL) {
1542 smp_rmb();
1543 bh->state = BUF_STATE_EMPTY;
1544 common->next_buffhd_to_drain = bh->next;
1545
1546 /* A short packet or an error ends everything */
1547 if (bh->outreq->actual != bh->outreq->length ||
1548 bh->outreq->status != 0) {
1549 raise_exception(common,
1550 FSG_STATE_ABORT_BULK_OUT);
1551 return -EINTR;
1552 }
1553 continue;
1554 }
1555
1556 /* Try to submit another request if we need one */
1557 bh = common->next_buffhd_to_fill;
1558 if (bh->state == BUF_STATE_EMPTY
1559 && common->usb_amount_left > 0) {
1560 amount = min(common->usb_amount_left, FSG_BUFLEN);
1561
1562 /* amount is always divisible by 512, hence by
1563 * the bulk-out maxpacket size */
1564 bh->outreq->length = amount;
1565 bh->bulk_out_intended_length = amount;
1566 bh->outreq->short_not_ok = 1;
1567 START_TRANSFER_OR(common, bulk_out, bh->outreq,
1568 &bh->outreq_busy, &bh->state)
1569 /* Don't know what to do if
1570 * common->fsg is NULL */
1571 return -EIO;
1572 common->next_buffhd_to_fill = bh->next;
1573 common->usb_amount_left -= amount;
1574 continue;
1575 }
1576
1577 /* Otherwise wait for something to happen */
1578 rc = sleep_thread(common);
1579 if (rc)
1580 return rc;
1581 }
1582 return 0;
1583}
1584
1585
1586static int finish_reply(struct fsg_common *common)
1587{
1588 struct fsg_buffhd *bh = common->next_buffhd_to_fill;
1589 int rc = 0;
1590
1591 switch (common->data_dir) {
1592 case DATA_DIR_NONE:
1593 break; /* Nothing to send */
1594
1595 /* If we don't know whether the host wants to read or write,
1596 * this must be CB or CBI with an unknown command. We mustn't
1597 * try to send or receive any data. So stall both bulk pipes
1598 * if we can and wait for a reset. */
1599 case DATA_DIR_UNKNOWN:
1600 if (!common->can_stall) {
1601 /* Nothing */
1602 } else if (fsg_is_set(common)) {
1603 fsg_set_halt(common->fsg, common->fsg->bulk_out);
1604 rc = halt_bulk_in_endpoint(common->fsg);
1605 } else {
1606 /* Don't know what to do if common->fsg is NULL */
1607 rc = -EIO;
1608 }
1609 break;
1610
1611 /* All but the last buffer of data must have already been sent */
1612 case DATA_DIR_TO_HOST:
1613 if (common->data_size == 0) {
1614 /* Nothing to send */
1615
1616 /* If there's no residue, simply send the last buffer */
1617 } else if (common->residue == 0) {
1618 bh->inreq->zero = 0;
1619 START_TRANSFER_OR(common, bulk_in, bh->inreq,
1620 &bh->inreq_busy, &bh->state)
1621 return -EIO;
1622 common->next_buffhd_to_fill = bh->next;
1623
1624 /* For Bulk-only, if we're allowed to stall then send the
1625 * short packet and halt the bulk-in endpoint. If we can't
1626 * stall, pad out the remaining data with 0's. */
1627 } else if (common->can_stall) {
1628 bh->inreq->zero = 1;
1629 START_TRANSFER_OR(common, bulk_in, bh->inreq,
1630 &bh->inreq_busy, &bh->state)
1631 /* Don't know what to do if
1632 * common->fsg is NULL */
1633 rc = -EIO;
1634 common->next_buffhd_to_fill = bh->next;
1635 if (common->fsg)
1636 rc = halt_bulk_in_endpoint(common->fsg);
1637 } else if (fsg_is_set(common)) {
1638 rc = pad_with_zeros(common->fsg);
1639 } else {
1640 /* Don't know what to do if common->fsg is NULL */
1641 rc = -EIO;
1642 }
1643 break;
1644
1645 /* We have processed all we want from the data the host has sent.
1646 * There may still be outstanding bulk-out requests. */
1647 case DATA_DIR_FROM_HOST:
1648 if (common->residue == 0) {
1649 /* Nothing to receive */
1650
1651 /* Did the host stop sending unexpectedly early? */
1652 } else if (common->short_packet_received) {
1653 raise_exception(common, FSG_STATE_ABORT_BULK_OUT);
1654 rc = -EINTR;
1655
1656 /* We haven't processed all the incoming data. Even though
1657 * we may be allowed to stall, doing so would cause a race.
1658 * The controller may already have ACK'ed all the remaining
1659 * bulk-out packets, in which case the host wouldn't see a
1660 * STALL. Not realizing the endpoint was halted, it wouldn't
1661 * clear the halt -- leading to problems later on. */
1662#if 0
1663 } else if (common->can_stall) {
1664 if (fsg_is_set(common))
1665 fsg_set_halt(common->fsg,
1666 common->fsg->bulk_out);
1667 raise_exception(common, FSG_STATE_ABORT_BULK_OUT);
1668 rc = -EINTR;
1669#endif
1670
1671 /* We can't stall. Read in the excess data and throw it
1672 * all away. */
1673 } else {
1674 rc = throw_away_data(common);
1675 }
1676 break;
1677 }
1678 return rc;
1679}
1680
1681
1682static int send_status(struct fsg_common *common)
1683{
1684 struct fsg_lun *curlun = common->curlun;
1685 struct fsg_buffhd *bh;
1686 struct bulk_cs_wrap *csw;
1687 int rc;
1688 u8 status = USB_STATUS_PASS;
1689 u32 sd, sdinfo = 0;
1690
1691 /* Wait for the next buffer to become available */
1692 bh = common->next_buffhd_to_fill;
1693 while (bh->state != BUF_STATE_EMPTY) {
1694 rc = sleep_thread(common);
1695 if (rc)
1696 return rc;
1697 }
1698
1699 if (curlun) {
1700 sd = curlun->sense_data;
1701 sdinfo = curlun->sense_data_info;
1702 } else if (common->bad_lun_okay)
1703 sd = SS_NO_SENSE;
1704 else
1705 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
1706
1707 if (common->phase_error) {
1708 DBG(common, "sending phase-error status\n");
1709 status = USB_STATUS_PHASE_ERROR;
1710 sd = SS_INVALID_COMMAND;
1711 } else if (sd != SS_NO_SENSE) {
1712 DBG(common, "sending command-failure status\n");
1713 status = USB_STATUS_FAIL;
1714 VDBG(common, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
1715 " info x%x\n",
1716 SK(sd), ASC(sd), ASCQ(sd), sdinfo);
1717 }
1718
1719 /* Store and send the Bulk-only CSW */
1720 csw = (void *)bh->buf;
1721
1722 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
1723 csw->Tag = common->tag;
1724 csw->Residue = cpu_to_le32(common->residue);
1725 csw->Status = status;
1726
1727 bh->inreq->length = USB_BULK_CS_WRAP_LEN;
1728 bh->inreq->zero = 0;
1729 START_TRANSFER_OR(common, bulk_in, bh->inreq,
1730 &bh->inreq_busy, &bh->state)
1731 /* Don't know what to do if common->fsg is NULL */
1732 return -EIO;
1733
1734 common->next_buffhd_to_fill = bh->next;
1735 return 0;
1736}
1737
1738
1739/*-------------------------------------------------------------------------*/
1740
1741/* Check whether the command is properly formed and whether its data size
1742 * and direction agree with the values we already have. */
1743static int check_command(struct fsg_common *common, int cmnd_size,
1744 enum data_direction data_dir, unsigned int mask,
1745 int needs_medium, const char *name)
1746{
1747 int i;
1748 int lun = common->cmnd[1] >> 5;
1749 static const char dirletter[4] = {'u', 'o', 'i', 'n'};
1750 char hdlen[20];
1751 struct fsg_lun *curlun;
1752
1753 hdlen[0] = 0;
1754 if (common->data_dir != DATA_DIR_UNKNOWN)
1755 sprintf(hdlen, ", H%c=%u", dirletter[(int) common->data_dir],
1756 common->data_size);
1757 VDBG(common, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
1758 name, cmnd_size, dirletter[(int) data_dir],
1759 common->data_size_from_cmnd, common->cmnd_size, hdlen);
1760
1761 /* We can't reply at all until we know the correct data direction
1762 * and size. */
1763 if (common->data_size_from_cmnd == 0)
1764 data_dir = DATA_DIR_NONE;
1765 if (common->data_size < common->data_size_from_cmnd) {
1766 /* Host data size < Device data size is a phase error.
1767 * Carry out the command, but only transfer as much as
1768 * we are allowed. */
1769 common->data_size_from_cmnd = common->data_size;
1770 common->phase_error = 1;
1771 }
1772 common->residue = common->data_size;
1773 common->usb_amount_left = common->data_size;
1774
1775 /* Conflicting data directions is a phase error */
1776 if (common->data_dir != data_dir
1777 && common->data_size_from_cmnd > 0) {
1778 common->phase_error = 1;
1779 return -EINVAL;
1780 }
1781
1782 /* Verify the length of the command itself */
1783 if (cmnd_size != common->cmnd_size) {
1784
1785 /* Special case workaround: There are plenty of buggy SCSI
1786 * implementations. Many have issues with cbw->Length
1787 * field passing a wrong command size. For those cases we
1788 * always try to work around the problem by using the length
1789 * sent by the host side provided it is at least as large
1790 * as the correct command length.
1791 * Examples of such cases would be MS-Windows, which issues
1792 * REQUEST SENSE with cbw->Length == 12 where it should
1793 * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
1794 * REQUEST SENSE with cbw->Length == 10 where it should
1795 * be 6 as well.
1796 */
1797 if (cmnd_size <= common->cmnd_size) {
1798 DBG(common, "%s is buggy! Expected length %d "
1799 "but we got %d\n", name,
1800 cmnd_size, common->cmnd_size);
1801 cmnd_size = common->cmnd_size;
1802 } else {
1803 common->phase_error = 1;
1804 return -EINVAL;
1805 }
1806 }
1807
1808 /* Check that the LUN values are consistent */
1809 if (common->lun != lun)
1810 DBG(common, "using LUN %d from CBW, not LUN %d from CDB\n",
1811 common->lun, lun);
1812
1813 /* Check the LUN */
1814 if (common->lun >= 0 && common->lun < common->nluns) {
1815 curlun = &common->luns[common->lun];
1816 common->curlun = curlun;
1817 if (common->cmnd[0] != SC_REQUEST_SENSE) {
1818 curlun->sense_data = SS_NO_SENSE;
1819 curlun->sense_data_info = 0;
1820 curlun->info_valid = 0;
1821 }
1822 } else {
1823 common->curlun = NULL;
1824 curlun = NULL;
1825 common->bad_lun_okay = 0;
1826
1827 /* INQUIRY and REQUEST SENSE commands are explicitly allowed
1828 * to use unsupported LUNs; all others may not. */
1829 if (common->cmnd[0] != SC_INQUIRY &&
1830 common->cmnd[0] != SC_REQUEST_SENSE) {
1831 DBG(common, "unsupported LUN %d\n", common->lun);
1832 return -EINVAL;
1833 }
1834 }
1835
1836 /* If a unit attention condition exists, only INQUIRY and
1837 * REQUEST SENSE commands are allowed; anything else must fail. */
1838 if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
1839 common->cmnd[0] != SC_INQUIRY &&
1840 common->cmnd[0] != SC_REQUEST_SENSE) {
1841 curlun->sense_data = curlun->unit_attention_data;
1842 curlun->unit_attention_data = SS_NO_SENSE;
1843 return -EINVAL;
1844 }
1845
1846 /* Check that only command bytes listed in the mask are non-zero */
1847 common->cmnd[1] &= 0x1f; /* Mask away the LUN */
1848 for (i = 1; i < cmnd_size; ++i) {
1849 if (common->cmnd[i] && !(mask & (1 << i))) {
1850 if (curlun)
1851 curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
1852 return -EINVAL;
1853 }
1854 }
1855
1856 /* If the medium isn't mounted and the command needs to access
1857 * it, return an error. */
1858 if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
1859 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
1860 return -EINVAL;
1861 }
1862
1863 return 0;
1864}
1865
1866
1867static int do_scsi_command(struct fsg_common *common)
1868{
1869 struct fsg_buffhd *bh;
1870 int rc;
1871 int reply = -EINVAL;
1872 int i;
1873 static char unknown[16];
1874
1875 dump_cdb(common);
1876
1877 /* Wait for the next buffer to become available for data or status */
1878 bh = common->next_buffhd_to_fill;
1879 common->next_buffhd_to_drain = bh;
1880 while (bh->state != BUF_STATE_EMPTY) {
1881 rc = sleep_thread(common);
1882 if (rc)
1883 return rc;
1884 }
1885 common->phase_error = 0;
1886 common->short_packet_received = 0;
1887
1888 down_read(&common->filesem); /* We're using the backing file */
1889 switch (common->cmnd[0]) {
1890
1891 case SC_INQUIRY:
1892 common->data_size_from_cmnd = common->cmnd[4];
1893 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1894 (1<<4), 0,
1895 "INQUIRY");
1896 if (reply == 0)
1897 reply = do_inquiry(common, bh);
1898 break;
1899
1900 case SC_MODE_SELECT_6:
1901 common->data_size_from_cmnd = common->cmnd[4];
1902 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
1903 (1<<1) | (1<<4), 0,
1904 "MODE SELECT(6)");
1905 if (reply == 0)
1906 reply = do_mode_select(common, bh);
1907 break;
1908
1909 case SC_MODE_SELECT_10:
1910 common->data_size_from_cmnd =
1911 get_unaligned_be16(&common->cmnd[7]);
1912 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
1913 (1<<1) | (3<<7), 0,
1914 "MODE SELECT(10)");
1915 if (reply == 0)
1916 reply = do_mode_select(common, bh);
1917 break;
1918
1919 case SC_MODE_SENSE_6:
1920 common->data_size_from_cmnd = common->cmnd[4];
1921 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1922 (1<<1) | (1<<2) | (1<<4), 0,
1923 "MODE SENSE(6)");
1924 if (reply == 0)
1925 reply = do_mode_sense(common, bh);
1926 break;
1927
1928 case SC_MODE_SENSE_10:
1929 common->data_size_from_cmnd =
1930 get_unaligned_be16(&common->cmnd[7]);
1931 reply = check_command(common, 10, DATA_DIR_TO_HOST,
1932 (1<<1) | (1<<2) | (3<<7), 0,
1933 "MODE SENSE(10)");
1934 if (reply == 0)
1935 reply = do_mode_sense(common, bh);
1936 break;
1937
1938 case SC_PREVENT_ALLOW_MEDIUM_REMOVAL:
1939 common->data_size_from_cmnd = 0;
1940 reply = check_command(common, 6, DATA_DIR_NONE,
1941 (1<<4), 0,
1942 "PREVENT-ALLOW MEDIUM REMOVAL");
1943 if (reply == 0)
1944 reply = do_prevent_allow(common);
1945 break;
1946
1947 case SC_READ_6:
1948 i = common->cmnd[4];
1949 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
1950 reply = check_command(common, 6, DATA_DIR_TO_HOST,
1951 (7<<1) | (1<<4), 1,
1952 "READ(6)");
1953 if (reply == 0)
1954 reply = do_read(common);
1955 break;
1956
1957 case SC_READ_10:
1958 common->data_size_from_cmnd =
1959 get_unaligned_be16(&common->cmnd[7]) << 9;
1960 reply = check_command(common, 10, DATA_DIR_TO_HOST,
1961 (1<<1) | (0xf<<2) | (3<<7), 1,
1962 "READ(10)");
1963 if (reply == 0)
1964 reply = do_read(common);
1965 break;
1966
1967 case SC_READ_12:
1968 common->data_size_from_cmnd =
1969 get_unaligned_be32(&common->cmnd[6]) << 9;
1970 reply = check_command(common, 12, DATA_DIR_TO_HOST,
1971 (1<<1) | (0xf<<2) | (0xf<<6), 1,
1972 "READ(12)");
1973 if (reply == 0)
1974 reply = do_read(common);
1975 break;
1976
1977 case SC_READ_CAPACITY:
1978 common->data_size_from_cmnd = 8;
1979 reply = check_command(common, 10, DATA_DIR_TO_HOST,
1980 (0xf<<2) | (1<<8), 1,
1981 "READ CAPACITY");
1982 if (reply == 0)
1983 reply = do_read_capacity(common, bh);
1984 break;
1985
1986 case SC_READ_HEADER:
1987 if (!common->curlun || !common->curlun->cdrom)
1988 goto unknown_cmnd;
1989 common->data_size_from_cmnd =
1990 get_unaligned_be16(&common->cmnd[7]);
1991 reply = check_command(common, 10, DATA_DIR_TO_HOST,
1992 (3<<7) | (0x1f<<1), 1,
1993 "READ HEADER");
1994 if (reply == 0)
1995 reply = do_read_header(common, bh);
1996 break;
1997
1998 case SC_READ_TOC:
1999 if (!common->curlun || !common->curlun->cdrom)
2000 goto unknown_cmnd;
2001 common->data_size_from_cmnd =
2002 get_unaligned_be16(&common->cmnd[7]);
2003 reply = check_command(common, 10, DATA_DIR_TO_HOST,
2004 (7<<6) | (1<<1), 1,
2005 "READ TOC");
2006 if (reply == 0)
2007 reply = do_read_toc(common, bh);
2008 break;
2009
2010 case SC_READ_FORMAT_CAPACITIES:
2011 common->data_size_from_cmnd =
2012 get_unaligned_be16(&common->cmnd[7]);
2013 reply = check_command(common, 10, DATA_DIR_TO_HOST,
2014 (3<<7), 1,
2015 "READ FORMAT CAPACITIES");
2016 if (reply == 0)
2017 reply = do_read_format_capacities(common, bh);
2018 break;
2019
2020 case SC_REQUEST_SENSE:
2021 common->data_size_from_cmnd = common->cmnd[4];
2022 reply = check_command(common, 6, DATA_DIR_TO_HOST,
2023 (1<<4), 0,
2024 "REQUEST SENSE");
2025 if (reply == 0)
2026 reply = do_request_sense(common, bh);
2027 break;
2028
2029 case SC_START_STOP_UNIT:
2030 common->data_size_from_cmnd = 0;
2031 reply = check_command(common, 6, DATA_DIR_NONE,
2032 (1<<1) | (1<<4), 0,
2033 "START-STOP UNIT");
2034 if (reply == 0)
2035 reply = do_start_stop(common);
2036 break;
2037
2038 case SC_SYNCHRONIZE_CACHE:
2039 common->data_size_from_cmnd = 0;
2040 reply = check_command(common, 10, DATA_DIR_NONE,
2041 (0xf<<2) | (3<<7), 1,
2042 "SYNCHRONIZE CACHE");
2043 if (reply == 0)
2044 reply = do_synchronize_cache(common);
2045 break;
2046
2047 case SC_TEST_UNIT_READY:
2048 common->data_size_from_cmnd = 0;
2049 reply = check_command(common, 6, DATA_DIR_NONE,
2050 0, 1,
2051 "TEST UNIT READY");
2052 break;
2053
2054 /* Although optional, this command is used by MS-Windows. We
2055 * support a minimal version: BytChk must be 0. */
2056 case SC_VERIFY:
2057 common->data_size_from_cmnd = 0;
2058 reply = check_command(common, 10, DATA_DIR_NONE,
2059 (1<<1) | (0xf<<2) | (3<<7), 1,
2060 "VERIFY");
2061 if (reply == 0)
2062 reply = do_verify(common);
2063 break;
2064
2065 case SC_WRITE_6:
2066 i = common->cmnd[4];
2067 common->data_size_from_cmnd = (i == 0 ? 256 : i) << 9;
2068 reply = check_command(common, 6, DATA_DIR_FROM_HOST,
2069 (7<<1) | (1<<4), 1,
2070 "WRITE(6)");
2071 if (reply == 0)
2072 reply = do_write(common);
2073 break;
2074
2075 case SC_WRITE_10:
2076 common->data_size_from_cmnd =
2077 get_unaligned_be16(&common->cmnd[7]) << 9;
2078 reply = check_command(common, 10, DATA_DIR_FROM_HOST,
2079 (1<<1) | (0xf<<2) | (3<<7), 1,
2080 "WRITE(10)");
2081 if (reply == 0)
2082 reply = do_write(common);
2083 break;
2084
2085 case SC_WRITE_12:
2086 common->data_size_from_cmnd =
2087 get_unaligned_be32(&common->cmnd[6]) << 9;
2088 reply = check_command(common, 12, DATA_DIR_FROM_HOST,
2089 (1<<1) | (0xf<<2) | (0xf<<6), 1,
2090 "WRITE(12)");
2091 if (reply == 0)
2092 reply = do_write(common);
2093 break;
2094
2095 /* Some mandatory commands that we recognize but don't implement.
2096 * They don't mean much in this setting. It's left as an exercise
2097 * for anyone interested to implement RESERVE and RELEASE in terms
2098 * of Posix locks. */
2099 case SC_FORMAT_UNIT:
2100 case SC_RELEASE:
2101 case SC_RESERVE:
2102 case SC_SEND_DIAGNOSTIC:
2103 /* Fall through */
2104
2105 default:
2106unknown_cmnd:
2107 common->data_size_from_cmnd = 0;
2108 sprintf(unknown, "Unknown x%02x", common->cmnd[0]);
2109 reply = check_command(common, common->cmnd_size,
2110 DATA_DIR_UNKNOWN, 0xff, 0, unknown);
2111 if (reply == 0) {
2112 common->curlun->sense_data = SS_INVALID_COMMAND;
2113 reply = -EINVAL;
2114 }
2115 break;
2116 }
2117 up_read(&common->filesem);
2118
2119 if (reply == -EINTR || signal_pending(current))
2120 return -EINTR;
2121
2122 /* Set up the single reply buffer for finish_reply() */
2123 if (reply == -EINVAL)
2124 reply = 0; /* Error reply length */
2125 if (reply >= 0 && common->data_dir == DATA_DIR_TO_HOST) {
2126 reply = min((u32) reply, common->data_size_from_cmnd);
2127 bh->inreq->length = reply;
2128 bh->state = BUF_STATE_FULL;
2129 common->residue -= reply;
2130 } /* Otherwise it's already set */
2131
2132 return 0;
2133}
2134
2135
2136/*-------------------------------------------------------------------------*/
2137
2138static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2139{
2140 struct usb_request *req = bh->outreq;
2141 struct fsg_bulk_cb_wrap *cbw = req->buf;
2142 struct fsg_common *common = fsg->common;
2143
2144 /* Was this a real packet? Should it be ignored? */
2145 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
2146 return -EINVAL;
2147
2148 /* Is the CBW valid? */
2149 if (req->actual != USB_BULK_CB_WRAP_LEN ||
2150 cbw->Signature != cpu_to_le32(
2151 USB_BULK_CB_SIG)) {
2152 DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
2153 req->actual,
2154 le32_to_cpu(cbw->Signature));
2155
2156 /* The Bulk-only spec says we MUST stall the IN endpoint
2157 * (6.6.1), so it's unavoidable. It also says we must
2158 * retain this state until the next reset, but there's
2159 * no way to tell the controller driver it should ignore
2160 * Clear-Feature(HALT) requests.
2161 *
2162 * We aren't required to halt the OUT endpoint; instead
2163 * we can simply accept and discard any data received
2164 * until the next reset. */
2165 wedge_bulk_in_endpoint(fsg);
2166 set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2167 return -EINVAL;
2168 }
2169
2170 /* Is the CBW meaningful? */
2171 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG ||
2172 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
2173 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
2174 "cmdlen %u\n",
2175 cbw->Lun, cbw->Flags, cbw->Length);
2176
2177 /* We can do anything we want here, so let's stall the
2178 * bulk pipes if we are allowed to. */
2179 if (common->can_stall) {
2180 fsg_set_halt(fsg, fsg->bulk_out);
2181 halt_bulk_in_endpoint(fsg);
2182 }
2183 return -EINVAL;
2184 }
2185
2186 /* Save the command for later */
2187 common->cmnd_size = cbw->Length;
2188 memcpy(common->cmnd, cbw->CDB, common->cmnd_size);
2189 if (cbw->Flags & USB_BULK_IN_FLAG)
2190 common->data_dir = DATA_DIR_TO_HOST;
2191 else
2192 common->data_dir = DATA_DIR_FROM_HOST;
2193 common->data_size = le32_to_cpu(cbw->DataTransferLength);
2194 if (common->data_size == 0)
2195 common->data_dir = DATA_DIR_NONE;
2196 common->lun = cbw->Lun;
2197 common->tag = cbw->Tag;
2198 return 0;
2199}
2200
2201
2202static int get_next_command(struct fsg_common *common)
2203{
2204 struct fsg_buffhd *bh;
2205 int rc = 0;
2206
2207 /* Wait for the next buffer to become available */
2208 bh = common->next_buffhd_to_fill;
2209 while (bh->state != BUF_STATE_EMPTY) {
2210 rc = sleep_thread(common);
2211 if (rc)
2212 return rc;
2213 }
2214
2215 /* Queue a request to read a Bulk-only CBW */
2216 set_bulk_out_req_length(common, bh, USB_BULK_CB_WRAP_LEN);
2217 bh->outreq->short_not_ok = 1;
2218 START_TRANSFER_OR(common, bulk_out, bh->outreq,
2219 &bh->outreq_busy, &bh->state)
2220 /* Don't know what to do if common->fsg is NULL */
2221 return -EIO;
2222
2223 /* We will drain the buffer in software, which means we
2224 * can reuse it for the next filling. No need to advance
2225 * next_buffhd_to_fill. */
2226
2227 /* Wait for the CBW to arrive */
2228 while (bh->state != BUF_STATE_FULL) {
2229 rc = sleep_thread(common);
2230 if (rc)
2231 return rc;
2232 }
2233 smp_rmb();
2234 rc = fsg_is_set(common) ? received_cbw(common->fsg, bh) : -EIO;
2235 bh->state = BUF_STATE_EMPTY;
2236
2237 return rc;
2238}
2239
2240
2241/*-------------------------------------------------------------------------*/
2242
2243static int enable_endpoint(struct fsg_common *common, struct usb_ep *ep,
2244 const struct usb_endpoint_descriptor *d)
2245{
2246 int rc;
2247
2248 ep->driver_data = common;
2249 rc = usb_ep_enable(ep, d);
2250 if (rc)
2251 ERROR(common, "can't enable %s, result %d\n", ep->name, rc);
2252 return rc;
2253}
2254
2255static int alloc_request(struct fsg_common *common, struct usb_ep *ep,
2256 struct usb_request **preq)
2257{
2258 *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
2259 if (*preq)
2260 return 0;
2261 ERROR(common, "can't allocate request for %s\n", ep->name);
2262 return -ENOMEM;
2263}
2264
2265/*
2266 * Reset interface setting and re-init endpoint state (toggle etc).
2267 * Call with altsetting < 0 to disable the interface. The only other
2268 * available altsetting is 0, which enables the interface.
2269 */
2270static int do_set_interface(struct fsg_common *common, int altsetting)
2271{
2272 int rc = 0;
2273 int i;
2274 const struct usb_endpoint_descriptor *d;
2275
2276 if (common->running)
2277 DBG(common, "reset interface\n");
2278
2279reset:
2280 /* Deallocate the requests */
2281 if (common->prev_fsg) {
2282 struct fsg_dev *fsg = common->prev_fsg;
2283
2284 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2285 struct fsg_buffhd *bh = &common->buffhds[i];
2286
2287 if (bh->inreq) {
2288 usb_ep_free_request(fsg->bulk_in, bh->inreq);
2289 bh->inreq = NULL;
2290 }
2291 if (bh->outreq) {
2292 usb_ep_free_request(fsg->bulk_out, bh->outreq);
2293 bh->outreq = NULL;
2294 }
2295 }
2296
2297 /* Disable the endpoints */
2298 if (fsg->bulk_in_enabled) {
2299 usb_ep_disable(fsg->bulk_in);
2300 fsg->bulk_in_enabled = 0;
2301 }
2302 if (fsg->bulk_out_enabled) {
2303 usb_ep_disable(fsg->bulk_out);
2304 fsg->bulk_out_enabled = 0;
2305 }
2306
2307 common->prev_fsg = 0;
2308 }
2309
2310 common->running = 0;
2311 if (altsetting < 0 || rc != 0)
2312 return rc;
2313
2314 DBG(common, "set interface %d\n", altsetting);
2315
2316 if (fsg_is_set(common)) {
2317 struct fsg_dev *fsg = common->fsg;
2318 common->prev_fsg = common->fsg;
2319
2320 /* Enable the endpoints */
2321 d = fsg_ep_desc(common->gadget,
2322 &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
2323 rc = enable_endpoint(common, fsg->bulk_in, d);
2324 if (rc)
2325 goto reset;
2326 fsg->bulk_in_enabled = 1;
2327
2328 d = fsg_ep_desc(common->gadget,
2329 &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
2330 rc = enable_endpoint(common, fsg->bulk_out, d);
2331 if (rc)
2332 goto reset;
2333 fsg->bulk_out_enabled = 1;
2334 common->bulk_out_maxpacket = le16_to_cpu(d->wMaxPacketSize);
2335 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
2336
2337 /* Allocate the requests */
2338 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2339 struct fsg_buffhd *bh = &common->buffhds[i];
2340
2341 rc = alloc_request(common, fsg->bulk_in, &bh->inreq);
2342 if (rc)
2343 goto reset;
2344 rc = alloc_request(common, fsg->bulk_out, &bh->outreq);
2345 if (rc)
2346 goto reset;
2347 bh->inreq->buf = bh->outreq->buf = bh->buf;
2348 bh->inreq->context = bh->outreq->context = bh;
2349 bh->inreq->complete = bulk_in_complete;
2350 bh->outreq->complete = bulk_out_complete;
2351 }
2352
2353 common->running = 1;
2354 for (i = 0; i < common->nluns; ++i)
2355 common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
2356 return rc;
2357 } else {
2358 return -EIO;
2359 }
2360}
2361
2362
2363/*
2364 * Change our operational configuration. This code must agree with the code
2365 * that returns config descriptors, and with interface altsetting code.
2366 *
2367 * It's also responsible for power management interactions. Some
2368 * configurations might not work with our current power sources.
2369 * For now we just assume the gadget is always self-powered.
2370 */
2371static int do_set_config(struct fsg_common *common, u8 new_config)
2372{
2373 int rc = 0;
2374
2375 /* Disable the single interface */
2376 if (common->config != 0) {
2377 DBG(common, "reset config\n");
2378 common->config = 0;
2379 rc = do_set_interface(common, -1);
2380 }
2381
2382 /* Enable the interface */
2383 if (new_config != 0) {
2384 common->config = new_config;
2385 rc = do_set_interface(common, 0);
2386 if (rc != 0)
2387 common->config = 0; /* Reset on errors */
2388 }
2389 return rc;
2390}
2391
2392
2393/****************************** ALT CONFIGS ******************************/
2394
2395
2396static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
2397{
2398 struct fsg_dev *fsg = fsg_from_func(f);
2399 fsg->common->prev_fsg = fsg->common->fsg;
2400 fsg->common->fsg = fsg;
2401 fsg->common->new_config = 1;
2402 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2403 return 0;
2404}
2405
2406static void fsg_disable(struct usb_function *f)
2407{
2408 struct fsg_dev *fsg = fsg_from_func(f);
2409 fsg->common->prev_fsg = fsg->common->fsg;
2410 fsg->common->fsg = fsg;
2411 fsg->common->new_config = 0;
2412 raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
2413}
2414
2415
2416/*-------------------------------------------------------------------------*/
2417
2418static void handle_exception(struct fsg_common *common)
2419{
2420 siginfo_t info;
2421 int sig;
2422 int i;
2423 struct fsg_buffhd *bh;
2424 enum fsg_state old_state;
2425 u8 new_config;
2426 struct fsg_lun *curlun;
2427 unsigned int exception_req_tag;
2428 int rc;
2429
2430 /* Clear the existing signals. Anything but SIGUSR1 is converted
2431 * into a high-priority EXIT exception. */
2432 for (;;) {
2433 sig = dequeue_signal_lock(current, &current->blocked, &info);
2434 if (!sig)
2435 break;
2436 if (sig != SIGUSR1) {
2437 if (common->state < FSG_STATE_EXIT)
2438 DBG(common, "Main thread exiting on signal\n");
2439 raise_exception(common, FSG_STATE_EXIT);
2440 }
2441 }
2442
2443 /* Cancel all the pending transfers */
2444 if (fsg_is_set(common)) {
2445 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2446 bh = &common->buffhds[i];
2447 if (bh->inreq_busy)
2448 usb_ep_dequeue(common->fsg->bulk_in, bh->inreq);
2449 if (bh->outreq_busy)
2450 usb_ep_dequeue(common->fsg->bulk_out,
2451 bh->outreq);
2452 }
2453
2454 /* Wait until everything is idle */
2455 for (;;) {
2456 int num_active = 0;
2457 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2458 bh = &common->buffhds[i];
2459 num_active += bh->inreq_busy + bh->outreq_busy;
2460 }
2461 if (num_active == 0)
2462 break;
2463 if (sleep_thread(common))
2464 return;
2465 }
2466
2467 /* Clear out the controller's fifos */
2468 if (common->fsg->bulk_in_enabled)
2469 usb_ep_fifo_flush(common->fsg->bulk_in);
2470 if (common->fsg->bulk_out_enabled)
2471 usb_ep_fifo_flush(common->fsg->bulk_out);
2472 }
2473
2474 /* Reset the I/O buffer states and pointers, the SCSI
2475 * state, and the exception. Then invoke the handler. */
2476 spin_lock_irq(&common->lock);
2477
2478 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
2479 bh = &common->buffhds[i];
2480 bh->state = BUF_STATE_EMPTY;
2481 }
2482 common->next_buffhd_to_fill = &common->buffhds[0];
2483 common->next_buffhd_to_drain = &common->buffhds[0];
2484 exception_req_tag = common->exception_req_tag;
2485 new_config = common->new_config;
2486 old_state = common->state;
2487
2488 if (old_state == FSG_STATE_ABORT_BULK_OUT)
2489 common->state = FSG_STATE_STATUS_PHASE;
2490 else {
2491 for (i = 0; i < common->nluns; ++i) {
2492 curlun = &common->luns[i];
2493 curlun->prevent_medium_removal = 0;
2494 curlun->sense_data = SS_NO_SENSE;
2495 curlun->unit_attention_data = SS_NO_SENSE;
2496 curlun->sense_data_info = 0;
2497 curlun->info_valid = 0;
2498 }
2499 common->state = FSG_STATE_IDLE;
2500 }
2501 spin_unlock_irq(&common->lock);
2502
2503 /* Carry out any extra actions required for the exception */
2504 switch (old_state) {
2505 case FSG_STATE_ABORT_BULK_OUT:
2506 send_status(common);
2507 spin_lock_irq(&common->lock);
2508 if (common->state == FSG_STATE_STATUS_PHASE)
2509 common->state = FSG_STATE_IDLE;
2510 spin_unlock_irq(&common->lock);
2511 break;
2512
2513 case FSG_STATE_RESET:
2514 /* In case we were forced against our will to halt a
2515 * bulk endpoint, clear the halt now. (The SuperH UDC
2516 * requires this.) */
2517 if (!fsg_is_set(common))
2518 break;
2519 if (test_and_clear_bit(IGNORE_BULK_OUT,
2520 &common->fsg->atomic_bitflags))
2521 usb_ep_clear_halt(common->fsg->bulk_in);
2522
2523 if (common->ep0_req_tag == exception_req_tag)
2524 ep0_queue(common); /* Complete the status stage */
2525
2526 /* Technically this should go here, but it would only be
2527 * a waste of time. Ditto for the INTERFACE_CHANGE and
2528 * CONFIG_CHANGE cases. */
2529 /* for (i = 0; i < common->nluns; ++i) */
2530 /* common->luns[i].unit_attention_data = */
2531 /* SS_RESET_OCCURRED; */
2532 break;
2533
2534 case FSG_STATE_CONFIG_CHANGE:
2535 rc = do_set_config(common, new_config);
2536 break;
2537
2538 case FSG_STATE_EXIT:
2539 case FSG_STATE_TERMINATED:
2540 do_set_config(common, 0); /* Free resources */
2541 spin_lock_irq(&common->lock);
2542 common->state = FSG_STATE_TERMINATED; /* Stop the thread */
2543 spin_unlock_irq(&common->lock);
2544 break;
2545
2546 case FSG_STATE_INTERFACE_CHANGE:
2547 case FSG_STATE_DISCONNECT:
2548 case FSG_STATE_COMMAND_PHASE:
2549 case FSG_STATE_DATA_PHASE:
2550 case FSG_STATE_STATUS_PHASE:
2551 case FSG_STATE_IDLE:
2552 break;
2553 }
2554}
2555
2556
2557/*-------------------------------------------------------------------------*/
2558
2559static int fsg_main_thread(void *common_)
2560{
2561 struct fsg_common *common = common_;
2562
2563 /* Allow the thread to be killed by a signal, but set the signal mask
2564 * to block everything but INT, TERM, KILL, and USR1. */
2565 allow_signal(SIGINT);
2566 allow_signal(SIGTERM);
2567 allow_signal(SIGKILL);
2568 allow_signal(SIGUSR1);
2569
2570 /* Allow the thread to be frozen */
2571 set_freezable();
2572
2573 /* Arrange for userspace references to be interpreted as kernel
2574 * pointers. That way we can pass a kernel pointer to a routine
2575 * that expects a __user pointer and it will work okay. */
2576 set_fs(get_ds());
2577
2578 /* The main loop */
2579 while (common->state != FSG_STATE_TERMINATED) {
2580 if (exception_in_progress(common) || signal_pending(current)) {
2581 handle_exception(common);
2582 continue;
2583 }
2584
2585 if (!common->running) {
2586 sleep_thread(common);
2587 continue;
2588 }
2589
2590 if (get_next_command(common))
2591 continue;
2592
2593 spin_lock_irq(&common->lock);
2594 if (!exception_in_progress(common))
2595 common->state = FSG_STATE_DATA_PHASE;
2596 spin_unlock_irq(&common->lock);
2597
2598 if (do_scsi_command(common) || finish_reply(common))
2599 continue;
2600
2601 spin_lock_irq(&common->lock);
2602 if (!exception_in_progress(common))
2603 common->state = FSG_STATE_STATUS_PHASE;
2604 spin_unlock_irq(&common->lock);
2605
2606 if (send_status(common))
2607 continue;
2608
2609 spin_lock_irq(&common->lock);
2610 if (!exception_in_progress(common))
2611 common->state = FSG_STATE_IDLE;
2612 spin_unlock_irq(&common->lock);
2613 }
2614
2615 spin_lock_irq(&common->lock);
2616 common->thread_task = NULL;
2617 spin_unlock_irq(&common->lock);
2618
2619 if (!common->thread_exits || common->thread_exits(common) < 0) {
2620 struct fsg_lun *curlun = common->luns;
2621 unsigned i = common->nluns;
2622
2623 down_write(&common->filesem);
2624 for (; i--; ++curlun) {
2625 if (!fsg_lun_is_open(curlun))
2626 continue;
2627
2628 fsg_lun_close(curlun);
2629 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
2630 }
2631 up_write(&common->filesem);
2632 }
2633
2634 /* Let the unbind and cleanup routines know the thread has exited */
2635 complete_and_exit(&common->thread_notifier, 0);
2636}
2637
2638
2639/*************************** DEVICE ATTRIBUTES ***************************/
2640
2641/* Write permission is checked per LUN in store_*() functions. */
2642static DEVICE_ATTR(ro, 0644, fsg_show_ro, fsg_store_ro);
2643static DEVICE_ATTR(file, 0644, fsg_show_file, fsg_store_file);
2644
2645
2646/****************************** FSG COMMON ******************************/
2647
2648static void fsg_common_release(struct kref *ref);
2649
2650static void fsg_lun_release(struct device *dev)
2651{
2652 /* Nothing needs to be done */
2653}
2654
2655static inline void fsg_common_get(struct fsg_common *common)
2656{
2657 kref_get(&common->ref);
2658}
2659
2660static inline void fsg_common_put(struct fsg_common *common)
2661{
2662 kref_put(&common->ref, fsg_common_release);
2663}
2664
2665
2666static struct fsg_common *fsg_common_init(struct fsg_common *common,
2667 struct usb_composite_dev *cdev,
2668 struct fsg_config *cfg)
2669{
2670 struct usb_gadget *gadget = cdev->gadget;
2671 struct fsg_buffhd *bh;
2672 struct fsg_lun *curlun;
2673 struct fsg_lun_config *lcfg;
2674 int nluns, i, rc;
2675 char *pathbuf;
2676
2677 /* Find out how many LUNs there should be */
2678 nluns = cfg->nluns;
2679 if (nluns < 1 || nluns > FSG_MAX_LUNS) {
2680 dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
2681 return ERR_PTR(-EINVAL);
2682 }
2683
2684 /* Allocate? */
2685 if (!common) {
2686 common = kzalloc(sizeof *common, GFP_KERNEL);
2687 if (!common)
2688 return ERR_PTR(-ENOMEM);
2689 common->free_storage_on_release = 1;
2690 } else {
2691 memset(common, 0, sizeof common);
2692 common->free_storage_on_release = 0;
2693 }
2694
2695 common->private_data = cfg->private_data;
2696
2697 common->gadget = gadget;
2698 common->ep0 = gadget->ep0;
2699 common->ep0req = cdev->req;
2700
2701 /* Maybe allocate device-global string IDs, and patch descriptors */
2702 if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
2703 rc = usb_string_id(cdev);
2704 if (rc < 0) {
2705 kfree(common);
2706 return ERR_PTR(rc);
2707 }
2708 fsg_strings[FSG_STRING_INTERFACE].id = rc;
2709 fsg_intf_desc.iInterface = rc;
2710 }
2711
2712 /* Create the LUNs, open their backing files, and register the
2713 * LUN devices in sysfs. */
2714 curlun = kzalloc(nluns * sizeof *curlun, GFP_KERNEL);
2715 if (!curlun) {
2716 kfree(common);
2717 return ERR_PTR(-ENOMEM);
2718 }
2719 common->luns = curlun;
2720
2721 init_rwsem(&common->filesem);
2722
2723 for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun, ++lcfg) {
2724 curlun->cdrom = !!lcfg->cdrom;
2725 curlun->ro = lcfg->cdrom || lcfg->ro;
2726 curlun->removable = lcfg->removable;
2727 curlun->dev.release = fsg_lun_release;
2728 curlun->dev.parent = &gadget->dev;
2729 /* curlun->dev.driver = &fsg_driver.driver; XXX */
2730 dev_set_drvdata(&curlun->dev, &common->filesem);
2731 dev_set_name(&curlun->dev,
2732 cfg->lun_name_format
2733 ? cfg->lun_name_format
2734 : "lun%d",
2735 i);
2736
2737 rc = device_register(&curlun->dev);
2738 if (rc) {
2739 INFO(common, "failed to register LUN%d: %d\n", i, rc);
2740 common->nluns = i;
2741 goto error_release;
2742 }
2743
2744 rc = device_create_file(&curlun->dev, &dev_attr_ro);
2745 if (rc)
2746 goto error_luns;
2747 rc = device_create_file(&curlun->dev, &dev_attr_file);
2748 if (rc)
2749 goto error_luns;
2750
2751 if (lcfg->filename) {
2752 rc = fsg_lun_open(curlun, lcfg->filename);
2753 if (rc)
2754 goto error_luns;
2755 } else if (!curlun->removable) {
2756 ERROR(common, "no file given for LUN%d\n", i);
2757 rc = -EINVAL;
2758 goto error_luns;
2759 }
2760 }
2761 common->nluns = nluns;
2762
2763
2764 /* Data buffers cyclic list */
2765 /* Buffers in buffhds are static -- no need for additional
2766 * allocation. */
2767 bh = common->buffhds;
2768 i = FSG_NUM_BUFFERS - 1;
2769 do {
2770 bh->next = bh + 1;
2771 } while (++bh, --i);
2772 bh->next = common->buffhds;
2773
2774
2775 /* Prepare inquiryString */
2776 if (cfg->release != 0xffff) {
2777 i = cfg->release;
2778 } else {
2779 i = usb_gadget_controller_number(gadget);
2780 if (i >= 0) {
2781 i = 0x0300 + i;
2782 } else {
2783 WARNING(common, "controller '%s' not recognized\n",
2784 gadget->name);
2785 i = 0x0399;
2786 }
2787 }
2788#define OR(x, y) ((x) ? (x) : (y))
2789 snprintf(common->inquiry_string, sizeof common->inquiry_string,
2790 "%-8s%-16s%04x",
2791 OR(cfg->vendor_name, "Linux "),
2792 /* Assume product name dependent on the first LUN */
2793 OR(cfg->product_name, common->luns->cdrom
2794 ? "File-Stor Gadget"
2795 : "File-CD Gadget "),
2796 i);
2797
2798
2799 /* Some peripheral controllers are known not to be able to
2800 * halt bulk endpoints correctly. If one of them is present,
2801 * disable stalls.
2802 */
2803 common->can_stall = cfg->can_stall &&
2804 !(gadget_is_at91(common->gadget));
2805
2806
2807 spin_lock_init(&common->lock);
2808 kref_init(&common->ref);
2809
2810
2811 /* Tell the thread to start working */
2812 common->thread_exits = cfg->thread_exits;
2813 common->thread_task =
2814 kthread_create(fsg_main_thread, common,
2815 OR(cfg->thread_name, "file-storage"));
2816 if (IS_ERR(common->thread_task)) {
2817 rc = PTR_ERR(common->thread_task);
2818 goto error_release;
2819 }
2820 init_completion(&common->thread_notifier);
2821#undef OR
2822
2823
2824 /* Information */
2825 INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
2826 INFO(common, "Number of LUNs=%d\n", common->nluns);
2827
2828 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
2829 for (i = 0, nluns = common->nluns, curlun = common->luns;
2830 i < nluns;
2831 ++curlun, ++i) {
2832 char *p = "(no medium)";
2833 if (fsg_lun_is_open(curlun)) {
2834 p = "(error)";
2835 if (pathbuf) {
2836 p = d_path(&curlun->filp->f_path,
2837 pathbuf, PATH_MAX);
2838 if (IS_ERR(p))
2839 p = "(error)";
2840 }
2841 }
2842 LINFO(curlun, "LUN: %s%s%sfile: %s\n",
2843 curlun->removable ? "removable " : "",
2844 curlun->ro ? "read only " : "",
2845 curlun->cdrom ? "CD-ROM " : "",
2846 p);
2847 }
2848 kfree(pathbuf);
2849
2850 DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task));
2851
2852 wake_up_process(common->thread_task);
2853
2854 return common;
2855
2856
2857error_luns:
2858 common->nluns = i + 1;
2859error_release:
2860 common->state = FSG_STATE_TERMINATED; /* The thread is dead */
2861 /* Call fsg_common_release() directly, ref might be not
2862 * initialised */
2863 fsg_common_release(&common->ref);
2864 return ERR_PTR(rc);
2865}
2866
2867
2868static void fsg_common_release(struct kref *ref)
2869{
2870 struct fsg_common *common =
2871 container_of(ref, struct fsg_common, ref);
2872 unsigned i = common->nluns;
2873 struct fsg_lun *lun = common->luns;
2874
2875 /* If the thread isn't already dead, tell it to exit now */
2876 if (common->state != FSG_STATE_TERMINATED) {
2877 raise_exception(common, FSG_STATE_EXIT);
2878 wait_for_completion(&common->thread_notifier);
2879
2880 /* The cleanup routine waits for this completion also */
2881 complete(&common->thread_notifier);
2882 }
2883
2884 /* Beware tempting for -> do-while optimization: when in error
2885 * recovery nluns may be zero. */
2886
2887 for (; i; --i, ++lun) {
2888 device_remove_file(&lun->dev, &dev_attr_ro);
2889 device_remove_file(&lun->dev, &dev_attr_file);
2890 fsg_lun_close(lun);
2891 device_unregister(&lun->dev);
2892 }
2893
2894 kfree(common->luns);
2895 if (common->free_storage_on_release)
2896 kfree(common);
2897}
2898
2899
2900/*-------------------------------------------------------------------------*/
2901
2902
2903static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
2904{
2905 struct fsg_dev *fsg = fsg_from_func(f);
2906
2907 DBG(fsg, "unbind\n");
2908 fsg_common_put(fsg->common);
2909 kfree(fsg);
2910}
2911
2912
2913static int __init fsg_bind(struct usb_configuration *c, struct usb_function *f)
2914{
2915 struct fsg_dev *fsg = fsg_from_func(f);
2916 struct usb_gadget *gadget = c->cdev->gadget;
2917 int rc;
2918 int i;
2919 struct usb_ep *ep;
2920
2921 fsg->gadget = gadget;
2922
2923 /* New interface */
2924 i = usb_interface_id(c, f);
2925 if (i < 0)
2926 return i;
2927 fsg_intf_desc.bInterfaceNumber = i;
2928 fsg->interface_number = i;
2929
2930 /* Find all the endpoints we will use */
2931 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
2932 if (!ep)
2933 goto autoconf_fail;
2934 ep->driver_data = fsg->common; /* claim the endpoint */
2935 fsg->bulk_in = ep;
2936
2937 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
2938 if (!ep)
2939 goto autoconf_fail;
2940 ep->driver_data = fsg->common; /* claim the endpoint */
2941 fsg->bulk_out = ep;
2942
2943 if (gadget_is_dualspeed(gadget)) {
2944 /* Assume endpoint addresses are the same for both speeds */
2945 fsg_hs_bulk_in_desc.bEndpointAddress =
2946 fsg_fs_bulk_in_desc.bEndpointAddress;
2947 fsg_hs_bulk_out_desc.bEndpointAddress =
2948 fsg_fs_bulk_out_desc.bEndpointAddress;
2949 f->hs_descriptors = fsg_hs_function;
2950 }
2951
2952 return 0;
2953
2954autoconf_fail:
2955 ERROR(fsg, "unable to autoconfigure all endpoints\n");
2956 rc = -ENOTSUPP;
2957 return rc;
2958}
2959
2960
2961/****************************** ADD FUNCTION ******************************/
2962
2963static struct usb_gadget_strings *fsg_strings_array[] = {
2964 &fsg_stringtab,
2965 NULL,
2966};
2967
2968static int fsg_add(struct usb_composite_dev *cdev,
2969 struct usb_configuration *c,
2970 struct fsg_common *common)
2971{
2972 struct fsg_dev *fsg;
2973 int rc;
2974
2975 fsg = kzalloc(sizeof *fsg, GFP_KERNEL);
2976 if (unlikely(!fsg))
2977 return -ENOMEM;
2978
2979 fsg->function.name = FSG_DRIVER_DESC;
2980 fsg->function.strings = fsg_strings_array;
2981 fsg->function.descriptors = fsg_fs_function;
2982 fsg->function.bind = fsg_bind;
2983 fsg->function.unbind = fsg_unbind;
2984 fsg->function.setup = fsg_setup;
2985 fsg->function.set_alt = fsg_set_alt;
2986 fsg->function.disable = fsg_disable;
2987
2988 fsg->common = common;
2989 /* Our caller holds a reference to common structure so we
2990 * don't have to be worry about it being freed until we return
2991 * from this function. So instead of incrementing counter now
2992 * and decrement in error recovery we increment it only when
2993 * call to usb_add_function() was successful. */
2994
2995 rc = usb_add_function(c, &fsg->function);
2996
2997 if (likely(rc == 0))
2998 fsg_common_get(fsg->common);
2999 else
3000 kfree(fsg);
3001
3002 return rc;
3003}
3004
3005
3006
3007/************************* Module parameters *************************/
3008
3009
3010struct fsg_module_parameters {
3011 char *file[FSG_MAX_LUNS];
3012 int ro[FSG_MAX_LUNS];
3013 int removable[FSG_MAX_LUNS];
3014 int cdrom[FSG_MAX_LUNS];
3015
3016 unsigned int file_count, ro_count, removable_count, cdrom_count;
3017 unsigned int luns; /* nluns */
3018 int stall; /* can_stall */
3019};
3020
3021
3022#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc) \
3023 module_param_array_named(prefix ## name, params.name, type, \
3024 &prefix ## params.name ## _count, \
3025 S_IRUGO); \
3026 MODULE_PARM_DESC(prefix ## name, desc)
3027
3028#define _FSG_MODULE_PARAM(prefix, params, name, type, desc) \
3029 module_param_named(prefix ## name, params.name, type, \
3030 S_IRUGO); \
3031 MODULE_PARM_DESC(prefix ## name, desc)
3032
3033#define FSG_MODULE_PARAMETERS(prefix, params) \
3034 _FSG_MODULE_PARAM_ARRAY(prefix, params, file, charp, \
3035 "names of backing files or devices"); \
3036 _FSG_MODULE_PARAM_ARRAY(prefix, params, ro, bool, \
3037 "true to force read-only"); \
3038 _FSG_MODULE_PARAM_ARRAY(prefix, params, removable, bool, \
3039 "true to simulate removable media"); \
3040 _FSG_MODULE_PARAM_ARRAY(prefix, params, cdrom, bool, \
3041 "true to simulate CD-ROM instead of disk"); \
3042 _FSG_MODULE_PARAM(prefix, params, luns, uint, \
3043 "number of LUNs"); \
3044 _FSG_MODULE_PARAM(prefix, params, stall, bool, \
3045 "false to prevent bulk stalls")
3046
3047
3048static void
3049fsg_config_from_params(struct fsg_config *cfg,
3050 const struct fsg_module_parameters *params)
3051{
3052 struct fsg_lun_config *lun;
3053 unsigned i;
3054
3055 /* Configure LUNs */
3056 cfg->nluns =
3057 min(params->luns ?: (params->file_count ?: 1u),
3058 (unsigned)FSG_MAX_LUNS);
3059 for (i = 0, lun = cfg->luns; i < cfg->nluns; ++i, ++lun) {
3060 lun->ro = !!params->ro[i];
3061 lun->cdrom = !!params->cdrom[i];
3062 lun->removable = /* Removable by default */
3063 params->removable_count <= i || params->removable[i];
3064 lun->filename =
3065 params->file_count > i && params->file[i][0]
3066 ? params->file[i]
3067 : 0;
3068 }
3069
3070 /* Let MSF use defaults */
3071 cfg->lun_name_format = 0;
3072 cfg->thread_name = 0;
3073 cfg->vendor_name = 0;
3074 cfg->product_name = 0;
3075 cfg->release = 0xffff;
3076
3077 cfg->thread_exits = 0;
3078 cfg->private_data = 0;
3079
3080 /* Finalise */
3081 cfg->can_stall = params->stall;
3082}
3083
3084static inline struct fsg_common *
3085fsg_common_from_params(struct fsg_common *common,
3086 struct usb_composite_dev *cdev,
3087 const struct fsg_module_parameters *params)
3088 __attribute__((unused));
3089static inline struct fsg_common *
3090fsg_common_from_params(struct fsg_common *common,
3091 struct usb_composite_dev *cdev,
3092 const struct fsg_module_parameters *params)
3093{
3094 struct fsg_config cfg;
3095 fsg_config_from_params(&cfg, params);
3096 return fsg_common_init(common, cdev, &cfg);
3097}
3098
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index b4a3ba654ea5..8f8c64371475 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -23,6 +23,7 @@
23 23
24/* #define VERBOSE_DEBUG */ 24/* #define VERBOSE_DEBUG */
25 25
26#include <linux/slab.h>
26#include <linux/kernel.h> 27#include <linux/kernel.h>
27#include <linux/device.h> 28#include <linux/device.h>
28 29
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index d2de10b9dc4b..3c6e1a058745 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -20,6 +20,7 @@
20 * 02110-1301 USA 20 * 02110-1301 USA
21 */ 21 */
22 22
23#include <linux/slab.h>
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/device.h> 25#include <linux/device.h>
25 26
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index c9966cc07d3a..56b022150f22 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -4,6 +4,8 @@
4 * Copyright (C) 2003-2005,2008 David Brownell 4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger 5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation 6 * Copyright (C) 2008 Nokia Corporation
7 * Copyright (C) 2009 Samsung Electronics
8 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
7 * 9 *
8 * This program is free software; you can redistribute it and/or modify 10 * 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 11 * it under the terms of the GNU General Public License as published by
@@ -22,6 +24,7 @@
22 24
23/* #define VERBOSE_DEBUG */ 25/* #define VERBOSE_DEBUG */
24 26
27#include <linux/slab.h>
25#include <linux/kernel.h> 28#include <linux/kernel.h>
26#include <linux/device.h> 29#include <linux/device.h>
27#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
@@ -149,8 +152,8 @@ static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = {
149 .bDataInterface = 0x01, 152 .bDataInterface = 0x01,
150}; 153};
151 154
152static struct usb_cdc_acm_descriptor acm_descriptor __initdata = { 155static struct usb_cdc_acm_descriptor rndis_acm_descriptor __initdata = {
153 .bLength = sizeof acm_descriptor, 156 .bLength = sizeof rndis_acm_descriptor,
154 .bDescriptorType = USB_DT_CS_INTERFACE, 157 .bDescriptorType = USB_DT_CS_INTERFACE,
155 .bDescriptorSubType = USB_CDC_ACM_TYPE, 158 .bDescriptorSubType = USB_CDC_ACM_TYPE,
156 159
@@ -179,6 +182,20 @@ static struct usb_interface_descriptor rndis_data_intf __initdata = {
179 /* .iInterface = DYNAMIC */ 182 /* .iInterface = DYNAMIC */
180}; 183};
181 184
185
186static struct usb_interface_assoc_descriptor
187rndis_iad_descriptor = {
188 .bLength = sizeof rndis_iad_descriptor,
189 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
190
191 .bFirstInterface = 0, /* XXX, hardcoded */
192 .bInterfaceCount = 2, // control + data
193 .bFunctionClass = USB_CLASS_COMM,
194 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
195 .bFunctionProtocol = USB_CDC_PROTO_NONE,
196 /* .iFunction = DYNAMIC */
197};
198
182/* full speed support: */ 199/* full speed support: */
183 200
184static struct usb_endpoint_descriptor fs_notify_desc __initdata = { 201static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
@@ -208,11 +225,12 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = {
208}; 225};
209 226
210static struct usb_descriptor_header *eth_fs_function[] __initdata = { 227static struct usb_descriptor_header *eth_fs_function[] __initdata = {
228 (struct usb_descriptor_header *) &rndis_iad_descriptor,
211 /* control interface matches ACM, not Ethernet */ 229 /* control interface matches ACM, not Ethernet */
212 (struct usb_descriptor_header *) &rndis_control_intf, 230 (struct usb_descriptor_header *) &rndis_control_intf,
213 (struct usb_descriptor_header *) &header_desc, 231 (struct usb_descriptor_header *) &header_desc,
214 (struct usb_descriptor_header *) &call_mgmt_descriptor, 232 (struct usb_descriptor_header *) &call_mgmt_descriptor,
215 (struct usb_descriptor_header *) &acm_descriptor, 233 (struct usb_descriptor_header *) &rndis_acm_descriptor,
216 (struct usb_descriptor_header *) &rndis_union_desc, 234 (struct usb_descriptor_header *) &rndis_union_desc,
217 (struct usb_descriptor_header *) &fs_notify_desc, 235 (struct usb_descriptor_header *) &fs_notify_desc,
218 /* data interface has no altsetting */ 236 /* data interface has no altsetting */
@@ -252,11 +270,12 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
252}; 270};
253 271
254static struct usb_descriptor_header *eth_hs_function[] __initdata = { 272static struct usb_descriptor_header *eth_hs_function[] __initdata = {
273 (struct usb_descriptor_header *) &rndis_iad_descriptor,
255 /* control interface matches ACM, not Ethernet */ 274 /* control interface matches ACM, not Ethernet */
256 (struct usb_descriptor_header *) &rndis_control_intf, 275 (struct usb_descriptor_header *) &rndis_control_intf,
257 (struct usb_descriptor_header *) &header_desc, 276 (struct usb_descriptor_header *) &header_desc,
258 (struct usb_descriptor_header *) &call_mgmt_descriptor, 277 (struct usb_descriptor_header *) &call_mgmt_descriptor,
259 (struct usb_descriptor_header *) &acm_descriptor, 278 (struct usb_descriptor_header *) &rndis_acm_descriptor,
260 (struct usb_descriptor_header *) &rndis_union_desc, 279 (struct usb_descriptor_header *) &rndis_union_desc,
261 (struct usb_descriptor_header *) &hs_notify_desc, 280 (struct usb_descriptor_header *) &hs_notify_desc,
262 /* data interface has no altsetting */ 281 /* data interface has no altsetting */
@@ -271,6 +290,7 @@ static struct usb_descriptor_header *eth_hs_function[] __initdata = {
271static struct usb_string rndis_string_defs[] = { 290static struct usb_string rndis_string_defs[] = {
272 [0].s = "RNDIS Communications Control", 291 [0].s = "RNDIS Communications Control",
273 [1].s = "RNDIS Ethernet Data", 292 [1].s = "RNDIS Ethernet Data",
293 [2].s = "RNDIS",
274 { } /* end of list */ 294 { } /* end of list */
275}; 295};
276 296
@@ -587,6 +607,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
587 if (status < 0) 607 if (status < 0)
588 goto fail; 608 goto fail;
589 rndis->ctrl_id = status; 609 rndis->ctrl_id = status;
610 rndis_iad_descriptor.bFirstInterface = status;
590 611
591 rndis_control_intf.bInterfaceNumber = status; 612 rndis_control_intf.bInterfaceNumber = status;
592 rndis_union_desc.bMasterInterface0 = status; 613 rndis_union_desc.bMasterInterface0 = status;
@@ -749,10 +770,6 @@ rndis_unbind(struct usb_configuration *c, struct usb_function *f)
749/* Some controllers can't support RNDIS ... */ 770/* Some controllers can't support RNDIS ... */
750static inline bool can_support_rndis(struct usb_configuration *c) 771static inline bool can_support_rndis(struct usb_configuration *c)
751{ 772{
752 /* only two endpoints on sa1100 */
753 if (gadget_is_sa1100(c->cdev->gadget))
754 return false;
755
756 /* everything else is *presumably* fine */ 773 /* everything else is *presumably* fine */
757 return true; 774 return true;
758} 775}
@@ -798,6 +815,13 @@ int __init rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
798 return status; 815 return status;
799 rndis_string_defs[1].id = status; 816 rndis_string_defs[1].id = status;
800 rndis_data_intf.iInterface = status; 817 rndis_data_intf.iInterface = status;
818
819 /* IAD iFunction label */
820 status = usb_string_id(c->cdev);
821 if (status < 0)
822 return status;
823 rndis_string_defs[2].id = status;
824 rndis_iad_descriptor.iFunction = status;
801 } 825 }
802 826
803 /* allocate and initialize one new instance */ 827 /* allocate and initialize one new instance */
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index db0aa93606ef..490b00b01a7d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -10,6 +10,7 @@
10 * either version 2 of that License or (at your option) any later version. 10 * either version 2 of that License or (at your option) any later version.
11 */ 11 */
12 12
13#include <linux/slab.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/device.h> 15#include <linux/device.h>
15 16
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 09cba273d2db..6d3cc443d914 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -21,6 +21,7 @@
21 21
22/* #define VERBOSE_DEBUG */ 22/* #define VERBOSE_DEBUG */
23 23
24#include <linux/slab.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/device.h> 26#include <linux/device.h>
26 27
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index a9c98fdb626d..8675ca415329 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <linux/slab.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/device.h> 24#include <linux/device.h>
24#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 1e6aa504d58a..b49d86e3e45b 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -248,8 +248,6 @@
248#include <linux/freezer.h> 248#include <linux/freezer.h>
249#include <linux/utsname.h> 249#include <linux/utsname.h>
250 250
251#include <asm/unaligned.h>
252
253#include <linux/usb/ch9.h> 251#include <linux/usb/ch9.h>
254#include <linux/usb/gadget.h> 252#include <linux/usb/gadget.h>
255 253
@@ -274,21 +272,20 @@
274#define DRIVER_NAME "g_file_storage" 272#define DRIVER_NAME "g_file_storage"
275#define DRIVER_VERSION "20 November 2008" 273#define DRIVER_VERSION "20 November 2008"
276 274
277static const char longname[] = DRIVER_DESC; 275static char fsg_string_manufacturer[64];
278static const char shortname[] = DRIVER_NAME; 276static const char fsg_string_product[] = DRIVER_DESC;
277static char fsg_string_serial[13];
278static const char fsg_string_config[] = "Self-powered";
279static const char fsg_string_interface[] = "Mass Storage";
280
281
282#include "storage_common.c"
283
279 284
280MODULE_DESCRIPTION(DRIVER_DESC); 285MODULE_DESCRIPTION(DRIVER_DESC);
281MODULE_AUTHOR("Alan Stern"); 286MODULE_AUTHOR("Alan Stern");
282MODULE_LICENSE("Dual BSD/GPL"); 287MODULE_LICENSE("Dual BSD/GPL");
283 288
284/* Thanks to NetChip Technologies for donating this product ID.
285 *
286 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
287 * Instead: allocate your own, using normal USB-IF procedures. */
288#define DRIVER_VENDOR_ID 0x0525 // NetChip
289#define DRIVER_PRODUCT_ID 0xa4a5 // Linux-USB File-backed Storage Gadget
290
291
292/* 289/*
293 * This driver assumes self-powered hardware and has no way for users to 290 * This driver assumes self-powered hardware and has no way for users to
294 * trigger remote wakeup. It uses autoconfiguration to select endpoints 291 * trigger remote wakeup. It uses autoconfiguration to select endpoints
@@ -298,54 +295,12 @@ MODULE_LICENSE("Dual BSD/GPL");
298 295
299/*-------------------------------------------------------------------------*/ 296/*-------------------------------------------------------------------------*/
300 297
301#define LDBG(lun,fmt,args...) \
302 dev_dbg(&(lun)->dev , fmt , ## args)
303#define MDBG(fmt,args...) \
304 pr_debug(DRIVER_NAME ": " fmt , ## args)
305
306#ifndef DEBUG
307#undef VERBOSE_DEBUG
308#undef DUMP_MSGS
309#endif /* !DEBUG */
310
311#ifdef VERBOSE_DEBUG
312#define VLDBG LDBG
313#else
314#define VLDBG(lun,fmt,args...) \
315 do { } while (0)
316#endif /* VERBOSE_DEBUG */
317
318#define LERROR(lun,fmt,args...) \
319 dev_err(&(lun)->dev , fmt , ## args)
320#define LWARN(lun,fmt,args...) \
321 dev_warn(&(lun)->dev , fmt , ## args)
322#define LINFO(lun,fmt,args...) \
323 dev_info(&(lun)->dev , fmt , ## args)
324
325#define MINFO(fmt,args...) \
326 pr_info(DRIVER_NAME ": " fmt , ## args)
327
328#define DBG(d, fmt, args...) \
329 dev_dbg(&(d)->gadget->dev , fmt , ## args)
330#define VDBG(d, fmt, args...) \
331 dev_vdbg(&(d)->gadget->dev , fmt , ## args)
332#define ERROR(d, fmt, args...) \
333 dev_err(&(d)->gadget->dev , fmt , ## args)
334#define WARNING(d, fmt, args...) \
335 dev_warn(&(d)->gadget->dev , fmt , ## args)
336#define INFO(d, fmt, args...) \
337 dev_info(&(d)->gadget->dev , fmt , ## args)
338
339
340/*-------------------------------------------------------------------------*/
341 298
342/* Encapsulate the module parameter settings */ 299/* Encapsulate the module parameter settings */
343 300
344#define MAX_LUNS 8
345
346static struct { 301static struct {
347 char *file[MAX_LUNS]; 302 char *file[FSG_MAX_LUNS];
348 int ro[MAX_LUNS]; 303 int ro[FSG_MAX_LUNS];
349 unsigned int num_filenames; 304 unsigned int num_filenames;
350 unsigned int num_ros; 305 unsigned int num_ros;
351 unsigned int nluns; 306 unsigned int nluns;
@@ -372,8 +327,8 @@ static struct {
372 .removable = 0, 327 .removable = 0,
373 .can_stall = 1, 328 .can_stall = 1,
374 .cdrom = 0, 329 .cdrom = 0,
375 .vendor = DRIVER_VENDOR_ID, 330 .vendor = FSG_VENDOR_ID,
376 .product = DRIVER_PRODUCT_ID, 331 .product = FSG_PRODUCT_ID,
377 .release = 0xffff, // Use controller chip type 332 .release = 0xffff, // Use controller chip type
378 .buflen = 16384, 333 .buflen = 16384,
379 }; 334 };
@@ -425,125 +380,6 @@ MODULE_PARM_DESC(buflen, "I/O buffer size");
425#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 380#endif /* CONFIG_USB_FILE_STORAGE_TEST */
426 381
427 382
428/*-------------------------------------------------------------------------*/
429
430/* SCSI device types */
431#define TYPE_DISK 0x00
432#define TYPE_CDROM 0x05
433
434/* USB protocol value = the transport method */
435#define USB_PR_CBI 0x00 // Control/Bulk/Interrupt
436#define USB_PR_CB 0x01 // Control/Bulk w/o interrupt
437#define USB_PR_BULK 0x50 // Bulk-only
438
439/* USB subclass value = the protocol encapsulation */
440#define USB_SC_RBC 0x01 // Reduced Block Commands (flash)
441#define USB_SC_8020 0x02 // SFF-8020i, MMC-2, ATAPI (CD-ROM)
442#define USB_SC_QIC 0x03 // QIC-157 (tape)
443#define USB_SC_UFI 0x04 // UFI (floppy)
444#define USB_SC_8070 0x05 // SFF-8070i (removable)
445#define USB_SC_SCSI 0x06 // Transparent SCSI
446
447/* Bulk-only data structures */
448
449/* Command Block Wrapper */
450struct bulk_cb_wrap {
451 __le32 Signature; // Contains 'USBC'
452 u32 Tag; // Unique per command id
453 __le32 DataTransferLength; // Size of the data
454 u8 Flags; // Direction in bit 7
455 u8 Lun; // LUN (normally 0)
456 u8 Length; // Of the CDB, <= MAX_COMMAND_SIZE
457 u8 CDB[16]; // Command Data Block
458};
459
460#define USB_BULK_CB_WRAP_LEN 31
461#define USB_BULK_CB_SIG 0x43425355 // Spells out USBC
462#define USB_BULK_IN_FLAG 0x80
463
464/* Command Status Wrapper */
465struct bulk_cs_wrap {
466 __le32 Signature; // Should = 'USBS'
467 u32 Tag; // Same as original command
468 __le32 Residue; // Amount not transferred
469 u8 Status; // See below
470};
471
472#define USB_BULK_CS_WRAP_LEN 13
473#define USB_BULK_CS_SIG 0x53425355 // Spells out 'USBS'
474#define USB_STATUS_PASS 0
475#define USB_STATUS_FAIL 1
476#define USB_STATUS_PHASE_ERROR 2
477
478/* Bulk-only class specific requests */
479#define USB_BULK_RESET_REQUEST 0xff
480#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
481
482
483/* CBI Interrupt data structure */
484struct interrupt_data {
485 u8 bType;
486 u8 bValue;
487};
488
489#define CBI_INTERRUPT_DATA_LEN 2
490
491/* CBI Accept Device-Specific Command request */
492#define USB_CBI_ADSC_REQUEST 0x00
493
494
495#define MAX_COMMAND_SIZE 16 // Length of a SCSI Command Data Block
496
497/* SCSI commands that we recognize */
498#define SC_FORMAT_UNIT 0x04
499#define SC_INQUIRY 0x12
500#define SC_MODE_SELECT_6 0x15
501#define SC_MODE_SELECT_10 0x55
502#define SC_MODE_SENSE_6 0x1a
503#define SC_MODE_SENSE_10 0x5a
504#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
505#define SC_READ_6 0x08
506#define SC_READ_10 0x28
507#define SC_READ_12 0xa8
508#define SC_READ_CAPACITY 0x25
509#define SC_READ_FORMAT_CAPACITIES 0x23
510#define SC_READ_HEADER 0x44
511#define SC_READ_TOC 0x43
512#define SC_RELEASE 0x17
513#define SC_REQUEST_SENSE 0x03
514#define SC_RESERVE 0x16
515#define SC_SEND_DIAGNOSTIC 0x1d
516#define SC_START_STOP_UNIT 0x1b
517#define SC_SYNCHRONIZE_CACHE 0x35
518#define SC_TEST_UNIT_READY 0x00
519#define SC_VERIFY 0x2f
520#define SC_WRITE_6 0x0a
521#define SC_WRITE_10 0x2a
522#define SC_WRITE_12 0xaa
523
524/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
525#define SS_NO_SENSE 0
526#define SS_COMMUNICATION_FAILURE 0x040800
527#define SS_INVALID_COMMAND 0x052000
528#define SS_INVALID_FIELD_IN_CDB 0x052400
529#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
530#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
531#define SS_MEDIUM_NOT_PRESENT 0x023a00
532#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
533#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
534#define SS_RESET_OCCURRED 0x062900
535#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
536#define SS_UNRECOVERED_READ_ERROR 0x031100
537#define SS_WRITE_ERROR 0x030c02
538#define SS_WRITE_PROTECTED 0x072700
539
540#define SK(x) ((u8) ((x) >> 16)) // Sense Key byte, etc.
541#define ASC(x) ((u8) ((x) >> 8))
542#define ASCQ(x) ((u8) (x))
543
544
545/*-------------------------------------------------------------------------*/
546
547/* 383/*
548 * These definitions will permit the compiler to avoid generating code for 384 * These definitions will permit the compiler to avoid generating code for
549 * parts of the driver that aren't used in the non-TEST version. Even gcc 385 * parts of the driver that aren't used in the non-TEST version. Even gcc
@@ -566,81 +402,8 @@ struct interrupt_data {
566#endif /* CONFIG_USB_FILE_STORAGE_TEST */ 402#endif /* CONFIG_USB_FILE_STORAGE_TEST */
567 403
568 404
569struct lun { 405/*-------------------------------------------------------------------------*/
570 struct file *filp;
571 loff_t file_length;
572 loff_t num_sectors;
573
574 unsigned int ro : 1;
575 unsigned int prevent_medium_removal : 1;
576 unsigned int registered : 1;
577 unsigned int info_valid : 1;
578
579 u32 sense_data;
580 u32 sense_data_info;
581 u32 unit_attention_data;
582
583 struct device dev;
584};
585
586#define backing_file_is_open(curlun) ((curlun)->filp != NULL)
587
588static struct lun *dev_to_lun(struct device *dev)
589{
590 return container_of(dev, struct lun, dev);
591}
592
593
594/* Big enough to hold our biggest descriptor */
595#define EP0_BUFSIZE 256
596#define DELAYED_STATUS (EP0_BUFSIZE + 999) // An impossibly large value
597
598/* Number of buffers we will use. 2 is enough for double-buffering */
599#define NUM_BUFFERS 2
600
601enum fsg_buffer_state {
602 BUF_STATE_EMPTY = 0,
603 BUF_STATE_FULL,
604 BUF_STATE_BUSY
605};
606
607struct fsg_buffhd {
608 void *buf;
609 enum fsg_buffer_state state;
610 struct fsg_buffhd *next;
611
612 /* The NetChip 2280 is faster, and handles some protocol faults
613 * better, if we don't submit any short bulk-out read requests.
614 * So we will record the intended request length here. */
615 unsigned int bulk_out_intended_length;
616
617 struct usb_request *inreq;
618 int inreq_busy;
619 struct usb_request *outreq;
620 int outreq_busy;
621};
622
623enum fsg_state {
624 FSG_STATE_COMMAND_PHASE = -10, // This one isn't used anywhere
625 FSG_STATE_DATA_PHASE,
626 FSG_STATE_STATUS_PHASE,
627
628 FSG_STATE_IDLE = 0,
629 FSG_STATE_ABORT_BULK_OUT,
630 FSG_STATE_RESET,
631 FSG_STATE_INTERFACE_CHANGE,
632 FSG_STATE_CONFIG_CHANGE,
633 FSG_STATE_DISCONNECT,
634 FSG_STATE_EXIT,
635 FSG_STATE_TERMINATED
636};
637 406
638enum data_direction {
639 DATA_DIR_UNKNOWN = 0,
640 DATA_DIR_FROM_HOST,
641 DATA_DIR_TO_HOST,
642 DATA_DIR_NONE
643};
644 407
645struct fsg_dev { 408struct fsg_dev {
646 /* lock protects: state, all the req_busy's, and cbbuf_cmnd */ 409 /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
@@ -662,7 +425,7 @@ struct fsg_dev {
662 int intreq_busy; 425 int intreq_busy;
663 struct fsg_buffhd *intr_buffhd; 426 struct fsg_buffhd *intr_buffhd;
664 427
665 unsigned int bulk_out_maxpacket; 428 unsigned int bulk_out_maxpacket;
666 enum fsg_state state; // For exception handling 429 enum fsg_state state; // For exception handling
667 unsigned int exception_req_tag; 430 unsigned int exception_req_tag;
668 431
@@ -687,7 +450,7 @@ struct fsg_dev {
687 450
688 struct fsg_buffhd *next_buffhd_to_fill; 451 struct fsg_buffhd *next_buffhd_to_fill;
689 struct fsg_buffhd *next_buffhd_to_drain; 452 struct fsg_buffhd *next_buffhd_to_drain;
690 struct fsg_buffhd buffhds[NUM_BUFFERS]; 453 struct fsg_buffhd buffhds[FSG_NUM_BUFFERS];
691 454
692 int thread_wakeup_needed; 455 int thread_wakeup_needed;
693 struct completion thread_notifier; 456 struct completion thread_notifier;
@@ -712,8 +475,8 @@ struct fsg_dev {
712 u8 cbbuf_cmnd[MAX_COMMAND_SIZE]; 475 u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
713 476
714 unsigned int nluns; 477 unsigned int nluns;
715 struct lun *luns; 478 struct fsg_lun *luns;
716 struct lun *curlun; 479 struct fsg_lun *curlun;
717}; 480};
718 481
719typedef void (*fsg_routine_t)(struct fsg_dev *); 482typedef void (*fsg_routine_t)(struct fsg_dev *);
@@ -739,49 +502,9 @@ static void set_bulk_out_req_length(struct fsg_dev *fsg,
739static struct fsg_dev *the_fsg; 502static struct fsg_dev *the_fsg;
740static struct usb_gadget_driver fsg_driver; 503static struct usb_gadget_driver fsg_driver;
741 504
742static void close_backing_file(struct lun *curlun);
743
744 505
745/*-------------------------------------------------------------------------*/ 506/*-------------------------------------------------------------------------*/
746 507
747#ifdef DUMP_MSGS
748
749static void dump_msg(struct fsg_dev *fsg, const char *label,
750 const u8 *buf, unsigned int length)
751{
752 if (length < 512) {
753 DBG(fsg, "%s, length %u:\n", label, length);
754 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET,
755 16, 1, buf, length, 0);
756 }
757}
758
759static void dump_cdb(struct fsg_dev *fsg)
760{}
761
762#else
763
764static void dump_msg(struct fsg_dev *fsg, const char *label,
765 const u8 *buf, unsigned int length)
766{}
767
768#ifdef VERBOSE_DEBUG
769
770static void dump_cdb(struct fsg_dev *fsg)
771{
772 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE,
773 16, 1, fsg->cmnd, fsg->cmnd_size, 0);
774}
775
776#else
777
778static void dump_cdb(struct fsg_dev *fsg)
779{}
780
781#endif /* VERBOSE_DEBUG */
782#endif /* DUMP_MSGS */
783
784
785static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep) 508static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
786{ 509{
787 const char *name; 510 const char *name;
@@ -799,26 +522,11 @@ static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
799 522
800/*-------------------------------------------------------------------------*/ 523/*-------------------------------------------------------------------------*/
801 524
802/* Routines for unaligned data access */
803
804static u32 get_unaligned_be24(u8 *buf)
805{
806 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
807}
808
809
810/*-------------------------------------------------------------------------*/
811
812/* 525/*
813 * DESCRIPTORS ... most are static, but strings and (full) configuration 526 * DESCRIPTORS ... most are static, but strings and (full) configuration
814 * descriptors are built on demand. Also the (static) config and interface 527 * descriptors are built on demand. Also the (static) config and interface
815 * descriptors are adjusted during fsg_bind(). 528 * descriptors are adjusted during fsg_bind().
816 */ 529 */
817#define STRING_MANUFACTURER 1
818#define STRING_PRODUCT 2
819#define STRING_SERIAL 3
820#define STRING_CONFIG 4
821#define STRING_INTERFACE 5
822 530
823/* There is only one configuration. */ 531/* There is only one configuration. */
824#define CONFIG_VALUE 1 532#define CONFIG_VALUE 1
@@ -832,13 +540,13 @@ device_desc = {
832 .bDeviceClass = USB_CLASS_PER_INTERFACE, 540 .bDeviceClass = USB_CLASS_PER_INTERFACE,
833 541
834 /* The next three values can be overridden by module parameters */ 542 /* The next three values can be overridden by module parameters */
835 .idVendor = cpu_to_le16(DRIVER_VENDOR_ID), 543 .idVendor = cpu_to_le16(FSG_VENDOR_ID),
836 .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID), 544 .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
837 .bcdDevice = cpu_to_le16(0xffff), 545 .bcdDevice = cpu_to_le16(0xffff),
838 546
839 .iManufacturer = STRING_MANUFACTURER, 547 .iManufacturer = FSG_STRING_MANUFACTURER,
840 .iProduct = STRING_PRODUCT, 548 .iProduct = FSG_STRING_PRODUCT,
841 .iSerialNumber = STRING_SERIAL, 549 .iSerialNumber = FSG_STRING_SERIAL,
842 .bNumConfigurations = 1, 550 .bNumConfigurations = 1,
843}; 551};
844 552
@@ -850,86 +558,12 @@ config_desc = {
850 /* wTotalLength computed by usb_gadget_config_buf() */ 558 /* wTotalLength computed by usb_gadget_config_buf() */
851 .bNumInterfaces = 1, 559 .bNumInterfaces = 1,
852 .bConfigurationValue = CONFIG_VALUE, 560 .bConfigurationValue = CONFIG_VALUE,
853 .iConfiguration = STRING_CONFIG, 561 .iConfiguration = FSG_STRING_CONFIG,
854 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, 562 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
855 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2, 563 .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
856}; 564};
857 565
858static struct usb_otg_descriptor
859otg_desc = {
860 .bLength = sizeof(otg_desc),
861 .bDescriptorType = USB_DT_OTG,
862
863 .bmAttributes = USB_OTG_SRP,
864};
865
866/* There is only one interface. */
867
868static struct usb_interface_descriptor
869intf_desc = {
870 .bLength = sizeof intf_desc,
871 .bDescriptorType = USB_DT_INTERFACE,
872
873 .bNumEndpoints = 2, // Adjusted during fsg_bind()
874 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
875 .bInterfaceSubClass = USB_SC_SCSI, // Adjusted during fsg_bind()
876 .bInterfaceProtocol = USB_PR_BULK, // Adjusted during fsg_bind()
877 .iInterface = STRING_INTERFACE,
878};
879
880/* Three full-speed endpoint descriptors: bulk-in, bulk-out,
881 * and interrupt-in. */
882
883static struct usb_endpoint_descriptor
884fs_bulk_in_desc = {
885 .bLength = USB_DT_ENDPOINT_SIZE,
886 .bDescriptorType = USB_DT_ENDPOINT,
887
888 .bEndpointAddress = USB_DIR_IN,
889 .bmAttributes = USB_ENDPOINT_XFER_BULK,
890 /* wMaxPacketSize set by autoconfiguration */
891};
892 566
893static struct usb_endpoint_descriptor
894fs_bulk_out_desc = {
895 .bLength = USB_DT_ENDPOINT_SIZE,
896 .bDescriptorType = USB_DT_ENDPOINT,
897
898 .bEndpointAddress = USB_DIR_OUT,
899 .bmAttributes = USB_ENDPOINT_XFER_BULK,
900 /* wMaxPacketSize set by autoconfiguration */
901};
902
903static struct usb_endpoint_descriptor
904fs_intr_in_desc = {
905 .bLength = USB_DT_ENDPOINT_SIZE,
906 .bDescriptorType = USB_DT_ENDPOINT,
907
908 .bEndpointAddress = USB_DIR_IN,
909 .bmAttributes = USB_ENDPOINT_XFER_INT,
910 .wMaxPacketSize = cpu_to_le16(2),
911 .bInterval = 32, // frames -> 32 ms
912};
913
914static const struct usb_descriptor_header *fs_function[] = {
915 (struct usb_descriptor_header *) &otg_desc,
916 (struct usb_descriptor_header *) &intf_desc,
917 (struct usb_descriptor_header *) &fs_bulk_in_desc,
918 (struct usb_descriptor_header *) &fs_bulk_out_desc,
919 (struct usb_descriptor_header *) &fs_intr_in_desc,
920 NULL,
921};
922#define FS_FUNCTION_PRE_EP_ENTRIES 2
923
924
925/*
926 * USB 2.0 devices need to expose both high speed and full speed
927 * descriptors, unless they only run at full speed.
928 *
929 * That means alternate endpoint descriptors (bigger packets)
930 * and a "device qualifier" ... plus more construction options
931 * for the config descriptor.
932 */
933static struct usb_qualifier_descriptor 567static struct usb_qualifier_descriptor
934dev_qualifier = { 568dev_qualifier = {
935 .bLength = sizeof dev_qualifier, 569 .bLength = sizeof dev_qualifier,
@@ -941,78 +575,6 @@ dev_qualifier = {
941 .bNumConfigurations = 1, 575 .bNumConfigurations = 1,
942}; 576};
943 577
944static struct usb_endpoint_descriptor
945hs_bulk_in_desc = {
946 .bLength = USB_DT_ENDPOINT_SIZE,
947 .bDescriptorType = USB_DT_ENDPOINT,
948
949 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
950 .bmAttributes = USB_ENDPOINT_XFER_BULK,
951 .wMaxPacketSize = cpu_to_le16(512),
952};
953
954static struct usb_endpoint_descriptor
955hs_bulk_out_desc = {
956 .bLength = USB_DT_ENDPOINT_SIZE,
957 .bDescriptorType = USB_DT_ENDPOINT,
958
959 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
960 .bmAttributes = USB_ENDPOINT_XFER_BULK,
961 .wMaxPacketSize = cpu_to_le16(512),
962 .bInterval = 1, // NAK every 1 uframe
963};
964
965static struct usb_endpoint_descriptor
966hs_intr_in_desc = {
967 .bLength = USB_DT_ENDPOINT_SIZE,
968 .bDescriptorType = USB_DT_ENDPOINT,
969
970 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
971 .bmAttributes = USB_ENDPOINT_XFER_INT,
972 .wMaxPacketSize = cpu_to_le16(2),
973 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
974};
975
976static const struct usb_descriptor_header *hs_function[] = {
977 (struct usb_descriptor_header *) &otg_desc,
978 (struct usb_descriptor_header *) &intf_desc,
979 (struct usb_descriptor_header *) &hs_bulk_in_desc,
980 (struct usb_descriptor_header *) &hs_bulk_out_desc,
981 (struct usb_descriptor_header *) &hs_intr_in_desc,
982 NULL,
983};
984#define HS_FUNCTION_PRE_EP_ENTRIES 2
985
986/* Maxpacket and other transfer characteristics vary by speed. */
987static struct usb_endpoint_descriptor *
988ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
989 struct usb_endpoint_descriptor *hs)
990{
991 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
992 return hs;
993 return fs;
994}
995
996
997/* The CBI specification limits the serial string to 12 uppercase hexadecimal
998 * characters. */
999static char manufacturer[64];
1000static char serial[13];
1001
1002/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
1003static struct usb_string strings[] = {
1004 {STRING_MANUFACTURER, manufacturer},
1005 {STRING_PRODUCT, longname},
1006 {STRING_SERIAL, serial},
1007 {STRING_CONFIG, "Self-powered"},
1008 {STRING_INTERFACE, "Mass Storage"},
1009 {}
1010};
1011
1012static struct usb_gadget_strings stringtab = {
1013 .language = 0x0409, // en-us
1014 .strings = strings,
1015};
1016 578
1017 579
1018/* 580/*
@@ -1032,10 +594,9 @@ static int populate_config_buf(struct usb_gadget *gadget,
1032 594
1033 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG) 595 if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
1034 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed; 596 speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
1035 if (gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH) 597 function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
1036 function = hs_function; 598 ? (const struct usb_descriptor_header **)fsg_hs_function
1037 else 599 : (const struct usb_descriptor_header **)fsg_fs_function;
1038 function = fs_function;
1039 600
1040 /* for now, don't advertise srp-only devices */ 601 /* for now, don't advertise srp-only devices */
1041 if (!gadget_is_otg(gadget)) 602 if (!gadget_is_otg(gadget))
@@ -1386,7 +947,7 @@ get_config:
1386 VDBG(fsg, "get string descriptor\n"); 947 VDBG(fsg, "get string descriptor\n");
1387 948
1388 /* wIndex == language code */ 949 /* wIndex == language code */
1389 value = usb_gadget_get_string(&stringtab, 950 value = usb_gadget_get_string(&fsg_stringtab,
1390 w_value & 0xff, req->buf); 951 w_value & 0xff, req->buf);
1391 break; 952 break;
1392 } 953 }
@@ -1551,7 +1112,7 @@ static int sleep_thread(struct fsg_dev *fsg)
1551 1112
1552static int do_read(struct fsg_dev *fsg) 1113static int do_read(struct fsg_dev *fsg)
1553{ 1114{
1554 struct lun *curlun = fsg->curlun; 1115 struct fsg_lun *curlun = fsg->curlun;
1555 u32 lba; 1116 u32 lba;
1556 struct fsg_buffhd *bh; 1117 struct fsg_buffhd *bh;
1557 int rc; 1118 int rc;
@@ -1677,7 +1238,7 @@ static int do_read(struct fsg_dev *fsg)
1677 1238
1678static int do_write(struct fsg_dev *fsg) 1239static int do_write(struct fsg_dev *fsg)
1679{ 1240{
1680 struct lun *curlun = fsg->curlun; 1241 struct fsg_lun *curlun = fsg->curlun;
1681 u32 lba; 1242 u32 lba;
1682 struct fsg_buffhd *bh; 1243 struct fsg_buffhd *bh;
1683 int get_some_more; 1244 int get_some_more;
@@ -1713,7 +1274,7 @@ static int do_write(struct fsg_dev *fsg)
1713 } 1274 }
1714 if (fsg->cmnd[1] & 0x08) { // FUA 1275 if (fsg->cmnd[1] & 0x08) { // FUA
1715 spin_lock(&curlun->filp->f_lock); 1276 spin_lock(&curlun->filp->f_lock);
1716 curlun->filp->f_flags |= O_SYNC; 1277 curlun->filp->f_flags |= O_DSYNC;
1717 spin_unlock(&curlun->filp->f_lock); 1278 spin_unlock(&curlun->filp->f_lock);
1718 } 1279 }
1719 } 1280 }
@@ -1864,33 +1425,14 @@ static int do_write(struct fsg_dev *fsg)
1864 1425
1865/*-------------------------------------------------------------------------*/ 1426/*-------------------------------------------------------------------------*/
1866 1427
1867/* Sync the file data, don't bother with the metadata.
1868 * This code was copied from fs/buffer.c:sys_fdatasync(). */
1869static int fsync_sub(struct lun *curlun)
1870{
1871 struct file *filp = curlun->filp;
1872
1873 if (curlun->ro || !filp)
1874 return 0;
1875 return vfs_fsync(filp, filp->f_path.dentry, 1);
1876}
1877
1878static void fsync_all(struct fsg_dev *fsg)
1879{
1880 int i;
1881
1882 for (i = 0; i < fsg->nluns; ++i)
1883 fsync_sub(&fsg->luns[i]);
1884}
1885
1886static int do_synchronize_cache(struct fsg_dev *fsg) 1428static int do_synchronize_cache(struct fsg_dev *fsg)
1887{ 1429{
1888 struct lun *curlun = fsg->curlun; 1430 struct fsg_lun *curlun = fsg->curlun;
1889 int rc; 1431 int rc;
1890 1432
1891 /* We ignore the requested LBA and write out all file's 1433 /* We ignore the requested LBA and write out all file's
1892 * dirty data buffers. */ 1434 * dirty data buffers. */
1893 rc = fsync_sub(curlun); 1435 rc = fsg_lun_fsync_sub(curlun);
1894 if (rc) 1436 if (rc)
1895 curlun->sense_data = SS_WRITE_ERROR; 1437 curlun->sense_data = SS_WRITE_ERROR;
1896 return 0; 1438 return 0;
@@ -1899,19 +1441,19 @@ static int do_synchronize_cache(struct fsg_dev *fsg)
1899 1441
1900/*-------------------------------------------------------------------------*/ 1442/*-------------------------------------------------------------------------*/
1901 1443
1902static void invalidate_sub(struct lun *curlun) 1444static void invalidate_sub(struct fsg_lun *curlun)
1903{ 1445{
1904 struct file *filp = curlun->filp; 1446 struct file *filp = curlun->filp;
1905 struct inode *inode = filp->f_path.dentry->d_inode; 1447 struct inode *inode = filp->f_path.dentry->d_inode;
1906 unsigned long rc; 1448 unsigned long rc;
1907 1449
1908 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1); 1450 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
1909 VLDBG(curlun, "invalidate_inode_pages -> %ld\n", rc); 1451 VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
1910} 1452}
1911 1453
1912static int do_verify(struct fsg_dev *fsg) 1454static int do_verify(struct fsg_dev *fsg)
1913{ 1455{
1914 struct lun *curlun = fsg->curlun; 1456 struct fsg_lun *curlun = fsg->curlun;
1915 u32 lba; 1457 u32 lba;
1916 u32 verification_length; 1458 u32 verification_length;
1917 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill; 1459 struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
@@ -1944,7 +1486,7 @@ static int do_verify(struct fsg_dev *fsg)
1944 file_offset = ((loff_t) lba) << 9; 1486 file_offset = ((loff_t) lba) << 9;
1945 1487
1946 /* Write out all the dirty buffers before invalidating them */ 1488 /* Write out all the dirty buffers before invalidating them */
1947 fsync_sub(curlun); 1489 fsg_lun_fsync_sub(curlun);
1948 if (signal_pending(current)) 1490 if (signal_pending(current))
1949 return -EINTR; 1491 return -EINTR;
1950 1492
@@ -2041,7 +1583,7 @@ static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2041 1583
2042static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1584static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2043{ 1585{
2044 struct lun *curlun = fsg->curlun; 1586 struct fsg_lun *curlun = fsg->curlun;
2045 u8 *buf = (u8 *) bh->buf; 1587 u8 *buf = (u8 *) bh->buf;
2046 u32 sd, sdinfo; 1588 u32 sd, sdinfo;
2047 int valid; 1589 int valid;
@@ -2095,7 +1637,7 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2095 1637
2096static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1638static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2097{ 1639{
2098 struct lun *curlun = fsg->curlun; 1640 struct fsg_lun *curlun = fsg->curlun;
2099 u32 lba = get_unaligned_be32(&fsg->cmnd[2]); 1641 u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
2100 int pmi = fsg->cmnd[8]; 1642 int pmi = fsg->cmnd[8];
2101 u8 *buf = (u8 *) bh->buf; 1643 u8 *buf = (u8 *) bh->buf;
@@ -2113,27 +1655,9 @@ static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2113} 1655}
2114 1656
2115 1657
2116static void store_cdrom_address(u8 *dest, int msf, u32 addr)
2117{
2118 if (msf) {
2119 /* Convert to Minutes-Seconds-Frames */
2120 addr >>= 2; /* Convert to 2048-byte frames */
2121 addr += 2*75; /* Lead-in occupies 2 seconds */
2122 dest[3] = addr % 75; /* Frames */
2123 addr /= 75;
2124 dest[2] = addr % 60; /* Seconds */
2125 addr /= 60;
2126 dest[1] = addr; /* Minutes */
2127 dest[0] = 0; /* Reserved */
2128 } else {
2129 /* Absolute sector */
2130 put_unaligned_be32(addr, dest);
2131 }
2132}
2133
2134static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1658static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2135{ 1659{
2136 struct lun *curlun = fsg->curlun; 1660 struct fsg_lun *curlun = fsg->curlun;
2137 int msf = fsg->cmnd[1] & 0x02; 1661 int msf = fsg->cmnd[1] & 0x02;
2138 u32 lba = get_unaligned_be32(&fsg->cmnd[2]); 1662 u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
2139 u8 *buf = (u8 *) bh->buf; 1663 u8 *buf = (u8 *) bh->buf;
@@ -2156,7 +1680,7 @@ static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2156 1680
2157static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1681static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2158{ 1682{
2159 struct lun *curlun = fsg->curlun; 1683 struct fsg_lun *curlun = fsg->curlun;
2160 int msf = fsg->cmnd[1] & 0x02; 1684 int msf = fsg->cmnd[1] & 0x02;
2161 int start_track = fsg->cmnd[6]; 1685 int start_track = fsg->cmnd[6];
2162 u8 *buf = (u8 *) bh->buf; 1686 u8 *buf = (u8 *) bh->buf;
@@ -2184,7 +1708,7 @@ static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2184 1708
2185static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1709static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2186{ 1710{
2187 struct lun *curlun = fsg->curlun; 1711 struct fsg_lun *curlun = fsg->curlun;
2188 int mscmnd = fsg->cmnd[0]; 1712 int mscmnd = fsg->cmnd[0];
2189 u8 *buf = (u8 *) bh->buf; 1713 u8 *buf = (u8 *) bh->buf;
2190 u8 *buf0 = buf; 1714 u8 *buf0 = buf;
@@ -2265,7 +1789,7 @@ static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2265 1789
2266static int do_start_stop(struct fsg_dev *fsg) 1790static int do_start_stop(struct fsg_dev *fsg)
2267{ 1791{
2268 struct lun *curlun = fsg->curlun; 1792 struct fsg_lun *curlun = fsg->curlun;
2269 int loej, start; 1793 int loej, start;
2270 1794
2271 if (!mod_data.removable) { 1795 if (!mod_data.removable) {
@@ -2295,7 +1819,7 @@ static int do_start_stop(struct fsg_dev *fsg)
2295 if (loej) { // Simulate an unload/eject 1819 if (loej) { // Simulate an unload/eject
2296 up_read(&fsg->filesem); 1820 up_read(&fsg->filesem);
2297 down_write(&fsg->filesem); 1821 down_write(&fsg->filesem);
2298 close_backing_file(curlun); 1822 fsg_lun_close(curlun);
2299 up_write(&fsg->filesem); 1823 up_write(&fsg->filesem);
2300 down_read(&fsg->filesem); 1824 down_read(&fsg->filesem);
2301 } 1825 }
@@ -2303,7 +1827,7 @@ static int do_start_stop(struct fsg_dev *fsg)
2303 1827
2304 /* Our emulation doesn't support mounting; the medium is 1828 /* Our emulation doesn't support mounting; the medium is
2305 * available for use as soon as it is loaded. */ 1829 * available for use as soon as it is loaded. */
2306 if (!backing_file_is_open(curlun)) { 1830 if (!fsg_lun_is_open(curlun)) {
2307 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 1831 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
2308 return -EINVAL; 1832 return -EINVAL;
2309 } 1833 }
@@ -2315,7 +1839,7 @@ static int do_start_stop(struct fsg_dev *fsg)
2315 1839
2316static int do_prevent_allow(struct fsg_dev *fsg) 1840static int do_prevent_allow(struct fsg_dev *fsg)
2317{ 1841{
2318 struct lun *curlun = fsg->curlun; 1842 struct fsg_lun *curlun = fsg->curlun;
2319 int prevent; 1843 int prevent;
2320 1844
2321 if (!mod_data.removable) { 1845 if (!mod_data.removable) {
@@ -2330,7 +1854,7 @@ static int do_prevent_allow(struct fsg_dev *fsg)
2330 } 1854 }
2331 1855
2332 if (curlun->prevent_medium_removal && !prevent) 1856 if (curlun->prevent_medium_removal && !prevent)
2333 fsync_sub(curlun); 1857 fsg_lun_fsync_sub(curlun);
2334 curlun->prevent_medium_removal = prevent; 1858 curlun->prevent_medium_removal = prevent;
2335 return 0; 1859 return 0;
2336} 1860}
@@ -2339,7 +1863,7 @@ static int do_prevent_allow(struct fsg_dev *fsg)
2339static int do_read_format_capacities(struct fsg_dev *fsg, 1863static int do_read_format_capacities(struct fsg_dev *fsg,
2340 struct fsg_buffhd *bh) 1864 struct fsg_buffhd *bh)
2341{ 1865{
2342 struct lun *curlun = fsg->curlun; 1866 struct fsg_lun *curlun = fsg->curlun;
2343 u8 *buf = (u8 *) bh->buf; 1867 u8 *buf = (u8 *) bh->buf;
2344 1868
2345 buf[0] = buf[1] = buf[2] = 0; 1869 buf[0] = buf[1] = buf[2] = 0;
@@ -2356,7 +1880,7 @@ static int do_read_format_capacities(struct fsg_dev *fsg,
2356 1880
2357static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh) 1881static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2358{ 1882{
2359 struct lun *curlun = fsg->curlun; 1883 struct fsg_lun *curlun = fsg->curlun;
2360 1884
2361 /* We don't support MODE SELECT */ 1885 /* We don't support MODE SELECT */
2362 curlun->sense_data = SS_INVALID_COMMAND; 1886 curlun->sense_data = SS_INVALID_COMMAND;
@@ -2599,7 +2123,7 @@ static int finish_reply(struct fsg_dev *fsg)
2599 2123
2600static int send_status(struct fsg_dev *fsg) 2124static int send_status(struct fsg_dev *fsg)
2601{ 2125{
2602 struct lun *curlun = fsg->curlun; 2126 struct fsg_lun *curlun = fsg->curlun;
2603 struct fsg_buffhd *bh; 2127 struct fsg_buffhd *bh;
2604 int rc; 2128 int rc;
2605 u8 status = USB_STATUS_PASS; 2129 u8 status = USB_STATUS_PASS;
@@ -2691,7 +2215,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2691 int lun = fsg->cmnd[1] >> 5; 2215 int lun = fsg->cmnd[1] >> 5;
2692 static const char dirletter[4] = {'u', 'o', 'i', 'n'}; 2216 static const char dirletter[4] = {'u', 'o', 'i', 'n'};
2693 char hdlen[20]; 2217 char hdlen[20];
2694 struct lun *curlun; 2218 struct fsg_lun *curlun;
2695 2219
2696 /* Adjust the expected cmnd_size for protocol encapsulation padding. 2220 /* Adjust the expected cmnd_size for protocol encapsulation padding.
2697 * Transparent SCSI doesn't pad. */ 2221 * Transparent SCSI doesn't pad. */
@@ -2820,7 +2344,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2820 2344
2821 /* If the medium isn't mounted and the command needs to access 2345 /* If the medium isn't mounted and the command needs to access
2822 * it, return an error. */ 2346 * it, return an error. */
2823 if (curlun && !backing_file_is_open(curlun) && needs_medium) { 2347 if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
2824 curlun->sense_data = SS_MEDIUM_NOT_PRESENT; 2348 curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
2825 return -EINVAL; 2349 return -EINVAL;
2826 } 2350 }
@@ -3075,8 +2599,8 @@ static int do_scsi_command(struct fsg_dev *fsg)
3075 2599
3076static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh) 2600static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
3077{ 2601{
3078 struct usb_request *req = bh->outreq; 2602 struct usb_request *req = bh->outreq;
3079 struct bulk_cb_wrap *cbw = req->buf; 2603 struct fsg_bulk_cb_wrap *cbw = req->buf;
3080 2604
3081 /* Was this a real packet? Should it be ignored? */ 2605 /* Was this a real packet? Should it be ignored? */
3082 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags)) 2606 if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
@@ -3105,7 +2629,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
3105 } 2629 }
3106 2630
3107 /* Is the CBW meaningful? */ 2631 /* Is the CBW meaningful? */
3108 if (cbw->Lun >= MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG || 2632 if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~USB_BULK_IN_FLAG ||
3109 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) { 2633 cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
3110 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, " 2634 DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
3111 "cmdlen %u\n", 2635 "cmdlen %u\n",
@@ -3238,7 +2762,7 @@ static int do_set_interface(struct fsg_dev *fsg, int altsetting)
3238 2762
3239reset: 2763reset:
3240 /* Deallocate the requests */ 2764 /* Deallocate the requests */
3241 for (i = 0; i < NUM_BUFFERS; ++i) { 2765 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3242 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2766 struct fsg_buffhd *bh = &fsg->buffhds[i];
3243 2767
3244 if (bh->inreq) { 2768 if (bh->inreq) {
@@ -3276,12 +2800,14 @@ reset:
3276 DBG(fsg, "set interface %d\n", altsetting); 2800 DBG(fsg, "set interface %d\n", altsetting);
3277 2801
3278 /* Enable the endpoints */ 2802 /* Enable the endpoints */
3279 d = ep_desc(fsg->gadget, &fs_bulk_in_desc, &hs_bulk_in_desc); 2803 d = fsg_ep_desc(fsg->gadget,
2804 &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc);
3280 if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0) 2805 if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
3281 goto reset; 2806 goto reset;
3282 fsg->bulk_in_enabled = 1; 2807 fsg->bulk_in_enabled = 1;
3283 2808
3284 d = ep_desc(fsg->gadget, &fs_bulk_out_desc, &hs_bulk_out_desc); 2809 d = fsg_ep_desc(fsg->gadget,
2810 &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc);
3285 if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0) 2811 if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
3286 goto reset; 2812 goto reset;
3287 fsg->bulk_out_enabled = 1; 2813 fsg->bulk_out_enabled = 1;
@@ -3289,14 +2815,15 @@ reset:
3289 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags); 2815 clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
3290 2816
3291 if (transport_is_cbi()) { 2817 if (transport_is_cbi()) {
3292 d = ep_desc(fsg->gadget, &fs_intr_in_desc, &hs_intr_in_desc); 2818 d = fsg_ep_desc(fsg->gadget,
2819 &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc);
3293 if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0) 2820 if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
3294 goto reset; 2821 goto reset;
3295 fsg->intr_in_enabled = 1; 2822 fsg->intr_in_enabled = 1;
3296 } 2823 }
3297 2824
3298 /* Allocate the requests */ 2825 /* Allocate the requests */
3299 for (i = 0; i < NUM_BUFFERS; ++i) { 2826 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3300 struct fsg_buffhd *bh = &fsg->buffhds[i]; 2827 struct fsg_buffhd *bh = &fsg->buffhds[i];
3301 2828
3302 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0) 2829 if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
@@ -3372,7 +2899,7 @@ static void handle_exception(struct fsg_dev *fsg)
3372 struct fsg_buffhd *bh; 2899 struct fsg_buffhd *bh;
3373 enum fsg_state old_state; 2900 enum fsg_state old_state;
3374 u8 new_config; 2901 u8 new_config;
3375 struct lun *curlun; 2902 struct fsg_lun *curlun;
3376 unsigned int exception_req_tag; 2903 unsigned int exception_req_tag;
3377 int rc; 2904 int rc;
3378 2905
@@ -3392,7 +2919,7 @@ static void handle_exception(struct fsg_dev *fsg)
3392 /* Cancel all the pending transfers */ 2919 /* Cancel all the pending transfers */
3393 if (fsg->intreq_busy) 2920 if (fsg->intreq_busy)
3394 usb_ep_dequeue(fsg->intr_in, fsg->intreq); 2921 usb_ep_dequeue(fsg->intr_in, fsg->intreq);
3395 for (i = 0; i < NUM_BUFFERS; ++i) { 2922 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3396 bh = &fsg->buffhds[i]; 2923 bh = &fsg->buffhds[i];
3397 if (bh->inreq_busy) 2924 if (bh->inreq_busy)
3398 usb_ep_dequeue(fsg->bulk_in, bh->inreq); 2925 usb_ep_dequeue(fsg->bulk_in, bh->inreq);
@@ -3403,7 +2930,7 @@ static void handle_exception(struct fsg_dev *fsg)
3403 /* Wait until everything is idle */ 2930 /* Wait until everything is idle */
3404 for (;;) { 2931 for (;;) {
3405 num_active = fsg->intreq_busy; 2932 num_active = fsg->intreq_busy;
3406 for (i = 0; i < NUM_BUFFERS; ++i) { 2933 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3407 bh = &fsg->buffhds[i]; 2934 bh = &fsg->buffhds[i];
3408 num_active += bh->inreq_busy + bh->outreq_busy; 2935 num_active += bh->inreq_busy + bh->outreq_busy;
3409 } 2936 }
@@ -3425,7 +2952,7 @@ static void handle_exception(struct fsg_dev *fsg)
3425 * state, and the exception. Then invoke the handler. */ 2952 * state, and the exception. Then invoke the handler. */
3426 spin_lock_irq(&fsg->lock); 2953 spin_lock_irq(&fsg->lock);
3427 2954
3428 for (i = 0; i < NUM_BUFFERS; ++i) { 2955 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
3429 bh = &fsg->buffhds[i]; 2956 bh = &fsg->buffhds[i];
3430 bh->state = BUF_STATE_EMPTY; 2957 bh->state = BUF_STATE_EMPTY;
3431 } 2958 }
@@ -3506,7 +3033,8 @@ static void handle_exception(struct fsg_dev *fsg)
3506 break; 3033 break;
3507 3034
3508 case FSG_STATE_DISCONNECT: 3035 case FSG_STATE_DISCONNECT:
3509 fsync_all(fsg); 3036 for (i = 0; i < fsg->nluns; ++i)
3037 fsg_lun_fsync_sub(fsg->luns + i);
3510 do_set_config(fsg, 0); // Unconfigured state 3038 do_set_config(fsg, 0); // Unconfigured state
3511 break; 3039 break;
3512 3040
@@ -3595,201 +3123,10 @@ static int fsg_main_thread(void *fsg_)
3595 3123
3596/*-------------------------------------------------------------------------*/ 3124/*-------------------------------------------------------------------------*/
3597 3125
3598/* If the next two routines are called while the gadget is registered,
3599 * the caller must own fsg->filesem for writing. */
3600
3601static int open_backing_file(struct lun *curlun, const char *filename)
3602{
3603 int ro;
3604 struct file *filp = NULL;
3605 int rc = -EINVAL;
3606 struct inode *inode = NULL;
3607 loff_t size;
3608 loff_t num_sectors;
3609 loff_t min_sectors;
3610
3611 /* R/W if we can, R/O if we must */
3612 ro = curlun->ro;
3613 if (!ro) {
3614 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
3615 if (-EROFS == PTR_ERR(filp))
3616 ro = 1;
3617 }
3618 if (ro)
3619 filp = filp_open(filename, O_RDONLY | O_LARGEFILE, 0);
3620 if (IS_ERR(filp)) {
3621 LINFO(curlun, "unable to open backing file: %s\n", filename);
3622 return PTR_ERR(filp);
3623 }
3624
3625 if (!(filp->f_mode & FMODE_WRITE))
3626 ro = 1;
3627
3628 if (filp->f_path.dentry)
3629 inode = filp->f_path.dentry->d_inode;
3630 if (inode && S_ISBLK(inode->i_mode)) {
3631 if (bdev_read_only(inode->i_bdev))
3632 ro = 1;
3633 } else if (!inode || !S_ISREG(inode->i_mode)) {
3634 LINFO(curlun, "invalid file type: %s\n", filename);
3635 goto out;
3636 }
3637
3638 /* If we can't read the file, it's no good.
3639 * If we can't write the file, use it read-only. */
3640 if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) {
3641 LINFO(curlun, "file not readable: %s\n", filename);
3642 goto out;
3643 }
3644 if (!(filp->f_op->write || filp->f_op->aio_write))
3645 ro = 1;
3646
3647 size = i_size_read(inode->i_mapping->host);
3648 if (size < 0) {
3649 LINFO(curlun, "unable to find file size: %s\n", filename);
3650 rc = (int) size;
3651 goto out;
3652 }
3653 num_sectors = size >> 9; // File size in 512-byte blocks
3654 min_sectors = 1;
3655 if (mod_data.cdrom) {
3656 num_sectors &= ~3; // Reduce to a multiple of 2048
3657 min_sectors = 300*4; // Smallest track is 300 frames
3658 if (num_sectors >= 256*60*75*4) {
3659 num_sectors = (256*60*75 - 1) * 4;
3660 LINFO(curlun, "file too big: %s\n", filename);
3661 LINFO(curlun, "using only first %d blocks\n",
3662 (int) num_sectors);
3663 }
3664 }
3665 if (num_sectors < min_sectors) {
3666 LINFO(curlun, "file too small: %s\n", filename);
3667 rc = -ETOOSMALL;
3668 goto out;
3669 }
3670
3671 get_file(filp);
3672 curlun->ro = ro;
3673 curlun->filp = filp;
3674 curlun->file_length = size;
3675 curlun->num_sectors = num_sectors;
3676 LDBG(curlun, "open backing file: %s\n", filename);
3677 rc = 0;
3678
3679out:
3680 filp_close(filp, current->files);
3681 return rc;
3682}
3683
3684
3685static void close_backing_file(struct lun *curlun)
3686{
3687 if (curlun->filp) {
3688 LDBG(curlun, "close backing file\n");
3689 fput(curlun->filp);
3690 curlun->filp = NULL;
3691 }
3692}
3693
3694
3695static ssize_t show_ro(struct device *dev, struct device_attribute *attr, char *buf)
3696{
3697 struct lun *curlun = dev_to_lun(dev);
3698
3699 return sprintf(buf, "%d\n", curlun->ro);
3700}
3701
3702static ssize_t show_file(struct device *dev, struct device_attribute *attr,
3703 char *buf)
3704{
3705 struct lun *curlun = dev_to_lun(dev);
3706 struct fsg_dev *fsg = dev_get_drvdata(dev);
3707 char *p;
3708 ssize_t rc;
3709
3710 down_read(&fsg->filesem);
3711 if (backing_file_is_open(curlun)) { // Get the complete pathname
3712 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1);
3713 if (IS_ERR(p))
3714 rc = PTR_ERR(p);
3715 else {
3716 rc = strlen(p);
3717 memmove(buf, p, rc);
3718 buf[rc] = '\n'; // Add a newline
3719 buf[++rc] = 0;
3720 }
3721 } else { // No file, return 0 bytes
3722 *buf = 0;
3723 rc = 0;
3724 }
3725 up_read(&fsg->filesem);
3726 return rc;
3727}
3728
3729
3730static ssize_t store_ro(struct device *dev, struct device_attribute *attr,
3731 const char *buf, size_t count)
3732{
3733 ssize_t rc = count;
3734 struct lun *curlun = dev_to_lun(dev);
3735 struct fsg_dev *fsg = dev_get_drvdata(dev);
3736 int i;
3737
3738 if (sscanf(buf, "%d", &i) != 1)
3739 return -EINVAL;
3740
3741 /* Allow the write-enable status to change only while the backing file
3742 * is closed. */
3743 down_read(&fsg->filesem);
3744 if (backing_file_is_open(curlun)) {
3745 LDBG(curlun, "read-only status change prevented\n");
3746 rc = -EBUSY;
3747 } else {
3748 curlun->ro = !!i;
3749 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
3750 }
3751 up_read(&fsg->filesem);
3752 return rc;
3753}
3754
3755static ssize_t store_file(struct device *dev, struct device_attribute *attr,
3756 const char *buf, size_t count)
3757{
3758 struct lun *curlun = dev_to_lun(dev);
3759 struct fsg_dev *fsg = dev_get_drvdata(dev);
3760 int rc = 0;
3761
3762 if (curlun->prevent_medium_removal && backing_file_is_open(curlun)) {
3763 LDBG(curlun, "eject attempt prevented\n");
3764 return -EBUSY; // "Door is locked"
3765 }
3766
3767 /* Remove a trailing newline */
3768 if (count > 0 && buf[count-1] == '\n')
3769 ((char *) buf)[count-1] = 0; // Ugh!
3770
3771 /* Eject current medium */
3772 down_write(&fsg->filesem);
3773 if (backing_file_is_open(curlun)) {
3774 close_backing_file(curlun);
3775 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
3776 }
3777
3778 /* Load new medium */
3779 if (count > 0 && buf[0]) {
3780 rc = open_backing_file(curlun, buf);
3781 if (rc == 0)
3782 curlun->unit_attention_data =
3783 SS_NOT_READY_TO_READY_TRANSITION;
3784 }
3785 up_write(&fsg->filesem);
3786 return (rc < 0 ? rc : count);
3787}
3788
3789 3126
3790/* The write permissions and store_xxx pointers are set in fsg_bind() */ 3127/* The write permissions and store_xxx pointers are set in fsg_bind() */
3791static DEVICE_ATTR(ro, 0444, show_ro, NULL); 3128static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
3792static DEVICE_ATTR(file, 0444, show_file, NULL); 3129static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
3793 3130
3794 3131
3795/*-------------------------------------------------------------------------*/ 3132/*-------------------------------------------------------------------------*/
@@ -3804,7 +3141,9 @@ static void fsg_release(struct kref *ref)
3804 3141
3805static void lun_release(struct device *dev) 3142static void lun_release(struct device *dev)
3806{ 3143{
3807 struct fsg_dev *fsg = dev_get_drvdata(dev); 3144 struct rw_semaphore *filesem = dev_get_drvdata(dev);
3145 struct fsg_dev *fsg =
3146 container_of(filesem, struct fsg_dev, filesem);
3808 3147
3809 kref_put(&fsg->ref, fsg_release); 3148 kref_put(&fsg->ref, fsg_release);
3810} 3149}
@@ -3813,7 +3152,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3813{ 3152{
3814 struct fsg_dev *fsg = get_gadget_data(gadget); 3153 struct fsg_dev *fsg = get_gadget_data(gadget);
3815 int i; 3154 int i;
3816 struct lun *curlun; 3155 struct fsg_lun *curlun;
3817 struct usb_request *req = fsg->ep0req; 3156 struct usb_request *req = fsg->ep0req;
3818 3157
3819 DBG(fsg, "unbind\n"); 3158 DBG(fsg, "unbind\n");
@@ -3825,7 +3164,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3825 if (curlun->registered) { 3164 if (curlun->registered) {
3826 device_remove_file(&curlun->dev, &dev_attr_ro); 3165 device_remove_file(&curlun->dev, &dev_attr_ro);
3827 device_remove_file(&curlun->dev, &dev_attr_file); 3166 device_remove_file(&curlun->dev, &dev_attr_file);
3828 close_backing_file(curlun); 3167 fsg_lun_close(curlun);
3829 device_unregister(&curlun->dev); 3168 device_unregister(&curlun->dev);
3830 curlun->registered = 0; 3169 curlun->registered = 0;
3831 } 3170 }
@@ -3841,7 +3180,7 @@ static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
3841 } 3180 }
3842 3181
3843 /* Free the data buffers */ 3182 /* Free the data buffers */
3844 for (i = 0; i < NUM_BUFFERS; ++i) 3183 for (i = 0; i < FSG_NUM_BUFFERS; ++i)
3845 kfree(fsg->buffhds[i].buf); 3184 kfree(fsg->buffhds[i].buf);
3846 3185
3847 /* Free the request and buffer for endpoint 0 */ 3186 /* Free the request and buffer for endpoint 0 */
@@ -3869,15 +3208,11 @@ static int __init check_parameters(struct fsg_dev *fsg)
3869 * halt bulk endpoints correctly. If one of them is present, 3208 * halt bulk endpoints correctly. If one of them is present,
3870 * disable stalls. 3209 * disable stalls.
3871 */ 3210 */
3872 if (gadget_is_sh(fsg->gadget) || gadget_is_at91(fsg->gadget)) 3211 if (gadget_is_at91(fsg->gadget))
3873 mod_data.can_stall = 0; 3212 mod_data.can_stall = 0;
3874 3213
3875 if (mod_data.release == 0xffff) { // Parameter wasn't set 3214 if (mod_data.release == 0xffff) { // Parameter wasn't set
3876 /* The sa1100 controller is not supported */ 3215 gcnum = usb_gadget_controller_number(fsg->gadget);
3877 if (gadget_is_sa1100(fsg->gadget))
3878 gcnum = -1;
3879 else
3880 gcnum = usb_gadget_controller_number(fsg->gadget);
3881 if (gcnum >= 0) 3216 if (gcnum >= 0)
3882 mod_data.release = 0x0300 + gcnum; 3217 mod_data.release = 0x0300 + gcnum;
3883 else { 3218 else {
@@ -3948,7 +3283,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3948 struct fsg_dev *fsg = the_fsg; 3283 struct fsg_dev *fsg = the_fsg;
3949 int rc; 3284 int rc;
3950 int i; 3285 int i;
3951 struct lun *curlun; 3286 struct fsg_lun *curlun;
3952 struct usb_ep *ep; 3287 struct usb_ep *ep;
3953 struct usb_request *req; 3288 struct usb_request *req;
3954 char *pathbuf, *p; 3289 char *pathbuf, *p;
@@ -3963,10 +3298,10 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3963 3298
3964 if (mod_data.removable) { // Enable the store_xxx attributes 3299 if (mod_data.removable) { // Enable the store_xxx attributes
3965 dev_attr_file.attr.mode = 0644; 3300 dev_attr_file.attr.mode = 0644;
3966 dev_attr_file.store = store_file; 3301 dev_attr_file.store = fsg_store_file;
3967 if (!mod_data.cdrom) { 3302 if (!mod_data.cdrom) {
3968 dev_attr_ro.attr.mode = 0644; 3303 dev_attr_ro.attr.mode = 0644;
3969 dev_attr_ro.store = store_ro; 3304 dev_attr_ro.store = fsg_store_ro;
3970 } 3305 }
3971 } 3306 }
3972 3307
@@ -3974,7 +3309,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3974 i = mod_data.nluns; 3309 i = mod_data.nluns;
3975 if (i == 0) 3310 if (i == 0)
3976 i = max(mod_data.num_filenames, 1u); 3311 i = max(mod_data.num_filenames, 1u);
3977 if (i > MAX_LUNS) { 3312 if (i > FSG_MAX_LUNS) {
3978 ERROR(fsg, "invalid number of LUNs: %d\n", i); 3313 ERROR(fsg, "invalid number of LUNs: %d\n", i);
3979 rc = -EINVAL; 3314 rc = -EINVAL;
3980 goto out; 3315 goto out;
@@ -3982,7 +3317,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3982 3317
3983 /* Create the LUNs, open their backing files, and register the 3318 /* Create the LUNs, open their backing files, and register the
3984 * LUN devices in sysfs. */ 3319 * LUN devices in sysfs. */
3985 fsg->luns = kzalloc(i * sizeof(struct lun), GFP_KERNEL); 3320 fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
3986 if (!fsg->luns) { 3321 if (!fsg->luns) {
3987 rc = -ENOMEM; 3322 rc = -ENOMEM;
3988 goto out; 3323 goto out;
@@ -3991,13 +3326,14 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3991 3326
3992 for (i = 0; i < fsg->nluns; ++i) { 3327 for (i = 0; i < fsg->nluns; ++i) {
3993 curlun = &fsg->luns[i]; 3328 curlun = &fsg->luns[i];
3994 curlun->ro = mod_data.ro[i]; 3329 curlun->cdrom = !!mod_data.cdrom;
3995 if (mod_data.cdrom) 3330 curlun->ro = mod_data.cdrom || mod_data.ro[i];
3996 curlun->ro = 1; 3331 curlun->initially_ro = curlun->ro;
3332 curlun->removable = mod_data.removable;
3997 curlun->dev.release = lun_release; 3333 curlun->dev.release = lun_release;
3998 curlun->dev.parent = &gadget->dev; 3334 curlun->dev.parent = &gadget->dev;
3999 curlun->dev.driver = &fsg_driver.driver; 3335 curlun->dev.driver = &fsg_driver.driver;
4000 dev_set_drvdata(&curlun->dev, fsg); 3336 dev_set_drvdata(&curlun->dev, &fsg->filesem);
4001 dev_set_name(&curlun->dev,"%s-lun%d", 3337 dev_set_name(&curlun->dev,"%s-lun%d",
4002 dev_name(&gadget->dev), i); 3338 dev_name(&gadget->dev), i);
4003 3339
@@ -4016,7 +3352,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4016 kref_get(&fsg->ref); 3352 kref_get(&fsg->ref);
4017 3353
4018 if (mod_data.file[i] && *mod_data.file[i]) { 3354 if (mod_data.file[i] && *mod_data.file[i]) {
4019 if ((rc = open_backing_file(curlun, 3355 if ((rc = fsg_lun_open(curlun,
4020 mod_data.file[i])) != 0) 3356 mod_data.file[i])) != 0)
4021 goto out; 3357 goto out;
4022 } else if (!mod_data.removable) { 3358 } else if (!mod_data.removable) {
@@ -4028,20 +3364,20 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4028 3364
4029 /* Find all the endpoints we will use */ 3365 /* Find all the endpoints we will use */
4030 usb_ep_autoconfig_reset(gadget); 3366 usb_ep_autoconfig_reset(gadget);
4031 ep = usb_ep_autoconfig(gadget, &fs_bulk_in_desc); 3367 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
4032 if (!ep) 3368 if (!ep)
4033 goto autoconf_fail; 3369 goto autoconf_fail;
4034 ep->driver_data = fsg; // claim the endpoint 3370 ep->driver_data = fsg; // claim the endpoint
4035 fsg->bulk_in = ep; 3371 fsg->bulk_in = ep;
4036 3372
4037 ep = usb_ep_autoconfig(gadget, &fs_bulk_out_desc); 3373 ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
4038 if (!ep) 3374 if (!ep)
4039 goto autoconf_fail; 3375 goto autoconf_fail;
4040 ep->driver_data = fsg; // claim the endpoint 3376 ep->driver_data = fsg; // claim the endpoint
4041 fsg->bulk_out = ep; 3377 fsg->bulk_out = ep;
4042 3378
4043 if (transport_is_cbi()) { 3379 if (transport_is_cbi()) {
4044 ep = usb_ep_autoconfig(gadget, &fs_intr_in_desc); 3380 ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
4045 if (!ep) 3381 if (!ep)
4046 goto autoconf_fail; 3382 goto autoconf_fail;
4047 ep->driver_data = fsg; // claim the endpoint 3383 ep->driver_data = fsg; // claim the endpoint
@@ -4055,28 +3391,28 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4055 device_desc.bcdDevice = cpu_to_le16(mod_data.release); 3391 device_desc.bcdDevice = cpu_to_le16(mod_data.release);
4056 3392
4057 i = (transport_is_cbi() ? 3 : 2); // Number of endpoints 3393 i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
4058 intf_desc.bNumEndpoints = i; 3394 fsg_intf_desc.bNumEndpoints = i;
4059 intf_desc.bInterfaceSubClass = mod_data.protocol_type; 3395 fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
4060 intf_desc.bInterfaceProtocol = mod_data.transport_type; 3396 fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
4061 fs_function[i + FS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3397 fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
4062 3398
4063 if (gadget_is_dualspeed(gadget)) { 3399 if (gadget_is_dualspeed(gadget)) {
4064 hs_function[i + HS_FUNCTION_PRE_EP_ENTRIES] = NULL; 3400 fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
4065 3401
4066 /* Assume ep0 uses the same maxpacket value for both speeds */ 3402 /* Assume ep0 uses the same maxpacket value for both speeds */
4067 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket; 3403 dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
4068 3404
4069 /* Assume endpoint addresses are the same for both speeds */ 3405 /* Assume endpoint addresses are the same for both speeds */
4070 hs_bulk_in_desc.bEndpointAddress = 3406 fsg_hs_bulk_in_desc.bEndpointAddress =
4071 fs_bulk_in_desc.bEndpointAddress; 3407 fsg_fs_bulk_in_desc.bEndpointAddress;
4072 hs_bulk_out_desc.bEndpointAddress = 3408 fsg_hs_bulk_out_desc.bEndpointAddress =
4073 fs_bulk_out_desc.bEndpointAddress; 3409 fsg_fs_bulk_out_desc.bEndpointAddress;
4074 hs_intr_in_desc.bEndpointAddress = 3410 fsg_hs_intr_in_desc.bEndpointAddress =
4075 fs_intr_in_desc.bEndpointAddress; 3411 fsg_fs_intr_in_desc.bEndpointAddress;
4076 } 3412 }
4077 3413
4078 if (gadget_is_otg(gadget)) 3414 if (gadget_is_otg(gadget))
4079 otg_desc.bmAttributes |= USB_OTG_HNP; 3415 fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
4080 3416
4081 rc = -ENOMEM; 3417 rc = -ENOMEM;
4082 3418
@@ -4090,7 +3426,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4090 req->complete = ep0_complete; 3426 req->complete = ep0_complete;
4091 3427
4092 /* Allocate the data buffers */ 3428 /* Allocate the data buffers */
4093 for (i = 0; i < NUM_BUFFERS; ++i) { 3429 for (i = 0; i < FSG_NUM_BUFFERS; ++i) {
4094 struct fsg_buffhd *bh = &fsg->buffhds[i]; 3430 struct fsg_buffhd *bh = &fsg->buffhds[i];
4095 3431
4096 /* Allocate for the bulk-in endpoint. We assume that 3432 /* Allocate for the bulk-in endpoint. We assume that
@@ -4101,23 +3437,24 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4101 goto out; 3437 goto out;
4102 bh->next = bh + 1; 3438 bh->next = bh + 1;
4103 } 3439 }
4104 fsg->buffhds[NUM_BUFFERS - 1].next = &fsg->buffhds[0]; 3440 fsg->buffhds[FSG_NUM_BUFFERS - 1].next = &fsg->buffhds[0];
4105 3441
4106 /* This should reflect the actual gadget power source */ 3442 /* This should reflect the actual gadget power source */
4107 usb_gadget_set_selfpowered(gadget); 3443 usb_gadget_set_selfpowered(gadget);
4108 3444
4109 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s", 3445 snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
3446 "%s %s with %s",
4110 init_utsname()->sysname, init_utsname()->release, 3447 init_utsname()->sysname, init_utsname()->release,
4111 gadget->name); 3448 gadget->name);
4112 3449
4113 /* On a real device, serial[] would be loaded from permanent 3450 /* On a real device, serial[] would be loaded from permanent
4114 * storage. We just encode it from the driver version string. */ 3451 * storage. We just encode it from the driver version string. */
4115 for (i = 0; i < sizeof(serial) - 2; i += 2) { 3452 for (i = 0; i < sizeof fsg_string_serial - 2; i += 2) {
4116 unsigned char c = DRIVER_VERSION[i / 2]; 3453 unsigned char c = DRIVER_VERSION[i / 2];
4117 3454
4118 if (!c) 3455 if (!c)
4119 break; 3456 break;
4120 sprintf(&serial[i], "%02X", c); 3457 sprintf(&fsg_string_serial[i], "%02X", c);
4121 } 3458 }
4122 3459
4123 fsg->thread_task = kthread_create(fsg_main_thread, fsg, 3460 fsg->thread_task = kthread_create(fsg_main_thread, fsg,
@@ -4133,7 +3470,7 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4133 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL); 3470 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
4134 for (i = 0; i < fsg->nluns; ++i) { 3471 for (i = 0; i < fsg->nluns; ++i) {
4135 curlun = &fsg->luns[i]; 3472 curlun = &fsg->luns[i];
4136 if (backing_file_is_open(curlun)) { 3473 if (fsg_lun_is_open(curlun)) {
4137 p = NULL; 3474 p = NULL;
4138 if (pathbuf) { 3475 if (pathbuf) {
4139 p = d_path(&curlun->filp->f_path, 3476 p = d_path(&curlun->filp->f_path,
@@ -4203,7 +3540,7 @@ static struct usb_gadget_driver fsg_driver = {
4203#else 3540#else
4204 .speed = USB_SPEED_FULL, 3541 .speed = USB_SPEED_FULL,
4205#endif 3542#endif
4206 .function = (char *) longname, 3543 .function = (char *) fsg_string_product,
4207 .bind = fsg_bind, 3544 .bind = fsg_bind,
4208 .unbind = fsg_unbind, 3545 .unbind = fsg_unbind,
4209 .disconnect = fsg_disconnect, 3546 .disconnect = fsg_disconnect,
@@ -4212,7 +3549,7 @@ static struct usb_gadget_driver fsg_driver = {
4212 .resume = fsg_resume, 3549 .resume = fsg_resume,
4213 3550
4214 .driver = { 3551 .driver = {
4215 .name = (char *) shortname, 3552 .name = DRIVER_NAME,
4216 .owner = THIS_MODULE, 3553 .owner = THIS_MODULE,
4217 // .release = ... 3554 // .release = ...
4218 // .suspend = ... 3555 // .suspend = ...
diff --git a/drivers/usb/gadget/fsl_mx3_udc.c b/drivers/usb/gadget/fsl_mx3_udc.c
index 4bc2bf3d602e..20a802ecaa15 100644
--- a/drivers/usb/gadget/fsl_mx3_udc.c
+++ b/drivers/usb/gadget/fsl_mx3_udc.c
@@ -17,6 +17,8 @@
17#include <linux/fsl_devices.h> 17#include <linux/fsl_devices.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19 19
20#include <mach/hardware.h>
21
20static struct clk *mxc_ahb_clk; 22static struct clk *mxc_ahb_clk;
21static struct clk *mxc_usb_clk; 23static struct clk *mxc_usb_clk;
22 24
@@ -28,14 +30,16 @@ int fsl_udc_clk_init(struct platform_device *pdev)
28 30
29 pdata = pdev->dev.platform_data; 31 pdata = pdev->dev.platform_data;
30 32
31 mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb"); 33 if (!cpu_is_mx35()) {
32 if (IS_ERR(mxc_ahb_clk)) 34 mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb");
33 return PTR_ERR(mxc_ahb_clk); 35 if (IS_ERR(mxc_ahb_clk))
36 return PTR_ERR(mxc_ahb_clk);
34 37
35 ret = clk_enable(mxc_ahb_clk); 38 ret = clk_enable(mxc_ahb_clk);
36 if (ret < 0) { 39 if (ret < 0) {
37 dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n"); 40 dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n");
38 goto eenahb; 41 goto eenahb;
42 }
39 } 43 }
40 44
41 /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */ 45 /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
@@ -50,6 +54,7 @@ int fsl_udc_clk_init(struct platform_device *pdev)
50 if (pdata->phy_mode != FSL_USB2_PHY_ULPI && 54 if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
51 (freq < 59999000 || freq > 60001000)) { 55 (freq < 59999000 || freq > 60001000)) {
52 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq); 56 dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
57 ret = -EINVAL;
53 goto eclkrate; 58 goto eclkrate;
54 } 59 }
55 60
@@ -66,9 +71,11 @@ eclkrate:
66 clk_put(mxc_usb_clk); 71 clk_put(mxc_usb_clk);
67 mxc_usb_clk = NULL; 72 mxc_usb_clk = NULL;
68egusb: 73egusb:
69 clk_disable(mxc_ahb_clk); 74 if (!cpu_is_mx35())
75 clk_disable(mxc_ahb_clk);
70eenahb: 76eenahb:
71 clk_put(mxc_ahb_clk); 77 if (!cpu_is_mx35())
78 clk_put(mxc_ahb_clk);
72 return ret; 79 return ret;
73} 80}
74 81
@@ -90,6 +97,8 @@ void fsl_udc_clk_release(void)
90 clk_disable(mxc_usb_clk); 97 clk_disable(mxc_usb_clk);
91 clk_put(mxc_usb_clk); 98 clk_put(mxc_usb_clk);
92 } 99 }
93 clk_disable(mxc_ahb_clk); 100 if (!cpu_is_mx35()) {
94 clk_put(mxc_ahb_clk); 101 clk_disable(mxc_ahb_clk);
102 clk_put(mxc_ahb_clk);
103 }
95} 104}
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 7881f12413c4..3537d51073b2 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2749,7 +2749,7 @@ static int __devexit qe_udc_remove(struct of_device *ofdev)
2749} 2749}
2750 2750
2751/*-------------------------------------------------------------------------*/ 2751/*-------------------------------------------------------------------------*/
2752static struct of_device_id __devinitdata qe_udc_match[] = { 2752static const struct of_device_id qe_udc_match[] __devinitconst = {
2753 { 2753 {
2754 .compatible = "fsl,mpc8323-qe-usb", 2754 .compatible = "fsl,mpc8323-qe-usb",
2755 .data = (void *)PORT_QE, 2755 .data = (void *)PORT_QE,
diff --git a/drivers/usb/gadget/fsl_qe_udc.h b/drivers/usb/gadget/fsl_qe_udc.h
index 31b2710882e4..bea5b827bebe 100644
--- a/drivers/usb/gadget/fsl_qe_udc.h
+++ b/drivers/usb/gadget/fsl_qe_udc.h
@@ -419,19 +419,4 @@ struct qe_udc {
419#define CPM_USB_RESTART_TX_OPCODE 0x0b 419#define CPM_USB_RESTART_TX_OPCODE 0x0b
420#define CPM_USB_EP_SHIFT 5 420#define CPM_USB_EP_SHIFT 5
421 421
422#ifndef CONFIG_CPM
423inline int cpm_command(u32 command, u8 opcode)
424{
425 return -EOPNOTSUPP;
426}
427#endif
428
429#ifndef CONFIG_QUICC_ENGINE
430inline int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol,
431 u32 cmd_input)
432{
433 return -EOPNOTSUPP;
434}
435#endif
436
437#endif /* __FSL_QE_UDC_H */ 422#endif /* __FSL_QE_UDC_H */
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index f2d270b202f2..e511fec9f26d 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -45,46 +45,18 @@
45#define gadget_is_goku(g) 0 45#define gadget_is_goku(g) 0
46#endif 46#endif
47 47
48/* SH3 UDC -- not yet ported 2.4 --> 2.6 */
49#ifdef CONFIG_USB_GADGET_SUPERH
50#define gadget_is_sh(g) !strcmp("sh_udc", (g)->name)
51#else
52#define gadget_is_sh(g) 0
53#endif
54
55/* not yet stable on 2.6 (would help "original Zaurus") */
56#ifdef CONFIG_USB_GADGET_SA1100
57#define gadget_is_sa1100(g) !strcmp("sa1100_udc", (g)->name)
58#else
59#define gadget_is_sa1100(g) 0
60#endif
61
62#ifdef CONFIG_USB_GADGET_LH7A40X 48#ifdef CONFIG_USB_GADGET_LH7A40X
63#define gadget_is_lh7a40x(g) !strcmp("lh7a40x_udc", (g)->name) 49#define gadget_is_lh7a40x(g) !strcmp("lh7a40x_udc", (g)->name)
64#else 50#else
65#define gadget_is_lh7a40x(g) 0 51#define gadget_is_lh7a40x(g) 0
66#endif 52#endif
67 53
68/* handhelds.org tree (?) */
69#ifdef CONFIG_USB_GADGET_MQ11XX
70#define gadget_is_mq11xx(g) !strcmp("mq11xx_udc", (g)->name)
71#else
72#define gadget_is_mq11xx(g) 0
73#endif
74
75#ifdef CONFIG_USB_GADGET_OMAP 54#ifdef CONFIG_USB_GADGET_OMAP
76#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name) 55#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name)
77#else 56#else
78#define gadget_is_omap(g) 0 57#define gadget_is_omap(g) 0
79#endif 58#endif
80 59
81/* not yet ported 2.4 --> 2.6 */
82#ifdef CONFIG_USB_GADGET_N9604
83#define gadget_is_n9604(g) !strcmp("n9604_udc", (g)->name)
84#else
85#define gadget_is_n9604(g) 0
86#endif
87
88/* various unstable versions available */ 60/* various unstable versions available */
89#ifdef CONFIG_USB_GADGET_PXA27X 61#ifdef CONFIG_USB_GADGET_PXA27X
90#define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name) 62#define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name)
@@ -122,14 +94,6 @@
122#define gadget_is_fsl_usb2(g) 0 94#define gadget_is_fsl_usb2(g) 0
123#endif 95#endif
124 96
125/* Mentor high speed function controller */
126/* from Montavista kernel (?) */
127#ifdef CONFIG_USB_GADGET_MUSBHSFC
128#define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name)
129#else
130#define gadget_is_musbhsfc(g) 0
131#endif
132
133/* Mentor high speed "dual role" controller, in peripheral role */ 97/* Mentor high speed "dual role" controller, in peripheral role */
134#ifdef CONFIG_USB_GADGET_MUSB_HDRC 98#ifdef CONFIG_USB_GADGET_MUSB_HDRC
135#define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name) 99#define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name)
@@ -143,13 +107,6 @@
143#define gadget_is_langwell(g) 0 107#define gadget_is_langwell(g) 0
144#endif 108#endif
145 109
146/* from Montavista kernel (?) */
147#ifdef CONFIG_USB_GADGET_MPC8272
148#define gadget_is_mpc8272(g) !strcmp("mpc8272_udc", (g)->name)
149#else
150#define gadget_is_mpc8272(g) 0
151#endif
152
153#ifdef CONFIG_USB_GADGET_M66592 110#ifdef CONFIG_USB_GADGET_M66592
154#define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name) 111#define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name)
155#else 112#else
@@ -179,6 +136,12 @@
179#define gadget_is_r8a66597(g) 0 136#define gadget_is_r8a66597(g) 0
180#endif 137#endif
181 138
139#ifdef CONFIG_USB_S3C_HSOTG
140#define gadget_is_s3c_hsotg(g) (!strcmp("s3c-hsotg", (g)->name))
141#else
142#define gadget_is_s3c_hsotg(g) 0
143#endif
144
182 145
183/** 146/**
184 * usb_gadget_controller_number - support bcdDevice id convention 147 * usb_gadget_controller_number - support bcdDevice id convention
@@ -203,20 +166,12 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
203 return 0x02; 166 return 0x02;
204 else if (gadget_is_pxa(gadget)) 167 else if (gadget_is_pxa(gadget))
205 return 0x03; 168 return 0x03;
206 else if (gadget_is_sh(gadget))
207 return 0x04;
208 else if (gadget_is_sa1100(gadget))
209 return 0x05;
210 else if (gadget_is_goku(gadget)) 169 else if (gadget_is_goku(gadget))
211 return 0x06; 170 return 0x06;
212 else if (gadget_is_mq11xx(gadget))
213 return 0x07;
214 else if (gadget_is_omap(gadget)) 171 else if (gadget_is_omap(gadget))
215 return 0x08; 172 return 0x08;
216 else if (gadget_is_lh7a40x(gadget)) 173 else if (gadget_is_lh7a40x(gadget))
217 return 0x09; 174 return 0x09;
218 else if (gadget_is_n9604(gadget))
219 return 0x10;
220 else if (gadget_is_pxa27x(gadget)) 175 else if (gadget_is_pxa27x(gadget))
221 return 0x11; 176 return 0x11;
222 else if (gadget_is_s3c2410(gadget)) 177 else if (gadget_is_s3c2410(gadget))
@@ -225,12 +180,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
225 return 0x13; 180 return 0x13;
226 else if (gadget_is_imx(gadget)) 181 else if (gadget_is_imx(gadget))
227 return 0x14; 182 return 0x14;
228 else if (gadget_is_musbhsfc(gadget))
229 return 0x15;
230 else if (gadget_is_musbhdrc(gadget)) 183 else if (gadget_is_musbhdrc(gadget))
231 return 0x16; 184 return 0x16;
232 else if (gadget_is_mpc8272(gadget))
233 return 0x17;
234 else if (gadget_is_atmel_usba(gadget)) 185 else if (gadget_is_atmel_usba(gadget))
235 return 0x18; 186 return 0x18;
236 else if (gadget_is_fsl_usb2(gadget)) 187 else if (gadget_is_fsl_usb2(gadget))
@@ -247,6 +198,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
247 return 0x24; 198 return 0x24;
248 else if (gadget_is_r8a66597(gadget)) 199 else if (gadget_is_r8a66597(gadget))
249 return 0x25; 200 return 0x25;
201 else if (gadget_is_s3c_hsotg(gadget))
202 return 0x26;
250 return -ENOENT; 203 return -ENOENT;
251} 204}
252 205
@@ -265,10 +218,6 @@ static inline bool gadget_supports_altsettings(struct usb_gadget *gadget)
265 if (gadget_is_pxa27x(gadget)) 218 if (gadget_is_pxa27x(gadget))
266 return false; 219 return false;
267 220
268 /* SH3 hardware just doesn't do altsettings */
269 if (gadget_is_sh(gadget))
270 return false;
271
272 /* Everything else is *presumably* fine ... */ 221 /* Everything else is *presumably* fine ... */
273 return true; 222 return true;
274} 223}
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index d0b1e836f0e0..2b56ce621852 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -21,6 +21,7 @@
21/* #define VERBOSE_DEBUG */ 21/* #define VERBOSE_DEBUG */
22 22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h>
24#include <linux/utsname.h> 25#include <linux/utsname.h>
25#include <linux/device.h> 26#include <linux/device.h>
26 27
@@ -237,7 +238,7 @@ static const struct usb_interface_descriptor ac_interface_desc = {
237}; 238};
238 239
239/* B.3.2 Class-Specific AC Interface Descriptor */ 240/* B.3.2 Class-Specific AC Interface Descriptor */
240static const struct uac_ac_header_descriptor_1 ac_header_desc = { 241static const struct uac_ac_header_descriptor_v1_1 ac_header_desc = {
241 .bLength = UAC_DT_AC_HEADER_SIZE(1), 242 .bLength = UAC_DT_AC_HEADER_SIZE(1),
242 .bDescriptorType = USB_DT_CS_INTERFACE, 243 .bDescriptorType = USB_DT_CS_INTERFACE,
243 .bDescriptorSubtype = USB_MS_HEADER, 244 .bDescriptorSubtype = USB_MS_HEADER,
@@ -618,11 +619,6 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
618 } 619 }
619#endif 620#endif
620 621
621 if (gadget_is_sa1100(gadget) && dev->config) {
622 /* tx fifo is full, but we can't clear it...*/
623 ERROR(dev, "can't change configurations\n");
624 return -ESPIPE;
625 }
626 gmidi_reset_config(dev); 622 gmidi_reset_config(dev);
627 623
628 switch (number) { 624 switch (number) {
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 112bb40a427c..1088d08c7ed8 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1768,7 +1768,7 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1768 * usb_gadget_driver_{register,unregister}() must change. 1768 * usb_gadget_driver_{register,unregister}() must change.
1769 */ 1769 */
1770 if (the_controller) { 1770 if (the_controller) {
1771 WARNING(dev, "ignoring %s\n", pci_name(pdev)); 1771 pr_warning("ignoring %s\n", pci_name(pdev));
1772 return -EBUSY; 1772 return -EBUSY;
1773 } 1773 }
1774 if (!pdev->irq) { 1774 if (!pdev->irq) {
@@ -1859,7 +1859,7 @@ done:
1859 1859
1860/*-------------------------------------------------------------------------*/ 1860/*-------------------------------------------------------------------------*/
1861 1861
1862static struct pci_device_id pci_ids [] = { { 1862static const struct pci_device_id pci_ids[] = { {
1863 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe), 1863 .class = ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
1864 .class_mask = ~0, 1864 .class_mask = ~0,
1865 .vendor = 0x102f, /* Toshiba */ 1865 .vendor = 0x102f, /* Toshiba */
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 01ee0b9bc957..e743122fcd93 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -29,6 +29,7 @@
29#include <linux/clk.h> 29#include <linux/clk.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/timer.h> 31#include <linux/timer.h>
32#include <linux/slab.h>
32 33
33#include <linux/usb/ch9.h> 34#include <linux/usb/ch9.h>
34#include <linux/usb/gadget.h> 35#include <linux/usb/gadget.h>
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index bf0f6520c6df..de8a83803505 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -194,7 +194,7 @@ enum ep_state {
194}; 194};
195 195
196struct ep_data { 196struct ep_data {
197 struct semaphore lock; 197 struct mutex lock;
198 enum ep_state state; 198 enum ep_state state;
199 atomic_t count; 199 atomic_t count;
200 struct dev_data *dev; 200 struct dev_data *dev;
@@ -298,10 +298,10 @@ get_ready_ep (unsigned f_flags, struct ep_data *epdata)
298 int val; 298 int val;
299 299
300 if (f_flags & O_NONBLOCK) { 300 if (f_flags & O_NONBLOCK) {
301 if (down_trylock (&epdata->lock) != 0) 301 if (!mutex_trylock(&epdata->lock))
302 goto nonblock; 302 goto nonblock;
303 if (epdata->state != STATE_EP_ENABLED) { 303 if (epdata->state != STATE_EP_ENABLED) {
304 up (&epdata->lock); 304 mutex_unlock(&epdata->lock);
305nonblock: 305nonblock:
306 val = -EAGAIN; 306 val = -EAGAIN;
307 } else 307 } else
@@ -309,7 +309,8 @@ nonblock:
309 return val; 309 return val;
310 } 310 }
311 311
312 if ((val = down_interruptible (&epdata->lock)) < 0) 312 val = mutex_lock_interruptible(&epdata->lock);
313 if (val < 0)
313 return val; 314 return val;
314 315
315 switch (epdata->state) { 316 switch (epdata->state) {
@@ -323,7 +324,7 @@ nonblock:
323 // FALLTHROUGH 324 // FALLTHROUGH
324 case STATE_EP_UNBOUND: /* clean disconnect */ 325 case STATE_EP_UNBOUND: /* clean disconnect */
325 val = -ENODEV; 326 val = -ENODEV;
326 up (&epdata->lock); 327 mutex_unlock(&epdata->lock);
327 } 328 }
328 return val; 329 return val;
329} 330}
@@ -393,7 +394,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
393 if (likely (data->ep != NULL)) 394 if (likely (data->ep != NULL))
394 usb_ep_set_halt (data->ep); 395 usb_ep_set_halt (data->ep);
395 spin_unlock_irq (&data->dev->lock); 396 spin_unlock_irq (&data->dev->lock);
396 up (&data->lock); 397 mutex_unlock(&data->lock);
397 return -EBADMSG; 398 return -EBADMSG;
398 } 399 }
399 400
@@ -411,7 +412,7 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
411 value = -EFAULT; 412 value = -EFAULT;
412 413
413free1: 414free1:
414 up (&data->lock); 415 mutex_unlock(&data->lock);
415 kfree (kbuf); 416 kfree (kbuf);
416 return value; 417 return value;
417} 418}
@@ -436,7 +437,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
436 if (likely (data->ep != NULL)) 437 if (likely (data->ep != NULL))
437 usb_ep_set_halt (data->ep); 438 usb_ep_set_halt (data->ep);
438 spin_unlock_irq (&data->dev->lock); 439 spin_unlock_irq (&data->dev->lock);
439 up (&data->lock); 440 mutex_unlock(&data->lock);
440 return -EBADMSG; 441 return -EBADMSG;
441 } 442 }
442 443
@@ -455,7 +456,7 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
455 VDEBUG (data->dev, "%s write %zu IN, status %d\n", 456 VDEBUG (data->dev, "%s write %zu IN, status %d\n",
456 data->name, len, (int) value); 457 data->name, len, (int) value);
457free1: 458free1:
458 up (&data->lock); 459 mutex_unlock(&data->lock);
459 kfree (kbuf); 460 kfree (kbuf);
460 return value; 461 return value;
461} 462}
@@ -466,7 +467,8 @@ ep_release (struct inode *inode, struct file *fd)
466 struct ep_data *data = fd->private_data; 467 struct ep_data *data = fd->private_data;
467 int value; 468 int value;
468 469
469 if ((value = down_interruptible(&data->lock)) < 0) 470 value = mutex_lock_interruptible(&data->lock);
471 if (value < 0)
470 return value; 472 return value;
471 473
472 /* clean up if this can be reopened */ 474 /* clean up if this can be reopened */
@@ -476,7 +478,7 @@ ep_release (struct inode *inode, struct file *fd)
476 data->hs_desc.bDescriptorType = 0; 478 data->hs_desc.bDescriptorType = 0;
477 usb_ep_disable(data->ep); 479 usb_ep_disable(data->ep);
478 } 480 }
479 up (&data->lock); 481 mutex_unlock(&data->lock);
480 put_ep (data); 482 put_ep (data);
481 return 0; 483 return 0;
482} 484}
@@ -507,7 +509,7 @@ static long ep_ioctl(struct file *fd, unsigned code, unsigned long value)
507 } else 509 } else
508 status = -ENODEV; 510 status = -ENODEV;
509 spin_unlock_irq (&data->dev->lock); 511 spin_unlock_irq (&data->dev->lock);
510 up (&data->lock); 512 mutex_unlock(&data->lock);
511 return status; 513 return status;
512} 514}
513 515
@@ -673,7 +675,7 @@ fail:
673 value = -ENODEV; 675 value = -ENODEV;
674 spin_unlock_irq(&epdata->dev->lock); 676 spin_unlock_irq(&epdata->dev->lock);
675 677
676 up(&epdata->lock); 678 mutex_unlock(&epdata->lock);
677 679
678 if (unlikely(value)) { 680 if (unlikely(value)) {
679 kfree(priv); 681 kfree(priv);
@@ -765,7 +767,8 @@ ep_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
765 u32 tag; 767 u32 tag;
766 int value, length = len; 768 int value, length = len;
767 769
768 if ((value = down_interruptible (&data->lock)) < 0) 770 value = mutex_lock_interruptible(&data->lock);
771 if (value < 0)
769 return value; 772 return value;
770 773
771 if (data->state != STATE_EP_READY) { 774 if (data->state != STATE_EP_READY) {
@@ -854,7 +857,7 @@ fail:
854 data->desc.bDescriptorType = 0; 857 data->desc.bDescriptorType = 0;
855 data->hs_desc.bDescriptorType = 0; 858 data->hs_desc.bDescriptorType = 0;
856 } 859 }
857 up (&data->lock); 860 mutex_unlock(&data->lock);
858 return value; 861 return value;
859fail0: 862fail0:
860 value = -EINVAL; 863 value = -EINVAL;
@@ -870,7 +873,7 @@ ep_open (struct inode *inode, struct file *fd)
870 struct ep_data *data = inode->i_private; 873 struct ep_data *data = inode->i_private;
871 int value = -EBUSY; 874 int value = -EBUSY;
872 875
873 if (down_interruptible (&data->lock) != 0) 876 if (mutex_lock_interruptible(&data->lock) != 0)
874 return -EINTR; 877 return -EINTR;
875 spin_lock_irq (&data->dev->lock); 878 spin_lock_irq (&data->dev->lock);
876 if (data->dev->state == STATE_DEV_UNBOUND) 879 if (data->dev->state == STATE_DEV_UNBOUND)
@@ -885,7 +888,7 @@ ep_open (struct inode *inode, struct file *fd)
885 DBG (data->dev, "%s state %d\n", 888 DBG (data->dev, "%s state %d\n",
886 data->name, data->state); 889 data->name, data->state);
887 spin_unlock_irq (&data->dev->lock); 890 spin_unlock_irq (&data->dev->lock);
888 up (&data->lock); 891 mutex_unlock(&data->lock);
889 return value; 892 return value;
890} 893}
891 894
@@ -1631,7 +1634,7 @@ static int activate_ep_files (struct dev_data *dev)
1631 if (!data) 1634 if (!data)
1632 goto enomem0; 1635 goto enomem0;
1633 data->state = STATE_EP_DISABLED; 1636 data->state = STATE_EP_DISABLED;
1634 init_MUTEX (&data->lock); 1637 mutex_init(&data->lock);
1635 init_waitqueue_head (&data->wait); 1638 init_waitqueue_head (&data->wait);
1636 1639
1637 strncpy (data->name, ep->name, sizeof (data->name) - 1); 1640 strncpy (data->name, ep->name, sizeof (data->name) - 1);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 6cd3d54f5640..fded3fca793b 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/slab.h>
25 26
26#include "lh7a40x_udc.h" 27#include "lh7a40x_udc.h"
27 28
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index a8c8543d1b08..166bf71fd348 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/slab.h>
28#include <linux/err.h> 29#include <linux/err.h>
29#include <linux/usb/ch9.h> 30#include <linux/usb/ch9.h>
30#include <linux/usb/gadget.h> 31#include <linux/usb/gadget.h>
diff --git a/drivers/usb/gadget/mass_storage.c b/drivers/usb/gadget/mass_storage.c
new file mode 100644
index 000000000000..705cc1f76327
--- /dev/null
+++ b/drivers/usb/gadget/mass_storage.c
@@ -0,0 +1,246 @@
1/*
2 * mass_storage.c -- Mass Storage USB Gadget
3 *
4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyright (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz <m.nazarewicz@samsung.com>
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24
25/*
26 * The Mass Storage Gadget acts as a USB Mass Storage device,
27 * appearing to the host as a disk drive or as a CD-ROM drive. In
28 * addition to providing an example of a genuinely useful gadget
29 * driver for a USB device, it also illustrates a technique of
30 * double-buffering for increased throughput. Last but not least, it
31 * gives an easy way to probe the behavior of the Mass Storage drivers
32 * in a USB host.
33 *
34 * Since this file serves only administrative purposes and all the
35 * business logic is implemented in f_mass_storage.* file. Read
36 * comments in this file for more detailed description.
37 */
38
39
40#include <linux/kernel.h>
41#include <linux/utsname.h>
42#include <linux/usb/ch9.h>
43
44
45/*-------------------------------------------------------------------------*/
46
47#define DRIVER_DESC "Mass Storage Gadget"
48#define DRIVER_VERSION "2009/09/11"
49
50/*-------------------------------------------------------------------------*/
51
52/*
53 * kbuild is not very cooperative with respect to linking separately
54 * compiled library objects into one module. So for now we won't use
55 * separate compilation ... ensuring init/exit sections work to shrink
56 * the runtime footprint, and giving us at least some parts of what
57 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
58 */
59
60#include "composite.c"
61#include "usbstring.c"
62#include "config.c"
63#include "epautoconf.c"
64#include "f_mass_storage.c"
65
66/*-------------------------------------------------------------------------*/
67
68static struct usb_device_descriptor msg_device_desc = {
69 .bLength = sizeof msg_device_desc,
70 .bDescriptorType = USB_DT_DEVICE,
71
72 .bcdUSB = cpu_to_le16(0x0200),
73 .bDeviceClass = USB_CLASS_PER_INTERFACE,
74
75 /* Vendor and product id can be overridden by module parameters. */
76 .idVendor = cpu_to_le16(FSG_VENDOR_ID),
77 .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
78 /* .bcdDevice = f(hardware) */
79 /* .iManufacturer = DYNAMIC */
80 /* .iProduct = DYNAMIC */
81 /* NO SERIAL NUMBER */
82 .bNumConfigurations = 1,
83};
84
85static struct usb_otg_descriptor otg_descriptor = {
86 .bLength = sizeof otg_descriptor,
87 .bDescriptorType = USB_DT_OTG,
88
89 /* REVISIT SRP-only hardware is possible, although
90 * it would not be called "OTG" ...
91 */
92 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
93};
94
95static const struct usb_descriptor_header *otg_desc[] = {
96 (struct usb_descriptor_header *) &otg_descriptor,
97 NULL,
98};
99
100
101/* string IDs are assigned dynamically */
102
103#define STRING_MANUFACTURER_IDX 0
104#define STRING_PRODUCT_IDX 1
105#define STRING_CONFIGURATION_IDX 2
106
107static char manufacturer[50];
108
109static struct usb_string strings_dev[] = {
110 [STRING_MANUFACTURER_IDX].s = manufacturer,
111 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
112 [STRING_CONFIGURATION_IDX].s = "Self Powered",
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 struct fsg_module_parameters mod_data = {
131 .stall = 1
132};
133FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
134
135static unsigned long msg_registered = 0;
136static void msg_cleanup(void);
137
138static int msg_thread_exits(struct fsg_common *common)
139{
140 msg_cleanup();
141 return 0;
142}
143
144static int __init msg_do_config(struct usb_configuration *c)
145{
146 struct fsg_common *common;
147 struct fsg_config config;
148 int ret;
149
150 if (gadget_is_otg(c->cdev->gadget)) {
151 c->descriptors = otg_desc;
152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
153 }
154
155 fsg_config_from_params(&config, &mod_data);
156 config.thread_exits = msg_thread_exits;
157 common = fsg_common_init(0, c->cdev, &config);
158 if (IS_ERR(common))
159 return PTR_ERR(common);
160
161 ret = fsg_add(c->cdev, c, common);
162 fsg_common_put(common);
163 return ret;
164}
165
166static struct usb_configuration msg_config_driver = {
167 .label = "Linux File-Backed Storage",
168 .bind = msg_do_config,
169 .bConfigurationValue = 1,
170 /* .iConfiguration = DYNAMIC */
171 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
172};
173
174
175
176/****************************** Gadget Bind ******************************/
177
178
179static int __init msg_bind(struct usb_composite_dev *cdev)
180{
181 struct usb_gadget *gadget = cdev->gadget;
182 int status;
183
184 /* Allocate string descriptor numbers ... note that string
185 * contents can be overridden by the composite_dev glue.
186 */
187
188 /* device descriptor strings: manufacturer, product */
189 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
190 init_utsname()->sysname, init_utsname()->release,
191 gadget->name);
192 status = usb_string_id(cdev);
193 if (status < 0)
194 return status;
195 strings_dev[STRING_MANUFACTURER_IDX].id = status;
196 msg_device_desc.iManufacturer = status;
197
198 status = usb_string_id(cdev);
199 if (status < 0)
200 return status;
201 strings_dev[STRING_PRODUCT_IDX].id = status;
202 msg_device_desc.iProduct = status;
203
204 status = usb_string_id(cdev);
205 if (status < 0)
206 return status;
207 strings_dev[STRING_CONFIGURATION_IDX].id = status;
208 msg_config_driver.iConfiguration = status;
209
210 /* register our second configuration */
211 status = usb_add_config(cdev, &msg_config_driver);
212 if (status < 0)
213 return status;
214
215 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
216 set_bit(0, &msg_registered);
217 return 0;
218}
219
220
221/****************************** Some noise ******************************/
222
223
224static struct usb_composite_driver msg_driver = {
225 .name = "g_mass_storage",
226 .dev = &msg_device_desc,
227 .strings = dev_strings,
228 .bind = msg_bind,
229};
230
231MODULE_DESCRIPTION(DRIVER_DESC);
232MODULE_AUTHOR("Michal Nazarewicz");
233MODULE_LICENSE("GPL");
234
235static int __init msg_init(void)
236{
237 return usb_composite_register(&msg_driver);
238}
239module_init(msg_init);
240
241static void msg_cleanup(void)
242{
243 if (test_and_clear_bit(0, &msg_registered))
244 usb_composite_unregister(&msg_driver);
245}
246module_exit(msg_cleanup);
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
new file mode 100644
index 000000000000..a930d7fd7e7a
--- /dev/null
+++ b/drivers/usb/gadget/multi.c
@@ -0,0 +1,356 @@
1/*
2 * multi.c -- Multifunction Composite driver
3 *
4 * Copyright (C) 2008 David Brownell
5 * Copyright (C) 2008 Nokia Corporation
6 * Copyright (C) 2009 Samsung Electronics
7 * Author: Michal Nazarewicz (m.nazarewicz@samsung.com)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24
25#include <linux/kernel.h>
26#include <linux/utsname.h>
27
28
29#if defined USB_ETH_RNDIS
30# undef USB_ETH_RNDIS
31#endif
32#ifdef CONFIG_USB_G_MULTI_RNDIS
33# define USB_ETH_RNDIS y
34#endif
35
36
37#define DRIVER_DESC "Multifunction Composite Gadget"
38#define DRIVER_VERSION "2009/07/21"
39
40/*-------------------------------------------------------------------------*/
41
42#define MULTI_VENDOR_NUM 0x0525 /* XXX NetChip */
43#define MULTI_PRODUCT_NUM 0xa4ab /* XXX */
44
45/*-------------------------------------------------------------------------*/
46
47/*
48 * kbuild is not very cooperative with respect to linking separately
49 * compiled library objects into one module. So for now we won't use
50 * separate compilation ... ensuring init/exit sections work to shrink
51 * the runtime footprint, and giving us at least some parts of what
52 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
53 */
54
55#include "composite.c"
56#include "usbstring.c"
57#include "config.c"
58#include "epautoconf.c"
59
60#include "u_serial.c"
61#include "f_acm.c"
62
63#include "f_ecm.c"
64#include "f_subset.c"
65#ifdef USB_ETH_RNDIS
66# include "f_rndis.c"
67# include "rndis.c"
68#endif
69#include "u_ether.c"
70
71#undef DBG /* u_ether.c has broken idea about macros */
72#undef VDBG /* so clean up after it */
73#undef ERROR
74#undef INFO
75#include "f_mass_storage.c"
76
77/*-------------------------------------------------------------------------*/
78
79static struct usb_device_descriptor device_desc = {
80 .bLength = sizeof device_desc,
81 .bDescriptorType = USB_DT_DEVICE,
82
83 .bcdUSB = cpu_to_le16(0x0200),
84
85 /* .bDeviceClass = USB_CLASS_COMM, */
86 /* .bDeviceSubClass = 0, */
87 /* .bDeviceProtocol = 0, */
88 .bDeviceClass = 0xEF,
89 .bDeviceSubClass = 2,
90 .bDeviceProtocol = 1,
91 /* .bMaxPacketSize0 = f(hardware) */
92
93 /* Vendor and product id can be overridden by module parameters. */
94 .idVendor = cpu_to_le16(MULTI_VENDOR_NUM),
95 .idProduct = cpu_to_le16(MULTI_PRODUCT_NUM),
96 /* .bcdDevice = f(hardware) */
97 /* .iManufacturer = DYNAMIC */
98 /* .iProduct = DYNAMIC */
99 /* NO SERIAL NUMBER */
100 .bNumConfigurations = 1,
101};
102
103static struct usb_otg_descriptor otg_descriptor = {
104 .bLength = sizeof otg_descriptor,
105 .bDescriptorType = USB_DT_OTG,
106
107 /* REVISIT SRP-only hardware is possible, although
108 * it would not be called "OTG" ...
109 */
110 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
111};
112
113static const struct usb_descriptor_header *otg_desc[] = {
114 (struct usb_descriptor_header *) &otg_descriptor,
115 NULL,
116};
117
118
119/* string IDs are assigned dynamically */
120
121#define STRING_MANUFACTURER_IDX 0
122#define STRING_PRODUCT_IDX 1
123
124static char manufacturer[50];
125
126static struct usb_string strings_dev[] = {
127 [STRING_MANUFACTURER_IDX].s = manufacturer,
128 [STRING_PRODUCT_IDX].s = DRIVER_DESC,
129 { } /* end of list */
130};
131
132static struct usb_gadget_strings stringtab_dev = {
133 .language = 0x0409, /* en-us */
134 .strings = strings_dev,
135};
136
137static struct usb_gadget_strings *dev_strings[] = {
138 &stringtab_dev,
139 NULL,
140};
141
142static u8 hostaddr[ETH_ALEN];
143
144
145
146/****************************** Configurations ******************************/
147
148static struct fsg_module_parameters mod_data = {
149 .stall = 1
150};
151FSG_MODULE_PARAMETERS(/* no prefix */, mod_data);
152
153static struct fsg_common *fsg_common;
154
155
156#ifdef USB_ETH_RNDIS
157
158static int __init rndis_do_config(struct usb_configuration *c)
159{
160 int ret;
161
162 if (gadget_is_otg(c->cdev->gadget)) {
163 c->descriptors = otg_desc;
164 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
165 }
166
167 ret = rndis_bind_config(c, hostaddr);
168 if (ret < 0)
169 return ret;
170
171 ret = acm_bind_config(c, 0);
172 if (ret < 0)
173 return ret;
174
175 ret = fsg_add(c->cdev, c, fsg_common);
176 if (ret < 0)
177 return ret;
178
179 return 0;
180}
181
182static struct usb_configuration rndis_config_driver = {
183 .label = "Multifunction Composite (RNDIS + MS + ACM)",
184 .bind = rndis_do_config,
185 .bConfigurationValue = 2,
186 /* .iConfiguration = DYNAMIC */
187 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
188};
189
190#endif
191
192#ifdef CONFIG_USB_G_MULTI_CDC
193
194static int __init cdc_do_config(struct usb_configuration *c)
195{
196 int ret;
197
198 if (gadget_is_otg(c->cdev->gadget)) {
199 c->descriptors = otg_desc;
200 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
201 }
202
203 ret = ecm_bind_config(c, hostaddr);
204 if (ret < 0)
205 return ret;
206
207 ret = acm_bind_config(c, 0);
208 if (ret < 0)
209 return ret;
210
211 ret = fsg_add(c->cdev, c, fsg_common);
212 if (ret < 0)
213 return ret;
214
215 return 0;
216}
217
218static struct usb_configuration cdc_config_driver = {
219 .label = "Multifunction Composite (CDC + MS + ACM)",
220 .bind = cdc_do_config,
221 .bConfigurationValue = 1,
222 /* .iConfiguration = DYNAMIC */
223 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
224};
225
226#endif
227
228
229
230/****************************** Gadget Bind ******************************/
231
232
233static int __init multi_bind(struct usb_composite_dev *cdev)
234{
235 struct usb_gadget *gadget = cdev->gadget;
236 int status, gcnum;
237
238 if (!can_support_ecm(cdev->gadget)) {
239 dev_err(&gadget->dev, "controller '%s' not usable\n",
240 gadget->name);
241 return -EINVAL;
242 }
243
244 /* set up network link layer */
245 status = gether_setup(cdev->gadget, hostaddr);
246 if (status < 0)
247 return status;
248
249 /* set up serial link layer */
250 status = gserial_setup(cdev->gadget, 1);
251 if (status < 0)
252 goto fail0;
253
254 /* set up mass storage function */
255 fsg_common = fsg_common_from_params(0, cdev, &mod_data);
256 if (IS_ERR(fsg_common)) {
257 status = PTR_ERR(fsg_common);
258 goto fail1;
259 }
260
261
262 gcnum = usb_gadget_controller_number(gadget);
263 if (gcnum >= 0)
264 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
265 else {
266 /* We assume that can_support_ecm() tells the truth;
267 * but if the controller isn't recognized at all then
268 * that assumption is a bit more likely to be wrong.
269 */
270 WARNING(cdev, "controller '%s' not recognized\n",
271 gadget->name);
272 device_desc.bcdDevice = cpu_to_le16(0x0300 | 0x0099);
273 }
274
275
276 /* Allocate string descriptor numbers ... note that string
277 * contents can be overridden by the composite_dev glue.
278 */
279
280 /* device descriptor strings: manufacturer, product */
281 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
282 init_utsname()->sysname, init_utsname()->release,
283 gadget->name);
284 status = usb_string_id(cdev);
285 if (status < 0)
286 goto fail2;
287 strings_dev[STRING_MANUFACTURER_IDX].id = status;
288 device_desc.iManufacturer = status;
289
290 status = usb_string_id(cdev);
291 if (status < 0)
292 goto fail2;
293 strings_dev[STRING_PRODUCT_IDX].id = status;
294 device_desc.iProduct = status;
295
296#ifdef USB_ETH_RNDIS
297 /* register our first configuration */
298 status = usb_add_config(cdev, &rndis_config_driver);
299 if (status < 0)
300 goto fail2;
301#endif
302
303#ifdef CONFIG_USB_G_MULTI_CDC
304 /* register our second configuration */
305 status = usb_add_config(cdev, &cdc_config_driver);
306 if (status < 0)
307 goto fail2;
308#endif
309
310 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
311 fsg_common_put(fsg_common);
312 return 0;
313
314fail2:
315 fsg_common_put(fsg_common);
316fail1:
317 gserial_cleanup();
318fail0:
319 gether_cleanup();
320 return status;
321}
322
323static int __exit multi_unbind(struct usb_composite_dev *cdev)
324{
325 gserial_cleanup();
326 gether_cleanup();
327 return 0;
328}
329
330
331/****************************** Some noise ******************************/
332
333
334static struct usb_composite_driver multi_driver = {
335 .name = "g_multi",
336 .dev = &device_desc,
337 .strings = dev_strings,
338 .bind = multi_bind,
339 .unbind = __exit_p(multi_unbind),
340};
341
342MODULE_DESCRIPTION(DRIVER_DESC);
343MODULE_AUTHOR("Michal Nazarewicz");
344MODULE_LICENSE("GPL");
345
346static int __init g_multi_init(void)
347{
348 return usb_composite_register(&multi_driver);
349}
350module_init(g_multi_init);
351
352static void __exit g_multi_cleanup(void)
353{
354 usb_composite_unregister(&multi_driver);
355}
356module_exit(g_multi_cleanup);
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
new file mode 100644
index 000000000000..7d6b66a85724
--- /dev/null
+++ b/drivers/usb/gadget/nokia.c
@@ -0,0 +1,259 @@
1/*
2 * nokia.c -- Nokia Composite Gadget Driver
3 *
4 * Copyright (C) 2008-2010 Nokia Corporation
5 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
6 *
7 * This gadget driver borrows from serial.c which is:
8 *
9 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
10 * Copyright (C) 2008 by David Brownell
11 * Copyright (C) 2008 by Nokia Corporation
12 *
13 * This software is distributed under the terms of the GNU General
14 * Public License ("GPL") as published by the Free Software Foundation,
15 * version 2 of that License.
16 */
17
18#include <linux/kernel.h>
19#include <linux/utsname.h>
20#include <linux/device.h>
21
22#include "u_serial.h"
23#include "u_ether.h"
24#include "u_phonet.h"
25#include "gadget_chips.h"
26
27/* Defines */
28
29#define NOKIA_VERSION_NUM 0x0211
30#define NOKIA_LONG_NAME "N900 (PC-Suite Mode)"
31
32/*-------------------------------------------------------------------------*/
33
34/*
35 * Kbuild is not very cooperative with respect to linking separately
36 * compiled library objects into one module. So for now we won't use
37 * separate compilation ... ensuring init/exit sections work to shrink
38 * the runtime footprint, and giving us at least some parts of what
39 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
40 */
41#include "composite.c"
42#include "usbstring.c"
43#include "config.c"
44#include "epautoconf.c"
45
46#include "u_serial.c"
47#include "f_acm.c"
48#include "f_ecm.c"
49#include "f_obex.c"
50#include "f_serial.c"
51#include "f_phonet.c"
52#include "u_ether.c"
53
54/*-------------------------------------------------------------------------*/
55
56#define NOKIA_VENDOR_ID 0x0421 /* Nokia */
57#define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
58
59/* string IDs are assigned dynamically */
60
61#define STRING_MANUFACTURER_IDX 0
62#define STRING_PRODUCT_IDX 1
63#define STRING_DESCRIPTION_IDX 2
64
65static char manufacturer_nokia[] = "Nokia";
66static const char product_nokia[] = NOKIA_LONG_NAME;
67static const char description_nokia[] = "PC-Suite Configuration";
68
69static struct usb_string strings_dev[] = {
70 [STRING_MANUFACTURER_IDX].s = manufacturer_nokia,
71 [STRING_PRODUCT_IDX].s = NOKIA_LONG_NAME,
72 [STRING_DESCRIPTION_IDX].s = description_nokia,
73 { } /* end of list */
74};
75
76static struct usb_gadget_strings stringtab_dev = {
77 .language = 0x0409, /* en-us */
78 .strings = strings_dev,
79};
80
81static struct usb_gadget_strings *dev_strings[] = {
82 &stringtab_dev,
83 NULL,
84};
85
86static struct usb_device_descriptor device_desc = {
87 .bLength = USB_DT_DEVICE_SIZE,
88 .bDescriptorType = USB_DT_DEVICE,
89 .bcdUSB = __constant_cpu_to_le16(0x0200),
90 .bDeviceClass = USB_CLASS_COMM,
91 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
92 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
93 /* .iManufacturer = DYNAMIC */
94 /* .iProduct = DYNAMIC */
95 .bNumConfigurations = 1,
96};
97
98/*-------------------------------------------------------------------------*/
99
100/* Module */
101MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
102MODULE_AUTHOR("Felipe Balbi");
103MODULE_LICENSE("GPL");
104
105/*-------------------------------------------------------------------------*/
106
107static u8 hostaddr[ETH_ALEN];
108
109static int __init nokia_bind_config(struct usb_configuration *c)
110{
111 int status = 0;
112
113 status = phonet_bind_config(c);
114 if (status)
115 printk(KERN_DEBUG "could not bind phonet config\n");
116
117 status = obex_bind_config(c, 0);
118 if (status)
119 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
120
121 status = obex_bind_config(c, 1);
122 if (status)
123 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
124
125 status = acm_bind_config(c, 2);
126 if (status)
127 printk(KERN_DEBUG "could not bind acm config\n");
128
129 status = ecm_bind_config(c, hostaddr);
130 if (status)
131 printk(KERN_DEBUG "could not bind ecm config\n");
132
133 return status;
134}
135
136static struct usb_configuration nokia_config_500ma_driver = {
137 .label = "Bus Powered",
138 .bind = nokia_bind_config,
139 .bConfigurationValue = 1,
140 /* .iConfiguration = DYNAMIC */
141 .bmAttributes = USB_CONFIG_ATT_ONE,
142 .bMaxPower = 250, /* 500mA */
143};
144
145static struct usb_configuration nokia_config_100ma_driver = {
146 .label = "Self Powered",
147 .bind = nokia_bind_config,
148 .bConfigurationValue = 2,
149 /* .iConfiguration = DYNAMIC */
150 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
151 .bMaxPower = 50, /* 100 mA */
152};
153
154static int __init nokia_bind(struct usb_composite_dev *cdev)
155{
156 int gcnum;
157 struct usb_gadget *gadget = cdev->gadget;
158 int status;
159
160 status = gphonet_setup(cdev->gadget);
161 if (status < 0)
162 goto err_phonet;
163
164 status = gserial_setup(cdev->gadget, 3);
165 if (status < 0)
166 goto err_serial;
167
168 status = gether_setup(cdev->gadget, hostaddr);
169 if (status < 0)
170 goto err_ether;
171
172 status = usb_string_id(cdev);
173 if (status < 0)
174 goto err_usb;
175 strings_dev[STRING_MANUFACTURER_IDX].id = status;
176
177 device_desc.iManufacturer = status;
178
179 status = usb_string_id(cdev);
180 if (status < 0)
181 goto err_usb;
182 strings_dev[STRING_PRODUCT_IDX].id = status;
183
184 device_desc.iProduct = status;
185
186 /* config description */
187 status = usb_string_id(cdev);
188 if (status < 0)
189 goto err_usb;
190 strings_dev[STRING_DESCRIPTION_IDX].id = status;
191
192 nokia_config_500ma_driver.iConfiguration = status;
193 nokia_config_100ma_driver.iConfiguration = status;
194
195 /* set up other descriptors */
196 gcnum = usb_gadget_controller_number(gadget);
197 if (gcnum >= 0)
198 device_desc.bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM);
199 else {
200 /* this should only work with hw that supports altsettings
201 * and several endpoints, anything else, panic.
202 */
203 pr_err("nokia_bind: controller '%s' not recognized\n",
204 gadget->name);
205 goto err_usb;
206 }
207
208 /* finaly register the configuration */
209 status = usb_add_config(cdev, &nokia_config_500ma_driver);
210 if (status < 0)
211 goto err_usb;
212
213 status = usb_add_config(cdev, &nokia_config_100ma_driver);
214 if (status < 0)
215 goto err_usb;
216
217 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
218
219 return 0;
220
221err_usb:
222 gether_cleanup();
223err_ether:
224 gserial_cleanup();
225err_serial:
226 gphonet_cleanup();
227err_phonet:
228 return status;
229}
230
231static int __exit nokia_unbind(struct usb_composite_dev *cdev)
232{
233 gphonet_cleanup();
234 gserial_cleanup();
235 gether_cleanup();
236
237 return 0;
238}
239
240static struct usb_composite_driver nokia_driver = {
241 .name = "g_nokia",
242 .dev = &device_desc,
243 .strings = dev_strings,
244 .bind = nokia_bind,
245 .unbind = __exit_p(nokia_unbind),
246};
247
248static int __init nokia_init(void)
249{
250 return usb_composite_register(&nokia_driver);
251}
252module_init(nokia_init);
253
254static void __exit nokia_cleanup(void)
255{
256 usb_composite_unregister(&nokia_driver);
257}
258module_exit(nokia_cleanup);
259
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index a2db0e174f2c..f81e4f025f23 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -52,9 +52,9 @@
52#include <asm/unaligned.h> 52#include <asm/unaligned.h>
53#include <asm/mach-types.h> 53#include <asm/mach-types.h>
54 54
55#include <mach/dma.h> 55#include <plat/dma.h>
56#include <mach/usb.h> 56#include <plat/usb.h>
57#include <mach/control.h> 57#include <plat/control.h>
58 58
59#include "omap_udc.h" 59#include "omap_udc.h"
60 60
@@ -2098,6 +2098,7 @@ static inline int machine_without_vbus_sense(void)
2098 || machine_is_omap_h4() 2098 || machine_is_omap_h4()
2099#endif 2099#endif
2100 || machine_is_sx1() 2100 || machine_is_sx1()
2101 || cpu_is_omap7xx() /* No known omap7xx boards with vbus sense */
2101 ); 2102 );
2102} 2103}
2103 2104
@@ -2838,6 +2839,16 @@ static int __init omap_udc_probe(struct platform_device *pdev)
2838 udelay(100); 2839 udelay(100);
2839 } 2840 }
2840 2841
2842 if (cpu_is_omap7xx()) {
2843 dc_clk = clk_get(&pdev->dev, "usb_dc_ck");
2844 hhc_clk = clk_get(&pdev->dev, "l3_ocpi_ck");
2845 BUG_ON(IS_ERR(dc_clk) || IS_ERR(hhc_clk));
2846 /* can't use omap_udc_enable_clock yet */
2847 clk_enable(dc_clk);
2848 clk_enable(hhc_clk);
2849 udelay(100);
2850 }
2851
2841 INFO("OMAP UDC rev %d.%d%s\n", 2852 INFO("OMAP UDC rev %d.%d%s\n",
2842 omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf, 2853 omap_readw(UDC_REV) >> 4, omap_readw(UDC_REV) & 0xf,
2843 config->otg ? ", Mini-AB" : ""); 2854 config->otg ? ", Mini-AB" : "");
@@ -2970,7 +2981,7 @@ known:
2970 goto cleanup3; 2981 goto cleanup3;
2971 } 2982 }
2972#endif 2983#endif
2973 if (cpu_is_omap16xx()) { 2984 if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
2974 udc->dc_clk = dc_clk; 2985 udc->dc_clk = dc_clk;
2975 udc->hhc_clk = hhc_clk; 2986 udc->hhc_clk = hhc_clk;
2976 clk_disable(hhc_clk); 2987 clk_disable(hhc_clk);
@@ -3008,7 +3019,7 @@ cleanup0:
3008 if (xceiv) 3019 if (xceiv)
3009 otg_put_transceiver(xceiv); 3020 otg_put_transceiver(xceiv);
3010 3021
3011 if (cpu_is_omap16xx() || cpu_is_omap24xx()) { 3022 if (cpu_is_omap16xx() || cpu_is_omap24xx() || cpu_is_omap7xx()) {
3012 clk_disable(hhc_clk); 3023 clk_disable(hhc_clk);
3013 clk_disable(dc_clk); 3024 clk_disable(dc_clk);
3014 clk_put(hhc_clk); 3025 clk_put(hhc_clk);
@@ -3115,6 +3126,10 @@ static struct platform_driver udc_driver = {
3115 3126
3116static int __init udc_init(void) 3127static int __init udc_init(void)
3117{ 3128{
3129 /* Disable DMA for omap7xx -- it doesn't work right. */
3130 if (cpu_is_omap7xx())
3131 use_dma = 0;
3132
3118 INFO("%s, version: " DRIVER_VERSION 3133 INFO("%s, version: " DRIVER_VERSION
3119#ifdef USE_ISO 3134#ifdef USE_ISO
3120 " (iso)" 3135 " (iso)"
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 2d867fd22413..6b8bf8c781c4 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -949,12 +949,6 @@ printer_set_config(struct printer_dev *dev, unsigned number)
949 int result = 0; 949 int result = 0;
950 struct usb_gadget *gadget = dev->gadget; 950 struct usb_gadget *gadget = dev->gadget;
951 951
952 if (gadget_is_sa1100(gadget) && dev->config) {
953 /* tx fifo is full, but we can't clear it...*/
954 INFO(dev, "can't change configurations\n");
955 return -ESPIPE;
956 }
957
958 switch (number) { 952 switch (number) {
959 case DEV_CONFIG_VALUE: 953 case DEV_CONFIG_VALUE:
960 result = 0; 954 result = 0;
@@ -1033,12 +1027,6 @@ set_interface(struct printer_dev *dev, unsigned number)
1033{ 1027{
1034 int result = 0; 1028 int result = 0;
1035 1029
1036 if (gadget_is_sa1100(dev->gadget) && dev->interface < 0) {
1037 /* tx fifo is full, but we can't clear it...*/
1038 INFO(dev, "can't change interfaces\n");
1039 return -ESPIPE;
1040 }
1041
1042 /* Free the current interface */ 1030 /* Free the current interface */
1043 switch (dev->interface) { 1031 switch (dev->interface) {
1044 case PRINTER_INTERFACE: 1032 case PRINTER_INTERFACE:
@@ -1392,12 +1380,6 @@ printer_bind(struct usb_gadget *gadget)
1392 goto fail; 1380 goto fail;
1393 } 1381 }
1394 1382
1395 if (gadget_is_sa1100(gadget)) {
1396 /* hardware can't write zero length packets. */
1397 ERROR(dev, "SA1100 controller is unsupport by this driver\n");
1398 goto fail;
1399 }
1400
1401 gcnum = usb_gadget_controller_number(gadget); 1383 gcnum = usb_gadget_controller_number(gadget);
1402 if (gcnum >= 0) { 1384 if (gcnum >= 0) {
1403 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum); 1385 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index e6fedbd5a654..be5fb34d9602 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -65,6 +65,10 @@
65#include <mach/pxa25x-udc.h> 65#include <mach/pxa25x-udc.h>
66#endif 66#endif
67 67
68#ifdef CONFIG_ARCH_LUBBOCK
69#include <mach/lubbock.h>
70#endif
71
68#include <asm/mach/udc_pxa2xx.h> 72#include <asm/mach/udc_pxa2xx.h>
69 73
70 74
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 1937d8c7b433..85b0d8921eae 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -31,6 +31,7 @@
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34#include <linux/slab.h>
34 35
35#include <asm/byteorder.h> 36#include <asm/byteorder.h>
36#include <mach/hardware.h> 37#include <mach/hardware.h>
@@ -742,13 +743,17 @@ static void ep_del_request(struct pxa_ep *ep, struct pxa27x_request *req)
742 * @ep: pxa physical endpoint 743 * @ep: pxa physical endpoint
743 * @req: pxa request 744 * @req: pxa request
744 * @status: usb request status sent to gadget API 745 * @status: usb request status sent to gadget API
746 * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
745 * 747 *
746 * Context: ep->lock held 748 * Context: ep->lock held if flags not NULL, else ep->lock released
747 * 749 *
748 * Retire a pxa27x usb request. Endpoint must be locked. 750 * Retire a pxa27x usb request. Endpoint must be locked.
749 */ 751 */
750static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status) 752static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status,
753 unsigned long *pflags)
751{ 754{
755 unsigned long flags;
756
752 ep_del_request(ep, req); 757 ep_del_request(ep, req);
753 if (likely(req->req.status == -EINPROGRESS)) 758 if (likely(req->req.status == -EINPROGRESS))
754 req->req.status = status; 759 req->req.status = status;
@@ -760,38 +765,48 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
760 &req->req, status, 765 &req->req, status,
761 req->req.actual, req->req.length); 766 req->req.actual, req->req.length);
762 767
768 if (pflags)
769 spin_unlock_irqrestore(&ep->lock, *pflags);
770 local_irq_save(flags);
763 req->req.complete(&req->udc_usb_ep->usb_ep, &req->req); 771 req->req.complete(&req->udc_usb_ep->usb_ep, &req->req);
772 local_irq_restore(flags);
773 if (pflags)
774 spin_lock_irqsave(&ep->lock, *pflags);
764} 775}
765 776
766/** 777/**
767 * ep_end_out_req - Ends endpoint OUT request 778 * ep_end_out_req - Ends endpoint OUT request
768 * @ep: physical endpoint 779 * @ep: physical endpoint
769 * @req: pxa request 780 * @req: pxa request
781 * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
770 * 782 *
771 * Context: ep->lock held 783 * Context: ep->lock held or released (see req_done())
772 * 784 *
773 * Ends endpoint OUT request (completes usb request). 785 * Ends endpoint OUT request (completes usb request).
774 */ 786 */
775static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 787static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
788 unsigned long *pflags)
776{ 789{
777 inc_ep_stats_reqs(ep, !USB_DIR_IN); 790 inc_ep_stats_reqs(ep, !USB_DIR_IN);
778 req_done(ep, req, 0); 791 req_done(ep, req, 0, pflags);
779} 792}
780 793
781/** 794/**
782 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage) 795 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
783 * @ep: physical endpoint 796 * @ep: physical endpoint
784 * @req: pxa request 797 * @req: pxa request
798 * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
785 * 799 *
786 * Context: ep->lock held 800 * Context: ep->lock held or released (see req_done())
787 * 801 *
788 * Ends control endpoint OUT request (completes usb request), and puts 802 * Ends control endpoint OUT request (completes usb request), and puts
789 * control endpoint into idle state 803 * control endpoint into idle state
790 */ 804 */
791static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 805static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req,
806 unsigned long *pflags)
792{ 807{
793 set_ep0state(ep->dev, OUT_STATUS_STAGE); 808 set_ep0state(ep->dev, OUT_STATUS_STAGE);
794 ep_end_out_req(ep, req); 809 ep_end_out_req(ep, req, pflags);
795 ep0_idle(ep->dev); 810 ep0_idle(ep->dev);
796} 811}
797 812
@@ -799,31 +814,35 @@ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
799 * ep_end_in_req - Ends endpoint IN request 814 * ep_end_in_req - Ends endpoint IN request
800 * @ep: physical endpoint 815 * @ep: physical endpoint
801 * @req: pxa request 816 * @req: pxa request
817 * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
802 * 818 *
803 * Context: ep->lock held 819 * Context: ep->lock held or released (see req_done())
804 * 820 *
805 * Ends endpoint IN request (completes usb request). 821 * Ends endpoint IN request (completes usb request).
806 */ 822 */
807static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 823static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
824 unsigned long *pflags)
808{ 825{
809 inc_ep_stats_reqs(ep, USB_DIR_IN); 826 inc_ep_stats_reqs(ep, USB_DIR_IN);
810 req_done(ep, req, 0); 827 req_done(ep, req, 0, pflags);
811} 828}
812 829
813/** 830/**
814 * ep0_end_in_req - Ends control endpoint IN request (ends data stage) 831 * ep0_end_in_req - Ends control endpoint IN request (ends data stage)
815 * @ep: physical endpoint 832 * @ep: physical endpoint
816 * @req: pxa request 833 * @req: pxa request
834 * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held
817 * 835 *
818 * Context: ep->lock held 836 * Context: ep->lock held or released (see req_done())
819 * 837 *
820 * Ends control endpoint IN request (completes usb request), and puts 838 * Ends control endpoint IN request (completes usb request), and puts
821 * control endpoint into status state 839 * control endpoint into status state
822 */ 840 */
823static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 841static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req,
842 unsigned long *pflags)
824{ 843{
825 set_ep0state(ep->dev, IN_STATUS_STAGE); 844 set_ep0state(ep->dev, IN_STATUS_STAGE);
826 ep_end_in_req(ep, req); 845 ep_end_in_req(ep, req, pflags);
827} 846}
828 847
829/** 848/**
@@ -831,19 +850,22 @@ static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
831 * @ep: pxa endpoint 850 * @ep: pxa endpoint
832 * @status: usb request status 851 * @status: usb request status
833 * 852 *
834 * Context: ep->lock held 853 * Context: ep->lock released
835 * 854 *
836 * Dequeues all requests on an endpoint. As a side effect, interrupts will be 855 * Dequeues all requests on an endpoint. As a side effect, interrupts will be
837 * disabled on that endpoint (because no more requests). 856 * disabled on that endpoint (because no more requests).
838 */ 857 */
839static void nuke(struct pxa_ep *ep, int status) 858static void nuke(struct pxa_ep *ep, int status)
840{ 859{
841 struct pxa27x_request *req; 860 struct pxa27x_request *req;
861 unsigned long flags;
842 862
863 spin_lock_irqsave(&ep->lock, flags);
843 while (!list_empty(&ep->queue)) { 864 while (!list_empty(&ep->queue)) {
844 req = list_entry(ep->queue.next, struct pxa27x_request, queue); 865 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
845 req_done(ep, req, status); 866 req_done(ep, req, status, &flags);
846 } 867 }
868 spin_unlock_irqrestore(&ep->lock, flags);
847} 869}
848 870
849/** 871/**
@@ -1123,6 +1145,7 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1123 int rc = 0; 1145 int rc = 0;
1124 int is_first_req; 1146 int is_first_req;
1125 unsigned length; 1147 unsigned length;
1148 int recursion_detected;
1126 1149
1127 req = container_of(_req, struct pxa27x_request, req); 1150 req = container_of(_req, struct pxa27x_request, req);
1128 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); 1151 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
@@ -1152,6 +1175,7 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1152 return -EMSGSIZE; 1175 return -EMSGSIZE;
1153 1176
1154 spin_lock_irqsave(&ep->lock, flags); 1177 spin_lock_irqsave(&ep->lock, flags);
1178 recursion_detected = ep->in_handle_ep;
1155 1179
1156 is_first_req = list_empty(&ep->queue); 1180 is_first_req = list_empty(&ep->queue);
1157 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n", 1181 ep_dbg(ep, "queue req %p(first=%s), len %d buf %p\n",
@@ -1161,12 +1185,12 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1161 if (!ep->enabled) { 1185 if (!ep->enabled) {
1162 _req->status = -ESHUTDOWN; 1186 _req->status = -ESHUTDOWN;
1163 rc = -ESHUTDOWN; 1187 rc = -ESHUTDOWN;
1164 goto out; 1188 goto out_locked;
1165 } 1189 }
1166 1190
1167 if (req->in_use) { 1191 if (req->in_use) {
1168 ep_err(ep, "refusing to queue req %p (already queued)\n", req); 1192 ep_err(ep, "refusing to queue req %p (already queued)\n", req);
1169 goto out; 1193 goto out_locked;
1170 } 1194 }
1171 1195
1172 length = _req->length; 1196 length = _req->length;
@@ -1174,12 +1198,13 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1174 _req->actual = 0; 1198 _req->actual = 0;
1175 1199
1176 ep_add_request(ep, req); 1200 ep_add_request(ep, req);
1201 spin_unlock_irqrestore(&ep->lock, flags);
1177 1202
1178 if (is_ep0(ep)) { 1203 if (is_ep0(ep)) {
1179 switch (dev->ep0state) { 1204 switch (dev->ep0state) {
1180 case WAIT_ACK_SET_CONF_INTERF: 1205 case WAIT_ACK_SET_CONF_INTERF:
1181 if (length == 0) { 1206 if (length == 0) {
1182 ep_end_in_req(ep, req); 1207 ep_end_in_req(ep, req, NULL);
1183 } else { 1208 } else {
1184 ep_err(ep, "got a request of %d bytes while" 1209 ep_err(ep, "got a request of %d bytes while"
1185 "in state WAIT_ACK_SET_CONF_INTERF\n", 1210 "in state WAIT_ACK_SET_CONF_INTERF\n",
@@ -1192,12 +1217,12 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1192 case IN_DATA_STAGE: 1217 case IN_DATA_STAGE:
1193 if (!ep_is_full(ep)) 1218 if (!ep_is_full(ep))
1194 if (write_ep0_fifo(ep, req)) 1219 if (write_ep0_fifo(ep, req))
1195 ep0_end_in_req(ep, req); 1220 ep0_end_in_req(ep, req, NULL);
1196 break; 1221 break;
1197 case OUT_DATA_STAGE: 1222 case OUT_DATA_STAGE:
1198 if ((length == 0) || !epout_has_pkt(ep)) 1223 if ((length == 0) || !epout_has_pkt(ep))
1199 if (read_ep0_fifo(ep, req)) 1224 if (read_ep0_fifo(ep, req))
1200 ep0_end_out_req(ep, req); 1225 ep0_end_out_req(ep, req, NULL);
1201 break; 1226 break;
1202 default: 1227 default:
1203 ep_err(ep, "odd state %s to send me a request\n", 1228 ep_err(ep, "odd state %s to send me a request\n",
@@ -1207,12 +1232,15 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1207 break; 1232 break;
1208 } 1233 }
1209 } else { 1234 } else {
1210 handle_ep(ep); 1235 if (!recursion_detected)
1236 handle_ep(ep);
1211 } 1237 }
1212 1238
1213out: 1239out:
1214 spin_unlock_irqrestore(&ep->lock, flags);
1215 return rc; 1240 return rc;
1241out_locked:
1242 spin_unlock_irqrestore(&ep->lock, flags);
1243 goto out;
1216} 1244}
1217 1245
1218/** 1246/**
@@ -1242,13 +1270,14 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1242 /* make sure it's actually queued on this endpoint */ 1270 /* make sure it's actually queued on this endpoint */
1243 list_for_each_entry(req, &ep->queue, queue) { 1271 list_for_each_entry(req, &ep->queue, queue) {
1244 if (&req->req == _req) { 1272 if (&req->req == _req) {
1245 req_done(ep, req, -ECONNRESET);
1246 rc = 0; 1273 rc = 0;
1247 break; 1274 break;
1248 } 1275 }
1249 } 1276 }
1250 1277
1251 spin_unlock_irqrestore(&ep->lock, flags); 1278 spin_unlock_irqrestore(&ep->lock, flags);
1279 if (!rc)
1280 req_done(ep, req, -ECONNRESET, NULL);
1252 return rc; 1281 return rc;
1253} 1282}
1254 1283
@@ -1445,7 +1474,6 @@ static int pxa_ep_disable(struct usb_ep *_ep)
1445{ 1474{
1446 struct pxa_ep *ep; 1475 struct pxa_ep *ep;
1447 struct udc_usb_ep *udc_usb_ep; 1476 struct udc_usb_ep *udc_usb_ep;
1448 unsigned long flags;
1449 1477
1450 if (!_ep) 1478 if (!_ep)
1451 return -EINVAL; 1479 return -EINVAL;
@@ -1455,10 +1483,8 @@ static int pxa_ep_disable(struct usb_ep *_ep)
1455 if (!ep || is_ep0(ep) || !list_empty(&ep->queue)) 1483 if (!ep || is_ep0(ep) || !list_empty(&ep->queue))
1456 return -EINVAL; 1484 return -EINVAL;
1457 1485
1458 spin_lock_irqsave(&ep->lock, flags);
1459 ep->enabled = 0; 1486 ep->enabled = 0;
1460 nuke(ep, -ESHUTDOWN); 1487 nuke(ep, -ESHUTDOWN);
1461 spin_unlock_irqrestore(&ep->lock, flags);
1462 1488
1463 pxa_ep_fifo_flush(_ep); 1489 pxa_ep_fifo_flush(_ep);
1464 udc_usb_ep->pxa_ep = NULL; 1490 udc_usb_ep->pxa_ep = NULL;
@@ -1524,7 +1550,7 @@ static int pxa_udc_get_frame(struct usb_gadget *_gadget)
1524 * pxa_udc_wakeup - Force udc device out of suspend 1550 * pxa_udc_wakeup - Force udc device out of suspend
1525 * @_gadget: usb gadget 1551 * @_gadget: usb gadget
1526 * 1552 *
1527 * Returns 0 if succesfull, error code otherwise 1553 * Returns 0 if successfull, error code otherwise
1528 */ 1554 */
1529static int pxa_udc_wakeup(struct usb_gadget *_gadget) 1555static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1530{ 1556{
@@ -1907,8 +1933,10 @@ static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1907 } u; 1933 } u;
1908 int i; 1934 int i;
1909 int have_extrabytes = 0; 1935 int have_extrabytes = 0;
1936 unsigned long flags;
1910 1937
1911 nuke(ep, -EPROTO); 1938 nuke(ep, -EPROTO);
1939 spin_lock_irqsave(&ep->lock, flags);
1912 1940
1913 /* 1941 /*
1914 * In the PXA320 manual, in the section about Back-to-Back setup 1942 * In the PXA320 manual, in the section about Back-to-Back setup
@@ -1947,10 +1975,13 @@ static void handle_ep0_ctrl_req(struct pxa_udc *udc,
1947 /* Tell UDC to enter Data Stage */ 1975 /* Tell UDC to enter Data Stage */
1948 ep_write_UDCCSR(ep, UDCCSR0_SA | UDCCSR0_OPC); 1976 ep_write_UDCCSR(ep, UDCCSR0_SA | UDCCSR0_OPC);
1949 1977
1978 spin_unlock_irqrestore(&ep->lock, flags);
1950 i = udc->driver->setup(&udc->gadget, &u.r); 1979 i = udc->driver->setup(&udc->gadget, &u.r);
1980 spin_lock_irqsave(&ep->lock, flags);
1951 if (i < 0) 1981 if (i < 0)
1952 goto stall; 1982 goto stall;
1953out: 1983out:
1984 spin_unlock_irqrestore(&ep->lock, flags);
1954 return; 1985 return;
1955stall: 1986stall:
1956 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n", 1987 ep_dbg(ep, "protocol STALL, udccsr0=%03x err %d\n",
@@ -2055,13 +2086,13 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2055 if (req && !ep_is_full(ep)) 2086 if (req && !ep_is_full(ep))
2056 completed = write_ep0_fifo(ep, req); 2087 completed = write_ep0_fifo(ep, req);
2057 if (completed) 2088 if (completed)
2058 ep0_end_in_req(ep, req); 2089 ep0_end_in_req(ep, req, NULL);
2059 break; 2090 break;
2060 case OUT_DATA_STAGE: /* SET_DESCRIPTOR */ 2091 case OUT_DATA_STAGE: /* SET_DESCRIPTOR */
2061 if (epout_has_pkt(ep) && req) 2092 if (epout_has_pkt(ep) && req)
2062 completed = read_ep0_fifo(ep, req); 2093 completed = read_ep0_fifo(ep, req);
2063 if (completed) 2094 if (completed)
2064 ep0_end_out_req(ep, req); 2095 ep0_end_out_req(ep, req, NULL);
2065 break; 2096 break;
2066 case STALL: 2097 case STALL:
2067 ep_write_UDCCSR(ep, UDCCSR0_FST); 2098 ep_write_UDCCSR(ep, UDCCSR0_FST);
@@ -2091,7 +2122,7 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
2091 * Tries to transfer all pending request data into the endpoint and/or 2122 * Tries to transfer all pending request data into the endpoint and/or
2092 * transfer all pending data in the endpoint into usb requests. 2123 * transfer all pending data in the endpoint into usb requests.
2093 * 2124 *
2094 * Is always called when in_interrupt() or with ep->lock held. 2125 * Is always called when in_interrupt() and with ep->lock released.
2095 */ 2126 */
2096static void handle_ep(struct pxa_ep *ep) 2127static void handle_ep(struct pxa_ep *ep)
2097{ 2128{
@@ -2100,10 +2131,17 @@ static void handle_ep(struct pxa_ep *ep)
2100 u32 udccsr; 2131 u32 udccsr;
2101 int is_in = ep->dir_in; 2132 int is_in = ep->dir_in;
2102 int loop = 0; 2133 int loop = 0;
2134 unsigned long flags;
2135
2136 spin_lock_irqsave(&ep->lock, flags);
2137 if (ep->in_handle_ep)
2138 goto recursion_detected;
2139 ep->in_handle_ep = 1;
2103 2140
2104 do { 2141 do {
2105 completed = 0; 2142 completed = 0;
2106 udccsr = udc_ep_readl(ep, UDCCSR); 2143 udccsr = udc_ep_readl(ep, UDCCSR);
2144
2107 if (likely(!list_empty(&ep->queue))) 2145 if (likely(!list_empty(&ep->queue)))
2108 req = list_entry(ep->queue.next, 2146 req = list_entry(ep->queue.next,
2109 struct pxa27x_request, queue); 2147 struct pxa27x_request, queue);
@@ -2122,15 +2160,22 @@ static void handle_ep(struct pxa_ep *ep)
2122 if (unlikely(is_in)) { 2160 if (unlikely(is_in)) {
2123 if (likely(!ep_is_full(ep))) 2161 if (likely(!ep_is_full(ep)))
2124 completed = write_fifo(ep, req); 2162 completed = write_fifo(ep, req);
2125 if (completed)
2126 ep_end_in_req(ep, req);
2127 } else { 2163 } else {
2128 if (likely(epout_has_pkt(ep))) 2164 if (likely(epout_has_pkt(ep)))
2129 completed = read_fifo(ep, req); 2165 completed = read_fifo(ep, req);
2130 if (completed) 2166 }
2131 ep_end_out_req(ep, req); 2167
2168 if (completed) {
2169 if (is_in)
2170 ep_end_in_req(ep, req, &flags);
2171 else
2172 ep_end_out_req(ep, req, &flags);
2132 } 2173 }
2133 } while (completed); 2174 } while (completed);
2175
2176 ep->in_handle_ep = 0;
2177recursion_detected:
2178 spin_unlock_irqrestore(&ep->lock, flags);
2134} 2179}
2135 2180
2136/** 2181/**
@@ -2218,9 +2263,13 @@ static void irq_handle_data(int irq, struct pxa_udc *udc)
2218 continue; 2263 continue;
2219 2264
2220 udc_writel(udc, UDCISR0, UDCISR_INT(i, UDCISR_INT_MASK)); 2265 udc_writel(udc, UDCISR0, UDCISR_INT(i, UDCISR_INT_MASK));
2221 ep = &udc->pxa_ep[i]; 2266
2222 ep->stats.irqs++; 2267 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep));
2223 handle_ep(ep); 2268 if (i < ARRAY_SIZE(udc->pxa_ep)) {
2269 ep = &udc->pxa_ep[i];
2270 ep->stats.irqs++;
2271 handle_ep(ep);
2272 }
2224 } 2273 }
2225 2274
2226 for (i = 16; udcisr1 != 0 && i < 24; udcisr1 >>= 2, i++) { 2275 for (i = 16; udcisr1 != 0 && i < 24; udcisr1 >>= 2, i++) {
@@ -2228,9 +2277,12 @@ static void irq_handle_data(int irq, struct pxa_udc *udc)
2228 if (!(udcisr1 & UDCISR_INT_MASK)) 2277 if (!(udcisr1 & UDCISR_INT_MASK))
2229 continue; 2278 continue;
2230 2279
2231 ep = &udc->pxa_ep[i]; 2280 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep));
2232 ep->stats.irqs++; 2281 if (i < ARRAY_SIZE(udc->pxa_ep)) {
2233 handle_ep(ep); 2282 ep = &udc->pxa_ep[i];
2283 ep->stats.irqs++;
2284 handle_ep(ep);
2285 }
2234 } 2286 }
2235 2287
2236} 2288}
@@ -2439,7 +2491,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2439 } 2491 }
2440 2492
2441 retval = -ENOMEM; 2493 retval = -ENOMEM;
2442 udc->regs = ioremap(regs->start, regs->end - regs->start + 1); 2494 udc->regs = ioremap(regs->start, resource_size(regs));
2443 if (!udc->regs) { 2495 if (!udc->regs) {
2444 dev_err(&pdev->dev, "Unable to map UDC I/O memory\n"); 2496 dev_err(&pdev->dev, "Unable to map UDC I/O memory\n");
2445 goto err_map; 2497 goto err_map;
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index e25225e26586..ff61e4866e8a 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -318,6 +318,11 @@ struct udc_usb_ep {
318 * @queue: requests queue 318 * @queue: requests queue
319 * @lock: lock to pxa_ep data (queues and stats) 319 * @lock: lock to pxa_ep data (queues and stats)
320 * @enabled: true when endpoint enabled (not stopped by gadget layer) 320 * @enabled: true when endpoint enabled (not stopped by gadget layer)
321 * @in_handle_ep: number of recursions of handle_ep() function
322 * Prevents deadlocks or infinite recursions of types :
323 * irq->handle_ep()->req_done()->req.complete()->pxa_ep_queue()->handle_ep()
324 * or
325 * pxa_ep_queue()->handle_ep()->req_done()->req.complete()->pxa_ep_queue()
321 * @idx: endpoint index (1 => epA, 2 => epB, ..., 24 => epX) 326 * @idx: endpoint index (1 => epA, 2 => epB, ..., 24 => epX)
322 * @name: endpoint name (for trace/debug purpose) 327 * @name: endpoint name (for trace/debug purpose)
323 * @dir_in: 1 if IN endpoint, 0 if OUT endpoint 328 * @dir_in: 1 if IN endpoint, 0 if OUT endpoint
@@ -346,6 +351,7 @@ struct pxa_ep {
346 spinlock_t lock; /* Protects this structure */ 351 spinlock_t lock; /* Protects this structure */
347 /* (queues, stats) */ 352 /* (queues, stats) */
348 unsigned enabled:1; 353 unsigned enabled:1;
354 unsigned in_handle_ep:1;
349 355
350 unsigned idx:5; 356 unsigned idx:5;
351 char *name; 357 char *name;
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index e220fb8091a3..888d8f166c0b 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -26,6 +26,8 @@
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/clk.h> 28#include <linux/clk.h>
29#include <linux/err.h>
30#include <linux/slab.h>
29 31
30#include <linux/usb/ch9.h> 32#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h> 33#include <linux/usb/gadget.h>
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 48267bc0b2e0..5c0d06c79a81 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/slab.h>
31#include <linux/seq_file.h> 32#include <linux/seq_file.h>
32#include <linux/netdevice.h> 33#include <linux/netdevice.h>
33 34
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index 4b5dbd0127f5..1f73b485732d 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -22,6 +22,7 @@
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/slab.h>
25 26
26#include <linux/usb/ch9.h> 27#include <linux/usb/ch9.h>
27#include <linux/usb/gadget.h> 28#include <linux/usb/gadget.h>
@@ -30,7 +31,7 @@
30 31
31#include <plat/regs-usb-hsotg-phy.h> 32#include <plat/regs-usb-hsotg-phy.h>
32#include <plat/regs-usb-hsotg.h> 33#include <plat/regs-usb-hsotg.h>
33#include <plat/regs-sys.h> 34#include <mach/regs-sys.h>
34#include <plat/udc-hs.h> 35#include <plat/udc-hs.h>
35 36
36#define DMA_ADDR_INVALID (~((dma_addr_t)0)) 37#define DMA_ADDR_INVALID (~((dma_addr_t)0))
@@ -317,7 +318,8 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
317 * 318 *
318 * Allocate a new USB request structure appropriate for the specified endpoint 319 * Allocate a new USB request structure appropriate for the specified endpoint
319 */ 320 */
320struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep, gfp_t flags) 321static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep,
322 gfp_t flags)
321{ 323{
322 struct s3c_hsotg_req *req; 324 struct s3c_hsotg_req *req;
323 325
@@ -373,7 +375,7 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg,
373 req->dma = DMA_ADDR_INVALID; 375 req->dma = DMA_ADDR_INVALID;
374 hs_req->mapped = 0; 376 hs_req->mapped = 0;
375 } else { 377 } else {
376 dma_sync_single(hsotg->dev, req->dma, req->length, dir); 378 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
377 } 379 }
378} 380}
379 381
@@ -755,7 +757,7 @@ static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg,
755 hs_req->mapped = 1; 757 hs_req->mapped = 1;
756 req->dma = dma; 758 req->dma = dma;
757 } else { 759 } else {
758 dma_sync_single(hsotg->dev, req->dma, req->length, dir); 760 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
759 hs_req->mapped = 0; 761 hs_req->mapped = 0;
760 } 762 }
761 763
@@ -1460,7 +1462,7 @@ static u32 s3c_hsotg_read_frameno(struct s3c_hsotg *hsotg)
1460 * as the actual data should be sent to the memory directly and we turn 1462 * as the actual data should be sent to the memory directly and we turn
1461 * on the completion interrupts to get notifications of transfer completion. 1463 * on the completion interrupts to get notifications of transfer completion.
1462 */ 1464 */
1463void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg) 1465static void s3c_hsotg_handle_rx(struct s3c_hsotg *hsotg)
1464{ 1466{
1465 u32 grxstsr = readl(hsotg->regs + S3C_GRXSTSP); 1467 u32 grxstsr = readl(hsotg->regs + S3C_GRXSTSP);
1466 u32 epnum, status, size; 1468 u32 epnum, status, size;
@@ -2143,6 +2145,7 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2143 u32 epctrl; 2145 u32 epctrl;
2144 u32 mps; 2146 u32 mps;
2145 int dir_in; 2147 int dir_in;
2148 int ret = 0;
2146 2149
2147 dev_dbg(hsotg->dev, 2150 dev_dbg(hsotg->dev,
2148 "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n", 2151 "%s: ep %s: a 0x%02x, attr 0x%02x, mps 0x%04x, intr %d\n",
@@ -2194,7 +2197,8 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2194 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 2197 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
2195 case USB_ENDPOINT_XFER_ISOC: 2198 case USB_ENDPOINT_XFER_ISOC:
2196 dev_err(hsotg->dev, "no current ISOC support\n"); 2199 dev_err(hsotg->dev, "no current ISOC support\n");
2197 return -EINVAL; 2200 ret = -EINVAL;
2201 goto out;
2198 2202
2199 case USB_ENDPOINT_XFER_BULK: 2203 case USB_ENDPOINT_XFER_BULK:
2200 epctrl |= S3C_DxEPCTL_EPType_Bulk; 2204 epctrl |= S3C_DxEPCTL_EPType_Bulk;
@@ -2233,8 +2237,9 @@ static int s3c_hsotg_ep_enable(struct usb_ep *ep,
2233 /* enable the endpoint interrupt */ 2237 /* enable the endpoint interrupt */
2234 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1); 2238 s3c_hsotg_ctrl_epint(hsotg, index, dir_in, 1);
2235 2239
2240out:
2236 spin_unlock_irqrestore(&hs_ep->lock, flags); 2241 spin_unlock_irqrestore(&hs_ep->lock, flags);
2237 return 0; 2242 return ret;
2238} 2243}
2239 2244
2240static int s3c_hsotg_ep_disable(struct usb_ep *ep) 2245static int s3c_hsotg_ep_disable(struct usb_ep *ep)
@@ -2582,6 +2587,7 @@ err:
2582 hsotg->gadget.dev.driver = NULL; 2587 hsotg->gadget.dev.driver = NULL;
2583 return ret; 2588 return ret;
2584} 2589}
2590EXPORT_SYMBOL(usb_gadget_register_driver);
2585 2591
2586int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) 2592int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2587{ 2593{
@@ -3093,7 +3099,7 @@ static void s3c_hsotg_gate(struct platform_device *pdev, bool on)
3093 local_irq_restore(flags); 3099 local_irq_restore(flags);
3094} 3100}
3095 3101
3096struct s3c_hsotg_plat s3c_hsotg_default_pdata; 3102static struct s3c_hsotg_plat s3c_hsotg_default_pdata;
3097 3103
3098static int __devinit s3c_hsotg_probe(struct platform_device *pdev) 3104static int __devinit s3c_hsotg_probe(struct platform_device *pdev)
3099{ 3105{
diff --git a/drivers/usb/gadget/storage_common.c b/drivers/usb/gadget/storage_common.c
new file mode 100644
index 000000000000..868d8ee86756
--- /dev/null
+++ b/drivers/usb/gadget/storage_common.c
@@ -0,0 +1,778 @@
1/*
2 * storage_common.c -- Common definitions for mass storage functionality
3 *
4 * Copyright (C) 2003-2008 Alan Stern
5 * Copyeight (C) 2009 Samsung Electronics
6 * Author: Michal Nazarewicz (m.nazarewicz@samsung.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/*
25 * This file requires the following identifiers used in USB strings to
26 * be defined (each of type pointer to char):
27 * - fsg_string_manufacturer -- name of the manufacturer
28 * - fsg_string_product -- name of the product
29 * - fsg_string_serial -- product's serial
30 * - fsg_string_config -- name of the configuration
31 * - fsg_string_interface -- name of the interface
32 * The first four are only needed when FSG_DESCRIPTORS_DEVICE_STRINGS
33 * macro is defined prior to including this file.
34 */
35
36/*
37 * When FSG_NO_INTR_EP is defined fsg_fs_intr_in_desc and
38 * fsg_hs_intr_in_desc objects as well as
39 * FSG_FS_FUNCTION_PRE_EP_ENTRIES and FSG_HS_FUNCTION_PRE_EP_ENTRIES
40 * macros are not defined.
41 *
42 * When FSG_NO_DEVICE_STRINGS is defined FSG_STRING_MANUFACTURER,
43 * FSG_STRING_PRODUCT, FSG_STRING_SERIAL and FSG_STRING_CONFIG are not
44 * defined (as well as corresponding entries in string tables are
45 * missing) and FSG_STRING_INTERFACE has value of zero.
46 *
47 * When FSG_NO_OTG is defined fsg_otg_desc won't be defined.
48 */
49
50/*
51 * When FSG_BUFFHD_STATIC_BUFFER is defined when this file is included
52 * the fsg_buffhd structure's buf field will be an array of FSG_BUFLEN
53 * characters rather then a pointer to void.
54 */
55
56
57#include <asm/unaligned.h>
58
59
60/* Thanks to NetChip Technologies for donating this product ID.
61 *
62 * DO NOT REUSE THESE IDs with any other driver!! Ever!!
63 * Instead: allocate your own, using normal USB-IF procedures. */
64#define FSG_VENDOR_ID 0x0525 /* NetChip */
65#define FSG_PRODUCT_ID 0xa4a5 /* Linux-USB File-backed Storage Gadget */
66
67
68/*-------------------------------------------------------------------------*/
69
70
71#ifndef DEBUG
72#undef VERBOSE_DEBUG
73#undef DUMP_MSGS
74#endif /* !DEBUG */
75
76#ifdef VERBOSE_DEBUG
77#define VLDBG LDBG
78#else
79#define VLDBG(lun, fmt, args...) do { } while (0)
80#endif /* VERBOSE_DEBUG */
81
82#define LDBG(lun, fmt, args...) dev_dbg (&(lun)->dev, fmt, ## args)
83#define LERROR(lun, fmt, args...) dev_err (&(lun)->dev, fmt, ## args)
84#define LWARN(lun, fmt, args...) dev_warn(&(lun)->dev, fmt, ## args)
85#define LINFO(lun, fmt, args...) dev_info(&(lun)->dev, fmt, ## args)
86
87/* Keep those macros in sync with thos in
88 * include/linux/ubs/composite.h or else GCC will complain. If they
89 * are identical (the same names of arguments, white spaces in the
90 * same places) GCC will allow redefinition otherwise (even if some
91 * white space is removed or added) warning will be issued. No
92 * checking if those symbols is defined is performed because warning
93 * is desired when those macros were defined by someone else to mean
94 * something else. */
95#define DBG(d, fmt, args...) dev_dbg(&(d)->gadget->dev , fmt , ## args)
96#define VDBG(d, fmt, args...) dev_vdbg(&(d)->gadget->dev , fmt , ## args)
97#define ERROR(d, fmt, args...) dev_err(&(d)->gadget->dev , fmt , ## args)
98#define WARNING(d, fmt, args...) dev_warn(&(d)->gadget->dev , fmt , ## args)
99#define INFO(d, fmt, args...) dev_info(&(d)->gadget->dev , fmt , ## args)
100
101
102
103#ifdef DUMP_MSGS
104
105# define dump_msg(fsg, /* const char * */ label, \
106 /* const u8 * */ buf, /* unsigned */ length) do { \
107 if (length < 512) { \
108 DBG(fsg, "%s, length %u:\n", label, length); \
109 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, \
110 16, 1, buf, length, 0); \
111 } \
112} while (0)
113
114# define dump_cdb(fsg) do { } while (0)
115
116#else
117
118# define dump_msg(fsg, /* const char * */ label, \
119 /* const u8 * */ buf, /* unsigned */ length) do { } while (0)
120
121# ifdef VERBOSE_DEBUG
122
123# define dump_cdb(fsg) \
124 print_hex_dump(KERN_DEBUG, "SCSI CDB: ", DUMP_PREFIX_NONE, \
125 16, 1, (fsg)->cmnd, (fsg)->cmnd_size, 0) \
126
127# else
128
129# define dump_cdb(fsg) do { } while (0)
130
131# endif /* VERBOSE_DEBUG */
132
133#endif /* DUMP_MSGS */
134
135
136
137
138
139/*-------------------------------------------------------------------------*/
140
141/* SCSI device types */
142#define TYPE_DISK 0x00
143#define TYPE_CDROM 0x05
144
145/* USB protocol value = the transport method */
146#define USB_PR_CBI 0x00 /* Control/Bulk/Interrupt */
147#define USB_PR_CB 0x01 /* Control/Bulk w/o interrupt */
148#define USB_PR_BULK 0x50 /* Bulk-only */
149
150/* USB subclass value = the protocol encapsulation */
151#define USB_SC_RBC 0x01 /* Reduced Block Commands (flash) */
152#define USB_SC_8020 0x02 /* SFF-8020i, MMC-2, ATAPI (CD-ROM) */
153#define USB_SC_QIC 0x03 /* QIC-157 (tape) */
154#define USB_SC_UFI 0x04 /* UFI (floppy) */
155#define USB_SC_8070 0x05 /* SFF-8070i (removable) */
156#define USB_SC_SCSI 0x06 /* Transparent SCSI */
157
158/* Bulk-only data structures */
159
160/* Command Block Wrapper */
161struct fsg_bulk_cb_wrap {
162 __le32 Signature; /* Contains 'USBC' */
163 u32 Tag; /* Unique per command id */
164 __le32 DataTransferLength; /* Size of the data */
165 u8 Flags; /* Direction in bit 7 */
166 u8 Lun; /* LUN (normally 0) */
167 u8 Length; /* Of the CDB, <= MAX_COMMAND_SIZE */
168 u8 CDB[16]; /* Command Data Block */
169};
170
171#define USB_BULK_CB_WRAP_LEN 31
172#define USB_BULK_CB_SIG 0x43425355 /* Spells out USBC */
173#define USB_BULK_IN_FLAG 0x80
174
175/* Command Status Wrapper */
176struct bulk_cs_wrap {
177 __le32 Signature; /* Should = 'USBS' */
178 u32 Tag; /* Same as original command */
179 __le32 Residue; /* Amount not transferred */
180 u8 Status; /* See below */
181};
182
183#define USB_BULK_CS_WRAP_LEN 13
184#define USB_BULK_CS_SIG 0x53425355 /* Spells out 'USBS' */
185#define USB_STATUS_PASS 0
186#define USB_STATUS_FAIL 1
187#define USB_STATUS_PHASE_ERROR 2
188
189/* Bulk-only class specific requests */
190#define USB_BULK_RESET_REQUEST 0xff
191#define USB_BULK_GET_MAX_LUN_REQUEST 0xfe
192
193
194/* CBI Interrupt data structure */
195struct interrupt_data {
196 u8 bType;
197 u8 bValue;
198};
199
200#define CBI_INTERRUPT_DATA_LEN 2
201
202/* CBI Accept Device-Specific Command request */
203#define USB_CBI_ADSC_REQUEST 0x00
204
205
206/* Length of a SCSI Command Data Block */
207#define MAX_COMMAND_SIZE 16
208
209/* SCSI commands that we recognize */
210#define SC_FORMAT_UNIT 0x04
211#define SC_INQUIRY 0x12
212#define SC_MODE_SELECT_6 0x15
213#define SC_MODE_SELECT_10 0x55
214#define SC_MODE_SENSE_6 0x1a
215#define SC_MODE_SENSE_10 0x5a
216#define SC_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
217#define SC_READ_6 0x08
218#define SC_READ_10 0x28
219#define SC_READ_12 0xa8
220#define SC_READ_CAPACITY 0x25
221#define SC_READ_FORMAT_CAPACITIES 0x23
222#define SC_READ_HEADER 0x44
223#define SC_READ_TOC 0x43
224#define SC_RELEASE 0x17
225#define SC_REQUEST_SENSE 0x03
226#define SC_RESERVE 0x16
227#define SC_SEND_DIAGNOSTIC 0x1d
228#define SC_START_STOP_UNIT 0x1b
229#define SC_SYNCHRONIZE_CACHE 0x35
230#define SC_TEST_UNIT_READY 0x00
231#define SC_VERIFY 0x2f
232#define SC_WRITE_6 0x0a
233#define SC_WRITE_10 0x2a
234#define SC_WRITE_12 0xaa
235
236/* SCSI Sense Key/Additional Sense Code/ASC Qualifier values */
237#define SS_NO_SENSE 0
238#define SS_COMMUNICATION_FAILURE 0x040800
239#define SS_INVALID_COMMAND 0x052000
240#define SS_INVALID_FIELD_IN_CDB 0x052400
241#define SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x052100
242#define SS_LOGICAL_UNIT_NOT_SUPPORTED 0x052500
243#define SS_MEDIUM_NOT_PRESENT 0x023a00
244#define SS_MEDIUM_REMOVAL_PREVENTED 0x055302
245#define SS_NOT_READY_TO_READY_TRANSITION 0x062800
246#define SS_RESET_OCCURRED 0x062900
247#define SS_SAVING_PARAMETERS_NOT_SUPPORTED 0x053900
248#define SS_UNRECOVERED_READ_ERROR 0x031100
249#define SS_WRITE_ERROR 0x030c02
250#define SS_WRITE_PROTECTED 0x072700
251
252#define SK(x) ((u8) ((x) >> 16)) /* Sense Key byte, etc. */
253#define ASC(x) ((u8) ((x) >> 8))
254#define ASCQ(x) ((u8) (x))
255
256
257/*-------------------------------------------------------------------------*/
258
259
260struct fsg_lun {
261 struct file *filp;
262 loff_t file_length;
263 loff_t num_sectors;
264
265 unsigned int initially_ro:1;
266 unsigned int ro:1;
267 unsigned int removable:1;
268 unsigned int cdrom:1;
269 unsigned int prevent_medium_removal:1;
270 unsigned int registered:1;
271 unsigned int info_valid:1;
272
273 u32 sense_data;
274 u32 sense_data_info;
275 u32 unit_attention_data;
276
277 struct device dev;
278};
279
280#define fsg_lun_is_open(curlun) ((curlun)->filp != NULL)
281
282static struct fsg_lun *fsg_lun_from_dev(struct device *dev)
283{
284 return container_of(dev, struct fsg_lun, dev);
285}
286
287
288/* Big enough to hold our biggest descriptor */
289#define EP0_BUFSIZE 256
290#define DELAYED_STATUS (EP0_BUFSIZE + 999) /* An impossibly large value */
291
292/* Number of buffers we will use. 2 is enough for double-buffering */
293#define FSG_NUM_BUFFERS 2
294
295/* Default size of buffer length. */
296#define FSG_BUFLEN ((u32)16384)
297
298/* Maximal number of LUNs supported in mass storage function */
299#define FSG_MAX_LUNS 8
300
301enum fsg_buffer_state {
302 BUF_STATE_EMPTY = 0,
303 BUF_STATE_FULL,
304 BUF_STATE_BUSY
305};
306
307struct fsg_buffhd {
308#ifdef FSG_BUFFHD_STATIC_BUFFER
309 char buf[FSG_BUFLEN];
310#else
311 void *buf;
312#endif
313 enum fsg_buffer_state state;
314 struct fsg_buffhd *next;
315
316 /* The NetChip 2280 is faster, and handles some protocol faults
317 * better, if we don't submit any short bulk-out read requests.
318 * So we will record the intended request length here. */
319 unsigned int bulk_out_intended_length;
320
321 struct usb_request *inreq;
322 int inreq_busy;
323 struct usb_request *outreq;
324 int outreq_busy;
325};
326
327enum fsg_state {
328 /* This one isn't used anywhere */
329 FSG_STATE_COMMAND_PHASE = -10,
330 FSG_STATE_DATA_PHASE,
331 FSG_STATE_STATUS_PHASE,
332
333 FSG_STATE_IDLE = 0,
334 FSG_STATE_ABORT_BULK_OUT,
335 FSG_STATE_RESET,
336 FSG_STATE_INTERFACE_CHANGE,
337 FSG_STATE_CONFIG_CHANGE,
338 FSG_STATE_DISCONNECT,
339 FSG_STATE_EXIT,
340 FSG_STATE_TERMINATED
341};
342
343enum data_direction {
344 DATA_DIR_UNKNOWN = 0,
345 DATA_DIR_FROM_HOST,
346 DATA_DIR_TO_HOST,
347 DATA_DIR_NONE
348};
349
350
351/*-------------------------------------------------------------------------*/
352
353
354static inline u32 get_unaligned_be24(u8 *buf)
355{
356 return 0xffffff & (u32) get_unaligned_be32(buf - 1);
357}
358
359
360/*-------------------------------------------------------------------------*/
361
362
363enum {
364#ifndef FSG_NO_DEVICE_STRINGS
365 FSG_STRING_MANUFACTURER = 1,
366 FSG_STRING_PRODUCT,
367 FSG_STRING_SERIAL,
368 FSG_STRING_CONFIG,
369#endif
370 FSG_STRING_INTERFACE
371};
372
373
374#ifndef FSG_NO_OTG
375static struct usb_otg_descriptor
376fsg_otg_desc = {
377 .bLength = sizeof fsg_otg_desc,
378 .bDescriptorType = USB_DT_OTG,
379
380 .bmAttributes = USB_OTG_SRP,
381};
382#endif
383
384/* There is only one interface. */
385
386static struct usb_interface_descriptor
387fsg_intf_desc = {
388 .bLength = sizeof fsg_intf_desc,
389 .bDescriptorType = USB_DT_INTERFACE,
390
391 .bNumEndpoints = 2, /* Adjusted during fsg_bind() */
392 .bInterfaceClass = USB_CLASS_MASS_STORAGE,
393 .bInterfaceSubClass = USB_SC_SCSI, /* Adjusted during fsg_bind() */
394 .bInterfaceProtocol = USB_PR_BULK, /* Adjusted during fsg_bind() */
395 .iInterface = FSG_STRING_INTERFACE,
396};
397
398/* Three full-speed endpoint descriptors: bulk-in, bulk-out,
399 * and interrupt-in. */
400
401static struct usb_endpoint_descriptor
402fsg_fs_bulk_in_desc = {
403 .bLength = USB_DT_ENDPOINT_SIZE,
404 .bDescriptorType = USB_DT_ENDPOINT,
405
406 .bEndpointAddress = USB_DIR_IN,
407 .bmAttributes = USB_ENDPOINT_XFER_BULK,
408 /* wMaxPacketSize set by autoconfiguration */
409};
410
411static struct usb_endpoint_descriptor
412fsg_fs_bulk_out_desc = {
413 .bLength = USB_DT_ENDPOINT_SIZE,
414 .bDescriptorType = USB_DT_ENDPOINT,
415
416 .bEndpointAddress = USB_DIR_OUT,
417 .bmAttributes = USB_ENDPOINT_XFER_BULK,
418 /* wMaxPacketSize set by autoconfiguration */
419};
420
421#ifndef FSG_NO_INTR_EP
422
423static struct usb_endpoint_descriptor
424fsg_fs_intr_in_desc = {
425 .bLength = USB_DT_ENDPOINT_SIZE,
426 .bDescriptorType = USB_DT_ENDPOINT,
427
428 .bEndpointAddress = USB_DIR_IN,
429 .bmAttributes = USB_ENDPOINT_XFER_INT,
430 .wMaxPacketSize = cpu_to_le16(2),
431 .bInterval = 32, /* frames -> 32 ms */
432};
433
434#ifndef FSG_NO_OTG
435# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 2
436#else
437# define FSG_FS_FUNCTION_PRE_EP_ENTRIES 1
438#endif
439
440#endif
441
442static struct usb_descriptor_header *fsg_fs_function[] = {
443#ifndef FSG_NO_OTG
444 (struct usb_descriptor_header *) &fsg_otg_desc,
445#endif
446 (struct usb_descriptor_header *) &fsg_intf_desc,
447 (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
448 (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
449#ifndef FSG_NO_INTR_EP
450 (struct usb_descriptor_header *) &fsg_fs_intr_in_desc,
451#endif
452 NULL,
453};
454
455
456/*
457 * USB 2.0 devices need to expose both high speed and full speed
458 * descriptors, unless they only run at full speed.
459 *
460 * That means alternate endpoint descriptors (bigger packets)
461 * and a "device qualifier" ... plus more construction options
462 * for the config descriptor.
463 */
464static struct usb_endpoint_descriptor
465fsg_hs_bulk_in_desc = {
466 .bLength = USB_DT_ENDPOINT_SIZE,
467 .bDescriptorType = USB_DT_ENDPOINT,
468
469 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
470 .bmAttributes = USB_ENDPOINT_XFER_BULK,
471 .wMaxPacketSize = cpu_to_le16(512),
472};
473
474static struct usb_endpoint_descriptor
475fsg_hs_bulk_out_desc = {
476 .bLength = USB_DT_ENDPOINT_SIZE,
477 .bDescriptorType = USB_DT_ENDPOINT,
478
479 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
480 .bmAttributes = USB_ENDPOINT_XFER_BULK,
481 .wMaxPacketSize = cpu_to_le16(512),
482 .bInterval = 1, /* NAK every 1 uframe */
483};
484
485#ifndef FSG_NO_INTR_EP
486
487static struct usb_endpoint_descriptor
488fsg_hs_intr_in_desc = {
489 .bLength = USB_DT_ENDPOINT_SIZE,
490 .bDescriptorType = USB_DT_ENDPOINT,
491
492 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
493 .bmAttributes = USB_ENDPOINT_XFER_INT,
494 .wMaxPacketSize = cpu_to_le16(2),
495 .bInterval = 9, /* 2**(9-1) = 256 uframes -> 32 ms */
496};
497
498#ifndef FSG_NO_OTG
499# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 2
500#else
501# define FSG_HS_FUNCTION_PRE_EP_ENTRIES 1
502#endif
503
504#endif
505
506static struct usb_descriptor_header *fsg_hs_function[] = {
507#ifndef FSG_NO_OTG
508 (struct usb_descriptor_header *) &fsg_otg_desc,
509#endif
510 (struct usb_descriptor_header *) &fsg_intf_desc,
511 (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
512 (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
513#ifndef FSG_NO_INTR_EP
514 (struct usb_descriptor_header *) &fsg_hs_intr_in_desc,
515#endif
516 NULL,
517};
518
519/* Maxpacket and other transfer characteristics vary by speed. */
520static struct usb_endpoint_descriptor *
521fsg_ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *fs,
522 struct usb_endpoint_descriptor *hs)
523{
524 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
525 return hs;
526 return fs;
527}
528
529
530/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
531static struct usb_string fsg_strings[] = {
532#ifndef FSG_NO_DEVICE_STRINGS
533 {FSG_STRING_MANUFACTURER, fsg_string_manufacturer},
534 {FSG_STRING_PRODUCT, fsg_string_product},
535 {FSG_STRING_SERIAL, fsg_string_serial},
536 {FSG_STRING_CONFIG, fsg_string_config},
537#endif
538 {FSG_STRING_INTERFACE, fsg_string_interface},
539 {}
540};
541
542static struct usb_gadget_strings fsg_stringtab = {
543 .language = 0x0409, /* en-us */
544 .strings = fsg_strings,
545};
546
547
548 /*-------------------------------------------------------------------------*/
549
550/* If the next two routines are called while the gadget is registered,
551 * the caller must own fsg->filesem for writing. */
552
553static int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
554{
555 int ro;
556 struct file *filp = NULL;
557 int rc = -EINVAL;
558 struct inode *inode = NULL;
559 loff_t size;
560 loff_t num_sectors;
561 loff_t min_sectors;
562
563 /* R/W if we can, R/O if we must */
564 ro = curlun->initially_ro;
565 if (!ro) {
566 filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0);
567 if (-EROFS == PTR_ERR(filp))
568 ro = 1;
569 }
570 if (ro)
571 filp = filp_open(filename, O_RDONLY | O_LARGEFILE, 0);
572 if (IS_ERR(filp)) {
573 LINFO(curlun, "unable to open backing file: %s\n", filename);
574 return PTR_ERR(filp);
575 }
576
577 if (!(filp->f_mode & FMODE_WRITE))
578 ro = 1;
579
580 if (filp->f_path.dentry)
581 inode = filp->f_path.dentry->d_inode;
582 if (inode && S_ISBLK(inode->i_mode)) {
583 if (bdev_read_only(inode->i_bdev))
584 ro = 1;
585 } else if (!inode || !S_ISREG(inode->i_mode)) {
586 LINFO(curlun, "invalid file type: %s\n", filename);
587 goto out;
588 }
589
590 /* If we can't read the file, it's no good.
591 * If we can't write the file, use it read-only. */
592 if (!filp->f_op || !(filp->f_op->read || filp->f_op->aio_read)) {
593 LINFO(curlun, "file not readable: %s\n", filename);
594 goto out;
595 }
596 if (!(filp->f_op->write || filp->f_op->aio_write))
597 ro = 1;
598
599 size = i_size_read(inode->i_mapping->host);
600 if (size < 0) {
601 LINFO(curlun, "unable to find file size: %s\n", filename);
602 rc = (int) size;
603 goto out;
604 }
605 num_sectors = size >> 9; /* File size in 512-byte blocks */
606 min_sectors = 1;
607 if (curlun->cdrom) {
608 num_sectors &= ~3; /* Reduce to a multiple of 2048 */
609 min_sectors = 300*4; /* Smallest track is 300 frames */
610 if (num_sectors >= 256*60*75*4) {
611 num_sectors = (256*60*75 - 1) * 4;
612 LINFO(curlun, "file too big: %s\n", filename);
613 LINFO(curlun, "using only first %d blocks\n",
614 (int) num_sectors);
615 }
616 }
617 if (num_sectors < min_sectors) {
618 LINFO(curlun, "file too small: %s\n", filename);
619 rc = -ETOOSMALL;
620 goto out;
621 }
622
623 get_file(filp);
624 curlun->ro = ro;
625 curlun->filp = filp;
626 curlun->file_length = size;
627 curlun->num_sectors = num_sectors;
628 LDBG(curlun, "open backing file: %s\n", filename);
629 rc = 0;
630
631out:
632 filp_close(filp, current->files);
633 return rc;
634}
635
636
637static void fsg_lun_close(struct fsg_lun *curlun)
638{
639 if (curlun->filp) {
640 LDBG(curlun, "close backing file\n");
641 fput(curlun->filp);
642 curlun->filp = NULL;
643 }
644}
645
646
647/*-------------------------------------------------------------------------*/
648
649/* Sync the file data, don't bother with the metadata.
650 * This code was copied from fs/buffer.c:sys_fdatasync(). */
651static int fsg_lun_fsync_sub(struct fsg_lun *curlun)
652{
653 struct file *filp = curlun->filp;
654
655 if (curlun->ro || !filp)
656 return 0;
657 return vfs_fsync(filp, filp->f_path.dentry, 1);
658}
659
660static void store_cdrom_address(u8 *dest, int msf, u32 addr)
661{
662 if (msf) {
663 /* Convert to Minutes-Seconds-Frames */
664 addr >>= 2; /* Convert to 2048-byte frames */
665 addr += 2*75; /* Lead-in occupies 2 seconds */
666 dest[3] = addr % 75; /* Frames */
667 addr /= 75;
668 dest[2] = addr % 60; /* Seconds */
669 addr /= 60;
670 dest[1] = addr; /* Minutes */
671 dest[0] = 0; /* Reserved */
672 } else {
673 /* Absolute sector */
674 put_unaligned_be32(addr, dest);
675 }
676}
677
678
679/*-------------------------------------------------------------------------*/
680
681
682static ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
683 char *buf)
684{
685 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
686
687 return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
688 ? curlun->ro
689 : curlun->initially_ro);
690}
691
692static ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
693 char *buf)
694{
695 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
696 struct rw_semaphore *filesem = dev_get_drvdata(dev);
697 char *p;
698 ssize_t rc;
699
700 down_read(filesem);
701 if (fsg_lun_is_open(curlun)) { /* Get the complete pathname */
702 p = d_path(&curlun->filp->f_path, buf, PAGE_SIZE - 1);
703 if (IS_ERR(p))
704 rc = PTR_ERR(p);
705 else {
706 rc = strlen(p);
707 memmove(buf, p, rc);
708 buf[rc] = '\n'; /* Add a newline */
709 buf[++rc] = 0;
710 }
711 } else { /* No file, return 0 bytes */
712 *buf = 0;
713 rc = 0;
714 }
715 up_read(filesem);
716 return rc;
717}
718
719
720static ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
721 const char *buf, size_t count)
722{
723 ssize_t rc = count;
724 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
725 struct rw_semaphore *filesem = dev_get_drvdata(dev);
726 int i;
727
728 if (sscanf(buf, "%d", &i) != 1)
729 return -EINVAL;
730
731 /* Allow the write-enable status to change only while the backing file
732 * is closed. */
733 down_read(filesem);
734 if (fsg_lun_is_open(curlun)) {
735 LDBG(curlun, "read-only status change prevented\n");
736 rc = -EBUSY;
737 } else {
738 curlun->ro = !!i;
739 curlun->initially_ro = !!i;
740 LDBG(curlun, "read-only status set to %d\n", curlun->ro);
741 }
742 up_read(filesem);
743 return rc;
744}
745
746static ssize_t fsg_store_file(struct device *dev, struct device_attribute *attr,
747 const char *buf, size_t count)
748{
749 struct fsg_lun *curlun = fsg_lun_from_dev(dev);
750 struct rw_semaphore *filesem = dev_get_drvdata(dev);
751 int rc = 0;
752
753 if (curlun->prevent_medium_removal && fsg_lun_is_open(curlun)) {
754 LDBG(curlun, "eject attempt prevented\n");
755 return -EBUSY; /* "Door is locked" */
756 }
757
758 /* Remove a trailing newline */
759 if (count > 0 && buf[count-1] == '\n')
760 ((char *) buf)[count-1] = 0; /* Ugh! */
761
762 /* Eject current medium */
763 down_write(filesem);
764 if (fsg_lun_is_open(curlun)) {
765 fsg_lun_close(curlun);
766 curlun->unit_attention_data = SS_MEDIUM_NOT_PRESENT;
767 }
768
769 /* Load new medium */
770 if (count > 0 && buf[0]) {
771 rc = fsg_lun_open(curlun, buf);
772 if (rc == 0)
773 curlun->unit_attention_data =
774 SS_NOT_READY_TO_READY_TRANSITION;
775 }
776 up_write(filesem);
777 return (rc < 0 ? rc : count);
778}
diff --git a/drivers/usb/gadget/u_audio.c b/drivers/usb/gadget/u_audio.c
index 8252595d619d..7a86d2c9109c 100644
--- a/drivers/usb/gadget/u_audio.c
+++ b/drivers/usb/gadget/u_audio.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/slab.h>
13#include <linux/device.h> 14#include <linux/device.h>
14#include <linux/delay.h> 15#include <linux/delay.h>
15#include <linux/ctype.h> 16#include <linux/ctype.h>
@@ -288,6 +289,7 @@ static int gaudio_close_snd_dev(struct gaudio *gau)
288 return 0; 289 return 0;
289} 290}
290 291
292static struct gaudio *the_card;
291/** 293/**
292 * gaudio_setup - setup ALSA interface and preparing for USB transfer 294 * gaudio_setup - setup ALSA interface and preparing for USB transfer
293 * 295 *
@@ -303,6 +305,9 @@ int __init gaudio_setup(struct gaudio *card)
303 if (ret) 305 if (ret)
304 ERROR(card, "we need at least one control device\n"); 306 ERROR(card, "we need at least one control device\n");
305 307
308 if (!the_card)
309 the_card = card;
310
306 return ret; 311 return ret;
307 312
308} 313}
@@ -312,9 +317,11 @@ int __init gaudio_setup(struct gaudio *card)
312 * 317 *
313 * This is called to free all resources allocated by @gaudio_setup(). 318 * This is called to free all resources allocated by @gaudio_setup().
314 */ 319 */
315void gaudio_cleanup(struct gaudio *card) 320void gaudio_cleanup(void)
316{ 321{
317 if (card) 322 if (the_card) {
318 gaudio_close_snd_dev(card); 323 gaudio_close_snd_dev(the_card);
324 the_card = NULL;
325 }
319} 326}
320 327
diff --git a/drivers/usb/gadget/u_audio.h b/drivers/usb/gadget/u_audio.h
index cc8d159c648a..08ffce3298e6 100644
--- a/drivers/usb/gadget/u_audio.h
+++ b/drivers/usb/gadget/u_audio.h
@@ -51,6 +51,6 @@ struct gaudio {
51}; 51};
52 52
53int gaudio_setup(struct gaudio *card); 53int gaudio_setup(struct gaudio *card);
54void gaudio_cleanup(struct gaudio *card); 54void gaudio_cleanup(void);
55 55
56#endif /* __U_AUDIO_H */ 56#endif /* __U_AUDIO_H */
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 2fc02bd95848..07f4178ad178 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -23,6 +23,7 @@
23/* #define VERBOSE_DEBUG */ 23/* #define VERBOSE_DEBUG */
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/gfp.h>
26#include <linux/device.h> 27#include <linux/device.h>
27#include <linux/ctype.h> 28#include <linux/ctype.h>
28#include <linux/etherdevice.h> 29#include <linux/etherdevice.h>
@@ -746,6 +747,10 @@ static const struct net_device_ops eth_netdev_ops = {
746 .ndo_validate_addr = eth_validate_addr, 747 .ndo_validate_addr = eth_validate_addr,
747}; 748};
748 749
750static struct device_type gadget_type = {
751 .name = "gadget",
752};
753
749/** 754/**
750 * gether_setup - initialize one ethernet-over-usb link 755 * gether_setup - initialize one ethernet-over-usb link
751 * @g: gadget to associated with these links 756 * @g: gadget to associated with these links
@@ -808,6 +813,7 @@ int __init gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN])
808 813
809 dev->gadget = g; 814 dev->gadget = g;
810 SET_NETDEV_DEV(net, &g->dev); 815 SET_NETDEV_DEV(net, &g->dev);
816 SET_NETDEV_DEVTYPE(net, &gadget_type);
811 817
812 status = register_netdev(net); 818 status = register_netdev(net);
813 if (status < 0) { 819 if (status < 0) {
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 91b39ffdf6ea..3c8c0c9f9d72 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -93,13 +93,6 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
93 if (!gadget_supports_altsettings(gadget)) 93 if (!gadget_supports_altsettings(gadget))
94 return false; 94 return false;
95 95
96 /* SA1100 can do ECM, *without* status endpoint ... but we'll
97 * only use it in non-ECM mode for backwards compatibility
98 * (and since we currently require a status endpoint)
99 */
100 if (gadget_is_sa1100(gadget))
101 return false;
102
103 /* Everything else is *presumably* fine ... but this is a bit 96 /* Everything else is *presumably* fine ... but this is a bit
104 * chancy, so be **CERTAIN** there are no hardware issues with 97 * chancy, so be **CERTAIN** there are no hardware issues with
105 * your controller. Add it above if it can't handle CDC. 98 * your controller. Add it above if it can't handle CDC.
@@ -112,7 +105,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
112int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 105int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
113int eem_bind_config(struct usb_configuration *c); 106int eem_bind_config(struct usb_configuration *c);
114 107
115#ifdef CONFIG_USB_ETH_RNDIS 108#ifdef USB_ETH_RNDIS
116 109
117int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 110int rndis_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]);
118 111
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index adf8260c3a6a..16bdf77f582a 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/tty.h> 24#include <linux/tty.h>
25#include <linux/tty_flip.h> 25#include <linux/tty_flip.h>
26#include <linux/slab.h>
26 27
27#include "u_serial.h" 28#include "u_serial.h"
28 29
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 2d772401b7ad..807280d069f9 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -50,6 +50,7 @@
50/* #define VERBOSE_DEBUG */ 50/* #define VERBOSE_DEBUG */
51 51
52#include <linux/kernel.h> 52#include <linux/kernel.h>
53#include <linux/slab.h>
53#include <linux/utsname.h> 54#include <linux/utsname.h>
54#include <linux/device.h> 55#include <linux/device.h>
55 56
@@ -297,12 +298,10 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
297 */ 298 */
298 if (loopdefault) { 299 if (loopdefault) {
299 loopback_add(cdev, autoresume != 0); 300 loopback_add(cdev, autoresume != 0);
300 if (!gadget_is_sh(gadget)) 301 sourcesink_add(cdev, autoresume != 0);
301 sourcesink_add(cdev, autoresume != 0);
302 } else { 302 } else {
303 sourcesink_add(cdev, autoresume != 0); 303 sourcesink_add(cdev, autoresume != 0);
304 if (!gadget_is_sh(gadget)) 304 loopback_add(cdev, autoresume != 0);
305 loopback_add(cdev, autoresume != 0);
306 } 305 }
307 306
308 gcnum = usb_gadget_controller_number(gadget); 307 gcnum = usb_gadget_controller_number(gadget);
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 9b43b226817f..8d3df0397de3 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -90,14 +90,25 @@ config USB_EHCI_TT_NEWSCHED
90 90
91config USB_EHCI_BIG_ENDIAN_MMIO 91config USB_EHCI_BIG_ENDIAN_MMIO
92 bool 92 bool
93 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX) 93 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX)
94 default y 94 default y
95 95
96config USB_EHCI_BIG_ENDIAN_DESC 96config USB_EHCI_BIG_ENDIAN_DESC
97 bool 97 bool
98 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX) 98 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX)
99 default y 99 default y
100 100
101config XPS_USB_HCD_XILINX
102 bool "Use Xilinx usb host EHCI controller core"
103 depends on USB_EHCI_HCD && (PPC32 || MICROBLAZE)
104 select USB_EHCI_BIG_ENDIAN_DESC
105 select USB_EHCI_BIG_ENDIAN_MMIO
106 ---help---
107 Xilinx xps USB host controller core is EHCI compilant and has
108 transaction translator built-in. It can be configured to either
109 support both high speed and full speed devices, or high speed
110 devices only.
111
101config USB_EHCI_FSL 112config USB_EHCI_FSL
102 bool "Support for Freescale on-chip EHCI USB controller" 113 bool "Support for Freescale on-chip EHCI USB controller"
103 depends on USB_EHCI_HCD && FSL_SOC 114 depends on USB_EHCI_HCD && FSL_SOC
@@ -105,6 +116,13 @@ config USB_EHCI_FSL
105 ---help--- 116 ---help---
106 Variation of ARC USB block used in some Freescale chips. 117 Variation of ARC USB block used in some Freescale chips.
107 118
119config USB_EHCI_MXC
120 bool "Support for Freescale on-chip EHCI USB controller"
121 depends on USB_EHCI_HCD && ARCH_MXC
122 select USB_EHCI_ROOT_HUB_TT
123 ---help---
124 Variation of ARC USB block used in some Freescale chips.
125
108config USB_EHCI_HCD_PPC_OF 126config USB_EHCI_HCD_PPC_OF
109 bool "EHCI support for PPC USB controller on OF platform bus" 127 bool "EHCI support for PPC USB controller on OF platform bus"
110 depends on USB_EHCI_HCD && PPC_OF 128 depends on USB_EHCI_HCD && PPC_OF
@@ -381,3 +399,14 @@ config USB_HWA_HCD
381 399
382 To compile this driver a module, choose M here: the module 400 To compile this driver a module, choose M here: the module
383 will be called "hwa-hc". 401 will be called "hwa-hc".
402
403config USB_IMX21_HCD
404 tristate "iMX21 HCD support"
405 depends on USB && ARM && MACH_MX21
406 help
407 This driver enables support for the on-chip USB host in the
408 iMX21 processor.
409
410 To compile this driver as a module, choose M here: the
411 module will be called "imx21-hcd".
412
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index f58b2494c44a..b6315aa47f7a 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -12,7 +12,7 @@ fhci-objs := fhci-hcd.o fhci-hub.o fhci-q.o fhci-mem.o \
12ifeq ($(CONFIG_FHCI_DEBUG),y) 12ifeq ($(CONFIG_FHCI_DEBUG),y)
13fhci-objs += fhci-dbg.o 13fhci-objs += fhci-dbg.o
14endif 14endif
15xhci-objs := xhci-hcd.o xhci-mem.o xhci-pci.o xhci-ring.o xhci-hub.o xhci-dbg.o 15xhci-hcd-objs := xhci.o xhci-mem.o xhci-pci.o xhci-ring.o xhci-hub.o xhci-dbg.o
16 16
17obj-$(CONFIG_USB_WHCI_HCD) += whci/ 17obj-$(CONFIG_USB_WHCI_HCD) += whci/
18 18
@@ -25,10 +25,12 @@ obj-$(CONFIG_USB_ISP1362_HCD) += isp1362-hcd.o
25obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o 25obj-$(CONFIG_USB_OHCI_HCD) += ohci-hcd.o
26obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o 26obj-$(CONFIG_USB_UHCI_HCD) += uhci-hcd.o
27obj-$(CONFIG_USB_FHCI_HCD) += fhci.o 27obj-$(CONFIG_USB_FHCI_HCD) += fhci.o
28obj-$(CONFIG_USB_XHCI_HCD) += xhci.o 28obj-$(CONFIG_USB_XHCI_HCD) += xhci-hcd.o
29obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o 29obj-$(CONFIG_USB_SL811_HCD) += sl811-hcd.o
30obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o 30obj-$(CONFIG_USB_SL811_CS) += sl811_cs.o
31obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o 31obj-$(CONFIG_USB_U132_HCD) += u132-hcd.o
32obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o 32obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
33obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o 33obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
34obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o 34obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
35obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
36
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 87c1b7c34c0e..51bd0edf544f 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -149,7 +149,7 @@ static int __init ehci_atmel_drv_probe(struct platform_device *pdev)
149 goto fail_request_resource; 149 goto fail_request_resource;
150 } 150 }
151 hcd->rsrc_start = res->start; 151 hcd->rsrc_start = res->start;
152 hcd->rsrc_len = res->end - res->start + 1; 152 hcd->rsrc_len = resource_size(res);
153 153
154 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 154 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
155 driver->description)) { 155 driver->description)) {
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index ed77be76d6bb..e3a74e75e822 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -121,6 +121,7 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
121{ 121{
122 struct usb_hcd *hcd; 122 struct usb_hcd *hcd;
123 struct ehci_hcd *ehci; 123 struct ehci_hcd *ehci;
124 struct resource *res;
124 int ret; 125 int ret;
125 126
126 if (usb_disabled()) 127 if (usb_disabled())
@@ -144,8 +145,9 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
144 if (!hcd) 145 if (!hcd)
145 return -ENOMEM; 146 return -ENOMEM;
146 147
147 hcd->rsrc_start = pdev->resource[0].start; 148 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
148 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; 149 hcd->rsrc_start = res->start;
150 hcd->rsrc_len = resource_size(res);
149 151
150 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 152 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
151 pr_debug("request_mem_region failed"); 153 pr_debug("request_mem_region failed");
@@ -297,7 +299,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
297 return 0; 299 return 0;
298} 300}
299 301
300static struct dev_pm_ops au1xxx_ehci_pmops = { 302static const struct dev_pm_ops au1xxx_ehci_pmops = {
301 .suspend = ehci_hcd_au1xxx_drv_suspend, 303 .suspend = ehci_hcd_au1xxx_drv_suspend,
302 .resume = ehci_hcd_au1xxx_drv_resume, 304 .resume = ehci_hcd_au1xxx_drv_resume,
303}; 305};
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 991174937db3..0e26aa13f158 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 MontaVista Software 2 * Copyright 2005-2009 MontaVista Software, Inc.
3 * Copyright 2008 Freescale Semiconductor, Inc.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the 6 * under the terms of the GNU General Public License as published by the
@@ -17,17 +18,20 @@
17 * 18 *
18 * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided 19 * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided
19 * by Hunter Wu. 20 * by Hunter Wu.
21 * Power Management support by Dave Liu <daveliu@freescale.com>,
22 * Jerry Huang <Chang-Ming.Huang@freescale.com> and
23 * Anton Vorontsov <avorontsov@ru.mvista.com>.
20 */ 24 */
21 25
26#include <linux/kernel.h>
27#include <linux/types.h>
28#include <linux/delay.h>
29#include <linux/pm.h>
22#include <linux/platform_device.h> 30#include <linux/platform_device.h>
23#include <linux/fsl_devices.h> 31#include <linux/fsl_devices.h>
24 32
25#include "ehci-fsl.h" 33#include "ehci-fsl.h"
26 34
27/* FIXME: Power Management is un-ported so temporarily disable it */
28#undef CONFIG_PM
29
30
31/* configure so an HC device and id are always provided */ 35/* configure so an HC device and id are always provided */
32/* always called with process context; sleeping is OK */ 36/* always called with process context; sleeping is OK */
33 37
@@ -40,8 +44,8 @@
40 * Allocates basic resources for this USB host controller. 44 * Allocates basic resources for this USB host controller.
41 * 45 *
42 */ 46 */
43int usb_hcd_fsl_probe(const struct hc_driver *driver, 47static int usb_hcd_fsl_probe(const struct hc_driver *driver,
44 struct platform_device *pdev) 48 struct platform_device *pdev)
45{ 49{
46 struct fsl_usb2_platform_data *pdata; 50 struct fsl_usb2_platform_data *pdata;
47 struct usb_hcd *hcd; 51 struct usb_hcd *hcd;
@@ -147,7 +151,8 @@ int usb_hcd_fsl_probe(const struct hc_driver *driver,
147 * Reverses the effect of usb_hcd_fsl_probe(). 151 * Reverses the effect of usb_hcd_fsl_probe().
148 * 152 *
149 */ 153 */
150void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev) 154static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
155 struct platform_device *pdev)
151{ 156{
152 usb_remove_hcd(hcd); 157 usb_remove_hcd(hcd);
153 iounmap(hcd->regs); 158 iounmap(hcd->regs);
@@ -284,10 +289,81 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
284 return retval; 289 return retval;
285} 290}
286 291
292struct ehci_fsl {
293 struct ehci_hcd ehci;
294
295#ifdef CONFIG_PM
296 /* Saved USB PHY settings, need to restore after deep sleep. */
297 u32 usb_ctrl;
298#endif
299};
300
301#ifdef CONFIG_PM
302
303static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
304{
305 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
306
307 return container_of(ehci, struct ehci_fsl, ehci);
308}
309
310static int ehci_fsl_drv_suspend(struct device *dev)
311{
312 struct usb_hcd *hcd = dev_get_drvdata(dev);
313 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
314 void __iomem *non_ehci = hcd->regs;
315
316 if (!fsl_deep_sleep())
317 return 0;
318
319 ehci_fsl->usb_ctrl = in_be32(non_ehci + FSL_SOC_USB_CTRL);
320 return 0;
321}
322
323static int ehci_fsl_drv_resume(struct device *dev)
324{
325 struct usb_hcd *hcd = dev_get_drvdata(dev);
326 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
327 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
328 void __iomem *non_ehci = hcd->regs;
329
330 if (!fsl_deep_sleep())
331 return 0;
332
333 usb_root_hub_lost_power(hcd->self.root_hub);
334
335 /* Restore USB PHY settings and enable the controller. */
336 out_be32(non_ehci + FSL_SOC_USB_CTRL, ehci_fsl->usb_ctrl);
337
338 ehci_reset(ehci);
339 ehci_fsl_reinit(ehci);
340
341 return 0;
342}
343
344static int ehci_fsl_drv_restore(struct device *dev)
345{
346 struct usb_hcd *hcd = dev_get_drvdata(dev);
347
348 usb_root_hub_lost_power(hcd->self.root_hub);
349 return 0;
350}
351
352static struct dev_pm_ops ehci_fsl_pm_ops = {
353 .suspend = ehci_fsl_drv_suspend,
354 .resume = ehci_fsl_drv_resume,
355 .restore = ehci_fsl_drv_restore,
356};
357
358#define EHCI_FSL_PM_OPS (&ehci_fsl_pm_ops)
359#else
360#define EHCI_FSL_PM_OPS NULL
361#endif /* CONFIG_PM */
362
287static const struct hc_driver ehci_fsl_hc_driver = { 363static const struct hc_driver ehci_fsl_hc_driver = {
288 .description = hcd_name, 364 .description = hcd_name,
289 .product_desc = "Freescale On-Chip EHCI Host Controller", 365 .product_desc = "Freescale On-Chip EHCI Host Controller",
290 .hcd_priv_size = sizeof(struct ehci_hcd), 366 .hcd_priv_size = sizeof(struct ehci_fsl),
291 367
292 /* 368 /*
293 * generic hardware linkage 369 * generic hardware linkage
@@ -354,6 +430,7 @@ static struct platform_driver ehci_fsl_driver = {
354 .remove = ehci_fsl_drv_remove, 430 .remove = ehci_fsl_drv_remove,
355 .shutdown = usb_hcd_platform_shutdown, 431 .shutdown = usb_hcd_platform_shutdown,
356 .driver = { 432 .driver = {
357 .name = "fsl-ehci", 433 .name = "fsl-ehci",
434 .pm = EHCI_FSL_PM_OPS,
358 }, 435 },
359}; 436};
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index f5f5601701c9..13ead00aecd5 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -23,7 +23,6 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/slab.h>
27#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
28#include <linux/errno.h> 27#include <linux/errno.h>
29#include <linux/init.h> 28#include <linux/init.h>
@@ -35,6 +34,7 @@
35#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
36#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
37#include <linux/debugfs.h> 36#include <linux/debugfs.h>
37#include <linux/slab.h>
38 38
39#include "../core/hcd.h" 39#include "../core/hcd.h"
40 40
@@ -210,7 +210,7 @@ static int handshake_on_error_set_halt(struct ehci_hcd *ehci, void __iomem *ptr,
210 if (error) { 210 if (error) {
211 ehci_halt(ehci); 211 ehci_halt(ehci);
212 ehci_to_hcd(ehci)->state = HC_STATE_HALT; 212 ehci_to_hcd(ehci)->state = HC_STATE_HALT;
213 ehci_err(ehci, "force halt; handhake %p %08x %08x -> %d\n", 213 ehci_err(ehci, "force halt; handshake %p %08x %08x -> %d\n",
214 ptr, mask, done, error); 214 ptr, mask, done, error);
215 } 215 }
216 216
@@ -543,13 +543,14 @@ static int ehci_init(struct usb_hcd *hcd)
543 */ 543 */
544 ehci->periodic_size = DEFAULT_I_TDPS; 544 ehci->periodic_size = DEFAULT_I_TDPS;
545 INIT_LIST_HEAD(&ehci->cached_itd_list); 545 INIT_LIST_HEAD(&ehci->cached_itd_list);
546 INIT_LIST_HEAD(&ehci->cached_sitd_list);
546 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0) 547 if ((retval = ehci_mem_init(ehci, GFP_KERNEL)) < 0)
547 return retval; 548 return retval;
548 549
549 /* controllers may cache some of the periodic schedule ... */ 550 /* controllers may cache some of the periodic schedule ... */
550 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params); 551 hcc_params = ehci_readl(ehci, &ehci->caps->hcc_params);
551 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache 552 if (HCC_ISOC_CACHE(hcc_params)) // full frame cache
552 ehci->i_thresh = 8; 553 ehci->i_thresh = 2 + 8;
553 else // N microframes cached 554 else // N microframes cached
554 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params); 555 ehci->i_thresh = 2 + HCC_ISOC_THRES(hcc_params);
555 556
@@ -605,6 +606,8 @@ static int ehci_init(struct usb_hcd *hcd)
605 } 606 }
606 ehci->command = temp; 607 ehci->command = temp;
607 608
609 /* Accept arbitrarily long scatter-gather lists */
610 hcd->self.sg_tablesize = ~0;
608 return 0; 611 return 0;
609} 612}
610 613
@@ -785,9 +788,10 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
785 788
786 /* start 20 msec resume signaling from this port, 789 /* start 20 msec resume signaling from this port,
787 * and make khubd collect PORT_STAT_C_SUSPEND to 790 * and make khubd collect PORT_STAT_C_SUSPEND to
788 * stop that signaling. 791 * stop that signaling. Use 5 ms extra for safety,
792 * like usb_port_resume() does.
789 */ 793 */
790 ehci->reset_done [i] = jiffies + msecs_to_jiffies (20); 794 ehci->reset_done[i] = jiffies + msecs_to_jiffies(25);
791 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1); 795 ehci_dbg (ehci, "port %d remote wakeup\n", i + 1);
792 mod_timer(&hcd->rh_timer, ehci->reset_done[i]); 796 mod_timer(&hcd->rh_timer, ehci->reset_done[i]);
793 } 797 }
@@ -992,7 +996,7 @@ rescan:
992 /* endpoints can be iso streams. for now, we don't 996 /* endpoints can be iso streams. for now, we don't
993 * accelerate iso completions ... so spin a while. 997 * accelerate iso completions ... so spin a while.
994 */ 998 */
995 if (qh->hw->hw_info1 == 0) { 999 if (qh->hw == NULL) {
996 ehci_vdbg (ehci, "iso delay\n"); 1000 ehci_vdbg (ehci, "iso delay\n");
997 goto idle_timeout; 1001 goto idle_timeout;
998 } 1002 }
@@ -1105,11 +1109,21 @@ MODULE_LICENSE ("GPL");
1105#define PLATFORM_DRIVER ehci_fsl_driver 1109#define PLATFORM_DRIVER ehci_fsl_driver
1106#endif 1110#endif
1107 1111
1112#ifdef CONFIG_USB_EHCI_MXC
1113#include "ehci-mxc.c"
1114#define PLATFORM_DRIVER ehci_mxc_driver
1115#endif
1116
1108#ifdef CONFIG_SOC_AU1200 1117#ifdef CONFIG_SOC_AU1200
1109#include "ehci-au1xxx.c" 1118#include "ehci-au1xxx.c"
1110#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver 1119#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
1111#endif 1120#endif
1112 1121
1122#ifdef CONFIG_ARCH_OMAP3
1123#include "ehci-omap.c"
1124#define PLATFORM_DRIVER ehci_hcd_omap_driver
1125#endif
1126
1113#ifdef CONFIG_PPC_PS3 1127#ifdef CONFIG_PPC_PS3
1114#include "ehci-ps3.c" 1128#include "ehci-ps3.c"
1115#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver 1129#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
@@ -1120,6 +1134,11 @@ MODULE_LICENSE ("GPL");
1120#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver 1134#define OF_PLATFORM_DRIVER ehci_hcd_ppc_of_driver
1121#endif 1135#endif
1122 1136
1137#ifdef CONFIG_XPS_USB_HCD_XILINX
1138#include "ehci-xilinx-of.c"
1139#define OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
1140#endif
1141
1123#ifdef CONFIG_PLAT_ORION 1142#ifdef CONFIG_PLAT_ORION
1124#include "ehci-orion.c" 1143#include "ehci-orion.c"
1125#define PLATFORM_DRIVER ehci_orion_driver 1144#define PLATFORM_DRIVER ehci_orion_driver
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 1b6f1c0e5cee..c7178bcde67a 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -120,9 +120,26 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
120 del_timer_sync(&ehci->watchdog); 120 del_timer_sync(&ehci->watchdog);
121 del_timer_sync(&ehci->iaa_watchdog); 121 del_timer_sync(&ehci->iaa_watchdog);
122 122
123 port = HCS_N_PORTS (ehci->hcs_params);
124 spin_lock_irq (&ehci->lock); 123 spin_lock_irq (&ehci->lock);
125 124
125 /* Once the controller is stopped, port resumes that are already
126 * in progress won't complete. Hence if remote wakeup is enabled
127 * for the root hub and any ports are in the middle of a resume or
128 * remote wakeup, we must fail the suspend.
129 */
130 if (hcd->self.root_hub->do_remote_wakeup) {
131 port = HCS_N_PORTS(ehci->hcs_params);
132 while (port--) {
133 if (ehci->reset_done[port] != 0) {
134 spin_unlock_irq(&ehci->lock);
135 ehci_dbg(ehci, "suspend failed because "
136 "port %d is resuming\n",
137 port + 1);
138 return -EBUSY;
139 }
140 }
141 }
142
126 /* stop schedules, clean any completed work */ 143 /* stop schedules, clean any completed work */
127 if (HC_IS_RUNNING(hcd->state)) { 144 if (HC_IS_RUNNING(hcd->state)) {
128 ehci_quiesce (ehci); 145 ehci_quiesce (ehci);
@@ -138,6 +155,7 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
138 */ 155 */
139 ehci->bus_suspended = 0; 156 ehci->bus_suspended = 0;
140 ehci->owned_ports = 0; 157 ehci->owned_ports = 0;
158 port = HCS_N_PORTS(ehci->hcs_params);
141 while (port--) { 159 while (port--) {
142 u32 __iomem *reg = &ehci->regs->port_status [port]; 160 u32 __iomem *reg = &ehci->regs->port_status [port];
143 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS; 161 u32 t1 = ehci_readl(ehci, reg) & ~PORT_RWC_BITS;
@@ -178,7 +196,9 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
178 if (hostpc_reg) { 196 if (hostpc_reg) {
179 u32 t3; 197 u32 t3;
180 198
199 spin_unlock_irq(&ehci->lock);
181 msleep(5);/* 5ms for HCD enter low pwr mode */ 200 msleep(5);/* 5ms for HCD enter low pwr mode */
201 spin_lock_irq(&ehci->lock);
182 t3 = ehci_readl(ehci, hostpc_reg); 202 t3 = ehci_readl(ehci, hostpc_reg);
183 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg); 203 ehci_writel(ehci, t3 | HOSTPC_PHCD, hostpc_reg);
184 t3 = ehci_readl(ehci, hostpc_reg); 204 t3 = ehci_readl(ehci, hostpc_reg);
@@ -236,7 +256,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
236 } 256 }
237 257
238 if (unlikely(ehci->debug)) { 258 if (unlikely(ehci->debug)) {
239 if (ehci->debug && !dbgp_reset_prep()) 259 if (!dbgp_reset_prep())
240 ehci->debug = NULL; 260 ehci->debug = NULL;
241 else 261 else
242 dbgp_external_startup(); 262 dbgp_external_startup();
@@ -781,7 +801,7 @@ static int ehci_hub_control (
781 * this bit; seems too long to spin routinely... 801 * this bit; seems too long to spin routinely...
782 */ 802 */
783 retval = handshake(ehci, status_reg, 803 retval = handshake(ehci, status_reg,
784 PORT_RESET, 0, 750); 804 PORT_RESET, 0, 1000);
785 if (retval != 0) { 805 if (retval != 0) {
786 ehci_err (ehci, "port %d reset error %d\n", 806 ehci_err (ehci, "port %d reset error %d\n",
787 wIndex + 1, retval); 807 wIndex + 1, retval);
@@ -886,17 +906,18 @@ static int ehci_hub_control (
886 if ((temp & PORT_PE) == 0 906 if ((temp & PORT_PE) == 0
887 || (temp & PORT_RESET) != 0) 907 || (temp & PORT_RESET) != 0)
888 goto error; 908 goto error;
889 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 909
890 /* After above check the port must be connected. 910 /* After above check the port must be connected.
891 * Set appropriate bit thus could put phy into low power 911 * Set appropriate bit thus could put phy into low power
892 * mode if we have hostpc feature 912 * mode if we have hostpc feature
893 */ 913 */
914 temp &= ~PORT_WKCONN_E;
915 temp |= PORT_WKDISC_E | PORT_WKOC_E;
916 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
894 if (hostpc_reg) { 917 if (hostpc_reg) {
895 temp &= ~PORT_WKCONN_E; 918 spin_unlock_irqrestore(&ehci->lock, flags);
896 temp |= (PORT_WKDISC_E | PORT_WKOC_E);
897 ehci_writel(ehci, temp | PORT_SUSPEND,
898 status_reg);
899 msleep(5);/* 5ms for HCD enter low pwr mode */ 919 msleep(5);/* 5ms for HCD enter low pwr mode */
920 spin_lock_irqsave(&ehci->lock, flags);
900 temp1 = ehci_readl(ehci, hostpc_reg); 921 temp1 = ehci_readl(ehci, hostpc_reg);
901 ehci_writel(ehci, temp1 | HOSTPC_PHCD, 922 ehci_writel(ehci, temp1 | HOSTPC_PHCD,
902 hostpc_reg); 923 hostpc_reg);
diff --git a/drivers/usb/host/ehci-mem.c b/drivers/usb/host/ehci-mem.c
index aeda96e0af67..1f3f01eacaf0 100644
--- a/drivers/usb/host/ehci-mem.c
+++ b/drivers/usb/host/ehci-mem.c
@@ -136,7 +136,7 @@ static inline void qh_put (struct ehci_qh *qh)
136 136
137static void ehci_mem_cleanup (struct ehci_hcd *ehci) 137static void ehci_mem_cleanup (struct ehci_hcd *ehci)
138{ 138{
139 free_cached_itd_list(ehci); 139 free_cached_lists(ehci);
140 if (ehci->async) 140 if (ehci->async)
141 qh_put (ehci->async); 141 qh_put (ehci->async);
142 ehci->async = NULL; 142 ehci->async = NULL;
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
new file mode 100644
index 000000000000..ead59f42e69b
--- /dev/null
+++ b/drivers/usb/host/ehci-mxc.c
@@ -0,0 +1,296 @@
1/*
2 * Copyright (c) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
3 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/platform_device.h>
21#include <linux/clk.h>
22#include <linux/delay.h>
23#include <linux/usb/otg.h>
24#include <linux/slab.h>
25
26#include <mach/mxc_ehci.h>
27
28#define ULPI_VIEWPORT_OFFSET 0x170
29#define PORTSC_OFFSET 0x184
30#define USBMODE_OFFSET 0x1a8
31#define USBMODE_CM_HOST 3
32
33struct ehci_mxc_priv {
34 struct clk *usbclk, *ahbclk;
35 struct usb_hcd *hcd;
36};
37
38/* called during probe() after chip reset completes */
39static int ehci_mxc_setup(struct usb_hcd *hcd)
40{
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
43
44 /* EHCI registers start at offset 0x100 */
45 ehci->caps = hcd->regs + 0x100;
46 ehci->regs = hcd->regs + 0x100 +
47 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
48 dbg_hcs_params(ehci, "reset");
49 dbg_hcc_params(ehci, "reset");
50
51 /* cache this readonly data; minimize chip reads */
52 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
53
54 retval = ehci_halt(ehci);
55 if (retval)
56 return retval;
57
58 /* data structure init */
59 retval = ehci_init(hcd);
60 if (retval)
61 return retval;
62
63 hcd->has_tt = 1;
64
65 ehci->sbrn = 0x20;
66
67 ehci_reset(ehci);
68
69 ehci_port_power(ehci, 0);
70 return 0;
71}
72
73static const struct hc_driver ehci_mxc_hc_driver = {
74 .description = hcd_name,
75 .product_desc = "Freescale On-Chip EHCI Host Controller",
76 .hcd_priv_size = sizeof(struct ehci_hcd),
77
78 /*
79 * generic hardware linkage
80 */
81 .irq = ehci_irq,
82 .flags = HCD_USB2 | HCD_MEMORY,
83
84 /*
85 * basic lifecycle operations
86 */
87 .reset = ehci_mxc_setup,
88 .start = ehci_run,
89 .stop = ehci_stop,
90 .shutdown = ehci_shutdown,
91
92 /*
93 * managing i/o requests and associated device resources
94 */
95 .urb_enqueue = ehci_urb_enqueue,
96 .urb_dequeue = ehci_urb_dequeue,
97 .endpoint_disable = ehci_endpoint_disable,
98
99 /*
100 * scheduling support
101 */
102 .get_frame_number = ehci_get_frame,
103
104 /*
105 * root hub support
106 */
107 .hub_status_data = ehci_hub_status_data,
108 .hub_control = ehci_hub_control,
109 .bus_suspend = ehci_bus_suspend,
110 .bus_resume = ehci_bus_resume,
111 .relinquish_port = ehci_relinquish_port,
112 .port_handed_over = ehci_port_handed_over,
113};
114
115static int ehci_mxc_drv_probe(struct platform_device *pdev)
116{
117 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
118 struct usb_hcd *hcd;
119 struct resource *res;
120 int irq, ret, temp;
121 struct ehci_mxc_priv *priv;
122 struct device *dev = &pdev->dev;
123
124 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
125
126 if (!pdata) {
127 dev_err(dev, "No platform data given, bailing out.\n");
128 return -EINVAL;
129 }
130
131 irq = platform_get_irq(pdev, 0);
132
133 hcd = usb_create_hcd(&ehci_mxc_hc_driver, dev, dev_name(dev));
134 if (!hcd)
135 return -ENOMEM;
136
137 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
138 if (!priv) {
139 ret = -ENOMEM;
140 goto err_alloc;
141 }
142
143 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
144 if (!res) {
145 dev_err(dev, "Found HC with no register addr. Check setup!\n");
146 ret = -ENODEV;
147 goto err_get_resource;
148 }
149
150 hcd->rsrc_start = res->start;
151 hcd->rsrc_len = resource_size(res);
152
153 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
154 dev_dbg(dev, "controller already in use\n");
155 ret = -EBUSY;
156 goto err_request_mem;
157 }
158
159 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
160 if (!hcd->regs) {
161 dev_err(dev, "error mapping memory\n");
162 ret = -EFAULT;
163 goto err_ioremap;
164 }
165
166 /* call platform specific init function */
167 if (pdata->init) {
168 ret = pdata->init(pdev);
169 if (ret) {
170 dev_err(dev, "platform init failed\n");
171 goto err_init;
172 }
173 /* platforms need some time to settle changed IO settings */
174 mdelay(10);
175 }
176
177 /* enable clocks */
178 priv->usbclk = clk_get(dev, "usb");
179 if (IS_ERR(priv->usbclk)) {
180 ret = PTR_ERR(priv->usbclk);
181 goto err_clk;
182 }
183 clk_enable(priv->usbclk);
184
185 if (!cpu_is_mx35()) {
186 priv->ahbclk = clk_get(dev, "usb_ahb");
187 if (IS_ERR(priv->ahbclk)) {
188 ret = PTR_ERR(priv->ahbclk);
189 goto err_clk_ahb;
190 }
191 clk_enable(priv->ahbclk);
192 }
193
194 /* set USBMODE to host mode */
195 temp = readl(hcd->regs + USBMODE_OFFSET);
196 writel(temp | USBMODE_CM_HOST, hcd->regs + USBMODE_OFFSET);
197
198 /* set up the PORTSCx register */
199 writel(pdata->portsc, hcd->regs + PORTSC_OFFSET);
200 mdelay(10);
201
202 /* setup USBCONTROL. */
203 ret = mxc_set_usbcontrol(pdev->id, pdata->flags);
204 if (ret < 0)
205 goto err_init;
206
207 /* Initialize the transceiver */
208 if (pdata->otg) {
209 pdata->otg->io_priv = hcd->regs + ULPI_VIEWPORT_OFFSET;
210 if (otg_init(pdata->otg) != 0)
211 dev_err(dev, "unable to init transceiver\n");
212 else if (otg_set_vbus(pdata->otg, 1) != 0)
213 dev_err(dev, "unable to enable vbus on transceiver\n");
214 }
215
216 priv->hcd = hcd;
217 platform_set_drvdata(pdev, priv);
218
219 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
220 if (ret)
221 goto err_add;
222
223 return 0;
224
225err_add:
226 if (pdata && pdata->exit)
227 pdata->exit(pdev);
228err_init:
229 if (priv->ahbclk) {
230 clk_disable(priv->ahbclk);
231 clk_put(priv->ahbclk);
232 }
233err_clk_ahb:
234 clk_disable(priv->usbclk);
235 clk_put(priv->usbclk);
236err_clk:
237 iounmap(hcd->regs);
238err_ioremap:
239 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
240err_request_mem:
241err_get_resource:
242 kfree(priv);
243err_alloc:
244 usb_put_hcd(hcd);
245 return ret;
246}
247
248static int __exit ehci_mxc_drv_remove(struct platform_device *pdev)
249{
250 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
251 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
252 struct usb_hcd *hcd = priv->hcd;
253
254 if (pdata && pdata->exit)
255 pdata->exit(pdev);
256
257 if (pdata->otg)
258 otg_shutdown(pdata->otg);
259
260 usb_remove_hcd(hcd);
261 iounmap(hcd->regs);
262 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
263 usb_put_hcd(hcd);
264 platform_set_drvdata(pdev, NULL);
265
266 clk_disable(priv->usbclk);
267 clk_put(priv->usbclk);
268 if (priv->ahbclk) {
269 clk_disable(priv->ahbclk);
270 clk_put(priv->ahbclk);
271 }
272
273 kfree(priv);
274
275 return 0;
276}
277
278static void ehci_mxc_drv_shutdown(struct platform_device *pdev)
279{
280 struct ehci_mxc_priv *priv = platform_get_drvdata(pdev);
281 struct usb_hcd *hcd = priv->hcd;
282
283 if (hcd->driver->shutdown)
284 hcd->driver->shutdown(hcd);
285}
286
287MODULE_ALIAS("platform:mxc-ehci");
288
289static struct platform_driver ehci_mxc_driver = {
290 .probe = ehci_mxc_drv_probe,
291 .remove = __exit_p(ehci_mxc_drv_remove),
292 .shutdown = ehci_mxc_drv_shutdown,
293 .driver = {
294 .name = "mxc-ehci",
295 },
296};
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
new file mode 100644
index 000000000000..40a858335035
--- /dev/null
+++ b/drivers/usb/host/ehci-omap.c
@@ -0,0 +1,794 @@
1/*
2 * ehci-omap.c - driver for USBHOST on OMAP 34xx processor
3 *
4 * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller
5 * Tested on OMAP3430 ES2.0 SDP
6 *
7 * Copyright (C) 2007-2008 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 *
10 * Copyright (C) 2009 Nokia Corporation
11 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
12 *
13 * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 * TODO (last updated Feb 12, 2010):
30 * - add kernel-doc
31 * - enable AUTOIDLE
32 * - add suspend/resume
33 * - move workarounds to board-files
34 */
35
36#include <linux/platform_device.h>
37#include <linux/clk.h>
38#include <linux/gpio.h>
39#include <linux/regulator/consumer.h>
40#include <linux/slab.h>
41#include <plat/usb.h>
42
43/*
44 * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES
45 * Use ehci_omap_readl()/ehci_omap_writel() functions
46 */
47
48/* TLL Register Set */
49#define OMAP_USBTLL_REVISION (0x00)
50#define OMAP_USBTLL_SYSCONFIG (0x10)
51#define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8)
52#define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3)
53#define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2)
54#define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1)
55#define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0)
56
57#define OMAP_USBTLL_SYSSTATUS (0x14)
58#define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0)
59
60#define OMAP_USBTLL_IRQSTATUS (0x18)
61#define OMAP_USBTLL_IRQENABLE (0x1C)
62
63#define OMAP_TLL_SHARED_CONF (0x30)
64#define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6)
65#define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5)
66#define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2)
67#define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1)
68#define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0)
69
70#define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num)
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_CHANEN (1 << 0)
76
77#define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num)
78#define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num)
79#define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num)
80#define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num)
81#define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num)
82#define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num)
83#define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num)
84#define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num)
85#define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num)
86
87#define OMAP_TLL_CHANNEL_COUNT 3
88#define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1)
89#define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2)
90#define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4)
91
92/* UHH Register Set */
93#define OMAP_UHH_REVISION (0x00)
94#define OMAP_UHH_SYSCONFIG (0x10)
95#define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12)
96#define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8)
97#define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3)
98#define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2)
99#define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1)
100#define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0)
101
102#define OMAP_UHH_SYSSTATUS (0x14)
103#define OMAP_UHH_HOSTCONFIG (0x40)
104#define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0)
105#define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0)
106#define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11)
107#define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12)
108#define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2)
109#define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3)
110#define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4)
111#define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5)
112#define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8)
113#define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9)
114#define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10)
115
116#define OMAP_UHH_DEBUG_CSR (0x44)
117
118/* EHCI Register Set */
119#define EHCI_INSNREG05_ULPI (0xA4)
120#define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31
121#define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24
122#define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22
123#define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16
124#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
125#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
126
127/*-------------------------------------------------------------------------*/
128
129static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val)
130{
131 __raw_writel(val, base + reg);
132}
133
134static inline u32 ehci_omap_readl(void __iomem *base, u32 reg)
135{
136 return __raw_readl(base + reg);
137}
138
139static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val)
140{
141 __raw_writeb(val, base + reg);
142}
143
144static inline u8 ehci_omap_readb(void __iomem *base, u8 reg)
145{
146 return __raw_readb(base + reg);
147}
148
149/*-------------------------------------------------------------------------*/
150
151struct ehci_hcd_omap {
152 struct ehci_hcd *ehci;
153 struct device *dev;
154
155 struct clk *usbhost_ick;
156 struct clk *usbhost2_120m_fck;
157 struct clk *usbhost1_48m_fck;
158 struct clk *usbtll_fck;
159 struct clk *usbtll_ick;
160
161 /* FIXME the following two workarounds are
162 * board specific not silicon-specific so these
163 * should be moved to board-file instead.
164 *
165 * Maybe someone from TI will know better which
166 * board is affected and needs the workarounds
167 * to be applied
168 */
169
170 /* gpio for resetting phy */
171 int reset_gpio_port[OMAP3_HS_USB_PORTS];
172
173 /* phy reset workaround */
174 int phy_reset;
175
176 /* desired phy_mode: TLL, PHY */
177 enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS];
178
179 void __iomem *uhh_base;
180 void __iomem *tll_base;
181 void __iomem *ehci_base;
182
183 /* Regulators for USB PHYs.
184 * Each PHY can have a seperate regulator.
185 */
186 struct regulator *regulator[OMAP3_HS_USB_PORTS];
187};
188
189/*-------------------------------------------------------------------------*/
190
191static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask)
192{
193 unsigned reg;
194 int i;
195
196 /* Program the 3 TLL channels upfront */
197 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
198 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
199
200 /* Disable AutoIdle, BitStuffing and use SDR Mode */
201 reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE
202 | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
203 | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE);
204 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
205 }
206
207 /* Program Common TLL register */
208 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF);
209 reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON
210 | OMAP_TLL_SHARED_CONF_USB_DIVRATION
211 | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN);
212 reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN;
213
214 ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg);
215
216 /* Enable channels now */
217 for (i = 0; i < OMAP_TLL_CHANNEL_COUNT; i++) {
218 reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i));
219
220 /* Enable only the reg that is needed */
221 if (!(tll_channel_mask & 1<<i))
222 continue;
223
224 reg |= OMAP_TLL_CHANNEL_CONF_CHANEN;
225 ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg);
226
227 ehci_omap_writeb(omap->tll_base,
228 OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe);
229 dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n",
230 i+1, ehci_omap_readb(omap->tll_base,
231 OMAP_TLL_ULPI_SCRATCH_REGISTER(i)));
232 }
233}
234
235/*-------------------------------------------------------------------------*/
236
237/* omap_start_ehc
238 * - Start the TI USBHOST controller
239 */
240static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
241{
242 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
243 u8 tll_ch_mask = 0;
244 unsigned reg = 0;
245 int ret = 0;
246
247 dev_dbg(omap->dev, "starting TI EHCI USB Controller\n");
248
249 /* Enable Clocks for USBHOST */
250 omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick");
251 if (IS_ERR(omap->usbhost_ick)) {
252 ret = PTR_ERR(omap->usbhost_ick);
253 goto err_host_ick;
254 }
255 clk_enable(omap->usbhost_ick);
256
257 omap->usbhost2_120m_fck = clk_get(omap->dev, "usbhost_120m_fck");
258 if (IS_ERR(omap->usbhost2_120m_fck)) {
259 ret = PTR_ERR(omap->usbhost2_120m_fck);
260 goto err_host_120m_fck;
261 }
262 clk_enable(omap->usbhost2_120m_fck);
263
264 omap->usbhost1_48m_fck = clk_get(omap->dev, "usbhost_48m_fck");
265 if (IS_ERR(omap->usbhost1_48m_fck)) {
266 ret = PTR_ERR(omap->usbhost1_48m_fck);
267 goto err_host_48m_fck;
268 }
269 clk_enable(omap->usbhost1_48m_fck);
270
271 if (omap->phy_reset) {
272 /* Refer: ISSUE1 */
273 if (gpio_is_valid(omap->reset_gpio_port[0])) {
274 gpio_request(omap->reset_gpio_port[0],
275 "USB1 PHY reset");
276 gpio_direction_output(omap->reset_gpio_port[0], 0);
277 }
278
279 if (gpio_is_valid(omap->reset_gpio_port[1])) {
280 gpio_request(omap->reset_gpio_port[1],
281 "USB2 PHY reset");
282 gpio_direction_output(omap->reset_gpio_port[1], 0);
283 }
284
285 /* Hold the PHY in RESET for enough time till DIR is high */
286 udelay(10);
287 }
288
289 /* Configure TLL for 60Mhz clk for ULPI */
290 omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck");
291 if (IS_ERR(omap->usbtll_fck)) {
292 ret = PTR_ERR(omap->usbtll_fck);
293 goto err_tll_fck;
294 }
295 clk_enable(omap->usbtll_fck);
296
297 omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick");
298 if (IS_ERR(omap->usbtll_ick)) {
299 ret = PTR_ERR(omap->usbtll_ick);
300 goto err_tll_ick;
301 }
302 clk_enable(omap->usbtll_ick);
303
304 /* perform TLL soft reset, and wait until reset is complete */
305 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
306 OMAP_USBTLL_SYSCONFIG_SOFTRESET);
307
308 /* Wait for TLL reset to complete */
309 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
310 & OMAP_USBTLL_SYSSTATUS_RESETDONE)) {
311 cpu_relax();
312
313 if (time_after(jiffies, timeout)) {
314 dev_dbg(omap->dev, "operation timed out\n");
315 ret = -EINVAL;
316 goto err_sys_status;
317 }
318 }
319
320 dev_dbg(omap->dev, "TLL RESET DONE\n");
321
322 /* (1<<3) = no idle mode only for initial debugging */
323 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG,
324 OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
325 OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
326 OMAP_USBTLL_SYSCONFIG_CACTIVITY);
327
328
329 /* Put UHH in NoIdle/NoStandby mode */
330 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG);
331 reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP
332 | OMAP_UHH_SYSCONFIG_SIDLEMODE
333 | OMAP_UHH_SYSCONFIG_CACTIVITY
334 | OMAP_UHH_SYSCONFIG_MIDLEMODE);
335 reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE;
336
337 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg);
338
339 reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG);
340
341 /* setup ULPI bypass and burst configurations */
342 reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
343 | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
344 | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN);
345 reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN;
346
347 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN)
348 reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS;
349 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN)
350 reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS;
351 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN)
352 reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS;
353
354 /* Bypass the TLL module for PHY mode operation */
355 if (omap_rev() <= OMAP3430_REV_ES2_1) {
356 dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1 \n");
357 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) ||
358 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) ||
359 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY))
360 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
361 else
362 reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS;
363 } else {
364 dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n");
365 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY)
366 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
367 else if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
368 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS;
369
370 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY)
371 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
372 else if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
373 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS;
374
375 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_PHY)
376 reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
377 else if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
378 reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS;
379
380 }
381 ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg);
382 dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg);
383
384
385 if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) ||
386 (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) ||
387 (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) {
388
389 if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL)
390 tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK;
391 if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL)
392 tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK;
393 if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)
394 tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK;
395
396 /* Enable UTMI mode for required TLL channels */
397 omap_usb_utmi_init(omap, tll_ch_mask);
398 }
399
400 if (omap->phy_reset) {
401 /* Refer ISSUE1:
402 * Hold the PHY in RESET for enough time till
403 * PHY is settled and ready
404 */
405 udelay(10);
406
407 if (gpio_is_valid(omap->reset_gpio_port[0]))
408 gpio_set_value(omap->reset_gpio_port[0], 1);
409
410 if (gpio_is_valid(omap->reset_gpio_port[1]))
411 gpio_set_value(omap->reset_gpio_port[1], 1);
412 }
413
414 return 0;
415
416err_sys_status:
417 clk_disable(omap->usbtll_ick);
418 clk_put(omap->usbtll_ick);
419
420err_tll_ick:
421 clk_disable(omap->usbtll_fck);
422 clk_put(omap->usbtll_fck);
423
424err_tll_fck:
425 clk_disable(omap->usbhost1_48m_fck);
426 clk_put(omap->usbhost1_48m_fck);
427
428 if (omap->phy_reset) {
429 if (gpio_is_valid(omap->reset_gpio_port[0]))
430 gpio_free(omap->reset_gpio_port[0]);
431
432 if (gpio_is_valid(omap->reset_gpio_port[1]))
433 gpio_free(omap->reset_gpio_port[1]);
434 }
435
436err_host_48m_fck:
437 clk_disable(omap->usbhost2_120m_fck);
438 clk_put(omap->usbhost2_120m_fck);
439
440err_host_120m_fck:
441 clk_disable(omap->usbhost_ick);
442 clk_put(omap->usbhost_ick);
443
444err_host_ick:
445 return ret;
446}
447
448static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd)
449{
450 unsigned long timeout = jiffies + msecs_to_jiffies(100);
451
452 dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n");
453
454 /* Reset OMAP modules for insmod/rmmod to work */
455 ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG,
456 OMAP_UHH_SYSCONFIG_SOFTRESET);
457 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
458 & (1 << 0))) {
459 cpu_relax();
460
461 if (time_after(jiffies, timeout))
462 dev_dbg(omap->dev, "operation timed out\n");
463 }
464
465 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
466 & (1 << 1))) {
467 cpu_relax();
468
469 if (time_after(jiffies, timeout))
470 dev_dbg(omap->dev, "operation timed out\n");
471 }
472
473 while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS)
474 & (1 << 2))) {
475 cpu_relax();
476
477 if (time_after(jiffies, timeout))
478 dev_dbg(omap->dev, "operation timed out\n");
479 }
480
481 ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1));
482
483 while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS)
484 & (1 << 0))) {
485 cpu_relax();
486
487 if (time_after(jiffies, timeout))
488 dev_dbg(omap->dev, "operation timed out\n");
489 }
490
491 if (omap->usbtll_fck != NULL) {
492 clk_disable(omap->usbtll_fck);
493 clk_put(omap->usbtll_fck);
494 omap->usbtll_fck = NULL;
495 }
496
497 if (omap->usbhost_ick != NULL) {
498 clk_disable(omap->usbhost_ick);
499 clk_put(omap->usbhost_ick);
500 omap->usbhost_ick = NULL;
501 }
502
503 if (omap->usbhost1_48m_fck != NULL) {
504 clk_disable(omap->usbhost1_48m_fck);
505 clk_put(omap->usbhost1_48m_fck);
506 omap->usbhost1_48m_fck = NULL;
507 }
508
509 if (omap->usbhost2_120m_fck != NULL) {
510 clk_disable(omap->usbhost2_120m_fck);
511 clk_put(omap->usbhost2_120m_fck);
512 omap->usbhost2_120m_fck = NULL;
513 }
514
515 if (omap->usbtll_ick != NULL) {
516 clk_disable(omap->usbtll_ick);
517 clk_put(omap->usbtll_ick);
518 omap->usbtll_ick = NULL;
519 }
520
521 if (omap->phy_reset) {
522 if (gpio_is_valid(omap->reset_gpio_port[0]))
523 gpio_free(omap->reset_gpio_port[0]);
524
525 if (gpio_is_valid(omap->reset_gpio_port[1]))
526 gpio_free(omap->reset_gpio_port[1]);
527 }
528
529 dev_dbg(omap->dev, "Clock to USB host has been disabled\n");
530}
531
532/*-------------------------------------------------------------------------*/
533
534static const struct hc_driver ehci_omap_hc_driver;
535
536/* configure so an HC device and id are always provided */
537/* always called with process context; sleeping is OK */
538
539/**
540 * ehci_hcd_omap_probe - initialize TI-based HCDs
541 *
542 * Allocates basic resources for this USB host controller, and
543 * then invokes the start() method for the HCD associated with it
544 * through the hotplug entry's driver_data.
545 */
546static int ehci_hcd_omap_probe(struct platform_device *pdev)
547{
548 struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data;
549 struct ehci_hcd_omap *omap;
550 struct resource *res;
551 struct usb_hcd *hcd;
552
553 int irq = platform_get_irq(pdev, 0);
554 int ret = -ENODEV;
555 int i;
556 char supply[7];
557
558 if (!pdata) {
559 dev_dbg(&pdev->dev, "missing platform_data\n");
560 goto err_pdata;
561 }
562
563 if (usb_disabled())
564 goto err_disabled;
565
566 omap = kzalloc(sizeof(*omap), GFP_KERNEL);
567 if (!omap) {
568 ret = -ENOMEM;
569 goto err_disabled;
570 }
571
572 hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev,
573 dev_name(&pdev->dev));
574 if (!hcd) {
575 dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret);
576 ret = -ENOMEM;
577 goto err_create_hcd;
578 }
579
580 platform_set_drvdata(pdev, omap);
581 omap->dev = &pdev->dev;
582 omap->phy_reset = pdata->phy_reset;
583 omap->reset_gpio_port[0] = pdata->reset_gpio_port[0];
584 omap->reset_gpio_port[1] = pdata->reset_gpio_port[1];
585 omap->reset_gpio_port[2] = pdata->reset_gpio_port[2];
586 omap->port_mode[0] = pdata->port_mode[0];
587 omap->port_mode[1] = pdata->port_mode[1];
588 omap->port_mode[2] = pdata->port_mode[2];
589 omap->ehci = hcd_to_ehci(hcd);
590 omap->ehci->sbrn = 0x20;
591
592 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
593
594 hcd->rsrc_start = res->start;
595 hcd->rsrc_len = resource_size(res);
596
597 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
598 if (!hcd->regs) {
599 dev_err(&pdev->dev, "EHCI ioremap failed\n");
600 ret = -ENOMEM;
601 goto err_ioremap;
602 }
603
604 /* we know this is the memory we want, no need to ioremap again */
605 omap->ehci->caps = hcd->regs;
606 omap->ehci_base = hcd->regs;
607
608 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
609 omap->uhh_base = ioremap(res->start, resource_size(res));
610 if (!omap->uhh_base) {
611 dev_err(&pdev->dev, "UHH ioremap failed\n");
612 ret = -ENOMEM;
613 goto err_uhh_ioremap;
614 }
615
616 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
617 omap->tll_base = ioremap(res->start, resource_size(res));
618 if (!omap->tll_base) {
619 dev_err(&pdev->dev, "TLL ioremap failed\n");
620 ret = -ENOMEM;
621 goto err_tll_ioremap;
622 }
623
624 /* get ehci regulator and enable */
625 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
626 if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) {
627 omap->regulator[i] = NULL;
628 continue;
629 }
630 snprintf(supply, sizeof(supply), "hsusb%d", i);
631 omap->regulator[i] = regulator_get(omap->dev, supply);
632 if (IS_ERR(omap->regulator[i])) {
633 omap->regulator[i] = NULL;
634 dev_dbg(&pdev->dev,
635 "failed to get ehci port%d regulator\n", i);
636 } else {
637 regulator_enable(omap->regulator[i]);
638 }
639 }
640
641 ret = omap_start_ehc(omap, hcd);
642 if (ret) {
643 dev_dbg(&pdev->dev, "failed to start ehci\n");
644 goto err_start;
645 }
646
647 omap->ehci->regs = hcd->regs
648 + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase));
649
650 dbg_hcs_params(omap->ehci, "reset");
651 dbg_hcc_params(omap->ehci, "reset");
652
653 /* cache this readonly data; minimize chip reads */
654 omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params);
655
656 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
657 if (ret) {
658 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
659 goto err_add_hcd;
660 }
661
662 return 0;
663
664err_add_hcd:
665 omap_stop_ehc(omap, hcd);
666
667err_start:
668 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
669 if (omap->regulator[i]) {
670 regulator_disable(omap->regulator[i]);
671 regulator_put(omap->regulator[i]);
672 }
673 }
674 iounmap(omap->tll_base);
675
676err_tll_ioremap:
677 iounmap(omap->uhh_base);
678
679err_uhh_ioremap:
680 iounmap(hcd->regs);
681
682err_ioremap:
683 usb_put_hcd(hcd);
684
685err_create_hcd:
686 kfree(omap);
687err_disabled:
688err_pdata:
689 return ret;
690}
691
692/* may be called without controller electrically present */
693/* may be called with controller, bus, and devices active */
694
695/**
696 * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs
697 * @pdev: USB Host Controller being removed
698 *
699 * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking
700 * the HCD's stop() method. It is always called from a thread
701 * context, normally "rmmod", "apmd", or something similar.
702 */
703static int ehci_hcd_omap_remove(struct platform_device *pdev)
704{
705 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
706 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
707 int i;
708
709 usb_remove_hcd(hcd);
710 omap_stop_ehc(omap, hcd);
711 iounmap(hcd->regs);
712 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
713 if (omap->regulator[i]) {
714 regulator_disable(omap->regulator[i]);
715 regulator_put(omap->regulator[i]);
716 }
717 }
718 iounmap(omap->tll_base);
719 iounmap(omap->uhh_base);
720 usb_put_hcd(hcd);
721 kfree(omap);
722
723 return 0;
724}
725
726static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
727{
728 struct ehci_hcd_omap *omap = platform_get_drvdata(pdev);
729 struct usb_hcd *hcd = ehci_to_hcd(omap->ehci);
730
731 if (hcd->driver->shutdown)
732 hcd->driver->shutdown(hcd);
733}
734
735static struct platform_driver ehci_hcd_omap_driver = {
736 .probe = ehci_hcd_omap_probe,
737 .remove = ehci_hcd_omap_remove,
738 .shutdown = ehci_hcd_omap_shutdown,
739 /*.suspend = ehci_hcd_omap_suspend, */
740 /*.resume = ehci_hcd_omap_resume, */
741 .driver = {
742 .name = "ehci-omap",
743 }
744};
745
746/*-------------------------------------------------------------------------*/
747
748static const struct hc_driver ehci_omap_hc_driver = {
749 .description = hcd_name,
750 .product_desc = "OMAP-EHCI Host Controller",
751 .hcd_priv_size = sizeof(struct ehci_hcd),
752
753 /*
754 * generic hardware linkage
755 */
756 .irq = ehci_irq,
757 .flags = HCD_MEMORY | HCD_USB2,
758
759 /*
760 * basic lifecycle operations
761 */
762 .reset = ehci_init,
763 .start = ehci_run,
764 .stop = ehci_stop,
765 .shutdown = ehci_shutdown,
766
767 /*
768 * managing i/o requests and associated device resources
769 */
770 .urb_enqueue = ehci_urb_enqueue,
771 .urb_dequeue = ehci_urb_dequeue,
772 .endpoint_disable = ehci_endpoint_disable,
773 .endpoint_reset = ehci_endpoint_reset,
774
775 /*
776 * scheduling support
777 */
778 .get_frame_number = ehci_get_frame,
779
780 /*
781 * root hub support
782 */
783 .hub_status_data = ehci_hub_status_data,
784 .hub_control = ehci_hub_control,
785 .bus_suspend = ehci_bus_suspend,
786 .bus_resume = ehci_bus_resume,
787
788 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
789};
790
791MODULE_ALIAS("platform:omap-ehci");
792MODULE_AUTHOR("Texas Instruments, Inc.");
793MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
794
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 1d283e1b2b8d..0f87dc72820a 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -222,14 +222,14 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
222 goto err1; 222 goto err1;
223 } 223 }
224 224
225 if (!request_mem_region(res->start, res->end - res->start + 1, 225 if (!request_mem_region(res->start, resource_size(res),
226 ehci_orion_hc_driver.description)) { 226 ehci_orion_hc_driver.description)) {
227 dev_dbg(&pdev->dev, "controller already in use\n"); 227 dev_dbg(&pdev->dev, "controller already in use\n");
228 err = -EBUSY; 228 err = -EBUSY;
229 goto err1; 229 goto err1;
230 } 230 }
231 231
232 regs = ioremap(res->start, res->end - res->start + 1); 232 regs = ioremap(res->start, resource_size(res));
233 if (regs == NULL) { 233 if (regs == NULL) {
234 dev_dbg(&pdev->dev, "error mapping memory\n"); 234 dev_dbg(&pdev->dev, "error mapping memory\n");
235 err = -EFAULT; 235 err = -EFAULT;
@@ -244,7 +244,7 @@ static int __devinit ehci_orion_drv_probe(struct platform_device *pdev)
244 } 244 }
245 245
246 hcd->rsrc_start = res->start; 246 hcd->rsrc_start = res->start;
247 hcd->rsrc_len = res->end - res->start + 1; 247 hcd->rsrc_len = resource_size(res);
248 hcd->regs = regs; 248 hcd->regs = regs;
249 249
250 ehci = hcd_to_ehci(hcd); 250 ehci = hcd_to_ehci(hcd);
@@ -287,7 +287,7 @@ err4:
287err3: 287err3:
288 iounmap(regs); 288 iounmap(regs);
289err2: 289err2:
290 release_mem_region(res->start, res->end - res->start + 1); 290 release_mem_region(res->start, resource_size(res));
291err1: 291err1:
292 dev_err(&pdev->dev, "init %s fail, %d\n", 292 dev_err(&pdev->dev, "init %s fail, %d\n",
293 dev_name(&pdev->dev), err); 293 dev_name(&pdev->dev), err);
diff --git a/drivers/usb/host/ehci-ppc-of.c b/drivers/usb/host/ehci-ppc-of.c
index 36f96da129f5..8df33b8a634c 100644
--- a/drivers/usb/host/ehci-ppc-of.c
+++ b/drivers/usb/host/ehci-ppc-of.c
@@ -134,21 +134,21 @@ ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
134 hcd->rsrc_len = res.end - res.start + 1; 134 hcd->rsrc_len = res.end - res.start + 1;
135 135
136 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 136 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
137 printk(KERN_ERR __FILE__ ": request_mem_region failed\n"); 137 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
138 rv = -EBUSY; 138 rv = -EBUSY;
139 goto err_rmr; 139 goto err_rmr;
140 } 140 }
141 141
142 irq = irq_of_parse_and_map(dn, 0); 142 irq = irq_of_parse_and_map(dn, 0);
143 if (irq == NO_IRQ) { 143 if (irq == NO_IRQ) {
144 printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n"); 144 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
145 rv = -EBUSY; 145 rv = -EBUSY;
146 goto err_irq; 146 goto err_irq;
147 } 147 }
148 148
149 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 149 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
150 if (!hcd->regs) { 150 if (!hcd->regs) {
151 printk(KERN_ERR __FILE__ ": ioremap failed\n"); 151 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
152 rv = -ENOMEM; 152 rv = -ENOMEM;
153 goto err_ioremap; 153 goto err_ioremap;
154 } 154 }
@@ -161,9 +161,9 @@ ehci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
161 ehci->ohci_hcctrl_reg = ioremap(res.start + 161 ehci->ohci_hcctrl_reg = ioremap(res.start +
162 OHCI_HCCTRL_OFFSET, OHCI_HCCTRL_LEN); 162 OHCI_HCCTRL_OFFSET, OHCI_HCCTRL_LEN);
163 else 163 else
164 pr_debug(__FILE__ ": no ohci offset in fdt\n"); 164 pr_debug("%s: no ohci offset in fdt\n", __FILE__);
165 if (!ehci->ohci_hcctrl_reg) { 165 if (!ehci->ohci_hcctrl_reg) {
166 pr_debug(__FILE__ ": ioremap for ohci hcctrl failed\n"); 166 pr_debug("%s: ioremap for ohci hcctrl failed\n", __FILE__);
167 } else { 167 } else {
168 ehci->has_amcc_usb23 = 1; 168 ehci->has_amcc_usb23 = 1;
169 } 169 }
@@ -241,7 +241,7 @@ static int ehci_hcd_ppc_of_remove(struct of_device *op)
241 else 241 else
242 release_mem_region(res.start, 0x4); 242 release_mem_region(res.start, 0x4);
243 else 243 else
244 pr_debug(__FILE__ ": no ohci offset in fdt\n"); 244 pr_debug("%s: no ohci offset in fdt\n", __FILE__);
245 of_node_put(np); 245 of_node_put(np);
246 } 246 }
247 247
@@ -264,7 +264,7 @@ static int ehci_hcd_ppc_of_shutdown(struct of_device *op)
264} 264}
265 265
266 266
267static struct of_device_id ehci_hcd_ppc_of_match[] = { 267static const struct of_device_id ehci_hcd_ppc_of_match[] = {
268 { 268 {
269 .compatible = "usb-ehci", 269 .compatible = "usb-ehci",
270 }, 270 },
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 139a2cc3f641..89521775c567 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -616,9 +616,11 @@ qh_urb_transaction (
616) { 616) {
617 struct ehci_qtd *qtd, *qtd_prev; 617 struct ehci_qtd *qtd, *qtd_prev;
618 dma_addr_t buf; 618 dma_addr_t buf;
619 int len, maxpacket; 619 int len, this_sg_len, maxpacket;
620 int is_input; 620 int is_input;
621 u32 token; 621 u32 token;
622 int i;
623 struct scatterlist *sg;
622 624
623 /* 625 /*
624 * URBs map to sequences of QTDs: one logical transaction 626 * URBs map to sequences of QTDs: one logical transaction
@@ -659,7 +661,20 @@ qh_urb_transaction (
659 /* 661 /*
660 * data transfer stage: buffer setup 662 * data transfer stage: buffer setup
661 */ 663 */
662 buf = urb->transfer_dma; 664 i = urb->num_sgs;
665 if (len > 0 && i > 0) {
666 sg = urb->sg->sg;
667 buf = sg_dma_address(sg);
668
669 /* urb->transfer_buffer_length may be smaller than the
670 * size of the scatterlist (or vice versa)
671 */
672 this_sg_len = min_t(int, sg_dma_len(sg), len);
673 } else {
674 sg = NULL;
675 buf = urb->transfer_dma;
676 this_sg_len = len;
677 }
663 678
664 if (is_input) 679 if (is_input)
665 token |= (1 /* "in" */ << 8); 680 token |= (1 /* "in" */ << 8);
@@ -675,7 +690,9 @@ qh_urb_transaction (
675 for (;;) { 690 for (;;) {
676 int this_qtd_len; 691 int this_qtd_len;
677 692
678 this_qtd_len = qtd_fill(ehci, qtd, buf, len, token, maxpacket); 693 this_qtd_len = qtd_fill(ehci, qtd, buf, this_sg_len, token,
694 maxpacket);
695 this_sg_len -= this_qtd_len;
679 len -= this_qtd_len; 696 len -= this_qtd_len;
680 buf += this_qtd_len; 697 buf += this_qtd_len;
681 698
@@ -691,8 +708,13 @@ qh_urb_transaction (
691 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0) 708 if ((maxpacket & (this_qtd_len + (maxpacket - 1))) == 0)
692 token ^= QTD_TOGGLE; 709 token ^= QTD_TOGGLE;
693 710
694 if (likely (len <= 0)) 711 if (likely(this_sg_len <= 0)) {
695 break; 712 if (--i <= 0 || len <= 0)
713 break;
714 sg = sg_next(sg);
715 buf = sg_dma_address(sg);
716 this_sg_len = min_t(int, sg_dma_len(sg), len);
717 }
696 718
697 qtd_prev = qtd; 719 qtd_prev = qtd;
698 qtd = ehci_qtd_alloc (ehci, flags); 720 qtd = ehci_qtd_alloc (ehci, flags);
@@ -827,9 +849,10 @@ qh_make (
827 * But interval 1 scheduling is simpler, and 849 * But interval 1 scheduling is simpler, and
828 * includes high bandwidth. 850 * includes high bandwidth.
829 */ 851 */
830 dbg ("intr period %d uframes, NYET!", 852 urb->interval = 1;
831 urb->interval); 853 } else if (qh->period > ehci->periodic_size) {
832 goto done; 854 qh->period = ehci->periodic_size;
855 urb->interval = qh->period << 3;
833 } 856 }
834 } else { 857 } else {
835 int think_time; 858 int think_time;
@@ -852,6 +875,10 @@ qh_make (
852 usb_calc_bus_time (urb->dev->speed, 875 usb_calc_bus_time (urb->dev->speed,
853 is_input, 0, max_packet (maxp))); 876 is_input, 0, max_packet (maxp)));
854 qh->period = urb->interval; 877 qh->period = urb->interval;
878 if (qh->period > ehci->periodic_size) {
879 qh->period = ehci->periodic_size;
880 urb->interval = qh->period;
881 }
855 } 882 }
856 } 883 }
857 884
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index a5535b5e3fe2..805ec633a652 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -510,6 +510,8 @@ static int disable_periodic (struct ehci_hcd *ehci)
510 ehci_writel(ehci, cmd, &ehci->regs->command); 510 ehci_writel(ehci, cmd, &ehci->regs->command);
511 /* posted write ... */ 511 /* posted write ... */
512 512
513 free_cached_lists(ehci);
514
513 ehci->next_uframe = -1; 515 ehci->next_uframe = -1;
514 return 0; 516 return 0;
515} 517}
@@ -1121,8 +1123,8 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
1121 urb->interval); 1123 urb->interval);
1122 } 1124 }
1123 1125
1124 /* if dev->ep [epnum] is a QH, info1.maxpacket is nonzero */ 1126 /* if dev->ep [epnum] is a QH, hw is set */
1125 } else if (unlikely (stream->hw_info1 != 0)) { 1127 } else if (unlikely (stream->hw != NULL)) {
1126 ehci_dbg (ehci, "dev %s ep%d%s, not iso??\n", 1128 ehci_dbg (ehci, "dev %s ep%d%s, not iso??\n",
1127 urb->dev->devpath, epnum, 1129 urb->dev->devpath, epnum,
1128 usb_pipein(urb->pipe) ? "in" : "out"); 1130 usb_pipein(urb->pipe) ? "in" : "out");
@@ -1385,7 +1387,7 @@ sitd_slot_ok (
1385 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler! 1387 * given EHCI_TUNE_FLS and the slop). Or, write a smarter scheduler!
1386 */ 1388 */
1387 1389
1388#define SCHEDULE_SLOP 10 /* frames */ 1390#define SCHEDULE_SLOP 80 /* microframes */
1389 1391
1390static int 1392static int
1391iso_stream_schedule ( 1393iso_stream_schedule (
@@ -1394,12 +1396,13 @@ iso_stream_schedule (
1394 struct ehci_iso_stream *stream 1396 struct ehci_iso_stream *stream
1395) 1397)
1396{ 1398{
1397 u32 now, start, max, period; 1399 u32 now, next, start, period;
1398 int status; 1400 int status;
1399 unsigned mod = ehci->periodic_size << 3; 1401 unsigned mod = ehci->periodic_size << 3;
1400 struct ehci_iso_sched *sched = urb->hcpriv; 1402 struct ehci_iso_sched *sched = urb->hcpriv;
1403 struct pci_dev *pdev;
1401 1404
1402 if (sched->span > (mod - 8 * SCHEDULE_SLOP)) { 1405 if (sched->span > (mod - SCHEDULE_SLOP)) {
1403 ehci_dbg (ehci, "iso request %p too long\n", urb); 1406 ehci_dbg (ehci, "iso request %p too long\n", urb);
1404 status = -EFBIG; 1407 status = -EFBIG;
1405 goto fail; 1408 goto fail;
@@ -1418,26 +1421,35 @@ iso_stream_schedule (
1418 1421
1419 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; 1422 now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;
1420 1423
1421 /* when's the last uframe this urb could start? */
1422 max = now + mod;
1423
1424 /* Typical case: reuse current schedule, stream is still active. 1424 /* Typical case: reuse current schedule, stream is still active.
1425 * Hopefully there are no gaps from the host falling behind 1425 * Hopefully there are no gaps from the host falling behind
1426 * (irq delays etc), but if there are we'll take the next 1426 * (irq delays etc), but if there are we'll take the next
1427 * slot in the schedule, implicitly assuming URB_ISO_ASAP. 1427 * slot in the schedule, implicitly assuming URB_ISO_ASAP.
1428 */ 1428 */
1429 if (likely (!list_empty (&stream->td_list))) { 1429 if (likely (!list_empty (&stream->td_list))) {
1430 pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
1430 start = stream->next_uframe; 1431 start = stream->next_uframe;
1431 if (start < now) 1432
1432 start += mod; 1433 /* For high speed devices, allow scheduling within the
1434 * isochronous scheduling threshold. For full speed devices,
1435 * don't. (Work around for Intel ICH9 bug.)
1436 */
1437 if (!stream->highspeed &&
1438 pdev->vendor == PCI_VENDOR_ID_INTEL)
1439 next = now + ehci->i_thresh;
1440 else
1441 next = now;
1433 1442
1434 /* Fell behind (by up to twice the slop amount)? */ 1443 /* Fell behind (by up to twice the slop amount)? */
1435 if (start >= max - 2 * 8 * SCHEDULE_SLOP) 1444 if (((start - next) & (mod - 1)) >=
1445 mod - 2 * SCHEDULE_SLOP)
1436 start += period * DIV_ROUND_UP( 1446 start += period * DIV_ROUND_UP(
1437 max - start, period) - mod; 1447 (next - start) & (mod - 1),
1448 period);
1438 1449
1439 /* Tried to schedule too far into the future? */ 1450 /* Tried to schedule too far into the future? */
1440 if (unlikely((start + sched->span) >= max)) { 1451 if (unlikely(((start - now) & (mod - 1)) + sched->span
1452 >= mod - 2 * SCHEDULE_SLOP)) {
1441 status = -EFBIG; 1453 status = -EFBIG;
1442 goto fail; 1454 goto fail;
1443 } 1455 }
@@ -1451,7 +1463,7 @@ iso_stream_schedule (
1451 * can also help high bandwidth if the dma and irq loads don't 1463 * can also help high bandwidth if the dma and irq loads don't
1452 * jump until after the queue is primed. 1464 * jump until after the queue is primed.
1453 */ 1465 */
1454 start = SCHEDULE_SLOP * 8 + (now & ~0x07); 1466 start = SCHEDULE_SLOP + (now & ~0x07);
1455 start %= mod; 1467 start %= mod;
1456 stream->next_uframe = start; 1468 stream->next_uframe = start;
1457 1469
@@ -1482,7 +1494,7 @@ iso_stream_schedule (
1482 /* no room in the schedule */ 1494 /* no room in the schedule */
1483 ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n", 1495 ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n",
1484 list_empty (&stream->td_list) ? "" : "re", 1496 list_empty (&stream->td_list) ? "" : "re",
1485 urb, now, max); 1497 urb, now, now + mod);
1486 status = -ENOSPC; 1498 status = -ENOSPC;
1487 1499
1488fail: 1500fail:
@@ -1553,13 +1565,27 @@ itd_patch(
1553static inline void 1565static inline void
1554itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd) 1566itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
1555{ 1567{
1556 /* always prepend ITD/SITD ... only QH tree is order-sensitive */ 1568 union ehci_shadow *prev = &ehci->pshadow[frame];
1557 itd->itd_next = ehci->pshadow [frame]; 1569 __hc32 *hw_p = &ehci->periodic[frame];
1558 itd->hw_next = ehci->periodic [frame]; 1570 union ehci_shadow here = *prev;
1559 ehci->pshadow [frame].itd = itd; 1571 __hc32 type = 0;
1572
1573 /* skip any iso nodes which might belong to previous microframes */
1574 while (here.ptr) {
1575 type = Q_NEXT_TYPE(ehci, *hw_p);
1576 if (type == cpu_to_hc32(ehci, Q_TYPE_QH))
1577 break;
1578 prev = periodic_next_shadow(ehci, prev, type);
1579 hw_p = shadow_next_periodic(ehci, &here, type);
1580 here = *prev;
1581 }
1582
1583 itd->itd_next = here;
1584 itd->hw_next = *hw_p;
1585 prev->itd = itd;
1560 itd->frame = frame; 1586 itd->frame = frame;
1561 wmb (); 1587 wmb ();
1562 ehci->periodic[frame] = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD); 1588 *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD);
1563} 1589}
1564 1590
1565/* fit urb's itds into the selected schedule slot; activate as needed */ 1591/* fit urb's itds into the selected schedule slot; activate as needed */
@@ -2113,13 +2139,27 @@ sitd_complete (
2113 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out"); 2139 (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out");
2114 } 2140 }
2115 iso_stream_put (ehci, stream); 2141 iso_stream_put (ehci, stream);
2116 /* OK to recycle this SITD now that its completion callback ran. */ 2142
2117done: 2143done:
2118 sitd->urb = NULL; 2144 sitd->urb = NULL;
2119 sitd->stream = NULL; 2145 if (ehci->clock_frame != sitd->frame) {
2120 list_move(&sitd->sitd_list, &stream->free_list); 2146 /* OK to recycle this SITD now. */
2121 iso_stream_put(ehci, stream); 2147 sitd->stream = NULL;
2122 2148 list_move(&sitd->sitd_list, &stream->free_list);
2149 iso_stream_put(ehci, stream);
2150 } else {
2151 /* HW might remember this SITD, so we can't recycle it yet.
2152 * Move it to a safe place until a new frame starts.
2153 */
2154 list_move(&sitd->sitd_list, &ehci->cached_sitd_list);
2155 if (stream->refcount == 2) {
2156 /* If iso_stream_put() were called here, stream
2157 * would be freed. Instead, just prevent reuse.
2158 */
2159 stream->ep->hcpriv = NULL;
2160 stream->ep = NULL;
2161 }
2162 }
2123 return retval; 2163 return retval;
2124} 2164}
2125 2165
@@ -2185,9 +2225,10 @@ done:
2185 2225
2186/*-------------------------------------------------------------------------*/ 2226/*-------------------------------------------------------------------------*/
2187 2227
2188static void free_cached_itd_list(struct ehci_hcd *ehci) 2228static void free_cached_lists(struct ehci_hcd *ehci)
2189{ 2229{
2190 struct ehci_itd *itd, *n; 2230 struct ehci_itd *itd, *n;
2231 struct ehci_sitd *sitd, *sn;
2191 2232
2192 list_for_each_entry_safe(itd, n, &ehci->cached_itd_list, itd_list) { 2233 list_for_each_entry_safe(itd, n, &ehci->cached_itd_list, itd_list) {
2193 struct ehci_iso_stream *stream = itd->stream; 2234 struct ehci_iso_stream *stream = itd->stream;
@@ -2195,6 +2236,13 @@ static void free_cached_itd_list(struct ehci_hcd *ehci)
2195 list_move(&itd->itd_list, &stream->free_list); 2236 list_move(&itd->itd_list, &stream->free_list);
2196 iso_stream_put(ehci, stream); 2237 iso_stream_put(ehci, stream);
2197 } 2238 }
2239
2240 list_for_each_entry_safe(sitd, sn, &ehci->cached_sitd_list, sitd_list) {
2241 struct ehci_iso_stream *stream = sitd->stream;
2242 sitd->stream = NULL;
2243 list_move(&sitd->sitd_list, &stream->free_list);
2244 iso_stream_put(ehci, stream);
2245 }
2198} 2246}
2199 2247
2200/*-------------------------------------------------------------------------*/ 2248/*-------------------------------------------------------------------------*/
@@ -2221,7 +2269,7 @@ scan_periodic (struct ehci_hcd *ehci)
2221 clock_frame = -1; 2269 clock_frame = -1;
2222 } 2270 }
2223 if (ehci->clock_frame != clock_frame) { 2271 if (ehci->clock_frame != clock_frame) {
2224 free_cached_itd_list(ehci); 2272 free_cached_lists(ehci);
2225 ehci->clock_frame = clock_frame; 2273 ehci->clock_frame = clock_frame;
2226 } 2274 }
2227 clock %= mod; 2275 clock %= mod;
@@ -2312,9 +2360,13 @@ restart:
2312 * No need to check for activity unless the 2360 * No need to check for activity unless the
2313 * frame is current. 2361 * frame is current.
2314 */ 2362 */
2315 if (frame == clock_frame && live && 2363 if (((frame == clock_frame) ||
2316 (q.sitd->hw_results & 2364 (((frame + 1) % ehci->periodic_size)
2317 SITD_ACTIVE(ehci))) { 2365 == clock_frame))
2366 && live
2367 && (q.sitd->hw_results &
2368 SITD_ACTIVE(ehci))) {
2369
2318 incomplete = true; 2370 incomplete = true;
2319 q_p = &q.sitd->sitd_next; 2371 q_p = &q.sitd->sitd_next;
2320 hw_p = &q.sitd->hw_next; 2372 hw_p = &q.sitd->hw_next;
@@ -2384,7 +2436,7 @@ restart:
2384 clock = now; 2436 clock = now;
2385 clock_frame = clock >> 3; 2437 clock_frame = clock >> 3;
2386 if (ehci->clock_frame != clock_frame) { 2438 if (ehci->clock_frame != clock_frame) {
2387 free_cached_itd_list(ehci); 2439 free_cached_lists(ehci);
2388 ehci->clock_frame = clock_frame; 2440 ehci->clock_frame = clock_frame;
2389 } 2441 }
2390 } else { 2442 } else {
diff --git a/drivers/usb/host/ehci-xilinx-of.c b/drivers/usb/host/ehci-xilinx-of.c
new file mode 100644
index 000000000000..f603bb2c0a8e
--- /dev/null
+++ b/drivers/usb/host/ehci-xilinx-of.c
@@ -0,0 +1,300 @@
1/*
2 * EHCI HCD (Host Controller Driver) for USB.
3 *
4 * Bus Glue for Xilinx EHCI core on the of_platform bus
5 *
6 * Copyright (c) 2009 Xilinx, Inc.
7 *
8 * Based on "ehci-ppc-of.c" by Valentine Barshak <vbarshak@ru.mvista.com>
9 * and "ehci-ppc-soc.c" by Stefan Roese <sr@denx.de>
10 * and "ohci-ppc-of.c" by Sylvain Munaut <tnt@246tNt.com>
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation,
24 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 */
27
28#include <linux/signal.h>
29
30#include <linux/of.h>
31#include <linux/of_platform.h>
32
33/**
34 * ehci_xilinx_of_setup - Initialize the device for ehci_reset()
35 * @hcd: Pointer to the usb_hcd device to which the host controller bound
36 *
37 * called during probe() after chip reset completes.
38 */
39static int ehci_xilinx_of_setup(struct usb_hcd *hcd)
40{
41 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
42 int retval;
43
44 retval = ehci_halt(ehci);
45 if (retval)
46 return retval;
47
48 retval = ehci_init(hcd);
49 if (retval)
50 return retval;
51
52 ehci->sbrn = 0x20;
53
54 return ehci_reset(ehci);
55}
56
57/**
58 * ehci_xilinx_port_handed_over - hand the port out if failed to enable it
59 * @hcd: Pointer to the usb_hcd device to which the host controller bound
60 * @portnum:Port number to which the device is attached.
61 *
62 * This function is used as a place to tell the user that the Xilinx USB host
63 * controller does support LS devices. And in an HS only configuration, it
64 * does not support FS devices either. It is hoped that this can help a
65 * confused user.
66 *
67 * There are cases when the host controller fails to enable the port due to,
68 * for example, insufficient power that can be supplied to the device from
69 * the USB bus. In those cases, the messages printed here are not helpful.
70 */
71static int ehci_xilinx_port_handed_over(struct usb_hcd *hcd, int portnum)
72{
73 dev_warn(hcd->self.controller, "port %d cannot be enabled\n", portnum);
74 if (hcd->has_tt) {
75 dev_warn(hcd->self.controller,
76 "Maybe you have connected a low speed device?\n");
77
78 dev_warn(hcd->self.controller,
79 "We do not support low speed devices\n");
80 } else {
81 dev_warn(hcd->self.controller,
82 "Maybe your device is not a high speed device?\n");
83 dev_warn(hcd->self.controller,
84 "The USB host controller does not support full speed "
85 "nor low speed devices\n");
86 dev_warn(hcd->self.controller,
87 "You can reconfigure the host controller to have "
88 "full speed support\n");
89 }
90
91 return 0;
92}
93
94
95static const struct hc_driver ehci_xilinx_of_hc_driver = {
96 .description = hcd_name,
97 .product_desc = "OF EHCI",
98 .hcd_priv_size = sizeof(struct ehci_hcd),
99
100 /*
101 * generic hardware linkage
102 */
103 .irq = ehci_irq,
104 .flags = HCD_MEMORY | HCD_USB2,
105
106 /*
107 * basic lifecycle operations
108 */
109 .reset = ehci_xilinx_of_setup,
110 .start = ehci_run,
111 .stop = ehci_stop,
112 .shutdown = ehci_shutdown,
113
114 /*
115 * managing i/o requests and associated device resources
116 */
117 .urb_enqueue = ehci_urb_enqueue,
118 .urb_dequeue = ehci_urb_dequeue,
119 .endpoint_disable = ehci_endpoint_disable,
120
121 /*
122 * scheduling support
123 */
124 .get_frame_number = ehci_get_frame,
125
126 /*
127 * root hub support
128 */
129 .hub_status_data = ehci_hub_status_data,
130 .hub_control = ehci_hub_control,
131#ifdef CONFIG_PM
132 .bus_suspend = ehci_bus_suspend,
133 .bus_resume = ehci_bus_resume,
134#endif
135 .relinquish_port = NULL,
136 .port_handed_over = ehci_xilinx_port_handed_over,
137
138 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
139};
140
141/**
142 * ehci_hcd_xilinx_of_probe - Probe method for the USB host controller
143 * @op: pointer to the of_device to which the host controller bound
144 * @match: pointer to of_device_id structure, not used
145 *
146 * This function requests resources and sets up appropriate properties for the
147 * host controller. Because the Xilinx USB host controller can be configured
148 * as HS only or HS/FS only, it checks the configuration in the device tree
149 * entry, and sets an appropriate value for hcd->has_tt.
150 */
151static int __devinit
152ehci_hcd_xilinx_of_probe(struct of_device *op, const struct of_device_id *match)
153{
154 struct device_node *dn = op->node;
155 struct usb_hcd *hcd;
156 struct ehci_hcd *ehci;
157 struct resource res;
158 int irq;
159 int rv;
160 int *value;
161
162 if (usb_disabled())
163 return -ENODEV;
164
165 dev_dbg(&op->dev, "initializing XILINX-OF USB Controller\n");
166
167 rv = of_address_to_resource(dn, 0, &res);
168 if (rv)
169 return rv;
170
171 hcd = usb_create_hcd(&ehci_xilinx_of_hc_driver, &op->dev,
172 "XILINX-OF USB");
173 if (!hcd)
174 return -ENOMEM;
175
176 hcd->rsrc_start = res.start;
177 hcd->rsrc_len = res.end - res.start + 1;
178
179 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
180 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
181 rv = -EBUSY;
182 goto err_rmr;
183 }
184
185 irq = irq_of_parse_and_map(dn, 0);
186 if (irq == NO_IRQ) {
187 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
188 rv = -EBUSY;
189 goto err_irq;
190 }
191
192 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
193 if (!hcd->regs) {
194 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
195 rv = -ENOMEM;
196 goto err_ioremap;
197 }
198
199 ehci = hcd_to_ehci(hcd);
200
201 /* This core always has big-endian register interface and uses
202 * big-endian memory descriptors.
203 */
204 ehci->big_endian_mmio = 1;
205 ehci->big_endian_desc = 1;
206
207 /* Check whether the FS support option is selected in the hardware.
208 */
209 value = (int *)of_get_property(dn, "xlnx,support-usb-fs", NULL);
210 if (value && (*value == 1)) {
211 ehci_dbg(ehci, "USB host controller supports FS devices\n");
212 hcd->has_tt = 1;
213 } else {
214 ehci_dbg(ehci,
215 "USB host controller is HS only\n");
216 hcd->has_tt = 0;
217 }
218
219 /* Debug registers are at the first 0x100 region
220 */
221 ehci->caps = hcd->regs + 0x100;
222 ehci->regs = hcd->regs + 0x100 +
223 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
224
225 /* cache this readonly data; minimize chip reads */
226 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
227
228 rv = usb_add_hcd(hcd, irq, 0);
229 if (rv == 0)
230 return 0;
231
232 iounmap(hcd->regs);
233
234err_ioremap:
235err_irq:
236 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
237err_rmr:
238 usb_put_hcd(hcd);
239
240 return rv;
241}
242
243/**
244 * ehci_hcd_xilinx_of_remove - shutdown hcd and release resources
245 * @op: pointer to of_device structure that is to be removed
246 *
247 * Remove the hcd structure, and release resources that has been requested
248 * during probe.
249 */
250static int ehci_hcd_xilinx_of_remove(struct of_device *op)
251{
252 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
253 dev_set_drvdata(&op->dev, NULL);
254
255 dev_dbg(&op->dev, "stopping XILINX-OF USB Controller\n");
256
257 usb_remove_hcd(hcd);
258
259 iounmap(hcd->regs);
260 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
261
262 usb_put_hcd(hcd);
263
264 return 0;
265}
266
267/**
268 * ehci_hcd_xilinx_of_shutdown - shutdown the hcd
269 * @op: pointer to of_device structure that is to be removed
270 *
271 * Properly shutdown the hcd, call driver's shutdown routine.
272 */
273static int ehci_hcd_xilinx_of_shutdown(struct of_device *op)
274{
275 struct usb_hcd *hcd = dev_get_drvdata(&op->dev);
276
277 if (hcd->driver->shutdown)
278 hcd->driver->shutdown(hcd);
279
280 return 0;
281}
282
283
284static const struct of_device_id ehci_hcd_xilinx_of_match[] = {
285 {.compatible = "xlnx,xps-usb-host-1.00.a",},
286 {},
287};
288MODULE_DEVICE_TABLE(of, ehci_hcd_xilinx_of_match);
289
290static struct of_platform_driver ehci_hcd_xilinx_of_driver = {
291 .name = "xilinx-of-ehci",
292 .match_table = ehci_hcd_xilinx_of_match,
293 .probe = ehci_hcd_xilinx_of_probe,
294 .remove = ehci_hcd_xilinx_of_remove,
295 .shutdown = ehci_hcd_xilinx_of_shutdown,
296 .driver = {
297 .name = "xilinx-of-ehci",
298 .owner = THIS_MODULE,
299 },
300};
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 2d85e21ff282..556c0b48f3ab 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -87,8 +87,9 @@ struct ehci_hcd { /* one per controller */
87 int next_uframe; /* scan periodic, start here */ 87 int next_uframe; /* scan periodic, start here */
88 unsigned periodic_sched; /* periodic activity count */ 88 unsigned periodic_sched; /* periodic activity count */
89 89
90 /* list of itds completed while clock_frame was still active */ 90 /* list of itds & sitds completed while clock_frame was still active */
91 struct list_head cached_itd_list; 91 struct list_head cached_itd_list;
92 struct list_head cached_sitd_list;
92 unsigned clock_frame; 93 unsigned clock_frame;
93 94
94 /* per root hub port */ 95 /* per root hub port */
@@ -195,7 +196,7 @@ timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
195 clear_bit (action, &ehci->actions); 196 clear_bit (action, &ehci->actions);
196} 197}
197 198
198static void free_cached_itd_list(struct ehci_hcd *ehci); 199static void free_cached_lists(struct ehci_hcd *ehci);
199 200
200/*-------------------------------------------------------------------------*/ 201/*-------------------------------------------------------------------------*/
201 202
@@ -394,9 +395,8 @@ struct ehci_iso_sched {
394 * acts like a qh would, if EHCI had them for ISO. 395 * acts like a qh would, if EHCI had them for ISO.
395 */ 396 */
396struct ehci_iso_stream { 397struct ehci_iso_stream {
397 /* first two fields match QH, but info1 == 0 */ 398 /* first field matches ehci_hq, but is NULL */
398 __hc32 hw_next; 399 struct ehci_qh_hw *hw;
399 __hc32 hw_info1;
400 400
401 u32 refcount; 401 u32 refcount;
402 u8 bEndpointAddress; 402 u8 bEndpointAddress;
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index 0951818ef93b..15379c636143 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -27,6 +27,7 @@
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/of_platform.h> 28#include <linux/of_platform.h>
29#include <linux/of_gpio.h> 29#include <linux/of_gpio.h>
30#include <linux/slab.h>
30#include <asm/qe.h> 31#include <asm/qe.h>
31#include <asm/fsl_gtm.h> 32#include <asm/fsl_gtm.h>
32#include "../core/hcd.h" 33#include "../core/hcd.h"
@@ -242,9 +243,10 @@ err:
242static void fhci_usb_free(void *lld) 243static void fhci_usb_free(void *lld)
243{ 244{
244 struct fhci_usb *usb = lld; 245 struct fhci_usb *usb = lld;
245 struct fhci_hcd *fhci = usb->fhci; 246 struct fhci_hcd *fhci;
246 247
247 if (usb) { 248 if (usb) {
249 fhci = usb->fhci;
248 fhci_config_transceiver(fhci, FHCI_PORT_POWER_OFF); 250 fhci_config_transceiver(fhci, FHCI_PORT_POWER_OFF);
249 fhci_ep0_free(usb); 251 fhci_ep0_free(usb);
250 kfree(usb->actual_frame); 252 kfree(usb->actual_frame);
@@ -432,7 +434,7 @@ static int fhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
432 return -ENOMEM; 434 return -ENOMEM;
433 435
434 /* allocate the private part of the URB */ 436 /* allocate the private part of the URB */
435 urb_priv->tds = kzalloc(size * sizeof(struct td), mem_flags); 437 urb_priv->tds = kcalloc(size, sizeof(*urb_priv->tds), mem_flags);
436 if (!urb_priv->tds) { 438 if (!urb_priv->tds) {
437 kfree(urb_priv); 439 kfree(urb_priv);
438 return -ENOMEM; 440 return -ENOMEM;
@@ -804,7 +806,7 @@ static int __devexit of_fhci_remove(struct of_device *ofdev)
804 return fhci_remove(&ofdev->dev); 806 return fhci_remove(&ofdev->dev);
805} 807}
806 808
807static struct of_device_id of_fhci_match[] = { 809static const struct of_device_id of_fhci_match[] = {
808 { .compatible = "fsl,mpc8323-qe-usb", }, 810 { .compatible = "fsl,mpc8323-qe-usb", },
809 {}, 811 {},
810}; 812};
diff --git a/drivers/usb/host/fhci-mem.c b/drivers/usb/host/fhci-mem.c
index 2c0736c99712..5591bfb499d1 100644
--- a/drivers/usb/host/fhci-mem.c
+++ b/drivers/usb/host/fhci-mem.c
@@ -18,6 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/slab.h>
21#include <linux/list.h> 22#include <linux/list.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23#include "../core/hcd.h" 24#include "../core/hcd.h"
diff --git a/drivers/usb/host/fhci-q.c b/drivers/usb/host/fhci-q.c
index b0a1446ba292..f73c92359beb 100644
--- a/drivers/usb/host/fhci-q.c
+++ b/drivers/usb/host/fhci-q.c
@@ -19,6 +19,7 @@
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/slab.h>
22#include <linux/list.h> 23#include <linux/list.h>
23#include <linux/usb.h> 24#include <linux/usb.h>
24#include "../core/hcd.h" 25#include "../core/hcd.h"
diff --git a/drivers/usb/host/fhci-sched.c b/drivers/usb/host/fhci-sched.c
index 62a226b61670..ff43747a614f 100644
--- a/drivers/usb/host/fhci-sched.c
+++ b/drivers/usb/host/fhci-sched.c
@@ -37,7 +37,7 @@ static void recycle_frame(struct fhci_usb *usb, struct packet *pkt)
37 pkt->info = 0; 37 pkt->info = 0;
38 pkt->priv_data = NULL; 38 pkt->priv_data = NULL;
39 39
40 cq_put(usb->ep0->empty_frame_Q, pkt); 40 cq_put(&usb->ep0->empty_frame_Q, pkt);
41} 41}
42 42
43/* confirm submitted packet */ 43/* confirm submitted packet */
@@ -57,7 +57,7 @@ void fhci_transaction_confirm(struct fhci_usb *usb, struct packet *pkt)
57 if ((td->data + td->actual_len) && trans_len) 57 if ((td->data + td->actual_len) && trans_len)
58 memcpy(td->data + td->actual_len, pkt->data, 58 memcpy(td->data + td->actual_len, pkt->data,
59 trans_len); 59 trans_len);
60 cq_put(usb->ep0->dummy_packets_Q, pkt->data); 60 cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
61 } 61 }
62 62
63 recycle_frame(usb, pkt); 63 recycle_frame(usb, pkt);
@@ -213,7 +213,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
213 } 213 }
214 214
215 /* update frame object fields before transmitting */ 215 /* update frame object fields before transmitting */
216 pkt = cq_get(usb->ep0->empty_frame_Q); 216 pkt = cq_get(&usb->ep0->empty_frame_Q);
217 if (!pkt) { 217 if (!pkt) {
218 fhci_dbg(usb->fhci, "there is no empty frame\n"); 218 fhci_dbg(usb->fhci, "there is no empty frame\n");
219 return -1; 219 return -1;
@@ -222,7 +222,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
222 222
223 pkt->info = 0; 223 pkt->info = 0;
224 if (data == NULL) { 224 if (data == NULL) {
225 data = cq_get(usb->ep0->dummy_packets_Q); 225 data = cq_get(&usb->ep0->dummy_packets_Q);
226 BUG_ON(!data); 226 BUG_ON(!data);
227 pkt->info = PKT_DUMMY_PACKET; 227 pkt->info = PKT_DUMMY_PACKET;
228 } 228 }
@@ -246,7 +246,7 @@ static int add_packet(struct fhci_usb *usb, struct ed *ed, struct td *td)
246 list_del_init(&td->frame_lh); 246 list_del_init(&td->frame_lh);
247 td->status = USB_TD_OK; 247 td->status = USB_TD_OK;
248 if (pkt->info & PKT_DUMMY_PACKET) 248 if (pkt->info & PKT_DUMMY_PACKET)
249 cq_put(usb->ep0->dummy_packets_Q, pkt->data); 249 cq_put(&usb->ep0->dummy_packets_Q, pkt->data);
250 recycle_frame(usb, pkt); 250 recycle_frame(usb, pkt);
251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD); 251 usb->actual_frame->total_bytes -= (len + PROTOCOL_OVERHEAD);
252 fhci_err(usb->fhci, "host transaction failed\n"); 252 fhci_err(usb->fhci, "host transaction failed\n");
@@ -627,7 +627,7 @@ irqreturn_t fhci_irq(struct usb_hcd *hcd)
627 627
628 628
629/* 629/*
630 * Process normal completions(error or sucess) and clean the schedule. 630 * Process normal completions(error or success) and clean the schedule.
631 * 631 *
632 * This is the main path for handing urbs back to drivers. The only other patth 632 * This is the main path for handing urbs back to drivers. The only other patth
633 * is process_del_list(),which unlinks URBs by scanning EDs,instead of scanning 633 * is process_del_list(),which unlinks URBs by scanning EDs,instead of scanning
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index b40332290319..57013479d7f7 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -18,6 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/slab.h>
21#include <linux/list.h> 22#include <linux/list.h>
22#include <linux/io.h> 23#include <linux/io.h>
23#include <linux/usb.h> 24#include <linux/usb.h>
@@ -105,34 +106,34 @@ void fhci_ep0_free(struct fhci_usb *usb)
105 if (ep->td_base) 106 if (ep->td_base)
106 cpm_muram_free(cpm_muram_offset(ep->td_base)); 107 cpm_muram_free(cpm_muram_offset(ep->td_base));
107 108
108 if (ep->conf_frame_Q) { 109 if (kfifo_initialized(&ep->conf_frame_Q)) {
109 size = cq_howmany(ep->conf_frame_Q); 110 size = cq_howmany(&ep->conf_frame_Q);
110 for (; size; size--) { 111 for (; size; size--) {
111 struct packet *pkt = cq_get(ep->conf_frame_Q); 112 struct packet *pkt = cq_get(&ep->conf_frame_Q);
112 113
113 kfree(pkt); 114 kfree(pkt);
114 } 115 }
115 cq_delete(ep->conf_frame_Q); 116 cq_delete(&ep->conf_frame_Q);
116 } 117 }
117 118
118 if (ep->empty_frame_Q) { 119 if (kfifo_initialized(&ep->empty_frame_Q)) {
119 size = cq_howmany(ep->empty_frame_Q); 120 size = cq_howmany(&ep->empty_frame_Q);
120 for (; size; size--) { 121 for (; size; size--) {
121 struct packet *pkt = cq_get(ep->empty_frame_Q); 122 struct packet *pkt = cq_get(&ep->empty_frame_Q);
122 123
123 kfree(pkt); 124 kfree(pkt);
124 } 125 }
125 cq_delete(ep->empty_frame_Q); 126 cq_delete(&ep->empty_frame_Q);
126 } 127 }
127 128
128 if (ep->dummy_packets_Q) { 129 if (kfifo_initialized(&ep->dummy_packets_Q)) {
129 size = cq_howmany(ep->dummy_packets_Q); 130 size = cq_howmany(&ep->dummy_packets_Q);
130 for (; size; size--) { 131 for (; size; size--) {
131 u8 *buff = cq_get(ep->dummy_packets_Q); 132 u8 *buff = cq_get(&ep->dummy_packets_Q);
132 133
133 kfree(buff); 134 kfree(buff);
134 } 135 }
135 cq_delete(ep->dummy_packets_Q); 136 cq_delete(&ep->dummy_packets_Q);
136 } 137 }
137 138
138 kfree(ep); 139 kfree(ep);
@@ -175,10 +176,9 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
175 ep->td_base = cpm_muram_addr(ep_offset); 176 ep->td_base = cpm_muram_addr(ep_offset);
176 177
177 /* zero all queue pointers */ 178 /* zero all queue pointers */
178 ep->conf_frame_Q = cq_new(ring_len + 2); 179 if (cq_new(&ep->conf_frame_Q, ring_len + 2) ||
179 ep->empty_frame_Q = cq_new(ring_len + 2); 180 cq_new(&ep->empty_frame_Q, ring_len + 2) ||
180 ep->dummy_packets_Q = cq_new(ring_len + 2); 181 cq_new(&ep->dummy_packets_Q, ring_len + 2)) {
181 if (!ep->conf_frame_Q || !ep->empty_frame_Q || !ep->dummy_packets_Q) {
182 err_for = "frame_queues"; 182 err_for = "frame_queues";
183 goto err; 183 goto err;
184 } 184 }
@@ -199,8 +199,8 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
199 err_for = "buffer"; 199 err_for = "buffer";
200 goto err; 200 goto err;
201 } 201 }
202 cq_put(ep->empty_frame_Q, pkt); 202 cq_put(&ep->empty_frame_Q, pkt);
203 cq_put(ep->dummy_packets_Q, buff); 203 cq_put(&ep->dummy_packets_Q, buff);
204 } 204 }
205 205
206 /* we put the endpoint parameter RAM right behind the TD ring */ 206 /* we put the endpoint parameter RAM right behind the TD ring */
@@ -319,7 +319,7 @@ static void fhci_td_transaction_confirm(struct fhci_usb *usb)
319 if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W)) 319 if ((buf == DUMMY2_BD_BUFFER) && !(td_status & ~TD_W))
320 continue; 320 continue;
321 321
322 pkt = cq_get(ep->conf_frame_Q); 322 pkt = cq_get(&ep->conf_frame_Q);
323 if (!pkt) 323 if (!pkt)
324 fhci_err(usb->fhci, "no frame to confirm\n"); 324 fhci_err(usb->fhci, "no frame to confirm\n");
325 325
@@ -460,9 +460,9 @@ u32 fhci_host_transaction(struct fhci_usb *usb,
460 out_be16(&td->length, pkt->len); 460 out_be16(&td->length, pkt->len);
461 461
462 /* put the frame to the confirmation queue */ 462 /* put the frame to the confirmation queue */
463 cq_put(ep->conf_frame_Q, pkt); 463 cq_put(&ep->conf_frame_Q, pkt);
464 464
465 if (cq_howmany(ep->conf_frame_Q) == 1) 465 if (cq_howmany(&ep->conf_frame_Q) == 1)
466 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO); 466 out_8(&usb->fhci->regs->usb_comm, USB_CMD_STR_FIFO);
467 467
468 return 0; 468 return 0;
diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index 7116284ed21a..72dae1c5ab38 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -423,9 +423,9 @@ struct endpoint {
423 struct usb_td __iomem *td_base; /* first TD in the ring */ 423 struct usb_td __iomem *td_base; /* first TD in the ring */
424 struct usb_td __iomem *conf_td; /* next TD for confirm after transac */ 424 struct usb_td __iomem *conf_td; /* next TD for confirm after transac */
425 struct usb_td __iomem *empty_td;/* next TD for new transaction req. */ 425 struct usb_td __iomem *empty_td;/* next TD for new transaction req. */
426 struct kfifo *empty_frame_Q; /* Empty frames list to use */ 426 struct kfifo empty_frame_Q; /* Empty frames list to use */
427 struct kfifo *conf_frame_Q; /* frames passed to TDs,waiting for tx */ 427 struct kfifo conf_frame_Q; /* frames passed to TDs,waiting for tx */
428 struct kfifo *dummy_packets_Q;/* dummy packets for the CRC overun */ 428 struct kfifo dummy_packets_Q;/* dummy packets for the CRC overun */
429 429
430 bool already_pushed_dummy_bd; 430 bool already_pushed_dummy_bd;
431}; 431};
@@ -493,9 +493,9 @@ static inline struct usb_hcd *fhci_to_hcd(struct fhci_hcd *fhci)
493} 493}
494 494
495/* fifo of pointers */ 495/* fifo of pointers */
496static inline struct kfifo *cq_new(int size) 496static inline int cq_new(struct kfifo *fifo, int size)
497{ 497{
498 return kfifo_alloc(size * sizeof(void *), GFP_KERNEL, NULL); 498 return kfifo_alloc(fifo, size * sizeof(void *), GFP_KERNEL);
499} 499}
500 500
501static inline void cq_delete(struct kfifo *kfifo) 501static inline void cq_delete(struct kfifo *kfifo)
@@ -505,19 +505,19 @@ static inline void cq_delete(struct kfifo *kfifo)
505 505
506static inline unsigned int cq_howmany(struct kfifo *kfifo) 506static inline unsigned int cq_howmany(struct kfifo *kfifo)
507{ 507{
508 return __kfifo_len(kfifo) / sizeof(void *); 508 return kfifo_len(kfifo) / sizeof(void *);
509} 509}
510 510
511static inline int cq_put(struct kfifo *kfifo, void *p) 511static inline int cq_put(struct kfifo *kfifo, void *p)
512{ 512{
513 return __kfifo_put(kfifo, (void *)&p, sizeof(p)); 513 return kfifo_in(kfifo, (void *)&p, sizeof(p));
514} 514}
515 515
516static inline void *cq_get(struct kfifo *kfifo) 516static inline void *cq_get(struct kfifo *kfifo)
517{ 517{
518 void *p = NULL; 518 void *p = NULL;
519 519
520 __kfifo_get(kfifo, (void *)&p, sizeof(p)); 520 kfifo_out(kfifo, (void *)&p, sizeof(p));
521 return p; 521 return p;
522} 522}
523 523
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 88b03214622b..35742f8c7cda 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -55,6 +55,7 @@
55 */ 55 */
56#include <linux/kernel.h> 56#include <linux/kernel.h>
57#include <linux/init.h> 57#include <linux/init.h>
58#include <linux/slab.h>
58#include <linux/module.h> 59#include <linux/module.h>
59#include <linux/workqueue.h> 60#include <linux/workqueue.h>
60#include <linux/wait.h> 61#include <linux/wait.h>
diff --git a/drivers/usb/host/imx21-dbg.c b/drivers/usb/host/imx21-dbg.c
new file mode 100644
index 000000000000..512f647448ca
--- /dev/null
+++ b/drivers/usb/host/imx21-dbg.c
@@ -0,0 +1,527 @@
1/*
2 * Copyright (c) 2009 by Martin Fuzzey
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* this file is part of imx21-hcd.c */
20
21#ifndef DEBUG
22
23static inline void create_debug_files(struct imx21 *imx21) { }
24static inline void remove_debug_files(struct imx21 *imx21) { }
25static inline void debug_urb_submitted(struct imx21 *imx21, struct urb *urb) {}
26static inline void debug_urb_completed(struct imx21 *imx21, struct urb *urb,
27 int status) {}
28static inline void debug_urb_unlinked(struct imx21 *imx21, struct urb *urb) {}
29static inline void debug_urb_queued_for_etd(struct imx21 *imx21,
30 struct urb *urb) {}
31static inline void debug_urb_queued_for_dmem(struct imx21 *imx21,
32 struct urb *urb) {}
33static inline void debug_etd_allocated(struct imx21 *imx21) {}
34static inline void debug_etd_freed(struct imx21 *imx21) {}
35static inline void debug_dmem_allocated(struct imx21 *imx21, int size) {}
36static inline void debug_dmem_freed(struct imx21 *imx21, int size) {}
37static inline void debug_isoc_submitted(struct imx21 *imx21,
38 int frame, struct td *td) {}
39static inline void debug_isoc_completed(struct imx21 *imx21,
40 int frame, struct td *td, int cc, int len) {}
41
42#else
43
44#include <linux/debugfs.h>
45#include <linux/seq_file.h>
46
47static const char *dir_labels[] = {
48 "TD 0",
49 "OUT",
50 "IN",
51 "TD 1"
52};
53
54static const char *speed_labels[] = {
55 "Full",
56 "Low"
57};
58
59static const char *format_labels[] = {
60 "Control",
61 "ISO",
62 "Bulk",
63 "Interrupt"
64};
65
66static inline struct debug_stats *stats_for_urb(struct imx21 *imx21,
67 struct urb *urb)
68{
69 return usb_pipeisoc(urb->pipe) ?
70 &imx21->isoc_stats : &imx21->nonisoc_stats;
71}
72
73static void debug_urb_submitted(struct imx21 *imx21, struct urb *urb)
74{
75 stats_for_urb(imx21, urb)->submitted++;
76}
77
78static void debug_urb_completed(struct imx21 *imx21, struct urb *urb, int st)
79{
80 if (st)
81 stats_for_urb(imx21, urb)->completed_failed++;
82 else
83 stats_for_urb(imx21, urb)->completed_ok++;
84}
85
86static void debug_urb_unlinked(struct imx21 *imx21, struct urb *urb)
87{
88 stats_for_urb(imx21, urb)->unlinked++;
89}
90
91static void debug_urb_queued_for_etd(struct imx21 *imx21, struct urb *urb)
92{
93 stats_for_urb(imx21, urb)->queue_etd++;
94}
95
96static void debug_urb_queued_for_dmem(struct imx21 *imx21, struct urb *urb)
97{
98 stats_for_urb(imx21, urb)->queue_dmem++;
99}
100
101static inline void debug_etd_allocated(struct imx21 *imx21)
102{
103 imx21->etd_usage.maximum = max(
104 ++(imx21->etd_usage.value),
105 imx21->etd_usage.maximum);
106}
107
108static inline void debug_etd_freed(struct imx21 *imx21)
109{
110 imx21->etd_usage.value--;
111}
112
113static inline void debug_dmem_allocated(struct imx21 *imx21, int size)
114{
115 imx21->dmem_usage.value += size;
116 imx21->dmem_usage.maximum = max(
117 imx21->dmem_usage.value,
118 imx21->dmem_usage.maximum);
119}
120
121static inline void debug_dmem_freed(struct imx21 *imx21, int size)
122{
123 imx21->dmem_usage.value -= size;
124}
125
126
127static void debug_isoc_submitted(struct imx21 *imx21,
128 int frame, struct td *td)
129{
130 struct debug_isoc_trace *trace = &imx21->isoc_trace[
131 imx21->isoc_trace_index++];
132
133 imx21->isoc_trace_index %= ARRAY_SIZE(imx21->isoc_trace);
134 trace->schedule_frame = td->frame;
135 trace->submit_frame = frame;
136 trace->request_len = td->len;
137 trace->td = td;
138}
139
140static inline void debug_isoc_completed(struct imx21 *imx21,
141 int frame, struct td *td, int cc, int len)
142{
143 struct debug_isoc_trace *trace, *trace_failed;
144 int i;
145 int found = 0;
146
147 trace = imx21->isoc_trace;
148 for (i = 0; i < ARRAY_SIZE(imx21->isoc_trace); i++, trace++) {
149 if (trace->td == td) {
150 trace->done_frame = frame;
151 trace->done_len = len;
152 trace->cc = cc;
153 trace->td = NULL;
154 found = 1;
155 break;
156 }
157 }
158
159 if (found && cc) {
160 trace_failed = &imx21->isoc_trace_failed[
161 imx21->isoc_trace_index_failed++];
162
163 imx21->isoc_trace_index_failed %= ARRAY_SIZE(
164 imx21->isoc_trace_failed);
165 *trace_failed = *trace;
166 }
167}
168
169
170static char *format_ep(struct usb_host_endpoint *ep, char *buf, int bufsize)
171{
172 if (ep)
173 snprintf(buf, bufsize, "ep_%02x (type:%02X kaddr:%p)",
174 ep->desc.bEndpointAddress,
175 usb_endpoint_type(&ep->desc),
176 ep);
177 else
178 snprintf(buf, bufsize, "none");
179 return buf;
180}
181
182static char *format_etd_dword0(u32 value, char *buf, int bufsize)
183{
184 snprintf(buf, bufsize,
185 "addr=%d ep=%d dir=%s speed=%s format=%s halted=%d",
186 value & 0x7F,
187 (value >> DW0_ENDPNT) & 0x0F,
188 dir_labels[(value >> DW0_DIRECT) & 0x03],
189 speed_labels[(value >> DW0_SPEED) & 0x01],
190 format_labels[(value >> DW0_FORMAT) & 0x03],
191 (value >> DW0_HALTED) & 0x01);
192 return buf;
193}
194
195static int debug_status_show(struct seq_file *s, void *v)
196{
197 struct imx21 *imx21 = s->private;
198 int etds_allocated = 0;
199 int etds_sw_busy = 0;
200 int etds_hw_busy = 0;
201 int dmem_blocks = 0;
202 int queued_for_etd = 0;
203 int queued_for_dmem = 0;
204 unsigned int dmem_bytes = 0;
205 int i;
206 struct etd_priv *etd;
207 u32 etd_enable_mask;
208 unsigned long flags;
209 struct imx21_dmem_area *dmem;
210 struct ep_priv *ep_priv;
211
212 spin_lock_irqsave(&imx21->lock, flags);
213
214 etd_enable_mask = readl(imx21->regs + USBH_ETDENSET);
215 for (i = 0, etd = imx21->etd; i < USB_NUM_ETD; i++, etd++) {
216 if (etd->alloc)
217 etds_allocated++;
218 if (etd->urb)
219 etds_sw_busy++;
220 if (etd_enable_mask & (1<<i))
221 etds_hw_busy++;
222 }
223
224 list_for_each_entry(dmem, &imx21->dmem_list, list) {
225 dmem_bytes += dmem->size;
226 dmem_blocks++;
227 }
228
229 list_for_each_entry(ep_priv, &imx21->queue_for_etd, queue)
230 queued_for_etd++;
231
232 list_for_each_entry(etd, &imx21->queue_for_dmem, queue)
233 queued_for_dmem++;
234
235 spin_unlock_irqrestore(&imx21->lock, flags);
236
237 seq_printf(s,
238 "Frame: %d\n"
239 "ETDs allocated: %d/%d (max=%d)\n"
240 "ETDs in use sw: %d\n"
241 "ETDs in use hw: %d\n"
242 "DMEM alocated: %d/%d (max=%d)\n"
243 "DMEM blocks: %d\n"
244 "Queued waiting for ETD: %d\n"
245 "Queued waiting for DMEM: %d\n",
246 readl(imx21->regs + USBH_FRMNUB) & 0xFFFF,
247 etds_allocated, USB_NUM_ETD, imx21->etd_usage.maximum,
248 etds_sw_busy,
249 etds_hw_busy,
250 dmem_bytes, DMEM_SIZE, imx21->dmem_usage.maximum,
251 dmem_blocks,
252 queued_for_etd,
253 queued_for_dmem);
254
255 return 0;
256}
257
258static int debug_dmem_show(struct seq_file *s, void *v)
259{
260 struct imx21 *imx21 = s->private;
261 struct imx21_dmem_area *dmem;
262 unsigned long flags;
263 char ep_text[40];
264
265 spin_lock_irqsave(&imx21->lock, flags);
266
267 list_for_each_entry(dmem, &imx21->dmem_list, list)
268 seq_printf(s,
269 "%04X: size=0x%X "
270 "ep=%s\n",
271 dmem->offset, dmem->size,
272 format_ep(dmem->ep, ep_text, sizeof(ep_text)));
273
274 spin_unlock_irqrestore(&imx21->lock, flags);
275
276 return 0;
277}
278
279static int debug_etd_show(struct seq_file *s, void *v)
280{
281 struct imx21 *imx21 = s->private;
282 struct etd_priv *etd;
283 char buf[60];
284 u32 dword;
285 int i, j;
286 unsigned long flags;
287
288 spin_lock_irqsave(&imx21->lock, flags);
289
290 for (i = 0, etd = imx21->etd; i < USB_NUM_ETD; i++, etd++) {
291 int state = -1;
292 struct urb_priv *urb_priv;
293 if (etd->urb) {
294 urb_priv = etd->urb->hcpriv;
295 if (urb_priv)
296 state = urb_priv->state;
297 }
298
299 seq_printf(s,
300 "etd_num: %d\n"
301 "ep: %s\n"
302 "alloc: %d\n"
303 "len: %d\n"
304 "busy sw: %d\n"
305 "busy hw: %d\n"
306 "urb state: %d\n"
307 "current urb: %p\n",
308
309 i,
310 format_ep(etd->ep, buf, sizeof(buf)),
311 etd->alloc,
312 etd->len,
313 etd->urb != NULL,
314 (readl(imx21->regs + USBH_ETDENSET) & (1 << i)) > 0,
315 state,
316 etd->urb);
317
318 for (j = 0; j < 4; j++) {
319 dword = etd_readl(imx21, i, j);
320 switch (j) {
321 case 0:
322 format_etd_dword0(dword, buf, sizeof(buf));
323 break;
324 case 2:
325 snprintf(buf, sizeof(buf),
326 "cc=0X%02X", dword >> DW2_COMPCODE);
327 break;
328 default:
329 *buf = 0;
330 break;
331 }
332 seq_printf(s,
333 "dword %d: submitted=%08X cur=%08X [%s]\n",
334 j,
335 etd->submitted_dwords[j],
336 dword,
337 buf);
338 }
339 seq_printf(s, "\n");
340 }
341
342 spin_unlock_irqrestore(&imx21->lock, flags);
343
344 return 0;
345}
346
347static void debug_statistics_show_one(struct seq_file *s,
348 const char *name, struct debug_stats *stats)
349{
350 seq_printf(s, "%s:\n"
351 "submitted URBs: %lu\n"
352 "completed OK: %lu\n"
353 "completed failed: %lu\n"
354 "unlinked: %lu\n"
355 "queued for ETD: %lu\n"
356 "queued for DMEM: %lu\n\n",
357 name,
358 stats->submitted,
359 stats->completed_ok,
360 stats->completed_failed,
361 stats->unlinked,
362 stats->queue_etd,
363 stats->queue_dmem);
364}
365
366static int debug_statistics_show(struct seq_file *s, void *v)
367{
368 struct imx21 *imx21 = s->private;
369 unsigned long flags;
370
371 spin_lock_irqsave(&imx21->lock, flags);
372
373 debug_statistics_show_one(s, "nonisoc", &imx21->nonisoc_stats);
374 debug_statistics_show_one(s, "isoc", &imx21->isoc_stats);
375 seq_printf(s, "unblock kludge triggers: %lu\n", imx21->debug_unblocks);
376 spin_unlock_irqrestore(&imx21->lock, flags);
377
378 return 0;
379}
380
381static void debug_isoc_show_one(struct seq_file *s,
382 const char *name, int index, struct debug_isoc_trace *trace)
383{
384 seq_printf(s, "%s %d:\n"
385 "cc=0X%02X\n"
386 "scheduled frame %d (%d)\n"
387 "submittted frame %d (%d)\n"
388 "completed frame %d (%d)\n"
389 "requested length=%d\n"
390 "completed length=%d\n\n",
391 name, index,
392 trace->cc,
393 trace->schedule_frame, trace->schedule_frame & 0xFFFF,
394 trace->submit_frame, trace->submit_frame & 0xFFFF,
395 trace->done_frame, trace->done_frame & 0xFFFF,
396 trace->request_len,
397 trace->done_len);
398}
399
400static int debug_isoc_show(struct seq_file *s, void *v)
401{
402 struct imx21 *imx21 = s->private;
403 struct debug_isoc_trace *trace;
404 unsigned long flags;
405 int i;
406
407 spin_lock_irqsave(&imx21->lock, flags);
408
409 trace = imx21->isoc_trace_failed;
410 for (i = 0; i < ARRAY_SIZE(imx21->isoc_trace_failed); i++, trace++)
411 debug_isoc_show_one(s, "isoc failed", i, trace);
412
413 trace = imx21->isoc_trace;
414 for (i = 0; i < ARRAY_SIZE(imx21->isoc_trace); i++, trace++)
415 debug_isoc_show_one(s, "isoc", i, trace);
416
417 spin_unlock_irqrestore(&imx21->lock, flags);
418
419 return 0;
420}
421
422static int debug_status_open(struct inode *inode, struct file *file)
423{
424 return single_open(file, debug_status_show, inode->i_private);
425}
426
427static int debug_dmem_open(struct inode *inode, struct file *file)
428{
429 return single_open(file, debug_dmem_show, inode->i_private);
430}
431
432static int debug_etd_open(struct inode *inode, struct file *file)
433{
434 return single_open(file, debug_etd_show, inode->i_private);
435}
436
437static int debug_statistics_open(struct inode *inode, struct file *file)
438{
439 return single_open(file, debug_statistics_show, inode->i_private);
440}
441
442static int debug_isoc_open(struct inode *inode, struct file *file)
443{
444 return single_open(file, debug_isoc_show, inode->i_private);
445}
446
447static const struct file_operations debug_status_fops = {
448 .open = debug_status_open,
449 .read = seq_read,
450 .llseek = seq_lseek,
451 .release = single_release,
452};
453
454static const struct file_operations debug_dmem_fops = {
455 .open = debug_dmem_open,
456 .read = seq_read,
457 .llseek = seq_lseek,
458 .release = single_release,
459};
460
461static const struct file_operations debug_etd_fops = {
462 .open = debug_etd_open,
463 .read = seq_read,
464 .llseek = seq_lseek,
465 .release = single_release,
466};
467
468static const struct file_operations debug_statistics_fops = {
469 .open = debug_statistics_open,
470 .read = seq_read,
471 .llseek = seq_lseek,
472 .release = single_release,
473};
474
475static const struct file_operations debug_isoc_fops = {
476 .open = debug_isoc_open,
477 .read = seq_read,
478 .llseek = seq_lseek,
479 .release = single_release,
480};
481
482static void create_debug_files(struct imx21 *imx21)
483{
484 imx21->debug_root = debugfs_create_dir(dev_name(imx21->dev), NULL);
485 if (!imx21->debug_root)
486 goto failed_create_rootdir;
487
488 if (!debugfs_create_file("status", S_IRUGO,
489 imx21->debug_root, imx21, &debug_status_fops))
490 goto failed_create;
491
492 if (!debugfs_create_file("dmem", S_IRUGO,
493 imx21->debug_root, imx21, &debug_dmem_fops))
494 goto failed_create;
495
496 if (!debugfs_create_file("etd", S_IRUGO,
497 imx21->debug_root, imx21, &debug_etd_fops))
498 goto failed_create;
499
500 if (!debugfs_create_file("statistics", S_IRUGO,
501 imx21->debug_root, imx21, &debug_statistics_fops))
502 goto failed_create;
503
504 if (!debugfs_create_file("isoc", S_IRUGO,
505 imx21->debug_root, imx21, &debug_isoc_fops))
506 goto failed_create;
507
508 return;
509
510failed_create:
511 debugfs_remove_recursive(imx21->debug_root);
512
513failed_create_rootdir:
514 imx21->debug_root = NULL;
515}
516
517
518static void remove_debug_files(struct imx21 *imx21)
519{
520 if (imx21->debug_root) {
521 debugfs_remove_recursive(imx21->debug_root);
522 imx21->debug_root = NULL;
523 }
524}
525
526#endif
527
diff --git a/drivers/usb/host/imx21-hcd.c b/drivers/usb/host/imx21-hcd.c
new file mode 100644
index 000000000000..8a12f297645f
--- /dev/null
+++ b/drivers/usb/host/imx21-hcd.c
@@ -0,0 +1,1790 @@
1/*
2 * USB Host Controller Driver for IMX21
3 *
4 * Copyright (C) 2006 Loping Dog Embedded Systems
5 * Copyright (C) 2009 Martin Fuzzey
6 * Originally written by Jay Monkman <jtm@lopingdog.com>
7 * Ported to 2.6.30, debugged and enhanced by Martin Fuzzey
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24
25 /*
26 * The i.MX21 USB hardware contains
27 * * 32 transfer descriptors (called ETDs)
28 * * 4Kb of Data memory
29 *
30 * The data memory is shared between the host and fuction controlers
31 * (but this driver only supports the host controler)
32 *
33 * So setting up a transfer involves:
34 * * Allocating a ETD
35 * * Fill in ETD with appropriate information
36 * * Allocating data memory (and putting the offset in the ETD)
37 * * Activate the ETD
38 * * Get interrupt when done.
39 *
40 * An ETD is assigned to each active endpoint.
41 *
42 * Low resource (ETD and Data memory) situations are handled differently for
43 * isochronous and non insosynchronous transactions :
44 *
45 * Non ISOC transfers are queued if either ETDs or Data memory are unavailable
46 *
47 * ISOC transfers use 2 ETDs per endpoint to achieve double buffering.
48 * They allocate both ETDs and Data memory during URB submission
49 * (and fail if unavailable).
50 */
51
52#include <linux/clk.h>
53#include <linux/io.h>
54#include <linux/kernel.h>
55#include <linux/list.h>
56#include <linux/platform_device.h>
57#include <linux/slab.h>
58#include <linux/usb.h>
59
60#include "../core/hcd.h"
61#include "imx21-hcd.h"
62
63#ifdef DEBUG
64#define DEBUG_LOG_FRAME(imx21, etd, event) \
65 (etd)->event##_frame = readl((imx21)->regs + USBH_FRMNUB)
66#else
67#define DEBUG_LOG_FRAME(imx21, etd, event) do { } while (0)
68#endif
69
70static const char hcd_name[] = "imx21-hcd";
71
72static inline struct imx21 *hcd_to_imx21(struct usb_hcd *hcd)
73{
74 return (struct imx21 *)hcd->hcd_priv;
75}
76
77
78/* =========================================== */
79/* Hardware access helpers */
80/* =========================================== */
81
82static inline void set_register_bits(struct imx21 *imx21, u32 offset, u32 mask)
83{
84 void __iomem *reg = imx21->regs + offset;
85 writel(readl(reg) | mask, reg);
86}
87
88static inline void clear_register_bits(struct imx21 *imx21,
89 u32 offset, u32 mask)
90{
91 void __iomem *reg = imx21->regs + offset;
92 writel(readl(reg) & ~mask, reg);
93}
94
95static inline void clear_toggle_bit(struct imx21 *imx21, u32 offset, u32 mask)
96{
97 void __iomem *reg = imx21->regs + offset;
98
99 if (readl(reg) & mask)
100 writel(mask, reg);
101}
102
103static inline void set_toggle_bit(struct imx21 *imx21, u32 offset, u32 mask)
104{
105 void __iomem *reg = imx21->regs + offset;
106
107 if (!(readl(reg) & mask))
108 writel(mask, reg);
109}
110
111static void etd_writel(struct imx21 *imx21, int etd_num, int dword, u32 value)
112{
113 writel(value, imx21->regs + USB_ETD_DWORD(etd_num, dword));
114}
115
116static u32 etd_readl(struct imx21 *imx21, int etd_num, int dword)
117{
118 return readl(imx21->regs + USB_ETD_DWORD(etd_num, dword));
119}
120
121static inline int wrap_frame(int counter)
122{
123 return counter & 0xFFFF;
124}
125
126static inline int frame_after(int frame, int after)
127{
128 /* handle wrapping like jiffies time_afer */
129 return (s16)((s16)after - (s16)frame) < 0;
130}
131
132static int imx21_hc_get_frame(struct usb_hcd *hcd)
133{
134 struct imx21 *imx21 = hcd_to_imx21(hcd);
135
136 return wrap_frame(readl(imx21->regs + USBH_FRMNUB));
137}
138
139
140#include "imx21-dbg.c"
141
142/* =========================================== */
143/* ETD management */
144/* =========================================== */
145
146static int alloc_etd(struct imx21 *imx21)
147{
148 int i;
149 struct etd_priv *etd = imx21->etd;
150
151 for (i = 0; i < USB_NUM_ETD; i++, etd++) {
152 if (etd->alloc == 0) {
153 memset(etd, 0, sizeof(imx21->etd[0]));
154 etd->alloc = 1;
155 debug_etd_allocated(imx21);
156 return i;
157 }
158 }
159 return -1;
160}
161
162static void disactivate_etd(struct imx21 *imx21, int num)
163{
164 int etd_mask = (1 << num);
165 struct etd_priv *etd = &imx21->etd[num];
166
167 writel(etd_mask, imx21->regs + USBH_ETDENCLR);
168 clear_register_bits(imx21, USBH_ETDDONEEN, etd_mask);
169 writel(etd_mask, imx21->regs + USB_ETDDMACHANLCLR);
170 clear_toggle_bit(imx21, USBH_ETDDONESTAT, etd_mask);
171
172 etd->active_count = 0;
173
174 DEBUG_LOG_FRAME(imx21, etd, disactivated);
175}
176
177static void reset_etd(struct imx21 *imx21, int num)
178{
179 struct etd_priv *etd = imx21->etd + num;
180 int i;
181
182 disactivate_etd(imx21, num);
183
184 for (i = 0; i < 4; i++)
185 etd_writel(imx21, num, i, 0);
186 etd->urb = NULL;
187 etd->ep = NULL;
188 etd->td = NULL;;
189}
190
191static void free_etd(struct imx21 *imx21, int num)
192{
193 if (num < 0)
194 return;
195
196 if (num >= USB_NUM_ETD) {
197 dev_err(imx21->dev, "BAD etd=%d!\n", num);
198 return;
199 }
200 if (imx21->etd[num].alloc == 0) {
201 dev_err(imx21->dev, "ETD %d already free!\n", num);
202 return;
203 }
204
205 debug_etd_freed(imx21);
206 reset_etd(imx21, num);
207 memset(&imx21->etd[num], 0, sizeof(imx21->etd[0]));
208}
209
210
211static void setup_etd_dword0(struct imx21 *imx21,
212 int etd_num, struct urb *urb, u8 dir, u16 maxpacket)
213{
214 etd_writel(imx21, etd_num, 0,
215 ((u32) usb_pipedevice(urb->pipe)) << DW0_ADDRESS |
216 ((u32) usb_pipeendpoint(urb->pipe) << DW0_ENDPNT) |
217 ((u32) dir << DW0_DIRECT) |
218 ((u32) ((urb->dev->speed == USB_SPEED_LOW) ?
219 1 : 0) << DW0_SPEED) |
220 ((u32) fmt_urb_to_etd[usb_pipetype(urb->pipe)] << DW0_FORMAT) |
221 ((u32) maxpacket << DW0_MAXPKTSIZ));
222}
223
224static void activate_etd(struct imx21 *imx21,
225 int etd_num, dma_addr_t dma, u8 dir)
226{
227 u32 etd_mask = 1 << etd_num;
228 struct etd_priv *etd = &imx21->etd[etd_num];
229
230 clear_toggle_bit(imx21, USBH_ETDDONESTAT, etd_mask);
231 set_register_bits(imx21, USBH_ETDDONEEN, etd_mask);
232 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
233 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
234
235 if (dma) {
236 set_register_bits(imx21, USB_ETDDMACHANLCLR, etd_mask);
237 clear_toggle_bit(imx21, USBH_XBUFSTAT, etd_mask);
238 clear_toggle_bit(imx21, USBH_YBUFSTAT, etd_mask);
239 writel(dma, imx21->regs + USB_ETDSMSA(etd_num));
240 set_register_bits(imx21, USB_ETDDMAEN, etd_mask);
241 } else {
242 if (dir != TD_DIR_IN) {
243 /* need to set for ZLP */
244 set_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
245 set_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
246 }
247 }
248
249 DEBUG_LOG_FRAME(imx21, etd, activated);
250
251#ifdef DEBUG
252 if (!etd->active_count) {
253 int i;
254 etd->activated_frame = readl(imx21->regs + USBH_FRMNUB);
255 etd->disactivated_frame = -1;
256 etd->last_int_frame = -1;
257 etd->last_req_frame = -1;
258
259 for (i = 0; i < 4; i++)
260 etd->submitted_dwords[i] = etd_readl(imx21, etd_num, i);
261 }
262#endif
263
264 etd->active_count = 1;
265 writel(etd_mask, imx21->regs + USBH_ETDENSET);
266}
267
268/* =========================================== */
269/* Data memory management */
270/* =========================================== */
271
272static int alloc_dmem(struct imx21 *imx21, unsigned int size,
273 struct usb_host_endpoint *ep)
274{
275 unsigned int offset = 0;
276 struct imx21_dmem_area *area;
277 struct imx21_dmem_area *tmp;
278
279 size += (~size + 1) & 0x3; /* Round to 4 byte multiple */
280
281 if (size > DMEM_SIZE) {
282 dev_err(imx21->dev, "size=%d > DMEM_SIZE(%d)\n",
283 size, DMEM_SIZE);
284 return -EINVAL;
285 }
286
287 list_for_each_entry(tmp, &imx21->dmem_list, list) {
288 if ((size + offset) < offset)
289 goto fail;
290 if ((size + offset) <= tmp->offset)
291 break;
292 offset = tmp->size + tmp->offset;
293 if ((offset + size) > DMEM_SIZE)
294 goto fail;
295 }
296
297 area = kmalloc(sizeof(struct imx21_dmem_area), GFP_ATOMIC);
298 if (area == NULL)
299 return -ENOMEM;
300
301 area->ep = ep;
302 area->offset = offset;
303 area->size = size;
304 list_add_tail(&area->list, &tmp->list);
305 debug_dmem_allocated(imx21, size);
306 return offset;
307
308fail:
309 return -ENOMEM;
310}
311
312/* Memory now available for a queued ETD - activate it */
313static void activate_queued_etd(struct imx21 *imx21,
314 struct etd_priv *etd, u32 dmem_offset)
315{
316 struct urb_priv *urb_priv = etd->urb->hcpriv;
317 int etd_num = etd - &imx21->etd[0];
318 u32 maxpacket = etd_readl(imx21, etd_num, 1) >> DW1_YBUFSRTAD;
319 u8 dir = (etd_readl(imx21, etd_num, 2) >> DW2_DIRPID) & 0x03;
320
321 dev_dbg(imx21->dev, "activating queued ETD %d now DMEM available\n",
322 etd_num);
323 etd_writel(imx21, etd_num, 1,
324 ((dmem_offset + maxpacket) << DW1_YBUFSRTAD) | dmem_offset);
325
326 urb_priv->active = 1;
327 activate_etd(imx21, etd_num, etd->dma_handle, dir);
328}
329
330static void free_dmem(struct imx21 *imx21, int offset)
331{
332 struct imx21_dmem_area *area;
333 struct etd_priv *etd, *tmp;
334 int found = 0;
335
336 list_for_each_entry(area, &imx21->dmem_list, list) {
337 if (area->offset == offset) {
338 debug_dmem_freed(imx21, area->size);
339 list_del(&area->list);
340 kfree(area);
341 found = 1;
342 break;
343 }
344 }
345
346 if (!found) {
347 dev_err(imx21->dev,
348 "Trying to free unallocated DMEM %d\n", offset);
349 return;
350 }
351
352 /* Try again to allocate memory for anything we've queued */
353 list_for_each_entry_safe(etd, tmp, &imx21->queue_for_dmem, queue) {
354 offset = alloc_dmem(imx21, etd->dmem_size, etd->ep);
355 if (offset >= 0) {
356 list_del(&etd->queue);
357 activate_queued_etd(imx21, etd, (u32)offset);
358 }
359 }
360}
361
362static void free_epdmem(struct imx21 *imx21, struct usb_host_endpoint *ep)
363{
364 struct imx21_dmem_area *area, *tmp;
365
366 list_for_each_entry_safe(area, tmp, &imx21->dmem_list, list) {
367 if (area->ep == ep) {
368 dev_err(imx21->dev,
369 "Active DMEM %d for disabled ep=%p\n",
370 area->offset, ep);
371 list_del(&area->list);
372 kfree(area);
373 }
374 }
375}
376
377
378/* =========================================== */
379/* End handling */
380/* =========================================== */
381static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb);
382
383/* Endpoint now idle - release it's ETD(s) or asssign to queued request */
384static void ep_idle(struct imx21 *imx21, struct ep_priv *ep_priv)
385{
386 int etd_num;
387 int i;
388
389 for (i = 0; i < NUM_ISO_ETDS; i++) {
390 etd_num = ep_priv->etd[i];
391 if (etd_num < 0)
392 continue;
393
394 ep_priv->etd[i] = -1;
395 if (list_empty(&imx21->queue_for_etd)) {
396 free_etd(imx21, etd_num);
397 continue;
398 }
399
400 dev_dbg(imx21->dev,
401 "assigning idle etd %d for queued request\n", etd_num);
402 ep_priv = list_first_entry(&imx21->queue_for_etd,
403 struct ep_priv, queue);
404 list_del(&ep_priv->queue);
405 reset_etd(imx21, etd_num);
406 ep_priv->waiting_etd = 0;
407 ep_priv->etd[i] = etd_num;
408
409 if (list_empty(&ep_priv->ep->urb_list)) {
410 dev_err(imx21->dev, "No urb for queued ep!\n");
411 continue;
412 }
413 schedule_nonisoc_etd(imx21, list_first_entry(
414 &ep_priv->ep->urb_list, struct urb, urb_list));
415 }
416}
417
418static void urb_done(struct usb_hcd *hcd, struct urb *urb, int status)
419__releases(imx21->lock)
420__acquires(imx21->lock)
421{
422 struct imx21 *imx21 = hcd_to_imx21(hcd);
423 struct ep_priv *ep_priv = urb->ep->hcpriv;
424 struct urb_priv *urb_priv = urb->hcpriv;
425
426 debug_urb_completed(imx21, urb, status);
427 dev_vdbg(imx21->dev, "urb %p done %d\n", urb, status);
428
429 kfree(urb_priv->isoc_td);
430 kfree(urb->hcpriv);
431 urb->hcpriv = NULL;
432 usb_hcd_unlink_urb_from_ep(hcd, urb);
433 spin_unlock(&imx21->lock);
434 usb_hcd_giveback_urb(hcd, urb, status);
435 spin_lock(&imx21->lock);
436 if (list_empty(&ep_priv->ep->urb_list))
437 ep_idle(imx21, ep_priv);
438}
439
440/* =========================================== */
441/* ISOC Handling ... */
442/* =========================================== */
443
444static void schedule_isoc_etds(struct usb_hcd *hcd,
445 struct usb_host_endpoint *ep)
446{
447 struct imx21 *imx21 = hcd_to_imx21(hcd);
448 struct ep_priv *ep_priv = ep->hcpriv;
449 struct etd_priv *etd;
450 struct urb_priv *urb_priv;
451 struct td *td;
452 int etd_num;
453 int i;
454 int cur_frame;
455 u8 dir;
456
457 for (i = 0; i < NUM_ISO_ETDS; i++) {
458too_late:
459 if (list_empty(&ep_priv->td_list))
460 break;
461
462 etd_num = ep_priv->etd[i];
463 if (etd_num < 0)
464 break;
465
466 etd = &imx21->etd[etd_num];
467 if (etd->urb)
468 continue;
469
470 td = list_entry(ep_priv->td_list.next, struct td, list);
471 list_del(&td->list);
472 urb_priv = td->urb->hcpriv;
473
474 cur_frame = imx21_hc_get_frame(hcd);
475 if (frame_after(cur_frame, td->frame)) {
476 dev_dbg(imx21->dev, "isoc too late frame %d > %d\n",
477 cur_frame, td->frame);
478 urb_priv->isoc_status = -EXDEV;
479 td->urb->iso_frame_desc[
480 td->isoc_index].actual_length = 0;
481 td->urb->iso_frame_desc[td->isoc_index].status = -EXDEV;
482 if (--urb_priv->isoc_remaining == 0)
483 urb_done(hcd, td->urb, urb_priv->isoc_status);
484 goto too_late;
485 }
486
487 urb_priv->active = 1;
488 etd->td = td;
489 etd->ep = td->ep;
490 etd->urb = td->urb;
491 etd->len = td->len;
492
493 debug_isoc_submitted(imx21, cur_frame, td);
494
495 dir = usb_pipeout(td->urb->pipe) ? TD_DIR_OUT : TD_DIR_IN;
496 setup_etd_dword0(imx21, etd_num, td->urb, dir, etd->dmem_size);
497 etd_writel(imx21, etd_num, 1, etd->dmem_offset);
498 etd_writel(imx21, etd_num, 2,
499 (TD_NOTACCESSED << DW2_COMPCODE) |
500 ((td->frame & 0xFFFF) << DW2_STARTFRM));
501 etd_writel(imx21, etd_num, 3,
502 (TD_NOTACCESSED << DW3_COMPCODE0) |
503 (td->len << DW3_PKTLEN0));
504
505 activate_etd(imx21, etd_num, td->data, dir);
506 }
507}
508
509static void isoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
510{
511 struct imx21 *imx21 = hcd_to_imx21(hcd);
512 int etd_mask = 1 << etd_num;
513 struct urb_priv *urb_priv = urb->hcpriv;
514 struct etd_priv *etd = imx21->etd + etd_num;
515 struct td *td = etd->td;
516 struct usb_host_endpoint *ep = etd->ep;
517 int isoc_index = td->isoc_index;
518 unsigned int pipe = urb->pipe;
519 int dir_in = usb_pipein(pipe);
520 int cc;
521 int bytes_xfrd;
522
523 disactivate_etd(imx21, etd_num);
524
525 cc = (etd_readl(imx21, etd_num, 3) >> DW3_COMPCODE0) & 0xf;
526 bytes_xfrd = etd_readl(imx21, etd_num, 3) & 0x3ff;
527
528 /* Input doesn't always fill the buffer, don't generate an error
529 * when this happens.
530 */
531 if (dir_in && (cc == TD_DATAUNDERRUN))
532 cc = TD_CC_NOERROR;
533
534 if (cc == TD_NOTACCESSED)
535 bytes_xfrd = 0;
536
537 debug_isoc_completed(imx21,
538 imx21_hc_get_frame(hcd), td, cc, bytes_xfrd);
539 if (cc) {
540 urb_priv->isoc_status = -EXDEV;
541 dev_dbg(imx21->dev,
542 "bad iso cc=0x%X frame=%d sched frame=%d "
543 "cnt=%d len=%d urb=%p etd=%d index=%d\n",
544 cc, imx21_hc_get_frame(hcd), td->frame,
545 bytes_xfrd, td->len, urb, etd_num, isoc_index);
546 }
547
548 if (dir_in)
549 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
550
551 urb->actual_length += bytes_xfrd;
552 urb->iso_frame_desc[isoc_index].actual_length = bytes_xfrd;
553 urb->iso_frame_desc[isoc_index].status = cc_to_error[cc];
554
555 etd->td = NULL;
556 etd->urb = NULL;
557 etd->ep = NULL;
558
559 if (--urb_priv->isoc_remaining == 0)
560 urb_done(hcd, urb, urb_priv->isoc_status);
561
562 schedule_isoc_etds(hcd, ep);
563}
564
565static struct ep_priv *alloc_isoc_ep(
566 struct imx21 *imx21, struct usb_host_endpoint *ep)
567{
568 struct ep_priv *ep_priv;
569 int i;
570
571 ep_priv = kzalloc(sizeof(struct ep_priv), GFP_ATOMIC);
572 if (ep_priv == NULL)
573 return NULL;
574
575 /* Allocate the ETDs */
576 for (i = 0; i < NUM_ISO_ETDS; i++) {
577 ep_priv->etd[i] = alloc_etd(imx21);
578 if (ep_priv->etd[i] < 0) {
579 int j;
580 dev_err(imx21->dev, "isoc: Couldn't allocate etd\n");
581 for (j = 0; j < i; j++)
582 free_etd(imx21, ep_priv->etd[j]);
583 goto alloc_etd_failed;
584 }
585 imx21->etd[ep_priv->etd[i]].ep = ep;
586 }
587
588 INIT_LIST_HEAD(&ep_priv->td_list);
589 ep_priv->ep = ep;
590 ep->hcpriv = ep_priv;
591 return ep_priv;
592
593alloc_etd_failed:
594 kfree(ep_priv);
595 return NULL;
596}
597
598static int imx21_hc_urb_enqueue_isoc(struct usb_hcd *hcd,
599 struct usb_host_endpoint *ep,
600 struct urb *urb, gfp_t mem_flags)
601{
602 struct imx21 *imx21 = hcd_to_imx21(hcd);
603 struct urb_priv *urb_priv;
604 unsigned long flags;
605 struct ep_priv *ep_priv;
606 struct td *td = NULL;
607 int i;
608 int ret;
609 int cur_frame;
610 u16 maxpacket;
611
612 urb_priv = kzalloc(sizeof(struct urb_priv), mem_flags);
613 if (urb_priv == NULL)
614 return -ENOMEM;
615
616 urb_priv->isoc_td = kzalloc(
617 sizeof(struct td) * urb->number_of_packets, mem_flags);
618 if (urb_priv->isoc_td == NULL) {
619 ret = -ENOMEM;
620 goto alloc_td_failed;
621 }
622
623 spin_lock_irqsave(&imx21->lock, flags);
624
625 if (ep->hcpriv == NULL) {
626 ep_priv = alloc_isoc_ep(imx21, ep);
627 if (ep_priv == NULL) {
628 ret = -ENOMEM;
629 goto alloc_ep_failed;
630 }
631 } else {
632 ep_priv = ep->hcpriv;
633 }
634
635 ret = usb_hcd_link_urb_to_ep(hcd, urb);
636 if (ret)
637 goto link_failed;
638
639 urb->status = -EINPROGRESS;
640 urb->actual_length = 0;
641 urb->error_count = 0;
642 urb->hcpriv = urb_priv;
643 urb_priv->ep = ep;
644
645 /* allocate data memory for largest packets if not already done */
646 maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
647 for (i = 0; i < NUM_ISO_ETDS; i++) {
648 struct etd_priv *etd = &imx21->etd[ep_priv->etd[i]];
649
650 if (etd->dmem_size > 0 && etd->dmem_size < maxpacket) {
651 /* not sure if this can really occur.... */
652 dev_err(imx21->dev, "increasing isoc buffer %d->%d\n",
653 etd->dmem_size, maxpacket);
654 ret = -EMSGSIZE;
655 goto alloc_dmem_failed;
656 }
657
658 if (etd->dmem_size == 0) {
659 etd->dmem_offset = alloc_dmem(imx21, maxpacket, ep);
660 if (etd->dmem_offset < 0) {
661 dev_dbg(imx21->dev, "failed alloc isoc dmem\n");
662 ret = -EAGAIN;
663 goto alloc_dmem_failed;
664 }
665 etd->dmem_size = maxpacket;
666 }
667 }
668
669 /* calculate frame */
670 cur_frame = imx21_hc_get_frame(hcd);
671 if (urb->transfer_flags & URB_ISO_ASAP) {
672 if (list_empty(&ep_priv->td_list))
673 urb->start_frame = cur_frame + 5;
674 else
675 urb->start_frame = list_entry(
676 ep_priv->td_list.prev,
677 struct td, list)->frame + urb->interval;
678 }
679 urb->start_frame = wrap_frame(urb->start_frame);
680 if (frame_after(cur_frame, urb->start_frame)) {
681 dev_dbg(imx21->dev,
682 "enqueue: adjusting iso start %d (cur=%d) asap=%d\n",
683 urb->start_frame, cur_frame,
684 (urb->transfer_flags & URB_ISO_ASAP) != 0);
685 urb->start_frame = wrap_frame(cur_frame + 1);
686 }
687
688 /* set up transfers */
689 td = urb_priv->isoc_td;
690 for (i = 0; i < urb->number_of_packets; i++, td++) {
691 td->ep = ep;
692 td->urb = urb;
693 td->len = urb->iso_frame_desc[i].length;
694 td->isoc_index = i;
695 td->frame = wrap_frame(urb->start_frame + urb->interval * i);
696 td->data = urb->transfer_dma + urb->iso_frame_desc[i].offset;
697 list_add_tail(&td->list, &ep_priv->td_list);
698 }
699
700 urb_priv->isoc_remaining = urb->number_of_packets;
701 dev_vdbg(imx21->dev, "setup %d packets for iso frame %d->%d\n",
702 urb->number_of_packets, urb->start_frame, td->frame);
703
704 debug_urb_submitted(imx21, urb);
705 schedule_isoc_etds(hcd, ep);
706
707 spin_unlock_irqrestore(&imx21->lock, flags);
708 return 0;
709
710alloc_dmem_failed:
711 usb_hcd_unlink_urb_from_ep(hcd, urb);
712
713link_failed:
714alloc_ep_failed:
715 spin_unlock_irqrestore(&imx21->lock, flags);
716 kfree(urb_priv->isoc_td);
717
718alloc_td_failed:
719 kfree(urb_priv);
720 return ret;
721}
722
723static void dequeue_isoc_urb(struct imx21 *imx21,
724 struct urb *urb, struct ep_priv *ep_priv)
725{
726 struct urb_priv *urb_priv = urb->hcpriv;
727 struct td *td, *tmp;
728 int i;
729
730 if (urb_priv->active) {
731 for (i = 0; i < NUM_ISO_ETDS; i++) {
732 int etd_num = ep_priv->etd[i];
733 if (etd_num != -1 && imx21->etd[etd_num].urb == urb) {
734 struct etd_priv *etd = imx21->etd + etd_num;
735
736 reset_etd(imx21, etd_num);
737 if (etd->dmem_size)
738 free_dmem(imx21, etd->dmem_offset);
739 etd->dmem_size = 0;
740 }
741 }
742 }
743
744 list_for_each_entry_safe(td, tmp, &ep_priv->td_list, list) {
745 if (td->urb == urb) {
746 dev_vdbg(imx21->dev, "removing td %p\n", td);
747 list_del(&td->list);
748 }
749 }
750}
751
752/* =========================================== */
753/* NON ISOC Handling ... */
754/* =========================================== */
755
756static void schedule_nonisoc_etd(struct imx21 *imx21, struct urb *urb)
757{
758 unsigned int pipe = urb->pipe;
759 struct urb_priv *urb_priv = urb->hcpriv;
760 struct ep_priv *ep_priv = urb_priv->ep->hcpriv;
761 int state = urb_priv->state;
762 int etd_num = ep_priv->etd[0];
763 struct etd_priv *etd;
764 int dmem_offset;
765 u32 count;
766 u16 etd_buf_size;
767 u16 maxpacket;
768 u8 dir;
769 u8 bufround;
770 u8 datatoggle;
771 u8 interval = 0;
772 u8 relpolpos = 0;
773
774 if (etd_num < 0) {
775 dev_err(imx21->dev, "No valid ETD\n");
776 return;
777 }
778 if (readl(imx21->regs + USBH_ETDENSET) & (1 << etd_num))
779 dev_err(imx21->dev, "submitting to active ETD %d\n", etd_num);
780
781 etd = &imx21->etd[etd_num];
782 maxpacket = usb_maxpacket(urb->dev, pipe, usb_pipeout(pipe));
783 if (!maxpacket)
784 maxpacket = 8;
785
786 if (usb_pipecontrol(pipe) && (state != US_CTRL_DATA)) {
787 if (state == US_CTRL_SETUP) {
788 dir = TD_DIR_SETUP;
789 etd->dma_handle = urb->setup_dma;
790 bufround = 0;
791 count = 8;
792 datatoggle = TD_TOGGLE_DATA0;
793 } else { /* US_CTRL_ACK */
794 dir = usb_pipeout(pipe) ? TD_DIR_IN : TD_DIR_OUT;
795 etd->dma_handle = urb->transfer_dma;
796 bufround = 0;
797 count = 0;
798 datatoggle = TD_TOGGLE_DATA1;
799 }
800 } else {
801 dir = usb_pipeout(pipe) ? TD_DIR_OUT : TD_DIR_IN;
802 bufround = (dir == TD_DIR_IN) ? 1 : 0;
803 etd->dma_handle = urb->transfer_dma;
804 if (usb_pipebulk(pipe) && (state == US_BULK0))
805 count = 0;
806 else
807 count = urb->transfer_buffer_length;
808
809 if (usb_pipecontrol(pipe)) {
810 datatoggle = TD_TOGGLE_DATA1;
811 } else {
812 if (usb_gettoggle(
813 urb->dev,
814 usb_pipeendpoint(urb->pipe),
815 usb_pipeout(urb->pipe)))
816 datatoggle = TD_TOGGLE_DATA1;
817 else
818 datatoggle = TD_TOGGLE_DATA0;
819 }
820 }
821
822 etd->urb = urb;
823 etd->ep = urb_priv->ep;
824 etd->len = count;
825
826 if (usb_pipeint(pipe)) {
827 interval = urb->interval;
828 relpolpos = (readl(imx21->regs + USBH_FRMNUB) + 1) & 0xff;
829 }
830
831 /* Write ETD to device memory */
832 setup_etd_dword0(imx21, etd_num, urb, dir, maxpacket);
833
834 etd_writel(imx21, etd_num, 2,
835 (u32) interval << DW2_POLINTERV |
836 ((u32) relpolpos << DW2_RELPOLPOS) |
837 ((u32) dir << DW2_DIRPID) |
838 ((u32) bufround << DW2_BUFROUND) |
839 ((u32) datatoggle << DW2_DATATOG) |
840 ((u32) TD_NOTACCESSED << DW2_COMPCODE));
841
842 /* DMA will always transfer buffer size even if TOBYCNT in DWORD3
843 is smaller. Make sure we don't overrun the buffer!
844 */
845 if (count && count < maxpacket)
846 etd_buf_size = count;
847 else
848 etd_buf_size = maxpacket;
849
850 etd_writel(imx21, etd_num, 3,
851 ((u32) (etd_buf_size - 1) << DW3_BUFSIZE) | (u32) count);
852
853 if (!count)
854 etd->dma_handle = 0;
855
856 /* allocate x and y buffer space at once */
857 etd->dmem_size = (count > maxpacket) ? maxpacket * 2 : maxpacket;
858 dmem_offset = alloc_dmem(imx21, etd->dmem_size, urb_priv->ep);
859 if (dmem_offset < 0) {
860 /* Setup everything we can in HW and update when we get DMEM */
861 etd_writel(imx21, etd_num, 1, (u32)maxpacket << 16);
862
863 dev_dbg(imx21->dev, "Queuing etd %d for DMEM\n", etd_num);
864 debug_urb_queued_for_dmem(imx21, urb);
865 list_add_tail(&etd->queue, &imx21->queue_for_dmem);
866 return;
867 }
868
869 etd_writel(imx21, etd_num, 1,
870 (((u32) dmem_offset + (u32) maxpacket) << DW1_YBUFSRTAD) |
871 (u32) dmem_offset);
872
873 urb_priv->active = 1;
874
875 /* enable the ETD to kick off transfer */
876 dev_vdbg(imx21->dev, "Activating etd %d for %d bytes %s\n",
877 etd_num, count, dir != TD_DIR_IN ? "out" : "in");
878 activate_etd(imx21, etd_num, etd->dma_handle, dir);
879
880}
881
882static void nonisoc_etd_done(struct usb_hcd *hcd, struct urb *urb, int etd_num)
883{
884 struct imx21 *imx21 = hcd_to_imx21(hcd);
885 struct etd_priv *etd = &imx21->etd[etd_num];
886 u32 etd_mask = 1 << etd_num;
887 struct urb_priv *urb_priv = urb->hcpriv;
888 int dir;
889 u16 xbufaddr;
890 int cc;
891 u32 bytes_xfrd;
892 int etd_done;
893
894 disactivate_etd(imx21, etd_num);
895
896 dir = (etd_readl(imx21, etd_num, 0) >> DW0_DIRECT) & 0x3;
897 xbufaddr = etd_readl(imx21, etd_num, 1) & 0xffff;
898 cc = (etd_readl(imx21, etd_num, 2) >> DW2_COMPCODE) & 0xf;
899 bytes_xfrd = etd->len - (etd_readl(imx21, etd_num, 3) & 0x1fffff);
900
901 /* save toggle carry */
902 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
903 usb_pipeout(urb->pipe),
904 (etd_readl(imx21, etd_num, 0) >> DW0_TOGCRY) & 0x1);
905
906 if (dir == TD_DIR_IN) {
907 clear_toggle_bit(imx21, USBH_XFILLSTAT, etd_mask);
908 clear_toggle_bit(imx21, USBH_YFILLSTAT, etd_mask);
909 }
910 free_dmem(imx21, xbufaddr);
911
912 urb->error_count = 0;
913 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)
914 && (cc == TD_DATAUNDERRUN))
915 cc = TD_CC_NOERROR;
916
917 if (cc != 0)
918 dev_vdbg(imx21->dev, "cc is 0x%x\n", cc);
919
920 etd_done = (cc_to_error[cc] != 0); /* stop if error */
921
922 switch (usb_pipetype(urb->pipe)) {
923 case PIPE_CONTROL:
924 switch (urb_priv->state) {
925 case US_CTRL_SETUP:
926 if (urb->transfer_buffer_length > 0)
927 urb_priv->state = US_CTRL_DATA;
928 else
929 urb_priv->state = US_CTRL_ACK;
930 break;
931 case US_CTRL_DATA:
932 urb->actual_length += bytes_xfrd;
933 urb_priv->state = US_CTRL_ACK;
934 break;
935 case US_CTRL_ACK:
936 etd_done = 1;
937 break;
938 default:
939 dev_err(imx21->dev,
940 "Invalid pipe state %d\n", urb_priv->state);
941 etd_done = 1;
942 break;
943 }
944 break;
945
946 case PIPE_BULK:
947 urb->actual_length += bytes_xfrd;
948 if ((urb_priv->state == US_BULK)
949 && (urb->transfer_flags & URB_ZERO_PACKET)
950 && urb->transfer_buffer_length > 0
951 && ((urb->transfer_buffer_length %
952 usb_maxpacket(urb->dev, urb->pipe,
953 usb_pipeout(urb->pipe))) == 0)) {
954 /* need a 0-packet */
955 urb_priv->state = US_BULK0;
956 } else {
957 etd_done = 1;
958 }
959 break;
960
961 case PIPE_INTERRUPT:
962 urb->actual_length += bytes_xfrd;
963 etd_done = 1;
964 break;
965 }
966
967 if (!etd_done) {
968 dev_vdbg(imx21->dev, "next state=%d\n", urb_priv->state);
969 schedule_nonisoc_etd(imx21, urb);
970 } else {
971 struct usb_host_endpoint *ep = urb->ep;
972
973 urb_done(hcd, urb, cc_to_error[cc]);
974 etd->urb = NULL;
975
976 if (!list_empty(&ep->urb_list)) {
977 urb = list_first_entry(&ep->urb_list,
978 struct urb, urb_list);
979 dev_vdbg(imx21->dev, "next URB %p\n", urb);
980 schedule_nonisoc_etd(imx21, urb);
981 }
982 }
983}
984
985static struct ep_priv *alloc_ep(void)
986{
987 int i;
988 struct ep_priv *ep_priv;
989
990 ep_priv = kzalloc(sizeof(struct ep_priv), GFP_ATOMIC);
991 if (!ep_priv)
992 return NULL;
993
994 for (i = 0; i < NUM_ISO_ETDS; ++i)
995 ep_priv->etd[i] = -1;
996
997 return ep_priv;
998}
999
1000static int imx21_hc_urb_enqueue(struct usb_hcd *hcd,
1001 struct urb *urb, gfp_t mem_flags)
1002{
1003 struct imx21 *imx21 = hcd_to_imx21(hcd);
1004 struct usb_host_endpoint *ep = urb->ep;
1005 struct urb_priv *urb_priv;
1006 struct ep_priv *ep_priv;
1007 struct etd_priv *etd;
1008 int ret;
1009 unsigned long flags;
1010 int new_ep = 0;
1011
1012 dev_vdbg(imx21->dev,
1013 "enqueue urb=%p ep=%p len=%d "
1014 "buffer=%p dma=%08X setupBuf=%p setupDma=%08X\n",
1015 urb, ep,
1016 urb->transfer_buffer_length,
1017 urb->transfer_buffer, urb->transfer_dma,
1018 urb->setup_packet, urb->setup_dma);
1019
1020 if (usb_pipeisoc(urb->pipe))
1021 return imx21_hc_urb_enqueue_isoc(hcd, ep, urb, mem_flags);
1022
1023 urb_priv = kzalloc(sizeof(struct urb_priv), mem_flags);
1024 if (!urb_priv)
1025 return -ENOMEM;
1026
1027 spin_lock_irqsave(&imx21->lock, flags);
1028
1029 ep_priv = ep->hcpriv;
1030 if (ep_priv == NULL) {
1031 ep_priv = alloc_ep();
1032 if (!ep_priv) {
1033 ret = -ENOMEM;
1034 goto failed_alloc_ep;
1035 }
1036 ep->hcpriv = ep_priv;
1037 ep_priv->ep = ep;
1038 new_ep = 1;
1039 }
1040
1041 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1042 if (ret)
1043 goto failed_link;
1044
1045 urb->status = -EINPROGRESS;
1046 urb->actual_length = 0;
1047 urb->error_count = 0;
1048 urb->hcpriv = urb_priv;
1049 urb_priv->ep = ep;
1050
1051 switch (usb_pipetype(urb->pipe)) {
1052 case PIPE_CONTROL:
1053 urb_priv->state = US_CTRL_SETUP;
1054 break;
1055 case PIPE_BULK:
1056 urb_priv->state = US_BULK;
1057 break;
1058 }
1059
1060 debug_urb_submitted(imx21, urb);
1061 if (ep_priv->etd[0] < 0) {
1062 if (ep_priv->waiting_etd) {
1063 dev_dbg(imx21->dev,
1064 "no ETD available already queued %p\n",
1065 ep_priv);
1066 debug_urb_queued_for_etd(imx21, urb);
1067 goto out;
1068 }
1069 ep_priv->etd[0] = alloc_etd(imx21);
1070 if (ep_priv->etd[0] < 0) {
1071 dev_dbg(imx21->dev,
1072 "no ETD available queueing %p\n", ep_priv);
1073 debug_urb_queued_for_etd(imx21, urb);
1074 list_add_tail(&ep_priv->queue, &imx21->queue_for_etd);
1075 ep_priv->waiting_etd = 1;
1076 goto out;
1077 }
1078 }
1079
1080 /* Schedule if no URB already active for this endpoint */
1081 etd = &imx21->etd[ep_priv->etd[0]];
1082 if (etd->urb == NULL) {
1083 DEBUG_LOG_FRAME(imx21, etd, last_req);
1084 schedule_nonisoc_etd(imx21, urb);
1085 }
1086
1087out:
1088 spin_unlock_irqrestore(&imx21->lock, flags);
1089 return 0;
1090
1091failed_link:
1092failed_alloc_ep:
1093 spin_unlock_irqrestore(&imx21->lock, flags);
1094 kfree(urb_priv);
1095 return ret;
1096}
1097
1098static int imx21_hc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1099 int status)
1100{
1101 struct imx21 *imx21 = hcd_to_imx21(hcd);
1102 unsigned long flags;
1103 struct usb_host_endpoint *ep;
1104 struct ep_priv *ep_priv;
1105 struct urb_priv *urb_priv = urb->hcpriv;
1106 int ret = -EINVAL;
1107
1108 dev_vdbg(imx21->dev, "dequeue urb=%p iso=%d status=%d\n",
1109 urb, usb_pipeisoc(urb->pipe), status);
1110
1111 spin_lock_irqsave(&imx21->lock, flags);
1112
1113 ret = usb_hcd_check_unlink_urb(hcd, urb, status);
1114 if (ret)
1115 goto fail;
1116 ep = urb_priv->ep;
1117 ep_priv = ep->hcpriv;
1118
1119 debug_urb_unlinked(imx21, urb);
1120
1121 if (usb_pipeisoc(urb->pipe)) {
1122 dequeue_isoc_urb(imx21, urb, ep_priv);
1123 schedule_isoc_etds(hcd, ep);
1124 } else if (urb_priv->active) {
1125 int etd_num = ep_priv->etd[0];
1126 if (etd_num != -1) {
1127 disactivate_etd(imx21, etd_num);
1128 free_dmem(imx21, etd_readl(imx21, etd_num, 1) & 0xffff);
1129 imx21->etd[etd_num].urb = NULL;
1130 }
1131 }
1132
1133 urb_done(hcd, urb, status);
1134
1135 spin_unlock_irqrestore(&imx21->lock, flags);
1136 return 0;
1137
1138fail:
1139 spin_unlock_irqrestore(&imx21->lock, flags);
1140 return ret;
1141}
1142
1143/* =========================================== */
1144/* Interrupt dispatch */
1145/* =========================================== */
1146
1147static void process_etds(struct usb_hcd *hcd, struct imx21 *imx21, int sof)
1148{
1149 int etd_num;
1150 int enable_sof_int = 0;
1151 unsigned long flags;
1152
1153 spin_lock_irqsave(&imx21->lock, flags);
1154
1155 for (etd_num = 0; etd_num < USB_NUM_ETD; etd_num++) {
1156 u32 etd_mask = 1 << etd_num;
1157 u32 enabled = readl(imx21->regs + USBH_ETDENSET) & etd_mask;
1158 u32 done = readl(imx21->regs + USBH_ETDDONESTAT) & etd_mask;
1159 struct etd_priv *etd = &imx21->etd[etd_num];
1160
1161
1162 if (done) {
1163 DEBUG_LOG_FRAME(imx21, etd, last_int);
1164 } else {
1165/*
1166 * Kludge warning!
1167 *
1168 * When multiple transfers are using the bus we sometimes get into a state
1169 * where the transfer has completed (the CC field of the ETD is != 0x0F),
1170 * the ETD has self disabled but the ETDDONESTAT flag is not set
1171 * (and hence no interrupt occurs).
1172 * This causes the transfer in question to hang.
1173 * The kludge below checks for this condition at each SOF and processes any
1174 * blocked ETDs (after an arbitary 10 frame wait)
1175 *
1176 * With a single active transfer the usbtest test suite will run for days
1177 * without the kludge.
1178 * With other bus activity (eg mass storage) even just test1 will hang without
1179 * the kludge.
1180 */
1181 u32 dword0;
1182 int cc;
1183
1184 if (etd->active_count && !enabled) /* suspicious... */
1185 enable_sof_int = 1;
1186
1187 if (!sof || enabled || !etd->active_count)
1188 continue;
1189
1190 cc = etd_readl(imx21, etd_num, 2) >> DW2_COMPCODE;
1191 if (cc == TD_NOTACCESSED)
1192 continue;
1193
1194 if (++etd->active_count < 10)
1195 continue;
1196
1197 dword0 = etd_readl(imx21, etd_num, 0);
1198 dev_dbg(imx21->dev,
1199 "unblock ETD %d dev=0x%X ep=0x%X cc=0x%02X!\n",
1200 etd_num, dword0 & 0x7F,
1201 (dword0 >> DW0_ENDPNT) & 0x0F,
1202 cc);
1203
1204#ifdef DEBUG
1205 dev_dbg(imx21->dev,
1206 "frame: act=%d disact=%d"
1207 " int=%d req=%d cur=%d\n",
1208 etd->activated_frame,
1209 etd->disactivated_frame,
1210 etd->last_int_frame,
1211 etd->last_req_frame,
1212 readl(imx21->regs + USBH_FRMNUB));
1213 imx21->debug_unblocks++;
1214#endif
1215 etd->active_count = 0;
1216/* End of kludge */
1217 }
1218
1219 if (etd->ep == NULL || etd->urb == NULL) {
1220 dev_dbg(imx21->dev,
1221 "Interrupt for unexpected etd %d"
1222 " ep=%p urb=%p\n",
1223 etd_num, etd->ep, etd->urb);
1224 disactivate_etd(imx21, etd_num);
1225 continue;
1226 }
1227
1228 if (usb_pipeisoc(etd->urb->pipe))
1229 isoc_etd_done(hcd, etd->urb, etd_num);
1230 else
1231 nonisoc_etd_done(hcd, etd->urb, etd_num);
1232 }
1233
1234 /* only enable SOF interrupt if it may be needed for the kludge */
1235 if (enable_sof_int)
1236 set_register_bits(imx21, USBH_SYSIEN, USBH_SYSIEN_SOFINT);
1237 else
1238 clear_register_bits(imx21, USBH_SYSIEN, USBH_SYSIEN_SOFINT);
1239
1240
1241 spin_unlock_irqrestore(&imx21->lock, flags);
1242}
1243
1244static irqreturn_t imx21_irq(struct usb_hcd *hcd)
1245{
1246 struct imx21 *imx21 = hcd_to_imx21(hcd);
1247 u32 ints = readl(imx21->regs + USBH_SYSISR);
1248
1249 if (ints & USBH_SYSIEN_HERRINT)
1250 dev_dbg(imx21->dev, "Scheduling error\n");
1251
1252 if (ints & USBH_SYSIEN_SORINT)
1253 dev_dbg(imx21->dev, "Scheduling overrun\n");
1254
1255 if (ints & (USBH_SYSISR_DONEINT | USBH_SYSISR_SOFINT))
1256 process_etds(hcd, imx21, ints & USBH_SYSISR_SOFINT);
1257
1258 writel(ints, imx21->regs + USBH_SYSISR);
1259 return IRQ_HANDLED;
1260}
1261
1262static void imx21_hc_endpoint_disable(struct usb_hcd *hcd,
1263 struct usb_host_endpoint *ep)
1264{
1265 struct imx21 *imx21 = hcd_to_imx21(hcd);
1266 unsigned long flags;
1267 struct ep_priv *ep_priv;
1268 int i;
1269
1270 if (ep == NULL)
1271 return;
1272
1273 spin_lock_irqsave(&imx21->lock, flags);
1274 ep_priv = ep->hcpriv;
1275 dev_vdbg(imx21->dev, "disable ep=%p, ep->hcpriv=%p\n", ep, ep_priv);
1276
1277 if (!list_empty(&ep->urb_list))
1278 dev_dbg(imx21->dev, "ep's URB list is not empty\n");
1279
1280 if (ep_priv != NULL) {
1281 for (i = 0; i < NUM_ISO_ETDS; i++) {
1282 if (ep_priv->etd[i] > -1)
1283 dev_dbg(imx21->dev, "free etd %d for disable\n",
1284 ep_priv->etd[i]);
1285
1286 free_etd(imx21, ep_priv->etd[i]);
1287 }
1288 kfree(ep_priv);
1289 ep->hcpriv = NULL;
1290 }
1291
1292 for (i = 0; i < USB_NUM_ETD; i++) {
1293 if (imx21->etd[i].alloc && imx21->etd[i].ep == ep) {
1294 dev_err(imx21->dev,
1295 "Active etd %d for disabled ep=%p!\n", i, ep);
1296 free_etd(imx21, i);
1297 }
1298 }
1299 free_epdmem(imx21, ep);
1300 spin_unlock_irqrestore(&imx21->lock, flags);
1301}
1302
1303/* =========================================== */
1304/* Hub handling */
1305/* =========================================== */
1306
1307static int get_hub_descriptor(struct usb_hcd *hcd,
1308 struct usb_hub_descriptor *desc)
1309{
1310 struct imx21 *imx21 = hcd_to_imx21(hcd);
1311 desc->bDescriptorType = 0x29; /* HUB descriptor */
1312 desc->bHubContrCurrent = 0;
1313
1314 desc->bNbrPorts = readl(imx21->regs + USBH_ROOTHUBA)
1315 & USBH_ROOTHUBA_NDNSTMPRT_MASK;
1316 desc->bDescLength = 9;
1317 desc->bPwrOn2PwrGood = 0;
1318 desc->wHubCharacteristics = (__force __u16) cpu_to_le16(
1319 0x0002 | /* No power switching */
1320 0x0010 | /* No over current protection */
1321 0);
1322
1323 desc->bitmap[0] = 1 << 1;
1324 desc->bitmap[1] = ~0;
1325 return 0;
1326}
1327
1328static int imx21_hc_hub_status_data(struct usb_hcd *hcd, char *buf)
1329{
1330 struct imx21 *imx21 = hcd_to_imx21(hcd);
1331 int ports;
1332 int changed = 0;
1333 int i;
1334 unsigned long flags;
1335
1336 spin_lock_irqsave(&imx21->lock, flags);
1337 ports = readl(imx21->regs + USBH_ROOTHUBA)
1338 & USBH_ROOTHUBA_NDNSTMPRT_MASK;
1339 if (ports > 7) {
1340 ports = 7;
1341 dev_err(imx21->dev, "ports %d > 7\n", ports);
1342 }
1343 for (i = 0; i < ports; i++) {
1344 if (readl(imx21->regs + USBH_PORTSTAT(i)) &
1345 (USBH_PORTSTAT_CONNECTSC |
1346 USBH_PORTSTAT_PRTENBLSC |
1347 USBH_PORTSTAT_PRTSTATSC |
1348 USBH_PORTSTAT_OVRCURIC |
1349 USBH_PORTSTAT_PRTRSTSC)) {
1350
1351 changed = 1;
1352 buf[0] |= 1 << (i + 1);
1353 }
1354 }
1355 spin_unlock_irqrestore(&imx21->lock, flags);
1356
1357 if (changed)
1358 dev_info(imx21->dev, "Hub status changed\n");
1359 return changed;
1360}
1361
1362static int imx21_hc_hub_control(struct usb_hcd *hcd,
1363 u16 typeReq,
1364 u16 wValue, u16 wIndex, char *buf, u16 wLength)
1365{
1366 struct imx21 *imx21 = hcd_to_imx21(hcd);
1367 int rc = 0;
1368 u32 status_write = 0;
1369
1370 switch (typeReq) {
1371 case ClearHubFeature:
1372 dev_dbg(imx21->dev, "ClearHubFeature\n");
1373 switch (wValue) {
1374 case C_HUB_OVER_CURRENT:
1375 dev_dbg(imx21->dev, " OVER_CURRENT\n");
1376 break;
1377 case C_HUB_LOCAL_POWER:
1378 dev_dbg(imx21->dev, " LOCAL_POWER\n");
1379 break;
1380 default:
1381 dev_dbg(imx21->dev, " unknown\n");
1382 rc = -EINVAL;
1383 break;
1384 }
1385 break;
1386
1387 case ClearPortFeature:
1388 dev_dbg(imx21->dev, "ClearPortFeature\n");
1389 switch (wValue) {
1390 case USB_PORT_FEAT_ENABLE:
1391 dev_dbg(imx21->dev, " ENABLE\n");
1392 status_write = USBH_PORTSTAT_CURCONST;
1393 break;
1394 case USB_PORT_FEAT_SUSPEND:
1395 dev_dbg(imx21->dev, " SUSPEND\n");
1396 status_write = USBH_PORTSTAT_PRTOVRCURI;
1397 break;
1398 case USB_PORT_FEAT_POWER:
1399 dev_dbg(imx21->dev, " POWER\n");
1400 status_write = USBH_PORTSTAT_LSDEVCON;
1401 break;
1402 case USB_PORT_FEAT_C_ENABLE:
1403 dev_dbg(imx21->dev, " C_ENABLE\n");
1404 status_write = USBH_PORTSTAT_PRTENBLSC;
1405 break;
1406 case USB_PORT_FEAT_C_SUSPEND:
1407 dev_dbg(imx21->dev, " C_SUSPEND\n");
1408 status_write = USBH_PORTSTAT_PRTSTATSC;
1409 break;
1410 case USB_PORT_FEAT_C_CONNECTION:
1411 dev_dbg(imx21->dev, " C_CONNECTION\n");
1412 status_write = USBH_PORTSTAT_CONNECTSC;
1413 break;
1414 case USB_PORT_FEAT_C_OVER_CURRENT:
1415 dev_dbg(imx21->dev, " C_OVER_CURRENT\n");
1416 status_write = USBH_PORTSTAT_OVRCURIC;
1417 break;
1418 case USB_PORT_FEAT_C_RESET:
1419 dev_dbg(imx21->dev, " C_RESET\n");
1420 status_write = USBH_PORTSTAT_PRTRSTSC;
1421 break;
1422 default:
1423 dev_dbg(imx21->dev, " unknown\n");
1424 rc = -EINVAL;
1425 break;
1426 }
1427
1428 break;
1429
1430 case GetHubDescriptor:
1431 dev_dbg(imx21->dev, "GetHubDescriptor\n");
1432 rc = get_hub_descriptor(hcd, (void *)buf);
1433 break;
1434
1435 case GetHubStatus:
1436 dev_dbg(imx21->dev, " GetHubStatus\n");
1437 *(__le32 *) buf = 0;
1438 break;
1439
1440 case GetPortStatus:
1441 dev_dbg(imx21->dev, "GetPortStatus: port: %d, 0x%x\n",
1442 wIndex, USBH_PORTSTAT(wIndex - 1));
1443 *(__le32 *) buf = readl(imx21->regs +
1444 USBH_PORTSTAT(wIndex - 1));
1445 break;
1446
1447 case SetHubFeature:
1448 dev_dbg(imx21->dev, "SetHubFeature\n");
1449 switch (wValue) {
1450 case C_HUB_OVER_CURRENT:
1451 dev_dbg(imx21->dev, " OVER_CURRENT\n");
1452 break;
1453
1454 case C_HUB_LOCAL_POWER:
1455 dev_dbg(imx21->dev, " LOCAL_POWER\n");
1456 break;
1457 default:
1458 dev_dbg(imx21->dev, " unknown\n");
1459 rc = -EINVAL;
1460 break;
1461 }
1462
1463 break;
1464
1465 case SetPortFeature:
1466 dev_dbg(imx21->dev, "SetPortFeature\n");
1467 switch (wValue) {
1468 case USB_PORT_FEAT_SUSPEND:
1469 dev_dbg(imx21->dev, " SUSPEND\n");
1470 status_write = USBH_PORTSTAT_PRTSUSPST;
1471 break;
1472 case USB_PORT_FEAT_POWER:
1473 dev_dbg(imx21->dev, " POWER\n");
1474 status_write = USBH_PORTSTAT_PRTPWRST;
1475 break;
1476 case USB_PORT_FEAT_RESET:
1477 dev_dbg(imx21->dev, " RESET\n");
1478 status_write = USBH_PORTSTAT_PRTRSTST;
1479 break;
1480 default:
1481 dev_dbg(imx21->dev, " unknown\n");
1482 rc = -EINVAL;
1483 break;
1484 }
1485 break;
1486
1487 default:
1488 dev_dbg(imx21->dev, " unknown\n");
1489 rc = -EINVAL;
1490 break;
1491 }
1492
1493 if (status_write)
1494 writel(status_write, imx21->regs + USBH_PORTSTAT(wIndex - 1));
1495 return rc;
1496}
1497
1498/* =========================================== */
1499/* Host controller management */
1500/* =========================================== */
1501
1502static int imx21_hc_reset(struct usb_hcd *hcd)
1503{
1504 struct imx21 *imx21 = hcd_to_imx21(hcd);
1505 unsigned long timeout;
1506 unsigned long flags;
1507
1508 spin_lock_irqsave(&imx21->lock, flags);
1509
1510 /* Reset the Host controler modules */
1511 writel(USBOTG_RST_RSTCTRL | USBOTG_RST_RSTRH |
1512 USBOTG_RST_RSTHSIE | USBOTG_RST_RSTHC,
1513 imx21->regs + USBOTG_RST_CTRL);
1514
1515 /* Wait for reset to finish */
1516 timeout = jiffies + HZ;
1517 while (readl(imx21->regs + USBOTG_RST_CTRL) != 0) {
1518 if (time_after(jiffies, timeout)) {
1519 spin_unlock_irqrestore(&imx21->lock, flags);
1520 dev_err(imx21->dev, "timeout waiting for reset\n");
1521 return -ETIMEDOUT;
1522 }
1523 spin_unlock_irq(&imx21->lock);
1524 schedule_timeout(1);
1525 spin_lock_irq(&imx21->lock);
1526 }
1527 spin_unlock_irqrestore(&imx21->lock, flags);
1528 return 0;
1529}
1530
1531static int __devinit imx21_hc_start(struct usb_hcd *hcd)
1532{
1533 struct imx21 *imx21 = hcd_to_imx21(hcd);
1534 unsigned long flags;
1535 int i, j;
1536 u32 hw_mode = USBOTG_HWMODE_CRECFG_HOST;
1537 u32 usb_control = 0;
1538
1539 hw_mode |= ((imx21->pdata->host_xcvr << USBOTG_HWMODE_HOSTXCVR_SHIFT) &
1540 USBOTG_HWMODE_HOSTXCVR_MASK);
1541 hw_mode |= ((imx21->pdata->otg_xcvr << USBOTG_HWMODE_OTGXCVR_SHIFT) &
1542 USBOTG_HWMODE_OTGXCVR_MASK);
1543
1544 if (imx21->pdata->host1_txenoe)
1545 usb_control |= USBCTRL_HOST1_TXEN_OE;
1546
1547 if (!imx21->pdata->host1_xcverless)
1548 usb_control |= USBCTRL_HOST1_BYP_TLL;
1549
1550 if (imx21->pdata->otg_ext_xcvr)
1551 usb_control |= USBCTRL_OTC_RCV_RXDP;
1552
1553
1554 spin_lock_irqsave(&imx21->lock, flags);
1555
1556 writel((USBOTG_CLK_CTRL_HST | USBOTG_CLK_CTRL_MAIN),
1557 imx21->regs + USBOTG_CLK_CTRL);
1558 writel(hw_mode, imx21->regs + USBOTG_HWMODE);
1559 writel(usb_control, imx21->regs + USBCTRL);
1560 writel(USB_MISCCONTROL_SKPRTRY | USB_MISCCONTROL_ARBMODE,
1561 imx21->regs + USB_MISCCONTROL);
1562
1563 /* Clear the ETDs */
1564 for (i = 0; i < USB_NUM_ETD; i++)
1565 for (j = 0; j < 4; j++)
1566 etd_writel(imx21, i, j, 0);
1567
1568 /* Take the HC out of reset */
1569 writel(USBH_HOST_CTRL_HCUSBSTE_OPERATIONAL | USBH_HOST_CTRL_CTLBLKSR_1,
1570 imx21->regs + USBH_HOST_CTRL);
1571
1572 /* Enable ports */
1573 if (imx21->pdata->enable_otg_host)
1574 writel(USBH_PORTSTAT_PRTPWRST | USBH_PORTSTAT_PRTENABST,
1575 imx21->regs + USBH_PORTSTAT(0));
1576
1577 if (imx21->pdata->enable_host1)
1578 writel(USBH_PORTSTAT_PRTPWRST | USBH_PORTSTAT_PRTENABST,
1579 imx21->regs + USBH_PORTSTAT(1));
1580
1581 if (imx21->pdata->enable_host2)
1582 writel(USBH_PORTSTAT_PRTPWRST | USBH_PORTSTAT_PRTENABST,
1583 imx21->regs + USBH_PORTSTAT(2));
1584
1585
1586 hcd->state = HC_STATE_RUNNING;
1587
1588 /* Enable host controller interrupts */
1589 set_register_bits(imx21, USBH_SYSIEN,
1590 USBH_SYSIEN_HERRINT |
1591 USBH_SYSIEN_DONEINT | USBH_SYSIEN_SORINT);
1592 set_register_bits(imx21, USBOTG_CINT_STEN, USBOTG_HCINT);
1593
1594 spin_unlock_irqrestore(&imx21->lock, flags);
1595
1596 return 0;
1597}
1598
1599static void imx21_hc_stop(struct usb_hcd *hcd)
1600{
1601 struct imx21 *imx21 = hcd_to_imx21(hcd);
1602 unsigned long flags;
1603
1604 spin_lock_irqsave(&imx21->lock, flags);
1605
1606 writel(0, imx21->regs + USBH_SYSIEN);
1607 clear_register_bits(imx21, USBOTG_CINT_STEN, USBOTG_HCINT);
1608 clear_register_bits(imx21, USBOTG_CLK_CTRL_HST | USBOTG_CLK_CTRL_MAIN,
1609 USBOTG_CLK_CTRL);
1610 spin_unlock_irqrestore(&imx21->lock, flags);
1611}
1612
1613/* =========================================== */
1614/* Driver glue */
1615/* =========================================== */
1616
1617static struct hc_driver imx21_hc_driver = {
1618 .description = hcd_name,
1619 .product_desc = "IMX21 USB Host Controller",
1620 .hcd_priv_size = sizeof(struct imx21),
1621
1622 .flags = HCD_USB11,
1623 .irq = imx21_irq,
1624
1625 .reset = imx21_hc_reset,
1626 .start = imx21_hc_start,
1627 .stop = imx21_hc_stop,
1628
1629 /* I/O requests */
1630 .urb_enqueue = imx21_hc_urb_enqueue,
1631 .urb_dequeue = imx21_hc_urb_dequeue,
1632 .endpoint_disable = imx21_hc_endpoint_disable,
1633
1634 /* scheduling support */
1635 .get_frame_number = imx21_hc_get_frame,
1636
1637 /* Root hub support */
1638 .hub_status_data = imx21_hc_hub_status_data,
1639 .hub_control = imx21_hc_hub_control,
1640
1641};
1642
1643static struct mx21_usbh_platform_data default_pdata = {
1644 .host_xcvr = MX21_USBXCVR_TXDIF_RXDIF,
1645 .otg_xcvr = MX21_USBXCVR_TXDIF_RXDIF,
1646 .enable_host1 = 1,
1647 .enable_host2 = 1,
1648 .enable_otg_host = 1,
1649
1650};
1651
1652static int imx21_remove(struct platform_device *pdev)
1653{
1654 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1655 struct imx21 *imx21 = hcd_to_imx21(hcd);
1656 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1657
1658 remove_debug_files(imx21);
1659 usb_remove_hcd(hcd);
1660
1661 if (res != NULL) {
1662 clk_disable(imx21->clk);
1663 clk_put(imx21->clk);
1664 iounmap(imx21->regs);
1665 release_mem_region(res->start, resource_size(res));
1666 }
1667
1668 kfree(hcd);
1669 return 0;
1670}
1671
1672
1673static int imx21_probe(struct platform_device *pdev)
1674{
1675 struct usb_hcd *hcd;
1676 struct imx21 *imx21;
1677 struct resource *res;
1678 int ret;
1679 int irq;
1680
1681 printk(KERN_INFO "%s\n", imx21_hc_driver.product_desc);
1682
1683 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1684 if (!res)
1685 return -ENODEV;
1686 irq = platform_get_irq(pdev, 0);
1687 if (irq < 0)
1688 return -ENXIO;
1689
1690 hcd = usb_create_hcd(&imx21_hc_driver,
1691 &pdev->dev, dev_name(&pdev->dev));
1692 if (hcd == NULL) {
1693 dev_err(&pdev->dev, "Cannot create hcd (%s)\n",
1694 dev_name(&pdev->dev));
1695 return -ENOMEM;
1696 }
1697
1698 imx21 = hcd_to_imx21(hcd);
1699 imx21->dev = &pdev->dev;
1700 imx21->pdata = pdev->dev.platform_data;
1701 if (!imx21->pdata)
1702 imx21->pdata = &default_pdata;
1703
1704 spin_lock_init(&imx21->lock);
1705 INIT_LIST_HEAD(&imx21->dmem_list);
1706 INIT_LIST_HEAD(&imx21->queue_for_etd);
1707 INIT_LIST_HEAD(&imx21->queue_for_dmem);
1708 create_debug_files(imx21);
1709
1710 res = request_mem_region(res->start, resource_size(res), hcd_name);
1711 if (!res) {
1712 ret = -EBUSY;
1713 goto failed_request_mem;
1714 }
1715
1716 imx21->regs = ioremap(res->start, resource_size(res));
1717 if (imx21->regs == NULL) {
1718 dev_err(imx21->dev, "Cannot map registers\n");
1719 ret = -ENOMEM;
1720 goto failed_ioremap;
1721 }
1722
1723 /* Enable clocks source */
1724 imx21->clk = clk_get(imx21->dev, NULL);
1725 if (IS_ERR(imx21->clk)) {
1726 dev_err(imx21->dev, "no clock found\n");
1727 ret = PTR_ERR(imx21->clk);
1728 goto failed_clock_get;
1729 }
1730
1731 ret = clk_set_rate(imx21->clk, clk_round_rate(imx21->clk, 48000000));
1732 if (ret)
1733 goto failed_clock_set;
1734 ret = clk_enable(imx21->clk);
1735 if (ret)
1736 goto failed_clock_enable;
1737
1738 dev_info(imx21->dev, "Hardware HC revision: 0x%02X\n",
1739 (readl(imx21->regs + USBOTG_HWMODE) >> 16) & 0xFF);
1740
1741 ret = usb_add_hcd(hcd, irq, IRQF_DISABLED);
1742 if (ret != 0) {
1743 dev_err(imx21->dev, "usb_add_hcd() returned %d\n", ret);
1744 goto failed_add_hcd;
1745 }
1746
1747 return 0;
1748
1749failed_add_hcd:
1750 clk_disable(imx21->clk);
1751failed_clock_enable:
1752failed_clock_set:
1753 clk_put(imx21->clk);
1754failed_clock_get:
1755 iounmap(imx21->regs);
1756failed_ioremap:
1757 release_mem_region(res->start, res->end - res->start);
1758failed_request_mem:
1759 remove_debug_files(imx21);
1760 usb_put_hcd(hcd);
1761 return ret;
1762}
1763
1764static struct platform_driver imx21_hcd_driver = {
1765 .driver = {
1766 .name = (char *)hcd_name,
1767 },
1768 .probe = imx21_probe,
1769 .remove = imx21_remove,
1770 .suspend = NULL,
1771 .resume = NULL,
1772};
1773
1774static int __init imx21_hcd_init(void)
1775{
1776 return platform_driver_register(&imx21_hcd_driver);
1777}
1778
1779static void __exit imx21_hcd_cleanup(void)
1780{
1781 platform_driver_unregister(&imx21_hcd_driver);
1782}
1783
1784module_init(imx21_hcd_init);
1785module_exit(imx21_hcd_cleanup);
1786
1787MODULE_DESCRIPTION("i.MX21 USB Host controller");
1788MODULE_AUTHOR("Martin Fuzzey");
1789MODULE_LICENSE("GPL");
1790MODULE_ALIAS("platform:imx21-hcd");
diff --git a/drivers/usb/host/imx21-hcd.h b/drivers/usb/host/imx21-hcd.h
new file mode 100644
index 000000000000..1b0d913780a5
--- /dev/null
+++ b/drivers/usb/host/imx21-hcd.h
@@ -0,0 +1,436 @@
1/*
2 * Macros and prototypes for i.MX21
3 *
4 * Copyright (C) 2006 Loping Dog Embedded Systems
5 * Copyright (C) 2009 Martin Fuzzey
6 * Originally written by Jay Monkman <jtm@lopingdog.com>
7 * Ported to 2.6.30, debugged and enhanced by Martin Fuzzey
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef __LINUX_IMX21_HCD_H__
25#define __LINUX_IMX21_HCD_H__
26
27#include <mach/mx21-usbhost.h>
28
29#define NUM_ISO_ETDS 2
30#define USB_NUM_ETD 32
31#define DMEM_SIZE 4096
32
33/* Register definitions */
34#define USBOTG_HWMODE 0x00
35#define USBOTG_HWMODE_ANASDBEN (1 << 14)
36#define USBOTG_HWMODE_OTGXCVR_SHIFT 6
37#define USBOTG_HWMODE_OTGXCVR_MASK (3 << 6)
38#define USBOTG_HWMODE_OTGXCVR_TD_RD (0 << 6)
39#define USBOTG_HWMODE_OTGXCVR_TS_RD (2 << 6)
40#define USBOTG_HWMODE_OTGXCVR_TD_RS (1 << 6)
41#define USBOTG_HWMODE_OTGXCVR_TS_RS (3 << 6)
42#define USBOTG_HWMODE_HOSTXCVR_SHIFT 4
43#define USBOTG_HWMODE_HOSTXCVR_MASK (3 << 4)
44#define USBOTG_HWMODE_HOSTXCVR_TD_RD (0 << 4)
45#define USBOTG_HWMODE_HOSTXCVR_TS_RD (2 << 4)
46#define USBOTG_HWMODE_HOSTXCVR_TD_RS (1 << 4)
47#define USBOTG_HWMODE_HOSTXCVR_TS_RS (3 << 4)
48#define USBOTG_HWMODE_CRECFG_MASK (3 << 0)
49#define USBOTG_HWMODE_CRECFG_HOST (1 << 0)
50#define USBOTG_HWMODE_CRECFG_FUNC (2 << 0)
51#define USBOTG_HWMODE_CRECFG_HNP (3 << 0)
52
53#define USBOTG_CINT_STAT 0x04
54#define USBOTG_CINT_STEN 0x08
55#define USBOTG_ASHNPINT (1 << 5)
56#define USBOTG_ASFCINT (1 << 4)
57#define USBOTG_ASHCINT (1 << 3)
58#define USBOTG_SHNPINT (1 << 2)
59#define USBOTG_FCINT (1 << 1)
60#define USBOTG_HCINT (1 << 0)
61
62#define USBOTG_CLK_CTRL 0x0c
63#define USBOTG_CLK_CTRL_FUNC (1 << 2)
64#define USBOTG_CLK_CTRL_HST (1 << 1)
65#define USBOTG_CLK_CTRL_MAIN (1 << 0)
66
67#define USBOTG_RST_CTRL 0x10
68#define USBOTG_RST_RSTI2C (1 << 15)
69#define USBOTG_RST_RSTCTRL (1 << 5)
70#define USBOTG_RST_RSTFC (1 << 4)
71#define USBOTG_RST_RSTFSKE (1 << 3)
72#define USBOTG_RST_RSTRH (1 << 2)
73#define USBOTG_RST_RSTHSIE (1 << 1)
74#define USBOTG_RST_RSTHC (1 << 0)
75
76#define USBOTG_FRM_INTVL 0x14
77#define USBOTG_FRM_REMAIN 0x18
78#define USBOTG_HNP_CSR 0x1c
79#define USBOTG_HNP_ISR 0x2c
80#define USBOTG_HNP_IEN 0x30
81
82#define USBOTG_I2C_TXCVR_REG(x) (0x100 + (x))
83#define USBOTG_I2C_XCVR_DEVAD 0x118
84#define USBOTG_I2C_SEQ_OP_REG 0x119
85#define USBOTG_I2C_SEQ_RD_STARTAD 0x11a
86#define USBOTG_I2C_OP_CTRL_REG 0x11b
87#define USBOTG_I2C_SCLK_TO_SCK_HPER 0x11e
88#define USBOTG_I2C_MASTER_INT_REG 0x11f
89
90#define USBH_HOST_CTRL 0x80
91#define USBH_HOST_CTRL_HCRESET (1 << 31)
92#define USBH_HOST_CTRL_SCHDOVR(x) ((x) << 16)
93#define USBH_HOST_CTRL_RMTWUEN (1 << 4)
94#define USBH_HOST_CTRL_HCUSBSTE_RESET (0 << 2)
95#define USBH_HOST_CTRL_HCUSBSTE_RESUME (1 << 2)
96#define USBH_HOST_CTRL_HCUSBSTE_OPERATIONAL (2 << 2)
97#define USBH_HOST_CTRL_HCUSBSTE_SUSPEND (3 << 2)
98#define USBH_HOST_CTRL_CTLBLKSR_1 (0 << 0)
99#define USBH_HOST_CTRL_CTLBLKSR_2 (1 << 0)
100#define USBH_HOST_CTRL_CTLBLKSR_3 (2 << 0)
101#define USBH_HOST_CTRL_CTLBLKSR_4 (3 << 0)
102
103#define USBH_SYSISR 0x88
104#define USBH_SYSISR_PSCINT (1 << 6)
105#define USBH_SYSISR_FMOFINT (1 << 5)
106#define USBH_SYSISR_HERRINT (1 << 4)
107#define USBH_SYSISR_RESDETINT (1 << 3)
108#define USBH_SYSISR_SOFINT (1 << 2)
109#define USBH_SYSISR_DONEINT (1 << 1)
110#define USBH_SYSISR_SORINT (1 << 0)
111
112#define USBH_SYSIEN 0x8c
113#define USBH_SYSIEN_PSCINT (1 << 6)
114#define USBH_SYSIEN_FMOFINT (1 << 5)
115#define USBH_SYSIEN_HERRINT (1 << 4)
116#define USBH_SYSIEN_RESDETINT (1 << 3)
117#define USBH_SYSIEN_SOFINT (1 << 2)
118#define USBH_SYSIEN_DONEINT (1 << 1)
119#define USBH_SYSIEN_SORINT (1 << 0)
120
121#define USBH_XBUFSTAT 0x98
122#define USBH_YBUFSTAT 0x9c
123#define USBH_XYINTEN 0xa0
124#define USBH_XFILLSTAT 0xa8
125#define USBH_YFILLSTAT 0xac
126#define USBH_ETDENSET 0xc0
127#define USBH_ETDENCLR 0xc4
128#define USBH_IMMEDINT 0xcc
129#define USBH_ETDDONESTAT 0xd0
130#define USBH_ETDDONEEN 0xd4
131#define USBH_FRMNUB 0xe0
132#define USBH_LSTHRESH 0xe4
133
134#define USBH_ROOTHUBA 0xe8
135#define USBH_ROOTHUBA_PWRTOGOOD_MASK (0xff)
136#define USBH_ROOTHUBA_PWRTOGOOD_SHIFT (24)
137#define USBH_ROOTHUBA_NOOVRCURP (1 << 12)
138#define USBH_ROOTHUBA_OVRCURPM (1 << 11)
139#define USBH_ROOTHUBA_DEVTYPE (1 << 10)
140#define USBH_ROOTHUBA_PWRSWTMD (1 << 9)
141#define USBH_ROOTHUBA_NOPWRSWT (1 << 8)
142#define USBH_ROOTHUBA_NDNSTMPRT_MASK (0xff)
143
144#define USBH_ROOTHUBB 0xec
145#define USBH_ROOTHUBB_PRTPWRCM(x) (1 << ((x) + 16))
146#define USBH_ROOTHUBB_DEVREMOVE(x) (1 << (x))
147
148#define USBH_ROOTSTAT 0xf0
149#define USBH_ROOTSTAT_CLRRMTWUE (1 << 31)
150#define USBH_ROOTSTAT_OVRCURCHG (1 << 17)
151#define USBH_ROOTSTAT_DEVCONWUE (1 << 15)
152#define USBH_ROOTSTAT_OVRCURI (1 << 1)
153#define USBH_ROOTSTAT_LOCPWRS (1 << 0)
154
155#define USBH_PORTSTAT(x) (0xf4 + ((x) * 4))
156#define USBH_PORTSTAT_PRTRSTSC (1 << 20)
157#define USBH_PORTSTAT_OVRCURIC (1 << 19)
158#define USBH_PORTSTAT_PRTSTATSC (1 << 18)
159#define USBH_PORTSTAT_PRTENBLSC (1 << 17)
160#define USBH_PORTSTAT_CONNECTSC (1 << 16)
161#define USBH_PORTSTAT_LSDEVCON (1 << 9)
162#define USBH_PORTSTAT_PRTPWRST (1 << 8)
163#define USBH_PORTSTAT_PRTRSTST (1 << 4)
164#define USBH_PORTSTAT_PRTOVRCURI (1 << 3)
165#define USBH_PORTSTAT_PRTSUSPST (1 << 2)
166#define USBH_PORTSTAT_PRTENABST (1 << 1)
167#define USBH_PORTSTAT_CURCONST (1 << 0)
168
169#define USB_DMAREV 0x800
170#define USB_DMAINTSTAT 0x804
171#define USB_DMAINTSTAT_EPERR (1 << 1)
172#define USB_DMAINTSTAT_ETDERR (1 << 0)
173
174#define USB_DMAINTEN 0x808
175#define USB_DMAINTEN_EPERRINTEN (1 << 1)
176#define USB_DMAINTEN_ETDERRINTEN (1 << 0)
177
178#define USB_ETDDMAERSTAT 0x80c
179#define USB_EPDMAERSTAT 0x810
180#define USB_ETDDMAEN 0x820
181#define USB_EPDMAEN 0x824
182#define USB_ETDDMAXTEN 0x828
183#define USB_EPDMAXTEN 0x82c
184#define USB_ETDDMAENXYT 0x830
185#define USB_EPDMAENXYT 0x834
186#define USB_ETDDMABST4EN 0x838
187#define USB_EPDMABST4EN 0x83c
188
189#define USB_MISCCONTROL 0x840
190#define USB_MISCCONTROL_ISOPREVFRM (1 << 3)
191#define USB_MISCCONTROL_SKPRTRY (1 << 2)
192#define USB_MISCCONTROL_ARBMODE (1 << 1)
193#define USB_MISCCONTROL_FILTCC (1 << 0)
194
195#define USB_ETDDMACHANLCLR 0x848
196#define USB_EPDMACHANLCLR 0x84c
197#define USB_ETDSMSA(x) (0x900 + ((x) * 4))
198#define USB_EPSMSA(x) (0x980 + ((x) * 4))
199#define USB_ETDDMABUFPTR(x) (0xa00 + ((x) * 4))
200#define USB_EPDMABUFPTR(x) (0xa80 + ((x) * 4))
201
202#define USB_ETD_DWORD(x, w) (0x200 + ((x) * 16) + ((w) * 4))
203#define DW0_ADDRESS 0
204#define DW0_ENDPNT 7
205#define DW0_DIRECT 11
206#define DW0_SPEED 13
207#define DW0_FORMAT 14
208#define DW0_MAXPKTSIZ 16
209#define DW0_HALTED 27
210#define DW0_TOGCRY 28
211#define DW0_SNDNAK 30
212
213#define DW1_XBUFSRTAD 0
214#define DW1_YBUFSRTAD 16
215
216#define DW2_RTRYDELAY 0
217#define DW2_POLINTERV 0
218#define DW2_STARTFRM 0
219#define DW2_RELPOLPOS 8
220#define DW2_DIRPID 16
221#define DW2_BUFROUND 18
222#define DW2_DELAYINT 19
223#define DW2_DATATOG 22
224#define DW2_ERRORCNT 24
225#define DW2_COMPCODE 28
226
227#define DW3_TOTBYECNT 0
228#define DW3_PKTLEN0 0
229#define DW3_COMPCODE0 12
230#define DW3_PKTLEN1 16
231#define DW3_BUFSIZE 21
232#define DW3_COMPCODE1 28
233
234#define USBCTRL 0x600
235#define USBCTRL_I2C_WU_INT_STAT (1 << 27)
236#define USBCTRL_OTG_WU_INT_STAT (1 << 26)
237#define USBCTRL_HOST_WU_INT_STAT (1 << 25)
238#define USBCTRL_FNT_WU_INT_STAT (1 << 24)
239#define USBCTRL_I2C_WU_INT_EN (1 << 19)
240#define USBCTRL_OTG_WU_INT_EN (1 << 18)
241#define USBCTRL_HOST_WU_INT_EN (1 << 17)
242#define USBCTRL_FNT_WU_INT_EN (1 << 16)
243#define USBCTRL_OTC_RCV_RXDP (1 << 13)
244#define USBCTRL_HOST1_BYP_TLL (1 << 12)
245#define USBCTRL_OTG_BYP_VAL(x) ((x) << 10)
246#define USBCTRL_HOST1_BYP_VAL(x) ((x) << 8)
247#define USBCTRL_OTG_PWR_MASK (1 << 6)
248#define USBCTRL_HOST1_PWR_MASK (1 << 5)
249#define USBCTRL_HOST2_PWR_MASK (1 << 4)
250#define USBCTRL_USB_BYP (1 << 2)
251#define USBCTRL_HOST1_TXEN_OE (1 << 1)
252
253
254/* Values in TD blocks */
255#define TD_DIR_SETUP 0
256#define TD_DIR_OUT 1
257#define TD_DIR_IN 2
258#define TD_FORMAT_CONTROL 0
259#define TD_FORMAT_ISO 1
260#define TD_FORMAT_BULK 2
261#define TD_FORMAT_INT 3
262#define TD_TOGGLE_CARRY 0
263#define TD_TOGGLE_DATA0 2
264#define TD_TOGGLE_DATA1 3
265
266/* control transfer states */
267#define US_CTRL_SETUP 2
268#define US_CTRL_DATA 1
269#define US_CTRL_ACK 0
270
271/* bulk transfer main state and 0-length packet */
272#define US_BULK 1
273#define US_BULK0 0
274
275/*ETD format description*/
276#define IMX_FMT_CTRL 0x0
277#define IMX_FMT_ISO 0x1
278#define IMX_FMT_BULK 0x2
279#define IMX_FMT_INT 0x3
280
281static char fmt_urb_to_etd[4] = {
282/*PIPE_ISOCHRONOUS*/ IMX_FMT_ISO,
283/*PIPE_INTERRUPT*/ IMX_FMT_INT,
284/*PIPE_CONTROL*/ IMX_FMT_CTRL,
285/*PIPE_BULK*/ IMX_FMT_BULK
286};
287
288/* condition (error) CC codes and mapping (OHCI like) */
289
290#define TD_CC_NOERROR 0x00
291#define TD_CC_CRC 0x01
292#define TD_CC_BITSTUFFING 0x02
293#define TD_CC_DATATOGGLEM 0x03
294#define TD_CC_STALL 0x04
295#define TD_DEVNOTRESP 0x05
296#define TD_PIDCHECKFAIL 0x06
297/*#define TD_UNEXPECTEDPID 0x07 - reserved, not active on MX2*/
298#define TD_DATAOVERRUN 0x08
299#define TD_DATAUNDERRUN 0x09
300#define TD_BUFFEROVERRUN 0x0C
301#define TD_BUFFERUNDERRUN 0x0D
302#define TD_SCHEDULEOVERRUN 0x0E
303#define TD_NOTACCESSED 0x0F
304
305static const int cc_to_error[16] = {
306 /* No Error */ 0,
307 /* CRC Error */ -EILSEQ,
308 /* Bit Stuff */ -EPROTO,
309 /* Data Togg */ -EILSEQ,
310 /* Stall */ -EPIPE,
311 /* DevNotResp */ -ETIMEDOUT,
312 /* PIDCheck */ -EPROTO,
313 /* UnExpPID */ -EPROTO,
314 /* DataOver */ -EOVERFLOW,
315 /* DataUnder */ -EREMOTEIO,
316 /* (for hw) */ -EIO,
317 /* (for hw) */ -EIO,
318 /* BufferOver */ -ECOMM,
319 /* BuffUnder */ -ENOSR,
320 /* (for HCD) */ -ENOSPC,
321 /* (for HCD) */ -EALREADY
322};
323
324/* HCD data associated with a usb core URB */
325struct urb_priv {
326 struct urb *urb;
327 struct usb_host_endpoint *ep;
328 int active;
329 int state;
330 struct td *isoc_td;
331 int isoc_remaining;
332 int isoc_status;
333};
334
335/* HCD data associated with a usb core endpoint */
336struct ep_priv {
337 struct usb_host_endpoint *ep;
338 struct list_head td_list;
339 struct list_head queue;
340 int etd[NUM_ISO_ETDS];
341 int waiting_etd;
342};
343
344/* isoc packet */
345struct td {
346 struct list_head list;
347 struct urb *urb;
348 struct usb_host_endpoint *ep;
349 dma_addr_t data;
350 unsigned long buf_addr;
351 int len;
352 int frame;
353 int isoc_index;
354};
355
356/* HCD data associated with a hardware ETD */
357struct etd_priv {
358 struct usb_host_endpoint *ep;
359 struct urb *urb;
360 struct td *td;
361 struct list_head queue;
362 dma_addr_t dma_handle;
363 int alloc;
364 int len;
365 int dmem_size;
366 int dmem_offset;
367 int active_count;
368#ifdef DEBUG
369 int activated_frame;
370 int disactivated_frame;
371 int last_int_frame;
372 int last_req_frame;
373 u32 submitted_dwords[4];
374#endif
375};
376
377/* Hardware data memory info */
378struct imx21_dmem_area {
379 struct usb_host_endpoint *ep;
380 unsigned int offset;
381 unsigned int size;
382 struct list_head list;
383};
384
385#ifdef DEBUG
386struct debug_usage_stats {
387 unsigned int value;
388 unsigned int maximum;
389};
390
391struct debug_stats {
392 unsigned long submitted;
393 unsigned long completed_ok;
394 unsigned long completed_failed;
395 unsigned long unlinked;
396 unsigned long queue_etd;
397 unsigned long queue_dmem;
398};
399
400struct debug_isoc_trace {
401 int schedule_frame;
402 int submit_frame;
403 int request_len;
404 int done_frame;
405 int done_len;
406 int cc;
407 struct td *td;
408};
409#endif
410
411/* HCD data structure */
412struct imx21 {
413 spinlock_t lock;
414 struct device *dev;
415 struct mx21_usbh_platform_data *pdata;
416 struct list_head dmem_list;
417 struct list_head queue_for_etd; /* eps queued due to etd shortage */
418 struct list_head queue_for_dmem; /* etds queued due to dmem shortage */
419 struct etd_priv etd[USB_NUM_ETD];
420 struct clk *clk;
421 void __iomem *regs;
422#ifdef DEBUG
423 struct dentry *debug_root;
424 struct debug_stats nonisoc_stats;
425 struct debug_stats isoc_stats;
426 struct debug_usage_stats etd_usage;
427 struct debug_usage_stats dmem_usage;
428 struct debug_isoc_trace isoc_trace[20];
429 struct debug_isoc_trace isoc_trace_failed[20];
430 unsigned long debug_unblocks;
431 int isoc_trace_index;
432 int isoc_trace_index_failed;
433#endif
434};
435
436#endif
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index a2b305477afe..92de71dc7729 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -62,6 +62,7 @@
62#include <linux/errno.h> 62#include <linux/errno.h>
63#include <linux/init.h> 63#include <linux/init.h>
64#include <linux/list.h> 64#include <linux/list.h>
65#include <linux/slab.h>
65#include <linux/usb.h> 66#include <linux/usb.h>
66#include <linux/usb/isp116x.h> 67#include <linux/usb/isp116x.h>
67#include <linux/platform_device.h> 68#include <linux/platform_device.h>
diff --git a/drivers/usb/host/isp1362-hcd.c b/drivers/usb/host/isp1362-hcd.c
index 5c774ab98252..217fb5170200 100644
--- a/drivers/usb/host/isp1362-hcd.c
+++ b/drivers/usb/host/isp1362-hcd.c
@@ -80,7 +80,7 @@
80#include <linux/platform_device.h> 80#include <linux/platform_device.h>
81#include <linux/pm.h> 81#include <linux/pm.h>
82#include <linux/io.h> 82#include <linux/io.h>
83#include <linux/bitops.h> 83#include <linux/bitmap.h>
84 84
85#include <asm/irq.h> 85#include <asm/irq.h>
86#include <asm/system.h> 86#include <asm/system.h>
@@ -190,10 +190,8 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
190 struct isp1362_ep *ep, u16 len) 190 struct isp1362_ep *ep, u16 len)
191{ 191{
192 int ptd_offset = -EINVAL; 192 int ptd_offset = -EINVAL;
193 int index;
194 int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1; 193 int num_ptds = ((len + PTD_HEADER_SIZE - 1) / epq->blk_size) + 1;
195 int found = -1; 194 int found;
196 int last = -1;
197 195
198 BUG_ON(len > epq->buf_size); 196 BUG_ON(len > epq->buf_size);
199 197
@@ -205,20 +203,9 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
205 epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map); 203 epq->name, len, epq->blk_size, num_ptds, epq->buf_map, epq->skip_map);
206 BUG_ON(ep->num_ptds != 0); 204 BUG_ON(ep->num_ptds != 0);
207 205
208 for (index = 0; index <= epq->buf_count - num_ptds; index++) { 206 found = bitmap_find_next_zero_area(&epq->buf_map, epq->buf_count, 0,
209 if (test_bit(index, &epq->buf_map)) 207 num_ptds, 0);
210 continue; 208 if (found >= epq->buf_count)
211 found = index;
212 for (last = index + 1; last < index + num_ptds; last++) {
213 if (test_bit(last, &epq->buf_map)) {
214 found = -1;
215 break;
216 }
217 }
218 if (found >= 0)
219 break;
220 }
221 if (found < 0)
222 return -EOVERFLOW; 209 return -EOVERFLOW;
223 210
224 DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__, 211 DBG(1, "%s: Found %d PTDs[%d] for %d/%d byte\n", __func__,
@@ -230,8 +217,7 @@ static int claim_ptd_buffers(struct isp1362_ep_queue *epq,
230 epq->buf_avail -= num_ptds; 217 epq->buf_avail -= num_ptds;
231 BUG_ON(epq->buf_avail > epq->buf_count); 218 BUG_ON(epq->buf_avail > epq->buf_count);
232 ep->ptd_index = found; 219 ep->ptd_index = found;
233 for (index = found; index < last; index++) 220 bitmap_set(&epq->buf_map, found, num_ptds);
234 __set_bit(index, &epq->buf_map);
235 DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n", 221 DBG(1, "%s: Done %s PTD[%d] $%04x, avail %d count %d claimed %d %08lx:%08lx\n",
236 __func__, epq->name, ep->ptd_index, ep->ptd_offset, 222 __func__, epq->name, ep->ptd_index, ep->ptd_offset,
237 epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map); 223 epq->buf_avail, epq->buf_count, num_ptds, epq->buf_map, epq->skip_map);
@@ -1271,7 +1257,7 @@ static int isp1362_urb_enqueue(struct usb_hcd *hcd,
1271 1257
1272 /* avoid all allocations within spinlocks: request or endpoint */ 1258 /* avoid all allocations within spinlocks: request or endpoint */
1273 if (!hep->hcpriv) { 1259 if (!hep->hcpriv) {
1274 ep = kcalloc(1, sizeof *ep, mem_flags); 1260 ep = kzalloc(sizeof *ep, mem_flags);
1275 if (!ep) 1261 if (!ep)
1276 return -ENOMEM; 1262 return -ENOMEM;
1277 } 1263 }
@@ -2284,10 +2270,10 @@ static int isp1362_mem_config(struct usb_hcd *hcd)
2284 dev_info(hcd->self.controller, "ISP1362 Memory usage:\n"); 2270 dev_info(hcd->self.controller, "ISP1362 Memory usage:\n");
2285 dev_info(hcd->self.controller, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n", 2271 dev_info(hcd->self.controller, " ISTL: 2 * %4d: %4d @ $%04x:$%04x\n",
2286 istl_size / 2, istl_size, 0, istl_size / 2); 2272 istl_size / 2, istl_size, 0, istl_size / 2);
2287 dev_info(hcd->self.controller, " INTL: %4d * (%3lu+8): %4d @ $%04x\n", 2273 dev_info(hcd->self.controller, " INTL: %4d * (%3zu+8): %4d @ $%04x\n",
2288 ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE, 2274 ISP1362_INTL_BUFFERS, intl_blksize - PTD_HEADER_SIZE,
2289 intl_size, istl_size); 2275 intl_size, istl_size);
2290 dev_info(hcd->self.controller, " ATL : %4d * (%3lu+8): %4d @ $%04x\n", 2276 dev_info(hcd->self.controller, " ATL : %4d * (%3zu+8): %4d @ $%04x\n",
2291 atl_buffers, atl_blksize - PTD_HEADER_SIZE, 2277 atl_buffers, atl_blksize - PTD_HEADER_SIZE,
2292 atl_size, istl_size + intl_size); 2278 atl_size, istl_size + intl_size);
2293 dev_info(hcd->self.controller, " USED/FREE: %4d %4d\n", total, 2279 dev_info(hcd->self.controller, " USED/FREE: %4d %4d\n", total,
@@ -2711,6 +2697,8 @@ static int __init isp1362_probe(struct platform_device *pdev)
2711 void __iomem *data_reg; 2697 void __iomem *data_reg;
2712 int irq; 2698 int irq;
2713 int retval = 0; 2699 int retval = 0;
2700 struct resource *irq_res;
2701 unsigned int irq_flags = 0;
2714 2702
2715 /* basic sanity checks first. board-specific init logic should 2703 /* basic sanity checks first. board-specific init logic should
2716 * have initialized this the three resources and probably board 2704 * have initialized this the three resources and probably board
@@ -2724,30 +2712,18 @@ static int __init isp1362_probe(struct platform_device *pdev)
2724 2712
2725 data = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2713 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2726 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1); 2714 addr = platform_get_resource(pdev, IORESOURCE_MEM, 1);
2727 irq = platform_get_irq(pdev, 0); 2715 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
2728 if (!addr || !data || irq < 0) { 2716 if (!addr || !data || !irq_res) {
2729 retval = -ENODEV; 2717 retval = -ENODEV;
2730 goto err1; 2718 goto err1;
2731 } 2719 }
2720 irq = irq_res->start;
2732 2721
2733#ifdef CONFIG_USB_HCD_DMA
2734 if (pdev->dev.dma_mask) {
2735 struct resource *dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
2736
2737 if (!dma_res) {
2738 retval = -ENODEV;
2739 goto err1;
2740 }
2741 isp1362_hcd->data_dma = dma_res->start;
2742 isp1362_hcd->max_dma_size = resource_len(dma_res);
2743 }
2744#else
2745 if (pdev->dev.dma_mask) { 2722 if (pdev->dev.dma_mask) {
2746 DBG(1, "won't do DMA"); 2723 DBG(1, "won't do DMA");
2747 retval = -ENODEV; 2724 retval = -ENODEV;
2748 goto err1; 2725 goto err1;
2749 } 2726 }
2750#endif
2751 2727
2752 if (!request_mem_region(addr->start, resource_len(addr), hcd_name)) { 2728 if (!request_mem_region(addr->start, resource_len(addr), hcd_name)) {
2753 retval = -EBUSY; 2729 retval = -EBUSY;
@@ -2795,12 +2771,16 @@ static int __init isp1362_probe(struct platform_device *pdev)
2795 } 2771 }
2796#endif 2772#endif
2797 2773
2798#ifdef CONFIG_ARM 2774 if (irq_res->flags & IORESOURCE_IRQ_HIGHEDGE)
2799 if (isp1362_hcd->board) 2775 irq_flags |= IRQF_TRIGGER_RISING;
2800 set_irq_type(irq, isp1362_hcd->board->int_act_high ? IRQT_RISING : IRQT_FALLING); 2776 if (irq_res->flags & IORESOURCE_IRQ_LOWEDGE)
2801#endif 2777 irq_flags |= IRQF_TRIGGER_FALLING;
2778 if (irq_res->flags & IORESOURCE_IRQ_HIGHLEVEL)
2779 irq_flags |= IRQF_TRIGGER_HIGH;
2780 if (irq_res->flags & IORESOURCE_IRQ_LOWLEVEL)
2781 irq_flags |= IRQF_TRIGGER_LOW;
2802 2782
2803 retval = usb_add_hcd(hcd, irq, IRQF_TRIGGER_LOW | IRQF_DISABLED | IRQF_SHARED); 2783 retval = usb_add_hcd(hcd, irq, irq_flags | IRQF_DISABLED | IRQF_SHARED);
2804 if (retval != 0) 2784 if (retval != 0)
2805 goto err6; 2785 goto err6;
2806 pr_info("%s, irq %d\n", hcd->product_desc, irq); 2786 pr_info("%s, irq %d\n", hcd->product_desc, irq);
diff --git a/drivers/usb/host/isp1362.h b/drivers/usb/host/isp1362.h
index 1a253ebf7e50..5151516ea1de 100644
--- a/drivers/usb/host/isp1362.h
+++ b/drivers/usb/host/isp1362.h
@@ -534,8 +534,8 @@ struct isp1362_hcd {
534 534
535 /* periodic schedule: isochronous */ 535 /* periodic schedule: isochronous */
536 struct list_head isoc; 536 struct list_head isoc;
537 int istl_flip:1; 537 unsigned int istl_flip:1;
538 int irq_active:1; 538 unsigned int irq_active:1;
539 539
540 /* Schedules for the current frame */ 540 /* Schedules for the current frame */
541 struct isp1362_ep_queue atl_queue; 541 struct isp1362_ep_queue atl_queue;
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index 9600a58299db..9f01293600b0 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -17,7 +17,9 @@
17#include <linux/debugfs.h> 17#include <linux/debugfs.h>
18#include <linux/uaccess.h> 18#include <linux/uaccess.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/mm.h>
20#include <asm/unaligned.h> 21#include <asm/unaligned.h>
22#include <asm/cacheflush.h>
21 23
22#include "../core/hcd.h" 24#include "../core/hcd.h"
23#include "isp1760-hcd.h" 25#include "isp1760-hcd.h"
@@ -904,6 +906,14 @@ __acquires(priv->lock)
904 status = 0; 906 status = 0;
905 } 907 }
906 908
909 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
910 void *ptr;
911 for (ptr = urb->transfer_buffer;
912 ptr < urb->transfer_buffer + urb->transfer_buffer_length;
913 ptr += PAGE_SIZE)
914 flush_dcache_page(virt_to_page(ptr));
915 }
916
907 /* complete() can reenter this HCD */ 917 /* complete() can reenter this HCD */
908 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb); 918 usb_hcd_unlink_urb_from_ep(priv_to_hcd(priv), urb);
909 spin_unlock(&priv->lock); 919 spin_unlock(&priv->lock);
@@ -1039,12 +1049,12 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
1039 if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) { 1049 if (!nakcount && (dw3 & DW3_QTD_ACTIVE)) {
1040 u32 buffstatus; 1050 u32 buffstatus;
1041 1051
1042 /* XXX 1052 /*
1043 * NAKs are handled in HW by the chip. Usually if the 1053 * NAKs are handled in HW by the chip. Usually if the
1044 * device is not able to send data fast enough. 1054 * device is not able to send data fast enough.
1045 * This did not trigger for a long time now. 1055 * This happens mostly on slower hardware.
1046 */ 1056 */
1047 printk(KERN_ERR "Reloading ptd %p/%p... qh %p readed: " 1057 printk(KERN_NOTICE "Reloading ptd %p/%p... qh %p read: "
1048 "%d of %zu done: %08x cur: %08x\n", qtd, 1058 "%d of %zu done: %08x cur: %08x\n", qtd,
1049 urb, qh, PTD_XFERRED_LENGTH(dw3), 1059 urb, qh, PTD_XFERRED_LENGTH(dw3),
1050 qtd->length, done_map, 1060 qtd->length, done_map,
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 1c9f977a5c9c..4293cfd28d61 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -109,7 +109,7 @@ static int of_isp1760_remove(struct of_device *dev)
109 return 0; 109 return 0;
110} 110}
111 111
112static struct of_device_id of_isp1760_match[] = { 112static const struct of_device_id of_isp1760_match[] = {
113 { 113 {
114 .compatible = "nxp,usb-isp1760", 114 .compatible = "nxp,usb-isp1760",
115 }, 115 },
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 7ccffcbe7b6f..944291e10f97 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -35,7 +35,7 @@ extern int usb_disabled(void);
35 35
36static void at91_start_clock(void) 36static void at91_start_clock(void)
37{ 37{
38 if (cpu_is_at91sam9261()) 38 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10())
39 clk_enable(hclk); 39 clk_enable(hclk);
40 clk_enable(iclk); 40 clk_enable(iclk);
41 clk_enable(fclk); 41 clk_enable(fclk);
@@ -46,7 +46,7 @@ static void at91_stop_clock(void)
46{ 46{
47 clk_disable(fclk); 47 clk_disable(fclk);
48 clk_disable(iclk); 48 clk_disable(iclk);
49 if (cpu_is_at91sam9261()) 49 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10())
50 clk_disable(hclk); 50 clk_disable(hclk);
51 clocked = 0; 51 clocked = 0;
52} 52}
@@ -142,7 +142,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
142 142
143 iclk = clk_get(&pdev->dev, "ohci_clk"); 143 iclk = clk_get(&pdev->dev, "ohci_clk");
144 fclk = clk_get(&pdev->dev, "uhpck"); 144 fclk = clk_get(&pdev->dev, "uhpck");
145 if (cpu_is_at91sam9261()) 145 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10())
146 hclk = clk_get(&pdev->dev, "hck0"); 146 hclk = clk_get(&pdev->dev, "hck0");
147 147
148 at91_start_hc(pdev); 148 at91_start_hc(pdev);
@@ -155,7 +155,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
155 /* Error handling */ 155 /* Error handling */
156 at91_stop_hc(pdev); 156 at91_stop_hc(pdev);
157 157
158 if (cpu_is_at91sam9261()) 158 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10())
159 clk_put(hclk); 159 clk_put(hclk);
160 clk_put(fclk); 160 clk_put(fclk);
161 clk_put(iclk); 161 clk_put(iclk);
@@ -192,7 +192,7 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
192 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 192 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
193 usb_put_hcd(hcd); 193 usb_put_hcd(hcd);
194 194
195 if (cpu_is_at91sam9261()) 195 if (cpu_is_at91sam9261() || cpu_is_at91sam9g10())
196 clk_put(hclk); 196 clk_put(hclk);
197 clk_put(fclk); 197 clk_put(fclk);
198 clk_put(iclk); 198 clk_put(iclk);
@@ -331,6 +331,8 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, pm_message_t mesg)
331 */ 331 */
332 if (at91_suspend_entering_slow_clock()) { 332 if (at91_suspend_entering_slow_clock()) {
333 ohci_usb_reset (ohci); 333 ohci_usb_reset (ohci);
334 /* flush the writes */
335 (void) ohci_readl (ohci, &ohci->regs->control);
334 at91_stop_clock(); 336 at91_stop_clock();
335 } 337 }
336 338
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index e4380082ebb1..17a6043c1fa0 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -294,7 +294,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
294 return 0; 294 return 0;
295} 295}
296 296
297static struct dev_pm_ops au1xxx_ohci_pmops = { 297static const struct dev_pm_ops au1xxx_ohci_pmops = {
298 .suspend = ohci_hcd_au1xxx_drv_suspend, 298 .suspend = ohci_hcd_au1xxx_drv_suspend,
299 .resume = ohci_hcd_au1xxx_drv_resume, 299 .resume = ohci_hcd_au1xxx_drv_resume,
300}; 300};
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
new file mode 100644
index 000000000000..d22fb4d577b7
--- /dev/null
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -0,0 +1,456 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * TI DA8xx (OMAP-L1x) Bus Glue
5 *
6 * Derived from: ohci-omap.c and ohci-s3c2410.c
7 * Copyright (C) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
8 *
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
12 */
13
14#include <linux/interrupt.h>
15#include <linux/jiffies.h>
16#include <linux/platform_device.h>
17#include <linux/clk.h>
18
19#include <mach/da8xx.h>
20#include <mach/usb.h>
21
22#ifndef CONFIG_ARCH_DAVINCI_DA8XX
23#error "This file is DA8xx bus glue. Define CONFIG_ARCH_DAVINCI_DA8XX."
24#endif
25
26#define CFGCHIP2 DA8XX_SYSCFG0_VIRT(DA8XX_CFGCHIP2_REG)
27
28static struct clk *usb11_clk;
29static struct clk *usb20_clk;
30
31/* Over-current indicator change bitmask */
32static volatile u16 ocic_mask;
33
34static void ohci_da8xx_clock(int on)
35{
36 u32 cfgchip2;
37
38 cfgchip2 = __raw_readl(CFGCHIP2);
39 if (on) {
40 clk_enable(usb11_clk);
41
42 /*
43 * If USB 1.1 reference clock is sourced from USB 2.0 PHY, we
44 * need to enable the USB 2.0 module clocking, start its PHY,
45 * and not allow it to stop the clock during USB 2.0 suspend.
46 */
47 if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX)) {
48 clk_enable(usb20_clk);
49
50 cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN);
51 cfgchip2 |= CFGCHIP2_PHY_PLLON;
52 __raw_writel(cfgchip2, CFGCHIP2);
53
54 pr_info("Waiting for USB PHY clock good...\n");
55 while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD))
56 cpu_relax();
57 }
58
59 /* Enable USB 1.1 PHY */
60 cfgchip2 |= CFGCHIP2_USB1SUSPENDM;
61 } else {
62 clk_disable(usb11_clk);
63 if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX))
64 clk_disable(usb20_clk);
65
66 /* Disable USB 1.1 PHY */
67 cfgchip2 &= ~CFGCHIP2_USB1SUSPENDM;
68 }
69 __raw_writel(cfgchip2, CFGCHIP2);
70}
71
72/*
73 * Handle the port over-current indicator change.
74 */
75static void ohci_da8xx_ocic_handler(struct da8xx_ohci_root_hub *hub,
76 unsigned port)
77{
78 ocic_mask |= 1 << port;
79
80 /* Once over-current is detected, the port needs to be powered down */
81 if (hub->get_oci(port) > 0)
82 hub->set_power(port, 0);
83}
84
85static int ohci_da8xx_init(struct usb_hcd *hcd)
86{
87 struct device *dev = hcd->self.controller;
88 struct da8xx_ohci_root_hub *hub = dev->platform_data;
89 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
90 int result;
91 u32 rh_a;
92
93 dev_dbg(dev, "starting USB controller\n");
94
95 ohci_da8xx_clock(1);
96
97 /*
98 * DA8xx only have 1 port connected to the pins but the HC root hub
99 * register A reports 2 ports, thus we'll have to override it...
100 */
101 ohci->num_ports = 1;
102
103 result = ohci_init(ohci);
104 if (result < 0)
105 return result;
106
107 /*
108 * Since we're providing a board-specific root hub port power control
109 * and over-current reporting, we have to override the HC root hub A
110 * register's default value, so that ohci_hub_control() could return
111 * the correct hub descriptor...
112 */
113 rh_a = ohci_readl(ohci, &ohci->regs->roothub.a);
114 if (hub->set_power) {
115 rh_a &= ~RH_A_NPS;
116 rh_a |= RH_A_PSM;
117 }
118 if (hub->get_oci) {
119 rh_a &= ~RH_A_NOCP;
120 rh_a |= RH_A_OCPM;
121 }
122 rh_a &= ~RH_A_POTPGT;
123 rh_a |= hub->potpgt << 24;
124 ohci_writel(ohci, rh_a, &ohci->regs->roothub.a);
125
126 return result;
127}
128
129static void ohci_da8xx_stop(struct usb_hcd *hcd)
130{
131 ohci_stop(hcd);
132 ohci_da8xx_clock(0);
133}
134
135static int ohci_da8xx_start(struct usb_hcd *hcd)
136{
137 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
138 int result;
139
140 result = ohci_run(ohci);
141 if (result < 0)
142 ohci_da8xx_stop(hcd);
143
144 return result;
145}
146
147/*
148 * Update the status data from the hub with the over-current indicator change.
149 */
150static int ohci_da8xx_hub_status_data(struct usb_hcd *hcd, char *buf)
151{
152 int length = ohci_hub_status_data(hcd, buf);
153
154 /* See if we have OCIC bit set on port 1 */
155 if (ocic_mask & (1 << 1)) {
156 dev_dbg(hcd->self.controller, "over-current indicator change "
157 "on port 1\n");
158
159 if (!length)
160 length = 1;
161
162 buf[0] |= 1 << 1;
163 }
164 return length;
165}
166
167/*
168 * Look at the control requests to the root hub and see if we need to override.
169 */
170static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
171 u16 wIndex, char *buf, u16 wLength)
172{
173 struct device *dev = hcd->self.controller;
174 struct da8xx_ohci_root_hub *hub = dev->platform_data;
175 int temp;
176
177 switch (typeReq) {
178 case GetPortStatus:
179 /* Check the port number */
180 if (wIndex != 1)
181 break;
182
183 dev_dbg(dev, "GetPortStatus(%u)\n", wIndex);
184
185 temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
186
187 /* The port power status (PPS) bit defaults to 1 */
188 if (hub->get_power && hub->get_power(wIndex) == 0)
189 temp &= ~RH_PS_PPS;
190
191 /* The port over-current indicator (POCI) bit is always 0 */
192 if (hub->get_oci && hub->get_oci(wIndex) > 0)
193 temp |= RH_PS_POCI;
194
195 /* The over-current indicator change (OCIC) bit is 0 too */
196 if (ocic_mask & (1 << wIndex))
197 temp |= RH_PS_OCIC;
198
199 put_unaligned(cpu_to_le32(temp), (__le32 *)buf);
200 return 0;
201 case SetPortFeature:
202 temp = 1;
203 goto check_port;
204 case ClearPortFeature:
205 temp = 0;
206
207check_port:
208 /* Check the port number */
209 if (wIndex != 1)
210 break;
211
212 switch (wValue) {
213 case USB_PORT_FEAT_POWER:
214 dev_dbg(dev, "%sPortFeature(%u): %s\n",
215 temp ? "Set" : "Clear", wIndex, "POWER");
216
217 if (!hub->set_power)
218 return -EPIPE;
219
220 return hub->set_power(wIndex, temp) ? -EPIPE : 0;
221 case USB_PORT_FEAT_C_OVER_CURRENT:
222 dev_dbg(dev, "%sPortFeature(%u): %s\n",
223 temp ? "Set" : "Clear", wIndex,
224 "C_OVER_CURRENT");
225
226 if (temp)
227 ocic_mask |= 1 << wIndex;
228 else
229 ocic_mask &= ~(1 << wIndex);
230 return 0;
231 }
232 }
233
234 return ohci_hub_control(hcd, typeReq, wValue, wIndex, buf, wLength);
235}
236
237static const struct hc_driver ohci_da8xx_hc_driver = {
238 .description = hcd_name,
239 .product_desc = "DA8xx OHCI",
240 .hcd_priv_size = sizeof(struct ohci_hcd),
241
242 /*
243 * generic hardware linkage
244 */
245 .irq = ohci_irq,
246 .flags = HCD_USB11 | HCD_MEMORY,
247
248 /*
249 * basic lifecycle operations
250 */
251 .reset = ohci_da8xx_init,
252 .start = ohci_da8xx_start,
253 .stop = ohci_da8xx_stop,
254 .shutdown = ohci_shutdown,
255
256 /*
257 * managing i/o requests and associated device resources
258 */
259 .urb_enqueue = ohci_urb_enqueue,
260 .urb_dequeue = ohci_urb_dequeue,
261 .endpoint_disable = ohci_endpoint_disable,
262
263 /*
264 * scheduling support
265 */
266 .get_frame_number = ohci_get_frame,
267
268 /*
269 * root hub support
270 */
271 .hub_status_data = ohci_da8xx_hub_status_data,
272 .hub_control = ohci_da8xx_hub_control,
273
274#ifdef CONFIG_PM
275 .bus_suspend = ohci_bus_suspend,
276 .bus_resume = ohci_bus_resume,
277#endif
278 .start_port_reset = ohci_start_port_reset,
279};
280
281/*-------------------------------------------------------------------------*/
282
283
284/**
285 * usb_hcd_da8xx_probe - initialize DA8xx-based HCDs
286 * Context: !in_interrupt()
287 *
288 * Allocates basic resources for this USB host controller, and
289 * then invokes the start() method for the HCD associated with it
290 * through the hotplug entry's driver_data.
291 */
292static int usb_hcd_da8xx_probe(const struct hc_driver *driver,
293 struct platform_device *pdev)
294{
295 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data;
296 struct usb_hcd *hcd;
297 struct resource *mem;
298 int error, irq;
299
300 if (hub == NULL)
301 return -ENODEV;
302
303 usb11_clk = clk_get(&pdev->dev, "usb11");
304 if (IS_ERR(usb11_clk))
305 return PTR_ERR(usb11_clk);
306
307 usb20_clk = clk_get(&pdev->dev, "usb20");
308 if (IS_ERR(usb20_clk)) {
309 error = PTR_ERR(usb20_clk);
310 goto err0;
311 }
312
313 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
314 if (!hcd) {
315 error = -ENOMEM;
316 goto err1;
317 }
318
319 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
320 if (!mem) {
321 error = -ENODEV;
322 goto err2;
323 }
324 hcd->rsrc_start = mem->start;
325 hcd->rsrc_len = mem->end - mem->start + 1;
326
327 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
328 dev_dbg(&pdev->dev, "request_mem_region failed\n");
329 error = -EBUSY;
330 goto err2;
331 }
332
333 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
334 if (!hcd->regs) {
335 dev_err(&pdev->dev, "ioremap failed\n");
336 error = -ENOMEM;
337 goto err3;
338 }
339
340 ohci_hcd_init(hcd_to_ohci(hcd));
341
342 irq = platform_get_irq(pdev, 0);
343 if (irq < 0) {
344 error = -ENODEV;
345 goto err4;
346 }
347 error = usb_add_hcd(hcd, irq, IRQF_DISABLED);
348 if (error)
349 goto err4;
350
351 if (hub->ocic_notify) {
352 error = hub->ocic_notify(ohci_da8xx_ocic_handler);
353 if (!error)
354 return 0;
355 }
356
357 usb_remove_hcd(hcd);
358err4:
359 iounmap(hcd->regs);
360err3:
361 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
362err2:
363 usb_put_hcd(hcd);
364err1:
365 clk_put(usb20_clk);
366err0:
367 clk_put(usb11_clk);
368 return error;
369}
370
371/**
372 * usb_hcd_da8xx_remove - shutdown processing for DA8xx-based HCDs
373 * @dev: USB Host Controller being removed
374 * Context: !in_interrupt()
375 *
376 * Reverses the effect of usb_hcd_da8xx_probe(), first invoking
377 * the HCD's stop() method. It is always called from a thread
378 * context, normally "rmmod", "apmd", or something similar.
379 */
380static inline void
381usb_hcd_da8xx_remove(struct usb_hcd *hcd, struct platform_device *pdev)
382{
383 struct da8xx_ohci_root_hub *hub = pdev->dev.platform_data;
384
385 hub->ocic_notify(NULL);
386 usb_remove_hcd(hcd);
387 iounmap(hcd->regs);
388 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
389 usb_put_hcd(hcd);
390 clk_put(usb20_clk);
391 clk_put(usb11_clk);
392}
393
394static int ohci_hcd_da8xx_drv_probe(struct platform_device *dev)
395{
396 return usb_hcd_da8xx_probe(&ohci_da8xx_hc_driver, dev);
397}
398
399static int ohci_hcd_da8xx_drv_remove(struct platform_device *dev)
400{
401 struct usb_hcd *hcd = platform_get_drvdata(dev);
402
403 usb_hcd_da8xx_remove(hcd, dev);
404 platform_set_drvdata(dev, NULL);
405
406 return 0;
407}
408
409#ifdef CONFIG_PM
410static int ohci_da8xx_suspend(struct platform_device *dev, pm_message_t message)
411{
412 struct usb_hcd *hcd = platform_get_drvdata(dev);
413 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
414
415 if (time_before(jiffies, ohci->next_statechange))
416 msleep(5);
417 ohci->next_statechange = jiffies;
418
419 ohci_da8xx_clock(0);
420 hcd->state = HC_STATE_SUSPENDED;
421 dev->dev.power.power_state = PMSG_SUSPEND;
422 return 0;
423}
424
425static int ohci_da8xx_resume(struct platform_device *dev)
426{
427 struct usb_hcd *hcd = platform_get_drvdata(dev);
428 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
429
430 if (time_before(jiffies, ohci->next_statechange))
431 msleep(5);
432 ohci->next_statechange = jiffies;
433
434 ohci_da8xx_clock(1);
435 dev->dev.power.power_state = PMSG_ON;
436 usb_hcd_resume_root_hub(hcd);
437 return 0;
438}
439#endif
440
441/*
442 * Driver definition to register with platform structure.
443 */
444static struct platform_driver ohci_hcd_da8xx_driver = {
445 .probe = ohci_hcd_da8xx_drv_probe,
446 .remove = ohci_hcd_da8xx_drv_remove,
447 .shutdown = usb_hcd_platform_shutdown,
448#ifdef CONFIG_PM
449 .suspend = ohci_da8xx_suspend,
450 .resume = ohci_da8xx_resume,
451#endif
452 .driver = {
453 .owner = THIS_MODULE,
454 .name = "ohci",
455 },
456};
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 811f5dfdc582..8ad2441b0284 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -53,13 +53,13 @@ urb_print(struct urb * urb, char * str, int small, int status)
53 int i, len; 53 int i, len;
54 54
55 if (usb_pipecontrol (pipe)) { 55 if (usb_pipecontrol (pipe)) {
56 printk (KERN_DEBUG __FILE__ ": setup(8):"); 56 printk (KERN_DEBUG "%s: setup(8):", __FILE__);
57 for (i = 0; i < 8 ; i++) 57 for (i = 0; i < 8 ; i++)
58 printk (" %02x", ((__u8 *) urb->setup_packet) [i]); 58 printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
59 printk ("\n"); 59 printk ("\n");
60 } 60 }
61 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) { 61 if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
62 printk (KERN_DEBUG __FILE__ ": data(%d/%d):", 62 printk (KERN_DEBUG "%s: data(%d/%d):", __FILE__,
63 urb->actual_length, 63 urb->actual_length,
64 urb->transfer_buffer_length); 64 urb->transfer_buffer_length);
65 len = usb_pipeout (pipe)? 65 len = usb_pipeout (pipe)?
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 24eb74781919..afe59be23645 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1051,6 +1051,11 @@ MODULE_LICENSE ("GPL");
1051#define PLATFORM_DRIVER usb_hcd_pnx4008_driver 1051#define PLATFORM_DRIVER usb_hcd_pnx4008_driver
1052#endif 1052#endif
1053 1053
1054#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1055#include "ohci-da8xx.c"
1056#define PLATFORM_DRIVER ohci_hcd_da8xx_driver
1057#endif
1058
1054#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 1059#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1055 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 1060 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1056 defined(CONFIG_CPU_SUBTYPE_SH7763) || \ 1061 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 32bbce9718f0..65cac8cc8921 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -697,7 +697,7 @@ static int ohci_hub_control (
697 u16 wLength 697 u16 wLength
698) { 698) {
699 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 699 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
700 int ports = hcd_to_bus (hcd)->root_hub->maxchild; 700 int ports = ohci->num_ports;
701 u32 temp; 701 u32 temp;
702 int retval = 0; 702 int retval = 0;
703 703
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index de42283149c7..18d39f0463ee 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -28,8 +28,8 @@ extern int usb_disabled(void);
28 28
29static void lh7a404_start_hc(struct platform_device *dev) 29static void lh7a404_start_hc(struct platform_device *dev)
30{ 30{
31 printk(KERN_DEBUG __FILE__ 31 printk(KERN_DEBUG "%s: starting LH7A404 OHCI USB Controller\n",
32 ": starting LH7A404 OHCI USB Controller\n"); 32 __FILE__);
33 33
34 /* 34 /*
35 * Now, carefully enable the USB clock, and take 35 * Now, carefully enable the USB clock, and take
@@ -39,14 +39,13 @@ static void lh7a404_start_hc(struct platform_device *dev)
39 udelay(1000); 39 udelay(1000);
40 USBH_CMDSTATUS = OHCI_HCR; 40 USBH_CMDSTATUS = OHCI_HCR;
41 41
42 printk(KERN_DEBUG __FILE__ 42 printk(KERN_DEBUG "%s: Clock to USB host has been enabled \n", __FILE__);
43 ": Clock to USB host has been enabled \n");
44} 43}
45 44
46static void lh7a404_stop_hc(struct platform_device *dev) 45static void lh7a404_stop_hc(struct platform_device *dev)
47{ 46{
48 printk(KERN_DEBUG __FILE__ 47 printk(KERN_DEBUG "%s: stopping LH7A404 OHCI USB Controller\n",
49 ": stopping LH7A404 OHCI USB Controller\n"); 48 __FILE__);
50 49
51 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */ 50 CSC_PWRCNT &= ~CSC_PWRCNT_USBH_EN; /* Disable clock */
52} 51}
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 83cbecd2a1ed..5645f70b9214 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -24,10 +24,10 @@
24#include <asm/io.h> 24#include <asm/io.h>
25#include <asm/mach-types.h> 25#include <asm/mach-types.h>
26 26
27#include <mach/mux.h> 27#include <plat/mux.h>
28#include <mach/irqs.h> 28#include <mach/irqs.h>
29#include <mach/fpga.h> 29#include <plat/fpga.h>
30#include <mach/usb.h> 30#include <plat/usb.h>
31 31
32 32
33/* OMAP-1510 OHCI has its own MMU for DMA */ 33/* OMAP-1510 OHCI has its own MMU for DMA */
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 100bf3d8437c..cd74bbdd007c 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -98,8 +98,8 @@
98#define ISP1301_I2C_INTERRUPT_RISING 0xE 98#define ISP1301_I2C_INTERRUPT_RISING 0xE
99#define ISP1301_I2C_REG_CLEAR_ADDR 1 99#define ISP1301_I2C_REG_CLEAR_ADDR 1
100 100
101struct i2c_driver isp1301_driver; 101static struct i2c_driver isp1301_driver;
102struct i2c_client *isp1301_i2c_client; 102static struct i2c_client *isp1301_i2c_client;
103 103
104extern int usb_disabled(void); 104extern int usb_disabled(void);
105extern int ocpi_enable(void); 105extern int ocpi_enable(void);
@@ -120,12 +120,12 @@ static int isp1301_remove(struct i2c_client *client)
120 return 0; 120 return 0;
121} 121}
122 122
123const struct i2c_device_id isp1301_id[] = { 123static const struct i2c_device_id isp1301_id[] = {
124 { "isp1301_pnx", 0 }, 124 { "isp1301_pnx", 0 },
125 { } 125 { }
126}; 126};
127 127
128struct i2c_driver isp1301_driver = { 128static struct i2c_driver isp1301_driver = {
129 .driver = { 129 .driver = {
130 .name = "isp1301_pnx", 130 .name = "isp1301_pnx",
131 }, 131 },
@@ -327,7 +327,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
327 } 327 }
328 i2c_adap = i2c_get_adapter(2); 328 i2c_adap = i2c_get_adapter(2);
329 memset(&i2c_info, 0, sizeof(struct i2c_board_info)); 329 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
330 strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE); 330 strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, 331 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
332 normal_i2c); 332 normal_i2c);
333 i2c_put_adapter(i2c_adap); 333 i2c_put_adapter(i2c_adap);
@@ -411,7 +411,7 @@ out3:
411out2: 411out2:
412 clk_put(usb_clk); 412 clk_put(usb_clk);
413out1: 413out1:
414 i2c_unregister_client(isp1301_i2c_client); 414 i2c_unregister_device(isp1301_i2c_client);
415 isp1301_i2c_client = NULL; 415 isp1301_i2c_client = NULL;
416out_i2c_driver: 416out_i2c_driver:
417 i2c_del_driver(&isp1301_driver); 417 i2c_del_driver(&isp1301_driver);
@@ -430,7 +430,7 @@ static int usb_hcd_pnx4008_remove(struct platform_device *pdev)
430 pnx4008_unset_usb_bits(); 430 pnx4008_unset_usb_bits();
431 clk_disable(usb_clk); 431 clk_disable(usb_clk);
432 clk_put(usb_clk); 432 clk_put(usb_clk);
433 i2c_unregister_client(isp1301_i2c_client); 433 i2c_unregister_device(isp1301_i2c_client);
434 isp1301_i2c_client = NULL; 434 isp1301_i2c_client = NULL;
435 i2c_del_driver(&isp1301_driver); 435 i2c_del_driver(&isp1301_driver);
436 436
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index 68a301710297..103263c230cf 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -114,21 +114,21 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
114 hcd->rsrc_len = res.end - res.start + 1; 114 hcd->rsrc_len = res.end - res.start + 1;
115 115
116 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 116 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
117 printk(KERN_ERR __FILE__ ": request_mem_region failed\n"); 117 printk(KERN_ERR "%s: request_mem_region failed\n", __FILE__);
118 rv = -EBUSY; 118 rv = -EBUSY;
119 goto err_rmr; 119 goto err_rmr;
120 } 120 }
121 121
122 irq = irq_of_parse_and_map(dn, 0); 122 irq = irq_of_parse_and_map(dn, 0);
123 if (irq == NO_IRQ) { 123 if (irq == NO_IRQ) {
124 printk(KERN_ERR __FILE__ ": irq_of_parse_and_map failed\n"); 124 printk(KERN_ERR "%s: irq_of_parse_and_map failed\n", __FILE__);
125 rv = -EBUSY; 125 rv = -EBUSY;
126 goto err_irq; 126 goto err_irq;
127 } 127 }
128 128
129 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 129 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
130 if (!hcd->regs) { 130 if (!hcd->regs) {
131 printk(KERN_ERR __FILE__ ": ioremap failed\n"); 131 printk(KERN_ERR "%s: ioremap failed\n", __FILE__);
132 rv = -ENOMEM; 132 rv = -ENOMEM;
133 goto err_ioremap; 133 goto err_ioremap;
134 } 134 }
@@ -169,7 +169,7 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
169 } else 169 } else
170 release_mem_region(res.start, 0x4); 170 release_mem_region(res.start, 0x4);
171 } else 171 } else
172 pr_debug(__FILE__ ": cannot get ehci offset from fdt\n"); 172 pr_debug("%s: cannot get ehci offset from fdt\n", __FILE__);
173 } 173 }
174 174
175 iounmap(hcd->regs); 175 iounmap(hcd->regs);
@@ -212,7 +212,7 @@ static int ohci_hcd_ppc_of_shutdown(struct of_device *op)
212} 212}
213 213
214 214
215static struct of_device_id ohci_hcd_ppc_of_match[] = { 215static const struct of_device_id ohci_hcd_ppc_of_match[] = {
216#ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE 216#ifdef CONFIG_USB_OHCI_HCD_PPC_OF_BE
217 { 217 {
218 .name = "usb", 218 .name = "usb",
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index cd3398b675b2..89e670e38c10 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -41,14 +41,14 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
41 41
42 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 42 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
43 if (!res) { 43 if (!res) {
44 pr_debug(__FILE__ ": no irq\n"); 44 pr_debug("%s: no irq\n", __FILE__);
45 return -ENODEV; 45 return -ENODEV;
46 } 46 }
47 irq = res->start; 47 irq = res->start;
48 48
49 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 49 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
50 if (!res) { 50 if (!res) {
51 pr_debug(__FILE__ ": no reg addr\n"); 51 pr_debug("%s: no reg addr\n", __FILE__);
52 return -ENODEV; 52 return -ENODEV;
53 } 53 }
54 54
@@ -59,14 +59,14 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
59 hcd->rsrc_len = res->end - res->start + 1; 59 hcd->rsrc_len = res->end - res->start + 1;
60 60
61 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 61 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
62 pr_debug(__FILE__ ": request_mem_region failed\n"); 62 pr_debug("%s: request_mem_region failed\n", __FILE__);
63 retval = -EBUSY; 63 retval = -EBUSY;
64 goto err1; 64 goto err1;
65 } 65 }
66 66
67 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 67 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
68 if (!hcd->regs) { 68 if (!hcd->regs) {
69 pr_debug(__FILE__ ": ioremap failed\n"); 69 pr_debug("%s: ioremap failed\n", __FILE__);
70 retval = -ENOMEM; 70 retval = -ENOMEM;
71 goto err2; 71 goto err2;
72 } 72 }
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index f1c06202fdf2..a18debdd79b8 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -518,7 +518,7 @@ static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
518 return 0; 518 return 0;
519} 519}
520 520
521static struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = { 521static const struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = {
522 .suspend = ohci_hcd_pxa27x_drv_suspend, 522 .suspend = ohci_hcd_pxa27x_drv_suspend,
523 .resume = ohci_hcd_pxa27x_drv_resume, 523 .resume = ohci_hcd_pxa27x_drv_resume,
524}; 524};
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 35288bcae0db..83094d067e0f 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/irq.h> 10#include <linux/irq.h>
11#include <linux/slab.h>
11 12
12static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv) 13static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
13{ 14{
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index e4bbe8e188e4..d8eb3bdafabb 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -31,8 +31,8 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
31{ 31{
32 unsigned int usb_rst = 0; 32 unsigned int usb_rst = 0;
33 33
34 printk(KERN_DEBUG __FILE__ 34 printk(KERN_DEBUG "%s: starting SA-1111 OHCI USB Controller\n",
35 ": starting SA-1111 OHCI USB Controller\n"); 35 __FILE__);
36 36
37#ifdef CONFIG_SA1100_BADGE4 37#ifdef CONFIG_SA1100_BADGE4
38 if (machine_is_badge4()) { 38 if (machine_is_badge4()) {
@@ -65,8 +65,8 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
65static void sa1111_stop_hc(struct sa1111_dev *dev) 65static void sa1111_stop_hc(struct sa1111_dev *dev)
66{ 66{
67 unsigned int usb_rst; 67 unsigned int usb_rst;
68 printk(KERN_DEBUG __FILE__ 68 printk(KERN_DEBUG "%s: stopping SA-1111 OHCI USB Controller\n",
69 ": stopping SA-1111 OHCI USB Controller\n"); 69 __FILE__);
70 70
71 /* 71 /*
72 * Put the USB host controller into reset. 72 * Put the USB host controller into reset.
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index 50f57f468836..e62b30b3e429 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -660,13 +660,13 @@ static struct ehci_qh *oxu_qh_alloc(struct oxu_hcd *oxu)
660 if (qh->dummy == NULL) { 660 if (qh->dummy == NULL) {
661 oxu_dbg(oxu, "no dummy td\n"); 661 oxu_dbg(oxu, "no dummy td\n");
662 oxu->qh_used[i] = 0; 662 oxu->qh_used[i] = 0;
663 663 qh = NULL;
664 return NULL; 664 goto unlock;
665 } 665 }
666 666
667 oxu->qh_used[i] = 1; 667 oxu->qh_used[i] = 1;
668 } 668 }
669 669unlock:
670 spin_unlock(&oxu->mem_lock); 670 spin_unlock(&oxu->mem_lock);
671 671
672 return qh; 672 return qh;
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index e33d36256350..d478ffad59b4 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -35,7 +35,10 @@
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/mm.h>
38#include <linux/irq.h> 39#include <linux/irq.h>
40#include <linux/slab.h>
41#include <asm/cacheflush.h>
39 42
40#include "../core/hcd.h" 43#include "../core/hcd.h"
41#include "r8a66597.h" 44#include "r8a66597.h"
@@ -216,8 +219,17 @@ static void disable_controller(struct r8a66597 *r8a66597)
216{ 219{
217 int port; 220 int port;
218 221
222 /* disable interrupts */
219 r8a66597_write(r8a66597, 0, INTENB0); 223 r8a66597_write(r8a66597, 0, INTENB0);
220 r8a66597_write(r8a66597, 0, INTSTS0); 224 r8a66597_write(r8a66597, 0, INTENB1);
225 r8a66597_write(r8a66597, 0, BRDYENB);
226 r8a66597_write(r8a66597, 0, BEMPENB);
227 r8a66597_write(r8a66597, 0, NRDYENB);
228
229 /* clear status */
230 r8a66597_write(r8a66597, 0, BRDYSTS);
231 r8a66597_write(r8a66597, 0, NRDYSTS);
232 r8a66597_write(r8a66597, 0, BEMPSTS);
221 233
222 for (port = 0; port < r8a66597->max_root_hub; port++) 234 for (port = 0; port < r8a66597->max_root_hub; port++)
223 r8a66597_disable_port(r8a66597, port); 235 r8a66597_disable_port(r8a66597, port);
@@ -407,7 +419,7 @@ static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
407 419
408/* this function must be called with interrupt disabled */ 420/* this function must be called with interrupt disabled */
409static void free_usb_address(struct r8a66597 *r8a66597, 421static void free_usb_address(struct r8a66597 *r8a66597,
410 struct r8a66597_device *dev) 422 struct r8a66597_device *dev, int reset)
411{ 423{
412 int port; 424 int port;
413 425
@@ -419,7 +431,13 @@ static void free_usb_address(struct r8a66597 *r8a66597,
419 dev->state = USB_STATE_DEFAULT; 431 dev->state = USB_STATE_DEFAULT;
420 r8a66597->address_map &= ~(1 << dev->address); 432 r8a66597->address_map &= ~(1 << dev->address);
421 dev->address = 0; 433 dev->address = 0;
422 dev_set_drvdata(&dev->udev->dev, NULL); 434 /*
435 * Only when resetting USB, it is necessary to erase drvdata. When
436 * a usb device with usb hub is disconnect, "dev->udev" is already
437 * freed on usb_desconnect(). So we cannot access the data.
438 */
439 if (reset)
440 dev_set_drvdata(&dev->udev->dev, NULL);
423 list_del(&dev->device_list); 441 list_del(&dev->device_list);
424 kfree(dev); 442 kfree(dev);
425 443
@@ -811,6 +829,26 @@ static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
811 enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb); 829 enable_r8a66597_pipe_dma(r8a66597, dev, pipe, urb);
812} 830}
813 831
832static void r8a66597_urb_done(struct r8a66597 *r8a66597, struct urb *urb,
833 int status)
834__releases(r8a66597->lock)
835__acquires(r8a66597->lock)
836{
837 if (usb_pipein(urb->pipe) && usb_pipetype(urb->pipe) != PIPE_CONTROL) {
838 void *ptr;
839
840 for (ptr = urb->transfer_buffer;
841 ptr < urb->transfer_buffer + urb->transfer_buffer_length;
842 ptr += PAGE_SIZE)
843 flush_dcache_page(virt_to_page(ptr));
844 }
845
846 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
847 spin_unlock(&r8a66597->lock);
848 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb, status);
849 spin_lock(&r8a66597->lock);
850}
851
814/* this function must be called with interrupt disabled */ 852/* this function must be called with interrupt disabled */
815static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address) 853static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
816{ 854{
@@ -822,8 +860,6 @@ static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
822 return; 860 return;
823 861
824 list_for_each_entry_safe(td, next, list, queue) { 862 list_for_each_entry_safe(td, next, list, queue) {
825 if (!td)
826 continue;
827 if (td->address != address) 863 if (td->address != address)
828 continue; 864 continue;
829 865
@@ -831,15 +867,9 @@ static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
831 list_del(&td->queue); 867 list_del(&td->queue);
832 kfree(td); 868 kfree(td);
833 869
834 if (urb) { 870 if (urb)
835 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), 871 r8a66597_urb_done(r8a66597, urb, -ENODEV);
836 urb);
837 872
838 spin_unlock(&r8a66597->lock);
839 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb,
840 -ENODEV);
841 spin_lock(&r8a66597->lock);
842 }
843 break; 873 break;
844 } 874 }
845} 875}
@@ -999,6 +1029,8 @@ static void start_root_hub_sampling(struct r8a66597 *r8a66597, int port,
999/* this function must be called with interrupt disabled */ 1029/* this function must be called with interrupt disabled */
1000static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port, 1030static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
1001 u16 syssts) 1031 u16 syssts)
1032__releases(r8a66597->lock)
1033__acquires(r8a66597->lock)
1002{ 1034{
1003 if (syssts == SE0) { 1035 if (syssts == SE0) {
1004 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port)); 1036 r8a66597_write(r8a66597, ~ATTCH, get_intsts_reg(port));
@@ -1016,7 +1048,9 @@ static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
1016 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597)); 1048 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
1017 } 1049 }
1018 1050
1051 spin_unlock(&r8a66597->lock);
1019 usb_hcd_poll_rh_status(r8a66597_to_hcd(r8a66597)); 1052 usb_hcd_poll_rh_status(r8a66597_to_hcd(r8a66597));
1053 spin_lock(&r8a66597->lock);
1020} 1054}
1021 1055
1022/* this function must be called with interrupt disabled */ 1056/* this function must be called with interrupt disabled */
@@ -1042,7 +1076,7 @@ static void r8a66597_usb_disconnect(struct r8a66597 *r8a66597, int port)
1042 struct r8a66597_device *dev = r8a66597->root_hub[port].dev; 1076 struct r8a66597_device *dev = r8a66597->root_hub[port].dev;
1043 1077
1044 disable_r8a66597_pipe_all(r8a66597, dev); 1078 disable_r8a66597_pipe_all(r8a66597, dev);
1045 free_usb_address(r8a66597, dev); 1079 free_usb_address(r8a66597, dev, 0);
1046 1080
1047 start_root_hub_sampling(r8a66597, port, 0); 1081 start_root_hub_sampling(r8a66597, port, 0);
1048} 1082}
@@ -1276,10 +1310,7 @@ __releases(r8a66597->lock) __acquires(r8a66597->lock)
1276 if (usb_pipeisoc(urb->pipe)) 1310 if (usb_pipeisoc(urb->pipe))
1277 urb->start_frame = r8a66597_get_frame(hcd); 1311 urb->start_frame = r8a66597_get_frame(hcd);
1278 1312
1279 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb); 1313 r8a66597_urb_done(r8a66597, urb, status);
1280 spin_unlock(&r8a66597->lock);
1281 usb_hcd_giveback_urb(hcd, urb, status);
1282 spin_lock(&r8a66597->lock);
1283 } 1314 }
1284 1315
1285 if (restart) { 1316 if (restart) {
@@ -2025,8 +2056,6 @@ static struct r8a66597_device *get_r8a66597_device(struct r8a66597 *r8a66597,
2025 struct list_head *list = &r8a66597->child_device; 2056 struct list_head *list = &r8a66597->child_device;
2026 2057
2027 list_for_each_entry(dev, list, device_list) { 2058 list_for_each_entry(dev, list, device_list) {
2028 if (!dev)
2029 continue;
2030 if (dev->usb_address != addr) 2059 if (dev->usb_address != addr)
2031 continue; 2060 continue;
2032 2061
@@ -2063,7 +2092,7 @@ static void update_usb_address_map(struct r8a66597 *r8a66597,
2063 spin_lock_irqsave(&r8a66597->lock, flags); 2092 spin_lock_irqsave(&r8a66597->lock, flags);
2064 dev = get_r8a66597_device(r8a66597, addr); 2093 dev = get_r8a66597_device(r8a66597, addr);
2065 disable_r8a66597_pipe_all(r8a66597, dev); 2094 disable_r8a66597_pipe_all(r8a66597, dev);
2066 free_usb_address(r8a66597, dev); 2095 free_usb_address(r8a66597, dev, 0);
2067 put_child_connect_map(r8a66597, addr); 2096 put_child_connect_map(r8a66597, addr);
2068 spin_unlock_irqrestore(&r8a66597->lock, flags); 2097 spin_unlock_irqrestore(&r8a66597->lock, flags);
2069 } 2098 }
@@ -2206,7 +2235,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2206 rh->port |= (1 << USB_PORT_FEAT_RESET); 2235 rh->port |= (1 << USB_PORT_FEAT_RESET);
2207 2236
2208 disable_r8a66597_pipe_all(r8a66597, dev); 2237 disable_r8a66597_pipe_all(r8a66597, dev);
2209 free_usb_address(r8a66597, dev); 2238 free_usb_address(r8a66597, dev, 1);
2210 2239
2211 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT, 2240 r8a66597_mdfy(r8a66597, USBRST, USBRST | UACT,
2212 get_dvstctr_reg(port)); 2241 get_dvstctr_reg(port));
@@ -2357,7 +2386,7 @@ static int r8a66597_resume(struct device *dev)
2357 return 0; 2386 return 0;
2358} 2387}
2359 2388
2360static struct dev_pm_ops r8a66597_dev_pm_ops = { 2389static const struct dev_pm_ops r8a66597_dev_pm_ops = {
2361 .suspend = r8a66597_suspend, 2390 .suspend = r8a66597_suspend,
2362 .resume = r8a66597_resume, 2391 .resume = r8a66597_resume,
2363 .poweroff = r8a66597_suspend, 2392 .poweroff = r8a66597_suspend,
@@ -2470,6 +2499,12 @@ static int __devinit r8a66597_probe(struct platform_device *pdev)
2470 r8a66597->rh_timer.data = (unsigned long)r8a66597; 2499 r8a66597->rh_timer.data = (unsigned long)r8a66597;
2471 r8a66597->reg = (unsigned long)reg; 2500 r8a66597->reg = (unsigned long)reg;
2472 2501
2502 /* make sure no interrupts are pending */
2503 ret = r8a66597_clock_enable(r8a66597);
2504 if (ret < 0)
2505 goto clean_up3;
2506 disable_controller(r8a66597);
2507
2473 for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) { 2508 for (i = 0; i < R8A66597_MAX_NUM_PIPE; i++) {
2474 INIT_LIST_HEAD(&r8a66597->pipe_queue[i]); 2509 INIT_LIST_HEAD(&r8a66597->pipe_queue[i]);
2475 init_timer(&r8a66597->td_timer[i]); 2510 init_timer(&r8a66597->td_timer[i]);
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 5b22a4d1c9e4..3b867a8af7b2 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -51,6 +51,7 @@
51#include <asm/irq.h> 51#include <asm/irq.h>
52#include <asm/system.h> 52#include <asm/system.h>
53#include <asm/byteorder.h> 53#include <asm/byteorder.h>
54#include <asm/unaligned.h>
54 55
55#include "../core/hcd.h" 56#include "../core/hcd.h"
56#include "sl811.h" 57#include "sl811.h"
@@ -719,10 +720,10 @@ retry:
719 /* port status seems weird until after reset, so 720 /* port status seems weird until after reset, so
720 * force the reset and make khubd clean up later. 721 * force the reset and make khubd clean up later.
721 */ 722 */
722 if (sl811->stat_insrmv & 1) 723 if (irqstat & SL11H_INTMASK_RD)
723 sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION;
724 else
725 sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION); 724 sl811->port1 &= ~(1 << USB_PORT_FEAT_CONNECTION);
725 else
726 sl811->port1 |= 1 << USB_PORT_FEAT_CONNECTION;
726 727
727 sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION; 728 sl811->port1 |= 1 << USB_PORT_FEAT_C_CONNECTION;
728 729
@@ -1272,12 +1273,12 @@ sl811h_hub_control(
1272 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf); 1273 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
1273 break; 1274 break;
1274 case GetHubStatus: 1275 case GetHubStatus:
1275 *(__le32 *) buf = cpu_to_le32(0); 1276 put_unaligned_le32(0, buf);
1276 break; 1277 break;
1277 case GetPortStatus: 1278 case GetPortStatus:
1278 if (wIndex != 1) 1279 if (wIndex != 1)
1279 goto error; 1280 goto error;
1280 *(__le32 *) buf = cpu_to_le32(sl811->port1); 1281 put_unaligned_le32(sl811->port1, buf);
1281 1282
1282#ifndef VERBOSE 1283#ifndef VERBOSE
1283 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */ 1284 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 516848dd9b48..39d253e841f6 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -37,28 +37,8 @@ MODULE_LICENSE("GPL");
37/* MACROS */ 37/* MACROS */
38/*====================================================================*/ 38/*====================================================================*/
39 39
40#if defined(DEBUG) || defined(PCMCIA_DEBUG)
41
42static int pc_debug = 0;
43module_param(pc_debug, int, 0644);
44
45#define DBG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG "sl811_cs: " args)
46
47#else
48#define DBG(n, args...) do{}while(0)
49#endif /* no debugging */
50
51#define INFO(args...) printk(KERN_INFO "sl811_cs: " args) 40#define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
52 41
53#define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0444)
54
55#define CS_CHECK(fn, ret) \
56 do { \
57 last_fn = (fn); \
58 if ((last_ret = (ret)) != 0) \
59 goto cs_failed; \
60 } while (0)
61
62/*====================================================================*/ 42/*====================================================================*/
63/* VARIABLES */ 43/* VARIABLES */
64/*====================================================================*/ 44/*====================================================================*/
@@ -76,7 +56,7 @@ static void sl811_cs_release(struct pcmcia_device * link);
76 56
77static void release_platform_dev(struct device * dev) 57static void release_platform_dev(struct device * dev)
78{ 58{
79 DBG(0, "sl811_cs platform_dev release\n"); 59 dev_dbg(dev, "sl811_cs platform_dev release\n");
80 dev->parent = NULL; 60 dev->parent = NULL;
81} 61}
82 62
@@ -140,7 +120,7 @@ static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
140 120
141static void sl811_cs_detach(struct pcmcia_device *link) 121static void sl811_cs_detach(struct pcmcia_device *link)
142{ 122{
143 DBG(0, "sl811_cs_detach(0x%p)\n", link); 123 dev_dbg(&link->dev, "sl811_cs_detach\n");
144 124
145 sl811_cs_release(link); 125 sl811_cs_release(link);
146 126
@@ -150,7 +130,7 @@ static void sl811_cs_detach(struct pcmcia_device *link)
150 130
151static void sl811_cs_release(struct pcmcia_device * link) 131static void sl811_cs_release(struct pcmcia_device * link)
152{ 132{
153 DBG(0, "sl811_cs_release(0x%p)\n", link); 133 dev_dbg(&link->dev, "sl811_cs_release\n");
154 134
155 pcmcia_disable_device(link); 135 pcmcia_disable_device(link);
156 platform_device_unregister(&platform_dev); 136 platform_device_unregister(&platform_dev);
@@ -205,11 +185,11 @@ static int sl811_cs_config_check(struct pcmcia_device *p_dev,
205 185
206static int sl811_cs_config(struct pcmcia_device *link) 186static int sl811_cs_config(struct pcmcia_device *link)
207{ 187{
208 struct device *parent = &handle_to_dev(link); 188 struct device *parent = &link->dev;
209 local_info_t *dev = link->priv; 189 local_info_t *dev = link->priv;
210 int last_fn, last_ret; 190 int ret;
211 191
212 DBG(0, "sl811_cs_config(0x%p)\n", link); 192 dev_dbg(&link->dev, "sl811_cs_config\n");
213 193
214 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) 194 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
215 goto failed; 195 goto failed;
@@ -217,14 +197,16 @@ static int sl811_cs_config(struct pcmcia_device *link)
217 /* require an IRQ and two registers */ 197 /* require an IRQ and two registers */
218 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2) 198 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
219 goto failed; 199 goto failed;
220 if (link->conf.Attributes & CONF_ENABLE_IRQ) 200 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
221 CS_CHECK(RequestIRQ, 201 ret = pcmcia_request_irq(link, &link->irq);
222 pcmcia_request_irq(link, &link->irq)); 202 if (ret)
223 else 203 goto failed;
204 } else
224 goto failed; 205 goto failed;
225 206
226 CS_CHECK(RequestConfiguration, 207 ret = pcmcia_request_configuration(link, &link->conf);
227 pcmcia_request_configuration(link, &link->conf)); 208 if (ret)
209 goto failed;
228 210
229 sprintf(dev->node.dev_name, driver_name); 211 sprintf(dev->node.dev_name, driver_name);
230 dev->node.major = dev->node.minor = 0; 212 dev->node.major = dev->node.minor = 0;
@@ -241,8 +223,6 @@ static int sl811_cs_config(struct pcmcia_device *link)
241 223
242 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ) 224 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
243 < 0) { 225 < 0) {
244cs_failed:
245 cs_error(link, last_fn, last_ret);
246failed: 226failed:
247 printk(KERN_WARNING "sl811_cs_config failed\n"); 227 printk(KERN_WARNING "sl811_cs_config failed\n");
248 sl811_cs_release(link); 228 sl811_cs_release(link);
@@ -263,7 +243,6 @@ static int sl811_cs_probe(struct pcmcia_device *link)
263 243
264 /* Initialize */ 244 /* Initialize */
265 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; 245 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
266 link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
267 link->irq.Handler = NULL; 246 link->irq.Handler = NULL;
268 247
269 link->conf.Attributes = 0; 248 link->conf.Attributes = 0;
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index e52b954dda47..98cf0b26b968 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -9,6 +9,7 @@
9 * (C) Copyright 1999-2001 Johannes Erdfelt 9 * (C) Copyright 1999-2001 Johannes Erdfelt
10 */ 10 */
11 11
12#include <linux/slab.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/debugfs.h> 14#include <linux/debugfs.h>
14#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index 5cd0e48f67fb..09197067fe6b 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -735,6 +735,7 @@ static void uhci_stop(struct usb_hcd *hcd)
735 uhci_hc_died(uhci); 735 uhci_hc_died(uhci);
736 uhci_scan_schedule(uhci); 736 uhci_scan_schedule(uhci);
737 spin_unlock_irq(&uhci->lock); 737 spin_unlock_irq(&uhci->lock);
738 synchronize_irq(hcd->irq);
738 739
739 del_timer_sync(&uhci->fsbr_timer); 740 del_timer_sync(&uhci->fsbr_timer);
740 release_uhci(uhci); 741 release_uhci(uhci);
@@ -749,7 +750,20 @@ static int uhci_rh_suspend(struct usb_hcd *hcd)
749 spin_lock_irq(&uhci->lock); 750 spin_lock_irq(&uhci->lock);
750 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) 751 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
751 rc = -ESHUTDOWN; 752 rc = -ESHUTDOWN;
752 else if (!uhci->dead) 753 else if (uhci->dead)
754 ; /* Dead controllers tell no tales */
755
756 /* Once the controller is stopped, port resumes that are already
757 * in progress won't complete. Hence if remote wakeup is enabled
758 * for the root hub and any ports are in the middle of a resume or
759 * remote wakeup, we must fail the suspend.
760 */
761 else if (hcd->self.root_hub->do_remote_wakeup &&
762 uhci->resuming_ports) {
763 dev_dbg(uhci_dev(uhci), "suspend failed because a port "
764 "is resuming\n");
765 rc = -EBUSY;
766 } else
753 suspend_rh(uhci, UHCI_RH_SUSPENDED); 767 suspend_rh(uhci, UHCI_RH_SUSPENDED);
754 spin_unlock_irq(&uhci->lock); 768 spin_unlock_irq(&uhci->lock);
755 return rc; 769 return rc;
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index 885b585360b9..8270055848ca 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -167,7 +167,7 @@ static void uhci_check_ports(struct uhci_hcd *uhci)
167 /* Port received a wakeup request */ 167 /* Port received a wakeup request */
168 set_bit(port, &uhci->resuming_ports); 168 set_bit(port, &uhci->resuming_ports);
169 uhci->ports_timeout = jiffies + 169 uhci->ports_timeout = jiffies +
170 msecs_to_jiffies(20); 170 msecs_to_jiffies(25);
171 171
172 /* Make sure we see the port again 172 /* Make sure we see the port again
173 * after the resuming period is over. */ 173 * after the resuming period is over. */
diff --git a/drivers/usb/host/whci/asl.c b/drivers/usb/host/whci/asl.c
index 562eba108816..773249306031 100644
--- a/drivers/usb/host/whci/asl.c
+++ b/drivers/usb/host/whci/asl.c
@@ -16,6 +16,7 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/gfp.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/uwb/umc.h> 21#include <linux/uwb/umc.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c
index 2273c815941f..c5305b599ca0 100644
--- a/drivers/usb/host/whci/debug.c
+++ b/drivers/usb/host/whci/debug.c
@@ -15,6 +15,7 @@
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/slab.h>
18#include <linux/kernel.h> 19#include <linux/kernel.h>
19#include <linux/debugfs.h> 20#include <linux/debugfs.h>
20#include <linux/seq_file.h> 21#include <linux/seq_file.h>
@@ -31,17 +32,29 @@ struct whc_dbg {
31 32
32void qset_print(struct seq_file *s, struct whc_qset *qset) 33void qset_print(struct seq_file *s, struct whc_qset *qset)
33{ 34{
35 static const char *qh_type[] = {
36 "ctrl", "isoc", "bulk", "intr", "rsvd", "rsvd", "rsvd", "lpintr", };
34 struct whc_std *std; 37 struct whc_std *std;
35 struct urb *urb = NULL; 38 struct urb *urb = NULL;
36 int i; 39 int i;
37 40
38 seq_printf(s, "qset %08x\n", (u32)qset->qset_dma); 41 seq_printf(s, "qset %08x", (u32)qset->qset_dma);
42 if (&qset->list_node == qset->whc->async_list.prev) {
43 seq_printf(s, " (dummy)\n");
44 } else {
45 seq_printf(s, " ep%d%s-%s maxpkt: %d\n",
46 qset->qh.info1 & 0x0f,
47 (qset->qh.info1 >> 4) & 0x1 ? "in" : "out",
48 qh_type[(qset->qh.info1 >> 5) & 0x7],
49 (qset->qh.info1 >> 16) & 0xffff);
50 }
39 seq_printf(s, " -> %08x\n", (u32)qset->qh.link); 51 seq_printf(s, " -> %08x\n", (u32)qset->qh.link);
40 seq_printf(s, " info: %08x %08x %08x\n", 52 seq_printf(s, " info: %08x %08x %08x\n",
41 qset->qh.info1, qset->qh.info2, qset->qh.info3); 53 qset->qh.info1, qset->qh.info2, qset->qh.info3);
42 seq_printf(s, " sts: %04x errs: %d\n", qset->qh.status, qset->qh.err_count); 54 seq_printf(s, " sts: %04x errs: %d curwin: %08x\n",
55 qset->qh.status, qset->qh.err_count, qset->qh.cur_window);
43 seq_printf(s, " TD: sts: %08x opts: %08x\n", 56 seq_printf(s, " TD: sts: %08x opts: %08x\n",
44 qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options); 57 qset->qh.overlay.qtd.status, qset->qh.overlay.qtd.options);
45 58
46 for (i = 0; i < WHCI_QSET_TD_MAX; i++) { 59 for (i = 0; i < WHCI_QSET_TD_MAX; i++) {
47 seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n", 60 seq_printf(s, " %c%c TD[%d]: sts: %08x opts: %08x ptr: %08x\n",
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index 687b622a1612..e0d3401285c8 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -250,6 +250,7 @@ static int whc_probe(struct umc_dev *umc)
250 } 250 }
251 251
252 usb_hcd->wireless = 1; 252 usb_hcd->wireless = 1;
253 usb_hcd->self.sg_tablesize = 2048; /* somewhat arbitrary */
253 254
254 wusbhc = usb_hcd_to_wusbhc(usb_hcd); 255 wusbhc = usb_hcd_to_wusbhc(usb_hcd);
255 whc = wusbhc_to_whc(wusbhc); 256 whc = wusbhc_to_whc(wusbhc);
diff --git a/drivers/usb/host/whci/init.c b/drivers/usb/host/whci/init.c
index 34a783cb0133..f7582e8e2169 100644
--- a/drivers/usb/host/whci/init.c
+++ b/drivers/usb/host/whci/init.c
@@ -16,6 +16,7 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/gfp.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/uwb/umc.h> 21#include <linux/uwb/umc.h>
21 22
diff --git a/drivers/usb/host/whci/pzl.c b/drivers/usb/host/whci/pzl.c
index 0db3fb2dc03a..33c5580b4d25 100644
--- a/drivers/usb/host/whci/pzl.c
+++ b/drivers/usb/host/whci/pzl.c
@@ -16,6 +16,7 @@
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/gfp.h>
19#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
20#include <linux/uwb/umc.h> 21#include <linux/uwb/umc.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
diff --git a/drivers/usb/host/whci/qset.c b/drivers/usb/host/whci/qset.c
index 1b9dc1571570..141d049beb3e 100644
--- a/drivers/usb/host/whci/qset.c
+++ b/drivers/usb/host/whci/qset.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/dma-mapping.h> 19#include <linux/dma-mapping.h>
20#include <linux/slab.h>
20#include <linux/uwb/umc.h> 21#include <linux/uwb/umc.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22 23
@@ -49,16 +50,19 @@ struct whc_qset *qset_alloc(struct whc *whc, gfp_t mem_flags)
49 * state 50 * state
50 * @urb: an urb for a transfer to this endpoint 51 * @urb: an urb for a transfer to this endpoint
51 */ 52 */
52static void qset_fill_qh(struct whc_qset *qset, struct urb *urb) 53static void qset_fill_qh(struct whc *whc, struct whc_qset *qset, struct urb *urb)
53{ 54{
54 struct usb_device *usb_dev = urb->dev; 55 struct usb_device *usb_dev = urb->dev;
56 struct wusb_dev *wusb_dev = usb_dev->wusb_dev;
55 struct usb_wireless_ep_comp_descriptor *epcd; 57 struct usb_wireless_ep_comp_descriptor *epcd;
56 bool is_out; 58 bool is_out;
59 uint8_t phy_rate;
57 60
58 is_out = usb_pipeout(urb->pipe); 61 is_out = usb_pipeout(urb->pipe);
59 62
60 epcd = (struct usb_wireless_ep_comp_descriptor *)qset->ep->extra; 63 qset->max_packet = le16_to_cpu(urb->ep->desc.wMaxPacketSize);
61 64
65 epcd = (struct usb_wireless_ep_comp_descriptor *)qset->ep->extra;
62 if (epcd) { 66 if (epcd) {
63 qset->max_seq = epcd->bMaxSequence; 67 qset->max_seq = epcd->bMaxSequence;
64 qset->max_burst = epcd->bMaxBurst; 68 qset->max_burst = epcd->bMaxBurst;
@@ -67,12 +71,28 @@ static void qset_fill_qh(struct whc_qset *qset, struct urb *urb)
67 qset->max_burst = 1; 71 qset->max_burst = 1;
68 } 72 }
69 73
74 /*
75 * Initial PHY rate is 53.3 Mbit/s for control endpoints or
76 * the maximum supported by the device for other endpoints
77 * (unless limited by the user).
78 */
79 if (usb_pipecontrol(urb->pipe))
80 phy_rate = UWB_PHY_RATE_53;
81 else {
82 uint16_t phy_rates;
83
84 phy_rates = le16_to_cpu(wusb_dev->wusb_cap_descr->wPHYRates);
85 phy_rate = fls(phy_rates) - 1;
86 if (phy_rate > whc->wusbhc.phy_rate)
87 phy_rate = whc->wusbhc.phy_rate;
88 }
89
70 qset->qh.info1 = cpu_to_le32( 90 qset->qh.info1 = cpu_to_le32(
71 QH_INFO1_EP(usb_pipeendpoint(urb->pipe)) 91 QH_INFO1_EP(usb_pipeendpoint(urb->pipe))
72 | (is_out ? QH_INFO1_DIR_OUT : QH_INFO1_DIR_IN) 92 | (is_out ? QH_INFO1_DIR_OUT : QH_INFO1_DIR_IN)
73 | usb_pipe_to_qh_type(urb->pipe) 93 | usb_pipe_to_qh_type(urb->pipe)
74 | QH_INFO1_DEV_INFO_IDX(wusb_port_no_to_idx(usb_dev->portnum)) 94 | QH_INFO1_DEV_INFO_IDX(wusb_port_no_to_idx(usb_dev->portnum))
75 | QH_INFO1_MAX_PKT_LEN(usb_maxpacket(urb->dev, urb->pipe, is_out)) 95 | QH_INFO1_MAX_PKT_LEN(qset->max_packet)
76 ); 96 );
77 qset->qh.info2 = cpu_to_le32( 97 qset->qh.info2 = cpu_to_le32(
78 QH_INFO2_BURST(qset->max_burst) 98 QH_INFO2_BURST(qset->max_burst)
@@ -86,7 +106,7 @@ static void qset_fill_qh(struct whc_qset *qset, struct urb *urb)
86 * strength and can presumably guess the Tx power required 106 * strength and can presumably guess the Tx power required
87 * from that? */ 107 * from that? */
88 qset->qh.info3 = cpu_to_le32( 108 qset->qh.info3 = cpu_to_le32(
89 QH_INFO3_TX_RATE_53_3 109 QH_INFO3_TX_RATE(phy_rate)
90 | QH_INFO3_TX_PWR(0) /* 0 == max power */ 110 | QH_INFO3_TX_PWR(0) /* 0 == max power */
91 ); 111 );
92 112
@@ -148,7 +168,7 @@ struct whc_qset *get_qset(struct whc *whc, struct urb *urb,
148 168
149 qset->ep = urb->ep; 169 qset->ep = urb->ep;
150 urb->ep->hcpriv = qset; 170 urb->ep->hcpriv = qset;
151 qset_fill_qh(qset, urb); 171 qset_fill_qh(whc, qset, urb);
152 } 172 }
153 return qset; 173 return qset;
154} 174}
@@ -241,6 +261,36 @@ static void qset_remove_qtd(struct whc *whc, struct whc_qset *qset)
241 qset->ntds--; 261 qset->ntds--;
242} 262}
243 263
264static void qset_copy_bounce_to_sg(struct whc *whc, struct whc_std *std)
265{
266 struct scatterlist *sg;
267 void *bounce;
268 size_t remaining, offset;
269
270 bounce = std->bounce_buf;
271 remaining = std->len;
272
273 sg = std->bounce_sg;
274 offset = std->bounce_offset;
275
276 while (remaining) {
277 size_t len;
278
279 len = min(sg->length - offset, remaining);
280 memcpy(sg_virt(sg) + offset, bounce, len);
281
282 bounce += len;
283 remaining -= len;
284
285 offset += len;
286 if (offset >= sg->length) {
287 sg = sg_next(sg);
288 offset = 0;
289 }
290 }
291
292}
293
244/** 294/**
245 * qset_free_std - remove an sTD and free it. 295 * qset_free_std - remove an sTD and free it.
246 * @whc: the WHCI host controller 296 * @whc: the WHCI host controller
@@ -249,13 +299,29 @@ static void qset_remove_qtd(struct whc *whc, struct whc_qset *qset)
249void qset_free_std(struct whc *whc, struct whc_std *std) 299void qset_free_std(struct whc *whc, struct whc_std *std)
250{ 300{
251 list_del(&std->list_node); 301 list_del(&std->list_node);
252 if (std->num_pointers) { 302 if (std->bounce_buf) {
253 dma_unmap_single(whc->wusbhc.dev, std->dma_addr, 303 bool is_out = usb_pipeout(std->urb->pipe);
254 std->num_pointers * sizeof(struct whc_page_list_entry), 304 dma_addr_t dma_addr;
255 DMA_TO_DEVICE); 305
306 if (std->num_pointers)
307 dma_addr = le64_to_cpu(std->pl_virt[0].buf_ptr);
308 else
309 dma_addr = std->dma_addr;
310
311 dma_unmap_single(whc->wusbhc.dev, dma_addr,
312 std->len, is_out ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
313 if (!is_out)
314 qset_copy_bounce_to_sg(whc, std);
315 kfree(std->bounce_buf);
316 }
317 if (std->pl_virt) {
318 if (std->dma_addr)
319 dma_unmap_single(whc->wusbhc.dev, std->dma_addr,
320 std->num_pointers * sizeof(struct whc_page_list_entry),
321 DMA_TO_DEVICE);
256 kfree(std->pl_virt); 322 kfree(std->pl_virt);
323 std->pl_virt = NULL;
257 } 324 }
258
259 kfree(std); 325 kfree(std);
260} 326}
261 327
@@ -293,12 +359,17 @@ static int qset_fill_page_list(struct whc *whc, struct whc_std *std, gfp_t mem_f
293{ 359{
294 dma_addr_t dma_addr = std->dma_addr; 360 dma_addr_t dma_addr = std->dma_addr;
295 dma_addr_t sp, ep; 361 dma_addr_t sp, ep;
296 size_t std_len = std->len;
297 size_t pl_len; 362 size_t pl_len;
298 int p; 363 int p;
299 364
300 sp = ALIGN(dma_addr, WHCI_PAGE_SIZE); 365 /* Short buffers don't need a page list. */
301 ep = dma_addr + std_len; 366 if (std->len <= WHCI_PAGE_SIZE) {
367 std->num_pointers = 0;
368 return 0;
369 }
370
371 sp = dma_addr & ~(WHCI_PAGE_SIZE-1);
372 ep = dma_addr + std->len;
302 std->num_pointers = DIV_ROUND_UP(ep - sp, WHCI_PAGE_SIZE); 373 std->num_pointers = DIV_ROUND_UP(ep - sp, WHCI_PAGE_SIZE);
303 374
304 pl_len = std->num_pointers * sizeof(struct whc_page_list_entry); 375 pl_len = std->num_pointers * sizeof(struct whc_page_list_entry);
@@ -309,7 +380,7 @@ static int qset_fill_page_list(struct whc *whc, struct whc_std *std, gfp_t mem_f
309 380
310 for (p = 0; p < std->num_pointers; p++) { 381 for (p = 0; p < std->num_pointers; p++) {
311 std->pl_virt[p].buf_ptr = cpu_to_le64(dma_addr); 382 std->pl_virt[p].buf_ptr = cpu_to_le64(dma_addr);
312 dma_addr = ALIGN(dma_addr + WHCI_PAGE_SIZE, WHCI_PAGE_SIZE); 383 dma_addr = (dma_addr + WHCI_PAGE_SIZE) & ~(WHCI_PAGE_SIZE-1);
313 } 384 }
314 385
315 return 0; 386 return 0;
@@ -339,6 +410,218 @@ static void urb_dequeue_work(struct work_struct *work)
339 spin_unlock_irqrestore(&whc->lock, flags); 410 spin_unlock_irqrestore(&whc->lock, flags);
340} 411}
341 412
413static struct whc_std *qset_new_std(struct whc *whc, struct whc_qset *qset,
414 struct urb *urb, gfp_t mem_flags)
415{
416 struct whc_std *std;
417
418 std = kzalloc(sizeof(struct whc_std), mem_flags);
419 if (std == NULL)
420 return NULL;
421
422 std->urb = urb;
423 std->qtd = NULL;
424
425 INIT_LIST_HEAD(&std->list_node);
426 list_add_tail(&std->list_node, &qset->stds);
427
428 return std;
429}
430
431static int qset_add_urb_sg(struct whc *whc, struct whc_qset *qset, struct urb *urb,
432 gfp_t mem_flags)
433{
434 size_t remaining;
435 struct scatterlist *sg;
436 int i;
437 int ntds = 0;
438 struct whc_std *std = NULL;
439 struct whc_page_list_entry *entry;
440 dma_addr_t prev_end = 0;
441 size_t pl_len;
442 int p = 0;
443
444 remaining = urb->transfer_buffer_length;
445
446 for_each_sg(urb->sg->sg, sg, urb->num_sgs, i) {
447 dma_addr_t dma_addr;
448 size_t dma_remaining;
449 dma_addr_t sp, ep;
450 int num_pointers;
451
452 if (remaining == 0) {
453 break;
454 }
455
456 dma_addr = sg_dma_address(sg);
457 dma_remaining = min_t(size_t, sg_dma_len(sg), remaining);
458
459 while (dma_remaining) {
460 size_t dma_len;
461
462 /*
463 * We can use the previous std (if it exists) provided that:
464 * - the previous one ended on a page boundary.
465 * - the current one begins on a page boundary.
466 * - the previous one isn't full.
467 *
468 * If a new std is needed but the previous one
469 * was not a whole number of packets then this
470 * sg list cannot be mapped onto multiple
471 * qTDs. Return an error and let the caller
472 * sort it out.
473 */
474 if (!std
475 || (prev_end & (WHCI_PAGE_SIZE-1))
476 || (dma_addr & (WHCI_PAGE_SIZE-1))
477 || std->len + WHCI_PAGE_SIZE > QTD_MAX_XFER_SIZE) {
478 if (std->len % qset->max_packet != 0)
479 return -EINVAL;
480 std = qset_new_std(whc, qset, urb, mem_flags);
481 if (std == NULL) {
482 return -ENOMEM;
483 }
484 ntds++;
485 p = 0;
486 }
487
488 dma_len = dma_remaining;
489
490 /*
491 * If the remainder of this element doesn't
492 * fit in a single qTD, limit the qTD to a
493 * whole number of packets. This allows the
494 * remainder to go into the next qTD.
495 */
496 if (std->len + dma_len > QTD_MAX_XFER_SIZE) {
497 dma_len = (QTD_MAX_XFER_SIZE / qset->max_packet)
498 * qset->max_packet - std->len;
499 }
500
501 std->len += dma_len;
502 std->ntds_remaining = -1; /* filled in later */
503
504 sp = dma_addr & ~(WHCI_PAGE_SIZE-1);
505 ep = dma_addr + dma_len;
506 num_pointers = DIV_ROUND_UP(ep - sp, WHCI_PAGE_SIZE);
507 std->num_pointers += num_pointers;
508
509 pl_len = std->num_pointers * sizeof(struct whc_page_list_entry);
510
511 std->pl_virt = krealloc(std->pl_virt, pl_len, mem_flags);
512 if (std->pl_virt == NULL) {
513 return -ENOMEM;
514 }
515
516 for (;p < std->num_pointers; p++, entry++) {
517 std->pl_virt[p].buf_ptr = cpu_to_le64(dma_addr);
518 dma_addr = (dma_addr + WHCI_PAGE_SIZE) & ~(WHCI_PAGE_SIZE-1);
519 }
520
521 prev_end = dma_addr = ep;
522 dma_remaining -= dma_len;
523 remaining -= dma_len;
524 }
525 }
526
527 /* Now the number of stds is know, go back and fill in
528 std->ntds_remaining. */
529 list_for_each_entry(std, &qset->stds, list_node) {
530 if (std->ntds_remaining == -1) {
531 pl_len = std->num_pointers * sizeof(struct whc_page_list_entry);
532 std->ntds_remaining = ntds--;
533 std->dma_addr = dma_map_single(whc->wusbhc.dev, std->pl_virt,
534 pl_len, DMA_TO_DEVICE);
535 }
536 }
537 return 0;
538}
539
540/**
541 * qset_add_urb_sg_linearize - add an urb with sg list, copying the data
542 *
543 * If the URB contains an sg list whose elements cannot be directly
544 * mapped to qTDs then the data must be transferred via bounce
545 * buffers.
546 */
547static int qset_add_urb_sg_linearize(struct whc *whc, struct whc_qset *qset,
548 struct urb *urb, gfp_t mem_flags)
549{
550 bool is_out = usb_pipeout(urb->pipe);
551 size_t max_std_len;
552 size_t remaining;
553 int ntds = 0;
554 struct whc_std *std = NULL;
555 void *bounce = NULL;
556 struct scatterlist *sg;
557 int i;
558
559 /* limit maximum bounce buffer to 16 * 3.5 KiB ~= 28 k */
560 max_std_len = qset->max_burst * qset->max_packet;
561
562 remaining = urb->transfer_buffer_length;
563
564 for_each_sg(urb->sg->sg, sg, urb->sg->nents, i) {
565 size_t len;
566 size_t sg_remaining;
567 void *orig;
568
569 if (remaining == 0) {
570 break;
571 }
572
573 sg_remaining = min_t(size_t, remaining, sg->length);
574 orig = sg_virt(sg);
575
576 while (sg_remaining) {
577 if (!std || std->len == max_std_len) {
578 std = qset_new_std(whc, qset, urb, mem_flags);
579 if (std == NULL)
580 return -ENOMEM;
581 std->bounce_buf = kmalloc(max_std_len, mem_flags);
582 if (std->bounce_buf == NULL)
583 return -ENOMEM;
584 std->bounce_sg = sg;
585 std->bounce_offset = orig - sg_virt(sg);
586 bounce = std->bounce_buf;
587 ntds++;
588 }
589
590 len = min(sg_remaining, max_std_len - std->len);
591
592 if (is_out)
593 memcpy(bounce, orig, len);
594
595 std->len += len;
596 std->ntds_remaining = -1; /* filled in later */
597
598 bounce += len;
599 orig += len;
600 sg_remaining -= len;
601 remaining -= len;
602 }
603 }
604
605 /*
606 * For each of the new sTDs, map the bounce buffers, create
607 * page lists (if necessary), and fill in std->ntds_remaining.
608 */
609 list_for_each_entry(std, &qset->stds, list_node) {
610 if (std->ntds_remaining != -1)
611 continue;
612
613 std->dma_addr = dma_map_single(&whc->umc->dev, std->bounce_buf, std->len,
614 is_out ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
615
616 if (qset_fill_page_list(whc, std, mem_flags) < 0)
617 return -ENOMEM;
618
619 std->ntds_remaining = ntds--;
620 }
621
622 return 0;
623}
624
342/** 625/**
343 * qset_add_urb - add an urb to the qset's queue. 626 * qset_add_urb - add an urb to the qset's queue.
344 * 627 *
@@ -353,10 +636,7 @@ int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb,
353 int remaining = urb->transfer_buffer_length; 636 int remaining = urb->transfer_buffer_length;
354 u64 transfer_dma = urb->transfer_dma; 637 u64 transfer_dma = urb->transfer_dma;
355 int ntds_remaining; 638 int ntds_remaining;
356 639 int ret;
357 ntds_remaining = DIV_ROUND_UP(remaining, QTD_MAX_XFER_SIZE);
358 if (ntds_remaining == 0)
359 ntds_remaining = 1;
360 640
361 wurb = kzalloc(sizeof(struct whc_urb), mem_flags); 641 wurb = kzalloc(sizeof(struct whc_urb), mem_flags);
362 if (wurb == NULL) 642 if (wurb == NULL)
@@ -366,32 +646,39 @@ int qset_add_urb(struct whc *whc, struct whc_qset *qset, struct urb *urb,
366 wurb->urb = urb; 646 wurb->urb = urb;
367 INIT_WORK(&wurb->dequeue_work, urb_dequeue_work); 647 INIT_WORK(&wurb->dequeue_work, urb_dequeue_work);
368 648
649 if (urb->sg) {
650 ret = qset_add_urb_sg(whc, qset, urb, mem_flags);
651 if (ret == -EINVAL) {
652 qset_free_stds(qset, urb);
653 ret = qset_add_urb_sg_linearize(whc, qset, urb, mem_flags);
654 }
655 if (ret < 0)
656 goto err_no_mem;
657 return 0;
658 }
659
660 ntds_remaining = DIV_ROUND_UP(remaining, QTD_MAX_XFER_SIZE);
661 if (ntds_remaining == 0)
662 ntds_remaining = 1;
663
369 while (ntds_remaining) { 664 while (ntds_remaining) {
370 struct whc_std *std; 665 struct whc_std *std;
371 size_t std_len; 666 size_t std_len;
372 667
373 std = kmalloc(sizeof(struct whc_std), mem_flags);
374 if (std == NULL)
375 goto err_no_mem;
376
377 std_len = remaining; 668 std_len = remaining;
378 if (std_len > QTD_MAX_XFER_SIZE) 669 if (std_len > QTD_MAX_XFER_SIZE)
379 std_len = QTD_MAX_XFER_SIZE; 670 std_len = QTD_MAX_XFER_SIZE;
380 671
381 std->urb = urb; 672 std = qset_new_std(whc, qset, urb, mem_flags);
673 if (std == NULL)
674 goto err_no_mem;
675
382 std->dma_addr = transfer_dma; 676 std->dma_addr = transfer_dma;
383 std->len = std_len; 677 std->len = std_len;
384 std->ntds_remaining = ntds_remaining; 678 std->ntds_remaining = ntds_remaining;
385 std->qtd = NULL;
386 679
387 INIT_LIST_HEAD(&std->list_node); 680 if (qset_fill_page_list(whc, std, mem_flags) < 0)
388 list_add_tail(&std->list_node, &qset->stds); 681 goto err_no_mem;
389
390 if (std_len > WHCI_PAGE_SIZE) {
391 if (qset_fill_page_list(whc, std, mem_flags) < 0)
392 goto err_no_mem;
393 } else
394 std->num_pointers = 0;
395 682
396 ntds_remaining--; 683 ntds_remaining--;
397 remaining -= std_len; 684 remaining -= std_len;
diff --git a/drivers/usb/host/whci/whcd.h b/drivers/usb/host/whci/whcd.h
index 24e94d983c5e..c80c7d93bc4a 100644
--- a/drivers/usb/host/whci/whcd.h
+++ b/drivers/usb/host/whci/whcd.h
@@ -84,6 +84,11 @@ struct whc {
84 * @len: the length of data in the associated TD. 84 * @len: the length of data in the associated TD.
85 * @ntds_remaining: number of TDs (starting from this one) in this transfer. 85 * @ntds_remaining: number of TDs (starting from this one) in this transfer.
86 * 86 *
87 * @bounce_buf: a bounce buffer if the std was from an urb with a sg
88 * list that could not be mapped to qTDs directly.
89 * @bounce_sg: the first scatterlist element bounce_buf is for.
90 * @bounce_offset: the offset into bounce_sg for the start of bounce_buf.
91 *
87 * Queued URBs may require more TDs than are available in a qset so we 92 * Queued URBs may require more TDs than are available in a qset so we
88 * use a list of these "software TDs" (sTDs) to hold per-TD data. 93 * use a list of these "software TDs" (sTDs) to hold per-TD data.
89 */ 94 */
@@ -97,6 +102,10 @@ struct whc_std {
97 int num_pointers; 102 int num_pointers;
98 dma_addr_t dma_addr; 103 dma_addr_t dma_addr;
99 struct whc_page_list_entry *pl_virt; 104 struct whc_page_list_entry *pl_virt;
105
106 void *bounce_buf;
107 struct scatterlist *bounce_sg;
108 unsigned bounce_offset;
100}; 109};
101 110
102/** 111/**
diff --git a/drivers/usb/host/whci/whci-hc.h b/drivers/usb/host/whci/whci-hc.h
index e8d0001605be..4d4cbc0730bf 100644
--- a/drivers/usb/host/whci/whci-hc.h
+++ b/drivers/usb/host/whci/whci-hc.h
@@ -172,14 +172,7 @@ struct whc_qhead {
172#define QH_INFO3_MAX_DELAY(d) ((d) << 0) /* maximum stream delay in 125 us units (isoc only) */ 172#define QH_INFO3_MAX_DELAY(d) ((d) << 0) /* maximum stream delay in 125 us units (isoc only) */
173#define QH_INFO3_INTERVAL(i) ((i) << 16) /* segment interval in 125 us units (isoc only) */ 173#define QH_INFO3_INTERVAL(i) ((i) << 16) /* segment interval in 125 us units (isoc only) */
174 174
175#define QH_INFO3_TX_RATE_53_3 (0 << 24) 175#define QH_INFO3_TX_RATE(r) ((r) << 24) /* PHY rate (see [ECMA-368] section 10.3.1.1) */
176#define QH_INFO3_TX_RATE_80 (1 << 24)
177#define QH_INFO3_TX_RATE_106_7 (2 << 24)
178#define QH_INFO3_TX_RATE_160 (3 << 24)
179#define QH_INFO3_TX_RATE_200 (4 << 24)
180#define QH_INFO3_TX_RATE_320 (5 << 24)
181#define QH_INFO3_TX_RATE_400 (6 << 24)
182#define QH_INFO3_TX_RATE_480 (7 << 24)
183#define QH_INFO3_TX_PWR(p) ((p) << 29) /* transmit power (see [WUSB] section 5.2.1.2) */ 176#define QH_INFO3_TX_PWR(p) ((p) << 29) /* transmit power (see [WUSB] section 5.2.1.2) */
184 177
185#define QH_STATUS_FLOW_CTRL (1 << 15) 178#define QH_STATUS_FLOW_CTRL (1 << 15)
@@ -267,8 +260,9 @@ struct whc_qset {
267 unsigned reset:1; 260 unsigned reset:1;
268 struct urb *pause_after_urb; 261 struct urb *pause_after_urb;
269 struct completion remove_complete; 262 struct completion remove_complete;
270 int max_burst; 263 uint16_t max_packet;
271 int max_seq; 264 uint8_t max_burst;
265 uint8_t max_seq;
272}; 266};
273 267
274static inline void whc_qset_set_link_ptr(u64 *ptr, u64 target) 268static inline void whc_qset_set_link_ptr(u64 *ptr, u64 target)
diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 33128d52f212..105fa8b025bb 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -406,6 +406,25 @@ static void dbg_rsvd64(struct xhci_hcd *xhci, u64 *ctx, dma_addr_t dma)
406 } 406 }
407} 407}
408 408
409char *xhci_get_slot_state(struct xhci_hcd *xhci,
410 struct xhci_container_ctx *ctx)
411{
412 struct xhci_slot_ctx *slot_ctx = xhci_get_slot_ctx(xhci, ctx);
413
414 switch (GET_SLOT_STATE(slot_ctx->dev_state)) {
415 case 0:
416 return "enabled/disabled";
417 case 1:
418 return "default";
419 case 2:
420 return "addressed";
421 case 3:
422 return "configured";
423 default:
424 return "reserved";
425 }
426}
427
409void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx) 428void xhci_dbg_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx)
410{ 429{
411 /* Fields are 32 bits wide, DMA addresses are in bytes */ 430 /* Fields are 32 bits wide, DMA addresses are in bytes */
diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h
index ecc131c3fe33..78c4edac1db1 100644
--- a/drivers/usb/host/xhci-ext-caps.h
+++ b/drivers/usb/host/xhci-ext-caps.h
@@ -101,12 +101,15 @@ static inline int xhci_find_next_cap_offset(void __iomem *base, int ext_offset)
101 101
102 next = readl(base + ext_offset); 102 next = readl(base + ext_offset);
103 103
104 if (ext_offset == XHCI_HCC_PARAMS_OFFSET) 104 if (ext_offset == XHCI_HCC_PARAMS_OFFSET) {
105 /* Find the first extended capability */ 105 /* Find the first extended capability */
106 next = XHCI_HCC_EXT_CAPS(next); 106 next = XHCI_HCC_EXT_CAPS(next);
107 else 107 ext_offset = 0;
108 } else {
108 /* Find the next extended capability */ 109 /* Find the next extended capability */
109 next = XHCI_EXT_CAPS_NEXT(next); 110 next = XHCI_EXT_CAPS_NEXT(next);
111 }
112
110 if (!next) 113 if (!next)
111 return 0; 114 return 0;
112 /* 115 /*
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index eac5b53aa9e7..208b805b80eb 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -129,6 +129,50 @@ static u32 xhci_port_state_to_neutral(u32 state)
129 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS); 129 return (state & XHCI_PORT_RO) | (state & XHCI_PORT_RWS);
130} 130}
131 131
132static void xhci_disable_port(struct xhci_hcd *xhci, u16 wIndex,
133 u32 __iomem *addr, u32 port_status)
134{
135 /* Write 1 to disable the port */
136 xhci_writel(xhci, port_status | PORT_PE, addr);
137 port_status = xhci_readl(xhci, addr);
138 xhci_dbg(xhci, "disable port, actual port %d status = 0x%x\n",
139 wIndex, port_status);
140}
141
142static void xhci_clear_port_change_bit(struct xhci_hcd *xhci, u16 wValue,
143 u16 wIndex, u32 __iomem *addr, u32 port_status)
144{
145 char *port_change_bit;
146 u32 status;
147
148 switch (wValue) {
149 case USB_PORT_FEAT_C_RESET:
150 status = PORT_RC;
151 port_change_bit = "reset";
152 break;
153 case USB_PORT_FEAT_C_CONNECTION:
154 status = PORT_CSC;
155 port_change_bit = "connect";
156 break;
157 case USB_PORT_FEAT_C_OVER_CURRENT:
158 status = PORT_OCC;
159 port_change_bit = "over-current";
160 break;
161 case USB_PORT_FEAT_C_ENABLE:
162 status = PORT_PEC;
163 port_change_bit = "enable/disable";
164 break;
165 default:
166 /* Should never happen */
167 return;
168 }
169 /* Change bits are all write 1 to clear */
170 xhci_writel(xhci, port_status | status, addr);
171 port_status = xhci_readl(xhci, addr);
172 xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n",
173 port_change_bit, wIndex, port_status);
174}
175
132int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 176int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
133 u16 wIndex, char *buf, u16 wLength) 177 u16 wIndex, char *buf, u16 wLength)
134{ 178{
@@ -138,7 +182,6 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
138 u32 temp, status; 182 u32 temp, status;
139 int retval = 0; 183 int retval = 0;
140 u32 __iomem *addr; 184 u32 __iomem *addr;
141 char *port_change_bit;
142 185
143 ports = HCS_MAX_PORTS(xhci->hcs_params1); 186 ports = HCS_MAX_PORTS(xhci->hcs_params1);
144 187
@@ -229,26 +272,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
229 temp = xhci_port_state_to_neutral(temp); 272 temp = xhci_port_state_to_neutral(temp);
230 switch (wValue) { 273 switch (wValue) {
231 case USB_PORT_FEAT_C_RESET: 274 case USB_PORT_FEAT_C_RESET:
232 status = PORT_RC;
233 port_change_bit = "reset";
234 break;
235 case USB_PORT_FEAT_C_CONNECTION: 275 case USB_PORT_FEAT_C_CONNECTION:
236 status = PORT_CSC;
237 port_change_bit = "connect";
238 break;
239 case USB_PORT_FEAT_C_OVER_CURRENT: 276 case USB_PORT_FEAT_C_OVER_CURRENT:
240 status = PORT_OCC; 277 case USB_PORT_FEAT_C_ENABLE:
241 port_change_bit = "over-current"; 278 xhci_clear_port_change_bit(xhci, wValue, wIndex,
279 addr, temp);
280 break;
281 case USB_PORT_FEAT_ENABLE:
282 xhci_disable_port(xhci, wIndex, addr, temp);
242 break; 283 break;
243 default: 284 default:
244 goto error; 285 goto error;
245 } 286 }
246 /* Change bits are all write 1 to clear */
247 xhci_writel(xhci, temp | status, addr);
248 temp = xhci_readl(xhci, addr);
249 xhci_dbg(xhci, "clear port %s change, actual port %d status = 0x%x\n",
250 port_change_bit, wIndex, temp);
251 temp = xhci_readl(xhci, addr); /* unblock any posted writes */
252 break; 287 break;
253 default: 288 default:
254error: 289error:
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index b8fd270a8b0d..d64f5724bfc4 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/slab.h>
25#include <linux/dmapool.h> 26#include <linux/dmapool.h>
26 27
27#include "xhci.h" 28#include "xhci.h"
@@ -125,6 +126,23 @@ void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring)
125 kfree(ring); 126 kfree(ring);
126} 127}
127 128
129static void xhci_initialize_ring_info(struct xhci_ring *ring)
130{
131 /* The ring is empty, so the enqueue pointer == dequeue pointer */
132 ring->enqueue = ring->first_seg->trbs;
133 ring->enq_seg = ring->first_seg;
134 ring->dequeue = ring->enqueue;
135 ring->deq_seg = ring->first_seg;
136 /* The ring is initialized to 0. The producer must write 1 to the cycle
137 * bit to handover ownership of the TRB, so PCS = 1. The consumer must
138 * compare CCS to the cycle bit to check ownership, so CCS = 1.
139 */
140 ring->cycle_state = 1;
141 /* Not necessary for new rings, but needed for re-initialized rings */
142 ring->enq_updates = 0;
143 ring->deq_updates = 0;
144}
145
128/** 146/**
129 * Create a new ring with zero or more segments. 147 * Create a new ring with zero or more segments.
130 * 148 *
@@ -173,17 +191,7 @@ static struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
173 " segment %p (virtual), 0x%llx (DMA)\n", 191 " segment %p (virtual), 0x%llx (DMA)\n",
174 prev, (unsigned long long)prev->dma); 192 prev, (unsigned long long)prev->dma);
175 } 193 }
176 /* The ring is empty, so the enqueue pointer == dequeue pointer */ 194 xhci_initialize_ring_info(ring);
177 ring->enqueue = ring->first_seg->trbs;
178 ring->enq_seg = ring->first_seg;
179 ring->dequeue = ring->enqueue;
180 ring->deq_seg = ring->first_seg;
181 /* The ring is initialized to 0. The producer must write 1 to the cycle
182 * bit to handover ownership of the TRB, so PCS = 1. The consumer must
183 * compare CCS to the cycle bit to check ownership, so CCS = 1.
184 */
185 ring->cycle_state = 1;
186
187 return ring; 195 return ring;
188 196
189fail: 197fail:
@@ -191,6 +199,52 @@ fail:
191 return 0; 199 return 0;
192} 200}
193 201
202void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
203 struct xhci_virt_device *virt_dev,
204 unsigned int ep_index)
205{
206 int rings_cached;
207
208 rings_cached = virt_dev->num_rings_cached;
209 if (rings_cached < XHCI_MAX_RINGS_CACHED) {
210 virt_dev->num_rings_cached++;
211 rings_cached = virt_dev->num_rings_cached;
212 virt_dev->ring_cache[rings_cached] =
213 virt_dev->eps[ep_index].ring;
214 xhci_dbg(xhci, "Cached old ring, "
215 "%d ring%s cached\n",
216 rings_cached,
217 (rings_cached > 1) ? "s" : "");
218 } else {
219 xhci_ring_free(xhci, virt_dev->eps[ep_index].ring);
220 xhci_dbg(xhci, "Ring cache full (%d rings), "
221 "freeing ring\n",
222 virt_dev->num_rings_cached);
223 }
224 virt_dev->eps[ep_index].ring = NULL;
225}
226
227/* Zero an endpoint ring (except for link TRBs) and move the enqueue and dequeue
228 * pointers to the beginning of the ring.
229 */
230static void xhci_reinit_cached_ring(struct xhci_hcd *xhci,
231 struct xhci_ring *ring)
232{
233 struct xhci_segment *seg = ring->first_seg;
234 do {
235 memset(seg->trbs, 0,
236 sizeof(union xhci_trb)*TRBS_PER_SEGMENT);
237 /* All endpoint rings have link TRBs */
238 xhci_link_segments(xhci, seg, seg->next, 1);
239 seg = seg->next;
240 } while (seg != ring->first_seg);
241 xhci_initialize_ring_info(ring);
242 /* td list should be empty since all URBs have been cancelled,
243 * but just in case...
244 */
245 INIT_LIST_HEAD(&ring->td_list);
246}
247
194#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32) 248#define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
195 249
196struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci, 250struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
@@ -214,6 +268,8 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
214void xhci_free_container_ctx(struct xhci_hcd *xhci, 268void xhci_free_container_ctx(struct xhci_hcd *xhci,
215 struct xhci_container_ctx *ctx) 269 struct xhci_container_ctx *ctx)
216{ 270{
271 if (!ctx)
272 return;
217 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma); 273 dma_pool_free(xhci->device_pool, ctx->bytes, ctx->dma);
218 kfree(ctx); 274 kfree(ctx);
219} 275}
@@ -248,6 +304,15 @@ struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci,
248 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params))); 304 (ctx->bytes + (ep_index * CTX_SIZE(xhci->hcc_params)));
249} 305}
250 306
307static void xhci_init_endpoint_timer(struct xhci_hcd *xhci,
308 struct xhci_virt_ep *ep)
309{
310 init_timer(&ep->stop_cmd_timer);
311 ep->stop_cmd_timer.data = (unsigned long) ep;
312 ep->stop_cmd_timer.function = xhci_stop_endpoint_command_watchdog;
313 ep->xhci = xhci;
314}
315
251/* All the xhci_tds in the ring's TD list should be freed at this point */ 316/* All the xhci_tds in the ring's TD list should be freed at this point */
252void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id) 317void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
253{ 318{
@@ -267,6 +332,12 @@ void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id)
267 if (dev->eps[i].ring) 332 if (dev->eps[i].ring)
268 xhci_ring_free(xhci, dev->eps[i].ring); 333 xhci_ring_free(xhci, dev->eps[i].ring);
269 334
335 if (dev->ring_cache) {
336 for (i = 0; i < dev->num_rings_cached; i++)
337 xhci_ring_free(xhci, dev->ring_cache[i]);
338 kfree(dev->ring_cache);
339 }
340
270 if (dev->in_ctx) 341 if (dev->in_ctx)
271 xhci_free_container_ctx(xhci, dev->in_ctx); 342 xhci_free_container_ctx(xhci, dev->in_ctx);
272 if (dev->out_ctx) 343 if (dev->out_ctx)
@@ -309,15 +380,25 @@ int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
309 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id, 380 xhci_dbg(xhci, "Slot %d input ctx = 0x%llx (dma)\n", slot_id,
310 (unsigned long long)dev->in_ctx->dma); 381 (unsigned long long)dev->in_ctx->dma);
311 382
312 /* Initialize the cancellation list for each endpoint */ 383 /* Initialize the cancellation list and watchdog timers for each ep */
313 for (i = 0; i < 31; i++) 384 for (i = 0; i < 31; i++) {
385 xhci_init_endpoint_timer(xhci, &dev->eps[i]);
314 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list); 386 INIT_LIST_HEAD(&dev->eps[i].cancelled_td_list);
387 }
315 388
316 /* Allocate endpoint 0 ring */ 389 /* Allocate endpoint 0 ring */
317 dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags); 390 dev->eps[0].ring = xhci_ring_alloc(xhci, 1, true, flags);
318 if (!dev->eps[0].ring) 391 if (!dev->eps[0].ring)
319 goto fail; 392 goto fail;
320 393
394 /* Allocate pointers to the ring cache */
395 dev->ring_cache = kzalloc(
396 sizeof(struct xhci_ring *)*XHCI_MAX_RINGS_CACHED,
397 flags);
398 if (!dev->ring_cache)
399 goto fail;
400 dev->num_rings_cached = 0;
401
321 init_completion(&dev->cmd_completion); 402 init_completion(&dev->cmd_completion);
322 INIT_LIST_HEAD(&dev->cmd_list); 403 INIT_LIST_HEAD(&dev->cmd_list);
323 404
@@ -374,7 +455,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
374 case USB_SPEED_LOW: 455 case USB_SPEED_LOW:
375 slot_ctx->dev_info |= (u32) SLOT_SPEED_LS; 456 slot_ctx->dev_info |= (u32) SLOT_SPEED_LS;
376 break; 457 break;
377 case USB_SPEED_VARIABLE: 458 case USB_SPEED_WIRELESS:
378 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 459 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
379 return -EINVAL; 460 return -EINVAL;
380 break; 461 break;
@@ -418,7 +499,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
418 case USB_SPEED_LOW: 499 case USB_SPEED_LOW:
419 ep0_ctx->ep_info2 |= MAX_PACKET(8); 500 ep0_ctx->ep_info2 |= MAX_PACKET(8);
420 break; 501 break;
421 case USB_SPEED_VARIABLE: 502 case USB_SPEED_WIRELESS:
422 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n"); 503 xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
423 return -EINVAL; 504 return -EINVAL;
424 break; 505 break;
@@ -486,8 +567,13 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
486 if (interval < 3) 567 if (interval < 3)
487 interval = 3; 568 interval = 3;
488 if ((1 << interval) != 8*ep->desc.bInterval) 569 if ((1 << interval) != 8*ep->desc.bInterval)
489 dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n", 570 dev_warn(&udev->dev,
490 ep->desc.bEndpointAddress, 1 << interval); 571 "ep %#x - rounding interval"
572 " to %d microframes, "
573 "ep desc says %d microframes\n",
574 ep->desc.bEndpointAddress,
575 1 << interval,
576 8*ep->desc.bInterval);
491 } 577 }
492 break; 578 break;
493 default: 579 default:
@@ -496,6 +582,19 @@ static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
496 return EP_INTERVAL(interval); 582 return EP_INTERVAL(interval);
497} 583}
498 584
585/* The "Mult" field in the endpoint context is only set for SuperSpeed devices.
586 * High speed endpoint descriptors can define "the number of additional
587 * transaction opportunities per microframe", but that goes in the Max Burst
588 * endpoint context field.
589 */
590static inline u32 xhci_get_endpoint_mult(struct usb_device *udev,
591 struct usb_host_endpoint *ep)
592{
593 if (udev->speed != USB_SPEED_SUPER || !ep->ss_ep_comp)
594 return 0;
595 return ep->ss_ep_comp->desc.bmAttributes;
596}
597
499static inline u32 xhci_get_endpoint_type(struct usb_device *udev, 598static inline u32 xhci_get_endpoint_type(struct usb_device *udev,
500 struct usb_host_endpoint *ep) 599 struct usb_host_endpoint *ep)
501{ 600{
@@ -526,6 +625,36 @@ static inline u32 xhci_get_endpoint_type(struct usb_device *udev,
526 return type; 625 return type;
527} 626}
528 627
628/* Return the maximum endpoint service interval time (ESIT) payload.
629 * Basically, this is the maxpacket size, multiplied by the burst size
630 * and mult size.
631 */
632static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci,
633 struct usb_device *udev,
634 struct usb_host_endpoint *ep)
635{
636 int max_burst;
637 int max_packet;
638
639 /* Only applies for interrupt or isochronous endpoints */
640 if (usb_endpoint_xfer_control(&ep->desc) ||
641 usb_endpoint_xfer_bulk(&ep->desc))
642 return 0;
643
644 if (udev->speed == USB_SPEED_SUPER) {
645 if (ep->ss_ep_comp)
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
652 max_packet = ep->desc.wMaxPacketSize & 0x3ff;
653 max_burst = (ep->desc.wMaxPacketSize & 0x1800) >> 11;
654 /* A 0 in max burst means 1 transfer per ESIT */
655 return max_packet * (max_burst + 1);
656}
657
529int xhci_endpoint_init(struct xhci_hcd *xhci, 658int xhci_endpoint_init(struct xhci_hcd *xhci,
530 struct xhci_virt_device *virt_dev, 659 struct xhci_virt_device *virt_dev,
531 struct usb_device *udev, 660 struct usb_device *udev,
@@ -537,6 +666,7 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
537 struct xhci_ring *ep_ring; 666 struct xhci_ring *ep_ring;
538 unsigned int max_packet; 667 unsigned int max_packet;
539 unsigned int max_burst; 668 unsigned int max_burst;
669 u32 max_esit_payload;
540 670
541 ep_index = xhci_get_endpoint_index(&ep->desc); 671 ep_index = xhci_get_endpoint_index(&ep->desc);
542 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index); 672 ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
@@ -544,12 +674,21 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
544 /* Set up the endpoint ring */ 674 /* Set up the endpoint ring */
545 virt_dev->eps[ep_index].new_ring = 675 virt_dev->eps[ep_index].new_ring =
546 xhci_ring_alloc(xhci, 1, true, mem_flags); 676 xhci_ring_alloc(xhci, 1, true, mem_flags);
547 if (!virt_dev->eps[ep_index].new_ring) 677 if (!virt_dev->eps[ep_index].new_ring) {
548 return -ENOMEM; 678 /* Attempt to use the ring cache */
679 if (virt_dev->num_rings_cached == 0)
680 return -ENOMEM;
681 virt_dev->eps[ep_index].new_ring =
682 virt_dev->ring_cache[virt_dev->num_rings_cached];
683 virt_dev->ring_cache[virt_dev->num_rings_cached] = NULL;
684 virt_dev->num_rings_cached--;
685 xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring);
686 }
549 ep_ring = virt_dev->eps[ep_index].new_ring; 687 ep_ring = virt_dev->eps[ep_index].new_ring;
550 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state; 688 ep_ctx->deq = ep_ring->first_seg->dma | ep_ring->cycle_state;
551 689
552 ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep); 690 ep_ctx->ep_info = xhci_get_endpoint_interval(udev, ep);
691 ep_ctx->ep_info |= EP_MULT(xhci_get_endpoint_mult(udev, ep));
553 692
554 /* FIXME dig Mult and streams info out of ep companion desc */ 693 /* FIXME dig Mult and streams info out of ep companion desc */
555 694
@@ -595,6 +734,26 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
595 default: 734 default:
596 BUG(); 735 BUG();
597 } 736 }
737 max_esit_payload = xhci_get_max_esit_payload(xhci, udev, ep);
738 ep_ctx->tx_info = MAX_ESIT_PAYLOAD_FOR_EP(max_esit_payload);
739
740 /*
741 * XXX no idea how to calculate the average TRB buffer length for bulk
742 * endpoints, as the driver gives us no clue how big each scatter gather
743 * list entry (or buffer) is going to be.
744 *
745 * For isochronous and interrupt endpoints, we set it to the max
746 * available, until we have new API in the USB core to allow drivers to
747 * declare how much bandwidth they actually need.
748 *
749 * Normally, it would be calculated by taking the total of the buffer
750 * lengths in the TD and then dividing by the number of TRBs in a TD,
751 * including link TRBs, No-op TRBs, and Event data TRBs. Since we don't
752 * use Event Data TRBs, and we don't chain in a link TRB on short
753 * transfers, we're basically dividing by 1.
754 */
755 ep_ctx->tx_info |= AVG_TRB_LENGTH_FOR_EP(max_esit_payload);
756
598 /* FIXME Debug endpoint context */ 757 /* FIXME Debug endpoint context */
599 return 0; 758 return 0;
600} 759}
@@ -758,7 +917,8 @@ static void scratchpad_free(struct xhci_hcd *xhci)
758} 917}
759 918
760struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 919struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
761 bool allocate_completion, gfp_t mem_flags) 920 bool allocate_in_ctx, bool allocate_completion,
921 gfp_t mem_flags)
762{ 922{
763 struct xhci_command *command; 923 struct xhci_command *command;
764 924
@@ -766,16 +926,22 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
766 if (!command) 926 if (!command)
767 return NULL; 927 return NULL;
768 928
769 command->in_ctx = 929 if (allocate_in_ctx) {
770 xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT, mem_flags); 930 command->in_ctx =
771 if (!command->in_ctx) 931 xhci_alloc_container_ctx(xhci, XHCI_CTX_TYPE_INPUT,
772 return NULL; 932 mem_flags);
933 if (!command->in_ctx) {
934 kfree(command);
935 return NULL;
936 }
937 }
773 938
774 if (allocate_completion) { 939 if (allocate_completion) {
775 command->completion = 940 command->completion =
776 kzalloc(sizeof(struct completion), mem_flags); 941 kzalloc(sizeof(struct completion), mem_flags);
777 if (!command->completion) { 942 if (!command->completion) {
778 xhci_free_container_ctx(xhci, command->in_ctx); 943 xhci_free_container_ctx(xhci, command->in_ctx);
944 kfree(command);
779 return NULL; 945 return NULL;
780 } 946 }
781 init_completion(command->completion); 947 init_completion(command->completion);
@@ -848,6 +1014,163 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
848 xhci->page_shift = 0; 1014 xhci->page_shift = 0;
849} 1015}
850 1016
1017static int xhci_test_trb_in_td(struct xhci_hcd *xhci,
1018 struct xhci_segment *input_seg,
1019 union xhci_trb *start_trb,
1020 union xhci_trb *end_trb,
1021 dma_addr_t input_dma,
1022 struct xhci_segment *result_seg,
1023 char *test_name, int test_number)
1024{
1025 unsigned long long start_dma;
1026 unsigned long long end_dma;
1027 struct xhci_segment *seg;
1028
1029 start_dma = xhci_trb_virt_to_dma(input_seg, start_trb);
1030 end_dma = xhci_trb_virt_to_dma(input_seg, end_trb);
1031
1032 seg = trb_in_td(input_seg, start_trb, end_trb, input_dma);
1033 if (seg != result_seg) {
1034 xhci_warn(xhci, "WARN: %s TRB math test %d failed!\n",
1035 test_name, test_number);
1036 xhci_warn(xhci, "Tested TRB math w/ seg %p and "
1037 "input DMA 0x%llx\n",
1038 input_seg,
1039 (unsigned long long) input_dma);
1040 xhci_warn(xhci, "starting TRB %p (0x%llx DMA), "
1041 "ending TRB %p (0x%llx DMA)\n",
1042 start_trb, start_dma,
1043 end_trb, end_dma);
1044 xhci_warn(xhci, "Expected seg %p, got seg %p\n",
1045 result_seg, seg);
1046 return -1;
1047 }
1048 return 0;
1049}
1050
1051/* TRB math checks for xhci_trb_in_td(), using the command and event rings. */
1052static int xhci_check_trb_in_td_math(struct xhci_hcd *xhci, gfp_t mem_flags)
1053{
1054 struct {
1055 dma_addr_t input_dma;
1056 struct xhci_segment *result_seg;
1057 } simple_test_vector [] = {
1058 /* A zeroed DMA field should fail */
1059 { 0, NULL },
1060 /* One TRB before the ring start should fail */
1061 { xhci->event_ring->first_seg->dma - 16, NULL },
1062 /* One byte before the ring start should fail */
1063 { xhci->event_ring->first_seg->dma - 1, NULL },
1064 /* Starting TRB should succeed */
1065 { xhci->event_ring->first_seg->dma, xhci->event_ring->first_seg },
1066 /* Ending TRB should succeed */
1067 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16,
1068 xhci->event_ring->first_seg },
1069 /* One byte after the ring end should fail */
1070 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 1)*16 + 1, NULL },
1071 /* One TRB after the ring end should fail */
1072 { xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT)*16, NULL },
1073 /* An address of all ones should fail */
1074 { (dma_addr_t) (~0), NULL },
1075 };
1076 struct {
1077 struct xhci_segment *input_seg;
1078 union xhci_trb *start_trb;
1079 union xhci_trb *end_trb;
1080 dma_addr_t input_dma;
1081 struct xhci_segment *result_seg;
1082 } complex_test_vector [] = {
1083 /* Test feeding a valid DMA address from a different ring */
1084 { .input_seg = xhci->event_ring->first_seg,
1085 .start_trb = xhci->event_ring->first_seg->trbs,
1086 .end_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
1087 .input_dma = xhci->cmd_ring->first_seg->dma,
1088 .result_seg = NULL,
1089 },
1090 /* Test feeding a valid end TRB from a different ring */
1091 { .input_seg = xhci->event_ring->first_seg,
1092 .start_trb = xhci->event_ring->first_seg->trbs,
1093 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
1094 .input_dma = xhci->cmd_ring->first_seg->dma,
1095 .result_seg = NULL,
1096 },
1097 /* Test feeding a valid start and end TRB from a different ring */
1098 { .input_seg = xhci->event_ring->first_seg,
1099 .start_trb = xhci->cmd_ring->first_seg->trbs,
1100 .end_trb = &xhci->cmd_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
1101 .input_dma = xhci->cmd_ring->first_seg->dma,
1102 .result_seg = NULL,
1103 },
1104 /* TRB in this ring, but after this TD */
1105 { .input_seg = xhci->event_ring->first_seg,
1106 .start_trb = &xhci->event_ring->first_seg->trbs[0],
1107 .end_trb = &xhci->event_ring->first_seg->trbs[3],
1108 .input_dma = xhci->event_ring->first_seg->dma + 4*16,
1109 .result_seg = NULL,
1110 },
1111 /* TRB in this ring, but before this TD */
1112 { .input_seg = xhci->event_ring->first_seg,
1113 .start_trb = &xhci->event_ring->first_seg->trbs[3],
1114 .end_trb = &xhci->event_ring->first_seg->trbs[6],
1115 .input_dma = xhci->event_ring->first_seg->dma + 2*16,
1116 .result_seg = NULL,
1117 },
1118 /* TRB in this ring, but after this wrapped TD */
1119 { .input_seg = xhci->event_ring->first_seg,
1120 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
1121 .end_trb = &xhci->event_ring->first_seg->trbs[1],
1122 .input_dma = xhci->event_ring->first_seg->dma + 2*16,
1123 .result_seg = NULL,
1124 },
1125 /* TRB in this ring, but before this wrapped TD */
1126 { .input_seg = xhci->event_ring->first_seg,
1127 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
1128 .end_trb = &xhci->event_ring->first_seg->trbs[1],
1129 .input_dma = xhci->event_ring->first_seg->dma + (TRBS_PER_SEGMENT - 4)*16,
1130 .result_seg = NULL,
1131 },
1132 /* TRB not in this ring, and we have a wrapped TD */
1133 { .input_seg = xhci->event_ring->first_seg,
1134 .start_trb = &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 3],
1135 .end_trb = &xhci->event_ring->first_seg->trbs[1],
1136 .input_dma = xhci->cmd_ring->first_seg->dma + 2*16,
1137 .result_seg = NULL,
1138 },
1139 };
1140
1141 unsigned int num_tests;
1142 int i, ret;
1143
1144 num_tests = sizeof(simple_test_vector) / sizeof(simple_test_vector[0]);
1145 for (i = 0; i < num_tests; i++) {
1146 ret = xhci_test_trb_in_td(xhci,
1147 xhci->event_ring->first_seg,
1148 xhci->event_ring->first_seg->trbs,
1149 &xhci->event_ring->first_seg->trbs[TRBS_PER_SEGMENT - 1],
1150 simple_test_vector[i].input_dma,
1151 simple_test_vector[i].result_seg,
1152 "Simple", i);
1153 if (ret < 0)
1154 return ret;
1155 }
1156
1157 num_tests = sizeof(complex_test_vector) / sizeof(complex_test_vector[0]);
1158 for (i = 0; i < num_tests; i++) {
1159 ret = xhci_test_trb_in_td(xhci,
1160 complex_test_vector[i].input_seg,
1161 complex_test_vector[i].start_trb,
1162 complex_test_vector[i].end_trb,
1163 complex_test_vector[i].input_dma,
1164 complex_test_vector[i].result_seg,
1165 "Complex", i);
1166 if (ret < 0)
1167 return ret;
1168 }
1169 xhci_dbg(xhci, "TRB math tests passed.\n");
1170 return 0;
1171}
1172
1173
851int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags) 1174int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
852{ 1175{
853 dma_addr_t dma; 1176 dma_addr_t dma;
@@ -951,6 +1274,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
951 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, false, flags); 1274 xhci->event_ring = xhci_ring_alloc(xhci, ERST_NUM_SEGS, false, flags);
952 if (!xhci->event_ring) 1275 if (!xhci->event_ring)
953 goto fail; 1276 goto fail;
1277 if (xhci_check_trb_in_td_math(xhci, flags) < 0)
1278 goto fail;
954 1279
955 xhci->erst.entries = pci_alloc_consistent(to_pci_dev(dev), 1280 xhci->erst.entries = pci_alloc_consistent(to_pci_dev(dev),
956 sizeof(struct xhci_erst_entry)*ERST_NUM_SEGS, &dma); 1281 sizeof(struct xhci_erst_entry)*ERST_NUM_SEGS, &dma);
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 06595ec27bb7..417d37aff8d7 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -54,6 +54,8 @@ 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;
58
57 xhci->cap_regs = hcd->regs; 59 xhci->cap_regs = hcd->regs;
58 xhci->op_regs = hcd->regs + 60 xhci->op_regs = hcd->regs +
59 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase)); 61 HC_LENGTH(xhci_readl(xhci, &xhci->cap_regs->hc_capbase));
@@ -137,6 +139,7 @@ static const struct hc_driver xhci_pci_hc_driver = {
137 .reset_bandwidth = xhci_reset_bandwidth, 139 .reset_bandwidth = xhci_reset_bandwidth,
138 .address_device = xhci_address_device, 140 .address_device = xhci_address_device,
139 .update_hub_device = xhci_update_hub_device, 141 .update_hub_device = xhci_update_hub_device,
142 .reset_device = xhci_reset_device,
140 143
141 /* 144 /*
142 * scheduling support 145 * scheduling support
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 821b7b4709de..85d7e8f2085e 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -65,6 +65,7 @@
65 */ 65 */
66 66
67#include <linux/scatterlist.h> 67#include <linux/scatterlist.h>
68#include <linux/slab.h>
68#include "xhci.h" 69#include "xhci.h"
69 70
70/* 71/*
@@ -306,7 +307,7 @@ static void ring_ep_doorbell(struct xhci_hcd *xhci,
306 /* Don't ring the doorbell for this endpoint if there are pending 307 /* Don't ring the doorbell for this endpoint if there are pending
307 * cancellations because the we don't want to interrupt processing. 308 * cancellations because the we don't want to interrupt processing.
308 */ 309 */
309 if (!ep->cancels_pending && !(ep_state & SET_DEQ_PENDING) 310 if (!(ep_state & EP_HALT_PENDING) && !(ep_state & SET_DEQ_PENDING)
310 && !(ep_state & EP_HALTED)) { 311 && !(ep_state & EP_HALTED)) {
311 field = xhci_readl(xhci, db_addr) & DB_MASK; 312 field = xhci_readl(xhci, db_addr) & DB_MASK;
312 xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr); 313 xhci_writel(xhci, field | EPI_TO_DB(ep_index), db_addr);
@@ -475,6 +476,35 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
475 ep->ep_state |= SET_DEQ_PENDING; 476 ep->ep_state |= SET_DEQ_PENDING;
476} 477}
477 478
479static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci,
480 struct xhci_virt_ep *ep)
481{
482 ep->ep_state &= ~EP_HALT_PENDING;
483 /* Can't del_timer_sync in interrupt, so we attempt to cancel. If the
484 * timer is running on another CPU, we don't decrement stop_cmds_pending
485 * (since we didn't successfully stop the watchdog timer).
486 */
487 if (del_timer(&ep->stop_cmd_timer))
488 ep->stop_cmds_pending--;
489}
490
491/* Must be called with xhci->lock held in interrupt context */
492static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci,
493 struct xhci_td *cur_td, int status, char *adjective)
494{
495 struct usb_hcd *hcd = xhci_to_hcd(xhci);
496
497 cur_td->urb->hcpriv = NULL;
498 usb_hcd_unlink_urb_from_ep(hcd, cur_td->urb);
499 xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, cur_td->urb);
500
501 spin_unlock(&xhci->lock);
502 usb_hcd_giveback_urb(hcd, cur_td->urb, status);
503 kfree(cur_td);
504 spin_lock(&xhci->lock);
505 xhci_dbg(xhci, "%s URB given back\n", adjective);
506}
507
478/* 508/*
479 * When we get a command completion for a Stop Endpoint Command, we need to 509 * When we get a command completion for a Stop Endpoint Command, we need to
480 * unlink any cancelled TDs from the ring. There are two ways to do that: 510 * unlink any cancelled TDs from the ring. There are two ways to do that:
@@ -497,9 +527,6 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
497 struct xhci_td *last_unlinked_td; 527 struct xhci_td *last_unlinked_td;
498 528
499 struct xhci_dequeue_state deq_state; 529 struct xhci_dequeue_state deq_state;
500#ifdef CONFIG_USB_HCD_STAT
501 ktime_t stop_time = ktime_get();
502#endif
503 530
504 memset(&deq_state, 0, sizeof(deq_state)); 531 memset(&deq_state, 0, sizeof(deq_state));
505 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]); 532 slot_id = TRB_TO_SLOT_ID(trb->generic.field[3]);
@@ -507,8 +534,11 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
507 ep = &xhci->devs[slot_id]->eps[ep_index]; 534 ep = &xhci->devs[slot_id]->eps[ep_index];
508 ep_ring = ep->ring; 535 ep_ring = ep->ring;
509 536
510 if (list_empty(&ep->cancelled_td_list)) 537 if (list_empty(&ep->cancelled_td_list)) {
538 xhci_stop_watchdog_timer_in_irq(xhci, ep);
539 ring_ep_doorbell(xhci, slot_id, ep_index);
511 return; 540 return;
541 }
512 542
513 /* Fix up the ep ring first, so HW stops executing cancelled TDs. 543 /* Fix up the ep ring first, so HW stops executing cancelled TDs.
514 * We have the xHCI lock, so nothing can modify this list until we drop 544 * We have the xHCI lock, so nothing can modify this list until we drop
@@ -535,9 +565,9 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
535 * the cancelled TD list for URB completion later. 565 * the cancelled TD list for URB completion later.
536 */ 566 */
537 list_del(&cur_td->td_list); 567 list_del(&cur_td->td_list);
538 ep->cancels_pending--;
539 } 568 }
540 last_unlinked_td = cur_td; 569 last_unlinked_td = cur_td;
570 xhci_stop_watchdog_timer_in_irq(xhci, ep);
541 571
542 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */ 572 /* If necessary, queue a Set Transfer Ring Dequeue Pointer command */
543 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) { 573 if (deq_state.new_deq_ptr && deq_state.new_deq_seg) {
@@ -561,27 +591,136 @@ static void handle_stopped_endpoint(struct xhci_hcd *xhci,
561 list_del(&cur_td->cancelled_td_list); 591 list_del(&cur_td->cancelled_td_list);
562 592
563 /* Clean up the cancelled URB */ 593 /* Clean up the cancelled URB */
564#ifdef CONFIG_USB_HCD_STAT
565 hcd_stat_update(xhci->tp_stat, cur_td->urb->actual_length,
566 ktime_sub(stop_time, cur_td->start_time));
567#endif
568 cur_td->urb->hcpriv = NULL;
569 usb_hcd_unlink_urb_from_ep(xhci_to_hcd(xhci), cur_td->urb);
570
571 xhci_dbg(xhci, "Giveback cancelled URB %p\n", cur_td->urb);
572 spin_unlock(&xhci->lock);
573 /* Doesn't matter what we pass for status, since the core will 594 /* Doesn't matter what we pass for status, since the core will
574 * just overwrite it (because the URB has been unlinked). 595 * just overwrite it (because the URB has been unlinked).
575 */ 596 */
576 usb_hcd_giveback_urb(xhci_to_hcd(xhci), cur_td->urb, 0); 597 xhci_giveback_urb_in_irq(xhci, cur_td, 0, "cancelled");
577 kfree(cur_td);
578 598
579 spin_lock(&xhci->lock); 599 /* Stop processing the cancelled list if the watchdog timer is
600 * running.
601 */
602 if (xhci->xhc_state & XHCI_STATE_DYING)
603 return;
580 } while (cur_td != last_unlinked_td); 604 } while (cur_td != last_unlinked_td);
581 605
582 /* Return to the event handler with xhci->lock re-acquired */ 606 /* Return to the event handler with xhci->lock re-acquired */
583} 607}
584 608
609/* Watchdog timer function for when a stop endpoint command fails to complete.
610 * In this case, we assume the host controller is broken or dying or dead. The
611 * host may still be completing some other events, so we have to be careful to
612 * let the event ring handler and the URB dequeueing/enqueueing functions know
613 * through xhci->state.
614 *
615 * The timer may also fire if the host takes a very long time to respond to the
616 * command, and the stop endpoint command completion handler cannot delete the
617 * timer before the timer function is called. Another endpoint cancellation may
618 * sneak in before the timer function can grab the lock, and that may queue
619 * another stop endpoint command and add the timer back. So we cannot use a
620 * simple flag to say whether there is a pending stop endpoint command for a
621 * particular endpoint.
622 *
623 * Instead we use a combination of that flag and a counter for the number of
624 * pending stop endpoint commands. If the timer is the tail end of the last
625 * stop endpoint command, and the endpoint's command is still pending, we assume
626 * the host is dying.
627 */
628void xhci_stop_endpoint_command_watchdog(unsigned long arg)
629{
630 struct xhci_hcd *xhci;
631 struct xhci_virt_ep *ep;
632 struct xhci_virt_ep *temp_ep;
633 struct xhci_ring *ring;
634 struct xhci_td *cur_td;
635 int ret, i, j;
636
637 ep = (struct xhci_virt_ep *) arg;
638 xhci = ep->xhci;
639
640 spin_lock(&xhci->lock);
641
642 ep->stop_cmds_pending--;
643 if (xhci->xhc_state & XHCI_STATE_DYING) {
644 xhci_dbg(xhci, "Stop EP timer ran, but another timer marked "
645 "xHCI as DYING, exiting.\n");
646 spin_unlock(&xhci->lock);
647 return;
648 }
649 if (!(ep->stop_cmds_pending == 0 && (ep->ep_state & EP_HALT_PENDING))) {
650 xhci_dbg(xhci, "Stop EP timer ran, but no command pending, "
651 "exiting.\n");
652 spin_unlock(&xhci->lock);
653 return;
654 }
655
656 xhci_warn(xhci, "xHCI host not responding to stop endpoint command.\n");
657 xhci_warn(xhci, "Assuming host is dying, halting host.\n");
658 /* Oops, HC is dead or dying or at least not responding to the stop
659 * endpoint command.
660 */
661 xhci->xhc_state |= XHCI_STATE_DYING;
662 /* Disable interrupts from the host controller and start halting it */
663 xhci_quiesce(xhci);
664 spin_unlock(&xhci->lock);
665
666 ret = xhci_halt(xhci);
667
668 spin_lock(&xhci->lock);
669 if (ret < 0) {
670 /* This is bad; the host is not responding to commands and it's
671 * not allowing itself to be halted. At least interrupts are
672 * disabled, so we can set HC_STATE_HALT and notify the
673 * USB core. But if we call usb_hc_died(), it will attempt to
674 * disconnect all device drivers under this host. Those
675 * disconnect() methods will wait for all URBs to be unlinked,
676 * so we must complete them.
677 */
678 xhci_warn(xhci, "Non-responsive xHCI host is not halting.\n");
679 xhci_warn(xhci, "Completing active URBs anyway.\n");
680 /* We could turn all TDs on the rings to no-ops. This won't
681 * help if the host has cached part of the ring, and is slow if
682 * we want to preserve the cycle bit. Skip it and hope the host
683 * doesn't touch the memory.
684 */
685 }
686 for (i = 0; i < MAX_HC_SLOTS; i++) {
687 if (!xhci->devs[i])
688 continue;
689 for (j = 0; j < 31; j++) {
690 temp_ep = &xhci->devs[i]->eps[j];
691 ring = temp_ep->ring;
692 if (!ring)
693 continue;
694 xhci_dbg(xhci, "Killing URBs for slot ID %u, "
695 "ep index %u\n", i, j);
696 while (!list_empty(&ring->td_list)) {
697 cur_td = list_first_entry(&ring->td_list,
698 struct xhci_td,
699 td_list);
700 list_del(&cur_td->td_list);
701 if (!list_empty(&cur_td->cancelled_td_list))
702 list_del(&cur_td->cancelled_td_list);
703 xhci_giveback_urb_in_irq(xhci, cur_td,
704 -ESHUTDOWN, "killed");
705 }
706 while (!list_empty(&temp_ep->cancelled_td_list)) {
707 cur_td = list_first_entry(
708 &temp_ep->cancelled_td_list,
709 struct xhci_td,
710 cancelled_td_list);
711 list_del(&cur_td->cancelled_td_list);
712 xhci_giveback_urb_in_irq(xhci, cur_td,
713 -ESHUTDOWN, "killed");
714 }
715 }
716 }
717 spin_unlock(&xhci->lock);
718 xhci_to_hcd(xhci)->state = HC_STATE_HALT;
719 xhci_dbg(xhci, "Calling usb_hc_died()\n");
720 usb_hc_died(xhci_to_hcd(xhci));
721 xhci_dbg(xhci, "xHCI host controller is dead.\n");
722}
723
585/* 724/*
586 * When we get a completion for a Set Transfer Ring Dequeue Pointer command, 725 * When we get a completion for a Set Transfer Ring Dequeue Pointer command,
587 * we need to clear the set deq pending flag in the endpoint ring state, so that 726 * we need to clear the set deq pending flag in the endpoint ring state, so that
@@ -765,28 +904,32 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
765 virt_dev->in_ctx); 904 virt_dev->in_ctx);
766 /* Input ctx add_flags are the endpoint index plus one */ 905 /* Input ctx add_flags are the endpoint index plus one */
767 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1; 906 ep_index = xhci_last_valid_endpoint(ctrl_ctx->add_flags) - 1;
768 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring; 907 /* A usb_set_interface() call directly after clearing a halted
769 if (!ep_ring) { 908 * condition may race on this quirky hardware.
770 /* This must have been an initial configure endpoint */ 909 * Not worth worrying about, since this is prototype hardware.
771 xhci->devs[slot_id]->cmd_status = 910 */
772 GET_COMP_CODE(event->status);
773 complete(&xhci->devs[slot_id]->cmd_completion);
774 break;
775 }
776 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
777 xhci_dbg(xhci, "Completed config ep cmd - last ep index = %d, "
778 "state = %d\n", ep_index, ep_state);
779 if (xhci->quirks & XHCI_RESET_EP_QUIRK && 911 if (xhci->quirks & XHCI_RESET_EP_QUIRK &&
780 ep_state & EP_HALTED) { 912 ep_index != (unsigned int) -1 &&
913 ctrl_ctx->add_flags - SLOT_FLAG ==
914 ctrl_ctx->drop_flags) {
915 ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
916 ep_state = xhci->devs[slot_id]->eps[ep_index].ep_state;
917 if (!(ep_state & EP_HALTED))
918 goto bandwidth_change;
919 xhci_dbg(xhci, "Completed config ep cmd - "
920 "last ep index = %d, state = %d\n",
921 ep_index, ep_state);
781 /* Clear our internal halted state and restart ring */ 922 /* Clear our internal halted state and restart ring */
782 xhci->devs[slot_id]->eps[ep_index].ep_state &= 923 xhci->devs[slot_id]->eps[ep_index].ep_state &=
783 ~EP_HALTED; 924 ~EP_HALTED;
784 ring_ep_doorbell(xhci, slot_id, ep_index); 925 ring_ep_doorbell(xhci, slot_id, ep_index);
785 } else { 926 break;
786 xhci->devs[slot_id]->cmd_status =
787 GET_COMP_CODE(event->status);
788 complete(&xhci->devs[slot_id]->cmd_completion);
789 } 927 }
928bandwidth_change:
929 xhci_dbg(xhci, "Completed config ep cmd\n");
930 xhci->devs[slot_id]->cmd_status =
931 GET_COMP_CODE(event->status);
932 complete(&xhci->devs[slot_id]->cmd_completion);
790 break; 933 break;
791 case TRB_TYPE(TRB_EVAL_CONTEXT): 934 case TRB_TYPE(TRB_EVAL_CONTEXT):
792 virt_dev = xhci->devs[slot_id]; 935 virt_dev = xhci->devs[slot_id];
@@ -811,6 +954,17 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
811 case TRB_TYPE(TRB_RESET_EP): 954 case TRB_TYPE(TRB_RESET_EP):
812 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue); 955 handle_reset_ep_completion(xhci, event, xhci->cmd_ring->dequeue);
813 break; 956 break;
957 case TRB_TYPE(TRB_RESET_DEV):
958 xhci_dbg(xhci, "Completed reset device command.\n");
959 slot_id = TRB_TO_SLOT_ID(
960 xhci->cmd_ring->dequeue->generic.field[3]);
961 virt_dev = xhci->devs[slot_id];
962 if (virt_dev)
963 handle_cmd_in_cmd_wait_list(xhci, virt_dev, event);
964 else
965 xhci_warn(xhci, "Reset device command completion "
966 "for disabled slot %u\n", slot_id);
967 break;
814 default: 968 default:
815 /* Skip over unknown commands on the event ring */ 969 /* Skip over unknown commands on the event ring */
816 xhci->error_bitmask |= 1 << 6; 970 xhci->error_bitmask |= 1 << 6;
@@ -849,8 +1003,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
849 * TRB in this TD, this function returns that TRB's segment. Otherwise it 1003 * TRB in this TD, this function returns that TRB's segment. Otherwise it
850 * returns 0. 1004 * returns 0.
851 */ 1005 */
852static struct xhci_segment *trb_in_td( 1006struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
853 struct xhci_segment *start_seg,
854 union xhci_trb *start_trb, 1007 union xhci_trb *start_trb,
855 union xhci_trb *end_trb, 1008 union xhci_trb *end_trb,
856 dma_addr_t suspect_dma) 1009 dma_addr_t suspect_dma)
@@ -900,6 +1053,59 @@ static struct xhci_segment *trb_in_td(
900 return 0; 1053 return 0;
901} 1054}
902 1055
1056static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci,
1057 unsigned int slot_id, unsigned int ep_index,
1058 struct xhci_td *td, union xhci_trb *event_trb)
1059{
1060 struct xhci_virt_ep *ep = &xhci->devs[slot_id]->eps[ep_index];
1061 ep->ep_state |= EP_HALTED;
1062 ep->stopped_td = td;
1063 ep->stopped_trb = event_trb;
1064 xhci_queue_reset_ep(xhci, slot_id, ep_index);
1065 xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index);
1066 xhci_ring_cmd_db(xhci);
1067}
1068
1069/* Check if an error has halted the endpoint ring. The class driver will
1070 * cleanup the halt for a non-default control endpoint if we indicate a stall.
1071 * However, a babble and other errors also halt the endpoint ring, and the class
1072 * driver won't clear the halt in that case, so we need to issue a Set Transfer
1073 * Ring Dequeue Pointer command manually.
1074 */
1075static int xhci_requires_manual_halt_cleanup(struct xhci_hcd *xhci,
1076 struct xhci_ep_ctx *ep_ctx,
1077 unsigned int trb_comp_code)
1078{
1079 /* TRB completion codes that may require a manual halt cleanup */
1080 if (trb_comp_code == COMP_TX_ERR ||
1081 trb_comp_code == COMP_BABBLE ||
1082 trb_comp_code == COMP_SPLIT_ERR)
1083 /* The 0.96 spec says a babbling control endpoint
1084 * is not halted. The 0.96 spec says it is. Some HW
1085 * claims to be 0.95 compliant, but it halts the control
1086 * endpoint anyway. Check if a babble halted the
1087 * endpoint.
1088 */
1089 if ((ep_ctx->ep_info & EP_STATE_MASK) == EP_STATE_HALTED)
1090 return 1;
1091
1092 return 0;
1093}
1094
1095int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code)
1096{
1097 if (trb_comp_code >= 224 && trb_comp_code <= 255) {
1098 /* Vendor defined "informational" completion code,
1099 * treat as not-an-error.
1100 */
1101 xhci_dbg(xhci, "Vendor defined info completion code %u\n",
1102 trb_comp_code);
1103 xhci_dbg(xhci, "Treating code as success.\n");
1104 return 1;
1105 }
1106 return 0;
1107}
1108
903/* 1109/*
904 * If this function returns an error condition, it means it got a Transfer 1110 * If this function returns an error condition, it means it got a Transfer
905 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address. 1111 * event with a corrupted Slot ID, Endpoint ID, or TRB DMA address.
@@ -1002,6 +1208,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1002 xhci_warn(xhci, "WARN: TRB error on endpoint\n"); 1208 xhci_warn(xhci, "WARN: TRB error on endpoint\n");
1003 status = -EILSEQ; 1209 status = -EILSEQ;
1004 break; 1210 break;
1211 case COMP_SPLIT_ERR:
1005 case COMP_TX_ERR: 1212 case COMP_TX_ERR:
1006 xhci_warn(xhci, "WARN: transfer error on endpoint\n"); 1213 xhci_warn(xhci, "WARN: transfer error on endpoint\n");
1007 status = -EPROTO; 1214 status = -EPROTO;
@@ -1015,6 +1222,10 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1015 status = -ENOSR; 1222 status = -ENOSR;
1016 break; 1223 break;
1017 default: 1224 default:
1225 if (xhci_is_vendor_info_code(xhci, trb_comp_code)) {
1226 status = 0;
1227 break;
1228 }
1018 xhci_warn(xhci, "ERROR Unknown event condition, HC probably busted\n"); 1229 xhci_warn(xhci, "ERROR Unknown event condition, HC probably busted\n");
1019 urb = NULL; 1230 urb = NULL;
1020 goto cleanup; 1231 goto cleanup;
@@ -1043,15 +1254,14 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1043 else 1254 else
1044 status = 0; 1255 status = 0;
1045 break; 1256 break;
1046 case COMP_BABBLE: 1257
1047 /* The 0.96 spec says a babbling control endpoint 1258 default:
1048 * is not halted. The 0.96 spec says it is. Some HW 1259 if (!xhci_requires_manual_halt_cleanup(xhci,
1049 * claims to be 0.95 compliant, but it halts the control 1260 ep_ctx, trb_comp_code))
1050 * endpoint anyway. Check if a babble halted the
1051 * endpoint.
1052 */
1053 if (ep_ctx->ep_info != EP_STATE_HALTED)
1054 break; 1261 break;
1262 xhci_dbg(xhci, "TRB error code %u, "
1263 "halted endpoint index = %u\n",
1264 trb_comp_code, ep_index);
1055 /* else fall through */ 1265 /* else fall through */
1056 case COMP_STALL: 1266 case COMP_STALL:
1057 /* Did we transfer part of the data (middle) phase? */ 1267 /* Did we transfer part of the data (middle) phase? */
@@ -1063,15 +1273,9 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1063 else 1273 else
1064 td->urb->actual_length = 0; 1274 td->urb->actual_length = 0;
1065 1275
1066 ep->stopped_td = td; 1276 xhci_cleanup_halted_endpoint(xhci,
1067 ep->stopped_trb = event_trb; 1277 slot_id, ep_index, td, event_trb);
1068 xhci_queue_reset_ep(xhci, slot_id, ep_index);
1069 xhci_cleanup_stalled_ring(xhci, td->urb->dev, ep_index);
1070 xhci_ring_cmd_db(xhci);
1071 goto td_cleanup; 1278 goto td_cleanup;
1072 default:
1073 /* Others already handled above */
1074 break;
1075 } 1279 }
1076 /* 1280 /*
1077 * Did we transfer any data, despite the errors that might have 1281 * Did we transfer any data, despite the errors that might have
@@ -1209,16 +1413,25 @@ static int handle_tx_event(struct xhci_hcd *xhci,
1209 ep->stopped_td = td; 1413 ep->stopped_td = td;
1210 ep->stopped_trb = event_trb; 1414 ep->stopped_trb = event_trb;
1211 } else { 1415 } else {
1212 if (trb_comp_code == COMP_STALL || 1416 if (trb_comp_code == COMP_STALL) {
1213 trb_comp_code == COMP_BABBLE) {
1214 /* The transfer is completed from the driver's 1417 /* The transfer is completed from the driver's
1215 * perspective, but we need to issue a set dequeue 1418 * perspective, but we need to issue a set dequeue
1216 * command for this stalled endpoint to move the dequeue 1419 * command for this stalled endpoint to move the dequeue
1217 * pointer past the TD. We can't do that here because 1420 * pointer past the TD. We can't do that here because
1218 * the halt condition must be cleared first. 1421 * the halt condition must be cleared first. Let the
1422 * USB class driver clear the stall later.
1219 */ 1423 */
1220 ep->stopped_td = td; 1424 ep->stopped_td = td;
1221 ep->stopped_trb = event_trb; 1425 ep->stopped_trb = event_trb;
1426 } else if (xhci_requires_manual_halt_cleanup(xhci,
1427 ep_ctx, trb_comp_code)) {
1428 /* Other types of errors halt the endpoint, but the
1429 * class driver doesn't call usb_reset_endpoint() unless
1430 * the error is -EPIPE. Clear the halted status in the
1431 * xHCI hardware manually.
1432 */
1433 xhci_cleanup_halted_endpoint(xhci,
1434 slot_id, ep_index, td, event_trb);
1222 } else { 1435 } else {
1223 /* Update ring dequeue pointer */ 1436 /* Update ring dequeue pointer */
1224 while (ep_ring->dequeue != td->last_trb) 1437 while (ep_ring->dequeue != td->last_trb)
@@ -1249,10 +1462,9 @@ td_cleanup:
1249 } 1462 }
1250 list_del(&td->td_list); 1463 list_del(&td->td_list);
1251 /* Was this TD slated to be cancelled but completed anyway? */ 1464 /* Was this TD slated to be cancelled but completed anyway? */
1252 if (!list_empty(&td->cancelled_td_list)) { 1465 if (!list_empty(&td->cancelled_td_list))
1253 list_del(&td->cancelled_td_list); 1466 list_del(&td->cancelled_td_list);
1254 ep->cancels_pending--; 1467
1255 }
1256 /* Leave the TD around for the reset endpoint function to use 1468 /* Leave the TD around for the reset endpoint function to use
1257 * (but only if it's not a control endpoint, since we already 1469 * (but only if it's not a control endpoint, since we already
1258 * queued the Set TR dequeue pointer command for stalled 1470 * queued the Set TR dequeue pointer command for stalled
@@ -1331,6 +1543,14 @@ void xhci_handle_event(struct xhci_hcd *xhci)
1331 default: 1543 default:
1332 xhci->error_bitmask |= 1 << 3; 1544 xhci->error_bitmask |= 1 << 3;
1333 } 1545 }
1546 /* Any of the above functions may drop and re-acquire the lock, so check
1547 * to make sure a watchdog timer didn't mark the host as non-responsive.
1548 */
1549 if (xhci->xhc_state & XHCI_STATE_DYING) {
1550 xhci_dbg(xhci, "xHCI host dying, returning from "
1551 "event handler.\n");
1552 return;
1553 }
1334 1554
1335 if (update_ptrs) { 1555 if (update_ptrs) {
1336 /* Update SW and HC event ring dequeue pointer */ 1556 /* Update SW and HC event ring dequeue pointer */
@@ -1555,6 +1775,21 @@ int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1555 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index); 1775 return xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, slot_id, ep_index);
1556} 1776}
1557 1777
1778/*
1779 * The TD size is the number of bytes remaining in the TD (including this TRB),
1780 * right shifted by 10.
1781 * It must fit in bits 21:17, so it can't be bigger than 31.
1782 */
1783static u32 xhci_td_remainder(unsigned int remainder)
1784{
1785 u32 max = (1 << (21 - 17 + 1)) - 1;
1786
1787 if ((remainder >> 10) >= max)
1788 return max << 17;
1789 else
1790 return (remainder >> 10) << 17;
1791}
1792
1558static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags, 1793static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1559 struct urb *urb, int slot_id, unsigned int ep_index) 1794 struct urb *urb, int slot_id, unsigned int ep_index)
1560{ 1795{
@@ -1612,6 +1847,7 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1612 do { 1847 do {
1613 u32 field = 0; 1848 u32 field = 0;
1614 u32 length_field = 0; 1849 u32 length_field = 0;
1850 u32 remainder = 0;
1615 1851
1616 /* Don't change the cycle bit of the first TRB until later */ 1852 /* Don't change the cycle bit of the first TRB until later */
1617 if (first_trb) 1853 if (first_trb)
@@ -1641,8 +1877,10 @@ static int queue_bulk_sg_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1641 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1), 1877 (unsigned int) (addr + TRB_MAX_BUFF_SIZE) & ~(TRB_MAX_BUFF_SIZE - 1),
1642 (unsigned int) addr + trb_buff_len); 1878 (unsigned int) addr + trb_buff_len);
1643 } 1879 }
1880 remainder = xhci_td_remainder(urb->transfer_buffer_length -
1881 running_total) ;
1644 length_field = TRB_LEN(trb_buff_len) | 1882 length_field = TRB_LEN(trb_buff_len) |
1645 TD_REMAINDER(urb->transfer_buffer_length - running_total) | 1883 remainder |
1646 TRB_INTR_TARGET(0); 1884 TRB_INTR_TARGET(0);
1647 queue_trb(xhci, ep_ring, false, 1885 queue_trb(xhci, ep_ring, false,
1648 lower_32_bits(addr), 1886 lower_32_bits(addr),
@@ -1755,6 +1993,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1755 1993
1756 /* Queue the first TRB, even if it's zero-length */ 1994 /* Queue the first TRB, even if it's zero-length */
1757 do { 1995 do {
1996 u32 remainder = 0;
1758 field = 0; 1997 field = 0;
1759 1998
1760 /* Don't change the cycle bit of the first TRB until later */ 1999 /* Don't change the cycle bit of the first TRB until later */
@@ -1773,8 +2012,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1773 td->last_trb = ep_ring->enqueue; 2012 td->last_trb = ep_ring->enqueue;
1774 field |= TRB_IOC; 2013 field |= TRB_IOC;
1775 } 2014 }
2015 remainder = xhci_td_remainder(urb->transfer_buffer_length -
2016 running_total);
1776 length_field = TRB_LEN(trb_buff_len) | 2017 length_field = TRB_LEN(trb_buff_len) |
1777 TD_REMAINDER(urb->transfer_buffer_length - running_total) | 2018 remainder |
1778 TRB_INTR_TARGET(0); 2019 TRB_INTR_TARGET(0);
1779 queue_trb(xhci, ep_ring, false, 2020 queue_trb(xhci, ep_ring, false,
1780 lower_32_bits(addr), 2021 lower_32_bits(addr),
@@ -1862,7 +2103,7 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
1862 /* If there's data, queue data TRBs */ 2103 /* If there's data, queue data TRBs */
1863 field = 0; 2104 field = 0;
1864 length_field = TRB_LEN(urb->transfer_buffer_length) | 2105 length_field = TRB_LEN(urb->transfer_buffer_length) |
1865 TD_REMAINDER(urb->transfer_buffer_length) | 2106 xhci_td_remainder(urb->transfer_buffer_length) |
1866 TRB_INTR_TARGET(0); 2107 TRB_INTR_TARGET(0);
1867 if (urb->transfer_buffer_length > 0) { 2108 if (urb->transfer_buffer_length > 0) {
1868 if (setup->bRequestType & USB_DIR_IN) 2109 if (setup->bRequestType & USB_DIR_IN)
@@ -1960,6 +2201,14 @@ int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1960 false); 2201 false);
1961} 2202}
1962 2203
2204/* Queue a reset device command TRB */
2205int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id)
2206{
2207 return queue_command(xhci, 0, 0, 0,
2208 TRB_TYPE(TRB_RESET_DEV) | SLOT_ID_FOR_TRB(slot_id),
2209 false);
2210}
2211
1963/* Queue a configure endpoint command TRB */ 2212/* Queue a configure endpoint command TRB */
1964int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 2213int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1965 u32 slot_id, bool command_must_succeed) 2214 u32 slot_id, bool command_must_succeed)
diff --git a/drivers/usb/host/xhci-hcd.c b/drivers/usb/host/xhci.c
index 932f99938481..7e4277273908 100644
--- a/drivers/usb/host/xhci-hcd.c
+++ b/drivers/usb/host/xhci.c
@@ -23,6 +23,7 @@
23#include <linux/irq.h> 23#include <linux/irq.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/slab.h>
26 27
27#include "xhci.h" 28#include "xhci.h"
28 29
@@ -67,22 +68,14 @@ static int handshake(struct xhci_hcd *xhci, void __iomem *ptr,
67} 68}
68 69
69/* 70/*
70 * Force HC into halt state. 71 * Disable interrupts and begin the xHCI halting process.
71 *
72 * Disable any IRQs and clear the run/stop bit.
73 * HC will complete any current and actively pipelined transactions, and
74 * should halt within 16 microframes of the run/stop bit being cleared.
75 * Read HC Halted bit in the status register to see when the HC is finished.
76 * XXX: shouldn't we set HC_STATE_HALT here somewhere?
77 */ 72 */
78int xhci_halt(struct xhci_hcd *xhci) 73void xhci_quiesce(struct xhci_hcd *xhci)
79{ 74{
80 u32 halted; 75 u32 halted;
81 u32 cmd; 76 u32 cmd;
82 u32 mask; 77 u32 mask;
83 78
84 xhci_dbg(xhci, "// Halt the HC\n");
85 /* Disable all interrupts from the host controller */
86 mask = ~(XHCI_IRQS); 79 mask = ~(XHCI_IRQS);
87 halted = xhci_readl(xhci, &xhci->op_regs->status) & STS_HALT; 80 halted = xhci_readl(xhci, &xhci->op_regs->status) & STS_HALT;
88 if (!halted) 81 if (!halted)
@@ -91,6 +84,21 @@ int xhci_halt(struct xhci_hcd *xhci)
91 cmd = xhci_readl(xhci, &xhci->op_regs->command); 84 cmd = xhci_readl(xhci, &xhci->op_regs->command);
92 cmd &= mask; 85 cmd &= mask;
93 xhci_writel(xhci, cmd, &xhci->op_regs->command); 86 xhci_writel(xhci, cmd, &xhci->op_regs->command);
87}
88
89/*
90 * Force HC into halt state.
91 *
92 * Disable any IRQs and clear the run/stop bit.
93 * HC will complete any current and actively pipelined transactions, and
94 * should halt within 16 microframes of the run/stop bit being cleared.
95 * Read HC Halted bit in the status register to see when the HC is finished.
96 * XXX: shouldn't we set HC_STATE_HALT here somewhere?
97 */
98int xhci_halt(struct xhci_hcd *xhci)
99{
100 xhci_dbg(xhci, "// Halt the HC\n");
101 xhci_quiesce(xhci);
94 102
95 return handshake(xhci, &xhci->op_regs->status, 103 return handshake(xhci, &xhci->op_regs->status,
96 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC); 104 STS_HALT, STS_HALT, XHCI_MAX_HALT_USEC);
@@ -124,28 +132,6 @@ int xhci_reset(struct xhci_hcd *xhci)
124 return handshake(xhci, &xhci->op_regs->command, CMD_RESET, 0, 250 * 1000); 132 return handshake(xhci, &xhci->op_regs->command, CMD_RESET, 0, 250 * 1000);
125} 133}
126 134
127/*
128 * Stop the HC from processing the endpoint queues.
129 */
130static void xhci_quiesce(struct xhci_hcd *xhci)
131{
132 /*
133 * Queues are per endpoint, so we need to disable an endpoint or slot.
134 *
135 * To disable a slot, we need to insert a disable slot command on the
136 * command ring and ring the doorbell. This will also free any internal
137 * resources associated with the slot (which might not be what we want).
138 *
139 * A Release Endpoint command sounds better - doesn't free internal HC
140 * memory, but removes the endpoints from the schedule and releases the
141 * bandwidth, disables the doorbells, and clears the endpoint enable
142 * flag. Usually used prior to a set interface command.
143 *
144 * TODO: Implement after command ring code is done.
145 */
146 BUG_ON(!HC_IS_RUNNING(xhci_to_hcd(xhci)->state));
147 xhci_dbg(xhci, "Finished quiescing -- code not written yet\n");
148}
149 135
150#if 0 136#if 0
151/* Set up MSI-X table for entry 0 (may claim other entries later) */ 137/* Set up MSI-X table for entry 0 (may claim other entries later) */
@@ -261,8 +247,14 @@ static void xhci_work(struct xhci_hcd *xhci)
261 /* Flush posted writes */ 247 /* Flush posted writes */
262 xhci_readl(xhci, &xhci->ir_set->irq_pending); 248 xhci_readl(xhci, &xhci->ir_set->irq_pending);
263 249
264 /* FIXME this should be a delayed service routine that clears the EHB */ 250 if (xhci->xhc_state & XHCI_STATE_DYING)
265 xhci_handle_event(xhci); 251 xhci_dbg(xhci, "xHCI dying, ignoring interrupt. "
252 "Shouldn't IRQs be disabled?\n");
253 else
254 /* FIXME this should be a delayed service routine
255 * that clears the EHB.
256 */
257 xhci_handle_event(xhci);
266 258
267 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */ 259 /* Clear the event handler busy flag (RW1C); the event ring should be empty. */
268 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue); 260 temp_64 = xhci_read_64(xhci, &xhci->ir_set->erst_dequeue);
@@ -335,7 +327,7 @@ void xhci_event_ring_work(unsigned long arg)
335 spin_lock_irqsave(&xhci->lock, flags); 327 spin_lock_irqsave(&xhci->lock, flags);
336 temp = xhci_readl(xhci, &xhci->op_regs->status); 328 temp = xhci_readl(xhci, &xhci->op_regs->status);
337 xhci_dbg(xhci, "op reg status = 0x%x\n", temp); 329 xhci_dbg(xhci, "op reg status = 0x%x\n", temp);
338 if (temp == 0xffffffff) { 330 if (temp == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) {
339 xhci_dbg(xhci, "HW died, polling stopped.\n"); 331 xhci_dbg(xhci, "HW died, polling stopped.\n");
340 spin_unlock_irqrestore(&xhci->lock, flags); 332 spin_unlock_irqrestore(&xhci->lock, flags);
341 return; 333 return;
@@ -490,8 +482,6 @@ void xhci_stop(struct usb_hcd *hcd)
490 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 482 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
491 483
492 spin_lock_irq(&xhci->lock); 484 spin_lock_irq(&xhci->lock);
493 if (HC_IS_RUNNING(hcd->state))
494 xhci_quiesce(xhci);
495 xhci_halt(xhci); 485 xhci_halt(xhci);
496 xhci_reset(xhci); 486 xhci_reset(xhci);
497 spin_unlock_irq(&xhci->lock); 487 spin_unlock_irq(&xhci->lock);
@@ -727,16 +717,22 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
727 * atomic context to this function, which may allocate memory. 717 * atomic context to this function, which may allocate memory.
728 */ 718 */
729 spin_lock_irqsave(&xhci->lock, flags); 719 spin_lock_irqsave(&xhci->lock, flags);
720 if (xhci->xhc_state & XHCI_STATE_DYING)
721 goto dying;
730 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb, 722 ret = xhci_queue_ctrl_tx(xhci, GFP_ATOMIC, urb,
731 slot_id, ep_index); 723 slot_id, ep_index);
732 spin_unlock_irqrestore(&xhci->lock, flags); 724 spin_unlock_irqrestore(&xhci->lock, flags);
733 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) { 725 } else if (usb_endpoint_xfer_bulk(&urb->ep->desc)) {
734 spin_lock_irqsave(&xhci->lock, flags); 726 spin_lock_irqsave(&xhci->lock, flags);
727 if (xhci->xhc_state & XHCI_STATE_DYING)
728 goto dying;
735 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb, 729 ret = xhci_queue_bulk_tx(xhci, GFP_ATOMIC, urb,
736 slot_id, ep_index); 730 slot_id, ep_index);
737 spin_unlock_irqrestore(&xhci->lock, flags); 731 spin_unlock_irqrestore(&xhci->lock, flags);
738 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) { 732 } else if (usb_endpoint_xfer_int(&urb->ep->desc)) {
739 spin_lock_irqsave(&xhci->lock, flags); 733 spin_lock_irqsave(&xhci->lock, flags);
734 if (xhci->xhc_state & XHCI_STATE_DYING)
735 goto dying;
740 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb, 736 ret = xhci_queue_intr_tx(xhci, GFP_ATOMIC, urb,
741 slot_id, ep_index); 737 slot_id, ep_index);
742 spin_unlock_irqrestore(&xhci->lock, flags); 738 spin_unlock_irqrestore(&xhci->lock, flags);
@@ -745,6 +741,12 @@ int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
745 } 741 }
746exit: 742exit:
747 return ret; 743 return ret;
744dying:
745 xhci_dbg(xhci, "Ep 0x%x: URB %p submitted for "
746 "non-responsive xHCI host.\n",
747 urb->ep->desc.bEndpointAddress, urb);
748 spin_unlock_irqrestore(&xhci->lock, flags);
749 return -ESHUTDOWN;
748} 750}
749 751
750/* 752/*
@@ -806,6 +808,17 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
806 kfree(td); 808 kfree(td);
807 return ret; 809 return ret;
808 } 810 }
811 if (xhci->xhc_state & XHCI_STATE_DYING) {
812 xhci_dbg(xhci, "Ep 0x%x: URB %p to be canceled on "
813 "non-responsive xHCI host.\n",
814 urb->ep->desc.bEndpointAddress, urb);
815 /* Let the stop endpoint command watchdog timer (which set this
816 * state) finish cleaning up the endpoint TD lists. We must
817 * have caught it in the middle of dropping a lock and giving
818 * back an URB.
819 */
820 goto done;
821 }
809 822
810 xhci_dbg(xhci, "Cancel URB %p\n", urb); 823 xhci_dbg(xhci, "Cancel URB %p\n", urb);
811 xhci_dbg(xhci, "Event ring:\n"); 824 xhci_dbg(xhci, "Event ring:\n");
@@ -817,12 +830,16 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
817 xhci_debug_ring(xhci, ep_ring); 830 xhci_debug_ring(xhci, ep_ring);
818 td = (struct xhci_td *) urb->hcpriv; 831 td = (struct xhci_td *) urb->hcpriv;
819 832
820 ep->cancels_pending++;
821 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 833 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list);
822 /* Queue a stop endpoint command, but only if this is 834 /* Queue a stop endpoint command, but only if this is
823 * the first cancellation to be handled. 835 * the first cancellation to be handled.
824 */ 836 */
825 if (ep->cancels_pending == 1) { 837 if (!(ep->ep_state & EP_HALT_PENDING)) {
838 ep->ep_state |= EP_HALT_PENDING;
839 ep->stop_cmds_pending++;
840 ep->stop_cmd_timer.expires = jiffies +
841 XHCI_STOP_EP_CMD_TIMEOUT * HZ;
842 add_timer(&ep->stop_cmd_timer);
826 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index); 843 xhci_queue_stop_endpoint(xhci, urb->dev->slot_id, ep_index);
827 xhci_ring_cmd_db(xhci); 844 xhci_ring_cmd_db(xhci);
828 } 845 }
@@ -991,7 +1008,7 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
991 * for usb_set_interface() and usb_set_configuration() claim). 1008 * for usb_set_interface() and usb_set_configuration() claim).
992 */ 1009 */
993 if (xhci_endpoint_init(xhci, xhci->devs[udev->slot_id], 1010 if (xhci_endpoint_init(xhci, xhci->devs[udev->slot_id],
994 udev, ep, GFP_KERNEL) < 0) { 1011 udev, ep, GFP_NOIO) < 0) {
995 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n", 1012 dev_dbg(&udev->dev, "%s - could not initialize ep %#x\n",
996 __func__, ep->desc.bEndpointAddress); 1013 __func__, ep->desc.bEndpointAddress);
997 return -ENOMEM; 1014 return -ENOMEM;
@@ -1157,6 +1174,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1157 cmd_completion = &virt_dev->cmd_completion; 1174 cmd_completion = &virt_dev->cmd_completion;
1158 cmd_status = &virt_dev->cmd_status; 1175 cmd_status = &virt_dev->cmd_status;
1159 } 1176 }
1177 init_completion(cmd_completion);
1160 1178
1161 if (!ctx_change) 1179 if (!ctx_change)
1162 ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma, 1180 ret = xhci_queue_configure_endpoint(xhci, in_ctx->dma,
@@ -1165,6 +1183,8 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
1165 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, 1183 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma,
1166 udev->slot_id); 1184 udev->slot_id);
1167 if (ret < 0) { 1185 if (ret < 0) {
1186 if (command)
1187 list_del(&command->cmd_list);
1168 spin_unlock_irqrestore(&xhci->lock, flags); 1188 spin_unlock_irqrestore(&xhci->lock, flags);
1169 xhci_dbg(xhci, "FIXME allocate a new ring segment\n"); 1189 xhci_dbg(xhci, "FIXME allocate a new ring segment\n");
1170 return -ENOMEM; 1190 return -ENOMEM;
@@ -1246,13 +1266,18 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1246 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info)); 1266 LAST_CTX_TO_EP_NUM(slot_ctx->dev_info));
1247 1267
1248 xhci_zero_in_ctx(xhci, virt_dev); 1268 xhci_zero_in_ctx(xhci, virt_dev);
1249 /* Free any old rings */ 1269 /* Install new rings and free or cache any old rings */
1250 for (i = 1; i < 31; ++i) { 1270 for (i = 1; i < 31; ++i) {
1251 if (virt_dev->eps[i].new_ring) { 1271 if (!virt_dev->eps[i].new_ring)
1252 xhci_ring_free(xhci, virt_dev->eps[i].ring); 1272 continue;
1253 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring; 1273 /* Only cache or free the old ring if it exists.
1254 virt_dev->eps[i].new_ring = NULL; 1274 * It may not if this is the first add of an endpoint.
1275 */
1276 if (virt_dev->eps[i].ring) {
1277 xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
1255 } 1278 }
1279 virt_dev->eps[i].ring = virt_dev->eps[i].new_ring;
1280 virt_dev->eps[i].new_ring = NULL;
1256 } 1281 }
1257 1282
1258 return ret; 1283 return ret;
@@ -1420,6 +1445,131 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1420} 1445}
1421 1446
1422/* 1447/*
1448 * 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
1450 * control endpoint. The USB core should come back and call
1451 * xhci_address_device(), and then re-set up the configuration. If this is
1452 * called because of a usb_reset_and_verify_device(), then the old alternate
1453 * settings will be re-installed through the normal bandwidth allocation
1454 * functions.
1455 *
1456 * Wait for the Reset Device command to finish. Remove all structures
1457 * associated with the endpoints that were disabled. Clear the input device
1458 * structure? Cache the rings? Reset the control endpoint 0 max packet size?
1459 */
1460int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev)
1461{
1462 int ret, i;
1463 unsigned long flags;
1464 struct xhci_hcd *xhci;
1465 unsigned int slot_id;
1466 struct xhci_virt_device *virt_dev;
1467 struct xhci_command *reset_device_cmd;
1468 int timeleft;
1469 int last_freed_endpoint;
1470
1471 ret = xhci_check_args(hcd, udev, NULL, 0, __func__);
1472 if (ret <= 0)
1473 return ret;
1474 xhci = hcd_to_xhci(hcd);
1475 slot_id = udev->slot_id;
1476 virt_dev = xhci->devs[slot_id];
1477 if (!virt_dev) {
1478 xhci_dbg(xhci, "%s called with invalid slot ID %u\n",
1479 __func__, slot_id);
1480 return -EINVAL;
1481 }
1482
1483 xhci_dbg(xhci, "Resetting device with slot ID %u\n", slot_id);
1484 /* Allocate the command structure that holds the struct completion.
1485 * Assume we're in process context, since the normal device reset
1486 * process has to wait for the device anyway. Storage devices are
1487 * reset as part of error handling, so use GFP_NOIO instead of
1488 * GFP_KERNEL.
1489 */
1490 reset_device_cmd = xhci_alloc_command(xhci, false, true, GFP_NOIO);
1491 if (!reset_device_cmd) {
1492 xhci_dbg(xhci, "Couldn't allocate command structure.\n");
1493 return -ENOMEM;
1494 }
1495
1496 /* Attempt to submit the Reset Device command to the command ring */
1497 spin_lock_irqsave(&xhci->lock, flags);
1498 reset_device_cmd->command_trb = xhci->cmd_ring->enqueue;
1499 list_add_tail(&reset_device_cmd->cmd_list, &virt_dev->cmd_list);
1500 ret = xhci_queue_reset_device(xhci, slot_id);
1501 if (ret) {
1502 xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
1503 list_del(&reset_device_cmd->cmd_list);
1504 spin_unlock_irqrestore(&xhci->lock, flags);
1505 goto command_cleanup;
1506 }
1507 xhci_ring_cmd_db(xhci);
1508 spin_unlock_irqrestore(&xhci->lock, flags);
1509
1510 /* Wait for the Reset Device command to finish */
1511 timeleft = wait_for_completion_interruptible_timeout(
1512 reset_device_cmd->completion,
1513 USB_CTRL_SET_TIMEOUT);
1514 if (timeleft <= 0) {
1515 xhci_warn(xhci, "%s while waiting for reset device command\n",
1516 timeleft == 0 ? "Timeout" : "Signal");
1517 spin_lock_irqsave(&xhci->lock, flags);
1518 /* The timeout might have raced with the event ring handler, so
1519 * only delete from the list if the item isn't poisoned.
1520 */
1521 if (reset_device_cmd->cmd_list.next != LIST_POISON1)
1522 list_del(&reset_device_cmd->cmd_list);
1523 spin_unlock_irqrestore(&xhci->lock, flags);
1524 ret = -ETIME;
1525 goto command_cleanup;
1526 }
1527
1528 /* The Reset Device command can't fail, according to the 0.95/0.96 spec,
1529 * unless we tried to reset a slot ID that wasn't enabled,
1530 * or the device wasn't in the addressed or configured state.
1531 */
1532 ret = reset_device_cmd->status;
1533 switch (ret) {
1534 case COMP_EBADSLT: /* 0.95 completion code for bad slot ID */
1535 case COMP_CTX_STATE: /* 0.96 completion code for same thing */
1536 xhci_info(xhci, "Can't reset device (slot ID %u) in %s state\n",
1537 slot_id,
1538 xhci_get_slot_state(xhci, virt_dev->out_ctx));
1539 xhci_info(xhci, "Not freeing device rings.\n");
1540 /* Don't treat this as an error. May change my mind later. */
1541 ret = 0;
1542 goto command_cleanup;
1543 case COMP_SUCCESS:
1544 xhci_dbg(xhci, "Successful reset device command.\n");
1545 break;
1546 default:
1547 if (xhci_is_vendor_info_code(xhci, ret))
1548 break;
1549 xhci_warn(xhci, "Unknown completion code %u for "
1550 "reset device command.\n", ret);
1551 ret = -EINVAL;
1552 goto command_cleanup;
1553 }
1554
1555 /* Everything but endpoint 0 is disabled, so free or cache the rings. */
1556 last_freed_endpoint = 1;
1557 for (i = 1; i < 31; ++i) {
1558 if (!virt_dev->eps[i].ring)
1559 continue;
1560 xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i);
1561 last_freed_endpoint = i;
1562 }
1563 xhci_dbg(xhci, "Output context after successful reset device cmd:\n");
1564 xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint);
1565 ret = 0;
1566
1567command_cleanup:
1568 xhci_free_command(xhci, reset_device_cmd);
1569 return ret;
1570}
1571
1572/*
1423 * At this point, the struct usb_device is about to go away, the device has 1573 * At this point, the struct usb_device is about to go away, the device has
1424 * disconnected, and all traffic has been stopped and the endpoints have been 1574 * disconnected, and all traffic has been stopped and the endpoints have been
1425 * disabled. Free any HC data structures associated with that device. 1575 * disabled. Free any HC data structures associated with that device.
@@ -1427,16 +1577,27 @@ void xhci_endpoint_reset(struct usb_hcd *hcd,
1427void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev) 1577void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
1428{ 1578{
1429 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1579 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1580 struct xhci_virt_device *virt_dev;
1430 unsigned long flags; 1581 unsigned long flags;
1431 u32 state; 1582 u32 state;
1583 int i;
1432 1584
1433 if (udev->slot_id == 0) 1585 if (udev->slot_id == 0)
1434 return; 1586 return;
1587 virt_dev = xhci->devs[udev->slot_id];
1588 if (!virt_dev)
1589 return;
1590
1591 /* Stop any wayward timer functions (which may grab the lock) */
1592 for (i = 0; i < 31; ++i) {
1593 virt_dev->eps[i].ep_state &= ~EP_HALT_PENDING;
1594 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
1595 }
1435 1596
1436 spin_lock_irqsave(&xhci->lock, flags); 1597 spin_lock_irqsave(&xhci->lock, flags);
1437 /* Don't disable the slot if the host controller is dead. */ 1598 /* Don't disable the slot if the host controller is dead. */
1438 state = xhci_readl(xhci, &xhci->op_regs->status); 1599 state = xhci_readl(xhci, &xhci->op_regs->status);
1439 if (state == 0xffffffff) { 1600 if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING)) {
1440 xhci_free_virt_device(xhci, udev->slot_id); 1601 xhci_free_virt_device(xhci, udev->slot_id);
1441 spin_unlock_irqrestore(&xhci->lock, flags); 1602 spin_unlock_irqrestore(&xhci->lock, flags);
1442 return; 1603 return;
@@ -1645,7 +1806,7 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1645 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n"); 1806 xhci_warn(xhci, "Cannot update hub desc for unknown device.\n");
1646 return -EINVAL; 1807 return -EINVAL;
1647 } 1808 }
1648 config_cmd = xhci_alloc_command(xhci, true, mem_flags); 1809 config_cmd = xhci_alloc_command(xhci, true, true, mem_flags);
1649 if (!config_cmd) { 1810 if (!config_cmd) {
1650 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n"); 1811 xhci_dbg(xhci, "Could not allocate xHCI command structure.\n");
1651 return -ENOMEM; 1812 return -ENOMEM;
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 4b254b6fa245..ea389e9a4931 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -609,6 +609,10 @@ struct xhci_ep_ctx {
609#define MAX_PACKET_MASK (0xffff << 16) 609#define MAX_PACKET_MASK (0xffff << 16)
610#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff) 610#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
611 611
612/* tx_info bitmasks */
613#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
614#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
615
612 616
613/** 617/**
614 * struct xhci_input_control_context 618 * struct xhci_input_control_context
@@ -652,13 +656,17 @@ struct xhci_virt_ep {
652 struct xhci_ring *new_ring; 656 struct xhci_ring *new_ring;
653 unsigned int ep_state; 657 unsigned int ep_state;
654#define SET_DEQ_PENDING (1 << 0) 658#define SET_DEQ_PENDING (1 << 0)
655#define EP_HALTED (1 << 1) 659#define EP_HALTED (1 << 1) /* For stall handling */
660#define EP_HALT_PENDING (1 << 2) /* For URB cancellation */
656 /* ---- Related to URB cancellation ---- */ 661 /* ---- Related to URB cancellation ---- */
657 struct list_head cancelled_td_list; 662 struct list_head cancelled_td_list;
658 unsigned int cancels_pending;
659 /* The TRB that was last reported in a stopped endpoint ring */ 663 /* The TRB that was last reported in a stopped endpoint ring */
660 union xhci_trb *stopped_trb; 664 union xhci_trb *stopped_trb;
661 struct xhci_td *stopped_td; 665 struct xhci_td *stopped_td;
666 /* Watchdog timer for stop endpoint command to cancel URBs */
667 struct timer_list stop_cmd_timer;
668 int stop_cmds_pending;
669 struct xhci_hcd *xhci;
662}; 670};
663 671
664struct xhci_virt_device { 672struct xhci_virt_device {
@@ -673,6 +681,10 @@ struct xhci_virt_device {
673 struct xhci_container_ctx *out_ctx; 681 struct xhci_container_ctx *out_ctx;
674 /* Used for addressing devices and configuration changes */ 682 /* Used for addressing devices and configuration changes */
675 struct xhci_container_ctx *in_ctx; 683 struct xhci_container_ctx *in_ctx;
684 /* Rings saved to ensure old alt settings can be re-instated */
685 struct xhci_ring **ring_cache;
686 int num_rings_cached;
687#define XHCI_MAX_RINGS_CACHED 31
676 struct xhci_virt_ep eps[31]; 688 struct xhci_virt_ep eps[31];
677 struct completion cmd_completion; 689 struct completion cmd_completion;
678 /* Status of the last command issued for this device */ 690 /* Status of the last command issued for this device */
@@ -824,9 +836,6 @@ struct xhci_event_cmd {
824/* Normal TRB fields */ 836/* Normal TRB fields */
825/* transfer_len bitmasks - bits 0:16 */ 837/* transfer_len bitmasks - bits 0:16 */
826#define TRB_LEN(p) ((p) & 0x1ffff) 838#define TRB_LEN(p) ((p) & 0x1ffff)
827/* TD size - number of bytes remaining in the TD (including this TRB):
828 * bits 17 - 21. Shift the number of bytes by 10. */
829#define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
830/* Interrupter Target - which MSI-X vector to target the completion event at */ 839/* Interrupter Target - which MSI-X vector to target the completion event at */
831#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22) 840#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
832#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff) 841#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
@@ -1022,6 +1031,8 @@ struct xhci_scratchpad {
1022#define ERST_ENTRIES 1 1031#define ERST_ENTRIES 1
1023/* Poll every 60 seconds */ 1032/* Poll every 60 seconds */
1024#define POLL_TIMEOUT 60 1033#define POLL_TIMEOUT 60
1034/* Stop endpoint command timeout (secs) for URB cancellation watchdog timer */
1035#define XHCI_STOP_EP_CMD_TIMEOUT 5
1025/* XXX: Make these module parameters */ 1036/* XXX: Make these module parameters */
1026 1037
1027 1038
@@ -1083,6 +1094,21 @@ struct xhci_hcd {
1083 struct timer_list event_ring_timer; 1094 struct timer_list event_ring_timer;
1084 int zombie; 1095 int zombie;
1085#endif 1096#endif
1097 /* Host controller watchdog timer structures */
1098 unsigned int xhc_state;
1099/* Host controller is dying - not responding to commands. "I'm not dead yet!"
1100 *
1101 * xHC interrupts have been disabled and a watchdog timer will (or has already)
1102 * halt the xHCI host, and complete all URBs with an -ESHUTDOWN code. Any code
1103 * that sees this status (other than the timer that set it) should stop touching
1104 * hardware immediately. Interrupt handlers should return immediately when
1105 * they see this status (any time they drop and re-acquire xhci->lock).
1106 * xhci_urb_dequeue() should call usb_hcd_check_unlink_urb() and return without
1107 * putting the TD on the canceled list, etc.
1108 *
1109 * There are no reports of xHCI host controllers that display this issue.
1110 */
1111#define XHCI_STATE_DYING (1 << 0)
1086 /* Statistics */ 1112 /* Statistics */
1087 int noops_submitted; 1113 int noops_submitted;
1088 int noops_handled; 1114 int noops_handled;
@@ -1188,6 +1214,8 @@ void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
1188void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci); 1214void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
1189void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring); 1215void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
1190void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep); 1216void 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,
1218 struct xhci_container_ctx *ctx);
1191 1219
1192/* xHCI memory management */ 1220/* xHCI memory management */
1193void xhci_mem_cleanup(struct xhci_hcd *xhci); 1221void xhci_mem_cleanup(struct xhci_hcd *xhci);
@@ -1211,8 +1239,12 @@ int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
1211 struct usb_device *udev, struct usb_host_endpoint *ep, 1239 struct usb_device *udev, struct usb_host_endpoint *ep,
1212 gfp_t mem_flags); 1240 gfp_t mem_flags);
1213void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring); 1241void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
1242void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
1243 struct xhci_virt_device *virt_dev,
1244 unsigned int ep_index);
1214struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci, 1245struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1215 bool allocate_completion, gfp_t mem_flags); 1246 bool allocate_in_ctx, bool allocate_completion,
1247 gfp_t mem_flags);
1216void xhci_free_command(struct xhci_hcd *xhci, 1248void xhci_free_command(struct xhci_hcd *xhci,
1217 struct xhci_command *command); 1249 struct xhci_command *command);
1218 1250
@@ -1223,6 +1255,7 @@ void xhci_unregister_pci(void);
1223#endif 1255#endif
1224 1256
1225/* xHCI host controller glue */ 1257/* xHCI host controller glue */
1258void xhci_quiesce(struct xhci_hcd *xhci);
1226int xhci_halt(struct xhci_hcd *xhci); 1259int xhci_halt(struct xhci_hcd *xhci);
1227int xhci_reset(struct xhci_hcd *xhci); 1260int xhci_reset(struct xhci_hcd *xhci);
1228int xhci_init(struct usb_hcd *hcd); 1261int xhci_init(struct usb_hcd *hcd);
@@ -1241,11 +1274,16 @@ int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1241int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); 1274int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1242int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep); 1275int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1243void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep); 1276void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
1277int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev);
1244int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1278int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1245void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev); 1279void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1246 1280
1247/* xHCI ring, segment, TRB, and TD functions */ 1281/* xHCI ring, segment, TRB, and TD functions */
1248dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb); 1282dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
1283struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1284 union xhci_trb *start_trb, union xhci_trb *end_trb,
1285 dma_addr_t suspect_dma);
1286int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1249void xhci_ring_cmd_db(struct xhci_hcd *xhci); 1287void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1250void *xhci_setup_one_noop(struct xhci_hcd *xhci); 1288void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1251void xhci_handle_event(struct xhci_hcd *xhci); 1289void xhci_handle_event(struct xhci_hcd *xhci);
@@ -1267,6 +1305,7 @@ int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1267 u32 slot_id); 1305 u32 slot_id);
1268int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 1306int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1269 unsigned int ep_index); 1307 unsigned int ep_index);
1308int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
1270void xhci_find_new_dequeue_state(struct xhci_hcd *xhci, 1309void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
1271 unsigned int slot_id, unsigned int ep_index, 1310 unsigned int slot_id, unsigned int ep_index,
1272 struct xhci_td *cur_td, struct xhci_dequeue_state *state); 1311 struct xhci_td *cur_td, struct xhci_dequeue_state *state);
@@ -1278,6 +1317,7 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1278void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci, 1317void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1279 unsigned int slot_id, unsigned int ep_index, 1318 unsigned int slot_id, unsigned int ep_index,
1280 struct xhci_dequeue_state *deq_state); 1319 struct xhci_dequeue_state *deq_state);
1320void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1281 1321
1282/* xHCI roothub code */ 1322/* xHCI roothub code */
1283int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1323int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index eca355dccf65..e192e8f7c560 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -967,7 +967,7 @@ static const struct file_operations mdc800_device_ops =
967 967
968 968
969 969
970static struct usb_device_id mdc800_table [] = { 970static const struct usb_device_id mdc800_table[] = {
971 { USB_DEVICE(MDC800_VENDOR_ID, MDC800_PRODUCT_ID) }, 971 { USB_DEVICE(MDC800_VENDOR_ID, MDC800_PRODUCT_ID) },
972 { } /* Terminating entry */ 972 { } /* Terminating entry */
973}; 973};
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 459a7287fe01..3a6bcd5fee09 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -155,7 +155,7 @@ static int mts_usb_probe(struct usb_interface *intf,
155 const struct usb_device_id *id); 155 const struct usb_device_id *id);
156static void mts_usb_disconnect(struct usb_interface *intf); 156static void mts_usb_disconnect(struct usb_interface *intf);
157 157
158static struct usb_device_id mts_usb_ids []; 158static const struct usb_device_id mts_usb_ids[];
159 159
160static struct usb_driver mts_usb_driver = { 160static struct usb_driver mts_usb_driver = {
161 .name = "microtekX6", 161 .name = "microtekX6",
@@ -656,7 +656,7 @@ static struct scsi_host_template mts_scsi_host_template = {
656/* The entries of microtek_table must correspond, line-by-line to 656/* The entries of microtek_table must correspond, line-by-line to
657 the entries of mts_supported_products[]. */ 657 the entries of mts_supported_products[]. */
658 658
659static struct usb_device_id mts_usb_ids [] = 659static const struct usb_device_id mts_usb_ids[] =
660{ 660{
661 { USB_DEVICE(0x4ce, 0x0300) }, 661 { USB_DEVICE(0x4ce, 0x0300) },
662 { USB_DEVICE(0x5da, 0x0094) }, 662 { USB_DEVICE(0x5da, 0x0094) },
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index abe3aa67ed00..55660eaf947c 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -87,17 +87,6 @@ config USB_LCD
87 To compile this driver as a module, choose M here: the 87 To compile this driver as a module, choose M here: the
88 module will be called usblcd. 88 module will be called usblcd.
89 89
90config USB_BERRY_CHARGE
91 tristate "USB BlackBerry recharge support"
92 depends on USB
93 help
94 Say Y here if you want to connect a BlackBerry device to your
95 computer's USB port and have it automatically switch to "recharge"
96 mode.
97
98 To compile this driver as a module, choose M here: the
99 module will be called berry_charge.
100
101config USB_LED 90config USB_LED
102 tristate "USB LED driver support" 91 tristate "USB LED driver support"
103 depends on USB 92 depends on USB
@@ -242,17 +231,3 @@ config USB_ISIGHTFW
242 driver beforehand. Tools for doing so are available at 231 driver beforehand. Tools for doing so are available at
243 http://bersace03.free.fr 232 http://bersace03.free.fr
244 233
245config USB_VST
246 tristate "USB VST driver"
247 depends on USB
248 help
249 This driver is intended for Vernier Software Technologies
250 bulk usb devices such as their Ocean-Optics spectrometers or
251 Labquest.
252 It is a bulk channel driver with configurable read and write
253 timeouts.
254
255 To compile this driver as a module, choose M here: the
256 module will be called vstusb.
257
258
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 0826aab8303f..717703e81425 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -5,7 +5,6 @@
5 5
6obj-$(CONFIG_USB_ADUTUX) += adutux.o 6obj-$(CONFIG_USB_ADUTUX) += adutux.o
7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o 7obj-$(CONFIG_USB_APPLEDISPLAY) += appledisplay.o
8obj-$(CONFIG_USB_BERRY_CHARGE) += berry_charge.o
9obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o 8obj-$(CONFIG_USB_CYPRESS_CY7C63)+= cypress_cy7c63.o
10obj-$(CONFIG_USB_CYTHERM) += cytherm.o 9obj-$(CONFIG_USB_CYTHERM) += cytherm.o
11obj-$(CONFIG_USB_EMI26) += emi26.o 10obj-$(CONFIG_USB_EMI26) += emi26.o
@@ -23,7 +22,6 @@ obj-$(CONFIG_USB_TEST) += usbtest.o
23obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o 22obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
24obj-$(CONFIG_USB_USS720) += uss720.o 23obj-$(CONFIG_USB_USS720) += uss720.o
25obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o 24obj-$(CONFIG_USB_SEVSEG) += usbsevseg.o
26obj-$(CONFIG_USB_VST) += vstusb.o
27 25
28obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/ 26obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
29 27
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index 203526542013..d240de097c62 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -38,7 +38,7 @@ static int debug = 1;
38#define dbg(lvl, format, arg...) \ 38#define dbg(lvl, format, arg...) \
39do { \ 39do { \
40 if (debug >= lvl) \ 40 if (debug >= lvl) \
41 printk(KERN_DEBUG __FILE__ " : " format " \n", ## arg); \ 41 printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
42} while (0) 42} while (0)
43 43
44 44
@@ -56,7 +56,7 @@ MODULE_PARM_DESC(debug, "Debug enabled or not");
56#define ADU_PRODUCT_ID 0x0064 56#define ADU_PRODUCT_ID 0x0064
57 57
58/* table of devices that work with this driver */ 58/* table of devices that work with this driver */
59static struct usb_device_id device_table [] = { 59static const struct usb_device_id device_table[] = {
60 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID) }, /* ADU100 */ 60 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID) }, /* ADU100 */
61 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+20) }, /* ADU120 */ 61 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+20) }, /* ADU120 */
62 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+30) }, /* ADU130 */ 62 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+30) }, /* ADU130 */
@@ -132,8 +132,8 @@ static void adu_debug_data(int level, const char *function, int size,
132 if (debug < level) 132 if (debug < level)
133 return; 133 return;
134 134
135 printk(KERN_DEBUG __FILE__": %s - length = %d, data = ", 135 printk(KERN_DEBUG "%s: %s - length = %d, data = ",
136 function, size); 136 __FILE__, function, size);
137 for (i = 0; i < size; ++i) 137 for (i = 0; i < size; ++i)
138 printk("%.2x ", data[i]); 138 printk("%.2x ", data[i]);
139 printk("\n"); 139 printk("\n");
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 1d8e39a557d9..094f91cbc578 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -24,6 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/slab.h>
27#include <linux/usb.h> 28#include <linux/usb.h>
28#include <linux/backlight.h> 29#include <linux/backlight.h>
29#include <linux/timer.h> 30#include <linux/timer.h>
@@ -57,9 +58,10 @@
57 .bInterfaceProtocol = 0x00 58 .bInterfaceProtocol = 0x00
58 59
59/* table of devices that work with this driver */ 60/* table of devices that work with this driver */
60static struct usb_device_id appledisplay_table [] = { 61static const struct usb_device_id appledisplay_table[] = {
61 { APPLEDISPLAY_DEVICE(0x9218) }, 62 { APPLEDISPLAY_DEVICE(0x9218) },
62 { APPLEDISPLAY_DEVICE(0x9219) }, 63 { APPLEDISPLAY_DEVICE(0x9219) },
64 { APPLEDISPLAY_DEVICE(0x921c) },
63 { APPLEDISPLAY_DEVICE(0x921d) }, 65 { APPLEDISPLAY_DEVICE(0x921d) },
64 66
65 /* Terminating entry */ 67 /* Terminating entry */
@@ -72,8 +74,8 @@ struct appledisplay {
72 struct usb_device *udev; /* usb device */ 74 struct usb_device *udev; /* usb device */
73 struct urb *urb; /* usb request block */ 75 struct urb *urb; /* usb request block */
74 struct backlight_device *bd; /* backlight device */ 76 struct backlight_device *bd; /* backlight device */
75 char *urbdata; /* interrupt URB data buffer */ 77 u8 *urbdata; /* interrupt URB data buffer */
76 char *msgdata; /* control message data buffer */ 78 u8 *msgdata; /* control message data buffer */
77 79
78 struct delayed_work work; 80 struct delayed_work work;
79 int button_pressed; 81 int button_pressed;
@@ -178,7 +180,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
178 return pdata->msgdata[1]; 180 return pdata->msgdata[1];
179} 181}
180 182
181static struct backlight_ops appledisplay_bl_data = { 183static const struct backlight_ops appledisplay_bl_data = {
182 .get_brightness = appledisplay_bl_get_brightness, 184 .get_brightness = appledisplay_bl_get_brightness,
183 .update_status = appledisplay_bl_update_status, 185 .update_status = appledisplay_bl_update_status,
184}; 186};
@@ -201,6 +203,7 @@ static void appledisplay_work(struct work_struct *work)
201static int appledisplay_probe(struct usb_interface *iface, 203static int appledisplay_probe(struct usb_interface *iface,
202 const struct usb_device_id *id) 204 const struct usb_device_id *id)
203{ 205{
206 struct backlight_properties props;
204 struct appledisplay *pdata; 207 struct appledisplay *pdata;
205 struct usb_device *udev = interface_to_usbdev(iface); 208 struct usb_device *udev = interface_to_usbdev(iface);
206 struct usb_host_interface *iface_desc; 209 struct usb_host_interface *iface_desc;
@@ -278,15 +281,16 @@ static int appledisplay_probe(struct usb_interface *iface,
278 /* Register backlight device */ 281 /* Register backlight device */
279 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
280 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 memset(&props, 0, sizeof(struct backlight_properties));
285 props.max_brightness = 0xff;
281 pdata->bd = backlight_device_register(bl_name, NULL, pdata, 286 pdata->bd = backlight_device_register(bl_name, NULL, pdata,
282 &appledisplay_bl_data); 287 &appledisplay_bl_data, &props);
283 if (IS_ERR(pdata->bd)) { 288 if (IS_ERR(pdata->bd)) {
284 dev_err(&iface->dev, "Backlight registration failed\n"); 289 dev_err(&iface->dev, "Backlight registration failed\n");
290 retval = PTR_ERR(pdata->bd);
285 goto error; 291 goto error;
286 } 292 }
287 293
288 pdata->bd->props.max_brightness = 0xff;
289
290 /* Try to get brightness */ 294 /* Try to get brightness */
291 brightness = appledisplay_bl_get_brightness(pdata->bd); 295 brightness = appledisplay_bl_get_brightness(pdata->bd);
292 296
diff --git a/drivers/usb/misc/berry_charge.c b/drivers/usb/misc/berry_charge.c
deleted file mode 100644
index c05a85bc5925..000000000000
--- a/drivers/usb/misc/berry_charge.c
+++ /dev/null
@@ -1,183 +0,0 @@
1/*
2 * USB BlackBerry charging module
3 *
4 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de>
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 as
8 * published by the Free Software Foundation, version 2.
9 *
10 * Information on how to switch configs was taken by the bcharge.cc file
11 * created by the barry.sf.net project.
12 *
13 * bcharge.cc has the following copyright:
14 * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/)
15 * and is released under the GPLv2.
16 *
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#define RIM_VENDOR 0x0fca
28#define BLACKBERRY 0x0001
29#define BLACKBERRY_PEARL_DUAL 0x0004
30#define BLACKBERRY_PEARL 0x0006
31
32static int debug;
33static int pearl_dual_mode = 1;
34
35#ifdef dbg
36#undef dbg
37#endif
38#define dbg(dev, format, arg...) \
39 if (debug) \
40 dev_printk(KERN_DEBUG , dev , format , ## arg)
41
42static struct usb_device_id id_table [] = {
43 { USB_DEVICE(RIM_VENDOR, BLACKBERRY) },
44 { USB_DEVICE(RIM_VENDOR, BLACKBERRY_PEARL) },
45 { USB_DEVICE(RIM_VENDOR, BLACKBERRY_PEARL_DUAL) },
46 { }, /* Terminating entry */
47};
48MODULE_DEVICE_TABLE(usb, id_table);
49
50static int magic_charge(struct usb_device *udev)
51{
52 char *dummy_buffer = kzalloc(2, GFP_KERNEL);
53 int retval;
54
55 if (!dummy_buffer)
56 return -ENOMEM;
57
58 /* send two magic commands and then set the configuration. The device
59 * will then reset itself with the new power usage and should start
60 * charging. */
61
62 /* Note, with testing, it only seems that the first message is really
63 * needed (at least for the 8700c), but to be safe, we emulate what
64 * other operating systems seem to be sending to their device. We
65 * really need to get some specs for this device to be sure about what
66 * is going on here.
67 */
68 dbg(&udev->dev, "Sending first magic command\n");
69 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
70 0xa5, 0xc0, 0, 1, dummy_buffer, 2, 100);
71 if (retval != 2) {
72 dev_err(&udev->dev, "First magic command failed: %d.\n",
73 retval);
74 goto exit;
75 }
76
77 dbg(&udev->dev, "Sending second magic command\n");
78 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
79 0xa2, 0x40, 0, 1, dummy_buffer, 0, 100);
80 if (retval != 0) {
81 dev_err(&udev->dev, "Second magic command failed: %d.\n",
82 retval);
83 goto exit;
84 }
85
86 dbg(&udev->dev, "Calling set_configuration\n");
87 retval = usb_driver_set_configuration(udev, 1);
88 if (retval)
89 dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);
90
91exit:
92 kfree(dummy_buffer);
93 return retval;
94}
95
96static int magic_dual_mode(struct usb_device *udev)
97{
98 char *dummy_buffer = kzalloc(2, GFP_KERNEL);
99 int retval;
100
101 if (!dummy_buffer)
102 return -ENOMEM;
103
104 /* send magic command so that the Blackberry Pearl device exposes
105 * two interfaces: both the USB mass-storage one and one which can
106 * be used for database access. */
107 dbg(&udev->dev, "Sending magic pearl command\n");
108 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
109 0xa9, 0xc0, 1, 1, dummy_buffer, 2, 100);
110 dbg(&udev->dev, "Magic pearl command returned %d\n", retval);
111
112 dbg(&udev->dev, "Calling set_configuration\n");
113 retval = usb_driver_set_configuration(udev, 1);
114 if (retval)
115 dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval);
116
117 kfree(dummy_buffer);
118 return retval;
119}
120
121static int berry_probe(struct usb_interface *intf,
122 const struct usb_device_id *id)
123{
124 struct usb_device *udev = interface_to_usbdev(intf);
125
126 if (udev->bus_mA < 500) {
127 dbg(&udev->dev, "Not enough power to charge available\n");
128 return -ENODEV;
129 }
130
131 dbg(&udev->dev, "Power is set to %dmA\n",
132 udev->actconfig->desc.bMaxPower * 2);
133
134 /* check the power usage so we don't try to enable something that is
135 * already enabled */
136 if ((udev->actconfig->desc.bMaxPower * 2) == 500) {
137 dbg(&udev->dev, "device is already charging, power is "
138 "set to %dmA\n", udev->actconfig->desc.bMaxPower * 2);
139 return -ENODEV;
140 }
141
142 /* turn the power on */
143 magic_charge(udev);
144
145 if ((le16_to_cpu(udev->descriptor.idProduct) == BLACKBERRY_PEARL) &&
146 (pearl_dual_mode))
147 magic_dual_mode(udev);
148
149 /* we don't really want to bind to the device, userspace programs can
150 * handle the syncing just fine, so get outta here. */
151 return -ENODEV;
152}
153
154static void berry_disconnect(struct usb_interface *intf)
155{
156}
157
158static struct usb_driver berry_driver = {
159 .name = "berry_charge",
160 .probe = berry_probe,
161 .disconnect = berry_disconnect,
162 .id_table = id_table,
163};
164
165static int __init berry_init(void)
166{
167 return usb_register(&berry_driver);
168}
169
170static void __exit berry_exit(void)
171{
172 usb_deregister(&berry_driver);
173}
174
175module_init(berry_init);
176module_exit(berry_exit);
177
178MODULE_LICENSE("GPL");
179MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
180module_param(debug, bool, S_IRUGO | S_IWUSR);
181MODULE_PARM_DESC(debug, "Debug enabled or not");
182module_param(pearl_dual_mode, bool, S_IRUGO | S_IWUSR);
183MODULE_PARM_DESC(pearl_dual_mode, "Change Blackberry Pearl to run in dual mode");
diff --git a/drivers/usb/misc/cypress_cy7c63.c b/drivers/usb/misc/cypress_cy7c63.c
index 5720bfef6a38..2f43c57743c9 100644
--- a/drivers/usb/misc/cypress_cy7c63.c
+++ b/drivers/usb/misc/cypress_cy7c63.c
@@ -32,6 +32,7 @@
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/slab.h>
35#include <linux/usb.h> 36#include <linux/usb.h>
36 37
37#define DRIVER_AUTHOR "Oliver Bock (bock@tfh-berlin.de)" 38#define DRIVER_AUTHOR "Oliver Bock (bock@tfh-berlin.de)"
@@ -56,7 +57,7 @@
56 57
57 58
58/* table of devices that work with this driver */ 59/* table of devices that work with this driver */
59static struct usb_device_id cypress_table [] = { 60static const struct usb_device_id cypress_table[] = {
60 { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) }, 61 { USB_DEVICE(CYPRESS_VENDOR_ID, CYPRESS_PRODUCT_ID) },
61 { } 62 { }
62}; 63};
diff --git a/drivers/usb/misc/cytherm.c b/drivers/usb/misc/cytherm.c
index 4fb3c38b924b..1d7251bc1b5f 100644
--- a/drivers/usb/misc/cytherm.c
+++ b/drivers/usb/misc/cytherm.c
@@ -17,6 +17,7 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/slab.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22 23
@@ -27,7 +28,7 @@
27#define USB_SKEL_VENDOR_ID 0x04b4 28#define USB_SKEL_VENDOR_ID 0x04b4
28#define USB_SKEL_PRODUCT_ID 0x0002 29#define USB_SKEL_PRODUCT_ID 0x0002
29 30
30static struct usb_device_id id_table [] = { 31static const struct usb_device_id id_table[] = {
31 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
32 { } 33 { }
33}; 34};
diff --git a/drivers/usb/misc/emi26.c b/drivers/usb/misc/emi26.c
index 879a980ca8c4..a6521c95f683 100644
--- a/drivers/usb/misc/emi26.c
+++ b/drivers/usb/misc/emi26.c
@@ -245,7 +245,7 @@ wraperr:
245 return err; 245 return err;
246} 246}
247 247
248static struct usb_device_id id_table [] = { 248static const struct usb_device_id id_table[] = {
249 { USB_DEVICE(EMI26_VENDOR_ID, EMI26_PRODUCT_ID) }, 249 { USB_DEVICE(EMI26_VENDOR_ID, EMI26_PRODUCT_ID) },
250 { USB_DEVICE(EMI26_VENDOR_ID, EMI26B_PRODUCT_ID) }, 250 { USB_DEVICE(EMI26_VENDOR_ID, EMI26B_PRODUCT_ID) },
251 { } /* Terminating entry */ 251 { } /* Terminating entry */
diff --git a/drivers/usb/misc/emi62.c b/drivers/usb/misc/emi62.c
index 602ee05ba9ff..fc15ad4c3139 100644
--- a/drivers/usb/misc/emi62.c
+++ b/drivers/usb/misc/emi62.c
@@ -167,7 +167,7 @@ static int emi62_load_firmware (struct usb_device *dev)
167 err("%s - error loading firmware: error = %d", __func__, err); 167 err("%s - error loading firmware: error = %d", __func__, err);
168 goto wraperr; 168 goto wraperr;
169 } 169 }
170 } while (i > 0); 170 } while (rec);
171 171
172 /* Assert reset (stop the CPU in the EMI) */ 172 /* Assert reset (stop the CPU in the EMI) */
173 err = emi62_set_reset(dev,1); 173 err = emi62_set_reset(dev,1);
@@ -259,7 +259,7 @@ wraperr:
259 return err; 259 return err;
260} 260}
261 261
262static __devinitdata struct usb_device_id id_table [] = { 262static const struct usb_device_id id_table[] __devinitconst = {
263 { USB_DEVICE(EMI62_VENDOR_ID, EMI62_PRODUCT_ID) }, 263 { USB_DEVICE(EMI62_VENDOR_ID, EMI62_PRODUCT_ID) },
264 { } /* Terminating entry */ 264 { } /* Terminating entry */
265}; 265};
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 9d0675ed0d4c..1edb6d361896 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -86,7 +86,7 @@ static struct list_head ftdi_static_list;
86#define USB_FTDI_ELAN_VENDOR_ID 0x0403 86#define USB_FTDI_ELAN_VENDOR_ID 0x0403
87#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea 87#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
88/* table of devices that work with this driver*/ 88/* table of devices that work with this driver*/
89static struct usb_device_id ftdi_elan_table[] = { 89static const struct usb_device_id ftdi_elan_table[] = {
90 {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)}, 90 {USB_DEVICE(USB_FTDI_ELAN_VENDOR_ID, USB_FTDI_ELAN_PRODUCT_ID)},
91 { /* Terminating entry */ } 91 { /* Terminating entry */ }
92}; 92};
@@ -623,9 +623,12 @@ static void ftdi_elan_status_work(struct work_struct *work)
623*/ 623*/
624static int ftdi_elan_open(struct inode *inode, struct file *file) 624static int ftdi_elan_open(struct inode *inode, struct file *file)
625{ 625{
626 int subminor = iminor(inode); 626 int subminor;
627 struct usb_interface *interface = usb_find_interface(&ftdi_elan_driver, 627 struct usb_interface *interface;
628 subminor); 628
629 subminor = iminor(inode);
630 interface = usb_find_interface(&ftdi_elan_driver, subminor);
631
629 if (!interface) { 632 if (!interface) {
630 printk(KERN_ERR "can't find device for minor %d\n", subminor); 633 printk(KERN_ERR "can't find device for minor %d\n", subminor);
631 return -ENODEV; 634 return -ENODEV;
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index 1337a9ce80b9..a54c3cb804ce 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -48,7 +48,7 @@
48#define ID_CHERRY 0x0010 48#define ID_CHERRY 0x0010
49 49
50/* device ID table */ 50/* device ID table */
51static struct usb_device_id idmouse_table[] = { 51static const struct usb_device_id idmouse_table[] = {
52 {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */ 52 {USB_DEVICE(ID_SIEMENS, ID_IDMOUSE)}, /* Siemens ID Mouse (Professional) */
53 {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */ 53 {USB_DEVICE(ID_SIEMENS, ID_CHERRY )}, /* Cherry FingerTIP ID Board */
54 {} /* terminating null entry */ 54 {} /* terminating null entry */
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index e75bb87ee92b..d3c852363883 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -139,7 +139,7 @@ static int usb_set_report(struct usb_interface *intf, unsigned char type,
139/* driver registration */ 139/* driver registration */
140/*---------------------*/ 140/*---------------------*/
141/* table of devices that work with this driver */ 141/* table of devices that work with this driver */
142static struct usb_device_id iowarrior_ids[] = { 142static const struct usb_device_id iowarrior_ids[] = {
143 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40)}, 143 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW40)},
144 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24)}, 144 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOW24)},
145 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV1)}, 145 {USB_DEVICE(USB_VENDOR_ID_CODEMERCS, USB_DEVICE_ID_CODEMERCS_IOWPV1)},
@@ -602,10 +602,12 @@ static int iowarrior_open(struct inode *inode, struct file *file)
602 602
603 dbg("%s", __func__); 603 dbg("%s", __func__);
604 604
605 lock_kernel();
605 subminor = iminor(inode); 606 subminor = iminor(inode);
606 607
607 interface = usb_find_interface(&iowarrior_driver, subminor); 608 interface = usb_find_interface(&iowarrior_driver, subminor);
608 if (!interface) { 609 if (!interface) {
610 unlock_kernel();
609 err("%s - error, can't find device for minor %d", __func__, 611 err("%s - error, can't find device for minor %d", __func__,
610 subminor); 612 subminor);
611 return -ENODEV; 613 return -ENODEV;
@@ -615,6 +617,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
615 dev = usb_get_intfdata(interface); 617 dev = usb_get_intfdata(interface);
616 if (!dev) { 618 if (!dev) {
617 mutex_unlock(&iowarrior_open_disc_lock); 619 mutex_unlock(&iowarrior_open_disc_lock);
620 unlock_kernel();
618 return -ENODEV; 621 return -ENODEV;
619 } 622 }
620 623
@@ -641,6 +644,7 @@ static int iowarrior_open(struct inode *inode, struct file *file)
641 644
642out: 645out:
643 mutex_unlock(&dev->mutex); 646 mutex_unlock(&dev->mutex);
647 unlock_kernel();
644 return retval; 648 return retval;
645} 649}
646 650
diff --git a/drivers/usb/misc/isight_firmware.c b/drivers/usb/misc/isight_firmware.c
index b897f6554ecd..fe1d44319d0a 100644
--- a/drivers/usb/misc/isight_firmware.c
+++ b/drivers/usb/misc/isight_firmware.c
@@ -25,8 +25,9 @@
25#include <linux/firmware.h> 25#include <linux/firmware.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/slab.h>
28 29
29static struct usb_device_id id_table[] = { 30static const struct usb_device_id id_table[] = {
30 {USB_DEVICE(0x05ac, 0x8300)}, 31 {USB_DEVICE(0x05ac, 0x8300)},
31 {}, 32 {},
32}; 33};
@@ -112,6 +113,8 @@ out:
112 return ret; 113 return ret;
113} 114}
114 115
116MODULE_FIRMWARE("isight.fw");
117
115static void isight_firmware_disconnect(struct usb_interface *intf) 118static void isight_firmware_disconnect(struct usb_interface *intf)
116{ 119{
117} 120}
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 90f130126c10..dd41d8710043 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -69,7 +69,7 @@
69#endif 69#endif
70 70
71/* table of devices that work with this driver */ 71/* table of devices that work with this driver */
72static struct usb_device_id ld_usb_table [] = { 72static const struct usb_device_id ld_usb_table[] = {
73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) }, 73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) }, 74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) }, 75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
@@ -798,7 +798,7 @@ static int __init ld_usb_init(void)
798 /* register this driver with the USB subsystem */ 798 /* register this driver with the USB subsystem */
799 retval = usb_register(&ld_usb_driver); 799 retval = usb_register(&ld_usb_driver);
800 if (retval) 800 if (retval)
801 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval); 801 err("usb_register failed for the %s driver. Error number %d\n", __FILE__, retval);
802 802
803 return retval; 803 return retval;
804} 804}
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index faa6d623de78..8547bf9e3175 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -95,8 +95,11 @@
95 95
96/* Use our own dbg macro */ 96/* Use our own dbg macro */
97#undef dbg 97#undef dbg
98#define dbg(lvl, format, arg...) do { if (debug >= lvl) printk(KERN_DEBUG __FILE__ ": " format "\n", ## arg); } while (0) 98#define dbg(lvl, format, arg...) \
99 99do { \
100 if (debug >= lvl) \
101 printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
102} while (0)
100 103
101/* Version Information */ 104/* Version Information */
102#define DRIVER_VERSION "v0.96" 105#define DRIVER_VERSION "v0.96"
@@ -192,7 +195,7 @@ struct tower_get_version_reply {
192 195
193 196
194/* table of devices that work with this driver */ 197/* table of devices that work with this driver */
195static struct usb_device_id tower_table [] = { 198static const struct usb_device_id tower_table[] = {
196 { USB_DEVICE(LEGO_USB_TOWER_VENDOR_ID, LEGO_USB_TOWER_PRODUCT_ID) }, 199 { USB_DEVICE(LEGO_USB_TOWER_VENDOR_ID, LEGO_USB_TOWER_PRODUCT_ID) },
197 { } /* Terminating entry */ 200 { } /* Terminating entry */
198}; 201};
@@ -302,7 +305,7 @@ static inline void lego_usb_tower_debug_data (int level, const char *function, i
302 if (debug < level) 305 if (debug < level)
303 return; 306 return;
304 307
305 printk (KERN_DEBUG __FILE__": %s - length = %d, data = ", function, size); 308 printk (KERN_DEBUG "%s: %s - length = %d, data = ", __FILE__, function, size);
306 for (i = 0; i < size; ++i) { 309 for (i = 0; i < size; ++i) {
307 printk ("%.2x ", data[i]); 310 printk ("%.2x ", data[i]);
308 } 311 }
@@ -1055,7 +1058,7 @@ static int __init lego_usb_tower_init(void)
1055 /* register this driver with the USB subsystem */ 1058 /* register this driver with the USB subsystem */
1056 result = usb_register(&tower_driver); 1059 result = usb_register(&tower_driver);
1057 if (result < 0) { 1060 if (result < 0) {
1058 err("usb_register failed for the "__FILE__" driver. Error number %d", result); 1061 err("usb_register failed for the %s driver. Error number %d", __FILE__, result);
1059 retval = -1; 1062 retval = -1;
1060 goto exit; 1063 goto exit;
1061 } 1064 }
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index 32d0199d0c32..a85771b1563d 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -78,10 +78,13 @@ static int open_rio(struct inode *inode, struct file *file)
78{ 78{
79 struct rio_usb_data *rio = &rio_instance; 79 struct rio_usb_data *rio = &rio_instance;
80 80
81 /* against disconnect() */
82 lock_kernel();
81 mutex_lock(&(rio->lock)); 83 mutex_lock(&(rio->lock));
82 84
83 if (rio->isopen || !rio->present) { 85 if (rio->isopen || !rio->present) {
84 mutex_unlock(&(rio->lock)); 86 mutex_unlock(&(rio->lock));
87 unlock_kernel();
85 return -EBUSY; 88 return -EBUSY;
86 } 89 }
87 rio->isopen = 1; 90 rio->isopen = 1;
@@ -91,6 +94,7 @@ static int open_rio(struct inode *inode, struct file *file)
91 mutex_unlock(&(rio->lock)); 94 mutex_unlock(&(rio->lock));
92 95
93 dev_info(&rio->rio_dev->dev, "Rio opened.\n"); 96 dev_info(&rio->rio_dev->dev, "Rio opened.\n");
97 unlock_kernel();
94 98
95 return 0; 99 return 0;
96} 100}
@@ -115,7 +119,6 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
115 int retries; 119 int retries;
116 int retval=0; 120 int retval=0;
117 121
118 lock_kernel();
119 mutex_lock(&(rio->lock)); 122 mutex_lock(&(rio->lock));
120 /* Sanity check to make sure rio is connected, powered, etc */ 123 /* Sanity check to make sure rio is connected, powered, etc */
121 if (rio->present == 0 || rio->rio_dev == NULL) { 124 if (rio->present == 0 || rio->rio_dev == NULL) {
@@ -254,7 +257,6 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
254 257
255err_out: 258err_out:
256 mutex_unlock(&(rio->lock)); 259 mutex_unlock(&(rio->lock));
257 unlock_kernel();
258 return retval; 260 return retval;
259} 261}
260 262
@@ -489,6 +491,7 @@ static void disconnect_rio(struct usb_interface *intf)
489 struct rio_usb_data *rio = usb_get_intfdata (intf); 491 struct rio_usb_data *rio = usb_get_intfdata (intf);
490 492
491 usb_set_intfdata (intf, NULL); 493 usb_set_intfdata (intf, NULL);
494 lock_kernel();
492 if (rio) { 495 if (rio) {
493 usb_deregister_dev(intf, &usb_rio_class); 496 usb_deregister_dev(intf, &usb_rio_class);
494 497
@@ -498,6 +501,7 @@ static void disconnect_rio(struct usb_interface *intf)
498 /* better let it finish - the release will do whats needed */ 501 /* better let it finish - the release will do whats needed */
499 rio->rio_dev = NULL; 502 rio->rio_dev = NULL;
500 mutex_unlock(&(rio->lock)); 503 mutex_unlock(&(rio->lock));
504 unlock_kernel();
501 return; 505 return;
502 } 506 }
503 kfree(rio->ibuf); 507 kfree(rio->ibuf);
@@ -508,9 +512,10 @@ static void disconnect_rio(struct usb_interface *intf)
508 rio->present = 0; 512 rio->present = 0;
509 mutex_unlock(&(rio->lock)); 513 mutex_unlock(&(rio->lock));
510 } 514 }
515 unlock_kernel();
511} 516}
512 517
513static struct usb_device_id rio_table [] = { 518static const struct usb_device_id rio_table[] = {
514 { USB_DEVICE(0x0841, 1) }, /* Rio 500 */ 519 { USB_DEVICE(0x0841, 1) }, /* Rio 500 */
515 { } /* Terminating entry */ 520 { } /* Terminating entry */
516}; 521};
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index 0025847743f3..aae95a009bd5 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -250,7 +250,7 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
250 sisusb->urbstatus[index] |= SU_URB_BUSY; 250 sisusb->urbstatus[index] |= SU_URB_BUSY;
251 251
252 /* Submit URB */ 252 /* Submit URB */
253 retval = usb_submit_urb(urb, GFP_ATOMIC); 253 retval = usb_submit_urb(urb, GFP_KERNEL);
254 254
255 /* If OK, and if timeout > 0, wait for completion */ 255 /* If OK, and if timeout > 0, wait for completion */
256 if ((retval == 0) && timeout) { 256 if ((retval == 0) && timeout) {
@@ -306,7 +306,7 @@ sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
306 urb->actual_length = 0; 306 urb->actual_length = 0;
307 307
308 sisusb->completein = 0; 308 sisusb->completein = 0;
309 retval = usb_submit_urb(urb, GFP_ATOMIC); 309 retval = usb_submit_urb(urb, GFP_KERNEL);
310 if (retval == 0) { 310 if (retval == 0) {
311 wait_event_timeout(sisusb->wait_q, sisusb->completein, timeout); 311 wait_event_timeout(sisusb->wait_q, sisusb->completein, timeout);
312 if (!sisusb->completein) { 312 if (!sisusb->completein) {
@@ -2416,21 +2416,28 @@ sisusb_open(struct inode *inode, struct file *file)
2416 struct usb_interface *interface; 2416 struct usb_interface *interface;
2417 int subminor = iminor(inode); 2417 int subminor = iminor(inode);
2418 2418
2419 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) 2419 lock_kernel();
2420 if (!(interface = usb_find_interface(&sisusb_driver, subminor))) {
2421 unlock_kernel();
2420 return -ENODEV; 2422 return -ENODEV;
2423 }
2421 2424
2422 if (!(sisusb = usb_get_intfdata(interface))) 2425 if (!(sisusb = usb_get_intfdata(interface))) {
2426 unlock_kernel();
2423 return -ENODEV; 2427 return -ENODEV;
2428 }
2424 2429
2425 mutex_lock(&sisusb->lock); 2430 mutex_lock(&sisusb->lock);
2426 2431
2427 if (!sisusb->present || !sisusb->ready) { 2432 if (!sisusb->present || !sisusb->ready) {
2428 mutex_unlock(&sisusb->lock); 2433 mutex_unlock(&sisusb->lock);
2434 unlock_kernel();
2429 return -ENODEV; 2435 return -ENODEV;
2430 } 2436 }
2431 2437
2432 if (sisusb->isopen) { 2438 if (sisusb->isopen) {
2433 mutex_unlock(&sisusb->lock); 2439 mutex_unlock(&sisusb->lock);
2440 unlock_kernel();
2434 return -EBUSY; 2441 return -EBUSY;
2435 } 2442 }
2436 2443
@@ -2439,11 +2446,13 @@ sisusb_open(struct inode *inode, struct file *file)
2439 if (sisusb_init_gfxdevice(sisusb, 0)) { 2446 if (sisusb_init_gfxdevice(sisusb, 0)) {
2440 mutex_unlock(&sisusb->lock); 2447 mutex_unlock(&sisusb->lock);
2441 dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n"); 2448 dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n");
2449 unlock_kernel();
2442 return -EIO; 2450 return -EIO;
2443 } 2451 }
2444 } else { 2452 } else {
2445 mutex_unlock(&sisusb->lock); 2453 mutex_unlock(&sisusb->lock);
2446 dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n"); 2454 dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n");
2455 unlock_kernel();
2447 return -EIO; 2456 return -EIO;
2448 } 2457 }
2449 } 2458 }
@@ -2456,6 +2465,7 @@ sisusb_open(struct inode *inode, struct file *file)
2456 file->private_data = sisusb; 2465 file->private_data = sisusb;
2457 2466
2458 mutex_unlock(&sisusb->lock); 2467 mutex_unlock(&sisusb->lock);
2468 unlock_kernel();
2459 2469
2460 return 0; 2470 return 0;
2461} 2471}
@@ -3238,13 +3248,14 @@ static void sisusb_disconnect(struct usb_interface *intf)
3238 kref_put(&sisusb->kref, sisusb_delete); 3248 kref_put(&sisusb->kref, sisusb_delete);
3239} 3249}
3240 3250
3241static struct usb_device_id sisusb_table [] = { 3251static const struct usb_device_id sisusb_table[] = {
3242 { USB_DEVICE(0x0711, 0x0550) }, 3252 { USB_DEVICE(0x0711, 0x0550) },
3243 { USB_DEVICE(0x0711, 0x0900) }, 3253 { USB_DEVICE(0x0711, 0x0900) },
3244 { USB_DEVICE(0x0711, 0x0901) }, 3254 { USB_DEVICE(0x0711, 0x0901) },
3245 { USB_DEVICE(0x0711, 0x0902) }, 3255 { USB_DEVICE(0x0711, 0x0902) },
3246 { USB_DEVICE(0x0711, 0x0903) }, 3256 { USB_DEVICE(0x0711, 0x0903) },
3247 { USB_DEVICE(0x0711, 0x0918) }, 3257 { USB_DEVICE(0x0711, 0x0918) },
3258 { USB_DEVICE(0x0711, 0x0920) },
3248 { USB_DEVICE(0x182d, 0x021c) }, 3259 { USB_DEVICE(0x182d, 0x021c) },
3249 { USB_DEVICE(0x182d, 0x0269) }, 3260 { USB_DEVICE(0x182d, 0x0269) },
3250 { } 3261 { }
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
index b624320df903..b271b0557a1f 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -58,7 +58,6 @@
58#include <linux/string.h> 58#include <linux/string.h>
59#include <linux/kd.h> 59#include <linux/kd.h>
60#include <linux/init.h> 60#include <linux/init.h>
61#include <linux/slab.h>
62#include <linux/vt_kern.h> 61#include <linux/vt_kern.h>
63#include <linux/selection.h> 62#include <linux/selection.h>
64#include <linux/spinlock.h> 63#include <linux/spinlock.h>
diff --git a/drivers/usb/misc/sisusbvga/sisusb_init.c b/drivers/usb/misc/sisusbvga/sisusb_init.c
index 0ab990744830..cb8a3d91f970 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_init.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_init.c
@@ -41,7 +41,6 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/poll.h> 42#include <linux/poll.h>
43#include <linux/init.h> 43#include <linux/init.h>
44#include <linux/slab.h>
45#include <linux/spinlock.h> 44#include <linux/spinlock.h>
46 45
47#include "sisusb.h" 46#include "sisusb.h"
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index 2e14102955c5..d77aba46ae85 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -22,6 +22,7 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h>
25#include <linux/module.h> 26#include <linux/module.h>
26#include <linux/usb.h> 27#include <linux/usb.h>
27 28
@@ -33,7 +34,7 @@
33#define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */ 34#define TRANCEVIBRATOR_VENDOR_ID 0x0b49 /* ASCII Corporation */
34#define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */ 35#define TRANCEVIBRATOR_PRODUCT_ID 0x064f /* Trance Vibrator */
35 36
36static struct usb_device_id id_table [] = { 37static const struct usb_device_id id_table[] = {
37 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) }, 38 { USB_DEVICE(TRANCEVIBRATOR_VENDOR_ID, TRANCEVIBRATOR_PRODUCT_ID) },
38 { }, 39 { },
39}; 40};
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 4fb120357c55..90aede90553e 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -30,7 +30,7 @@
30#define IOCTL_GET_DRV_VERSION 2 30#define IOCTL_GET_DRV_VERSION 2
31 31
32 32
33static struct usb_device_id id_table [] = { 33static const struct usb_device_id id_table[] = {
34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, }, 34 { .idVendor = 0x10D2, .match_flags = USB_DEVICE_ID_MATCH_VENDOR, },
35 { }, 35 { },
36}; 36};
@@ -74,10 +74,12 @@ static int lcd_open(struct inode *inode, struct file *file)
74 struct usb_interface *interface; 74 struct usb_interface *interface;
75 int subminor, r; 75 int subminor, r;
76 76
77 lock_kernel();
77 subminor = iminor(inode); 78 subminor = iminor(inode);
78 79
79 interface = usb_find_interface(&lcd_driver, subminor); 80 interface = usb_find_interface(&lcd_driver, subminor);
80 if (!interface) { 81 if (!interface) {
82 unlock_kernel();
81 err ("USBLCD: %s - error, can't find device for minor %d", 83 err ("USBLCD: %s - error, can't find device for minor %d",
82 __func__, subminor); 84 __func__, subminor);
83 return -ENODEV; 85 return -ENODEV;
@@ -87,6 +89,7 @@ static int lcd_open(struct inode *inode, struct file *file)
87 dev = usb_get_intfdata(interface); 89 dev = usb_get_intfdata(interface);
88 if (!dev) { 90 if (!dev) {
89 mutex_unlock(&open_disc_mutex); 91 mutex_unlock(&open_disc_mutex);
92 unlock_kernel();
90 return -ENODEV; 93 return -ENODEV;
91 } 94 }
92 95
@@ -98,11 +101,13 @@ static int lcd_open(struct inode *inode, struct file *file)
98 r = usb_autopm_get_interface(interface); 101 r = usb_autopm_get_interface(interface);
99 if (r < 0) { 102 if (r < 0) {
100 kref_put(&dev->kref, lcd_delete); 103 kref_put(&dev->kref, lcd_delete);
104 unlock_kernel();
101 return r; 105 return r;
102 } 106 }
103 107
104 /* save our object in the file's private structure */ 108 /* save our object in the file's private structure */
105 file->private_data = dev; 109 file->private_data = dev;
110 unlock_kernel();
106 111
107 return 0; 112 return 0;
108} 113}
diff --git a/drivers/usb/misc/usbled.c b/drivers/usb/misc/usbled.c
index 06cb71942dc7..63da2c3c838f 100644
--- a/drivers/usb/misc/usbled.c
+++ b/drivers/usb/misc/usbled.c
@@ -24,7 +24,7 @@
24#define PRODUCT_ID 0x1223 24#define PRODUCT_ID 0x1223
25 25
26/* table of devices that work with this driver */ 26/* table of devices that work with this driver */
27static struct usb_device_id id_table [] = { 27static const struct usb_device_id id_table[] = {
28 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, 28 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) },
29 { }, 29 { },
30}; 30};
diff --git a/drivers/usb/misc/usbsevseg.c b/drivers/usb/misc/usbsevseg.c
index 3db255537e79..de8ef945b536 100644
--- a/drivers/usb/misc/usbsevseg.c
+++ b/drivers/usb/misc/usbsevseg.c
@@ -27,7 +27,7 @@
27#define MAXLEN 6 27#define MAXLEN 6
28 28
29/* table of devices that work with this driver */ 29/* table of devices that work with this driver */
30static struct usb_device_id id_table[] = { 30static const struct usb_device_id id_table[] = {
31 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, 31 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) },
32 { }, 32 { },
33}; 33};
@@ -49,6 +49,7 @@ struct usb_sevsegdev {
49 u16 textlength; 49 u16 textlength;
50 50
51 u8 shadow_power; /* for PM */ 51 u8 shadow_power; /* for PM */
52 u8 has_interface_pm;
52}; 53};
53 54
54/* sysfs_streq can't replace this completely 55/* sysfs_streq can't replace this completely
@@ -68,12 +69,16 @@ static void update_display_powered(struct usb_sevsegdev *mydev)
68{ 69{
69 int rc; 70 int rc;
70 71
71 if (!mydev->shadow_power && mydev->powered) { 72 if (mydev->powered && !mydev->has_interface_pm) {
72 rc = usb_autopm_get_interface(mydev->intf); 73 rc = usb_autopm_get_interface(mydev->intf);
73 if (rc < 0) 74 if (rc < 0)
74 return; 75 return;
76 mydev->has_interface_pm = 1;
75 } 77 }
76 78
79 if (mydev->shadow_power != 1)
80 return;
81
77 rc = usb_control_msg(mydev->udev, 82 rc = usb_control_msg(mydev->udev,
78 usb_sndctrlpipe(mydev->udev, 0), 83 usb_sndctrlpipe(mydev->udev, 0),
79 0x12, 84 0x12,
@@ -86,8 +91,10 @@ static void update_display_powered(struct usb_sevsegdev *mydev)
86 if (rc < 0) 91 if (rc < 0)
87 dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc); 92 dev_dbg(&mydev->udev->dev, "power retval = %d\n", rc);
88 93
89 if (mydev->shadow_power && !mydev->powered) 94 if (!mydev->powered && mydev->has_interface_pm) {
90 usb_autopm_put_interface(mydev->intf); 95 usb_autopm_put_interface(mydev->intf);
96 mydev->has_interface_pm = 0;
97 }
91} 98}
92 99
93static void update_display_mode(struct usb_sevsegdev *mydev) 100static void update_display_mode(struct usb_sevsegdev *mydev)
@@ -351,6 +358,10 @@ static int sevseg_probe(struct usb_interface *interface,
351 mydev->intf = interface; 358 mydev->intf = interface;
352 usb_set_intfdata(interface, mydev); 359 usb_set_intfdata(interface, mydev);
353 360
361 /* PM */
362 mydev->shadow_power = 1; /* currently active */
363 mydev->has_interface_pm = 0; /* have not issued autopm_get */
364
354 /*set defaults */ 365 /*set defaults */
355 mydev->textmode = 0x02; /* ascii mode */ 366 mydev->textmode = 0x02; /* ascii mode */
356 mydev->mode_msb = 0x06; /* 6 characters */ 367 mydev->mode_msb = 0x06; /* 6 characters */
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index a9f06d76960f..a21cce6f7403 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -213,8 +213,9 @@ static struct urb *simple_alloc_urb (
213} 213}
214 214
215static unsigned pattern = 0; 215static unsigned pattern = 0;
216module_param (pattern, uint, S_IRUGO); 216static unsigned mod_pattern;
217MODULE_PARM_DESC(pattern, "i/o pattern (0 == zeroes)"); 217module_param_named(pattern, mod_pattern, uint, S_IRUGO | S_IWUSR);
218MODULE_PARM_DESC(mod_pattern, "i/o pattern (0 == zeroes)");
218 219
219static inline void simple_fill_buf (struct urb *urb) 220static inline void simple_fill_buf (struct urb *urb)
220{ 221{
@@ -1567,6 +1568,8 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1567 1568
1568 // FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is. 1569 // FIXME USBDEVFS_CONNECTINFO doesn't say how fast the device is.
1569 1570
1571 pattern = mod_pattern;
1572
1570 if (code != USBTEST_REQUEST) 1573 if (code != USBTEST_REQUEST)
1571 return -EOPNOTSUPP; 1574 return -EOPNOTSUPP;
1572 1575
@@ -1577,10 +1580,6 @@ usbtest_ioctl (struct usb_interface *intf, unsigned int code, void *buf)
1577 return -ERESTARTSYS; 1580 return -ERESTARTSYS;
1578 1581
1579 /* FIXME: What if a system sleep starts while a test is running? */ 1582 /* FIXME: What if a system sleep starts while a test is running? */
1580 if (!intf->is_active) {
1581 mutex_unlock(&dev->lock);
1582 return -EHOSTUNREACH;
1583 }
1584 1583
1585 /* some devices, like ez-usb default devices, need a non-default 1584 /* some devices, like ez-usb default devices, need a non-default
1586 * altsetting to have any active endpoints. some tests change 1585 * altsetting to have any active endpoints. some tests change
@@ -2098,7 +2097,7 @@ static struct usbtest_info generic_info = {
2098#endif 2097#endif
2099 2098
2100 2099
2101static struct usb_device_id id_table [] = { 2100static const struct usb_device_id id_table[] = {
2102 2101
2103 /*-------------------------------------------------------------*/ 2102 /*-------------------------------------------------------------*/
2104 2103
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 9a6c27a01793..796e2f68f749 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -49,6 +49,7 @@
49#include <linux/delay.h> 49#include <linux/delay.h>
50#include <linux/completion.h> 50#include <linux/completion.h>
51#include <linux/kref.h> 51#include <linux/kref.h>
52#include <linux/slab.h>
52 53
53/* 54/*
54 * Version Information 55 * Version Information
@@ -770,7 +771,7 @@ static void uss720_disconnect(struct usb_interface *intf)
770} 771}
771 772
772/* table of cables that work through this driver */ 773/* table of cables that work through this driver */
773static struct usb_device_id uss720_table [] = { 774static const struct usb_device_id uss720_table[] = {
774 { USB_DEVICE(0x047e, 0x1001) }, 775 { USB_DEVICE(0x047e, 0x1001) },
775 { USB_DEVICE(0x0557, 0x2001) }, 776 { USB_DEVICE(0x0557, 0x2001) },
776 { USB_DEVICE(0x0729, 0x1284) }, 777 { USB_DEVICE(0x0729, 0x1284) },
diff --git a/drivers/usb/misc/vstusb.c b/drivers/usb/misc/vstusb.c
deleted file mode 100644
index f26ea8dc1577..000000000000
--- a/drivers/usb/misc/vstusb.c
+++ /dev/null
@@ -1,783 +0,0 @@
1/*****************************************************************************
2 * File: drivers/usb/misc/vstusb.c
3 *
4 * Purpose: Support for the bulk USB Vernier Spectrophotometers
5 *
6 * Author: Johnnie Peters
7 * Axian Consulting
8 * Beaverton, OR, USA 97005
9 *
10 * Modified by: EQware Engineering, Inc.
11 * Oregon City, OR, USA 97045
12 *
13 * Copyright: 2007, 2008
14 * Vernier Software & Technology
15 * Beaverton, OR, USA 97005
16 *
17 * Web: www.vernier.com
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 2 as
21 * published by the Free Software Foundation.
22 *
23 *****************************************************************************/
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/module.h>
29#include <linux/mutex.h>
30#include <linux/uaccess.h>
31#include <linux/usb.h>
32
33#include <linux/usb/vstusb.h>
34
35#define DRIVER_VERSION "VST USB Driver Version 1.5"
36#define DRIVER_DESC "Vernier Software Technology Bulk USB Driver"
37
38#ifdef CONFIG_USB_DYNAMIC_MINORS
39 #define VSTUSB_MINOR_BASE 0
40#else
41 #define VSTUSB_MINOR_BASE 199
42#endif
43
44#define USB_VENDOR_OCEANOPTICS 0x2457
45#define USB_VENDOR_VERNIER 0x08F7 /* Vernier Software & Technology */
46
47#define USB_PRODUCT_USB2000 0x1002
48#define USB_PRODUCT_ADC1000_FW 0x1003 /* firmware download (renumerates) */
49#define USB_PRODUCT_ADC1000 0x1004
50#define USB_PRODUCT_HR2000_FW 0x1009 /* firmware download (renumerates) */
51#define USB_PRODUCT_HR2000 0x100A
52#define USB_PRODUCT_HR4000_FW 0x1011 /* firmware download (renumerates) */
53#define USB_PRODUCT_HR4000 0x1012
54#define USB_PRODUCT_USB650 0x1014 /* "Red Tide" */
55#define USB_PRODUCT_QE65000 0x1018
56#define USB_PRODUCT_USB4000 0x1022
57#define USB_PRODUCT_USB325 0x1024 /* "Vernier Spectrometer" */
58
59#define USB_PRODUCT_LABPRO 0x0001
60#define USB_PRODUCT_LABQUEST 0x0005
61
62#define VST_MAXBUFFER (64*1024)
63
64static struct usb_device_id id_table[] = {
65 { USB_DEVICE(USB_VENDOR_OCEANOPTICS, USB_PRODUCT_USB2000)},
66 { USB_DEVICE(USB_VENDOR_OCEANOPTICS, USB_PRODUCT_HR4000)},
67 { USB_DEVICE(USB_VENDOR_OCEANOPTICS, USB_PRODUCT_USB650)},
68 { USB_DEVICE(USB_VENDOR_OCEANOPTICS, USB_PRODUCT_USB4000)},
69 { USB_DEVICE(USB_VENDOR_OCEANOPTICS, USB_PRODUCT_USB325)},
70 { USB_DEVICE(USB_VENDOR_VERNIER, USB_PRODUCT_LABQUEST)},
71 { USB_DEVICE(USB_VENDOR_VERNIER, USB_PRODUCT_LABPRO)},
72 {},
73};
74
75MODULE_DEVICE_TABLE(usb, id_table);
76
77struct vstusb_device {
78 struct kref kref;
79 struct mutex lock;
80 struct usb_device *usb_dev;
81 char present;
82 char isopen;
83 struct usb_anchor submitted;
84 int rd_pipe;
85 int rd_timeout_ms;
86 int wr_pipe;
87 int wr_timeout_ms;
88};
89#define to_vst_dev(d) container_of(d, struct vstusb_device, kref)
90
91static struct usb_driver vstusb_driver;
92
93static void vstusb_delete(struct kref *kref)
94{
95 struct vstusb_device *vstdev = to_vst_dev(kref);
96
97 usb_put_dev(vstdev->usb_dev);
98 kfree(vstdev);
99}
100
101static int vstusb_open(struct inode *inode, struct file *file)
102{
103 struct vstusb_device *vstdev;
104 struct usb_interface *interface;
105
106 interface = usb_find_interface(&vstusb_driver, iminor(inode));
107
108 if (!interface) {
109 printk(KERN_ERR KBUILD_MODNAME
110 ": %s - error, can't find device for minor %d\n",
111 __func__, iminor(inode));
112 return -ENODEV;
113 }
114
115 vstdev = usb_get_intfdata(interface);
116
117 if (!vstdev)
118 return -ENODEV;
119
120 /* lock this device */
121 mutex_lock(&vstdev->lock);
122
123 /* can only open one time */
124 if ((!vstdev->present) || (vstdev->isopen)) {
125 mutex_unlock(&vstdev->lock);
126 return -EBUSY;
127 }
128
129 /* increment our usage count */
130 kref_get(&vstdev->kref);
131
132 vstdev->isopen = 1;
133
134 /* save device in the file's private structure */
135 file->private_data = vstdev;
136
137 dev_dbg(&vstdev->usb_dev->dev, "%s: opened\n", __func__);
138
139 mutex_unlock(&vstdev->lock);
140
141 return 0;
142}
143
144static int vstusb_release(struct inode *inode, struct file *file)
145{
146 struct vstusb_device *vstdev;
147
148 vstdev = file->private_data;
149
150 if (vstdev == NULL)
151 return -ENODEV;
152
153 mutex_lock(&vstdev->lock);
154
155 vstdev->isopen = 0;
156
157 dev_dbg(&vstdev->usb_dev->dev, "%s: released\n", __func__);
158
159 mutex_unlock(&vstdev->lock);
160
161 kref_put(&vstdev->kref, vstusb_delete);
162
163 return 0;
164}
165
166static void usb_api_blocking_completion(struct urb *urb)
167{
168 struct completion *completeit = urb->context;
169
170 complete(completeit);
171}
172
173static int vstusb_fill_and_send_urb(struct urb *urb,
174 struct usb_device *usb_dev,
175 unsigned int pipe, void *data,
176 unsigned int len, struct completion *done)
177{
178 struct usb_host_endpoint *ep;
179 struct usb_host_endpoint **hostep;
180 unsigned int pipend;
181
182 int status;
183
184 hostep = usb_pipein(pipe) ? usb_dev->ep_in : usb_dev->ep_out;
185 pipend = usb_pipeendpoint(pipe);
186 ep = hostep[pipend];
187
188 if (!ep || (len == 0))
189 return -EINVAL;
190
191 if ((ep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
192 == USB_ENDPOINT_XFER_INT) {
193 pipe = (pipe & ~(3 << 30)) | (PIPE_INTERRUPT << 30);
194 usb_fill_int_urb(urb, usb_dev, pipe, data, len,
195 (usb_complete_t)usb_api_blocking_completion,
196 NULL, ep->desc.bInterval);
197 } else
198 usb_fill_bulk_urb(urb, usb_dev, pipe, data, len,
199 (usb_complete_t)usb_api_blocking_completion,
200 NULL);
201
202 init_completion(done);
203 urb->context = done;
204 urb->actual_length = 0;
205 status = usb_submit_urb(urb, GFP_KERNEL);
206
207 return status;
208}
209
210static int vstusb_complete_urb(struct urb *urb, struct completion *done,
211 int timeout, int *actual_length)
212{
213 unsigned long expire;
214 int status;
215
216 expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT;
217 if (!wait_for_completion_interruptible_timeout(done, expire)) {
218 usb_kill_urb(urb);
219 status = urb->status == -ENOENT ? -ETIMEDOUT : urb->status;
220
221 dev_dbg(&urb->dev->dev,
222 "%s timed out on ep%d%s len=%d/%d, urb status = %d\n",
223 current->comm,
224 usb_pipeendpoint(urb->pipe),
225 usb_pipein(urb->pipe) ? "in" : "out",
226 urb->actual_length,
227 urb->transfer_buffer_length,
228 urb->status);
229
230 } else {
231 if (signal_pending(current)) {
232 /* if really an error */
233 if (urb->status && !((urb->status == -ENOENT) ||
234 (urb->status == -ECONNRESET) ||
235 (urb->status == -ESHUTDOWN))) {
236 status = -EINTR;
237 usb_kill_urb(urb);
238 } else {
239 status = 0;
240 }
241
242 dev_dbg(&urb->dev->dev,
243 "%s: signal pending on ep%d%s len=%d/%d,"
244 "urb status = %d\n",
245 current->comm,
246 usb_pipeendpoint(urb->pipe),
247 usb_pipein(urb->pipe) ? "in" : "out",
248 urb->actual_length,
249 urb->transfer_buffer_length,
250 urb->status);
251
252 } else {
253 status = urb->status;
254 }
255 }
256
257 if (actual_length)
258 *actual_length = urb->actual_length;
259
260 return status;
261}
262
263static ssize_t vstusb_read(struct file *file, char __user *buffer,
264 size_t count, loff_t *ppos)
265{
266 struct vstusb_device *vstdev;
267 int cnt = -1;
268 void *buf;
269 int retval = 0;
270
271 struct urb *urb;
272 struct usb_device *dev;
273 unsigned int pipe;
274 int timeout;
275
276 DECLARE_COMPLETION_ONSTACK(done);
277
278 vstdev = file->private_data;
279
280 if (vstdev == NULL)
281 return -ENODEV;
282
283 /* verify that we actually want to read some data */
284 if ((count == 0) || (count > VST_MAXBUFFER))
285 return -EINVAL;
286
287 /* lock this object */
288 if (mutex_lock_interruptible(&vstdev->lock))
289 return -ERESTARTSYS;
290
291 /* anyone home */
292 if (!vstdev->present) {
293 mutex_unlock(&vstdev->lock);
294 printk(KERN_ERR KBUILD_MODNAME
295 ": %s: device not present\n", __func__);
296 return -ENODEV;
297 }
298
299 /* pull out the necessary data */
300 dev = vstdev->usb_dev;
301 pipe = usb_rcvbulkpipe(dev, vstdev->rd_pipe);
302 timeout = vstdev->rd_timeout_ms;
303
304 buf = kmalloc(count, GFP_KERNEL);
305 if (buf == NULL) {
306 mutex_unlock(&vstdev->lock);
307 return -ENOMEM;
308 }
309
310 urb = usb_alloc_urb(0, GFP_KERNEL);
311 if (!urb) {
312 kfree(buf);
313 mutex_unlock(&vstdev->lock);
314 return -ENOMEM;
315 }
316
317 usb_anchor_urb(urb, &vstdev->submitted);
318 retval = vstusb_fill_and_send_urb(urb, dev, pipe, buf, count, &done);
319 mutex_unlock(&vstdev->lock);
320 if (retval) {
321 usb_unanchor_urb(urb);
322 dev_err(&dev->dev, "%s: error %d filling and sending urb %d\n",
323 __func__, retval, pipe);
324 goto exit;
325 }
326
327 retval = vstusb_complete_urb(urb, &done, timeout, &cnt);
328 if (retval) {
329 dev_err(&dev->dev, "%s: error %d completing urb %d\n",
330 __func__, retval, pipe);
331 goto exit;
332 }
333
334 if (copy_to_user(buffer, buf, cnt)) {
335 dev_err(&dev->dev, "%s: can't copy_to_user\n", __func__);
336 retval = -EFAULT;
337 } else {
338 retval = cnt;
339 dev_dbg(&dev->dev, "%s: read %d bytes from pipe %d\n",
340 __func__, cnt, pipe);
341 }
342
343exit:
344 usb_free_urb(urb);
345 kfree(buf);
346 return retval;
347}
348
349static ssize_t vstusb_write(struct file *file, const char __user *buffer,
350 size_t count, loff_t *ppos)
351{
352 struct vstusb_device *vstdev;
353 int cnt = -1;
354 void *buf;
355 int retval = 0;
356
357 struct urb *urb;
358 struct usb_device *dev;
359 unsigned int pipe;
360 int timeout;
361
362 DECLARE_COMPLETION_ONSTACK(done);
363
364 vstdev = file->private_data;
365
366 if (vstdev == NULL)
367 return -ENODEV;
368
369 /* verify that we actually have some data to write */
370 if ((count == 0) || (count > VST_MAXBUFFER))
371 return retval;
372
373 /* lock this object */
374 if (mutex_lock_interruptible(&vstdev->lock))
375 return -ERESTARTSYS;
376
377 /* anyone home */
378 if (!vstdev->present) {
379 mutex_unlock(&vstdev->lock);
380 printk(KERN_ERR KBUILD_MODNAME
381 ": %s: device not present\n", __func__);
382 return -ENODEV;
383 }
384
385 /* pull out the necessary data */
386 dev = vstdev->usb_dev;
387 pipe = usb_sndbulkpipe(dev, vstdev->wr_pipe);
388 timeout = vstdev->wr_timeout_ms;
389
390 buf = kmalloc(count, GFP_KERNEL);
391 if (buf == NULL) {
392 mutex_unlock(&vstdev->lock);
393 return -ENOMEM;
394 }
395
396 urb = usb_alloc_urb(0, GFP_KERNEL);
397 if (!urb) {
398 kfree(buf);
399 mutex_unlock(&vstdev->lock);
400 return -ENOMEM;
401 }
402
403 if (copy_from_user(buf, buffer, count)) {
404 mutex_unlock(&vstdev->lock);
405 dev_err(&dev->dev, "%s: can't copy_from_user\n", __func__);
406 retval = -EFAULT;
407 goto exit;
408 }
409
410 usb_anchor_urb(urb, &vstdev->submitted);
411 retval = vstusb_fill_and_send_urb(urb, dev, pipe, buf, count, &done);
412 mutex_unlock(&vstdev->lock);
413 if (retval) {
414 usb_unanchor_urb(urb);
415 dev_err(&dev->dev, "%s: error %d filling and sending urb %d\n",
416 __func__, retval, pipe);
417 goto exit;
418 }
419
420 retval = vstusb_complete_urb(urb, &done, timeout, &cnt);
421 if (retval) {
422 dev_err(&dev->dev, "%s: error %d completing urb %d\n",
423 __func__, retval, pipe);
424 goto exit;
425 } else {
426 retval = cnt;
427 dev_dbg(&dev->dev, "%s: sent %d bytes to pipe %d\n",
428 __func__, cnt, pipe);
429 }
430
431exit:
432 usb_free_urb(urb);
433 kfree(buf);
434 return retval;
435}
436
437static long vstusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
438{
439 int retval = 0;
440 int cnt = -1;
441 void __user *data = (void __user *)arg;
442 struct vstusb_args usb_data;
443
444 struct vstusb_device *vstdev;
445 void *buffer = NULL; /* must be initialized. buffer is
446 * referenced on exit but not all
447 * ioctls allocate it */
448
449 struct urb *urb = NULL; /* must be initialized. urb is
450 * referenced on exit but not all
451 * ioctls allocate it */
452 struct usb_device *dev;
453 unsigned int pipe;
454 int timeout;
455
456 DECLARE_COMPLETION_ONSTACK(done);
457
458 vstdev = file->private_data;
459
460 if (_IOC_TYPE(cmd) != VST_IOC_MAGIC) {
461 dev_warn(&vstdev->usb_dev->dev,
462 "%s: ioctl command %x, bad ioctl magic %x, "
463 "expected %x\n", __func__, cmd,
464 _IOC_TYPE(cmd), VST_IOC_MAGIC);
465 return -EINVAL;
466 }
467
468 if (vstdev == NULL)
469 return -ENODEV;
470
471 if (copy_from_user(&usb_data, data, sizeof(struct vstusb_args))) {
472 dev_err(&vstdev->usb_dev->dev, "%s: can't copy_from_user\n",
473 __func__);
474 return -EFAULT;
475 }
476
477 /* lock this object */
478 if (mutex_lock_interruptible(&vstdev->lock)) {
479 retval = -ERESTARTSYS;
480 goto exit;
481 }
482
483 /* anyone home */
484 if (!vstdev->present) {
485 mutex_unlock(&vstdev->lock);
486 dev_err(&vstdev->usb_dev->dev, "%s: device not present\n",
487 __func__);
488 retval = -ENODEV;
489 goto exit;
490 }
491
492 /* pull out the necessary data */
493 dev = vstdev->usb_dev;
494
495 switch (cmd) {
496
497 case IOCTL_VSTUSB_CONFIG_RW:
498
499 vstdev->rd_pipe = usb_data.rd_pipe;
500 vstdev->rd_timeout_ms = usb_data.rd_timeout_ms;
501 vstdev->wr_pipe = usb_data.wr_pipe;
502 vstdev->wr_timeout_ms = usb_data.wr_timeout_ms;
503
504 mutex_unlock(&vstdev->lock);
505
506 dev_dbg(&dev->dev, "%s: setting pipes/timeouts, "
507 "rdpipe = %d, rdtimeout = %d, "
508 "wrpipe = %d, wrtimeout = %d\n", __func__,
509 vstdev->rd_pipe, vstdev->rd_timeout_ms,
510 vstdev->wr_pipe, vstdev->wr_timeout_ms);
511 break;
512
513 case IOCTL_VSTUSB_SEND_PIPE:
514
515 if ((usb_data.count == 0) || (usb_data.count > VST_MAXBUFFER)) {
516 mutex_unlock(&vstdev->lock);
517 retval = -EINVAL;
518 goto exit;
519 }
520
521 buffer = kmalloc(usb_data.count, GFP_KERNEL);
522 if (buffer == NULL) {
523 mutex_unlock(&vstdev->lock);
524 retval = -ENOMEM;
525 goto exit;
526 }
527
528 urb = usb_alloc_urb(0, GFP_KERNEL);
529 if (!urb) {
530 mutex_unlock(&vstdev->lock);
531 retval = -ENOMEM;
532 goto exit;
533 }
534
535 timeout = usb_data.timeout_ms;
536
537 pipe = usb_sndbulkpipe(dev, usb_data.pipe);
538
539 if (copy_from_user(buffer, usb_data.buffer, usb_data.count)) {
540 dev_err(&dev->dev, "%s: can't copy_from_user\n",
541 __func__);
542 mutex_unlock(&vstdev->lock);
543 retval = -EFAULT;
544 goto exit;
545 }
546
547 usb_anchor_urb(urb, &vstdev->submitted);
548 retval = vstusb_fill_and_send_urb(urb, dev, pipe, buffer,
549 usb_data.count, &done);
550 mutex_unlock(&vstdev->lock);
551 if (retval) {
552 usb_unanchor_urb(urb);
553 dev_err(&dev->dev,
554 "%s: error %d filling and sending urb %d\n",
555 __func__, retval, pipe);
556 goto exit;
557 }
558
559 retval = vstusb_complete_urb(urb, &done, timeout, &cnt);
560 if (retval) {
561 dev_err(&dev->dev, "%s: error %d completing urb %d\n",
562 __func__, retval, pipe);
563 }
564
565 break;
566 case IOCTL_VSTUSB_RECV_PIPE:
567
568 if ((usb_data.count == 0) || (usb_data.count > VST_MAXBUFFER)) {
569 mutex_unlock(&vstdev->lock);
570 retval = -EINVAL;
571 goto exit;
572 }
573
574 buffer = kmalloc(usb_data.count, GFP_KERNEL);
575 if (buffer == NULL) {
576 mutex_unlock(&vstdev->lock);
577 retval = -ENOMEM;
578 goto exit;
579 }
580
581 urb = usb_alloc_urb(0, GFP_KERNEL);
582 if (!urb) {
583 mutex_unlock(&vstdev->lock);
584 retval = -ENOMEM;
585 goto exit;
586 }
587
588 timeout = usb_data.timeout_ms;
589
590 pipe = usb_rcvbulkpipe(dev, usb_data.pipe);
591
592 usb_anchor_urb(urb, &vstdev->submitted);
593 retval = vstusb_fill_and_send_urb(urb, dev, pipe, buffer,
594 usb_data.count, &done);
595 mutex_unlock(&vstdev->lock);
596 if (retval) {
597 usb_unanchor_urb(urb);
598 dev_err(&dev->dev,
599 "%s: error %d filling and sending urb %d\n",
600 __func__, retval, pipe);
601 goto exit;
602 }
603
604 retval = vstusb_complete_urb(urb, &done, timeout, &cnt);
605 if (retval) {
606 dev_err(&dev->dev, "%s: error %d completing urb %d\n",
607 __func__, retval, pipe);
608 goto exit;
609 }
610
611 if (copy_to_user(usb_data.buffer, buffer, cnt)) {
612 dev_err(&dev->dev, "%s: can't copy_to_user\n",
613 __func__);
614 retval = -EFAULT;
615 goto exit;
616 }
617
618 usb_data.count = cnt;
619 if (copy_to_user(data, &usb_data, sizeof(struct vstusb_args))) {
620 dev_err(&dev->dev, "%s: can't copy_to_user\n",
621 __func__);
622 retval = -EFAULT;
623 } else {
624 dev_dbg(&dev->dev, "%s: recv %zd bytes from pipe %d\n",
625 __func__, usb_data.count, usb_data.pipe);
626 }
627
628 break;
629
630 default:
631 mutex_unlock(&vstdev->lock);
632 dev_warn(&dev->dev, "ioctl_vstusb: invalid ioctl cmd %x\n",
633 cmd);
634 return -EINVAL;
635 break;
636 }
637exit:
638 usb_free_urb(urb);
639 kfree(buffer);
640 return retval;
641}
642
643static const struct file_operations vstusb_fops = {
644 .owner = THIS_MODULE,
645 .read = vstusb_read,
646 .write = vstusb_write,
647 .unlocked_ioctl = vstusb_ioctl,
648 .compat_ioctl = vstusb_ioctl,
649 .open = vstusb_open,
650 .release = vstusb_release,
651};
652
653static struct usb_class_driver usb_vstusb_class = {
654 .name = "usb/vstusb%d",
655 .fops = &vstusb_fops,
656 .minor_base = VSTUSB_MINOR_BASE,
657};
658
659static int vstusb_probe(struct usb_interface *intf,
660 const struct usb_device_id *id)
661{
662 struct usb_device *dev = interface_to_usbdev(intf);
663 struct vstusb_device *vstdev;
664 int i;
665 int retval = 0;
666
667 /* allocate memory for our device state and intialize it */
668
669 vstdev = kzalloc(sizeof(*vstdev), GFP_KERNEL);
670 if (vstdev == NULL)
671 return -ENOMEM;
672
673 /* must do usb_get_dev() prior to kref_init() since the kref_put()
674 * release function will do a usb_put_dev() */
675 usb_get_dev(dev);
676 kref_init(&vstdev->kref);
677 mutex_init(&vstdev->lock);
678
679 i = dev->descriptor.bcdDevice;
680
681 dev_dbg(&intf->dev, "Version %1d%1d.%1d%1d found at address %d\n",
682 (i & 0xF000) >> 12, (i & 0xF00) >> 8,
683 (i & 0xF0) >> 4, (i & 0xF), dev->devnum);
684
685 vstdev->present = 1;
686 vstdev->isopen = 0;
687 vstdev->usb_dev = dev;
688 init_usb_anchor(&vstdev->submitted);
689
690 usb_set_intfdata(intf, vstdev);
691 retval = usb_register_dev(intf, &usb_vstusb_class);
692 if (retval) {
693 dev_err(&intf->dev,
694 "%s: Not able to get a minor for this device.\n",
695 __func__);
696 usb_set_intfdata(intf, NULL);
697 kref_put(&vstdev->kref, vstusb_delete);
698 return retval;
699 }
700
701 /* let the user know what node this device is now attached to */
702 dev_info(&intf->dev,
703 "VST USB Device #%d now attached to major %d minor %d\n",
704 (intf->minor - VSTUSB_MINOR_BASE), USB_MAJOR, intf->minor);
705
706 dev_info(&intf->dev, "%s, %s\n", DRIVER_DESC, DRIVER_VERSION);
707
708 return retval;
709}
710
711static void vstusb_disconnect(struct usb_interface *intf)
712{
713 struct vstusb_device *vstdev = usb_get_intfdata(intf);
714
715 usb_deregister_dev(intf, &usb_vstusb_class);
716 usb_set_intfdata(intf, NULL);
717
718 if (vstdev) {
719
720 mutex_lock(&vstdev->lock);
721 vstdev->present = 0;
722
723 usb_kill_anchored_urbs(&vstdev->submitted);
724
725 mutex_unlock(&vstdev->lock);
726
727 kref_put(&vstdev->kref, vstusb_delete);
728 }
729
730}
731
732static int vstusb_suspend(struct usb_interface *intf, pm_message_t message)
733{
734 struct vstusb_device *vstdev = usb_get_intfdata(intf);
735 int time;
736 if (!vstdev)
737 return 0;
738
739 mutex_lock(&vstdev->lock);
740 time = usb_wait_anchor_empty_timeout(&vstdev->submitted, 1000);
741 if (!time)
742 usb_kill_anchored_urbs(&vstdev->submitted);
743 mutex_unlock(&vstdev->lock);
744
745 return 0;
746}
747
748static int vstusb_resume(struct usb_interface *intf)
749{
750 return 0;
751}
752
753static struct usb_driver vstusb_driver = {
754 .name = "vstusb",
755 .probe = vstusb_probe,
756 .disconnect = vstusb_disconnect,
757 .suspend = vstusb_suspend,
758 .resume = vstusb_resume,
759 .id_table = id_table,
760};
761
762static int __init vstusb_init(void)
763{
764 int rc;
765
766 rc = usb_register(&vstusb_driver);
767 if (rc)
768 printk(KERN_ERR "%s: failed to register (%d)", __func__, rc);
769
770 return rc;
771}
772
773static void __exit vstusb_exit(void)
774{
775 usb_deregister(&vstusb_driver);
776}
777
778module_init(vstusb_init);
779module_exit(vstusb_exit);
780
781MODULE_AUTHOR("Dennis O'Brien/Stephen Ware");
782MODULE_DESCRIPTION(DRIVER_VERSION);
783MODULE_LICENSE("GPL");
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 10f3205798e8..ddf7f9a1b336 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -16,6 +16,8 @@
16#include <linux/compat.h> 16#include <linux/compat.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/smp_lock.h> 18#include <linux/smp_lock.h>
19#include <linux/scatterlist.h>
20#include <linux/slab.h>
19 21
20#include <asm/uaccess.h> 22#include <asm/uaccess.h>
21 23
@@ -221,7 +223,7 @@ static void mon_free_buff(struct mon_pgmap *map, int npages);
221/* 223/*
222 * This is a "chunked memcpy". It does not manipulate any counters. 224 * This is a "chunked memcpy". It does not manipulate any counters.
223 */ 225 */
224static void mon_copy_to_buff(const struct mon_reader_bin *this, 226static unsigned int mon_copy_to_buff(const struct mon_reader_bin *this,
225 unsigned int off, const unsigned char *from, unsigned int length) 227 unsigned int off, const unsigned char *from, unsigned int length)
226{ 228{
227 unsigned int step_len; 229 unsigned int step_len;
@@ -246,6 +248,7 @@ static void mon_copy_to_buff(const struct mon_reader_bin *this,
246 from += step_len; 248 from += step_len;
247 length -= step_len; 249 length -= step_len;
248 } 250 }
251 return off;
249} 252}
250 253
251/* 254/*
@@ -394,14 +397,44 @@ static inline char mon_bin_get_setup(unsigned char *setupb,
394 return 0; 397 return 0;
395} 398}
396 399
397static char mon_bin_get_data(const struct mon_reader_bin *rp, 400static unsigned int mon_bin_get_data(const struct mon_reader_bin *rp,
398 unsigned int offset, struct urb *urb, unsigned int length) 401 unsigned int offset, struct urb *urb, unsigned int length,
402 char *flag)
399{ 403{
404 int i;
405 struct scatterlist *sg;
406 unsigned int this_len;
407
408 *flag = 0;
409 if (urb->num_sgs == 0) {
410 if (urb->transfer_buffer == NULL) {
411 *flag = 'Z';
412 return length;
413 }
414 mon_copy_to_buff(rp, offset, urb->transfer_buffer, length);
415 length = 0;
400 416
401 if (urb->transfer_buffer == NULL) 417 } else {
402 return 'Z'; 418 /* If IOMMU coalescing occurred, we cannot trust sg_page */
403 mon_copy_to_buff(rp, offset, urb->transfer_buffer, length); 419 if (urb->sg->nents != urb->num_sgs) {
404 return 0; 420 *flag = 'D';
421 return length;
422 }
423
424 /* Copy up to the first non-addressable segment */
425 for_each_sg(urb->sg->sg, sg, urb->num_sgs, i) {
426 if (length == 0 || PageHighMem(sg_page(sg)))
427 break;
428 this_len = min_t(unsigned int, sg->length, length);
429 offset = mon_copy_to_buff(rp, offset, sg_virt(sg),
430 this_len);
431 length -= this_len;
432 }
433 if (i == 0)
434 *flag = 'D';
435 }
436
437 return length;
405} 438}
406 439
407static void mon_bin_get_isodesc(const struct mon_reader_bin *rp, 440static void mon_bin_get_isodesc(const struct mon_reader_bin *rp,
@@ -428,8 +461,8 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
428 char ev_type, int status) 461 char ev_type, int status)
429{ 462{
430 const struct usb_endpoint_descriptor *epd = &urb->ep->desc; 463 const struct usb_endpoint_descriptor *epd = &urb->ep->desc;
431 unsigned long flags;
432 struct timeval ts; 464 struct timeval ts;
465 unsigned long flags;
433 unsigned int urb_length; 466 unsigned int urb_length;
434 unsigned int offset; 467 unsigned int offset;
435 unsigned int length; 468 unsigned int length;
@@ -536,8 +569,9 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
536 } 569 }
537 570
538 if (length != 0) { 571 if (length != 0) {
539 ep->flag_data = mon_bin_get_data(rp, offset, urb, length); 572 length = mon_bin_get_data(rp, offset, urb, length,
540 if (ep->flag_data != 0) { /* Yes, it's 0x00, not '0' */ 573 &ep->flag_data);
574 if (length > 0) {
541 delta = (ep->len_cap + PKT_ALIGN-1) & ~(PKT_ALIGN-1); 575 delta = (ep->len_cap + PKT_ALIGN-1) & ~(PKT_ALIGN-1);
542 ep->len_cap -= length; 576 ep->len_cap -= length;
543 delta -= (ep->len_cap + PKT_ALIGN-1) & ~(PKT_ALIGN-1); 577 delta -= (ep->len_cap + PKT_ALIGN-1) & ~(PKT_ALIGN-1);
@@ -567,10 +601,13 @@ static void mon_bin_complete(void *data, struct urb *urb, int status)
567static void mon_bin_error(void *data, struct urb *urb, int error) 601static void mon_bin_error(void *data, struct urb *urb, int error)
568{ 602{
569 struct mon_reader_bin *rp = data; 603 struct mon_reader_bin *rp = data;
604 struct timeval ts;
570 unsigned long flags; 605 unsigned long flags;
571 unsigned int offset; 606 unsigned int offset;
572 struct mon_bin_hdr *ep; 607 struct mon_bin_hdr *ep;
573 608
609 do_gettimeofday(&ts);
610
574 spin_lock_irqsave(&rp->b_lock, flags); 611 spin_lock_irqsave(&rp->b_lock, flags);
575 612
576 offset = mon_buff_area_alloc(rp, PKT_SIZE); 613 offset = mon_buff_area_alloc(rp, PKT_SIZE);
@@ -590,6 +627,8 @@ static void mon_bin_error(void *data, struct urb *urb, int error)
590 ep->devnum = urb->dev->devnum; 627 ep->devnum = urb->dev->devnum;
591 ep->busnum = urb->dev->bus->busnum; 628 ep->busnum = urb->dev->bus->busnum;
592 ep->id = (unsigned long) urb; 629 ep->id = (unsigned long) urb;
630 ep->ts_sec = ts.tv_sec;
631 ep->ts_usec = ts.tv_usec;
593 ep->status = error; 632 ep->status = error;
594 633
595 ep->flag_setup = '-'; 634 ep->flag_setup = '-';
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index e0c2db3b767b..e4af18b93c7d 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -9,6 +9,7 @@
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/slab.h>
12#include <linux/notifier.h> 13#include <linux/notifier.h>
13#include <linux/mutex.h> 14#include <linux/mutex.h>
14 15
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index ac8b0d5ce7f8..1becdc3837e6 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/slab.h>
11#include <linux/usb.h> 12#include <linux/usb.h>
12#include <linux/fs.h> 13#include <linux/fs.h>
13#include <asm/uaccess.h> 14#include <asm/uaccess.h>
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 9f1a9227ebe6..4d0be130f49b 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -7,9 +7,11 @@
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/usb.h> 9#include <linux/usb.h>
10#include <linux/slab.h>
10#include <linux/time.h> 11#include <linux/time.h>
11#include <linux/mutex.h> 12#include <linux/mutex.h>
12#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/scatterlist.h>
13#include <asm/uaccess.h> 15#include <asm/uaccess.h>
14 16
15#include "usb_mon.h" 17#include "usb_mon.h"
@@ -137,6 +139,8 @@ static inline char mon_text_get_setup(struct mon_event_text *ep,
137static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, 139static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
138 int len, char ev_type, struct mon_bus *mbus) 140 int len, char ev_type, struct mon_bus *mbus)
139{ 141{
142 void *src;
143
140 if (len <= 0) 144 if (len <= 0)
141 return 'L'; 145 return 'L';
142 if (len >= DATA_MAX) 146 if (len >= DATA_MAX)
@@ -150,10 +154,24 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
150 return '>'; 154 return '>';
151 } 155 }
152 156
153 if (urb->transfer_buffer == NULL) 157 if (urb->num_sgs == 0) {
154 return 'Z'; /* '0' would be not as pretty. */ 158 src = urb->transfer_buffer;
159 if (src == NULL)
160 return 'Z'; /* '0' would be not as pretty. */
161 } else {
162 struct scatterlist *sg = urb->sg->sg;
163
164 /* If IOMMU coalescing occurred, we cannot trust sg_page */
165 if (urb->sg->nents != urb->num_sgs ||
166 PageHighMem(sg_page(sg)))
167 return 'D';
155 168
156 memcpy(ep->data, urb->transfer_buffer, len); 169 /* For the text interface we copy only the first sg buffer */
170 len = min_t(int, sg->length, len);
171 src = sg_virt(sg);
172 }
173
174 memcpy(ep->data, src, len);
157 return 0; 175 return 0;
158} 176}
159 177
@@ -163,7 +181,7 @@ static inline unsigned int mon_get_timestamp(void)
163 unsigned int stamp; 181 unsigned int stamp;
164 182
165 do_gettimeofday(&tval); 183 do_gettimeofday(&tval);
166 stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s. */ 184 stamp = tval.tv_sec & 0xFFF; /* 2^32 = 4294967296. Limit to 4096s. */
167 stamp = stamp * 1000000 + tval.tv_usec; 185 stamp = stamp * 1000000 + tval.tv_usec;
168 return stamp; 186 return stamp;
169} 187}
@@ -256,12 +274,12 @@ static void mon_text_error(void *data, struct urb *urb, int error)
256 274
257 ep->type = 'E'; 275 ep->type = 'E';
258 ep->id = (unsigned long) urb; 276 ep->id = (unsigned long) urb;
259 ep->busnum = 0; 277 ep->busnum = urb->dev->bus->busnum;
260 ep->devnum = urb->dev->devnum; 278 ep->devnum = urb->dev->devnum;
261 ep->epnum = usb_endpoint_num(&urb->ep->desc); 279 ep->epnum = usb_endpoint_num(&urb->ep->desc);
262 ep->xfertype = usb_endpoint_type(&urb->ep->desc); 280 ep->xfertype = usb_endpoint_type(&urb->ep->desc);
263 ep->is_in = usb_urb_dir_in(urb); 281 ep->is_in = usb_urb_dir_in(urb);
264 ep->tstamp = 0; 282 ep->tstamp = mon_get_timestamp();
265 ep->length = 0; 283 ep->length = 0;
266 ep->status = error; 284 ep->status = error;
267 285
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index b84abd8ee8a5..07fe490b44d8 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -9,10 +9,9 @@ comment "Enable Host or Gadget support to see Inventra options"
9# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller 9# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
10config USB_MUSB_HDRC 10config USB_MUSB_HDRC
11 depends on (USB || USB_GADGET) 11 depends on (USB || USB_GADGET)
12 depends on (ARM || BLACKFIN) 12 depends on (ARM || (BF54x && !BF544) || (BF52x && !BF522 && !BF523))
13 select NOP_USB_XCEIV if ARCH_DAVINCI 13 select NOP_USB_XCEIV if (ARCH_DAVINCI || MACH_OMAP3EVM || BLACKFIN)
14 select TWL4030_USB if MACH_OMAP_3430SDP 14 select TWL4030_USB if MACH_OMAP_3430SDP
15 select NOP_USB_XCEIV if MACH_OMAP3EVM
16 select USB_OTG_UTILS 15 select USB_OTG_UTILS
17 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 16 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
18 help 17 help
@@ -38,18 +37,18 @@ config USB_MUSB_SOC
38 depends on USB_MUSB_HDRC 37 depends on USB_MUSB_HDRC
39 default y if ARCH_DAVINCI 38 default y if ARCH_DAVINCI
40 default y if ARCH_OMAP2430 39 default y if ARCH_OMAP2430
41 default y if ARCH_OMAP34XX 40 default y if ARCH_OMAP3
42 default y if (BF54x && !BF544) 41 default y if (BF54x && !BF544)
43 default y if (BF52x && !BF522 && !BF523) 42 default y if (BF52x && !BF522 && !BF523)
44 43
45comment "DaVinci 35x and 644x USB support" 44comment "DaVinci 35x and 644x USB support"
46 depends on USB_MUSB_HDRC && ARCH_DAVINCI 45 depends on USB_MUSB_HDRC && ARCH_DAVINCI_DMx
47 46
48comment "OMAP 243x high speed USB support" 47comment "OMAP 243x high speed USB support"
49 depends on USB_MUSB_HDRC && ARCH_OMAP2430 48 depends on USB_MUSB_HDRC && ARCH_OMAP2430
50 49
51comment "OMAP 343x high speed USB support" 50comment "OMAP 343x high speed USB support"
52 depends on USB_MUSB_HDRC && ARCH_OMAP34XX 51 depends on USB_MUSB_HDRC && ARCH_OMAP3
53 52
54comment "Blackfin high speed USB Support" 53comment "Blackfin high speed USB Support"
55 depends on USB_MUSB_HDRC && ((BF54x && !BF544) || (BF52x && !BF522 && !BF523)) 54 depends on USB_MUSB_HDRC && ((BF54x && !BF544) || (BF52x && !BF522 && !BF523))
@@ -154,7 +153,7 @@ config MUSB_PIO_ONLY
154config USB_INVENTRA_DMA 153config USB_INVENTRA_DMA
155 bool 154 bool
156 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY 155 depends on USB_MUSB_HDRC && !MUSB_PIO_ONLY
157 default ARCH_OMAP2430 || ARCH_OMAP34XX || BLACKFIN 156 default ARCH_OMAP2430 || ARCH_OMAP3 || BLACKFIN
158 help 157 help
159 Enable DMA transfers using Mentor's engine. 158 Enable DMA transfers using Mentor's engine.
160 159
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index 85710ccc1887..3a485dabebbb 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -6,7 +6,7 @@ musb_hdrc-objs := musb_core.o
6 6
7obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o 7obj-$(CONFIG_USB_MUSB_HDRC) += musb_hdrc.o
8 8
9ifeq ($(CONFIG_ARCH_DAVINCI),y) 9ifeq ($(CONFIG_ARCH_DAVINCI_DMx),y)
10 musb_hdrc-objs += davinci.o 10 musb_hdrc-objs += davinci.o
11endif 11endif
12 12
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index fcec87ea709e..ec8d324237f6 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/slab.h>
15#include <linux/init.h> 14#include <linux/init.h>
16#include <linux/list.h> 15#include <linux/list.h>
17#include <linux/gpio.h> 16#include <linux/gpio.h>
@@ -29,6 +28,7 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
29{ 28{
30 void __iomem *fifo = hw_ep->fifo; 29 void __iomem *fifo = hw_ep->fifo;
31 void __iomem *epio = hw_ep->regs; 30 void __iomem *epio = hw_ep->regs;
31 u8 epnum = hw_ep->epnum;
32 32
33 prefetch((u8 *)src); 33 prefetch((u8 *)src);
34 34
@@ -39,14 +39,51 @@ void musb_write_fifo(struct musb_hw_ep *hw_ep, u16 len, const u8 *src)
39 39
40 dump_fifo_data(src, len); 40 dump_fifo_data(src, len);
41 41
42 if (unlikely((unsigned long)src & 0x01)) 42 if (!ANOMALY_05000380 && epnum != 0) {
43 outsw_8((unsigned long)fifo, src, 43 u16 dma_reg;
44 len & 0x01 ? (len >> 1) + 1 : len >> 1); 44
45 else 45 flush_dcache_range((unsigned long)src,
46 outsw((unsigned long)fifo, src, 46 (unsigned long)(src + len));
47 len & 0x01 ? (len >> 1) + 1 : len >> 1); 47
48} 48 /* Setup DMA address register */
49 dma_reg = (u32)src;
50 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_LOW), dma_reg);
51 SSYNC();
52
53 dma_reg = (u32)src >> 16;
54 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_HIGH), dma_reg);
55 SSYNC();
56
57 /* Setup DMA count register */
58 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_LOW), len);
59 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_HIGH), 0);
60 SSYNC();
61
62 /* Enable the DMA */
63 dma_reg = (epnum << 4) | DMA_ENA | INT_ENA | DIRECTION;
64 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg);
65 SSYNC();
66
67 /* Wait for compelete */
68 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum)))
69 cpu_relax();
70
71 /* acknowledge dma interrupt */
72 bfin_write_USB_DMA_INTERRUPT(1 << epnum);
73 SSYNC();
49 74
75 /* Reset DMA */
76 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), 0);
77 SSYNC();
78 } else {
79 SSYNC();
80
81 if (unlikely((unsigned long)src & 0x01))
82 outsw_8((unsigned long)fifo, src, (len + 1) >> 1);
83 else
84 outsw((unsigned long)fifo, src, (len + 1) >> 1);
85 }
86}
50/* 87/*
51 * Unload an endpoint's FIFO 88 * Unload an endpoint's FIFO
52 */ 89 */
@@ -54,53 +91,62 @@ void musb_read_fifo(struct musb_hw_ep *hw_ep, u16 len, u8 *dst)
54{ 91{
55 void __iomem *fifo = hw_ep->fifo; 92 void __iomem *fifo = hw_ep->fifo;
56 u8 epnum = hw_ep->epnum; 93 u8 epnum = hw_ep->epnum;
57 u16 dma_reg = 0;
58 94
59 DBG(4, "%cX ep%d fifo %p count %d buf %p\n", 95 if (ANOMALY_05000467 && epnum != 0) {
60 'R', hw_ep->epnum, fifo, len, dst); 96 u16 dma_reg;
61 97
62#ifdef CONFIG_BF52x 98 invalidate_dcache_range((unsigned long)dst,
63 invalidate_dcache_range((unsigned int)dst, 99 (unsigned long)(dst + len));
64 (unsigned int)(dst + len));
65 100
66 /* Setup DMA address register */ 101 /* Setup DMA address register */
67 dma_reg = (u16) ((u32) dst & 0xFFFF); 102 dma_reg = (u32)dst;
68 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_LOW), dma_reg); 103 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_LOW), dma_reg);
69 SSYNC(); 104 SSYNC();
70 105
71 dma_reg = (u16) (((u32) dst >> 16) & 0xFFFF); 106 dma_reg = (u32)dst >> 16;
72 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_HIGH), dma_reg); 107 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_ADDR_HIGH), dma_reg);
73 SSYNC(); 108 SSYNC();
74 109
75 /* Setup DMA count register */ 110 /* Setup DMA count register */
76 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_LOW), len); 111 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_LOW), len);
77 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_HIGH), 0); 112 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_COUNT_HIGH), 0);
78 SSYNC(); 113 SSYNC();
79 114
80 /* Enable the DMA */ 115 /* Enable the DMA */
81 dma_reg = (epnum << 4) | DMA_ENA | INT_ENA; 116 dma_reg = (epnum << 4) | DMA_ENA | INT_ENA;
82 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg); 117 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), dma_reg);
83 SSYNC(); 118 SSYNC();
84 119
85 /* Wait for compelete */ 120 /* Wait for compelete */
86 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum))) 121 while (!(bfin_read_USB_DMA_INTERRUPT() & (1 << epnum)))
87 cpu_relax(); 122 cpu_relax();
88 123
89 /* acknowledge dma interrupt */ 124 /* acknowledge dma interrupt */
90 bfin_write_USB_DMA_INTERRUPT(1 << epnum); 125 bfin_write_USB_DMA_INTERRUPT(1 << epnum);
91 SSYNC(); 126 SSYNC();
92 127
93 /* Reset DMA */ 128 /* Reset DMA */
94 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), 0); 129 bfin_write16(USB_DMA_REG(epnum, USB_DMAx_CTRL), 0);
95 SSYNC(); 130 SSYNC();
96#else 131 } else {
97 if (unlikely((unsigned long)dst & 0x01)) 132 SSYNC();
98 insw_8((unsigned long)fifo, dst, 133 /* Read the last byte of packet with odd size from address fifo + 4
99 len & 0x01 ? (len >> 1) + 1 : len >> 1); 134 * to trigger 1 byte access to EP0 FIFO.
100 else 135 */
101 insw((unsigned long)fifo, dst, 136 if (len == 1)
102 len & 0x01 ? (len >> 1) + 1 : len >> 1); 137 *dst = (u8)inw((unsigned long)fifo + 4);
103#endif 138 else {
139 if (unlikely((unsigned long)dst & 0x01))
140 insw_8((unsigned long)fifo, dst, len >> 1);
141 else
142 insw((unsigned long)fifo, dst, len >> 1);
143
144 if (len & 0x01)
145 *(dst + len - 1) = (u8)inw((unsigned long)fifo + 4);
146 }
147 }
148 DBG(4, "%cX ep%d fifo %p count %d buf %p\n",
149 'R', hw_ep->epnum, fifo, len, dst);
104 150
105 dump_fifo_data(dst, len); 151 dump_fifo_data(dst, len);
106} 152}
@@ -126,13 +172,7 @@ static irqreturn_t blackfin_interrupt(int irq, void *__hci)
126 172
127 spin_unlock_irqrestore(&musb->lock, flags); 173 spin_unlock_irqrestore(&musb->lock, flags);
128 174
129 /* REVISIT we sometimes get spurious IRQs on g_ep0 175 return retval;
130 * not clear why... fall in BF54x too.
131 */
132 if (retval != IRQ_HANDLED)
133 DBG(5, "spurious?\n");
134
135 return IRQ_HANDLED;
136} 176}
137 177
138static void musb_conn_timer_handler(unsigned long _musb) 178static void musb_conn_timer_handler(unsigned long _musb)
@@ -225,8 +265,9 @@ int musb_platform_get_vbus_status(struct musb *musb)
225 return 0; 265 return 0;
226} 266}
227 267
228void musb_platform_set_mode(struct musb *musb, u8 musb_mode) 268int musb_platform_set_mode(struct musb *musb, u8 musb_mode)
229{ 269{
270 return -EIO;
230} 271}
231 272
232int __init musb_platform_init(struct musb *musb) 273int __init musb_platform_init(struct musb *musb)
@@ -261,10 +302,6 @@ int __init musb_platform_init(struct musb *musb)
261 SSYNC(); 302 SSYNC();
262 } 303 }
263 304
264 /* TODO
265 * Set SIC-IVG register
266 */
267
268 /* Configure PLL oscillator register */ 305 /* Configure PLL oscillator register */
269 bfin_write_USB_PLLOSC_CTRL(0x30a8); 306 bfin_write_USB_PLLOSC_CTRL(0x30a8);
270 SSYNC(); 307 SSYNC();
diff --git a/drivers/usb/musb/blackfin.h b/drivers/usb/musb/blackfin.h
index a240c1e53d16..bd9352a2ef2a 100644
--- a/drivers/usb/musb/blackfin.h
+++ b/drivers/usb/musb/blackfin.h
@@ -14,6 +14,43 @@
14 * Blackfin specific definitions 14 * Blackfin specific definitions
15 */ 15 */
16 16
17/* Anomalies notes:
18 *
19 * 05000450 - USB DMA Mode 1 Short Packet Data Corruption:
20 * MUSB driver is designed to transfer buffer of N * maxpacket size
21 * in DMA mode 1 and leave the rest of the data to the next
22 * transfer in DMA mode 0, so we never transmit a short packet in
23 * DMA mode 1.
24 *
25 * 05000463 - This anomaly doesn't affect this driver since it
26 * never uses L1 or L2 memory as data destination.
27 *
28 * 05000464 - This anomaly doesn't affect this driver since it
29 * never uses L1 or L2 memory as data source.
30 *
31 * 05000465 - The anomaly can be seen when SCLK is over 100 MHz, and there is
32 * no way to workaround for bulk endpoints. Since the wMaxPackSize
33 * of bulk is less than or equal to 512, while the fifo size of
34 * endpoint 5, 6, 7 is 1024, the double buffer mode is enabled
35 * automatically when these endpoints are used for bulk OUT.
36 *
37 * 05000466 - This anomaly doesn't affect this driver since it never mixes
38 * concurrent DMA and core accesses to the TX endpoint FIFOs.
39 *
40 * 05000467 - The workaround for this anomaly will introduce another
41 * anomaly - 05000465.
42 */
43
44/* The Mentor USB DMA engine on BF52x (silicon v0.0 and v0.1) seems to be
45 * unstable in host mode. This may be caused by Anomaly 05000380. After
46 * digging out the root cause, we will change this number accordingly.
47 * So, need to either use silicon v0.2+ or disable DMA mode in MUSB.
48 */
49#if ANOMALY_05000380 && defined(CONFIG_BF52x) && \
50 defined(CONFIG_USB_MUSB_HDRC) && !defined(CONFIG_MUSB_PIO_ONLY)
51# error "Please use PIO mode in MUSB driver on bf52x chip v0.0 and v0.1"
52#endif
53
17#undef DUMP_FIFO_DATA 54#undef DUMP_FIFO_DATA
18#ifdef DUMP_FIFO_DATA 55#ifdef DUMP_FIFO_DATA
19static void dump_fifo_data(u8 *buf, u16 len) 56static void dump_fifo_data(u8 *buf, u16 len)
@@ -32,7 +69,6 @@ static void dump_fifo_data(u8 *buf, u16 len)
32#define dump_fifo_data(buf, len) do {} while (0) 69#define dump_fifo_data(buf, len) do {} while (0)
33#endif 70#endif
34 71
35#ifdef CONFIG_BF52x
36 72
37#define USB_DMA_BASE USB_DMA_INTERRUPT 73#define USB_DMA_BASE USB_DMA_INTERRUPT
38#define USB_DMAx_CTRL 0x04 74#define USB_DMAx_CTRL 0x04
@@ -42,7 +78,6 @@ static void dump_fifo_data(u8 *buf, u16 len)
42#define USB_DMAx_COUNT_HIGH 0x14 78#define USB_DMAx_COUNT_HIGH 0x14
43 79
44#define USB_DMA_REG(ep, reg) (USB_DMA_BASE + 0x20 * ep + reg) 80#define USB_DMA_REG(ep, reg) (USB_DMA_BASE + 0x20 * ep + reg)
45#endif
46 81
47/* Almost 1 second */ 82/* Almost 1 second */
48#define TIMER_DELAY (1 * HZ) 83#define TIMER_DELAY (1 * HZ)
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index ef2332a9941d..59dc3d351b60 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/platform_device.h> 9#include <linux/platform_device.h>
10#include <linux/slab.h>
10#include <linux/usb.h> 11#include <linux/usb.h>
11 12
12#include "musb_core.h" 13#include "musb_core.h"
@@ -1154,8 +1155,11 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1154 struct musb_hw_ep *hw_ep = NULL; 1155 struct musb_hw_ep *hw_ep = NULL;
1155 u32 rx, tx; 1156 u32 rx, tx;
1156 int i, index; 1157 int i, index;
1158 unsigned long flags;
1157 1159
1158 cppi = container_of(musb->dma_controller, struct cppi, controller); 1160 cppi = container_of(musb->dma_controller, struct cppi, controller);
1161 if (cppi->irq)
1162 spin_lock_irqsave(&musb->lock, flags);
1159 1163
1160 tibase = musb->ctrl_base; 1164 tibase = musb->ctrl_base;
1161 1165
@@ -1188,8 +1192,13 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1188 1192
1189 bd = tx_ch->head; 1193 bd = tx_ch->head;
1190 1194
1195 /*
1196 * If Head is null then this could mean that a abort interrupt
1197 * that needs to be acknowledged.
1198 */
1191 if (NULL == bd) { 1199 if (NULL == bd) {
1192 DBG(1, "null BD\n"); 1200 DBG(1, "null BD\n");
1201 tx_ram->tx_complete = 0;
1193 continue; 1202 continue;
1194 } 1203 }
1195 1204
@@ -1285,6 +1294,9 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id)
1285 /* write to CPPI EOI register to re-enable interrupts */ 1294 /* write to CPPI EOI register to re-enable interrupts */
1286 musb_writel(tibase, DAVINCI_CPPI_EOI_REG, 0); 1295 musb_writel(tibase, DAVINCI_CPPI_EOI_REG, 0);
1287 1296
1297 if (cppi->irq)
1298 spin_unlock_irqrestore(&musb->lock, flags);
1299
1288 return IRQ_HANDLED; 1300 return IRQ_HANDLED;
1289} 1301}
1290 1302
@@ -1406,15 +1418,6 @@ static int cppi_channel_abort(struct dma_channel *channel)
1406 1418
1407 if (cppi_ch->transmit) { 1419 if (cppi_ch->transmit) {
1408 struct cppi_tx_stateram __iomem *tx_ram; 1420 struct cppi_tx_stateram __iomem *tx_ram;
1409 int enabled;
1410
1411 /* mask interrupts raised to signal teardown complete. */
1412 enabled = musb_readl(tibase, DAVINCI_TXCPPI_INTENAB_REG)
1413 & (1 << cppi_ch->index);
1414 if (enabled)
1415 musb_writel(tibase, DAVINCI_TXCPPI_INTCLR_REG,
1416 (1 << cppi_ch->index));
1417
1418 /* REVISIT put timeouts on these controller handshakes */ 1421 /* REVISIT put timeouts on these controller handshakes */
1419 1422
1420 cppi_dump_tx(6, cppi_ch, " (teardown)"); 1423 cppi_dump_tx(6, cppi_ch, " (teardown)");
@@ -1429,7 +1432,6 @@ static int cppi_channel_abort(struct dma_channel *channel)
1429 do { 1432 do {
1430 value = musb_readl(&tx_ram->tx_complete, 0); 1433 value = musb_readl(&tx_ram->tx_complete, 0);
1431 } while (0xFFFFFFFC != value); 1434 } while (0xFFFFFFFC != value);
1432 musb_writel(&tx_ram->tx_complete, 0, 0xFFFFFFFC);
1433 1435
1434 /* FIXME clean up the transfer state ... here? 1436 /* FIXME clean up the transfer state ... here?
1435 * the completion routine should get called with 1437 * the completion routine should get called with
@@ -1442,23 +1444,15 @@ static int cppi_channel_abort(struct dma_channel *channel)
1442 musb_writew(regs, MUSB_TXCSR, value); 1444 musb_writew(regs, MUSB_TXCSR, value);
1443 musb_writew(regs, MUSB_TXCSR, value); 1445 musb_writew(regs, MUSB_TXCSR, value);
1444 1446
1445 /* While we scrub the TX state RAM, ensure that we clean 1447 /*
1446 * up any interrupt that's currently asserted:
1447 * 1. Write to completion Ptr value 0x1(bit 0 set) 1448 * 1. Write to completion Ptr value 0x1(bit 0 set)
1448 * (write back mode) 1449 * (write back mode)
1449 * 2. Write to completion Ptr value 0x0(bit 0 cleared) 1450 * 2. Wait for abort interrupt and then put the channel in
1450 * (compare mode) 1451 * compare mode by writing 1 to the tx_complete register.
1451 * Value written is compared(for bits 31:2) and when
1452 * equal, interrupt is deasserted.
1453 */ 1452 */
1454 cppi_reset_tx(tx_ram, 1); 1453 cppi_reset_tx(tx_ram, 1);
1455 musb_writel(&tx_ram->tx_complete, 0, 0); 1454 cppi_ch->head = 0;
1456 1455 musb_writel(&tx_ram->tx_complete, 0, 1);
1457 /* re-enable interrupt */
1458 if (enabled)
1459 musb_writel(tibase, DAVINCI_TXCPPI_INTENAB_REG,
1460 (1 << cppi_ch->index));
1461
1462 cppi_dump_tx(5, cppi_ch, " (done teardown)"); 1456 cppi_dump_tx(5, cppi_ch, " (done teardown)");
1463 1457
1464 /* REVISIT tx side _should_ clean up the same way 1458 /* REVISIT tx side _should_ clean up the same way
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index e16ff605c458..ce2e16fee0df 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -24,7 +24,6 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/slab.h>
28#include <linux/init.h> 27#include <linux/init.h>
29#include <linux/list.h> 28#include <linux/list.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
@@ -42,7 +41,7 @@
42#include "musb_core.h" 41#include "musb_core.h"
43 42
44#ifdef CONFIG_MACH_DAVINCI_EVM 43#ifdef CONFIG_MACH_DAVINCI_EVM
45#define GPIO_nVBUS_DRV 144 44#define GPIO_nVBUS_DRV 160
46#endif 45#endif
47 46
48#include "davinci.h" 47#include "davinci.h"
@@ -274,7 +273,7 @@ static irqreturn_t davinci_interrupt(int irq, void *__hci)
274 /* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through 273 /* NOTE: DaVinci shadows the Mentor IRQs. Don't manage them through
275 * the Mentor registers (except for setup), use the TI ones and EOI. 274 * the Mentor registers (except for setup), use the TI ones and EOI.
276 * 275 *
277 * Docs describe irq "vector" registers asociated with the CPPI and 276 * Docs describe irq "vector" registers associated with the CPPI and
278 * USB EOI registers. These hold a bitmask corresponding to the 277 * USB EOI registers. These hold a bitmask corresponding to the
279 * current IRQ, not an irq handler address. Would using those bits 278 * current IRQ, not an irq handler address. Would using those bits
280 * resolve some of the races observed in this dispatch code?? 279 * resolve some of the races observed in this dispatch code??
@@ -445,6 +444,8 @@ int __init musb_platform_init(struct musb *musb)
445 return 0; 444 return 0;
446 445
447fail: 446fail:
447 clk_disable(musb->clock);
448
448 usb_nop_xceiv_unregister(); 449 usb_nop_xceiv_unregister();
449 return -ENODEV; 450 return -ENODEV;
450} 451}
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 547e0e390726..705cc4ad8737 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -379,7 +379,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
379 u8 devctl, u8 power) 379 u8 devctl, u8 power)
380{ 380{
381 irqreturn_t handled = IRQ_NONE; 381 irqreturn_t handled = IRQ_NONE;
382 void __iomem *mbase = musb->mregs;
383 382
384 DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl, 383 DBG(3, "<== Power=%02x, DevCtl=%02x, int_usb=0x%x\n", power, devctl,
385 int_usb); 384 int_usb);
@@ -394,6 +393,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
394 393
395 if (devctl & MUSB_DEVCTL_HM) { 394 if (devctl & MUSB_DEVCTL_HM) {
396#ifdef CONFIG_USB_MUSB_HDRC_HCD 395#ifdef CONFIG_USB_MUSB_HDRC_HCD
396 void __iomem *mbase = musb->mregs;
397
397 switch (musb->xceiv->state) { 398 switch (musb->xceiv->state) {
398 case OTG_STATE_A_SUSPEND: 399 case OTG_STATE_A_SUSPEND:
399 /* remote wakeup? later, GetPortStatus 400 /* remote wakeup? later, GetPortStatus
@@ -471,6 +472,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
471#ifdef CONFIG_USB_MUSB_HDRC_HCD 472#ifdef CONFIG_USB_MUSB_HDRC_HCD
472 /* see manual for the order of the tests */ 473 /* see manual for the order of the tests */
473 if (int_usb & MUSB_INTR_SESSREQ) { 474 if (int_usb & MUSB_INTR_SESSREQ) {
475 void __iomem *mbase = musb->mregs;
476
474 DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb)); 477 DBG(1, "SESSION_REQUEST (%s)\n", otg_state_string(musb));
475 478
476 /* IRQ arrives from ID pin sense or (later, if VBUS power 479 /* IRQ arrives from ID pin sense or (later, if VBUS power
@@ -519,6 +522,8 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
519 case OTG_STATE_A_WAIT_BCON: 522 case OTG_STATE_A_WAIT_BCON:
520 case OTG_STATE_A_WAIT_VRISE: 523 case OTG_STATE_A_WAIT_VRISE:
521 if (musb->vbuserr_retry) { 524 if (musb->vbuserr_retry) {
525 void __iomem *mbase = musb->mregs;
526
522 musb->vbuserr_retry--; 527 musb->vbuserr_retry--;
523 ignore = 1; 528 ignore = 1;
524 devctl |= MUSB_DEVCTL_SESSION; 529 devctl |= MUSB_DEVCTL_SESSION;
@@ -557,8 +562,72 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
557 handled = IRQ_HANDLED; 562 handled = IRQ_HANDLED;
558 } 563 }
559 564
565
566 if (int_usb & MUSB_INTR_SUSPEND) {
567 DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
568 otg_state_string(musb), devctl, power);
569 handled = IRQ_HANDLED;
570
571 switch (musb->xceiv->state) {
572#ifdef CONFIG_USB_MUSB_OTG
573 case OTG_STATE_A_PERIPHERAL:
574 /* We also come here if the cable is removed, since
575 * this silicon doesn't report ID-no-longer-grounded.
576 *
577 * We depend on T(a_wait_bcon) to shut us down, and
578 * hope users don't do anything dicey during this
579 * undesired detour through A_WAIT_BCON.
580 */
581 musb_hnp_stop(musb);
582 usb_hcd_resume_root_hub(musb_to_hcd(musb));
583 musb_root_disconnect(musb);
584 musb_platform_try_idle(musb, jiffies
585 + msecs_to_jiffies(musb->a_wait_bcon
586 ? : OTG_TIME_A_WAIT_BCON));
587
588 break;
589#endif
590 case OTG_STATE_B_IDLE:
591 if (!musb->is_active)
592 break;
593 case OTG_STATE_B_PERIPHERAL:
594 musb_g_suspend(musb);
595 musb->is_active = is_otg_enabled(musb)
596 && musb->xceiv->gadget->b_hnp_enable;
597 if (musb->is_active) {
598#ifdef CONFIG_USB_MUSB_OTG
599 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
600 DBG(1, "HNP: Setting timer for b_ase0_brst\n");
601 mod_timer(&musb->otg_timer, jiffies
602 + msecs_to_jiffies(
603 OTG_TIME_B_ASE0_BRST));
604#endif
605 }
606 break;
607 case OTG_STATE_A_WAIT_BCON:
608 if (musb->a_wait_bcon != 0)
609 musb_platform_try_idle(musb, jiffies
610 + msecs_to_jiffies(musb->a_wait_bcon));
611 break;
612 case OTG_STATE_A_HOST:
613 musb->xceiv->state = OTG_STATE_A_SUSPEND;
614 musb->is_active = is_otg_enabled(musb)
615 && musb->xceiv->host->b_hnp_enable;
616 break;
617 case OTG_STATE_B_HOST:
618 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
619 DBG(1, "REVISIT: SUSPEND as B_HOST\n");
620 break;
621 default:
622 /* "should not happen" */
623 musb->is_active = 0;
624 break;
625 }
626 }
627
560 if (int_usb & MUSB_INTR_CONNECT) { 628 if (int_usb & MUSB_INTR_CONNECT) {
561 struct usb_hcd *hcd = musb_to_hcd(musb); 629 struct usb_hcd *hcd = musb_to_hcd(musb);
630 void __iomem *mbase = musb->mregs;
562 631
563 handled = IRQ_HANDLED; 632 handled = IRQ_HANDLED;
564 musb->is_active = 1; 633 musb->is_active = 1;
@@ -625,10 +694,61 @@ b_host:
625 } 694 }
626#endif /* CONFIG_USB_MUSB_HDRC_HCD */ 695#endif /* CONFIG_USB_MUSB_HDRC_HCD */
627 696
697 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
698 DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
699 otg_state_string(musb),
700 MUSB_MODE(musb), devctl);
701 handled = IRQ_HANDLED;
702
703 switch (musb->xceiv->state) {
704#ifdef CONFIG_USB_MUSB_HDRC_HCD
705 case OTG_STATE_A_HOST:
706 case OTG_STATE_A_SUSPEND:
707 usb_hcd_resume_root_hub(musb_to_hcd(musb));
708 musb_root_disconnect(musb);
709 if (musb->a_wait_bcon != 0 && is_otg_enabled(musb))
710 musb_platform_try_idle(musb, jiffies
711 + msecs_to_jiffies(musb->a_wait_bcon));
712 break;
713#endif /* HOST */
714#ifdef CONFIG_USB_MUSB_OTG
715 case OTG_STATE_B_HOST:
716 /* REVISIT this behaves for "real disconnect"
717 * cases; make sure the other transitions from
718 * from B_HOST act right too. The B_HOST code
719 * in hnp_stop() is currently not used...
720 */
721 musb_root_disconnect(musb);
722 musb_to_hcd(musb)->self.is_b_host = 0;
723 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
724 MUSB_DEV_MODE(musb);
725 musb_g_disconnect(musb);
726 break;
727 case OTG_STATE_A_PERIPHERAL:
728 musb_hnp_stop(musb);
729 musb_root_disconnect(musb);
730 /* FALLTHROUGH */
731 case OTG_STATE_B_WAIT_ACON:
732 /* FALLTHROUGH */
733#endif /* OTG */
734#ifdef CONFIG_USB_GADGET_MUSB_HDRC
735 case OTG_STATE_B_PERIPHERAL:
736 case OTG_STATE_B_IDLE:
737 musb_g_disconnect(musb);
738 break;
739#endif /* GADGET */
740 default:
741 WARNING("unhandled DISCONNECT transition (%s)\n",
742 otg_state_string(musb));
743 break;
744 }
745 }
746
628 /* mentor saves a bit: bus reset and babble share the same irq. 747 /* mentor saves a bit: bus reset and babble share the same irq.
629 * only host sees babble; only peripheral sees bus reset. 748 * only host sees babble; only peripheral sees bus reset.
630 */ 749 */
631 if (int_usb & MUSB_INTR_RESET) { 750 if (int_usb & MUSB_INTR_RESET) {
751 handled = IRQ_HANDLED;
632 if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) { 752 if (is_host_capable() && (devctl & MUSB_DEVCTL_HM) != 0) {
633 /* 753 /*
634 * Looks like non-HS BABBLE can be ignored, but 754 * Looks like non-HS BABBLE can be ignored, but
@@ -641,7 +761,7 @@ b_host:
641 DBG(1, "BABBLE devctl: %02x\n", devctl); 761 DBG(1, "BABBLE devctl: %02x\n", devctl);
642 else { 762 else {
643 ERR("Stopping host session -- babble\n"); 763 ERR("Stopping host session -- babble\n");
644 musb_writeb(mbase, MUSB_DEVCTL, 0); 764 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
645 } 765 }
646 } else if (is_peripheral_capable()) { 766 } else if (is_peripheral_capable()) {
647 DBG(1, "BUS RESET as %s\n", otg_state_string(musb)); 767 DBG(1, "BUS RESET as %s\n", otg_state_string(musb));
@@ -686,29 +806,7 @@ b_host:
686 otg_state_string(musb)); 806 otg_state_string(musb));
687 } 807 }
688 } 808 }
689
690 handled = IRQ_HANDLED;
691 } 809 }
692 schedule_work(&musb->irq_work);
693
694 return handled;
695}
696
697/*
698 * Interrupt Service Routine to record USB "global" interrupts.
699 * Since these do not happen often and signify things of
700 * paramount importance, it seems OK to check them individually;
701 * the order of the tests is specified in the manual
702 *
703 * @param musb instance pointer
704 * @param int_usb register contents
705 * @param devctl
706 * @param power
707 */
708static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
709 u8 devctl, u8 power)
710{
711 irqreturn_t handled = IRQ_NONE;
712 810
713#if 0 811#if 0
714/* REVISIT ... this would be for multiplexing periodic endpoints, or 812/* REVISIT ... this would be for multiplexing periodic endpoints, or
@@ -755,117 +853,7 @@ static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
755 } 853 }
756#endif 854#endif
757 855
758 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 856 schedule_work(&musb->irq_work);
759 DBG(1, "DISCONNECT (%s) as %s, devctl %02x\n",
760 otg_state_string(musb),
761 MUSB_MODE(musb), devctl);
762 handled = IRQ_HANDLED;
763
764 switch (musb->xceiv->state) {
765#ifdef CONFIG_USB_MUSB_HDRC_HCD
766 case OTG_STATE_A_HOST:
767 case OTG_STATE_A_SUSPEND:
768 usb_hcd_resume_root_hub(musb_to_hcd(musb));
769 musb_root_disconnect(musb);
770 if (musb->a_wait_bcon != 0 && is_otg_enabled(musb))
771 musb_platform_try_idle(musb, jiffies
772 + msecs_to_jiffies(musb->a_wait_bcon));
773 break;
774#endif /* HOST */
775#ifdef CONFIG_USB_MUSB_OTG
776 case OTG_STATE_B_HOST:
777 /* REVISIT this behaves for "real disconnect"
778 * cases; make sure the other transitions from
779 * from B_HOST act right too. The B_HOST code
780 * in hnp_stop() is currently not used...
781 */
782 musb_root_disconnect(musb);
783 musb_to_hcd(musb)->self.is_b_host = 0;
784 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
785 MUSB_DEV_MODE(musb);
786 musb_g_disconnect(musb);
787 break;
788 case OTG_STATE_A_PERIPHERAL:
789 musb_hnp_stop(musb);
790 musb_root_disconnect(musb);
791 /* FALLTHROUGH */
792 case OTG_STATE_B_WAIT_ACON:
793 /* FALLTHROUGH */
794#endif /* OTG */
795#ifdef CONFIG_USB_GADGET_MUSB_HDRC
796 case OTG_STATE_B_PERIPHERAL:
797 case OTG_STATE_B_IDLE:
798 musb_g_disconnect(musb);
799 break;
800#endif /* GADGET */
801 default:
802 WARNING("unhandled DISCONNECT transition (%s)\n",
803 otg_state_string(musb));
804 break;
805 }
806
807 schedule_work(&musb->irq_work);
808 }
809
810 if (int_usb & MUSB_INTR_SUSPEND) {
811 DBG(1, "SUSPEND (%s) devctl %02x power %02x\n",
812 otg_state_string(musb), devctl, power);
813 handled = IRQ_HANDLED;
814
815 switch (musb->xceiv->state) {
816#ifdef CONFIG_USB_MUSB_OTG
817 case OTG_STATE_A_PERIPHERAL:
818 /* We also come here if the cable is removed, since
819 * this silicon doesn't report ID-no-longer-grounded.
820 *
821 * We depend on T(a_wait_bcon) to shut us down, and
822 * hope users don't do anything dicey during this
823 * undesired detour through A_WAIT_BCON.
824 */
825 musb_hnp_stop(musb);
826 usb_hcd_resume_root_hub(musb_to_hcd(musb));
827 musb_root_disconnect(musb);
828 musb_platform_try_idle(musb, jiffies
829 + msecs_to_jiffies(musb->a_wait_bcon
830 ? : OTG_TIME_A_WAIT_BCON));
831 break;
832#endif
833 case OTG_STATE_B_PERIPHERAL:
834 musb_g_suspend(musb);
835 musb->is_active = is_otg_enabled(musb)
836 && musb->xceiv->gadget->b_hnp_enable;
837 if (musb->is_active) {
838#ifdef CONFIG_USB_MUSB_OTG
839 musb->xceiv->state = OTG_STATE_B_WAIT_ACON;
840 DBG(1, "HNP: Setting timer for b_ase0_brst\n");
841 mod_timer(&musb->otg_timer, jiffies
842 + msecs_to_jiffies(
843 OTG_TIME_B_ASE0_BRST));
844#endif
845 }
846 break;
847 case OTG_STATE_A_WAIT_BCON:
848 if (musb->a_wait_bcon != 0)
849 musb_platform_try_idle(musb, jiffies
850 + msecs_to_jiffies(musb->a_wait_bcon));
851 break;
852 case OTG_STATE_A_HOST:
853 musb->xceiv->state = OTG_STATE_A_SUSPEND;
854 musb->is_active = is_otg_enabled(musb)
855 && musb->xceiv->host->b_hnp_enable;
856 break;
857 case OTG_STATE_B_HOST:
858 /* Transition to B_PERIPHERAL, see 6.8.2.6 p 44 */
859 DBG(1, "REVISIT: SUSPEND as B_HOST\n");
860 break;
861 default:
862 /* "should not happen" */
863 musb->is_active = 0;
864 break;
865 }
866 schedule_work(&musb->irq_work);
867 }
868
869 857
870 return handled; 858 return handled;
871} 859}
@@ -977,10 +965,8 @@ static void musb_shutdown(struct platform_device *pdev)
977 spin_lock_irqsave(&musb->lock, flags); 965 spin_lock_irqsave(&musb->lock, flags);
978 musb_platform_disable(musb); 966 musb_platform_disable(musb);
979 musb_generic_disable(musb); 967 musb_generic_disable(musb);
980 if (musb->clock) { 968 if (musb->clock)
981 clk_put(musb->clock); 969 clk_put(musb->clock);
982 musb->clock = NULL;
983 }
984 spin_unlock_irqrestore(&musb->lock, flags); 970 spin_unlock_irqrestore(&musb->lock, flags);
985 971
986 /* FIXME power down */ 972 /* FIXME power down */
@@ -1000,7 +986,7 @@ static void musb_shutdown(struct platform_device *pdev)
1000 * more than selecting one of a bunch of predefined configurations. 986 * more than selecting one of a bunch of predefined configurations.
1001 */ 987 */
1002#if defined(CONFIG_USB_TUSB6010) || \ 988#if defined(CONFIG_USB_TUSB6010) || \
1003 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX) 989 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
1004static ushort __initdata fifo_mode = 4; 990static ushort __initdata fifo_mode = 4;
1005#else 991#else
1006static ushort __initdata fifo_mode = 2; 992static ushort __initdata fifo_mode = 2;
@@ -1095,6 +1081,36 @@ static struct fifo_cfg __initdata mode_4_cfg[] = {
1095{ .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, }, 1081{ .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
1096}; 1082};
1097 1083
1084/* mode 5 - fits in 8KB */
1085static struct fifo_cfg __initdata mode_5_cfg[] = {
1086{ .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, },
1087{ .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, },
1088{ .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 512, },
1089{ .hw_ep_num = 2, .style = FIFO_RX, .maxpacket = 512, },
1090{ .hw_ep_num = 3, .style = FIFO_TX, .maxpacket = 512, },
1091{ .hw_ep_num = 3, .style = FIFO_RX, .maxpacket = 512, },
1092{ .hw_ep_num = 4, .style = FIFO_TX, .maxpacket = 512, },
1093{ .hw_ep_num = 4, .style = FIFO_RX, .maxpacket = 512, },
1094{ .hw_ep_num = 5, .style = FIFO_TX, .maxpacket = 512, },
1095{ .hw_ep_num = 5, .style = FIFO_RX, .maxpacket = 512, },
1096{ .hw_ep_num = 6, .style = FIFO_TX, .maxpacket = 32, },
1097{ .hw_ep_num = 6, .style = FIFO_RX, .maxpacket = 32, },
1098{ .hw_ep_num = 7, .style = FIFO_TX, .maxpacket = 32, },
1099{ .hw_ep_num = 7, .style = FIFO_RX, .maxpacket = 32, },
1100{ .hw_ep_num = 8, .style = FIFO_TX, .maxpacket = 32, },
1101{ .hw_ep_num = 8, .style = FIFO_RX, .maxpacket = 32, },
1102{ .hw_ep_num = 9, .style = FIFO_TX, .maxpacket = 32, },
1103{ .hw_ep_num = 9, .style = FIFO_RX, .maxpacket = 32, },
1104{ .hw_ep_num = 10, .style = FIFO_TX, .maxpacket = 32, },
1105{ .hw_ep_num = 10, .style = FIFO_RX, .maxpacket = 32, },
1106{ .hw_ep_num = 11, .style = FIFO_TX, .maxpacket = 32, },
1107{ .hw_ep_num = 11, .style = FIFO_RX, .maxpacket = 32, },
1108{ .hw_ep_num = 12, .style = FIFO_TX, .maxpacket = 32, },
1109{ .hw_ep_num = 12, .style = FIFO_RX, .maxpacket = 32, },
1110{ .hw_ep_num = 13, .style = FIFO_RXTX, .maxpacket = 512, },
1111{ .hw_ep_num = 14, .style = FIFO_RXTX, .maxpacket = 1024, },
1112{ .hw_ep_num = 15, .style = FIFO_RXTX, .maxpacket = 1024, },
1113};
1098 1114
1099/* 1115/*
1100 * configure a fifo; for non-shared endpoints, this may be called 1116 * configure a fifo; for non-shared endpoints, this may be called
@@ -1210,6 +1226,10 @@ static int __init ep_config_from_table(struct musb *musb)
1210 cfg = mode_4_cfg; 1226 cfg = mode_4_cfg;
1211 n = ARRAY_SIZE(mode_4_cfg); 1227 n = ARRAY_SIZE(mode_4_cfg);
1212 break; 1228 break;
1229 case 5:
1230 cfg = mode_5_cfg;
1231 n = ARRAY_SIZE(mode_5_cfg);
1232 break;
1213 } 1233 }
1214 1234
1215 printk(KERN_DEBUG "%s: setup fifo_mode %d\n", 1235 printk(KERN_DEBUG "%s: setup fifo_mode %d\n",
@@ -1314,13 +1334,9 @@ enum { MUSB_CONTROLLER_MHDRC, MUSB_CONTROLLER_HDRC, };
1314 */ 1334 */
1315static int __init musb_core_init(u16 musb_type, struct musb *musb) 1335static int __init musb_core_init(u16 musb_type, struct musb *musb)
1316{ 1336{
1317#ifdef MUSB_AHB_ID
1318 u32 data;
1319#endif
1320 u8 reg; 1337 u8 reg;
1321 char *type; 1338 char *type;
1322 u16 hwvers, rev_major, rev_minor; 1339 char aInfo[90], aRevision[32], aDate[12];
1323 char aInfo[78], aRevision[32], aDate[12];
1324 void __iomem *mbase = musb->mregs; 1340 void __iomem *mbase = musb->mregs;
1325 int status = 0; 1341 int status = 0;
1326 int i; 1342 int i;
@@ -1329,23 +1345,17 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1329 reg = musb_read_configdata(mbase); 1345 reg = musb_read_configdata(mbase);
1330 1346
1331 strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8"); 1347 strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8");
1332 if (reg & MUSB_CONFIGDATA_DYNFIFO) 1348 if (reg & MUSB_CONFIGDATA_DYNFIFO) {
1333 strcat(aInfo, ", dyn FIFOs"); 1349 strcat(aInfo, ", dyn FIFOs");
1350 musb->dyn_fifo = true;
1351 }
1334 if (reg & MUSB_CONFIGDATA_MPRXE) { 1352 if (reg & MUSB_CONFIGDATA_MPRXE) {
1335 strcat(aInfo, ", bulk combine"); 1353 strcat(aInfo, ", bulk combine");
1336#ifdef C_MP_RX
1337 musb->bulk_combine = true; 1354 musb->bulk_combine = true;
1338#else
1339 strcat(aInfo, " (X)"); /* no driver support */
1340#endif
1341 } 1355 }
1342 if (reg & MUSB_CONFIGDATA_MPTXE) { 1356 if (reg & MUSB_CONFIGDATA_MPTXE) {
1343 strcat(aInfo, ", bulk split"); 1357 strcat(aInfo, ", bulk split");
1344#ifdef C_MP_TX
1345 musb->bulk_split = true; 1358 musb->bulk_split = true;
1346#else
1347 strcat(aInfo, " (X)"); /* no driver support */
1348#endif
1349 } 1359 }
1350 if (reg & MUSB_CONFIGDATA_HBRXE) { 1360 if (reg & MUSB_CONFIGDATA_HBRXE) {
1351 strcat(aInfo, ", HB-ISO Rx"); 1361 strcat(aInfo, ", HB-ISO Rx");
@@ -1361,20 +1371,7 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1361 printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n", 1371 printk(KERN_DEBUG "%s: ConfigData=0x%02x (%s)\n",
1362 musb_driver_name, reg, aInfo); 1372 musb_driver_name, reg, aInfo);
1363 1373
1364#ifdef MUSB_AHB_ID
1365 data = musb_readl(mbase, 0x404);
1366 sprintf(aDate, "%04d-%02x-%02x", (data & 0xffff),
1367 (data >> 16) & 0xff, (data >> 24) & 0xff);
1368 /* FIXME ID2 and ID3 are unused */
1369 data = musb_readl(mbase, 0x408);
1370 printk(KERN_DEBUG "ID2=%lx\n", (long unsigned)data);
1371 data = musb_readl(mbase, 0x40c);
1372 printk(KERN_DEBUG "ID3=%lx\n", (long unsigned)data);
1373 reg = musb_readb(mbase, 0x400);
1374 musb_type = ('M' == reg) ? MUSB_CONTROLLER_MHDRC : MUSB_CONTROLLER_HDRC;
1375#else
1376 aDate[0] = 0; 1374 aDate[0] = 0;
1377#endif
1378 if (MUSB_CONTROLLER_MHDRC == musb_type) { 1375 if (MUSB_CONTROLLER_MHDRC == musb_type) {
1379 musb->is_multipoint = 1; 1376 musb->is_multipoint = 1;
1380 type = "M"; 1377 type = "M";
@@ -1391,11 +1388,10 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1391 } 1388 }
1392 1389
1393 /* log release info */ 1390 /* log release info */
1394 hwvers = musb_read_hwvers(mbase); 1391 musb->hwvers = musb_read_hwvers(mbase);
1395 rev_major = (hwvers >> 10) & 0x1f; 1392 snprintf(aRevision, 32, "%d.%d%s", MUSB_HWVERS_MAJOR(musb->hwvers),
1396 rev_minor = hwvers & 0x3ff; 1393 MUSB_HWVERS_MINOR(musb->hwvers),
1397 snprintf(aRevision, 32, "%d.%d%s", rev_major, 1394 (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : "");
1398 rev_minor, (hwvers & 0x8000) ? "RC" : "");
1399 printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n", 1395 printk(KERN_DEBUG "%s: %sHDRC RTL version %s %s\n",
1400 musb_driver_name, type, aRevision, aDate); 1396 musb_driver_name, type, aRevision, aDate);
1401 1397
@@ -1406,21 +1402,10 @@ static int __init musb_core_init(u16 musb_type, struct musb *musb)
1406 musb->nr_endpoints = 1; 1402 musb->nr_endpoints = 1;
1407 musb->epmask = 1; 1403 musb->epmask = 1;
1408 1404
1409 if (reg & MUSB_CONFIGDATA_DYNFIFO) { 1405 if (musb->dyn_fifo)
1410 if (musb->config->dyn_fifo) 1406 status = ep_config_from_table(musb);
1411 status = ep_config_from_table(musb); 1407 else
1412 else { 1408 status = ep_config_from_hw(musb);
1413 ERR("reconfigure software for Dynamic FIFOs\n");
1414 status = -ENODEV;
1415 }
1416 } else {
1417 if (!musb->config->dyn_fifo)
1418 status = ep_config_from_hw(musb);
1419 else {
1420 ERR("reconfigure software for static FIFOs\n");
1421 return -ENODEV;
1422 }
1423 }
1424 1409
1425 if (status < 0) 1410 if (status < 0)
1426 return status; 1411 return status;
@@ -1523,6 +1508,14 @@ irqreturn_t musb_interrupt(struct musb *musb)
1523 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral", 1508 (devctl & MUSB_DEVCTL_HM) ? "host" : "peripheral",
1524 musb->int_usb, musb->int_tx, musb->int_rx); 1509 musb->int_usb, musb->int_tx, musb->int_rx);
1525 1510
1511#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1512 if (is_otg_enabled(musb) || is_peripheral_enabled(musb))
1513 if (!musb->gadget_driver) {
1514 DBG(5, "No gadget driver loaded\n");
1515 return IRQ_HANDLED;
1516 }
1517#endif
1518
1526 /* the core can interrupt us for multiple reasons; docs have 1519 /* the core can interrupt us for multiple reasons; docs have
1527 * a generic interrupt flowchart to follow 1520 * a generic interrupt flowchart to follow
1528 */ 1521 */
@@ -1581,11 +1574,6 @@ irqreturn_t musb_interrupt(struct musb *musb)
1581 ep_num++; 1574 ep_num++;
1582 } 1575 }
1583 1576
1584 /* finish handling "global" interrupts after handling fifos */
1585 if (musb->int_usb)
1586 retval |= musb_stage2_irq(musb,
1587 musb->int_usb, devctl, power);
1588
1589 return retval; 1577 return retval;
1590} 1578}
1591 1579
@@ -1690,7 +1678,7 @@ musb_vbus_store(struct device *dev, struct device_attribute *attr,
1690 unsigned long val; 1678 unsigned long val;
1691 1679
1692 if (sscanf(buf, "%lu", &val) < 1) { 1680 if (sscanf(buf, "%lu", &val) < 1) {
1693 printk(KERN_ERR "Invalid VBUS timeout ms value\n"); 1681 dev_err(dev, "Invalid VBUS timeout ms value\n");
1694 return -EINVAL; 1682 return -EINVAL;
1695 } 1683 }
1696 1684
@@ -1740,7 +1728,7 @@ musb_srp_store(struct device *dev, struct device_attribute *attr,
1740 1728
1741 if (sscanf(buf, "%hu", &srp) != 1 1729 if (sscanf(buf, "%hu", &srp) != 1
1742 || (srp != 1)) { 1730 || (srp != 1)) {
1743 printk(KERN_ERR "SRP: Value must be 1\n"); 1731 dev_err(dev, "SRP: Value must be 1\n");
1744 return -EINVAL; 1732 return -EINVAL;
1745 } 1733 }
1746 1734
@@ -1753,6 +1741,19 @@ static DEVICE_ATTR(srp, 0644, NULL, musb_srp_store);
1753 1741
1754#endif /* CONFIG_USB_GADGET_MUSB_HDRC */ 1742#endif /* CONFIG_USB_GADGET_MUSB_HDRC */
1755 1743
1744static struct attribute *musb_attributes[] = {
1745 &dev_attr_mode.attr,
1746 &dev_attr_vbus.attr,
1747#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1748 &dev_attr_srp.attr,
1749#endif
1750 NULL
1751};
1752
1753static const struct attribute_group musb_attr_group = {
1754 .attrs = musb_attributes,
1755};
1756
1756#endif /* sysfs */ 1757#endif /* sysfs */
1757 1758
1758/* Only used to provide driver mode change events */ 1759/* Only used to provide driver mode change events */
@@ -1827,11 +1828,7 @@ static void musb_free(struct musb *musb)
1827 */ 1828 */
1828 1829
1829#ifdef CONFIG_SYSFS 1830#ifdef CONFIG_SYSFS
1830 device_remove_file(musb->controller, &dev_attr_mode); 1831 sysfs_remove_group(&musb->controller->kobj, &musb_attr_group);
1831 device_remove_file(musb->controller, &dev_attr_vbus);
1832#ifdef CONFIG_USB_GADGET_MUSB_HDRC
1833 device_remove_file(musb->controller, &dev_attr_srp);
1834#endif
1835#endif 1832#endif
1836 1833
1837#ifdef CONFIG_USB_GADGET_MUSB_HDRC 1834#ifdef CONFIG_USB_GADGET_MUSB_HDRC
@@ -1854,15 +1851,6 @@ static void musb_free(struct musb *musb)
1854 put_device(musb->xceiv->dev); 1851 put_device(musb->xceiv->dev);
1855#endif 1852#endif
1856 1853
1857 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1858 musb_platform_exit(musb);
1859 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
1860
1861 if (musb->clock) {
1862 clk_disable(musb->clock);
1863 clk_put(musb->clock);
1864 }
1865
1866#ifdef CONFIG_USB_MUSB_HDRC_HCD 1854#ifdef CONFIG_USB_MUSB_HDRC_HCD
1867 usb_put_hcd(musb_to_hcd(musb)); 1855 usb_put_hcd(musb_to_hcd(musb));
1868#else 1856#else
@@ -1890,8 +1878,10 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1890 */ 1878 */
1891 if (!plat) { 1879 if (!plat) {
1892 dev_dbg(dev, "no platform_data?\n"); 1880 dev_dbg(dev, "no platform_data?\n");
1893 return -ENODEV; 1881 status = -ENODEV;
1882 goto fail0;
1894 } 1883 }
1884
1895 switch (plat->mode) { 1885 switch (plat->mode) {
1896 case MUSB_HOST: 1886 case MUSB_HOST:
1897#ifdef CONFIG_USB_MUSB_HDRC_HCD 1887#ifdef CONFIG_USB_MUSB_HDRC_HCD
@@ -1913,13 +1903,16 @@ bad_config:
1913#endif 1903#endif
1914 default: 1904 default:
1915 dev_err(dev, "incompatible Kconfig role setting\n"); 1905 dev_err(dev, "incompatible Kconfig role setting\n");
1916 return -EINVAL; 1906 status = -EINVAL;
1907 goto fail0;
1917 } 1908 }
1918 1909
1919 /* allocate */ 1910 /* allocate */
1920 musb = allocate_instance(dev, plat->config, ctrl); 1911 musb = allocate_instance(dev, plat->config, ctrl);
1921 if (!musb) 1912 if (!musb) {
1922 return -ENOMEM; 1913 status = -ENOMEM;
1914 goto fail0;
1915 }
1923 1916
1924 spin_lock_init(&musb->lock); 1917 spin_lock_init(&musb->lock);
1925 musb->board_mode = plat->mode; 1918 musb->board_mode = plat->mode;
@@ -1937,7 +1930,7 @@ bad_config:
1937 if (IS_ERR(musb->clock)) { 1930 if (IS_ERR(musb->clock)) {
1938 status = PTR_ERR(musb->clock); 1931 status = PTR_ERR(musb->clock);
1939 musb->clock = NULL; 1932 musb->clock = NULL;
1940 goto fail; 1933 goto fail1;
1941 } 1934 }
1942 } 1935 }
1943 1936
@@ -1956,12 +1949,12 @@ bad_config:
1956 */ 1949 */
1957 musb->isr = generic_interrupt; 1950 musb->isr = generic_interrupt;
1958 status = musb_platform_init(musb); 1951 status = musb_platform_init(musb);
1959
1960 if (status < 0) 1952 if (status < 0)
1961 goto fail; 1953 goto fail2;
1954
1962 if (!musb->isr) { 1955 if (!musb->isr) {
1963 status = -ENODEV; 1956 status = -ENODEV;
1964 goto fail2; 1957 goto fail3;
1965 } 1958 }
1966 1959
1967#ifndef CONFIG_MUSB_PIO_ONLY 1960#ifndef CONFIG_MUSB_PIO_ONLY
@@ -1987,7 +1980,7 @@ bad_config:
1987 ? MUSB_CONTROLLER_MHDRC 1980 ? MUSB_CONTROLLER_MHDRC
1988 : MUSB_CONTROLLER_HDRC, musb); 1981 : MUSB_CONTROLLER_HDRC, musb);
1989 if (status < 0) 1982 if (status < 0)
1990 goto fail2; 1983 goto fail3;
1991 1984
1992#ifdef CONFIG_USB_MUSB_OTG 1985#ifdef CONFIG_USB_MUSB_OTG
1993 setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb); 1986 setup_timer(&musb->otg_timer, musb_otg_timer_func, (unsigned long) musb);
@@ -2000,7 +1993,7 @@ bad_config:
2000 if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) { 1993 if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
2001 dev_err(dev, "request_irq %d failed!\n", nIrq); 1994 dev_err(dev, "request_irq %d failed!\n", nIrq);
2002 status = -ENODEV; 1995 status = -ENODEV;
2003 goto fail2; 1996 goto fail3;
2004 } 1997 }
2005 musb->nIrq = nIrq; 1998 musb->nIrq = nIrq;
2006/* FIXME this handles wakeup irqs wrong */ 1999/* FIXME this handles wakeup irqs wrong */
@@ -2011,19 +2004,6 @@ bad_config:
2011 musb->irq_wake = 0; 2004 musb->irq_wake = 0;
2012 } 2005 }
2013 2006
2014 pr_info("%s: USB %s mode controller at %p using %s, IRQ %d\n",
2015 musb_driver_name,
2016 ({char *s;
2017 switch (musb->board_mode) {
2018 case MUSB_HOST: s = "Host"; break;
2019 case MUSB_PERIPHERAL: s = "Peripheral"; break;
2020 default: s = "OTG"; break;
2021 }; s; }),
2022 ctrl,
2023 (is_dma_capable() && musb->dma_controller)
2024 ? "DMA" : "PIO",
2025 musb->nIrq);
2026
2027 /* host side needs more setup */ 2007 /* host side needs more setup */
2028 if (is_host_enabled(musb)) { 2008 if (is_host_enabled(musb)) {
2029 struct usb_hcd *hcd = musb_to_hcd(musb); 2009 struct usb_hcd *hcd = musb_to_hcd(musb);
@@ -2034,6 +2014,13 @@ bad_config:
2034 hcd->self.otg_port = 1; 2014 hcd->self.otg_port = 1;
2035 musb->xceiv->host = &hcd->self; 2015 musb->xceiv->host = &hcd->self;
2036 hcd->power_budget = 2 * (plat->power ? : 250); 2016 hcd->power_budget = 2 * (plat->power ? : 250);
2017
2018 /* program PHY to use external vBus if required */
2019 if (plat->extvbus) {
2020 u8 busctl = musb_read_ulpi_buscontrol(musb->mregs);
2021 busctl |= MUSB_ULPI_USE_EXTVBUS;
2022 musb_write_ulpi_buscontrol(musb->mregs, busctl);
2023 }
2037 } 2024 }
2038 2025
2039 /* For the host-only role, we can activate right away. 2026 /* For the host-only role, we can activate right away.
@@ -2046,8 +2033,6 @@ bad_config:
2046 musb->xceiv->state = OTG_STATE_A_IDLE; 2033 musb->xceiv->state = OTG_STATE_A_IDLE;
2047 2034
2048 status = usb_add_hcd(musb_to_hcd(musb), -1, 0); 2035 status = usb_add_hcd(musb_to_hcd(musb), -1, 0);
2049 if (status)
2050 goto fail;
2051 2036
2052 DBG(1, "%s mode, status %d, devctl %02x %c\n", 2037 DBG(1, "%s mode, status %d, devctl %02x %c\n",
2053 "HOST", status, 2038 "HOST", status,
@@ -2062,8 +2047,6 @@ bad_config:
2062 musb->xceiv->state = OTG_STATE_B_IDLE; 2047 musb->xceiv->state = OTG_STATE_B_IDLE;
2063 2048
2064 status = musb_gadget_setup(musb); 2049 status = musb_gadget_setup(musb);
2065 if (status)
2066 goto fail;
2067 2050
2068 DBG(1, "%s mode, status %d, dev%02x\n", 2051 DBG(1, "%s mode, status %d, dev%02x\n",
2069 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL", 2052 is_otg_enabled(musb) ? "OTG" : "PERIPHERAL",
@@ -2071,38 +2054,52 @@ bad_config:
2071 musb_readb(musb->mregs, MUSB_DEVCTL)); 2054 musb_readb(musb->mregs, MUSB_DEVCTL));
2072 2055
2073 } 2056 }
2057 if (status < 0)
2058 goto fail3;
2074 2059
2075#ifdef CONFIG_SYSFS 2060#ifdef CONFIG_SYSFS
2076 status = device_create_file(dev, &dev_attr_mode); 2061 status = sysfs_create_group(&musb->controller->kobj, &musb_attr_group);
2077 status = device_create_file(dev, &dev_attr_vbus);
2078#ifdef CONFIG_USB_GADGET_MUSB_HDRC
2079 status = device_create_file(dev, &dev_attr_srp);
2080#endif /* CONFIG_USB_GADGET_MUSB_HDRC */
2081 status = 0;
2082#endif
2083 if (status) 2062 if (status)
2084 goto fail2; 2063 goto fail4;
2064#endif
2065
2066 dev_info(dev, "USB %s mode controller at %p using %s, IRQ %d\n",
2067 ({char *s;
2068 switch (musb->board_mode) {
2069 case MUSB_HOST: s = "Host"; break;
2070 case MUSB_PERIPHERAL: s = "Peripheral"; break;
2071 default: s = "OTG"; break;
2072 }; s; }),
2073 ctrl,
2074 (is_dma_capable() && musb->dma_controller)
2075 ? "DMA" : "PIO",
2076 musb->nIrq);
2085 2077
2086 return 0; 2078 return 0;
2087 2079
2088fail2: 2080fail4:
2089#ifdef CONFIG_SYSFS 2081 if (!is_otg_enabled(musb) && is_host_enabled(musb))
2090 device_remove_file(musb->controller, &dev_attr_mode); 2082 usb_remove_hcd(musb_to_hcd(musb));
2091 device_remove_file(musb->controller, &dev_attr_vbus); 2083 else
2092#ifdef CONFIG_USB_GADGET_MUSB_HDRC 2084 musb_gadget_cleanup(musb);
2093 device_remove_file(musb->controller, &dev_attr_srp); 2085
2094#endif 2086fail3:
2095#endif 2087 if (musb->irq_wake)
2088 device_init_wakeup(dev, 0);
2096 musb_platform_exit(musb); 2089 musb_platform_exit(musb);
2097fail:
2098 dev_err(musb->controller,
2099 "musb_init_controller failed with status %d\n", status);
2100 2090
2091fail2:
2101 if (musb->clock) 2092 if (musb->clock)
2102 clk_put(musb->clock); 2093 clk_put(musb->clock);
2103 device_init_wakeup(dev, 0); 2094
2095fail1:
2096 dev_err(musb->controller,
2097 "musb_init_controller failed with status %d\n", status);
2098
2104 musb_free(musb); 2099 musb_free(musb);
2105 2100
2101fail0:
2102
2106 return status; 2103 return status;
2107 2104
2108} 2105}
@@ -2121,6 +2118,7 @@ static int __init musb_probe(struct platform_device *pdev)
2121{ 2118{
2122 struct device *dev = &pdev->dev; 2119 struct device *dev = &pdev->dev;
2123 int irq = platform_get_irq(pdev, 0); 2120 int irq = platform_get_irq(pdev, 0);
2121 int status;
2124 struct resource *iomem; 2122 struct resource *iomem;
2125 void __iomem *base; 2123 void __iomem *base;
2126 2124
@@ -2128,7 +2126,7 @@ static int __init musb_probe(struct platform_device *pdev)
2128 if (!iomem || irq == 0) 2126 if (!iomem || irq == 0)
2129 return -ENODEV; 2127 return -ENODEV;
2130 2128
2131 base = ioremap(iomem->start, iomem->end - iomem->start + 1); 2129 base = ioremap(iomem->start, resource_size(iomem));
2132 if (!base) { 2130 if (!base) {
2133 dev_err(dev, "ioremap failed\n"); 2131 dev_err(dev, "ioremap failed\n");
2134 return -ENOMEM; 2132 return -ENOMEM;
@@ -2138,10 +2136,14 @@ static int __init musb_probe(struct platform_device *pdev)
2138 /* clobbered by use_dma=n */ 2136 /* clobbered by use_dma=n */
2139 orig_dma_mask = dev->dma_mask; 2137 orig_dma_mask = dev->dma_mask;
2140#endif 2138#endif
2141 return musb_init_controller(dev, irq, base); 2139 status = musb_init_controller(dev, irq, base);
2140 if (status < 0)
2141 iounmap(base);
2142
2143 return status;
2142} 2144}
2143 2145
2144static int __devexit musb_remove(struct platform_device *pdev) 2146static int __exit musb_remove(struct platform_device *pdev)
2145{ 2147{
2146 struct musb *musb = dev_to_musb(&pdev->dev); 2148 struct musb *musb = dev_to_musb(&pdev->dev);
2147 void __iomem *ctrl_base = musb->ctrl_base; 2149 void __iomem *ctrl_base = musb->ctrl_base;
@@ -2156,6 +2158,10 @@ static int __devexit musb_remove(struct platform_device *pdev)
2156 if (musb->board_mode == MUSB_HOST) 2158 if (musb->board_mode == MUSB_HOST)
2157 usb_remove_hcd(musb_to_hcd(musb)); 2159 usb_remove_hcd(musb_to_hcd(musb));
2158#endif 2160#endif
2161 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2162 musb_platform_exit(musb);
2163 musb_writeb(musb->mregs, MUSB_DEVCTL, 0);
2164
2159 musb_free(musb); 2165 musb_free(musb);
2160 iounmap(ctrl_base); 2166 iounmap(ctrl_base);
2161 device_init_wakeup(&pdev->dev, 0); 2167 device_init_wakeup(&pdev->dev, 0);
@@ -2167,6 +2173,150 @@ static int __devexit musb_remove(struct platform_device *pdev)
2167 2173
2168#ifdef CONFIG_PM 2174#ifdef CONFIG_PM
2169 2175
2176static struct musb_context_registers musb_context;
2177
2178void musb_save_context(struct musb *musb)
2179{
2180 int i;
2181 void __iomem *musb_base = musb->mregs;
2182
2183 if (is_host_enabled(musb)) {
2184 musb_context.frame = musb_readw(musb_base, MUSB_FRAME);
2185 musb_context.testmode = musb_readb(musb_base, MUSB_TESTMODE);
2186 musb_context.busctl = musb_read_ulpi_buscontrol(musb->mregs);
2187 }
2188 musb_context.power = musb_readb(musb_base, MUSB_POWER);
2189 musb_context.intrtxe = musb_readw(musb_base, MUSB_INTRTXE);
2190 musb_context.intrrxe = musb_readw(musb_base, MUSB_INTRRXE);
2191 musb_context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE);
2192 musb_context.index = musb_readb(musb_base, MUSB_INDEX);
2193 musb_context.devctl = musb_readb(musb_base, MUSB_DEVCTL);
2194
2195 for (i = 0; i < MUSB_C_NUM_EPS; ++i) {
2196 musb_writeb(musb_base, MUSB_INDEX, i);
2197 musb_context.index_regs[i].txmaxp =
2198 musb_readw(musb_base, 0x10 + MUSB_TXMAXP);
2199 musb_context.index_regs[i].txcsr =
2200 musb_readw(musb_base, 0x10 + MUSB_TXCSR);
2201 musb_context.index_regs[i].rxmaxp =
2202 musb_readw(musb_base, 0x10 + MUSB_RXMAXP);
2203 musb_context.index_regs[i].rxcsr =
2204 musb_readw(musb_base, 0x10 + MUSB_RXCSR);
2205
2206 if (musb->dyn_fifo) {
2207 musb_context.index_regs[i].txfifoadd =
2208 musb_read_txfifoadd(musb_base);
2209 musb_context.index_regs[i].rxfifoadd =
2210 musb_read_rxfifoadd(musb_base);
2211 musb_context.index_regs[i].txfifosz =
2212 musb_read_txfifosz(musb_base);
2213 musb_context.index_regs[i].rxfifosz =
2214 musb_read_rxfifosz(musb_base);
2215 }
2216 if (is_host_enabled(musb)) {
2217 musb_context.index_regs[i].txtype =
2218 musb_readb(musb_base, 0x10 + MUSB_TXTYPE);
2219 musb_context.index_regs[i].txinterval =
2220 musb_readb(musb_base, 0x10 + MUSB_TXINTERVAL);
2221 musb_context.index_regs[i].rxtype =
2222 musb_readb(musb_base, 0x10 + MUSB_RXTYPE);
2223 musb_context.index_regs[i].rxinterval =
2224 musb_readb(musb_base, 0x10 + MUSB_RXINTERVAL);
2225
2226 musb_context.index_regs[i].txfunaddr =
2227 musb_read_txfunaddr(musb_base, i);
2228 musb_context.index_regs[i].txhubaddr =
2229 musb_read_txhubaddr(musb_base, i);
2230 musb_context.index_regs[i].txhubport =
2231 musb_read_txhubport(musb_base, i);
2232
2233 musb_context.index_regs[i].rxfunaddr =
2234 musb_read_rxfunaddr(musb_base, i);
2235 musb_context.index_regs[i].rxhubaddr =
2236 musb_read_rxhubaddr(musb_base, i);
2237 musb_context.index_regs[i].rxhubport =
2238 musb_read_rxhubport(musb_base, i);
2239 }
2240 }
2241
2242 musb_writeb(musb_base, MUSB_INDEX, musb_context.index);
2243
2244 musb_platform_save_context(musb, &musb_context);
2245}
2246
2247void musb_restore_context(struct musb *musb)
2248{
2249 int i;
2250 void __iomem *musb_base = musb->mregs;
2251 void __iomem *ep_target_regs;
2252
2253 musb_platform_restore_context(musb, &musb_context);
2254
2255 if (is_host_enabled(musb)) {
2256 musb_writew(musb_base, MUSB_FRAME, musb_context.frame);
2257 musb_writeb(musb_base, MUSB_TESTMODE, musb_context.testmode);
2258 musb_write_ulpi_buscontrol(musb->mregs, musb_context.busctl);
2259 }
2260 musb_writeb(musb_base, MUSB_POWER, musb_context.power);
2261 musb_writew(musb_base, MUSB_INTRTXE, musb_context.intrtxe);
2262 musb_writew(musb_base, MUSB_INTRRXE, musb_context.intrrxe);
2263 musb_writeb(musb_base, MUSB_INTRUSBE, musb_context.intrusbe);
2264 musb_writeb(musb_base, MUSB_DEVCTL, musb_context.devctl);
2265
2266 for (i = 0; i < MUSB_C_NUM_EPS; ++i) {
2267 musb_writeb(musb_base, MUSB_INDEX, i);
2268 musb_writew(musb_base, 0x10 + MUSB_TXMAXP,
2269 musb_context.index_regs[i].txmaxp);
2270 musb_writew(musb_base, 0x10 + MUSB_TXCSR,
2271 musb_context.index_regs[i].txcsr);
2272 musb_writew(musb_base, 0x10 + MUSB_RXMAXP,
2273 musb_context.index_regs[i].rxmaxp);
2274 musb_writew(musb_base, 0x10 + MUSB_RXCSR,
2275 musb_context.index_regs[i].rxcsr);
2276
2277 if (musb->dyn_fifo) {
2278 musb_write_txfifosz(musb_base,
2279 musb_context.index_regs[i].txfifosz);
2280 musb_write_rxfifosz(musb_base,
2281 musb_context.index_regs[i].rxfifosz);
2282 musb_write_txfifoadd(musb_base,
2283 musb_context.index_regs[i].txfifoadd);
2284 musb_write_rxfifoadd(musb_base,
2285 musb_context.index_regs[i].rxfifoadd);
2286 }
2287
2288 if (is_host_enabled(musb)) {
2289 musb_writeb(musb_base, 0x10 + MUSB_TXTYPE,
2290 musb_context.index_regs[i].txtype);
2291 musb_writeb(musb_base, 0x10 + MUSB_TXINTERVAL,
2292 musb_context.index_regs[i].txinterval);
2293 musb_writeb(musb_base, 0x10 + MUSB_RXTYPE,
2294 musb_context.index_regs[i].rxtype);
2295 musb_writeb(musb_base, 0x10 + MUSB_RXINTERVAL,
2296
2297 musb_context.index_regs[i].rxinterval);
2298 musb_write_txfunaddr(musb_base, i,
2299 musb_context.index_regs[i].txfunaddr);
2300 musb_write_txhubaddr(musb_base, i,
2301 musb_context.index_regs[i].txhubaddr);
2302 musb_write_txhubport(musb_base, i,
2303 musb_context.index_regs[i].txhubport);
2304
2305 ep_target_regs =
2306 musb_read_target_reg_base(i, musb_base);
2307
2308 musb_write_rxfunaddr(ep_target_regs,
2309 musb_context.index_regs[i].rxfunaddr);
2310 musb_write_rxhubaddr(ep_target_regs,
2311 musb_context.index_regs[i].rxhubaddr);
2312 musb_write_rxhubport(ep_target_regs,
2313 musb_context.index_regs[i].rxhubport);
2314 }
2315 }
2316
2317 musb_writeb(musb_base, MUSB_INDEX, musb_context.index);
2318}
2319
2170static int musb_suspend(struct device *dev) 2320static int musb_suspend(struct device *dev)
2171{ 2321{
2172 struct platform_device *pdev = to_platform_device(dev); 2322 struct platform_device *pdev = to_platform_device(dev);
@@ -2188,6 +2338,8 @@ static int musb_suspend(struct device *dev)
2188 */ 2338 */
2189 } 2339 }
2190 2340
2341 musb_save_context(musb);
2342
2191 if (musb->set_clock) 2343 if (musb->set_clock)
2192 musb->set_clock(musb->clock, 0); 2344 musb->set_clock(musb->clock, 0);
2193 else 2345 else
@@ -2209,6 +2361,8 @@ static int musb_resume_noirq(struct device *dev)
2209 else 2361 else
2210 clk_enable(musb->clock); 2362 clk_enable(musb->clock);
2211 2363
2364 musb_restore_context(musb);
2365
2212 /* for static cmos like DaVinci, register values were preserved 2366 /* for static cmos like DaVinci, register values were preserved
2213 * unless for some reason the whole soc powered down or the USB 2367 * unless for some reason the whole soc powered down or the USB
2214 * module got reset through the PSC (vs just being disabled). 2368 * module got reset through the PSC (vs just being disabled).
@@ -2216,7 +2370,7 @@ static int musb_resume_noirq(struct device *dev)
2216 return 0; 2370 return 0;
2217} 2371}
2218 2372
2219static struct dev_pm_ops musb_dev_pm_ops = { 2373static const struct dev_pm_ops musb_dev_pm_ops = {
2220 .suspend = musb_suspend, 2374 .suspend = musb_suspend,
2221 .resume_noirq = musb_resume_noirq, 2375 .resume_noirq = musb_resume_noirq,
2222}; 2376};
@@ -2233,7 +2387,7 @@ static struct platform_driver musb_driver = {
2233 .owner = THIS_MODULE, 2387 .owner = THIS_MODULE,
2234 .pm = MUSB_DEV_PM_OPS, 2388 .pm = MUSB_DEV_PM_OPS,
2235 }, 2389 },
2236 .remove = __devexit_p(musb_remove), 2390 .remove = __exit_p(musb_remove),
2237 .shutdown = musb_shutdown, 2391 .shutdown = musb_shutdown,
2238}; 2392};
2239 2393
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 6aa5f22e5274..ac17b004909b 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -52,6 +52,15 @@ struct musb;
52struct musb_hw_ep; 52struct musb_hw_ep;
53struct musb_ep; 53struct musb_ep;
54 54
55/* Helper defines for struct musb->hwvers */
56#define MUSB_HWVERS_MAJOR(x) ((x >> 10) & 0x1f)
57#define MUSB_HWVERS_MINOR(x) (x & 0x3ff)
58#define MUSB_HWVERS_RC 0x8000
59#define MUSB_HWVERS_1300 0x52C
60#define MUSB_HWVERS_1400 0x590
61#define MUSB_HWVERS_1800 0x720
62#define MUSB_HWVERS_1900 0x784
63#define MUSB_HWVERS_2000 0x800
55 64
56#include "musb_debug.h" 65#include "musb_debug.h"
57#include "musb_dma.h" 66#include "musb_dma.h"
@@ -322,6 +331,7 @@ struct musb {
322 struct clk *clock; 331 struct clk *clock;
323 irqreturn_t (*isr)(int, void *); 332 irqreturn_t (*isr)(int, void *);
324 struct work_struct irq_work; 333 struct work_struct irq_work;
334 u16 hwvers;
325 335
326/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */ 336/* this hub status bit is reserved by USB 2.0 and not seen by usbcore */
327#define MUSB_PORT_STAT_RESUME (1 << 31) 337#define MUSB_PORT_STAT_RESUME (1 << 31)
@@ -403,22 +413,15 @@ struct musb {
403 413
404 unsigned hb_iso_rx:1; /* high bandwidth iso rx? */ 414 unsigned hb_iso_rx:1; /* high bandwidth iso rx? */
405 unsigned hb_iso_tx:1; /* high bandwidth iso tx? */ 415 unsigned hb_iso_tx:1; /* high bandwidth iso tx? */
416 unsigned dyn_fifo:1; /* dynamic FIFO supported? */
406 417
407#ifdef C_MP_TX 418 unsigned bulk_split:1;
408 unsigned bulk_split:1;
409#define can_bulk_split(musb,type) \ 419#define can_bulk_split(musb,type) \
410 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_split) 420 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_split)
411#else
412#define can_bulk_split(musb, type) 0
413#endif
414 421
415#ifdef C_MP_RX 422 unsigned bulk_combine:1;
416 unsigned bulk_combine:1;
417#define can_bulk_combine(musb,type) \ 423#define can_bulk_combine(musb,type) \
418 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine) 424 (((type) == USB_ENDPOINT_XFER_BULK) && (musb)->bulk_combine)
419#else
420#define can_bulk_combine(musb, type) 0
421#endif
422 425
423#ifdef CONFIG_USB_GADGET_MUSB_HDRC 426#ifdef CONFIG_USB_GADGET_MUSB_HDRC
424 /* is_suspended means USB B_PERIPHERAL suspend */ 427 /* is_suspended means USB B_PERIPHERAL suspend */
@@ -453,6 +456,45 @@ struct musb {
453#endif 456#endif
454}; 457};
455 458
459#ifdef CONFIG_PM
460struct musb_csr_regs {
461 /* FIFO registers */
462 u16 txmaxp, txcsr, rxmaxp, rxcsr;
463 u16 rxfifoadd, txfifoadd;
464 u8 txtype, txinterval, rxtype, rxinterval;
465 u8 rxfifosz, txfifosz;
466 u8 txfunaddr, txhubaddr, txhubport;
467 u8 rxfunaddr, rxhubaddr, rxhubport;
468};
469
470struct musb_context_registers {
471
472#ifdef CONFIG_PM
473 u32 otg_sysconfig, otg_forcestandby;
474#endif
475 u8 power;
476 u16 intrtxe, intrrxe;
477 u8 intrusbe;
478 u16 frame;
479 u8 index, testmode;
480
481 u8 devctl, busctl, misc;
482
483 struct musb_csr_regs index_regs[MUSB_C_NUM_EPS];
484};
485
486#ifdef CONFIG_PM
487extern void musb_platform_save_context(struct musb *musb,
488 struct musb_context_registers *musb_context);
489extern void musb_platform_restore_context(struct musb *musb,
490 struct musb_context_registers *musb_context);
491#else
492#define musb_platform_save_context(m, x) do {} while (0)
493#define musb_platform_restore_context(m, x) do {} while (0)
494#endif
495
496#endif
497
456static inline void musb_set_vbus(struct musb *musb, int is_on) 498static inline void musb_set_vbus(struct musb *musb, int is_on)
457{ 499{
458 musb->board_set_vbus(musb, is_on); 500 musb->board_set_vbus(musb, is_on);
@@ -554,7 +596,7 @@ extern void musb_hnp_stop(struct musb *musb);
554extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode); 596extern int musb_platform_set_mode(struct musb *musb, u8 musb_mode);
555 597
556#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \ 598#if defined(CONFIG_USB_TUSB6010) || defined(CONFIG_BLACKFIN) || \
557 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP34XX) 599 defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3)
558extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout); 600extern void musb_platform_try_idle(struct musb *musb, unsigned long timeout);
559#else 601#else
560#define musb_platform_try_idle(x, y) do {} while (0) 602#define musb_platform_try_idle(x, y) do {} while (0)
diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 0a2c4e3602c1..916065ba9e70 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -80,6 +80,17 @@ struct musb_hw_ep;
80#define tusb_dma_omap() 0 80#define tusb_dma_omap() 0
81#endif 81#endif
82 82
83/* Anomaly 05000456 - USB Receive Interrupt Is Not Generated in DMA Mode 1
84 * Only allow DMA mode 1 to be used when the USB will actually generate the
85 * interrupts we expect.
86 */
87#ifdef CONFIG_BLACKFIN
88# undef USE_MODE1
89# if !ANOMALY_05000456
90# define USE_MODE1
91# endif
92#endif
93
83/* 94/*
84 * DMA channel status ... updated by the dma controller driver whenever that 95 * DMA channel status ... updated by the dma controller driver whenever that
85 * status changes, and protected by the overall controller spinlock. 96 * status changes, and protected by the overall controller spinlock.
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 74073f9a43f0..6fca870e957e 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -43,6 +43,7 @@
43#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
44#include <linux/stat.h> 44#include <linux/stat.h>
45#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
46#include <linux/slab.h>
46 47
47#include "musb_core.h" 48#include "musb_core.h"
48 49
@@ -309,7 +310,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
309 size_t request_size; 310 size_t request_size;
310 311
311 /* setup DMA, then program endpoint CSR */ 312 /* setup DMA, then program endpoint CSR */
312 request_size = min(request->length, 313 request_size = min_t(size_t, request->length,
313 musb_ep->dma->max_len); 314 musb_ep->dma->max_len);
314 if (request_size < musb_ep->packet_sz) 315 if (request_size < musb_ep->packet_sz)
315 musb_ep->dma->desired_mode = 0; 316 musb_ep->dma->desired_mode = 0;
@@ -319,7 +320,7 @@ static void txstate(struct musb *musb, struct musb_request *req)
319 use_dma = use_dma && c->channel_program( 320 use_dma = use_dma && c->channel_program(
320 musb_ep->dma, musb_ep->packet_sz, 321 musb_ep->dma, musb_ep->packet_sz,
321 musb_ep->dma->desired_mode, 322 musb_ep->dma->desired_mode,
322 request->dma, request_size); 323 request->dma + request->actual, request_size);
323 if (use_dma) { 324 if (use_dma) {
324 if (musb_ep->dma->desired_mode == 0) { 325 if (musb_ep->dma->desired_mode == 0) {
325 /* 326 /*
@@ -429,112 +430,102 @@ void musb_g_tx(struct musb *musb, u8 epnum)
429 DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr); 430 DBG(4, "<== %s, txcsr %04x\n", musb_ep->end_point.name, csr);
430 431
431 dma = is_dma_capable() ? musb_ep->dma : NULL; 432 dma = is_dma_capable() ? musb_ep->dma : NULL;
432 do { 433
433 /* REVISIT for high bandwidth, MUSB_TXCSR_P_INCOMPTX 434 /*
434 * probably rates reporting as a host error 435 * REVISIT: for high bandwidth, MUSB_TXCSR_P_INCOMPTX
436 * probably rates reporting as a host error.
437 */
438 if (csr & MUSB_TXCSR_P_SENTSTALL) {
439 csr |= MUSB_TXCSR_P_WZC_BITS;
440 csr &= ~MUSB_TXCSR_P_SENTSTALL;
441 musb_writew(epio, MUSB_TXCSR, csr);
442 return;
443 }
444
445 if (csr & MUSB_TXCSR_P_UNDERRUN) {
446 /* We NAKed, no big deal... little reason to care. */
447 csr |= MUSB_TXCSR_P_WZC_BITS;
448 csr &= ~(MUSB_TXCSR_P_UNDERRUN | MUSB_TXCSR_TXPKTRDY);
449 musb_writew(epio, MUSB_TXCSR, csr);
450 DBG(20, "underrun on ep%d, req %p\n", epnum, request);
451 }
452
453 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
454 /*
455 * SHOULD NOT HAPPEN... has with CPPI though, after
456 * changing SENDSTALL (and other cases); harmless?
435 */ 457 */
436 if (csr & MUSB_TXCSR_P_SENTSTALL) { 458 DBG(5, "%s dma still busy?\n", musb_ep->end_point.name);
437 csr |= MUSB_TXCSR_P_WZC_BITS; 459 return;
438 csr &= ~MUSB_TXCSR_P_SENTSTALL; 460 }
439 musb_writew(epio, MUSB_TXCSR, csr); 461
440 break; 462 if (request) {
441 } 463 u8 is_dma = 0;
442 464
443 if (csr & MUSB_TXCSR_P_UNDERRUN) { 465 if (dma && (csr & MUSB_TXCSR_DMAENAB)) {
444 /* we NAKed, no big deal ... little reason to care */ 466 is_dma = 1;
445 csr |= MUSB_TXCSR_P_WZC_BITS; 467 csr |= MUSB_TXCSR_P_WZC_BITS;
446 csr &= ~(MUSB_TXCSR_P_UNDERRUN 468 csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN |
447 | MUSB_TXCSR_TXPKTRDY); 469 MUSB_TXCSR_TXPKTRDY);
448 musb_writew(epio, MUSB_TXCSR, csr); 470 musb_writew(epio, MUSB_TXCSR, csr);
449 DBG(20, "underrun on ep%d, req %p\n", epnum, request); 471 /* Ensure writebuffer is empty. */
472 csr = musb_readw(epio, MUSB_TXCSR);
473 request->actual += musb_ep->dma->actual_len;
474 DBG(4, "TXCSR%d %04x, DMA off, len %zu, req %p\n",
475 epnum, csr, musb_ep->dma->actual_len, request);
450 } 476 }
451 477
452 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) { 478 if (is_dma || request->actual == request->length) {
453 /* SHOULD NOT HAPPEN ... has with cppi though, after 479 /*
454 * changing SENDSTALL (and other cases); harmless? 480 * First, maybe a terminating short packet. Some DMA
481 * engines might handle this by themselves.
455 */ 482 */
456 DBG(5, "%s dma still busy?\n", musb_ep->end_point.name); 483 if ((request->zero && request->length
457 break; 484 && request->length % musb_ep->packet_sz == 0)
458 } 485#ifdef CONFIG_USB_INVENTRA_DMA
459 486 || (is_dma && (!dma->desired_mode ||
460 if (request) { 487 (request->actual &
461 u8 is_dma = 0; 488 (musb_ep->packet_sz - 1))))
489#endif
490 ) {
491 /*
492 * On DMA completion, FIFO may not be
493 * available yet...
494 */
495 if (csr & MUSB_TXCSR_TXPKTRDY)
496 return;
462 497
463 if (dma && (csr & MUSB_TXCSR_DMAENAB)) { 498 DBG(4, "sending zero pkt\n");
464 is_dma = 1; 499 musb_writew(epio, MUSB_TXCSR, MUSB_TXCSR_MODE
465 csr |= MUSB_TXCSR_P_WZC_BITS;
466 csr &= ~(MUSB_TXCSR_DMAENAB
467 | MUSB_TXCSR_P_UNDERRUN
468 | MUSB_TXCSR_TXPKTRDY); 500 | MUSB_TXCSR_TXPKTRDY);
469 musb_writew(epio, MUSB_TXCSR, csr); 501 request->zero = 0;
470 /* ensure writebuffer is empty */
471 csr = musb_readw(epio, MUSB_TXCSR);
472 request->actual += musb_ep->dma->actual_len;
473 DBG(4, "TXCSR%d %04x, dma off, "
474 "len %zu, req %p\n",
475 epnum, csr,
476 musb_ep->dma->actual_len,
477 request);
478 } 502 }
479 503
480 if (is_dma || request->actual == request->length) { 504 /* ... or if not, then complete it. */
481 505 musb_g_giveback(musb_ep, request, 0);
482 /* First, maybe a terminating short packet.
483 * Some DMA engines might handle this by
484 * themselves.
485 */
486 if ((request->zero
487 && request->length
488 && (request->length
489 % musb_ep->packet_sz)
490 == 0)
491#ifdef CONFIG_USB_INVENTRA_DMA
492 || (is_dma &&
493 ((!dma->desired_mode) ||
494 (request->actual &
495 (musb_ep->packet_sz - 1))))
496#endif
497 ) {
498 /* on dma completion, fifo may not
499 * be available yet ...
500 */
501 if (csr & MUSB_TXCSR_TXPKTRDY)
502 break;
503
504 DBG(4, "sending zero pkt\n");
505 musb_writew(epio, MUSB_TXCSR,
506 MUSB_TXCSR_MODE
507 | MUSB_TXCSR_TXPKTRDY);
508 request->zero = 0;
509 }
510
511 /* ... or if not, then complete it */
512 musb_g_giveback(musb_ep, request, 0);
513 506
514 /* kickstart next transfer if appropriate; 507 /*
515 * the packet that just completed might not 508 * Kickstart next transfer if appropriate;
516 * be transmitted for hours or days. 509 * the packet that just completed might not
517 * REVISIT for double buffering... 510 * be transmitted for hours or days.
518 * FIXME revisit for stalls too... 511 * REVISIT for double buffering...
519 */ 512 * FIXME revisit for stalls too...
520 musb_ep_select(mbase, epnum); 513 */
521 csr = musb_readw(epio, MUSB_TXCSR); 514 musb_ep_select(mbase, epnum);
522 if (csr & MUSB_TXCSR_FIFONOTEMPTY) 515 csr = musb_readw(epio, MUSB_TXCSR);
523 break; 516 if (csr & MUSB_TXCSR_FIFONOTEMPTY)
524 request = musb_ep->desc 517 return;
525 ? next_request(musb_ep) 518
526 : NULL; 519 request = musb_ep->desc ? next_request(musb_ep) : NULL;
527 if (!request) { 520 if (!request) {
528 DBG(4, "%s idle now\n", 521 DBG(4, "%s idle now\n",
529 musb_ep->end_point.name); 522 musb_ep->end_point.name);
530 break; 523 return;
531 }
532 } 524 }
533
534 txstate(musb, to_musb_request(request));
535 } 525 }
536 526
537 } while (0); 527 txstate(musb, to_musb_request(request));
528 }
538} 529}
539 530
540/* ------------------------------------------------------------ */ 531/* ------------------------------------------------------------ */
@@ -756,6 +747,8 @@ void musb_g_rx(struct musb *musb, u8 epnum)
756 musb_ep_select(mbase, epnum); 747 musb_ep_select(mbase, epnum);
757 748
758 request = next_request(musb_ep); 749 request = next_request(musb_ep);
750 if (!request)
751 return;
759 752
760 csr = musb_readw(epio, MUSB_RXCSR); 753 csr = musb_readw(epio, MUSB_RXCSR);
761 dma = is_dma_capable() ? musb_ep->dma : NULL; 754 dma = is_dma_capable() ? musb_ep->dma : NULL;
@@ -903,7 +896,14 @@ static int musb_gadget_enable(struct usb_ep *ep,
903 /* REVISIT if can_bulk_split(), use by updating "tmp"; 896 /* REVISIT if can_bulk_split(), use by updating "tmp";
904 * likewise high bandwidth periodic tx 897 * likewise high bandwidth periodic tx
905 */ 898 */
906 musb_writew(regs, MUSB_TXMAXP, tmp); 899 /* Set TXMAXP with the FIFO size of the endpoint
900 * to disable double buffering mode. Currently, It seems that double
901 * buffering has problem if musb RTL revision number < 2.0.
902 */
903 if (musb->hwvers < MUSB_HWVERS_2000)
904 musb_writew(regs, MUSB_TXMAXP, hw_ep->max_packet_sz_tx);
905 else
906 musb_writew(regs, MUSB_TXMAXP, tmp);
907 907
908 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG; 908 csr = MUSB_TXCSR_MODE | MUSB_TXCSR_CLRDATATOG;
909 if (musb_readw(regs, MUSB_TXCSR) 909 if (musb_readw(regs, MUSB_TXCSR)
@@ -933,7 +933,13 @@ static int musb_gadget_enable(struct usb_ep *ep,
933 /* REVISIT if can_bulk_combine() use by updating "tmp" 933 /* REVISIT if can_bulk_combine() use by updating "tmp"
934 * likewise high bandwidth periodic rx 934 * likewise high bandwidth periodic rx
935 */ 935 */
936 musb_writew(regs, MUSB_RXMAXP, tmp); 936 /* Set RXMAXP with the FIFO size of the endpoint
937 * to disable double buffering mode.
938 */
939 if (musb->hwvers < MUSB_HWVERS_2000)
940 musb_writew(regs, MUSB_RXMAXP, hw_ep->max_packet_sz_rx);
941 else
942 musb_writew(regs, MUSB_RXMAXP, tmp);
937 943
938 /* force shared fifo to OUT-only mode */ 944 /* force shared fifo to OUT-only mode */
939 if (hw_ep->is_shared_fifo) { 945 if (hw_ep->is_shared_fifo) {
@@ -966,6 +972,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
966 972
967 musb_ep->desc = desc; 973 musb_ep->desc = desc;
968 musb_ep->busy = 0; 974 musb_ep->busy = 0;
975 musb_ep->wedged = 0;
969 status = 0; 976 status = 0;
970 977
971 pr_debug("%s periph: enabled %s for %s %s, %smaxpacket %d\n", 978 pr_debug("%s periph: enabled %s for %s %s, %smaxpacket %d\n",
@@ -1220,7 +1227,7 @@ done:
1220 * 1227 *
1221 * exported to ep0 code 1228 * exported to ep0 code
1222 */ 1229 */
1223int musb_gadget_set_halt(struct usb_ep *ep, int value) 1230static int musb_gadget_set_halt(struct usb_ep *ep, int value)
1224{ 1231{
1225 struct musb_ep *musb_ep = to_musb_ep(ep); 1232 struct musb_ep *musb_ep = to_musb_ep(ep);
1226 u8 epnum = musb_ep->current_epnum; 1233 u8 epnum = musb_ep->current_epnum;
@@ -1262,7 +1269,8 @@ int musb_gadget_set_halt(struct usb_ep *ep, int value)
1262 goto done; 1269 goto done;
1263 } 1270 }
1264 } 1271 }
1265 } 1272 } else
1273 musb_ep->wedged = 0;
1266 1274
1267 /* set/clear the stall and toggle bits */ 1275 /* set/clear the stall and toggle bits */
1268 DBG(2, "%s: %s stall\n", ep->name, value ? "set" : "clear"); 1276 DBG(2, "%s: %s stall\n", ep->name, value ? "set" : "clear");
@@ -1301,6 +1309,21 @@ done:
1301 return status; 1309 return status;
1302} 1310}
1303 1311
1312/*
1313 * Sets the halt feature with the clear requests ignored
1314 */
1315static int musb_gadget_set_wedge(struct usb_ep *ep)
1316{
1317 struct musb_ep *musb_ep = to_musb_ep(ep);
1318
1319 if (!ep)
1320 return -EINVAL;
1321
1322 musb_ep->wedged = 1;
1323
1324 return usb_ep_set_halt(ep);
1325}
1326
1304static int musb_gadget_fifo_status(struct usb_ep *ep) 1327static int musb_gadget_fifo_status(struct usb_ep *ep)
1305{ 1328{
1306 struct musb_ep *musb_ep = to_musb_ep(ep); 1329 struct musb_ep *musb_ep = to_musb_ep(ep);
@@ -1371,6 +1394,7 @@ static const struct usb_ep_ops musb_ep_ops = {
1371 .queue = musb_gadget_queue, 1394 .queue = musb_gadget_queue,
1372 .dequeue = musb_gadget_dequeue, 1395 .dequeue = musb_gadget_dequeue,
1373 .set_halt = musb_gadget_set_halt, 1396 .set_halt = musb_gadget_set_halt,
1397 .set_wedge = musb_gadget_set_wedge,
1374 .fifo_status = musb_gadget_fifo_status, 1398 .fifo_status = musb_gadget_fifo_status,
1375 .fifo_flush = musb_gadget_fifo_flush 1399 .fifo_flush = musb_gadget_fifo_flush
1376}; 1400};
@@ -1687,8 +1711,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1687 return -EINVAL; 1711 return -EINVAL;
1688 1712
1689 /* driver must be initialized to support peripheral mode */ 1713 /* driver must be initialized to support peripheral mode */
1690 if (!musb || !(musb->board_mode == MUSB_OTG 1714 if (!musb) {
1691 || musb->board_mode != MUSB_OTG)) {
1692 DBG(1, "%s, no dev??\n", __func__); 1715 DBG(1, "%s, no dev??\n", __func__);
1693 return -ENODEV; 1716 return -ENODEV;
1694 } 1717 }
@@ -1723,6 +1746,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1723 spin_lock_irqsave(&musb->lock, flags); 1746 spin_lock_irqsave(&musb->lock, flags);
1724 1747
1725 otg_set_peripheral(musb->xceiv, &musb->g); 1748 otg_set_peripheral(musb->xceiv, &musb->g);
1749 musb->xceiv->state = OTG_STATE_B_IDLE;
1726 musb->is_active = 1; 1750 musb->is_active = 1;
1727 1751
1728 /* FIXME this ignores the softconnect flag. Drivers are 1752 /* FIXME this ignores the softconnect flag. Drivers are
diff --git a/drivers/usb/musb/musb_gadget.h b/drivers/usb/musb/musb_gadget.h
index 59502da9f739..c8b140325d82 100644
--- a/drivers/usb/musb/musb_gadget.h
+++ b/drivers/usb/musb/musb_gadget.h
@@ -75,6 +75,8 @@ struct musb_ep {
75 /* later things are modified based on usage */ 75 /* later things are modified based on usage */
76 struct list_head req_list; 76 struct list_head req_list;
77 77
78 u8 wedged;
79
78 /* true if lock must be dropped but req_list may not be advanced */ 80 /* true if lock must be dropped but req_list may not be advanced */
79 u8 busy; 81 u8 busy;
80}; 82};
@@ -103,6 +105,4 @@ extern void musb_gadget_cleanup(struct musb *);
103 105
104extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int); 106extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
105 107
106extern int musb_gadget_set_halt(struct usb_ep *ep, int value);
107
108#endif /* __MUSB_GADGET_H */ 108#endif /* __MUSB_GADGET_H */
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 522efb31b56b..53d06451f820 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -199,7 +199,6 @@ service_in_request(struct musb *musb, const struct usb_ctrlrequest *ctrlrequest)
199static void musb_g_ep0_giveback(struct musb *musb, struct usb_request *req) 199static void musb_g_ep0_giveback(struct musb *musb, struct usb_request *req)
200{ 200{
201 musb_g_giveback(&musb->endpoints[0].ep_in, req, 0); 201 musb_g_giveback(&musb->endpoints[0].ep_in, req, 0);
202 musb->ep0_state = MUSB_EP0_STAGE_SETUP;
203} 202}
204 203
205/* 204/*
@@ -258,30 +257,53 @@ __acquires(musb->lock)
258 case USB_RECIP_INTERFACE: 257 case USB_RECIP_INTERFACE:
259 break; 258 break;
260 case USB_RECIP_ENDPOINT:{ 259 case USB_RECIP_ENDPOINT:{
261 const u8 num = ctrlrequest->wIndex & 0x0f; 260 const u8 epnum =
262 struct musb_ep *musb_ep; 261 ctrlrequest->wIndex & 0x0f;
262 struct musb_ep *musb_ep;
263 struct musb_hw_ep *ep;
264 void __iomem *regs;
265 int is_in;
266 u16 csr;
263 267
264 if (num == 0 268 if (epnum == 0 || epnum >= MUSB_C_NUM_EPS ||
265 || num >= MUSB_C_NUM_EPS 269 ctrlrequest->wValue != USB_ENDPOINT_HALT)
266 || ctrlrequest->wValue
267 != USB_ENDPOINT_HALT)
268 break; 270 break;
269 271
270 if (ctrlrequest->wIndex & USB_DIR_IN) 272 ep = musb->endpoints + epnum;
271 musb_ep = &musb->endpoints[num].ep_in; 273 regs = ep->regs;
274 is_in = ctrlrequest->wIndex & USB_DIR_IN;
275 if (is_in)
276 musb_ep = &ep->ep_in;
272 else 277 else
273 musb_ep = &musb->endpoints[num].ep_out; 278 musb_ep = &ep->ep_out;
274 if (!musb_ep->desc) 279 if (!musb_ep->desc)
275 break; 280 break;
276 281
277 /* REVISIT do it directly, no locking games */ 282 handled = 1;
278 spin_unlock(&musb->lock); 283 /* Ignore request if endpoint is wedged */
279 musb_gadget_set_halt(&musb_ep->end_point, 0); 284 if (musb_ep->wedged)
280 spin_lock(&musb->lock); 285 break;
286
287 musb_ep_select(mbase, epnum);
288 if (is_in) {
289 csr = musb_readw(regs, MUSB_TXCSR);
290 csr |= MUSB_TXCSR_CLRDATATOG |
291 MUSB_TXCSR_P_WZC_BITS;
292 csr &= ~(MUSB_TXCSR_P_SENDSTALL |
293 MUSB_TXCSR_P_SENTSTALL |
294 MUSB_TXCSR_TXPKTRDY);
295 musb_writew(regs, MUSB_TXCSR, csr);
296 } else {
297 csr = musb_readw(regs, MUSB_RXCSR);
298 csr |= MUSB_RXCSR_CLRDATATOG |
299 MUSB_RXCSR_P_WZC_BITS;
300 csr &= ~(MUSB_RXCSR_P_SENDSTALL |
301 MUSB_RXCSR_P_SENTSTALL);
302 musb_writew(regs, MUSB_RXCSR, csr);
303 }
281 304
282 /* select ep0 again */ 305 /* select ep0 again */
283 musb_ep_select(mbase, 0); 306 musb_ep_select(mbase, 0);
284 handled = 1;
285 } break; 307 } break;
286 default: 308 default:
287 /* class, vendor, etc ... delegate */ 309 /* class, vendor, etc ... delegate */
@@ -374,10 +396,8 @@ stall:
374 int is_in; 396 int is_in;
375 u16 csr; 397 u16 csr;
376 398
377 if (epnum == 0 399 if (epnum == 0 || epnum >= MUSB_C_NUM_EPS ||
378 || epnum >= MUSB_C_NUM_EPS 400 ctrlrequest->wValue != USB_ENDPOINT_HALT)
379 || ctrlrequest->wValue
380 != USB_ENDPOINT_HALT)
381 break; 401 break;
382 402
383 ep = musb->endpoints + epnum; 403 ep = musb->endpoints + epnum;
@@ -392,24 +412,20 @@ stall:
392 412
393 musb_ep_select(mbase, epnum); 413 musb_ep_select(mbase, epnum);
394 if (is_in) { 414 if (is_in) {
395 csr = musb_readw(regs, 415 csr = musb_readw(regs, MUSB_TXCSR);
396 MUSB_TXCSR);
397 if (csr & MUSB_TXCSR_FIFONOTEMPTY) 416 if (csr & MUSB_TXCSR_FIFONOTEMPTY)
398 csr |= MUSB_TXCSR_FLUSHFIFO; 417 csr |= MUSB_TXCSR_FLUSHFIFO;
399 csr |= MUSB_TXCSR_P_SENDSTALL 418 csr |= MUSB_TXCSR_P_SENDSTALL
400 | MUSB_TXCSR_CLRDATATOG 419 | MUSB_TXCSR_CLRDATATOG
401 | MUSB_TXCSR_P_WZC_BITS; 420 | MUSB_TXCSR_P_WZC_BITS;
402 musb_writew(regs, MUSB_TXCSR, 421 musb_writew(regs, MUSB_TXCSR, csr);
403 csr);
404 } else { 422 } else {
405 csr = musb_readw(regs, 423 csr = musb_readw(regs, MUSB_RXCSR);
406 MUSB_RXCSR);
407 csr |= MUSB_RXCSR_P_SENDSTALL 424 csr |= MUSB_RXCSR_P_SENDSTALL
408 | MUSB_RXCSR_FLUSHFIFO 425 | MUSB_RXCSR_FLUSHFIFO
409 | MUSB_RXCSR_CLRDATATOG 426 | MUSB_RXCSR_CLRDATATOG
410 | MUSB_RXCSR_P_WZC_BITS; 427 | MUSB_RXCSR_P_WZC_BITS;
411 musb_writew(regs, MUSB_RXCSR, 428 musb_writew(regs, MUSB_RXCSR, csr);
412 csr);
413 } 429 }
414 430
415 /* select ep0 again */ 431 /* select ep0 again */
@@ -648,7 +664,7 @@ irqreturn_t musb_g_ep0_irq(struct musb *musb)
648 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; 664 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN;
649 break; 665 break;
650 default: 666 default:
651 ERR("SetupEnd came in a wrong ep0stage %s", 667 ERR("SetupEnd came in a wrong ep0stage %s\n",
652 decode_ep0stage(musb->ep0_state)); 668 decode_ep0stage(musb->ep0_state));
653 } 669 }
654 csr = musb_readw(regs, MUSB_CSR0); 670 csr = musb_readw(regs, MUSB_CSR0);
@@ -771,12 +787,18 @@ setup:
771 handled = service_zero_data_request( 787 handled = service_zero_data_request(
772 musb, &setup); 788 musb, &setup);
773 789
790 /*
791 * We're expecting no data in any case, so
792 * always set the DATAEND bit -- doing this
793 * here helps avoid SetupEnd interrupt coming
794 * in the idle stage when we're stalling...
795 */
796 musb->ackpend |= MUSB_CSR0_P_DATAEND;
797
774 /* status stage might be immediate */ 798 /* status stage might be immediate */
775 if (handled > 0) { 799 if (handled > 0)
776 musb->ackpend |= MUSB_CSR0_P_DATAEND;
777 musb->ep0_state = 800 musb->ep0_state =
778 MUSB_EP0_STAGE_STATUSIN; 801 MUSB_EP0_STAGE_STATUSIN;
779 }
780 break; 802 break;
781 803
782 /* sequence #1 (IN to host), includes GET_STATUS 804 /* sequence #1 (IN to host), includes GET_STATUS
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index e3ab40a966eb..877d20b1dff9 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -605,8 +605,14 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
605 musb_writeb(ep->regs, MUSB_RXTYPE, qh->type_reg); 605 musb_writeb(ep->regs, MUSB_RXTYPE, qh->type_reg);
606 musb_writeb(ep->regs, MUSB_RXINTERVAL, qh->intv_reg); 606 musb_writeb(ep->regs, MUSB_RXINTERVAL, qh->intv_reg);
607 /* NOTE: bulk combining rewrites high bits of maxpacket */ 607 /* NOTE: bulk combining rewrites high bits of maxpacket */
608 musb_writew(ep->regs, MUSB_RXMAXP, 608 /* Set RXMAXP with the FIFO size of the endpoint
609 qh->maxpacket | ((qh->hb_mult - 1) << 11)); 609 * to disable double buffer mode.
610 */
611 if (musb->hwvers < MUSB_HWVERS_2000)
612 musb_writew(ep->regs, MUSB_RXMAXP, ep->max_packet_sz_rx);
613 else
614 musb_writew(ep->regs, MUSB_RXMAXP,
615 qh->maxpacket | ((qh->hb_mult - 1) << 11));
610 616
611 ep->rx_reinit = 0; 617 ep->rx_reinit = 0;
612} 618}
@@ -1642,18 +1648,18 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1642 c = musb->dma_controller; 1648 c = musb->dma_controller;
1643 1649
1644 if (usb_pipeisoc(pipe)) { 1650 if (usb_pipeisoc(pipe)) {
1645 int status = 0; 1651 int d_status = 0;
1646 struct usb_iso_packet_descriptor *d; 1652 struct usb_iso_packet_descriptor *d;
1647 1653
1648 d = urb->iso_frame_desc + qh->iso_idx; 1654 d = urb->iso_frame_desc + qh->iso_idx;
1649 1655
1650 if (iso_err) { 1656 if (iso_err) {
1651 status = -EILSEQ; 1657 d_status = -EILSEQ;
1652 urb->error_count++; 1658 urb->error_count++;
1653 } 1659 }
1654 if (rx_count > d->length) { 1660 if (rx_count > d->length) {
1655 if (status == 0) { 1661 if (d_status == 0) {
1656 status = -EOVERFLOW; 1662 d_status = -EOVERFLOW;
1657 urb->error_count++; 1663 urb->error_count++;
1658 } 1664 }
1659 DBG(2, "** OVERFLOW %d into %d\n",\ 1665 DBG(2, "** OVERFLOW %d into %d\n",\
@@ -1662,7 +1668,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1662 length = d->length; 1668 length = d->length;
1663 } else 1669 } else
1664 length = rx_count; 1670 length = rx_count;
1665 d->status = status; 1671 d->status = d_status;
1666 buf = urb->transfer_dma + d->offset; 1672 buf = urb->transfer_dma + d->offset;
1667 } else { 1673 } else {
1668 length = rx_count; 1674 length = rx_count;
@@ -1683,7 +1689,7 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1683 dma->desired_mode = 1; 1689 dma->desired_mode = 1;
1684 if (rx_count < hw_ep->max_packet_sz_rx) { 1690 if (rx_count < hw_ep->max_packet_sz_rx) {
1685 length = rx_count; 1691 length = rx_count;
1686 dma->bDesiredMode = 0; 1692 dma->desired_mode = 0;
1687 } else { 1693 } else {
1688 length = urb->transfer_buffer_length; 1694 length = urb->transfer_buffer_length;
1689 } 1695 }
@@ -1771,6 +1777,9 @@ static int musb_schedule(
1771 int best_end, epnum; 1777 int best_end, epnum;
1772 struct musb_hw_ep *hw_ep = NULL; 1778 struct musb_hw_ep *hw_ep = NULL;
1773 struct list_head *head = NULL; 1779 struct list_head *head = NULL;
1780 u8 toggle;
1781 u8 txtype;
1782 struct urb *urb = next_urb(qh);
1774 1783
1775 /* use fixed hardware for control and bulk */ 1784 /* use fixed hardware for control and bulk */
1776 if (qh->type == USB_ENDPOINT_XFER_CONTROL) { 1785 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
@@ -1809,6 +1818,27 @@ static int musb_schedule(
1809 diff -= (qh->maxpacket * qh->hb_mult); 1818 diff -= (qh->maxpacket * qh->hb_mult);
1810 1819
1811 if (diff >= 0 && best_diff > diff) { 1820 if (diff >= 0 && best_diff > diff) {
1821
1822 /*
1823 * Mentor controller has a bug in that if we schedule
1824 * a BULK Tx transfer on an endpoint that had earlier
1825 * handled ISOC then the BULK transfer has to start on
1826 * a zero toggle. If the BULK transfer starts on a 1
1827 * toggle then this transfer will fail as the mentor
1828 * controller starts the Bulk transfer on a 0 toggle
1829 * irrespective of the programming of the toggle bits
1830 * in the TXCSR register. Check for this condition
1831 * while allocating the EP for a Tx Bulk transfer. If
1832 * so skip this EP.
1833 */
1834 hw_ep = musb->endpoints + epnum;
1835 toggle = usb_gettoggle(urb->dev, qh->epnum, !is_in);
1836 txtype = (musb_readb(hw_ep->regs, MUSB_TXTYPE)
1837 >> 4) & 0x3;
1838 if (!is_in && (qh->type == USB_ENDPOINT_XFER_BULK) &&
1839 toggle && (txtype == USB_ENDPOINT_XFER_ISOC))
1840 continue;
1841
1812 best_diff = diff; 1842 best_diff = diff;
1813 best_end = epnum; 1843 best_end = epnum;
1814 } 1844 }
@@ -2012,6 +2042,7 @@ static int musb_urb_enqueue(
2012 * odd, rare, error prone, but legal. 2042 * odd, rare, error prone, but legal.
2013 */ 2043 */
2014 kfree(qh); 2044 kfree(qh);
2045 qh = NULL;
2015 ret = 0; 2046 ret = 0;
2016 } else 2047 } else
2017 ret = musb_schedule(musb, qh, 2048 ret = musb_schedule(musb, qh,
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index cc1d71b57d3c..fa55aacc385d 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -72,6 +72,10 @@
72#define MUSB_DEVCTL_HR 0x02 72#define MUSB_DEVCTL_HR 0x02
73#define MUSB_DEVCTL_SESSION 0x01 73#define MUSB_DEVCTL_SESSION 0x01
74 74
75/* MUSB ULPI VBUSCONTROL */
76#define MUSB_ULPI_USE_EXTVBUS 0x01
77#define MUSB_ULPI_USE_EXTVBUSIND 0x02
78
75/* TESTMODE */ 79/* TESTMODE */
76#define MUSB_TEST_FORCE_HOST 0x80 80#define MUSB_TEST_FORCE_HOST 0x80
77#define MUSB_TEST_FIFO_ACCESS 0x40 81#define MUSB_TEST_FIFO_ACCESS 0x40
@@ -246,6 +250,7 @@
246 250
247/* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */ 251/* REVISIT: vctrl/vstatus: optional vendor utmi+phy register at 0x68 */
248#define MUSB_HWVERS 0x6C /* 8 bit */ 252#define MUSB_HWVERS 0x6C /* 8 bit */
253#define MUSB_ULPI_BUSCONTROL 0x70 /* 8 bit */
249 254
250#define MUSB_EPINFO 0x78 /* 8 bit */ 255#define MUSB_EPINFO 0x78 /* 8 bit */
251#define MUSB_RAMINFO 0x79 /* 8 bit */ 256#define MUSB_RAMINFO 0x79 /* 8 bit */
@@ -321,6 +326,36 @@ static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off)
321 musb_writew(mbase, MUSB_RXFIFOADD, c_off); 326 musb_writew(mbase, MUSB_RXFIFOADD, c_off);
322} 327}
323 328
329static inline void musb_write_ulpi_buscontrol(void __iomem *mbase, u8 val)
330{
331 musb_writeb(mbase, MUSB_ULPI_BUSCONTROL, val);
332}
333
334static inline u8 musb_read_txfifosz(void __iomem *mbase)
335{
336 return musb_readb(mbase, MUSB_TXFIFOSZ);
337}
338
339static inline u16 musb_read_txfifoadd(void __iomem *mbase)
340{
341 return musb_readw(mbase, MUSB_TXFIFOADD);
342}
343
344static inline u8 musb_read_rxfifosz(void __iomem *mbase)
345{
346 return musb_readb(mbase, MUSB_RXFIFOSZ);
347}
348
349static inline u16 musb_read_rxfifoadd(void __iomem *mbase)
350{
351 return musb_readw(mbase, MUSB_RXFIFOADD);
352}
353
354static inline u8 musb_read_ulpi_buscontrol(void __iomem *mbase)
355{
356 return musb_readb(mbase, MUSB_ULPI_BUSCONTROL);
357}
358
324static inline u8 musb_read_configdata(void __iomem *mbase) 359static inline u8 musb_read_configdata(void __iomem *mbase)
325{ 360{
326 musb_writeb(mbase, MUSB_INDEX, 0); 361 musb_writeb(mbase, MUSB_INDEX, 0);
@@ -376,6 +411,36 @@ static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum,
376 qh_h_port_reg); 411 qh_h_port_reg);
377} 412}
378 413
414static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum)
415{
416 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXFUNCADDR));
417}
418
419static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum)
420{
421 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBADDR));
422}
423
424static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum)
425{
426 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_RXHUBPORT));
427}
428
429static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum)
430{
431 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXFUNCADDR));
432}
433
434static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum)
435{
436 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBADDR));
437}
438
439static inline u8 musb_read_txhubport(void __iomem *mbase, u8 epnum)
440{
441 return musb_readb(mbase, MUSB_BUSCTL_OFFSET(epnum, MUSB_TXHUBPORT));
442}
443
379#else /* CONFIG_BLACKFIN */ 444#else /* CONFIG_BLACKFIN */
380 445
381#define USB_BASE USB_FADDR 446#define USB_BASE USB_FADDR
@@ -436,7 +501,7 @@ static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum,
436#define MUSB_FLAT_OFFSET(_epnum, _offset) \ 501#define MUSB_FLAT_OFFSET(_epnum, _offset) \
437 (USB_OFFSET(USB_EP_NI0_TXMAXP) + (0x40 * (_epnum)) + (_offset)) 502 (USB_OFFSET(USB_EP_NI0_TXMAXP) + (0x40 * (_epnum)) + (_offset))
438 503
439/* Not implemented - HW has seperate Tx/Rx FIFO */ 504/* Not implemented - HW has separate Tx/Rx FIFO */
440#define MUSB_TXCSR_MODE 0x0000 505#define MUSB_TXCSR_MODE 0x0000
441 506
442static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size) 507static inline void musb_write_txfifosz(void __iomem *mbase, u8 c_size)
@@ -455,21 +520,54 @@ static inline void musb_write_rxfifoadd(void __iomem *mbase, u16 c_off)
455{ 520{
456} 521}
457 522
458static inline u8 musb_read_configdata(void __iomem *mbase) 523static inline void musb_write_ulpi_buscontrol(void __iomem *mbase, u8 val)
524{
525}
526
527static inline u8 musb_read_txfifosz(void __iomem *mbase)
459{ 528{
460 return 0; 529 return 0;
461} 530}
462 531
463static inline u16 musb_read_hwvers(void __iomem *mbase) 532static inline u16 musb_read_txfifoadd(void __iomem *mbase)
533{
534 return 0;
535}
536
537static inline u8 musb_read_rxfifosz(void __iomem *mbase)
538{
539 return 0;
540}
541
542static inline u16 musb_read_rxfifoadd(void __iomem *mbase)
543{
544 return 0;
545}
546
547static inline u8 musb_read_ulpi_buscontrol(void __iomem *mbase)
464{ 548{
465 return 0; 549 return 0;
466} 550}
467 551
468static inline u16 musb_read_target_reg_base(u8 i, void __iomem *mbase) 552static inline u8 musb_read_configdata(void __iomem *mbase)
469{ 553{
470 return 0; 554 return 0;
471} 555}
472 556
557static inline u16 musb_read_hwvers(void __iomem *mbase)
558{
559 /*
560 * This register is invisible on Blackfin, actually the MUSB
561 * RTL version of Blackfin is 1.9, so just harcode its value.
562 */
563 return MUSB_HWVERS_1900;
564}
565
566static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem *mbase)
567{
568 return NULL;
569}
570
473static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs, 571static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs,
474 u8 qh_addr_req) 572 u8 qh_addr_req)
475{ 573{
@@ -500,6 +598,35 @@ static inline void musb_write_txhubport(void __iomem *mbase, u8 epnum,
500{ 598{
501} 599}
502 600
601static inline u8 musb_read_rxfunaddr(void __iomem *mbase, u8 epnum)
602{
603 return 0;
604}
605
606static inline u8 musb_read_rxhubaddr(void __iomem *mbase, u8 epnum)
607{
608 return 0;
609}
610
611static inline u8 musb_read_rxhubport(void __iomem *mbase, u8 epnum)
612{
613 return 0;
614}
615
616static inline u8 musb_read_txfunaddr(void __iomem *mbase, u8 epnum)
617{
618 return 0;
619}
620
621static inline u8 musb_read_txhubaddr(void __iomem *mbase, u8 epnum)
622{
623 return 0;
624}
625
626static inline void musb_read_txhubport(void __iomem *mbase, u8 epnum)
627{
628}
629
503#endif /* CONFIG_BLACKFIN */ 630#endif /* CONFIG_BLACKFIN */
504 631
505#endif /* __MUSB_REGS_H__ */ 632#endif /* __MUSB_REGS_H__ */
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index bfe5fe4ebfee..7775e1c0a215 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -35,7 +35,6 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h>
39#include <linux/errno.h> 38#include <linux/errno.h>
40#include <linux/init.h> 39#include <linux/init.h>
41#include <linux/time.h> 40#include <linux/time.h>
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index 5e83f96d6b77..1008044a3bbc 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -33,6 +33,7 @@
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/slab.h>
36#include "musb_core.h" 37#include "musb_core.h"
37#include "musbhsdma.h" 38#include "musbhsdma.h"
38 39
@@ -250,14 +251,38 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
250 u8 bchannel; 251 u8 bchannel;
251 u8 int_hsdma; 252 u8 int_hsdma;
252 253
253 u32 addr; 254 u32 addr, count;
254 u16 csr; 255 u16 csr;
255 256
256 spin_lock_irqsave(&musb->lock, flags); 257 spin_lock_irqsave(&musb->lock, flags);
257 258
258 int_hsdma = musb_readb(mbase, MUSB_HSDMA_INTR); 259 int_hsdma = musb_readb(mbase, MUSB_HSDMA_INTR);
259 if (!int_hsdma) 260
260 goto done; 261#ifdef CONFIG_BLACKFIN
262 /* Clear DMA interrupt flags */
263 musb_writeb(mbase, MUSB_HSDMA_INTR, int_hsdma);
264#endif
265
266 if (!int_hsdma) {
267 DBG(2, "spurious DMA irq\n");
268
269 for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) {
270 musb_channel = (struct musb_dma_channel *)
271 &(controller->channel[bchannel]);
272 channel = &musb_channel->channel;
273 if (channel->status == MUSB_DMA_STATUS_BUSY) {
274 count = musb_read_hsdma_count(mbase, bchannel);
275
276 if (count == 0)
277 int_hsdma |= (1 << bchannel);
278 }
279 }
280
281 DBG(2, "int_hsdma = 0x%x\n", int_hsdma);
282
283 if (!int_hsdma)
284 goto done;
285 }
261 286
262 for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) { 287 for (bchannel = 0; bchannel < MUSB_HSDMA_CHANNELS; bchannel++) {
263 if (int_hsdma & (1 << bchannel)) { 288 if (int_hsdma & (1 << bchannel)) {
@@ -280,7 +305,7 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
280 channel->actual_len = addr 305 channel->actual_len = addr
281 - musb_channel->start_addr; 306 - musb_channel->start_addr;
282 307
283 DBG(2, "ch %p, 0x%x -> 0x%x (%d / %d) %s\n", 308 DBG(2, "ch %p, 0x%x -> 0x%x (%zu / %d) %s\n",
284 channel, musb_channel->start_addr, 309 channel, musb_channel->start_addr,
285 addr, channel->actual_len, 310 addr, channel->actual_len,
286 musb_channel->len, 311 musb_channel->len,
@@ -324,11 +349,6 @@ static irqreturn_t dma_controller_irq(int irq, void *private_data)
324 } 349 }
325 } 350 }
326 351
327#ifdef CONFIG_BLACKFIN
328 /* Clear DMA interrup flags */
329 musb_writeb(mbase, MUSB_HSDMA_INTR, int_hsdma);
330#endif
331
332 retval = IRQ_HANDLED; 352 retval = IRQ_HANDLED;
333done: 353done:
334 spin_unlock_irqrestore(&musb->lock, flags); 354 spin_unlock_irqrestore(&musb->lock, flags);
diff --git a/drivers/usb/musb/musbhsdma.h b/drivers/usb/musb/musbhsdma.h
index 1299d92dc83f..613f95a058f7 100644
--- a/drivers/usb/musb/musbhsdma.h
+++ b/drivers/usb/musb/musbhsdma.h
@@ -55,6 +55,10 @@
55 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \ 55 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_ADDRESS), \
56 addr) 56 addr)
57 57
58#define musb_read_hsdma_count(mbase, bchannel) \
59 musb_readl(mbase, \
60 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT))
61
58#define musb_write_hsdma_count(mbase, bchannel, len) \ 62#define musb_write_hsdma_count(mbase, bchannel, len) \
59 musb_writel(mbase, \ 63 musb_writel(mbase, \
60 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \ 64 MUSB_HSDMA_CHANNEL_OFFSET(bchannel, MUSB_HSDMA_COUNT), \
@@ -96,6 +100,19 @@ static inline void musb_write_hsdma_addr(void __iomem *mbase,
96 ((u16)(((u32) dma_addr >> 16) & 0xFFFF))); 100 ((u16)(((u32) dma_addr >> 16) & 0xFFFF)));
97} 101}
98 102
103static inline u32 musb_read_hsdma_count(void __iomem *mbase, u8 bchannel)
104{
105 u32 count = musb_readw(mbase,
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}
115
99static inline void musb_write_hsdma_count(void __iomem *mbase, 116static inline void musb_write_hsdma_count(void __iomem *mbase,
100 u8 bchannel, u32 len) 117 u8 bchannel, u32 len)
101{ 118{
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 34875201ee04..82592633502f 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -27,7 +27,6 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/sched.h> 29#include <linux/sched.h>
30#include <linux/slab.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/list.h> 31#include <linux/list.h>
33#include <linux/clk.h> 32#include <linux/clk.h>
@@ -35,7 +34,7 @@
35 34
36#include <asm/mach-types.h> 35#include <asm/mach-types.h>
37#include <mach/hardware.h> 36#include <mach/hardware.h>
38#include <mach/mux.h> 37#include <plat/mux.h>
39 38
40#include "musb_core.h" 39#include "musb_core.h"
41#include "omap2430.h" 40#include "omap2430.h"
@@ -220,7 +219,7 @@ int __init musb_platform_init(struct musb *musb)
220 219
221 musb_platform_resume(musb); 220 musb_platform_resume(musb);
222 221
223 l = omap_readl(OTG_SYSCONFIG); 222 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
224 l &= ~ENABLEWAKEUP; /* disable wakeup */ 223 l &= ~ENABLEWAKEUP; /* disable wakeup */
225 l &= ~NOSTDBY; /* remove possible nostdby */ 224 l &= ~NOSTDBY; /* remove possible nostdby */
226 l |= SMARTSTDBY; /* enable smart standby */ 225 l |= SMARTSTDBY; /* enable smart standby */
@@ -233,17 +232,19 @@ int __init musb_platform_init(struct musb *musb)
233 */ 232 */
234 if (!cpu_is_omap3430()) 233 if (!cpu_is_omap3430())
235 l |= AUTOIDLE; /* enable auto idle */ 234 l |= AUTOIDLE; /* enable auto idle */
236 omap_writel(l, OTG_SYSCONFIG); 235 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
237 236
238 l = omap_readl(OTG_INTERFSEL); 237 l = musb_readl(musb->mregs, OTG_INTERFSEL);
239 l |= ULPI_12PIN; 238 l |= ULPI_12PIN;
240 omap_writel(l, OTG_INTERFSEL); 239 musb_writel(musb->mregs, OTG_INTERFSEL, l);
241 240
242 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, " 241 pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
243 "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n", 242 "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
244 omap_readl(OTG_REVISION), omap_readl(OTG_SYSCONFIG), 243 musb_readl(musb->mregs, OTG_REVISION),
245 omap_readl(OTG_SYSSTATUS), omap_readl(OTG_INTERFSEL), 244 musb_readl(musb->mregs, OTG_SYSCONFIG),
246 omap_readl(OTG_SIMENABLE)); 245 musb_readl(musb->mregs, OTG_SYSSTATUS),
246 musb_readl(musb->mregs, OTG_INTERFSEL),
247 musb_readl(musb->mregs, OTG_SIMENABLE));
247 248
248 omap_vbus_power(musb, musb->board_mode == MUSB_HOST, 1); 249 omap_vbus_power(musb, musb->board_mode == MUSB_HOST, 1);
249 250
@@ -255,6 +256,22 @@ int __init musb_platform_init(struct musb *musb)
255 return 0; 256 return 0;
256} 257}
257 258
259#ifdef CONFIG_PM
260void musb_platform_save_context(struct musb *musb,
261 struct musb_context_registers *musb_context)
262{
263 musb_context->otg_sysconfig = musb_readl(musb->mregs, OTG_SYSCONFIG);
264 musb_context->otg_forcestandby = musb_readl(musb->mregs, OTG_FORCESTDBY);
265}
266
267void musb_platform_restore_context(struct musb *musb,
268 struct musb_context_registers *musb_context)
269{
270 musb_writel(musb->mregs, OTG_SYSCONFIG, musb_context->otg_sysconfig);
271 musb_writel(musb->mregs, OTG_FORCESTDBY, musb_context->otg_forcestandby);
272}
273#endif
274
258int musb_platform_suspend(struct musb *musb) 275int musb_platform_suspend(struct musb *musb)
259{ 276{
260 u32 l; 277 u32 l;
@@ -263,13 +280,13 @@ int musb_platform_suspend(struct musb *musb)
263 return 0; 280 return 0;
264 281
265 /* in any role */ 282 /* in any role */
266 l = omap_readl(OTG_FORCESTDBY); 283 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
267 l |= ENABLEFORCE; /* enable MSTANDBY */ 284 l |= ENABLEFORCE; /* enable MSTANDBY */
268 omap_writel(l, OTG_FORCESTDBY); 285 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
269 286
270 l = omap_readl(OTG_SYSCONFIG); 287 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
271 l |= ENABLEWAKEUP; /* enable wakeup */ 288 l |= ENABLEWAKEUP; /* enable wakeup */
272 omap_writel(l, OTG_SYSCONFIG); 289 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
273 290
274 otg_set_suspend(musb->xceiv, 1); 291 otg_set_suspend(musb->xceiv, 1);
275 292
@@ -295,13 +312,13 @@ static int musb_platform_resume(struct musb *musb)
295 else 312 else
296 clk_enable(musb->clock); 313 clk_enable(musb->clock);
297 314
298 l = omap_readl(OTG_SYSCONFIG); 315 l = musb_readl(musb->mregs, OTG_SYSCONFIG);
299 l &= ~ENABLEWAKEUP; /* disable wakeup */ 316 l &= ~ENABLEWAKEUP; /* disable wakeup */
300 omap_writel(l, OTG_SYSCONFIG); 317 musb_writel(musb->mregs, OTG_SYSCONFIG, l);
301 318
302 l = omap_readl(OTG_FORCESTDBY); 319 l = musb_readl(musb->mregs, OTG_FORCESTDBY);
303 l &= ~ENABLEFORCE; /* disable MSTANDBY */ 320 l &= ~ENABLEFORCE; /* disable MSTANDBY */
304 omap_writel(l, OTG_FORCESTDBY); 321 musb_writel(musb->mregs, OTG_FORCESTDBY, l);
305 322
306 return 0; 323 return 0;
307} 324}
@@ -314,8 +331,5 @@ int musb_platform_exit(struct musb *musb)
314 331
315 musb_platform_suspend(musb); 332 musb_platform_suspend(musb);
316 333
317 clk_put(musb->clock);
318 musb->clock = 0;
319
320 return 0; 334 return 0;
321} 335}
diff --git a/drivers/usb/musb/omap2430.h b/drivers/usb/musb/omap2430.h
index dc7670718cd2..40b3c02ae9f0 100644
--- a/drivers/usb/musb/omap2430.h
+++ b/drivers/usb/musb/omap2430.h
@@ -10,47 +10,43 @@
10#ifndef __MUSB_OMAP243X_H__ 10#ifndef __MUSB_OMAP243X_H__
11#define __MUSB_OMAP243X_H__ 11#define __MUSB_OMAP243X_H__
12 12
13#if defined(CONFIG_ARCH_OMAP2430) || defined(CONFIG_ARCH_OMAP3430) 13#include <plat/usb.h>
14#include <mach/hardware.h>
15#include <mach/usb.h>
16 14
17/* 15/*
18 * OMAP2430-specific definitions 16 * OMAP2430-specific definitions
19 */ 17 */
20 18
21#define MENTOR_BASE_OFFSET 0 19#define OTG_REVISION 0x400
22#if defined(CONFIG_ARCH_OMAP2430) 20
23#define OMAP_HSOTG_BASE (OMAP243X_HS_BASE) 21#define OTG_SYSCONFIG 0x404
24#elif defined(CONFIG_ARCH_OMAP3430)
25#define OMAP_HSOTG_BASE (OMAP34XX_HSUSB_OTG_BASE)
26#endif
27#define OMAP_HSOTG(offset) (OMAP_HSOTG_BASE + 0x400 + (offset))
28#define OTG_REVISION OMAP_HSOTG(0x0)
29#define OTG_SYSCONFIG OMAP_HSOTG(0x4)
30# define MIDLEMODE 12 /* bit position */ 22# define MIDLEMODE 12 /* bit position */
31# define FORCESTDBY (0 << MIDLEMODE) 23# define FORCESTDBY (0 << MIDLEMODE)
32# define NOSTDBY (1 << MIDLEMODE) 24# define NOSTDBY (1 << MIDLEMODE)
33# define SMARTSTDBY (2 << MIDLEMODE) 25# define SMARTSTDBY (2 << MIDLEMODE)
26
34# define SIDLEMODE 3 /* bit position */ 27# define SIDLEMODE 3 /* bit position */
35# define FORCEIDLE (0 << SIDLEMODE) 28# define FORCEIDLE (0 << SIDLEMODE)
36# define NOIDLE (1 << SIDLEMODE) 29# define NOIDLE (1 << SIDLEMODE)
37# define SMARTIDLE (2 << SIDLEMODE) 30# define SMARTIDLE (2 << SIDLEMODE)
31
38# define ENABLEWAKEUP (1 << 2) 32# define ENABLEWAKEUP (1 << 2)
39# define SOFTRST (1 << 1) 33# define SOFTRST (1 << 1)
40# define AUTOIDLE (1 << 0) 34# define AUTOIDLE (1 << 0)
41#define OTG_SYSSTATUS OMAP_HSOTG(0x8) 35
36#define OTG_SYSSTATUS 0x408
42# define RESETDONE (1 << 0) 37# define RESETDONE (1 << 0)
43#define OTG_INTERFSEL OMAP_HSOTG(0xc) 38
39#define OTG_INTERFSEL 0x40c
44# define EXTCP (1 << 2) 40# define EXTCP (1 << 2)
45# define PHYSEL 0 /* bit position */ 41# define PHYSEL 0 /* bit position */
46# define UTMI_8BIT (0 << PHYSEL) 42# define UTMI_8BIT (0 << PHYSEL)
47# define ULPI_12PIN (1 << PHYSEL) 43# define ULPI_12PIN (1 << PHYSEL)
48# define ULPI_8PIN (2 << PHYSEL) 44# define ULPI_8PIN (2 << PHYSEL)
49#define OTG_SIMENABLE OMAP_HSOTG(0x10) 45
46#define OTG_SIMENABLE 0x410
50# define TM1 (1 << 0) 47# define TM1 (1 << 0)
51#define OTG_FORCESTDBY OMAP_HSOTG(0x14)
52# define ENABLEFORCE (1 << 0)
53 48
54#endif /* CONFIG_ARCH_OMAP2430 */ 49#define OTG_FORCESTDBY 0x414
50# define ENABLEFORCE (1 << 0)
55 51
56#endif /* __MUSB_OMAP243X_H__ */ 52#endif /* __MUSB_OMAP243X_H__ */
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 88b587c703e9..60d3938cafcf 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -29,6 +29,19 @@ static void tusb_source_power(struct musb *musb, int is_on);
29#define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf) 29#define TUSB_REV_MAJOR(reg_val) ((reg_val >> 4) & 0xf)
30#define TUSB_REV_MINOR(reg_val) (reg_val & 0xf) 30#define TUSB_REV_MINOR(reg_val) (reg_val & 0xf)
31 31
32#ifdef CONFIG_PM
33/* REVISIT: These should be only needed if somebody implements off idle */
34void musb_platform_save_context(struct musb *musb,
35 struct musb_context_registers *musb_context)
36{
37}
38
39void musb_platform_restore_context(struct musb *musb,
40 struct musb_context_registers *musb_context)
41{
42}
43#endif
44
32/* 45/*
33 * Checks the revision. We need to use the DMA register as 3.0 does not 46 * Checks the revision. We need to use the DMA register as 3.0 does not
34 * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV. 47 * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV.
@@ -1118,7 +1131,7 @@ int __init musb_platform_init(struct musb *musb)
1118 } 1131 }
1119 musb->sync = mem->start; 1132 musb->sync = mem->start;
1120 1133
1121 sync = ioremap(mem->start, mem->end - mem->start + 1); 1134 sync = ioremap(mem->start, resource_size(mem));
1122 if (!sync) { 1135 if (!sync) {
1123 pr_debug("ioremap for sync failed\n"); 1136 pr_debug("ioremap for sync failed\n");
1124 ret = -ENOMEM; 1137 ret = -ENOMEM;
diff --git a/drivers/usb/musb/tusb6010_omap.c b/drivers/usb/musb/tusb6010_omap.c
index 7e073a0d7ac9..c061a88f2b0f 100644
--- a/drivers/usb/musb/tusb6010_omap.c
+++ b/drivers/usb/musb/tusb6010_omap.c
@@ -15,8 +15,9 @@
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <mach/dma.h> 18#include <linux/slab.h>
19#include <mach/mux.h> 19#include <plat/dma.h>
20#include <plat/mux.h>
20 21
21#include "musb_core.h" 22#include "musb_core.h"
22 23
@@ -38,7 +39,7 @@ struct tusb_omap_dma_ch {
38 39
39 struct tusb_omap_dma *tusb_dma; 40 struct tusb_omap_dma *tusb_dma;
40 41
41 void __iomem *dma_addr; 42 dma_addr_t dma_addr;
42 43
43 u32 len; 44 u32 len;
44 u16 packet_sz; 45 u16 packet_sz;
@@ -125,6 +126,7 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
125 struct tusb_omap_dma_ch *chdat = to_chdat(channel); 126 struct tusb_omap_dma_ch *chdat = to_chdat(channel);
126 struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; 127 struct tusb_omap_dma *tusb_dma = chdat->tusb_dma;
127 struct musb *musb = chdat->musb; 128 struct musb *musb = chdat->musb;
129 struct device *dev = musb->controller;
128 struct musb_hw_ep *hw_ep = chdat->hw_ep; 130 struct musb_hw_ep *hw_ep = chdat->hw_ep;
129 void __iomem *ep_conf = hw_ep->conf; 131 void __iomem *ep_conf = hw_ep->conf;
130 void __iomem *mbase = musb->mregs; 132 void __iomem *mbase = musb->mregs;
@@ -172,13 +174,15 @@ static void tusb_omap_dma_cb(int lch, u16 ch_status, void *data)
172 DBG(3, "Using PIO for remaining %lu bytes\n", pio); 174 DBG(3, "Using PIO for remaining %lu bytes\n", pio);
173 buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len; 175 buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len;
174 if (chdat->tx) { 176 if (chdat->tx) {
175 dma_cache_maint(phys_to_virt((u32)chdat->dma_addr), 177 dma_unmap_single(dev, chdat->dma_addr,
176 chdat->transfer_len, DMA_TO_DEVICE); 178 chdat->transfer_len,
179 DMA_TO_DEVICE);
177 musb_write_fifo(hw_ep, pio, buf); 180 musb_write_fifo(hw_ep, pio, buf);
178 } else { 181 } else {
182 dma_unmap_single(dev, chdat->dma_addr,
183 chdat->transfer_len,
184 DMA_FROM_DEVICE);
179 musb_read_fifo(hw_ep, pio, buf); 185 musb_read_fifo(hw_ep, pio, buf);
180 dma_cache_maint(phys_to_virt((u32)chdat->dma_addr),
181 chdat->transfer_len, DMA_FROM_DEVICE);
182 } 186 }
183 channel->actual_len += pio; 187 channel->actual_len += pio;
184 } 188 }
@@ -223,6 +227,7 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
223 struct tusb_omap_dma_ch *chdat = to_chdat(channel); 227 struct tusb_omap_dma_ch *chdat = to_chdat(channel);
224 struct tusb_omap_dma *tusb_dma = chdat->tusb_dma; 228 struct tusb_omap_dma *tusb_dma = chdat->tusb_dma;
225 struct musb *musb = chdat->musb; 229 struct musb *musb = chdat->musb;
230 struct device *dev = musb->controller;
226 struct musb_hw_ep *hw_ep = chdat->hw_ep; 231 struct musb_hw_ep *hw_ep = chdat->hw_ep;
227 void __iomem *mbase = musb->mregs; 232 void __iomem *mbase = musb->mregs;
228 void __iomem *ep_conf = hw_ep->conf; 233 void __iomem *ep_conf = hw_ep->conf;
@@ -298,14 +303,16 @@ static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
298 chdat->packet_sz = packet_sz; 303 chdat->packet_sz = packet_sz;
299 chdat->len = len; 304 chdat->len = len;
300 channel->actual_len = 0; 305 channel->actual_len = 0;
301 chdat->dma_addr = (void __iomem *)dma_addr; 306 chdat->dma_addr = dma_addr;
302 channel->status = MUSB_DMA_STATUS_BUSY; 307 channel->status = MUSB_DMA_STATUS_BUSY;
303 308
304 /* Since we're recycling dma areas, we need to clean or invalidate */ 309 /* Since we're recycling dma areas, we need to clean or invalidate */
305 if (chdat->tx) 310 if (chdat->tx)
306 dma_cache_maint(phys_to_virt(dma_addr), len, DMA_TO_DEVICE); 311 dma_map_single(dev, phys_to_virt(dma_addr), len,
312 DMA_TO_DEVICE);
307 else 313 else
308 dma_cache_maint(phys_to_virt(dma_addr), len, DMA_FROM_DEVICE); 314 dma_map_single(dev, phys_to_virt(dma_addr), len,
315 DMA_FROM_DEVICE);
309 316
310 /* Use 16-bit transfer if dma_addr is not 32-bit aligned */ 317 /* Use 16-bit transfer if dma_addr is not 32-bit aligned */
311 if ((dma_addr & 0x3) == 0) { 318 if ((dma_addr & 0x3) == 0) {
@@ -648,7 +655,7 @@ void dma_controller_destroy(struct dma_controller *c)
648 } 655 }
649 } 656 }
650 657
651 if (!tusb_dma->multichannel && tusb_dma && tusb_dma->ch >= 0) 658 if (tusb_dma && !tusb_dma->multichannel && tusb_dma->ch >= 0)
652 omap_free_dma(tusb_dma->ch); 659 omap_free_dma(tusb_dma->ch);
653 660
654 kfree(tusb_dma); 661 kfree(tusb_dma);
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index aa884d072f0b..3d2d3e549bd1 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -41,6 +41,16 @@ config ISP1301_OMAP
41 This driver can also be built as a module. If so, the module 41 This driver can also be built as a module. If so, the module
42 will be called isp1301_omap. 42 will be called isp1301_omap.
43 43
44config USB_ULPI
45 bool "Generic ULPI Transceiver Driver"
46 depends on ARM
47 select USB_OTG_UTILS
48 help
49 Enable this to support ULPI connected USB OTG transceivers which
50 are likely found on embedded boards.
51
52 The only chip currently supported is NXP's ISP1504
53
44config TWL4030_USB 54config TWL4030_USB
45 tristate "TWL4030 USB Transceiver Driver" 55 tristate "TWL4030 USB Transceiver Driver"
46 depends on TWL4030_CORE && REGULATOR_TWL4030 56 depends on TWL4030_CORE && REGULATOR_TWL4030
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index 208167856529..aeb49a8ec412 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o
10obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 10obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
11obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o 11obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o
12obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o 12obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
13obj-$(CONFIG_USB_ULPI) += ulpi.o
13 14
14ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG 15ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG
15ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG 16ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 1c26c94513e9..221c44444ec6 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/gpio.h> 13#include <linux/gpio.h>
14#include <linux/slab.h>
14#include <linux/interrupt.h> 15#include <linux/interrupt.h>
15#include <linux/usb.h> 16#include <linux/usb.h>
16#include <linux/workqueue.h> 17#include <linux/workqueue.h>
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/otg/isp1301_omap.c
index 77a5f4188999..78a209709260 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/otg/isp1301_omap.c
@@ -36,8 +36,8 @@
36#include <asm/irq.h> 36#include <asm/irq.h>
37#include <asm/mach-types.h> 37#include <asm/mach-types.h>
38 38
39#include <mach/usb.h> 39#include <plat/usb.h>
40#include <mach/mux.h> 40#include <plat/mux.h>
41 41
42 42
43#ifndef DEBUG 43#ifndef DEBUG
@@ -843,7 +843,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
843 843
844static struct platform_device *otg_dev; 844static struct platform_device *otg_dev;
845 845
846static int otg_init(struct isp1301 *isp) 846static int isp1301_otg_init(struct isp1301 *isp)
847{ 847{
848 u32 l; 848 u32 l;
849 849
@@ -1275,7 +1275,7 @@ static int __exit isp1301_remove(struct i2c_client *i2c)
1275static int isp1301_otg_enable(struct isp1301 *isp) 1275static int isp1301_otg_enable(struct isp1301 *isp)
1276{ 1276{
1277 power_up(isp); 1277 power_up(isp);
1278 otg_init(isp); 1278 isp1301_otg_init(isp);
1279 1279
1280 /* NOTE: since we don't change this, this provides 1280 /* NOTE: since we don't change this, this provides
1281 * a few more interrupts than are strictly needed. 1281 * a few more interrupts than are strictly needed.
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
index af456b48985f..e70014ab0976 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -30,6 +30,7 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/dma-mapping.h> 31#include <linux/dma-mapping.h>
32#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
33#include <linux/slab.h>
33 34
34struct nop_usb_xceiv { 35struct nop_usb_xceiv {
35 struct otg_transceiver otg; 36 struct otg_transceiver otg;
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 9e3e7a5c258b..223cdf46ccb7 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -33,10 +33,11 @@
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/i2c/twl4030.h> 36#include <linux/i2c/twl.h>
37#include <linux/regulator/consumer.h> 37#include <linux/regulator/consumer.h>
38#include <linux/err.h> 38#include <linux/err.h>
39 39#include <linux/notifier.h>
40#include <linux/slab.h>
40 41
41/* Register defines */ 42/* Register defines */
42 43
@@ -236,15 +237,6 @@
236#define PMBR1 0x0D 237#define PMBR1 0x0D
237#define GPIO_USB_4PIN_ULPI_2430C (3 << 0) 238#define GPIO_USB_4PIN_ULPI_2430C (3 << 0)
238 239
239
240
241enum linkstat {
242 USB_LINK_UNKNOWN = 0,
243 USB_LINK_NONE,
244 USB_LINK_VBUS,
245 USB_LINK_ID,
246};
247
248struct twl4030_usb { 240struct twl4030_usb {
249 struct otg_transceiver otg; 241 struct otg_transceiver otg;
250 struct device *dev; 242 struct device *dev;
@@ -276,16 +268,16 @@ static int twl4030_i2c_write_u8_verify(struct twl4030_usb *twl,
276{ 268{
277 u8 check; 269 u8 check;
278 270
279 if ((twl4030_i2c_write_u8(module, data, address) >= 0) && 271 if ((twl_i2c_write_u8(module, data, address) >= 0) &&
280 (twl4030_i2c_read_u8(module, &check, address) >= 0) && 272 (twl_i2c_read_u8(module, &check, address) >= 0) &&
281 (check == data)) 273 (check == data))
282 return 0; 274 return 0;
283 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", 275 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
284 1, module, address, check, data); 276 1, module, address, check, data);
285 277
286 /* Failed once: Try again */ 278 /* Failed once: Try again */
287 if ((twl4030_i2c_write_u8(module, data, address) >= 0) && 279 if ((twl_i2c_write_u8(module, data, address) >= 0) &&
288 (twl4030_i2c_read_u8(module, &check, address) >= 0) && 280 (twl_i2c_read_u8(module, &check, address) >= 0) &&
289 (check == data)) 281 (check == data))
290 return 0; 282 return 0;
291 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n", 283 dev_dbg(twl->dev, "Write%d[%d,0x%x] wrote %02x but read %02x\n",
@@ -303,7 +295,7 @@ static inline int twl4030_usb_write(struct twl4030_usb *twl,
303{ 295{
304 int ret = 0; 296 int ret = 0;
305 297
306 ret = twl4030_i2c_write_u8(TWL4030_MODULE_USB, data, address); 298 ret = twl_i2c_write_u8(TWL4030_MODULE_USB, data, address);
307 if (ret < 0) 299 if (ret < 0)
308 dev_dbg(twl->dev, 300 dev_dbg(twl->dev,
309 "TWL4030:USB:Write[0x%x] Error %d\n", address, ret); 301 "TWL4030:USB:Write[0x%x] Error %d\n", address, ret);
@@ -315,7 +307,7 @@ static inline int twl4030_readb(struct twl4030_usb *twl, u8 module, u8 address)
315 u8 data; 307 u8 data;
316 int ret = 0; 308 int ret = 0;
317 309
318 ret = twl4030_i2c_read_u8(module, &data, address); 310 ret = twl_i2c_read_u8(module, &data, address);
319 if (ret >= 0) 311 if (ret >= 0)
320 ret = data; 312 ret = data;
321 else 313 else
@@ -347,10 +339,10 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
347 339
348/*-------------------------------------------------------------------------*/ 340/*-------------------------------------------------------------------------*/
349 341
350static enum linkstat twl4030_usb_linkstat(struct twl4030_usb *twl) 342static enum usb_xceiv_events twl4030_usb_linkstat(struct twl4030_usb *twl)
351{ 343{
352 int status; 344 int status;
353 int linkstat = USB_LINK_UNKNOWN; 345 int linkstat = USB_EVENT_NONE;
354 346
355 /* 347 /*
356 * For ID/VBUS sensing, see manual section 15.4.8 ... 348 * For ID/VBUS sensing, see manual section 15.4.8 ...
@@ -368,11 +360,11 @@ static enum linkstat twl4030_usb_linkstat(struct twl4030_usb *twl)
368 dev_err(twl->dev, "USB link status err %d\n", status); 360 dev_err(twl->dev, "USB link status err %d\n", status);
369 else if (status & (BIT(7) | BIT(2))) { 361 else if (status & (BIT(7) | BIT(2))) {
370 if (status & BIT(2)) 362 if (status & BIT(2))
371 linkstat = USB_LINK_ID; 363 linkstat = USB_EVENT_ID;
372 else 364 else
373 linkstat = USB_LINK_VBUS; 365 linkstat = USB_EVENT_VBUS;
374 } else 366 } else
375 linkstat = USB_LINK_NONE; 367 linkstat = USB_EVENT_NONE;
376 368
377 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n", 369 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",
378 status, status, linkstat); 370 status, status, linkstat);
@@ -383,7 +375,7 @@ static enum linkstat twl4030_usb_linkstat(struct twl4030_usb *twl)
383 375
384 spin_lock_irq(&twl->lock); 376 spin_lock_irq(&twl->lock);
385 twl->linkstat = linkstat; 377 twl->linkstat = linkstat;
386 if (linkstat == USB_LINK_ID) { 378 if (linkstat == USB_EVENT_ID) {
387 twl->otg.default_a = true; 379 twl->otg.default_a = true;
388 twl->otg.state = OTG_STATE_A_IDLE; 380 twl->otg.state = OTG_STATE_A_IDLE;
389 } else { 381 } else {
@@ -462,7 +454,7 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
462 * SLEEP. We work around this by clearing the bit after usv3v1 454 * SLEEP. We work around this by clearing the bit after usv3v1
463 * is re-activated. This ensures that VUSB3V1 is really active. 455 * is re-activated. This ensures that VUSB3V1 is really active.
464 */ 456 */
465 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, 457 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0,
466 VUSB_DEDICATED2); 458 VUSB_DEDICATED2);
467 regulator_enable(twl->usb1v5); 459 regulator_enable(twl->usb1v5);
468 pwr &= ~PHY_PWR_PHYPWD; 460 pwr &= ~PHY_PWR_PHYPWD;
@@ -505,44 +497,44 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
505static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 497static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
506{ 498{
507 /* Enable writing to power configuration registers */ 499 /* Enable writing to power configuration registers */
508 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY); 500 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY);
509 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY); 501 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY);
510 502
511 /* put VUSB3V1 LDO in active state */ 503 /* put VUSB3V1 LDO in active state */
512 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); 504 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);
513 505
514 /* input to VUSB3V1 LDO is from VBAT, not VBUS */ 506 /* input to VUSB3V1 LDO is from VBAT, not VBUS */
515 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1); 507 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1);
516 508
517 /* Initialize 3.1V regulator */ 509 /* Initialize 3.1V regulator */
518 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP); 510 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP);
519 511
520 twl->usb3v1 = regulator_get(twl->dev, "usb3v1"); 512 twl->usb3v1 = regulator_get(twl->dev, "usb3v1");
521 if (IS_ERR(twl->usb3v1)) 513 if (IS_ERR(twl->usb3v1))
522 return -ENODEV; 514 return -ENODEV;
523 515
524 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE); 516 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE);
525 517
526 /* Initialize 1.5V regulator */ 518 /* Initialize 1.5V regulator */
527 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP); 519 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP);
528 520
529 twl->usb1v5 = regulator_get(twl->dev, "usb1v5"); 521 twl->usb1v5 = regulator_get(twl->dev, "usb1v5");
530 if (IS_ERR(twl->usb1v5)) 522 if (IS_ERR(twl->usb1v5))
531 goto fail1; 523 goto fail1;
532 524
533 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); 525 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
534 526
535 /* Initialize 1.8V regulator */ 527 /* Initialize 1.8V regulator */
536 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP); 528 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP);
537 529
538 twl->usb1v8 = regulator_get(twl->dev, "usb1v8"); 530 twl->usb1v8 = regulator_get(twl->dev, "usb1v8");
539 if (IS_ERR(twl->usb1v8)) 531 if (IS_ERR(twl->usb1v8))
540 goto fail2; 532 goto fail2;
541 533
542 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); 534 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
543 535
544 /* disable access to power configuration registers */ 536 /* disable access to power configuration registers */
545 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY); 537 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY);
546 538
547 return 0; 539 return 0;
548 540
@@ -564,7 +556,7 @@ static ssize_t twl4030_usb_vbus_show(struct device *dev,
564 556
565 spin_lock_irqsave(&twl->lock, flags); 557 spin_lock_irqsave(&twl->lock, flags);
566 ret = sprintf(buf, "%s\n", 558 ret = sprintf(buf, "%s\n",
567 (twl->linkstat == USB_LINK_VBUS) ? "on" : "off"); 559 (twl->linkstat == USB_EVENT_VBUS) ? "on" : "off");
568 spin_unlock_irqrestore(&twl->lock, flags); 560 spin_unlock_irqrestore(&twl->lock, flags);
569 561
570 return ret; 562 return ret;
@@ -576,17 +568,8 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
576 struct twl4030_usb *twl = _twl; 568 struct twl4030_usb *twl = _twl;
577 int status; 569 int status;
578 570
579#ifdef CONFIG_LOCKDEP
580 /* WORKAROUND for lockdep forcing IRQF_DISABLED on us, which
581 * we don't want and can't tolerate. Although it might be
582 * friendlier not to borrow this thread context...
583 */
584 local_irq_enable();
585#endif
586
587 status = twl4030_usb_linkstat(twl); 571 status = twl4030_usb_linkstat(twl);
588 if (status != USB_LINK_UNKNOWN) { 572 if (status >= 0) {
589
590 /* FIXME add a set_power() method so that B-devices can 573 /* FIXME add a set_power() method so that B-devices can
591 * configure the charger appropriately. It's not always 574 * configure the charger appropriately. It's not always
592 * correct to consume VBUS power, and how much current to 575 * correct to consume VBUS power, and how much current to
@@ -598,12 +581,13 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
598 * USB_LINK_VBUS state. musb_hdrc won't care until it 581 * USB_LINK_VBUS state. musb_hdrc won't care until it
599 * starts to handle softconnect right. 582 * starts to handle softconnect right.
600 */ 583 */
601 twl4030charger_usb_en(status == USB_LINK_VBUS); 584 if (status == USB_EVENT_NONE)
602
603 if (status == USB_LINK_NONE)
604 twl4030_phy_suspend(twl, 0); 585 twl4030_phy_suspend(twl, 0);
605 else 586 else
606 twl4030_phy_resume(twl); 587 twl4030_phy_resume(twl);
588
589 blocking_notifier_call_chain(&twl->otg.notifier, status,
590 twl->otg.gadget);
607 } 591 }
608 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 592 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609 593
@@ -693,6 +677,8 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
693 if (device_create_file(&pdev->dev, &dev_attr_vbus)) 677 if (device_create_file(&pdev->dev, &dev_attr_vbus))
694 dev_warn(&pdev->dev, "could not create sysfs file\n"); 678 dev_warn(&pdev->dev, "could not create sysfs file\n");
695 679
680 BLOCKING_INIT_NOTIFIER_HEAD(&twl->otg.notifier);
681
696 /* Our job is to use irqs and status from the power module 682 /* Our job is to use irqs and status from the power module
697 * to keep the transceiver disabled when nothing's connected. 683 * to keep the transceiver disabled when nothing's connected.
698 * 684 *
@@ -702,7 +688,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
702 * need both handles, otherwise just one suffices. 688 * need both handles, otherwise just one suffices.
703 */ 689 */
704 twl->irq_enabled = true; 690 twl->irq_enabled = true;
705 status = request_irq(twl->irq, twl4030_usb_irq, 691 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq,
706 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 692 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
707 "twl4030_usb", twl); 693 "twl4030_usb", twl);
708 if (status < 0) { 694 if (status < 0) {
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
new file mode 100644
index 000000000000..9010225e0d06
--- /dev/null
+++ b/drivers/usb/otg/ulpi.c
@@ -0,0 +1,137 @@
1/*
2 * Generic ULPI USB transceiver support
3 *
4 * Copyright (C) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * Based on sources from
7 *
8 * Sascha Hauer <s.hauer@pengutronix.de>
9 * Freescale Semiconductors
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
27#include <linux/slab.h>
28#include <linux/usb.h>
29#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h>
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))
55
56#define TR_FLAG(flags, a, b) (((flags) & a) ? b : 0)
57
58/* ULPI hardcoded IDs, used for probing */
59static unsigned int ulpi_ids[] = {
60 ULPI_ID(0x04cc, 0x1504), /* NXP ISP1504 */
61};
62
63static int ulpi_set_flags(struct otg_transceiver *otg)
64{
65 unsigned int flags = 0;
66
67 if (otg->flags & USB_OTG_PULLUP_ID)
68 flags |= ID_PULL_UP;
69
70 if (otg->flags & USB_OTG_PULLDOWN_DM)
71 flags |= DM_PULL_DOWN;
72
73 if (otg->flags & USB_OTG_PULLDOWN_DP)
74 flags |= DP_PULL_DOWN;
75
76 if (otg->flags & USB_OTG_EXT_VBUS_INDICATOR)
77 flags |= USE_EXT_VBUS_IND;
78
79 return otg_io_write(otg, flags, ULPI_OTGCTL + ULPI_REG_SET);
80}
81
82static int ulpi_init(struct otg_transceiver *otg)
83{
84 int i, vid, pid;
85
86 vid = (otg_io_read(otg, ULPI_VID_HIGH) << 8) |
87 otg_io_read(otg, ULPI_VID_LOW);
88 pid = (otg_io_read(otg, ULPI_PID_HIGH) << 8) |
89 otg_io_read(otg, ULPI_PID_LOW);
90
91 pr_info("ULPI transceiver vendor/product ID 0x%04x/0x%04x\n", vid, pid);
92
93 for (i = 0; i < ARRAY_SIZE(ulpi_ids); i++)
94 if (ulpi_ids[i] == ULPI_ID(vid, pid))
95 return ulpi_set_flags(otg);
96
97 pr_err("ULPI ID does not match any known transceiver.\n");
98 return -ENODEV;
99}
100
101static int ulpi_set_vbus(struct otg_transceiver *otg, bool on)
102{
103 unsigned int flags = otg_io_read(otg, ULPI_OTGCTL);
104
105 flags &= ~(DRV_VBUS | DRV_VBUS_EXT);
106
107 if (on) {
108 if (otg->flags & USB_OTG_DRV_VBUS)
109 flags |= DRV_VBUS;
110
111 if (otg->flags & USB_OTG_DRV_VBUS_EXT)
112 flags |= DRV_VBUS_EXT;
113 }
114
115 return otg_io_write(otg, flags, ULPI_OTGCTL + ULPI_REG_SET);
116}
117
118struct otg_transceiver *
119otg_ulpi_create(struct otg_io_access_ops *ops,
120 unsigned int flags)
121{
122 struct otg_transceiver *otg;
123
124 otg = kzalloc(sizeof(*otg), GFP_KERNEL);
125 if (!otg)
126 return NULL;
127
128 otg->label = "ULPI";
129 otg->flags = flags;
130 otg->io_ops = ops;
131 otg->init = ulpi_init;
132 otg->set_vbus = ulpi_set_vbus;
133
134 return otg;
135}
136EXPORT_SYMBOL_GPL(otg_ulpi_create);
137
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index c480ea4c19f2..a0ecb42cb33a 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -472,6 +472,17 @@ config USB_SERIAL_OTI6858
472 To compile this driver as a module, choose M here: the 472 To compile this driver as a module, choose M here: the
473 module will be called oti6858. 473 module will be called oti6858.
474 474
475config USB_SERIAL_QCAUX
476 tristate "USB Qualcomm Auxiliary Serial Port Driver"
477 help
478 Say Y here if you want to use the auxiliary serial ports provided
479 by many modems based on Qualcomm chipsets. These ports often use
480 a proprietary protocol called DM and cannot be used for AT- or
481 PPP-based communication.
482
483 To compile this driver as a module, choose M here: the
484 module will be called qcaux. If unsure, choose N.
485
475config USB_SERIAL_QUALCOMM 486config USB_SERIAL_QUALCOMM
476 tristate "USB Qualcomm Serial modem" 487 tristate "USB Qualcomm Serial modem"
477 help 488 help
@@ -600,6 +611,14 @@ config USB_SERIAL_OPTICON
600 To compile this driver as a module, choose M here: the 611 To compile this driver as a module, choose M here: the
601 module will be called opticon. 612 module will be called opticon.
602 613
614config USB_SERIAL_VIVOPAY_SERIAL
615 tristate "USB ViVOpay serial interface driver"
616 help
617 Say Y here if you want to use a ViVOtech ViVOpay USB device.
618
619 To compile this driver as a module, choose M here: the
620 module will be called vivopay-serial.
621
603config USB_SERIAL_DEBUG 622config USB_SERIAL_DEBUG
604 tristate "USB Debugging Device" 623 tristate "USB Debugging Device"
605 help 624 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 66619beb6cc0..83c9e431a568 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o
45obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 45obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
46obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o 46obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o
47obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 47obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
48obj-$(CONFIG_USB_SERIAL_QCAUX) += qcaux.o
48obj-$(CONFIG_USB_SERIAL_QUALCOMM) += qcserial.o 49obj-$(CONFIG_USB_SERIAL_QUALCOMM) += qcserial.o
49obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 50obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
50obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o 51obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o
@@ -55,4 +56,5 @@ obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
55obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 56obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
56obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 57obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
57obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 58obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o
59obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o
58 60
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index b10ac8409411..4fd7af98b1ae 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -43,6 +43,7 @@
43 */ 43 */
44 44
45#include <linux/tty.h> 45#include <linux/tty.h>
46#include <linux/slab.h>
46#include <linux/tty_flip.h> 47#include <linux/tty_flip.h>
47#include <linux/circ_buf.h> 48#include <linux/circ_buf.h>
48#include <linux/usb.h> 49#include <linux/usb.h>
@@ -78,7 +79,7 @@ static int debug;
78#define DRIVER_DESC "AIRcable USB Driver" 79#define DRIVER_DESC "AIRcable USB Driver"
79 80
80/* ID table that will be registered with USB core */ 81/* ID table that will be registered with USB core */
81static struct usb_device_id id_table [] = { 82static const struct usb_device_id id_table[] = {
82 { USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) }, 83 { USB_DEVICE(AIRCABLE_VID, AIRCABLE_USB_PID) },
83 { }, 84 { },
84}; 85};
@@ -468,10 +469,6 @@ static void aircable_read_bulk_callback(struct urb *urb)
468 469
469 if (status) { 470 if (status) {
470 dbg("%s - urb status = %d", __func__, status); 471 dbg("%s - urb status = %d", __func__, status);
471 if (!port->port.count) {
472 dbg("%s - port is closed, exiting.", __func__);
473 return;
474 }
475 if (status == -EPROTO) { 472 if (status == -EPROTO) {
476 dbg("%s - caught -EPROTO, resubmitting the urb", 473 dbg("%s - caught -EPROTO, resubmitting the urb",
477 __func__); 474 __func__);
@@ -530,23 +527,19 @@ static void aircable_read_bulk_callback(struct urb *urb)
530 } 527 }
531 tty_kref_put(tty); 528 tty_kref_put(tty);
532 529
533 /* Schedule the next read _if_ we are still open */ 530 /* Schedule the next read */
534 if (port->port.count) { 531 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
535 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 532 usb_rcvbulkpipe(port->serial->dev,
536 usb_rcvbulkpipe(port->serial->dev, 533 port->bulk_in_endpointAddress),
537 port->bulk_in_endpointAddress), 534 port->read_urb->transfer_buffer,
538 port->read_urb->transfer_buffer, 535 port->read_urb->transfer_buffer_length,
539 port->read_urb->transfer_buffer_length, 536 aircable_read_bulk_callback, port);
540 aircable_read_bulk_callback, port); 537
541 538 result = usb_submit_urb(urb, GFP_ATOMIC);
542 result = usb_submit_urb(urb, GFP_ATOMIC); 539 if (result && result != -EPERM)
543 if (result) 540 dev_err(&urb->dev->dev,
544 dev_err(&urb->dev->dev, 541 "%s - failed resubmitting read urb, error %d\n",
545 "%s - failed resubmitting read urb, error %d\n", 542 __func__, result);
546 __func__, result);
547 }
548
549 return;
550} 543}
551 544
552/* Based on ftdi_sio.c throttle */ 545/* Based on ftdi_sio.c throttle */
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 131e61adaaf7..9b66bf19f751 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -1,4 +1,6 @@
1/* 1/*
2 * Copyright (C) 2009 by Bart Hartgers (bart.hartgers+ark3116@gmail.com)
3 * Original version:
2 * Copyright (C) 2006 4 * Copyright (C) 2006
3 * Simon Schulz (ark3116_driver <at> auctionant.de) 5 * Simon Schulz (ark3116_driver <at> auctionant.de)
4 * 6 *
@@ -6,10 +8,13 @@
6 * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547, 8 * - implements a driver for the arkmicro ark3116 chipset (vendor=0x6547,
7 * productid=0x0232) (used in a datacable called KQ-U8A) 9 * productid=0x0232) (used in a datacable called KQ-U8A)
8 * 10 *
9 * - based on code by krisfx -> thanks !! 11 * Supports full modem status lines, break, hardware flow control. Does not
10 * (see http://www.linuxquestions.org/questions/showthread.php?p=2184457#post2184457) 12 * support software flow control, since I do not know how to enable it in hw.
11 * 13 *
12 * - based on logs created by usbsnoopy 14 * This driver is a essentially new implementation. I initially dug
15 * into the old ark3116.c driver and suddenly realized the ark3116 is
16 * a 16450 with a USB interface glued to it. See comments at the
17 * bottom of this file.
13 * 18 *
14 * This program is free software; you can redistribute it and/or modify it 19 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the 20 * under the terms of the GNU General Public License as published by the
@@ -19,17 +24,34 @@
19 24
20#include <linux/kernel.h> 25#include <linux/kernel.h>
21#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/ioctl.h>
22#include <linux/tty.h> 28#include <linux/tty.h>
29#include <linux/slab.h>
30#include <linux/tty_flip.h>
23#include <linux/module.h> 31#include <linux/module.h>
24#include <linux/usb.h> 32#include <linux/usb.h>
25#include <linux/usb/serial.h> 33#include <linux/usb/serial.h>
26#include <linux/serial.h> 34#include <linux/serial.h>
35#include <linux/serial_reg.h>
27#include <linux/uaccess.h> 36#include <linux/uaccess.h>
28 37#include <linux/mutex.h>
38#include <linux/spinlock.h>
29 39
30static int debug; 40static int debug;
41/*
42 * Version information
43 */
31 44
32static struct usb_device_id id_table [] = { 45#define DRIVER_VERSION "v0.5"
46#define DRIVER_AUTHOR "Bart Hartgers <bart.hartgers+ark3116@gmail.com>"
47#define DRIVER_DESC "USB ARK3116 serial/IrDA driver"
48#define DRIVER_DEV_DESC "ARK3116 RS232/IrDA"
49#define DRIVER_NAME "ark3116"
50
51/* usb timeout of 1 second */
52#define ARK_TIMEOUT (1*HZ)
53
54static const struct usb_device_id id_table[] = {
33 { USB_DEVICE(0x6547, 0x0232) }, 55 { USB_DEVICE(0x6547, 0x0232) },
34 { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */ 56 { USB_DEVICE(0x18ec, 0x3118) }, /* USB to IrDA adapter */
35 { }, 57 { },
@@ -45,118 +67,152 @@ static int is_irda(struct usb_serial *serial)
45 return 0; 67 return 0;
46} 68}
47 69
48static inline void ARK3116_SND(struct usb_serial *serial, int seq, 70struct ark3116_private {
49 __u8 request, __u8 requesttype, 71 wait_queue_head_t delta_msr_wait;
50 __u16 value, __u16 index) 72 struct async_icount icount;
73 int irda; /* 1 for irda device */
74
75 /* protects hw register updates */
76 struct mutex hw_lock;
77
78 int quot; /* baudrate divisor */
79 __u32 lcr; /* line control register value */
80 __u32 hcr; /* handshake control register (0x8)
81 * value */
82 __u32 mcr; /* modem contol register value */
83
84 /* protects the status values below */
85 spinlock_t status_lock;
86 __u32 msr; /* modem status register value */
87 __u32 lsr; /* line status register value */
88};
89
90static int ark3116_write_reg(struct usb_serial *serial,
91 unsigned reg, __u8 val)
51{ 92{
52 int result; 93 int result;
94 /* 0xfe 0x40 are magic values taken from original driver */
53 result = usb_control_msg(serial->dev, 95 result = usb_control_msg(serial->dev,
54 usb_sndctrlpipe(serial->dev, 0), 96 usb_sndctrlpipe(serial->dev, 0),
55 request, requesttype, value, index, 97 0xfe, 0x40, val, reg,
56 NULL, 0x00, 1000); 98 NULL, 0, ARK_TIMEOUT);
57 dbg("%03d > ok", seq); 99 return result;
58} 100}
59 101
60static inline void ARK3116_RCV(struct usb_serial *serial, int seq, 102static int ark3116_read_reg(struct usb_serial *serial,
61 __u8 request, __u8 requesttype, 103 unsigned reg, unsigned char *buf)
62 __u16 value, __u16 index, __u8 expected,
63 char *buf)
64{ 104{
65 int result; 105 int result;
106 /* 0xfe 0xc0 are magic values taken from original driver */
66 result = usb_control_msg(serial->dev, 107 result = usb_control_msg(serial->dev,
67 usb_rcvctrlpipe(serial->dev, 0), 108 usb_rcvctrlpipe(serial->dev, 0),
68 request, requesttype, value, index, 109 0xfe, 0xc0, 0, reg,
69 buf, 0x0000001, 1000); 110 buf, 1, ARK_TIMEOUT);
70 if (result) 111 if (result < 0)
71 dbg("%03d < %d bytes [0x%02X]", seq, result, 112 return result;
72 ((unsigned char *)buf)[0]);
73 else 113 else
74 dbg("%03d < 0 bytes", seq); 114 return buf[0];
75} 115}
76 116
77static inline void ARK3116_RCV_QUIET(struct usb_serial *serial, 117static inline int calc_divisor(int bps)
78 __u8 request, __u8 requesttype,
79 __u16 value, __u16 index, char *buf)
80{ 118{
81 usb_control_msg(serial->dev, 119 /* Original ark3116 made some exceptions in rounding here
82 usb_rcvctrlpipe(serial->dev, 0), 120 * because windows did the same. Assume that is not really
83 request, requesttype, value, index, 121 * necessary.
84 buf, 0x0000001, 1000); 122 * Crystal is 12MHz, probably because of USB, but we divide by 4?
123 */
124 return (12000000 + 2*bps) / (4*bps);
85} 125}
86 126
87static int ark3116_attach(struct usb_serial *serial) 127static int ark3116_attach(struct usb_serial *serial)
88{ 128{
89 char *buf; 129 struct usb_serial_port *port = serial->port[0];
130 struct ark3116_private *priv;
131
132 /* make sure we have our end-points */
133 if ((serial->num_bulk_in == 0) ||
134 (serial->num_bulk_out == 0) ||
135 (serial->num_interrupt_in == 0)) {
136 dev_err(&serial->dev->dev,
137 "%s - missing endpoint - "
138 "bulk in: %d, bulk out: %d, int in %d\n",
139 KBUILD_MODNAME,
140 serial->num_bulk_in,
141 serial->num_bulk_out,
142 serial->num_interrupt_in);
143 return -EINVAL;
144 }
90 145
91 buf = kmalloc(1, GFP_KERNEL); 146 priv = kzalloc(sizeof(struct ark3116_private),
92 if (!buf) { 147 GFP_KERNEL);
93 dbg("error kmalloc -> out of mem?"); 148 if (!priv)
94 return -ENOMEM; 149 return -ENOMEM;
95 }
96 150
97 if (is_irda(serial)) 151 init_waitqueue_head(&priv->delta_msr_wait);
98 dbg("IrDA mode"); 152 mutex_init(&priv->hw_lock);
153 spin_lock_init(&priv->status_lock);
154
155 priv->irda = is_irda(serial);
99 156
100 /* 3 */ 157 usb_set_serial_port_data(port, priv);
101 ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
102 ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
103 ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
104 ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000,
105 0x000B);
106 158
107 if (is_irda(serial)) { 159 /* setup the hardware */
108 ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C); 160 ark3116_write_reg(serial, UART_IER, 0);
109 ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D); 161 /* disable DMA */
110 ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A); 162 ark3116_write_reg(serial, UART_FCR, 0);
163 /* handshake control */
164 priv->hcr = 0;
165 ark3116_write_reg(serial, 0x8 , 0);
166 /* modem control */
167 priv->mcr = 0;
168 ark3116_write_reg(serial, UART_MCR, 0);
169
170 if (!(priv->irda)) {
171 ark3116_write_reg(serial, 0xb , 0);
172 } else {
173 ark3116_write_reg(serial, 0xb , 1);
174 ark3116_write_reg(serial, 0xc , 0);
175 ark3116_write_reg(serial, 0xd , 0x41);
176 ark3116_write_reg(serial, 0xa , 1);
111 } 177 }
112 178
113 /* <-- seq7 */ 179 /* setup baudrate */
114 ARK3116_RCV(serial, 7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf); 180 ark3116_write_reg(serial, UART_LCR, UART_LCR_DLAB);
115 ARK3116_SND(serial, 8, 0xFE, 0x40, 0x0080, 0x0003);
116 ARK3116_SND(serial, 9, 0xFE, 0x40, 0x001A, 0x0000);
117 ARK3116_SND(serial, 10, 0xFE, 0x40, 0x0000, 0x0001);
118 ARK3116_SND(serial, 11, 0xFE, 0x40, 0x0000, 0x0003);
119
120 /* <-- seq12 */
121 ARK3116_RCV(serial, 12, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
122 ARK3116_SND(serial, 13, 0xFE, 0x40, 0x0000, 0x0004);
123
124 /* 14 */
125 ARK3116_RCV(serial, 14, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
126 ARK3116_SND(serial, 15, 0xFE, 0x40, 0x0000, 0x0004);
127
128 /* 16 */
129 ARK3116_RCV(serial, 16, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
130 /* --> seq17 */
131 ARK3116_SND(serial, 17, 0xFE, 0x40, 0x0001, 0x0004);
132
133 /* <-- seq18 */
134 ARK3116_RCV(serial, 18, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
135
136 /* --> seq19 */
137 ARK3116_SND(serial, 19, 0xFE, 0x40, 0x0003, 0x0004);
138
139 /* <-- seq20 */
140 /* seems like serial port status info (RTS, CTS, ...) */
141 /* returns modem control line status?! */
142 ARK3116_RCV(serial, 20, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
143
144 /* set 9600 baud & do some init?! */
145 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
146 ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
147 ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
148 if (is_irda(serial))
149 ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
150 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
151 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
152 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
153 ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
154 ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003);
155 181
156 kfree(buf); 182 /* setup for 9600 8N1 */
183 priv->quot = calc_divisor(9600);
184 ark3116_write_reg(serial, UART_DLL, priv->quot & 0xff);
185 ark3116_write_reg(serial, UART_DLM, (priv->quot>>8) & 0xff);
186
187 priv->lcr = UART_LCR_WLEN8;
188 ark3116_write_reg(serial, UART_LCR, UART_LCR_WLEN8);
189
190 ark3116_write_reg(serial, 0xe, 0);
191
192 if (priv->irda)
193 ark3116_write_reg(serial, 0x9, 0);
194
195 dev_info(&serial->dev->dev,
196 "%s using %s mode\n",
197 KBUILD_MODNAME,
198 priv->irda ? "IrDA" : "RS232");
157 return 0; 199 return 0;
158} 200}
159 201
202static void ark3116_release(struct usb_serial *serial)
203{
204 struct usb_serial_port *port = serial->port[0];
205 struct ark3116_private *priv = usb_get_serial_port_data(port);
206
207 /* device is closed, so URBs and DMA should be down */
208
209 usb_set_serial_port_data(port, NULL);
210
211 mutex_destroy(&priv->hw_lock);
212
213 kfree(priv);
214}
215
160static void ark3116_init_termios(struct tty_struct *tty) 216static void ark3116_init_termios(struct tty_struct *tty)
161{ 217{
162 struct ktermios *termios = tty->termios; 218 struct ktermios *termios = tty->termios;
@@ -172,200 +228,189 @@ static void ark3116_set_termios(struct tty_struct *tty,
172 struct ktermios *old_termios) 228 struct ktermios *old_termios)
173{ 229{
174 struct usb_serial *serial = port->serial; 230 struct usb_serial *serial = port->serial;
231 struct ark3116_private *priv = usb_get_serial_port_data(port);
175 struct ktermios *termios = tty->termios; 232 struct ktermios *termios = tty->termios;
176 unsigned int cflag = termios->c_cflag; 233 unsigned int cflag = termios->c_cflag;
177 int baud; 234 int bps = tty_get_baud_rate(tty);
178 int ark3116_baud; 235 int quot;
179 char *buf; 236 __u8 lcr, hcr, eval;
180 char config; 237
181 238 /* set data bit count */
182 config = 0; 239 switch (cflag & CSIZE) {
183 240 case CS5:
184 dbg("%s - port %d", __func__, port->number); 241 lcr = UART_LCR_WLEN5;
242 break;
243 case CS6:
244 lcr = UART_LCR_WLEN6;
245 break;
246 case CS7:
247 lcr = UART_LCR_WLEN7;
248 break;
249 default:
250 case CS8:
251 lcr = UART_LCR_WLEN8;
252 break;
253 }
254 if (cflag & CSTOPB)
255 lcr |= UART_LCR_STOP;
256 if (cflag & PARENB)
257 lcr |= UART_LCR_PARITY;
258 if (!(cflag & PARODD))
259 lcr |= UART_LCR_EPAR;
260#ifdef CMSPAR
261 if (cflag & CMSPAR)
262 lcr |= UART_LCR_SPAR;
263#endif
264 /* handshake control */
265 hcr = (cflag & CRTSCTS) ? 0x03 : 0x00;
266
267 /* calc baudrate */
268 dbg("%s - setting bps to %d", __func__, bps);
269 eval = 0;
270 switch (bps) {
271 case 0:
272 quot = calc_divisor(9600);
273 break;
274 default:
275 if ((bps < 75) || (bps > 3000000))
276 bps = 9600;
277 quot = calc_divisor(bps);
278 break;
279 case 460800:
280 eval = 1;
281 quot = calc_divisor(bps);
282 break;
283 case 921600:
284 eval = 2;
285 quot = calc_divisor(bps);
286 break;
287 }
185 288
289 /* Update state: synchronize */
290 mutex_lock(&priv->hw_lock);
186 291
187 cflag = termios->c_cflag; 292 /* keep old LCR_SBC bit */
188 termios->c_cflag &= ~(CMSPAR|CRTSCTS); 293 lcr |= (priv->lcr & UART_LCR_SBC);
189 294
190 buf = kmalloc(1, GFP_KERNEL); 295 dbg("%s - setting hcr:0x%02x,lcr:0x%02x,quot:%d",
191 if (!buf) { 296 __func__, hcr, lcr, quot);
192 dbg("error kmalloc");
193 *termios = *old_termios;
194 return;
195 }
196 297
197 /* set data bit count (8/7/6/5) */ 298 /* handshake control */
198 if (cflag & CSIZE) { 299 if (priv->hcr != hcr) {
199 switch (cflag & CSIZE) { 300 priv->hcr = hcr;
200 case CS5: 301 ark3116_write_reg(serial, 0x8, hcr);
201 config |= 0x00;
202 dbg("setting CS5");
203 break;
204 case CS6:
205 config |= 0x01;
206 dbg("setting CS6");
207 break;
208 case CS7:
209 config |= 0x02;
210 dbg("setting CS7");
211 break;
212 default:
213 dbg("CSIZE was set but not CS5-CS8, using CS8!");
214 /* fall through */
215 case CS8:
216 config |= 0x03;
217 dbg("setting CS8");
218 break;
219 }
220 } 302 }
221 303
222 /* set parity (NONE/EVEN/ODD) */ 304 /* baudrate */
223 if (cflag & PARENB) { 305 if (priv->quot != quot) {
224 if (cflag & PARODD) { 306 priv->quot = quot;
225 config |= 0x08; 307 priv->lcr = lcr; /* need to write lcr anyway */
226 dbg("setting parity to ODD"); 308
227 } else { 309 /* disable DMA since transmit/receive is
228 config |= 0x18; 310 * shadowed by UART_DLL
229 dbg("setting parity to EVEN"); 311 */
230 } 312 ark3116_write_reg(serial, UART_FCR, 0);
231 } else { 313
232 dbg("setting parity to NONE"); 314 ark3116_write_reg(serial, UART_LCR,
315 lcr|UART_LCR_DLAB);
316 ark3116_write_reg(serial, UART_DLL, quot & 0xff);
317 ark3116_write_reg(serial, UART_DLM, (quot>>8) & 0xff);
318
319 /* restore lcr */
320 ark3116_write_reg(serial, UART_LCR, lcr);
321 /* magic baudrate thingy: not sure what it does,
322 * but windows does this as well.
323 */
324 ark3116_write_reg(serial, 0xe, eval);
325
326 /* enable DMA */
327 ark3116_write_reg(serial, UART_FCR, UART_FCR_DMA_SELECT);
328 } else if (priv->lcr != lcr) {
329 priv->lcr = lcr;
330 ark3116_write_reg(serial, UART_LCR, lcr);
233 } 331 }
234 332
235 /* set stop bit (1/2) */ 333 mutex_unlock(&priv->hw_lock);
236 if (cflag & CSTOPB) {
237 config |= 0x04;
238 dbg("setting 2 stop bits");
239 } else {
240 dbg("setting 1 stop bit");
241 }
242 334
243 /* set baudrate */ 335 /* check for software flow control */
244 baud = tty_get_baud_rate(tty); 336 if (I_IXOFF(tty) || I_IXON(tty)) {
245 337 dev_warn(&serial->dev->dev,
246 switch (baud) { 338 "%s: don't know how to do software flow control\n",
247 case 75: 339 KBUILD_MODNAME);
248 case 150:
249 case 300:
250 case 600:
251 case 1200:
252 case 1800:
253 case 2400:
254 case 4800:
255 case 9600:
256 case 19200:
257 case 38400:
258 case 57600:
259 case 115200:
260 case 230400:
261 case 460800:
262 /* Report the resulting rate back to the caller */
263 tty_encode_baud_rate(tty, baud, baud);
264 break;
265 /* set 9600 as default (if given baudrate is invalid for example) */
266 default:
267 tty_encode_baud_rate(tty, 9600, 9600);
268 case 0:
269 baud = 9600;
270 } 340 }
271 341
272 /* 342 /* Don't rewrite B0 */
273 * found by try'n'error, be careful, maybe there are other options 343 if (tty_termios_baud_rate(termios))
274 * for multiplicator etc! (3.5 for example) 344 tty_termios_encode_baud_rate(termios, bps, bps);
275 */ 345}
276 if (baud == 460800)
277 /* strange, for 460800 the formula is wrong
278 * if using round() then 9600baud is wrong) */
279 ark3116_baud = 7;
280 else
281 ark3116_baud = 3000000 / baud;
282
283 /* ? */
284 ARK3116_RCV(serial, 0, 0xFE, 0xC0, 0x0000, 0x0003, 0x03, buf);
285
286 /* offset = buf[0]; */
287 /* offset = 0x03; */
288 /* dbg("using 0x%04X as target for 0x0003:", 0x0080 + offset); */
289
290 /* set baudrate */
291 dbg("setting baudrate to %d (->reg=%d)", baud, ark3116_baud);
292 ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
293 ARK3116_SND(serial, 148, 0xFE, 0x40,
294 (ark3116_baud & 0x00FF), 0x0000);
295 ARK3116_SND(serial, 149, 0xFE, 0x40,
296 (ark3116_baud & 0xFF00) >> 8, 0x0001);
297 ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
298
299 /* ? */
300 ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
301 ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
302
303 /* set data bit count, stop bit count & parity: */
304 dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config);
305 ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
306 ARK3116_SND(serial, 154, 0xFE, 0x40, config, 0x0003);
307 346
308 if (cflag & CRTSCTS) 347static void ark3116_close(struct usb_serial_port *port)
309 dbg("CRTSCTS not supported by chipset?!"); 348{
349 struct usb_serial *serial = port->serial;
310 350
311 /* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */ 351 if (serial->dev) {
352 /* disable DMA */
353 ark3116_write_reg(serial, UART_FCR, 0);
312 354
313 kfree(buf); 355 /* deactivate interrupts */
356 ark3116_write_reg(serial, UART_IER, 0);
314 357
315 return; 358 /* shutdown any bulk reads that might be going on */
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)
364 usb_kill_urb(port->interrupt_in_urb);
365 }
316} 366}
317 367
318static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) 368static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
319{ 369{
320 struct ktermios tmp_termios; 370 struct ark3116_private *priv = usb_get_serial_port_data(port);
321 struct usb_serial *serial = port->serial; 371 struct usb_serial *serial = port->serial;
322 char *buf; 372 unsigned char *buf;
323 int result = 0; 373 int result;
324
325 dbg("%s - port %d", __func__, port->number);
326 374
327 buf = kmalloc(1, GFP_KERNEL); 375 buf = kmalloc(1, GFP_KERNEL);
328 if (!buf) { 376 if (buf == NULL)
329 dbg("error kmalloc -> out of mem?");
330 return -ENOMEM; 377 return -ENOMEM;
331 }
332 378
333 result = usb_serial_generic_open(tty, port); 379 result = usb_serial_generic_open(tty, port);
334 if (result) 380 if (result) {
381 dbg("%s - usb_serial_generic_open failed: %d",
382 __func__, result);
335 goto err_out; 383 goto err_out;
384 }
336 385
337 /* open */ 386 /* setup termios */
338 ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf); 387 if (tty)
339 388 ark3116_set_termios(tty, port, NULL);
340 ARK3116_SND(serial, 112, 0xFE, 0x40, 0x0082, 0x0003);
341 ARK3116_SND(serial, 113, 0xFE, 0x40, 0x001A, 0x0000);
342 ARK3116_SND(serial, 114, 0xFE, 0x40, 0x0000, 0x0001);
343 ARK3116_SND(serial, 115, 0xFE, 0x40, 0x0002, 0x0003);
344
345 ARK3116_RCV(serial, 116, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
346 ARK3116_SND(serial, 117, 0xFE, 0x40, 0x0002, 0x0004);
347
348 ARK3116_RCV(serial, 118, 0xFE, 0xC0, 0x0000, 0x0004, 0x02, buf);
349 ARK3116_SND(serial, 119, 0xFE, 0x40, 0x0000, 0x0004);
350
351 ARK3116_RCV(serial, 120, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
352 389
353 ARK3116_SND(serial, 121, 0xFE, 0x40, 0x0001, 0x0004); 390 /* remove any data still left: also clears error state */
391 ark3116_read_reg(serial, UART_RX, buf);
354 392
355 ARK3116_RCV(serial, 122, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf); 393 /* read modem status */
394 priv->msr = ark3116_read_reg(serial, UART_MSR, buf);
395 /* read line status */
396 priv->lsr = ark3116_read_reg(serial, UART_LSR, buf);
356 397
357 ARK3116_SND(serial, 123, 0xFE, 0x40, 0x0003, 0x0004); 398 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
399 if (result) {
400 dev_err(&port->dev, "submit irq_in urb failed %d\n",
401 result);
402 ark3116_close(port);
403 goto err_out;
404 }
358 405
359 /* returns different values (control lines?!) */ 406 /* activate interrupts */
360 ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf); 407 ark3116_write_reg(port->serial, UART_IER, UART_IER_MSI|UART_IER_RLSI);
361 408
362 /* initialise termios */ 409 /* enable DMA */
363 if (tty) 410 ark3116_write_reg(port->serial, UART_FCR, UART_FCR_DMA_SELECT);
364 ark3116_set_termios(tty, port, &tmp_termios);
365 411
366err_out: 412err_out:
367 kfree(buf); 413 kfree(buf);
368
369 return result; 414 return result;
370} 415}
371 416
@@ -373,6 +418,7 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
373 unsigned int cmd, unsigned long arg) 418 unsigned int cmd, unsigned long arg)
374{ 419{
375 struct usb_serial_port *port = tty->driver_data; 420 struct usb_serial_port *port = tty->driver_data;
421 struct ark3116_private *priv = usb_get_serial_port_data(port);
376 struct serial_struct serstruct; 422 struct serial_struct serstruct;
377 void __user *user_arg = (void __user *)arg; 423 void __user *user_arg = (void __user *)arg;
378 424
@@ -394,9 +440,48 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
394 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) 440 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
395 return -EFAULT; 441 return -EFAULT;
396 return 0; 442 return 0;
397 default: 443 case TIOCMIWAIT:
398 dbg("%s cmd 0x%04x not supported", __func__, cmd); 444 for (;;) {
445 struct async_icount prev = priv->icount;
446 interruptible_sleep_on(&priv->delta_msr_wait);
447 /* see if a signal did it */
448 if (signal_pending(current))
449 return -ERESTARTSYS;
450 if ((prev.rng == priv->icount.rng) &&
451 (prev.dsr == priv->icount.dsr) &&
452 (prev.dcd == priv->icount.dcd) &&
453 (prev.cts == priv->icount.cts))
454 return -EIO;
455 if ((arg & TIOCM_RNG &&
456 (prev.rng != priv->icount.rng)) ||
457 (arg & TIOCM_DSR &&
458 (prev.dsr != priv->icount.dsr)) ||
459 (arg & TIOCM_CD &&
460 (prev.dcd != priv->icount.dcd)) ||
461 (arg & TIOCM_CTS &&
462 (prev.cts != priv->icount.cts)))
463 return 0;
464 }
399 break; 465 break;
466 case TIOCGICOUNT: {
467 struct serial_icounter_struct icount;
468 struct async_icount cnow = priv->icount;
469 memset(&icount, 0, sizeof(icount));
470 icount.cts = cnow.cts;
471 icount.dsr = cnow.dsr;
472 icount.rng = cnow.rng;
473 icount.dcd = cnow.dcd;
474 icount.rx = cnow.rx;
475 icount.tx = cnow.tx;
476 icount.frame = cnow.frame;
477 icount.overrun = cnow.overrun;
478 icount.parity = cnow.parity;
479 icount.brk = cnow.brk;
480 icount.buf_overrun = cnow.buf_overrun;
481 if (copy_to_user(user_arg, &icount, sizeof(icount)))
482 return -EFAULT;
483 return 0;
484 }
400 } 485 }
401 486
402 return -ENOIOCTLCMD; 487 return -ENOIOCTLCMD;
@@ -405,32 +490,272 @@ static int ark3116_ioctl(struct tty_struct *tty, struct file *file,
405static int ark3116_tiocmget(struct tty_struct *tty, struct file *file) 490static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
406{ 491{
407 struct usb_serial_port *port = tty->driver_data; 492 struct usb_serial_port *port = tty->driver_data;
408 struct usb_serial *serial = port->serial; 493 struct ark3116_private *priv = usb_get_serial_port_data(port);
409 char *buf; 494 __u32 status;
410 char temp; 495 __u32 ctrl;
496 unsigned long flags;
497
498 mutex_lock(&priv->hw_lock);
499 ctrl = priv->mcr;
500 mutex_unlock(&priv->hw_lock);
501
502 spin_lock_irqsave(&priv->status_lock, flags);
503 status = priv->msr;
504 spin_unlock_irqrestore(&priv->status_lock, flags);
505
506 return (status & UART_MSR_DSR ? TIOCM_DSR : 0) |
507 (status & UART_MSR_CTS ? TIOCM_CTS : 0) |
508 (status & UART_MSR_RI ? TIOCM_RI : 0) |
509 (status & UART_MSR_DCD ? TIOCM_CD : 0) |
510 (ctrl & UART_MCR_DTR ? TIOCM_DTR : 0) |
511 (ctrl & UART_MCR_RTS ? TIOCM_RTS : 0) |
512 (ctrl & UART_MCR_OUT1 ? TIOCM_OUT1 : 0) |
513 (ctrl & UART_MCR_OUT2 ? TIOCM_OUT2 : 0);
514}
411 515
412 /* seems like serial port status info (RTS, CTS, ...) is stored 516static int ark3116_tiocmset(struct tty_struct *tty, struct file *file,
413 * in reg(?) 0x0006 517 unsigned set, unsigned clr)
414 * pcb connection point 11 = GND -> sets bit4 of response 518{
415 * pcb connection point 7 = GND -> sets bit6 of response 519 struct usb_serial_port *port = tty->driver_data;
520 struct ark3116_private *priv = usb_get_serial_port_data(port);
521
522 /* we need to take the mutex here, to make sure that the value
523 * in priv->mcr is actually the one that is in the hardware
416 */ 524 */
417 525
418 buf = kmalloc(1, GFP_KERNEL); 526 mutex_lock(&priv->hw_lock);
419 if (!buf) { 527
420 dbg("error kmalloc"); 528 if (set & TIOCM_RTS)
421 return -ENOMEM; 529 priv->mcr |= UART_MCR_RTS;
530 if (set & TIOCM_DTR)
531 priv->mcr |= UART_MCR_DTR;
532 if (set & TIOCM_OUT1)
533 priv->mcr |= UART_MCR_OUT1;
534 if (set & TIOCM_OUT2)
535 priv->mcr |= UART_MCR_OUT2;
536 if (clr & TIOCM_RTS)
537 priv->mcr &= ~UART_MCR_RTS;
538 if (clr & TIOCM_DTR)
539 priv->mcr &= ~UART_MCR_DTR;
540 if (clr & TIOCM_OUT1)
541 priv->mcr &= ~UART_MCR_OUT1;
542 if (clr & TIOCM_OUT2)
543 priv->mcr &= ~UART_MCR_OUT2;
544
545 ark3116_write_reg(port->serial, UART_MCR, priv->mcr);
546
547 mutex_unlock(&priv->hw_lock);
548
549 return 0;
550}
551
552static void ark3116_break_ctl(struct tty_struct *tty, int break_state)
553{
554 struct usb_serial_port *port = tty->driver_data;
555 struct ark3116_private *priv = usb_get_serial_port_data(port);
556
557 /* LCR is also used for other things: protect access */
558 mutex_lock(&priv->hw_lock);
559
560 if (break_state)
561 priv->lcr |= UART_LCR_SBC;
562 else
563 priv->lcr &= ~UART_LCR_SBC;
564
565 ark3116_write_reg(port->serial, UART_LCR, priv->lcr);
566
567 mutex_unlock(&priv->hw_lock);
568}
569
570static void ark3116_update_msr(struct usb_serial_port *port, __u8 msr)
571{
572 struct ark3116_private *priv = usb_get_serial_port_data(port);
573 unsigned long flags;
574
575 spin_lock_irqsave(&priv->status_lock, flags);
576 priv->msr = msr;
577 spin_unlock_irqrestore(&priv->status_lock, flags);
578
579 if (msr & UART_MSR_ANY_DELTA) {
580 /* update input line counters */
581 if (msr & UART_MSR_DCTS)
582 priv->icount.cts++;
583 if (msr & UART_MSR_DDSR)
584 priv->icount.dsr++;
585 if (msr & UART_MSR_DDCD)
586 priv->icount.dcd++;
587 if (msr & UART_MSR_TERI)
588 priv->icount.rng++;
589 wake_up_interruptible(&priv->delta_msr_wait);
422 } 590 }
591}
423 592
424 /* read register */ 593static void ark3116_update_lsr(struct usb_serial_port *port, __u8 lsr)
425 ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, buf); 594{
426 temp = buf[0]; 595 struct ark3116_private *priv = usb_get_serial_port_data(port);
427 kfree(buf); 596 unsigned long flags;
597
598 spin_lock_irqsave(&priv->status_lock, flags);
599 /* combine bits */
600 priv->lsr |= lsr;
601 spin_unlock_irqrestore(&priv->status_lock, flags);
602
603 if (lsr&UART_LSR_BRK_ERROR_BITS) {
604 if (lsr & UART_LSR_BI)
605 priv->icount.brk++;
606 if (lsr & UART_LSR_FE)
607 priv->icount.frame++;
608 if (lsr & UART_LSR_PE)
609 priv->icount.parity++;
610 if (lsr & UART_LSR_OE)
611 priv->icount.overrun++;
612 }
613}
428 614
429 /* i do not really know if bit4=CTS and bit6=DSR... just a 615static void ark3116_read_int_callback(struct urb *urb)
430 * quick guess! 616{
431 */ 617 struct usb_serial_port *port = urb->context;
432 return (temp & (1<<4) ? TIOCM_CTS : 0) 618 int status = urb->status;
433 | (temp & (1<<6) ? TIOCM_DSR : 0); 619 const __u8 *data = urb->transfer_buffer;
620 int result;
621
622 switch (status) {
623 case -ECONNRESET:
624 case -ENOENT:
625 case -ESHUTDOWN:
626 /* this urb is terminated, clean up */
627 dbg("%s - urb shutting down with status: %d",
628 __func__, status);
629 return;
630 default:
631 dbg("%s - nonzero urb status received: %d",
632 __func__, status);
633 break;
634 case 0: /* success */
635 /* discovered this by trail and error... */
636 if ((urb->actual_length == 4) && (data[0] == 0xe8)) {
637 const __u8 id = data[1]&UART_IIR_ID;
638 dbg("%s: iir=%02x", __func__, data[1]);
639 if (id == UART_IIR_MSI) {
640 dbg("%s: msr=%02x", __func__, data[3]);
641 ark3116_update_msr(port, data[3]);
642 break;
643 } else if (id == UART_IIR_RLSI) {
644 dbg("%s: lsr=%02x", __func__, data[2]);
645 ark3116_update_lsr(port, data[2]);
646 break;
647 }
648 }
649 /*
650 * Not sure what this data meant...
651 */
652 usb_serial_debug_data(debug, &port->dev,
653 __func__,
654 urb->actual_length,
655 urb->transfer_buffer);
656 break;
657 }
658
659 result = usb_submit_urb(urb, GFP_ATOMIC);
660 if (result)
661 dev_err(&urb->dev->dev,
662 "%s - Error %d submitting interrupt urb\n",
663 __func__, result);
664}
665
666
667/* Data comes in via the bulk (data) URB, erors/interrupts via the int URB.
668 * This means that we cannot be sure which data byte has an associated error
669 * condition, so we report an error for all data in the next bulk read.
670 *
671 * Actually, there might even be a window between the bulk data leaving the
672 * ark and reading/resetting the lsr in the read_bulk_callback where an
673 * interrupt for the next data block could come in.
674 * Without somekind of ordering on the ark, we would have to report the
675 * error for the next block of data as well...
676 * For now, let's pretend this can't happen.
677 */
678
679static void send_to_tty(struct tty_struct *tty,
680 const unsigned char *chars,
681 size_t size, char flag)
682{
683 if (size == 0)
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);
698 const __u8 *data = urb->transfer_buffer;
699 int status = urb->status;
700 struct tty_struct *tty;
701 unsigned long flags;
702 int result;
703 char flag;
704 __u32 lsr;
705
706 switch (status) {
707 case -ECONNRESET:
708 case -ENOENT:
709 case -ESHUTDOWN:
710 /* this urb is terminated, clean up */
711 dbg("%s - urb shutting down with status: %d",
712 __func__, status);
713 return;
714 default:
715 dbg("%s - nonzero urb status received: %d",
716 __func__, status);
717 break;
718 case 0: /* success */
719
720 spin_lock_irqsave(&priv->status_lock, flags);
721 lsr = priv->lsr;
722 /* clear error bits */
723 priv->lsr &= ~UART_LSR_BRK_ERROR_BITS;
724 spin_unlock_irqrestore(&priv->status_lock, flags);
725
726 if (unlikely(lsr & UART_LSR_BI))
727 flag = TTY_BREAK;
728 else if (unlikely(lsr & UART_LSR_PE))
729 flag = TTY_PARITY;
730 else if (unlikely(lsr & UART_LSR_FE))
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
745 /* Throttle the device if requested by tty */
746 spin_lock_irqsave(&port->lock, flags);
747 port->throttled = port->throttle_req;
748 if (port->throttled) {
749 spin_unlock_irqrestore(&port->lock, flags);
750 return;
751 } else
752 spin_unlock_irqrestore(&port->lock, flags);
753 }
754 /* Continue reading from device */
755 result = usb_submit_urb(urb, GFP_ATOMIC);
756 if (result)
757 dev_err(&urb->dev->dev, "%s - failed resubmitting"
758 " read urb, error %d\n", __func__, result);
434} 759}
435 760
436static struct usb_driver ark3116_driver = { 761static struct usb_driver ark3116_driver = {
@@ -450,11 +775,17 @@ static struct usb_serial_driver ark3116_device = {
450 .usb_driver = &ark3116_driver, 775 .usb_driver = &ark3116_driver,
451 .num_ports = 1, 776 .num_ports = 1,
452 .attach = ark3116_attach, 777 .attach = ark3116_attach,
778 .release = ark3116_release,
453 .set_termios = ark3116_set_termios, 779 .set_termios = ark3116_set_termios,
454 .init_termios = ark3116_init_termios, 780 .init_termios = ark3116_init_termios,
455 .ioctl = ark3116_ioctl, 781 .ioctl = ark3116_ioctl,
456 .tiocmget = ark3116_tiocmget, 782 .tiocmget = ark3116_tiocmget,
783 .tiocmset = ark3116_tiocmset,
457 .open = ark3116_open, 784 .open = ark3116_open,
785 .close = ark3116_close,
786 .break_ctl = ark3116_break_ctl,
787 .read_int_callback = ark3116_read_int_callback,
788 .read_bulk_callback = ark3116_read_bulk_callback,
458}; 789};
459 790
460static int __init ark3116_init(void) 791static int __init ark3116_init(void)
@@ -465,7 +796,12 @@ static int __init ark3116_init(void)
465 if (retval) 796 if (retval)
466 return retval; 797 return retval;
467 retval = usb_register(&ark3116_driver); 798 retval = usb_register(&ark3116_driver);
468 if (retval) 799 if (retval == 0) {
800 printk(KERN_INFO "%s:"
801 DRIVER_VERSION ":"
802 DRIVER_DESC "\n",
803 KBUILD_MODNAME);
804 } else
469 usb_serial_deregister(&ark3116_device); 805 usb_serial_deregister(&ark3116_device);
470 return retval; 806 return retval;
471} 807}
@@ -480,6 +816,109 @@ module_init(ark3116_init);
480module_exit(ark3116_exit); 816module_exit(ark3116_exit);
481MODULE_LICENSE("GPL"); 817MODULE_LICENSE("GPL");
482 818
819MODULE_AUTHOR(DRIVER_AUTHOR);
820MODULE_DESCRIPTION(DRIVER_DESC);
821
483module_param(debug, bool, S_IRUGO | S_IWUSR); 822module_param(debug, bool, S_IRUGO | S_IWUSR);
484MODULE_PARM_DESC(debug, "Debug enabled or not"); 823MODULE_PARM_DESC(debug, "Enable debug");
485 824
825/*
826 * The following describes what I learned from studying the old
827 * ark3116.c driver, disassembling the windows driver, and some lucky
828 * guesses. Since I do not have any datasheet or other
829 * documentation, inaccuracies are almost guaranteed.
830 *
831 * Some specs for the ARK3116 can be found here:
832 * http://web.archive.org/web/20060318000438/
833 * www.arkmicro.com/en/products/view.php?id=10
834 * On that page, 2 GPIO pins are mentioned: I assume these are the
835 * OUT1 and OUT2 pins of the UART, so I added support for those
836 * through the MCR. Since the pins are not available on my hardware,
837 * I could not verify this.
838 * Also, it states there is "on-chip hardware flow control". I have
839 * discovered how to enable that. Unfortunately, I do not know how to
840 * enable XON/XOFF (software) flow control, which would need support
841 * from the chip as well to work. Because of the wording on the web
842 * page there is a real possibility the chip simply does not support
843 * software flow control.
844 *
845 * I got my ark3116 as part of a mobile phone adapter cable. On the
846 * PCB, the following numbered contacts are present:
847 *
848 * 1:- +5V
849 * 2:o DTR
850 * 3:i RX
851 * 4:i DCD
852 * 5:o RTS
853 * 6:o TX
854 * 7:i RI
855 * 8:i DSR
856 * 10:- 0V
857 * 11:i CTS
858 *
859 * On my chip, all signals seem to be 3.3V, but 5V tolerant. But that
860 * may be different for the one you have ;-).
861 *
862 * The windows driver limits the registers to 0-F, so I assume there
863 * are actually 16 present on the device.
864 *
865 * On an UART interrupt, 4 bytes of data come in on the interrupt
866 * endpoint. The bytes are 0xe8 IIR LSR MSR.
867 *
868 * The baudrate seems to be generated from the 12MHz crystal, using
869 * 4-times subsampling. So quot=12e6/(4*baud). Also see description
870 * of register E.
871 *
872 * Registers 0-7:
873 * These seem to be the same as for a regular 16450. The FCR is set
874 * to UART_FCR_DMA_SELECT (0x8), I guess to enable transfers between
875 * the UART and the USB bridge/DMA engine.
876 *
877 * Register 8:
878 * By trial and error, I found out that bit 0 enables hardware CTS,
879 * stopping TX when CTS is +5V. Bit 1 does the same for RTS, making
880 * RTS +5V when the 3116 cannot transfer the data to the USB bus
881 * (verified by disabling the reading URB). Note that as far as I can
882 * tell, the windows driver does NOT use this, so there might be some
883 * hardware bug or something.
884 *
885 * According to a patch provided here
886 * (http://lkml.org/lkml/2009/7/26/56), the ARK3116 can also be used
887 * as an IrDA dongle. Since I do not have such a thing, I could not
888 * investigate that aspect. However, I can speculate ;-).
889 *
890 * - IrDA encodes data differently than RS232. Most likely, one of
891 * the bits in registers 9..E enables the IR ENDEC (encoder/decoder).
892 * - Depending on the IR transceiver, the input and output need to be
893 * inverted, so there are probably bits for that as well.
894 * - IrDA is half-duplex, so there should be a bit for selecting that.
895 *
896 * This still leaves at least two registers unaccounted for. Perhaps
897 * The chip can do XON/XOFF or CRC in HW?
898 *
899 * Register 9:
900 * Set to 0x00 for IrDA, when the baudrate is initialised.
901 *
902 * Register A:
903 * Set to 0x01 for IrDA, at init.
904 *
905 * Register B:
906 * Set to 0x01 for IrDA, 0x00 for RS232, at init.
907 *
908 * Register C:
909 * Set to 00 for IrDA, at init.
910 *
911 * Register D:
912 * Set to 0x41 for IrDA, at init.
913 *
914 * Register E:
915 * Somekind of baudrate override. The windows driver seems to set
916 * this to 0x00 for normal baudrates, 0x01 for 460800, 0x02 for 921600.
917 * Since 460800 and 921600 cannot be obtained by dividing 3MHz by an integer,
918 * it could be somekind of subdivisor thingy.
919 * However,it does not seem to do anything: selecting 921600 (divisor 3,
920 * reg E=2), still gets 1 MHz. I also checked if registers 9, C or F would
921 * work, but they don't.
922 *
923 * Register F: unknown
924 */
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index a0467bc61627..1295e44e3f1c 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -103,7 +103,7 @@ static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file,
103 unsigned int set, unsigned int clear); 103 unsigned int set, unsigned int clear);
104 104
105 105
106static struct usb_device_id id_table_combined [] = { 106static const struct usb_device_id id_table_combined[] = {
107 { USB_DEVICE(BELKIN_SA_VID, BELKIN_SA_PID) }, 107 { USB_DEVICE(BELKIN_SA_VID, BELKIN_SA_PID) },
108 { USB_DEVICE(BELKIN_OLD_VID, BELKIN_OLD_PID) }, 108 { USB_DEVICE(BELKIN_OLD_VID, BELKIN_OLD_PID) },
109 { USB_DEVICE(PERACOM_VID, PERACOM_PID) }, 109 { USB_DEVICE(PERACOM_VID, PERACOM_PID) },
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index ba555c528cc6..7f547dc3a590 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/tty.h> 13#include <linux/tty.h>
14#include <linux/slab.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/usb.h> 16#include <linux/usb.h>
16#include <linux/usb/serial.h> 17#include <linux/usb/serial.h>
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 59eff721fcc5..7e8e39818414 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -19,9 +19,11 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/tty.h> 20#include <linux/tty.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/slab.h>
22#include <linux/usb.h> 23#include <linux/usb.h>
23#include <linux/usb/serial.h> 24#include <linux/usb/serial.h>
24#include <linux/serial.h> 25#include <linux/serial.h>
26#include <asm/unaligned.h>
25 27
26#define DEFAULT_BAUD_RATE 9600 28#define DEFAULT_BAUD_RATE 9600
27#define DEFAULT_TIMEOUT 1000 29#define DEFAULT_TIMEOUT 1000
@@ -70,7 +72,7 @@
70 72
71static int debug; 73static int debug;
72 74
73static struct usb_device_id id_table [] = { 75static const struct usb_device_id id_table[] = {
74 { USB_DEVICE(0x4348, 0x5523) }, 76 { USB_DEVICE(0x4348, 0x5523) },
75 { USB_DEVICE(0x1a86, 0x7523) }, 77 { USB_DEVICE(0x1a86, 0x7523) },
76 { }, 78 { },
@@ -392,16 +394,22 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
392 struct usb_serial_port *port = tty->driver_data; 394 struct usb_serial_port *port = tty->driver_data;
393 int r; 395 int r;
394 uint16_t reg_contents; 396 uint16_t reg_contents;
395 uint8_t break_reg[2]; 397 uint8_t *break_reg;
396 398
397 dbg("%s()", __func__); 399 dbg("%s()", __func__);
398 400
401 break_reg = kmalloc(2, GFP_KERNEL);
402 if (!break_reg) {
403 dev_err(&port->dev, "%s - kmalloc failed\n", __func__);
404 return;
405 }
406
399 r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG, 407 r = ch341_control_in(port->serial->dev, CH341_REQ_READ_REG,
400 ch341_break_reg, 0, break_reg, sizeof(break_reg)); 408 ch341_break_reg, 0, break_reg, 2);
401 if (r < 0) { 409 if (r < 0) {
402 printk(KERN_WARNING "%s: USB control read error whilst getting" 410 dev_err(&port->dev, "%s - USB control read error (%d)\n",
403 " break register contents.\n", __FILE__); 411 __func__, r);
404 return; 412 goto out;
405 } 413 }
406 dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x", 414 dbg("%s - initial ch341 break register contents - reg1: %x, reg2: %x",
407 __func__, break_reg[0], break_reg[1]); 415 __func__, break_reg[0], break_reg[1]);
@@ -416,12 +424,14 @@ static void ch341_break_ctl(struct tty_struct *tty, int break_state)
416 } 424 }
417 dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x", 425 dbg("%s - New ch341 break register contents - reg1: %x, reg2: %x",
418 __func__, break_reg[0], break_reg[1]); 426 __func__, break_reg[0], break_reg[1]);
419 reg_contents = (uint16_t)break_reg[0] | ((uint16_t)break_reg[1] << 8); 427 reg_contents = get_unaligned_le16(break_reg);
420 r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG, 428 r = ch341_control_out(port->serial->dev, CH341_REQ_WRITE_REG,
421 ch341_break_reg, reg_contents); 429 ch341_break_reg, reg_contents);
422 if (r < 0) 430 if (r < 0)
423 printk(KERN_WARNING "%s: USB control write error whilst setting" 431 dev_err(&port->dev, "%s - USB control write error (%d)\n",
424 " break register contents.\n", __FILE__); 432 __func__, r);
433out:
434 kfree(break_reg);
425} 435}
426 436
427static int ch341_tiocmset(struct tty_struct *tty, struct file *file, 437static int ch341_tiocmset(struct tty_struct *tty, struct file *file,
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index b22ac3258523..f347da2ef00a 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -181,6 +181,7 @@ static int usb_console_setup(struct console *co, char *options)
181 /* The console is special in terms of closing the device so 181 /* The console is special in terms of closing the device so
182 * indicate this port is now acting as a system console. */ 182 * indicate this port is now acting as a system console. */
183 port->console = 1; 183 port->console = 1;
184 port->port.console = 1;
184 185
185 mutex_unlock(&serial->disc_mutex); 186 mutex_unlock(&serial->disc_mutex);
186 return retval; 187 return retval;
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index bd254ec97d14..ec9b0449ccf6 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -55,7 +55,7 @@ static int cp210x_carrier_raised(struct usb_serial_port *p);
55 55
56static int debug; 56static int debug;
57 57
58static struct usb_device_id id_table [] = { 58static const struct usb_device_id id_table[] = {
59 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ 59 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
60 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 60 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
61 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */ 61 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */
@@ -91,11 +91,12 @@ static struct usb_device_id id_table [] = {
91 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ 91 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
92 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ 92 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
93 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ 93 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
94 { USB_DEVICE(0x10C4, 0x81E8) }, /* Zephyr Bioharness */
94 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */ 95 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */
95 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 96 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
96 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ 97 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */
97 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ 98 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */
98 { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ 99 { USB_DEVICE(0x10C4, 0x8293) }, /* Telegesys ETRX2USB */
99 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */ 100 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */
100 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ 101 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
101 { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */ 102 { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */
@@ -312,11 +313,6 @@ static int cp210x_set_config(struct usb_serial_port *port, u8 request,
312 return -EPROTO; 313 return -EPROTO;
313 } 314 }
314 315
315 /* Single data value */
316 result = usb_control_msg(serial->dev,
317 usb_sndctrlpipe(serial->dev, 0),
318 request, REQTYPE_HOST_TO_DEVICE, data[0],
319 0, NULL, 0, 300);
320 return 0; 316 return 0;
321} 317}
322 318
@@ -612,7 +608,7 @@ static void cp210x_set_termios(struct tty_struct *tty,
612 baud); 608 baud);
613 if (cp210x_set_config_single(port, CP210X_SET_BAUDDIV, 609 if (cp210x_set_config_single(port, CP210X_SET_BAUDDIV,
614 ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { 610 ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) {
615 dbg("Baud rate requested not supported by device\n"); 611 dbg("Baud rate requested not supported by device");
616 baud = tty_termios_baud_rate(old_termios); 612 baud = tty_termios_baud_rate(old_termios);
617 } 613 }
618 } 614 }
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index b0f6402a91ca..f744ab7a3b19 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -70,7 +70,7 @@ static void cyberjack_read_int_callback(struct urb *urb);
70static void cyberjack_read_bulk_callback(struct urb *urb); 70static void cyberjack_read_bulk_callback(struct urb *urb);
71static void cyberjack_write_bulk_callback(struct urb *urb); 71static void cyberjack_write_bulk_callback(struct urb *urb);
72 72
73static struct usb_device_id id_table [] = { 73static const struct usb_device_id id_table[] = {
74 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) }, 74 { USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) },
75 { } /* Terminating entry */ 75 { } /* Terminating entry */
76}; 76};
@@ -391,11 +391,10 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
391 391
392 tty = tty_port_tty_get(&port->port); 392 tty = tty_port_tty_get(&port->port);
393 if (!tty) { 393 if (!tty) {
394 dbg("%s - ignoring since device not open\n", __func__); 394 dbg("%s - ignoring since device not open", __func__);
395 return; 395 return;
396 } 396 }
397 if (urb->actual_length) { 397 if (urb->actual_length) {
398 tty_buffer_request_room(tty, urb->actual_length);
399 tty_insert_flip_string(tty, data, urb->actual_length); 398 tty_insert_flip_string(tty, data, urb->actual_length);
400 tty_flip_buffer_push(tty); 399 tty_flip_buffer_push(tty);
401 } 400 }
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index a591ebec0f89..e23c77925e7a 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -66,17 +66,15 @@
66#include <linux/serial.h> 66#include <linux/serial.h>
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/uaccess.h> 68#include <linux/uaccess.h>
69#include <asm/unaligned.h>
69 70
70#include "cypress_m8.h" 71#include "cypress_m8.h"
71 72
72 73
73#ifdef CONFIG_USB_SERIAL_DEBUG 74static int debug;
74 static int debug = 1;
75#else
76 static int debug;
77#endif
78static int stats; 75static int stats;
79static int interval; 76static int interval;
77static int unstable_bauds;
80 78
81/* 79/*
82 * Version Information 80 * Version Information
@@ -89,24 +87,24 @@ static int interval;
89#define CYPRESS_BUF_SIZE 1024 87#define CYPRESS_BUF_SIZE 1024
90#define CYPRESS_CLOSING_WAIT (30*HZ) 88#define CYPRESS_CLOSING_WAIT (30*HZ)
91 89
92static struct usb_device_id id_table_earthmate [] = { 90static const struct usb_device_id id_table_earthmate[] = {
93 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, 91 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
94 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, 92 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
95 { } /* Terminating entry */ 93 { } /* Terminating entry */
96}; 94};
97 95
98static struct usb_device_id id_table_cyphidcomrs232 [] = { 96static const struct usb_device_id id_table_cyphidcomrs232[] = {
99 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, 97 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
100 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) }, 98 { USB_DEVICE(VENDOR_ID_POWERCOM, PRODUCT_ID_UPS) },
101 { } /* Terminating entry */ 99 { } /* Terminating entry */
102}; 100};
103 101
104static struct usb_device_id id_table_nokiaca42v2 [] = { 102static const struct usb_device_id id_table_nokiaca42v2[] = {
105 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) }, 103 { USB_DEVICE(VENDOR_ID_DAZZLE, PRODUCT_ID_CA42) },
106 { } /* Terminating entry */ 104 { } /* Terminating entry */
107}; 105};
108 106
109static struct usb_device_id id_table_combined [] = { 107static const struct usb_device_id id_table_combined[] = {
110 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) }, 108 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB) },
111 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) }, 109 { USB_DEVICE(VENDOR_ID_DELORME, PRODUCT_ID_EARTHMATEUSB_LT20) },
112 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) }, 110 { USB_DEVICE(VENDOR_ID_CYPRESS, PRODUCT_ID_CYPHIDCOM) },
@@ -154,7 +152,7 @@ struct cypress_private {
154 int isthrottled; /* if throttled, discard reads */ 152 int isthrottled; /* if throttled, discard reads */
155 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ 153 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
156 char prev_status, diff_status; /* used for TIOCMIWAIT */ 154 char prev_status, diff_status; /* used for TIOCMIWAIT */
157 /* we pass a pointer to this as the arguement sent to 155 /* we pass a pointer to this as the argument sent to
158 cypress_set_termios old_termios */ 156 cypress_set_termios old_termios */
159 struct ktermios tmp_termios; /* stores the old termios settings */ 157 struct ktermios tmp_termios; /* stores the old termios settings */
160}; 158};
@@ -295,6 +293,9 @@ static int analyze_baud_rate(struct usb_serial_port *port, speed_t new_rate)
295 struct cypress_private *priv; 293 struct cypress_private *priv;
296 priv = usb_get_serial_port_data(port); 294 priv = usb_get_serial_port_data(port);
297 295
296 if (unstable_bauds)
297 return new_rate;
298
298 /* 299 /*
299 * The general purpose firmware for the Cypress M8 allows for 300 * The general purpose firmware for the Cypress M8 allows for
300 * a maximum speed of 57600bps (I have no idea whether DeLorme 301 * a maximum speed of 57600bps (I have no idea whether DeLorme
@@ -344,7 +345,8 @@ static int cypress_serial_control(struct tty_struct *tty,
344{ 345{
345 int new_baudrate = 0, retval = 0, tries = 0; 346 int new_baudrate = 0, retval = 0, tries = 0;
346 struct cypress_private *priv; 347 struct cypress_private *priv;
347 __u8 feature_buffer[5]; 348 u8 *feature_buffer;
349 const unsigned int feature_len = 5;
348 unsigned long flags; 350 unsigned long flags;
349 351
350 dbg("%s", __func__); 352 dbg("%s", __func__);
@@ -354,17 +356,18 @@ static int cypress_serial_control(struct tty_struct *tty,
354 if (!priv->comm_is_ok) 356 if (!priv->comm_is_ok)
355 return -ENODEV; 357 return -ENODEV;
356 358
359 feature_buffer = kcalloc(feature_len, sizeof(u8), GFP_KERNEL);
360 if (!feature_buffer)
361 return -ENOMEM;
362
357 switch (cypress_request_type) { 363 switch (cypress_request_type) {
358 case CYPRESS_SET_CONFIG: 364 case CYPRESS_SET_CONFIG:
359 new_baudrate = priv->baud_rate;
360 /* 0 means 'Hang up' so doesn't change the true bit rate */ 365 /* 0 means 'Hang up' so doesn't change the true bit rate */
361 if (baud_rate == 0) 366 new_baudrate = priv->baud_rate;
362 new_baudrate = priv->baud_rate; 367 if (baud_rate && baud_rate != priv->baud_rate) {
363 /* Change of speed ? */
364 else if (baud_rate != priv->baud_rate) {
365 dbg("%s - baud rate is changing", __func__); 368 dbg("%s - baud rate is changing", __func__);
366 retval = analyze_baud_rate(port, baud_rate); 369 retval = analyze_baud_rate(port, baud_rate);
367 if (retval >= 0) { 370 if (retval >= 0) {
368 new_baudrate = retval; 371 new_baudrate = retval;
369 dbg("%s - New baud rate set to %d", 372 dbg("%s - New baud rate set to %d",
370 __func__, new_baudrate); 373 __func__, new_baudrate);
@@ -373,9 +376,8 @@ static int cypress_serial_control(struct tty_struct *tty,
373 dbg("%s - baud rate is being sent as %d", 376 dbg("%s - baud rate is being sent as %d",
374 __func__, new_baudrate); 377 __func__, new_baudrate);
375 378
376 memset(feature_buffer, 0, sizeof(feature_buffer));
377 /* fill the feature_buffer with new configuration */ 379 /* fill the feature_buffer with new configuration */
378 *((u_int32_t *)feature_buffer) = new_baudrate; 380 put_unaligned_le32(new_baudrate, feature_buffer);
379 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */ 381 feature_buffer[4] |= data_bits; /* assign data bits in 2 bit space ( max 3 ) */
380 /* 1 bit gap */ 382 /* 1 bit gap */
381 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */ 383 feature_buffer[4] |= (stop_bits << 3); /* assign stop bits in 1 bit space */
@@ -397,15 +399,15 @@ static int cypress_serial_control(struct tty_struct *tty,
397 HID_REQ_SET_REPORT, 399 HID_REQ_SET_REPORT,
398 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 400 USB_DIR_OUT | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
399 0x0300, 0, feature_buffer, 401 0x0300, 0, feature_buffer,
400 sizeof(feature_buffer), 500); 402 feature_len, 500);
401 403
402 if (tries++ >= 3) 404 if (tries++ >= 3)
403 break; 405 break;
404 406
405 } while (retval != sizeof(feature_buffer) && 407 } while (retval != feature_len &&
406 retval != -ENODEV); 408 retval != -ENODEV);
407 409
408 if (retval != sizeof(feature_buffer)) { 410 if (retval != feature_len) {
409 dev_err(&port->dev, "%s - failed sending serial " 411 dev_err(&port->dev, "%s - failed sending serial "
410 "line settings - %d\n", __func__, retval); 412 "line settings - %d\n", __func__, retval);
411 cypress_set_dead(port); 413 cypress_set_dead(port);
@@ -425,43 +427,42 @@ static int cypress_serial_control(struct tty_struct *tty,
425 /* Not implemented for this device, 427 /* Not implemented for this device,
426 and if we try to do it we're likely 428 and if we try to do it we're likely
427 to crash the hardware. */ 429 to crash the hardware. */
428 return -ENOTTY; 430 retval = -ENOTTY;
431 goto out;
429 } 432 }
430 dbg("%s - retreiving serial line settings", __func__); 433 dbg("%s - retreiving serial line settings", __func__);
431 /* set initial values in feature buffer */
432 memset(feature_buffer, 0, sizeof(feature_buffer));
433
434 do { 434 do {
435 retval = usb_control_msg(port->serial->dev, 435 retval = usb_control_msg(port->serial->dev,
436 usb_rcvctrlpipe(port->serial->dev, 0), 436 usb_rcvctrlpipe(port->serial->dev, 0),
437 HID_REQ_GET_REPORT, 437 HID_REQ_GET_REPORT,
438 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS, 438 USB_DIR_IN | USB_RECIP_INTERFACE | USB_TYPE_CLASS,
439 0x0300, 0, feature_buffer, 439 0x0300, 0, feature_buffer,
440 sizeof(feature_buffer), 500); 440 feature_len, 500);
441 441
442 if (tries++ >= 3) 442 if (tries++ >= 3)
443 break; 443 break;
444 } while (retval != sizeof(feature_buffer) 444 } while (retval != feature_len
445 && retval != -ENODEV); 445 && retval != -ENODEV);
446 446
447 if (retval != sizeof(feature_buffer)) { 447 if (retval != feature_len) {
448 dev_err(&port->dev, "%s - failed to retrieve serial " 448 dev_err(&port->dev, "%s - failed to retrieve serial "
449 "line settings - %d\n", __func__, retval); 449 "line settings - %d\n", __func__, retval);
450 cypress_set_dead(port); 450 cypress_set_dead(port);
451 return retval; 451 goto out;
452 } else { 452 } else {
453 spin_lock_irqsave(&priv->lock, flags); 453 spin_lock_irqsave(&priv->lock, flags);
454 /* store the config in one byte, and later 454 /* store the config in one byte, and later
455 use bit masks to check values */ 455 use bit masks to check values */
456 priv->current_config = feature_buffer[4]; 456 priv->current_config = feature_buffer[4];
457 priv->baud_rate = *((u_int32_t *)feature_buffer); 457 priv->baud_rate = get_unaligned_le32(feature_buffer);
458 spin_unlock_irqrestore(&priv->lock, flags); 458 spin_unlock_irqrestore(&priv->lock, flags);
459 } 459 }
460 } 460 }
461 spin_lock_irqsave(&priv->lock, flags); 461 spin_lock_irqsave(&priv->lock, flags);
462 ++priv->cmd_count; 462 ++priv->cmd_count;
463 spin_unlock_irqrestore(&priv->lock, flags); 463 spin_unlock_irqrestore(&priv->lock, flags);
464 464out:
465 kfree(feature_buffer);
465 return retval; 466 return retval;
466} /* cypress_serial_control */ 467} /* cypress_serial_control */
467 468
@@ -690,7 +691,6 @@ static void cypress_dtr_rts(struct usb_serial_port *port, int on)
690{ 691{
691 struct cypress_private *priv = usb_get_serial_port_data(port); 692 struct cypress_private *priv = usb_get_serial_port_data(port);
692 /* drop dtr and rts */ 693 /* drop dtr and rts */
693 priv = usb_get_serial_port_data(port);
694 spin_lock_irq(&priv->lock); 694 spin_lock_irq(&priv->lock);
695 if (on == 0) 695 if (on == 0)
696 priv->line_control = 0; 696 priv->line_control = 0;
@@ -1307,13 +1307,9 @@ static void cypress_read_int_callback(struct urb *urb)
1307 spin_unlock_irqrestore(&priv->lock, flags); 1307 spin_unlock_irqrestore(&priv->lock, flags);
1308 1308
1309 /* process read if there is data other than line status */ 1309 /* process read if there is data other than line status */
1310 if (tty && (bytes > i)) { 1310 if (tty && bytes > i) {
1311 bytes = tty_buffer_request_room(tty, bytes); 1311 tty_insert_flip_string_fixed_flag(tty, data + i,
1312 for (; i < bytes ; ++i) { 1312 bytes - i, tty_flag);
1313 dbg("pushing byte number %d - %d - %c", i, data[i],
1314 data[i]);
1315 tty_insert_flip_char(tty, data[i], tty_flag);
1316 }
1317 tty_flip_buffer_push(tty); 1313 tty_flip_buffer_push(tty);
1318 } 1314 }
1319 1315
@@ -1325,9 +1321,9 @@ static void cypress_read_int_callback(struct urb *urb)
1325continue_read: 1321continue_read:
1326 tty_kref_put(tty); 1322 tty_kref_put(tty);
1327 1323
1328 /* Continue trying to always read... unless the port has closed. */ 1324 /* Continue trying to always read */
1329 1325
1330 if (port->port.count > 0 && priv->comm_is_ok) { 1326 if (priv->comm_is_ok) {
1331 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev, 1327 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
1332 usb_rcvintpipe(port->serial->dev, 1328 usb_rcvintpipe(port->serial->dev,
1333 port->interrupt_in_endpointAddress), 1329 port->interrupt_in_endpointAddress),
@@ -1336,7 +1332,7 @@ continue_read:
1336 cypress_read_int_callback, port, 1332 cypress_read_int_callback, port,
1337 priv->read_urb_interval); 1333 priv->read_urb_interval);
1338 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 1334 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
1339 if (result) { 1335 if (result && result != -EPERM) {
1340 dev_err(&urb->dev->dev, "%s - failed resubmitting " 1336 dev_err(&urb->dev->dev, "%s - failed resubmitting "
1341 "read urb, error %d\n", __func__, 1337 "read urb, error %d\n", __func__,
1342 result); 1338 result);
@@ -1650,3 +1646,5 @@ module_param(stats, bool, S_IRUGO | S_IWUSR);
1650MODULE_PARM_DESC(stats, "Enable statistics or not"); 1646MODULE_PARM_DESC(stats, "Enable statistics or not");
1651module_param(interval, int, S_IRUGO | S_IWUSR); 1647module_param(interval, int, S_IRUGO | S_IWUSR);
1652MODULE_PARM_DESC(interval, "Overrides interrupt interval"); 1648MODULE_PARM_DESC(interval, "Overrides interrupt interval");
1649module_param(unstable_bauds, bool, S_IRUGO | S_IWUSR);
1650MODULE_PARM_DESC(unstable_bauds, "Allow unstable baud rates");
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 68e80be6b9e1..68b0aa5e516c 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -470,18 +470,18 @@ static int digi_read_oob_callback(struct urb *urb);
470 470
471static int debug; 471static int debug;
472 472
473static struct usb_device_id id_table_combined [] = { 473static const struct usb_device_id id_table_combined[] = {
474 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) }, 474 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
475 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) }, 475 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
476 { } /* Terminating entry */ 476 { } /* Terminating entry */
477}; 477};
478 478
479static struct usb_device_id id_table_2 [] = { 479static const struct usb_device_id id_table_2[] = {
480 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) }, 480 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_2_ID) },
481 { } /* Terminating entry */ 481 { } /* Terminating entry */
482}; 482};
483 483
484static struct usb_device_id id_table_4 [] = { 484static const struct usb_device_id id_table_4[] = {
485 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) }, 485 { USB_DEVICE(DIGI_VENDOR_ID, DIGI_4_ID) },
486 { } /* Terminating entry */ 486 { } /* Terminating entry */
487}; 487};
@@ -1262,10 +1262,10 @@ static void digi_write_bulk_callback(struct urb *urb)
1262 return; 1262 return;
1263 } 1263 }
1264 1264
1265 /* try to send any buffered data on this port, if it is open */ 1265 /* try to send any buffered data on this port */
1266 spin_lock(&priv->dp_port_lock); 1266 spin_lock(&priv->dp_port_lock);
1267 priv->dp_write_urb_in_use = 0; 1267 priv->dp_write_urb_in_use = 0;
1268 if (port->port.count && priv->dp_out_buf_len > 0) { 1268 if (priv->dp_out_buf_len > 0) {
1269 *((unsigned char *)(port->write_urb->transfer_buffer)) 1269 *((unsigned char *)(port->write_urb->transfer_buffer))
1270 = (unsigned char)DIGI_CMD_SEND_DATA; 1270 = (unsigned char)DIGI_CMD_SEND_DATA;
1271 *((unsigned char *)(port->write_urb->transfer_buffer) + 1) 1271 *((unsigned char *)(port->write_urb->transfer_buffer) + 1)
@@ -1288,7 +1288,7 @@ static void digi_write_bulk_callback(struct urb *urb)
1288 schedule_work(&priv->dp_wakeup_work); 1288 schedule_work(&priv->dp_wakeup_work);
1289 1289
1290 spin_unlock(&priv->dp_port_lock); 1290 spin_unlock(&priv->dp_port_lock);
1291 if (ret) 1291 if (ret && ret != -EPERM)
1292 dev_err(&port->dev, 1292 dev_err(&port->dev,
1293 "%s: usb_submit_urb failed, ret=%d, port=%d\n", 1293 "%s: usb_submit_urb failed, ret=%d, port=%d\n",
1294 __func__, ret, priv->dp_port_num); 1294 __func__, ret, priv->dp_port_num);
@@ -1353,8 +1353,7 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port)
1353 struct digi_port *priv = usb_get_serial_port_data(port); 1353 struct digi_port *priv = usb_get_serial_port_data(port);
1354 struct ktermios not_termios; 1354 struct ktermios not_termios;
1355 1355
1356 dbg("digi_open: TOP: port=%d, open_count=%d", 1356 dbg("digi_open: TOP: port=%d", priv->dp_port_num);
1357 priv->dp_port_num, port->port.count);
1358 1357
1359 /* be sure the device is started up */ 1358 /* be sure the device is started up */
1360 if (digi_startup_device(port->serial) != 0) 1359 if (digi_startup_device(port->serial) != 0)
@@ -1393,8 +1392,7 @@ static void digi_close(struct usb_serial_port *port)
1393 unsigned char buf[32]; 1392 unsigned char buf[32];
1394 struct digi_port *priv = usb_get_serial_port_data(port); 1393 struct digi_port *priv = usb_get_serial_port_data(port);
1395 1394
1396 dbg("digi_close: TOP: port=%d, open_count=%d", 1395 dbg("digi_close: TOP: port=%d", priv->dp_port_num);
1397 priv->dp_port_num, port->port.count);
1398 1396
1399 mutex_lock(&port->serial->disc_mutex); 1397 mutex_lock(&port->serial->disc_mutex);
1400 /* if disconnected, just clear flags */ 1398 /* if disconnected, just clear flags */
@@ -1629,7 +1627,7 @@ static void digi_read_bulk_callback(struct urb *urb)
1629 /* continue read */ 1627 /* continue read */
1630 urb->dev = port->serial->dev; 1628 urb->dev = port->serial->dev;
1631 ret = usb_submit_urb(urb, GFP_ATOMIC); 1629 ret = usb_submit_urb(urb, GFP_ATOMIC);
1632 if (ret != 0) { 1630 if (ret != 0 && ret != -EPERM) {
1633 dev_err(&port->dev, 1631 dev_err(&port->dev,
1634 "%s: failed resubmitting urb, ret=%d, port=%d\n", 1632 "%s: failed resubmitting urb, ret=%d, port=%d\n",
1635 __func__, ret, priv->dp_port_num); 1633 __func__, ret, priv->dp_port_num);
@@ -1658,12 +1656,11 @@ static int digi_read_inb_callback(struct urb *urb)
1658 int port_status = ((unsigned char *)urb->transfer_buffer)[2]; 1656 int port_status = ((unsigned char *)urb->transfer_buffer)[2];
1659 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3; 1657 unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
1660 int flag, throttled; 1658 int flag, throttled;
1661 int i;
1662 int status = urb->status; 1659 int status = urb->status;
1663 1660
1664 /* do not process callbacks on closed ports */ 1661 /* do not process callbacks on closed ports */
1665 /* but do continue the read chain */ 1662 /* but do continue the read chain */
1666 if (port->port.count == 0) 1663 if (urb->status == -ENOENT)
1667 return 0; 1664 return 0;
1668 1665
1669 /* short/multiple packet check */ 1666 /* short/multiple packet check */
@@ -1705,17 +1702,9 @@ static int digi_read_inb_callback(struct urb *urb)
1705 1702
1706 /* 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) */
1707 --len; 1704 --len;
1708
1709 len = tty_buffer_request_room(tty, len);
1710 if (len > 0) { 1705 if (len > 0) {
1711 /* Hot path */ 1706 tty_insert_flip_string_fixed_flag(tty, data, len,
1712 if (flag == TTY_NORMAL) 1707 flag);
1713 tty_insert_flip_string(tty, data, len);
1714 else {
1715 for (i = 0; i < len; i++)
1716 tty_insert_flip_char(tty,
1717 data[i], flag);
1718 }
1719 tty_flip_buffer_push(tty); 1708 tty_flip_buffer_push(tty);
1720 } 1709 }
1721 } 1710 }
@@ -1776,8 +1765,7 @@ static int digi_read_oob_callback(struct urb *urb)
1776 1765
1777 tty = tty_port_tty_get(&port->port); 1766 tty = tty_port_tty_get(&port->port);
1778 rts = 0; 1767 rts = 0;
1779 if (port->port.count) 1768 rts = tty->termios->c_cflag & CRTSCTS;
1780 rts = tty->termios->c_cflag & CRTSCTS;
1781 1769
1782 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1770 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1783 spin_lock(&priv->dp_port_lock); 1771 spin_lock(&priv->dp_port_lock);
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 7dd0e3eadbe6..5f740a1eacab 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -93,7 +93,7 @@ static void empeg_init_termios(struct tty_struct *tty);
93static void empeg_write_bulk_callback(struct urb *urb); 93static void empeg_write_bulk_callback(struct urb *urb);
94static void empeg_read_bulk_callback(struct urb *urb); 94static void empeg_read_bulk_callback(struct urb *urb);
95 95
96static struct usb_device_id id_table [] = { 96static const struct usb_device_id id_table[] = {
97 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, 97 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) },
98 { } /* Terminating entry */ 98 { } /* Terminating entry */
99}; 99};
@@ -346,7 +346,6 @@ static void empeg_read_bulk_callback(struct urb *urb)
346 tty = tty_port_tty_get(&port->port); 346 tty = tty_port_tty_get(&port->port);
347 347
348 if (urb->actual_length) { 348 if (urb->actual_length) {
349 tty_buffer_request_room(tty, urb->actual_length);
350 tty_insert_flip_string(tty, data, urb->actual_length); 349 tty_insert_flip_string(tty, data, urb->actual_length);
351 tty_flip_buffer_push(tty); 350 tty_flip_buffer_push(tty);
352 bytes_in += urb->actual_length; 351 bytes_in += urb->actual_length;
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ebcc6d0e2e91..1d7c4fac02e8 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -33,23 +33,24 @@
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/smp_lock.h>
37#include <linux/tty.h> 36#include <linux/tty.h>
38#include <linux/tty_driver.h> 37#include <linux/tty_driver.h>
39#include <linux/tty_flip.h> 38#include <linux/tty_flip.h>
40#include <linux/module.h> 39#include <linux/module.h>
41#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/mutex.h>
42#include <linux/uaccess.h> 42#include <linux/uaccess.h>
43#include <linux/usb.h> 43#include <linux/usb.h>
44#include <linux/serial.h> 44#include <linux/serial.h>
45#include <linux/usb/serial.h> 45#include <linux/usb/serial.h>
46#include "ftdi_sio.h" 46#include "ftdi_sio.h"
47#include "ftdi_sio_ids.h"
47 48
48/* 49/*
49 * Version Information 50 * Version Information
50 */ 51 */
51#define DRIVER_VERSION "v1.5.0" 52#define DRIVER_VERSION "v1.5.0"
52#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>" 53#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Bill Ryder <bryder@sgi.com>, Kuba Ober <kuba@mareimbrium.org>, Andreas Mohr"
53#define DRIVER_DESC "USB FTDI Serial Converters Driver" 54#define DRIVER_DESC "USB FTDI Serial Converters Driver"
54 55
55static int debug; 56static int debug;
@@ -87,10 +88,10 @@ struct ftdi_private {
87 88
88 unsigned int latency; /* latency setting in use */ 89 unsigned int latency; /* latency setting in use */
89 spinlock_t tx_lock; /* spinlock for transmit state */ 90 spinlock_t tx_lock; /* spinlock for transmit state */
90 unsigned long tx_bytes;
91 unsigned long tx_outstanding_bytes; 91 unsigned long tx_outstanding_bytes;
92 unsigned long tx_outstanding_urbs; 92 unsigned long tx_outstanding_urbs;
93 unsigned short max_packet_size; 93 unsigned short max_packet_size;
94 struct mutex cfg_lock; /* Avoid mess by parallel calls of config ioctl() and change_speed() */
94}; 95};
95 96
96/* struct ftdi_sio_quirk is used by devices requiring special attention. */ 97/* struct ftdi_sio_quirk is used by devices requiring special attention. */
@@ -144,10 +145,15 @@ static struct ftdi_sio_quirk ftdi_HE_TIRA1_quirk = {
144 145
145 146
146 147
148/*
149 * Device ID not listed? Test via module params product/vendor or
150 * /sys/bus/usb/ftdi_sio/new_id, then send patch/report!
151 */
147static struct usb_device_id id_table_combined [] = { 152static struct usb_device_id id_table_combined [] = {
148 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) }, 153 { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) },
149 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) }, 154 { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) },
150 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) }, 155 { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) },
156 { USB_DEVICE(FTDI_VID, FTDI_NXTCAM_PID) },
151 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) }, 157 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_0_PID) },
152 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) }, 158 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_1_PID) },
153 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) }, 159 { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_2_PID) },
@@ -551,9 +557,16 @@ static struct usb_device_id id_table_combined [] = {
551 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) }, 557 { USB_DEVICE(FTDI_VID, FTDI_IBS_PEDO_PID) },
552 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) }, 558 { USB_DEVICE(FTDI_VID, FTDI_IBS_PROD_PID) },
553 /* 559 /*
554 * Due to many user requests for multiple ELV devices we enable 560 * ELV devices:
555 * them by default.
556 */ 561 */
562 { USB_DEVICE(FTDI_VID, FTDI_ELV_USR_PID) },
563 { USB_DEVICE(FTDI_VID, FTDI_ELV_MSM1_PID) },
564 { USB_DEVICE(FTDI_VID, FTDI_ELV_KL100_PID) },
565 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS550_PID) },
566 { USB_DEVICE(FTDI_VID, FTDI_ELV_EC3000_PID) },
567 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS888_PID) },
568 { USB_DEVICE(FTDI_VID, FTDI_ELV_TWS550_PID) },
569 { USB_DEVICE(FTDI_VID, FTDI_ELV_FEM_PID) },
557 { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) }, 570 { USB_DEVICE(FTDI_VID, FTDI_ELV_CLI7000_PID) },
558 { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) }, 571 { USB_DEVICE(FTDI_VID, FTDI_ELV_PPS7330_PID) },
559 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) }, 572 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFM100_PID) },
@@ -570,11 +583,17 @@ static struct usb_device_id id_table_combined [] = {
570 { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) }, 583 { USB_DEVICE(FTDI_VID, FTDI_ELV_PCK100_PID) },
571 { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) }, 584 { USB_DEVICE(FTDI_VID, FTDI_ELV_RFP500_PID) },
572 { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) }, 585 { USB_DEVICE(FTDI_VID, FTDI_ELV_FS20SIG_PID) },
586 { USB_DEVICE(FTDI_VID, FTDI_ELV_UTP8_PID) },
573 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) }, 587 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS300PC_PID) },
588 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS444PC_PID) },
574 { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) }, 589 { USB_DEVICE(FTDI_VID, FTDI_ELV_FHZ1300PC_PID) },
575 { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) }, 590 { USB_DEVICE(FTDI_VID, FTDI_ELV_EM1010PC_PID) },
576 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) }, 591 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS500_PID) },
577 { USB_DEVICE(FTDI_VID, FTDI_ELV_HS485_PID) }, 592 { USB_DEVICE(FTDI_VID, FTDI_ELV_HS485_PID) },
593 { USB_DEVICE(FTDI_VID, FTDI_ELV_UMS100_PID) },
594 { USB_DEVICE(FTDI_VID, FTDI_ELV_TFD128_PID) },
595 { USB_DEVICE(FTDI_VID, FTDI_ELV_FM3RX_PID) },
596 { USB_DEVICE(FTDI_VID, FTDI_ELV_WS777_PID) },
578 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) }, 597 { USB_DEVICE(FTDI_VID, LINX_SDMUSBQSS_PID) },
579 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) }, 598 { USB_DEVICE(FTDI_VID, LINX_MASTERDEVEL2_PID) },
580 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) }, 599 { USB_DEVICE(FTDI_VID, LINX_FUTURE_0_PID) },
@@ -595,9 +614,24 @@ static struct usb_device_id id_table_combined [] = {
595 { USB_DEVICE(FTDI_VID, FTDI_OCEANIC_PID) }, 614 { USB_DEVICE(FTDI_VID, FTDI_OCEANIC_PID) },
596 { USB_DEVICE(TTI_VID, TTI_QL355P_PID) }, 615 { USB_DEVICE(TTI_VID, TTI_QL355P_PID) },
597 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) }, 616 { USB_DEVICE(FTDI_VID, FTDI_RM_CANVIEW_PID) },
617 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) },
598 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) }, 618 { USB_DEVICE(BANDB_VID, BANDB_USOTL4_PID) },
599 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) }, 619 { USB_DEVICE(BANDB_VID, BANDB_USTL4_PID) },
600 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) }, 620 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2_PID) },
621 { USB_DEVICE(BANDB_VID, BANDB_USOPTL4_PID) },
622 { USB_DEVICE(BANDB_VID, BANDB_USPTL4_PID) },
623 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2DR_2_PID) },
624 { USB_DEVICE(BANDB_VID, BANDB_USO9ML2DR_PID) },
625 { USB_DEVICE(BANDB_VID, BANDB_USOPTL4DR2_PID) },
626 { USB_DEVICE(BANDB_VID, BANDB_USOPTL4DR_PID) },
627 { USB_DEVICE(BANDB_VID, BANDB_485USB9F_2W_PID) },
628 { USB_DEVICE(BANDB_VID, BANDB_485USB9F_4W_PID) },
629 { USB_DEVICE(BANDB_VID, BANDB_232USB9M_PID) },
630 { USB_DEVICE(BANDB_VID, BANDB_485USBTB_2W_PID) },
631 { USB_DEVICE(BANDB_VID, BANDB_485USBTB_4W_PID) },
632 { USB_DEVICE(BANDB_VID, BANDB_TTL5USB9M_PID) },
633 { USB_DEVICE(BANDB_VID, BANDB_TTL3USB9M_PID) },
634 { USB_DEVICE(BANDB_VID, BANDB_ZZ_PROG1_USB_PID) },
601 { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) }, 635 { USB_DEVICE(FTDI_VID, EVER_ECO_PRO_CDS) },
602 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) }, 636 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_1_PID) },
603 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) }, 637 { USB_DEVICE(FTDI_VID, FTDI_4N_GALAXY_DE_2_PID) },
@@ -624,6 +658,7 @@ static struct usb_device_id id_table_combined [] = {
624 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) }, 658 { USB_DEVICE(EVOLUTION_VID, EVOLUTION_ER1_PID) },
625 { USB_DEVICE(EVOLUTION_VID, EVO_HYBRID_PID) }, 659 { USB_DEVICE(EVOLUTION_VID, EVO_HYBRID_PID) },
626 { USB_DEVICE(EVOLUTION_VID, EVO_RCM4_PID) }, 660 { USB_DEVICE(EVOLUTION_VID, EVO_RCM4_PID) },
661 { USB_DEVICE(CONTEC_VID, CONTEC_COM1USBH_PID) },
627 { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) }, 662 { USB_DEVICE(FTDI_VID, FTDI_ARTEMIS_PID) },
628 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) }, 663 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16_PID) },
629 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) }, 664 { USB_DEVICE(FTDI_VID, FTDI_ATIK_ATK16C_PID) },
@@ -682,6 +717,7 @@ static struct usb_device_id id_table_combined [] = {
682 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) }, 717 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID_USB60F) },
683 { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) }, 718 { USB_DEVICE(FTDI_VID, FTDI_REU_TINY_PID) },
684 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) }, 719 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_QUIDO4x4_PID) },
720 { USB_DEVICE(PAPOUCH_VID, PAPOUCH_AD4USB_PID) },
685 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) }, 721 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DGQG_PID) },
686 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) }, 722 { USB_DEVICE(FTDI_VID, FTDI_DOMINTELL_DUSB_PID) },
687 { USB_DEVICE(ALTI2_VID, ALTI2_N3_PID) }, 723 { USB_DEVICE(ALTI2_VID, ALTI2_N3_PID) },
@@ -703,6 +739,10 @@ static struct usb_device_id id_table_combined [] = {
703 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 739 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
704 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) }, 740 { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) },
705 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) }, 741 { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) },
742 { USB_DEVICE(FTDI_VID, MJSG_GENERIC_PID) },
743 { USB_DEVICE(FTDI_VID, MJSG_SR_RADIO_PID) },
744 { USB_DEVICE(FTDI_VID, MJSG_HD_RADIO_PID) },
745 { USB_DEVICE(FTDI_VID, MJSG_XM_RADIO_PID) },
706 { }, /* Optional parameter entry */ 746 { }, /* Optional parameter entry */
707 { } /* Terminating entry */ 747 { } /* Terminating entry */
708}; 748};
@@ -778,7 +818,7 @@ static struct usb_serial_driver ftdi_sio_device = {
778 .name = "ftdi_sio", 818 .name = "ftdi_sio",
779 }, 819 },
780 .description = "FTDI USB Serial Device", 820 .description = "FTDI USB Serial Device",
781 .usb_driver = &ftdi_driver , 821 .usb_driver = &ftdi_driver,
782 .id_table = id_table_combined, 822 .id_table = id_table_combined,
783 .num_ports = 1, 823 .num_ports = 1,
784 .probe = ftdi_sio_probe, 824 .probe = ftdi_sio_probe,
@@ -794,8 +834,8 @@ static struct usb_serial_driver ftdi_sio_device = {
794 .chars_in_buffer = ftdi_chars_in_buffer, 834 .chars_in_buffer = ftdi_chars_in_buffer,
795 .read_bulk_callback = ftdi_read_bulk_callback, 835 .read_bulk_callback = ftdi_read_bulk_callback,
796 .write_bulk_callback = ftdi_write_bulk_callback, 836 .write_bulk_callback = ftdi_write_bulk_callback,
797 .tiocmget = ftdi_tiocmget, 837 .tiocmget = ftdi_tiocmget,
798 .tiocmset = ftdi_tiocmset, 838 .tiocmset = ftdi_tiocmset,
799 .ioctl = ftdi_ioctl, 839 .ioctl = ftdi_ioctl,
800 .set_termios = ftdi_set_termios, 840 .set_termios = ftdi_set_termios,
801 .break_ctl = ftdi_break_ctl, 841 .break_ctl = ftdi_break_ctl,
@@ -901,7 +941,6 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set,
901 unsigned int clear) 941 unsigned int clear)
902{ 942{
903 struct ftdi_private *priv = usb_get_serial_port_data(port); 943 struct ftdi_private *priv = usb_get_serial_port_data(port);
904 char *buf;
905 unsigned urb_value; 944 unsigned urb_value;
906 int rv; 945 int rv;
907 946
@@ -910,10 +949,6 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set,
910 return 0; /* no change */ 949 return 0; /* no change */
911 } 950 }
912 951
913 buf = kmalloc(1, GFP_NOIO);
914 if (!buf)
915 return -ENOMEM;
916
917 clear &= ~set; /* 'set' takes precedence over 'clear' */ 952 clear &= ~set; /* 'set' takes precedence over 'clear' */
918 urb_value = 0; 953 urb_value = 0;
919 if (clear & TIOCM_DTR) 954 if (clear & TIOCM_DTR)
@@ -929,9 +964,7 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set,
929 FTDI_SIO_SET_MODEM_CTRL_REQUEST, 964 FTDI_SIO_SET_MODEM_CTRL_REQUEST,
930 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE, 965 FTDI_SIO_SET_MODEM_CTRL_REQUEST_TYPE,
931 urb_value, priv->interface, 966 urb_value, priv->interface,
932 buf, 0, WDR_TIMEOUT); 967 NULL, 0, WDR_TIMEOUT);
933
934 kfree(buf);
935 if (rv < 0) { 968 if (rv < 0) {
936 dbg("%s Error from MODEM_CTRL urb: DTR %s, RTS %s", 969 dbg("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
937 __func__, 970 __func__,
@@ -1090,16 +1123,11 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty,
1090static int change_speed(struct tty_struct *tty, struct usb_serial_port *port) 1123static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
1091{ 1124{
1092 struct ftdi_private *priv = usb_get_serial_port_data(port); 1125 struct ftdi_private *priv = usb_get_serial_port_data(port);
1093 char *buf;
1094 __u16 urb_value; 1126 __u16 urb_value;
1095 __u16 urb_index; 1127 __u16 urb_index;
1096 __u32 urb_index_value; 1128 __u32 urb_index_value;
1097 int rv; 1129 int rv;
1098 1130
1099 buf = kmalloc(1, GFP_NOIO);
1100 if (!buf)
1101 return -ENOMEM;
1102
1103 urb_index_value = get_ftdi_divisor(tty, port); 1131 urb_index_value = get_ftdi_divisor(tty, port);
1104 urb_value = (__u16)urb_index_value; 1132 urb_value = (__u16)urb_index_value;
1105 urb_index = (__u16)(urb_index_value >> 16); 1133 urb_index = (__u16)(urb_index_value >> 16);
@@ -1112,9 +1140,7 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
1112 FTDI_SIO_SET_BAUDRATE_REQUEST, 1140 FTDI_SIO_SET_BAUDRATE_REQUEST,
1113 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE, 1141 FTDI_SIO_SET_BAUDRATE_REQUEST_TYPE,
1114 urb_value, urb_index, 1142 urb_value, urb_index,
1115 buf, 0, WDR_SHORT_TIMEOUT); 1143 NULL, 0, WDR_SHORT_TIMEOUT);
1116
1117 kfree(buf);
1118 return rv; 1144 return rv;
1119} 1145}
1120 1146
@@ -1122,8 +1148,7 @@ static int write_latency_timer(struct usb_serial_port *port)
1122{ 1148{
1123 struct ftdi_private *priv = usb_get_serial_port_data(port); 1149 struct ftdi_private *priv = usb_get_serial_port_data(port);
1124 struct usb_device *udev = port->serial->dev; 1150 struct usb_device *udev = port->serial->dev;
1125 char buf[1]; 1151 int rv;
1126 int rv = 0;
1127 int l = priv->latency; 1152 int l = priv->latency;
1128 1153
1129 if (priv->flags & ASYNC_LOW_LATENCY) 1154 if (priv->flags & ASYNC_LOW_LATENCY)
@@ -1136,8 +1161,7 @@ static int write_latency_timer(struct usb_serial_port *port)
1136 FTDI_SIO_SET_LATENCY_TIMER_REQUEST, 1161 FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
1137 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, 1162 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
1138 l, priv->interface, 1163 l, priv->interface,
1139 buf, 0, WDR_TIMEOUT); 1164 NULL, 0, WDR_TIMEOUT);
1140
1141 if (rv < 0) 1165 if (rv < 0)
1142 dev_err(&port->dev, "Unable to write latency timer: %i\n", rv); 1166 dev_err(&port->dev, "Unable to write latency timer: %i\n", rv);
1143 return rv; 1167 return rv;
@@ -1147,24 +1171,29 @@ static int read_latency_timer(struct usb_serial_port *port)
1147{ 1171{
1148 struct ftdi_private *priv = usb_get_serial_port_data(port); 1172 struct ftdi_private *priv = usb_get_serial_port_data(port);
1149 struct usb_device *udev = port->serial->dev; 1173 struct usb_device *udev = port->serial->dev;
1150 unsigned short latency = 0; 1174 unsigned char *buf;
1151 int rv = 0; 1175 int rv;
1152
1153 1176
1154 dbg("%s", __func__); 1177 dbg("%s", __func__);
1155 1178
1179 buf = kmalloc(1, GFP_KERNEL);
1180 if (!buf)
1181 return -ENOMEM;
1182
1156 rv = usb_control_msg(udev, 1183 rv = usb_control_msg(udev,
1157 usb_rcvctrlpipe(udev, 0), 1184 usb_rcvctrlpipe(udev, 0),
1158 FTDI_SIO_GET_LATENCY_TIMER_REQUEST, 1185 FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1159 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE, 1186 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1160 0, priv->interface, 1187 0, priv->interface,
1161 (char *) &latency, 1, WDR_TIMEOUT); 1188 buf, 1, WDR_TIMEOUT);
1162 1189 if (rv < 0)
1163 if (rv < 0) {
1164 dev_err(&port->dev, "Unable to read latency timer: %i\n", rv); 1190 dev_err(&port->dev, "Unable to read latency timer: %i\n", rv);
1165 return -EIO; 1191 else
1166 } 1192 priv->latency = buf[0];
1167 return latency; 1193
1194 kfree(buf);
1195
1196 return rv;
1168} 1197}
1169 1198
1170static int get_serial_info(struct usb_serial_port *port, 1199static int get_serial_info(struct usb_serial_port *port,
@@ -1195,7 +1224,7 @@ static int set_serial_info(struct tty_struct *tty,
1195 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial))) 1224 if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
1196 return -EFAULT; 1225 return -EFAULT;
1197 1226
1198 lock_kernel(); 1227 mutex_lock(&priv->cfg_lock);
1199 old_priv = *priv; 1228 old_priv = *priv;
1200 1229
1201 /* Do error checking and permission checking */ 1230 /* Do error checking and permission checking */
@@ -1203,7 +1232,7 @@ static int set_serial_info(struct tty_struct *tty,
1203 if (!capable(CAP_SYS_ADMIN)) { 1232 if (!capable(CAP_SYS_ADMIN)) {
1204 if (((new_serial.flags & ~ASYNC_USR_MASK) != 1233 if (((new_serial.flags & ~ASYNC_USR_MASK) !=
1205 (priv->flags & ~ASYNC_USR_MASK))) { 1234 (priv->flags & ~ASYNC_USR_MASK))) {
1206 unlock_kernel(); 1235 mutex_unlock(&priv->cfg_lock);
1207 return -EPERM; 1236 return -EPERM;
1208 } 1237 }
1209 priv->flags = ((priv->flags & ~ASYNC_USR_MASK) | 1238 priv->flags = ((priv->flags & ~ASYNC_USR_MASK) |
@@ -1214,7 +1243,7 @@ static int set_serial_info(struct tty_struct *tty,
1214 1243
1215 if ((new_serial.baud_base != priv->baud_base) && 1244 if ((new_serial.baud_base != priv->baud_base) &&
1216 (new_serial.baud_base < 9600)) { 1245 (new_serial.baud_base < 9600)) {
1217 unlock_kernel(); 1246 mutex_unlock(&priv->cfg_lock);
1218 return -EINVAL; 1247 return -EINVAL;
1219 } 1248 }
1220 1249
@@ -1244,11 +1273,11 @@ check_and_exit:
1244 (priv->flags & ASYNC_SPD_MASK)) || 1273 (priv->flags & ASYNC_SPD_MASK)) ||
1245 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) && 1274 (((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST) &&
1246 (old_priv.custom_divisor != priv->custom_divisor))) { 1275 (old_priv.custom_divisor != priv->custom_divisor))) {
1247 unlock_kernel();
1248 change_speed(tty, port); 1276 change_speed(tty, port);
1277 mutex_unlock(&priv->cfg_lock);
1249 } 1278 }
1250 else 1279 else
1251 unlock_kernel(); 1280 mutex_unlock(&priv->cfg_lock);
1252 return 0; 1281 return 0;
1253 1282
1254} /* set_serial_info */ 1283} /* set_serial_info */
@@ -1304,20 +1333,20 @@ static void ftdi_determine_type(struct usb_serial_port *port)
1304 __func__); 1333 __func__);
1305 } 1334 }
1306 } else if (version < 0x200) { 1335 } else if (version < 0x200) {
1307 /* Old device. Assume its the original SIO. */ 1336 /* Old device. Assume it's the original SIO. */
1308 priv->chip_type = SIO; 1337 priv->chip_type = SIO;
1309 priv->baud_base = 12000000 / 16; 1338 priv->baud_base = 12000000 / 16;
1310 priv->write_offset = 1; 1339 priv->write_offset = 1;
1311 } else if (version < 0x400) { 1340 } else if (version < 0x400) {
1312 /* Assume its an FT8U232AM (or FT8U245AM) */ 1341 /* Assume it's an FT8U232AM (or FT8U245AM) */
1313 /* (It might be a BM because of the iSerialNumber bug, 1342 /* (It might be a BM because of the iSerialNumber bug,
1314 * but it will still work as an AM device.) */ 1343 * but it will still work as an AM device.) */
1315 priv->chip_type = FT8U232AM; 1344 priv->chip_type = FT8U232AM;
1316 } else if (version < 0x600) { 1345 } else if (version < 0x600) {
1317 /* Assume its an FT232BM (or FT245BM) */ 1346 /* Assume it's an FT232BM (or FT245BM) */
1318 priv->chip_type = FT232BM; 1347 priv->chip_type = FT232BM;
1319 } else { 1348 } else {
1320 /* Assume its an FT232R */ 1349 /* Assume it's an FT232R */
1321 priv->chip_type = FT232RL; 1350 priv->chip_type = FT232RL;
1322 } 1351 }
1323 dev_info(&udev->dev, "Detected %s\n", ftdi_chip_name[priv->chip_type]); 1352 dev_info(&udev->dev, "Detected %s\n", ftdi_chip_name[priv->chip_type]);
@@ -1337,7 +1366,7 @@ static void ftdi_set_max_packet_size(struct usb_serial_port *port)
1337 struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc; 1366 struct usb_endpoint_descriptor *ep_desc = &interface->cur_altsetting->endpoint[1].desc;
1338 1367
1339 unsigned num_endpoints; 1368 unsigned num_endpoints;
1340 int i = 0; 1369 int i;
1341 1370
1342 num_endpoints = interface->cur_altsetting->desc.bNumEndpoints; 1371 num_endpoints = interface->cur_altsetting->desc.bNumEndpoints;
1343 dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints); 1372 dev_info(&udev->dev, "Number of endpoints %d\n", num_endpoints);
@@ -1389,7 +1418,7 @@ static ssize_t store_latency_timer(struct device *dev,
1389 struct usb_serial_port *port = to_usb_serial_port(dev); 1418 struct usb_serial_port *port = to_usb_serial_port(dev);
1390 struct ftdi_private *priv = usb_get_serial_port_data(port); 1419 struct ftdi_private *priv = usb_get_serial_port_data(port);
1391 int v = simple_strtoul(valbuf, NULL, 10); 1420 int v = simple_strtoul(valbuf, NULL, 10);
1392 int rv = 0; 1421 int rv;
1393 1422
1394 priv->latency = v; 1423 priv->latency = v;
1395 rv = write_latency_timer(port); 1424 rv = write_latency_timer(port);
@@ -1406,9 +1435,8 @@ static ssize_t store_event_char(struct device *dev,
1406 struct usb_serial_port *port = to_usb_serial_port(dev); 1435 struct usb_serial_port *port = to_usb_serial_port(dev);
1407 struct ftdi_private *priv = usb_get_serial_port_data(port); 1436 struct ftdi_private *priv = usb_get_serial_port_data(port);
1408 struct usb_device *udev = port->serial->dev; 1437 struct usb_device *udev = port->serial->dev;
1409 char buf[1];
1410 int v = simple_strtoul(valbuf, NULL, 10); 1438 int v = simple_strtoul(valbuf, NULL, 10);
1411 int rv = 0; 1439 int rv;
1412 1440
1413 dbg("%s: setting event char = %i", __func__, v); 1441 dbg("%s: setting event char = %i", __func__, v);
1414 1442
@@ -1417,8 +1445,7 @@ static ssize_t store_event_char(struct device *dev,
1417 FTDI_SIO_SET_EVENT_CHAR_REQUEST, 1445 FTDI_SIO_SET_EVENT_CHAR_REQUEST,
1418 FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE, 1446 FTDI_SIO_SET_EVENT_CHAR_REQUEST_TYPE,
1419 v, priv->interface, 1447 v, priv->interface,
1420 buf, 0, WDR_TIMEOUT); 1448 NULL, 0, WDR_TIMEOUT);
1421
1422 if (rv < 0) { 1449 if (rv < 0) {
1423 dbg("Unable to write event character: %i", rv); 1450 dbg("Unable to write event character: %i", rv);
1424 return -EIO; 1451 return -EIO;
@@ -1517,9 +1544,9 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1517 1544
1518 kref_init(&priv->kref); 1545 kref_init(&priv->kref);
1519 spin_lock_init(&priv->tx_lock); 1546 spin_lock_init(&priv->tx_lock);
1547 mutex_init(&priv->cfg_lock);
1520 init_waitqueue_head(&priv->delta_msr_wait); 1548 init_waitqueue_head(&priv->delta_msr_wait);
1521 /* This will push the characters through immediately rather 1549
1522 than queue a task to deliver them */
1523 priv->flags = ASYNC_LOW_LATENCY; 1550 priv->flags = ASYNC_LOW_LATENCY;
1524 1551
1525 if (quirk && quirk->port_probe) 1552 if (quirk && quirk->port_probe)
@@ -1551,7 +1578,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1551 1578
1552 ftdi_determine_type(port); 1579 ftdi_determine_type(port);
1553 ftdi_set_max_packet_size(port); 1580 ftdi_set_max_packet_size(port);
1554 read_latency_timer(port); 1581 if (read_latency_timer(port) < 0)
1582 priv->latency = 16;
1555 create_sysfs_attrs(port); 1583 create_sysfs_attrs(port);
1556 return 0; 1584 return 0;
1557} 1585}
@@ -1596,8 +1624,6 @@ static int ftdi_NDI_device_setup(struct usb_serial *serial)
1596{ 1624{
1597 struct usb_device *udev = serial->dev; 1625 struct usb_device *udev = serial->dev;
1598 int latency = ndi_latency_timer; 1626 int latency = ndi_latency_timer;
1599 int rv = 0;
1600 char buf[1];
1601 1627
1602 if (latency == 0) 1628 if (latency == 0)
1603 latency = 1; 1629 latency = 1;
@@ -1607,10 +1633,11 @@ static int ftdi_NDI_device_setup(struct usb_serial *serial)
1607 dbg("%s setting NDI device latency to %d", __func__, latency); 1633 dbg("%s setting NDI device latency to %d", __func__, latency);
1608 dev_info(&udev->dev, "NDI device with a latency value of %d", latency); 1634 dev_info(&udev->dev, "NDI device with a latency value of %d", latency);
1609 1635
1610 rv = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 1636 /* FIXME: errors are not returned */
1637 usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
1611 FTDI_SIO_SET_LATENCY_TIMER_REQUEST, 1638 FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
1612 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE, 1639 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
1613 latency, 0, buf, 0, WDR_TIMEOUT); 1640 latency, 0, NULL, 0, WDR_TIMEOUT);
1614 return 0; 1641 return 0;
1615} 1642}
1616 1643
@@ -1686,7 +1713,7 @@ static int ftdi_submit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
1686 urb->transfer_buffer_length, 1713 urb->transfer_buffer_length,
1687 ftdi_read_bulk_callback, port); 1714 ftdi_read_bulk_callback, port);
1688 result = usb_submit_urb(urb, mem_flags); 1715 result = usb_submit_urb(urb, mem_flags);
1689 if (result) 1716 if (result && result != -EPERM)
1690 dev_err(&port->dev, 1717 dev_err(&port->dev,
1691 "%s - failed submitting read urb, error %d\n", 1718 "%s - failed submitting read urb, error %d\n",
1692 __func__, result); 1719 __func__, result);
@@ -1698,16 +1725,10 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1698 struct usb_device *dev = port->serial->dev; 1725 struct usb_device *dev = port->serial->dev;
1699 struct ftdi_private *priv = usb_get_serial_port_data(port); 1726 struct ftdi_private *priv = usb_get_serial_port_data(port);
1700 unsigned long flags; 1727 unsigned long flags;
1701 1728 int result;
1702 int result = 0;
1703 char buf[1]; /* Needed for the usb_control_msg I think */
1704 1729
1705 dbg("%s", __func__); 1730 dbg("%s", __func__);
1706 1731
1707 spin_lock_irqsave(&priv->tx_lock, flags);
1708 priv->tx_bytes = 0;
1709 spin_unlock_irqrestore(&priv->tx_lock, flags);
1710
1711 write_latency_timer(port); 1732 write_latency_timer(port);
1712 1733
1713 /* No error checking for this (will get errors later anyway) */ 1734 /* No error checking for this (will get errors later anyway) */
@@ -1715,7 +1736,7 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1715 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1736 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
1716 FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE, 1737 FTDI_SIO_RESET_REQUEST, FTDI_SIO_RESET_REQUEST_TYPE,
1717 FTDI_SIO_RESET_SIO, 1738 FTDI_SIO_RESET_SIO,
1718 priv->interface, buf, 0, WDR_TIMEOUT); 1739 priv->interface, NULL, 0, WDR_TIMEOUT);
1719 1740
1720 /* Termios defaults are set by usb_serial_init. We don't change 1741 /* Termios defaults are set by usb_serial_init. We don't change
1721 port->tty->termios - this would lose speed settings, etc. 1742 port->tty->termios - this would lose speed settings, etc.
@@ -1743,7 +1764,6 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1743static void ftdi_dtr_rts(struct usb_serial_port *port, int on) 1764static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1744{ 1765{
1745 struct ftdi_private *priv = usb_get_serial_port_data(port); 1766 struct ftdi_private *priv = usb_get_serial_port_data(port);
1746 char buf[1];
1747 1767
1748 mutex_lock(&port->serial->disc_mutex); 1768 mutex_lock(&port->serial->disc_mutex);
1749 if (!port->serial->disconnected) { 1769 if (!port->serial->disconnected) {
@@ -1752,7 +1772,7 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1752 usb_sndctrlpipe(port->serial->dev, 0), 1772 usb_sndctrlpipe(port->serial->dev, 0),
1753 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 1773 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
1754 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 1774 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
1755 0, priv->interface, buf, 0, 1775 0, priv->interface, NULL, 0,
1756 WDR_TIMEOUT) < 0) { 1776 WDR_TIMEOUT) < 0) {
1757 dev_err(&port->dev, "error from flowcontrol urb\n"); 1777 dev_err(&port->dev, "error from flowcontrol urb\n");
1758 } 1778 }
@@ -1813,7 +1833,7 @@ static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
1813 spin_lock_irqsave(&priv->tx_lock, flags); 1833 spin_lock_irqsave(&priv->tx_lock, flags);
1814 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) { 1834 if (priv->tx_outstanding_urbs > URB_UPPER_LIMIT) {
1815 spin_unlock_irqrestore(&priv->tx_lock, flags); 1835 spin_unlock_irqrestore(&priv->tx_lock, flags);
1816 dbg("%s - write limit hit\n", __func__); 1836 dbg("%s - write limit hit", __func__);
1817 return 0; 1837 return 0;
1818 } 1838 }
1819 priv->tx_outstanding_urbs++; 1839 priv->tx_outstanding_urbs++;
@@ -1893,7 +1913,6 @@ static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
1893 } else { 1913 } else {
1894 spin_lock_irqsave(&priv->tx_lock, flags); 1914 spin_lock_irqsave(&priv->tx_lock, flags);
1895 priv->tx_outstanding_bytes += count; 1915 priv->tx_outstanding_bytes += count;
1896 priv->tx_bytes += count;
1897 spin_unlock_irqrestore(&priv->tx_lock, flags); 1916 spin_unlock_irqrestore(&priv->tx_lock, flags);
1898 } 1917 }
1899 1918
@@ -2120,8 +2139,7 @@ static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2120{ 2139{
2121 struct usb_serial_port *port = tty->driver_data; 2140 struct usb_serial_port *port = tty->driver_data;
2122 struct ftdi_private *priv = usb_get_serial_port_data(port); 2141 struct ftdi_private *priv = usb_get_serial_port_data(port);
2123 __u16 urb_value = 0; 2142 __u16 urb_value;
2124 char buf[1];
2125 2143
2126 /* break_state = -1 to turn on break, and 0 to turn off break */ 2144 /* break_state = -1 to turn on break, and 0 to turn off break */
2127 /* see drivers/char/tty_io.c to see it used */ 2145 /* see drivers/char/tty_io.c to see it used */
@@ -2137,7 +2155,7 @@ static void ftdi_break_ctl(struct tty_struct *tty, int break_state)
2137 FTDI_SIO_SET_DATA_REQUEST, 2155 FTDI_SIO_SET_DATA_REQUEST,
2138 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2156 FTDI_SIO_SET_DATA_REQUEST_TYPE,
2139 urb_value , priv->interface, 2157 urb_value , priv->interface,
2140 buf, 0, WDR_TIMEOUT) < 0) { 2158 NULL, 0, WDR_TIMEOUT) < 0) {
2141 dev_err(&port->dev, "%s FAILED to enable/disable break state " 2159 dev_err(&port->dev, "%s FAILED to enable/disable break state "
2142 "(state was %d)\n", __func__, break_state); 2160 "(state was %d)\n", __func__, break_state);
2143 } 2161 }
@@ -2161,7 +2179,6 @@ static void ftdi_set_termios(struct tty_struct *tty,
2161 struct ktermios *termios = tty->termios; 2179 struct ktermios *termios = tty->termios;
2162 unsigned int cflag = termios->c_cflag; 2180 unsigned int cflag = termios->c_cflag;
2163 __u16 urb_value; /* will hold the new flags */ 2181 __u16 urb_value; /* will hold the new flags */
2164 char buf[1]; /* Perhaps I should dynamically alloc this? */
2165 2182
2166 /* Added for xon/xoff support */ 2183 /* Added for xon/xoff support */
2167 unsigned int iflag = termios->c_iflag; 2184 unsigned int iflag = termios->c_iflag;
@@ -2195,23 +2212,27 @@ static void ftdi_set_termios(struct tty_struct *tty,
2195 2212
2196 /* Set number of data bits, parity, stop bits */ 2213 /* Set number of data bits, parity, stop bits */
2197 2214
2198 termios->c_cflag &= ~CMSPAR;
2199
2200 urb_value = 0; 2215 urb_value = 0;
2201 urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 : 2216 urb_value |= (cflag & CSTOPB ? FTDI_SIO_SET_DATA_STOP_BITS_2 :
2202 FTDI_SIO_SET_DATA_STOP_BITS_1); 2217 FTDI_SIO_SET_DATA_STOP_BITS_1);
2203 urb_value |= (cflag & PARENB ? 2218 if (cflag & PARENB) {
2204 (cflag & PARODD ? FTDI_SIO_SET_DATA_PARITY_ODD : 2219 if (cflag & CMSPAR)
2205 FTDI_SIO_SET_DATA_PARITY_EVEN) : 2220 urb_value |= cflag & PARODD ?
2206 FTDI_SIO_SET_DATA_PARITY_NONE); 2221 FTDI_SIO_SET_DATA_PARITY_MARK :
2222 FTDI_SIO_SET_DATA_PARITY_SPACE;
2223 else
2224 urb_value |= cflag & PARODD ?
2225 FTDI_SIO_SET_DATA_PARITY_ODD :
2226 FTDI_SIO_SET_DATA_PARITY_EVEN;
2227 } else {
2228 urb_value |= FTDI_SIO_SET_DATA_PARITY_NONE;
2229 }
2207 if (cflag & CSIZE) { 2230 if (cflag & CSIZE) {
2208 switch (cflag & CSIZE) { 2231 switch (cflag & CSIZE) {
2209 case CS5: urb_value |= 5; dbg("Setting CS5"); break;
2210 case CS6: urb_value |= 6; dbg("Setting CS6"); break;
2211 case CS7: urb_value |= 7; dbg("Setting CS7"); break; 2232 case CS7: urb_value |= 7; dbg("Setting CS7"); break;
2212 case CS8: urb_value |= 8; dbg("Setting CS8"); break; 2233 case CS8: urb_value |= 8; dbg("Setting CS8"); break;
2213 default: 2234 default:
2214 dev_err(&port->dev, "CSIZE was set but not CS5-CS8\n"); 2235 dev_err(&port->dev, "CSIZE was set but not CS7-CS8\n");
2215 } 2236 }
2216 } 2237 }
2217 2238
@@ -2223,7 +2244,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2223 FTDI_SIO_SET_DATA_REQUEST, 2244 FTDI_SIO_SET_DATA_REQUEST,
2224 FTDI_SIO_SET_DATA_REQUEST_TYPE, 2245 FTDI_SIO_SET_DATA_REQUEST_TYPE,
2225 urb_value , priv->interface, 2246 urb_value , priv->interface,
2226 buf, 0, WDR_SHORT_TIMEOUT) < 0) { 2247 NULL, 0, WDR_SHORT_TIMEOUT) < 0) {
2227 dev_err(&port->dev, "%s FAILED to set " 2248 dev_err(&port->dev, "%s FAILED to set "
2228 "databits/stopbits/parity\n", __func__); 2249 "databits/stopbits/parity\n", __func__);
2229 } 2250 }
@@ -2235,7 +2256,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2235 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2256 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2236 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2257 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2237 0, priv->interface, 2258 0, priv->interface,
2238 buf, 0, WDR_TIMEOUT) < 0) { 2259 NULL, 0, WDR_TIMEOUT) < 0) {
2239 dev_err(&port->dev, 2260 dev_err(&port->dev,
2240 "%s error from disable flowcontrol urb\n", 2261 "%s error from disable flowcontrol urb\n",
2241 __func__); 2262 __func__);
@@ -2244,9 +2265,11 @@ static void ftdi_set_termios(struct tty_struct *tty,
2244 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2265 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
2245 } else { 2266 } else {
2246 /* set the baudrate determined before */ 2267 /* set the baudrate determined before */
2268 mutex_lock(&priv->cfg_lock);
2247 if (change_speed(tty, port)) 2269 if (change_speed(tty, port))
2248 dev_err(&port->dev, "%s urb failed to set baudrate\n", 2270 dev_err(&port->dev, "%s urb failed to set baudrate\n",
2249 __func__); 2271 __func__);
2272 mutex_unlock(&priv->cfg_lock);
2250 /* Ensure RTS and DTR are raised when baudrate changed from 0 */ 2273 /* Ensure RTS and DTR are raised when baudrate changed from 0 */
2251 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0) 2274 if (!old_termios || (old_termios->c_cflag & CBAUD) == B0)
2252 set_mctrl(port, TIOCM_DTR | TIOCM_RTS); 2275 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
@@ -2261,7 +2284,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2261 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2284 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2262 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2285 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2263 0 , (FTDI_SIO_RTS_CTS_HS | priv->interface), 2286 0 , (FTDI_SIO_RTS_CTS_HS | priv->interface),
2264 buf, 0, WDR_TIMEOUT) < 0) { 2287 NULL, 0, WDR_TIMEOUT) < 0) {
2265 dev_err(&port->dev, 2288 dev_err(&port->dev,
2266 "urb failed to set to rts/cts flow control\n"); 2289 "urb failed to set to rts/cts flow control\n");
2267 } 2290 }
@@ -2293,7 +2316,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2293 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2316 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2294 urb_value , (FTDI_SIO_XON_XOFF_HS 2317 urb_value , (FTDI_SIO_XON_XOFF_HS
2295 | priv->interface), 2318 | priv->interface),
2296 buf, 0, WDR_TIMEOUT) < 0) { 2319 NULL, 0, WDR_TIMEOUT) < 0) {
2297 dev_err(&port->dev, "urb failed to set to " 2320 dev_err(&port->dev, "urb failed to set to "
2298 "xon/xoff flow control\n"); 2321 "xon/xoff flow control\n");
2299 } 2322 }
@@ -2307,7 +2330,7 @@ static void ftdi_set_termios(struct tty_struct *tty,
2307 FTDI_SIO_SET_FLOW_CTRL_REQUEST, 2330 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
2308 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE, 2331 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
2309 0, priv->interface, 2332 0, priv->interface,
2310 buf, 0, WDR_TIMEOUT) < 0) { 2333 NULL, 0, WDR_TIMEOUT) < 0) {
2311 dev_err(&port->dev, 2334 dev_err(&port->dev,
2312 "urb failed to clear flow control\n"); 2335 "urb failed to clear flow control\n");
2313 } 2336 }
@@ -2321,21 +2344,22 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2321{ 2344{
2322 struct usb_serial_port *port = tty->driver_data; 2345 struct usb_serial_port *port = tty->driver_data;
2323 struct ftdi_private *priv = usb_get_serial_port_data(port); 2346 struct ftdi_private *priv = usb_get_serial_port_data(port);
2324 unsigned char buf[2]; 2347 unsigned char *buf;
2348 int len;
2325 int ret; 2349 int ret;
2326 2350
2327 dbg("%s TIOCMGET", __func__); 2351 dbg("%s TIOCMGET", __func__);
2352
2353 buf = kmalloc(2, GFP_KERNEL);
2354 if (!buf)
2355 return -ENOMEM;
2356 /*
2357 * The 8U232AM returns a two byte value (the SIO a 1 byte value) in
2358 * the same format as the data returned from the in point.
2359 */
2328 switch (priv->chip_type) { 2360 switch (priv->chip_type) {
2329 case SIO: 2361 case SIO:
2330 /* Request the status from the device */ 2362 len = 1;
2331 ret = usb_control_msg(port->serial->dev,
2332 usb_rcvctrlpipe(port->serial->dev, 0),
2333 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2334 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2335 0, 0,
2336 buf, 1, WDR_TIMEOUT);
2337 if (ret < 0)
2338 return ret;
2339 break; 2363 break;
2340 case FT8U232AM: 2364 case FT8U232AM:
2341 case FT232BM: 2365 case FT232BM:
@@ -2343,27 +2367,30 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2343 case FT232RL: 2367 case FT232RL:
2344 case FT2232H: 2368 case FT2232H:
2345 case FT4232H: 2369 case FT4232H:
2346 /* the 8U232AM returns a two byte value (the sio is a 1 byte 2370 len = 2;
2347 value) - in the same format as the data returned from the in
2348 point */
2349 ret = usb_control_msg(port->serial->dev,
2350 usb_rcvctrlpipe(port->serial->dev, 0),
2351 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2352 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2353 0, priv->interface,
2354 buf, 2, WDR_TIMEOUT);
2355 if (ret < 0)
2356 return ret;
2357 break; 2371 break;
2358 default: 2372 default:
2359 return -EFAULT; 2373 ret = -EFAULT;
2374 goto out;
2360 } 2375 }
2361 2376
2362 return (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) | 2377 ret = usb_control_msg(port->serial->dev,
2378 usb_rcvctrlpipe(port->serial->dev, 0),
2379 FTDI_SIO_GET_MODEM_STATUS_REQUEST,
2380 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2381 0, priv->interface,
2382 buf, len, WDR_TIMEOUT);
2383 if (ret < 0)
2384 goto out;
2385
2386 ret = (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
2363 (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) | 2387 (buf[0] & FTDI_SIO_CTS_MASK ? TIOCM_CTS : 0) |
2364 (buf[0] & FTDI_SIO_RI_MASK ? TIOCM_RI : 0) | 2388 (buf[0] & FTDI_SIO_RI_MASK ? TIOCM_RI : 0) |
2365 (buf[0] & FTDI_SIO_RLSD_MASK ? TIOCM_CD : 0) | 2389 (buf[0] & FTDI_SIO_RLSD_MASK ? TIOCM_CD : 0) |
2366 priv->last_dtr_rts; 2390 priv->last_dtr_rts;
2391out:
2392 kfree(buf);
2393 return ret;
2367} 2394}
2368 2395
2369static int ftdi_tiocmset(struct tty_struct *tty, struct file *file, 2396static int ftdi_tiocmset(struct tty_struct *tty, struct file *file,
@@ -2468,8 +2495,7 @@ void ftdi_unthrottle(struct tty_struct *tty)
2468 port->throttled = port->throttle_req = 0; 2495 port->throttled = port->throttle_req = 0;
2469 spin_unlock_irqrestore(&port->lock, flags); 2496 spin_unlock_irqrestore(&port->lock, flags);
2470 2497
2471 /* Resubmit urb if throttled and open. */ 2498 if (was_throttled)
2472 if (was_throttled && test_bit(ASYNCB_INITIALIZED, &port->port.flags))
2473 ftdi_submit_read_urb(port, GFP_KERNEL); 2499 ftdi_submit_read_urb(port, GFP_KERNEL);
2474} 2500}
2475 2501
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 6f31e0d71898..ff9bf80327a3 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -1,7 +1,10 @@
1/* 1/*
2 * Definitions for the FTDI USB Single Port Serial Converter - 2 * Driver definitions for the FTDI USB Single Port Serial Converter -
3 * known as FTDI_SIO (Serial Input/Output application of the chipset) 3 * known as FTDI_SIO (Serial Input/Output application of the chipset)
4 * 4 *
5 * For USB vendor/product IDs (VID/PID), please see ftdi_sio_ids.h
6 *
7 *
5 * The example I have is known as the USC-1000 which is available from 8 * The example I have is known as the USC-1000 which is available from
6 * http://www.dse.co.nz - cat no XH4214 It looks similar to this: 9 * http://www.dse.co.nz - cat no XH4214 It looks similar to this:
7 * http://www.dansdata.com/usbser.htm but I can't be sure There are other 10 * http://www.dansdata.com/usbser.htm but I can't be sure There are other
@@ -17,866 +20,7 @@
17 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the 20 * Bill Ryder - bryder@sgi.com formerly of Silicon Graphics, Inc.- wrote the
18 * FTDI_SIO implementation. 21 * FTDI_SIO implementation.
19 * 22 *
20 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais
21 * from Rudolf Gugler
22 *
23 */
24
25#define FTDI_VID 0x0403 /* Vendor Id */
26#define FTDI_SIO_PID 0x8372 /* Product Id SIO application of 8U100AX */
27#define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */
28#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */
29#define FTDI_8U2232C_PID 0x6010 /* Dual channel device */
30#define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */
31#define FTDI_4232H_PID 0x6011 /* Quad channel hi-speed device */
32#define FTDI_RELAIS_PID 0xFA10 /* Relais device from Rudolf Gugler */
33#define FTDI_NF_RIC_VID 0x0DCD /* Vendor Id */
34#define FTDI_NF_RIC_PID 0x0001 /* Product Id */
35#define FTDI_USBX_707_PID 0xF857 /* ADSTech IR Blaster USBX-707 */
36
37/* Larsen and Brusgaard AltiTrack/USBtrack */
38#define LARSENBRUSGAARD_VID 0x0FD8
39#define LB_ALTITRACK_PID 0x0001
40
41/* www.canusb.com Lawicel CANUSB device */
42#define FTDI_CANUSB_PID 0xFFA8 /* Product Id */
43
44/* AlphaMicro Components AMC-232USB01 device */
45#define FTDI_AMC232_PID 0xFF00 /* Product Id */
46
47/* www.candapter.com Ewert Energy Systems CANdapter device */
48#define FTDI_CANDAPTER_PID 0x9F80 /* Product Id */
49
50/* SCS HF Radio Modems PID's (http://www.scs-ptc.com) */
51/* the VID is the standard ftdi vid (FTDI_VID) */
52#define FTDI_SCS_DEVICE_0_PID 0xD010 /* SCS PTC-IIusb */
53#define FTDI_SCS_DEVICE_1_PID 0xD011 /* SCS Tracker / DSP TNC */
54#define FTDI_SCS_DEVICE_2_PID 0xD012
55#define FTDI_SCS_DEVICE_3_PID 0xD013
56#define FTDI_SCS_DEVICE_4_PID 0xD014
57#define FTDI_SCS_DEVICE_5_PID 0xD015
58#define FTDI_SCS_DEVICE_6_PID 0xD016
59#define FTDI_SCS_DEVICE_7_PID 0xD017
60
61/* ACT Solutions HomePro ZWave interface (http://www.act-solutions.com/HomePro.htm) */
62#define FTDI_ACTZWAVE_PID 0xF2D0
63
64
65/* www.starting-point-systems.com µChameleon device */
66#define FTDI_MICRO_CHAMELEON_PID 0xCAA0 /* Product Id */
67
68/* www.irtrans.de device */
69#define FTDI_IRTRANS_PID 0xFC60 /* Product Id */
70
71
72/* www.thoughttechnology.com/ TT-USB provide with procomp use ftdi_sio */
73#define FTDI_TTUSB_PID 0xFF20 /* Product Id */
74
75/* iPlus device */
76#define FTDI_IPLUS_PID 0xD070 /* Product Id */
77#define FTDI_IPLUS2_PID 0xD071 /* Product Id */
78
79/* DMX4ALL DMX Interfaces */
80#define FTDI_DMX4ALL 0xC850
81
82/* OpenDCC (www.opendcc.de) product id */
83#define FTDI_OPENDCC_PID 0xBFD8
84#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9
85#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
86#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
87
88/* Sprog II (Andrew Crosland's SprogII DCC interface) */
89#define FTDI_SPROG_II 0xF0C8
90
91/* www.crystalfontz.com devices - thanx for providing free devices for evaluation ! */
92/* they use the ftdi chipset for the USB interface and the vendor id is the same */
93#define FTDI_XF_632_PID 0xFC08 /* 632: 16x2 Character Display */
94#define FTDI_XF_634_PID 0xFC09 /* 634: 20x4 Character Display */
95#define FTDI_XF_547_PID 0xFC0A /* 547: Two line Display */
96#define FTDI_XF_633_PID 0xFC0B /* 633: 16x2 Character Display with Keys */
97#define FTDI_XF_631_PID 0xFC0C /* 631: 20x2 Character Display */
98#define FTDI_XF_635_PID 0xFC0D /* 635: 20x4 Character Display */
99#define FTDI_XF_640_PID 0xFC0E /* 640: Two line Display */
100#define FTDI_XF_642_PID 0xFC0F /* 642: Two line Display */
101
102/* Video Networks Limited / Homechoice in the UK use an ftdi-based device for their 1Mb */
103/* broadband internet service. The following PID is exhibited by the usb device supplied */
104/* (the VID is the standard ftdi vid (FTDI_VID) */
105#define FTDI_VNHCPCUSB_D_PID 0xfe38 /* Product Id */
106
107/*
108 * PCDJ use ftdi based dj-controllers. The following PID is for their DAC-2 device
109 * http://www.pcdjhardware.com/DAC2.asp (PID sent by Wouter Paesen)
110 * (the VID is the standard ftdi vid (FTDI_VID) */
111#define FTDI_PCDJ_DAC2_PID 0xFA88
112
113/*
114 * The following are the values for the Matrix Orbital LCD displays,
115 * which are the FT232BM ( similar to the 8U232AM )
116 */
117#define FTDI_MTXORB_0_PID 0xFA00 /* Matrix Orbital Product Id */
118#define FTDI_MTXORB_1_PID 0xFA01 /* Matrix Orbital Product Id */
119#define FTDI_MTXORB_2_PID 0xFA02 /* Matrix Orbital Product Id */
120#define FTDI_MTXORB_3_PID 0xFA03 /* Matrix Orbital Product Id */
121#define FTDI_MTXORB_4_PID 0xFA04 /* Matrix Orbital Product Id */
122#define FTDI_MTXORB_5_PID 0xFA05 /* Matrix Orbital Product Id */
123#define FTDI_MTXORB_6_PID 0xFA06 /* Matrix Orbital Product Id */
124
125/* OOCDlink by Joern Kaipf <joernk@web.de>
126 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */
127#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */
128
129/*
130 * The following are the values for the Matrix Orbital FTDI Range
131 * Anything in this range will use an FT232RL.
132 */
133#define MTXORB_VID 0x1B3D
134#define MTXORB_FTDI_RANGE_0100_PID 0x0100
135#define MTXORB_FTDI_RANGE_0101_PID 0x0101
136#define MTXORB_FTDI_RANGE_0102_PID 0x0102
137#define MTXORB_FTDI_RANGE_0103_PID 0x0103
138#define MTXORB_FTDI_RANGE_0104_PID 0x0104
139#define MTXORB_FTDI_RANGE_0105_PID 0x0105
140#define MTXORB_FTDI_RANGE_0106_PID 0x0106
141#define MTXORB_FTDI_RANGE_0107_PID 0x0107
142#define MTXORB_FTDI_RANGE_0108_PID 0x0108
143#define MTXORB_FTDI_RANGE_0109_PID 0x0109
144#define MTXORB_FTDI_RANGE_010A_PID 0x010A
145#define MTXORB_FTDI_RANGE_010B_PID 0x010B
146#define MTXORB_FTDI_RANGE_010C_PID 0x010C
147#define MTXORB_FTDI_RANGE_010D_PID 0x010D
148#define MTXORB_FTDI_RANGE_010E_PID 0x010E
149#define MTXORB_FTDI_RANGE_010F_PID 0x010F
150#define MTXORB_FTDI_RANGE_0110_PID 0x0110
151#define MTXORB_FTDI_RANGE_0111_PID 0x0111
152#define MTXORB_FTDI_RANGE_0112_PID 0x0112
153#define MTXORB_FTDI_RANGE_0113_PID 0x0113
154#define MTXORB_FTDI_RANGE_0114_PID 0x0114
155#define MTXORB_FTDI_RANGE_0115_PID 0x0115
156#define MTXORB_FTDI_RANGE_0116_PID 0x0116
157#define MTXORB_FTDI_RANGE_0117_PID 0x0117
158#define MTXORB_FTDI_RANGE_0118_PID 0x0118
159#define MTXORB_FTDI_RANGE_0119_PID 0x0119
160#define MTXORB_FTDI_RANGE_011A_PID 0x011A
161#define MTXORB_FTDI_RANGE_011B_PID 0x011B
162#define MTXORB_FTDI_RANGE_011C_PID 0x011C
163#define MTXORB_FTDI_RANGE_011D_PID 0x011D
164#define MTXORB_FTDI_RANGE_011E_PID 0x011E
165#define MTXORB_FTDI_RANGE_011F_PID 0x011F
166#define MTXORB_FTDI_RANGE_0120_PID 0x0120
167#define MTXORB_FTDI_RANGE_0121_PID 0x0121
168#define MTXORB_FTDI_RANGE_0122_PID 0x0122
169#define MTXORB_FTDI_RANGE_0123_PID 0x0123
170#define MTXORB_FTDI_RANGE_0124_PID 0x0124
171#define MTXORB_FTDI_RANGE_0125_PID 0x0125
172#define MTXORB_FTDI_RANGE_0126_PID 0x0126
173#define MTXORB_FTDI_RANGE_0127_PID 0x0127
174#define MTXORB_FTDI_RANGE_0128_PID 0x0128
175#define MTXORB_FTDI_RANGE_0129_PID 0x0129
176#define MTXORB_FTDI_RANGE_012A_PID 0x012A
177#define MTXORB_FTDI_RANGE_012B_PID 0x012B
178#define MTXORB_FTDI_RANGE_012C_PID 0x012C
179#define MTXORB_FTDI_RANGE_012D_PID 0x012D
180#define MTXORB_FTDI_RANGE_012E_PID 0x012E
181#define MTXORB_FTDI_RANGE_012F_PID 0x012F
182#define MTXORB_FTDI_RANGE_0130_PID 0x0130
183#define MTXORB_FTDI_RANGE_0131_PID 0x0131
184#define MTXORB_FTDI_RANGE_0132_PID 0x0132
185#define MTXORB_FTDI_RANGE_0133_PID 0x0133
186#define MTXORB_FTDI_RANGE_0134_PID 0x0134
187#define MTXORB_FTDI_RANGE_0135_PID 0x0135
188#define MTXORB_FTDI_RANGE_0136_PID 0x0136
189#define MTXORB_FTDI_RANGE_0137_PID 0x0137
190#define MTXORB_FTDI_RANGE_0138_PID 0x0138
191#define MTXORB_FTDI_RANGE_0139_PID 0x0139
192#define MTXORB_FTDI_RANGE_013A_PID 0x013A
193#define MTXORB_FTDI_RANGE_013B_PID 0x013B
194#define MTXORB_FTDI_RANGE_013C_PID 0x013C
195#define MTXORB_FTDI_RANGE_013D_PID 0x013D
196#define MTXORB_FTDI_RANGE_013E_PID 0x013E
197#define MTXORB_FTDI_RANGE_013F_PID 0x013F
198#define MTXORB_FTDI_RANGE_0140_PID 0x0140
199#define MTXORB_FTDI_RANGE_0141_PID 0x0141
200#define MTXORB_FTDI_RANGE_0142_PID 0x0142
201#define MTXORB_FTDI_RANGE_0143_PID 0x0143
202#define MTXORB_FTDI_RANGE_0144_PID 0x0144
203#define MTXORB_FTDI_RANGE_0145_PID 0x0145
204#define MTXORB_FTDI_RANGE_0146_PID 0x0146
205#define MTXORB_FTDI_RANGE_0147_PID 0x0147
206#define MTXORB_FTDI_RANGE_0148_PID 0x0148
207#define MTXORB_FTDI_RANGE_0149_PID 0x0149
208#define MTXORB_FTDI_RANGE_014A_PID 0x014A
209#define MTXORB_FTDI_RANGE_014B_PID 0x014B
210#define MTXORB_FTDI_RANGE_014C_PID 0x014C
211#define MTXORB_FTDI_RANGE_014D_PID 0x014D
212#define MTXORB_FTDI_RANGE_014E_PID 0x014E
213#define MTXORB_FTDI_RANGE_014F_PID 0x014F
214#define MTXORB_FTDI_RANGE_0150_PID 0x0150
215#define MTXORB_FTDI_RANGE_0151_PID 0x0151
216#define MTXORB_FTDI_RANGE_0152_PID 0x0152
217#define MTXORB_FTDI_RANGE_0153_PID 0x0153
218#define MTXORB_FTDI_RANGE_0154_PID 0x0154
219#define MTXORB_FTDI_RANGE_0155_PID 0x0155
220#define MTXORB_FTDI_RANGE_0156_PID 0x0156
221#define MTXORB_FTDI_RANGE_0157_PID 0x0157
222#define MTXORB_FTDI_RANGE_0158_PID 0x0158
223#define MTXORB_FTDI_RANGE_0159_PID 0x0159
224#define MTXORB_FTDI_RANGE_015A_PID 0x015A
225#define MTXORB_FTDI_RANGE_015B_PID 0x015B
226#define MTXORB_FTDI_RANGE_015C_PID 0x015C
227#define MTXORB_FTDI_RANGE_015D_PID 0x015D
228#define MTXORB_FTDI_RANGE_015E_PID 0x015E
229#define MTXORB_FTDI_RANGE_015F_PID 0x015F
230#define MTXORB_FTDI_RANGE_0160_PID 0x0160
231#define MTXORB_FTDI_RANGE_0161_PID 0x0161
232#define MTXORB_FTDI_RANGE_0162_PID 0x0162
233#define MTXORB_FTDI_RANGE_0163_PID 0x0163
234#define MTXORB_FTDI_RANGE_0164_PID 0x0164
235#define MTXORB_FTDI_RANGE_0165_PID 0x0165
236#define MTXORB_FTDI_RANGE_0166_PID 0x0166
237#define MTXORB_FTDI_RANGE_0167_PID 0x0167
238#define MTXORB_FTDI_RANGE_0168_PID 0x0168
239#define MTXORB_FTDI_RANGE_0169_PID 0x0169
240#define MTXORB_FTDI_RANGE_016A_PID 0x016A
241#define MTXORB_FTDI_RANGE_016B_PID 0x016B
242#define MTXORB_FTDI_RANGE_016C_PID 0x016C
243#define MTXORB_FTDI_RANGE_016D_PID 0x016D
244#define MTXORB_FTDI_RANGE_016E_PID 0x016E
245#define MTXORB_FTDI_RANGE_016F_PID 0x016F
246#define MTXORB_FTDI_RANGE_0170_PID 0x0170
247#define MTXORB_FTDI_RANGE_0171_PID 0x0171
248#define MTXORB_FTDI_RANGE_0172_PID 0x0172
249#define MTXORB_FTDI_RANGE_0173_PID 0x0173
250#define MTXORB_FTDI_RANGE_0174_PID 0x0174
251#define MTXORB_FTDI_RANGE_0175_PID 0x0175
252#define MTXORB_FTDI_RANGE_0176_PID 0x0176
253#define MTXORB_FTDI_RANGE_0177_PID 0x0177
254#define MTXORB_FTDI_RANGE_0178_PID 0x0178
255#define MTXORB_FTDI_RANGE_0179_PID 0x0179
256#define MTXORB_FTDI_RANGE_017A_PID 0x017A
257#define MTXORB_FTDI_RANGE_017B_PID 0x017B
258#define MTXORB_FTDI_RANGE_017C_PID 0x017C
259#define MTXORB_FTDI_RANGE_017D_PID 0x017D
260#define MTXORB_FTDI_RANGE_017E_PID 0x017E
261#define MTXORB_FTDI_RANGE_017F_PID 0x017F
262#define MTXORB_FTDI_RANGE_0180_PID 0x0180
263#define MTXORB_FTDI_RANGE_0181_PID 0x0181
264#define MTXORB_FTDI_RANGE_0182_PID 0x0182
265#define MTXORB_FTDI_RANGE_0183_PID 0x0183
266#define MTXORB_FTDI_RANGE_0184_PID 0x0184
267#define MTXORB_FTDI_RANGE_0185_PID 0x0185
268#define MTXORB_FTDI_RANGE_0186_PID 0x0186
269#define MTXORB_FTDI_RANGE_0187_PID 0x0187
270#define MTXORB_FTDI_RANGE_0188_PID 0x0188
271#define MTXORB_FTDI_RANGE_0189_PID 0x0189
272#define MTXORB_FTDI_RANGE_018A_PID 0x018A
273#define MTXORB_FTDI_RANGE_018B_PID 0x018B
274#define MTXORB_FTDI_RANGE_018C_PID 0x018C
275#define MTXORB_FTDI_RANGE_018D_PID 0x018D
276#define MTXORB_FTDI_RANGE_018E_PID 0x018E
277#define MTXORB_FTDI_RANGE_018F_PID 0x018F
278#define MTXORB_FTDI_RANGE_0190_PID 0x0190
279#define MTXORB_FTDI_RANGE_0191_PID 0x0191
280#define MTXORB_FTDI_RANGE_0192_PID 0x0192
281#define MTXORB_FTDI_RANGE_0193_PID 0x0193
282#define MTXORB_FTDI_RANGE_0194_PID 0x0194
283#define MTXORB_FTDI_RANGE_0195_PID 0x0195
284#define MTXORB_FTDI_RANGE_0196_PID 0x0196
285#define MTXORB_FTDI_RANGE_0197_PID 0x0197
286#define MTXORB_FTDI_RANGE_0198_PID 0x0198
287#define MTXORB_FTDI_RANGE_0199_PID 0x0199
288#define MTXORB_FTDI_RANGE_019A_PID 0x019A
289#define MTXORB_FTDI_RANGE_019B_PID 0x019B
290#define MTXORB_FTDI_RANGE_019C_PID 0x019C
291#define MTXORB_FTDI_RANGE_019D_PID 0x019D
292#define MTXORB_FTDI_RANGE_019E_PID 0x019E
293#define MTXORB_FTDI_RANGE_019F_PID 0x019F
294#define MTXORB_FTDI_RANGE_01A0_PID 0x01A0
295#define MTXORB_FTDI_RANGE_01A1_PID 0x01A1
296#define MTXORB_FTDI_RANGE_01A2_PID 0x01A2
297#define MTXORB_FTDI_RANGE_01A3_PID 0x01A3
298#define MTXORB_FTDI_RANGE_01A4_PID 0x01A4
299#define MTXORB_FTDI_RANGE_01A5_PID 0x01A5
300#define MTXORB_FTDI_RANGE_01A6_PID 0x01A6
301#define MTXORB_FTDI_RANGE_01A7_PID 0x01A7
302#define MTXORB_FTDI_RANGE_01A8_PID 0x01A8
303#define MTXORB_FTDI_RANGE_01A9_PID 0x01A9
304#define MTXORB_FTDI_RANGE_01AA_PID 0x01AA
305#define MTXORB_FTDI_RANGE_01AB_PID 0x01AB
306#define MTXORB_FTDI_RANGE_01AC_PID 0x01AC
307#define MTXORB_FTDI_RANGE_01AD_PID 0x01AD
308#define MTXORB_FTDI_RANGE_01AE_PID 0x01AE
309#define MTXORB_FTDI_RANGE_01AF_PID 0x01AF
310#define MTXORB_FTDI_RANGE_01B0_PID 0x01B0
311#define MTXORB_FTDI_RANGE_01B1_PID 0x01B1
312#define MTXORB_FTDI_RANGE_01B2_PID 0x01B2
313#define MTXORB_FTDI_RANGE_01B3_PID 0x01B3
314#define MTXORB_FTDI_RANGE_01B4_PID 0x01B4
315#define MTXORB_FTDI_RANGE_01B5_PID 0x01B5
316#define MTXORB_FTDI_RANGE_01B6_PID 0x01B6
317#define MTXORB_FTDI_RANGE_01B7_PID 0x01B7
318#define MTXORB_FTDI_RANGE_01B8_PID 0x01B8
319#define MTXORB_FTDI_RANGE_01B9_PID 0x01B9
320#define MTXORB_FTDI_RANGE_01BA_PID 0x01BA
321#define MTXORB_FTDI_RANGE_01BB_PID 0x01BB
322#define MTXORB_FTDI_RANGE_01BC_PID 0x01BC
323#define MTXORB_FTDI_RANGE_01BD_PID 0x01BD
324#define MTXORB_FTDI_RANGE_01BE_PID 0x01BE
325#define MTXORB_FTDI_RANGE_01BF_PID 0x01BF
326#define MTXORB_FTDI_RANGE_01C0_PID 0x01C0
327#define MTXORB_FTDI_RANGE_01C1_PID 0x01C1
328#define MTXORB_FTDI_RANGE_01C2_PID 0x01C2
329#define MTXORB_FTDI_RANGE_01C3_PID 0x01C3
330#define MTXORB_FTDI_RANGE_01C4_PID 0x01C4
331#define MTXORB_FTDI_RANGE_01C5_PID 0x01C5
332#define MTXORB_FTDI_RANGE_01C6_PID 0x01C6
333#define MTXORB_FTDI_RANGE_01C7_PID 0x01C7
334#define MTXORB_FTDI_RANGE_01C8_PID 0x01C8
335#define MTXORB_FTDI_RANGE_01C9_PID 0x01C9
336#define MTXORB_FTDI_RANGE_01CA_PID 0x01CA
337#define MTXORB_FTDI_RANGE_01CB_PID 0x01CB
338#define MTXORB_FTDI_RANGE_01CC_PID 0x01CC
339#define MTXORB_FTDI_RANGE_01CD_PID 0x01CD
340#define MTXORB_FTDI_RANGE_01CE_PID 0x01CE
341#define MTXORB_FTDI_RANGE_01CF_PID 0x01CF
342#define MTXORB_FTDI_RANGE_01D0_PID 0x01D0
343#define MTXORB_FTDI_RANGE_01D1_PID 0x01D1
344#define MTXORB_FTDI_RANGE_01D2_PID 0x01D2
345#define MTXORB_FTDI_RANGE_01D3_PID 0x01D3
346#define MTXORB_FTDI_RANGE_01D4_PID 0x01D4
347#define MTXORB_FTDI_RANGE_01D5_PID 0x01D5
348#define MTXORB_FTDI_RANGE_01D6_PID 0x01D6
349#define MTXORB_FTDI_RANGE_01D7_PID 0x01D7
350#define MTXORB_FTDI_RANGE_01D8_PID 0x01D8
351#define MTXORB_FTDI_RANGE_01D9_PID 0x01D9
352#define MTXORB_FTDI_RANGE_01DA_PID 0x01DA
353#define MTXORB_FTDI_RANGE_01DB_PID 0x01DB
354#define MTXORB_FTDI_RANGE_01DC_PID 0x01DC
355#define MTXORB_FTDI_RANGE_01DD_PID 0x01DD
356#define MTXORB_FTDI_RANGE_01DE_PID 0x01DE
357#define MTXORB_FTDI_RANGE_01DF_PID 0x01DF
358#define MTXORB_FTDI_RANGE_01E0_PID 0x01E0
359#define MTXORB_FTDI_RANGE_01E1_PID 0x01E1
360#define MTXORB_FTDI_RANGE_01E2_PID 0x01E2
361#define MTXORB_FTDI_RANGE_01E3_PID 0x01E3
362#define MTXORB_FTDI_RANGE_01E4_PID 0x01E4
363#define MTXORB_FTDI_RANGE_01E5_PID 0x01E5
364#define MTXORB_FTDI_RANGE_01E6_PID 0x01E6
365#define MTXORB_FTDI_RANGE_01E7_PID 0x01E7
366#define MTXORB_FTDI_RANGE_01E8_PID 0x01E8
367#define MTXORB_FTDI_RANGE_01E9_PID 0x01E9
368#define MTXORB_FTDI_RANGE_01EA_PID 0x01EA
369#define MTXORB_FTDI_RANGE_01EB_PID 0x01EB
370#define MTXORB_FTDI_RANGE_01EC_PID 0x01EC
371#define MTXORB_FTDI_RANGE_01ED_PID 0x01ED
372#define MTXORB_FTDI_RANGE_01EE_PID 0x01EE
373#define MTXORB_FTDI_RANGE_01EF_PID 0x01EF
374#define MTXORB_FTDI_RANGE_01F0_PID 0x01F0
375#define MTXORB_FTDI_RANGE_01F1_PID 0x01F1
376#define MTXORB_FTDI_RANGE_01F2_PID 0x01F2
377#define MTXORB_FTDI_RANGE_01F3_PID 0x01F3
378#define MTXORB_FTDI_RANGE_01F4_PID 0x01F4
379#define MTXORB_FTDI_RANGE_01F5_PID 0x01F5
380#define MTXORB_FTDI_RANGE_01F6_PID 0x01F6
381#define MTXORB_FTDI_RANGE_01F7_PID 0x01F7
382#define MTXORB_FTDI_RANGE_01F8_PID 0x01F8
383#define MTXORB_FTDI_RANGE_01F9_PID 0x01F9
384#define MTXORB_FTDI_RANGE_01FA_PID 0x01FA
385#define MTXORB_FTDI_RANGE_01FB_PID 0x01FB
386#define MTXORB_FTDI_RANGE_01FC_PID 0x01FC
387#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD
388#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE
389#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF
390
391
392
393/* Interbiometrics USB I/O Board */
394/* Developed for Interbiometrics by Rudolf Gugler */
395#define INTERBIOMETRICS_VID 0x1209
396#define INTERBIOMETRICS_IOBOARD_PID 0x1002
397#define INTERBIOMETRICS_MINI_IOBOARD_PID 0x1006
398
399/*
400 * The following are the values for the Perle Systems
401 * UltraPort USB serial converters
402 */
403#define FTDI_PERLE_ULTRAPORT_PID 0xF0C0 /* Perle UltraPort Product Id */
404
405/*
406 * The following are the values for the Sealevel SeaLINK+ adapters.
407 * (Original list sent by Tuan Hoang. Ian Abbott renamed the macros and
408 * removed some PIDs that don't seem to match any existing products.)
409 */
410#define SEALEVEL_VID 0x0c52 /* Sealevel Vendor ID */
411#define SEALEVEL_2101_PID 0x2101 /* SeaLINK+232 (2101/2105) */
412#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */
413#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */
414#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */
415#define SEALEVEL_2106_PID 0x9020 /* SeaLINK+422 (2106) */
416#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */
417#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */
418#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */
419#define SEALEVEL_2202_2_PID 0x2222 /* SeaPORT+2/485 (2202) Port 2 */
420#define SEALEVEL_2203_1_PID 0x2213 /* SeaPORT+2 (2203) Port 1 */
421#define SEALEVEL_2203_2_PID 0x2223 /* SeaPORT+2 (2203) Port 2 */
422#define SEALEVEL_2401_1_PID 0x2411 /* SeaPORT+4/232 (2401) Port 1 */
423#define SEALEVEL_2401_2_PID 0x2421 /* SeaPORT+4/232 (2401) Port 2 */
424#define SEALEVEL_2401_3_PID 0x2431 /* SeaPORT+4/232 (2401) Port 3 */
425#define SEALEVEL_2401_4_PID 0x2441 /* SeaPORT+4/232 (2401) Port 4 */
426#define SEALEVEL_2402_1_PID 0x2412 /* SeaPORT+4/485 (2402) Port 1 */
427#define SEALEVEL_2402_2_PID 0x2422 /* SeaPORT+4/485 (2402) Port 2 */
428#define SEALEVEL_2402_3_PID 0x2432 /* SeaPORT+4/485 (2402) Port 3 */
429#define SEALEVEL_2402_4_PID 0x2442 /* SeaPORT+4/485 (2402) Port 4 */
430#define SEALEVEL_2403_1_PID 0x2413 /* SeaPORT+4 (2403) Port 1 */
431#define SEALEVEL_2403_2_PID 0x2423 /* SeaPORT+4 (2403) Port 2 */
432#define SEALEVEL_2403_3_PID 0x2433 /* SeaPORT+4 (2403) Port 3 */
433#define SEALEVEL_2403_4_PID 0x2443 /* SeaPORT+4 (2403) Port 4 */
434#define SEALEVEL_2801_1_PID 0X2811 /* SeaLINK+8/232 (2801) Port 1 */
435#define SEALEVEL_2801_2_PID 0X2821 /* SeaLINK+8/232 (2801) Port 2 */
436#define SEALEVEL_2801_3_PID 0X2831 /* SeaLINK+8/232 (2801) Port 3 */
437#define SEALEVEL_2801_4_PID 0X2841 /* SeaLINK+8/232 (2801) Port 4 */
438#define SEALEVEL_2801_5_PID 0X2851 /* SeaLINK+8/232 (2801) Port 5 */
439#define SEALEVEL_2801_6_PID 0X2861 /* SeaLINK+8/232 (2801) Port 6 */
440#define SEALEVEL_2801_7_PID 0X2871 /* SeaLINK+8/232 (2801) Port 7 */
441#define SEALEVEL_2801_8_PID 0X2881 /* SeaLINK+8/232 (2801) Port 8 */
442#define SEALEVEL_2802_1_PID 0X2812 /* SeaLINK+8/485 (2802) Port 1 */
443#define SEALEVEL_2802_2_PID 0X2822 /* SeaLINK+8/485 (2802) Port 2 */
444#define SEALEVEL_2802_3_PID 0X2832 /* SeaLINK+8/485 (2802) Port 3 */
445#define SEALEVEL_2802_4_PID 0X2842 /* SeaLINK+8/485 (2802) Port 4 */
446#define SEALEVEL_2802_5_PID 0X2852 /* SeaLINK+8/485 (2802) Port 5 */
447#define SEALEVEL_2802_6_PID 0X2862 /* SeaLINK+8/485 (2802) Port 6 */
448#define SEALEVEL_2802_7_PID 0X2872 /* SeaLINK+8/485 (2802) Port 7 */
449#define SEALEVEL_2802_8_PID 0X2882 /* SeaLINK+8/485 (2802) Port 8 */
450#define SEALEVEL_2803_1_PID 0X2813 /* SeaLINK+8 (2803) Port 1 */
451#define SEALEVEL_2803_2_PID 0X2823 /* SeaLINK+8 (2803) Port 2 */
452#define SEALEVEL_2803_3_PID 0X2833 /* SeaLINK+8 (2803) Port 3 */
453#define SEALEVEL_2803_4_PID 0X2843 /* SeaLINK+8 (2803) Port 4 */
454#define SEALEVEL_2803_5_PID 0X2853 /* SeaLINK+8 (2803) Port 5 */
455#define SEALEVEL_2803_6_PID 0X2863 /* SeaLINK+8 (2803) Port 6 */
456#define SEALEVEL_2803_7_PID 0X2873 /* SeaLINK+8 (2803) Port 7 */
457#define SEALEVEL_2803_8_PID 0X2883 /* SeaLINK+8 (2803) Port 8 */
458
459/*
460 * The following are the values for two KOBIL chipcard terminals.
461 */
462#define KOBIL_VID 0x0d46 /* KOBIL Vendor ID */
463#define KOBIL_CONV_B1_PID 0x2020 /* KOBIL Konverter for B1 */
464#define KOBIL_CONV_KAAN_PID 0x2021 /* KOBIL_Konverter for KAAN */
465
466/*
467 * Icom ID-1 digital transceiver
468 */
469
470#define ICOM_ID1_VID 0x0C26
471#define ICOM_ID1_PID 0x0004
472
473/*
474 * ASK.fr devices
475 */
476#define FTDI_ASK_RDR400_PID 0xC991 /* ASK RDR 400 series card reader */
477
478/*
479 * FTDI USB UART chips used in construction projects from the
480 * Elektor Electronics magazine (http://elektor-electronics.co.uk)
481 */
482#define ELEKTOR_VID 0x0C7D
483#define ELEKTOR_FT323R_PID 0x0005 /* RFID-Reader, issue 09-2006 */
484
485/*
486 * DSS-20 Sync Station for Sony Ericsson P800
487 */
488#define FTDI_DSS20_PID 0xFC82
489
490/*
491 * Home Electronics (www.home-electro.com) USB gadgets
492 */
493#define FTDI_HE_TIRA1_PID 0xFA78 /* Tira-1 IR transceiver */
494
495/* USB-UIRT - An infrared receiver and transmitter using the 8U232AM chip */
496/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */
497#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */
498
499/* TNC-X USB-to-packet-radio adapter, versions prior to 3.0 (DLP module) */
500
501#define FTDI_TNC_X_PID 0xEBE0
502
503/*
504 * ELV USB devices submitted by Christian Abt of ELV (www.elv.de).
505 * All of these devices use FTDI's vendor ID (0x0403).
506 *
507 * The previously included PID for the UO 100 module was incorrect.
508 * In fact, that PID was for ELV's UR 100 USB-RS232 converter (0xFB58).
509 *
510 * Armin Laeuger originally sent the PID for the UM 100 module.
511 */
512#define FTDI_R2000KU_TRUE_RNG 0xFB80 /* R2000KU TRUE RNG */
513#define FTDI_ELV_UR100_PID 0xFB58 /* USB-RS232-Umsetzer (UR 100) */
514#define FTDI_ELV_UM100_PID 0xFB5A /* USB-Modul UM 100 */
515#define FTDI_ELV_UO100_PID 0xFB5B /* USB-Modul UO 100 */
516#define FTDI_ELV_ALC8500_PID 0xF06E /* ALC 8500 Expert */
517/* Additional ELV PIDs that default to using the FTDI D2XX drivers on
518 * MS Windows, rather than the FTDI Virtual Com Port drivers.
519 * Maybe these will be easier to use with the libftdi/libusb user-space
520 * drivers, or possibly the Comedi drivers in some cases. */
521#define FTDI_ELV_CLI7000_PID 0xFB59 /* Computer-Light-Interface (CLI 7000) */
522#define FTDI_ELV_PPS7330_PID 0xFB5C /* Processor-Power-Supply (PPS 7330) */
523#define FTDI_ELV_TFM100_PID 0xFB5D /* Temperartur-Feuchte Messgeraet (TFM 100) */
524#define FTDI_ELV_UDF77_PID 0xFB5E /* USB DCF Funkurh (UDF 77) */
525#define FTDI_ELV_UIO88_PID 0xFB5F /* USB-I/O Interface (UIO 88) */
526#define FTDI_ELV_UAD8_PID 0xF068 /* USB-AD-Wandler (UAD 8) */
527#define FTDI_ELV_UDA7_PID 0xF069 /* USB-DA-Wandler (UDA 7) */
528#define FTDI_ELV_USI2_PID 0xF06A /* USB-Schrittmotoren-Interface (USI 2) */
529#define FTDI_ELV_T1100_PID 0xF06B /* Thermometer (T 1100) */
530#define FTDI_ELV_PCD200_PID 0xF06C /* PC-Datenlogger (PCD 200) */
531#define FTDI_ELV_ULA200_PID 0xF06D /* USB-LCD-Ansteuerung (ULA 200) */
532#define FTDI_ELV_FHZ1000PC_PID 0xF06F /* FHZ 1000 PC */
533#define FTDI_ELV_CSI8_PID 0xE0F0 /* Computer-Schalt-Interface (CSI 8) */
534#define FTDI_ELV_EM1000DL_PID 0xE0F1 /* PC-Datenlogger fuer Energiemonitor (EM 1000 DL) */
535#define FTDI_ELV_PCK100_PID 0xE0F2 /* PC-Kabeltester (PCK 100) */
536#define FTDI_ELV_RFP500_PID 0xE0F3 /* HF-Leistungsmesser (RFP 500) */
537#define FTDI_ELV_FS20SIG_PID 0xE0F4 /* Signalgeber (FS 20 SIG) */
538#define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */
539#define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */
540#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */
541#define FTDI_ELV_HS485_PID 0xE0EA /* USB to RS-485 adapter */
542#define FTDI_ELV_EM1010PC_PID 0xE0EF /* Engery monitor EM 1010 PC */
543#define FTDI_PHI_FISCO_PID 0xE40B /* PHI Fisco USB to Serial cable */
544
545/*
546 * Definitions for ID TECH (www.idt-net.com) devices
547 */
548#define IDTECH_VID 0x0ACD /* ID TECH Vendor ID */
549#define IDTECH_IDT1221U_PID 0x0300 /* IDT1221U USB to RS-232 adapter */
550
551/*
552 * Definitions for Omnidirectional Control Technology, Inc. devices
553 */
554#define OCT_VID 0x0B39 /* OCT vendor ID */
555/* Note: OCT US101 is also rebadged as Dick Smith Electronics (NZ) XH6381 */
556/* Also rebadged as Dick Smith Electronics (Aus) XH6451 */
557/* Also rebadged as SIIG Inc. model US2308 hardware version 1 */
558#define OCT_US101_PID 0x0421 /* OCT US101 USB to RS-232 */
559
560/* an infrared receiver for user access control with IR tags */
561#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */
562
563/*
564 * Definitions for Artemis astronomical USB based cameras
565 * Check it at http://www.artemisccd.co.uk/
566 */
567#define FTDI_ARTEMIS_PID 0xDF28 /* All Artemis Cameras */
568
569/*
570 * Definitions for ATIK Instruments astronomical USB based cameras
571 * Check it at http://www.atik-instruments.com/
572 */
573#define FTDI_ATIK_ATK16_PID 0xDF30 /* ATIK ATK-16 Grayscale Camera */
574#define FTDI_ATIK_ATK16C_PID 0xDF32 /* ATIK ATK-16C Colour Camera */
575#define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Grayscale Camera */
576#define FTDI_ATIK_ATK16HRC_PID 0xDF33 /* ATIK ATK-16HRC Colour Camera */
577#define FTDI_ATIK_ATK16IC_PID 0xDF35 /* ATIK ATK-16IC Grayscale Camera */
578
579/*
580 * Protego product ids
581 */
582#define PROTEGO_SPECIAL_1 0xFC70 /* special/unknown device */
583#define PROTEGO_R2X0 0xFC71 /* R200-USB TRNG unit (R210, R220, and R230) */
584#define PROTEGO_SPECIAL_3 0xFC72 /* special/unknown device */
585#define PROTEGO_SPECIAL_4 0xFC73 /* special/unknown device */
586
587/*
588 * Gude Analog- und Digitalsysteme GmbH
589 */
590#define FTDI_GUDEADS_E808_PID 0xE808
591#define FTDI_GUDEADS_E809_PID 0xE809
592#define FTDI_GUDEADS_E80A_PID 0xE80A
593#define FTDI_GUDEADS_E80B_PID 0xE80B
594#define FTDI_GUDEADS_E80C_PID 0xE80C
595#define FTDI_GUDEADS_E80D_PID 0xE80D
596#define FTDI_GUDEADS_E80E_PID 0xE80E
597#define FTDI_GUDEADS_E80F_PID 0xE80F
598#define FTDI_GUDEADS_E888_PID 0xE888 /* Expert ISDN Control USB */
599#define FTDI_GUDEADS_E889_PID 0xE889 /* USB RS-232 OptoBridge */
600#define FTDI_GUDEADS_E88A_PID 0xE88A
601#define FTDI_GUDEADS_E88B_PID 0xE88B
602#define FTDI_GUDEADS_E88C_PID 0xE88C
603#define FTDI_GUDEADS_E88D_PID 0xE88D
604#define FTDI_GUDEADS_E88E_PID 0xE88E
605#define FTDI_GUDEADS_E88F_PID 0xE88F
606
607/*
608 * Linx Technologies product ids
609 */
610#define LINX_SDMUSBQSS_PID 0xF448 /* Linx SDM-USB-QS-S */
611#define LINX_MASTERDEVEL2_PID 0xF449 /* Linx Master Development 2.0 */
612#define LINX_FUTURE_0_PID 0xF44A /* Linx future device */
613#define LINX_FUTURE_1_PID 0xF44B /* Linx future device */
614#define LINX_FUTURE_2_PID 0xF44C /* Linx future device */
615
616/* CCS Inc. ICDU/ICDU40 product ID - the FT232BM is used in an in-circuit-debugger */
617/* unit for PIC16's/PIC18's */
618#define FTDI_CCSICDU20_0_PID 0xF9D0
619#define FTDI_CCSICDU40_1_PID 0xF9D1
620#define FTDI_CCSMACHX_2_PID 0xF9D2
621#define FTDI_CCSLOAD_N_GO_3_PID 0xF9D3
622#define FTDI_CCSICDU64_4_PID 0xF9D4
623#define FTDI_CCSPRIME8_5_PID 0xF9D5
624
625/* Inside Accesso contactless reader (http://www.insidefr.com) */
626#define INSIDE_ACCESSO 0xFAD0
627
628/*
629 * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI
630 */
631#define INTREPID_VID 0x093C
632#define INTREPID_VALUECAN_PID 0x0601
633#define INTREPID_NEOVI_PID 0x0701
634
635/*
636 * Falcom Wireless Communications GmbH
637 */
638#define FALCOM_VID 0x0F94 /* Vendor Id */
639#define FALCOM_TWIST_PID 0x0001 /* Falcom Twist USB GPRS modem */
640#define FALCOM_SAMBA_PID 0x0005 /* Falcom Samba USB GPRS modem */
641
642/*
643 * SUUNTO product ids
644 */
645#define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */
646
647/*
648 * Oceanic product ids
649 */
650#define FTDI_OCEANIC_PID 0xF460 /* Oceanic dive instrument */
651
652/*
653 * TTi (Thurlby Thandar Instruments)
654 */
655#define TTI_VID 0x103E /* Vendor Id */
656#define TTI_QL355P_PID 0x03E8 /* TTi QL355P power supply */
657
658/*
659 * Definitions for B&B Electronics products.
660 */
661#define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */
662#define BANDB_USOTL4_PID 0xAC01 /* USOTL4 Isolated RS-485 Converter */
663#define BANDB_USTL4_PID 0xAC02 /* USTL4 RS-485 Converter */
664#define BANDB_USO9ML2_PID 0xAC03 /* USO9ML2 Isolated RS-232 Converter */
665
666/*
667 * RM Michaelides CANview USB (http://www.rmcan.com)
668 * CAN fieldbus interface adapter, added by port GmbH www.port.de)
669 * Ian Abbott changed the macro names for consistency.
670 */
671#define FTDI_RM_CANVIEW_PID 0xfd60 /* Product Id */
672
673/*
674 * EVER Eco Pro UPS (http://www.ever.com.pl/)
675 */
676
677#define EVER_ECO_PRO_CDS 0xe520 /* RS-232 converter */
678
679/*
680 * 4N-GALAXY.DE PIDs for CAN-USB, USB-RS232, USB-RS422, USB-RS485,
681 * USB-TTY activ, USB-TTY passiv. Some PIDs are used by several devices
682 * and I'm not entirely sure which are used by which.
683 */
684#define FTDI_4N_GALAXY_DE_1_PID 0xF3C0
685#define FTDI_4N_GALAXY_DE_2_PID 0xF3C1
686
687/*
688 * Mobility Electronics products.
689 */
690#define MOBILITY_VID 0x1342
691#define MOBILITY_USB_SERIAL_PID 0x0202 /* EasiDock USB 200 serial */
692
693/*
694 * microHAM product IDs (http://www.microham.com).
695 * Submitted by Justin Burket (KL1RL) <zorton@jtan.com>
696 * and Mike Studer (K6EEP) <k6eep@hamsoftware.org>.
697 * Ian Abbott <abbotti@mev.co.uk> added a few more from the driver INF file.
698 */
699#define FTDI_MHAM_KW_PID 0xEEE8 /* USB-KW interface */
700#define FTDI_MHAM_YS_PID 0xEEE9 /* USB-YS interface */
701#define FTDI_MHAM_Y6_PID 0xEEEA /* USB-Y6 interface */
702#define FTDI_MHAM_Y8_PID 0xEEEB /* USB-Y8 interface */
703#define FTDI_MHAM_IC_PID 0xEEEC /* USB-IC interface */
704#define FTDI_MHAM_DB9_PID 0xEEED /* USB-DB9 interface */
705#define FTDI_MHAM_RS232_PID 0xEEEE /* USB-RS232 interface */
706#define FTDI_MHAM_Y9_PID 0xEEEF /* USB-Y9 interface */
707
708/*
709 * Active Robots product ids.
710 */
711#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */
712
713/*
714 * Xsens Technologies BV products (http://www.xsens.com).
715 */
716#define XSENS_CONVERTER_0_PID 0xD388
717#define XSENS_CONVERTER_1_PID 0xD389
718#define XSENS_CONVERTER_2_PID 0xD38A
719#define XSENS_CONVERTER_3_PID 0xD38B
720#define XSENS_CONVERTER_4_PID 0xD38C
721#define XSENS_CONVERTER_5_PID 0xD38D
722#define XSENS_CONVERTER_6_PID 0xD38E
723#define XSENS_CONVERTER_7_PID 0xD38F
724
725/*
726 * Teratronik product ids.
727 * Submitted by O. Wölfelschneider.
728 */
729#define FTDI_TERATRONIK_VCP_PID 0xEC88 /* Teratronik device (preferring VCP driver on windows) */
730#define FTDI_TERATRONIK_D2XX_PID 0xEC89 /* Teratronik device (preferring D2XX driver on windows) */
731
732/*
733 * Evolution Robotics products (http://www.evolution.com/).
734 * Submitted by Shawn M. Lavelle.
735 */
736#define EVOLUTION_VID 0xDEEE /* Vendor ID */
737#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */
738#define EVO_8U232AM_PID 0x02FF /* Evolution robotics RCM2 (FT232AM)*/
739#define EVO_HYBRID_PID 0x0302 /* Evolution robotics RCM4 PID (FT232BM)*/
740#define EVO_RCM4_PID 0x0303 /* Evolution robotics RCM4 PID */
741
742/* Pyramid Computer GmbH */
743#define FTDI_PYRAMID_PID 0xE6C8 /* Pyramid Appliance Display */
744
745/*
746 * NDI (www.ndigital.com) product ids
747 */
748#define FTDI_NDI_HUC_PID 0xDA70 /* NDI Host USB Converter */
749#define FTDI_NDI_SPECTRA_SCU_PID 0xDA71 /* NDI Spectra SCU */
750#define FTDI_NDI_FUTURE_2_PID 0xDA72 /* NDI future device #2 */
751#define FTDI_NDI_FUTURE_3_PID 0xDA73 /* NDI future device #3 */
752#define FTDI_NDI_AURORA_SCU_PID 0xDA74 /* NDI Aurora SCU */
753
754/*
755 * Posiflex inc retail equipment (http://www.posiflex.com.tw)
756 */
757#define POSIFLEX_VID 0x0d3a /* Vendor ID */
758#define POSIFLEX_PP7000_PID 0x0300 /* PP-7000II thermal printer */
759
760/*
761 * Westrex International devices submitted by Cory Lee
762 */
763#define FTDI_WESTREX_MODEL_777_PID 0xDC00 /* Model 777 */
764#define FTDI_WESTREX_MODEL_8900F_PID 0xDC01 /* Model 8900F */
765
766/*
767 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com)
768 */
769#define FTDI_RRCIRKITS_LOCOBUFFER_PID 0xc7d0 /* LocoBuffer USB */
770
771/*
772 * Eclo (http://www.eclo.pt/) product IDs.
773 * PID 0xEA90 submitted by Martin Grill.
774 */
775#define FTDI_ECLO_COM_1WIRE_PID 0xEA90 /* COM to 1-Wire USB adaptor */
776
777/*
778 * Papouch products (http://www.papouch.com/)
779 * Submitted by Folkert van Heusden
780 */
781
782#define PAPOUCH_VID 0x5050 /* Vendor ID */
783#define PAPOUCH_TMU_PID 0x0400 /* TMU USB Thermometer */
784#define PAPOUCH_QUIDO4x4_PID 0x0900 /* Quido 4/4 Module */
785
786/*
787 * ACG Identification Technologies GmbH products (http://www.acg.de/).
788 * Submitted by anton -at- goto10 -dot- org.
789 */ 23 */
790#define FTDI_ACG_HFDUAL_PID 0xDD20 /* HF Dual ISO Reader (RFID) */
791
792/*
793 * Yost Engineering, Inc. products (www.yostengineering.com).
794 * PID 0xE050 submitted by Aaron Prose.
795 */
796#define FTDI_YEI_SERVOCENTER31_PID 0xE050 /* YEI ServoCenter3.1 USB */
797
798/*
799 * ThorLabs USB motor drivers
800 */
801#define FTDI_THORLABS_PID 0xfaf0 /* ThorLabs USB motor drivers */
802
803/*
804 * Testo products (http://www.testo.com/)
805 * Submitted by Colin Leroy
806 */
807#define TESTO_VID 0x128D
808#define TESTO_USB_INTERFACE_PID 0x0001
809
810/*
811 * Gamma Scout (http://gamma-scout.com/). Submitted by rsc@runtux.com.
812 */
813#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */
814
815/*
816 * Tactrix OpenPort (ECU) devices.
817 * OpenPort 1.3M submitted by Donour Sizemore.
818 * OpenPort 1.3S and 1.3U submitted by Ian Abbott.
819 */
820#define FTDI_TACTRIX_OPENPORT_13M_PID 0xCC48 /* OpenPort 1.3 Mitsubishi */
821#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */
822#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */
823
824/*
825 * Telldus Technologies
826 */
827#define TELLDUS_VID 0x1781 /* Vendor ID */
828#define TELLDUS_TELLSTICK_PID 0x0C30 /* RF control dongle 433 MHz using FT232RL */
829
830/*
831 * IBS elektronik product ids
832 * Submitted by Thomas Schleusener
833 */
834#define FTDI_IBS_US485_PID 0xff38 /* IBS US485 (USB<-->RS422/485 interface) */
835#define FTDI_IBS_PICPRO_PID 0xff39 /* IBS PIC-Programmer */
836#define FTDI_IBS_PCMCIA_PID 0xff3a /* IBS Card reader for PCMCIA SRAM-cards */
837#define FTDI_IBS_PK1_PID 0xff3b /* IBS PK1 - Particel counter */
838#define FTDI_IBS_RS232MON_PID 0xff3c /* IBS RS232 - Monitor */
839#define FTDI_IBS_APP70_PID 0xff3d /* APP 70 (dust monitoring system) */
840#define FTDI_IBS_PEDO_PID 0xff3e /* IBS PEDO-Modem (RF modem 868.35 MHz) */
841#define FTDI_IBS_PROD_PID 0xff3f /* future device */
842
843/*
844 * MaxStream devices www.maxstream.net
845 */
846#define FTDI_MAXSTREAM_PID 0xEE18 /* Xbee PKG-U Module */
847
848/* Olimex */
849#define OLIMEX_VID 0x15BA
850#define OLIMEX_ARM_USB_OCD_PID 0x0003
851
852/* Luminary Micro Stellaris Boards, VID = FTDI_VID */
853/* FTDI 2332C Dual channel device, side A=245 FIFO (JTAG), Side B=RS232 UART */
854#define LMI_LM3S_DEVEL_BOARD_PID 0xbcd8
855#define LMI_LM3S_EVAL_BOARD_PID 0xbcd9
856
857/* www.elsterelectricity.com Elster Unicom III Optical Probe */
858#define FTDI_ELSTER_UNICOM_PID 0xE700 /* Product Id */
859
860/*
861 * The Mobility Lab (TML)
862 * Submitted by Pierre Castella
863 */
864#define TML_VID 0x1B91 /* Vendor ID */
865#define TML_USB_SERIAL_PID 0x0064 /* USB - Serial Converter */
866
867/* Propox devices */
868#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738
869
870/* Rig Expert Ukraine devices */
871#define FTDI_REU_TINY_PID 0xED22 /* RigExpert Tiny */
872
873/* Domintell products http://www.domintell.com */
874#define FTDI_DOMINTELL_DGQG_PID 0xEF50 /* Master */
875#define FTDI_DOMINTELL_DUSB_PID 0xEF51 /* DUSB01 module */
876
877/* Alti-2 products http://www.alti-2.com */
878#define ALTI2_VID 0x1BC9
879#define ALTI2_N3_PID 0x6001 /* Neptune 3 */
880 24
881/* Commands */ 25/* Commands */
882#define FTDI_SIO_RESET 0 /* Reset the port */ 26#define FTDI_SIO_RESET 0 /* Reset the port */
@@ -884,98 +28,18 @@
884#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */ 28#define FTDI_SIO_SET_FLOW_CTRL 2 /* Set flow control register */
885#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */ 29#define FTDI_SIO_SET_BAUD_RATE 3 /* Set baud rate */
886#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 the port */
887#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modern status register */ 31#define FTDI_SIO_GET_MODEM_STATUS 5 /* Retrieve current value of modem status register */
888#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */ 32#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
889#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */ 33#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
890#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */ 34#define FTDI_SIO_SET_LATENCY_TIMER 9 /* Set the latency timer */
891#define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */ 35#define FTDI_SIO_GET_LATENCY_TIMER 10 /* Get the latency timer */
892 36
893/* Interface indicies for FT2232, FT2232H and FT4232H devices*/ 37/* Interface indices for FT2232, FT2232H and FT4232H devices */
894#define INTERFACE_A 1 38#define INTERFACE_A 1
895#define INTERFACE_B 2 39#define INTERFACE_B 2
896#define INTERFACE_C 3 40#define INTERFACE_C 3
897#define INTERFACE_D 4 41#define INTERFACE_D 4
898 42
899/*
900 * FIC / OpenMoko, Inc. http://wiki.openmoko.org/wiki/Neo1973_Debug_Board_v3
901 * Submitted by Harald Welte <laforge@openmoko.org>
902 */
903#define FIC_VID 0x1457
904#define FIC_NEO1973_DEBUG_PID 0x5118
905
906/*
907 * RATOC REX-USB60F
908 */
909#define RATOC_VENDOR_ID 0x0584
910#define RATOC_PRODUCT_ID_USB60F 0xb020
911
912/*
913 * DIEBOLD BCS SE923
914 */
915#define DIEBOLD_BCS_SE923_PID 0xfb99
916
917/*
918 * Atmel STK541
919 */
920#define ATMEL_VID 0x03eb /* Vendor ID */
921#define STK541_PID 0x2109 /* Zigbee Controller */
922
923/*
924 * Dresden Elektronic Sensor Terminal Board
925 */
926#define DE_VID 0x1cf1 /* Vendor ID */
927#define STB_PID 0x0001 /* Sensor Terminal Board */
928#define WHT_PID 0x0004 /* Wireless Handheld Terminal */
929
930/*
931 * Blackfin gnICE JTAG
932 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice
933 */
934#define ADI_VID 0x0456
935#define ADI_GNICE_PID 0xF000
936#define ADI_GNICEPLUS_PID 0xF001
937
938/*
939 * JETI SPECTROMETER SPECBOS 1201
940 * http://www.jeti.com/products/sys/scb/scb1201.php
941 */
942#define JETI_VID 0x0c6c
943#define JETI_SPC1201_PID 0x04b2
944
945/*
946 * Marvell SheevaPlug
947 */
948#define MARVELL_VID 0x9e88
949#define MARVELL_SHEEVAPLUG_PID 0x9e8f
950
951#define FTDI_TURTELIZER_PID 0xBDC8 /* JTAG/RS-232 adapter by egnite GmBH */
952
953/*
954 * GN Otometrics (http://www.otometrics.com)
955 * Submitted by Ville Sundberg.
956 */
957#define GN_OTOMETRICS_VID 0x0c33 /* Vendor ID */
958#define AURICAL_USB_PID 0x0010 /* Aurical USB Audiometer */
959
960/*
961 * Bayer Ascensia Contour blood glucose meter USB-converter cable.
962 * http://winglucofacts.com/cables/
963 */
964#define BAYER_VID 0x1A79
965#define BAYER_CONTOUR_CABLE_PID 0x6001
966
967/*
968 * Marvell OpenRD Base, Client
969 * http://www.open-rd.org
970 * OpenRD Base, Client use VID 0x0403
971 */
972#define MARVELL_OPENRD_PID 0x9e90
973
974/*
975 * Hameg HO820 and HO870 interface (using VID 0x0403)
976 */
977#define HAMEG_HO820_PID 0xed74
978#define HAMEG_HO870_PID 0xed71
979 43
980/* 44/*
981 * BmRequestType: 1100 0000b 45 * BmRequestType: 1100 0000b
@@ -1206,7 +270,7 @@ typedef enum {
1206 * BmRequestType: 0100 0000b 270 * BmRequestType: 0100 0000b
1207 * bRequest: FTDI_SIO_SET_FLOW_CTRL 271 * bRequest: FTDI_SIO_SET_FLOW_CTRL
1208 * wValue: Xoff/Xon 272 * wValue: Xoff/Xon
1209 * wIndex: Protocol/Port - hIndex is protocl / lIndex is port 273 * wIndex: Protocol/Port - hIndex is protocol / lIndex is port
1210 * wLength: 0 274 * wLength: 0
1211 * Data: None 275 * Data: None
1212 * 276 *
@@ -1490,4 +554,3 @@ typedef enum {
1490 * B2..7 Length of message - (not including Byte 0) 554 * B2..7 Length of message - (not including Byte 0)
1491 * 555 *
1492 */ 556 */
1493
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
new file mode 100644
index 000000000000..75482cbc3998
--- /dev/null
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -0,0 +1,1026 @@
1/*
2 * vendor/product IDs (VID/PID) of devices using FTDI USB serial converters.
3 * Please keep numerically sorted within individual areas, thanks!
4 *
5 * Philipp Gühring - pg@futureware.at - added the Device ID of the USB relais
6 * from Rudolf Gugler
7 *
8 */
9
10
11/**********************************/
12/***** devices using FTDI VID *****/
13/**********************************/
14
15
16#define FTDI_VID 0x0403 /* Vendor Id */
17
18
19/*** "original" FTDI device PIDs ***/
20
21#define FTDI_8U232AM_PID 0x6001 /* Similar device to SIO above */
22#define FTDI_8U232AM_ALT_PID 0x6006 /* FTDI's alternate PID for above */
23#define FTDI_8U2232C_PID 0x6010 /* Dual channel device */
24#define FTDI_4232H_PID 0x6011 /* Quad channel hi-speed device */
25#define FTDI_SIO_PID 0x8372 /* Product Id SIO application of 8U100AX */
26#define FTDI_232RL_PID 0xFBFA /* Product ID for FT232RL */
27
28
29/*** third-party PIDs (using FTDI_VID) ***/
30
31/*
32 * Marvell OpenRD Base, Client
33 * http://www.open-rd.org
34 * OpenRD Base, Client use VID 0x0403
35 */
36#define MARVELL_OPENRD_PID 0x9e90
37
38/* www.candapter.com Ewert Energy Systems CANdapter device */
39#define FTDI_CANDAPTER_PID 0x9F80 /* Product Id */
40
41#define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */
42
43/* OOCDlink by Joern Kaipf <joernk@web.de>
44 * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */
45#define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */
46
47/* Luminary Micro Stellaris Boards, VID = FTDI_VID */
48/* FTDI 2332C Dual channel device, side A=245 FIFO (JTAG), Side B=RS232 UART */
49#define LMI_LM3S_DEVEL_BOARD_PID 0xbcd8
50#define LMI_LM3S_EVAL_BOARD_PID 0xbcd9
51
52#define FTDI_TURTELIZER_PID 0xBDC8 /* JTAG/RS-232 adapter by egnite GmbH */
53
54/* OpenDCC (www.opendcc.de) product id */
55#define FTDI_OPENDCC_PID 0xBFD8
56#define FTDI_OPENDCC_SNIFFER_PID 0xBFD9
57#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
58#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
59
60/*
61 * RR-CirKits LocoBuffer USB (http://www.rr-cirkits.com)
62 */
63#define FTDI_RRCIRKITS_LOCOBUFFER_PID 0xc7d0 /* LocoBuffer USB */
64
65/* DMX4ALL DMX Interfaces */
66#define FTDI_DMX4ALL 0xC850
67
68/*
69 * ASK.fr devices
70 */
71#define FTDI_ASK_RDR400_PID 0xC991 /* ASK RDR 400 series card reader */
72
73/* www.starting-point-systems.com µChameleon device */
74#define FTDI_MICRO_CHAMELEON_PID 0xCAA0 /* Product Id */
75
76/*
77 * Tactrix OpenPort (ECU) devices.
78 * OpenPort 1.3M submitted by Donour Sizemore.
79 * OpenPort 1.3S and 1.3U submitted by Ian Abbott.
80 */
81#define FTDI_TACTRIX_OPENPORT_13M_PID 0xCC48 /* OpenPort 1.3 Mitsubishi */
82#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */
83#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */
84
85/* SCS HF Radio Modems PID's (http://www.scs-ptc.com) */
86/* the VID is the standard ftdi vid (FTDI_VID) */
87#define FTDI_SCS_DEVICE_0_PID 0xD010 /* SCS PTC-IIusb */
88#define FTDI_SCS_DEVICE_1_PID 0xD011 /* SCS Tracker / DSP TNC */
89#define FTDI_SCS_DEVICE_2_PID 0xD012
90#define FTDI_SCS_DEVICE_3_PID 0xD013
91#define FTDI_SCS_DEVICE_4_PID 0xD014
92#define FTDI_SCS_DEVICE_5_PID 0xD015
93#define FTDI_SCS_DEVICE_6_PID 0xD016
94#define FTDI_SCS_DEVICE_7_PID 0xD017
95
96/* iPlus device */
97#define FTDI_IPLUS_PID 0xD070 /* Product Id */
98#define FTDI_IPLUS2_PID 0xD071 /* Product Id */
99
100/*
101 * Gamma Scout (http://gamma-scout.com/). Submitted by rsc@runtux.com.
102 */
103#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */
104
105/* Propox devices */
106#define FTDI_PROPOX_JTAGCABLEII_PID 0xD738
107
108/*
109 * Xsens Technologies BV products (http://www.xsens.com).
110 */
111#define XSENS_CONVERTER_0_PID 0xD388
112#define XSENS_CONVERTER_1_PID 0xD389
113#define XSENS_CONVERTER_2_PID 0xD38A
114#define XSENS_CONVERTER_3_PID 0xD38B
115#define XSENS_CONVERTER_4_PID 0xD38C
116#define XSENS_CONVERTER_5_PID 0xD38D
117#define XSENS_CONVERTER_6_PID 0xD38E
118#define XSENS_CONVERTER_7_PID 0xD38F
119
120/*
121 * NDI (www.ndigital.com) product ids
122 */
123#define FTDI_NDI_HUC_PID 0xDA70 /* NDI Host USB Converter */
124#define FTDI_NDI_SPECTRA_SCU_PID 0xDA71 /* NDI Spectra SCU */
125#define FTDI_NDI_FUTURE_2_PID 0xDA72 /* NDI future device #2 */
126#define FTDI_NDI_FUTURE_3_PID 0xDA73 /* NDI future device #3 */
127#define FTDI_NDI_AURORA_SCU_PID 0xDA74 /* NDI Aurora SCU */
128
129/*
130 * Westrex International devices submitted by Cory Lee
131 */
132#define FTDI_WESTREX_MODEL_777_PID 0xDC00 /* Model 777 */
133#define FTDI_WESTREX_MODEL_8900F_PID 0xDC01 /* Model 8900F */
134
135/*
136 * ACG Identification Technologies GmbH products (http://www.acg.de/).
137 * Submitted by anton -at- goto10 -dot- org.
138 */
139#define FTDI_ACG_HFDUAL_PID 0xDD20 /* HF Dual ISO Reader (RFID) */
140
141/*
142 * Definitions for Artemis astronomical USB based cameras
143 * Check it at http://www.artemisccd.co.uk/
144 */
145#define FTDI_ARTEMIS_PID 0xDF28 /* All Artemis Cameras */
146
147/*
148 * Definitions for ATIK Instruments astronomical USB based cameras
149 * Check it at http://www.atik-instruments.com/
150 */
151#define FTDI_ATIK_ATK16_PID 0xDF30 /* ATIK ATK-16 Grayscale Camera */
152#define FTDI_ATIK_ATK16C_PID 0xDF32 /* ATIK ATK-16C Colour Camera */
153#define FTDI_ATIK_ATK16HR_PID 0xDF31 /* ATIK ATK-16HR Grayscale Camera */
154#define FTDI_ATIK_ATK16HRC_PID 0xDF33 /* ATIK ATK-16HRC Colour Camera */
155#define FTDI_ATIK_ATK16IC_PID 0xDF35 /* ATIK ATK-16IC Grayscale Camera */
156
157/*
158 * Yost Engineering, Inc. products (www.yostengineering.com).
159 * PID 0xE050 submitted by Aaron Prose.
160 */
161#define FTDI_YEI_SERVOCENTER31_PID 0xE050 /* YEI ServoCenter3.1 USB */
162
163/*
164 * ELV USB devices submitted by Christian Abt of ELV (www.elv.de).
165 * All of these devices use FTDI's vendor ID (0x0403).
166 * Further IDs taken from ELV Windows .inf file.
167 *
168 * The previously included PID for the UO 100 module was incorrect.
169 * In fact, that PID was for ELV's UR 100 USB-RS232 converter (0xFB58).
170 *
171 * Armin Laeuger originally sent the PID for the UM 100 module.
172 */
173#define FTDI_ELV_USR_PID 0xE000 /* ELV Universal-Sound-Recorder */
174#define FTDI_ELV_MSM1_PID 0xE001 /* ELV Mini-Sound-Modul */
175#define FTDI_ELV_KL100_PID 0xE002 /* ELV Kfz-Leistungsmesser KL 100 */
176#define FTDI_ELV_WS550_PID 0xE004 /* WS 550 */
177#define FTDI_ELV_EC3000_PID 0xE006 /* ENERGY CONTROL 3000 USB */
178#define FTDI_ELV_WS888_PID 0xE008 /* WS 888 */
179#define FTDI_ELV_TWS550_PID 0xE009 /* Technoline WS 550 */
180#define FTDI_ELV_FEM_PID 0xE00A /* Funk Energie Monitor */
181#define FTDI_ELV_FHZ1300PC_PID 0xE0E8 /* FHZ 1300 PC */
182#define FTDI_ELV_WS500_PID 0xE0E9 /* PC-Wetterstation (WS 500) */
183#define FTDI_ELV_HS485_PID 0xE0EA /* USB to RS-485 adapter */
184#define FTDI_ELV_UMS100_PID 0xE0EB /* ELV USB Master-Slave Schaltsteckdose UMS 100 */
185#define FTDI_ELV_TFD128_PID 0xE0EC /* ELV Temperatur-Feuchte-Datenlogger TFD 128 */
186#define FTDI_ELV_FM3RX_PID 0xE0ED /* ELV Messwertuebertragung FM3 RX */
187#define FTDI_ELV_WS777_PID 0xE0EE /* Conrad WS 777 */
188#define FTDI_ELV_EM1010PC_PID 0xE0EF /* Energy monitor EM 1010 PC */
189#define FTDI_ELV_CSI8_PID 0xE0F0 /* Computer-Schalt-Interface (CSI 8) */
190#define FTDI_ELV_EM1000DL_PID 0xE0F1 /* PC-Datenlogger fuer Energiemonitor (EM 1000 DL) */
191#define FTDI_ELV_PCK100_PID 0xE0F2 /* PC-Kabeltester (PCK 100) */
192#define FTDI_ELV_RFP500_PID 0xE0F3 /* HF-Leistungsmesser (RFP 500) */
193#define FTDI_ELV_FS20SIG_PID 0xE0F4 /* Signalgeber (FS 20 SIG) */
194#define FTDI_ELV_UTP8_PID 0xE0F5 /* ELV UTP 8 */
195#define FTDI_ELV_WS300PC_PID 0xE0F6 /* PC-Wetterstation (WS 300 PC) */
196#define FTDI_ELV_WS444PC_PID 0xE0F7 /* Conrad WS 444 PC */
197#define FTDI_PHI_FISCO_PID 0xE40B /* PHI Fisco USB to Serial cable */
198#define FTDI_ELV_UAD8_PID 0xF068 /* USB-AD-Wandler (UAD 8) */
199#define FTDI_ELV_UDA7_PID 0xF069 /* USB-DA-Wandler (UDA 7) */
200#define FTDI_ELV_USI2_PID 0xF06A /* USB-Schrittmotoren-Interface (USI 2) */
201#define FTDI_ELV_T1100_PID 0xF06B /* Thermometer (T 1100) */
202#define FTDI_ELV_PCD200_PID 0xF06C /* PC-Datenlogger (PCD 200) */
203#define FTDI_ELV_ULA200_PID 0xF06D /* USB-LCD-Ansteuerung (ULA 200) */
204#define FTDI_ELV_ALC8500_PID 0xF06E /* ALC 8500 Expert */
205#define FTDI_ELV_FHZ1000PC_PID 0xF06F /* FHZ 1000 PC */
206#define FTDI_ELV_UR100_PID 0xFB58 /* USB-RS232-Umsetzer (UR 100) */
207#define FTDI_ELV_UM100_PID 0xFB5A /* USB-Modul UM 100 */
208#define FTDI_ELV_UO100_PID 0xFB5B /* USB-Modul UO 100 */
209/* Additional ELV PIDs that default to using the FTDI D2XX drivers on
210 * MS Windows, rather than the FTDI Virtual Com Port drivers.
211 * Maybe these will be easier to use with the libftdi/libusb user-space
212 * drivers, or possibly the Comedi drivers in some cases. */
213#define FTDI_ELV_CLI7000_PID 0xFB59 /* Computer-Light-Interface (CLI 7000) */
214#define FTDI_ELV_PPS7330_PID 0xFB5C /* Processor-Power-Supply (PPS 7330) */
215#define FTDI_ELV_TFM100_PID 0xFB5D /* Temperatur-Feuchte-Messgeraet (TFM 100) */
216#define FTDI_ELV_UDF77_PID 0xFB5E /* USB DCF Funkuhr (UDF 77) */
217#define FTDI_ELV_UIO88_PID 0xFB5F /* USB-I/O Interface (UIO 88) */
218
219/*
220 * EVER Eco Pro UPS (http://www.ever.com.pl/)
221 */
222
223#define EVER_ECO_PRO_CDS 0xe520 /* RS-232 converter */
224
225/*
226 * Active Robots product ids.
227 */
228#define FTDI_ACTIVE_ROBOTS_PID 0xE548 /* USB comms board */
229
230/* Pyramid Computer GmbH */
231#define FTDI_PYRAMID_PID 0xE6C8 /* Pyramid Appliance Display */
232
233/* www.elsterelectricity.com Elster Unicom III Optical Probe */
234#define FTDI_ELSTER_UNICOM_PID 0xE700 /* Product Id */
235
236/*
237 * Gude Analog- und Digitalsysteme GmbH
238 */
239#define FTDI_GUDEADS_E808_PID 0xE808
240#define FTDI_GUDEADS_E809_PID 0xE809
241#define FTDI_GUDEADS_E80A_PID 0xE80A
242#define FTDI_GUDEADS_E80B_PID 0xE80B
243#define FTDI_GUDEADS_E80C_PID 0xE80C
244#define FTDI_GUDEADS_E80D_PID 0xE80D
245#define FTDI_GUDEADS_E80E_PID 0xE80E
246#define FTDI_GUDEADS_E80F_PID 0xE80F
247#define FTDI_GUDEADS_E888_PID 0xE888 /* Expert ISDN Control USB */
248#define FTDI_GUDEADS_E889_PID 0xE889 /* USB RS-232 OptoBridge */
249#define FTDI_GUDEADS_E88A_PID 0xE88A
250#define FTDI_GUDEADS_E88B_PID 0xE88B
251#define FTDI_GUDEADS_E88C_PID 0xE88C
252#define FTDI_GUDEADS_E88D_PID 0xE88D
253#define FTDI_GUDEADS_E88E_PID 0xE88E
254#define FTDI_GUDEADS_E88F_PID 0xE88F
255
256/*
257 * Eclo (http://www.eclo.pt/) product IDs.
258 * PID 0xEA90 submitted by Martin Grill.
259 */
260#define FTDI_ECLO_COM_1WIRE_PID 0xEA90 /* COM to 1-Wire USB adaptor */
261
262/* TNC-X USB-to-packet-radio adapter, versions prior to 3.0 (DLP module) */
263#define FTDI_TNC_X_PID 0xEBE0
264
265/*
266 * Teratronik product ids.
267 * Submitted by O. Wölfelschneider.
268 */
269#define FTDI_TERATRONIK_VCP_PID 0xEC88 /* Teratronik device (preferring VCP driver on windows) */
270#define FTDI_TERATRONIK_D2XX_PID 0xEC89 /* Teratronik device (preferring D2XX driver on windows) */
271
272/* Rig Expert Ukraine devices */
273#define FTDI_REU_TINY_PID 0xED22 /* RigExpert Tiny */
274
275/*
276 * Hameg HO820 and HO870 interface (using VID 0x0403)
277 */
278#define HAMEG_HO820_PID 0xed74
279#define HAMEG_HO870_PID 0xed71
280
281/*
282 * MaxStream devices www.maxstream.net
283 */
284#define FTDI_MAXSTREAM_PID 0xEE18 /* Xbee PKG-U Module */
285
286/*
287 * microHAM product IDs (http://www.microham.com).
288 * Submitted by Justin Burket (KL1RL) <zorton@jtan.com>
289 * and Mike Studer (K6EEP) <k6eep@hamsoftware.org>.
290 * Ian Abbott <abbotti@mev.co.uk> added a few more from the driver INF file.
291 */
292#define FTDI_MHAM_KW_PID 0xEEE8 /* USB-KW interface */
293#define FTDI_MHAM_YS_PID 0xEEE9 /* USB-YS interface */
294#define FTDI_MHAM_Y6_PID 0xEEEA /* USB-Y6 interface */
295#define FTDI_MHAM_Y8_PID 0xEEEB /* USB-Y8 interface */
296#define FTDI_MHAM_IC_PID 0xEEEC /* USB-IC interface */
297#define FTDI_MHAM_DB9_PID 0xEEED /* USB-DB9 interface */
298#define FTDI_MHAM_RS232_PID 0xEEEE /* USB-RS232 interface */
299#define FTDI_MHAM_Y9_PID 0xEEEF /* USB-Y9 interface */
300
301/* Domintell products http://www.domintell.com */
302#define FTDI_DOMINTELL_DGQG_PID 0xEF50 /* Master */
303#define FTDI_DOMINTELL_DUSB_PID 0xEF51 /* DUSB01 module */
304
305/*
306 * The following are the values for the Perle Systems
307 * UltraPort USB serial converters
308 */
309#define FTDI_PERLE_ULTRAPORT_PID 0xF0C0 /* Perle UltraPort Product Id */
310
311/* Sprog II (Andrew Crosland's SprogII DCC interface) */
312#define FTDI_SPROG_II 0xF0C8
313
314/* an infrared receiver for user access control with IR tags */
315#define FTDI_PIEGROUP_PID 0xF208 /* Product Id */
316
317/* ACT Solutions HomePro ZWave interface
318 (http://www.act-solutions.com/HomePro.htm) */
319#define FTDI_ACTZWAVE_PID 0xF2D0
320
321/*
322 * 4N-GALAXY.DE PIDs for CAN-USB, USB-RS232, USB-RS422, USB-RS485,
323 * USB-TTY aktiv, USB-TTY passiv. Some PIDs are used by several devices
324 * and I'm not entirely sure which are used by which.
325 */
326#define FTDI_4N_GALAXY_DE_1_PID 0xF3C0
327#define FTDI_4N_GALAXY_DE_2_PID 0xF3C1
328
329/*
330 * Linx Technologies product ids
331 */
332#define LINX_SDMUSBQSS_PID 0xF448 /* Linx SDM-USB-QS-S */
333#define LINX_MASTERDEVEL2_PID 0xF449 /* Linx Master Development 2.0 */
334#define LINX_FUTURE_0_PID 0xF44A /* Linx future device */
335#define LINX_FUTURE_1_PID 0xF44B /* Linx future device */
336#define LINX_FUTURE_2_PID 0xF44C /* Linx future device */
337
338/*
339 * Oceanic product ids
340 */
341#define FTDI_OCEANIC_PID 0xF460 /* Oceanic dive instrument */
342
343/*
344 * SUUNTO product ids
345 */
346#define FTDI_SUUNTO_SPORTS_PID 0xF680 /* Suunto Sports instrument */
347
348/* USB-UIRT - An infrared receiver and transmitter using the 8U232AM chip */
349/* http://home.earthlink.net/~jrhees/USBUIRT/index.htm */
350#define FTDI_USB_UIRT_PID 0xF850 /* Product Id */
351
352/* CCS Inc. ICDU/ICDU40 product ID -
353 * the FT232BM is used in an in-circuit-debugger unit for PIC16's/PIC18's */
354#define FTDI_CCSICDU20_0_PID 0xF9D0
355#define FTDI_CCSICDU40_1_PID 0xF9D1
356#define FTDI_CCSMACHX_2_PID 0xF9D2
357#define FTDI_CCSLOAD_N_GO_3_PID 0xF9D3
358#define FTDI_CCSICDU64_4_PID 0xF9D4
359#define FTDI_CCSPRIME8_5_PID 0xF9D5
360
361/*
362 * The following are the values for the Matrix Orbital LCD displays,
363 * which are the FT232BM ( similar to the 8U232AM )
364 */
365#define FTDI_MTXORB_0_PID 0xFA00 /* Matrix Orbital Product Id */
366#define FTDI_MTXORB_1_PID 0xFA01 /* Matrix Orbital Product Id */
367#define FTDI_MTXORB_2_PID 0xFA02 /* Matrix Orbital Product Id */
368#define FTDI_MTXORB_3_PID 0xFA03 /* Matrix Orbital Product Id */
369#define FTDI_MTXORB_4_PID 0xFA04 /* Matrix Orbital Product Id */
370#define FTDI_MTXORB_5_PID 0xFA05 /* Matrix Orbital Product Id */
371#define FTDI_MTXORB_6_PID 0xFA06 /* Matrix Orbital Product Id */
372
373/*
374 * Home Electronics (www.home-electro.com) USB gadgets
375 */
376#define FTDI_HE_TIRA1_PID 0xFA78 /* Tira-1 IR transceiver */
377
378/* Inside Accesso contactless reader (http://www.insidefr.com) */
379#define INSIDE_ACCESSO 0xFAD0
380
381/*
382 * ThorLabs USB motor drivers
383 */
384#define FTDI_THORLABS_PID 0xfaf0 /* ThorLabs USB motor drivers */
385
386/*
387 * Protego product ids
388 */
389#define PROTEGO_SPECIAL_1 0xFC70 /* special/unknown device */
390#define PROTEGO_R2X0 0xFC71 /* R200-USB TRNG unit (R210, R220, and R230) */
391#define PROTEGO_SPECIAL_3 0xFC72 /* special/unknown device */
392#define PROTEGO_SPECIAL_4 0xFC73 /* special/unknown device */
393
394/*
395 * DSS-20 Sync Station for Sony Ericsson P800
396 */
397#define FTDI_DSS20_PID 0xFC82
398
399/* www.irtrans.de device */
400#define FTDI_IRTRANS_PID 0xFC60 /* Product Id */
401
402/*
403 * RM Michaelides CANview USB (http://www.rmcan.com) (FTDI_VID)
404 * CAN fieldbus interface adapter, added by port GmbH www.port.de)
405 * Ian Abbott changed the macro names for consistency.
406 */
407#define FTDI_RM_CANVIEW_PID 0xfd60 /* Product Id */
408/* www.thoughttechnology.com/ TT-USB provide with procomp use ftdi_sio */
409#define FTDI_TTUSB_PID 0xFF20 /* Product Id */
410
411#define FTDI_USBX_707_PID 0xF857 /* ADSTech IR Blaster USBX-707 (FTDI_VID) */
412
413#define FTDI_RELAIS_PID 0xFA10 /* Relais device from Rudolf Gugler */
414
415/*
416 * PCDJ use ftdi based dj-controllers. The following PID is
417 * for their DAC-2 device http://www.pcdjhardware.com/DAC2.asp
418 * (the VID is the standard ftdi vid (FTDI_VID), PID sent by Wouter Paesen)
419 */
420#define FTDI_PCDJ_DAC2_PID 0xFA88
421
422#define FTDI_R2000KU_TRUE_RNG 0xFB80 /* R2000KU TRUE RNG (FTDI_VID) */
423
424/*
425 * DIEBOLD BCS SE923 (FTDI_VID)
426 */
427#define DIEBOLD_BCS_SE923_PID 0xfb99
428
429/* www.crystalfontz.com devices
430 * - thanx for providing free devices for evaluation !
431 * they use the ftdi chipset for the USB interface
432 * and the vendor id is the same
433 */
434#define FTDI_XF_632_PID 0xFC08 /* 632: 16x2 Character Display */
435#define FTDI_XF_634_PID 0xFC09 /* 634: 20x4 Character Display */
436#define FTDI_XF_547_PID 0xFC0A /* 547: Two line Display */
437#define FTDI_XF_633_PID 0xFC0B /* 633: 16x2 Character Display with Keys */
438#define FTDI_XF_631_PID 0xFC0C /* 631: 20x2 Character Display */
439#define FTDI_XF_635_PID 0xFC0D /* 635: 20x4 Character Display */
440#define FTDI_XF_640_PID 0xFC0E /* 640: Two line Display */
441#define FTDI_XF_642_PID 0xFC0F /* 642: Two line Display */
442
443/*
444 * Video Networks Limited / Homechoice in the UK use an ftdi-based device
445 * for their 1Mb broadband internet service. The following PID is exhibited
446 * by the usb device supplied (the VID is the standard ftdi vid (FTDI_VID)
447 */
448#define FTDI_VNHCPCUSB_D_PID 0xfe38 /* Product Id */
449
450/* AlphaMicro Components AMC-232USB01 device (FTDI_VID) */
451#define FTDI_AMC232_PID 0xFF00 /* Product Id */
452
453/*
454 * IBS elektronik product ids (FTDI_VID)
455 * Submitted by Thomas Schleusener
456 */
457#define FTDI_IBS_US485_PID 0xff38 /* IBS US485 (USB<-->RS422/485 interface) */
458#define FTDI_IBS_PICPRO_PID 0xff39 /* IBS PIC-Programmer */
459#define FTDI_IBS_PCMCIA_PID 0xff3a /* IBS Card reader for PCMCIA SRAM-cards */
460#define FTDI_IBS_PK1_PID 0xff3b /* IBS PK1 - Particel counter */
461#define FTDI_IBS_RS232MON_PID 0xff3c /* IBS RS232 - Monitor */
462#define FTDI_IBS_APP70_PID 0xff3d /* APP 70 (dust monitoring system) */
463#define FTDI_IBS_PEDO_PID 0xff3e /* IBS PEDO-Modem (RF modem 868.35 MHz) */
464#define FTDI_IBS_PROD_PID 0xff3f /* future device */
465/* www.canusb.com Lawicel CANUSB device (FTDI_VID) */
466#define FTDI_CANUSB_PID 0xFFA8 /* Product Id */
467
468
469
470/********************************/
471/** third-party VID/PID combos **/
472/********************************/
473
474
475
476/*
477 * Atmel STK541
478 */
479#define ATMEL_VID 0x03eb /* Vendor ID */
480#define STK541_PID 0x2109 /* Zigbee Controller */
481
482/*
483 * Blackfin gnICE JTAG
484 * http://docs.blackfin.uclinux.org/doku.php?id=hw:jtag:gnice
485 */
486#define ADI_VID 0x0456
487#define ADI_GNICE_PID 0xF000
488#define ADI_GNICEPLUS_PID 0xF001
489
490/*
491 * RATOC REX-USB60F
492 */
493#define RATOC_VENDOR_ID 0x0584
494#define RATOC_PRODUCT_ID_USB60F 0xb020
495
496/*
497 * Contec products (http://www.contec.com)
498 * Submitted by Daniel Sangorrin
499 */
500#define CONTEC_VID 0x06CE /* Vendor ID */
501#define CONTEC_COM1USBH_PID 0x8311 /* COM-1(USB)H */
502
503/*
504 * Contec products (http://www.contec.com)
505 * Submitted by Daniel Sangorrin
506 */
507#define CONTEC_VID 0x06CE /* Vendor ID */
508#define CONTEC_COM1USBH_PID 0x8311 /* COM-1(USB)H */
509
510/*
511 * Definitions for B&B Electronics products.
512 */
513#define BANDB_VID 0x0856 /* B&B Electronics Vendor ID */
514#define BANDB_USOTL4_PID 0xAC01 /* USOTL4 Isolated RS-485 Converter */
515#define BANDB_USTL4_PID 0xAC02 /* USTL4 RS-485 Converter */
516#define BANDB_USO9ML2_PID 0xAC03 /* USO9ML2 Isolated RS-232 Converter */
517#define BANDB_USOPTL4_PID 0xAC11
518#define BANDB_USPTL4_PID 0xAC12
519#define BANDB_USO9ML2DR_2_PID 0xAC16
520#define BANDB_USO9ML2DR_PID 0xAC17
521#define BANDB_USOPTL4DR2_PID 0xAC18 /* USOPTL4R-2 2-port Isolated RS-232 Converter */
522#define BANDB_USOPTL4DR_PID 0xAC19
523#define BANDB_485USB9F_2W_PID 0xAC25
524#define BANDB_485USB9F_4W_PID 0xAC26
525#define BANDB_232USB9M_PID 0xAC27
526#define BANDB_485USBTB_2W_PID 0xAC33
527#define BANDB_485USBTB_4W_PID 0xAC34
528#define BANDB_TTL5USB9M_PID 0xAC49
529#define BANDB_TTL3USB9M_PID 0xAC50
530#define BANDB_ZZ_PROG1_USB_PID 0xBA02
531
532/*
533 * Intrepid Control Systems (http://www.intrepidcs.com/) ValueCAN and NeoVI
534 */
535#define INTREPID_VID 0x093C
536#define INTREPID_VALUECAN_PID 0x0601
537#define INTREPID_NEOVI_PID 0x0701
538
539/*
540 * Definitions for ID TECH (www.idt-net.com) devices
541 */
542#define IDTECH_VID 0x0ACD /* ID TECH Vendor ID */
543#define IDTECH_IDT1221U_PID 0x0300 /* IDT1221U USB to RS-232 adapter */
544
545/*
546 * Definitions for Omnidirectional Control Technology, Inc. devices
547 */
548#define OCT_VID 0x0B39 /* OCT vendor ID */
549/* Note: OCT US101 is also rebadged as Dick Smith Electronics (NZ) XH6381 */
550/* Also rebadged as Dick Smith Electronics (Aus) XH6451 */
551/* Also rebadged as SIIG Inc. model US2308 hardware version 1 */
552#define OCT_US101_PID 0x0421 /* OCT US101 USB to RS-232 */
553
554/*
555 * Icom ID-1 digital transceiver
556 */
557
558#define ICOM_ID1_VID 0x0C26
559#define ICOM_ID1_PID 0x0004
560
561/*
562 * GN Otometrics (http://www.otometrics.com)
563 * Submitted by Ville Sundberg.
564 */
565#define GN_OTOMETRICS_VID 0x0c33 /* Vendor ID */
566#define AURICAL_USB_PID 0x0010 /* Aurical USB Audiometer */
567
568/*
569 * The following are the values for the Sealevel SeaLINK+ adapters.
570 * (Original list sent by Tuan Hoang. Ian Abbott renamed the macros and
571 * removed some PIDs that don't seem to match any existing products.)
572 */
573#define SEALEVEL_VID 0x0c52 /* Sealevel Vendor ID */
574#define SEALEVEL_2101_PID 0x2101 /* SeaLINK+232 (2101/2105) */
575#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */
576#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */
577#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */
578#define SEALEVEL_2106_PID 0x9020 /* SeaLINK+422 (2106) */
579#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */
580#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */
581#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */
582#define SEALEVEL_2202_2_PID 0x2222 /* SeaPORT+2/485 (2202) Port 2 */
583#define SEALEVEL_2203_1_PID 0x2213 /* SeaPORT+2 (2203) Port 1 */
584#define SEALEVEL_2203_2_PID 0x2223 /* SeaPORT+2 (2203) Port 2 */
585#define SEALEVEL_2401_1_PID 0x2411 /* SeaPORT+4/232 (2401) Port 1 */
586#define SEALEVEL_2401_2_PID 0x2421 /* SeaPORT+4/232 (2401) Port 2 */
587#define SEALEVEL_2401_3_PID 0x2431 /* SeaPORT+4/232 (2401) Port 3 */
588#define SEALEVEL_2401_4_PID 0x2441 /* SeaPORT+4/232 (2401) Port 4 */
589#define SEALEVEL_2402_1_PID 0x2412 /* SeaPORT+4/485 (2402) Port 1 */
590#define SEALEVEL_2402_2_PID 0x2422 /* SeaPORT+4/485 (2402) Port 2 */
591#define SEALEVEL_2402_3_PID 0x2432 /* SeaPORT+4/485 (2402) Port 3 */
592#define SEALEVEL_2402_4_PID 0x2442 /* SeaPORT+4/485 (2402) Port 4 */
593#define SEALEVEL_2403_1_PID 0x2413 /* SeaPORT+4 (2403) Port 1 */
594#define SEALEVEL_2403_2_PID 0x2423 /* SeaPORT+4 (2403) Port 2 */
595#define SEALEVEL_2403_3_PID 0x2433 /* SeaPORT+4 (2403) Port 3 */
596#define SEALEVEL_2403_4_PID 0x2443 /* SeaPORT+4 (2403) Port 4 */
597#define SEALEVEL_2801_1_PID 0X2811 /* SeaLINK+8/232 (2801) Port 1 */
598#define SEALEVEL_2801_2_PID 0X2821 /* SeaLINK+8/232 (2801) Port 2 */
599#define SEALEVEL_2801_3_PID 0X2831 /* SeaLINK+8/232 (2801) Port 3 */
600#define SEALEVEL_2801_4_PID 0X2841 /* SeaLINK+8/232 (2801) Port 4 */
601#define SEALEVEL_2801_5_PID 0X2851 /* SeaLINK+8/232 (2801) Port 5 */
602#define SEALEVEL_2801_6_PID 0X2861 /* SeaLINK+8/232 (2801) Port 6 */
603#define SEALEVEL_2801_7_PID 0X2871 /* SeaLINK+8/232 (2801) Port 7 */
604#define SEALEVEL_2801_8_PID 0X2881 /* SeaLINK+8/232 (2801) Port 8 */
605#define SEALEVEL_2802_1_PID 0X2812 /* SeaLINK+8/485 (2802) Port 1 */
606#define SEALEVEL_2802_2_PID 0X2822 /* SeaLINK+8/485 (2802) Port 2 */
607#define SEALEVEL_2802_3_PID 0X2832 /* SeaLINK+8/485 (2802) Port 3 */
608#define SEALEVEL_2802_4_PID 0X2842 /* SeaLINK+8/485 (2802) Port 4 */
609#define SEALEVEL_2802_5_PID 0X2852 /* SeaLINK+8/485 (2802) Port 5 */
610#define SEALEVEL_2802_6_PID 0X2862 /* SeaLINK+8/485 (2802) Port 6 */
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 */
613#define SEALEVEL_2803_1_PID 0X2813 /* SeaLINK+8 (2803) Port 1 */
614#define SEALEVEL_2803_2_PID 0X2823 /* SeaLINK+8 (2803) Port 2 */
615#define SEALEVEL_2803_3_PID 0X2833 /* SeaLINK+8 (2803) Port 3 */
616#define SEALEVEL_2803_4_PID 0X2843 /* SeaLINK+8 (2803) Port 4 */
617#define SEALEVEL_2803_5_PID 0X2853 /* SeaLINK+8 (2803) Port 5 */
618#define SEALEVEL_2803_6_PID 0X2863 /* SeaLINK+8 (2803) Port 6 */
619#define SEALEVEL_2803_7_PID 0X2873 /* SeaLINK+8 (2803) Port 7 */
620#define SEALEVEL_2803_8_PID 0X2883 /* SeaLINK+8 (2803) Port 8 */
621
622/*
623 * JETI SPECTROMETER SPECBOS 1201
624 * http://www.jeti.com/products/sys/scb/scb1201.php
625 */
626#define JETI_VID 0x0c6c
627#define JETI_SPC1201_PID 0x04b2
628
629/*
630 * FTDI USB UART chips used in construction projects from the
631 * Elektor Electronics magazine (http://elektor-electronics.co.uk)
632 */
633#define ELEKTOR_VID 0x0C7D
634#define ELEKTOR_FT323R_PID 0x0005 /* RFID-Reader, issue 09-2006 */
635
636/*
637 * Posiflex inc retail equipment (http://www.posiflex.com.tw)
638 */
639#define POSIFLEX_VID 0x0d3a /* Vendor ID */
640#define POSIFLEX_PP7000_PID 0x0300 /* PP-7000II thermal printer */
641
642/*
643 * The following are the values for two KOBIL chipcard terminals.
644 */
645#define KOBIL_VID 0x0d46 /* KOBIL Vendor ID */
646#define KOBIL_CONV_B1_PID 0x2020 /* KOBIL Konverter for B1 */
647#define KOBIL_CONV_KAAN_PID 0x2021 /* KOBIL_Konverter for KAAN */
648
649#define FTDI_NF_RIC_VID 0x0DCD /* Vendor Id */
650#define FTDI_NF_RIC_PID 0x0001 /* Product Id */
651
652/*
653 * Falcom Wireless Communications GmbH
654 */
655#define FALCOM_VID 0x0F94 /* Vendor Id */
656#define FALCOM_TWIST_PID 0x0001 /* Falcom Twist USB GPRS modem */
657#define FALCOM_SAMBA_PID 0x0005 /* Falcom Samba USB GPRS modem */
658
659/* Larsen and Brusgaard AltiTrack/USBtrack */
660#define LARSENBRUSGAARD_VID 0x0FD8
661#define LB_ALTITRACK_PID 0x0001
662
663/*
664 * TTi (Thurlby Thandar Instruments)
665 */
666#define TTI_VID 0x103E /* Vendor Id */
667#define TTI_QL355P_PID 0x03E8 /* TTi QL355P power supply */
668
669/* Interbiometrics USB I/O Board */
670/* Developed for Interbiometrics by Rudolf Gugler */
671#define INTERBIOMETRICS_VID 0x1209
672#define INTERBIOMETRICS_IOBOARD_PID 0x1002
673#define INTERBIOMETRICS_MINI_IOBOARD_PID 0x1006
674
675/*
676 * Testo products (http://www.testo.com/)
677 * Submitted by Colin Leroy
678 */
679#define TESTO_VID 0x128D
680#define TESTO_USB_INTERFACE_PID 0x0001
681
682/*
683 * Mobility Electronics products.
684 */
685#define MOBILITY_VID 0x1342
686#define MOBILITY_USB_SERIAL_PID 0x0202 /* EasiDock USB 200 serial */
687
688/*
689 * FIC / OpenMoko, Inc. http://wiki.openmoko.org/wiki/Neo1973_Debug_Board_v3
690 * Submitted by Harald Welte <laforge@openmoko.org>
691 */
692#define FIC_VID 0x1457
693#define FIC_NEO1973_DEBUG_PID 0x5118
694
695/* Olimex */
696#define OLIMEX_VID 0x15BA
697#define OLIMEX_ARM_USB_OCD_PID 0x0003
698
699/*
700 * Telldus Technologies
701 */
702#define TELLDUS_VID 0x1781 /* Vendor ID */
703#define TELLDUS_TELLSTICK_PID 0x0C30 /* RF control dongle 433 MHz using FT232RL */
704
705/*
706 * Bayer Ascensia Contour blood glucose meter USB-converter cable.
707 * http://winglucofacts.com/cables/
708 */
709#define BAYER_VID 0x1A79
710#define BAYER_CONTOUR_CABLE_PID 0x6001
711
712/*
713 * The following are the values for the Matrix Orbital FTDI Range
714 * Anything in this range will use an FT232RL.
715 */
716#define MTXORB_VID 0x1B3D
717#define MTXORB_FTDI_RANGE_0100_PID 0x0100
718#define MTXORB_FTDI_RANGE_0101_PID 0x0101
719#define MTXORB_FTDI_RANGE_0102_PID 0x0102
720#define MTXORB_FTDI_RANGE_0103_PID 0x0103
721#define MTXORB_FTDI_RANGE_0104_PID 0x0104
722#define MTXORB_FTDI_RANGE_0105_PID 0x0105
723#define MTXORB_FTDI_RANGE_0106_PID 0x0106
724#define MTXORB_FTDI_RANGE_0107_PID 0x0107
725#define MTXORB_FTDI_RANGE_0108_PID 0x0108
726#define MTXORB_FTDI_RANGE_0109_PID 0x0109
727#define MTXORB_FTDI_RANGE_010A_PID 0x010A
728#define MTXORB_FTDI_RANGE_010B_PID 0x010B
729#define MTXORB_FTDI_RANGE_010C_PID 0x010C
730#define MTXORB_FTDI_RANGE_010D_PID 0x010D
731#define MTXORB_FTDI_RANGE_010E_PID 0x010E
732#define MTXORB_FTDI_RANGE_010F_PID 0x010F
733#define MTXORB_FTDI_RANGE_0110_PID 0x0110
734#define MTXORB_FTDI_RANGE_0111_PID 0x0111
735#define MTXORB_FTDI_RANGE_0112_PID 0x0112
736#define MTXORB_FTDI_RANGE_0113_PID 0x0113
737#define MTXORB_FTDI_RANGE_0114_PID 0x0114
738#define MTXORB_FTDI_RANGE_0115_PID 0x0115
739#define MTXORB_FTDI_RANGE_0116_PID 0x0116
740#define MTXORB_FTDI_RANGE_0117_PID 0x0117
741#define MTXORB_FTDI_RANGE_0118_PID 0x0118
742#define MTXORB_FTDI_RANGE_0119_PID 0x0119
743#define MTXORB_FTDI_RANGE_011A_PID 0x011A
744#define MTXORB_FTDI_RANGE_011B_PID 0x011B
745#define MTXORB_FTDI_RANGE_011C_PID 0x011C
746#define MTXORB_FTDI_RANGE_011D_PID 0x011D
747#define MTXORB_FTDI_RANGE_011E_PID 0x011E
748#define MTXORB_FTDI_RANGE_011F_PID 0x011F
749#define MTXORB_FTDI_RANGE_0120_PID 0x0120
750#define MTXORB_FTDI_RANGE_0121_PID 0x0121
751#define MTXORB_FTDI_RANGE_0122_PID 0x0122
752#define MTXORB_FTDI_RANGE_0123_PID 0x0123
753#define MTXORB_FTDI_RANGE_0124_PID 0x0124
754#define MTXORB_FTDI_RANGE_0125_PID 0x0125
755#define MTXORB_FTDI_RANGE_0126_PID 0x0126
756#define MTXORB_FTDI_RANGE_0127_PID 0x0127
757#define MTXORB_FTDI_RANGE_0128_PID 0x0128
758#define MTXORB_FTDI_RANGE_0129_PID 0x0129
759#define MTXORB_FTDI_RANGE_012A_PID 0x012A
760#define MTXORB_FTDI_RANGE_012B_PID 0x012B
761#define MTXORB_FTDI_RANGE_012C_PID 0x012C
762#define MTXORB_FTDI_RANGE_012D_PID 0x012D
763#define MTXORB_FTDI_RANGE_012E_PID 0x012E
764#define MTXORB_FTDI_RANGE_012F_PID 0x012F
765#define MTXORB_FTDI_RANGE_0130_PID 0x0130
766#define MTXORB_FTDI_RANGE_0131_PID 0x0131
767#define MTXORB_FTDI_RANGE_0132_PID 0x0132
768#define MTXORB_FTDI_RANGE_0133_PID 0x0133
769#define MTXORB_FTDI_RANGE_0134_PID 0x0134
770#define MTXORB_FTDI_RANGE_0135_PID 0x0135
771#define MTXORB_FTDI_RANGE_0136_PID 0x0136
772#define MTXORB_FTDI_RANGE_0137_PID 0x0137
773#define MTXORB_FTDI_RANGE_0138_PID 0x0138
774#define MTXORB_FTDI_RANGE_0139_PID 0x0139
775#define MTXORB_FTDI_RANGE_013A_PID 0x013A
776#define MTXORB_FTDI_RANGE_013B_PID 0x013B
777#define MTXORB_FTDI_RANGE_013C_PID 0x013C
778#define MTXORB_FTDI_RANGE_013D_PID 0x013D
779#define MTXORB_FTDI_RANGE_013E_PID 0x013E
780#define MTXORB_FTDI_RANGE_013F_PID 0x013F
781#define MTXORB_FTDI_RANGE_0140_PID 0x0140
782#define MTXORB_FTDI_RANGE_0141_PID 0x0141
783#define MTXORB_FTDI_RANGE_0142_PID 0x0142
784#define MTXORB_FTDI_RANGE_0143_PID 0x0143
785#define MTXORB_FTDI_RANGE_0144_PID 0x0144
786#define MTXORB_FTDI_RANGE_0145_PID 0x0145
787#define MTXORB_FTDI_RANGE_0146_PID 0x0146
788#define MTXORB_FTDI_RANGE_0147_PID 0x0147
789#define MTXORB_FTDI_RANGE_0148_PID 0x0148
790#define MTXORB_FTDI_RANGE_0149_PID 0x0149
791#define MTXORB_FTDI_RANGE_014A_PID 0x014A
792#define MTXORB_FTDI_RANGE_014B_PID 0x014B
793#define MTXORB_FTDI_RANGE_014C_PID 0x014C
794#define MTXORB_FTDI_RANGE_014D_PID 0x014D
795#define MTXORB_FTDI_RANGE_014E_PID 0x014E
796#define MTXORB_FTDI_RANGE_014F_PID 0x014F
797#define MTXORB_FTDI_RANGE_0150_PID 0x0150
798#define MTXORB_FTDI_RANGE_0151_PID 0x0151
799#define MTXORB_FTDI_RANGE_0152_PID 0x0152
800#define MTXORB_FTDI_RANGE_0153_PID 0x0153
801#define MTXORB_FTDI_RANGE_0154_PID 0x0154
802#define MTXORB_FTDI_RANGE_0155_PID 0x0155
803#define MTXORB_FTDI_RANGE_0156_PID 0x0156
804#define MTXORB_FTDI_RANGE_0157_PID 0x0157
805#define MTXORB_FTDI_RANGE_0158_PID 0x0158
806#define MTXORB_FTDI_RANGE_0159_PID 0x0159
807#define MTXORB_FTDI_RANGE_015A_PID 0x015A
808#define MTXORB_FTDI_RANGE_015B_PID 0x015B
809#define MTXORB_FTDI_RANGE_015C_PID 0x015C
810#define MTXORB_FTDI_RANGE_015D_PID 0x015D
811#define MTXORB_FTDI_RANGE_015E_PID 0x015E
812#define MTXORB_FTDI_RANGE_015F_PID 0x015F
813#define MTXORB_FTDI_RANGE_0160_PID 0x0160
814#define MTXORB_FTDI_RANGE_0161_PID 0x0161
815#define MTXORB_FTDI_RANGE_0162_PID 0x0162
816#define MTXORB_FTDI_RANGE_0163_PID 0x0163
817#define MTXORB_FTDI_RANGE_0164_PID 0x0164
818#define MTXORB_FTDI_RANGE_0165_PID 0x0165
819#define MTXORB_FTDI_RANGE_0166_PID 0x0166
820#define MTXORB_FTDI_RANGE_0167_PID 0x0167
821#define MTXORB_FTDI_RANGE_0168_PID 0x0168
822#define MTXORB_FTDI_RANGE_0169_PID 0x0169
823#define MTXORB_FTDI_RANGE_016A_PID 0x016A
824#define MTXORB_FTDI_RANGE_016B_PID 0x016B
825#define MTXORB_FTDI_RANGE_016C_PID 0x016C
826#define MTXORB_FTDI_RANGE_016D_PID 0x016D
827#define MTXORB_FTDI_RANGE_016E_PID 0x016E
828#define MTXORB_FTDI_RANGE_016F_PID 0x016F
829#define MTXORB_FTDI_RANGE_0170_PID 0x0170
830#define MTXORB_FTDI_RANGE_0171_PID 0x0171
831#define MTXORB_FTDI_RANGE_0172_PID 0x0172
832#define MTXORB_FTDI_RANGE_0173_PID 0x0173
833#define MTXORB_FTDI_RANGE_0174_PID 0x0174
834#define MTXORB_FTDI_RANGE_0175_PID 0x0175
835#define MTXORB_FTDI_RANGE_0176_PID 0x0176
836#define MTXORB_FTDI_RANGE_0177_PID 0x0177
837#define MTXORB_FTDI_RANGE_0178_PID 0x0178
838#define MTXORB_FTDI_RANGE_0179_PID 0x0179
839#define MTXORB_FTDI_RANGE_017A_PID 0x017A
840#define MTXORB_FTDI_RANGE_017B_PID 0x017B
841#define MTXORB_FTDI_RANGE_017C_PID 0x017C
842#define MTXORB_FTDI_RANGE_017D_PID 0x017D
843#define MTXORB_FTDI_RANGE_017E_PID 0x017E
844#define MTXORB_FTDI_RANGE_017F_PID 0x017F
845#define MTXORB_FTDI_RANGE_0180_PID 0x0180
846#define MTXORB_FTDI_RANGE_0181_PID 0x0181
847#define MTXORB_FTDI_RANGE_0182_PID 0x0182
848#define MTXORB_FTDI_RANGE_0183_PID 0x0183
849#define MTXORB_FTDI_RANGE_0184_PID 0x0184
850#define MTXORB_FTDI_RANGE_0185_PID 0x0185
851#define MTXORB_FTDI_RANGE_0186_PID 0x0186
852#define MTXORB_FTDI_RANGE_0187_PID 0x0187
853#define MTXORB_FTDI_RANGE_0188_PID 0x0188
854#define MTXORB_FTDI_RANGE_0189_PID 0x0189
855#define MTXORB_FTDI_RANGE_018A_PID 0x018A
856#define MTXORB_FTDI_RANGE_018B_PID 0x018B
857#define MTXORB_FTDI_RANGE_018C_PID 0x018C
858#define MTXORB_FTDI_RANGE_018D_PID 0x018D
859#define MTXORB_FTDI_RANGE_018E_PID 0x018E
860#define MTXORB_FTDI_RANGE_018F_PID 0x018F
861#define MTXORB_FTDI_RANGE_0190_PID 0x0190
862#define MTXORB_FTDI_RANGE_0191_PID 0x0191
863#define MTXORB_FTDI_RANGE_0192_PID 0x0192
864#define MTXORB_FTDI_RANGE_0193_PID 0x0193
865#define MTXORB_FTDI_RANGE_0194_PID 0x0194
866#define MTXORB_FTDI_RANGE_0195_PID 0x0195
867#define MTXORB_FTDI_RANGE_0196_PID 0x0196
868#define MTXORB_FTDI_RANGE_0197_PID 0x0197
869#define MTXORB_FTDI_RANGE_0198_PID 0x0198
870#define MTXORB_FTDI_RANGE_0199_PID 0x0199
871#define MTXORB_FTDI_RANGE_019A_PID 0x019A
872#define MTXORB_FTDI_RANGE_019B_PID 0x019B
873#define MTXORB_FTDI_RANGE_019C_PID 0x019C
874#define MTXORB_FTDI_RANGE_019D_PID 0x019D
875#define MTXORB_FTDI_RANGE_019E_PID 0x019E
876#define MTXORB_FTDI_RANGE_019F_PID 0x019F
877#define MTXORB_FTDI_RANGE_01A0_PID 0x01A0
878#define MTXORB_FTDI_RANGE_01A1_PID 0x01A1
879#define MTXORB_FTDI_RANGE_01A2_PID 0x01A2
880#define MTXORB_FTDI_RANGE_01A3_PID 0x01A3
881#define MTXORB_FTDI_RANGE_01A4_PID 0x01A4
882#define MTXORB_FTDI_RANGE_01A5_PID 0x01A5
883#define MTXORB_FTDI_RANGE_01A6_PID 0x01A6
884#define MTXORB_FTDI_RANGE_01A7_PID 0x01A7
885#define MTXORB_FTDI_RANGE_01A8_PID 0x01A8
886#define MTXORB_FTDI_RANGE_01A9_PID 0x01A9
887#define MTXORB_FTDI_RANGE_01AA_PID 0x01AA
888#define MTXORB_FTDI_RANGE_01AB_PID 0x01AB
889#define MTXORB_FTDI_RANGE_01AC_PID 0x01AC
890#define MTXORB_FTDI_RANGE_01AD_PID 0x01AD
891#define MTXORB_FTDI_RANGE_01AE_PID 0x01AE
892#define MTXORB_FTDI_RANGE_01AF_PID 0x01AF
893#define MTXORB_FTDI_RANGE_01B0_PID 0x01B0
894#define MTXORB_FTDI_RANGE_01B1_PID 0x01B1
895#define MTXORB_FTDI_RANGE_01B2_PID 0x01B2
896#define MTXORB_FTDI_RANGE_01B3_PID 0x01B3
897#define MTXORB_FTDI_RANGE_01B4_PID 0x01B4
898#define MTXORB_FTDI_RANGE_01B5_PID 0x01B5
899#define MTXORB_FTDI_RANGE_01B6_PID 0x01B6
900#define MTXORB_FTDI_RANGE_01B7_PID 0x01B7
901#define MTXORB_FTDI_RANGE_01B8_PID 0x01B8
902#define MTXORB_FTDI_RANGE_01B9_PID 0x01B9
903#define MTXORB_FTDI_RANGE_01BA_PID 0x01BA
904#define MTXORB_FTDI_RANGE_01BB_PID 0x01BB
905#define MTXORB_FTDI_RANGE_01BC_PID 0x01BC
906#define MTXORB_FTDI_RANGE_01BD_PID 0x01BD
907#define MTXORB_FTDI_RANGE_01BE_PID 0x01BE
908#define MTXORB_FTDI_RANGE_01BF_PID 0x01BF
909#define MTXORB_FTDI_RANGE_01C0_PID 0x01C0
910#define MTXORB_FTDI_RANGE_01C1_PID 0x01C1
911#define MTXORB_FTDI_RANGE_01C2_PID 0x01C2
912#define MTXORB_FTDI_RANGE_01C3_PID 0x01C3
913#define MTXORB_FTDI_RANGE_01C4_PID 0x01C4
914#define MTXORB_FTDI_RANGE_01C5_PID 0x01C5
915#define MTXORB_FTDI_RANGE_01C6_PID 0x01C6
916#define MTXORB_FTDI_RANGE_01C7_PID 0x01C7
917#define MTXORB_FTDI_RANGE_01C8_PID 0x01C8
918#define MTXORB_FTDI_RANGE_01C9_PID 0x01C9
919#define MTXORB_FTDI_RANGE_01CA_PID 0x01CA
920#define MTXORB_FTDI_RANGE_01CB_PID 0x01CB
921#define MTXORB_FTDI_RANGE_01CC_PID 0x01CC
922#define MTXORB_FTDI_RANGE_01CD_PID 0x01CD
923#define MTXORB_FTDI_RANGE_01CE_PID 0x01CE
924#define MTXORB_FTDI_RANGE_01CF_PID 0x01CF
925#define MTXORB_FTDI_RANGE_01D0_PID 0x01D0
926#define MTXORB_FTDI_RANGE_01D1_PID 0x01D1
927#define MTXORB_FTDI_RANGE_01D2_PID 0x01D2
928#define MTXORB_FTDI_RANGE_01D3_PID 0x01D3
929#define MTXORB_FTDI_RANGE_01D4_PID 0x01D4
930#define MTXORB_FTDI_RANGE_01D5_PID 0x01D5
931#define MTXORB_FTDI_RANGE_01D6_PID 0x01D6
932#define MTXORB_FTDI_RANGE_01D7_PID 0x01D7
933#define MTXORB_FTDI_RANGE_01D8_PID 0x01D8
934#define MTXORB_FTDI_RANGE_01D9_PID 0x01D9
935#define MTXORB_FTDI_RANGE_01DA_PID 0x01DA
936#define MTXORB_FTDI_RANGE_01DB_PID 0x01DB
937#define MTXORB_FTDI_RANGE_01DC_PID 0x01DC
938#define MTXORB_FTDI_RANGE_01DD_PID 0x01DD
939#define MTXORB_FTDI_RANGE_01DE_PID 0x01DE
940#define MTXORB_FTDI_RANGE_01DF_PID 0x01DF
941#define MTXORB_FTDI_RANGE_01E0_PID 0x01E0
942#define MTXORB_FTDI_RANGE_01E1_PID 0x01E1
943#define MTXORB_FTDI_RANGE_01E2_PID 0x01E2
944#define MTXORB_FTDI_RANGE_01E3_PID 0x01E3
945#define MTXORB_FTDI_RANGE_01E4_PID 0x01E4
946#define MTXORB_FTDI_RANGE_01E5_PID 0x01E5
947#define MTXORB_FTDI_RANGE_01E6_PID 0x01E6
948#define MTXORB_FTDI_RANGE_01E7_PID 0x01E7
949#define MTXORB_FTDI_RANGE_01E8_PID 0x01E8
950#define MTXORB_FTDI_RANGE_01E9_PID 0x01E9
951#define MTXORB_FTDI_RANGE_01EA_PID 0x01EA
952#define MTXORB_FTDI_RANGE_01EB_PID 0x01EB
953#define MTXORB_FTDI_RANGE_01EC_PID 0x01EC
954#define MTXORB_FTDI_RANGE_01ED_PID 0x01ED
955#define MTXORB_FTDI_RANGE_01EE_PID 0x01EE
956#define MTXORB_FTDI_RANGE_01EF_PID 0x01EF
957#define MTXORB_FTDI_RANGE_01F0_PID 0x01F0
958#define MTXORB_FTDI_RANGE_01F1_PID 0x01F1
959#define MTXORB_FTDI_RANGE_01F2_PID 0x01F2
960#define MTXORB_FTDI_RANGE_01F3_PID 0x01F3
961#define MTXORB_FTDI_RANGE_01F4_PID 0x01F4
962#define MTXORB_FTDI_RANGE_01F5_PID 0x01F5
963#define MTXORB_FTDI_RANGE_01F6_PID 0x01F6
964#define MTXORB_FTDI_RANGE_01F7_PID 0x01F7
965#define MTXORB_FTDI_RANGE_01F8_PID 0x01F8
966#define MTXORB_FTDI_RANGE_01F9_PID 0x01F9
967#define MTXORB_FTDI_RANGE_01FA_PID 0x01FA
968#define MTXORB_FTDI_RANGE_01FB_PID 0x01FB
969#define MTXORB_FTDI_RANGE_01FC_PID 0x01FC
970#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD
971#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE
972#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF
973
974
975
976/*
977 * The Mobility Lab (TML)
978 * Submitted by Pierre Castella
979 */
980#define TML_VID 0x1B91 /* Vendor ID */
981#define TML_USB_SERIAL_PID 0x0064 /* USB - Serial Converter */
982
983/* Alti-2 products http://www.alti-2.com */
984#define ALTI2_VID 0x1BC9
985#define ALTI2_N3_PID 0x6001 /* Neptune 3 */
986
987/*
988 * Dresden Elektronik Sensor Terminal Board
989 */
990#define DE_VID 0x1cf1 /* Vendor ID */
991#define STB_PID 0x0001 /* Sensor Terminal Board */
992#define WHT_PID 0x0004 /* Wireless Handheld Terminal */
993
994/*
995 * Papouch products (http://www.papouch.com/)
996 * Submitted by Folkert van Heusden
997 */
998
999#define PAPOUCH_VID 0x5050 /* Vendor ID */
1000#define PAPOUCH_TMU_PID 0x0400 /* TMU USB Thermometer */
1001#define PAPOUCH_QUIDO4x4_PID 0x0900 /* Quido 4/4 Module */
1002#define PAPOUCH_AD4USB_PID 0x8003 /* AD4USB Measurement Module */
1003
1004/*
1005 * Marvell SheevaPlug
1006 */
1007#define MARVELL_VID 0x9e88
1008#define MARVELL_SHEEVAPLUG_PID 0x9e8f
1009
1010/*
1011 * Evolution Robotics products (http://www.evolution.com/).
1012 * Submitted by Shawn M. Lavelle.
1013 */
1014#define EVOLUTION_VID 0xDEEE /* Vendor ID */
1015#define EVOLUTION_ER1_PID 0x0300 /* ER1 Control Module */
1016#define EVO_8U232AM_PID 0x02FF /* Evolution robotics RCM2 (FT232AM)*/
1017#define EVO_HYBRID_PID 0x0302 /* Evolution robotics RCM4 PID (FT232BM)*/
1018#define EVO_RCM4_PID 0x0303 /* Evolution robotics RCM4 PID */
1019
1020/*
1021 * MJS Gadgets HD Radio / XM Radio / Sirius Radio interfaces (using VID 0x0403)
1022 */
1023#define MJSG_GENERIC_PID 0x9378
1024#define MJSG_SR_RADIO_PID 0x9379
1025#define MJSG_XM_RADIO_PID 0x937A
1026#define MJSG_HD_RADIO_PID 0x937C
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index d30f736d2cc5..e21ce9ddfc63 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -18,7 +18,7 @@
18 18
19static int debug; 19static int debug;
20 20
21static struct usb_device_id id_table [] = { 21static const struct usb_device_id id_table[] = {
22 { USB_DEVICE(0x1404, 0xcddc) }, 22 { USB_DEVICE(0x1404, 0xcddc) },
23 { }, 23 { },
24}; 24};
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 5ac900e5a50e..a42b29a695b2 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -210,7 +210,7 @@ static unsigned char const PRIVATE_REQ[]
210 210
211 211
212 212
213static struct usb_device_id id_table [] = { 213static const struct usb_device_id id_table[] = {
214 /* the same device id seems to be used by all 214 /* the same device id seems to be used by all
215 usb enabled GPS devices */ 215 usb enabled GPS devices */
216 { USB_DEVICE(GARMIN_VENDOR_ID, 3) }, 216 { USB_DEVICE(GARMIN_VENDOR_ID, 3) },
@@ -271,7 +271,6 @@ static void send_to_tty(struct usb_serial_port *port,
271 usb_serial_debug_data(debug, &port->dev, 271 usb_serial_debug_data(debug, &port->dev,
272 __func__, actual_length, data); 272 __func__, actual_length, data);
273 273
274 tty_buffer_request_room(tty, actual_length);
275 tty_insert_flip_string(tty, data, actual_length); 274 tty_insert_flip_string(tty, data, actual_length);
276 tty_flip_buffer_push(tty); 275 tty_flip_buffer_push(tty);
277 } 276 }
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index bbe005cefcfb..f804acb138ec 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -20,6 +20,7 @@
20#include <linux/usb/serial.h> 20#include <linux/usb/serial.h>
21#include <linux/uaccess.h> 21#include <linux/uaccess.h>
22#include <linux/kfifo.h> 22#include <linux/kfifo.h>
23#include <linux/serial.h>
23 24
24static int debug; 25static int debug;
25 26
@@ -41,7 +42,7 @@ static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
41 42
42/* we want to look at all devices, as the vendor/product id can change 43/* we want to look at all devices, as the vendor/product id can change
43 * depending on the command line argument */ 44 * depending on the command line argument */
44static struct usb_device_id generic_serial_ids[] = { 45static const struct usb_device_id generic_serial_ids[] = {
45 {.driver_info = 42}, 46 {.driver_info = 42},
46 {} 47 {}
47}; 48};
@@ -129,7 +130,7 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
129 spin_unlock_irqrestore(&port->lock, flags); 130 spin_unlock_irqrestore(&port->lock, flags);
130 131
131 /* if we have a bulk endpoint, start reading from it */ 132 /* if we have a bulk endpoint, start reading from it */
132 if (serial->num_bulk_in) { 133 if (port->bulk_in_size) {
133 /* Start reading from the device */ 134 /* Start reading from the device */
134 usb_fill_bulk_urb(port->read_urb, serial->dev, 135 usb_fill_bulk_urb(port->read_urb, serial->dev,
135 usb_rcvbulkpipe(serial->dev, 136 usb_rcvbulkpipe(serial->dev,
@@ -158,10 +159,10 @@ static void generic_cleanup(struct usb_serial_port *port)
158 dbg("%s - port %d", __func__, port->number); 159 dbg("%s - port %d", __func__, port->number);
159 160
160 if (serial->dev) { 161 if (serial->dev) {
161 /* shutdown any bulk reads that might be going on */ 162 /* shutdown any bulk transfers that might be going on */
162 if (serial->num_bulk_out) 163 if (port->bulk_out_size)
163 usb_kill_urb(port->write_urb); 164 usb_kill_urb(port->write_urb);
164 if (serial->num_bulk_in) 165 if (port->bulk_in_size)
165 usb_kill_urb(port->read_urb); 166 usb_kill_urb(port->read_urb);
166 } 167 }
167} 168}
@@ -194,7 +195,7 @@ static int usb_serial_multi_urb_write(struct tty_struct *tty,
194 if (port->urbs_in_flight > 195 if (port->urbs_in_flight >
195 port->serial->type->max_in_flight_urbs) { 196 port->serial->type->max_in_flight_urbs) {
196 spin_unlock_irqrestore(&port->lock, flags); 197 spin_unlock_irqrestore(&port->lock, flags);
197 dbg("%s - write limit hit\n", __func__); 198 dbg("%s - write limit hit", __func__);
198 return bwrite; 199 return bwrite;
199 } 200 }
200 port->tx_bytes_flight += towrite; 201 port->tx_bytes_flight += towrite;
@@ -276,7 +277,7 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port)
276 if (port->write_urb_busy) 277 if (port->write_urb_busy)
277 start_io = false; 278 start_io = false;
278 else { 279 else {
279 start_io = (__kfifo_len(port->write_fifo) != 0); 280 start_io = (kfifo_len(&port->write_fifo) != 0);
280 port->write_urb_busy = start_io; 281 port->write_urb_busy = start_io;
281 } 282 }
282 spin_unlock_irqrestore(&port->lock, flags); 283 spin_unlock_irqrestore(&port->lock, flags);
@@ -285,7 +286,7 @@ static int usb_serial_generic_write_start(struct usb_serial_port *port)
285 return 0; 286 return 0;
286 287
287 data = port->write_urb->transfer_buffer; 288 data = port->write_urb->transfer_buffer;
288 count = kfifo_get(port->write_fifo, data, port->bulk_out_size); 289 count = kfifo_out_locked(&port->write_fifo, data, port->bulk_out_size, &port->lock);
289 usb_serial_debug_data(debug, &port->dev, __func__, count, data); 290 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
290 291
291 /* set up our urb */ 292 /* set up our urb */
@@ -332,20 +333,20 @@ int usb_serial_generic_write(struct tty_struct *tty,
332 333
333 dbg("%s - port %d", __func__, port->number); 334 dbg("%s - port %d", __func__, port->number);
334 335
336 /* only do something if we have a bulk out endpoint */
337 if (!port->bulk_out_size)
338 return -ENODEV;
339
335 if (count == 0) { 340 if (count == 0) {
336 dbg("%s - write request of 0 bytes", __func__); 341 dbg("%s - write request of 0 bytes", __func__);
337 return 0; 342 return 0;
338 } 343 }
339 344
340 /* only do something if we have a bulk out endpoint */
341 if (!serial->num_bulk_out)
342 return 0;
343
344 if (serial->type->max_in_flight_urbs) 345 if (serial->type->max_in_flight_urbs)
345 return usb_serial_multi_urb_write(tty, port, 346 return usb_serial_multi_urb_write(tty, port,
346 buf, count); 347 buf, count);
347 348
348 count = kfifo_put(port->write_fifo, buf, count); 349 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
349 result = usb_serial_generic_write_start(port); 350 result = usb_serial_generic_write_start(port);
350 351
351 if (result >= 0) 352 if (result >= 0)
@@ -363,14 +364,19 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
363 int room = 0; 364 int room = 0;
364 365
365 dbg("%s - port %d", __func__, port->number); 366 dbg("%s - port %d", __func__, port->number);
367
368 if (!port->bulk_out_size)
369 return 0;
370
366 spin_lock_irqsave(&port->lock, flags); 371 spin_lock_irqsave(&port->lock, flags);
367 if (serial->type->max_in_flight_urbs) { 372 if (serial->type->max_in_flight_urbs) {
368 if (port->urbs_in_flight < serial->type->max_in_flight_urbs) 373 if (port->urbs_in_flight < serial->type->max_in_flight_urbs)
369 room = port->bulk_out_size * 374 room = port->bulk_out_size *
370 (serial->type->max_in_flight_urbs - 375 (serial->type->max_in_flight_urbs -
371 port->urbs_in_flight); 376 port->urbs_in_flight);
372 } else if (serial->num_bulk_out) 377 } else {
373 room = port->write_fifo->size - __kfifo_len(port->write_fifo); 378 room = kfifo_avail(&port->write_fifo);
379 }
374 spin_unlock_irqrestore(&port->lock, flags); 380 spin_unlock_irqrestore(&port->lock, flags);
375 381
376 dbg("%s - returns %d", __func__, room); 382 dbg("%s - returns %d", __func__, room);
@@ -381,17 +387,20 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
381{ 387{
382 struct usb_serial_port *port = tty->driver_data; 388 struct usb_serial_port *port = tty->driver_data;
383 struct usb_serial *serial = port->serial; 389 struct usb_serial *serial = port->serial;
384 int chars = 0;
385 unsigned long flags; 390 unsigned long flags;
391 int chars;
386 392
387 dbg("%s - port %d", __func__, port->number); 393 dbg("%s - port %d", __func__, port->number);
388 394
389 if (serial->type->max_in_flight_urbs) { 395 if (!port->bulk_out_size)
390 spin_lock_irqsave(&port->lock, flags); 396 return 0;
397
398 spin_lock_irqsave(&port->lock, flags);
399 if (serial->type->max_in_flight_urbs)
391 chars = port->tx_bytes_flight; 400 chars = port->tx_bytes_flight;
392 spin_unlock_irqrestore(&port->lock, flags); 401 else
393 } else if (serial->num_bulk_out) 402 chars = kfifo_len(&port->write_fifo);
394 chars = kfifo_len(port->write_fifo); 403 spin_unlock_irqrestore(&port->lock, flags);
395 404
396 dbg("%s - returns %d", __func__, chars); 405 dbg("%s - returns %d", __func__, chars);
397 return chars; 406 return chars;
@@ -414,11 +423,13 @@ void usb_serial_generic_resubmit_read_urb(struct usb_serial_port *port,
414 ((serial->type->read_bulk_callback) ? 423 ((serial->type->read_bulk_callback) ?
415 serial->type->read_bulk_callback : 424 serial->type->read_bulk_callback :
416 usb_serial_generic_read_bulk_callback), port); 425 usb_serial_generic_read_bulk_callback), port);
426
417 result = usb_submit_urb(urb, mem_flags); 427 result = usb_submit_urb(urb, mem_flags);
418 if (result) 428 if (result && result != -EPERM) {
419 dev_err(&port->dev, 429 dev_err(&port->dev,
420 "%s - failed resubmitting read urb, error %d\n", 430 "%s - failed resubmitting read urb, error %d\n",
421 __func__, result); 431 __func__, result);
432 }
422} 433}
423EXPORT_SYMBOL_GPL(usb_serial_generic_resubmit_read_urb); 434EXPORT_SYMBOL_GPL(usb_serial_generic_resubmit_read_urb);
424 435
@@ -489,29 +500,26 @@ void usb_serial_generic_write_bulk_callback(struct urb *urb)
489 dbg("%s - port %d", __func__, port->number); 500 dbg("%s - port %d", __func__, port->number);
490 501
491 if (port->serial->type->max_in_flight_urbs) { 502 if (port->serial->type->max_in_flight_urbs) {
503 kfree(urb->transfer_buffer);
504
492 spin_lock_irqsave(&port->lock, flags); 505 spin_lock_irqsave(&port->lock, flags);
493 --port->urbs_in_flight; 506 --port->urbs_in_flight;
494 port->tx_bytes_flight -= urb->transfer_buffer_length; 507 port->tx_bytes_flight -= urb->transfer_buffer_length;
495 if (port->urbs_in_flight < 0) 508 if (port->urbs_in_flight < 0)
496 port->urbs_in_flight = 0; 509 port->urbs_in_flight = 0;
497 spin_unlock_irqrestore(&port->lock, flags); 510 spin_unlock_irqrestore(&port->lock, flags);
498
499 if (status) {
500 dbg("%s - nonzero multi-urb write bulk status "
501 "received: %d", __func__, status);
502 return;
503 }
504 } else { 511 } else {
505 port->write_urb_busy = 0; 512 port->write_urb_busy = 0;
506 513
507 if (status) { 514 if (status)
508 dbg("%s - nonzero multi-urb write bulk status " 515 kfifo_reset_out(&port->write_fifo);
509 "received: %d", __func__, status); 516 else
510 kfifo_reset(port->write_fifo);
511 } else
512 usb_serial_generic_write_start(port); 517 usb_serial_generic_write_start(port);
513 } 518 }
514 519
520 if (status)
521 dbg("%s - non-zero urb status: %d", __func__, status);
522
515 usb_serial_port_softint(port); 523 usb_serial_port_softint(port);
516} 524}
517EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); 525EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
@@ -583,7 +591,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
583 591
584 for (i = 0; i < serial->num_ports; i++) { 592 for (i = 0; i < serial->num_ports; i++) {
585 port = serial->port[i]; 593 port = serial->port[i];
586 if (!port->port.count) 594 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
587 continue; 595 continue;
588 596
589 if (port->read_urb) { 597 if (port->read_urb) {
diff --git a/drivers/usb/serial/hp4x.c b/drivers/usb/serial/hp4x.c
index 431329275133..809379159b0e 100644
--- a/drivers/usb/serial/hp4x.c
+++ b/drivers/usb/serial/hp4x.c
@@ -29,7 +29,7 @@
29#define HP_VENDOR_ID 0x03f0 29#define HP_VENDOR_ID 0x03f0
30#define HP49GP_PRODUCT_ID 0x0121 30#define HP49GP_PRODUCT_ID 0x0121
31 31
32static struct usb_device_id id_table [] = { 32static const struct usb_device_id id_table[] = {
33 { USB_DEVICE(HP_VENDOR_ID, HP49GP_PRODUCT_ID) }, 33 { USB_DEVICE(HP_VENDOR_ID, HP49GP_PRODUCT_ID) },
34 { } /* Terminating entry */ 34 { } /* Terminating entry */
35}; 35};
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index b97960ac92f2..3ef8df0ef888 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -364,42 +364,6 @@ static void update_edgeport_E2PROM(struct edgeport_serial *edge_serial)
364 release_firmware(fw); 364 release_firmware(fw);
365} 365}
366 366
367
368/************************************************************************
369 * *
370 * Get string descriptor from device *
371 * *
372 ************************************************************************/
373static int get_string(struct usb_device *dev, int Id, char *string, int buflen)
374{
375 struct usb_string_descriptor StringDesc;
376 struct usb_string_descriptor *pStringDesc;
377
378 dbg("%s - USB String ID = %d", __func__, Id);
379
380 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
381 &StringDesc, sizeof(StringDesc)))
382 return 0;
383
384 pStringDesc = kmalloc(StringDesc.bLength, GFP_KERNEL);
385 if (!pStringDesc)
386 return 0;
387
388 if (!usb_get_descriptor(dev, USB_DT_STRING, Id,
389 pStringDesc, StringDesc.bLength)) {
390 kfree(pStringDesc);
391 return 0;
392 }
393
394 unicode_to_ascii(string, buflen,
395 pStringDesc->wData, pStringDesc->bLength/2);
396
397 kfree(pStringDesc);
398 dbg("%s - USB String %s", __func__, string);
399 return strlen(string);
400}
401
402
403#if 0 367#if 0
404/************************************************************************ 368/************************************************************************
405 * 369 *
@@ -2007,7 +1971,7 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
2007 return; 1971 return;
2008 1972
2009 case IOSP_EXT_STATUS_RX_CHECK_RSP: 1973 case IOSP_EXT_STATUS_RX_CHECK_RSP:
2010 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============\n", __func__, edge_serial->rxPort, byte3); 1974 dbg("%s ========== Port %u CHECK_RSP Sequence = %02x =============", __func__, edge_serial->rxPort, byte3);
2011 /* Port->RxCheckRsp = true; */ 1975 /* Port->RxCheckRsp = true; */
2012 return; 1976 return;
2013 } 1977 }
@@ -2075,7 +2039,7 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
2075 break; 2039 break;
2076 2040
2077 default: 2041 default:
2078 dbg("%s - Unrecognized IOSP status code %u\n", __func__, code); 2042 dbg("%s - Unrecognized IOSP status code %u", __func__, code);
2079 break; 2043 break;
2080 } 2044 }
2081 return; 2045 return;
@@ -2091,18 +2055,13 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
2091{ 2055{
2092 int cnt; 2056 int cnt;
2093 2057
2094 do { 2058 cnt = tty_insert_flip_string(tty, data, length);
2095 cnt = tty_buffer_request_room(tty, length); 2059 if (cnt < length) {
2096 if (cnt < length) { 2060 dev_err(dev, "%s - dropping data, %d bytes lost\n",
2097 dev_err(dev, "%s - dropping data, %d bytes lost\n", 2061 __func__, length - cnt);
2098 __func__, length - cnt); 2062 }
2099 if (cnt == 0) 2063 data += cnt;
2100 break; 2064 length -= cnt;
2101 }
2102 tty_insert_flip_string(tty, data, cnt);
2103 data += cnt;
2104 length -= cnt;
2105 } while (length > 0);
2106 2065
2107 tty_flip_buffer_push(tty); 2066 tty_flip_buffer_push(tty);
2108} 2067}
@@ -2530,7 +2489,7 @@ static int calc_baud_rate_divisor(int baudrate, int *divisor)
2530 2489
2531 *divisor = custom; 2490 *divisor = custom;
2532 2491
2533 dbg("%s - Baud %d = %d\n", __func__, baudrate, custom); 2492 dbg("%s - Baud %d = %d", __func__, baudrate, custom);
2534 return 0; 2493 return 0;
2535 } 2494 }
2536 2495
@@ -2915,7 +2874,7 @@ static void load_application_firmware(struct edgeport_serial *edge_serial)
2915 break; 2874 break;
2916 2875
2917 case EDGE_DOWNLOAD_FILE_NONE: 2876 case EDGE_DOWNLOAD_FILE_NONE:
2918 dbg ("No download file specified, skipping download\n"); 2877 dbg("No download file specified, skipping download");
2919 return; 2878 return;
2920 2879
2921 default: 2880 default:
@@ -2997,10 +2956,12 @@ static int edge_startup(struct usb_serial *serial)
2997 usb_set_serial_data(serial, edge_serial); 2956 usb_set_serial_data(serial, edge_serial);
2998 2957
2999 /* get the name for the device from the device */ 2958 /* get the name for the device from the device */
3000 i = get_string(dev, dev->descriptor.iManufacturer, 2959 i = usb_string(dev, dev->descriptor.iManufacturer,
3001 &edge_serial->name[0], MAX_NAME_LEN+1); 2960 &edge_serial->name[0], MAX_NAME_LEN+1);
2961 if (i < 0)
2962 i = 0;
3002 edge_serial->name[i++] = ' '; 2963 edge_serial->name[i++] = ' ';
3003 get_string(dev, dev->descriptor.iProduct, 2964 usb_string(dev, dev->descriptor.iProduct,
3004 &edge_serial->name[i], MAX_NAME_LEN+2 - i); 2965 &edge_serial->name[i], MAX_NAME_LEN+2 - i);
3005 2966
3006 dev_info(&serial->dev->dev, "%s detected\n", edge_serial->name); 2967 dev_info(&serial->dev->dev, "%s detected\n", edge_serial->name);
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 9241d3147513..feb56a4ca799 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -14,7 +14,7 @@
14#ifndef IO_TABLES_H 14#ifndef IO_TABLES_H
15#define IO_TABLES_H 15#define IO_TABLES_H
16 16
17static struct usb_device_id edgeport_2port_id_table [] = { 17static const struct usb_device_id edgeport_2port_id_table[] = {
18 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_2) }, 18 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_2) },
19 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_2I) }, 19 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_2I) },
20 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_421) }, 20 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_421) },
@@ -23,7 +23,7 @@ static struct usb_device_id edgeport_2port_id_table [] = {
23 { } 23 { }
24}; 24};
25 25
26static struct usb_device_id edgeport_4port_id_table [] = { 26static const struct usb_device_id edgeport_4port_id_table[] = {
27 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4) }, 27 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4) },
28 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_RAPIDPORT_4) }, 28 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_RAPIDPORT_4) },
29 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4T) }, 29 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4T) },
@@ -37,7 +37,7 @@ static struct usb_device_id edgeport_4port_id_table [] = {
37 { } 37 { }
38}; 38};
39 39
40static struct usb_device_id edgeport_8port_id_table [] = { 40static const struct usb_device_id edgeport_8port_id_table[] = {
41 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8) }, 41 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8) },
42 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU) }, 42 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_16_DUAL_CPU) },
43 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8I) }, 43 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_8I) },
@@ -47,7 +47,7 @@ static struct usb_device_id edgeport_8port_id_table [] = {
47 { } 47 { }
48}; 48};
49 49
50static struct usb_device_id Epic_port_id_table [] = { 50static const struct usb_device_id Epic_port_id_table[] = {
51 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0202) }, 51 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0202) },
52 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0203) }, 52 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0203) },
53 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0310) }, 53 { USB_DEVICE(USB_VENDOR_ID_NCR, NCR_DEVICE_ID_EPIC_0310) },
@@ -60,7 +60,7 @@ static struct usb_device_id Epic_port_id_table [] = {
60}; 60};
61 61
62/* Devices that this driver supports */ 62/* Devices that this driver supports */
63static struct usb_device_id id_table_combined [] = { 63static const struct usb_device_id id_table_combined[] = {
64 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4) }, 64 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4) },
65 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_RAPIDPORT_4) }, 65 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_RAPIDPORT_4) },
66 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4T) }, 66 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_EDGEPORT_4T) },
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index d4cc0f7af400..aa876f71f228 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -134,7 +134,7 @@ struct edgeport_serial {
134 134
135 135
136/* Devices that this driver supports */ 136/* Devices that this driver supports */
137static struct usb_device_id edgeport_1port_id_table [] = { 137static const struct usb_device_id edgeport_1port_id_table[] = {
138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) }, 138 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) }, 139 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) }, 140 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
@@ -154,7 +154,7 @@ static struct usb_device_id edgeport_1port_id_table [] = {
154 { } 154 { }
155}; 155};
156 156
157static struct usb_device_id edgeport_2port_id_table [] = { 157static const struct usb_device_id edgeport_2port_id_table[] = {
158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) }, 158 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2) },
159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) }, 159 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2C) },
160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) }, 160 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_2I) },
@@ -177,7 +177,7 @@ static struct usb_device_id edgeport_2port_id_table [] = {
177}; 177};
178 178
179/* Devices that this driver supports */ 179/* Devices that this driver supports */
180static struct usb_device_id id_table_combined [] = { 180static const struct usb_device_id id_table_combined[] = {
181 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) }, 181 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_EDGEPORT_1) },
182 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) }, 182 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1) },
183 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) }, 183 { USB_DEVICE(USB_VENDOR_ID_ION, ION_DEVICE_ID_TI_TI3410_EDGEPORT_1I) },
@@ -413,11 +413,18 @@ static int write_boot_mem(struct edgeport_serial *serial,
413{ 413{
414 int status = 0; 414 int status = 0;
415 int i; 415 int i;
416 __u8 temp; 416 u8 *temp;
417 417
418 /* Must do a read before write */ 418 /* Must do a read before write */
419 if (!serial->TiReadI2C) { 419 if (!serial->TiReadI2C) {
420 status = read_boot_mem(serial, 0, 1, &temp); 420 temp = kmalloc(1, GFP_KERNEL);
421 if (!temp) {
422 dev_err(&serial->serial->dev->dev,
423 "%s - out of memory\n", __func__);
424 return -ENOMEM;
425 }
426 status = read_boot_mem(serial, 0, 1, temp);
427 kfree(temp);
421 if (status) 428 if (status)
422 return status; 429 return status;
423 } 430 }
@@ -935,37 +942,47 @@ static int build_i2c_fw_hdr(__u8 *header, struct device *dev)
935static int i2c_type_bootmode(struct edgeport_serial *serial) 942static int i2c_type_bootmode(struct edgeport_serial *serial)
936{ 943{
937 int status; 944 int status;
938 __u8 data; 945 u8 *data;
946
947 data = kmalloc(1, GFP_KERNEL);
948 if (!data) {
949 dev_err(&serial->serial->dev->dev,
950 "%s - out of memory\n", __func__);
951 return -ENOMEM;
952 }
939 953
940 /* Try to read type 2 */ 954 /* Try to read type 2 */
941 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, 955 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
942 DTK_ADDR_SPACE_I2C_TYPE_II, 0, &data, 0x01); 956 DTK_ADDR_SPACE_I2C_TYPE_II, 0, data, 0x01);
943 if (status) 957 if (status)
944 dbg("%s - read 2 status error = %d", __func__, status); 958 dbg("%s - read 2 status error = %d", __func__, status);
945 else 959 else
946 dbg("%s - read 2 data = 0x%x", __func__, data); 960 dbg("%s - read 2 data = 0x%x", __func__, *data);
947 if ((!status) && (data == UMP5152 || data == UMP3410)) { 961 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
948 dbg("%s - ROM_TYPE_II", __func__); 962 dbg("%s - ROM_TYPE_II", __func__);
949 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 963 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
950 return 0; 964 goto out;
951 } 965 }
952 966
953 /* Try to read type 3 */ 967 /* Try to read type 3 */
954 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ, 968 status = ti_vread_sync(serial->serial->dev, UMPC_MEMORY_READ,
955 DTK_ADDR_SPACE_I2C_TYPE_III, 0, &data, 0x01); 969 DTK_ADDR_SPACE_I2C_TYPE_III, 0, data, 0x01);
956 if (status) 970 if (status)
957 dbg("%s - read 3 status error = %d", __func__, status); 971 dbg("%s - read 3 status error = %d", __func__, status);
958 else 972 else
959 dbg("%s - read 2 data = 0x%x", __func__, data); 973 dbg("%s - read 2 data = 0x%x", __func__, *data);
960 if ((!status) && (data == UMP5152 || data == UMP3410)) { 974 if ((!status) && (*data == UMP5152 || *data == UMP3410)) {
961 dbg("%s - ROM_TYPE_III", __func__); 975 dbg("%s - ROM_TYPE_III", __func__);
962 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III; 976 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_III;
963 return 0; 977 goto out;
964 } 978 }
965 979
966 dbg("%s - Unknown", __func__); 980 dbg("%s - Unknown", __func__);
967 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II; 981 serial->TI_I2C_Type = DTK_ADDR_SPACE_I2C_TYPE_II;
968 return -ENODEV; 982 status = -ENODEV;
983out:
984 kfree(data);
985 return status;
969} 986}
970 987
971static int bulk_xfer(struct usb_serial *serial, void *buffer, 988static int bulk_xfer(struct usb_serial *serial, void *buffer,
@@ -1113,7 +1130,7 @@ static int download_fw(struct edgeport_serial *serial)
1113 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc); 1130 I2C_DESC_TYPE_FIRMWARE_BASIC, rom_desc);
1114 if (start_address != 0) { 1131 if (start_address != 0) {
1115 struct ti_i2c_firmware_rec *firmware_version; 1132 struct ti_i2c_firmware_rec *firmware_version;
1116 __u8 record; 1133 u8 *record;
1117 1134
1118 dbg("%s - Found Type FIRMWARE (Type 2) record", 1135 dbg("%s - Found Type FIRMWARE (Type 2) record",
1119 __func__); 1136 __func__);
@@ -1165,6 +1182,15 @@ static int download_fw(struct edgeport_serial *serial)
1165 OperationalMajorVersion, 1182 OperationalMajorVersion,
1166 OperationalMinorVersion); 1183 OperationalMinorVersion);
1167 1184
1185 record = kmalloc(1, GFP_KERNEL);
1186 if (!record) {
1187 dev_err(dev, "%s - out of memory.\n",
1188 __func__);
1189 kfree(firmware_version);
1190 kfree(rom_desc);
1191 kfree(ti_manuf_desc);
1192 return -ENOMEM;
1193 }
1168 /* In order to update the I2C firmware we must 1194 /* In order to update the I2C firmware we must
1169 * change the type 2 record to type 0xF2. This 1195 * change the type 2 record to type 0xF2. This
1170 * will force the UMP to come up in Boot Mode. 1196 * will force the UMP to come up in Boot Mode.
@@ -1177,13 +1203,14 @@ static int download_fw(struct edgeport_serial *serial)
1177 * firmware will update the record type from 1203 * firmware will update the record type from
1178 * 0xf2 to 0x02. 1204 * 0xf2 to 0x02.
1179 */ 1205 */
1180 record = I2C_DESC_TYPE_FIRMWARE_BLANK; 1206 *record = I2C_DESC_TYPE_FIRMWARE_BLANK;
1181 1207
1182 /* Change the I2C Firmware record type to 1208 /* Change the I2C Firmware record type to
1183 0xf2 to trigger an update */ 1209 0xf2 to trigger an update */
1184 status = write_rom(serial, start_address, 1210 status = write_rom(serial, start_address,
1185 sizeof(record), &record); 1211 sizeof(*record), record);
1186 if (status) { 1212 if (status) {
1213 kfree(record);
1187 kfree(firmware_version); 1214 kfree(firmware_version);
1188 kfree(rom_desc); 1215 kfree(rom_desc);
1189 kfree(ti_manuf_desc); 1216 kfree(ti_manuf_desc);
@@ -1196,19 +1223,21 @@ static int download_fw(struct edgeport_serial *serial)
1196 */ 1223 */
1197 status = read_rom(serial, 1224 status = read_rom(serial,
1198 start_address, 1225 start_address,
1199 sizeof(record), 1226 sizeof(*record),
1200 &record); 1227 record);
1201 if (status) { 1228 if (status) {
1229 kfree(record);
1202 kfree(firmware_version); 1230 kfree(firmware_version);
1203 kfree(rom_desc); 1231 kfree(rom_desc);
1204 kfree(ti_manuf_desc); 1232 kfree(ti_manuf_desc);
1205 return status; 1233 return status;
1206 } 1234 }
1207 1235
1208 if (record != I2C_DESC_TYPE_FIRMWARE_BLANK) { 1236 if (*record != I2C_DESC_TYPE_FIRMWARE_BLANK) {
1209 dev_err(dev, 1237 dev_err(dev,
1210 "%s - error resetting device\n", 1238 "%s - error resetting device\n",
1211 __func__); 1239 __func__);
1240 kfree(record);
1212 kfree(firmware_version); 1241 kfree(firmware_version);
1213 kfree(rom_desc); 1242 kfree(rom_desc);
1214 kfree(ti_manuf_desc); 1243 kfree(ti_manuf_desc);
@@ -1226,6 +1255,7 @@ static int download_fw(struct edgeport_serial *serial)
1226 __func__, status); 1255 __func__, status);
1227 1256
1228 /* return an error on purpose. */ 1257 /* return an error on purpose. */
1258 kfree(record);
1229 kfree(firmware_version); 1259 kfree(firmware_version);
1230 kfree(rom_desc); 1260 kfree(rom_desc);
1231 kfree(ti_manuf_desc); 1261 kfree(ti_manuf_desc);
@@ -1686,7 +1716,7 @@ static void edge_interrupt_callback(struct urb *urb)
1686 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */ 1716 case TIUMP_INTERRUPT_CODE_MSR: /* MSR */
1687 /* Copy MSR from UMP */ 1717 /* Copy MSR from UMP */
1688 msr = data[1]; 1718 msr = data[1];
1689 dbg("%s - ===== Port %u MSR Status = %02x ======\n", 1719 dbg("%s - ===== Port %u MSR Status = %02x ======",
1690 __func__, port_number, msr); 1720 __func__, port_number, msr);
1691 handle_new_msr(edge_port, msr); 1721 handle_new_msr(edge_port, msr);
1692 break; 1722 break;
@@ -1790,7 +1820,6 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty,
1790{ 1820{
1791 int queued; 1821 int queued;
1792 1822
1793 tty_buffer_request_room(tty, length);
1794 queued = tty_insert_flip_string(tty, data, length); 1823 queued = tty_insert_flip_string(tty, data, length);
1795 if (queued < length) 1824 if (queued < length)
1796 dev_err(dev, "%s - dropping data, %d bytes lost\n", 1825 dev_err(dev, "%s - dropping data, %d bytes lost\n",
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index d6231c38813e..3fea9298eb15 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -747,7 +747,6 @@ static void ipaq_read_bulk_callback(struct urb *urb)
747 747
748 tty = tty_port_tty_get(&port->port); 748 tty = tty_port_tty_get(&port->port);
749 if (tty && urb->actual_length) { 749 if (tty && urb->actual_length) {
750 tty_buffer_request_room(tty, urb->actual_length);
751 tty_insert_flip_string(tty, data, urb->actual_length); 750 tty_insert_flip_string(tty, data, urb->actual_length);
752 tty_flip_buffer_push(tty); 751 tty_flip_buffer_push(tty);
753 bytes_in += urb->actual_length; 752 bytes_in += urb->actual_length;
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 727d323f092a..e1d07840cee6 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -134,7 +134,7 @@ enum {
134 134
135#define IPW_WANTS_TO_SEND 0x30 135#define IPW_WANTS_TO_SEND 0x30
136 136
137static struct usb_device_id usb_ipw_ids[] = { 137static const struct usb_device_id usb_ipw_ids[] = {
138 { USB_DEVICE(IPW_VID, IPW_PID) }, 138 { USB_DEVICE(IPW_VID, IPW_PID) },
139 { }, 139 { },
140}; 140};
@@ -172,7 +172,6 @@ static void ipw_read_bulk_callback(struct urb *urb)
172 172
173 tty = tty_port_tty_get(&port->port); 173 tty = tty_port_tty_get(&port->port);
174 if (tty && urb->actual_length) { 174 if (tty && urb->actual_length) {
175 tty_buffer_request_room(tty, urb->actual_length);
176 tty_insert_flip_string(tty, data, urb->actual_length); 175 tty_insert_flip_string(tty, data, urb->actual_length);
177 tty_flip_buffer_push(tty); 176 tty_flip_buffer_push(tty);
178 } 177 }
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 95d8d26b9a44..4a0f51974232 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -100,7 +100,7 @@ static u8 ir_baud;
100static u8 ir_xbof; 100static u8 ir_xbof;
101static u8 ir_add_bof; 101static u8 ir_add_bof;
102 102
103static struct usb_device_id ir_id_table[] = { 103static const struct usb_device_id ir_id_table[] = {
104 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */ 104 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */
105 { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */ 105 { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */
106 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */ 106 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */
@@ -445,11 +445,6 @@ static void ir_read_bulk_callback(struct urb *urb)
445 445
446 dbg("%s - port %d", __func__, port->number); 446 dbg("%s - port %d", __func__, port->number);
447 447
448 if (!port->port.count) {
449 dbg("%s - port closed.", __func__);
450 return;
451 }
452
453 switch (status) { 448 switch (status) {
454 case 0: /* Successful */ 449 case 0: /* Successful */
455 /* 450 /*
@@ -462,10 +457,8 @@ static void ir_read_bulk_callback(struct urb *urb)
462 usb_serial_debug_data(debug, &port->dev, __func__, 457 usb_serial_debug_data(debug, &port->dev, __func__,
463 urb->actual_length, data); 458 urb->actual_length, data);
464 tty = tty_port_tty_get(&port->port); 459 tty = tty_port_tty_get(&port->port);
465 if (tty_buffer_request_room(tty, urb->actual_length - 1)) { 460 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
466 tty_insert_flip_string(tty, data+1, urb->actual_length - 1); 461 tty_flip_buffer_push(tty);
467 tty_flip_buffer_push(tty);
468 }
469 tty_kref_put(tty); 462 tty_kref_put(tty);
470 463
471 /* 464 /*
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index e6e02b178d2b..43f13cf2f016 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -43,7 +43,7 @@ static int debug;
43#define DRIVER_VERSION "v0.11" 43#define DRIVER_VERSION "v0.11"
44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" 44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
45 45
46static struct usb_device_id id_table[] = { 46static const struct usb_device_id id_table[] = {
47 {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)}, 47 {USB_DEVICE(IUU_USB_VENDOR_ID, IUU_USB_PRODUCT_ID)},
48 {} /* Terminating entry */ 48 {} /* Terminating entry */
49}; 49};
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index f8c4b07033ff..297163c3c610 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -464,13 +464,9 @@ static void usa26_indat_callback(struct urb *urb)
464 464
465 /* Resubmit urb so we continue receiving */ 465 /* Resubmit urb so we continue receiving */
466 urb->dev = port->serial->dev; 466 urb->dev = port->serial->dev;
467 if (port->port.count) { 467 err = usb_submit_urb(urb, GFP_ATOMIC);
468 err = usb_submit_urb(urb, GFP_ATOMIC); 468 if (err != 0)
469 if (err != 0) 469 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
470 dbg("%s - resubmit read urb failed. (%d)",
471 __func__, err);
472 }
473 return;
474} 470}
475 471
476/* Outdat handling is common for all devices */ 472/* Outdat handling is common for all devices */
@@ -483,8 +479,7 @@ static void usa2x_outdat_callback(struct urb *urb)
483 p_priv = usb_get_serial_port_data(port); 479 p_priv = usb_get_serial_port_data(port);
484 dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]); 480 dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
485 481
486 if (port->port.count) 482 usb_serial_port_softint(port);
487 usb_serial_port_softint(port);
488} 483}
489 484
490static void usa26_inack_callback(struct urb *urb) 485static void usa26_inack_callback(struct urb *urb)
@@ -615,12 +610,10 @@ static void usa28_indat_callback(struct urb *urb)
615 610
616 /* Resubmit urb so we continue receiving */ 611 /* Resubmit urb so we continue receiving */
617 urb->dev = port->serial->dev; 612 urb->dev = port->serial->dev;
618 if (port->port.count) { 613 err = usb_submit_urb(urb, GFP_ATOMIC);
619 err = usb_submit_urb(urb, GFP_ATOMIC); 614 if (err != 0)
620 if (err != 0) 615 dbg("%s - resubmit read urb failed. (%d)",
621 dbg("%s - resubmit read urb failed. (%d)", 616 __func__, err);
622 __func__, err);
623 }
624 p_priv->in_flip ^= 1; 617 p_priv->in_flip ^= 1;
625 618
626 urb = p_priv->in_urbs[p_priv->in_flip]; 619 urb = p_priv->in_urbs[p_priv->in_flip];
@@ -856,12 +849,9 @@ static void usa49_indat_callback(struct urb *urb)
856 849
857 /* Resubmit urb so we continue receiving */ 850 /* Resubmit urb so we continue receiving */
858 urb->dev = port->serial->dev; 851 urb->dev = port->serial->dev;
859 if (port->port.count) { 852 err = usb_submit_urb(urb, GFP_ATOMIC);
860 err = usb_submit_urb(urb, GFP_ATOMIC); 853 if (err != 0)
861 if (err != 0) 854 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
862 dbg("%s - resubmit read urb failed. (%d)",
863 __func__, err);
864 }
865} 855}
866 856
867static void usa49wg_indat_callback(struct urb *urb) 857static void usa49wg_indat_callback(struct urb *urb)
@@ -904,11 +894,7 @@ static void usa49wg_indat_callback(struct urb *urb)
904 /* no error on any byte */ 894 /* no error on any byte */
905 i++; 895 i++;
906 for (x = 1; x < len ; ++x) 896 for (x = 1; x < len ; ++x)
907 if (port->port.count) 897 tty_insert_flip_char(tty, data[i++], 0);
908 tty_insert_flip_char(tty,
909 data[i++], 0);
910 else
911 i++;
912 } else { 898 } else {
913 /* 899 /*
914 * some bytes had errors, every byte has status 900 * some bytes had errors, every byte has status
@@ -922,14 +908,12 @@ static void usa49wg_indat_callback(struct urb *urb)
922 if (stat & RXERROR_PARITY) 908 if (stat & RXERROR_PARITY)
923 flag |= TTY_PARITY; 909 flag |= TTY_PARITY;
924 /* XXX should handle break (0x10) */ 910 /* XXX should handle break (0x10) */
925 if (port->port.count) 911 tty_insert_flip_char(tty,
926 tty_insert_flip_char(tty,
927 data[i+1], flag); 912 data[i+1], flag);
928 i += 2; 913 i += 2;
929 } 914 }
930 } 915 }
931 if (port->port.count) 916 tty_flip_buffer_push(tty);
932 tty_flip_buffer_push(tty);
933 tty_kref_put(tty); 917 tty_kref_put(tty);
934 } 918 }
935 } 919 }
@@ -1013,13 +997,9 @@ static void usa90_indat_callback(struct urb *urb)
1013 997
1014 /* Resubmit urb so we continue receiving */ 998 /* Resubmit urb so we continue receiving */
1015 urb->dev = port->serial->dev; 999 urb->dev = port->serial->dev;
1016 if (port->port.count) { 1000 err = usb_submit_urb(urb, GFP_ATOMIC);
1017 err = usb_submit_urb(urb, GFP_ATOMIC); 1001 if (err != 0)
1018 if (err != 0) 1002 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1019 dbg("%s - resubmit read urb failed. (%d)",
1020 __func__, err);
1021 }
1022 return;
1023} 1003}
1024 1004
1025 1005
@@ -2418,8 +2398,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
2418 msg.portEnabled = 0; 2398 msg.portEnabled = 0;
2419 /* Sending intermediate configs */ 2399 /* Sending intermediate configs */
2420 else { 2400 else {
2421 if (port->port.count) 2401 msg.portEnabled = 1;
2422 msg.portEnabled = 1;
2423 msg.txBreak = (p_priv->break_on); 2402 msg.txBreak = (p_priv->break_on);
2424 } 2403 }
2425 2404
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index 30771e5b3973..bf3297ddd186 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -456,7 +456,7 @@ static const struct keyspan_device_details *keyspan_devices[] = {
456 NULL, 456 NULL,
457}; 457};
458 458
459static struct usb_device_id keyspan_ids_combined[] = { 459static const struct usb_device_id keyspan_ids_combined[] = {
460 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) }, 460 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
461 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) }, 461 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
462 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) }, 462 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19w_pre_product_id) },
@@ -497,7 +497,7 @@ static struct usb_driver keyspan_driver = {
497}; 497};
498 498
499/* usb_device_id table for the pre-firmware download keyspan devices */ 499/* usb_device_id table for the pre-firmware download keyspan devices */
500static struct usb_device_id keyspan_pre_ids[] = { 500static const struct usb_device_id keyspan_pre_ids[] = {
501 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) }, 501 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_pre_product_id) },
502 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) }, 502 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_pre_product_id) },
503 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) }, 503 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_pre_product_id) },
@@ -513,7 +513,7 @@ static struct usb_device_id keyspan_pre_ids[] = {
513 { } /* Terminating entry */ 513 { } /* Terminating entry */
514}; 514};
515 515
516static struct usb_device_id keyspan_1port_ids[] = { 516static const struct usb_device_id keyspan_1port_ids[] = {
517 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) }, 517 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa18x_product_id) },
518 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) }, 518 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19_product_id) },
519 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) }, 519 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa19qi_product_id) },
@@ -524,7 +524,7 @@ static struct usb_device_id keyspan_1port_ids[] = {
524 { } /* Terminating entry */ 524 { } /* Terminating entry */
525}; 525};
526 526
527static struct usb_device_id keyspan_2port_ids[] = { 527static const struct usb_device_id keyspan_2port_ids[] = {
528 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) }, 528 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28_product_id) },
529 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) }, 529 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28x_product_id) },
530 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) }, 530 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa28xa_product_id) },
@@ -532,7 +532,7 @@ static struct usb_device_id keyspan_2port_ids[] = {
532 { } /* Terminating entry */ 532 { } /* Terminating entry */
533}; 533};
534 534
535static struct usb_device_id keyspan_4port_ids[] = { 535static const struct usb_device_id keyspan_4port_ids[] = {
536 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id) }, 536 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49w_product_id) },
537 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)}, 537 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wlc_product_id)},
538 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)}, 538 { USB_DEVICE(KEYSPAN_VENDOR_ID, keyspan_usa49wg_product_id)},
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 1296a097f5c3..185fe9a7d4e0 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -125,7 +125,7 @@ struct keyspan_pda_private {
125#define ENTREGRA_VENDOR_ID 0x1645 125#define ENTREGRA_VENDOR_ID 0x1645
126#define ENTREGRA_FAKE_ID 0x8093 126#define ENTREGRA_FAKE_ID 0x8093
127 127
128static struct usb_device_id id_table_combined [] = { 128static const struct usb_device_id id_table_combined[] = {
129#ifdef KEYSPAN 129#ifdef KEYSPAN
130 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) }, 130 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
131#endif 131#endif
@@ -147,20 +147,20 @@ static struct usb_driver keyspan_pda_driver = {
147 .no_dynamic_id = 1, 147 .no_dynamic_id = 1,
148}; 148};
149 149
150static struct usb_device_id id_table_std [] = { 150static const struct usb_device_id id_table_std[] = {
151 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) }, 151 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
152 { } /* Terminating entry */ 152 { } /* Terminating entry */
153}; 153};
154 154
155#ifdef KEYSPAN 155#ifdef KEYSPAN
156static struct usb_device_id id_table_fake [] = { 156static const struct usb_device_id id_table_fake[] = {
157 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) }, 157 { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
158 { } /* Terminating entry */ 158 { } /* Terminating entry */
159}; 159};
160#endif 160#endif
161 161
162#ifdef XIRCOM 162#ifdef XIRCOM
163static struct usb_device_id id_table_fake_xircom [] = { 163static const struct usb_device_id id_table_fake_xircom[] = {
164 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, 164 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
165 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) }, 165 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
166 { } 166 { }
@@ -429,13 +429,20 @@ static int keyspan_pda_get_modem_info(struct usb_serial *serial,
429 unsigned char *value) 429 unsigned char *value)
430{ 430{
431 int rc; 431 int rc;
432 unsigned char data; 432 u8 *data;
433
434 data = kmalloc(1, GFP_KERNEL);
435 if (!data)
436 return -ENOMEM;
437
433 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 438 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
434 3, /* get pins */ 439 3, /* get pins */
435 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN, 440 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
436 0, 0, &data, 1, 2000); 441 0, 0, data, 1, 2000);
437 if (rc >= 0) 442 if (rc >= 0)
438 *value = data; 443 *value = *data;
444
445 kfree(data);
439 return rc; 446 return rc;
440} 447}
441 448
@@ -543,7 +550,14 @@ static int keyspan_pda_write(struct tty_struct *tty,
543 device how much room it really has. This is done only on 550 device how much room it really has. This is done only on
544 scheduler time, since usb_control_msg() sleeps. */ 551 scheduler time, since usb_control_msg() sleeps. */
545 if (count > priv->tx_room && !in_interrupt()) { 552 if (count > priv->tx_room && !in_interrupt()) {
546 unsigned char room; 553 u8 *room;
554
555 room = kmalloc(1, GFP_KERNEL);
556 if (!room) {
557 rc = -ENOMEM;
558 goto exit;
559 }
560
547 rc = usb_control_msg(serial->dev, 561 rc = usb_control_msg(serial->dev,
548 usb_rcvctrlpipe(serial->dev, 0), 562 usb_rcvctrlpipe(serial->dev, 0),
549 6, /* write_room */ 563 6, /* write_room */
@@ -551,9 +565,14 @@ static int keyspan_pda_write(struct tty_struct *tty,
551 | USB_DIR_IN, 565 | USB_DIR_IN,
552 0, /* value: 0 means "remaining room" */ 566 0, /* value: 0 means "remaining room" */
553 0, /* index */ 567 0, /* index */
554 &room, 568 room,
555 1, 569 1,
556 2000); 570 2000);
571 if (rc > 0) {
572 dbg(" roomquery says %d", *room);
573 priv->tx_room = *room;
574 }
575 kfree(room);
557 if (rc < 0) { 576 if (rc < 0) {
558 dbg(" roomquery failed"); 577 dbg(" roomquery failed");
559 goto exit; 578 goto exit;
@@ -563,8 +582,6 @@ static int keyspan_pda_write(struct tty_struct *tty,
563 rc = -EIO; /* device didn't return any data */ 582 rc = -EIO; /* device didn't return any data */
564 goto exit; 583 goto exit;
565 } 584 }
566 dbg(" roomquery says %d", room);
567 priv->tx_room = room;
568 } 585 }
569 if (count > priv->tx_room) { 586 if (count > priv->tx_room) {
570 /* we're about to completely fill the Tx buffer, so 587 /* we're about to completely fill the Tx buffer, so
@@ -684,18 +701,22 @@ static int keyspan_pda_open(struct tty_struct *tty,
684 struct usb_serial_port *port) 701 struct usb_serial_port *port)
685{ 702{
686 struct usb_serial *serial = port->serial; 703 struct usb_serial *serial = port->serial;
687 unsigned char room; 704 u8 *room;
688 int rc = 0; 705 int rc = 0;
689 struct keyspan_pda_private *priv; 706 struct keyspan_pda_private *priv;
690 707
691 /* find out how much room is in the Tx ring */ 708 /* find out how much room is in the Tx ring */
709 room = kmalloc(1, GFP_KERNEL);
710 if (!room)
711 return -ENOMEM;
712
692 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 713 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
693 6, /* write_room */ 714 6, /* write_room */
694 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 715 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
695 | USB_DIR_IN, 716 | USB_DIR_IN,
696 0, /* value */ 717 0, /* value */
697 0, /* index */ 718 0, /* index */
698 &room, 719 room,
699 1, 720 1,
700 2000); 721 2000);
701 if (rc < 0) { 722 if (rc < 0) {
@@ -708,8 +729,8 @@ static int keyspan_pda_open(struct tty_struct *tty,
708 goto error; 729 goto error;
709 } 730 }
710 priv = usb_get_serial_port_data(port); 731 priv = usb_get_serial_port_data(port);
711 priv->tx_room = room; 732 priv->tx_room = *room;
712 priv->tx_throttled = room ? 0 : 1; 733 priv->tx_throttled = *room ? 0 : 1;
713 734
714 /*Start reading from the device*/ 735 /*Start reading from the device*/
715 port->interrupt_in_urb->dev = serial->dev; 736 port->interrupt_in_urb->dev = serial->dev;
@@ -718,8 +739,8 @@ static int keyspan_pda_open(struct tty_struct *tty,
718 dbg("%s - usb_submit_urb(read int) failed", __func__); 739 dbg("%s - usb_submit_urb(read int) failed", __func__);
719 goto error; 740 goto error;
720 } 741 }
721
722error: 742error:
743 kfree(room);
723 return rc; 744 return rc;
724} 745}
725static void keyspan_pda_close(struct usb_serial_port *port) 746static void keyspan_pda_close(struct usb_serial_port *port)
@@ -789,6 +810,13 @@ static int keyspan_pda_fake_startup(struct usb_serial *serial)
789 return 1; 810 return 1;
790} 811}
791 812
813#ifdef KEYSPAN
814MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
815#endif
816#ifdef XIRCOM
817MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
818#endif
819
792static int keyspan_pda_startup(struct usb_serial *serial) 820static int keyspan_pda_startup(struct usb_serial *serial)
793{ 821{
794 822
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 3a7873806f46..8eef91ba4b1c 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -94,7 +94,7 @@ static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
94/* 94/*
95 * All of the device info needed for the KLSI converters. 95 * All of the device info needed for the KLSI converters.
96 */ 96 */
97static struct usb_device_id id_table [] = { 97static const struct usb_device_id id_table[] = {
98 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) }, 98 { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
99 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) }, 99 { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
100 { } /* Terminating entry */ 100 { } /* Terminating entry */
@@ -212,10 +212,19 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
212 unsigned long *line_state_p) 212 unsigned long *line_state_p)
213{ 213{
214 int rc; 214 int rc;
215 __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1}; 215 u8 *status_buf;
216 __u16 status; 216 __u16 status;
217 217
218 dev_info(&port->serial->dev->dev, "sending SIO Poll request\n"); 218 dev_info(&port->serial->dev->dev, "sending SIO Poll request\n");
219
220 status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL);
221 if (!status_buf) {
222 dev_err(&port->dev, "%s - out of memory for status buffer.\n",
223 __func__);
224 return -ENOMEM;
225 }
226 status_buf[0] = 0xff;
227 status_buf[1] = 0xff;
219 rc = usb_control_msg(port->serial->dev, 228 rc = usb_control_msg(port->serial->dev,
220 usb_rcvctrlpipe(port->serial->dev, 0), 229 usb_rcvctrlpipe(port->serial->dev, 0),
221 KL5KUSB105A_SIO_POLL, 230 KL5KUSB105A_SIO_POLL,
@@ -236,6 +245,8 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
236 245
237 *line_state_p = klsi_105_status2linestate(status); 246 *line_state_p = klsi_105_status2linestate(status);
238 } 247 }
248
249 kfree(status_buf);
239 return rc; 250 return rc;
240} 251}
241 252
@@ -364,7 +375,7 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
364 int rc; 375 int rc;
365 int i; 376 int i;
366 unsigned long line_state; 377 unsigned long line_state;
367 struct klsi_105_port_settings cfg; 378 struct klsi_105_port_settings *cfg;
368 unsigned long flags; 379 unsigned long flags;
369 380
370 dbg("%s port %d", __func__, port->number); 381 dbg("%s port %d", __func__, port->number);
@@ -376,12 +387,18 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
376 * Then read the modem line control and store values in 387 * Then read the modem line control and store values in
377 * priv->line_state. 388 * priv->line_state.
378 */ 389 */
379 cfg.pktlen = 5; 390 cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
380 cfg.baudrate = kl5kusb105a_sio_b9600; 391 if (!cfg) {
381 cfg.databits = kl5kusb105a_dtb_8; 392 dev_err(&port->dev, "%s - out of memory for config buffer.\n",
382 cfg.unknown1 = 0; 393 __func__);
383 cfg.unknown2 = 1; 394 return -ENOMEM;
384 klsi_105_chg_port_settings(port, &cfg); 395 }
396 cfg->pktlen = 5;
397 cfg->baudrate = kl5kusb105a_sio_b9600;
398 cfg->databits = kl5kusb105a_dtb_8;
399 cfg->unknown1 = 0;
400 cfg->unknown2 = 1;
401 klsi_105_chg_port_settings(port, cfg);
385 402
386 /* set up termios structure */ 403 /* set up termios structure */
387 spin_lock_irqsave(&priv->lock, flags); 404 spin_lock_irqsave(&priv->lock, flags);
@@ -391,11 +408,11 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
391 priv->termios.c_lflag = tty->termios->c_lflag; 408 priv->termios.c_lflag = tty->termios->c_lflag;
392 for (i = 0; i < NCCS; i++) 409 for (i = 0; i < NCCS; i++)
393 priv->termios.c_cc[i] = tty->termios->c_cc[i]; 410 priv->termios.c_cc[i] = tty->termios->c_cc[i];
394 priv->cfg.pktlen = cfg.pktlen; 411 priv->cfg.pktlen = cfg->pktlen;
395 priv->cfg.baudrate = cfg.baudrate; 412 priv->cfg.baudrate = cfg->baudrate;
396 priv->cfg.databits = cfg.databits; 413 priv->cfg.databits = cfg->databits;
397 priv->cfg.unknown1 = cfg.unknown1; 414 priv->cfg.unknown1 = cfg->unknown1;
398 priv->cfg.unknown2 = cfg.unknown2; 415 priv->cfg.unknown2 = cfg->unknown2;
399 spin_unlock_irqrestore(&priv->lock, flags); 416 spin_unlock_irqrestore(&priv->lock, flags);
400 417
401 /* READ_ON and urb submission */ 418 /* READ_ON and urb submission */
@@ -441,6 +458,7 @@ static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
441 retval = rc; 458 retval = rc;
442 459
443exit: 460exit:
461 kfree(cfg);
444 return retval; 462 return retval;
445} /* klsi_105_open */ 463} /* klsi_105_open */
446 464
@@ -681,7 +699,6 @@ static void klsi_105_read_bulk_callback(struct urb *urb)
681 bytes_sent = urb->actual_length - 2; 699 bytes_sent = urb->actual_length - 2;
682 } 700 }
683 701
684 tty_buffer_request_room(tty, bytes_sent);
685 tty_insert_flip_string(tty, data + 2, bytes_sent); 702 tty_insert_flip_string(tty, data + 2, bytes_sent);
686 tty_flip_buffer_push(tty); 703 tty_flip_buffer_push(tty);
687 tty_kref_put(tty); 704 tty_kref_put(tty);
@@ -714,10 +731,17 @@ static void klsi_105_set_termios(struct tty_struct *tty,
714 unsigned int old_iflag = old_termios->c_iflag; 731 unsigned int old_iflag = old_termios->c_iflag;
715 unsigned int cflag = tty->termios->c_cflag; 732 unsigned int cflag = tty->termios->c_cflag;
716 unsigned int old_cflag = old_termios->c_cflag; 733 unsigned int old_cflag = old_termios->c_cflag;
717 struct klsi_105_port_settings cfg; 734 struct klsi_105_port_settings *cfg;
718 unsigned long flags; 735 unsigned long flags;
719 speed_t baud; 736 speed_t baud;
720 737
738 cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
739 if (!cfg) {
740 dev_err(&port->dev, "%s - out of memory for config buffer.\n",
741 __func__);
742 return;
743 }
744
721 /* lock while we are modifying the settings */ 745 /* lock while we are modifying the settings */
722 spin_lock_irqsave(&priv->lock, flags); 746 spin_lock_irqsave(&priv->lock, flags);
723 747
@@ -793,11 +817,11 @@ static void klsi_105_set_termios(struct tty_struct *tty,
793 case CS5: 817 case CS5:
794 dbg("%s - 5 bits/byte not supported", __func__); 818 dbg("%s - 5 bits/byte not supported", __func__);
795 spin_unlock_irqrestore(&priv->lock, flags); 819 spin_unlock_irqrestore(&priv->lock, flags);
796 return ; 820 goto err;
797 case CS6: 821 case CS6:
798 dbg("%s - 6 bits/byte not supported", __func__); 822 dbg("%s - 6 bits/byte not supported", __func__);
799 spin_unlock_irqrestore(&priv->lock, flags); 823 spin_unlock_irqrestore(&priv->lock, flags);
800 return ; 824 goto err;
801 case CS7: 825 case CS7:
802 priv->cfg.databits = kl5kusb105a_dtb_7; 826 priv->cfg.databits = kl5kusb105a_dtb_7;
803 break; 827 break;
@@ -856,11 +880,13 @@ static void klsi_105_set_termios(struct tty_struct *tty,
856#endif 880#endif
857 ; 881 ;
858 } 882 }
859 memcpy(&cfg, &priv->cfg, sizeof(cfg)); 883 memcpy(cfg, &priv->cfg, sizeof(*cfg));
860 spin_unlock_irqrestore(&priv->lock, flags); 884 spin_unlock_irqrestore(&priv->lock, flags);
861 885
862 /* now commit changes to device */ 886 /* now commit changes to device */
863 klsi_105_chg_port_settings(port, &cfg); 887 klsi_105_chg_port_settings(port, cfg);
888err:
889 kfree(cfg);
864} /* klsi_105_set_termios */ 890} /* klsi_105_set_termios */
865 891
866 892
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 45ea694b3ae6..c113a2a0e10c 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -86,7 +86,7 @@ static void kobil_set_termios(struct tty_struct *tty,
86 struct usb_serial_port *port, struct ktermios *old); 86 struct usb_serial_port *port, struct ktermios *old);
87static void kobil_init_termios(struct tty_struct *tty); 87static void kobil_init_termios(struct tty_struct *tty);
88 88
89static struct usb_device_id id_table [] = { 89static const struct usb_device_id id_table[] = {
90 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) }, 90 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_B_PRODUCT_ID) },
91 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_K_PRODUCT_ID) }, 91 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_ADAPTER_K_PRODUCT_ID) },
92 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_USBTWIN_PRODUCT_ID) }, 92 { USB_DEVICE(KOBIL_VENDOR_ID, KOBIL_USBTWIN_PRODUCT_ID) },
@@ -388,7 +388,6 @@ static void kobil_read_int_callback(struct urb *urb)
388 */ 388 */
389 /* END DEBUG */ 389 /* END DEBUG */
390 390
391 tty_buffer_request_room(tty, urb->actual_length);
392 tty_insert_flip_string(tty, data, urb->actual_length); 391 tty_insert_flip_string(tty, data, urb->actual_length);
393 tty_flip_buffer_push(tty); 392 tty_flip_buffer_push(tty);
394 } 393 }
@@ -624,7 +623,6 @@ static void kobil_set_termios(struct tty_struct *tty,
624 unsigned short urb_val = 0; 623 unsigned short urb_val = 0;
625 int c_cflag = tty->termios->c_cflag; 624 int c_cflag = tty->termios->c_cflag;
626 speed_t speed; 625 speed_t speed;
627 void *settings;
628 626
629 priv = usb_get_serial_port_data(port); 627 priv = usb_get_serial_port_data(port);
630 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID || 628 if (priv->device_type == KOBIL_USBTWIN_PRODUCT_ID ||
@@ -647,25 +645,13 @@ static void kobil_set_termios(struct tty_struct *tty,
647 } 645 }
648 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits : 646 urb_val |= (c_cflag & CSTOPB) ? SUSBCR_SPASB_2StopBits :
649 SUSBCR_SPASB_1StopBit; 647 SUSBCR_SPASB_1StopBit;
650
651 settings = kzalloc(50, GFP_KERNEL);
652 if (!settings)
653 return;
654
655 sprintf(settings, "%d ", speed);
656
657 if (c_cflag & PARENB) { 648 if (c_cflag & PARENB) {
658 if (c_cflag & PARODD) { 649 if (c_cflag & PARODD)
659 urb_val |= SUSBCR_SPASB_OddParity; 650 urb_val |= SUSBCR_SPASB_OddParity;
660 strcat(settings, "Odd Parity"); 651 else
661 } else {
662 urb_val |= SUSBCR_SPASB_EvenParity; 652 urb_val |= SUSBCR_SPASB_EvenParity;
663 strcat(settings, "Even Parity"); 653 } else
664 }
665 } else {
666 urb_val |= SUSBCR_SPASB_NoParity; 654 urb_val |= SUSBCR_SPASB_NoParity;
667 strcat(settings, "No Parity");
668 }
669 tty->termios->c_cflag &= ~CMSPAR; 655 tty->termios->c_cflag &= ~CMSPAR;
670 tty_encode_baud_rate(tty, speed, speed); 656 tty_encode_baud_rate(tty, speed, speed);
671 657
@@ -675,11 +661,10 @@ static void kobil_set_termios(struct tty_struct *tty,
675 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT, 661 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT | USB_DIR_OUT,
676 urb_val, 662 urb_val,
677 0, 663 0,
678 settings, 664 NULL,
679 0, 665 0,
680 KOBIL_TIMEOUT 666 KOBIL_TIMEOUT
681 ); 667 );
682 kfree(settings);
683} 668}
684 669
685static int kobil_ioctl(struct tty_struct *tty, struct file *file, 670static int kobil_ioctl(struct tty_struct *tty, struct file *file,
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index cd009cb280a5..2849f8c32015 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -75,6 +75,7 @@
75#include <linux/module.h> 75#include <linux/module.h>
76#include <linux/spinlock.h> 76#include <linux/spinlock.h>
77#include <linux/uaccess.h> 77#include <linux/uaccess.h>
78#include <asm/unaligned.h>
78#include <linux/usb.h> 79#include <linux/usb.h>
79#include <linux/usb/serial.h> 80#include <linux/usb/serial.h>
80#include "mct_u232.h" 81#include "mct_u232.h"
@@ -110,7 +111,7 @@ static void mct_u232_unthrottle(struct tty_struct *tty);
110/* 111/*
111 * All of the device info needed for the MCT USB-RS232 converter. 112 * All of the device info needed for the MCT USB-RS232 converter.
112 */ 113 */
113static struct usb_device_id id_table_combined [] = { 114static const struct usb_device_id id_table_combined[] = {
114 { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) }, 115 { USB_DEVICE(MCT_U232_VID, MCT_U232_PID) },
115 { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) }, 116 { USB_DEVICE(MCT_U232_VID, MCT_U232_SITECOM_PID) },
116 { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) }, 117 { USB_DEVICE(MCT_U232_VID, MCT_U232_DU_H3SP_PID) },
@@ -231,19 +232,22 @@ static int mct_u232_calculate_baud_rate(struct usb_serial *serial,
231static int mct_u232_set_baud_rate(struct tty_struct *tty, 232static int mct_u232_set_baud_rate(struct tty_struct *tty,
232 struct usb_serial *serial, struct usb_serial_port *port, speed_t value) 233 struct usb_serial *serial, struct usb_serial_port *port, speed_t value)
233{ 234{
234 __le32 divisor; 235 unsigned int divisor;
235 int rc; 236 int rc;
236 unsigned char zero_byte = 0; 237 unsigned char *buf;
237 unsigned char cts_enable_byte = 0; 238 unsigned char cts_enable_byte = 0;
238 speed_t speed; 239 speed_t speed;
239 240
240 divisor = cpu_to_le32(mct_u232_calculate_baud_rate(serial, value, 241 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
241 &speed)); 242 if (buf == NULL)
243 return -ENOMEM;
242 244
245 divisor = mct_u232_calculate_baud_rate(serial, value, &speed);
246 put_unaligned_le32(cpu_to_le32(divisor), buf);
243 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 247 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
244 MCT_U232_SET_BAUD_RATE_REQUEST, 248 MCT_U232_SET_BAUD_RATE_REQUEST,
245 MCT_U232_SET_REQUEST_TYPE, 249 MCT_U232_SET_REQUEST_TYPE,
246 0, 0, &divisor, MCT_U232_SET_BAUD_RATE_SIZE, 250 0, 0, buf, MCT_U232_SET_BAUD_RATE_SIZE,
247 WDR_TIMEOUT); 251 WDR_TIMEOUT);
248 if (rc < 0) /*FIXME: What value speed results */ 252 if (rc < 0) /*FIXME: What value speed results */
249 dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n", 253 dev_err(&port->dev, "Set BAUD RATE %d failed (error = %d)\n",
@@ -269,10 +273,11 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
269 a device which is not asserting 'CTS'. 273 a device which is not asserting 'CTS'.
270 */ 274 */
271 275
276 buf[0] = 0;
272 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 277 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
273 MCT_U232_SET_UNKNOWN1_REQUEST, 278 MCT_U232_SET_UNKNOWN1_REQUEST,
274 MCT_U232_SET_REQUEST_TYPE, 279 MCT_U232_SET_REQUEST_TYPE,
275 0, 0, &zero_byte, MCT_U232_SET_UNKNOWN1_SIZE, 280 0, 0, buf, MCT_U232_SET_UNKNOWN1_SIZE,
276 WDR_TIMEOUT); 281 WDR_TIMEOUT);
277 if (rc < 0) 282 if (rc < 0)
278 dev_err(&port->dev, "Sending USB device request code %d " 283 dev_err(&port->dev, "Sending USB device request code %d "
@@ -284,30 +289,40 @@ static int mct_u232_set_baud_rate(struct tty_struct *tty,
284 289
285 dbg("set_baud_rate: send second control message, data = %02X", 290 dbg("set_baud_rate: send second control message, data = %02X",
286 cts_enable_byte); 291 cts_enable_byte);
292 buf[0] = cts_enable_byte;
287 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 293 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
288 MCT_U232_SET_CTS_REQUEST, 294 MCT_U232_SET_CTS_REQUEST,
289 MCT_U232_SET_REQUEST_TYPE, 295 MCT_U232_SET_REQUEST_TYPE,
290 0, 0, &cts_enable_byte, MCT_U232_SET_CTS_SIZE, 296 0, 0, buf, MCT_U232_SET_CTS_SIZE,
291 WDR_TIMEOUT); 297 WDR_TIMEOUT);
292 if (rc < 0) 298 if (rc < 0)
293 dev_err(&port->dev, "Sending USB device request code %d " 299 dev_err(&port->dev, "Sending USB device request code %d "
294 "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc); 300 "failed (error = %d)\n", MCT_U232_SET_CTS_REQUEST, rc);
295 301
302 kfree(buf);
296 return rc; 303 return rc;
297} /* mct_u232_set_baud_rate */ 304} /* mct_u232_set_baud_rate */
298 305
299static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr) 306static int mct_u232_set_line_ctrl(struct usb_serial *serial, unsigned char lcr)
300{ 307{
301 int rc; 308 int rc;
309 unsigned char *buf;
310
311 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
312 if (buf == NULL)
313 return -ENOMEM;
314
315 buf[0] = lcr;
302 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 316 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
303 MCT_U232_SET_LINE_CTRL_REQUEST, 317 MCT_U232_SET_LINE_CTRL_REQUEST,
304 MCT_U232_SET_REQUEST_TYPE, 318 MCT_U232_SET_REQUEST_TYPE,
305 0, 0, &lcr, MCT_U232_SET_LINE_CTRL_SIZE, 319 0, 0, buf, MCT_U232_SET_LINE_CTRL_SIZE,
306 WDR_TIMEOUT); 320 WDR_TIMEOUT);
307 if (rc < 0) 321 if (rc < 0)
308 dev_err(&serial->dev->dev, 322 dev_err(&serial->dev->dev,
309 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc); 323 "Set LINE CTRL 0x%x failed (error = %d)\n", lcr, rc);
310 dbg("set_line_ctrl: 0x%x", lcr); 324 dbg("set_line_ctrl: 0x%x", lcr);
325 kfree(buf);
311 return rc; 326 return rc;
312} /* mct_u232_set_line_ctrl */ 327} /* mct_u232_set_line_ctrl */
313 328
@@ -315,23 +330,31 @@ static int mct_u232_set_modem_ctrl(struct usb_serial *serial,
315 unsigned int control_state) 330 unsigned int control_state)
316{ 331{
317 int rc; 332 int rc;
318 unsigned char mcr = MCT_U232_MCR_NONE; 333 unsigned char mcr;
334 unsigned char *buf;
335
336 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
337 if (buf == NULL)
338 return -ENOMEM;
319 339
340 mcr = MCT_U232_MCR_NONE;
320 if (control_state & TIOCM_DTR) 341 if (control_state & TIOCM_DTR)
321 mcr |= MCT_U232_MCR_DTR; 342 mcr |= MCT_U232_MCR_DTR;
322 if (control_state & TIOCM_RTS) 343 if (control_state & TIOCM_RTS)
323 mcr |= MCT_U232_MCR_RTS; 344 mcr |= MCT_U232_MCR_RTS;
324 345
346 buf[0] = mcr;
325 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 347 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
326 MCT_U232_SET_MODEM_CTRL_REQUEST, 348 MCT_U232_SET_MODEM_CTRL_REQUEST,
327 MCT_U232_SET_REQUEST_TYPE, 349 MCT_U232_SET_REQUEST_TYPE,
328 0, 0, &mcr, MCT_U232_SET_MODEM_CTRL_SIZE, 350 0, 0, buf, MCT_U232_SET_MODEM_CTRL_SIZE,
329 WDR_TIMEOUT); 351 WDR_TIMEOUT);
330 if (rc < 0) 352 if (rc < 0)
331 dev_err(&serial->dev->dev, 353 dev_err(&serial->dev->dev,
332 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc); 354 "Set MODEM CTRL 0x%x failed (error = %d)\n", mcr, rc);
333 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr); 355 dbg("set_modem_ctrl: state=0x%x ==> mcr=0x%x", control_state, mcr);
334 356
357 kfree(buf);
335 return rc; 358 return rc;
336} /* mct_u232_set_modem_ctrl */ 359} /* mct_u232_set_modem_ctrl */
337 360
@@ -339,17 +362,27 @@ static int mct_u232_get_modem_stat(struct usb_serial *serial,
339 unsigned char *msr) 362 unsigned char *msr)
340{ 363{
341 int rc; 364 int rc;
365 unsigned char *buf;
366
367 buf = kmalloc(MCT_U232_MAX_SIZE, GFP_KERNEL);
368 if (buf == NULL) {
369 *msr = 0;
370 return -ENOMEM;
371 }
342 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 372 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
343 MCT_U232_GET_MODEM_STAT_REQUEST, 373 MCT_U232_GET_MODEM_STAT_REQUEST,
344 MCT_U232_GET_REQUEST_TYPE, 374 MCT_U232_GET_REQUEST_TYPE,
345 0, 0, msr, MCT_U232_GET_MODEM_STAT_SIZE, 375 0, 0, buf, MCT_U232_GET_MODEM_STAT_SIZE,
346 WDR_TIMEOUT); 376 WDR_TIMEOUT);
347 if (rc < 0) { 377 if (rc < 0) {
348 dev_err(&serial->dev->dev, 378 dev_err(&serial->dev->dev,
349 "Get MODEM STATus failed (error = %d)\n", rc); 379 "Get MODEM STATus failed (error = %d)\n", rc);
350 *msr = 0; 380 *msr = 0;
381 } else {
382 *msr = buf[0];
351 } 383 }
352 dbg("get_modem_stat: 0x%x", *msr); 384 dbg("get_modem_stat: 0x%x", *msr);
385 kfree(buf);
353 return rc; 386 return rc;
354} /* mct_u232_get_modem_stat */ 387} /* mct_u232_get_modem_stat */
355 388
diff --git a/drivers/usb/serial/mct_u232.h b/drivers/usb/serial/mct_u232.h
index 07b6bec31dc8..7417d5ce1e23 100644
--- a/drivers/usb/serial/mct_u232.h
+++ b/drivers/usb/serial/mct_u232.h
@@ -73,6 +73,8 @@
73#define MCT_U232_SET_CTS_REQUEST 12 73#define MCT_U232_SET_CTS_REQUEST 12
74#define MCT_U232_SET_CTS_SIZE 1 74#define MCT_U232_SET_CTS_SIZE 1
75 75
76#define MCT_U232_MAX_SIZE 4 /* of MCT_XXX_SIZE */
77
76/* 78/*
77 * Baud rate (divisor) 79 * Baud rate (divisor)
78 * Actually, there are two of them, MCT website calls them "Philips solution" 80 * Actually, there are two of them, MCT website calls them "Philips solution"
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 763e32a44be0..0d47f2c4d59f 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -81,12 +81,15 @@ struct moschip_serial {
81 81
82static int debug; 82static int debug;
83 83
84static struct usb_serial_driver moschip7720_2port_driver;
85
84#define USB_VENDOR_ID_MOSCHIP 0x9710 86#define USB_VENDOR_ID_MOSCHIP 0x9710
85#define MOSCHIP_DEVICE_ID_7720 0x7720 87#define MOSCHIP_DEVICE_ID_7720 0x7720
86#define MOSCHIP_DEVICE_ID_7715 0x7715 88#define MOSCHIP_DEVICE_ID_7715 0x7715
87 89
88static struct usb_device_id moschip_port_id_table[] = { 90static const struct usb_device_id moschip_port_id_table[] = {
89 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) }, 91 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) },
92 { USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7715) },
90 { } /* terminating entry */ 93 { } /* terminating entry */
91}; 94};
92MODULE_DEVICE_TABLE(usb, moschip_port_id_table); 95MODULE_DEVICE_TABLE(usb, moschip_port_id_table);
@@ -106,7 +109,7 @@ static void mos7720_interrupt_callback(struct urb *urb)
106 __u8 sp1; 109 __u8 sp1;
107 __u8 sp2; 110 __u8 sp2;
108 111
109 dbg("%s", " : Entering\n"); 112 dbg(" : Entering");
110 113
111 switch (status) { 114 switch (status) {
112 case 0: 115 case 0:
@@ -186,6 +189,75 @@ exit:
186} 189}
187 190
188/* 191/*
192 * mos7715_interrupt_callback
193 * this is the 7715's callback function for when we have received data on
194 * the interrupt endpoint.
195 */
196static void mos7715_interrupt_callback(struct urb *urb)
197{
198 int result;
199 int length;
200 int status = urb->status;
201 __u8 *data;
202 __u8 iir;
203
204 switch (status) {
205 case 0:
206 /* success */
207 break;
208 case -ECONNRESET:
209 case -ENOENT:
210 case -ESHUTDOWN:
211 /* this urb is terminated, clean up */
212 dbg("%s - urb shutting down with status: %d", __func__,
213 status);
214 return;
215 default:
216 dbg("%s - nonzero urb status received: %d", __func__,
217 status);
218 goto exit;
219 }
220
221 length = urb->actual_length;
222 data = urb->transfer_buffer;
223
224 /* Structure of data from 7715 device:
225 * Byte 1: IIR serial Port
226 * Byte 2: unused
227 * Byte 2: DSR parallel port
228 * Byte 4: FIFO status for both */
229
230 if (unlikely(length != 4)) {
231 dbg("Wrong data !!!");
232 return;
233 }
234
235 iir = data[0];
236 if (!(iir & 0x01)) { /* serial port interrupt pending */
237 switch (iir & 0x0f) {
238 case SERIAL_IIR_RLS:
239 dbg("Serial Port: Receiver status error or address "
240 "bit detected in 9-bit mode\n");
241 break;
242 case SERIAL_IIR_CTI:
243 dbg("Serial Port: Receiver time out");
244 break;
245 case SERIAL_IIR_MS:
246 dbg("Serial Port: Modem status change");
247 break;
248 }
249 }
250
251exit:
252 result = usb_submit_urb(urb, GFP_ATOMIC);
253 if (result)
254 dev_err(&urb->dev->dev,
255 "%s - Error %d submitting control urb\n",
256 __func__, result);
257 return;
258}
259
260/*
189 * mos7720_bulk_in_callback 261 * mos7720_bulk_in_callback
190 * this is the callback function for when we have received data on the 262 * this is the callback function for when we have received data on the
191 * bulk in endpoint. 263 * bulk in endpoint.
@@ -206,7 +278,7 @@ static void mos7720_bulk_in_callback(struct urb *urb)
206 278
207 mos7720_port = urb->context; 279 mos7720_port = urb->context;
208 if (!mos7720_port) { 280 if (!mos7720_port) {
209 dbg("%s", "NULL mos7720_port pointer \n"); 281 dbg("NULL mos7720_port pointer");
210 return ; 282 return ;
211 } 283 }
212 284
@@ -218,7 +290,6 @@ static void mos7720_bulk_in_callback(struct urb *urb)
218 290
219 tty = tty_port_tty_get(&port->port); 291 tty = tty_port_tty_get(&port->port);
220 if (tty && urb->actual_length) { 292 if (tty && urb->actual_length) {
221 tty_buffer_request_room(tty, urb->actual_length);
222 tty_insert_flip_string(tty, data, urb->actual_length); 293 tty_insert_flip_string(tty, data, urb->actual_length);
223 tty_flip_buffer_push(tty); 294 tty_flip_buffer_push(tty);
224 } 295 }
@@ -275,17 +346,15 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
275 * this function will be used for sending command to device 346 * this function will be used for sending command to device
276 */ 347 */
277static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value, 348static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
278 __u16 index, void *data) 349 __u16 index, u8 *data)
279{ 350{
280 int status; 351 int status;
281 unsigned int pipe; 352 u8 *buf;
282 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 353 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
283 __u8 requesttype;
284 __u16 size = 0x0000;
285 354
286 if (value < MOS_MAX_PORT) { 355 if (value < MOS_MAX_PORT) {
287 if (product == MOSCHIP_DEVICE_ID_7715) 356 if (product == MOSCHIP_DEVICE_ID_7715)
288 value = value*0x100+0x100; 357 value = 0x0200; /* identifies the 7715's serial port */
289 else 358 else
290 value = value*0x100+0x200; 359 value = value*0x100+0x200;
291 } else { 360 } else {
@@ -298,27 +367,58 @@ static int send_mos_cmd(struct usb_serial *serial, __u8 request, __u16 value,
298 } 367 }
299 368
300 if (request == MOS_WRITE) { 369 if (request == MOS_WRITE) {
301 request = (__u8)MOS_WRITE; 370 value = value + *data;
302 requesttype = (__u8)0x40; 371 status = usb_control_msg(serial->dev,
303 value = value + (__u16)*((unsigned char *)data); 372 usb_sndctrlpipe(serial->dev, 0), MOS_WRITE,
304 data = NULL; 373 0x40, value, index, NULL, 0, MOS_WDR_TIMEOUT);
305 pipe = usb_sndctrlpipe(serial->dev, 0);
306 } else { 374 } else {
307 request = (__u8)MOS_READ; 375 buf = kmalloc(1, GFP_KERNEL);
308 requesttype = (__u8)0xC0; 376 if (!buf) {
309 size = 0x01; 377 status = -ENOMEM;
310 pipe = usb_rcvctrlpipe(serial->dev, 0); 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);
311 } 385 }
312 386out:
313 status = usb_control_msg(serial->dev, pipe, request, requesttype,
314 value, index, data, size, MOS_WDR_TIMEOUT);
315
316 if (status < 0) 387 if (status < 0)
317 dbg("Command Write failed Value %x index %x\n", value, index); 388 dbg("Command Write failed Value %x index %x", value, index);
318 389
319 return status; 390 return status;
320} 391}
321 392
393
394/*
395 * mos77xx_probe
396 * this function installs the appropriate read interrupt endpoint callback
397 * depending on whether the device is a 7720 or 7715, thus avoiding costly
398 * run-time checks in the high-frequency callback routine itself.
399 */
400static int mos77xx_probe(struct usb_serial *serial,
401 const struct usb_device_id *id)
402{
403 if (id->idProduct == MOSCHIP_DEVICE_ID_7715)
404 moschip7720_2port_driver.read_int_callback =
405 mos7715_interrupt_callback;
406 else
407 moschip7720_2port_driver.read_int_callback =
408 mos7720_interrupt_callback;
409
410 return 0;
411}
412
413static int mos77xx_calc_num_ports(struct usb_serial *serial)
414{
415 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
416 if (product == MOSCHIP_DEVICE_ID_7715)
417 return 1;
418
419 return 2;
420}
421
322static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port) 422static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
323{ 423{
324 struct usb_serial *serial; 424 struct usb_serial *serial;
@@ -390,7 +490,7 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
390 */ 490 */
391 port_number = port->number - port->serial->minor; 491 port_number = port->number - port->serial->minor;
392 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data); 492 send_mos_cmd(port->serial, MOS_READ, port_number, UART_LSR, &data);
393 dbg("SS::%p LSR:%x\n", mos7720_port, data); 493 dbg("SS::%p LSR:%x", mos7720_port, data);
394 494
395 dbg("Check:Sending Command .........."); 495 dbg("Check:Sending Command ..........");
396 496
@@ -729,7 +829,7 @@ static void mos7720_throttle(struct tty_struct *tty)
729 struct moschip_port *mos7720_port; 829 struct moschip_port *mos7720_port;
730 int status; 830 int status;
731 831
732 dbg("%s- port %d\n", __func__, port->number); 832 dbg("%s- port %d", __func__, port->number);
733 833
734 mos7720_port = usb_get_serial_port_data(port); 834 mos7720_port = usb_get_serial_port_data(port);
735 835
@@ -1208,7 +1308,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1208 return; 1308 return;
1209 } 1309 }
1210 1310
1211 dbg("%s\n", "setting termios - ASPIRE"); 1311 dbg("setting termios - ASPIRE");
1212 1312
1213 cflag = tty->termios->c_cflag; 1313 cflag = tty->termios->c_cflag;
1214 1314
@@ -1226,7 +1326,7 @@ static void mos7720_set_termios(struct tty_struct *tty,
1226 change_port_settings(tty, mos7720_port, old_termios); 1326 change_port_settings(tty, mos7720_port, old_termios);
1227 1327
1228 if (!port->read_urb) { 1328 if (!port->read_urb) {
1229 dbg("%s", "URB KILLED !!!!!\n"); 1329 dbg("URB KILLED !!!!!");
1230 return; 1330 return;
1231 } 1331 }
1232 1332
@@ -1495,6 +1595,7 @@ static int mos7720_startup(struct usb_serial *serial)
1495 struct usb_device *dev; 1595 struct usb_device *dev;
1496 int i; 1596 int i;
1497 char data; 1597 char data;
1598 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
1498 1599
1499 dbg("%s: Entering ..........", __func__); 1600 dbg("%s: Entering ..........", __func__);
1500 1601
@@ -1514,6 +1615,29 @@ static int mos7720_startup(struct usb_serial *serial)
1514 1615
1515 usb_set_serial_data(serial, mos7720_serial); 1616 usb_set_serial_data(serial, mos7720_serial);
1516 1617
1618 /*
1619 * 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
1621 * assumes both pairs are serial ports, we must engage in a bit of
1622 * subterfuge and swap the pointers for ports 0 and 1 in order to make
1623 * port 0 point to the serial port. However, both moschip devices use a
1624 * single interrupt-in endpoint for both ports (as mentioned a little
1625 * further down), and this endpoint was assigned to port 0. So after
1626 * the swap, we must copy the interrupt endpoint elements from port 1
1627 * (as newly assigned) to port 0, and null out port 1 pointers.
1628 */
1629 if (product == MOSCHIP_DEVICE_ID_7715) {
1630 struct usb_serial_port *tmp = serial->port[0];
1631 serial->port[0] = serial->port[1];
1632 serial->port[1] = tmp;
1633 serial->port[0]->interrupt_in_urb = tmp->interrupt_in_urb;
1634 serial->port[0]->interrupt_in_buffer = tmp->interrupt_in_buffer;
1635 serial->port[0]->interrupt_in_endpointAddress =
1636 tmp->interrupt_in_endpointAddress;
1637 serial->port[1]->interrupt_in_urb = NULL;
1638 serial->port[1]->interrupt_in_buffer = NULL;
1639 }
1640
1517 /* we set up the pointers to the endpoints in the mos7720_open * 1641 /* we set up the pointers to the endpoints in the mos7720_open *
1518 * function, as the structures aren't created yet. */ 1642 * function, as the structures aren't created yet. */
1519 1643
@@ -1529,7 +1653,7 @@ static int mos7720_startup(struct usb_serial *serial)
1529 1653
1530 /* Initialize all port interrupt end point to port 0 int 1654 /* Initialize all port interrupt end point to port 0 int
1531 * endpoint. Our device has only one interrupt endpoint 1655 * endpoint. Our device has only one interrupt endpoint
1532 * comman to all ports */ 1656 * common to all ports */
1533 serial->port[i]->interrupt_in_endpointAddress = 1657 serial->port[i]->interrupt_in_endpointAddress =
1534 serial->port[0]->interrupt_in_endpointAddress; 1658 serial->port[0]->interrupt_in_endpointAddress;
1535 1659
@@ -1584,11 +1708,12 @@ static struct usb_serial_driver moschip7720_2port_driver = {
1584 .description = "Moschip 2 port adapter", 1708 .description = "Moschip 2 port adapter",
1585 .usb_driver = &usb_driver, 1709 .usb_driver = &usb_driver,
1586 .id_table = moschip_port_id_table, 1710 .id_table = moschip_port_id_table,
1587 .num_ports = 2, 1711 .calc_num_ports = mos77xx_calc_num_ports,
1588 .open = mos7720_open, 1712 .open = mos7720_open,
1589 .close = mos7720_close, 1713 .close = mos7720_close,
1590 .throttle = mos7720_throttle, 1714 .throttle = mos7720_throttle,
1591 .unthrottle = mos7720_unthrottle, 1715 .unthrottle = mos7720_unthrottle,
1716 .probe = mos77xx_probe,
1592 .attach = mos7720_startup, 1717 .attach = mos7720_startup,
1593 .release = mos7720_release, 1718 .release = mos7720_release,
1594 .ioctl = mos7720_ioctl, 1719 .ioctl = mos7720_ioctl,
@@ -1600,7 +1725,7 @@ static struct usb_serial_driver moschip7720_2port_driver = {
1600 .chars_in_buffer = mos7720_chars_in_buffer, 1725 .chars_in_buffer = mos7720_chars_in_buffer,
1601 .break_ctl = mos7720_break, 1726 .break_ctl = mos7720_break,
1602 .read_bulk_callback = mos7720_bulk_in_callback, 1727 .read_bulk_callback = mos7720_bulk_in_callback,
1603 .read_int_callback = mos7720_interrupt_callback, 1728 .read_int_callback = NULL /* dynamically assigned in probe() */
1604}; 1729};
1605 1730
1606static int __init moschip7720_init(void) 1731static int __init moschip7720_init(void)
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index f11abf52be7d..2fda1c0182b7 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -121,8 +121,15 @@
121 * moschip_id_table_combined 121 * moschip_id_table_combined
122 */ 122 */
123#define USB_VENDOR_ID_BANDB 0x0856 123#define USB_VENDOR_ID_BANDB 0x0856
124#define BANDB_DEVICE_ID_USOPTL4_4 0xAC44 124#define BANDB_DEVICE_ID_USO9ML2_2 0xAC22
125#define BANDB_DEVICE_ID_USOPTL4_2 0xAC42 125#define BANDB_DEVICE_ID_USO9ML2_4 0xAC24
126#define BANDB_DEVICE_ID_US9ML2_2 0xAC29
127#define BANDB_DEVICE_ID_US9ML2_4 0xAC30
128#define BANDB_DEVICE_ID_USPTL4_2 0xAC31
129#define BANDB_DEVICE_ID_USPTL4_4 0xAC32
130#define BANDB_DEVICE_ID_USOPTL4_2 0xAC42
131#define BANDB_DEVICE_ID_USOPTL4_4 0xAC44
132#define BANDB_DEVICE_ID_USOPTL2_4 0xAC24
126 133
127/* This driver also supports 134/* This driver also supports
128 * ATEN UC2324 device using Moschip MCS7840 135 * ATEN UC2324 device using Moschip MCS7840
@@ -174,21 +181,35 @@
174#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */ 181#define URB_TRANSFER_BUFFER_SIZE 32 /* URB Size */
175 182
176 183
177static struct usb_device_id moschip_port_id_table[] = { 184static const struct usb_device_id moschip_port_id_table[] = {
178 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, 185 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
179 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, 186 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
180 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, 187 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
188 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
189 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
190 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
191 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
192 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
181 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, 193 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
194 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
195 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
182 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, 196 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
183 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, 197 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
184 {} /* terminating entry */ 198 {} /* terminating entry */
185}; 199};
186 200
187static __devinitdata struct usb_device_id moschip_id_table_combined[] = { 201static const struct usb_device_id moschip_id_table_combined[] __devinitconst = {
188 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)}, 202 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7840)},
189 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)}, 203 {USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7820)},
190 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)}, 204 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_2)},
205 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USO9ML2_4)},
206 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_2)},
207 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_US9ML2_4)},
208 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_2)},
209 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USPTL4_4)},
191 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)}, 210 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_2)},
211 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL4_4)},
212 {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
192 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)}, 213 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
193 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)}, 214 {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
194 {} /* terminating entry */ 215 {} /* terminating entry */
@@ -262,12 +283,19 @@ static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
262{ 283{
263 struct usb_device *dev = port->serial->dev; 284 struct usb_device *dev = port->serial->dev;
264 int ret = 0; 285 int ret = 0;
286 u8 *buf;
287
288 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
289 if (!buf)
290 return -ENOMEM;
265 291
266 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 292 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
267 MCS_RD_RTYPE, 0, reg, val, VENDOR_READ_LENGTH, 293 MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
268 MOS_WDR_TIMEOUT); 294 MOS_WDR_TIMEOUT);
295 *val = buf[0];
269 dbg("mos7840_get_reg_sync offset is %x, return val %x", reg, *val); 296 dbg("mos7840_get_reg_sync offset is %x, return val %x", reg, *val);
270 *val = (*val) & 0x00ff; 297
298 kfree(buf);
271 return ret; 299 return ret;
272} 300}
273 301
@@ -320,6 +348,11 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
320 struct usb_device *dev = port->serial->dev; 348 struct usb_device *dev = port->serial->dev;
321 int ret = 0; 349 int ret = 0;
322 __u16 Wval; 350 __u16 Wval;
351 u8 *buf;
352
353 buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
354 if (!buf)
355 return -ENOMEM;
323 356
324 /* dbg("application number is %4x", 357 /* dbg("application number is %4x",
325 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */ 358 (((__u16)port->number - (__u16)(port->serial->minor))+1)<<8); */
@@ -343,9 +376,11 @@ static int mos7840_get_uart_reg(struct usb_serial_port *port, __u16 reg,
343 } 376 }
344 } 377 }
345 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, 378 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
346 MCS_RD_RTYPE, Wval, reg, val, VENDOR_READ_LENGTH, 379 MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH,
347 MOS_WDR_TIMEOUT); 380 MOS_WDR_TIMEOUT);
348 *val = (*val) & 0x00ff; 381 *val = buf[0];
382
383 kfree(buf);
349 return ret; 384 return ret;
350} 385}
351 386
@@ -729,7 +764,6 @@ static void mos7840_bulk_in_callback(struct urb *urb)
729 if (urb->actual_length) { 764 if (urb->actual_length) {
730 tty = tty_port_tty_get(&mos7840_port->port->port); 765 tty = tty_port_tty_get(&mos7840_port->port->port);
731 if (tty) { 766 if (tty) {
732 tty_buffer_request_room(tty, urb->actual_length);
733 tty_insert_flip_string(tty, data, urb->actual_length); 767 tty_insert_flip_string(tty, data, urb->actual_length);
734 dbg(" %s ", data); 768 dbg(" %s ", data);
735 tty_flip_buffer_push(tty); 769 tty_flip_buffer_push(tty);
diff --git a/drivers/usb/serial/moto_modem.c b/drivers/usb/serial/moto_modem.c
index 99bd00f5188a..cf1718394e18 100644
--- a/drivers/usb/serial/moto_modem.c
+++ b/drivers/usb/serial/moto_modem.c
@@ -21,7 +21,7 @@
21#include <linux/usb.h> 21#include <linux/usb.h>
22#include <linux/usb/serial.h> 22#include <linux/usb/serial.h>
23 23
24static struct usb_device_id id_table [] = { 24static const struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */ 25 { USB_DEVICE(0x05c6, 0x3197) }, /* unknown Motorola phone */
26 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */ 26 { USB_DEVICE(0x0c44, 0x0022) }, /* unknown Mororola phone */
27 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */ 27 { USB_DEVICE(0x22b8, 0x2a64) }, /* Motorola KRZR K1m */
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index 5ceaa4c6be09..a6b207c84917 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -12,6 +12,7 @@
12 * flags as the navman is rx only so cannot echo. 12 * flags as the navman is rx only so cannot echo.
13 */ 13 */
14 14
15#include <linux/gfp.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/tty.h> 18#include <linux/tty.h>
@@ -22,7 +23,7 @@
22 23
23static int debug; 24static int debug;
24 25
25static struct usb_device_id id_table [] = { 26static const struct usb_device_id id_table[] = {
26 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */ 27 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
27 { }, 28 { },
28}; 29};
@@ -66,7 +67,6 @@ static void navman_read_int_callback(struct urb *urb)
66 67
67 tty = tty_port_tty_get(&port->port); 68 tty = tty_port_tty_get(&port->port);
68 if (tty && urb->actual_length) { 69 if (tty && urb->actual_length) {
69 tty_buffer_request_room(tty, urb->actual_length);
70 tty_insert_flip_string(tty, data, urb->actual_length); 70 tty_insert_flip_string(tty, data, urb->actual_length);
71 tty_flip_buffer_push(tty); 71 tty_flip_buffer_push(tty);
72 } 72 }
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 062265038bf0..89c724c0ac0a 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -75,7 +75,7 @@ static void omninet_disconnect(struct usb_serial *serial);
75static void omninet_release(struct usb_serial *serial); 75static void omninet_release(struct usb_serial *serial);
76static int omninet_attach(struct usb_serial *serial); 76static int omninet_attach(struct usb_serial *serial);
77 77
78static struct usb_device_id id_table[] = { 78static const struct usb_device_id id_table[] = {
79 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, 79 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
80 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) }, 80 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) },
81 { } /* Terminating entry */ 81 { } /* Terminating entry */
@@ -218,8 +218,8 @@ static void omninet_read_bulk_callback(struct urb *urb)
218 218
219 if (debug && header->oh_xxx != 0x30) { 219 if (debug && header->oh_xxx != 0x30) {
220 if (urb->actual_length) { 220 if (urb->actual_length) {
221 printk(KERN_DEBUG __FILE__ 221 printk(KERN_DEBUG "%s: omninet_read %d: ",
222 ": omninet_read %d: ", header->oh_len); 222 __FILE__, header->oh_len);
223 for (i = 0; i < (header->oh_len + 223 for (i = 0; i < (header->oh_len +
224 OMNINET_HEADERLEN); i++) 224 OMNINET_HEADERLEN); i++)
225 printk("%.2x ", data[i]); 225 printk("%.2x ", data[i]);
@@ -332,7 +332,7 @@ static void omninet_write_bulk_callback(struct urb *urb)
332 struct usb_serial_port *port = urb->context; 332 struct usb_serial_port *port = urb->context;
333 int status = urb->status; 333 int status = urb->status;
334 334
335 dbg("%s - port %0x\n", __func__, port->number); 335 dbg("%s - port %0x", __func__, port->number);
336 336
337 port->write_urb_busy = 0; 337 port->write_urb_busy = 0;
338 if (status) { 338 if (status) {
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 80f59b6350cb..ed01f3b2de8c 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -13,6 +13,7 @@
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/tty_driver.h> 15#include <linux/tty_driver.h>
16#include <linux/slab.h>
16#include <linux/tty_flip.h> 17#include <linux/tty_flip.h>
17#include <linux/serial.h> 18#include <linux/serial.h>
18#include <linux/module.h> 19#include <linux/module.h>
@@ -22,7 +23,7 @@
22 23
23static int debug; 24static int debug;
24 25
25static struct usb_device_id id_table[] = { 26static const struct usb_device_id id_table[] = {
26 { USB_DEVICE(0x065a, 0x0009) }, 27 { USB_DEVICE(0x065a, 0x0009) },
27 { }, 28 { },
28}; 29};
@@ -55,7 +56,6 @@ static void opticon_bulk_callback(struct urb *urb)
55 int status = urb->status; 56 int status = urb->status;
56 struct tty_struct *tty; 57 struct tty_struct *tty;
57 int result; 58 int result;
58 int available_room = 0;
59 int data_length; 59 int data_length;
60 60
61 dbg("%s - port %d", __func__, port->number); 61 dbg("%s - port %d", __func__, port->number);
@@ -96,13 +96,9 @@ static void opticon_bulk_callback(struct urb *urb)
96 /* real data, send it to the tty layer */ 96 /* real data, send it to the tty layer */
97 tty = tty_port_tty_get(&port->port); 97 tty = tty_port_tty_get(&port->port);
98 if (tty) { 98 if (tty) {
99 available_room = tty_buffer_request_room(tty, 99 tty_insert_flip_string(tty, data,
100 data_length); 100 data_length);
101 if (available_room) { 101 tty_flip_buffer_push(tty);
102 tty_insert_flip_string(tty, data,
103 available_room);
104 tty_flip_buffer_push(tty);
105 }
106 tty_kref_put(tty); 102 tty_kref_put(tty);
107 } 103 }
108 } else { 104 } else {
@@ -120,7 +116,7 @@ static void opticon_bulk_callback(struct urb *urb)
120 } 116 }
121 } else { 117 } else {
122 dev_dbg(&priv->udev->dev, 118 dev_dbg(&priv->udev->dev,
123 "Improper ammount of data received from the device, " 119 "Improper amount of data received from the device, "
124 "%d bytes", urb->actual_length); 120 "%d bytes", urb->actual_length);
125 } 121 }
126 122
@@ -217,7 +213,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
217 spin_lock_irqsave(&priv->lock, flags); 213 spin_lock_irqsave(&priv->lock, flags);
218 if (priv->outstanding_urbs > URB_UPPER_LIMIT) { 214 if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
219 spin_unlock_irqrestore(&priv->lock, flags); 215 spin_unlock_irqrestore(&priv->lock, flags);
220 dbg("%s - write limit hit\n", __func__); 216 dbg("%s - write limit hit", __func__);
221 return 0; 217 return 0;
222 } 218 }
223 priv->outstanding_urbs++; 219 priv->outstanding_urbs++;
@@ -288,7 +284,7 @@ static int opticon_write_room(struct tty_struct *tty)
288 spin_lock_irqsave(&priv->lock, flags); 284 spin_lock_irqsave(&priv->lock, flags);
289 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) { 285 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
290 spin_unlock_irqrestore(&priv->lock, flags); 286 spin_unlock_irqrestore(&priv->lock, flags);
291 dbg("%s - write limit hit\n", __func__); 287 dbg("%s - write limit hit", __func__);
292 return 0; 288 return 0;
293 } 289 }
294 spin_unlock_irqrestore(&priv->lock, flags); 290 spin_unlock_irqrestore(&priv->lock, flags);
@@ -501,12 +497,13 @@ static int opticon_resume(struct usb_interface *intf)
501 struct usb_serial_port *port = serial->port[0]; 497 struct usb_serial_port *port = serial->port[0];
502 int result; 498 int result;
503 499
504 mutex_lock(&port->mutex); 500 mutex_lock(&port->port.mutex);
505 if (port->port.count) 501 /* This is protected by the port mutex against close/open */
502 if (test_bit(ASYNCB_INITIALIZED, &port->port.flags))
506 result = usb_submit_urb(priv->bulk_read_urb, GFP_NOIO); 503 result = usb_submit_urb(priv->bulk_read_urb, GFP_NOIO);
507 else 504 else
508 result = 0; 505 result = 0;
509 mutex_unlock(&port->mutex); 506 mutex_unlock(&port->port.mutex);
510 return result; 507 return result;
511} 508}
512 509
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 0577e4b61114..84d0edad8e4f 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -37,6 +37,7 @@
37#include <linux/errno.h> 37#include <linux/errno.h>
38#include <linux/tty.h> 38#include <linux/tty.h>
39#include <linux/tty_flip.h> 39#include <linux/tty_flip.h>
40#include <linux/slab.h>
40#include <linux/module.h> 41#include <linux/module.h>
41#include <linux/bitops.h> 42#include <linux/bitops.h>
42#include <linux/usb.h> 43#include <linux/usb.h>
@@ -288,7 +289,9 @@ static int option_resume(struct usb_serial *serial);
288 289
289#define QUALCOMM_VENDOR_ID 0x05C6 290#define QUALCOMM_VENDOR_ID 0x05C6
290 291
291#define MAXON_VENDOR_ID 0x16d8 292#define CMOTECH_VENDOR_ID 0x16d8
293#define CMOTECH_PRODUCT_6008 0x6008
294#define CMOTECH_PRODUCT_6280 0x6280
292 295
293#define TELIT_VENDOR_ID 0x1bc7 296#define TELIT_VENDOR_ID 0x1bc7
294#define TELIT_PRODUCT_UC864E 0x1003 297#define TELIT_PRODUCT_UC864E 0x1003
@@ -302,6 +305,11 @@ static int option_resume(struct usb_serial *serial);
302#define ZTE_PRODUCT_CDMA_TECH 0xfffe 305#define ZTE_PRODUCT_CDMA_TECH 0xfffe
303#define ZTE_PRODUCT_AC8710 0xfff1 306#define ZTE_PRODUCT_AC8710 0xfff1
304#define ZTE_PRODUCT_AC2726 0xfff5 307#define ZTE_PRODUCT_AC2726 0xfff5
308#define ZTE_PRODUCT_AC8710T 0xffff
309
310/* ZTE PRODUCTS -- alternate vendor ID */
311#define ZTE_VENDOR_ID2 0x1d6b
312#define ZTE_PRODUCT_MF_330 0x0002
305 313
306#define BENQ_VENDOR_ID 0x04a5 314#define BENQ_VENDOR_ID 0x04a5
307#define BENQ_PRODUCT_H10 0x4068 315#define BENQ_PRODUCT_H10 0x4068
@@ -309,6 +317,7 @@ static int option_resume(struct usb_serial *serial);
309#define DLINK_VENDOR_ID 0x1186 317#define DLINK_VENDOR_ID 0x1186
310#define DLINK_PRODUCT_DWM_652 0x3e04 318#define DLINK_PRODUCT_DWM_652 0x3e04
311#define DLINK_PRODUCT_DWM_652_U5 0xce16 319#define DLINK_PRODUCT_DWM_652_U5 0xce16
320#define DLINK_PRODUCT_DWM_652_U5A 0xce1e
312 321
313#define QISDA_VENDOR_ID 0x1da5 322#define QISDA_VENDOR_ID 0x1da5
314#define QISDA_PRODUCT_H21_4512 0x4512 323#define QISDA_PRODUCT_H21_4512 0x4512
@@ -332,15 +341,66 @@ static int option_resume(struct usb_serial *serial);
332#define ALCATEL_VENDOR_ID 0x1bbb 341#define ALCATEL_VENDOR_ID 0x1bbb
333#define ALCATEL_PRODUCT_X060S 0x0000 342#define ALCATEL_PRODUCT_X060S 0x0000
334 343
344#define PIRELLI_VENDOR_ID 0x1266
345#define PIRELLI_PRODUCT_C100_1 0x1002
346#define PIRELLI_PRODUCT_C100_2 0x1003
347#define PIRELLI_PRODUCT_1004 0x1004
348#define PIRELLI_PRODUCT_1005 0x1005
349#define PIRELLI_PRODUCT_1006 0x1006
350#define PIRELLI_PRODUCT_1007 0x1007
351#define PIRELLI_PRODUCT_1008 0x1008
352#define PIRELLI_PRODUCT_1009 0x1009
353#define PIRELLI_PRODUCT_100A 0x100a
354#define PIRELLI_PRODUCT_100B 0x100b
355#define PIRELLI_PRODUCT_100C 0x100c
356#define PIRELLI_PRODUCT_100D 0x100d
357#define PIRELLI_PRODUCT_100E 0x100e
358#define PIRELLI_PRODUCT_100F 0x100f
359#define PIRELLI_PRODUCT_1011 0x1011
360#define PIRELLI_PRODUCT_1012 0x1012
361
335/* Airplus products */ 362/* Airplus products */
336#define AIRPLUS_VENDOR_ID 0x1011 363#define AIRPLUS_VENDOR_ID 0x1011
337#define AIRPLUS_PRODUCT_MCD650 0x3198 364#define AIRPLUS_PRODUCT_MCD650 0x3198
338 365
366/* Longcheer/Longsung vendor ID; makes whitelabel devices that
367 * many other vendors like 4G Systems, Alcatel, ChinaBird,
368 * Mobidata, etc sell under their own brand names.
369 */
370#define LONGCHEER_VENDOR_ID 0x1c9e
371
339/* 4G Systems products */ 372/* 4G Systems products */
340#define FOUR_G_SYSTEMS_VENDOR_ID 0x1c9e 373/* This is the 4G XS Stick W14 a.k.a. Mobilcom Debitel Surf-Stick *
374 * It seems to contain a Qualcomm QSC6240/6290 chipset */
341#define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603 375#define FOUR_G_SYSTEMS_PRODUCT_W14 0x9603
342 376
343static struct usb_device_id option_ids[] = { 377/* Haier products */
378#define HAIER_VENDOR_ID 0x201e
379#define HAIER_PRODUCT_CE100 0x2009
380
381#define CINTERION_VENDOR_ID 0x0681
382
383/* some devices interfaces need special handling due to a number of reasons */
384enum option_blacklist_reason {
385 OPTION_BLACKLIST_NONE = 0,
386 OPTION_BLACKLIST_SENDSETUP = 1,
387 OPTION_BLACKLIST_RESERVED_IF = 2
388};
389
390struct option_blacklist_info {
391 const u32 infolen; /* number of interface numbers on blacklist */
392 const u8 *ifaceinfo; /* pointer to the array holding the numbers */
393 enum option_blacklist_reason reason;
394};
395
396static const u8 four_g_w14_no_sendsetup[] = { 0, 1 };
397static const struct option_blacklist_info four_g_w14_blacklist = {
398 .infolen = ARRAY_SIZE(four_g_w14_no_sendsetup),
399 .ifaceinfo = four_g_w14_no_sendsetup,
400 .reason = OPTION_BLACKLIST_SENDSETUP
401};
402
403static const struct usb_device_id option_ids[] = {
344 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) }, 404 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
345 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) }, 405 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
346 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) }, 406 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
@@ -516,7 +576,8 @@ static struct usb_device_id option_ids[] = {
516 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) }, 576 { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_PRODUCT_KPC680) },
517 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */ 577 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6000)}, /* ZTE AC8700 */
518 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */ 578 { USB_DEVICE(QUALCOMM_VENDOR_ID, 0x6613)}, /* Onda H600/ZTE MF330 */
519 { USB_DEVICE(MAXON_VENDOR_ID, 0x6280) }, /* BP3-USB & BP3-EXT HSDPA */ 579 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6280) }, /* BP3-USB & BP3-EXT HSDPA */
580 { USB_DEVICE(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_6008) },
520 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) }, 581 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864E) },
521 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) }, 582 { USB_DEVICE(TELIT_VENDOR_ID, TELIT_PRODUCT_UC864G) },
522 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */ 583 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_MF622, 0xff, 0xff, 0xff) }, /* ZTE WCDMA products */
@@ -580,18 +641,57 @@ static struct usb_device_id option_ids[] = {
580 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0086, 0xff, 0xff, 0xff) }, 641 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0086, 0xff, 0xff, 0xff) },
581 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 0xff, 0xff) }, 642 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2002, 0xff, 0xff, 0xff) },
582 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) }, 643 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x2003, 0xff, 0xff, 0xff) },
644 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0104, 0xff, 0xff, 0xff) },
645 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0106, 0xff, 0xff, 0xff) },
646 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0108, 0xff, 0xff, 0xff) },
647 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0113, 0xff, 0xff, 0xff) },
648 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0117, 0xff, 0xff, 0xff) },
649 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0118, 0xff, 0xff, 0xff) },
650 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0121, 0xff, 0xff, 0xff) },
651 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0122, 0xff, 0xff, 0xff) },
652 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0123, 0xff, 0xff, 0xff) },
653 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0124, 0xff, 0xff, 0xff) },
654 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0125, 0xff, 0xff, 0xff) },
655 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0126, 0xff, 0xff, 0xff) },
656 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0128, 0xff, 0xff, 0xff) },
657 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0142, 0xff, 0xff, 0xff) },
658 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0143, 0xff, 0xff, 0xff) },
659 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0144, 0xff, 0xff, 0xff) },
660 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0145, 0xff, 0xff, 0xff) },
661 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0146, 0xff, 0xff, 0xff) },
662 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0147, 0xff, 0xff, 0xff) },
663 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0148, 0xff, 0xff, 0xff) },
664 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0149, 0xff, 0xff, 0xff) },
665 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0150, 0xff, 0xff, 0xff) },
666 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0151, 0xff, 0xff, 0xff) },
667 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0152, 0xff, 0xff, 0xff) },
668 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0153, 0xff, 0xff, 0xff) },
669 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0154, 0xff, 0xff, 0xff) },
670 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0155, 0xff, 0xff, 0xff) },
671 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0156, 0xff, 0xff, 0xff) },
672 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0157, 0xff, 0xff, 0xff) },
673 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0158, 0xff, 0xff, 0xff) },
674 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0159, 0xff, 0xff, 0xff) },
675 { 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) },
677 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0162, 0xff, 0xff, 0xff) },
583 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0014, 0xff, 0xff, 0xff) }, /* ZTE CDMA products */ 678 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0014, 0xff, 0xff, 0xff) }, /* ZTE CDMA products */
584 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0027, 0xff, 0xff, 0xff) }, 679 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0027, 0xff, 0xff, 0xff) },
585 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0059, 0xff, 0xff, 0xff) }, 680 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0059, 0xff, 0xff, 0xff) },
586 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0060, 0xff, 0xff, 0xff) }, 681 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0060, 0xff, 0xff, 0xff) },
587 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0070, 0xff, 0xff, 0xff) }, 682 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0070, 0xff, 0xff, 0xff) },
588 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) }, 683 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0073, 0xff, 0xff, 0xff) },
684 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0130, 0xff, 0xff, 0xff) },
685 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x0141, 0xff, 0xff, 0xff) },
589 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) }, 686 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH, 0xff, 0xff, 0xff) },
590 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) }, 687 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710, 0xff, 0xff, 0xff) },
591 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) }, 688 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC2726, 0xff, 0xff, 0xff) },
689 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, ZTE_PRODUCT_AC8710T, 0xff, 0xff, 0xff) },
690 { USB_DEVICE(ZTE_VENDOR_ID2, ZTE_PRODUCT_MF_330) },
592 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) }, 691 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_H10) },
593 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) }, 692 { USB_DEVICE(DLINK_VENDOR_ID, DLINK_PRODUCT_DWM_652) },
594 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */ 693 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5) }, /* Yes, ALINK_VENDOR_ID */
694 { USB_DEVICE(ALINK_VENDOR_ID, DLINK_PRODUCT_DWM_652_U5A) },
595 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) }, 695 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4512) },
596 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4523) }, 696 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H21_4523) },
597 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H20_4515) }, 697 { USB_DEVICE(QISDA_VENDOR_ID, QISDA_PRODUCT_H20_4515) },
@@ -603,7 +703,29 @@ static struct usb_device_id option_ids[] = {
603 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S) }, 703 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_X060S) },
604 { USB_DEVICE(AIRPLUS_VENDOR_ID, AIRPLUS_PRODUCT_MCD650) }, 704 { USB_DEVICE(AIRPLUS_VENDOR_ID, AIRPLUS_PRODUCT_MCD650) },
605 { USB_DEVICE(TLAYTECH_VENDOR_ID, TLAYTECH_PRODUCT_TEU800) }, 705 { USB_DEVICE(TLAYTECH_VENDOR_ID, TLAYTECH_PRODUCT_TEU800) },
606 { USB_DEVICE(FOUR_G_SYSTEMS_VENDOR_ID, FOUR_G_SYSTEMS_PRODUCT_W14) }, 706 { USB_DEVICE(LONGCHEER_VENDOR_ID, FOUR_G_SYSTEMS_PRODUCT_W14),
707 .driver_info = (kernel_ulong_t)&four_g_w14_blacklist
708 },
709 { USB_DEVICE(HAIER_VENDOR_ID, HAIER_PRODUCT_CE100) },
710 /* Pirelli */
711 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_1)},
712 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_C100_2)},
713 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1004)},
714 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1005)},
715 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1006)},
716 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1007)},
717 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1008)},
718 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1009)},
719 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100A)},
720 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100B) },
721 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100C) },
722 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100D) },
723 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100E) },
724 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_100F) },
725 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1011)},
726 { USB_DEVICE(PIRELLI_VENDOR_ID, PIRELLI_PRODUCT_1012)},
727
728 { USB_DEVICE(CINTERION_VENDOR_ID, 0x0047) },
607 { } /* Terminating entry */ 729 { } /* Terminating entry */
608}; 730};
609MODULE_DEVICE_TABLE(usb, option_ids); 731MODULE_DEVICE_TABLE(usb, option_ids);
@@ -667,6 +789,7 @@ struct option_intf_private {
667 spinlock_t susp_lock; 789 spinlock_t susp_lock;
668 unsigned int suspended:1; 790 unsigned int suspended:1;
669 int in_flight; 791 int in_flight;
792 struct option_blacklist_info *blacklist_info;
670}; 793};
671 794
672struct option_port_private { 795struct option_port_private {
@@ -726,19 +849,44 @@ static int option_probe(struct usb_serial *serial,
726 const struct usb_device_id *id) 849 const struct usb_device_id *id)
727{ 850{
728 struct option_intf_private *data; 851 struct option_intf_private *data;
852
729 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ 853 /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */
730 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && 854 if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID &&
731 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && 855 serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 &&
732 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) 856 serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8)
733 return -ENODEV; 857 return -ENODEV;
734 858
859 /* Bandrich modem and AT command interface is 0xff */
860 if ((serial->dev->descriptor.idVendor == BANDRICH_VENDOR_ID ||
861 serial->dev->descriptor.idVendor == PIRELLI_VENDOR_ID) &&
862 serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff)
863 return -ENODEV;
864
735 data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL); 865 data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL);
736 if (!data) 866 if (!data)
737 return -ENOMEM; 867 return -ENOMEM;
738 spin_lock_init(&data->susp_lock); 868 spin_lock_init(&data->susp_lock);
869 data->blacklist_info = (struct option_blacklist_info*) id->driver_info;
739 return 0; 870 return 0;
740} 871}
741 872
873static enum option_blacklist_reason is_blacklisted(const u8 ifnum,
874 const struct option_blacklist_info *blacklist)
875{
876 const u8 *info;
877 int i;
878
879 if (blacklist) {
880 info = blacklist->ifaceinfo;
881
882 for (i = 0; i < blacklist->infolen; i++) {
883 if (info[i] == ifnum)
884 return blacklist->reason;
885 }
886 }
887 return OPTION_BLACKLIST_NONE;
888}
889
742static void option_set_termios(struct tty_struct *tty, 890static void option_set_termios(struct tty_struct *tty,
743 struct usb_serial_port *port, struct ktermios *old_termios) 891 struct usb_serial_port *port, struct ktermios *old_termios)
744{ 892{
@@ -879,7 +1027,6 @@ static void option_indat_callback(struct urb *urb)
879 } else { 1027 } else {
880 tty = tty_port_tty_get(&port->port); 1028 tty = tty_port_tty_get(&port->port);
881 if (urb->actual_length) { 1029 if (urb->actual_length) {
882 tty_buffer_request_room(tty, urb->actual_length);
883 tty_insert_flip_string(tty, data, urb->actual_length); 1030 tty_insert_flip_string(tty, data, urb->actual_length);
884 tty_flip_buffer_push(tty); 1031 tty_flip_buffer_push(tty);
885 } else 1032 } else
@@ -887,9 +1034,9 @@ static void option_indat_callback(struct urb *urb)
887 tty_kref_put(tty); 1034 tty_kref_put(tty);
888 1035
889 /* Resubmit urb so we continue receiving */ 1036 /* Resubmit urb so we continue receiving */
890 if (port->port.count && status != -ESHUTDOWN) { 1037 if (status != -ESHUTDOWN) {
891 err = usb_submit_urb(urb, GFP_ATOMIC); 1038 err = usb_submit_urb(urb, GFP_ATOMIC);
892 if (err) 1039 if (err && err != -EPERM)
893 printk(KERN_ERR "%s: resubmit read urb failed. " 1040 printk(KERN_ERR "%s: resubmit read urb failed. "
894 "(%d)", __func__, err); 1041 "(%d)", __func__, err);
895 else 1042 else
@@ -943,7 +1090,7 @@ static void option_instat_callback(struct urb *urb)
943 (struct usb_ctrlrequest *)urb->transfer_buffer; 1090 (struct usb_ctrlrequest *)urb->transfer_buffer;
944 1091
945 if (!req_pkt) { 1092 if (!req_pkt) {
946 dbg("%s: NULL req_pkt\n", __func__); 1093 dbg("%s: NULL req_pkt", __func__);
947 return; 1094 return;
948 } 1095 }
949 if ((req_pkt->bRequestType == 0xA1) && 1096 if ((req_pkt->bRequestType == 0xA1) &&
@@ -1169,11 +1316,19 @@ static void option_setup_urbs(struct usb_serial *serial)
1169static int option_send_setup(struct usb_serial_port *port) 1316static int option_send_setup(struct usb_serial_port *port)
1170{ 1317{
1171 struct usb_serial *serial = port->serial; 1318 struct usb_serial *serial = port->serial;
1319 struct option_intf_private *intfdata =
1320 (struct option_intf_private *) serial->private;
1172 struct option_port_private *portdata; 1321 struct option_port_private *portdata;
1173 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 1322 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
1174 int val = 0; 1323 int val = 0;
1175 dbg("%s", __func__); 1324 dbg("%s", __func__);
1176 1325
1326 if (is_blacklisted(ifNum, intfdata->blacklist_info) ==
1327 OPTION_BLACKLIST_SENDSETUP) {
1328 dbg("No send_setup on blacklisted interface #%d\n", ifNum);
1329 return -EIO;
1330 }
1331
1177 portdata = usb_get_serial_port_data(port); 1332 portdata = usb_get_serial_port_data(port);
1178 1333
1179 if (portdata->dtr_state) 1334 if (portdata->dtr_state)
@@ -1312,7 +1467,7 @@ static int option_suspend(struct usb_serial *serial, pm_message_t message)
1312 1467
1313 dbg("%s entered", __func__); 1468 dbg("%s entered", __func__);
1314 1469
1315 if (serial->dev->auto_pm) { 1470 if (message.event & PM_EVENT_AUTO) {
1316 spin_lock_irq(&intfdata->susp_lock); 1471 spin_lock_irq(&intfdata->susp_lock);
1317 b = intfdata->in_flight; 1472 b = intfdata->in_flight;
1318 spin_unlock_irq(&intfdata->susp_lock); 1473 spin_unlock_irq(&intfdata->susp_lock);
@@ -1359,7 +1514,7 @@ static int option_resume(struct usb_serial *serial)
1359 for (i = 0; i < serial->num_ports; i++) { 1514 for (i = 0; i < serial->num_ports; i++) {
1360 port = serial->port[i]; 1515 port = serial->port[i];
1361 if (!port->interrupt_in_urb) { 1516 if (!port->interrupt_in_urb) {
1362 dbg("%s: No interrupt URB for port %d\n", __func__, i); 1517 dbg("%s: No interrupt URB for port %d", __func__, i);
1363 continue; 1518 continue;
1364 } 1519 }
1365 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); 1520 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index c644e26394b4..deeacdea05db 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -58,7 +58,7 @@
58#define OTI6858_AUTHOR "Tomasz Michal Lukaszewski <FIXME@FIXME>" 58#define OTI6858_AUTHOR "Tomasz Michal Lukaszewski <FIXME@FIXME>"
59#define OTI6858_VERSION "0.1" 59#define OTI6858_VERSION "0.1"
60 60
61static struct usb_device_id id_table [] = { 61static const struct usb_device_id id_table[] = {
62 { USB_DEVICE(OTI6858_VENDOR_ID, OTI6858_PRODUCT_ID) }, 62 { USB_DEVICE(OTI6858_VENDOR_ID, OTI6858_PRODUCT_ID) },
63 { } 63 { }
64}; 64};
@@ -302,7 +302,7 @@ void send_data(struct work_struct *work)
302 struct usb_serial_port *port = priv->port; 302 struct usb_serial_port *port = priv->port;
303 int count = 0, result; 303 int count = 0, result;
304 unsigned long flags; 304 unsigned long flags;
305 unsigned char allow; 305 u8 *allow;
306 306
307 dbg("%s(port = %d)", __func__, port->number); 307 dbg("%s(port = %d)", __func__, port->number);
308 308
@@ -321,13 +321,20 @@ void send_data(struct work_struct *work)
321 count = port->bulk_out_size; 321 count = port->bulk_out_size;
322 322
323 if (count != 0) { 323 if (count != 0) {
324 allow = kmalloc(1, GFP_KERNEL);
325 if (!allow) {
326 dev_err(&port->dev, "%s(): kmalloc failed\n",
327 __func__);
328 return;
329 }
324 result = usb_control_msg(port->serial->dev, 330 result = usb_control_msg(port->serial->dev,
325 usb_rcvctrlpipe(port->serial->dev, 0), 331 usb_rcvctrlpipe(port->serial->dev, 0),
326 OTI6858_REQ_T_CHECK_TXBUFF, 332 OTI6858_REQ_T_CHECK_TXBUFF,
327 OTI6858_REQ_CHECK_TXBUFF, 333 OTI6858_REQ_CHECK_TXBUFF,
328 count, 0, &allow, 1, 100); 334 count, 0, allow, 1, 100);
329 if (result != 1 || allow != 0) 335 if (result != 1 || *allow != 0)
330 count = 0; 336 count = 0;
337 kfree(allow);
331 } 338 }
332 339
333 if (count == 0) { 340 if (count == 0) {
@@ -578,9 +585,6 @@ static int oti6858_open(struct tty_struct *tty, struct usb_serial_port *port)
578 usb_clear_halt(serial->dev, port->write_urb->pipe); 585 usb_clear_halt(serial->dev, port->write_urb->pipe);
579 usb_clear_halt(serial->dev, port->read_urb->pipe); 586 usb_clear_halt(serial->dev, port->read_urb->pipe);
580 587
581 if (port->port.count != 1)
582 return 0;
583
584 buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); 588 buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL);
585 if (buf == NULL) { 589 if (buf == NULL) {
586 dev_err(&port->dev, "%s(): out of memory!\n", __func__); 590 dev_err(&port->dev, "%s(): out of memory!\n", __func__);
@@ -927,10 +931,6 @@ static void oti6858_read_bulk_callback(struct urb *urb)
927 spin_unlock_irqrestore(&priv->lock, flags); 931 spin_unlock_irqrestore(&priv->lock, flags);
928 932
929 if (status != 0) { 933 if (status != 0) {
930 if (!port->port.count) {
931 dbg("%s(): port is closed, exiting", __func__);
932 return;
933 }
934 /* 934 /*
935 if (status == -EPROTO) { 935 if (status == -EPROTO) {
936 * PL2303 mysteriously fails with -EPROTO reschedule 936 * PL2303 mysteriously fails with -EPROTO reschedule
@@ -954,14 +954,12 @@ static void oti6858_read_bulk_callback(struct urb *urb)
954 } 954 }
955 tty_kref_put(tty); 955 tty_kref_put(tty);
956 956
957 /* schedule the interrupt urb if we are still open */ 957 /* schedule the interrupt urb */
958 if (port->port.count != 0) { 958 port->interrupt_in_urb->dev = port->serial->dev;
959 port->interrupt_in_urb->dev = port->serial->dev; 959 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
960 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 960 if (result != 0 && result != -EPERM) {
961 if (result != 0) { 961 dev_err(&port->dev, "%s(): usb_submit_urb() failed,"
962 dev_err(&port->dev, "%s(): usb_submit_urb() failed," 962 " error %d\n", __func__, result);
963 " error %d\n", __func__, result);
964 }
965 } 963 }
966} 964}
967 965
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 9ec1a49e2362..c28b1607eacc 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -50,7 +50,7 @@ struct pl2303_buf {
50 char *buf_put; 50 char *buf_put;
51}; 51};
52 52
53static struct usb_device_id id_table [] = { 53static const struct usb_device_id id_table[] = {
54 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, 54 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
55 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, 55 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
56 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) }, 56 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) },
@@ -59,6 +59,7 @@ static struct usb_device_id id_table [] = {
59 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) }, 59 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ALDIGA) },
60 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) }, 60 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MMX) },
61 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) }, 61 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GPRS) },
62 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_HCR331) },
62 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, 63 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
63 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) }, 64 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
64 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) }, 65 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
@@ -97,6 +98,7 @@ static struct usb_device_id id_table [] = {
97 { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) }, 98 { USB_DEVICE(CRESSI_VENDOR_ID, CRESSI_EDY_PRODUCT_ID) },
98 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) }, 99 { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
99 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) }, 100 { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
101 { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) },
100 { } /* Terminating entry */ 102 { } /* Terminating entry */
101}; 103};
102 104
@@ -451,7 +453,6 @@ static void pl2303_send(struct usb_serial_port *port)
451 port->write_urb->transfer_buffer); 453 port->write_urb->transfer_buffer);
452 454
453 port->write_urb->transfer_buffer_length = count; 455 port->write_urb->transfer_buffer_length = count;
454 port->write_urb->dev = port->serial->dev;
455 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 456 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
456 if (result) { 457 if (result) {
457 dev_err(&port->dev, "%s - failed submitting write urb," 458 dev_err(&port->dev, "%s - failed submitting write urb,"
@@ -769,7 +770,6 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
769 pl2303_set_termios(tty, port, &tmp_termios); 770 pl2303_set_termios(tty, port, &tmp_termios);
770 771
771 dbg("%s - submitting read urb", __func__); 772 dbg("%s - submitting read urb", __func__);
772 port->read_urb->dev = serial->dev;
773 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 773 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
774 if (result) { 774 if (result) {
775 dev_err(&port->dev, "%s - failed submitting read urb," 775 dev_err(&port->dev, "%s - failed submitting read urb,"
@@ -779,7 +779,6 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
779 } 779 }
780 780
781 dbg("%s - submitting interrupt urb", __func__); 781 dbg("%s - submitting interrupt urb", __func__);
782 port->interrupt_in_urb->dev = serial->dev;
783 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 782 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
784 if (result) { 783 if (result) {
785 dev_err(&port->dev, "%s - failed submitting interrupt urb," 784 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
@@ -895,10 +894,23 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
895static int pl2303_ioctl(struct tty_struct *tty, struct file *file, 894static int pl2303_ioctl(struct tty_struct *tty, struct file *file,
896 unsigned int cmd, unsigned long arg) 895 unsigned int cmd, unsigned long arg)
897{ 896{
897 struct serial_struct ser;
898 struct usb_serial_port *port = tty->driver_data; 898 struct usb_serial_port *port = tty->driver_data;
899 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd); 899 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
900 900
901 switch (cmd) { 901 switch (cmd) {
902 case TIOCGSERIAL:
903 memset(&ser, 0, sizeof ser);
904 ser.type = PORT_16654;
905 ser.line = port->serial->minor;
906 ser.port = port->number;
907 ser.baud_base = 460800;
908
909 if (copy_to_user((void __user *)arg, &ser, sizeof ser))
910 return -EFAULT;
911
912 return 0;
913
902 case TIOCMIWAIT: 914 case TIOCMIWAIT:
903 dbg("%s (%d) TIOCMIWAIT", __func__, port->number); 915 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
904 return wait_modem_info(port, arg); 916 return wait_modem_info(port, arg);
@@ -1042,7 +1054,6 @@ static void pl2303_push_data(struct tty_struct *tty,
1042 tty_flag = TTY_FRAME; 1054 tty_flag = TTY_FRAME;
1043 dbg("%s - tty_flag = %d", __func__, tty_flag); 1055 dbg("%s - tty_flag = %d", __func__, tty_flag);
1044 1056
1045 tty_buffer_request_room(tty, urb->actual_length + 1);
1046 /* overrun is special, not associated with a char */ 1057 /* overrun is special, not associated with a char */
1047 if (line_status & UART_OVERRUN_ERROR) 1058 if (line_status & UART_OVERRUN_ERROR)
1048 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 1059 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
@@ -1072,16 +1083,11 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1072 1083
1073 if (status) { 1084 if (status) {
1074 dbg("%s - urb status = %d", __func__, status); 1085 dbg("%s - urb status = %d", __func__, status);
1075 if (!port->port.count) {
1076 dbg("%s - port is closed, exiting.", __func__);
1077 return;
1078 }
1079 if (status == -EPROTO) { 1086 if (status == -EPROTO) {
1080 /* PL2303 mysteriously fails with -EPROTO reschedule 1087 /* PL2303 mysteriously fails with -EPROTO reschedule
1081 * the read */ 1088 * the read */
1082 dbg("%s - caught -EPROTO, resubmitting the urb", 1089 dbg("%s - caught -EPROTO, resubmitting the urb",
1083 __func__); 1090 __func__);
1084 urb->dev = port->serial->dev;
1085 result = usb_submit_urb(urb, GFP_ATOMIC); 1091 result = usb_submit_urb(urb, GFP_ATOMIC);
1086 if (result) 1092 if (result)
1087 dev_err(&urb->dev->dev, "%s - failed" 1093 dev_err(&urb->dev->dev, "%s - failed"
@@ -1108,15 +1114,10 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1108 } 1114 }
1109 tty_kref_put(tty); 1115 tty_kref_put(tty);
1110 /* Schedule the next read _if_ we are still open */ 1116 /* Schedule the next read _if_ we are still open */
1111 if (port->port.count) { 1117 result = usb_submit_urb(urb, GFP_ATOMIC);
1112 urb->dev = port->serial->dev; 1118 if (result && result != -EPERM)
1113 result = usb_submit_urb(urb, GFP_ATOMIC); 1119 dev_err(&urb->dev->dev, "%s - failed resubmitting"
1114 if (result) 1120 " read urb, error %d\n", __func__, result);
1115 dev_err(&urb->dev->dev, "%s - failed resubmitting"
1116 " read urb, error %d\n", __func__, result);
1117 }
1118
1119 return;
1120} 1121}
1121 1122
1122static void pl2303_write_bulk_callback(struct urb *urb) 1123static void pl2303_write_bulk_callback(struct urb *urb)
@@ -1146,7 +1147,6 @@ static void pl2303_write_bulk_callback(struct urb *urb)
1146 dbg("%s - nonzero write bulk status received: %d", __func__, 1147 dbg("%s - nonzero write bulk status received: %d", __func__,
1147 status); 1148 status);
1148 port->write_urb->transfer_buffer_length = 1; 1149 port->write_urb->transfer_buffer_length = 1;
1149 port->write_urb->dev = port->serial->dev;
1150 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 1150 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
1151 if (result) 1151 if (result)
1152 dev_err(&urb->dev->dev, "%s - failed resubmitting write" 1152 dev_err(&urb->dev->dev, "%s - failed resubmitting write"
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index d640dc951568..23c09b38b9ec 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -20,6 +20,7 @@
20#define PL2303_PRODUCT_ID_ALDIGA 0x0611 20#define PL2303_PRODUCT_ID_ALDIGA 0x0611
21#define PL2303_PRODUCT_ID_MMX 0x0612 21#define PL2303_PRODUCT_ID_MMX 0x0612
22#define PL2303_PRODUCT_ID_GPRS 0x0609 22#define PL2303_PRODUCT_ID_GPRS 0x0609
23#define PL2303_PRODUCT_ID_HCR331 0x331a
23 24
24#define ATEN_VENDOR_ID 0x0557 25#define ATEN_VENDOR_ID 0x0557
25#define ATEN_VENDOR_ID2 0x0547 26#define ATEN_VENDOR_ID2 0x0547
@@ -134,3 +135,7 @@
134/* Sanwa KB-USB2 multimeter cable (ID: 11ad:0001) */ 135/* Sanwa KB-USB2 multimeter cable (ID: 11ad:0001) */
135#define SANWA_VENDOR_ID 0x11ad 136#define SANWA_VENDOR_ID 0x11ad
136#define SANWA_PRODUCT_ID 0x0001 137#define SANWA_PRODUCT_ID 0x0001
138
139/* ADLINK ND-6530 RS232,RS485 and RS422 adapter */
140#define ADLINK_VENDOR_ID 0x0b63
141#define ADLINK_ND6530_PRODUCT_ID 0x6530
diff --git a/drivers/usb/serial/qcaux.c b/drivers/usb/serial/qcaux.c
new file mode 100644
index 000000000000..7e3bea23600b
--- /dev/null
+++ b/drivers/usb/serial/qcaux.c
@@ -0,0 +1,106 @@
1/*
2 * Qualcomm USB Auxiliary Serial Port driver
3 *
4 * Copyright (C) 2008 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2010 Dan Williams <dcbw@redhat.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 version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Devices listed here usually provide a CDC ACM port on which normal modem
12 * AT commands and PPP can be used. But when that port is in-use by PPP it
13 * cannot be used simultaneously for status or signal strength. Instead, the
14 * ports here can be queried for that information using the Qualcomm DM
15 * protocol.
16 */
17
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/tty.h>
21#include <linux/module.h>
22#include <linux/usb.h>
23#include <linux/usb/serial.h>
24
25/* NOTE: for now, only use this driver for devices that provide a CDC-ACM port
26 * for normal AT commands, but also provide secondary USB interfaces for the
27 * QCDM-capable ports. Devices that do not provide a CDC-ACM port should
28 * probably be driven by option.ko.
29 */
30
31/* UTStarcom/Pantech/Curitel devices */
32#define UTSTARCOM_VENDOR_ID 0x106c
33#define UTSTARCOM_PRODUCT_PC5740 0x3701
34#define UTSTARCOM_PRODUCT_PC5750 0x3702 /* aka Pantech PX-500 */
35#define UTSTARCOM_PRODUCT_UM150 0x3711
36#define UTSTARCOM_PRODUCT_UM175_V1 0x3712
37#define UTSTARCOM_PRODUCT_UM175_V2 0x3714
38#define UTSTARCOM_PRODUCT_UM175_ALLTEL 0x3715
39
40/* CMOTECH devices */
41#define CMOTECH_VENDOR_ID 0x16d8
42#define CMOTECH_PRODUCT_CDU550 0x5553
43#define CMOTECH_PRODUCT_CDX650 0x6512
44
45/* LG devices */
46#define LG_VENDOR_ID 0x1004
47#define LG_PRODUCT_VX4400_6000 0x6000 /* VX4400/VX6000/Rumor */
48
49/* Sanyo devices */
50#define SANYO_VENDOR_ID 0x0474
51#define SANYO_PRODUCT_KATANA_LX 0x0754 /* SCP-3800 (Katana LX) */
52
53static struct usb_device_id id_table[] = {
54 { 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) },
56 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM150, 0xff, 0x00, 0x00) },
57 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM175_V1, 0xff, 0x00, 0x00) },
58 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM175_V2, 0xff, 0x00, 0x00) },
59 { USB_DEVICE_AND_INTERFACE_INFO(UTSTARCOM_VENDOR_ID, UTSTARCOM_PRODUCT_UM175_ALLTEL, 0xff, 0x00, 0x00) },
60 { USB_DEVICE_AND_INTERFACE_INFO(CMOTECH_VENDOR_ID, CMOTECH_PRODUCT_CDU550, 0xff, 0xff, 0x00) },
61 { 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) },
63 { USB_DEVICE_AND_INTERFACE_INFO(SANYO_VENDOR_ID, SANYO_PRODUCT_KATANA_LX, 0xff, 0xff, 0x00) },
64 { },
65};
66MODULE_DEVICE_TABLE(usb, id_table);
67
68static struct usb_driver qcaux_driver = {
69 .name = "qcaux",
70 .probe = usb_serial_probe,
71 .disconnect = usb_serial_disconnect,
72 .id_table = id_table,
73 .no_dynamic_id = 1,
74};
75
76static struct usb_serial_driver qcaux_device = {
77 .driver = {
78 .owner = THIS_MODULE,
79 .name = "qcaux",
80 },
81 .id_table = id_table,
82 .num_ports = 1,
83};
84
85static int __init qcaux_init(void)
86{
87 int retval;
88
89 retval = usb_serial_register(&qcaux_device);
90 if (retval)
91 return retval;
92 retval = usb_register(&qcaux_driver);
93 if (retval)
94 usb_serial_deregister(&qcaux_device);
95 return retval;
96}
97
98static void __exit qcaux_exit(void)
99{
100 usb_deregister(&qcaux_driver);
101 usb_serial_deregister(&qcaux_device);
102}
103
104module_init(qcaux_init);
105module_exit(qcaux_exit);
106MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index 7528b8d57f1c..53a2d5a935a2 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -21,7 +21,7 @@
21 21
22static int debug; 22static int debug;
23 23
24static struct usb_device_id id_table[] = { 24static const struct usb_device_id id_table[] = {
25 {USB_DEVICE(0x05c6, 0x9211)}, /* Acer Gobi QDL device */ 25 {USB_DEVICE(0x05c6, 0x9211)}, /* Acer Gobi QDL device */
26 {USB_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 26 {USB_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
27 {USB_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */ 27 {USB_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
@@ -47,6 +47,35 @@ static struct usb_device_id id_table[] = {
47 {USB_DEVICE(0x05c6, 0x9221)}, /* Generic Gobi QDL device */ 47 {USB_DEVICE(0x05c6, 0x9221)}, /* Generic Gobi QDL device */
48 {USB_DEVICE(0x05c6, 0x9231)}, /* Generic Gobi QDL device */ 48 {USB_DEVICE(0x05c6, 0x9231)}, /* Generic Gobi QDL device */
49 {USB_DEVICE(0x1f45, 0x0001)}, /* Unknown Gobi QDL device */ 49 {USB_DEVICE(0x1f45, 0x0001)}, /* Unknown Gobi QDL device */
50 {USB_DEVICE(0x413c, 0x8185)}, /* Dell Gobi 2000 QDL device (N0218, VU936) */
51 {USB_DEVICE(0x413c, 0x8186)}, /* Dell Gobi 2000 Modem device (N0218, VU936) */
52 {USB_DEVICE(0x05c6, 0x9224)}, /* Sony Gobi 2000 QDL device (N0279, VU730) */
53 {USB_DEVICE(0x05c6, 0x9225)}, /* Sony Gobi 2000 Modem device (N0279, VU730) */
54 {USB_DEVICE(0x05c6, 0x9244)}, /* Samsung Gobi 2000 QDL device (VL176) */
55 {USB_DEVICE(0x05c6, 0x9245)}, /* Samsung Gobi 2000 Modem device (VL176) */
56 {USB_DEVICE(0x03f0, 0x241d)}, /* HP Gobi 2000 QDL device (VP412) */
57 {USB_DEVICE(0x03f0, 0x251d)}, /* HP Gobi 2000 Modem device (VP412) */
58 {USB_DEVICE(0x05c6, 0x9214)}, /* Acer Gobi 2000 QDL device (VP413) */
59 {USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */
60 {USB_DEVICE(0x05c6, 0x9264)}, /* Asus Gobi 2000 QDL device (VR305) */
61 {USB_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modem device (VR305) */
62 {USB_DEVICE(0x05c6, 0x9234)}, /* Top Global Gobi 2000 QDL device (VR306) */
63 {USB_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000 Modem device (VR306) */
64 {USB_DEVICE(0x05c6, 0x9274)}, /* iRex Technologies Gobi 2000 QDL device (VR307) */
65 {USB_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi 2000 Modem device (VR307) */
66 {USB_DEVICE(0x1199, 0x9000)}, /* Sierra Wireless Gobi 2000 QDL device (VT773) */
67 {USB_DEVICE(0x1199, 0x9001)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
68 {USB_DEVICE(0x1199, 0x9002)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
69 {USB_DEVICE(0x1199, 0x9003)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
70 {USB_DEVICE(0x1199, 0x9004)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
71 {USB_DEVICE(0x1199, 0x9005)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
72 {USB_DEVICE(0x1199, 0x9006)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
73 {USB_DEVICE(0x1199, 0x9007)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
74 {USB_DEVICE(0x1199, 0x9008)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
75 {USB_DEVICE(0x1199, 0x9009)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
76 {USB_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */
77 {USB_DEVICE(0x16d8, 0x8001)}, /* CMDTech Gobi 2000 QDL device (VU922) */
78 {USB_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */
50 { } /* Terminating entry */ 79 { } /* Terminating entry */
51}; 80};
52MODULE_DEVICE_TABLE(usb, id_table); 81MODULE_DEVICE_TABLE(usb, id_table);
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 4b463cd140ef..43a0cadd5782 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -64,8 +64,8 @@
64 64
65#include <linux/kernel.h> 65#include <linux/kernel.h>
66#include <linux/errno.h> 66#include <linux/errno.h>
67#include <linux/gfp.h>
67#include <linux/init.h> 68#include <linux/init.h>
68#include <linux/slab.h>
69#include <linux/tty.h> 69#include <linux/tty.h>
70#include <linux/tty_driver.h> 70#include <linux/tty_driver.h>
71#include <linux/tty_flip.h> 71#include <linux/tty_flip.h>
diff --git a/drivers/usb/serial/siemens_mpi.c b/drivers/usb/serial/siemens_mpi.c
index 951ea0c6ba77..cb8195cabfde 100644
--- a/drivers/usb/serial/siemens_mpi.c
+++ b/drivers/usb/serial/siemens_mpi.c
@@ -22,7 +22,7 @@
22#define DRIVER_DESC "Driver for Siemens USB/MPI adapter" 22#define DRIVER_DESC "Driver for Siemens USB/MPI adapter"
23 23
24 24
25static struct usb_device_id id_table[] = { 25static const struct usb_device_id id_table[] = {
26 /* Vendor and product id for 6ES7-972-0CB20-0XA0 */ 26 /* Vendor and product id for 6ES7-972-0CB20-0XA0 */
27 { USB_DEVICE(0x908, 0x0004) }, 27 { USB_DEVICE(0x908, 0x0004) },
28 { }, 28 { },
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 5019325ba25d..ef0bdb08d788 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -16,8 +16,9 @@
16 Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> 16 Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de>
17 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> 17 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
18*/ 18*/
19 19/* Uncomment to log function calls */
20#define DRIVER_VERSION "v.1.3.8" 20/* #define DEBUG */
21#define DRIVER_VERSION "v.1.7.16"
21#define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" 22#define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer"
22#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 23#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
23 24
@@ -25,6 +26,7 @@
25#include <linux/jiffies.h> 26#include <linux/jiffies.h>
26#include <linux/errno.h> 27#include <linux/errno.h>
27#include <linux/tty.h> 28#include <linux/tty.h>
29#include <linux/slab.h>
28#include <linux/tty_flip.h> 30#include <linux/tty_flip.h>
29#include <linux/module.h> 31#include <linux/module.h>
30#include <linux/usb.h> 32#include <linux/usb.h>
@@ -33,8 +35,10 @@
33#define SWIMS_USB_REQUEST_SetPower 0x00 35#define SWIMS_USB_REQUEST_SetPower 0x00
34#define SWIMS_USB_REQUEST_SetNmea 0x07 36#define SWIMS_USB_REQUEST_SetNmea 0x07
35 37
36#define N_IN_URB 8 38#define N_IN_URB_HM 8
37#define N_OUT_URB 64 39#define N_OUT_URB_HM 64
40#define N_IN_URB 4
41#define N_OUT_URB 4
38#define IN_BUFLEN 4096 42#define IN_BUFLEN 4096
39 43
40#define MAX_TRANSFER (PAGE_SIZE - 512) 44#define MAX_TRANSFER (PAGE_SIZE - 512)
@@ -124,6 +128,23 @@ static int is_blacklisted(const u8 ifnum,
124 return 0; 128 return 0;
125} 129}
126 130
131static int is_himemory(const u8 ifnum,
132 const struct sierra_iface_info *himemorylist)
133{
134 const u8 *info;
135 int i;
136
137 if (himemorylist) {
138 info = himemorylist->ifaceinfo;
139
140 for (i=0; i < himemorylist->infolen; i++) {
141 if (info[i] == ifnum)
142 return 1;
143 }
144 }
145 return 0;
146}
147
127static int sierra_calc_interface(struct usb_serial *serial) 148static int sierra_calc_interface(struct usb_serial *serial)
128{ 149{
129 int interface; 150 int interface;
@@ -186,15 +207,30 @@ static int sierra_probe(struct usb_serial *serial,
186 return result; 207 return result;
187} 208}
188 209
210/* interfaces with higher memory requirements */
211static const u8 hi_memory_typeA_ifaces[] = { 0, 2 };
212static const struct sierra_iface_info typeA_interface_list = {
213 .infolen = ARRAY_SIZE(hi_memory_typeA_ifaces),
214 .ifaceinfo = hi_memory_typeA_ifaces,
215};
216
217static const u8 hi_memory_typeB_ifaces[] = { 3, 4, 5, 6 };
218static const struct sierra_iface_info typeB_interface_list = {
219 .infolen = ARRAY_SIZE(hi_memory_typeB_ifaces),
220 .ifaceinfo = hi_memory_typeB_ifaces,
221};
222
223/* 'blacklist' of interfaces not served by this driver */
189static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 }; 224static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 };
190static const struct sierra_iface_info direct_ip_interface_blacklist = { 225static const struct sierra_iface_info direct_ip_interface_blacklist = {
191 .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces), 226 .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces),
192 .ifaceinfo = direct_ip_non_serial_ifaces, 227 .ifaceinfo = direct_ip_non_serial_ifaces,
193}; 228};
194 229
195static struct usb_device_id id_table [] = { 230static const struct usb_device_id id_table[] = {
196 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 231 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */
197 { USB_DEVICE(0x03F0, 0x1B1D) }, /* HP ev2200 a.k.a MC5720 */ 232 { USB_DEVICE(0x03F0, 0x1B1D) }, /* HP ev2200 a.k.a MC5720 */
233 { USB_DEVICE(0x03F0, 0x211D) }, /* HP ev2210 a.k.a MC5725 */
198 { USB_DEVICE(0x03F0, 0x1E1D) }, /* HP hs2300 a.k.a MC8775 */ 234 { USB_DEVICE(0x03F0, 0x1E1D) }, /* HP hs2300 a.k.a MC8775 */
199 235
200 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ 236 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
@@ -264,21 +300,12 @@ static struct usb_device_id id_table [] = {
264 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */ 300 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */
265 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist 301 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
266 }, 302 },
303 { USB_DEVICE(0x413C, 0x08133) }, /* Dell Computer Corp. Wireless 5720 VZW Mobile Broadband (EVDO Rev-A) Minicard GPS Port */
267 304
268 { } 305 { }
269}; 306};
270MODULE_DEVICE_TABLE(usb, id_table); 307MODULE_DEVICE_TABLE(usb, id_table);
271 308
272static struct usb_driver sierra_driver = {
273 .name = "sierra",
274 .probe = usb_serial_probe,
275 .disconnect = usb_serial_disconnect,
276 .suspend = usb_serial_suspend,
277 .resume = usb_serial_resume,
278 .id_table = id_table,
279 .no_dynamic_id = 1,
280 .supports_autosuspend = 1,
281};
282 309
283struct sierra_port_private { 310struct sierra_port_private {
284 spinlock_t lock; /* lock the structure */ 311 spinlock_t lock; /* lock the structure */
@@ -286,8 +313,10 @@ struct sierra_port_private {
286 struct usb_anchor active; 313 struct usb_anchor active;
287 struct usb_anchor delayed; 314 struct usb_anchor delayed;
288 315
316 int num_out_urbs;
317 int num_in_urbs;
289 /* Input endpoints and buffers for this port */ 318 /* Input endpoints and buffers for this port */
290 struct urb *in_urbs[N_IN_URB]; 319 struct urb *in_urbs[N_IN_URB_HM];
291 320
292 /* Settings for the port */ 321 /* Settings for the port */
293 int rts_state; /* Handshaking pins (outputs) */ 322 int rts_state; /* Handshaking pins (outputs) */
@@ -440,7 +469,7 @@ static void sierra_outdat_callback(struct urb *urb)
440static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, 469static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
441 const unsigned char *buf, int count) 470 const unsigned char *buf, int count)
442{ 471{
443 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 472 struct sierra_port_private *portdata;
444 struct sierra_intf_private *intfdata; 473 struct sierra_intf_private *intfdata;
445 struct usb_serial *serial = port->serial; 474 struct usb_serial *serial = port->serial;
446 unsigned long flags; 475 unsigned long flags;
@@ -460,7 +489,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
460 spin_lock_irqsave(&portdata->lock, flags); 489 spin_lock_irqsave(&portdata->lock, flags);
461 dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__, 490 dev_dbg(&port->dev, "%s - outstanding_urbs: %d\n", __func__,
462 portdata->outstanding_urbs); 491 portdata->outstanding_urbs);
463 if (portdata->outstanding_urbs > N_OUT_URB) { 492 if (portdata->outstanding_urbs > portdata->num_out_urbs) {
464 spin_unlock_irqrestore(&portdata->lock, flags); 493 spin_unlock_irqrestore(&portdata->lock, flags);
465 dev_dbg(&port->dev, "%s - write limit hit\n", __func__); 494 dev_dbg(&port->dev, "%s - write limit hit\n", __func__);
466 return 0; 495 return 0;
@@ -567,14 +596,15 @@ static void sierra_indat_callback(struct urb *urb)
567 } else { 596 } else {
568 if (urb->actual_length) { 597 if (urb->actual_length) {
569 tty = tty_port_tty_get(&port->port); 598 tty = tty_port_tty_get(&port->port);
570 599 if (tty) {
571 tty_buffer_request_room(tty, urb->actual_length); 600 tty_insert_flip_string(tty, data,
572 tty_insert_flip_string(tty, data, urb->actual_length); 601 urb->actual_length);
573 tty_flip_buffer_push(tty); 602 tty_flip_buffer_push(tty);
574 603
575 tty_kref_put(tty); 604 tty_kref_put(tty);
576 usb_serial_debug_data(debug, &port->dev, __func__, 605 usb_serial_debug_data(debug, &port->dev,
577 urb->actual_length, data); 606 __func__, urb->actual_length, data);
607 }
578 } else { 608 } else {
579 dev_dbg(&port->dev, "%s: empty read urb" 609 dev_dbg(&port->dev, "%s: empty read urb"
580 " received\n", __func__); 610 " received\n", __func__);
@@ -582,10 +612,10 @@ static void sierra_indat_callback(struct urb *urb)
582 } 612 }
583 613
584 /* Resubmit urb so we continue receiving */ 614 /* Resubmit urb so we continue receiving */
585 if (port->port.count && status != -ESHUTDOWN && status != -EPERM) { 615 if (status != -ESHUTDOWN && status != -EPERM) {
586 usb_mark_last_busy(port->serial->dev); 616 usb_mark_last_busy(port->serial->dev);
587 err = usb_submit_urb(urb, GFP_ATOMIC); 617 err = usb_submit_urb(urb, GFP_ATOMIC);
588 if (err) 618 if (err && err != -EPERM)
589 dev_err(&port->dev, "resubmit read urb failed." 619 dev_err(&port->dev, "resubmit read urb failed."
590 "(%d)\n", err); 620 "(%d)\n", err);
591 } 621 }
@@ -644,11 +674,11 @@ static void sierra_instat_callback(struct urb *urb)
644 dev_dbg(&port->dev, "%s: error %d\n", __func__, status); 674 dev_dbg(&port->dev, "%s: error %d\n", __func__, status);
645 675
646 /* Resubmit urb so we continue receiving IRQ data */ 676 /* Resubmit urb so we continue receiving IRQ data */
647 if (port->port.count && status != -ESHUTDOWN && status != -ENOENT) { 677 if (status != -ESHUTDOWN && status != -ENOENT) {
648 usb_mark_last_busy(serial->dev); 678 usb_mark_last_busy(serial->dev);
649 urb->dev = serial->dev; 679 urb->dev = serial->dev;
650 err = usb_submit_urb(urb, GFP_ATOMIC); 680 err = usb_submit_urb(urb, GFP_ATOMIC);
651 if (err) 681 if (err && err != -EPERM)
652 dev_err(&port->dev, "%s: resubmit intr urb " 682 dev_err(&port->dev, "%s: resubmit intr urb "
653 "failed. (%d)\n", __func__, err); 683 "failed. (%d)\n", __func__, err);
654 } 684 }
@@ -665,7 +695,7 @@ static int sierra_write_room(struct tty_struct *tty)
665 /* try to give a good number back based on if we have any free urbs at 695 /* try to give a good number back based on if we have any free urbs at
666 * this point in time */ 696 * this point in time */
667 spin_lock_irqsave(&portdata->lock, flags); 697 spin_lock_irqsave(&portdata->lock, flags);
668 if (portdata->outstanding_urbs > N_OUT_URB * 2 / 3) { 698 if (portdata->outstanding_urbs > (portdata->num_out_urbs * 2) / 3) {
669 spin_unlock_irqrestore(&portdata->lock, flags); 699 spin_unlock_irqrestore(&portdata->lock, flags);
670 dev_dbg(&port->dev, "%s - write limit hit\n", __func__); 700 dev_dbg(&port->dev, "%s - write limit hit\n", __func__);
671 return 0; 701 return 0;
@@ -680,7 +710,7 @@ static void sierra_stop_rx_urbs(struct usb_serial_port *port)
680 int i; 710 int i;
681 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 711 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
682 712
683 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) 713 for (i = 0; i < portdata->num_in_urbs; i++)
684 usb_kill_urb(portdata->in_urbs[i]); 714 usb_kill_urb(portdata->in_urbs[i]);
685 715
686 usb_kill_urb(port->interrupt_in_urb); 716 usb_kill_urb(port->interrupt_in_urb);
@@ -695,7 +725,7 @@ static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags)
695 struct sierra_port_private *portdata = usb_get_serial_port_data(port); 725 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
696 726
697 ok_cnt = 0; 727 ok_cnt = 0;
698 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 728 for (i = 0; i < portdata->num_in_urbs; i++) {
699 urb = portdata->in_urbs[i]; 729 urb = portdata->in_urbs[i];
700 if (!urb) 730 if (!urb)
701 continue; 731 continue;
@@ -791,7 +821,7 @@ static void sierra_close(struct usb_serial_port *port)
791 /* Stop reading urbs */ 821 /* Stop reading urbs */
792 sierra_stop_rx_urbs(port); 822 sierra_stop_rx_urbs(port);
793 /* .. and release them */ 823 /* .. and release them */
794 for (i = 0; i < N_IN_URB; i++) { 824 for (i = 0; i < portdata->num_in_urbs; i++) {
795 sierra_release_urb(portdata->in_urbs[i]); 825 sierra_release_urb(portdata->in_urbs[i]);
796 portdata->in_urbs[i] = NULL; 826 portdata->in_urbs[i] = NULL;
797 } 827 }
@@ -818,7 +848,7 @@ static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port)
818 848
819 849
820 endpoint = port->bulk_in_endpointAddress; 850 endpoint = port->bulk_in_endpointAddress;
821 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) { 851 for (i = 0; i < portdata->num_in_urbs; i++) {
822 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port, 852 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port,
823 IN_BUFLEN, GFP_KERNEL, 853 IN_BUFLEN, GFP_KERNEL,
824 sierra_indat_callback); 854 sierra_indat_callback);
@@ -869,7 +899,9 @@ static int sierra_startup(struct usb_serial *serial)
869{ 899{
870 struct usb_serial_port *port; 900 struct usb_serial_port *port;
871 struct sierra_port_private *portdata; 901 struct sierra_port_private *portdata;
902 struct sierra_iface_info *himemoryp = NULL;
872 int i; 903 int i;
904 u8 ifnum;
873 905
874 dev_dbg(&serial->dev->dev, "%s\n", __func__); 906 dev_dbg(&serial->dev->dev, "%s\n", __func__);
875 907
@@ -886,13 +918,40 @@ static int sierra_startup(struct usb_serial *serial)
886 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); 918 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
887 if (!portdata) { 919 if (!portdata) {
888 dev_dbg(&port->dev, "%s: kmalloc for " 920 dev_dbg(&port->dev, "%s: kmalloc for "
889 "sierra_port_private (%d) failed!.\n", 921 "sierra_port_private (%d) failed!\n",
890 __func__, i); 922 __func__, i);
891 return -ENOMEM; 923 return -ENOMEM;
892 } 924 }
893 spin_lock_init(&portdata->lock); 925 spin_lock_init(&portdata->lock);
894 init_usb_anchor(&portdata->active); 926 init_usb_anchor(&portdata->active);
895 init_usb_anchor(&portdata->delayed); 927 init_usb_anchor(&portdata->delayed);
928 ifnum = i;
929 /* Assume low memory requirements */
930 portdata->num_out_urbs = N_OUT_URB;
931 portdata->num_in_urbs = N_IN_URB;
932
933 /* Determine actual memory requirements */
934 if (serial->num_ports == 1) {
935 /* Get interface number for composite device */
936 ifnum = sierra_calc_interface(serial);
937 himemoryp =
938 (struct sierra_iface_info *)&typeB_interface_list;
939 if (is_himemory(ifnum, himemoryp)) {
940 portdata->num_out_urbs = N_OUT_URB_HM;
941 portdata->num_in_urbs = N_IN_URB_HM;
942 }
943 }
944 else {
945 himemoryp =
946 (struct sierra_iface_info *)&typeA_interface_list;
947 if (is_himemory(i, himemoryp)) {
948 portdata->num_out_urbs = N_OUT_URB_HM;
949 portdata->num_in_urbs = N_IN_URB_HM;
950 }
951 }
952 dev_dbg(&serial->dev->dev,
953 "Memory usage (urbs) interface #%d, in=%d, out=%d\n",
954 ifnum,portdata->num_in_urbs, portdata->num_out_urbs );
896 /* Set the port private data pointer */ 955 /* Set the port private data pointer */
897 usb_set_serial_port_data(port, portdata); 956 usb_set_serial_port_data(port, portdata);
898 } 957 }
@@ -940,7 +999,7 @@ static int sierra_suspend(struct usb_serial *serial, pm_message_t message)
940 struct sierra_intf_private *intfdata; 999 struct sierra_intf_private *intfdata;
941 int b; 1000 int b;
942 1001
943 if (serial->dev->auto_pm) { 1002 if (message.event & PM_EVENT_AUTO) {
944 intfdata = serial->private; 1003 intfdata = serial->private;
945 spin_lock_irq(&intfdata->susp_lock); 1004 spin_lock_irq(&intfdata->susp_lock);
946 b = intfdata->in_flight; 1005 b = intfdata->in_flight;
@@ -995,11 +1054,31 @@ static int sierra_resume(struct usb_serial *serial)
995 1054
996 return ec ? -EIO : 0; 1055 return ec ? -EIO : 0;
997} 1056}
1057
1058static int sierra_reset_resume(struct usb_interface *intf)
1059{
1060 struct usb_serial *serial = usb_get_intfdata(intf);
1061 dev_err(&serial->dev->dev, "%s\n", __func__);
1062 return usb_serial_resume(intf);
1063}
998#else 1064#else
999#define sierra_suspend NULL 1065#define sierra_suspend NULL
1000#define sierra_resume NULL 1066#define sierra_resume NULL
1067#define sierra_reset_resume NULL
1001#endif 1068#endif
1002 1069
1070static struct usb_driver sierra_driver = {
1071 .name = "sierra",
1072 .probe = usb_serial_probe,
1073 .disconnect = usb_serial_disconnect,
1074 .suspend = usb_serial_suspend,
1075 .resume = usb_serial_resume,
1076 .reset_resume = sierra_reset_resume,
1077 .id_table = id_table,
1078 .no_dynamic_id = 1,
1079 .supports_autosuspend = 1,
1080};
1081
1003static struct usb_serial_driver sierra_device = { 1082static struct usb_serial_driver sierra_device = {
1004 .driver = { 1083 .driver = {
1005 .owner = THIS_MODULE, 1084 .owner = THIS_MODULE,
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 1e58220403d1..5d39191e7244 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -45,7 +45,7 @@ static int debug;
45#define SPCP8x5_835_VID 0x04fc 45#define SPCP8x5_835_VID 0x04fc
46#define SPCP8x5_835_PID 0x0231 46#define SPCP8x5_835_PID 0x0231
47 47
48static struct usb_device_id id_table [] = { 48static const struct usb_device_id id_table[] = {
49 { USB_DEVICE(SPCP8x5_PHILIPS_VID , SPCP8x5_PHILIPS_PID)}, 49 { USB_DEVICE(SPCP8x5_PHILIPS_VID , SPCP8x5_PHILIPS_PID)},
50 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)}, 50 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)},
51 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)}, 51 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)},
@@ -609,7 +609,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
609 if (i < 0) 609 if (i < 0)
610 dev_err(&port->dev, "Set UART format %#x failed (error = %d)\n", 610 dev_err(&port->dev, "Set UART format %#x failed (error = %d)\n",
611 uartdata, i); 611 uartdata, i);
612 dbg("0x21:0x40:0:0 %d\n", i); 612 dbg("0x21:0x40:0:0 %d", i);
613 613
614 if (cflag & CRTSCTS) { 614 if (cflag & CRTSCTS) {
615 /* enable hardware flow control */ 615 /* enable hardware flow control */
@@ -677,7 +677,6 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
677 struct tty_struct *tty; 677 struct tty_struct *tty;
678 unsigned char *data = urb->transfer_buffer; 678 unsigned char *data = urb->transfer_buffer;
679 unsigned long flags; 679 unsigned long flags;
680 int i;
681 int result = urb->status; 680 int result = urb->status;
682 u8 status; 681 u8 status;
683 char tty_flag; 682 char tty_flag;
@@ -687,8 +686,6 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
687 686
688 /* check the urb status */ 687 /* check the urb status */
689 if (result) { 688 if (result) {
690 if (!port->port.count)
691 return;
692 if (result == -EPROTO) { 689 if (result == -EPROTO) {
693 /* spcp8x5 mysteriously fails with -EPROTO */ 690 /* spcp8x5 mysteriously fails with -EPROTO */
694 /* reschedule the read */ 691 /* reschedule the read */
@@ -726,26 +723,20 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
726 723
727 tty = tty_port_tty_get(&port->port); 724 tty = tty_port_tty_get(&port->port);
728 if (tty && urb->actual_length) { 725 if (tty && urb->actual_length) {
729 tty_buffer_request_room(tty, urb->actual_length + 1);
730 /* overrun is special, not associated with a char */ 726 /* overrun is special, not associated with a char */
731 if (status & UART_OVERRUN_ERROR) 727 if (status & UART_OVERRUN_ERROR)
732 tty_insert_flip_char(tty, 0, TTY_OVERRUN); 728 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
733 for (i = 0; i < urb->actual_length; ++i) 729 tty_insert_flip_string_fixed_flag(tty, data,
734 tty_insert_flip_char(tty, data[i], tty_flag); 730 urb->actual_length, tty_flag);
735 tty_flip_buffer_push(tty); 731 tty_flip_buffer_push(tty);
736 } 732 }
737 tty_kref_put(tty); 733 tty_kref_put(tty);
738 734
739 /* Schedule the next read _if_ we are still open */ 735 /* Schedule the next read */
740 if (port->port.count) { 736 urb->dev = port->serial->dev;
741 urb->dev = port->serial->dev; 737 result = usb_submit_urb(urb , GFP_ATOMIC);
742 result = usb_submit_urb(urb , GFP_ATOMIC); 738 if (result)
743 if (result) 739 dev_dbg(&port->dev, "failed submitting read urb %d\n", result);
744 dev_dbg(&port->dev, "failed submitting read urb %d\n",
745 result);
746 }
747
748 return;
749} 740}
750 741
751/* get data from ring buffer and then write to usb bus */ 742/* get data from ring buffer and then write to usb bus */
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c
index b282c0f2d8e5..d9457bd4fe10 100644
--- a/drivers/usb/serial/symbolserial.c
+++ b/drivers/usb/serial/symbolserial.c
@@ -12,6 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/slab.h>
15#include <linux/tty_driver.h> 16#include <linux/tty_driver.h>
16#include <linux/tty_flip.h> 17#include <linux/tty_flip.h>
17#include <linux/module.h> 18#include <linux/module.h>
@@ -21,7 +22,7 @@
21 22
22static int debug; 23static int debug;
23 24
24static struct usb_device_id id_table[] = { 25static const struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x05e0, 0x0600) }, 26 { USB_DEVICE(0x05e0, 0x0600) },
26 { }, 27 { },
27}; 28};
@@ -51,7 +52,6 @@ static void symbol_int_callback(struct urb *urb)
51 int status = urb->status; 52 int status = urb->status;
52 struct tty_struct *tty; 53 struct tty_struct *tty;
53 int result; 54 int result;
54 int available_room = 0;
55 int data_length; 55 int data_length;
56 56
57 dbg("%s - port %d", __func__, port->number); 57 dbg("%s - port %d", __func__, port->number);
@@ -89,18 +89,13 @@ static void symbol_int_callback(struct urb *urb)
89 */ 89 */
90 tty = tty_port_tty_get(&port->port); 90 tty = tty_port_tty_get(&port->port);
91 if (tty) { 91 if (tty) {
92 available_room = tty_buffer_request_room(tty, 92 tty_insert_flip_string(tty, &data[1], data_length);
93 data_length); 93 tty_flip_buffer_push(tty);
94 if (available_room) {
95 tty_insert_flip_string(tty, &data[1],
96 available_room);
97 tty_flip_buffer_push(tty);
98 }
99 tty_kref_put(tty); 94 tty_kref_put(tty);
100 } 95 }
101 } else { 96 } else {
102 dev_dbg(&priv->udev->dev, 97 dev_dbg(&priv->udev->dev,
103 "Improper ammount of data received from the device, " 98 "Improper amount of data received from the device, "
104 "%d bytes", urb->actual_length); 99 "%d bytes", urb->actual_length);
105 } 100 }
106 101
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 1e9dc8821698..e1bfda33f5b9 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -172,7 +172,7 @@ static unsigned int product_5052_count;
172/* the array dimension is the number of default entries plus */ 172/* the array dimension is the number of default entries plus */
173/* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */ 173/* TI_EXTRA_VID_PID_COUNT user defined entries plus 1 terminating */
174/* null entry */ 174/* null entry */
175static struct usb_device_id ti_id_table_3410[10+TI_EXTRA_VID_PID_COUNT+1] = { 175static struct usb_device_id ti_id_table_3410[13+TI_EXTRA_VID_PID_COUNT+1] = {
176 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, 176 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
177 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, 177 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
178 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, 178 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
@@ -180,6 +180,9 @@ static struct usb_device_id ti_id_table_3410[10+TI_EXTRA_VID_PID_COUNT+1] = {
180 { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, 180 { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) },
181 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, 181 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) },
182 { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, 182 { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) },
183 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) },
184 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) },
185 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) },
183 { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) }, 186 { USB_DEVICE(IBM_VENDOR_ID, IBM_4543_PRODUCT_ID) },
184 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) }, 187 { USB_DEVICE(IBM_VENDOR_ID, IBM_454B_PRODUCT_ID) },
185 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) }, 188 { USB_DEVICE(IBM_VENDOR_ID, IBM_454C_PRODUCT_ID) },
@@ -192,7 +195,7 @@ static struct usb_device_id ti_id_table_5052[5+TI_EXTRA_VID_PID_COUNT+1] = {
192 { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) }, 195 { USB_DEVICE(TI_VENDOR_ID, TI_5052_FIRMWARE_PRODUCT_ID) },
193}; 196};
194 197
195static struct usb_device_id ti_id_table_combined[14+2*TI_EXTRA_VID_PID_COUNT+1] = { 198static struct usb_device_id ti_id_table_combined[17+2*TI_EXTRA_VID_PID_COUNT+1] = {
196 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, 199 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) },
197 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) }, 200 { USB_DEVICE(TI_VENDOR_ID, TI_3410_EZ430_ID) },
198 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) }, 201 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_NO_FW_PRODUCT_ID) },
@@ -200,6 +203,9 @@ static struct usb_device_id ti_id_table_combined[14+2*TI_EXTRA_VID_PID_COUNT+1]
200 { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) }, 203 { USB_DEVICE(MTS_VENDOR_ID, MTS_CDMA_PRODUCT_ID) },
201 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) }, 204 { USB_DEVICE(MTS_VENDOR_ID, MTS_GSM_PRODUCT_ID) },
202 { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) }, 205 { USB_DEVICE(MTS_VENDOR_ID, MTS_EDGE_PRODUCT_ID) },
206 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234MU_PRODUCT_ID) },
207 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBA_PRODUCT_ID) },
208 { USB_DEVICE(MTS_VENDOR_ID, MTS_MT9234ZBAOLD_PRODUCT_ID) },
203 { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) }, 209 { USB_DEVICE(TI_VENDOR_ID, TI_5052_BOOT_PRODUCT_ID) },
204 { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) }, 210 { USB_DEVICE(TI_VENDOR_ID, TI_5152_BOOT_PRODUCT_ID) },
205 { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) }, 211 { USB_DEVICE(TI_VENDOR_ID, TI_5052_EEPROM_PRODUCT_ID) },
@@ -287,6 +293,8 @@ MODULE_FIRMWARE("ti_5052.fw");
287MODULE_FIRMWARE("mts_cdma.fw"); 293MODULE_FIRMWARE("mts_cdma.fw");
288MODULE_FIRMWARE("mts_gsm.fw"); 294MODULE_FIRMWARE("mts_gsm.fw");
289MODULE_FIRMWARE("mts_edge.fw"); 295MODULE_FIRMWARE("mts_edge.fw");
296MODULE_FIRMWARE("mts_mt9234mu.fw");
297MODULE_FIRMWARE("mts_mt9234zba.fw");
290 298
291module_param(debug, bool, S_IRUGO | S_IWUSR); 299module_param(debug, bool, S_IRUGO | S_IWUSR);
292MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes"); 300MODULE_PARM_DESC(debug, "Enable debugging, 0=no, 1=yes");
@@ -1271,14 +1279,13 @@ static void ti_recv(struct device *dev, struct tty_struct *tty,
1271 int cnt; 1279 int cnt;
1272 1280
1273 do { 1281 do {
1274 cnt = tty_buffer_request_room(tty, length); 1282 cnt = tty_insert_flip_string(tty, data, length);
1275 if (cnt < length) { 1283 if (cnt < length) {
1276 dev_err(dev, "%s - dropping data, %d bytes lost\n", 1284 dev_err(dev, "%s - dropping data, %d bytes lost\n",
1277 __func__, length - cnt); 1285 __func__, length - cnt);
1278 if (cnt == 0) 1286 if (cnt == 0)
1279 break; 1287 break;
1280 } 1288 }
1281 tty_insert_flip_string(tty, data, cnt);
1282 tty_flip_buffer_push(tty); 1289 tty_flip_buffer_push(tty);
1283 data += cnt; 1290 data += cnt;
1284 length -= cnt; 1291 length -= cnt;
@@ -1688,6 +1695,7 @@ static int ti_download_firmware(struct ti_device *tdev)
1688 const struct firmware *fw_p; 1695 const struct firmware *fw_p;
1689 char buf[32]; 1696 char buf[32];
1690 1697
1698 dbg("%s\n", __func__);
1691 /* try ID specific firmware first, then try generic firmware */ 1699 /* try ID specific firmware first, then try generic firmware */
1692 sprintf(buf, "ti_usb-v%04x-p%04x.fw", dev->descriptor.idVendor, 1700 sprintf(buf, "ti_usb-v%04x-p%04x.fw", dev->descriptor.idVendor,
1693 dev->descriptor.idProduct); 1701 dev->descriptor.idProduct);
@@ -1704,7 +1712,15 @@ static int ti_download_firmware(struct ti_device *tdev)
1704 case MTS_EDGE_PRODUCT_ID: 1712 case MTS_EDGE_PRODUCT_ID:
1705 strcpy(buf, "mts_edge.fw"); 1713 strcpy(buf, "mts_edge.fw");
1706 break; 1714 break;
1707 } 1715 case MTS_MT9234MU_PRODUCT_ID:
1716 strcpy(buf, "mts_mt9234mu.fw");
1717 break;
1718 case MTS_MT9234ZBA_PRODUCT_ID:
1719 strcpy(buf, "mts_mt9234zba.fw");
1720 break;
1721 case MTS_MT9234ZBAOLD_PRODUCT_ID:
1722 strcpy(buf, "mts_mt9234zba.fw");
1723 break; }
1708 } 1724 }
1709 if (buf[0] == '\0') { 1725 if (buf[0] == '\0') {
1710 if (tdev->td_is_3410) 1726 if (tdev->td_is_3410)
@@ -1719,7 +1735,7 @@ static int ti_download_firmware(struct ti_device *tdev)
1719 return -ENOENT; 1735 return -ENOENT;
1720 } 1736 }
1721 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) { 1737 if (fw_p->size > TI_FIRMWARE_BUF_SIZE) {
1722 dev_err(&dev->dev, "%s - firmware too large\n", __func__); 1738 dev_err(&dev->dev, "%s - firmware too large %zu\n", __func__, fw_p->size);
1723 return -ENOENT; 1739 return -ENOENT;
1724 } 1740 }
1725 1741
@@ -1731,6 +1747,7 @@ static int ti_download_firmware(struct ti_device *tdev)
1731 status = ti_do_download(dev, pipe, buffer, fw_p->size); 1747 status = ti_do_download(dev, pipe, buffer, fw_p->size);
1732 kfree(buffer); 1748 kfree(buffer);
1733 } else { 1749 } else {
1750 dbg("%s ENOMEM\n", __func__);
1734 status = -ENOMEM; 1751 status = -ENOMEM;
1735 } 1752 }
1736 release_firmware(fw_p); 1753 release_firmware(fw_p);
diff --git a/drivers/usb/serial/ti_usb_3410_5052.h b/drivers/usb/serial/ti_usb_3410_5052.h
index f323c6025858..2aac1953993b 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.h
+++ b/drivers/usb/serial/ti_usb_3410_5052.h
@@ -45,6 +45,9 @@
45#define MTS_CDMA_PRODUCT_ID 0xF110 45#define MTS_CDMA_PRODUCT_ID 0xF110
46#define MTS_GSM_PRODUCT_ID 0xF111 46#define MTS_GSM_PRODUCT_ID 0xF111
47#define MTS_EDGE_PRODUCT_ID 0xF112 47#define MTS_EDGE_PRODUCT_ID 0xF112
48#define MTS_MT9234MU_PRODUCT_ID 0xF114
49#define MTS_MT9234ZBA_PRODUCT_ID 0xF115
50#define MTS_MT9234ZBAOLD_PRODUCT_ID 0x0319
48 51
49/* Commands */ 52/* Commands */
50#define TI_GET_VERSION 0x01 53#define TI_GET_VERSION 0x01
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index bd3fa7ff15b1..3873660d8217 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -247,96 +247,66 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
247 return retval; 247 return retval;
248} 248}
249 249
250static int serial_open(struct tty_struct *tty, struct file *filp) 250static int serial_activate(struct tty_port *tport, struct tty_struct *tty)
251{ 251{
252 struct usb_serial_port *port = tty->driver_data; 252 struct usb_serial_port *port =
253 container_of(tport, struct usb_serial_port, port);
253 struct usb_serial *serial = port->serial; 254 struct usb_serial *serial = port->serial;
254 int retval; 255 int retval;
255 256
256 dbg("%s - port %d", __func__, port->number); 257 mutex_lock(&serial->disc_mutex);
257 258 if (serial->disconnected)
258 spin_lock_irq(&port->port.lock); 259 retval = -ENODEV;
259 if (!tty_hung_up_p(filp)) 260 else
260 ++port->port.count; 261 retval = port->serial->type->open(tty, port);
261 spin_unlock_irq(&port->port.lock); 262 mutex_unlock(&serial->disc_mutex);
262 tty_port_tty_set(&port->port, tty); 263 return retval;
264}
263 265
264 /* Do the device-specific open only if the hardware isn't 266static int serial_open(struct tty_struct *tty, struct file *filp)
265 * already initialized. 267{
266 */ 268 struct usb_serial_port *port = tty->driver_data;
267 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
268 if (mutex_lock_interruptible(&port->mutex))
269 return -ERESTARTSYS;
270 mutex_lock(&serial->disc_mutex);
271 if (serial->disconnected)
272 retval = -ENODEV;
273 else
274 retval = port->serial->type->open(tty, port);
275 mutex_unlock(&serial->disc_mutex);
276 mutex_unlock(&port->mutex);
277 if (retval)
278 return retval;
279 set_bit(ASYNCB_INITIALIZED, &port->port.flags);
280 }
281 269
282 /* Now do the correct tty layer semantics */ 270 dbg("%s - port %d", __func__, port->number);
283 retval = tty_port_block_til_ready(&port->port, tty, filp); 271 return tty_port_open(&port->port, tty, filp);
284 return retval;
285} 272}
286 273
287/** 274/**
288 * serial_down - shut down hardware 275 * serial_down - shut down hardware
289 * @port: port to shut down 276 * @tport: tty port to shut down
290 * 277 *
291 * Shut down a USB serial port unless it is the console. We never 278 * Shut down a USB serial port unless it is the console. We never
292 * shut down the console hardware as it will always be in use. 279 * shut down the console hardware as it will always be in use. Serialized
280 * against activate by the tport mutex and kept to matching open/close pairs
281 * of calls by the ASYNCB_INITIALIZED flag.
293 */ 282 */
294static void serial_down(struct usb_serial_port *port) 283static void serial_down(struct tty_port *tport)
295{ 284{
285 struct usb_serial_port *port =
286 container_of(tport, struct usb_serial_port, port);
296 struct usb_serial_driver *drv = port->serial->type; 287 struct usb_serial_driver *drv = port->serial->type;
297
298 /* 288 /*
299 * The console is magical. Do not hang up the console hardware 289 * The console is magical. Do not hang up the console hardware
300 * or there will be tears. 290 * or there will be tears.
301 */ 291 */
302 if (port->console) 292 if (port->console)
303 return; 293 return;
304
305 /* Don't call the close method if the hardware hasn't been
306 * initialized.
307 */
308 if (!test_and_clear_bit(ASYNCB_INITIALIZED, &port->port.flags))
309 return;
310
311 mutex_lock(&port->mutex);
312 if (drv->close) 294 if (drv->close)
313 drv->close(port); 295 drv->close(port);
314 mutex_unlock(&port->mutex);
315} 296}
316 297
317static void serial_hangup(struct tty_struct *tty) 298static void serial_hangup(struct tty_struct *tty)
318{ 299{
319 struct usb_serial_port *port = tty->driver_data; 300 struct usb_serial_port *port = tty->driver_data;
320
321 dbg("%s - port %d", __func__, port->number); 301 dbg("%s - port %d", __func__, port->number);
322
323 serial_down(port);
324 tty_port_hangup(&port->port); 302 tty_port_hangup(&port->port);
325} 303}
326 304
327static void serial_close(struct tty_struct *tty, struct file *filp) 305static void serial_close(struct tty_struct *tty, struct file *filp)
328{ 306{
329 struct usb_serial_port *port = tty->driver_data; 307 struct usb_serial_port *port = tty->driver_data;
330
331 dbg("%s - port %d", __func__, port->number); 308 dbg("%s - port %d", __func__, port->number);
332 309 tty_port_close(&port->port, tty, filp);
333 if (tty_hung_up_p(filp))
334 return;
335 if (tty_port_close_start(&port->port, tty, filp) == 0)
336 return;
337 serial_down(port);
338 tty_port_close_end(&port->port, tty);
339 tty_port_tty_set(&port->port, NULL);
340} 310}
341 311
342/** 312/**
@@ -388,10 +358,6 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
388 358
389 dbg("%s - port %d, %d byte(s)", __func__, port->number, count); 359 dbg("%s - port %d, %d byte(s)", __func__, port->number, count);
390 360
391 /* count is managed under the mutex lock for the tty so cannot
392 drop to zero until after the last close completes */
393 WARN_ON(!port->port.count);
394
395 /* pass on to the driver specific version of this function */ 361 /* pass on to the driver specific version of this function */
396 retval = port->serial->type->write(tty, port, buf, count); 362 retval = port->serial->type->write(tty, port, buf, count);
397 363
@@ -403,7 +369,6 @@ static int serial_write_room(struct tty_struct *tty)
403{ 369{
404 struct usb_serial_port *port = tty->driver_data; 370 struct usb_serial_port *port = tty->driver_data;
405 dbg("%s - port %d", __func__, port->number); 371 dbg("%s - port %d", __func__, port->number);
406 WARN_ON(!port->port.count);
407 /* pass on to the driver specific version of this function */ 372 /* pass on to the driver specific version of this function */
408 return port->serial->type->write_room(tty); 373 return port->serial->type->write_room(tty);
409} 374}
@@ -411,7 +376,7 @@ static int serial_write_room(struct tty_struct *tty)
411static int serial_chars_in_buffer(struct tty_struct *tty) 376static int serial_chars_in_buffer(struct tty_struct *tty)
412{ 377{
413 struct usb_serial_port *port = tty->driver_data; 378 struct usb_serial_port *port = tty->driver_data;
414 dbg("%s = port %d", __func__, port->number); 379 dbg("%s - port %d", __func__, port->number);
415 380
416 /* if the device was unplugged then any remaining characters 381 /* if the device was unplugged then any remaining characters
417 fell out of the connector ;) */ 382 fell out of the connector ;) */
@@ -426,7 +391,6 @@ static void serial_throttle(struct tty_struct *tty)
426 struct usb_serial_port *port = tty->driver_data; 391 struct usb_serial_port *port = tty->driver_data;
427 dbg("%s - port %d", __func__, port->number); 392 dbg("%s - port %d", __func__, port->number);
428 393
429 WARN_ON(!port->port.count);
430 /* pass on to the driver specific version of this function */ 394 /* pass on to the driver specific version of this function */
431 if (port->serial->type->throttle) 395 if (port->serial->type->throttle)
432 port->serial->type->throttle(tty); 396 port->serial->type->throttle(tty);
@@ -437,7 +401,6 @@ static void serial_unthrottle(struct tty_struct *tty)
437 struct usb_serial_port *port = tty->driver_data; 401 struct usb_serial_port *port = tty->driver_data;
438 dbg("%s - port %d", __func__, port->number); 402 dbg("%s - port %d", __func__, port->number);
439 403
440 WARN_ON(!port->port.count);
441 /* pass on to the driver specific version of this function */ 404 /* pass on to the driver specific version of this function */
442 if (port->serial->type->unthrottle) 405 if (port->serial->type->unthrottle)
443 port->serial->type->unthrottle(tty); 406 port->serial->type->unthrottle(tty);
@@ -451,8 +414,6 @@ static int serial_ioctl(struct tty_struct *tty, struct file *file,
451 414
452 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 415 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
453 416
454 WARN_ON(!port->port.count);
455
456 /* pass on to the driver specific version of this function 417 /* pass on to the driver specific version of this function
457 if it is available */ 418 if it is available */
458 if (port->serial->type->ioctl) { 419 if (port->serial->type->ioctl) {
@@ -467,7 +428,6 @@ static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
467 struct usb_serial_port *port = tty->driver_data; 428 struct usb_serial_port *port = tty->driver_data;
468 dbg("%s - port %d", __func__, port->number); 429 dbg("%s - port %d", __func__, port->number);
469 430
470 WARN_ON(!port->port.count);
471 /* pass on to the driver specific version of this function 431 /* pass on to the driver specific version of this function
472 if it is available */ 432 if it is available */
473 if (port->serial->type->set_termios) 433 if (port->serial->type->set_termios)
@@ -482,7 +442,6 @@ static int serial_break(struct tty_struct *tty, int break_state)
482 442
483 dbg("%s - port %d", __func__, port->number); 443 dbg("%s - port %d", __func__, port->number);
484 444
485 WARN_ON(!port->port.count);
486 /* pass on to the driver specific version of this function 445 /* pass on to the driver specific version of this function
487 if it is available */ 446 if it is available */
488 if (port->serial->type->break_ctl) 447 if (port->serial->type->break_ctl)
@@ -543,7 +502,6 @@ static int serial_tiocmget(struct tty_struct *tty, struct file *file)
543 502
544 dbg("%s - port %d", __func__, port->number); 503 dbg("%s - port %d", __func__, port->number);
545 504
546 WARN_ON(!port->port.count);
547 if (port->serial->type->tiocmget) 505 if (port->serial->type->tiocmget)
548 return port->serial->type->tiocmget(tty, file); 506 return port->serial->type->tiocmget(tty, file);
549 return -EINVAL; 507 return -EINVAL;
@@ -556,7 +514,6 @@ static int serial_tiocmset(struct tty_struct *tty, struct file *file,
556 514
557 dbg("%s - port %d", __func__, port->number); 515 dbg("%s - port %d", __func__, port->number);
558 516
559 WARN_ON(!port->port.count);
560 if (port->serial->type->tiocmset) 517 if (port->serial->type->tiocmset)
561 return port->serial->type->tiocmset(tty, file, set, clear); 518 return port->serial->type->tiocmset(tty, file, set, clear);
562 return -EINVAL; 519 return -EINVAL;
@@ -625,8 +582,7 @@ static void port_release(struct device *dev)
625 usb_free_urb(port->write_urb); 582 usb_free_urb(port->write_urb);
626 usb_free_urb(port->interrupt_in_urb); 583 usb_free_urb(port->interrupt_in_urb);
627 usb_free_urb(port->interrupt_out_urb); 584 usb_free_urb(port->interrupt_out_urb);
628 if (!IS_ERR(port->write_fifo) && port->write_fifo) 585 kfifo_free(&port->write_fifo);
629 kfifo_free(port->write_fifo);
630 kfree(port->bulk_in_buffer); 586 kfree(port->bulk_in_buffer);
631 kfree(port->bulk_out_buffer); 587 kfree(port->bulk_out_buffer);
632 kfree(port->interrupt_in_buffer); 588 kfree(port->interrupt_in_buffer);
@@ -725,6 +681,8 @@ static void serial_dtr_rts(struct tty_port *port, int on)
725static const struct tty_port_operations serial_port_ops = { 681static const struct tty_port_operations serial_port_ops = {
726 .carrier_raised = serial_carrier_raised, 682 .carrier_raised = serial_carrier_raised,
727 .dtr_rts = serial_dtr_rts, 683 .dtr_rts = serial_dtr_rts,
684 .activate = serial_activate,
685 .shutdown = serial_down,
728}; 686};
729 687
730int usb_serial_probe(struct usb_interface *interface, 688int usb_serial_probe(struct usb_interface *interface,
@@ -923,7 +881,8 @@ int usb_serial_probe(struct usb_interface *interface,
923 port->port.ops = &serial_port_ops; 881 port->port.ops = &serial_port_ops;
924 port->serial = serial; 882 port->serial = serial;
925 spin_lock_init(&port->lock); 883 spin_lock_init(&port->lock);
926 mutex_init(&port->mutex); 884 /* Keep this for private driver use for the moment but
885 should probably go away */
927 INIT_WORK(&port->work, usb_serial_port_work); 886 INIT_WORK(&port->work, usb_serial_port_work);
928 serial->port[i] = port; 887 serial->port[i] = port;
929 port->dev.parent = &interface->dev; 888 port->dev.parent = &interface->dev;
@@ -966,9 +925,7 @@ int usb_serial_probe(struct usb_interface *interface,
966 dev_err(&interface->dev, "No free urbs available\n"); 925 dev_err(&interface->dev, "No free urbs available\n");
967 goto probe_error; 926 goto probe_error;
968 } 927 }
969 port->write_fifo = kfifo_alloc(PAGE_SIZE, GFP_KERNEL, 928 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL))
970 &port->lock);
971 if (IS_ERR(port->write_fifo))
972 goto probe_error; 929 goto probe_error;
973 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); 930 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
974 port->bulk_out_size = buffer_size; 931 port->bulk_out_size = buffer_size;
diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index 7b5bfc4edd3d..28026b47344a 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -8,6 +8,7 @@
8 * 2 as published by the Free Software Foundation. 8 * 2 as published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/gfp.h>
11#include <linux/kernel.h> 12#include <linux/kernel.h>
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/tty.h> 14#include <linux/tty.h>
@@ -29,7 +30,7 @@ static char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = {
29 0xff, 30 0xff,
30}; 31};
31 32
32static struct usb_device_id id_table [] = { 33static const struct usb_device_id id_table[] = {
33 { USB_DEVICE(0x0525, 0x127a) }, 34 { USB_DEVICE(0x0525, 0x127a) },
34 { }, 35 { },
35}; 36};
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index ad1f9232292d..094942707c7d 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -368,7 +368,7 @@ static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
368 spin_lock_irqsave(&priv->lock, flags); 368 spin_lock_irqsave(&priv->lock, flags);
369 if (priv->outstanding_urbs > URB_UPPER_LIMIT) { 369 if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
370 spin_unlock_irqrestore(&priv->lock, flags); 370 spin_unlock_irqrestore(&priv->lock, flags);
371 dbg("%s - write limit hit\n", __func__); 371 dbg("%s - write limit hit", __func__);
372 return 0; 372 return 0;
373 } 373 }
374 priv->outstanding_urbs++; 374 priv->outstanding_urbs++;
@@ -446,7 +446,7 @@ static int visor_write_room(struct tty_struct *tty)
446 spin_lock_irqsave(&priv->lock, flags); 446 spin_lock_irqsave(&priv->lock, flags);
447 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) { 447 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
448 spin_unlock_irqrestore(&priv->lock, flags); 448 spin_unlock_irqrestore(&priv->lock, flags);
449 dbg("%s - write limit hit\n", __func__); 449 dbg("%s - write limit hit", __func__);
450 return 0; 450 return 0;
451 } 451 }
452 spin_unlock_irqrestore(&priv->lock, flags); 452 spin_unlock_irqrestore(&priv->lock, flags);
@@ -503,13 +503,9 @@ static void visor_read_bulk_callback(struct urb *urb)
503 if (urb->actual_length) { 503 if (urb->actual_length) {
504 tty = tty_port_tty_get(&port->port); 504 tty = tty_port_tty_get(&port->port);
505 if (tty) { 505 if (tty) {
506 available_room = tty_buffer_request_room(tty, 506 tty_insert_flip_string(tty, data,
507 urb->actual_length); 507 urb->actual_length);
508 if (available_room) { 508 tty_flip_buffer_push(tty);
509 tty_insert_flip_string(tty, data,
510 available_room);
511 tty_flip_buffer_push(tty);
512 }
513 tty_kref_put(tty); 509 tty_kref_put(tty);
514 } 510 }
515 spin_lock(&priv->lock); 511 spin_lock(&priv->lock);
@@ -807,10 +803,14 @@ static int clie_3_5_startup(struct usb_serial *serial)
807{ 803{
808 struct device *dev = &serial->dev->dev; 804 struct device *dev = &serial->dev->dev;
809 int result; 805 int result;
810 u8 data; 806 u8 *data;
811 807
812 dbg("%s", __func__); 808 dbg("%s", __func__);
813 809
810 data = kmalloc(1, GFP_KERNEL);
811 if (!data)
812 return -ENOMEM;
813
814 /* 814 /*
815 * Note that PEG-300 series devices expect the following two calls. 815 * Note that PEG-300 series devices expect the following two calls.
816 */ 816 */
@@ -818,36 +818,42 @@ static int clie_3_5_startup(struct usb_serial *serial)
818 /* get the config number */ 818 /* get the config number */
819 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 819 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
820 USB_REQ_GET_CONFIGURATION, USB_DIR_IN, 820 USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
821 0, 0, &data, 1, 3000); 821 0, 0, data, 1, 3000);
822 if (result < 0) { 822 if (result < 0) {
823 dev_err(dev, "%s: get config number failed: %d\n", 823 dev_err(dev, "%s: get config number failed: %d\n",
824 __func__, result); 824 __func__, result);
825 return result; 825 goto out;
826 } 826 }
827 if (result != 1) { 827 if (result != 1) {
828 dev_err(dev, "%s: get config number bad return length: %d\n", 828 dev_err(dev, "%s: get config number bad return length: %d\n",
829 __func__, result); 829 __func__, result);
830 return -EIO; 830 result = -EIO;
831 goto out;
831 } 832 }
832 833
833 /* get the interface number */ 834 /* get the interface number */
834 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 835 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
835 USB_REQ_GET_INTERFACE, 836 USB_REQ_GET_INTERFACE,
836 USB_DIR_IN | USB_RECIP_INTERFACE, 837 USB_DIR_IN | USB_RECIP_INTERFACE,
837 0, 0, &data, 1, 3000); 838 0, 0, data, 1, 3000);
838 if (result < 0) { 839 if (result < 0) {
839 dev_err(dev, "%s: get interface number failed: %d\n", 840 dev_err(dev, "%s: get interface number failed: %d\n",
840 __func__, result); 841 __func__, result);
841 return result; 842 goto out;
842 } 843 }
843 if (result != 1) { 844 if (result != 1) {
844 dev_err(dev, 845 dev_err(dev,
845 "%s: get interface number bad return length: %d\n", 846 "%s: get interface number bad return length: %d\n",
846 __func__, result); 847 __func__, result);
847 return -EIO; 848 result = -EIO;
849 goto out;
848 } 850 }
849 851
850 return generic_startup(serial); 852 result = generic_startup(serial);
853out:
854 kfree(data);
855
856 return result;
851} 857}
852 858
853static int treo_attach(struct usb_serial *serial) 859static int treo_attach(struct usb_serial *serial)
diff --git a/drivers/usb/serial/vivopay-serial.c b/drivers/usb/serial/vivopay-serial.c
new file mode 100644
index 000000000000..f719d00972fc
--- /dev/null
+++ b/drivers/usb/serial/vivopay-serial.c
@@ -0,0 +1,76 @@
1/*
2 * Copyright (C) 2001-2005 Greg Kroah-Hartman (greg@kroah.com)
3 * Copyright (C) 2009 Outpost Embedded, LLC
4 */
5
6#include <linux/kernel.h>
7#include <linux/init.h>
8#include <linux/tty.h>
9#include <linux/module.h>
10#include <linux/usb.h>
11#include <linux/usb/serial.h>
12
13
14#define DRIVER_VERSION "v1.0"
15#define DRIVER_DESC "ViVOpay USB Serial Driver"
16
17#define VIVOPAY_VENDOR_ID 0x1d5f
18
19
20static struct usb_device_id id_table [] = {
21 /* ViVOpay 8800 */
22 { USB_DEVICE(VIVOPAY_VENDOR_ID, 0x1004) },
23 { },
24};
25
26MODULE_DEVICE_TABLE(usb, id_table);
27
28static struct usb_driver vivopay_serial_driver = {
29 .name = "vivopay-serial",
30 .probe = usb_serial_probe,
31 .disconnect = usb_serial_disconnect,
32 .id_table = id_table,
33 .no_dynamic_id = 1,
34};
35
36static struct usb_serial_driver vivopay_serial_device = {
37 .driver = {
38 .owner = THIS_MODULE,
39 .name = "vivopay-serial",
40 },
41 .id_table = id_table,
42 .usb_driver = &vivopay_serial_driver,
43 .num_ports = 1,
44};
45
46static int __init vivopay_serial_init(void)
47{
48 int retval;
49 retval = usb_serial_register(&vivopay_serial_device);
50 if (retval)
51 goto failed_usb_serial_register;
52 retval = usb_register(&vivopay_serial_driver);
53 if (retval)
54 goto failed_usb_register;
55 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
56 DRIVER_DESC "\n");
57 return 0;
58failed_usb_register:
59 usb_serial_deregister(&vivopay_serial_device);
60failed_usb_serial_register:
61 return retval;
62}
63
64static void __exit vivopay_serial_exit(void)
65{
66 usb_deregister(&vivopay_serial_driver);
67 usb_serial_deregister(&vivopay_serial_device);
68}
69
70module_init(vivopay_serial_init);
71module_exit(vivopay_serial_exit);
72
73MODULE_AUTHOR("Forest Bond <forest.bond@outpostembedded.com>");
74MODULE_DESCRIPTION(DRIVER_DESC);
75MODULE_VERSION(DRIVER_VERSION);
76MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 1093d2eb046a..12ed8209ca72 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -111,17 +111,17 @@ static int debug;
111 separate ID tables, and then a third table that combines them 111 separate ID tables, and then a third table that combines them
112 just for the purpose of exporting the autoloading information. 112 just for the purpose of exporting the autoloading information.
113*/ 113*/
114static struct usb_device_id id_table_std [] = { 114static const struct usb_device_id id_table_std[] = {
115 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, 115 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
116 { } /* Terminating entry */ 116 { } /* Terminating entry */
117}; 117};
118 118
119static struct usb_device_id id_table_prerenumeration [] = { 119static const struct usb_device_id id_table_prerenumeration[] = {
120 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, 120 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
121 { } /* Terminating entry */ 121 { } /* Terminating entry */
122}; 122};
123 123
124static struct usb_device_id id_table_combined [] = { 124static const struct usb_device_id id_table_combined[] = {
125 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) }, 125 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
126 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) }, 126 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
127 { } /* Terminating entry */ 127 { } /* Terminating entry */
@@ -1492,21 +1492,9 @@ static void rx_data_softint(struct work_struct *work)
1492 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list); 1492 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
1493 urb = wrap->urb; 1493 urb = wrap->urb;
1494 1494
1495 if (tty && urb->actual_length) { 1495 if (tty && urb->actual_length)
1496 int len = tty_buffer_request_room(tty, 1496 sent += tty_insert_flip_string(tty,
1497 urb->actual_length); 1497 urb->transfer_buffer, urb->actual_length);
1498 /* This stuff can go away now I suspect */
1499 if (unlikely(len < urb->actual_length)) {
1500 spin_lock_irqsave(&info->lock, flags);
1501 list_add(tmp, &info->rx_urb_q);
1502 spin_unlock_irqrestore(&info->lock, flags);
1503 tty_flip_buffer_push(tty);
1504 schedule_work(&info->rx_work);
1505 goto out;
1506 }
1507 tty_insert_flip_string(tty, urb->transfer_buffer, len);
1508 sent += len;
1509 }
1510 1498
1511 urb->dev = port->serial->dev; 1499 urb->dev = port->serial->dev;
1512 result = usb_submit_urb(urb, GFP_ATOMIC); 1500 result = usb_submit_urb(urb, GFP_ATOMIC);
diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 67edc65acb8e..42d0eaed4a01 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/slab.h>
35 36
36#include <scsi/scsi.h> 37#include <scsi/scsi.h>
37#include <scsi/scsi_cmnd.h> 38#include <scsi/scsi_cmnd.h>
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
index 7953d93a7739..ba1b78906880 100644
--- a/drivers/usb/storage/karma.c
+++ b/drivers/usb/storage/karma.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/slab.h>
22 23
23#include <scsi/scsi.h> 24#include <scsi/scsi.h>
24#include <scsi/scsi_cmnd.h> 25#include <scsi/scsi_cmnd.h>
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index 80e65f29921c..198bb3ed95b2 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -202,7 +202,7 @@ static int onetouch_connect_input(struct us_data *ss)
202 goto fail1; 202 goto fail1;
203 203
204 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, 204 onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN,
205 GFP_ATOMIC, &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
diff --git a/drivers/usb/storage/option_ms.c b/drivers/usb/storage/option_ms.c
index 773a5cd38c5a..89460181d122 100644
--- a/drivers/usb/storage/option_ms.c
+++ b/drivers/usb/storage/option_ms.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/slab.h>
24 25
25#include "usb.h" 26#include "usb.h"
26#include "transport.h" 27#include "transport.h"
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index cfa26d56ce60..d8d98cfecada 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -43,7 +43,6 @@
43 * 675 Mass Ave, Cambridge, MA 02139, USA. 43 * 675 Mass Ave, Cambridge, MA 02139, USA.
44 */ 44 */
45 45
46#include <linux/slab.h>
47#include <linux/module.h> 46#include <linux/module.h>
48#include <linux/mutex.h> 47#include <linux/mutex.h>
49 48
@@ -73,7 +72,8 @@
73 72
74static const char* host_info(struct Scsi_Host *host) 73static const char* host_info(struct Scsi_Host *host)
75{ 74{
76 return "SCSI emulation for USB Mass Storage devices"; 75 struct us_data *us = host_to_us(host);
76 return us->scsi_name;
77} 77}
78 78
79static int slave_alloc (struct scsi_device *sdev) 79static int slave_alloc (struct scsi_device *sdev)
@@ -132,15 +132,15 @@ static int slave_configure(struct scsi_device *sdev)
132 132
133 if (us->fflags & US_FL_MAX_SECTORS_MIN) 133 if (us->fflags & US_FL_MAX_SECTORS_MIN)
134 max_sectors = PAGE_CACHE_SIZE >> 9; 134 max_sectors = PAGE_CACHE_SIZE >> 9;
135 if (queue_max_sectors(sdev->request_queue) > max_sectors) 135 if (queue_max_hw_sectors(sdev->request_queue) > max_sectors)
136 blk_queue_max_sectors(sdev->request_queue, 136 blk_queue_max_hw_sectors(sdev->request_queue,
137 max_sectors); 137 max_sectors);
138 } else if (sdev->type == TYPE_TAPE) { 138 } else if (sdev->type == TYPE_TAPE) {
139 /* Tapes need much higher max_sector limits, so just 139 /* Tapes need much higher max_sector limits, so just
140 * raise it to the maximum possible (4 GB / 512) and 140 * raise it to the maximum possible (4 GB / 512) and
141 * let the queue segment size sort out the real limit. 141 * let the queue segment size sort out the real limit.
142 */ 142 */
143 blk_queue_max_sectors(sdev->request_queue, 0x7FFFFF); 143 blk_queue_max_hw_sectors(sdev->request_queue, 0x7FFFFF);
144 } 144 }
145 145
146 /* Some USB host controllers can't do DMA; they have to use PIO. 146 /* Some USB host controllers can't do DMA; they have to use PIO.
@@ -483,7 +483,7 @@ static ssize_t show_max_sectors(struct device *dev, struct device_attribute *att
483{ 483{
484 struct scsi_device *sdev = to_scsi_device(dev); 484 struct scsi_device *sdev = to_scsi_device(dev);
485 485
486 return sprintf(buf, "%u\n", queue_max_sectors(sdev->request_queue)); 486 return sprintf(buf, "%u\n", queue_max_hw_sectors(sdev->request_queue));
487} 487}
488 488
489/* Input routine for the sysfs max_sectors file */ 489/* Input routine for the sysfs max_sectors file */
@@ -493,9 +493,9 @@ static ssize_t store_max_sectors(struct device *dev, struct device_attribute *at
493 struct scsi_device *sdev = to_scsi_device(dev); 493 struct scsi_device *sdev = to_scsi_device(dev);
494 unsigned short ms; 494 unsigned short ms;
495 495
496 if (sscanf(buf, "%hu", &ms) > 0 && ms <= SCSI_DEFAULT_MAX_SECTORS) { 496 if (sscanf(buf, "%hu", &ms) > 0) {
497 blk_queue_max_sectors(sdev->request_queue, ms); 497 blk_queue_max_hw_sectors(sdev->request_queue, ms);
498 return strlen(buf); 498 return count;
499 } 499 }
500 return -EINVAL; 500 return -EINVAL;
501} 501}
@@ -538,7 +538,7 @@ struct scsi_host_template usb_stor_host_template = {
538 .slave_configure = slave_configure, 538 .slave_configure = slave_configure,
539 539
540 /* lots of sg segments can be handled */ 540 /* lots of sg segments can be handled */
541 .sg_tablesize = SG_ALL, 541 .sg_tablesize = SCSI_MAX_SG_CHAIN_SEGMENTS,
542 542
543 /* limit the total size of a transfer to 120 KB */ 543 /* limit the total size of a transfer to 120 KB */
544 .max_sectors = 240, 544 .max_sectors = 240,
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index b62a28814ebe..bd3f415893d8 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1628,10 +1628,10 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1628 return USB_STOR_TRANSPORT_ERROR; 1628 return USB_STOR_TRANSPORT_ERROR;
1629 } 1629 }
1630 1630
1631 if ( (result = usbat_multiple_write(us, 1631 result = usbat_multiple_write(us, registers, data, 7);
1632 registers, data, 7)) != USB_STOR_TRANSPORT_GOOD) { 1632
1633 if (result != USB_STOR_TRANSPORT_GOOD)
1633 return result; 1634 return result;
1634 }
1635 1635
1636 /* 1636 /*
1637 * Write the 12-byte command header. 1637 * Write the 12-byte command header.
@@ -1643,12 +1643,11 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1643 * AT SPEED 4 IS UNRELIABLE!!! 1643 * AT SPEED 4 IS UNRELIABLE!!!
1644 */ 1644 */
1645 1645
1646 if ((result = usbat_write_block(us, 1646 result = usbat_write_block(us, USBAT_ATA, srb->cmnd, 12,
1647 USBAT_ATA, srb->cmnd, 12, 1647 srb->cmnd[0] == GPCMD_BLANK ? 75 : 10, 0);
1648 (srb->cmnd[0]==GPCMD_BLANK ? 75 : 10), 0) != 1648
1649 USB_STOR_TRANSPORT_GOOD)) { 1649 if (result != USB_STOR_TRANSPORT_GOOD)
1650 return result; 1650 return result;
1651 }
1652 1651
1653 /* If there is response data to be read in then do it here. */ 1652 /* If there is response data to be read in then do it here. */
1654 1653
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 4395c4100ec2..57fc2f532cab 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -3,6 +3,7 @@
3#include <scsi/scsi_cmnd.h> 3#include <scsi/scsi_cmnd.h>
4#include <scsi/scsi_device.h> 4#include <scsi/scsi_device.h>
5#include <linux/usb.h> 5#include <linux/usb.h>
6#include <linux/slab.h>
6 7
7#include "usb.h" 8#include "usb.h"
8#include "transport.h" 9#include "transport.h"
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 589f6b4404f0..f253edec3bb8 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -44,8 +44,10 @@
44 */ 44 */
45 45
46#include <linux/sched.h> 46#include <linux/sched.h>
47#include <linux/gfp.h>
47#include <linux/errno.h> 48#include <linux/errno.h>
48#include <linux/slab.h> 49
50#include <linux/usb/quirks.h>
49 51
50#include <scsi/scsi.h> 52#include <scsi/scsi.h>
51#include <scsi/scsi_eh.h> 53#include <scsi/scsi_eh.h>
@@ -666,10 +668,11 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
666 * to wait for at least one CHECK_CONDITION to determine 668 * to wait for at least one CHECK_CONDITION to determine
667 * SANE_SENSE support 669 * SANE_SENSE support
668 */ 670 */
669 if ((srb->cmnd[0] == ATA_16 || srb->cmnd[0] == ATA_12) && 671 if (unlikely((srb->cmnd[0] == ATA_16 || srb->cmnd[0] == ATA_12) &&
670 result == USB_STOR_TRANSPORT_GOOD && 672 result == USB_STOR_TRANSPORT_GOOD &&
671 !(us->fflags & US_FL_SANE_SENSE) && 673 !(us->fflags & US_FL_SANE_SENSE) &&
672 !(srb->cmnd[2] & 0x20)) { 674 !(us->fflags & US_FL_BAD_SENSE) &&
675 !(srb->cmnd[2] & 0x20))) {
673 US_DEBUGP("-- SAT supported, increasing auto-sense\n"); 676 US_DEBUGP("-- SAT supported, increasing auto-sense\n");
674 us->fflags |= US_FL_SANE_SENSE; 677 us->fflags |= US_FL_SANE_SENSE;
675 } 678 }
@@ -718,6 +721,12 @@ Retry_Sense:
718 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { 721 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
719 US_DEBUGP("-- auto-sense aborted\n"); 722 US_DEBUGP("-- auto-sense aborted\n");
720 srb->result = DID_ABORT << 16; 723 srb->result = DID_ABORT << 16;
724
725 /* If SANE_SENSE caused this problem, disable it */
726 if (sense_size != US_SENSE_SIZE) {
727 us->fflags &= ~US_FL_SANE_SENSE;
728 us->fflags |= US_FL_BAD_SENSE;
729 }
721 goto Handle_Errors; 730 goto Handle_Errors;
722 } 731 }
723 732
@@ -727,10 +736,11 @@ Retry_Sense:
727 * (small) sense request. This fixes some USB GSM modems 736 * (small) sense request. This fixes some USB GSM modems
728 */ 737 */
729 if (temp_result == USB_STOR_TRANSPORT_FAILED && 738 if (temp_result == USB_STOR_TRANSPORT_FAILED &&
730 (us->fflags & US_FL_SANE_SENSE) && 739 sense_size != US_SENSE_SIZE) {
731 sense_size != US_SENSE_SIZE) {
732 US_DEBUGP("-- auto-sense failure, retry small sense\n"); 740 US_DEBUGP("-- auto-sense failure, retry small sense\n");
733 sense_size = US_SENSE_SIZE; 741 sense_size = US_SENSE_SIZE;
742 us->fflags &= ~US_FL_SANE_SENSE;
743 us->fflags |= US_FL_BAD_SENSE;
734 goto Retry_Sense; 744 goto Retry_Sense;
735 } 745 }
736 746
@@ -754,6 +764,7 @@ Retry_Sense:
754 */ 764 */
755 if (srb->sense_buffer[7] > (US_SENSE_SIZE - 8) && 765 if (srb->sense_buffer[7] > (US_SENSE_SIZE - 8) &&
756 !(us->fflags & US_FL_SANE_SENSE) && 766 !(us->fflags & US_FL_SANE_SENSE) &&
767 !(us->fflags & US_FL_BAD_SENSE) &&
757 (srb->sense_buffer[0] & 0x7C) == 0x70) { 768 (srb->sense_buffer[0] & 0x7C) == 0x70) {
758 US_DEBUGP("-- SANE_SENSE support enabled\n"); 769 US_DEBUGP("-- SANE_SENSE support enabled\n");
759 us->fflags |= US_FL_SANE_SENSE; 770 us->fflags |= US_FL_SANE_SENSE;
@@ -1288,6 +1299,10 @@ int usb_stor_port_reset(struct us_data *us)
1288{ 1299{
1289 int result; 1300 int result;
1290 1301
1302 /*for these devices we must use the class specific method */
1303 if (us->pusb_dev->quirks & USB_QUIRK_RESET_MORPHS)
1304 return -EPERM;
1305
1291 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); 1306 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1292 if (result < 0) 1307 if (result < 0)
1293 US_DEBUGP("unable to lock device for reset: %d\n", result); 1308 US_DEBUGP("unable to lock device for reset: %d\n", result);
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index d4f034ebaa8a..ccf1dbbb87ef 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -374,6 +374,15 @@ UNUSUAL_DEV( 0x04ce, 0x0002, 0x0074, 0x0074,
374 US_SC_DEVICE, US_PR_DEVICE, NULL, 374 US_SC_DEVICE, US_PR_DEVICE, NULL,
375 US_FL_FIX_INQUIRY), 375 US_FL_FIX_INQUIRY),
376 376
377/* Reported by Ondrej Zary <linux@rainbow-software.org>
378 * The device reports one sector more and breaks when that sector is accessed
379 */
380UNUSUAL_DEV( 0x04ce, 0x0002, 0x026c, 0x026c,
381 "ScanLogic",
382 "SL11R-IDE",
383 US_SC_DEVICE, US_PR_DEVICE, NULL,
384 US_FL_FIX_CAPACITY),
385
377/* Reported by Kriston Fincher <kriston@airmail.net> 386/* Reported by Kriston Fincher <kriston@airmail.net>
378 * Patch submitted by Sean Millichamp <sean@bruenor.org> 387 * Patch submitted by Sean Millichamp <sean@bruenor.org>
379 * This is to support the Panasonic PalmCam PV-SD4090 388 * This is to support the Panasonic PalmCam PV-SD4090
@@ -818,6 +827,13 @@ UNUSUAL_DEV( 0x066f, 0x8000, 0x0001, 0x0001,
818 US_SC_DEVICE, US_PR_DEVICE, NULL, 827 US_SC_DEVICE, US_PR_DEVICE, NULL,
819 US_FL_FIX_CAPACITY ), 828 US_FL_FIX_CAPACITY ),
820 829
830/* Reported by Daniel Kukula <daniel.kuku@gmail.com> */
831UNUSUAL_DEV( 0x067b, 0x1063, 0x0100, 0x0100,
832 "Prolific Technology, Inc.",
833 "Prolific Storage Gadget",
834 US_SC_DEVICE, US_PR_DEVICE, NULL,
835 US_FL_BAD_SENSE ),
836
821/* Reported by Rogerio Brito <rbrito@ime.usp.br> */ 837/* Reported by Rogerio Brito <rbrito@ime.usp.br> */
822UNUSUAL_DEV( 0x067b, 0x2317, 0x0001, 0x001, 838UNUSUAL_DEV( 0x067b, 0x2317, 0x0001, 0x001,
823 "Prolific Technology, Inc.", 839 "Prolific Technology, Inc.",
@@ -934,7 +950,7 @@ UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999,
934UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133, 950UNUSUAL_DEV( 0x07af, 0x0004, 0x0100, 0x0133,
935 "Microtech", 951 "Microtech",
936 "USB-SCSI-DB25", 952 "USB-SCSI-DB25",
937 US_SC_SCSI, US_PR_BULK, usb_stor_euscsi_init, 953 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init,
938 US_FL_SCM_MULT_TARG ), 954 US_FL_SCM_MULT_TARG ),
939 955
940UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100, 956UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100,
@@ -1140,8 +1156,8 @@ UNUSUAL_DEV( 0x0af0, 0x7401, 0x0000, 0x0000,
1140 0 ), 1156 0 ),
1141 1157
1142/* Reported by Jan Dumon <j.dumon@option.com> 1158/* Reported by Jan Dumon <j.dumon@option.com>
1143 * This device (wrongly) has a vendor-specific device descriptor. 1159 * These devices (wrongly) have a vendor-specific device descriptor.
1144 * The entry is needed so usb-storage can bind to it's mass-storage 1160 * These entries are needed so usb-storage can bind to their mass-storage
1145 * interface as an interface driver */ 1161 * interface as an interface driver */
1146UNUSUAL_DEV( 0x0af0, 0x7501, 0x0000, 0x0000, 1162UNUSUAL_DEV( 0x0af0, 0x7501, 0x0000, 0x0000,
1147 "Option", 1163 "Option",
@@ -1149,6 +1165,90 @@ UNUSUAL_DEV( 0x0af0, 0x7501, 0x0000, 0x0000,
1149 US_SC_DEVICE, US_PR_DEVICE, NULL, 1165 US_SC_DEVICE, US_PR_DEVICE, NULL,
1150 0 ), 1166 0 ),
1151 1167
1168UNUSUAL_DEV( 0x0af0, 0x7701, 0x0000, 0x0000,
1169 "Option",
1170 "GI 0451 SD-Card",
1171 US_SC_DEVICE, US_PR_DEVICE, NULL,
1172 0 ),
1173
1174UNUSUAL_DEV( 0x0af0, 0x7706, 0x0000, 0x0000,
1175 "Option",
1176 "GI 0451 SD-Card",
1177 US_SC_DEVICE, US_PR_DEVICE, NULL,
1178 0 ),
1179
1180UNUSUAL_DEV( 0x0af0, 0x7901, 0x0000, 0x0000,
1181 "Option",
1182 "GI 0452 SD-Card",
1183 US_SC_DEVICE, US_PR_DEVICE, NULL,
1184 0 ),
1185
1186UNUSUAL_DEV( 0x0af0, 0x7A01, 0x0000, 0x0000,
1187 "Option",
1188 "GI 0461 SD-Card",
1189 US_SC_DEVICE, US_PR_DEVICE, NULL,
1190 0 ),
1191
1192UNUSUAL_DEV( 0x0af0, 0x7A05, 0x0000, 0x0000,
1193 "Option",
1194 "GI 0461 SD-Card",
1195 US_SC_DEVICE, US_PR_DEVICE, NULL,
1196 0 ),
1197
1198UNUSUAL_DEV( 0x0af0, 0x8300, 0x0000, 0x0000,
1199 "Option",
1200 "GI 033x SD-Card",
1201 US_SC_DEVICE, US_PR_DEVICE, NULL,
1202 0 ),
1203
1204UNUSUAL_DEV( 0x0af0, 0x8302, 0x0000, 0x0000,
1205 "Option",
1206 "GI 033x SD-Card",
1207 US_SC_DEVICE, US_PR_DEVICE, NULL,
1208 0 ),
1209
1210UNUSUAL_DEV( 0x0af0, 0x8304, 0x0000, 0x0000,
1211 "Option",
1212 "GI 033x SD-Card",
1213 US_SC_DEVICE, US_PR_DEVICE, NULL,
1214 0 ),
1215
1216UNUSUAL_DEV( 0x0af0, 0xc100, 0x0000, 0x0000,
1217 "Option",
1218 "GI 070x SD-Card",
1219 US_SC_DEVICE, US_PR_DEVICE, NULL,
1220 0 ),
1221
1222UNUSUAL_DEV( 0x0af0, 0xd057, 0x0000, 0x0000,
1223 "Option",
1224 "GI 1505 SD-Card",
1225 US_SC_DEVICE, US_PR_DEVICE, NULL,
1226 0 ),
1227
1228UNUSUAL_DEV( 0x0af0, 0xd058, 0x0000, 0x0000,
1229 "Option",
1230 "GI 1509 SD-Card",
1231 US_SC_DEVICE, US_PR_DEVICE, NULL,
1232 0 ),
1233
1234UNUSUAL_DEV( 0x0af0, 0xd157, 0x0000, 0x0000,
1235 "Option",
1236 "GI 1515 SD-Card",
1237 US_SC_DEVICE, US_PR_DEVICE, NULL,
1238 0 ),
1239
1240UNUSUAL_DEV( 0x0af0, 0xd257, 0x0000, 0x0000,
1241 "Option",
1242 "GI 1215 SD-Card",
1243 US_SC_DEVICE, US_PR_DEVICE, NULL,
1244 0 ),
1245
1246UNUSUAL_DEV( 0x0af0, 0xd357, 0x0000, 0x0000,
1247 "Option",
1248 "GI 1505 SD-Card",
1249 US_SC_DEVICE, US_PR_DEVICE, NULL,
1250 0 ),
1251
1152/* Reported by Ben Efros <ben@pc-doctor.com> */ 1252/* Reported by Ben Efros <ben@pc-doctor.com> */
1153UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000, 1253UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000,
1154 "Seagate", 1254 "Seagate",
@@ -1289,20 +1389,6 @@ UNUSUAL_DEV( 0x0f19, 0x0105, 0x0100, 0x0100,
1289 US_SC_DEVICE, US_PR_DEVICE, NULL, 1389 US_SC_DEVICE, US_PR_DEVICE, NULL,
1290 US_FL_IGNORE_RESIDUE ), 1390 US_FL_IGNORE_RESIDUE ),
1291 1391
1292/* Jeremy Katz <katzj@redhat.com>:
1293 * The Blackberry Pearl can run in two modes; a usb-storage only mode
1294 * and a mode that allows access via mass storage and to its database.
1295 * The berry_charge module will set the device to dual mode and thus we
1296 * should ignore its native mode if that module is built
1297 */
1298#ifdef CONFIG_USB_BERRY_CHARGE
1299UNUSUAL_DEV( 0x0fca, 0x0006, 0x0001, 0x0001,
1300 "RIM",
1301 "Blackberry Pearl",
1302 US_SC_DEVICE, US_PR_DEVICE, NULL,
1303 US_FL_IGNORE_DEVICE ),
1304#endif
1305
1306/* Reported by Michael Stattmann <michael@stattmann.com> */ 1392/* Reported by Michael Stattmann <michael@stattmann.com> */
1307UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000, 1393UNUSUAL_DEV( 0x0fce, 0xd008, 0x0000, 0x0000,
1308 "Sony Ericsson", 1394 "Sony Ericsson",
@@ -1800,13 +1886,6 @@ UNUSUAL_DEV( 0x2735, 0x100b, 0x0000, 0x9999,
1800 US_SC_DEVICE, US_PR_DEVICE, NULL, 1886 US_SC_DEVICE, US_PR_DEVICE, NULL,
1801 US_FL_GO_SLOW ), 1887 US_FL_GO_SLOW ),
1802 1888
1803/* Reported by Rohan Hart <rohan.hart17@gmail.com> */
1804UNUSUAL_DEV( 0x2770, 0x915d, 0x0010, 0x0010,
1805 "INTOVA",
1806 "Pixtreme",
1807 US_SC_DEVICE, US_PR_DEVICE, NULL,
1808 US_FL_FIX_CAPACITY ),
1809
1810/* Reported by Frederic Marchal <frederic.marchal@wowcompany.com> 1889/* Reported by Frederic Marchal <frederic.marchal@wowcompany.com>
1811 * Mio Moov 330 1890 * Mio Moov 330
1812 */ 1891 */
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 8060b85fe1a3..bbeeb92a2131 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -45,6 +45,10 @@
45 * 675 Mass Ave, Cambridge, MA 02139, USA. 45 * 675 Mass Ave, Cambridge, MA 02139, USA.
46 */ 46 */
47 47
48#ifdef CONFIG_USB_STORAGE_DEBUG
49#define DEBUG
50#endif
51
48#include <linux/sched.h> 52#include <linux/sched.h>
49#include <linux/errno.h> 53#include <linux/errno.h>
50#include <linux/freezer.h> 54#include <linux/freezer.h>
@@ -74,7 +78,7 @@ MODULE_AUTHOR("Matthew Dharm <mdharm-usb@one-eyed-alien.net>");
74MODULE_DESCRIPTION("USB Mass Storage driver for Linux"); 78MODULE_DESCRIPTION("USB Mass Storage driver for Linux");
75MODULE_LICENSE("GPL"); 79MODULE_LICENSE("GPL");
76 80
77static unsigned int delay_use = 5; 81static unsigned int delay_use = 1;
78module_param(delay_use, uint, S_IRUGO | S_IWUSR); 82module_param(delay_use, uint, S_IRUGO | S_IWUSR);
79MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device"); 83MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
80 84
@@ -228,6 +232,7 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data,
228 if (data_len<36) // You lose. 232 if (data_len<36) // You lose.
229 return; 233 return;
230 234
235 memset(data+8, ' ', 28);
231 if(data[0]&0x20) { /* USB device currently not connected. Return 236 if(data[0]&0x20) { /* USB device currently not connected. Return
232 peripheral qualifier 001b ("...however, the 237 peripheral qualifier 001b ("...however, the
233 physical device is not currently connected 238 physical device is not currently connected
@@ -237,15 +242,15 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data,
237 device, it may return zeros or ASCII spaces 242 device, it may return zeros or ASCII spaces
238 (20h) in those fields until the data is 243 (20h) in those fields until the data is
239 available from the device."). */ 244 available from the device."). */
240 memset(data+8,0,28);
241 } else { 245 } else {
242 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); 246 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
243 memcpy(data+8, us->unusual_dev->vendorName, 247 int n;
244 strlen(us->unusual_dev->vendorName) > 8 ? 8 : 248
245 strlen(us->unusual_dev->vendorName)); 249 n = strlen(us->unusual_dev->vendorName);
246 memcpy(data+16, us->unusual_dev->productName, 250 memcpy(data+8, us->unusual_dev->vendorName, min(8, n));
247 strlen(us->unusual_dev->productName) > 16 ? 16 : 251 n = strlen(us->unusual_dev->productName);
248 strlen(us->unusual_dev->productName)); 252 memcpy(data+16, us->unusual_dev->productName, min(16, n));
253
249 data[32] = 0x30 + ((bcdDevice>>12) & 0x0F); 254 data[32] = 0x30 + ((bcdDevice>>12) & 0x0F);
250 data[33] = 0x30 + ((bcdDevice>>8) & 0x0F); 255 data[33] = 0x30 + ((bcdDevice>>8) & 0x0F);
251 data[34] = 0x30 + ((bcdDevice>>4) & 0x0F); 256 data[34] = 0x30 + ((bcdDevice>>4) & 0x0F);
@@ -429,7 +434,8 @@ static void adjust_quirks(struct us_data *us)
429 u16 vid = le16_to_cpu(us->pusb_dev->descriptor.idVendor); 434 u16 vid = le16_to_cpu(us->pusb_dev->descriptor.idVendor);
430 u16 pid = le16_to_cpu(us->pusb_dev->descriptor.idProduct); 435 u16 pid = le16_to_cpu(us->pusb_dev->descriptor.idProduct);
431 unsigned f = 0; 436 unsigned f = 0;
432 unsigned int mask = (US_FL_SANE_SENSE | US_FL_FIX_CAPACITY | 437 unsigned int mask = (US_FL_SANE_SENSE | US_FL_BAD_SENSE |
438 US_FL_FIX_CAPACITY |
433 US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE | 439 US_FL_CAPACITY_HEURISTICS | US_FL_IGNORE_DEVICE |
434 US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 | 440 US_FL_NOT_LOCKABLE | US_FL_MAX_SECTORS_64 |
435 US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE | 441 US_FL_CAPACITY_OK | US_FL_IGNORE_RESIDUE |
@@ -459,6 +465,9 @@ static void adjust_quirks(struct us_data *us)
459 case 'a': 465 case 'a':
460 f |= US_FL_SANE_SENSE; 466 f |= US_FL_SANE_SENSE;
461 break; 467 break;
468 case 'b':
469 f |= US_FL_BAD_SENSE;
470 break;
462 case 'c': 471 case 'c':
463 f |= US_FL_FIX_CAPACITY; 472 f |= US_FL_FIX_CAPACITY;
464 break; 473 break;
@@ -808,14 +817,13 @@ static int usb_stor_scan_thread(void * __us)
808{ 817{
809 struct us_data *us = (struct us_data *)__us; 818 struct us_data *us = (struct us_data *)__us;
810 819
811 printk(KERN_DEBUG 820 dev_dbg(&us->pusb_intf->dev, "device found\n");
812 "usb-storage: device found at %d\n", us->pusb_dev->devnum);
813 821
814 set_freezable(); 822 set_freezable();
815 /* Wait for the timeout to expire or for a disconnect */ 823 /* Wait for the timeout to expire or for a disconnect */
816 if (delay_use > 0) { 824 if (delay_use > 0) {
817 printk(KERN_DEBUG "usb-storage: waiting for device " 825 dev_dbg(&us->pusb_intf->dev, "waiting for device to settle "
818 "to settle before scanning\n"); 826 "before scanning\n");
819 wait_event_freezable_timeout(us->delay_wait, 827 wait_event_freezable_timeout(us->delay_wait,
820 test_bit(US_FLIDX_DONT_SCAN, &us->dflags), 828 test_bit(US_FLIDX_DONT_SCAN, &us->dflags),
821 delay_use * HZ); 829 delay_use * HZ);
@@ -832,7 +840,7 @@ static int usb_stor_scan_thread(void * __us)
832 mutex_unlock(&us->dev_mutex); 840 mutex_unlock(&us->dev_mutex);
833 } 841 }
834 scsi_scan_host(us_to_host(us)); 842 scsi_scan_host(us_to_host(us));
835 printk(KERN_DEBUG "usb-storage: device scan complete\n"); 843 dev_dbg(&us->pusb_intf->dev, "scan complete\n");
836 844
837 /* Should we unbind if no devices were detected? */ 845 /* Should we unbind if no devices were detected? */
838 } 846 }
@@ -840,6 +848,15 @@ static int usb_stor_scan_thread(void * __us)
840 complete_and_exit(&us->scanning_done, 0); 848 complete_and_exit(&us->scanning_done, 0);
841} 849}
842 850
851static unsigned int usb_stor_sg_tablesize(struct usb_interface *intf)
852{
853 struct usb_device *usb_dev = interface_to_usbdev(intf);
854
855 if (usb_dev->bus->sg_tablesize) {
856 return usb_dev->bus->sg_tablesize;
857 }
858 return SG_ALL;
859}
843 860
844/* First part of general USB mass-storage probing */ 861/* First part of general USB mass-storage probing */
845int usb_stor_probe1(struct us_data **pus, 862int usb_stor_probe1(struct us_data **pus,
@@ -868,6 +885,7 @@ int usb_stor_probe1(struct us_data **pus,
868 * Allow 16-byte CDBs and thus > 2TB 885 * Allow 16-byte CDBs and thus > 2TB
869 */ 886 */
870 host->max_cmd_len = 16; 887 host->max_cmd_len = 16;
888 host->sg_tablesize = usb_stor_sg_tablesize(intf);
871 *pus = us = host_to_us(host); 889 *pus = us = host_to_us(host);
872 memset(us, 0, sizeof(struct us_data)); 890 memset(us, 0, sizeof(struct us_data));
873 mutex_init(&(us->dev_mutex)); 891 mutex_init(&(us->dev_mutex));
@@ -929,6 +947,8 @@ int usb_stor_probe2(struct us_data *us)
929 result = usb_stor_acquire_resources(us); 947 result = usb_stor_acquire_resources(us);
930 if (result) 948 if (result)
931 goto BadDevice; 949 goto BadDevice;
950 snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",
951 dev_name(&us->pusb_intf->dev));
932 result = scsi_add_host(us_to_host(us), &us->pusb_intf->dev); 952 result = scsi_add_host(us_to_host(us), &us->pusb_intf->dev);
933 if (result) { 953 if (result) {
934 printk(KERN_WARNING USB_STORAGE 954 printk(KERN_WARNING USB_STORAGE
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 2609efb2bd7e..69717134231b 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -132,6 +132,7 @@ struct us_data {
132 /* SCSI interfaces */ 132 /* SCSI interfaces */
133 struct scsi_cmnd *srb; /* current srb */ 133 struct scsi_cmnd *srb; /* current srb */
134 unsigned int tag; /* current dCBWTag */ 134 unsigned int tag; /* current dCBWTag */
135 char scsi_name[32]; /* scsi_host name */
135 136
136 /* control and bulk communications data */ 137 /* control and bulk communications data */
137 struct urb *current_urb; /* USB requests */ 138 struct urb *current_urb; /* USB requests */
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index b62f2bc064f6..61522787f39c 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -28,7 +28,7 @@
28#define USB_SKEL_PRODUCT_ID 0xfff0 28#define USB_SKEL_PRODUCT_ID 0xfff0
29 29
30/* table of devices that work with this driver */ 30/* table of devices that work with this driver */
31static struct usb_device_id skel_table[] = { 31static const struct usb_device_id skel_table[] = {
32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 32 { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
33 { } /* Terminating entry */ 33 { } /* Terminating entry */
34}; 34};
@@ -358,7 +358,7 @@ retry:
358 rv = skel_do_read_io(dev, count); 358 rv = skel_do_read_io(dev, count);
359 if (rv < 0) 359 if (rv < 0)
360 goto exit; 360 goto exit;
361 else if (!file->f_flags & O_NONBLOCK) 361 else if (!(file->f_flags & O_NONBLOCK))
362 goto retry; 362 goto retry;
363 rv = -EAGAIN; 363 rv = -EAGAIN;
364 } 364 }
@@ -411,7 +411,7 @@ static ssize_t skel_write(struct file *file, const char *user_buffer,
411 * limit the number of URBs in flight to stop a user from using up all 411 * limit the number of URBs in flight to stop a user from using up all
412 * RAM 412 * RAM
413 */ 413 */
414 if (!file->f_flags & O_NONBLOCK) { 414 if (!(file->f_flags & O_NONBLOCK)) {
415 if (down_interruptible(&dev->limit_sem)) { 415 if (down_interruptible(&dev->limit_sem)) {
416 retval = -ERESTARTSYS; 416 retval = -ERESTARTSYS;
417 goto exit; 417 goto exit;
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index 25eae405f622..c0c5665e60a9 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -92,6 +92,7 @@
92#include <linux/interrupt.h> 92#include <linux/interrupt.h>
93#include <linux/delay.h> 93#include <linux/delay.h>
94#include <linux/random.h> 94#include <linux/random.h>
95#include <linux/slab.h>
95#include <linux/mutex.h> 96#include <linux/mutex.h>
96#include <linux/uwb.h> 97#include <linux/uwb.h>
97#include <linux/usb/wusb.h> 98#include <linux/usb/wusb.h>
@@ -641,7 +642,7 @@ static void cbaf_disconnect(struct usb_interface *iface)
641 kzfree(cbaf); 642 kzfree(cbaf);
642} 643}
643 644
644static struct usb_device_id cbaf_id_table[] = { 645static const struct usb_device_id cbaf_id_table[] = {
645 { USB_INTERFACE_INFO(0xef, 0x03, 0x01), }, 646 { USB_INTERFACE_INFO(0xef, 0x03, 0x01), },
646 { }, 647 { },
647}; 648};
diff --git a/drivers/usb/wusbcore/crypto.c b/drivers/usb/wusbcore/crypto.c
index 9ec7fd5da489..827c87f10cc5 100644
--- a/drivers/usb/wusbcore/crypto.c
+++ b/drivers/usb/wusbcore/crypto.c
@@ -49,6 +49,7 @@
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/err.h> 50#include <linux/err.h>
51#include <linux/uwb.h> 51#include <linux/uwb.h>
52#include <linux/slab.h>
52#include <linux/usb/wusb.h> 53#include <linux/usb/wusb.h>
53#include <linux/scatterlist.h> 54#include <linux/scatterlist.h>
54 55
@@ -111,7 +112,7 @@ struct aes_ccm_b1 {
111 * 112 *
112 * CCM uses Ax blocks to generate a keystream with which the MIC and 113 * CCM uses Ax blocks to generate a keystream with which the MIC and
113 * the message's payload are encoded. A0 always encrypts/decrypts the 114 * the message's payload are encoded. A0 always encrypts/decrypts the
114 * MIC. Ax (x>0) are used for the sucesive payload blocks. 115 * MIC. Ax (x>0) are used for the successive payload blocks.
115 * 116 *
116 * The x is the counter, and is increased for each block. 117 * The x is the counter, and is increased for each block.
117 */ 118 */
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 4ac4300a3f9a..7ec24e46b34b 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -88,6 +88,7 @@
88 88
89#include <linux/jiffies.h> 89#include <linux/jiffies.h>
90#include <linux/ctype.h> 90#include <linux/ctype.h>
91#include <linux/slab.h>
91#include <linux/workqueue.h> 92#include <linux/workqueue.h>
92#include "wusbhc.h" 93#include "wusbhc.h"
93 94
@@ -119,10 +120,12 @@ static struct wusb_dev *wusb_dev_alloc(struct wusbhc *wusbhc)
119 urb = usb_alloc_urb(0, GFP_KERNEL); 120 urb = usb_alloc_urb(0, GFP_KERNEL);
120 if (urb == NULL) 121 if (urb == NULL)
121 goto err; 122 goto err;
123 wusb_dev->set_gtk_urb = urb;
122 124
123 req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); 125 req = kmalloc(sizeof(*req), GFP_KERNEL);
124 if (req == NULL) 126 if (req == NULL)
125 goto err; 127 goto err;
128 wusb_dev->set_gtk_req = req;
126 129
127 req->bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE; 130 req->bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
128 req->bRequest = USB_REQ_SET_DESCRIPTOR; 131 req->bRequest = USB_REQ_SET_DESCRIPTOR;
@@ -130,9 +133,6 @@ static struct wusb_dev *wusb_dev_alloc(struct wusbhc *wusbhc)
130 req->wIndex = 0; 133 req->wIndex = 0;
131 req->wLength = cpu_to_le16(wusbhc->gtk.descr.bLength); 134 req->wLength = cpu_to_le16(wusbhc->gtk.descr.bLength);
132 135
133 wusb_dev->set_gtk_urb = urb;
134 wusb_dev->set_gtk_req = req;
135
136 return wusb_dev; 136 return wusb_dev;
137err: 137err:
138 wusb_dev_free(wusb_dev); 138 wusb_dev_free(wusb_dev);
@@ -438,7 +438,7 @@ static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
438 old_keep_alives = ie->hdr.bLength - sizeof(ie->hdr); 438 old_keep_alives = ie->hdr.bLength - sizeof(ie->hdr);
439 keep_alives = 0; 439 keep_alives = 0;
440 for (cnt = 0; 440 for (cnt = 0;
441 keep_alives <= WUIE_ELT_MAX && cnt < wusbhc->ports_max; 441 keep_alives < WUIE_ELT_MAX && cnt < wusbhc->ports_max;
442 cnt++) { 442 cnt++) {
443 unsigned tt = msecs_to_jiffies(wusbhc->trust_timeout); 443 unsigned tt = msecs_to_jiffies(wusbhc->trust_timeout);
444 444
@@ -869,7 +869,7 @@ static struct usb_wireless_cap_descriptor wusb_cap_descr_default = {
869 * reference that we'll drop. 869 * reference that we'll drop.
870 * 870 *
871 * First we need to determine if the device is a WUSB device (else we 871 * First we need to determine if the device is a WUSB device (else we
872 * ignore it). For that we use the speed setting (USB_SPEED_VARIABLE) 872 * ignore it). For that we use the speed setting (USB_SPEED_WIRELESS)
873 * [FIXME: maybe we'd need something more definitive]. If so, we track 873 * [FIXME: maybe we'd need something more definitive]. If so, we track
874 * it's usb_busd and from there, the WUSB HC. 874 * it's usb_busd and from there, the WUSB HC.
875 * 875 *
diff --git a/drivers/usb/wusbcore/mmc.c b/drivers/usb/wusbcore/mmc.c
index 3b52161e6e9c..0a57ff0a0b0c 100644
--- a/drivers/usb/wusbcore/mmc.c
+++ b/drivers/usb/wusbcore/mmc.c
@@ -37,6 +37,7 @@
37 * - add timers that autoremove intervalled IEs? 37 * - add timers that autoremove intervalled IEs?
38 */ 38 */
39#include <linux/usb/wusb.h> 39#include <linux/usb/wusb.h>
40#include <linux/slab.h>
40#include "wusbhc.h" 41#include "wusbhc.h"
41 42
42/* Initialize the MMCIEs handling mechanism */ 43/* Initialize the MMCIEs handling mechanism */
@@ -263,7 +264,7 @@ int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
263{ 264{
264 int result = 0; 265 int result = 0;
265 266
266 if (memcmp(chid, &wusb_ckhdid_zero, sizeof(chid)) == 0) 267 if (memcmp(chid, &wusb_ckhdid_zero, sizeof(*chid)) == 0)
267 chid = NULL; 268 chid = NULL;
268 269
269 mutex_lock(&wusbhc->mutex); 270 mutex_lock(&wusbhc->mutex);
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index 9fe4246cecb9..a68ad7aa0b59 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -69,6 +69,7 @@
69 * 69 *
70 * wusbhc_rh_start_port_reset() ??? unimplemented 70 * wusbhc_rh_start_port_reset() ??? unimplemented
71 */ 71 */
72#include <linux/slab.h>
72#include "wusbhc.h" 73#include "wusbhc.h"
73 74
74/* 75/*
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c
index 4516c36436e6..b60799b811c1 100644
--- a/drivers/usb/wusbcore/security.c
+++ b/drivers/usb/wusbcore/security.c
@@ -23,6 +23,7 @@
23 * FIXME: docs 23 * FIXME: docs
24 */ 24 */
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/slab.h>
26#include <linux/usb/ch9.h> 27#include <linux/usb/ch9.h>
27#include <linux/random.h> 28#include <linux/random.h>
28#include "wusbhc.h" 29#include "wusbhc.h"
@@ -205,15 +206,15 @@ int wusb_dev_sec_add(struct wusbhc *wusbhc,
205 const void *itr, *top; 206 const void *itr, *top;
206 char buf[64]; 207 char buf[64];
207 208
208 secd = kmalloc(sizeof(struct usb_security_descriptor), GFP_KERNEL); 209 secd = kmalloc(sizeof(*secd), GFP_KERNEL);
209 if (secd == NULL) { 210 if (secd == NULL) {
210 result = -ENOMEM; 211 result = -ENOMEM;
211 goto out; 212 goto out;
212 } 213 }
213 214
214 result = usb_get_descriptor(usb_dev, USB_DT_SECURITY, 215 result = usb_get_descriptor(usb_dev, USB_DT_SECURITY,
215 0, secd, sizeof(struct usb_security_descriptor)); 216 0, secd, sizeof(*secd));
216 if (result < sizeof(secd)) { 217 if (result < sizeof(*secd)) {
217 dev_err(dev, "Can't read security descriptor or " 218 dev_err(dev, "Can't read security descriptor or "
218 "not enough data: %d\n", result); 219 "not enough data: %d\n", result);
219 goto out; 220 goto out;
diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index 9d04722415bb..59a748a0e5da 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -22,6 +22,7 @@
22 * 22 *
23 * FIXME: docs 23 * FIXME: docs
24 */ 24 */
25#include <linux/slab.h>
25#include "wusbhc.h" 26#include "wusbhc.h"
26#include "wa-hc.h" 27#include "wa-hc.h"
27 28
diff --git a/drivers/usb/wusbcore/wa-nep.c b/drivers/usb/wusbcore/wa-nep.c
index 17d2626038be..f67f7f1e6df9 100644
--- a/drivers/usb/wusbcore/wa-nep.c
+++ b/drivers/usb/wusbcore/wa-nep.c
@@ -51,6 +51,7 @@
51 */ 51 */
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/ctype.h> 53#include <linux/ctype.h>
54#include <linux/slab.h>
54 55
55#include "wa-hc.h" 56#include "wa-hc.h"
56#include "wusbhc.h" 57#include "wusbhc.h"
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index 7369655f69cd..c7b1d8108de9 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -60,6 +60,7 @@
60#include <linux/init.h> 60#include <linux/init.h>
61#include <asm/atomic.h> 61#include <asm/atomic.h>
62#include <linux/bitmap.h> 62#include <linux/bitmap.h>
63#include <linux/slab.h>
63 64
64#include "wusbhc.h" 65#include "wusbhc.h"
65#include "wa-hc.h" 66#include "wa-hc.h"
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 613a5fc490d3..112ef7e26f6b 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -81,6 +81,7 @@
81 */ 81 */
82#include <linux/init.h> 82#include <linux/init.h>
83#include <linux/spinlock.h> 83#include <linux/spinlock.h>
84#include <linux/slab.h>
84#include <linux/hash.h> 85#include <linux/hash.h>
85 86
86#include "wa-hc.h" 87#include "wa-hc.h"
@@ -558,7 +559,7 @@ static void wa_seg_dto_cb(struct urb *urb)
558/* 559/*
559 * Callback for the segment request 560 * Callback for the segment request
560 * 561 *
561 * If succesful transition state (unless already transitioned or 562 * If successful transition state (unless already transitioned or
562 * outbound transfer); otherwise, take a note of the error, mark this 563 * outbound transfer); otherwise, take a note of the error, mark this
563 * segment done and try completion. 564 * segment done and try completion.
564 * 565 *
@@ -1364,7 +1365,7 @@ segment_aborted:
1364/* 1365/*
1365 * Callback for the IN data phase 1366 * Callback for the IN data phase
1366 * 1367 *
1367 * If succesful transition state; otherwise, take a note of the 1368 * If successful transition state; otherwise, take a note of the
1368 * error, mark this segment done and try completion. 1369 * error, mark this segment done and try completion.
1369 * 1370 *
1370 * Note we don't access until we are sure that the transfer hasn't 1371 * Note we don't access until we are sure that the transfer hasn't
diff --git a/drivers/usb/wusbcore/wusbhc.c b/drivers/usb/wusbcore/wusbhc.c
index ee6256f23636..eab86e4bc770 100644
--- a/drivers/usb/wusbcore/wusbhc.c
+++ b/drivers/usb/wusbcore/wusbhc.c
@@ -147,10 +147,40 @@ static ssize_t wusb_chid_store(struct device *dev,
147} 147}
148static DEVICE_ATTR(wusb_chid, 0644, wusb_chid_show, wusb_chid_store); 148static DEVICE_ATTR(wusb_chid, 0644, wusb_chid_show, wusb_chid_store);
149 149
150
151static ssize_t wusb_phy_rate_show(struct device *dev,
152 struct device_attribute *attr,
153 char *buf)
154{
155 struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev);
156
157 return sprintf(buf, "%d\n", wusbhc->phy_rate);
158}
159
160static ssize_t wusb_phy_rate_store(struct device *dev,
161 struct device_attribute *attr,
162 const char *buf, size_t size)
163{
164 struct wusbhc *wusbhc = usbhc_dev_to_wusbhc(dev);
165 uint8_t phy_rate;
166 ssize_t result;
167
168 result = sscanf(buf, "%hhu", &phy_rate);
169 if (result != 1)
170 return -EINVAL;
171 if (phy_rate >= UWB_PHY_RATE_INVALID)
172 return -EINVAL;
173
174 wusbhc->phy_rate = phy_rate;
175 return size;
176}
177static DEVICE_ATTR(wusb_phy_rate, 0644, wusb_phy_rate_show, wusb_phy_rate_store);
178
150/* Group all the WUSBHC attributes */ 179/* Group all the WUSBHC attributes */
151static struct attribute *wusbhc_attrs[] = { 180static struct attribute *wusbhc_attrs[] = {
152 &dev_attr_wusb_trust_timeout.attr, 181 &dev_attr_wusb_trust_timeout.attr,
153 &dev_attr_wusb_chid.attr, 182 &dev_attr_wusb_chid.attr,
183 &dev_attr_wusb_phy_rate.attr,
154 NULL, 184 NULL,
155}; 185};
156 186
@@ -177,6 +207,8 @@ int wusbhc_create(struct wusbhc *wusbhc)
177 int result = 0; 207 int result = 0;
178 208
179 wusbhc->trust_timeout = WUSB_TRUST_TIMEOUT_MS; 209 wusbhc->trust_timeout = WUSB_TRUST_TIMEOUT_MS;
210 wusbhc->phy_rate = UWB_PHY_RATE_INVALID - 1;
211
180 mutex_init(&wusbhc->mutex); 212 mutex_init(&wusbhc->mutex);
181 result = wusbhc_mmcie_create(wusbhc); 213 result = wusbhc_mmcie_create(wusbhc);
182 if (result < 0) 214 if (result < 0)
diff --git a/drivers/usb/wusbcore/wusbhc.h b/drivers/usb/wusbcore/wusbhc.h
index 797c2453a35b..759cda55f7c3 100644
--- a/drivers/usb/wusbcore/wusbhc.h
+++ b/drivers/usb/wusbcore/wusbhc.h
@@ -198,7 +198,7 @@ struct wusb_port {
198 * ports) this HC will take. Read-only. 198 * ports) this HC will take. Read-only.
199 * 199 *
200 * @port Array of port status for each fake root port. Guaranteed to 200 * @port Array of port status for each fake root port. Guaranteed to
201 * always be the same lenght during device existence 201 * always be the same length during device existence
202 * [this allows for some unlocked but referenced reading]. 202 * [this allows for some unlocked but referenced reading].
203 * 203 *
204 * @mmcies_max Max number of Information Elements this HC can send 204 * @mmcies_max Max number of Information Elements this HC can send
@@ -253,6 +253,7 @@ struct wusbhc {
253 253
254 unsigned trust_timeout; /* in jiffies */ 254 unsigned trust_timeout; /* in jiffies */
255 struct wusb_ckhdid chid; 255 struct wusb_ckhdid chid;
256 uint8_t phy_rate;
256 struct wuie_host_info *wuie_host_info; 257 struct wuie_host_info *wuie_host_info;
257 258
258 struct mutex mutex; /* locks everything else */ 259 struct mutex mutex; /* locks everything else */