aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-bus-usb6
-rw-r--r--Documentation/devicetree/bindings/usb/ci13xxx-imx.txt2
-rw-r--r--Documentation/devicetree/bindings/usb/ehci-omap.txt32
-rw-r--r--Documentation/devicetree/bindings/usb/ohci-omap3.txt15
-rw-r--r--Documentation/devicetree/bindings/usb/omap-usb.txt40
-rw-r--r--Documentation/devicetree/bindings/usb/samsung-usbphy.txt76
-rw-r--r--Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt34
-rw-r--r--Documentation/ioctl/ioctl-number.txt1
-rw-r--r--Documentation/usb/power-management.txt10
-rw-r--r--arch/arm/Kconfig2
-rw-r--r--arch/arm/configs/imx_v6_v7_defconfig1
-rw-r--r--arch/arm/configs/lpc32xx_defconfig1
-rw-r--r--arch/arm/configs/mxs_defconfig1
-rw-r--r--arch/arm/configs/omap1_defconfig1
-rw-r--r--arch/arm/mach-exynos/setup-usb-phy.c8
-rw-r--r--arch/arm/mach-mmp/aspenite.c6
-rw-r--r--arch/arm/mach-mmp/ttc_dkb.c6
-rw-r--r--arch/arm/mach-s3c64xx/setup-usb-phy.c4
-rw-r--r--arch/arm/mach-s5pv210/setup-usb-phy.c4
-rw-r--r--arch/arm/mach-shmobile/board-armadillo800eva.c8
-rw-r--r--arch/arm/mach-shmobile/board-kzm9g.c8
-rw-r--r--arch/arm/mach-shmobile/board-mackerel.c12
-rw-r--r--arch/arm/mach-tegra/Kconfig8
-rw-r--r--arch/arm/plat-samsung/include/plat/usb-phy.h5
-rw-r--r--arch/mips/Kconfig3
-rw-r--r--arch/powerpc/platforms/44x/Kconfig2
-rw-r--r--arch/powerpc/platforms/512x/Kconfig2
-rw-r--r--arch/sh/boards/mach-ecovec24/setup.c4
-rw-r--r--arch/sparc/Kconfig2
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/hid/usbhid/hid-core.c14
-rw-r--r--drivers/net/usb/cdc_mbim.c5
-rw-r--r--drivers/net/usb/qmi_wwan.c5
-rw-r--r--drivers/net/usb/smsc75xx.c6
-rw-r--r--drivers/net/usb/smsc95xx.c6
-rw-r--r--drivers/power/Kconfig2
-rw-r--r--drivers/power/pda_power.c14
-rw-r--r--drivers/usb/Kconfig25
-rw-r--r--drivers/usb/Makefile4
-rw-r--r--drivers/usb/atm/Kconfig2
-rw-r--r--drivers/usb/atm/usbatm.c6
-rw-r--r--drivers/usb/chipidea/Makefile2
-rw-r--r--drivers/usb/chipidea/ci.h19
-rw-r--r--drivers/usb/chipidea/ci13xxx_imx.c12
-rw-r--r--drivers/usb/chipidea/ci13xxx_imx.h3
-rw-r--r--drivers/usb/chipidea/ci13xxx_pci.c6
-rw-r--r--drivers/usb/chipidea/core.c66
-rw-r--r--drivers/usb/chipidea/debug.c888
-rw-r--r--drivers/usb/chipidea/debug.h34
-rw-r--r--drivers/usb/chipidea/udc.c299
-rw-r--r--drivers/usb/chipidea/udc.h4
-rw-r--r--drivers/usb/chipidea/usbmisc_imx.c261
-rw-r--r--drivers/usb/chipidea/usbmisc_imx6q.c162
-rw-r--r--drivers/usb/class/Kconfig6
-rw-r--r--drivers/usb/class/cdc-acm.c8
-rw-r--r--drivers/usb/class/cdc-wdm.c19
-rw-r--r--drivers/usb/class/usbtmc.c26
-rw-r--r--drivers/usb/core/Kconfig36
-rw-r--r--drivers/usb/core/devio.c2
-rw-r--r--drivers/usb/core/driver.c25
-rw-r--r--drivers/usb/core/generic.c2
-rw-r--r--drivers/usb/core/hcd-pci.c214
-rw-r--r--drivers/usb/core/hcd.c10
-rw-r--r--drivers/usb/core/hub.c136
-rw-r--r--drivers/usb/core/port.c4
-rw-r--r--drivers/usb/core/quirks.c16
-rw-r--r--drivers/usb/core/sysfs.c4
-rw-r--r--drivers/usb/core/urb.c5
-rw-r--r--drivers/usb/core/usb.c4
-rw-r--r--drivers/usb/core/usb.h2
-rw-r--r--drivers/usb/dwc3/Kconfig1
-rw-r--r--drivers/usb/dwc3/core.c201
-rw-r--r--drivers/usb/dwc3/core.h72
-rw-r--r--drivers/usb/dwc3/debugfs.c52
-rw-r--r--drivers/usb/dwc3/dwc3-exynos.c98
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c245
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c38
-rw-r--r--drivers/usb/dwc3/ep0.c33
-rw-r--r--drivers/usb/dwc3/gadget.c321
-rw-r--r--drivers/usb/gadget/Kconfig20
-rw-r--r--drivers/usb/gadget/Makefile13
-rw-r--r--drivers/usb/gadget/acm_ms.c15
-rw-r--r--drivers/usb/gadget/amd5536udc.c16
-rw-r--r--drivers/usb/gadget/amd5536udc.h1
-rw-r--r--drivers/usb/gadget/at91_udc.c14
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c44
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.h6
-rw-r--r--drivers/usb/gadget/bcm63xx_udc.c23
-rw-r--r--drivers/usb/gadget/cdc2.c31
-rw-r--r--drivers/usb/gadget/composite.c1
-rw-r--r--drivers/usb/gadget/configfs.c1003
-rw-r--r--drivers/usb/gadget/dummy_hcd.c19
-rw-r--r--drivers/usb/gadget/ether.c20
-rw-r--r--drivers/usb/gadget/f_acm.c137
-rw-r--r--drivers/usb/gadget/f_ecm.c4
-rw-r--r--drivers/usb/gadget/f_eem.c3
-rw-r--r--drivers/usb/gadget/f_ncm.c4
-rw-r--r--drivers/usb/gadget/f_obex.c227
-rw-r--r--drivers/usb/gadget/f_rndis.c3
-rw-r--r--drivers/usb/gadget/f_serial.c174
-rw-r--r--drivers/usb/gadget/f_sourcesink.c4
-rw-r--r--drivers/usb/gadget/f_subset.c4
-rw-r--r--drivers/usb/gadget/f_uvc.c262
-rw-r--r--drivers/usb/gadget/f_uvc.h12
-rw-r--r--drivers/usb/gadget/fsl_qe_udc.c18
-rw-r--r--drivers/usb/gadget/fsl_udc_core.c83
-rw-r--r--drivers/usb/gadget/fusb300_udc.c46
-rw-r--r--drivers/usb/gadget/fusb300_udc.h2
-rw-r--r--drivers/usb/gadget/g_ffs.c35
-rw-r--r--drivers/usb/gadget/goku_udc.c20
-rw-r--r--drivers/usb/gadget/goku_udc.h3
-rw-r--r--drivers/usb/gadget/imx_udc.c16
-rw-r--r--drivers/usb/gadget/lpc32xx_udc.c51
-rw-r--r--drivers/usb/gadget/m66592-udc.c17
-rw-r--r--drivers/usb/gadget/multi.c33
-rw-r--r--drivers/usb/gadget/mv_u3d_core.c65
-rw-r--r--drivers/usb/gadget/mv_udc.h3
-rw-r--r--drivers/usb/gadget/mv_udc_core.c117
-rw-r--r--drivers/usb/gadget/ncm.c13
-rw-r--r--drivers/usb/gadget/net2272.c25
-rw-r--r--drivers/usb/gadget/net2280.c25
-rw-r--r--drivers/usb/gadget/nokia.c95
-rw-r--r--drivers/usb/gadget/omap_udc.c21
-rw-r--r--drivers/usb/gadget/pch_udc.c21
-rw-r--r--drivers/usb/gadget/pxa25x_udc.c16
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c51
-rw-r--r--drivers/usb/gadget/r8a66597-udc.c14
-rw-r--r--drivers/usb/gadget/s3c-hsotg.c78
-rw-r--r--drivers/usb/gadget/s3c-hsudc.c16
-rw-r--r--drivers/usb/gadget/s3c2410_udc.c15
-rw-r--r--drivers/usb/gadget/serial.c59
-rw-r--r--drivers/usb/gadget/u_ether.c32
-rw-r--r--drivers/usb/gadget/u_ether.h27
-rw-r--r--drivers/usb/gadget/u_serial.h1
-rw-r--r--drivers/usb/gadget/udc-core.c90
-rw-r--r--drivers/usb/gadget/uvc.h3
-rw-r--r--drivers/usb/gadget/uvc_queue.c538
-rw-r--r--drivers/usb/gadget/uvc_queue.h32
-rw-r--r--drivers/usb/gadget/uvc_v4l2.c71
-rw-r--r--drivers/usb/gadget/uvc_video.c31
-rw-r--r--drivers/usb/gadget/zero.c2
-rw-r--r--drivers/usb/host/Kconfig217
-rw-r--r--drivers/usb/host/Makefile6
-rw-r--r--drivers/usb/host/ehci-atmel.c88
-rw-r--r--drivers/usb/host/ehci-dbg.c15
-rw-r--r--drivers/usb/host/ehci-fsl.c9
-rw-r--r--drivers/usb/host/ehci-hcd.c107
-rw-r--r--drivers/usb/host/ehci-hub.c23
-rw-r--r--drivers/usb/host/ehci-msm.c91
-rw-r--r--drivers/usb/host/ehci-mv.c56
-rw-r--r--drivers/usb/host/ehci-mxc.c10
-rw-r--r--drivers/usb/host/ehci-omap.c331
-rw-r--r--drivers/usb/host/ehci-orion.c86
-rw-r--r--drivers/usb/host/ehci-pci.c14
-rw-r--r--drivers/usb/host/ehci-platform.c36
-rw-r--r--drivers/usb/host/ehci-ps3.c1
-rw-r--r--drivers/usb/host/ehci-q.c241
-rw-r--r--drivers/usb/host/ehci-s5p.c180
-rw-r--r--drivers/usb/host/ehci-sched.c40
-rw-r--r--drivers/usb/host/ehci-sh.c5
-rw-r--r--drivers/usb/host/ehci-spear.c119
-rw-r--r--drivers/usb/host/ehci-tegra.c34
-rw-r--r--drivers/usb/host/ehci-timer.c72
-rw-r--r--drivers/usb/host/ehci-vt8500.c150
-rw-r--r--drivers/usb/host/ehci.h16
-rw-r--r--drivers/usb/host/ohci-exynos.c14
-rw-r--r--drivers/usb/host/ohci-hcd.c136
-rw-r--r--drivers/usb/host/ohci-hub.c6
-rw-r--r--drivers/usb/host/ohci-omap3.c24
-rw-r--r--drivers/usb/host/sl811-hcd.c2
-rw-r--r--drivers/usb/host/u132-hcd.c9
-rw-r--r--drivers/usb/host/xhci-hub.c2
-rw-r--r--drivers/usb/host/xhci-mem.c16
-rw-r--r--drivers/usb/host/xhci.c18
-rw-r--r--drivers/usb/host/xhci.h4
-rw-r--r--drivers/usb/image/Kconfig4
-rw-r--r--drivers/usb/misc/Kconfig21
-rw-r--r--drivers/usb/misc/appledisplay.c1
-rw-r--r--drivers/usb/misc/sisusbvga/Kconfig2
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c2
-rw-r--r--drivers/usb/misc/usb3503.c13
-rw-r--r--drivers/usb/mon/Kconfig1
-rw-r--r--drivers/usb/musb/Kconfig8
-rw-r--r--drivers/usb/musb/am35x.c8
-rw-r--r--drivers/usb/musb/blackfin.c6
-rw-r--r--drivers/usb/musb/cppi_dma.c17
-rw-r--r--drivers/usb/musb/da8xx.c8
-rw-r--r--drivers/usb/musb/davinci.c4
-rw-r--r--drivers/usb/musb/musb_core.c71
-rw-r--r--drivers/usb/musb/musb_dsps.c14
-rw-r--r--drivers/usb/musb/musb_gadget.c156
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c6
-rw-r--r--drivers/usb/musb/musb_host.c119
-rw-r--r--drivers/usb/musb/musb_virthub.c4
-rw-r--r--drivers/usb/musb/omap2430.c32
-rw-r--r--drivers/usb/musb/tusb6010.c14
-rw-r--r--drivers/usb/musb/ux500.c106
-rw-r--r--drivers/usb/musb/ux500_dma.c24
-rw-r--r--drivers/usb/otg/Kconfig141
-rw-r--r--drivers/usb/otg/Makefile24
-rw-r--r--drivers/usb/otg/ab8500-usb.c596
-rw-r--r--drivers/usb/phy/Kconfig180
-rw-r--r--drivers/usb/phy/Makefile35
-rw-r--r--drivers/usb/phy/isp1301.c71
-rw-r--r--drivers/usb/phy/phy-ab8500-usb.c924
-rw-r--r--drivers/usb/phy/phy-fsl-usb.c (renamed from drivers/usb/otg/fsl_otg.c)34
-rw-r--r--drivers/usb/phy/phy-fsl-usb.h (renamed from drivers/usb/otg/fsl_otg.h)0
-rw-r--r--drivers/usb/phy/phy-fsm-usb.c (renamed from drivers/usb/otg/otg_fsm.c)4
-rw-r--r--drivers/usb/phy/phy-fsm-usb.h (renamed from drivers/usb/otg/otg_fsm.h)0
-rw-r--r--drivers/usb/phy/phy-gpio-vbus-usb.c (renamed from drivers/usb/otg/gpio_vbus.c)9
-rw-r--r--drivers/usb/phy/phy-isp1301-omap.c (renamed from drivers/usb/otg/isp1301_omap.c)10
-rw-r--r--drivers/usb/phy/phy-isp1301.c162
-rw-r--r--drivers/usb/phy/phy-msm-usb.c (renamed from drivers/usb/otg/msm_otg.c)0
-rw-r--r--drivers/usb/phy/phy-mv-u3d-usb.c (renamed from drivers/usb/phy/mv_u3d_phy.c)4
-rw-r--r--drivers/usb/phy/phy-mv-u3d-usb.h (renamed from drivers/usb/phy/mv_u3d_phy.h)0
-rw-r--r--drivers/usb/phy/phy-mv-usb.c (renamed from drivers/usb/otg/mv_otg.c)30
-rw-r--r--drivers/usb/phy/phy-mv-usb.h (renamed from drivers/usb/otg/mv_otg.h)3
-rw-r--r--drivers/usb/phy/phy-mxs-usb.c (renamed from drivers/usb/otg/mxs-phy.c)41
-rw-r--r--drivers/usb/phy/phy-nop.c (renamed from drivers/usb/otg/nop-usb-xceiv.c)143
-rw-r--r--drivers/usb/phy/phy-omap-control.c (renamed from drivers/usb/phy/omap-control-usb.c)0
-rw-r--r--drivers/usb/phy/phy-omap-usb2.c (renamed from drivers/usb/phy/omap-usb2.c)0
-rw-r--r--drivers/usb/phy/phy-omap-usb3.c (renamed from drivers/usb/phy/omap-usb3.c)0
-rw-r--r--drivers/usb/phy/phy-rcar-usb.c (renamed from drivers/usb/phy/rcar-phy.c)0
-rw-r--r--drivers/usb/phy/phy-samsung-usb.c236
-rw-r--r--drivers/usb/phy/phy-samsung-usb.h327
-rw-r--r--drivers/usb/phy/phy-samsung-usb2.c509
-rw-r--r--drivers/usb/phy/phy-samsung-usb3.c347
-rw-r--r--drivers/usb/phy/phy-tegra-usb.c (renamed from drivers/usb/phy/tegra_usb_phy.c)13
-rw-r--r--drivers/usb/phy/phy-twl4030-usb.c (renamed from drivers/usb/otg/twl4030-usb.c)178
-rw-r--r--drivers/usb/phy/phy-twl6030-usb.c (renamed from drivers/usb/otg/twl6030-usb.c)15
-rw-r--r--drivers/usb/phy/phy-ulpi-viewport.c (renamed from drivers/usb/otg/ulpi_viewport.c)0
-rw-r--r--drivers/usb/phy/phy-ulpi.c (renamed from drivers/usb/otg/ulpi.c)0
-rw-r--r--drivers/usb/phy/phy.c (renamed from drivers/usb/otg/otg.c)64
-rw-r--r--drivers/usb/phy/samsung-usbphy.c928
-rw-r--r--drivers/usb/renesas_usbhs/Kconfig2
-rw-r--r--drivers/usb/renesas_usbhs/fifo.c1
-rw-r--r--drivers/usb/renesas_usbhs/fifo.h2
-rw-r--r--drivers/usb/renesas_usbhs/mod_gadget.c24
-rw-r--r--drivers/usb/serial/Kconfig19
-rw-r--r--drivers/usb/serial/Makefile1
-rw-r--r--drivers/usb/serial/ark3116.c87
-rw-r--r--drivers/usb/serial/bus.c5
-rw-r--r--drivers/usb/serial/ch341.c30
-rw-r--r--drivers/usb/serial/cp210x.c6
-rw-r--r--drivers/usb/serial/cyberjack.c19
-rw-r--r--drivers/usb/serial/cypress_m8.c94
-rw-r--r--drivers/usb/serial/digi_acceleport.c95
-rw-r--r--drivers/usb/serial/f81232.c13
-rw-r--r--drivers/usb/serial/ftdi_sio.c144
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h4
-rw-r--r--drivers/usb/serial/garmin_gps.c10
-rw-r--r--drivers/usb/serial/generic.c144
-rw-r--r--drivers/usb/serial/io_edgeport.c76
-rw-r--r--drivers/usb/serial/io_tables.h12
-rw-r--r--drivers/usb/serial/io_ti.c98
-rw-r--r--drivers/usb/serial/iuu_phoenix.c21
-rw-r--r--drivers/usb/serial/keyspan.c96
-rw-r--r--drivers/usb/serial/keyspan_pda.c19
-rw-r--r--drivers/usb/serial/kl5kusb105.c30
-rw-r--r--drivers/usb/serial/kobil_sct.c103
-rw-r--r--drivers/usb/serial/mct_u232.c131
-rw-r--r--drivers/usb/serial/metro-usb.c5
-rw-r--r--drivers/usb/serial/mos7720.c68
-rw-r--r--drivers/usb/serial/mos7840.c157
-rw-r--r--drivers/usb/serial/omninet.c81
-rw-r--r--drivers/usb/serial/opticon.c18
-rw-r--r--drivers/usb/serial/option.c8
-rw-r--r--drivers/usb/serial/oti6858.c30
-rw-r--r--drivers/usb/serial/pl2303.c39
-rw-r--r--drivers/usb/serial/quatech2.c97
-rw-r--r--drivers/usb/serial/sierra.c39
-rw-r--r--drivers/usb/serial/spcp8x5.c301
-rw-r--r--drivers/usb/serial/ssu100.c100
-rw-r--r--drivers/usb/serial/symbolserial.c130
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c163
-rw-r--r--drivers/usb/serial/usb-serial.c230
-rw-r--r--drivers/usb/serial/usb_wwan.c25
-rw-r--r--drivers/usb/serial/visor.c16
-rw-r--r--drivers/usb/serial/wishbone-serial.c95
-rw-r--r--drivers/usb/storage/Kconfig7
-rw-r--r--drivers/usb/storage/alauda.c101
-rw-r--r--drivers/usb/storage/cypress_atacb.c18
-rw-r--r--drivers/usb/storage/datafab.c59
-rw-r--r--drivers/usb/storage/debug.c36
-rw-r--r--drivers/usb/storage/debug.h23
-rw-r--r--drivers/usb/storage/ene_ub6250.c86
-rw-r--r--drivers/usb/storage/freecom.c85
-rw-r--r--drivers/usb/storage/initializers.c10
-rw-r--r--drivers/usb/storage/isd200.c295
-rw-r--r--drivers/usb/storage/jumpshot.c69
-rw-r--r--drivers/usb/storage/karma.c6
-rw-r--r--drivers/usb/storage/onetouch.c4
-rw-r--r--drivers/usb/storage/option_ms.c23
-rw-r--r--drivers/usb/storage/realtek_cr.c128
-rw-r--r--drivers/usb/storage/scsiglue.c13
-rw-r--r--drivers/usb/storage/sddr09.c146
-rw-r--r--drivers/usb/storage/sddr55.c86
-rw-r--r--drivers/usb/storage/shuttle_usbat.c119
-rw-r--r--drivers/usb/storage/sierra_ms.c43
-rw-r--r--drivers/usb/storage/transport.c181
-rw-r--r--drivers/usb/storage/usb.c117
-rw-r--r--drivers/usb/usb-common.c47
-rw-r--r--drivers/usb/usb-skeleton.c32
-rw-r--r--drivers/usb/wusbcore/Kconfig2
-rw-r--r--include/linux/platform_data/dwc3-omap.h4
-rw-r--r--include/linux/platform_data/mv_usb.h2
-rw-r--r--include/linux/usb.h13
-rw-r--r--include/linux/usb/cdc-wdm.h2
-rw-r--r--include/linux/usb/ch9.h9
-rw-r--r--include/linux/usb/composite.h3
-rw-r--r--include/linux/usb/dwc3-omap.h6
-rw-r--r--include/linux/usb/gadget.h11
-rw-r--r--include/linux/usb/gadget_configfs.h110
-rw-r--r--include/linux/usb/hcd.h6
-rw-r--r--include/linux/usb/musb-ux500.h31
-rw-r--r--include/linux/usb/nop-usb-xceiv.h5
-rw-r--r--include/linux/usb/otg.h9
-rw-r--r--include/linux/usb/phy.h33
-rw-r--r--include/linux/usb/renesas_usbhs.h6
-rw-r--r--include/linux/usb/serial.h12
-rw-r--r--include/linux/usb/tegra_usb_phy.h10
-rw-r--r--include/uapi/linux/usb/cdc-wdm.h21
-rw-r--r--include/uapi/linux/usb/ch9.h4
323 files changed, 10495 insertions, 9849 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index c8baaf53594a..f093e59cbe5f 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -32,7 +32,7 @@ Date: January 2008
32KernelVersion: 2.6.25 32KernelVersion: 2.6.25
33Contact: Sarah Sharp <sarah.a.sharp@intel.com> 33Contact: Sarah Sharp <sarah.a.sharp@intel.com>
34Description: 34Description:
35 If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file 35 If CONFIG_PM_RUNTIME is enabled then this file
36 is present. When read, it returns the total time (in msec) 36 is present. When read, it returns the total time (in msec)
37 that the USB device has been connected to the machine. This 37 that the USB device has been connected to the machine. This
38 file is read-only. 38 file is read-only.
@@ -45,7 +45,7 @@ Date: January 2008
45KernelVersion: 2.6.25 45KernelVersion: 2.6.25
46Contact: Sarah Sharp <sarah.a.sharp@intel.com> 46Contact: Sarah Sharp <sarah.a.sharp@intel.com>
47Description: 47Description:
48 If CONFIG_PM and CONFIG_USB_SUSPEND are enabled, then this file 48 If CONFIG_PM_RUNTIME is enabled then this file
49 is present. When read, it returns the total time (in msec) 49 is present. When read, it returns the total time (in msec)
50 that the USB device has been active, i.e. not in a suspended 50 that the USB device has been active, i.e. not in a suspended
51 state. This file is read-only. 51 state. This file is read-only.
@@ -187,7 +187,7 @@ What: /sys/bus/usb/devices/.../power/usb2_hardware_lpm
187Date: September 2011 187Date: September 2011
188Contact: Andiry Xu <andiry.xu@amd.com> 188Contact: Andiry Xu <andiry.xu@amd.com>
189Description: 189Description:
190 If CONFIG_USB_SUSPEND is set and a USB 2.0 lpm-capable device 190 If CONFIG_PM_RUNTIME is set and a USB 2.0 lpm-capable device
191 is plugged in to a xHCI host which support link PM, it will 191 is plugged in to a xHCI host which support link PM, it will
192 perform a LPM test; if the test is passed and host supports 192 perform a LPM test; if the test is passed and host supports
193 USB2 hardware LPM (xHCI 1.0 feature), USB2 hardware LPM will 193 USB2 hardware LPM (xHCI 1.0 feature), USB2 hardware LPM will
diff --git a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
index 5778b9c83bd8..1c04a4c9515f 100644
--- a/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
+++ b/Documentation/devicetree/bindings/usb/ci13xxx-imx.txt
@@ -11,6 +11,7 @@ Optional properties:
11 that indicate usb controller index 11 that indicate usb controller index
12- vbus-supply: regulator for vbus 12- vbus-supply: regulator for vbus
13- disable-over-current: disable over current detect 13- disable-over-current: disable over current detect
14- external-vbus-divider: enables off-chip resistor divider for Vbus
14 15
15Examples: 16Examples:
16usb@02184000 { /* USB OTG */ 17usb@02184000 { /* USB OTG */
@@ -20,4 +21,5 @@ usb@02184000 { /* USB OTG */
20 fsl,usbphy = <&usbphy1>; 21 fsl,usbphy = <&usbphy1>;
21 fsl,usbmisc = <&usbmisc 0>; 22 fsl,usbmisc = <&usbmisc 0>;
22 disable-over-current; 23 disable-over-current;
24 external-vbus-divider;
23}; 25};
diff --git a/Documentation/devicetree/bindings/usb/ehci-omap.txt b/Documentation/devicetree/bindings/usb/ehci-omap.txt
new file mode 100644
index 000000000000..485a9a1efa7a
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ehci-omap.txt
@@ -0,0 +1,32 @@
1OMAP HS USB EHCI controller
2
3This device is usually the child of the omap-usb-host
4Documentation/devicetree/bindings/mfd/omap-usb-host.txt
5
6Required properties:
7
8- compatible: should be "ti,ehci-omap"
9- reg: should contain one register range i.e. start and length
10- interrupts: description of the interrupt line
11
12Optional properties:
13
14- phys: list of phandles to PHY nodes.
15 This property is required if at least one of the ports are in
16 PHY mode i.e. OMAP_EHCI_PORT_MODE_PHY
17
18To specify the port mode, see
19Documentation/devicetree/bindings/mfd/omap-usb-host.txt
20
21Example for OMAP4:
22
23usbhsehci: ehci@4a064c00 {
24 compatible = "ti,ehci-omap", "usb-ehci";
25 reg = <0x4a064c00 0x400>;
26 interrupts = <0 77 0x4>;
27};
28
29&usbhsehci {
30 phys = <&hsusb1_phy 0 &hsusb3_phy>;
31};
32
diff --git a/Documentation/devicetree/bindings/usb/ohci-omap3.txt b/Documentation/devicetree/bindings/usb/ohci-omap3.txt
new file mode 100644
index 000000000000..14ab42812a8e
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ohci-omap3.txt
@@ -0,0 +1,15 @@
1OMAP HS USB OHCI controller (OMAP3 and later)
2
3Required properties:
4
5- compatible: should be "ti,ohci-omap3"
6- reg: should contain one register range i.e. start and length
7- interrupts: description of the interrupt line
8
9Example for OMAP4:
10
11usbhsohci: ohci@4a064800 {
12 compatible = "ti,ohci-omap3", "usb-ohci";
13 reg = <0x4a064800 0x400>;
14 interrupts = <0 76 0x4>;
15};
diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 1ef0ce71f8fa..662f0f1d2315 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -8,10 +8,10 @@ OMAP MUSB GLUE
8 and disconnect. 8 and disconnect.
9 - multipoint : Should be "1" indicating the musb controller supports 9 - multipoint : Should be "1" indicating the musb controller supports
10 multipoint. This is a MUSB configuration-specific setting. 10 multipoint. This is a MUSB configuration-specific setting.
11 - num_eps : Specifies the number of endpoints. This is also a 11 - num-eps : Specifies the number of endpoints. This is also a
12 MUSB configuration-specific setting. Should be set to "16" 12 MUSB configuration-specific setting. Should be set to "16"
13 - ram_bits : Specifies the ram address size. Should be set to "12" 13 - ram-bits : Specifies the ram address size. Should be set to "12"
14 - interface_type : This is a board specific setting to describe the type of 14 - interface-type : This is a board specific setting to describe the type of
15 interface between the controller and the phy. It should be "0" or "1" 15 interface between the controller and the phy. It should be "0" or "1"
16 specifying ULPI and UTMI respectively. 16 specifying ULPI and UTMI respectively.
17 - mode : Should be "3" to represent OTG. "1" signifies HOST and "2" 17 - mode : Should be "3" to represent OTG. "1" signifies HOST and "2"
@@ -29,18 +29,46 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
29 ti,hwmods = "usb_otg_hs"; 29 ti,hwmods = "usb_otg_hs";
30 ti,has-mailbox; 30 ti,has-mailbox;
31 multipoint = <1>; 31 multipoint = <1>;
32 num_eps = <16>; 32 num-eps = <16>;
33 ram_bits = <12>; 33 ram-bits = <12>;
34 ctrl-module = <&omap_control_usb>; 34 ctrl-module = <&omap_control_usb>;
35}; 35};
36 36
37Board specific device node entry 37Board specific device node entry
38&usb_otg_hs { 38&usb_otg_hs {
39 interface_type = <1>; 39 interface-type = <1>;
40 mode = <3>; 40 mode = <3>;
41 power = <50>; 41 power = <50>;
42}; 42};
43 43
44OMAP DWC3 GLUE
45 - compatible : Should be "ti,dwc3"
46 - ti,hwmods : Should be "usb_otg_ss"
47 - reg : Address and length of the register set for the device.
48 - interrupts : The irq number of this device that is used to interrupt the
49 MPU
50 - #address-cells, #size-cells : Must be present if the device has sub-nodes
51 - utmi-mode : controls the source of UTMI/PIPE status for VBUS and OTG ID.
52 It should be set to "1" for HW mode and "2" for SW mode.
53 - ranges: the child address space are mapped 1:1 onto the parent address space
54
55Sub-nodes:
56The dwc3 core should be added as subnode to omap dwc3 glue.
57- dwc3 :
58 The binding details of dwc3 can be found in:
59 Documentation/devicetree/bindings/usb/dwc3.txt
60
61omap_dwc3 {
62 compatible = "ti,dwc3";
63 ti,hwmods = "usb_otg_ss";
64 reg = <0x4a020000 0x1ff>;
65 interrupts = <0 93 4>;
66 #address-cells = <1>;
67 #size-cells = <1>;
68 utmi-mode = <2>;
69 ranges;
70};
71
44OMAP CONTROL USB 72OMAP CONTROL USB
45 73
46Required properties: 74Required properties:
diff --git a/Documentation/devicetree/bindings/usb/samsung-usbphy.txt b/Documentation/devicetree/bindings/usb/samsung-usbphy.txt
index 033194934f64..f575302e5173 100644
--- a/Documentation/devicetree/bindings/usb/samsung-usbphy.txt
+++ b/Documentation/devicetree/bindings/usb/samsung-usbphy.txt
@@ -1,20 +1,25 @@
1* Samsung's usb phy transceiver 1SAMSUNG USB-PHY controllers
2 2
3The Samsung's phy transceiver is used for controlling usb phy for 3** Samsung's usb 2.0 phy transceiver
4s3c-hsotg as well as ehci-s5p and ohci-exynos usb controllers 4
5across Samsung SOCs. 5The Samsung's usb 2.0 phy transceiver is used for controlling
6usb 2.0 phy for s3c-hsotg as well as ehci-s5p and ohci-exynos
7usb controllers across Samsung SOCs.
6TODO: Adding the PHY binding with controller(s) according to the under 8TODO: Adding the PHY binding with controller(s) according to the under
7developement generic PHY driver. 9developement generic PHY driver.
8 10
9Required properties: 11Required properties:
10 12
11Exynos4210: 13Exynos4210:
12- compatible : should be "samsung,exynos4210-usbphy" 14- compatible : should be "samsung,exynos4210-usb2phy"
13- reg : base physical address of the phy registers and length of memory mapped 15- reg : base physical address of the phy registers and length of memory mapped
14 region. 16 region.
17- clocks: Clock IDs array as required by the controller.
18- clock-names: names of clock correseponding IDs clock property as requested
19 by the controller driver.
15 20
16Exynos5250: 21Exynos5250:
17- compatible : should be "samsung,exynos5250-usbphy" 22- compatible : should be "samsung,exynos5250-usb2phy"
18- reg : base physical address of the phy registers and length of memory mapped 23- reg : base physical address of the phy registers and length of memory mapped
19 region. 24 region.
20 25
@@ -44,12 +49,69 @@ Example:
44 usbphy@125B0000 { 49 usbphy@125B0000 {
45 #address-cells = <1>; 50 #address-cells = <1>;
46 #size-cells = <1>; 51 #size-cells = <1>;
47 compatible = "samsung,exynos4210-usbphy"; 52 compatible = "samsung,exynos4210-usb2phy";
48 reg = <0x125B0000 0x100>; 53 reg = <0x125B0000 0x100>;
49 ranges; 54 ranges;
50 55
56 clocks = <&clock 2>, <&clock 305>;
57 clock-names = "xusbxti", "otg";
58
51 usbphy-sys { 59 usbphy-sys {
52 /* USB device and host PHY_CONTROL registers */ 60 /* USB device and host PHY_CONTROL registers */
53 reg = <0x10020704 0x8>; 61 reg = <0x10020704 0x8>;
54 }; 62 };
55 }; 63 };
64
65
66** Samsung's usb 3.0 phy transceiver
67
68Starting exynso5250, Samsung's SoC have usb 3.0 phy transceiver
69which is used for controlling usb 3.0 phy for dwc3-exynos usb 3.0
70controllers across Samsung SOCs.
71
72Required properties:
73
74Exynos5250:
75- compatible : should be "samsung,exynos5250-usb3phy"
76- reg : base physical address of the phy registers and length of memory mapped
77 region.
78- clocks: Clock IDs array as required by the controller.
79- clock-names: names of clocks correseponding to IDs in the clock property
80 as requested by the controller driver.
81
82Optional properties:
83- #address-cells: should be '1' when usbphy node has a child node with 'reg'
84 property.
85- #size-cells: should be '1' when usbphy node has a child node with 'reg'
86 property.
87- ranges: allows valid translation between child's address space and parent's
88 address space.
89
90- The child node 'usbphy-sys' to the node 'usbphy' is for the system controller
91 interface for usb-phy. It should provide the following information required by
92 usb-phy controller to control phy.
93 - reg : base physical address of PHY_CONTROL registers.
94 The size of this register is the total sum of size of all PHY_CONTROL
95 registers that the SoC has. For example, the size will be
96 '0x4' in case we have only one PHY_CONTROL register (e.g.
97 OTHERS register in S3C64XX or USB_PHY_CONTROL register in S5PV210)
98 and, '0x8' in case we have two PHY_CONTROL registers (e.g.
99 USBDEVICE_PHY_CONTROL and USBHOST_PHY_CONTROL registers in exynos4x).
100 and so on.
101
102Example:
103 usbphy@12100000 {
104 compatible = "samsung,exynos5250-usb3phy";
105 reg = <0x12100000 0x100>;
106 #address-cells = <1>;
107 #size-cells = <1>;
108 ranges;
109
110 clocks = <&clock 1>, <&clock 286>;
111 clock-names = "ext_xtal", "usbdrd30";
112
113 usbphy-sys {
114 /* USB device and host PHY_CONTROL registers */
115 reg = <0x10040704 0x8>;
116 };
117 };
diff --git a/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
new file mode 100644
index 000000000000..d7e272671c7e
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/usb-nop-xceiv.txt
@@ -0,0 +1,34 @@
1USB NOP PHY
2
3Required properties:
4- compatible: should be usb-nop-xceiv
5
6Optional properties:
7- clocks: phandle to the PHY clock. Use as per Documentation/devicetree
8 /bindings/clock/clock-bindings.txt
9 This property is required if clock-frequency is specified.
10
11- clock-names: Should be "main_clk"
12
13- clock-frequency: the clock frequency (in Hz) that the PHY clock must
14 be configured to.
15
16- vcc-supply: phandle to the regulator that provides RESET to the PHY.
17
18- reset-supply: phandle to the regulator that provides power to the PHY.
19
20Example:
21
22 hsusb1_phy {
23 compatible = "usb-nop-xceiv";
24 clock-frequency = <19200000>;
25 clocks = <&osc 0>;
26 clock-names = "main_clk";
27 vcc-supply = <&hsusb1_vcc_regulator>;
28 reset-supply = <&hsusb1_reset_regulator>;
29 };
30
31hsusb1_phy is a NOP USB PHY device that gets its clock from an oscillator
32and expects that clock to be configured to 19.2MHz by the NOP PHY driver.
33hsusb1_vcc_regulator provides power to the PHY and hsusb1_reset_regulator
34controls RESET.
diff --git a/Documentation/ioctl/ioctl-number.txt b/Documentation/ioctl/ioctl-number.txt
index 3210540f8bd3..237acab169dd 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -131,6 +131,7 @@ Code Seq#(hex) Include File Comments
131'H' 40-4F sound/hdspm.h conflict! 131'H' 40-4F sound/hdspm.h conflict!
132'H' 40-4F sound/hdsp.h conflict! 132'H' 40-4F sound/hdsp.h conflict!
133'H' 90 sound/usb/usx2y/usb_stream.h 133'H' 90 sound/usb/usx2y/usb_stream.h
134'H' A0 uapi/linux/usb/cdc-wdm.h
134'H' C0-F0 net/bluetooth/hci.h conflict! 135'H' C0-F0 net/bluetooth/hci.h conflict!
135'H' C0-DF net/bluetooth/hidp/hidp.h conflict! 136'H' C0-DF net/bluetooth/hidp/hidp.h conflict!
136'H' C0-DF net/bluetooth/cmtp/cmtp.h conflict! 137'H' C0-DF net/bluetooth/cmtp/cmtp.h conflict!
diff --git a/Documentation/usb/power-management.txt b/Documentation/usb/power-management.txt
index 4204eb01fd38..1392b61d6ebe 100644
--- a/Documentation/usb/power-management.txt
+++ b/Documentation/usb/power-management.txt
@@ -33,6 +33,10 @@ built with CONFIG_USB_SUSPEND enabled (which depends on
33CONFIG_PM_RUNTIME). System PM support is present only if the kernel 33CONFIG_PM_RUNTIME). System PM support is present only if the kernel
34was built with CONFIG_SUSPEND or CONFIG_HIBERNATION enabled. 34was built with CONFIG_SUSPEND or CONFIG_HIBERNATION enabled.
35 35
36(Starting with the 3.10 kernel release, dynamic PM support for USB is
37present whenever the kernel was built with CONFIG_PM_RUNTIME enabled.
38The CONFIG_USB_SUSPEND option has been eliminated.)
39
36 40
37 What is Remote Wakeup? 41 What is Remote Wakeup?
38 ---------------------- 42 ----------------------
@@ -206,10 +210,8 @@ initialized to 5. (The idle-delay values for already existing devices
206will not be affected.) 210will not be affected.)
207 211
208Setting the initial default idle-delay to -1 will prevent any 212Setting the initial default idle-delay to -1 will prevent any
209autosuspend of any USB device. This is a simple alternative to 213autosuspend of any USB device. This has the benefit of allowing you
210disabling CONFIG_USB_SUSPEND and rebuilding the kernel, and it has the 214then to enable autosuspend for selected devices.
211added benefit of allowing you to enable autosuspend for selected
212devices.
213 215
214 216
215 Warnings 217 Warnings
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 1cacda426a0e..bbddefea77bb 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -549,6 +549,8 @@ config ARCH_IXP4XX
549 select GENERIC_CLOCKEVENTS 549 select GENERIC_CLOCKEVENTS
550 select MIGHT_HAVE_PCI 550 select MIGHT_HAVE_PCI
551 select NEED_MACH_IO_H 551 select NEED_MACH_IO_H
552 select USB_EHCI_BIG_ENDIAN_MMIO
553 select USB_EHCI_BIG_ENDIAN_DESC
552 help 554 help
553 Support for Intel's IXP4XX (XScale) family of processors. 555 Support for Intel's IXP4XX (XScale) family of processors.
554 556
diff --git a/arch/arm/configs/imx_v6_v7_defconfig b/arch/arm/configs/imx_v6_v7_defconfig
index e36b01025321..088d6c11a0fa 100644
--- a/arch/arm/configs/imx_v6_v7_defconfig
+++ b/arch/arm/configs/imx_v6_v7_defconfig
@@ -188,6 +188,7 @@ CONFIG_USB_EHCI_HCD=y
188CONFIG_USB_EHCI_MXC=y 188CONFIG_USB_EHCI_MXC=y
189CONFIG_USB_CHIPIDEA=y 189CONFIG_USB_CHIPIDEA=y
190CONFIG_USB_CHIPIDEA_HOST=y 190CONFIG_USB_CHIPIDEA_HOST=y
191CONFIG_USB_PHY=y
191CONFIG_USB_MXS_PHY=y 192CONFIG_USB_MXS_PHY=y
192CONFIG_USB_STORAGE=y 193CONFIG_USB_STORAGE=y
193CONFIG_MMC=y 194CONFIG_MMC=y
diff --git a/arch/arm/configs/lpc32xx_defconfig b/arch/arm/configs/lpc32xx_defconfig
index 92386b20bd09..afa7249fac6e 100644
--- a/arch/arm/configs/lpc32xx_defconfig
+++ b/arch/arm/configs/lpc32xx_defconfig
@@ -134,6 +134,7 @@ CONFIG_SND_DEBUG_VERBOSE=y
134# CONFIG_SND_SPI is not set 134# CONFIG_SND_SPI is not set
135CONFIG_SND_SOC=y 135CONFIG_SND_SOC=y
136CONFIG_USB=y 136CONFIG_USB=y
137CONFIG_USB_PHY=y
137CONFIG_USB_OHCI_HCD=y 138CONFIG_USB_OHCI_HCD=y
138CONFIG_USB_STORAGE=y 139CONFIG_USB_STORAGE=y
139CONFIG_USB_GADGET=y 140CONFIG_USB_GADGET=y
diff --git a/arch/arm/configs/mxs_defconfig b/arch/arm/configs/mxs_defconfig
index 6a99e30f81d2..87924d671115 100644
--- a/arch/arm/configs/mxs_defconfig
+++ b/arch/arm/configs/mxs_defconfig
@@ -120,6 +120,7 @@ CONFIG_USB_EHCI_HCD=y
120CONFIG_USB_CHIPIDEA=y 120CONFIG_USB_CHIPIDEA=y
121CONFIG_USB_CHIPIDEA_HOST=y 121CONFIG_USB_CHIPIDEA_HOST=y
122CONFIG_USB_STORAGE=y 122CONFIG_USB_STORAGE=y
123CONFIG_USB_PHY=y
123CONFIG_USB_MXS_PHY=y 124CONFIG_USB_MXS_PHY=y
124CONFIG_MMC=y 125CONFIG_MMC=y
125CONFIG_MMC_MXS=y 126CONFIG_MMC_MXS=y
diff --git a/arch/arm/configs/omap1_defconfig b/arch/arm/configs/omap1_defconfig
index 42eab9a2a0fd..7e0ebb64a7f9 100644
--- a/arch/arm/configs/omap1_defconfig
+++ b/arch/arm/configs/omap1_defconfig
@@ -195,6 +195,7 @@ CONFIG_SND_SOC=y
195CONFIG_SND_OMAP_SOC=y 195CONFIG_SND_OMAP_SOC=y
196# CONFIG_USB_HID is not set 196# CONFIG_USB_HID is not set
197CONFIG_USB=y 197CONFIG_USB=y
198CONFIG_USB_PHY=y
198CONFIG_USB_DEBUG=y 199CONFIG_USB_DEBUG=y
199CONFIG_USB_DEVICEFS=y 200CONFIG_USB_DEVICEFS=y
200# CONFIG_USB_DEVICE_CLASS is not set 201# CONFIG_USB_DEVICE_CLASS is not set
diff --git a/arch/arm/mach-exynos/setup-usb-phy.c b/arch/arm/mach-exynos/setup-usb-phy.c
index b81cc569a8dd..6af40662a449 100644
--- a/arch/arm/mach-exynos/setup-usb-phy.c
+++ b/arch/arm/mach-exynos/setup-usb-phy.c
@@ -204,9 +204,9 @@ static int exynos4210_usb_phy1_exit(struct platform_device *pdev)
204 204
205int s5p_usb_phy_init(struct platform_device *pdev, int type) 205int s5p_usb_phy_init(struct platform_device *pdev, int type)
206{ 206{
207 if (type == S5P_USB_PHY_DEVICE) 207 if (type == USB_PHY_TYPE_DEVICE)
208 return exynos4210_usb_phy0_init(pdev); 208 return exynos4210_usb_phy0_init(pdev);
209 else if (type == S5P_USB_PHY_HOST) 209 else if (type == USB_PHY_TYPE_HOST)
210 return exynos4210_usb_phy1_init(pdev); 210 return exynos4210_usb_phy1_init(pdev);
211 211
212 return -EINVAL; 212 return -EINVAL;
@@ -214,9 +214,9 @@ int s5p_usb_phy_init(struct platform_device *pdev, int type)
214 214
215int s5p_usb_phy_exit(struct platform_device *pdev, int type) 215int s5p_usb_phy_exit(struct platform_device *pdev, int type)
216{ 216{
217 if (type == S5P_USB_PHY_DEVICE) 217 if (type == USB_PHY_TYPE_DEVICE)
218 return exynos4210_usb_phy0_exit(pdev); 218 return exynos4210_usb_phy0_exit(pdev);
219 else if (type == S5P_USB_PHY_HOST) 219 else if (type == USB_PHY_TYPE_HOST)
220 return exynos4210_usb_phy1_exit(pdev); 220 return exynos4210_usb_phy1_exit(pdev);
221 221
222 return -EINVAL; 222 return -EINVAL;
diff --git a/arch/arm/mach-mmp/aspenite.c b/arch/arm/mach-mmp/aspenite.c
index 9f64d5632e07..76901f4ce611 100644
--- a/arch/arm/mach-mmp/aspenite.c
+++ b/arch/arm/mach-mmp/aspenite.c
@@ -223,13 +223,7 @@ static struct pxa27x_keypad_platform_data aspenite_keypad_info __initdata = {
223}; 223};
224 224
225#if defined(CONFIG_USB_EHCI_MV) 225#if defined(CONFIG_USB_EHCI_MV)
226static char *pxa168_sph_clock_name[] = {
227 [0] = "PXA168-USBCLK",
228};
229
230static struct mv_usb_platform_data pxa168_sph_pdata = { 226static struct mv_usb_platform_data pxa168_sph_pdata = {
231 .clknum = 1,
232 .clkname = pxa168_sph_clock_name,
233 .mode = MV_USB_MODE_HOST, 227 .mode = MV_USB_MODE_HOST,
234 .phy_init = pxa_usb_phy_init, 228 .phy_init = pxa_usb_phy_init,
235 .phy_deinit = pxa_usb_phy_deinit, 229 .phy_deinit = pxa_usb_phy_deinit,
diff --git a/arch/arm/mach-mmp/ttc_dkb.c b/arch/arm/mach-mmp/ttc_dkb.c
index 22a9058f9f4d..6528a5fa6a26 100644
--- a/arch/arm/mach-mmp/ttc_dkb.c
+++ b/arch/arm/mach-mmp/ttc_dkb.c
@@ -162,13 +162,7 @@ static struct i2c_board_info ttc_dkb_i2c_info[] = {
162#ifdef CONFIG_USB_SUPPORT 162#ifdef CONFIG_USB_SUPPORT
163#if defined(CONFIG_USB_MV_UDC) || defined(CONFIG_USB_EHCI_MV_U2O) 163#if defined(CONFIG_USB_MV_UDC) || defined(CONFIG_USB_EHCI_MV_U2O)
164 164
165static char *pxa910_usb_clock_name[] = {
166 [0] = "U2OCLK",
167};
168
169static struct mv_usb_platform_data ttc_usb_pdata = { 165static struct mv_usb_platform_data ttc_usb_pdata = {
170 .clknum = 1,
171 .clkname = pxa910_usb_clock_name,
172 .vbus = NULL, 166 .vbus = NULL,
173 .mode = MV_USB_MODE_OTG, 167 .mode = MV_USB_MODE_OTG,
174 .otg_force_a_bus_req = 1, 168 .otg_force_a_bus_req = 1,
diff --git a/arch/arm/mach-s3c64xx/setup-usb-phy.c b/arch/arm/mach-s3c64xx/setup-usb-phy.c
index c8174d95339b..ca960bda02fd 100644
--- a/arch/arm/mach-s3c64xx/setup-usb-phy.c
+++ b/arch/arm/mach-s3c64xx/setup-usb-phy.c
@@ -76,7 +76,7 @@ static int s3c_usb_otgphy_exit(struct platform_device *pdev)
76 76
77int s5p_usb_phy_init(struct platform_device *pdev, int type) 77int s5p_usb_phy_init(struct platform_device *pdev, int type)
78{ 78{
79 if (type == S5P_USB_PHY_DEVICE) 79 if (type == USB_PHY_TYPE_DEVICE)
80 return s3c_usb_otgphy_init(pdev); 80 return s3c_usb_otgphy_init(pdev);
81 81
82 return -EINVAL; 82 return -EINVAL;
@@ -84,7 +84,7 @@ int s5p_usb_phy_init(struct platform_device *pdev, int type)
84 84
85int s5p_usb_phy_exit(struct platform_device *pdev, int type) 85int s5p_usb_phy_exit(struct platform_device *pdev, int type)
86{ 86{
87 if (type == S5P_USB_PHY_DEVICE) 87 if (type == USB_PHY_TYPE_DEVICE)
88 return s3c_usb_otgphy_exit(pdev); 88 return s3c_usb_otgphy_exit(pdev);
89 89
90 return -EINVAL; 90 return -EINVAL;
diff --git a/arch/arm/mach-s5pv210/setup-usb-phy.c b/arch/arm/mach-s5pv210/setup-usb-phy.c
index 356a0900af03..b2ee5333f89c 100644
--- a/arch/arm/mach-s5pv210/setup-usb-phy.c
+++ b/arch/arm/mach-s5pv210/setup-usb-phy.c
@@ -80,7 +80,7 @@ static int s5pv210_usb_otgphy_exit(struct platform_device *pdev)
80 80
81int s5p_usb_phy_init(struct platform_device *pdev, int type) 81int s5p_usb_phy_init(struct platform_device *pdev, int type)
82{ 82{
83 if (type == S5P_USB_PHY_DEVICE) 83 if (type == USB_PHY_TYPE_DEVICE)
84 return s5pv210_usb_otgphy_init(pdev); 84 return s5pv210_usb_otgphy_init(pdev);
85 85
86 return -EINVAL; 86 return -EINVAL;
@@ -88,7 +88,7 @@ int s5p_usb_phy_init(struct platform_device *pdev, int type)
88 88
89int s5p_usb_phy_exit(struct platform_device *pdev, int type) 89int s5p_usb_phy_exit(struct platform_device *pdev, int type)
90{ 90{
91 if (type == S5P_USB_PHY_DEVICE) 91 if (type == USB_PHY_TYPE_DEVICE)
92 return s5pv210_usb_otgphy_exit(pdev); 92 return s5pv210_usb_otgphy_exit(pdev);
93 93
94 return -EINVAL; 94 return -EINVAL;
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c
index f2ec0777cfbe..ff8b7ba9b93c 100644
--- a/arch/arm/mach-shmobile/board-armadillo800eva.c
+++ b/arch/arm/mach-shmobile/board-armadillo800eva.c
@@ -169,7 +169,7 @@ static int usbhsf_get_id(struct platform_device *pdev)
169 return USBHS_GADGET; 169 return USBHS_GADGET;
170} 170}
171 171
172static void usbhsf_power_ctrl(struct platform_device *pdev, 172static int usbhsf_power_ctrl(struct platform_device *pdev,
173 void __iomem *base, int enable) 173 void __iomem *base, int enable)
174{ 174{
175 struct usbhsf_private *priv = usbhsf_get_priv(pdev); 175 struct usbhsf_private *priv = usbhsf_get_priv(pdev);
@@ -223,6 +223,8 @@ static void usbhsf_power_ctrl(struct platform_device *pdev,
223 clk_disable(priv->pci); /* usb work around */ 223 clk_disable(priv->pci); /* usb work around */
224 clk_disable(priv->usb24); /* usb work around */ 224 clk_disable(priv->usb24); /* usb work around */
225 } 225 }
226
227 return 0;
226} 228}
227 229
228static int usbhsf_get_vbus(struct platform_device *pdev) 230static int usbhsf_get_vbus(struct platform_device *pdev)
@@ -239,7 +241,7 @@ static irqreturn_t usbhsf_interrupt(int irq, void *data)
239 return IRQ_HANDLED; 241 return IRQ_HANDLED;
240} 242}
241 243
242static void usbhsf_hardware_exit(struct platform_device *pdev) 244static int usbhsf_hardware_exit(struct platform_device *pdev)
243{ 245{
244 struct usbhsf_private *priv = usbhsf_get_priv(pdev); 246 struct usbhsf_private *priv = usbhsf_get_priv(pdev);
245 247
@@ -264,6 +266,8 @@ static void usbhsf_hardware_exit(struct platform_device *pdev)
264 priv->usbh_base = NULL; 266 priv->usbh_base = NULL;
265 267
266 free_irq(IRQ7, pdev); 268 free_irq(IRQ7, pdev);
269
270 return 0;
267} 271}
268 272
269static int usbhsf_hardware_init(struct platform_device *pdev) 273static int usbhsf_hardware_init(struct platform_device *pdev)
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c
index 7f3a6b7e7b7c..a385f570bbfc 100644
--- a/arch/arm/mach-shmobile/board-kzm9g.c
+++ b/arch/arm/mach-shmobile/board-kzm9g.c
@@ -155,12 +155,14 @@ static int usbhs_get_vbus(struct platform_device *pdev)
155 return !((1 << 7) & __raw_readw(priv->cr2)); 155 return !((1 << 7) & __raw_readw(priv->cr2));
156} 156}
157 157
158static void usbhs_phy_reset(struct platform_device *pdev) 158static int usbhs_phy_reset(struct platform_device *pdev)
159{ 159{
160 struct usbhs_private *priv = usbhs_get_priv(pdev); 160 struct usbhs_private *priv = usbhs_get_priv(pdev);
161 161
162 /* init phy */ 162 /* init phy */
163 __raw_writew(0x8a0a, priv->cr2); 163 __raw_writew(0x8a0a, priv->cr2);
164
165 return 0;
164} 166}
165 167
166static int usbhs_get_id(struct platform_device *pdev) 168static int usbhs_get_id(struct platform_device *pdev)
@@ -202,7 +204,7 @@ static int usbhs_hardware_init(struct platform_device *pdev)
202 return 0; 204 return 0;
203} 205}
204 206
205static void usbhs_hardware_exit(struct platform_device *pdev) 207static int usbhs_hardware_exit(struct platform_device *pdev)
206{ 208{
207 struct usbhs_private *priv = usbhs_get_priv(pdev); 209 struct usbhs_private *priv = usbhs_get_priv(pdev);
208 210
@@ -210,6 +212,8 @@ static void usbhs_hardware_exit(struct platform_device *pdev)
210 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy); 212 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->phy);
211 213
212 free_irq(IRQ15, pdev); 214 free_irq(IRQ15, pdev);
215
216 return 0;
213} 217}
214 218
215static u32 usbhs_pipe_cfg[] = { 219static u32 usbhs_pipe_cfg[] = {
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index db968a585ff0..979237c18dad 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -596,12 +596,14 @@ static int usbhs_get_vbus(struct platform_device *pdev)
596 return usbhs_is_connected(usbhs_get_priv(pdev)); 596 return usbhs_is_connected(usbhs_get_priv(pdev));
597} 597}
598 598
599static void usbhs_phy_reset(struct platform_device *pdev) 599static int usbhs_phy_reset(struct platform_device *pdev)
600{ 600{
601 struct usbhs_private *priv = usbhs_get_priv(pdev); 601 struct usbhs_private *priv = usbhs_get_priv(pdev);
602 602
603 /* init phy */ 603 /* init phy */
604 __raw_writew(0x8a0a, priv->usbcrcaddr); 604 __raw_writew(0x8a0a, priv->usbcrcaddr);
605
606 return 0;
605} 607}
606 608
607static int usbhs0_get_id(struct platform_device *pdev) 609static int usbhs0_get_id(struct platform_device *pdev)
@@ -628,11 +630,13 @@ static int usbhs0_hardware_init(struct platform_device *pdev)
628 return 0; 630 return 0;
629} 631}
630 632
631static void usbhs0_hardware_exit(struct platform_device *pdev) 633static int usbhs0_hardware_exit(struct platform_device *pdev)
632{ 634{
633 struct usbhs_private *priv = usbhs_get_priv(pdev); 635 struct usbhs_private *priv = usbhs_get_priv(pdev);
634 636
635 cancel_delayed_work_sync(&priv->work); 637 cancel_delayed_work_sync(&priv->work);
638
639 return 0;
636} 640}
637 641
638static struct usbhs_private usbhs0_private = { 642static struct usbhs_private usbhs0_private = {
@@ -735,7 +739,7 @@ static int usbhs1_hardware_init(struct platform_device *pdev)
735 return 0; 739 return 0;
736} 740}
737 741
738static void usbhs1_hardware_exit(struct platform_device *pdev) 742static int usbhs1_hardware_exit(struct platform_device *pdev)
739{ 743{
740 struct usbhs_private *priv = usbhs_get_priv(pdev); 744 struct usbhs_private *priv = usbhs_get_priv(pdev);
741 745
@@ -743,6 +747,8 @@ static void usbhs1_hardware_exit(struct platform_device *pdev)
743 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr); 747 __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
744 748
745 free_irq(IRQ8, pdev); 749 free_irq(IRQ8, pdev);
750
751 return 0;
746} 752}
747 753
748static int usbhs1_get_id(struct platform_device *pdev) 754static int usbhs1_get_id(struct platform_device *pdev)
diff --git a/arch/arm/mach-tegra/Kconfig b/arch/arm/mach-tegra/Kconfig
index d1c4893894ce..dbc653ea851c 100644
--- a/arch/arm/mach-tegra/Kconfig
+++ b/arch/arm/mach-tegra/Kconfig
@@ -18,8 +18,8 @@ config ARCH_TEGRA_2x_SOC
18 select PL310_ERRATA_727915 if CACHE_L2X0 18 select PL310_ERRATA_727915 if CACHE_L2X0
19 select PL310_ERRATA_769419 if CACHE_L2X0 19 select PL310_ERRATA_769419 if CACHE_L2X0
20 select USB_ARCH_HAS_EHCI if USB_SUPPORT 20 select USB_ARCH_HAS_EHCI if USB_SUPPORT
21 select USB_ULPI if USB 21 select USB_ULPI if USB_PHY
22 select USB_ULPI_VIEWPORT if USB_SUPPORT 22 select USB_ULPI_VIEWPORT if USB_PHY
23 help 23 help
24 Support for NVIDIA Tegra AP20 and T20 processors, based on the 24 Support for NVIDIA Tegra AP20 and T20 processors, based on the
25 ARM CortexA9MP CPU and the ARM PL310 L2 cache controller 25 ARM CortexA9MP CPU and the ARM PL310 L2 cache controller
@@ -37,8 +37,8 @@ config ARCH_TEGRA_3x_SOC
37 select PINCTRL_TEGRA30 37 select PINCTRL_TEGRA30
38 select PL310_ERRATA_769419 if CACHE_L2X0 38 select PL310_ERRATA_769419 if CACHE_L2X0
39 select USB_ARCH_HAS_EHCI if USB_SUPPORT 39 select USB_ARCH_HAS_EHCI if USB_SUPPORT
40 select USB_ULPI if USB 40 select USB_ULPI if USB_PHY
41 select USB_ULPI_VIEWPORT if USB_SUPPORT 41 select USB_ULPI_VIEWPORT if USB_PHY
42 help 42 help
43 Support for NVIDIA Tegra T30 processor family, based on the 43 Support for NVIDIA Tegra T30 processor family, based on the
44 ARM CortexA9MP CPU and the ARM PL310 L2 cache controller 44 ARM CortexA9MP CPU and the ARM PL310 L2 cache controller
diff --git a/arch/arm/plat-samsung/include/plat/usb-phy.h b/arch/arm/plat-samsung/include/plat/usb-phy.h
index 959bcdb03a25..ab34dfadb7f9 100644
--- a/arch/arm/plat-samsung/include/plat/usb-phy.h
+++ b/arch/arm/plat-samsung/include/plat/usb-phy.h
@@ -11,10 +11,7 @@
11#ifndef __PLAT_SAMSUNG_USB_PHY_H 11#ifndef __PLAT_SAMSUNG_USB_PHY_H
12#define __PLAT_SAMSUNG_USB_PHY_H __FILE__ 12#define __PLAT_SAMSUNG_USB_PHY_H __FILE__
13 13
14enum s5p_usb_phy_type { 14#include <linux/usb/samsung_usb_phy.h>
15 S5P_USB_PHY_DEVICE,
16 S5P_USB_PHY_HOST,
17};
18 15
19extern int s5p_usb_phy_init(struct platform_device *pdev, int type); 16extern int s5p_usb_phy_init(struct platform_device *pdev, int type);
20extern int s5p_usb_phy_exit(struct platform_device *pdev, int type); 17extern int s5p_usb_phy_exit(struct platform_device *pdev, int type);
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 51244bf97271..3a7b3954ce1b 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -404,6 +404,8 @@ config PMC_MSP
404 select IRQ_CPU 404 select IRQ_CPU
405 select SERIAL_8250 405 select SERIAL_8250
406 select SERIAL_8250_CONSOLE 406 select SERIAL_8250_CONSOLE
407 select USB_EHCI_BIG_ENDIAN_MMIO
408 select USB_EHCI_BIG_ENDIAN_DESC
407 help 409 help
408 This adds support for the PMC-Sierra family of Multi-Service 410 This adds support for the PMC-Sierra family of Multi-Service
409 Processor System-On-A-Chips. These parts include a number 411 Processor System-On-A-Chips. These parts include a number
@@ -1433,6 +1435,7 @@ config CPU_CAVIUM_OCTEON
1433 select CPU_SUPPORTS_HUGEPAGES 1435 select CPU_SUPPORTS_HUGEPAGES
1434 select LIBFDT 1436 select LIBFDT
1435 select USE_OF 1437 select USE_OF
1438 select USB_EHCI_BIG_ENDIAN_MMIO
1436 help 1439 help
1437 The Cavium Octeon processor is a highly integrated chip containing 1440 The Cavium Octeon processor is a highly integrated chip containing
1438 many ethernet hardware widgets for networking tasks. The processor 1441 many ethernet hardware widgets for networking tasks. The processor
diff --git a/arch/powerpc/platforms/44x/Kconfig b/arch/powerpc/platforms/44x/Kconfig
index 0effe9f5a1ea..7be93367d92f 100644
--- a/arch/powerpc/platforms/44x/Kconfig
+++ b/arch/powerpc/platforms/44x/Kconfig
@@ -274,6 +274,8 @@ config 440EPX
274 select IBM_EMAC_EMAC4 274 select IBM_EMAC_EMAC4
275 select IBM_EMAC_RGMII 275 select IBM_EMAC_RGMII
276 select IBM_EMAC_ZMII 276 select IBM_EMAC_ZMII
277 select USB_EHCI_BIG_ENDIAN_MMIO
278 select USB_EHCI_BIG_ENDIAN_DESC
277 279
278config 440GRX 280config 440GRX
279 bool 281 bool
diff --git a/arch/powerpc/platforms/512x/Kconfig b/arch/powerpc/platforms/512x/Kconfig
index c16999802ecf..381a592826a2 100644
--- a/arch/powerpc/platforms/512x/Kconfig
+++ b/arch/powerpc/platforms/512x/Kconfig
@@ -7,6 +7,8 @@ config PPC_MPC512x
7 select PPC_PCI_CHOICE 7 select PPC_PCI_CHOICE
8 select FSL_PCI if PCI 8 select FSL_PCI if PCI
9 select ARCH_WANT_OPTIONAL_GPIOLIB 9 select ARCH_WANT_OPTIONAL_GPIOLIB
10 select USB_EHCI_BIG_ENDIAN_MMIO
11 select USB_EHCI_BIG_ENDIAN_DESC
10 12
11config MPC5121_ADS 13config MPC5121_ADS
12 bool "Freescale MPC5121E ADS" 14 bool "Freescale MPC5121E ADS"
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index aaff7671101b..764530c85aa9 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -254,11 +254,13 @@ static int usbhs_get_id(struct platform_device *pdev)
254 return gpio_get_value(GPIO_PTB3); 254 return gpio_get_value(GPIO_PTB3);
255} 255}
256 256
257static void usbhs_phy_reset(struct platform_device *pdev) 257static int usbhs_phy_reset(struct platform_device *pdev)
258{ 258{
259 /* enable vbus if HOST */ 259 /* enable vbus if HOST */
260 if (!gpio_get_value(GPIO_PTB3)) 260 if (!gpio_get_value(GPIO_PTB3))
261 gpio_set_value(GPIO_PTB5, 1); 261 gpio_set_value(GPIO_PTB5, 1);
262
263 return 0;
262} 264}
263 265
264static struct renesas_usbhs_platform_info usbhs_info = { 266static struct renesas_usbhs_platform_info usbhs_info = {
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 3d361f236308..66dc562950ae 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -407,6 +407,8 @@ config SERIAL_CONSOLE
407config SPARC_LEON 407config SPARC_LEON
408 bool "Sparc Leon processor family" 408 bool "Sparc Leon processor family"
409 depends on SPARC32 409 depends on SPARC32
410 select USB_EHCI_BIG_ENDIAN_MMIO
411 select USB_EHCI_BIG_ENDIAN_DESC
410 ---help--- 412 ---help---
411 If you say Y here if you are running on a SPARC-LEON processor. 413 If you say Y here if you are running on a SPARC-LEON processor.
412 The LEON processor is a synthesizable VHDL model of the 414 The LEON processor is a synthesizable VHDL model of the
diff --git a/drivers/Makefile b/drivers/Makefile
index 4865ed24708a..33360de63650 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -79,7 +79,7 @@ obj-$(CONFIG_ATA_OVER_ETH) += block/aoe/
79obj-$(CONFIG_PARIDE) += block/paride/ 79obj-$(CONFIG_PARIDE) += block/paride/
80obj-$(CONFIG_TC) += tc/ 80obj-$(CONFIG_TC) += tc/
81obj-$(CONFIG_UWB) += uwb/ 81obj-$(CONFIG_UWB) += uwb/
82obj-$(CONFIG_USB_OTG_UTILS) += usb/ 82obj-$(CONFIG_USB_PHY) += usb/
83obj-$(CONFIG_USB) += usb/ 83obj-$(CONFIG_USB) += usb/
84obj-$(CONFIG_PCI) += usb/ 84obj-$(CONFIG_PCI) += usb/
85obj-$(CONFIG_USB_GADGET) += usb/ 85obj-$(CONFIG_USB_GADGET) += usb/
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 8e0c4bf94ebc..1f9e56bfeaa0 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1493,7 +1493,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1493{ 1493{
1494 struct hid_device *hid = usb_get_intfdata(intf); 1494 struct hid_device *hid = usb_get_intfdata(intf);
1495 struct usbhid_device *usbhid = hid->driver_data; 1495 struct usbhid_device *usbhid = hid->driver_data;
1496 int status; 1496 int status = 0;
1497 bool driver_suspended = false; 1497 bool driver_suspended = false;
1498 1498
1499 if (PMSG_IS_AUTO(message)) { 1499 if (PMSG_IS_AUTO(message)) {
@@ -1520,19 +1520,15 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1520 } 1520 }
1521 1521
1522 } else { 1522 } else {
1523 if (hid->driver && hid->driver->suspend) { 1523 /* TODO: resume() might need to handle suspend failure */
1524 if (hid->driver && hid->driver->suspend)
1524 status = hid->driver->suspend(hid, message); 1525 status = hid->driver->suspend(hid, message);
1525 if (status < 0)
1526 return status;
1527 }
1528 driver_suspended = true; 1526 driver_suspended = true;
1529 spin_lock_irq(&usbhid->lock); 1527 spin_lock_irq(&usbhid->lock);
1530 set_bit(HID_SUSPENDED, &usbhid->iofl); 1528 set_bit(HID_SUSPENDED, &usbhid->iofl);
1531 spin_unlock_irq(&usbhid->lock); 1529 spin_unlock_irq(&usbhid->lock);
1532 if (usbhid_wait_io(hid) < 0) { 1530 if (usbhid_wait_io(hid) < 0)
1533 status = -EIO; 1531 status = -EIO;
1534 goto failed;
1535 }
1536 } 1532 }
1537 1533
1538 hid_cancel_delayed_stuff(usbhid); 1534 hid_cancel_delayed_stuff(usbhid);
@@ -1544,7 +1540,7 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
1544 goto failed; 1540 goto failed;
1545 } 1541 }
1546 dev_dbg(&intf->dev, "suspend\n"); 1542 dev_dbg(&intf->dev, "suspend\n");
1547 return 0; 1543 return status;
1548 1544
1549 failed: 1545 failed:
1550 hid_resume_common(hid, driver_suspended); 1546 hid_resume_common(hid, driver_suspended);
diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index 6bd91676d2cb..32a76059e7da 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -323,6 +323,11 @@ static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message)
323 goto error; 323 goto error;
324 } 324 }
325 325
326 /*
327 * Both usbnet_suspend() and subdriver->suspend() MUST return 0
328 * in system sleep context, otherwise, the resume callback has
329 * to recover device from previous suspend failure.
330 */
326 ret = usbnet_suspend(intf, message); 331 ret = usbnet_suspend(intf, message);
327 if (ret < 0) 332 if (ret < 0)
328 goto error; 333 goto error;
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 2a3579f67910..5a88e72090ce 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -374,6 +374,11 @@ static int qmi_wwan_suspend(struct usb_interface *intf, pm_message_t message)
374 struct qmi_wwan_state *info = (void *)&dev->data; 374 struct qmi_wwan_state *info = (void *)&dev->data;
375 int ret; 375 int ret;
376 376
377 /*
378 * Both usbnet_suspend() and subdriver->suspend() MUST return 0
379 * in system sleep context, otherwise, the resume callback has
380 * to recover device from previous suspend failure.
381 */
377 ret = usbnet_suspend(intf, message); 382 ret = usbnet_suspend(intf, message);
378 if (ret < 0) 383 if (ret < 0)
379 goto err; 384 goto err;
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 1a15ec14c386..75409748c774 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -2015,7 +2015,11 @@ static int smsc75xx_suspend(struct usb_interface *intf, pm_message_t message)
2015 ret = smsc75xx_enter_suspend0(dev); 2015 ret = smsc75xx_enter_suspend0(dev);
2016 2016
2017done: 2017done:
2018 if (ret) 2018 /*
2019 * TODO: resume() might need to handle the suspend failure
2020 * in system sleep
2021 */
2022 if (ret && PMSG_IS_AUTO(message))
2019 usbnet_resume(intf); 2023 usbnet_resume(intf);
2020 return ret; 2024 return ret;
2021} 2025}
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index e6d2dea1373c..3f38ba868f61 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -1660,7 +1660,11 @@ static int smsc95xx_suspend(struct usb_interface *intf, pm_message_t message)
1660 ret = smsc95xx_enter_suspend0(dev); 1660 ret = smsc95xx_enter_suspend0(dev);
1661 1661
1662done: 1662done:
1663 if (ret) 1663 /*
1664 * TODO: resume() might need to handle the suspend failure
1665 * in system sleep
1666 */
1667 if (ret && PMSG_IS_AUTO(message))
1664 usbnet_resume(intf); 1668 usbnet_resume(intf);
1665 return ret; 1669 return ret;
1666} 1670}
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 9e00c389e777..ffe02fb7cbc7 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -254,7 +254,7 @@ config BATTERY_RX51
254 254
255config CHARGER_ISP1704 255config CHARGER_ISP1704
256 tristate "ISP1704 USB Charger Detection" 256 tristate "ISP1704 USB Charger Detection"
257 depends on USB_OTG_UTILS 257 depends on USB_PHY
258 help 258 help
259 Say Y to enable support for USB Charger Detection with 259 Say Y to enable support for USB Charger Detection with
260 ISP1707/ISP1704 USB transceivers. 260 ISP1707/ISP1704 USB transceivers.
diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
index 7df7c5facc10..0c52e2a0d90c 100644
--- a/drivers/power/pda_power.c
+++ b/drivers/power/pda_power.c
@@ -35,7 +35,7 @@ static struct timer_list supply_timer;
35static struct timer_list polling_timer; 35static struct timer_list polling_timer;
36static int polling; 36static int polling;
37 37
38#ifdef CONFIG_USB_OTG_UTILS 38#if IS_ENABLED(CONFIG_USB_PHY)
39static struct usb_phy *transceiver; 39static struct usb_phy *transceiver;
40static struct notifier_block otg_nb; 40static struct notifier_block otg_nb;
41#endif 41#endif
@@ -218,7 +218,7 @@ static void polling_timer_func(unsigned long unused)
218 jiffies + msecs_to_jiffies(pdata->polling_interval)); 218 jiffies + msecs_to_jiffies(pdata->polling_interval));
219} 219}
220 220
221#ifdef CONFIG_USB_OTG_UTILS 221#if IS_ENABLED(CONFIG_USB_PHY)
222static int otg_is_usb_online(void) 222static int otg_is_usb_online(void)
223{ 223{
224 return (transceiver->last_event == USB_EVENT_VBUS || 224 return (transceiver->last_event == USB_EVENT_VBUS ||
@@ -315,7 +315,7 @@ static int pda_power_probe(struct platform_device *pdev)
315 pda_psy_usb.num_supplicants = pdata->num_supplicants; 315 pda_psy_usb.num_supplicants = pdata->num_supplicants;
316 } 316 }
317 317
318#ifdef CONFIG_USB_OTG_UTILS 318#if IS_ENABLED(CONFIG_USB_PHY)
319 transceiver = usb_get_phy(USB_PHY_TYPE_USB2); 319 transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
320 if (!IS_ERR_OR_NULL(transceiver)) { 320 if (!IS_ERR_OR_NULL(transceiver)) {
321 if (!pdata->is_usb_online) 321 if (!pdata->is_usb_online)
@@ -367,7 +367,7 @@ static int pda_power_probe(struct platform_device *pdev)
367 } 367 }
368 } 368 }
369 369
370#ifdef CONFIG_USB_OTG_UTILS 370#if IS_ENABLED(CONFIG_USB_PHY)
371 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) { 371 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
372 otg_nb.notifier_call = otg_handle_notification; 372 otg_nb.notifier_call = otg_handle_notification;
373 ret = usb_register_notifier(transceiver, &otg_nb); 373 ret = usb_register_notifier(transceiver, &otg_nb);
@@ -391,7 +391,7 @@ static int pda_power_probe(struct platform_device *pdev)
391 391
392 return 0; 392 return 0;
393 393
394#ifdef CONFIG_USB_OTG_UTILS 394#if IS_ENABLED(CONFIG_USB_PHY)
395otg_reg_notifier_failed: 395otg_reg_notifier_failed:
396 if (pdata->is_usb_online && usb_irq) 396 if (pdata->is_usb_online && usb_irq)
397 free_irq(usb_irq->start, &pda_psy_usb); 397 free_irq(usb_irq->start, &pda_psy_usb);
@@ -402,7 +402,7 @@ usb_irq_failed:
402usb_supply_failed: 402usb_supply_failed:
403 if (pdata->is_ac_online && ac_irq) 403 if (pdata->is_ac_online && ac_irq)
404 free_irq(ac_irq->start, &pda_psy_ac); 404 free_irq(ac_irq->start, &pda_psy_ac);
405#ifdef CONFIG_USB_OTG_UTILS 405#if IS_ENABLED(CONFIG_USB_PHY)
406 if (!IS_ERR_OR_NULL(transceiver)) 406 if (!IS_ERR_OR_NULL(transceiver))
407 usb_put_phy(transceiver); 407 usb_put_phy(transceiver);
408#endif 408#endif
@@ -437,7 +437,7 @@ static int pda_power_remove(struct platform_device *pdev)
437 power_supply_unregister(&pda_psy_usb); 437 power_supply_unregister(&pda_psy_usb);
438 if (pdata->is_ac_online) 438 if (pdata->is_ac_online)
439 power_supply_unregister(&pda_psy_ac); 439 power_supply_unregister(&pda_psy_ac);
440#ifdef CONFIG_USB_OTG_UTILS 440#if IS_ENABLED(CONFIG_USB_PHY)
441 if (!IS_ERR_OR_NULL(transceiver)) 441 if (!IS_ERR_OR_NULL(transceiver))
442 usb_put_phy(transceiver); 442 usb_put_phy(transceiver);
443#endif 443#endif
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 640ae6c6d2d2..92e1dc94ecc8 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -122,9 +122,9 @@ config USB
122 To compile this driver as a module, choose M here: the 122 To compile this driver as a module, choose M here: the
123 module will be called usbcore. 123 module will be called usbcore.
124 124
125source "drivers/usb/core/Kconfig" 125if USB
126 126
127source "drivers/usb/dwc3/Kconfig" 127source "drivers/usb/core/Kconfig"
128 128
129source "drivers/usb/mon/Kconfig" 129source "drivers/usb/mon/Kconfig"
130 130
@@ -134,8 +134,6 @@ source "drivers/usb/host/Kconfig"
134 134
135source "drivers/usb/musb/Kconfig" 135source "drivers/usb/musb/Kconfig"
136 136
137source "drivers/usb/chipidea/Kconfig"
138
139source "drivers/usb/renesas_usbhs/Kconfig" 137source "drivers/usb/renesas_usbhs/Kconfig"
140 138
141source "drivers/usb/class/Kconfig" 139source "drivers/usb/class/Kconfig"
@@ -144,12 +142,19 @@ source "drivers/usb/storage/Kconfig"
144 142
145source "drivers/usb/image/Kconfig" 143source "drivers/usb/image/Kconfig"
146 144
145endif
146
147source "drivers/usb/dwc3/Kconfig"
148
149source "drivers/usb/chipidea/Kconfig"
150
147comment "USB port drivers" 151comment "USB port drivers"
148 depends on USB 152
153if USB
149 154
150config USB_USS720 155config USB_USS720
151 tristate "USS720 parport driver" 156 tristate "USS720 parport driver"
152 depends on USB && PARPORT 157 depends on PARPORT
153 select PARPORT_NOT_PC 158 select PARPORT_NOT_PC
154 ---help--- 159 ---help---
155 This driver is for USB parallel port adapters that use the Lucent 160 This driver is for USB parallel port adapters that use the Lucent
@@ -180,12 +185,12 @@ source "drivers/usb/serial/Kconfig"
180 185
181source "drivers/usb/misc/Kconfig" 186source "drivers/usb/misc/Kconfig"
182 187
183source "drivers/usb/phy/Kconfig"
184
185source "drivers/usb/atm/Kconfig" 188source "drivers/usb/atm/Kconfig"
186 189
187source "drivers/usb/gadget/Kconfig" 190endif # USB
191
192source "drivers/usb/phy/Kconfig"
188 193
189source "drivers/usb/otg/Kconfig" 194source "drivers/usb/gadget/Kconfig"
190 195
191endif # USB_SUPPORT 196endif # USB_SUPPORT
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 8f5ebced5df0..c41feba8d5c0 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -6,8 +6,6 @@
6 6
7obj-$(CONFIG_USB) += core/ 7obj-$(CONFIG_USB) += core/
8 8
9obj-$(CONFIG_USB_OTG_UTILS) += otg/
10
11obj-$(CONFIG_USB_DWC3) += dwc3/ 9obj-$(CONFIG_USB_DWC3) += dwc3/
12 10
13obj-$(CONFIG_USB_MON) += mon/ 11obj-$(CONFIG_USB_MON) += mon/
@@ -46,7 +44,7 @@ obj-$(CONFIG_USB_MICROTEK) += image/
46obj-$(CONFIG_USB_SERIAL) += serial/ 44obj-$(CONFIG_USB_SERIAL) += serial/
47 45
48obj-$(CONFIG_USB) += misc/ 46obj-$(CONFIG_USB) += misc/
49obj-$(CONFIG_USB_OTG_UTILS) += phy/ 47obj-$(CONFIG_USB_PHY) += phy/
50obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/ 48obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
51 49
52obj-$(CONFIG_USB_ATM) += atm/ 50obj-$(CONFIG_USB_ATM) += atm/
diff --git a/drivers/usb/atm/Kconfig b/drivers/usb/atm/Kconfig
index be0b8daac9c7..0f922942a07a 100644
--- a/drivers/usb/atm/Kconfig
+++ b/drivers/usb/atm/Kconfig
@@ -4,7 +4,7 @@
4 4
5menuconfig USB_ATM 5menuconfig USB_ATM
6 tristate "USB DSL modem support" 6 tristate "USB DSL modem support"
7 depends on USB && ATM 7 depends on ATM
8 select CRC32 8 select CRC32
9 default n 9 default n
10 help 10 help
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 35f10bfe15db..d3527dd8b90c 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -672,9 +672,6 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
672 struct usbatm_control *ctrl = UDSL_SKB(skb); 672 struct usbatm_control *ctrl = UDSL_SKB(skb);
673 int err; 673 int err;
674 674
675 vdbg(&instance->usb_intf->dev, "%s called (skb 0x%p, len %u)", __func__,
676 skb, skb->len);
677
678 /* racy disconnection check - fine */ 675 /* racy disconnection check - fine */
679 if (!instance || instance->disconnected) { 676 if (!instance || instance->disconnected) {
680#ifdef DEBUG 677#ifdef DEBUG
@@ -684,6 +681,9 @@ static int usbatm_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
684 goto fail; 681 goto fail;
685 } 682 }
686 683
684 vdbg(&instance->usb_intf->dev, "%s called (skb 0x%p, len %u)", __func__,
685 skb, skb->len);
686
687 if (vcc->qos.aal != ATM_AAL5) { 687 if (vcc->qos.aal != ATM_AAL5) {
688 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal); 688 atm_rldbg(instance, "%s: unsupported ATM type %d!\n", __func__, vcc->qos.aal);
689 err = -EINVAL; 689 err = -EINVAL;
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index d92ca325b104..4ab83e98219b 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -17,5 +17,5 @@ ifneq ($(CONFIG_PCI),)
17endif 17endif
18 18
19ifneq ($(CONFIG_OF_DEVICE),) 19ifneq ($(CONFIG_OF_DEVICE),)
20 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o usbmisc_imx6q.o 20 obj-$(CONFIG_USB_CHIPIDEA) += ci13xxx_imx.o usbmisc_imx.o
21endif 21endif
diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index e25d1263da13..b0a6bce064ca 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -21,6 +21,7 @@
21/****************************************************************************** 21/******************************************************************************
22 * DEFINE 22 * DEFINE
23 *****************************************************************************/ 23 *****************************************************************************/
24#define TD_PAGE_COUNT 5
24#define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */ 25#define CI13XXX_PAGE_SIZE 4096ul /* page size for TD's */
25#define ENDPT_MAX 32 26#define ENDPT_MAX 32
26 27
@@ -129,6 +130,7 @@ struct hw_bank {
129 * @vbus_active: is VBUS active 130 * @vbus_active: is VBUS active
130 * @transceiver: pointer to USB PHY, if any 131 * @transceiver: pointer to USB PHY, if any
131 * @hcd: pointer to usb_hcd for ehci host driver 132 * @hcd: pointer to usb_hcd for ehci host driver
133 * @debugfs: root dentry for this controller in debugfs
132 */ 134 */
133struct ci13xxx { 135struct ci13xxx {
134 struct device *dev; 136 struct device *dev;
@@ -139,7 +141,6 @@ struct ci13xxx {
139 enum ci_role role; 141 enum ci_role role;
140 bool is_otg; 142 bool is_otg;
141 struct work_struct work; 143 struct work_struct work;
142 struct work_struct vbus_work;
143 struct workqueue_struct *wq; 144 struct workqueue_struct *wq;
144 145
145 struct dma_pool *qh_pool; 146 struct dma_pool *qh_pool;
@@ -165,6 +166,7 @@ struct ci13xxx {
165 bool global_phy; 166 bool global_phy;
166 struct usb_phy *transceiver; 167 struct usb_phy *transceiver;
167 struct usb_hcd *hcd; 168 struct usb_hcd *hcd;
169 struct dentry *debugfs;
168}; 170};
169 171
170static inline struct ci_role_driver *ci_role(struct ci13xxx *ci) 172static inline struct ci_role_driver *ci_role(struct ci13xxx *ci)
@@ -234,19 +236,6 @@ enum ci13xxx_regs {
234}; 236};
235 237
236/** 238/**
237 * ffs_nr: find first (least significant) bit set
238 * @x: the word to search
239 *
240 * This function returns bit number (instead of position)
241 */
242static inline int ffs_nr(u32 x)
243{
244 int n = ffs(x);
245
246 return n ? n-1 : 32;
247}
248
249/**
250 * hw_read: reads from a hw register 239 * hw_read: reads from a hw register
251 * @reg: register index 240 * @reg: register index
252 * @mask: bitfield mask 241 * @mask: bitfield mask
@@ -304,7 +293,7 @@ static inline u32 hw_test_and_write(struct ci13xxx *ci, enum ci13xxx_regs reg,
304 u32 val = hw_read(ci, reg, ~0); 293 u32 val = hw_read(ci, reg, ~0);
305 294
306 hw_write(ci, reg, mask, data); 295 hw_write(ci, reg, mask, data);
307 return (val & mask) >> ffs_nr(mask); 296 return (val & mask) >> __ffs(mask);
308} 297}
309 298
310int hw_device_reset(struct ci13xxx *ci, u32 mode); 299int hw_device_reset(struct ci13xxx *ci, u32 mode);
diff --git a/drivers/usb/chipidea/ci13xxx_imx.c b/drivers/usb/chipidea/ci13xxx_imx.c
index 8c291220be7f..8faec9dbbb84 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.c
+++ b/drivers/usb/chipidea/ci13xxx_imx.c
@@ -79,6 +79,9 @@ int usbmisc_get_init_data(struct device *dev, struct usbmisc_usb_device *usbdev)
79 if (of_find_property(np, "disable-over-current", NULL)) 79 if (of_find_property(np, "disable-over-current", NULL))
80 usbdev->disable_oc = 1; 80 usbdev->disable_oc = 1;
81 81
82 if (of_find_property(np, "external-vbus-divider", NULL))
83 usbdev->evdo = 1;
84
82 return 0; 85 return 0;
83} 86}
84EXPORT_SYMBOL_GPL(usbmisc_get_init_data); 87EXPORT_SYMBOL_GPL(usbmisc_get_init_data);
@@ -202,6 +205,15 @@ static int ci13xxx_imx_probe(struct platform_device *pdev)
202 goto err; 205 goto err;
203 } 206 }
204 207
208 if (usbmisc_ops && usbmisc_ops->post) {
209 ret = usbmisc_ops->post(&pdev->dev);
210 if (ret) {
211 dev_err(&pdev->dev,
212 "usbmisc post failed, ret=%d\n", ret);
213 goto put_np;
214 }
215 }
216
205 data->ci_pdev = plat_ci; 217 data->ci_pdev = plat_ci;
206 platform_set_drvdata(pdev, data); 218 platform_set_drvdata(pdev, data);
207 219
diff --git a/drivers/usb/chipidea/ci13xxx_imx.h b/drivers/usb/chipidea/ci13xxx_imx.h
index 9cd2e910b1ca..550bfa457620 100644
--- a/drivers/usb/chipidea/ci13xxx_imx.h
+++ b/drivers/usb/chipidea/ci13xxx_imx.h
@@ -13,6 +13,8 @@
13struct usbmisc_ops { 13struct usbmisc_ops {
14 /* It's called once when probe a usb device */ 14 /* It's called once when probe a usb device */
15 int (*init)(struct device *dev); 15 int (*init)(struct device *dev);
16 /* It's called once after adding a usb device */
17 int (*post)(struct device *dev);
16}; 18};
17 19
18struct usbmisc_usb_device { 20struct usbmisc_usb_device {
@@ -20,6 +22,7 @@ struct usbmisc_usb_device {
20 int index; 22 int index;
21 23
22 unsigned int disable_oc:1; /* over current detect disabled */ 24 unsigned int disable_oc:1; /* over current detect disabled */
25 unsigned int evdo:1; /* set external vbus divider option */
23}; 26};
24 27
25int usbmisc_set_ops(const struct usbmisc_ops *ops); 28int usbmisc_set_ops(const struct usbmisc_ops *ops);
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c
index 9b227e39299a..4e1fc61b9d95 100644
--- a/drivers/usb/chipidea/ci13xxx_pci.c
+++ b/drivers/usb/chipidea/ci13xxx_pci.c
@@ -23,17 +23,17 @@
23/****************************************************************************** 23/******************************************************************************
24 * PCI block 24 * PCI block
25 *****************************************************************************/ 25 *****************************************************************************/
26struct ci13xxx_platform_data pci_platdata = { 26static struct ci13xxx_platform_data pci_platdata = {
27 .name = UDC_DRIVER_NAME, 27 .name = UDC_DRIVER_NAME,
28 .capoffset = DEF_CAPOFFSET, 28 .capoffset = DEF_CAPOFFSET,
29}; 29};
30 30
31struct ci13xxx_platform_data langwell_pci_platdata = { 31static struct ci13xxx_platform_data langwell_pci_platdata = {
32 .name = UDC_DRIVER_NAME, 32 .name = UDC_DRIVER_NAME,
33 .capoffset = 0, 33 .capoffset = 0,
34}; 34};
35 35
36struct ci13xxx_platform_data penwell_pci_platdata = { 36static struct ci13xxx_platform_data penwell_pci_platdata = {
37 .name = UDC_DRIVER_NAME, 37 .name = UDC_DRIVER_NAME,
38 .capoffset = 0, 38 .capoffset = 0,
39 .power_budget = 200, 39 .power_budget = 200,
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 57cae1f897b2..450107e5f657 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -51,15 +51,12 @@
51 */ 51 */
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/device.h> 53#include <linux/device.h>
54#include <linux/dmapool.h>
55#include <linux/dma-mapping.h> 54#include <linux/dma-mapping.h>
56#include <linux/init.h>
57#include <linux/platform_device.h> 55#include <linux/platform_device.h>
58#include <linux/module.h> 56#include <linux/module.h>
59#include <linux/idr.h> 57#include <linux/idr.h>
60#include <linux/interrupt.h> 58#include <linux/interrupt.h>
61#include <linux/io.h> 59#include <linux/io.h>
62#include <linux/irq.h>
63#include <linux/kernel.h> 60#include <linux/kernel.h>
64#include <linux/slab.h> 61#include <linux/slab.h>
65#include <linux/pm_runtime.h> 62#include <linux/pm_runtime.h>
@@ -158,7 +155,7 @@ int hw_port_test_set(struct ci13xxx *ci, u8 mode)
158 if (mode > TEST_MODE_MAX) 155 if (mode > TEST_MODE_MAX)
159 return -EINVAL; 156 return -EINVAL;
160 157
161 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << ffs_nr(PORTSC_PTC)); 158 hw_write(ci, OP_PORTSC, PORTSC_PTC, mode << __ffs(PORTSC_PTC));
162 return 0; 159 return 0;
163} 160}
164 161
@@ -169,7 +166,7 @@ int hw_port_test_set(struct ci13xxx *ci, u8 mode)
169 */ 166 */
170u8 hw_port_test_get(struct ci13xxx *ci) 167u8 hw_port_test_get(struct ci13xxx *ci)
171{ 168{
172 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> ffs_nr(PORTSC_PTC); 169 return hw_read(ci, OP_PORTSC, PORTSC_PTC) >> __ffs(PORTSC_PTC);
173} 170}
174 171
175static int hw_device_init(struct ci13xxx *ci, void __iomem *base) 172static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
@@ -181,11 +178,11 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
181 178
182 ci->hw_bank.cap = ci->hw_bank.abs; 179 ci->hw_bank.cap = ci->hw_bank.abs;
183 ci->hw_bank.cap += ci->platdata->capoffset; 180 ci->hw_bank.cap += ci->platdata->capoffset;
184 ci->hw_bank.op = ci->hw_bank.cap + ioread8(ci->hw_bank.cap); 181 ci->hw_bank.op = ci->hw_bank.cap + (ioread32(ci->hw_bank.cap) & 0xff);
185 182
186 hw_alloc_regmap(ci, false); 183 hw_alloc_regmap(ci, false);
187 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >> 184 reg = hw_read(ci, CAP_HCCPARAMS, HCCPARAMS_LEN) >>
188 ffs_nr(HCCPARAMS_LEN); 185 __ffs(HCCPARAMS_LEN);
189 ci->hw_bank.lpm = reg; 186 ci->hw_bank.lpm = reg;
190 hw_alloc_regmap(ci, !!reg); 187 hw_alloc_regmap(ci, !!reg);
191 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs; 188 ci->hw_bank.size = ci->hw_bank.op - ci->hw_bank.abs;
@@ -193,7 +190,7 @@ static int hw_device_init(struct ci13xxx *ci, void __iomem *base)
193 ci->hw_bank.size /= sizeof(u32); 190 ci->hw_bank.size /= sizeof(u32);
194 191
195 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >> 192 reg = hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DEN) >>
196 ffs_nr(DCCPARAMS_DEN); 193 __ffs(DCCPARAMS_DEN);
197 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */ 194 ci->hw_ep_max = reg * 2; /* cache hw ENDPT_MAX */
198 195
199 if (ci->hw_ep_max > ENDPT_MAX) 196 if (ci->hw_ep_max > ENDPT_MAX)
@@ -283,38 +280,6 @@ static void ci_role_work(struct work_struct *work)
283 } 280 }
284} 281}
285 282
286static ssize_t show_role(struct device *dev, struct device_attribute *attr,
287 char *buf)
288{
289 struct ci13xxx *ci = dev_get_drvdata(dev);
290
291 return sprintf(buf, "%s\n", ci_role(ci)->name);
292}
293
294static ssize_t store_role(struct device *dev, struct device_attribute *attr,
295 const char *buf, size_t count)
296{
297 struct ci13xxx *ci = dev_get_drvdata(dev);
298 enum ci_role role;
299 int ret;
300
301 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
302 if (ci->roles[role] && !strcmp(buf, ci->roles[role]->name))
303 break;
304
305 if (role == CI_ROLE_END || role == ci->role)
306 return -EINVAL;
307
308 ci_role_stop(ci);
309 ret = ci_role_start(ci, role);
310 if (ret)
311 return ret;
312
313 return count;
314}
315
316static DEVICE_ATTR(role, S_IRUSR | S_IWUSR, show_role, store_role);
317
318static irqreturn_t ci_irq(int irq, void *data) 283static irqreturn_t ci_irq(int irq, void *data)
319{ 284{
320 struct ci13xxx *ci = data; 285 struct ci13xxx *ci = data;
@@ -410,11 +375,9 @@ static int ci_hdrc_probe(struct platform_device *pdev)
410 return -ENODEV; 375 return -ENODEV;
411 } 376 }
412 377
413 base = devm_request_and_ioremap(dev, res); 378 base = devm_ioremap_resource(dev, res);
414 if (!base) { 379 if (IS_ERR(base))
415 dev_err(dev, "can't request and ioremap resource\n"); 380 return PTR_ERR(base);
416 return -ENOMEM;
417 }
418 381
419 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL); 382 ci = devm_kzalloc(dev, sizeof(*ci), GFP_KERNEL);
420 if (!ci) { 383 if (!ci) {
@@ -489,17 +452,14 @@ static int ci_hdrc_probe(struct platform_device *pdev)
489 if (ret) 452 if (ret)
490 goto stop; 453 goto stop;
491 454
492 ret = device_create_file(dev, &dev_attr_role);
493 if (ret)
494 goto rm_attr;
495
496 if (ci->is_otg) 455 if (ci->is_otg)
497 hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE); 456 hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE);
498 457
499 return ret; 458 ret = dbg_create_files(ci);
459 if (!ret)
460 return 0;
500 461
501rm_attr: 462 free_irq(ci->irq, ci);
502 device_remove_file(dev, &dev_attr_role);
503stop: 463stop:
504 ci_role_stop(ci); 464 ci_role_stop(ci);
505rm_wq: 465rm_wq:
@@ -513,9 +473,9 @@ static int ci_hdrc_remove(struct platform_device *pdev)
513{ 473{
514 struct ci13xxx *ci = platform_get_drvdata(pdev); 474 struct ci13xxx *ci = platform_get_drvdata(pdev);
515 475
476 dbg_remove_files(ci);
516 flush_workqueue(ci->wq); 477 flush_workqueue(ci->wq);
517 destroy_workqueue(ci->wq); 478 destroy_workqueue(ci->wq);
518 device_remove_file(ci->dev, &dev_attr_role);
519 free_irq(ci->irq, ci); 479 free_irq(ci->irq, ci);
520 ci_role_stop(ci); 480 ci_role_stop(ci);
521 481
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c
index a62c4a47d52c..36a7063a6cba 100644
--- a/drivers/usb/chipidea/debug.c
+++ b/drivers/usb/chipidea/debug.c
@@ -1,590 +1,126 @@
1#include <linux/delay.h>
2#include <linux/device.h>
3#include <linux/dmapool.h>
4#include <linux/dma-mapping.h>
5#include <linux/init.h>
6#include <linux/platform_device.h>
7#include <linux/module.h>
8#include <linux/interrupt.h>
9#include <linux/io.h>
10#include <linux/irq.h>
11#include <linux/kernel.h> 1#include <linux/kernel.h>
12#include <linux/slab.h> 2#include <linux/device.h>
13#include <linux/pm_runtime.h> 3#include <linux/types.h>
4#include <linux/spinlock.h>
5#include <linux/debugfs.h>
6#include <linux/seq_file.h>
7#include <linux/uaccess.h>
14#include <linux/usb/ch9.h> 8#include <linux/usb/ch9.h>
15#include <linux/usb/gadget.h> 9#include <linux/usb/gadget.h>
16#include <linux/usb/otg.h>
17#include <linux/usb/chipidea.h>
18 10
19#include "ci.h" 11#include "ci.h"
20#include "udc.h" 12#include "udc.h"
21#include "bits.h" 13#include "bits.h"
22#include "debug.h" 14#include "debug.h"
23 15
24/* Interrupt statistics */
25#define ISR_MASK 0x1F
26static struct isr_statistics {
27 u32 test;
28 u32 ui;
29 u32 uei;
30 u32 pci;
31 u32 uri;
32 u32 sli;
33 u32 none;
34 struct {
35 u32 cnt;
36 u32 buf[ISR_MASK+1];
37 u32 idx;
38 } hndl;
39} isr_statistics;
40
41void dbg_interrupt(u32 intmask)
42{
43 if (!intmask) {
44 isr_statistics.none++;
45 return;
46 }
47
48 isr_statistics.hndl.buf[isr_statistics.hndl.idx++] = intmask;
49 isr_statistics.hndl.idx &= ISR_MASK;
50 isr_statistics.hndl.cnt++;
51
52 if (USBi_URI & intmask)
53 isr_statistics.uri++;
54 if (USBi_PCI & intmask)
55 isr_statistics.pci++;
56 if (USBi_UEI & intmask)
57 isr_statistics.uei++;
58 if (USBi_UI & intmask)
59 isr_statistics.ui++;
60 if (USBi_SLI & intmask)
61 isr_statistics.sli++;
62}
63
64/** 16/**
65 * hw_register_read: reads all device registers (execute without interruption) 17 * ci_device_show: prints information about device capabilities and status
66 * @buf: destination buffer
67 * @size: buffer size
68 *
69 * This function returns number of registers read
70 */ 18 */
71static size_t hw_register_read(struct ci13xxx *ci, u32 *buf, size_t size) 19static int ci_device_show(struct seq_file *s, void *data)
72{ 20{
73 unsigned i; 21 struct ci13xxx *ci = s->private;
74
75 if (size > ci->hw_bank.size)
76 size = ci->hw_bank.size;
77
78 for (i = 0; i < size; i++)
79 buf[i] = hw_read(ci, i * sizeof(u32), ~0);
80
81 return size;
82}
83
84/**
85 * hw_register_write: writes to register
86 * @addr: register address
87 * @data: register value
88 *
89 * This function returns an error code
90 */
91static int hw_register_write(struct ci13xxx *ci, u16 addr, u32 data)
92{
93 /* align */
94 addr /= sizeof(u32);
95
96 if (addr >= ci->hw_bank.size)
97 return -EINVAL;
98
99 /* align */
100 addr *= sizeof(u32);
101
102 hw_write(ci, addr, ~0, data);
103 return 0;
104}
105
106/**
107 * hw_intr_clear: disables interrupt & clears interrupt status (execute without
108 * interruption)
109 * @n: interrupt bit
110 *
111 * This function returns an error code
112 */
113static int hw_intr_clear(struct ci13xxx *ci, int n)
114{
115 if (n >= REG_BITS)
116 return -EINVAL;
117
118 hw_write(ci, OP_USBINTR, BIT(n), 0);
119 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
120 return 0;
121}
122
123/**
124 * hw_intr_force: enables interrupt & forces interrupt status (execute without
125 * interruption)
126 * @n: interrupt bit
127 *
128 * This function returns an error code
129 */
130static int hw_intr_force(struct ci13xxx *ci, int n)
131{
132 if (n >= REG_BITS)
133 return -EINVAL;
134
135 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, TESTMODE_FORCE);
136 hw_write(ci, OP_USBINTR, BIT(n), BIT(n));
137 hw_write(ci, OP_USBSTS, BIT(n), BIT(n));
138 hw_write(ci, CAP_TESTMODE, TESTMODE_FORCE, 0);
139 return 0;
140}
141
142/**
143 * show_device: prints information about device capabilities and status
144 *
145 * Check "device.h" for details
146 */
147static ssize_t show_device(struct device *dev, struct device_attribute *attr,
148 char *buf)
149{
150 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
151 struct usb_gadget *gadget = &ci->gadget; 22 struct usb_gadget *gadget = &ci->gadget;
152 int n = 0;
153 23
154 if (attr == NULL || buf == NULL) { 24 seq_printf(s, "speed = %d\n", gadget->speed);
155 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 25 seq_printf(s, "max_speed = %d\n", gadget->max_speed);
26 seq_printf(s, "is_otg = %d\n", gadget->is_otg);
27 seq_printf(s, "is_a_peripheral = %d\n", gadget->is_a_peripheral);
28 seq_printf(s, "b_hnp_enable = %d\n", gadget->b_hnp_enable);
29 seq_printf(s, "a_hnp_support = %d\n", gadget->a_hnp_support);
30 seq_printf(s, "a_alt_hnp_support = %d\n", gadget->a_alt_hnp_support);
31 seq_printf(s, "name = %s\n",
32 (gadget->name ? gadget->name : ""));
33
34 if (!ci->driver)
156 return 0; 35 return 0;
157 }
158
159 n += scnprintf(buf + n, PAGE_SIZE - n, "speed = %d\n",
160 gadget->speed);
161 n += scnprintf(buf + n, PAGE_SIZE - n, "max_speed = %d\n",
162 gadget->max_speed);
163 n += scnprintf(buf + n, PAGE_SIZE - n, "is_otg = %d\n",
164 gadget->is_otg);
165 n += scnprintf(buf + n, PAGE_SIZE - n, "is_a_peripheral = %d\n",
166 gadget->is_a_peripheral);
167 n += scnprintf(buf + n, PAGE_SIZE - n, "b_hnp_enable = %d\n",
168 gadget->b_hnp_enable);
169 n += scnprintf(buf + n, PAGE_SIZE - n, "a_hnp_support = %d\n",
170 gadget->a_hnp_support);
171 n += scnprintf(buf + n, PAGE_SIZE - n, "a_alt_hnp_support = %d\n",
172 gadget->a_alt_hnp_support);
173 n += scnprintf(buf + n, PAGE_SIZE - n, "name = %s\n",
174 (gadget->name ? gadget->name : ""));
175
176 return n;
177}
178static DEVICE_ATTR(device, S_IRUSR, show_device, NULL);
179
180/**
181 * show_driver: prints information about attached gadget (if any)
182 *
183 * Check "device.h" for details
184 */
185static ssize_t show_driver(struct device *dev, struct device_attribute *attr,
186 char *buf)
187{
188 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
189 struct usb_gadget_driver *driver = ci->driver;
190 int n = 0;
191
192 if (attr == NULL || buf == NULL) {
193 dev_err(dev, "[%s] EINVAL\n", __func__);
194 return 0;
195 }
196
197 if (driver == NULL)
198 return scnprintf(buf, PAGE_SIZE,
199 "There is no gadget attached!\n");
200 36
201 n += scnprintf(buf + n, PAGE_SIZE - n, "function = %s\n", 37 seq_printf(s, "gadget function = %s\n",
202 (driver->function ? driver->function : "")); 38 (ci->driver->function ? ci->driver->function : ""));
203 n += scnprintf(buf + n, PAGE_SIZE - n, "max speed = %d\n", 39 seq_printf(s, "gadget max speed = %d\n", ci->driver->max_speed);
204 driver->max_speed);
205 40
206 return n; 41 return 0;
207}
208static DEVICE_ATTR(driver, S_IRUSR, show_driver, NULL);
209
210/* Maximum event message length */
211#define DBG_DATA_MSG 64UL
212
213/* Maximum event messages */
214#define DBG_DATA_MAX 128UL
215
216/* Event buffer descriptor */
217static struct {
218 char (buf[DBG_DATA_MAX])[DBG_DATA_MSG]; /* buffer */
219 unsigned idx; /* index */
220 unsigned tty; /* print to console? */
221 rwlock_t lck; /* lock */
222} dbg_data = {
223 .idx = 0,
224 .tty = 0,
225 .lck = __RW_LOCK_UNLOCKED(dbg_data.lck)
226};
227
228/**
229 * dbg_dec: decrements debug event index
230 * @idx: buffer index
231 */
232static void dbg_dec(unsigned *idx)
233{
234 *idx = (*idx - 1) & (DBG_DATA_MAX-1);
235}
236
237/**
238 * dbg_inc: increments debug event index
239 * @idx: buffer index
240 */
241static void dbg_inc(unsigned *idx)
242{
243 *idx = (*idx + 1) & (DBG_DATA_MAX-1);
244}
245
246/**
247 * dbg_print: prints the common part of the event
248 * @addr: endpoint address
249 * @name: event name
250 * @status: status
251 * @extra: extra information
252 */
253static void dbg_print(u8 addr, const char *name, int status, const char *extra)
254{
255 struct timeval tval;
256 unsigned int stamp;
257 unsigned long flags;
258
259 write_lock_irqsave(&dbg_data.lck, flags);
260
261 do_gettimeofday(&tval);
262 stamp = tval.tv_sec & 0xFFFF; /* 2^32 = 4294967296. Limit to 4096s */
263 stamp = stamp * 1000000 + tval.tv_usec;
264
265 scnprintf(dbg_data.buf[dbg_data.idx], DBG_DATA_MSG,
266 "%04X\t? %02X %-7.7s %4i ?\t%s\n",
267 stamp, addr, name, status, extra);
268
269 dbg_inc(&dbg_data.idx);
270
271 write_unlock_irqrestore(&dbg_data.lck, flags);
272
273 if (dbg_data.tty != 0)
274 pr_notice("%04X\t? %02X %-7.7s %4i ?\t%s\n",
275 stamp, addr, name, status, extra);
276}
277
278/**
279 * dbg_done: prints a DONE event
280 * @addr: endpoint address
281 * @td: transfer descriptor
282 * @status: status
283 */
284void dbg_done(u8 addr, const u32 token, int status)
285{
286 char msg[DBG_DATA_MSG];
287
288 scnprintf(msg, sizeof(msg), "%d %02X",
289 (int)(token & TD_TOTAL_BYTES) >> ffs_nr(TD_TOTAL_BYTES),
290 (int)(token & TD_STATUS) >> ffs_nr(TD_STATUS));
291 dbg_print(addr, "DONE", status, msg);
292}
293
294/**
295 * dbg_event: prints a generic event
296 * @addr: endpoint address
297 * @name: event name
298 * @status: status
299 */
300void dbg_event(u8 addr, const char *name, int status)
301{
302 if (name != NULL)
303 dbg_print(addr, name, status, "");
304}
305
306/*
307 * dbg_queue: prints a QUEUE event
308 * @addr: endpoint address
309 * @req: USB request
310 * @status: status
311 */
312void dbg_queue(u8 addr, const struct usb_request *req, int status)
313{
314 char msg[DBG_DATA_MSG];
315
316 if (req != NULL) {
317 scnprintf(msg, sizeof(msg),
318 "%d %d", !req->no_interrupt, req->length);
319 dbg_print(addr, "QUEUE", status, msg);
320 }
321}
322
323/**
324 * dbg_setup: prints a SETUP event
325 * @addr: endpoint address
326 * @req: setup request
327 */
328void dbg_setup(u8 addr, const struct usb_ctrlrequest *req)
329{
330 char msg[DBG_DATA_MSG];
331
332 if (req != NULL) {
333 scnprintf(msg, sizeof(msg),
334 "%02X %02X %04X %04X %d", req->bRequestType,
335 req->bRequest, le16_to_cpu(req->wValue),
336 le16_to_cpu(req->wIndex), le16_to_cpu(req->wLength));
337 dbg_print(addr, "SETUP", 0, msg);
338 }
339} 42}
340 43
341/** 44static int ci_device_open(struct inode *inode, struct file *file)
342 * show_events: displays the event buffer
343 *
344 * Check "device.h" for details
345 */
346static ssize_t show_events(struct device *dev, struct device_attribute *attr,
347 char *buf)
348{ 45{
349 unsigned long flags; 46 return single_open(file, ci_device_show, inode->i_private);
350 unsigned i, j, n = 0;
351
352 if (attr == NULL || buf == NULL) {
353 dev_err(dev->parent, "[%s] EINVAL\n", __func__);
354 return 0;
355 }
356
357 read_lock_irqsave(&dbg_data.lck, flags);
358
359 i = dbg_data.idx;
360 for (dbg_dec(&i); i != dbg_data.idx; dbg_dec(&i)) {
361 n += strlen(dbg_data.buf[i]);
362 if (n >= PAGE_SIZE) {
363 n -= strlen(dbg_data.buf[i]);
364 break;
365 }
366 }
367 for (j = 0, dbg_inc(&i); j < n; dbg_inc(&i))
368 j += scnprintf(buf + j, PAGE_SIZE - j,
369 "%s", dbg_data.buf[i]);
370
371 read_unlock_irqrestore(&dbg_data.lck, flags);
372
373 return n;
374} 47}
375 48
376/** 49static const struct file_operations ci_device_fops = {
377 * store_events: configure if events are going to be also printed to console 50 .open = ci_device_open,
378 * 51 .read = seq_read,
379 * Check "device.h" for details 52 .llseek = seq_lseek,
380 */ 53 .release = single_release,
381static ssize_t store_events(struct device *dev, struct device_attribute *attr, 54};
382 const char *buf, size_t count)
383{
384 unsigned tty;
385
386 if (attr == NULL || buf == NULL) {
387 dev_err(dev, "[%s] EINVAL\n", __func__);
388 goto done;
389 }
390
391 if (sscanf(buf, "%u", &tty) != 1 || tty > 1) {
392 dev_err(dev, "<1|0>: enable|disable console log\n");
393 goto done;
394 }
395
396 dbg_data.tty = tty;
397 dev_info(dev, "tty = %u", dbg_data.tty);
398
399 done:
400 return count;
401}
402static DEVICE_ATTR(events, S_IRUSR | S_IWUSR, show_events, store_events);
403 55
404/** 56/**
405 * show_inters: interrupt status, enable status and historic 57 * ci_port_test_show: reads port test mode
406 *
407 * Check "device.h" for details
408 */ 58 */
409static ssize_t show_inters(struct device *dev, struct device_attribute *attr, 59static int ci_port_test_show(struct seq_file *s, void *data)
410 char *buf)
411{ 60{
412 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 61 struct ci13xxx *ci = s->private;
413 unsigned long flags; 62 unsigned long flags;
414 u32 intr; 63 unsigned mode;
415 unsigned i, j, n = 0;
416
417 if (attr == NULL || buf == NULL) {
418 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
419 return 0;
420 }
421 64
422 spin_lock_irqsave(&ci->lock, flags); 65 spin_lock_irqsave(&ci->lock, flags);
423 66 mode = hw_port_test_get(ci);
424 /*n += scnprintf(buf + n, PAGE_SIZE - n,
425 "status = %08x\n", hw_read_intr_status(ci));
426 n += scnprintf(buf + n, PAGE_SIZE - n,
427 "enable = %08x\n", hw_read_intr_enable(ci));*/
428
429 n += scnprintf(buf + n, PAGE_SIZE - n, "*test = %d\n",
430 isr_statistics.test);
431 n += scnprintf(buf + n, PAGE_SIZE - n, "? ui = %d\n",
432 isr_statistics.ui);
433 n += scnprintf(buf + n, PAGE_SIZE - n, "? uei = %d\n",
434 isr_statistics.uei);
435 n += scnprintf(buf + n, PAGE_SIZE - n, "? pci = %d\n",
436 isr_statistics.pci);
437 n += scnprintf(buf + n, PAGE_SIZE - n, "? uri = %d\n",
438 isr_statistics.uri);
439 n += scnprintf(buf + n, PAGE_SIZE - n, "? sli = %d\n",
440 isr_statistics.sli);
441 n += scnprintf(buf + n, PAGE_SIZE - n, "*none = %d\n",
442 isr_statistics.none);
443 n += scnprintf(buf + n, PAGE_SIZE - n, "*hndl = %d\n",
444 isr_statistics.hndl.cnt);
445
446 for (i = isr_statistics.hndl.idx, j = 0; j <= ISR_MASK; j++, i++) {
447 i &= ISR_MASK;
448 intr = isr_statistics.hndl.buf[i];
449
450 if (USBi_UI & intr)
451 n += scnprintf(buf + n, PAGE_SIZE - n, "ui ");
452 intr &= ~USBi_UI;
453 if (USBi_UEI & intr)
454 n += scnprintf(buf + n, PAGE_SIZE - n, "uei ");
455 intr &= ~USBi_UEI;
456 if (USBi_PCI & intr)
457 n += scnprintf(buf + n, PAGE_SIZE - n, "pci ");
458 intr &= ~USBi_PCI;
459 if (USBi_URI & intr)
460 n += scnprintf(buf + n, PAGE_SIZE - n, "uri ");
461 intr &= ~USBi_URI;
462 if (USBi_SLI & intr)
463 n += scnprintf(buf + n, PAGE_SIZE - n, "sli ");
464 intr &= ~USBi_SLI;
465 if (intr)
466 n += scnprintf(buf + n, PAGE_SIZE - n, "??? ");
467 if (isr_statistics.hndl.buf[i])
468 n += scnprintf(buf + n, PAGE_SIZE - n, "\n");
469 }
470
471 spin_unlock_irqrestore(&ci->lock, flags); 67 spin_unlock_irqrestore(&ci->lock, flags);
472 68
473 return n; 69 seq_printf(s, "mode = %u\n", mode);
474}
475
476/**
477 * store_inters: enable & force or disable an individual interrutps
478 * (to be used for test purposes only)
479 *
480 * Check "device.h" for details
481 */
482static ssize_t store_inters(struct device *dev, struct device_attribute *attr,
483 const char *buf, size_t count)
484{
485 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev);
486 unsigned long flags;
487 unsigned en, bit;
488
489 if (attr == NULL || buf == NULL) {
490 dev_err(ci->dev, "EINVAL\n");
491 goto done;
492 }
493 70
494 if (sscanf(buf, "%u %u", &en, &bit) != 2 || en > 1) { 71 return 0;
495 dev_err(ci->dev, "<1|0> <bit>: enable|disable interrupt\n");
496 goto done;
497 }
498
499 spin_lock_irqsave(&ci->lock, flags);
500 if (en) {
501 if (hw_intr_force(ci, bit))
502 dev_err(dev, "invalid bit number\n");
503 else
504 isr_statistics.test++;
505 } else {
506 if (hw_intr_clear(ci, bit))
507 dev_err(dev, "invalid bit number\n");
508 }
509 spin_unlock_irqrestore(&ci->lock, flags);
510
511 done:
512 return count;
513} 72}
514static DEVICE_ATTR(inters, S_IRUSR | S_IWUSR, show_inters, store_inters);
515 73
516/** 74/**
517 * show_port_test: reads port test mode 75 * ci_port_test_write: writes port test mode
518 *
519 * Check "device.h" for details
520 */ 76 */
521static ssize_t show_port_test(struct device *dev, 77static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf,
522 struct device_attribute *attr, char *buf) 78 size_t count, loff_t *ppos)
523{ 79{
524 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 80 struct seq_file *s = file->private_data;
81 struct ci13xxx *ci = s->private;
525 unsigned long flags; 82 unsigned long flags;
526 unsigned mode; 83 unsigned mode;
84 char buf[32];
85 int ret;
527 86
528 if (attr == NULL || buf == NULL) { 87 if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
529 dev_err(ci->dev, "EINVAL\n"); 88 return -EFAULT;
530 return 0; 89
531 } 90 if (sscanf(buf, "%u", &mode) != 1)
91 return -EINVAL;
532 92
533 spin_lock_irqsave(&ci->lock, flags); 93 spin_lock_irqsave(&ci->lock, flags);
534 mode = hw_port_test_get(ci); 94 ret = hw_port_test_set(ci, mode);
535 spin_unlock_irqrestore(&ci->lock, flags); 95 spin_unlock_irqrestore(&ci->lock, flags);
536 96
537 return scnprintf(buf, PAGE_SIZE, "mode = %u\n", mode); 97 return ret ? ret : count;
538} 98}
539 99
540/** 100static int ci_port_test_open(struct inode *inode, struct file *file)
541 * store_port_test: writes port test mode
542 *
543 * Check "device.h" for details
544 */
545static ssize_t store_port_test(struct device *dev,
546 struct device_attribute *attr,
547 const char *buf, size_t count)
548{ 101{
549 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 102 return single_open(file, ci_port_test_show, inode->i_private);
550 unsigned long flags;
551 unsigned mode;
552
553 if (attr == NULL || buf == NULL) {
554 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
555 goto done;
556 }
557
558 if (sscanf(buf, "%u", &mode) != 1) {
559 dev_err(ci->dev, "<mode>: set port test mode");
560 goto done;
561 }
562
563 spin_lock_irqsave(&ci->lock, flags);
564 if (hw_port_test_set(ci, mode))
565 dev_err(ci->dev, "invalid mode\n");
566 spin_unlock_irqrestore(&ci->lock, flags);
567
568 done:
569 return count;
570} 103}
571static DEVICE_ATTR(port_test, S_IRUSR | S_IWUSR, 104
572 show_port_test, store_port_test); 105static const struct file_operations ci_port_test_fops = {
106 .open = ci_port_test_open,
107 .write = ci_port_test_write,
108 .read = seq_read,
109 .llseek = seq_lseek,
110 .release = single_release,
111};
573 112
574/** 113/**
575 * show_qheads: DMA contents of all queue heads 114 * ci_qheads_show: DMA contents of all queue heads
576 *
577 * Check "device.h" for details
578 */ 115 */
579static ssize_t show_qheads(struct device *dev, struct device_attribute *attr, 116static int ci_qheads_show(struct seq_file *s, void *data)
580 char *buf)
581{ 117{
582 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 118 struct ci13xxx *ci = s->private;
583 unsigned long flags; 119 unsigned long flags;
584 unsigned i, j, n = 0; 120 unsigned i, j;
585 121
586 if (attr == NULL || buf == NULL) { 122 if (ci->role != CI_ROLE_GADGET) {
587 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 123 seq_printf(s, "not in gadget mode\n");
588 return 0; 124 return 0;
589 } 125 }
590 126
@@ -593,209 +129,173 @@ static ssize_t show_qheads(struct device *dev, struct device_attribute *attr,
593 struct ci13xxx_ep *mEpRx = &ci->ci13xxx_ep[i]; 129 struct ci13xxx_ep *mEpRx = &ci->ci13xxx_ep[i];
594 struct ci13xxx_ep *mEpTx = 130 struct ci13xxx_ep *mEpTx =
595 &ci->ci13xxx_ep[i + ci->hw_ep_max/2]; 131 &ci->ci13xxx_ep[i + ci->hw_ep_max/2];
596 n += scnprintf(buf + n, PAGE_SIZE - n, 132 seq_printf(s, "EP=%02i: RX=%08X TX=%08X\n",
597 "EP=%02i: RX=%08X TX=%08X\n", 133 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma);
598 i, (u32)mEpRx->qh.dma, (u32)mEpTx->qh.dma); 134 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++)
599 for (j = 0; j < (sizeof(struct ci13xxx_qh)/sizeof(u32)); j++) { 135 seq_printf(s, " %04X: %08X %08X\n", j,
600 n += scnprintf(buf + n, PAGE_SIZE - n, 136 *((u32 *)mEpRx->qh.ptr + j),
601 " %04X: %08X %08X\n", j, 137 *((u32 *)mEpTx->qh.ptr + j));
602 *((u32 *)mEpRx->qh.ptr + j),
603 *((u32 *)mEpTx->qh.ptr + j));
604 }
605 } 138 }
606 spin_unlock_irqrestore(&ci->lock, flags); 139 spin_unlock_irqrestore(&ci->lock, flags);
607 140
608 return n; 141 return 0;
142}
143
144static int ci_qheads_open(struct inode *inode, struct file *file)
145{
146 return single_open(file, ci_qheads_show, inode->i_private);
609} 147}
610static DEVICE_ATTR(qheads, S_IRUSR, show_qheads, NULL); 148
149static const struct file_operations ci_qheads_fops = {
150 .open = ci_qheads_open,
151 .read = seq_read,
152 .llseek = seq_lseek,
153 .release = single_release,
154};
611 155
612/** 156/**
613 * show_registers: dumps all registers 157 * ci_requests_show: DMA contents of all requests currently queued (all endpts)
614 *
615 * Check "device.h" for details
616 */ 158 */
617#define DUMP_ENTRIES 512 159static int ci_requests_show(struct seq_file *s, void *data)
618static ssize_t show_registers(struct device *dev,
619 struct device_attribute *attr, char *buf)
620{ 160{
621 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 161 struct ci13xxx *ci = s->private;
622 unsigned long flags; 162 unsigned long flags;
623 u32 *dump; 163 struct list_head *ptr = NULL;
624 unsigned i, k, n = 0; 164 struct ci13xxx_req *req = NULL;
625 165 unsigned i, j, qsize = sizeof(struct ci13xxx_td)/sizeof(u32);
626 if (attr == NULL || buf == NULL) {
627 dev_err(ci->dev, "[%s] EINVAL\n", __func__);
628 return 0;
629 }
630 166
631 dump = kmalloc(sizeof(u32) * DUMP_ENTRIES, GFP_KERNEL); 167 if (ci->role != CI_ROLE_GADGET) {
632 if (!dump) { 168 seq_printf(s, "not in gadget mode\n");
633 dev_err(ci->dev, "%s: out of memory\n", __func__);
634 return 0; 169 return 0;
635 } 170 }
636 171
637 spin_lock_irqsave(&ci->lock, flags); 172 spin_lock_irqsave(&ci->lock, flags);
638 k = hw_register_read(ci, dump, DUMP_ENTRIES); 173 for (i = 0; i < ci->hw_ep_max; i++)
639 spin_unlock_irqrestore(&ci->lock, flags); 174 list_for_each(ptr, &ci->ci13xxx_ep[i].qh.queue) {
175 req = list_entry(ptr, struct ci13xxx_req, queue);
640 176
641 for (i = 0; i < k; i++) { 177 seq_printf(s, "EP=%02i: TD=%08X %s\n",
642 n += scnprintf(buf + n, PAGE_SIZE - n, 178 i % (ci->hw_ep_max / 2), (u32)req->dma,
643 "reg[0x%04X] = 0x%08X\n", 179 ((i < ci->hw_ep_max/2) ? "RX" : "TX"));
644 i * (unsigned)sizeof(u32), dump[i]); 180
645 } 181 for (j = 0; j < qsize; j++)
646 kfree(dump); 182 seq_printf(s, " %04X: %08X\n", j,
183 *((u32 *)req->ptr + j));
184 }
185 spin_unlock_irqrestore(&ci->lock, flags);
647 186
648 return n; 187 return 0;
649} 188}
650 189
651/** 190static int ci_requests_open(struct inode *inode, struct file *file)
652 * store_registers: writes value to register address
653 *
654 * Check "device.h" for details
655 */
656static ssize_t store_registers(struct device *dev,
657 struct device_attribute *attr,
658 const char *buf, size_t count)
659{ 191{
660 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 192 return single_open(file, ci_requests_show, inode->i_private);
661 unsigned long addr, data, flags; 193}
662 194
663 if (attr == NULL || buf == NULL) { 195static const struct file_operations ci_requests_fops = {
664 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 196 .open = ci_requests_open,
665 goto done; 197 .read = seq_read,
666 } 198 .llseek = seq_lseek,
199 .release = single_release,
200};
667 201
668 if (sscanf(buf, "%li %li", &addr, &data) != 2) { 202static int ci_role_show(struct seq_file *s, void *data)
669 dev_err(ci->dev, 203{
670 "<addr> <data>: write data to register address\n"); 204 struct ci13xxx *ci = s->private;
671 goto done;
672 }
673 205
674 spin_lock_irqsave(&ci->lock, flags); 206 seq_printf(s, "%s\n", ci_role(ci)->name);
675 if (hw_register_write(ci, addr, data))
676 dev_err(ci->dev, "invalid address range\n");
677 spin_unlock_irqrestore(&ci->lock, flags);
678 207
679 done: 208 return 0;
680 return count;
681} 209}
682static DEVICE_ATTR(registers, S_IRUSR | S_IWUSR,
683 show_registers, store_registers);
684 210
685/** 211static ssize_t ci_role_write(struct file *file, const char __user *ubuf,
686 * show_requests: DMA contents of all requests currently queued (all endpts) 212 size_t count, loff_t *ppos)
687 *
688 * Check "device.h" for details
689 */
690static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
691 char *buf)
692{ 213{
693 struct ci13xxx *ci = container_of(dev, struct ci13xxx, gadget.dev); 214 struct seq_file *s = file->private_data;
694 unsigned long flags; 215 struct ci13xxx *ci = s->private;
695 struct list_head *ptr = NULL; 216 enum ci_role role;
696 struct ci13xxx_req *req = NULL; 217 char buf[8];
697 unsigned i, j, n = 0, qSize = sizeof(struct ci13xxx_td)/sizeof(u32); 218 int ret;
698 219
699 if (attr == NULL || buf == NULL) { 220 if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
700 dev_err(ci->dev, "[%s] EINVAL\n", __func__); 221 return -EFAULT;
701 return 0; 222
702 } 223 for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
224 if (ci->roles[role] &&
225 !strncmp(buf, ci->roles[role]->name,
226 strlen(ci->roles[role]->name)))
227 break;
703 228
704 spin_lock_irqsave(&ci->lock, flags); 229 if (role == CI_ROLE_END || role == ci->role)
705 for (i = 0; i < ci->hw_ep_max; i++) 230 return -EINVAL;
706 list_for_each(ptr, &ci->ci13xxx_ep[i].qh.queue)
707 {
708 req = list_entry(ptr, struct ci13xxx_req, queue);
709 231
710 n += scnprintf(buf + n, PAGE_SIZE - n, 232 ci_role_stop(ci);
711 "EP=%02i: TD=%08X %s\n", 233 ret = ci_role_start(ci, role);
712 i % ci->hw_ep_max/2, (u32)req->dma,
713 ((i < ci->hw_ep_max/2) ? "RX" : "TX"));
714 234
715 for (j = 0; j < qSize; j++) 235 return ret ? ret : count;
716 n += scnprintf(buf + n, PAGE_SIZE - n, 236}
717 " %04X: %08X\n", j,
718 *((u32 *)req->ptr + j));
719 }
720 spin_unlock_irqrestore(&ci->lock, flags);
721 237
722 return n; 238static int ci_role_open(struct inode *inode, struct file *file)
239{
240 return single_open(file, ci_role_show, inode->i_private);
723} 241}
724static DEVICE_ATTR(requests, S_IRUSR, show_requests, NULL); 242
243static const struct file_operations ci_role_fops = {
244 .open = ci_role_open,
245 .write = ci_role_write,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = single_release,
249};
725 250
726/** 251/**
727 * dbg_create_files: initializes the attribute interface 252 * dbg_create_files: initializes the attribute interface
728 * @dev: device 253 * @ci: device
729 * 254 *
730 * This function returns an error code 255 * This function returns an error code
731 */ 256 */
732int dbg_create_files(struct device *dev) 257int dbg_create_files(struct ci13xxx *ci)
733{ 258{
734 int retval = 0; 259 struct dentry *dent;
735 260
736 if (dev == NULL) 261 ci->debugfs = debugfs_create_dir(dev_name(ci->dev), NULL);
737 return -EINVAL; 262 if (!ci->debugfs)
738 retval = device_create_file(dev, &dev_attr_device); 263 return -ENOMEM;
739 if (retval) 264
740 goto done; 265 dent = debugfs_create_file("device", S_IRUGO, ci->debugfs, ci,
741 retval = device_create_file(dev, &dev_attr_driver); 266 &ci_device_fops);
742 if (retval) 267 if (!dent)
743 goto rm_device; 268 goto err;
744 retval = device_create_file(dev, &dev_attr_events); 269
745 if (retval) 270 dent = debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs,
746 goto rm_driver; 271 ci, &ci_port_test_fops);
747 retval = device_create_file(dev, &dev_attr_inters); 272 if (!dent)
748 if (retval) 273 goto err;
749 goto rm_events; 274
750 retval = device_create_file(dev, &dev_attr_port_test); 275 dent = debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci,
751 if (retval) 276 &ci_qheads_fops);
752 goto rm_inters; 277 if (!dent)
753 retval = device_create_file(dev, &dev_attr_qheads); 278 goto err;
754 if (retval) 279
755 goto rm_port_test; 280 dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
756 retval = device_create_file(dev, &dev_attr_registers); 281 &ci_requests_fops);
757 if (retval) 282 if (!dent)
758 goto rm_qheads; 283 goto err;
759 retval = device_create_file(dev, &dev_attr_requests); 284
760 if (retval) 285 dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
761 goto rm_registers; 286 &ci_role_fops);
762 return 0; 287 if (dent)
763 288 return 0;
764 rm_registers: 289err:
765 device_remove_file(dev, &dev_attr_registers); 290 debugfs_remove_recursive(ci->debugfs);
766 rm_qheads: 291 return -ENOMEM;
767 device_remove_file(dev, &dev_attr_qheads);
768 rm_port_test:
769 device_remove_file(dev, &dev_attr_port_test);
770 rm_inters:
771 device_remove_file(dev, &dev_attr_inters);
772 rm_events:
773 device_remove_file(dev, &dev_attr_events);
774 rm_driver:
775 device_remove_file(dev, &dev_attr_driver);
776 rm_device:
777 device_remove_file(dev, &dev_attr_device);
778 done:
779 return retval;
780} 292}
781 293
782/** 294/**
783 * dbg_remove_files: destroys the attribute interface 295 * dbg_remove_files: destroys the attribute interface
784 * @dev: device 296 * @ci: device
785 *
786 * This function returns an error code
787 */ 297 */
788int dbg_remove_files(struct device *dev) 298void dbg_remove_files(struct ci13xxx *ci)
789{ 299{
790 if (dev == NULL) 300 debugfs_remove_recursive(ci->debugfs);
791 return -EINVAL;
792 device_remove_file(dev, &dev_attr_requests);
793 device_remove_file(dev, &dev_attr_registers);
794 device_remove_file(dev, &dev_attr_qheads);
795 device_remove_file(dev, &dev_attr_port_test);
796 device_remove_file(dev, &dev_attr_inters);
797 device_remove_file(dev, &dev_attr_events);
798 device_remove_file(dev, &dev_attr_driver);
799 device_remove_file(dev, &dev_attr_device);
800 return 0;
801} 301}
diff --git a/drivers/usb/chipidea/debug.h b/drivers/usb/chipidea/debug.h
index 80d96865775c..7ca6ca0a24a5 100644
--- a/drivers/usb/chipidea/debug.h
+++ b/drivers/usb/chipidea/debug.h
@@ -14,42 +14,16 @@
14#define __DRIVERS_USB_CHIPIDEA_DEBUG_H 14#define __DRIVERS_USB_CHIPIDEA_DEBUG_H
15 15
16#ifdef CONFIG_USB_CHIPIDEA_DEBUG 16#ifdef CONFIG_USB_CHIPIDEA_DEBUG
17void dbg_interrupt(u32 intmask); 17int dbg_create_files(struct ci13xxx *ci);
18void dbg_done(u8 addr, const u32 token, int status); 18void dbg_remove_files(struct ci13xxx *ci);
19void dbg_event(u8 addr, const char *name, int status);
20void dbg_queue(u8 addr, const struct usb_request *req, int status);
21void dbg_setup(u8 addr, const struct usb_ctrlrequest *req);
22int dbg_create_files(struct device *dev);
23int dbg_remove_files(struct device *dev);
24#else 19#else
25static inline void dbg_interrupt(u32 intmask) 20static inline int dbg_create_files(struct ci13xxx *ci)
26{
27}
28
29static inline void dbg_done(u8 addr, const u32 token, int status)
30{
31}
32
33static inline void dbg_event(u8 addr, const char *name, int status)
34{
35}
36
37static inline void dbg_queue(u8 addr, const struct usb_request *req, int status)
38{
39}
40
41static inline void dbg_setup(u8 addr, const struct usb_ctrlrequest *req)
42{
43}
44
45static inline int dbg_create_files(struct device *dev)
46{ 21{
47 return 0; 22 return 0;
48} 23}
49 24
50static inline int dbg_remove_files(struct device *dev) 25static inline void dbg_remove_files(struct ci13xxx *ci)
51{ 26{
52 return 0;
53} 27}
54#endif 28#endif
55 29
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index f64fbea1cf20..519ead2443c5 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -13,14 +13,8 @@
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/dmapool.h> 15#include <linux/dmapool.h>
16#include <linux/dma-mapping.h>
17#include <linux/err.h> 16#include <linux/err.h>
18#include <linux/init.h> 17#include <linux/irqreturn.h>
19#include <linux/platform_device.h>
20#include <linux/module.h>
21#include <linux/interrupt.h>
22#include <linux/io.h>
23#include <linux/irq.h>
24#include <linux/kernel.h> 18#include <linux/kernel.h>
25#include <linux/slab.h> 19#include <linux/slab.h>
26#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
@@ -146,7 +140,7 @@ static int hw_ep_enable(struct ci13xxx *ci, int num, int dir, int type)
146 140
147 if (dir) { 141 if (dir) {
148 mask = ENDPTCTRL_TXT; /* type */ 142 mask = ENDPTCTRL_TXT; /* type */
149 data = type << ffs_nr(mask); 143 data = type << __ffs(mask);
150 144
151 mask |= ENDPTCTRL_TXS; /* unstall */ 145 mask |= ENDPTCTRL_TXS; /* unstall */
152 mask |= ENDPTCTRL_TXR; /* reset data toggle */ 146 mask |= ENDPTCTRL_TXR; /* reset data toggle */
@@ -155,7 +149,7 @@ static int hw_ep_enable(struct ci13xxx *ci, int num, int dir, int type)
155 data |= ENDPTCTRL_TXE; 149 data |= ENDPTCTRL_TXE;
156 } else { 150 } else {
157 mask = ENDPTCTRL_RXT; /* type */ 151 mask = ENDPTCTRL_RXT; /* type */
158 data = type << ffs_nr(mask); 152 data = type << __ffs(mask);
159 153
160 mask |= ENDPTCTRL_RXS; /* unstall */ 154 mask |= ENDPTCTRL_RXS; /* unstall */
161 mask |= ENDPTCTRL_RXR; /* reset data toggle */ 155 mask |= ENDPTCTRL_RXR; /* reset data toggle */
@@ -305,18 +299,6 @@ static u32 hw_test_and_clear_intr_active(struct ci13xxx *ci)
305 return reg; 299 return reg;
306} 300}
307 301
308static void hw_enable_vbus_intr(struct ci13xxx *ci)
309{
310 hw_write(ci, OP_OTGSC, OTGSC_AVVIS, OTGSC_AVVIS);
311 hw_write(ci, OP_OTGSC, OTGSC_AVVIE, OTGSC_AVVIE);
312 queue_work(ci->wq, &ci->vbus_work);
313}
314
315static void hw_disable_vbus_intr(struct ci13xxx *ci)
316{
317 hw_write(ci, OP_OTGSC, OTGSC_AVVIE, 0);
318}
319
320/** 302/**
321 * hw_test_and_clear_setup_guard: test & clear setup guard (execute without 303 * hw_test_and_clear_setup_guard: test & clear setup guard (execute without
322 * interruption) 304 * interruption)
@@ -349,7 +331,7 @@ static int hw_test_and_set_setup_guard(struct ci13xxx *ci)
349static void hw_usb_set_address(struct ci13xxx *ci, u8 value) 331static void hw_usb_set_address(struct ci13xxx *ci, u8 value)
350{ 332{
351 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR, 333 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR,
352 value << ffs_nr(DEVICEADDR_USBADR)); 334 value << __ffs(DEVICEADDR_USBADR));
353} 335}
354 336
355/** 337/**
@@ -383,16 +365,6 @@ static int hw_usb_reset(struct ci13xxx *ci)
383 return 0; 365 return 0;
384} 366}
385 367
386static void vbus_work(struct work_struct *work)
387{
388 struct ci13xxx *ci = container_of(work, struct ci13xxx, vbus_work);
389
390 if (hw_read(ci, OP_OTGSC, OTGSC_AVV))
391 usb_gadget_vbus_connect(&ci->gadget);
392 else
393 usb_gadget_vbus_disconnect(&ci->gadget);
394}
395
396/****************************************************************************** 368/******************************************************************************
397 * UTIL block 369 * UTIL block
398 *****************************************************************************/ 370 *****************************************************************************/
@@ -432,10 +404,10 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
432 return -ENOMEM; 404 return -ENOMEM;
433 405
434 memset(mReq->zptr, 0, sizeof(*mReq->zptr)); 406 memset(mReq->zptr, 0, sizeof(*mReq->zptr));
435 mReq->zptr->next = TD_TERMINATE; 407 mReq->zptr->next = cpu_to_le32(TD_TERMINATE);
436 mReq->zptr->token = TD_STATUS_ACTIVE; 408 mReq->zptr->token = cpu_to_le32(TD_STATUS_ACTIVE);
437 if (!mReq->req.no_interrupt) 409 if (!mReq->req.no_interrupt)
438 mReq->zptr->token |= TD_IOC; 410 mReq->zptr->token |= cpu_to_le32(TD_IOC);
439 } 411 }
440 ret = usb_gadget_map_request(&ci->gadget, &mReq->req, mEp->dir); 412 ret = usb_gadget_map_request(&ci->gadget, &mReq->req, mEp->dir);
441 if (ret) 413 if (ret)
@@ -446,32 +418,37 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
446 * TODO - handle requests which spawns into several TDs 418 * TODO - handle requests which spawns into several TDs
447 */ 419 */
448 memset(mReq->ptr, 0, sizeof(*mReq->ptr)); 420 memset(mReq->ptr, 0, sizeof(*mReq->ptr));
449 mReq->ptr->token = length << ffs_nr(TD_TOTAL_BYTES); 421 mReq->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES));
450 mReq->ptr->token &= TD_TOTAL_BYTES; 422 mReq->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES);
451 mReq->ptr->token |= TD_STATUS_ACTIVE; 423 mReq->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE);
452 if (mReq->zptr) { 424 if (mReq->zptr) {
453 mReq->ptr->next = mReq->zdma; 425 mReq->ptr->next = cpu_to_le32(mReq->zdma);
454 } else { 426 } else {
455 mReq->ptr->next = TD_TERMINATE; 427 mReq->ptr->next = cpu_to_le32(TD_TERMINATE);
456 if (!mReq->req.no_interrupt) 428 if (!mReq->req.no_interrupt)
457 mReq->ptr->token |= TD_IOC; 429 mReq->ptr->token |= cpu_to_le32(TD_IOC);
430 }
431 mReq->ptr->page[0] = cpu_to_le32(mReq->req.dma);
432 for (i = 1; i < TD_PAGE_COUNT; i++) {
433 u32 page = mReq->req.dma + i * CI13XXX_PAGE_SIZE;
434 page &= ~TD_RESERVED_MASK;
435 mReq->ptr->page[i] = cpu_to_le32(page);
458 } 436 }
459 mReq->ptr->page[0] = mReq->req.dma; 437
460 for (i = 1; i < 5; i++) 438 wmb();
461 mReq->ptr->page[i] =
462 (mReq->req.dma + i * CI13XXX_PAGE_SIZE) & ~TD_RESERVED_MASK;
463 439
464 if (!list_empty(&mEp->qh.queue)) { 440 if (!list_empty(&mEp->qh.queue)) {
465 struct ci13xxx_req *mReqPrev; 441 struct ci13xxx_req *mReqPrev;
466 int n = hw_ep_bit(mEp->num, mEp->dir); 442 int n = hw_ep_bit(mEp->num, mEp->dir);
467 int tmp_stat; 443 int tmp_stat;
444 u32 next = mReq->dma & TD_ADDR_MASK;
468 445
469 mReqPrev = list_entry(mEp->qh.queue.prev, 446 mReqPrev = list_entry(mEp->qh.queue.prev,
470 struct ci13xxx_req, queue); 447 struct ci13xxx_req, queue);
471 if (mReqPrev->zptr) 448 if (mReqPrev->zptr)
472 mReqPrev->zptr->next = mReq->dma & TD_ADDR_MASK; 449 mReqPrev->zptr->next = cpu_to_le32(next);
473 else 450 else
474 mReqPrev->ptr->next = mReq->dma & TD_ADDR_MASK; 451 mReqPrev->ptr->next = cpu_to_le32(next);
475 wmb(); 452 wmb();
476 if (hw_read(ci, OP_ENDPTPRIME, BIT(n))) 453 if (hw_read(ci, OP_ENDPTPRIME, BIT(n)))
477 goto done; 454 goto done;
@@ -485,9 +462,9 @@ static int _hardware_enqueue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
485 } 462 }
486 463
487 /* QH configuration */ 464 /* QH configuration */
488 mEp->qh.ptr->td.next = mReq->dma; /* TERMINATE = 0 */ 465 mEp->qh.ptr->td.next = cpu_to_le32(mReq->dma); /* TERMINATE = 0 */
489 mEp->qh.ptr->td.token &= ~TD_STATUS; /* clear status */ 466 mEp->qh.ptr->td.token &=
490 mEp->qh.ptr->cap |= QH_ZLT; 467 cpu_to_le32(~(TD_STATUS_HALTED|TD_STATUS_ACTIVE));
491 468
492 wmb(); /* synchronize before ep prime */ 469 wmb(); /* synchronize before ep prime */
493 470
@@ -506,14 +483,16 @@ done:
506 */ 483 */
507static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq) 484static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
508{ 485{
486 u32 tmptoken = le32_to_cpu(mReq->ptr->token);
487
509 if (mReq->req.status != -EALREADY) 488 if (mReq->req.status != -EALREADY)
510 return -EINVAL; 489 return -EINVAL;
511 490
512 if ((TD_STATUS_ACTIVE & mReq->ptr->token) != 0) 491 if ((TD_STATUS_ACTIVE & tmptoken) != 0)
513 return -EBUSY; 492 return -EBUSY;
514 493
515 if (mReq->zptr) { 494 if (mReq->zptr) {
516 if ((TD_STATUS_ACTIVE & mReq->zptr->token) != 0) 495 if ((cpu_to_le32(TD_STATUS_ACTIVE) & mReq->zptr->token) != 0)
517 return -EBUSY; 496 return -EBUSY;
518 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma); 497 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
519 mReq->zptr = NULL; 498 mReq->zptr = NULL;
@@ -523,7 +502,7 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
523 502
524 usb_gadget_unmap_request(&mEp->ci->gadget, &mReq->req, mEp->dir); 503 usb_gadget_unmap_request(&mEp->ci->gadget, &mReq->req, mEp->dir);
525 504
526 mReq->req.status = mReq->ptr->token & TD_STATUS; 505 mReq->req.status = tmptoken & TD_STATUS;
527 if ((TD_STATUS_HALTED & mReq->req.status) != 0) 506 if ((TD_STATUS_HALTED & mReq->req.status) != 0)
528 mReq->req.status = -1; 507 mReq->req.status = -1;
529 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0) 508 else if ((TD_STATUS_DT_ERR & mReq->req.status) != 0)
@@ -531,8 +510,8 @@ static int _hardware_dequeue(struct ci13xxx_ep *mEp, struct ci13xxx_req *mReq)
531 else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0) 510 else if ((TD_STATUS_TR_ERR & mReq->req.status) != 0)
532 mReq->req.status = -1; 511 mReq->req.status = -1;
533 512
534 mReq->req.actual = mReq->ptr->token & TD_TOTAL_BYTES; 513 mReq->req.actual = tmptoken & TD_TOTAL_BYTES;
535 mReq->req.actual >>= ffs_nr(TD_TOTAL_BYTES); 514 mReq->req.actual >>= __ffs(TD_TOTAL_BYTES);
536 mReq->req.actual = mReq->req.length - mReq->req.actual; 515 mReq->req.actual = mReq->req.length - mReq->req.actual;
537 mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual; 516 mReq->req.actual = mReq->req.status ? 0 : mReq->req.actual;
538 517
@@ -561,6 +540,12 @@ __acquires(mEp->lock)
561 struct ci13xxx_req *mReq = \ 540 struct ci13xxx_req *mReq = \
562 list_entry(mEp->qh.queue.next, 541 list_entry(mEp->qh.queue.next,
563 struct ci13xxx_req, queue); 542 struct ci13xxx_req, queue);
543
544 if (mReq->zptr) {
545 dma_pool_free(mEp->td_pool, mReq->zptr, mReq->zdma);
546 mReq->zptr = NULL;
547 }
548
564 list_del_init(&mReq->queue); 549 list_del_init(&mReq->queue);
565 mReq->req.status = -ESHUTDOWN; 550 mReq->req.status = -ESHUTDOWN;
566 551
@@ -629,8 +614,6 @@ __acquires(ci->lock)
629{ 614{
630 int retval; 615 int retval;
631 616
632 dbg_event(0xFF, "BUS RST", 0);
633
634 spin_unlock(&ci->lock); 617 spin_unlock(&ci->lock);
635 retval = _gadget_stop_activity(&ci->gadget); 618 retval = _gadget_stop_activity(&ci->gadget);
636 if (retval) 619 if (retval)
@@ -668,6 +651,59 @@ static void isr_get_status_complete(struct usb_ep *ep, struct usb_request *req)
668} 651}
669 652
670/** 653/**
654 * _ep_queue: queues (submits) an I/O request to an endpoint
655 *
656 * Caller must hold lock
657 */
658static int _ep_queue(struct usb_ep *ep, struct usb_request *req,
659 gfp_t __maybe_unused gfp_flags)
660{
661 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
662 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);
663 struct ci13xxx *ci = mEp->ci;
664 int retval = 0;
665
666 if (ep == NULL || req == NULL || mEp->ep.desc == NULL)
667 return -EINVAL;
668
669 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
670 if (req->length)
671 mEp = (ci->ep0_dir == RX) ?
672 ci->ep0out : ci->ep0in;
673 if (!list_empty(&mEp->qh.queue)) {
674 _ep_nuke(mEp);
675 retval = -EOVERFLOW;
676 dev_warn(mEp->ci->dev, "endpoint ctrl %X nuked\n",
677 _usb_addr(mEp));
678 }
679 }
680
681 /* first nuke then test link, e.g. previous status has not sent */
682 if (!list_empty(&mReq->queue)) {
683 dev_err(mEp->ci->dev, "request already in queue\n");
684 return -EBUSY;
685 }
686
687 if (req->length > (TD_PAGE_COUNT - 1) * CI13XXX_PAGE_SIZE) {
688 dev_err(mEp->ci->dev, "request bigger than one td\n");
689 return -EMSGSIZE;
690 }
691
692 /* push request */
693 mReq->req.status = -EINPROGRESS;
694 mReq->req.actual = 0;
695
696 retval = _hardware_enqueue(mEp, mReq);
697
698 if (retval == -EALREADY)
699 retval = 0;
700 if (!retval)
701 list_add_tail(&mReq->queue, &mEp->qh.queue);
702
703 return retval;
704}
705
706/**
671 * isr_get_status_response: get_status request response 707 * isr_get_status_response: get_status request response
672 * @ci: ci struct 708 * @ci: ci struct
673 * @setup: setup request packet 709 * @setup: setup request packet
@@ -714,9 +750,7 @@ __acquires(mEp->lock)
714 } 750 }
715 /* else do nothing; reserved for future use */ 751 /* else do nothing; reserved for future use */
716 752
717 spin_unlock(mEp->lock); 753 retval = _ep_queue(&mEp->ep, req, gfp_flags);
718 retval = usb_ep_queue(&mEp->ep, req, gfp_flags);
719 spin_lock(mEp->lock);
720 if (retval) 754 if (retval)
721 goto err_free_buf; 755 goto err_free_buf;
722 756
@@ -763,8 +797,6 @@ isr_setup_status_complete(struct usb_ep *ep, struct usb_request *req)
763 * This function returns an error code 797 * This function returns an error code
764 */ 798 */
765static int isr_setup_status_phase(struct ci13xxx *ci) 799static int isr_setup_status_phase(struct ci13xxx *ci)
766__releases(mEp->lock)
767__acquires(mEp->lock)
768{ 800{
769 int retval; 801 int retval;
770 struct ci13xxx_ep *mEp; 802 struct ci13xxx_ep *mEp;
@@ -773,9 +805,7 @@ __acquires(mEp->lock)
773 ci->status->context = ci; 805 ci->status->context = ci;
774 ci->status->complete = isr_setup_status_complete; 806 ci->status->complete = isr_setup_status_complete;
775 807
776 spin_unlock(mEp->lock); 808 retval = _ep_queue(&mEp->ep, ci->status, GFP_ATOMIC);
777 retval = usb_ep_queue(&mEp->ep, ci->status, GFP_ATOMIC);
778 spin_lock(mEp->lock);
779 809
780 return retval; 810 return retval;
781} 811}
@@ -801,7 +831,6 @@ __acquires(mEp->lock)
801 if (retval < 0) 831 if (retval < 0)
802 break; 832 break;
803 list_del_init(&mReq->queue); 833 list_del_init(&mReq->queue);
804 dbg_done(_usb_addr(mEp), mReq->ptr->token, retval);
805 if (mReq->req.complete != NULL) { 834 if (mReq->req.complete != NULL) {
806 spin_unlock(mEp->lock); 835 spin_unlock(mEp->lock);
807 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) && 836 if ((mEp->type == USB_ENDPOINT_XFER_CONTROL) &&
@@ -814,8 +843,6 @@ __acquires(mEp->lock)
814 843
815 if (retval == -EBUSY) 844 if (retval == -EBUSY)
816 retval = 0; 845 retval = 0;
817 if (retval < 0)
818 dbg_event(_usb_addr(mEp), "DONE", retval);
819 846
820 return retval; 847 return retval;
821} 848}
@@ -847,8 +874,6 @@ __acquires(ci->lock)
847 if (err > 0) /* needs status phase */ 874 if (err > 0) /* needs status phase */
848 err = isr_setup_status_phase(ci); 875 err = isr_setup_status_phase(ci);
849 if (err < 0) { 876 if (err < 0) {
850 dbg_event(_usb_addr(mEp),
851 "ERROR", err);
852 spin_unlock(&ci->lock); 877 spin_unlock(&ci->lock);
853 if (usb_ep_set_halt(&mEp->ep)) 878 if (usb_ep_set_halt(&mEp->ep))
854 dev_err(ci->dev, 879 dev_err(ci->dev,
@@ -884,8 +909,6 @@ __acquires(ci->lock)
884 909
885 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX; 910 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX;
886 911
887 dbg_setup(_usb_addr(mEp), &req);
888
889 switch (req.bRequest) { 912 switch (req.bRequest) {
890 case USB_REQ_CLEAR_FEATURE: 913 case USB_REQ_CLEAR_FEATURE:
891 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) && 914 if (type == (USB_DIR_OUT|USB_RECIP_ENDPOINT) &&
@@ -997,8 +1020,6 @@ delegate:
997 } 1020 }
998 1021
999 if (err < 0) { 1022 if (err < 0) {
1000 dbg_event(_usb_addr(mEp), "ERROR", err);
1001
1002 spin_unlock(&ci->lock); 1023 spin_unlock(&ci->lock);
1003 if (usb_ep_set_halt(&mEp->ep)) 1024 if (usb_ep_set_halt(&mEp->ep))
1004 dev_err(ci->dev, "error: ep_set_halt\n"); 1025 dev_err(ci->dev, "error: ep_set_halt\n");
@@ -1021,6 +1042,7 @@ static int ep_enable(struct usb_ep *ep,
1021 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 1042 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1022 int retval = 0; 1043 int retval = 0;
1023 unsigned long flags; 1044 unsigned long flags;
1045 u32 cap = 0;
1024 1046
1025 if (ep == NULL || desc == NULL) 1047 if (ep == NULL || desc == NULL)
1026 return -EINVAL; 1048 return -EINVAL;
@@ -1040,20 +1062,15 @@ static int ep_enable(struct usb_ep *ep,
1040 1062
1041 mEp->ep.maxpacket = usb_endpoint_maxp(desc); 1063 mEp->ep.maxpacket = usb_endpoint_maxp(desc);
1042 1064
1043 dbg_event(_usb_addr(mEp), "ENABLE", 0);
1044
1045 mEp->qh.ptr->cap = 0;
1046
1047 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) 1065 if (mEp->type == USB_ENDPOINT_XFER_CONTROL)
1048 mEp->qh.ptr->cap |= QH_IOS; 1066 cap |= QH_IOS;
1049 else if (mEp->type == USB_ENDPOINT_XFER_ISOC) 1067 if (mEp->num)
1050 mEp->qh.ptr->cap &= ~QH_MULT; 1068 cap |= QH_ZLT;
1051 else 1069 cap |= (mEp->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT;
1052 mEp->qh.ptr->cap &= ~QH_ZLT; 1070
1071 mEp->qh.ptr->cap = cpu_to_le32(cap);
1053 1072
1054 mEp->qh.ptr->cap |= 1073 mEp->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */
1055 (mEp->ep.maxpacket << ffs_nr(QH_MAX_PKT)) & QH_MAX_PKT;
1056 mEp->qh.ptr->td.next |= TD_TERMINATE; /* needed? */
1057 1074
1058 /* 1075 /*
1059 * Enable endpoints in the HW other than ep0 as ep0 1076 * Enable endpoints in the HW other than ep0 as ep0
@@ -1088,8 +1105,6 @@ static int ep_disable(struct usb_ep *ep)
1088 1105
1089 direction = mEp->dir; 1106 direction = mEp->dir;
1090 do { 1107 do {
1091 dbg_event(_usb_addr(mEp), "DISABLE", 0);
1092
1093 retval |= _ep_nuke(mEp); 1108 retval |= _ep_nuke(mEp);
1094 retval |= hw_ep_disable(mEp->ci, mEp->num, mEp->dir); 1109 retval |= hw_ep_disable(mEp->ci, mEp->num, mEp->dir);
1095 1110
@@ -1129,8 +1144,6 @@ static struct usb_request *ep_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
1129 } 1144 }
1130 } 1145 }
1131 1146
1132 dbg_event(_usb_addr(mEp), "ALLOC", mReq == NULL);
1133
1134 return (mReq == NULL) ? NULL : &mReq->req; 1147 return (mReq == NULL) ? NULL : &mReq->req;
1135} 1148}
1136 1149
@@ -1158,8 +1171,6 @@ static void ep_free_request(struct usb_ep *ep, struct usb_request *req)
1158 dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma); 1171 dma_pool_free(mEp->td_pool, mReq->ptr, mReq->dma);
1159 kfree(mReq); 1172 kfree(mReq);
1160 1173
1161 dbg_event(_usb_addr(mEp), "FREE", 0);
1162
1163 spin_unlock_irqrestore(mEp->lock, flags); 1174 spin_unlock_irqrestore(mEp->lock, flags);
1164} 1175}
1165 1176
@@ -1172,8 +1183,6 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1172 gfp_t __maybe_unused gfp_flags) 1183 gfp_t __maybe_unused gfp_flags)
1173{ 1184{
1174 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep); 1185 struct ci13xxx_ep *mEp = container_of(ep, struct ci13xxx_ep, ep);
1175 struct ci13xxx_req *mReq = container_of(req, struct ci13xxx_req, req);
1176 struct ci13xxx *ci = mEp->ci;
1177 int retval = 0; 1186 int retval = 0;
1178 unsigned long flags; 1187 unsigned long flags;
1179 1188
@@ -1181,48 +1190,7 @@ static int ep_queue(struct usb_ep *ep, struct usb_request *req,
1181 return -EINVAL; 1190 return -EINVAL;
1182 1191
1183 spin_lock_irqsave(mEp->lock, flags); 1192 spin_lock_irqsave(mEp->lock, flags);
1184 1193 retval = _ep_queue(ep, req, gfp_flags);
1185 if (mEp->type == USB_ENDPOINT_XFER_CONTROL) {
1186 if (req->length)
1187 mEp = (ci->ep0_dir == RX) ?
1188 ci->ep0out : ci->ep0in;
1189 if (!list_empty(&mEp->qh.queue)) {
1190 _ep_nuke(mEp);
1191 retval = -EOVERFLOW;
1192 dev_warn(mEp->ci->dev, "endpoint ctrl %X nuked\n",
1193 _usb_addr(mEp));
1194 }
1195 }
1196
1197 /* first nuke then test link, e.g. previous status has not sent */
1198 if (!list_empty(&mReq->queue)) {
1199 retval = -EBUSY;
1200 dev_err(mEp->ci->dev, "request already in queue\n");
1201 goto done;
1202 }
1203
1204 if (req->length > 4 * CI13XXX_PAGE_SIZE) {
1205 req->length = 4 * CI13XXX_PAGE_SIZE;
1206 retval = -EMSGSIZE;
1207 dev_warn(mEp->ci->dev, "request length truncated\n");
1208 }
1209
1210 dbg_queue(_usb_addr(mEp), req, retval);
1211
1212 /* push request */
1213 mReq->req.status = -EINPROGRESS;
1214 mReq->req.actual = 0;
1215
1216 retval = _hardware_enqueue(mEp, mReq);
1217
1218 if (retval == -EALREADY) {
1219 dbg_event(_usb_addr(mEp), "QUEUE", retval);
1220 retval = 0;
1221 }
1222 if (!retval)
1223 list_add_tail(&mReq->queue, &mEp->qh.queue);
1224
1225 done:
1226 spin_unlock_irqrestore(mEp->lock, flags); 1194 spin_unlock_irqrestore(mEp->lock, flags);
1227 return retval; 1195 return retval;
1228} 1196}
@@ -1245,8 +1213,6 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req)
1245 1213
1246 spin_lock_irqsave(mEp->lock, flags); 1214 spin_lock_irqsave(mEp->lock, flags);
1247 1215
1248 dbg_event(_usb_addr(mEp), "DEQUEUE", 0);
1249
1250 hw_ep_flush(mEp->ci, mEp->num, mEp->dir); 1216 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1251 1217
1252 /* pop request */ 1218 /* pop request */
@@ -1293,7 +1259,6 @@ static int ep_set_halt(struct usb_ep *ep, int value)
1293 1259
1294 direction = mEp->dir; 1260 direction = mEp->dir;
1295 do { 1261 do {
1296 dbg_event(_usb_addr(mEp), "HALT", value);
1297 retval |= hw_ep_set_halt(mEp->ci, mEp->num, mEp->dir, value); 1262 retval |= hw_ep_set_halt(mEp->ci, mEp->num, mEp->dir, value);
1298 1263
1299 if (!value) 1264 if (!value)
@@ -1322,10 +1287,7 @@ static int ep_set_wedge(struct usb_ep *ep)
1322 return -EINVAL; 1287 return -EINVAL;
1323 1288
1324 spin_lock_irqsave(mEp->lock, flags); 1289 spin_lock_irqsave(mEp->lock, flags);
1325
1326 dbg_event(_usb_addr(mEp), "WEDGE", 0);
1327 mEp->wedge = 1; 1290 mEp->wedge = 1;
1328
1329 spin_unlock_irqrestore(mEp->lock, flags); 1291 spin_unlock_irqrestore(mEp->lock, flags);
1330 1292
1331 return usb_ep_set_halt(ep); 1293 return usb_ep_set_halt(ep);
@@ -1348,7 +1310,6 @@ static void ep_fifo_flush(struct usb_ep *ep)
1348 1310
1349 spin_lock_irqsave(mEp->lock, flags); 1311 spin_lock_irqsave(mEp->lock, flags);
1350 1312
1351 dbg_event(_usb_addr(mEp), "FFLUSH", 0);
1352 hw_ep_flush(mEp->ci, mEp->num, mEp->dir); 1313 hw_ep_flush(mEp->ci, mEp->num, mEp->dir);
1353 1314
1354 spin_unlock_irqrestore(mEp->lock, flags); 1315 spin_unlock_irqrestore(mEp->lock, flags);
@@ -1392,7 +1353,6 @@ static int ci13xxx_vbus_session(struct usb_gadget *_gadget, int is_active)
1392 if (is_active) { 1353 if (is_active) {
1393 pm_runtime_get_sync(&_gadget->dev); 1354 pm_runtime_get_sync(&_gadget->dev);
1394 hw_device_reset(ci, USBMODE_CM_DC); 1355 hw_device_reset(ci, USBMODE_CM_DC);
1395 hw_enable_vbus_intr(ci);
1396 hw_device_state(ci, ci->ep0out->qh.dma); 1356 hw_device_state(ci, ci->ep0out->qh.dma);
1397 } else { 1357 } else {
1398 hw_device_state(ci, 0); 1358 hw_device_state(ci, 0);
@@ -1567,10 +1527,8 @@ static int ci13xxx_start(struct usb_gadget *gadget,
1567 pm_runtime_get_sync(&ci->gadget.dev); 1527 pm_runtime_get_sync(&ci->gadget.dev);
1568 if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) { 1528 if (ci->platdata->flags & CI13XXX_PULLUP_ON_VBUS) {
1569 if (ci->vbus_active) { 1529 if (ci->vbus_active) {
1570 if (ci->platdata->flags & CI13XXX_REGS_SHARED) { 1530 if (ci->platdata->flags & CI13XXX_REGS_SHARED)
1571 hw_device_reset(ci, USBMODE_CM_DC); 1531 hw_device_reset(ci, USBMODE_CM_DC);
1572 hw_enable_vbus_intr(ci);
1573 }
1574 } else { 1532 } else {
1575 pm_runtime_put_sync(&ci->gadget.dev); 1533 pm_runtime_put_sync(&ci->gadget.dev);
1576 goto done; 1534 goto done;
@@ -1642,7 +1600,6 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
1642 } 1600 }
1643 } 1601 }
1644 intr = hw_test_and_clear_intr_active(ci); 1602 intr = hw_test_and_clear_intr_active(ci);
1645 dbg_interrupt(intr);
1646 1603
1647 if (intr) { 1604 if (intr) {
1648 /* order defines priority - do NOT change it */ 1605 /* order defines priority - do NOT change it */
@@ -1676,29 +1633,12 @@ static irqreturn_t udc_irq(struct ci13xxx *ci)
1676 } else { 1633 } else {
1677 retval = IRQ_NONE; 1634 retval = IRQ_NONE;
1678 } 1635 }
1679
1680 intr = hw_read(ci, OP_OTGSC, ~0);
1681 hw_write(ci, OP_OTGSC, ~0, intr);
1682
1683 if (intr & (OTGSC_AVVIE & OTGSC_AVVIS))
1684 queue_work(ci->wq, &ci->vbus_work);
1685
1686 spin_unlock(&ci->lock); 1636 spin_unlock(&ci->lock);
1687 1637
1688 return retval; 1638 return retval;
1689} 1639}
1690 1640
1691/** 1641/**
1692 * udc_release: driver release function
1693 * @dev: device
1694 *
1695 * Currently does nothing
1696 */
1697static void udc_release(struct device *dev)
1698{
1699}
1700
1701/**
1702 * udc_start: initialize gadget role 1642 * udc_start: initialize gadget role
1703 * @ci: chipidea controller 1643 * @ci: chipidea controller
1704 */ 1644 */
@@ -1717,12 +1657,6 @@ static int udc_start(struct ci13xxx *ci)
1717 1657
1718 INIT_LIST_HEAD(&ci->gadget.ep_list); 1658 INIT_LIST_HEAD(&ci->gadget.ep_list);
1719 1659
1720 dev_set_name(&ci->gadget.dev, "gadget");
1721 ci->gadget.dev.dma_mask = dev->dma_mask;
1722 ci->gadget.dev.coherent_dma_mask = dev->coherent_dma_mask;
1723 ci->gadget.dev.parent = dev;
1724 ci->gadget.dev.release = udc_release;
1725
1726 /* alloc resources */ 1660 /* alloc resources */
1727 ci->qh_pool = dma_pool_create("ci13xxx_qh", dev, 1661 ci->qh_pool = dma_pool_create("ci13xxx_qh", dev,
1728 sizeof(struct ci13xxx_qh), 1662 sizeof(struct ci13xxx_qh),
@@ -1758,24 +1692,13 @@ static int udc_start(struct ci13xxx *ci)
1758 retval = hw_device_reset(ci, USBMODE_CM_DC); 1692 retval = hw_device_reset(ci, USBMODE_CM_DC);
1759 if (retval) 1693 if (retval)
1760 goto put_transceiver; 1694 goto put_transceiver;
1761 hw_enable_vbus_intr(ci);
1762 }
1763
1764 retval = device_register(&ci->gadget.dev);
1765 if (retval) {
1766 put_device(&ci->gadget.dev);
1767 goto put_transceiver;
1768 } 1695 }
1769 1696
1770 retval = dbg_create_files(ci->dev);
1771 if (retval)
1772 goto unreg_device;
1773
1774 if (!IS_ERR_OR_NULL(ci->transceiver)) { 1697 if (!IS_ERR_OR_NULL(ci->transceiver)) {
1775 retval = otg_set_peripheral(ci->transceiver->otg, 1698 retval = otg_set_peripheral(ci->transceiver->otg,
1776 &ci->gadget); 1699 &ci->gadget);
1777 if (retval) 1700 if (retval)
1778 goto remove_dbg; 1701 goto put_transceiver;
1779 } 1702 }
1780 1703
1781 retval = usb_add_gadget_udc(dev, &ci->gadget); 1704 retval = usb_add_gadget_udc(dev, &ci->gadget);
@@ -1795,10 +1718,6 @@ remove_trans:
1795 } 1718 }
1796 1719
1797 dev_err(dev, "error = %i\n", retval); 1720 dev_err(dev, "error = %i\n", retval);
1798remove_dbg:
1799 dbg_remove_files(ci->dev);
1800unreg_device:
1801 device_unregister(&ci->gadget.dev);
1802put_transceiver: 1721put_transceiver:
1803 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy) 1722 if (!IS_ERR_OR_NULL(ci->transceiver) && ci->global_phy)
1804 usb_put_phy(ci->transceiver); 1723 usb_put_phy(ci->transceiver);
@@ -1821,9 +1740,6 @@ static void udc_stop(struct ci13xxx *ci)
1821 if (ci == NULL) 1740 if (ci == NULL)
1822 return; 1741 return;
1823 1742
1824 hw_disable_vbus_intr(ci);
1825 cancel_work_sync(&ci->vbus_work);
1826
1827 usb_del_gadget_udc(&ci->gadget); 1743 usb_del_gadget_udc(&ci->gadget);
1828 1744
1829 destroy_eps(ci); 1745 destroy_eps(ci);
@@ -1836,8 +1752,6 @@ static void udc_stop(struct ci13xxx *ci)
1836 if (ci->global_phy) 1752 if (ci->global_phy)
1837 usb_put_phy(ci->transceiver); 1753 usb_put_phy(ci->transceiver);
1838 } 1754 }
1839 dbg_remove_files(ci->dev);
1840 device_unregister(&ci->gadget.dev);
1841 /* my kobject is dynamic, I swear! */ 1755 /* my kobject is dynamic, I swear! */
1842 memset(&ci->gadget, 0, sizeof(ci->gadget)); 1756 memset(&ci->gadget, 0, sizeof(ci->gadget));
1843} 1757}
@@ -1864,7 +1778,6 @@ int ci_hdrc_gadget_init(struct ci13xxx *ci)
1864 rdrv->irq = udc_irq; 1778 rdrv->irq = udc_irq;
1865 rdrv->name = "gadget"; 1779 rdrv->name = "gadget";
1866 ci->roles[CI_ROLE_GADGET] = rdrv; 1780 ci->roles[CI_ROLE_GADGET] = rdrv;
1867 INIT_WORK(&ci->vbus_work, vbus_work);
1868 1781
1869 return 0; 1782 return 0;
1870} 1783}
diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h
index 4ff2384d7ca8..d12e8b59b110 100644
--- a/drivers/usb/chipidea/udc.h
+++ b/drivers/usb/chipidea/udc.h
@@ -40,7 +40,7 @@ struct ci13xxx_td {
40#define TD_CURR_OFFSET (0x0FFFUL << 0) 40#define TD_CURR_OFFSET (0x0FFFUL << 0)
41#define TD_FRAME_NUM (0x07FFUL << 0) 41#define TD_FRAME_NUM (0x07FFUL << 0)
42#define TD_RESERVED_MASK (0x0FFFUL << 0) 42#define TD_RESERVED_MASK (0x0FFFUL << 0)
43} __attribute__ ((packed)); 43} __attribute__ ((packed, aligned(4)));
44 44
45/* DMA layout of queue heads */ 45/* DMA layout of queue heads */
46struct ci13xxx_qh { 46struct ci13xxx_qh {
@@ -57,7 +57,7 @@ struct ci13xxx_qh {
57 /* 9 */ 57 /* 9 */
58 u32 RESERVED; 58 u32 RESERVED;
59 struct usb_ctrlrequest setup; 59 struct usb_ctrlrequest setup;
60} __attribute__ ((packed)); 60} __attribute__ ((packed, aligned(4)));
61 61
62/** 62/**
63 * struct ci13xxx_req - usb request representation 63 * struct ci13xxx_req - usb request representation
diff --git a/drivers/usb/chipidea/usbmisc_imx.c b/drivers/usb/chipidea/usbmisc_imx.c
new file mode 100644
index 000000000000..714a6bd810ed
--- /dev/null
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -0,0 +1,261 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18
19#include "ci13xxx_imx.h"
20
21#define USB_DEV_MAX 4
22
23#define MX25_USB_PHY_CTRL_OFFSET 0x08
24#define MX25_BM_EXTERNAL_VBUS_DIVIDER BIT(23)
25
26#define MX53_USB_OTG_PHY_CTRL_0_OFFSET 0x08
27#define MX53_USB_UH2_CTRL_OFFSET 0x14
28#define MX53_USB_UH3_CTRL_OFFSET 0x18
29#define MX53_BM_OVER_CUR_DIS_H1 BIT(5)
30#define MX53_BM_OVER_CUR_DIS_OTG BIT(8)
31#define MX53_BM_OVER_CUR_DIS_UHx BIT(30)
32
33#define MX6_BM_OVER_CUR_DIS BIT(7)
34
35struct imx_usbmisc {
36 void __iomem *base;
37 spinlock_t lock;
38 struct clk *clk;
39 struct usbmisc_usb_device usbdev[USB_DEV_MAX];
40 const struct usbmisc_ops *ops;
41};
42
43static struct imx_usbmisc *usbmisc;
44
45static struct usbmisc_usb_device *get_usbdev(struct device *dev)
46{
47 int i, ret;
48
49 for (i = 0; i < USB_DEV_MAX; i++) {
50 if (usbmisc->usbdev[i].dev == dev)
51 return &usbmisc->usbdev[i];
52 else if (!usbmisc->usbdev[i].dev)
53 break;
54 }
55
56 if (i >= USB_DEV_MAX)
57 return ERR_PTR(-EBUSY);
58
59 ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
60 if (ret)
61 return ERR_PTR(ret);
62
63 return &usbmisc->usbdev[i];
64}
65
66static int usbmisc_imx25_post(struct device *dev)
67{
68 struct usbmisc_usb_device *usbdev;
69 void __iomem *reg;
70 unsigned long flags;
71 u32 val;
72
73 usbdev = get_usbdev(dev);
74 if (IS_ERR(usbdev))
75 return PTR_ERR(usbdev);
76
77 reg = usbmisc->base + MX25_USB_PHY_CTRL_OFFSET;
78
79 if (usbdev->evdo) {
80 spin_lock_irqsave(&usbmisc->lock, flags);
81 val = readl(reg);
82 writel(val | MX25_BM_EXTERNAL_VBUS_DIVIDER, reg);
83 spin_unlock_irqrestore(&usbmisc->lock, flags);
84 usleep_range(5000, 10000); /* needed to stabilize voltage */
85 }
86
87 return 0;
88}
89
90static int usbmisc_imx53_init(struct device *dev)
91{
92 struct usbmisc_usb_device *usbdev;
93 void __iomem *reg = NULL;
94 unsigned long flags;
95 u32 val = 0;
96
97 usbdev = get_usbdev(dev);
98 if (IS_ERR(usbdev))
99 return PTR_ERR(usbdev);
100
101 if (usbdev->disable_oc) {
102 spin_lock_irqsave(&usbmisc->lock, flags);
103 switch (usbdev->index) {
104 case 0:
105 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
106 val = readl(reg) | MX53_BM_OVER_CUR_DIS_OTG;
107 break;
108 case 1:
109 reg = usbmisc->base + MX53_USB_OTG_PHY_CTRL_0_OFFSET;
110 val = readl(reg) | MX53_BM_OVER_CUR_DIS_H1;
111 break;
112 case 2:
113 reg = usbmisc->base + MX53_USB_UH2_CTRL_OFFSET;
114 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
115 break;
116 case 3:
117 reg = usbmisc->base + MX53_USB_UH3_CTRL_OFFSET;
118 val = readl(reg) | MX53_BM_OVER_CUR_DIS_UHx;
119 break;
120 }
121 if (reg && val)
122 writel(val, reg);
123 spin_unlock_irqrestore(&usbmisc->lock, flags);
124 }
125
126 return 0;
127}
128
129static int usbmisc_imx6q_init(struct device *dev)
130{
131
132 struct usbmisc_usb_device *usbdev;
133 unsigned long flags;
134 u32 reg;
135
136 usbdev = get_usbdev(dev);
137 if (IS_ERR(usbdev))
138 return PTR_ERR(usbdev);
139
140 if (usbdev->disable_oc) {
141 spin_lock_irqsave(&usbmisc->lock, flags);
142 reg = readl(usbmisc->base + usbdev->index * 4);
143 writel(reg | MX6_BM_OVER_CUR_DIS,
144 usbmisc->base + usbdev->index * 4);
145 spin_unlock_irqrestore(&usbmisc->lock, flags);
146 }
147
148 return 0;
149}
150
151static const struct usbmisc_ops imx25_usbmisc_ops = {
152 .post = usbmisc_imx25_post,
153};
154
155static const struct usbmisc_ops imx53_usbmisc_ops = {
156 .init = usbmisc_imx53_init,
157};
158
159static const struct usbmisc_ops imx6q_usbmisc_ops = {
160 .init = usbmisc_imx6q_init,
161};
162
163static const struct of_device_id usbmisc_imx_dt_ids[] = {
164 {
165 .compatible = "fsl,imx25-usbmisc",
166 .data = &imx25_usbmisc_ops,
167 },
168 {
169 .compatible = "fsl,imx53-usbmisc",
170 .data = &imx53_usbmisc_ops,
171 },
172 {
173 .compatible = "fsl,imx6q-usbmisc",
174 .data = &imx6q_usbmisc_ops,
175 },
176 { /* sentinel */ }
177};
178
179static int usbmisc_imx_probe(struct platform_device *pdev)
180{
181 struct resource *res;
182 struct imx_usbmisc *data;
183 int ret;
184 struct of_device_id *tmp_dev;
185
186 if (usbmisc)
187 return -EBUSY;
188
189 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
190 if (!data)
191 return -ENOMEM;
192
193 spin_lock_init(&data->lock);
194
195 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
196 data->base = devm_ioremap_resource(&pdev->dev, res);
197 if (IS_ERR(data->base))
198 return PTR_ERR(data->base);
199
200 data->clk = devm_clk_get(&pdev->dev, NULL);
201 if (IS_ERR(data->clk)) {
202 dev_err(&pdev->dev,
203 "failed to get clock, err=%ld\n", PTR_ERR(data->clk));
204 return PTR_ERR(data->clk);
205 }
206
207 ret = clk_prepare_enable(data->clk);
208 if (ret) {
209 dev_err(&pdev->dev,
210 "clk_prepare_enable failed, err=%d\n", ret);
211 return ret;
212 }
213
214 tmp_dev = (struct of_device_id *)
215 of_match_device(usbmisc_imx_dt_ids, &pdev->dev);
216 data->ops = (const struct usbmisc_ops *)tmp_dev->data;
217 usbmisc = data;
218 ret = usbmisc_set_ops(data->ops);
219 if (ret) {
220 usbmisc = NULL;
221 clk_disable_unprepare(data->clk);
222 return ret;
223 }
224
225 return 0;
226}
227
228static int usbmisc_imx_remove(struct platform_device *pdev)
229{
230 usbmisc_unset_ops(usbmisc->ops);
231 clk_disable_unprepare(usbmisc->clk);
232 usbmisc = NULL;
233 return 0;
234}
235
236static struct platform_driver usbmisc_imx_driver = {
237 .probe = usbmisc_imx_probe,
238 .remove = usbmisc_imx_remove,
239 .driver = {
240 .name = "usbmisc_imx",
241 .owner = THIS_MODULE,
242 .of_match_table = usbmisc_imx_dt_ids,
243 },
244};
245
246int usbmisc_imx_drv_init(void)
247{
248 return platform_driver_register(&usbmisc_imx_driver);
249}
250subsys_initcall(usbmisc_imx_drv_init);
251
252void usbmisc_imx_drv_exit(void)
253{
254 platform_driver_unregister(&usbmisc_imx_driver);
255}
256module_exit(usbmisc_imx_drv_exit);
257
258MODULE_ALIAS("platform:usbmisc-imx");
259MODULE_LICENSE("GPL v2");
260MODULE_DESCRIPTION("driver for imx usb non-core registers");
261MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
diff --git a/drivers/usb/chipidea/usbmisc_imx6q.c b/drivers/usb/chipidea/usbmisc_imx6q.c
deleted file mode 100644
index a1bce391e825..000000000000
--- a/drivers/usb/chipidea/usbmisc_imx6q.c
+++ /dev/null
@@ -1,162 +0,0 @@
1/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <linux/clk.h>
15#include <linux/err.h>
16#include <linux/io.h>
17
18#include "ci13xxx_imx.h"
19
20#define USB_DEV_MAX 4
21
22#define BM_OVER_CUR_DIS BIT(7)
23
24struct imx6q_usbmisc {
25 void __iomem *base;
26 spinlock_t lock;
27 struct clk *clk;
28 struct usbmisc_usb_device usbdev[USB_DEV_MAX];
29};
30
31static struct imx6q_usbmisc *usbmisc;
32
33static struct usbmisc_usb_device *get_usbdev(struct device *dev)
34{
35 int i, ret;
36
37 for (i = 0; i < USB_DEV_MAX; i++) {
38 if (usbmisc->usbdev[i].dev == dev)
39 return &usbmisc->usbdev[i];
40 else if (!usbmisc->usbdev[i].dev)
41 break;
42 }
43
44 if (i >= USB_DEV_MAX)
45 return ERR_PTR(-EBUSY);
46
47 ret = usbmisc_get_init_data(dev, &usbmisc->usbdev[i]);
48 if (ret)
49 return ERR_PTR(ret);
50
51 return &usbmisc->usbdev[i];
52}
53
54static int usbmisc_imx6q_init(struct device *dev)
55{
56
57 struct usbmisc_usb_device *usbdev;
58 unsigned long flags;
59 u32 reg;
60
61 usbdev = get_usbdev(dev);
62 if (IS_ERR(usbdev))
63 return PTR_ERR(usbdev);
64
65 if (usbdev->disable_oc) {
66 spin_lock_irqsave(&usbmisc->lock, flags);
67 reg = readl(usbmisc->base + usbdev->index * 4);
68 writel(reg | BM_OVER_CUR_DIS,
69 usbmisc->base + usbdev->index * 4);
70 spin_unlock_irqrestore(&usbmisc->lock, flags);
71 }
72
73 return 0;
74}
75
76static const struct usbmisc_ops imx6q_usbmisc_ops = {
77 .init = usbmisc_imx6q_init,
78};
79
80static const struct of_device_id usbmisc_imx6q_dt_ids[] = {
81 { .compatible = "fsl,imx6q-usbmisc"},
82 { /* sentinel */ }
83};
84
85static int usbmisc_imx6q_probe(struct platform_device *pdev)
86{
87 struct resource *res;
88 struct imx6q_usbmisc *data;
89 int ret;
90
91 if (usbmisc)
92 return -EBUSY;
93
94 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
95 if (!data)
96 return -ENOMEM;
97
98 spin_lock_init(&data->lock);
99
100 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
101 data->base = devm_ioremap_resource(&pdev->dev, res);
102 if (IS_ERR(data->base))
103 return PTR_ERR(data->base);
104
105 data->clk = devm_clk_get(&pdev->dev, NULL);
106 if (IS_ERR(data->clk)) {
107 dev_err(&pdev->dev,
108 "failed to get clock, err=%ld\n", PTR_ERR(data->clk));
109 return PTR_ERR(data->clk);
110 }
111
112 ret = clk_prepare_enable(data->clk);
113 if (ret) {
114 dev_err(&pdev->dev,
115 "clk_prepare_enable failed, err=%d\n", ret);
116 return ret;
117 }
118
119 ret = usbmisc_set_ops(&imx6q_usbmisc_ops);
120 if (ret) {
121 clk_disable_unprepare(data->clk);
122 return ret;
123 }
124
125 usbmisc = data;
126
127 return 0;
128}
129
130static int usbmisc_imx6q_remove(struct platform_device *pdev)
131{
132 usbmisc_unset_ops(&imx6q_usbmisc_ops);
133 clk_disable_unprepare(usbmisc->clk);
134 return 0;
135}
136
137static struct platform_driver usbmisc_imx6q_driver = {
138 .probe = usbmisc_imx6q_probe,
139 .remove = usbmisc_imx6q_remove,
140 .driver = {
141 .name = "usbmisc_imx6q",
142 .owner = THIS_MODULE,
143 .of_match_table = usbmisc_imx6q_dt_ids,
144 },
145};
146
147int __init usbmisc_imx6q_drv_init(void)
148{
149 return platform_driver_register(&usbmisc_imx6q_driver);
150}
151subsys_initcall(usbmisc_imx6q_drv_init);
152
153void __exit usbmisc_imx6q_drv_exit(void)
154{
155 platform_driver_unregister(&usbmisc_imx6q_driver);
156}
157module_exit(usbmisc_imx6q_drv_exit);
158
159MODULE_ALIAS("platform:usbmisc-imx6q");
160MODULE_LICENSE("GPL v2");
161MODULE_DESCRIPTION("driver for imx6q usb non-core registers");
162MODULE_AUTHOR("Richard Zhao <richard.zhao@freescale.com>");
diff --git a/drivers/usb/class/Kconfig b/drivers/usb/class/Kconfig
index 316aac8e4ca1..bb8b73682a70 100644
--- a/drivers/usb/class/Kconfig
+++ b/drivers/usb/class/Kconfig
@@ -2,11 +2,10 @@
2# USB Class driver configuration 2# USB Class driver configuration
3# 3#
4comment "USB Device Class drivers" 4comment "USB Device Class drivers"
5 depends on USB
6 5
7config USB_ACM 6config USB_ACM
8 tristate "USB Modem (CDC ACM) support" 7 tristate "USB Modem (CDC ACM) support"
9 depends on USB && TTY 8 depends on TTY
10 ---help--- 9 ---help---
11 This driver supports USB modems and ISDN adapters which support the 10 This driver supports USB modems and ISDN adapters which support the
12 Communication Device Class Abstract Control Model interface. 11 Communication Device Class Abstract Control Model interface.
@@ -21,7 +20,6 @@ config USB_ACM
21 20
22config USB_PRINTER 21config USB_PRINTER
23 tristate "USB Printer support" 22 tristate "USB Printer support"
24 depends on USB
25 help 23 help
26 Say Y here if you want to connect a USB printer to your computer's 24 Say Y here if you want to connect a USB printer to your computer's
27 USB port. 25 USB port.
@@ -31,7 +29,6 @@ config USB_PRINTER
31 29
32config USB_WDM 30config USB_WDM
33 tristate "USB Wireless Device Management support" 31 tristate "USB Wireless Device Management support"
34 depends on USB
35 ---help--- 32 ---help---
36 This driver supports the WMC Device Management functionality 33 This driver supports the WMC Device Management functionality
37 of cell phones compliant to the CDC WMC specification. You can use 34 of cell phones compliant to the CDC WMC specification. You can use
@@ -42,7 +39,6 @@ config USB_WDM
42 39
43config USB_TMC 40config USB_TMC
44 tristate "USB Test and Measurement Class support" 41 tristate "USB Test and Measurement Class support"
45 depends on USB
46 help 42 help
47 Say Y here if you want to connect a USB device that follows 43 Say Y here if you want to connect a USB device that follows
48 the USB.org specification for USB Test and Measurement devices 44 the USB.org specification for USB Test and Measurement devices
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index c77f7ae48f1c..171d7a9df3ae 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -828,14 +828,6 @@ static int acm_tty_ioctl(struct tty_struct *tty,
828 return rv; 828 return rv;
829} 829}
830 830
831static const __u32 acm_tty_speed[] = {
832 0, 50, 75, 110, 134, 150, 200, 300, 600,
833 1200, 1800, 2400, 4800, 9600, 19200, 38400,
834 57600, 115200, 230400, 460800, 500000, 576000,
835 921600, 1000000, 1152000, 1500000, 2000000,
836 2500000, 3000000, 3500000, 4000000
837};
838
839static void acm_tty_set_termios(struct tty_struct *tty, 831static void acm_tty_set_termios(struct tty_struct *tty,
840 struct ktermios *termios_old) 832 struct ktermios *termios_old)
841{ 833{
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 122d056d96d5..8a230f0ef77c 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16#include <linux/ioctl.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/mutex.h> 19#include <linux/mutex.h>
@@ -644,6 +645,22 @@ static int wdm_release(struct inode *inode, struct file *file)
644 return 0; 645 return 0;
645} 646}
646 647
648static long wdm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
649{
650 struct wdm_device *desc = file->private_data;
651 int rv = 0;
652
653 switch (cmd) {
654 case IOCTL_WDM_MAX_COMMAND:
655 if (copy_to_user((void __user *)arg, &desc->wMaxCommand, sizeof(desc->wMaxCommand)))
656 rv = -EFAULT;
657 break;
658 default:
659 rv = -ENOTTY;
660 }
661 return rv;
662}
663
647static const struct file_operations wdm_fops = { 664static const struct file_operations wdm_fops = {
648 .owner = THIS_MODULE, 665 .owner = THIS_MODULE,
649 .read = wdm_read, 666 .read = wdm_read,
@@ -652,6 +669,8 @@ static const struct file_operations wdm_fops = {
652 .flush = wdm_flush, 669 .flush = wdm_flush,
653 .release = wdm_release, 670 .release = wdm_release,
654 .poll = wdm_poll, 671 .poll = wdm_poll,
672 .unlocked_ioctl = wdm_ioctl,
673 .compat_ioctl = wdm_ioctl,
655 .llseek = noop_llseek, 674 .llseek = noop_llseek,
656}; 675};
657 676
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index 70d69d06054f..4c5506ae5e45 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -718,50 +718,32 @@ exit:
718 718
719static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data *data) 719static int usbtmc_ioctl_clear_out_halt(struct usbtmc_device_data *data)
720{ 720{
721 u8 *buffer;
722 int rv; 721 int rv;
723 722
724 buffer = kmalloc(2, GFP_KERNEL);
725 if (!buffer)
726 return -ENOMEM;
727
728 rv = usb_clear_halt(data->usb_dev, 723 rv = usb_clear_halt(data->usb_dev,
729 usb_sndbulkpipe(data->usb_dev, data->bulk_out)); 724 usb_sndbulkpipe(data->usb_dev, data->bulk_out));
730 725
731 if (rv < 0) { 726 if (rv < 0) {
732 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", 727 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n",
733 rv); 728 rv);
734 goto exit; 729 return rv;
735 } 730 }
736 rv = 0; 731 return 0;
737
738exit:
739 kfree(buffer);
740 return rv;
741} 732}
742 733
743static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data *data) 734static int usbtmc_ioctl_clear_in_halt(struct usbtmc_device_data *data)
744{ 735{
745 u8 *buffer;
746 int rv; 736 int rv;
747 737
748 buffer = kmalloc(2, GFP_KERNEL);
749 if (!buffer)
750 return -ENOMEM;
751
752 rv = usb_clear_halt(data->usb_dev, 738 rv = usb_clear_halt(data->usb_dev,
753 usb_rcvbulkpipe(data->usb_dev, data->bulk_in)); 739 usb_rcvbulkpipe(data->usb_dev, data->bulk_in));
754 740
755 if (rv < 0) { 741 if (rv < 0) {
756 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n", 742 dev_err(&data->usb_dev->dev, "usb_control_msg returned %d\n",
757 rv); 743 rv);
758 goto exit; 744 return rv;
759 } 745 }
760 rv = 0; 746 return 0;
761
762exit:
763 kfree(buffer);
764 return rv;
765} 747}
766 748
767static int get_capabilities(struct usbtmc_device_data *data) 749static int get_capabilities(struct usbtmc_device_data *data)
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index f70c1a1694ad..8772b3659296 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -3,7 +3,6 @@
3# 3#
4config USB_DEBUG 4config USB_DEBUG
5 bool "USB verbose debug messages" 5 bool "USB verbose debug messages"
6 depends on USB
7 help 6 help
8 Say Y here if you want the USB core & hub drivers to produce a bunch 7 Say Y here if you want the USB core & hub drivers to produce a bunch
9 of debug messages to the system log. Select this if you are having a 8 of debug messages to the system log. Select this if you are having a
@@ -11,7 +10,6 @@ config USB_DEBUG
11 10
12config USB_ANNOUNCE_NEW_DEVICES 11config USB_ANNOUNCE_NEW_DEVICES
13 bool "USB announce new devices" 12 bool "USB announce new devices"
14 depends on USB
15 default N 13 default N
16 help 14 help
17 Say Y here if you want the USB core to always announce the 15 Say Y here if you want the USB core to always announce the
@@ -25,11 +23,24 @@ config USB_ANNOUNCE_NEW_DEVICES
25 log, or have any doubts about this, say N here. 23 log, or have any doubts about this, say N here.
26 24
27comment "Miscellaneous USB options" 25comment "Miscellaneous USB options"
28 depends on USB 26
27config USB_DEFAULT_PERSIST
28 bool "Enable USB persist by default"
29 default y
30 help
31 Say N here if you don't want USB power session persistance
32 enabled by default. If you say N it will make suspended USB
33 devices that lose power get reenumerated as if they had been
34 unplugged, causing any mounted filesystems to be lost. The
35 persist feature can still be enabled for individual devices
36 through the power/persist sysfs node. See
37 Documentation/usb/persist.txt for more info.
38
39 If you have any questions about this, say Y here, only say N
40 if you know exactly what you are doing.
29 41
30config USB_DYNAMIC_MINORS 42config USB_DYNAMIC_MINORS
31 bool "Dynamic USB minor allocation" 43 bool "Dynamic USB minor allocation"
32 depends on USB
33 help 44 help
34 If you say Y here, the USB subsystem will use dynamic minor 45 If you say Y here, the USB subsystem will use dynamic minor
35 allocation for any device that uses the USB major number. 46 allocation for any device that uses the USB major number.
@@ -38,25 +49,8 @@ config USB_DYNAMIC_MINORS
38 49
39 If you are unsure about this, say N here. 50 If you are unsure about this, say N here.
40 51
41config USB_SUSPEND
42 bool "USB runtime power management (autosuspend) and wakeup"
43 depends on USB && PM_RUNTIME
44 help
45 If you say Y here, you can use driver calls or the sysfs
46 "power/control" file to enable or disable autosuspend for
47 individual USB peripherals (see
48 Documentation/usb/power-management.txt for more details).
49
50 Also, USB "remote wakeup" signaling is supported, whereby some
51 USB devices (like keyboards and network adapters) can wake up
52 their parent hub. That wakeup cascades up the USB tree, and
53 could wake the system from states like suspend-to-RAM.
54
55 If you are unsure about this, say N here.
56
57config USB_OTG 52config USB_OTG
58 bool "OTG support" 53 bool "OTG support"
59 depends on USB
60 depends on USB_SUSPEND 54 depends on USB_SUSPEND
61 default n 55 default n
62 help 56 help
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 8823e98989fe..caefc800f298 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -739,6 +739,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
739 index &= 0xff; 739 index &= 0xff;
740 switch (requesttype & USB_RECIP_MASK) { 740 switch (requesttype & USB_RECIP_MASK) {
741 case USB_RECIP_ENDPOINT: 741 case USB_RECIP_ENDPOINT:
742 if ((index & ~USB_DIR_IN) == 0)
743 return 0;
742 ret = findintfep(ps->dev, index); 744 ret = findintfep(ps->dev, index);
743 if (ret >= 0) 745 if (ret >= 0)
744 ret = checkintf(ps, ret); 746 ret = checkintf(ps, ret);
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index d938b2b99e31..6eab440e1542 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1196,9 +1196,14 @@ done:
1196 * 1196 *
1197 * This is the central routine for suspending USB devices. It calls the 1197 * This is the central routine for suspending USB devices. It calls the
1198 * suspend methods for all the interface drivers in @udev and then calls 1198 * suspend methods for all the interface drivers in @udev and then calls
1199 * the suspend method for @udev itself. If an error occurs at any stage, 1199 * the suspend method for @udev itself. When the routine is called in
1200 * all the interfaces which were suspended are resumed so that they remain 1200 * autosuspend, if an error occurs at any stage, all the interfaces
1201 * in the same state as the device. 1201 * which were suspended are resumed so that they remain in the same
1202 * state as the device, but when called from system sleep, all error
1203 * from suspend methods of interfaces and the non-root-hub device itself
1204 * are simply ignored, so all suspended interfaces are only resumed
1205 * to the device's state when @udev is root-hub and its suspend method
1206 * returns failure.
1202 * 1207 *
1203 * Autosuspend requests originating from a child device or an interface 1208 * Autosuspend requests originating from a child device or an interface
1204 * driver may be made without the protection of @udev's device lock, but 1209 * driver may be made without the protection of @udev's device lock, but
@@ -1248,10 +1253,12 @@ static int usb_suspend_both(struct usb_device *udev, pm_message_t msg)
1248 1253
1249 /* If the suspend failed, resume interfaces that did get suspended */ 1254 /* If the suspend failed, resume interfaces that did get suspended */
1250 if (status != 0) { 1255 if (status != 0) {
1251 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); 1256 if (udev->actconfig) {
1252 while (++i < n) { 1257 msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME);
1253 intf = udev->actconfig->interface[i]; 1258 while (++i < n) {
1254 usb_resume_interface(udev, intf, msg, 0); 1259 intf = udev->actconfig->interface[i];
1260 usb_resume_interface(udev, intf, msg, 0);
1261 }
1255 } 1262 }
1256 1263
1257 /* If the suspend succeeded then prevent any more URB submissions 1264 /* If the suspend succeeded then prevent any more URB submissions
@@ -1407,7 +1414,7 @@ int usb_resume(struct device *dev, pm_message_t msg)
1407 1414
1408#endif /* CONFIG_PM */ 1415#endif /* CONFIG_PM */
1409 1416
1410#ifdef CONFIG_USB_SUSPEND 1417#ifdef CONFIG_PM_RUNTIME
1411 1418
1412/** 1419/**
1413 * usb_enable_autosuspend - allow a USB device to be autosuspended 1420 * usb_enable_autosuspend - allow a USB device to be autosuspended
@@ -1775,7 +1782,7 @@ int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
1775 return ret; 1782 return ret;
1776} 1783}
1777 1784
1778#endif /* CONFIG_USB_SUSPEND */ 1785#endif /* CONFIG_PM_RUNTIME */
1779 1786
1780struct bus_type usb_bus_type = { 1787struct bus_type usb_bus_type = {
1781 .name = "usb", 1788 .name = "usb",
diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 271e761f563e..acbfeb0a0119 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -169,7 +169,7 @@ static int generic_probe(struct usb_device *udev)
169 c = usb_choose_configuration(udev); 169 c = usb_choose_configuration(udev);
170 if (c >= 0) { 170 if (c >= 0) {
171 err = usb_set_configuration(udev, c); 171 err = usb_set_configuration(udev, c);
172 if (err) { 172 if (err && err != -ENODEV) {
173 dev_err(&udev->dev, "can't set config #%d, error %d\n", 173 dev_err(&udev->dev, "can't set config #%d, error %d\n",
174 c, err); 174 c, err);
175 /* This need not be fatal. The user can try to 175 /* This need not be fatal. The user can try to
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c
index 2b487d4797bd..caeb8d6d39fb 100644
--- a/drivers/usb/core/hcd-pci.c
+++ b/drivers/usb/core/hcd-pci.c
@@ -37,119 +37,123 @@
37 37
38/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */ 38/* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
39 39
40#ifdef CONFIG_PM_SLEEP 40/*
41 41 * Coordinate handoffs between EHCI and companion controllers
42/* Coordinate handoffs between EHCI and companion controllers 42 * during EHCI probing and system resume.
43 * during system resume
44 */ 43 */
45 44
46static DEFINE_MUTEX(companions_mutex); 45static DECLARE_RWSEM(companions_rwsem);
47 46
48#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI 47#define CL_UHCI PCI_CLASS_SERIAL_USB_UHCI
49#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI 48#define CL_OHCI PCI_CLASS_SERIAL_USB_OHCI
50#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI 49#define CL_EHCI PCI_CLASS_SERIAL_USB_EHCI
51 50
52enum companion_action { 51static inline int is_ohci_or_uhci(struct pci_dev *pdev)
53 SET_HS_COMPANION, CLEAR_HS_COMPANION, WAIT_FOR_COMPANIONS 52{
54}; 53 return pdev->class == CL_OHCI || pdev->class == CL_UHCI;
54}
55
56typedef void (*companion_fn)(struct pci_dev *pdev, struct usb_hcd *hcd,
57 struct pci_dev *companion, struct usb_hcd *companion_hcd);
55 58
56static void companion_common(struct pci_dev *pdev, struct usb_hcd *hcd, 59/* Iterate over PCI devices in the same slot as pdev and call fn for each */
57 enum companion_action action) 60static void for_each_companion(struct pci_dev *pdev, struct usb_hcd *hcd,
61 companion_fn fn)
58{ 62{
59 struct pci_dev *companion; 63 struct pci_dev *companion;
60 struct usb_hcd *companion_hcd; 64 struct usb_hcd *companion_hcd;
61 unsigned int slot = PCI_SLOT(pdev->devfn); 65 unsigned int slot = PCI_SLOT(pdev->devfn);
62 66
63 /* Iterate through other PCI functions in the same slot. 67 /*
64 * If pdev is OHCI or UHCI then we are looking for EHCI, and 68 * Iterate through other PCI functions in the same slot.
65 * vice versa. 69 * If the function's drvdata isn't set then it isn't bound to
70 * a USB host controller driver, so skip it.
66 */ 71 */
67 companion = NULL; 72 companion = NULL;
68 for_each_pci_dev(companion) { 73 for_each_pci_dev(companion) {
69 if (companion->bus != pdev->bus || 74 if (companion->bus != pdev->bus ||
70 PCI_SLOT(companion->devfn) != slot) 75 PCI_SLOT(companion->devfn) != slot)
71 continue; 76 continue;
72
73 companion_hcd = pci_get_drvdata(companion); 77 companion_hcd = pci_get_drvdata(companion);
74 if (!companion_hcd) 78 if (!companion_hcd)
75 continue; 79 continue;
76 80 fn(pdev, hcd, companion, companion_hcd);
77 /* For SET_HS_COMPANION, store a pointer to the EHCI bus in
78 * the OHCI/UHCI companion bus structure.
79 * For CLEAR_HS_COMPANION, clear the pointer to the EHCI bus
80 * in the OHCI/UHCI companion bus structure.
81 * For WAIT_FOR_COMPANIONS, wait until the OHCI/UHCI
82 * companion controllers have fully resumed.
83 */
84
85 if ((pdev->class == CL_OHCI || pdev->class == CL_UHCI) &&
86 companion->class == CL_EHCI) {
87 /* action must be SET_HS_COMPANION */
88 dev_dbg(&companion->dev, "HS companion for %s\n",
89 dev_name(&pdev->dev));
90 hcd->self.hs_companion = &companion_hcd->self;
91
92 } else if (pdev->class == CL_EHCI &&
93 (companion->class == CL_OHCI ||
94 companion->class == CL_UHCI)) {
95 switch (action) {
96 case SET_HS_COMPANION:
97 dev_dbg(&pdev->dev, "HS companion for %s\n",
98 dev_name(&companion->dev));
99 companion_hcd->self.hs_companion = &hcd->self;
100 break;
101 case CLEAR_HS_COMPANION:
102 companion_hcd->self.hs_companion = NULL;
103 break;
104 case WAIT_FOR_COMPANIONS:
105 device_pm_wait_for_dev(&pdev->dev,
106 &companion->dev);
107 break;
108 }
109 }
110 } 81 }
111} 82}
112 83
113static void set_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) 84/*
85 * We're about to add an EHCI controller, which will unceremoniously grab
86 * all the port connections away from its companions. To prevent annoying
87 * error messages, lock the companion's root hub and gracefully unconfigure
88 * it beforehand. Leave it locked until the EHCI controller is all set.
89 */
90static void ehci_pre_add(struct pci_dev *pdev, struct usb_hcd *hcd,
91 struct pci_dev *companion, struct usb_hcd *companion_hcd)
114{ 92{
115 mutex_lock(&companions_mutex); 93 struct usb_device *udev;
116 dev_set_drvdata(&pdev->dev, hcd); 94
117 companion_common(pdev, hcd, SET_HS_COMPANION); 95 if (is_ohci_or_uhci(companion)) {
118 mutex_unlock(&companions_mutex); 96 udev = companion_hcd->self.root_hub;
97 usb_lock_device(udev);
98 usb_set_configuration(udev, 0);
99 }
119} 100}
120 101
121static void clear_hs_companion(struct pci_dev *pdev, struct usb_hcd *hcd) 102/*
103 * Adding the EHCI controller has either succeeded or failed. Set the
104 * companion pointer accordingly, and in either case, reconfigure and
105 * unlock the root hub.
106 */
107static void ehci_post_add(struct pci_dev *pdev, struct usb_hcd *hcd,
108 struct pci_dev *companion, struct usb_hcd *companion_hcd)
122{ 109{
123 mutex_lock(&companions_mutex); 110 struct usb_device *udev;
124 dev_set_drvdata(&pdev->dev, NULL);
125 111
126 /* If pdev is OHCI or UHCI, just clear its hs_companion pointer */ 112 if (is_ohci_or_uhci(companion)) {
127 if (pdev->class == CL_OHCI || pdev->class == CL_UHCI) 113 if (dev_get_drvdata(&pdev->dev)) { /* Succeeded */
128 hcd->self.hs_companion = NULL; 114 dev_dbg(&pdev->dev, "HS companion for %s\n",
115 dev_name(&companion->dev));
116 companion_hcd->self.hs_companion = &hcd->self;
117 }
118 udev = companion_hcd->self.root_hub;
119 usb_set_configuration(udev, 1);
120 usb_unlock_device(udev);
121 }
122}
129 123
130 /* Otherwise search for companion buses and clear their pointers */ 124/*
131 else 125 * We just added a non-EHCI controller. Find the EHCI controller to
132 companion_common(pdev, hcd, CLEAR_HS_COMPANION); 126 * which it is a companion, and store a pointer to the bus structure.
133 mutex_unlock(&companions_mutex); 127 */
128static void non_ehci_add(struct pci_dev *pdev, struct usb_hcd *hcd,
129 struct pci_dev *companion, struct usb_hcd *companion_hcd)
130{
131 if (is_ohci_or_uhci(pdev) && companion->class == CL_EHCI) {
132 dev_dbg(&pdev->dev, "FS/LS companion for %s\n",
133 dev_name(&companion->dev));
134 hcd->self.hs_companion = &companion_hcd->self;
135 }
134} 136}
135 137
136static void wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd) 138/* We are removing an EHCI controller. Clear the companions' pointers. */
139static void ehci_remove(struct pci_dev *pdev, struct usb_hcd *hcd,
140 struct pci_dev *companion, struct usb_hcd *companion_hcd)
137{ 141{
138 /* Only EHCI controllers need to wait. 142 if (is_ohci_or_uhci(companion))
139 * No locking is needed because a controller cannot be resumed 143 companion_hcd->self.hs_companion = NULL;
140 * while one of its companions is getting unbound.
141 */
142 if (pdev->class == CL_EHCI)
143 companion_common(pdev, hcd, WAIT_FOR_COMPANIONS);
144} 144}
145 145
146#else /* !CONFIG_PM_SLEEP */ 146#ifdef CONFIG_PM
147 147
148static inline void set_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} 148/* An EHCI controller must wait for its companions before resuming. */
149static inline void clear_hs_companion(struct pci_dev *d, struct usb_hcd *h) {} 149static void ehci_wait_for_companions(struct pci_dev *pdev, struct usb_hcd *hcd,
150static inline void wait_for_companions(struct pci_dev *d, struct usb_hcd *h) {} 150 struct pci_dev *companion, struct usb_hcd *companion_hcd)
151{
152 if (is_ohci_or_uhci(companion))
153 device_pm_wait_for_dev(&pdev->dev, &companion->dev);
154}
151 155
152#endif /* !CONFIG_PM_SLEEP */ 156#endif /* CONFIG_PM */
153 157
154/*-------------------------------------------------------------------------*/ 158/*-------------------------------------------------------------------------*/
155 159
@@ -217,7 +221,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
217 driver->description)) { 221 driver->description)) {
218 dev_dbg(&dev->dev, "controller already in use\n"); 222 dev_dbg(&dev->dev, "controller already in use\n");
219 retval = -EBUSY; 223 retval = -EBUSY;
220 goto clear_companion; 224 goto put_hcd;
221 } 225 }
222 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); 226 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
223 if (hcd->regs == NULL) { 227 if (hcd->regs == NULL) {
@@ -244,16 +248,35 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
244 if (region == PCI_ROM_RESOURCE) { 248 if (region == PCI_ROM_RESOURCE) {
245 dev_dbg(&dev->dev, "no i/o regions available\n"); 249 dev_dbg(&dev->dev, "no i/o regions available\n");
246 retval = -EBUSY; 250 retval = -EBUSY;
247 goto clear_companion; 251 goto put_hcd;
248 } 252 }
249 } 253 }
250 254
251 pci_set_master(dev); 255 pci_set_master(dev);
252 256
253 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED); 257 /* Note: dev_set_drvdata must be called while holding the rwsem */
258 if (dev->class == CL_EHCI) {
259 down_write(&companions_rwsem);
260 dev_set_drvdata(&dev->dev, hcd);
261 for_each_companion(dev, hcd, ehci_pre_add);
262 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
263 if (retval != 0)
264 dev_set_drvdata(&dev->dev, NULL);
265 for_each_companion(dev, hcd, ehci_post_add);
266 up_write(&companions_rwsem);
267 } else {
268 down_read(&companions_rwsem);
269 dev_set_drvdata(&dev->dev, hcd);
270 retval = usb_add_hcd(hcd, hcd_irq, IRQF_SHARED);
271 if (retval != 0)
272 dev_set_drvdata(&dev->dev, NULL);
273 else
274 for_each_companion(dev, hcd, non_ehci_add);
275 up_read(&companions_rwsem);
276 }
277
254 if (retval != 0) 278 if (retval != 0)
255 goto unmap_registers; 279 goto unmap_registers;
256 set_hs_companion(dev, hcd);
257 280
258 if (pci_dev_run_wake(dev)) 281 if (pci_dev_run_wake(dev))
259 pm_runtime_put_noidle(&dev->dev); 282 pm_runtime_put_noidle(&dev->dev);
@@ -266,8 +289,7 @@ release_mem_region:
266 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 289 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
267 } else 290 } else
268 release_region(hcd->rsrc_start, hcd->rsrc_len); 291 release_region(hcd->rsrc_start, hcd->rsrc_len);
269clear_companion: 292put_hcd:
270 clear_hs_companion(dev, hcd);
271 usb_put_hcd(hcd); 293 usb_put_hcd(hcd);
272disable_pci: 294disable_pci:
273 pci_disable_device(dev); 295 pci_disable_device(dev);
@@ -310,14 +332,29 @@ void usb_hcd_pci_remove(struct pci_dev *dev)
310 usb_hcd_irq(0, hcd); 332 usb_hcd_irq(0, hcd);
311 local_irq_enable(); 333 local_irq_enable();
312 334
313 usb_remove_hcd(hcd); 335 /* Note: dev_set_drvdata must be called while holding the rwsem */
336 if (dev->class == CL_EHCI) {
337 down_write(&companions_rwsem);
338 for_each_companion(dev, hcd, ehci_remove);
339 usb_remove_hcd(hcd);
340 dev_set_drvdata(&dev->dev, NULL);
341 up_write(&companions_rwsem);
342 } else {
343 /* Not EHCI; just clear the companion pointer */
344 down_read(&companions_rwsem);
345 hcd->self.hs_companion = NULL;
346 usb_remove_hcd(hcd);
347 dev_set_drvdata(&dev->dev, NULL);
348 up_read(&companions_rwsem);
349 }
350
314 if (hcd->driver->flags & HCD_MEMORY) { 351 if (hcd->driver->flags & HCD_MEMORY) {
315 iounmap(hcd->regs); 352 iounmap(hcd->regs);
316 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 353 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
317 } else { 354 } else {
318 release_region(hcd->rsrc_start, hcd->rsrc_len); 355 release_region(hcd->rsrc_start, hcd->rsrc_len);
319 } 356 }
320 clear_hs_companion(dev, hcd); 357
321 usb_put_hcd(hcd); 358 usb_put_hcd(hcd);
322 pci_disable_device(dev); 359 pci_disable_device(dev);
323} 360}
@@ -463,8 +500,15 @@ static int resume_common(struct device *dev, int event)
463 pci_set_master(pci_dev); 500 pci_set_master(pci_dev);
464 501
465 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) { 502 if (hcd->driver->pci_resume && !HCD_DEAD(hcd)) {
466 if (event != PM_EVENT_AUTO_RESUME) 503
467 wait_for_companions(pci_dev, hcd); 504 /*
505 * Only EHCI controllers have to wait for their companions.
506 * No locking is needed because PCI controller drivers do not
507 * get unbound during system resume.
508 */
509 if (pci_dev->class == CL_EHCI && event != PM_EVENT_AUTO_RESUME)
510 for_each_companion(pci_dev, hcd,
511 ehci_wait_for_companions);
468 512
469 retval = hcd->driver->pci_resume(hcd, 513 retval = hcd->driver->pci_resume(hcd,
470 event == PM_EVENT_RESTORE); 514 event == PM_EVENT_RESTORE);
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index f9ec44cbb82f..d53547d2e4c7 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2125,7 +2125,7 @@ int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
2125 2125
2126#endif /* CONFIG_PM */ 2126#endif /* CONFIG_PM */
2127 2127
2128#ifdef CONFIG_USB_SUSPEND 2128#ifdef CONFIG_PM_RUNTIME
2129 2129
2130/* Workqueue routine for root-hub remote wakeup */ 2130/* Workqueue routine for root-hub remote wakeup */
2131static void hcd_resume_work(struct work_struct *work) 2131static void hcd_resume_work(struct work_struct *work)
@@ -2160,7 +2160,7 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd)
2160} 2160}
2161EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); 2161EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub);
2162 2162
2163#endif /* CONFIG_USB_SUSPEND */ 2163#endif /* CONFIG_PM_RUNTIME */
2164 2164
2165/*-------------------------------------------------------------------------*/ 2165/*-------------------------------------------------------------------------*/
2166 2166
@@ -2336,7 +2336,7 @@ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,
2336 init_timer(&hcd->rh_timer); 2336 init_timer(&hcd->rh_timer);
2337 hcd->rh_timer.function = rh_timer_func; 2337 hcd->rh_timer.function = rh_timer_func;
2338 hcd->rh_timer.data = (unsigned long) hcd; 2338 hcd->rh_timer.data = (unsigned long) hcd;
2339#ifdef CONFIG_USB_SUSPEND 2339#ifdef CONFIG_PM_RUNTIME
2340 INIT_WORK(&hcd->wakeup_work, hcd_resume_work); 2340 INIT_WORK(&hcd->wakeup_work, hcd_resume_work);
2341#endif 2341#endif
2342 2342
@@ -2590,7 +2590,7 @@ error_create_attr_group:
2590 hcd->rh_registered = 0; 2590 hcd->rh_registered = 0;
2591 spin_unlock_irq(&hcd_root_hub_lock); 2591 spin_unlock_irq(&hcd_root_hub_lock);
2592 2592
2593#ifdef CONFIG_USB_SUSPEND 2593#ifdef CONFIG_PM_RUNTIME
2594 cancel_work_sync(&hcd->wakeup_work); 2594 cancel_work_sync(&hcd->wakeup_work);
2595#endif 2595#endif
2596 mutex_lock(&usb_bus_list_lock); 2596 mutex_lock(&usb_bus_list_lock);
@@ -2645,7 +2645,7 @@ void usb_remove_hcd(struct usb_hcd *hcd)
2645 hcd->rh_registered = 0; 2645 hcd->rh_registered = 0;
2646 spin_unlock_irq (&hcd_root_hub_lock); 2646 spin_unlock_irq (&hcd_root_hub_lock);
2647 2647
2648#ifdef CONFIG_USB_SUSPEND 2648#ifdef CONFIG_PM_RUNTIME
2649 cancel_work_sync(&hcd->wakeup_work); 2649 cancel_work_sync(&hcd->wakeup_work);
2650#endif 2650#endif
2651 2651
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 5480352f984d..feef9351463d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -555,8 +555,9 @@ static int hub_port_status(struct usb_hub *hub, int port1,
555 mutex_lock(&hub->status_mutex); 555 mutex_lock(&hub->status_mutex);
556 ret = get_port_status(hub->hdev, port1, &hub->status->port); 556 ret = get_port_status(hub->hdev, port1, &hub->status->port);
557 if (ret < 4) { 557 if (ret < 4) {
558 dev_err(hub->intfdev, 558 if (ret != -ENODEV)
559 "%s failed (err = %d)\n", __func__, ret); 559 dev_err(hub->intfdev,
560 "%s failed (err = %d)\n", __func__, ret);
560 if (ret >= 0) 561 if (ret >= 0)
561 ret = -EIO; 562 ret = -EIO;
562 } else { 563 } else {
@@ -699,7 +700,7 @@ static void hub_tt_work(struct work_struct *work)
699 /* drop lock so HCD can concurrently report other TT errors */ 700 /* drop lock so HCD can concurrently report other TT errors */
700 spin_unlock_irqrestore (&hub->tt.lock, flags); 701 spin_unlock_irqrestore (&hub->tt.lock, flags);
701 status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt); 702 status = hub_clear_tt_buffer (hdev, clear->devinfo, clear->tt);
702 if (status) 703 if (status && status != -ENODEV)
703 dev_err (&hdev->dev, 704 dev_err (&hdev->dev,
704 "clear tt %d (%04x) error %d\n", 705 "clear tt %d (%04x) error %d\n",
705 clear->tt, clear->devinfo, status); 706 clear->tt, clear->devinfo, status);
@@ -837,10 +838,11 @@ static int hub_hub_status(struct usb_hub *hub,
837 838
838 mutex_lock(&hub->status_mutex); 839 mutex_lock(&hub->status_mutex);
839 ret = get_hub_status(hub->hdev, &hub->status->hub); 840 ret = get_hub_status(hub->hdev, &hub->status->hub);
840 if (ret < 0) 841 if (ret < 0) {
841 dev_err (hub->intfdev, 842 if (ret != -ENODEV)
842 "%s failed (err = %d)\n", __func__, ret); 843 dev_err(hub->intfdev,
843 else { 844 "%s failed (err = %d)\n", __func__, ret);
845 } else {
844 *status = le16_to_cpu(hub->status->hub.wHubStatus); 846 *status = le16_to_cpu(hub->status->hub.wHubStatus);
845 *change = le16_to_cpu(hub->status->hub.wHubChange); 847 *change = le16_to_cpu(hub->status->hub.wHubChange);
846 ret = 0; 848 ret = 0;
@@ -877,11 +879,8 @@ static int hub_usb3_port_disable(struct usb_hub *hub, int port1)
877 return -EINVAL; 879 return -EINVAL;
878 880
879 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED); 881 ret = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_SS_DISABLED);
880 if (ret) { 882 if (ret)
881 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
882 port1, ret);
883 return ret; 883 return ret;
884 }
885 884
886 /* Wait for the link to enter the disabled state. */ 885 /* Wait for the link to enter the disabled state. */
887 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) { 886 for (total_time = 0; ; total_time += HUB_DEBOUNCE_STEP) {
@@ -918,7 +917,7 @@ static int hub_port_disable(struct usb_hub *hub, int port1, int set_state)
918 ret = usb_clear_port_feature(hdev, port1, 917 ret = usb_clear_port_feature(hdev, port1,
919 USB_PORT_FEAT_ENABLE); 918 USB_PORT_FEAT_ENABLE);
920 } 919 }
921 if (ret) 920 if (ret && ret != -ENODEV)
922 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n", 921 dev_err(hub->intfdev, "cannot disable port %d (err = %d)\n",
923 port1, ret); 922 port1, ret);
924 return ret; 923 return ret;
@@ -1317,6 +1316,10 @@ static int hub_configure(struct usb_hub *hub,
1317 message = "hub has too many ports!"; 1316 message = "hub has too many ports!";
1318 ret = -ENODEV; 1317 ret = -ENODEV;
1319 goto fail; 1318 goto fail;
1319 } else if (hub->descriptor->bNbrPorts == 0) {
1320 message = "hub doesn't have any ports!";
1321 ret = -ENODEV;
1322 goto fail;
1320 } 1323 }
1321 1324
1322 hdev->maxchild = hub->descriptor->bNbrPorts; 1325 hdev->maxchild = hub->descriptor->bNbrPorts;
@@ -2192,8 +2195,9 @@ static int usb_enumerate_device(struct usb_device *udev)
2192 if (udev->config == NULL) { 2195 if (udev->config == NULL) {
2193 err = usb_get_configuration(udev); 2196 err = usb_get_configuration(udev);
2194 if (err < 0) { 2197 if (err < 0) {
2195 dev_err(&udev->dev, "can't read configurations, error %d\n", 2198 if (err != -ENODEV)
2196 err); 2199 dev_err(&udev->dev, "can't read configurations, error %d\n",
2200 err);
2197 return err; 2201 return err;
2198 } 2202 }
2199 } 2203 }
@@ -2640,14 +2644,16 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2640 status = set_port_feature(hub->hdev, port1, (warm ? 2644 status = set_port_feature(hub->hdev, port1, (warm ?
2641 USB_PORT_FEAT_BH_PORT_RESET : 2645 USB_PORT_FEAT_BH_PORT_RESET :
2642 USB_PORT_FEAT_RESET)); 2646 USB_PORT_FEAT_RESET));
2643 if (status) { 2647 if (status == -ENODEV) {
2648 ; /* The hub is gone */
2649 } else if (status) {
2644 dev_err(hub->intfdev, 2650 dev_err(hub->intfdev,
2645 "cannot %sreset port %d (err = %d)\n", 2651 "cannot %sreset port %d (err = %d)\n",
2646 warm ? "warm " : "", port1, status); 2652 warm ? "warm " : "", port1, status);
2647 } else { 2653 } else {
2648 status = hub_port_wait_reset(hub, port1, udev, delay, 2654 status = hub_port_wait_reset(hub, port1, udev, delay,
2649 warm); 2655 warm);
2650 if (status && status != -ENOTCONN) 2656 if (status && status != -ENOTCONN && status != -ENODEV)
2651 dev_dbg(hub->intfdev, 2657 dev_dbg(hub->intfdev,
2652 "port_wait_reset: err = %d\n", 2658 "port_wait_reset: err = %d\n",
2653 status); 2659 status);
@@ -2821,7 +2827,7 @@ void usb_enable_ltm(struct usb_device *udev)
2821} 2827}
2822EXPORT_SYMBOL_GPL(usb_enable_ltm); 2828EXPORT_SYMBOL_GPL(usb_enable_ltm);
2823 2829
2824#ifdef CONFIG_USB_SUSPEND 2830#ifdef CONFIG_PM
2825/* 2831/*
2826 * usb_disable_function_remotewakeup - disable usb3.0 2832 * usb_disable_function_remotewakeup - disable usb3.0
2827 * device's function remote wakeup 2833 * device's function remote wakeup
@@ -2880,9 +2886,11 @@ static int usb_disable_function_remotewakeup(struct usb_device *udev)
2880 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd 2886 * Linux (2.6) currently has NO mechanisms to initiate that: no khubd
2881 * timer, no SRP, no requests through sysfs. 2887 * timer, no SRP, no requests through sysfs.
2882 * 2888 *
2883 * If CONFIG_USB_SUSPEND isn't enabled, devices only really suspend when 2889 * If Runtime PM isn't enabled or used, non-SuperSpeed devices really get
2884 * the root hub for their bus goes into global suspend ... so we don't 2890 * suspended only when their bus goes into global suspend (i.e., the root
2885 * (falsely) update the device power state to say it suspended. 2891 * hub is suspended). Nevertheless, we change @udev->state to
2892 * USB_STATE_SUSPENDED as this is the device's "logical" state. The actual
2893 * upstream port setting is stored in @udev->port_is_suspended.
2886 * 2894 *
2887 * Returns 0 on success, else negative errno. 2895 * Returns 0 on success, else negative errno.
2888 */ 2896 */
@@ -2893,6 +2901,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2893 enum pm_qos_flags_status pm_qos_stat; 2901 enum pm_qos_flags_status pm_qos_stat;
2894 int port1 = udev->portnum; 2902 int port1 = udev->portnum;
2895 int status; 2903 int status;
2904 bool really_suspend = true;
2896 2905
2897 /* enable remote wakeup when appropriate; this lets the device 2906 /* enable remote wakeup when appropriate; this lets the device
2898 * wake up the upstream hub (including maybe the root hub). 2907 * wake up the upstream hub (including maybe the root hub).
@@ -2949,9 +2958,19 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2949 /* see 7.1.7.6 */ 2958 /* see 7.1.7.6 */
2950 if (hub_is_superspeed(hub->hdev)) 2959 if (hub_is_superspeed(hub->hdev))
2951 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3); 2960 status = hub_set_port_link_state(hub, port1, USB_SS_PORT_LS_U3);
2952 else 2961 else if (PMSG_IS_AUTO(msg))
2953 status = set_port_feature(hub->hdev, port1, 2962 status = set_port_feature(hub->hdev, port1,
2954 USB_PORT_FEAT_SUSPEND); 2963 USB_PORT_FEAT_SUSPEND);
2964 /*
2965 * For system suspend, we do not need to enable the suspend feature
2966 * on individual USB-2 ports. The devices will automatically go
2967 * into suspend a few ms after the root hub stops sending packets.
2968 * The USB 2.0 spec calls this "global suspend".
2969 */
2970 else {
2971 really_suspend = false;
2972 status = 0;
2973 }
2955 if (status) { 2974 if (status) {
2956 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", 2975 dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n",
2957 port1, status); 2976 port1, status);
@@ -2987,8 +3006,10 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
2987 (PMSG_IS_AUTO(msg) ? "auto-" : ""), 3006 (PMSG_IS_AUTO(msg) ? "auto-" : ""),
2988 udev->do_remote_wakeup); 3007 udev->do_remote_wakeup);
2989 usb_set_device_state(udev, USB_STATE_SUSPENDED); 3008 usb_set_device_state(udev, USB_STATE_SUSPENDED);
2990 udev->port_is_suspended = 1; 3009 if (really_suspend) {
2991 msleep(10); 3010 udev->port_is_suspended = 1;
3011 msleep(10);
3012 }
2992 } 3013 }
2993 3014
2994 /* 3015 /*
@@ -3226,6 +3247,10 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3226 return status; 3247 return status;
3227} 3248}
3228 3249
3250#endif /* CONFIG_PM */
3251
3252#ifdef CONFIG_PM_RUNTIME
3253
3229/* caller has locked udev */ 3254/* caller has locked udev */
3230int usb_remote_wakeup(struct usb_device *udev) 3255int usb_remote_wakeup(struct usb_device *udev)
3231{ 3256{
@@ -3242,38 +3267,6 @@ int usb_remote_wakeup(struct usb_device *udev)
3242 return status; 3267 return status;
3243} 3268}
3244 3269
3245#else /* CONFIG_USB_SUSPEND */
3246
3247/* When CONFIG_USB_SUSPEND isn't set, we never suspend or resume any ports. */
3248
3249int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
3250{
3251 return 0;
3252}
3253
3254/* However we may need to do a reset-resume */
3255
3256int usb_port_resume(struct usb_device *udev, pm_message_t msg)
3257{
3258 struct usb_hub *hub = usb_hub_to_struct_hub(udev->parent);
3259 int port1 = udev->portnum;
3260 int status;
3261 u16 portchange, portstatus;
3262
3263 status = hub_port_status(hub, port1, &portstatus, &portchange);
3264 status = check_port_resume_type(udev,
3265 hub, port1, status, portchange, portstatus);
3266
3267 if (status) {
3268 dev_dbg(&udev->dev, "can't resume, status %d\n", status);
3269 hub_port_logical_disconnect(hub, port1);
3270 } else if (udev->reset_resume) {
3271 dev_dbg(&udev->dev, "reset-resume\n");
3272 status = usb_reset_and_verify_device(udev);
3273 }
3274 return status;
3275}
3276
3277#endif 3270#endif
3278 3271
3279static int check_ports_changed(struct usb_hub *hub) 3272static int check_ports_changed(struct usb_hub *hub)
@@ -4090,9 +4083,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4090 goto fail; 4083 goto fail;
4091 } 4084 }
4092 if (r) { 4085 if (r) {
4093 dev_err(&udev->dev, 4086 if (r != -ENODEV)
4094 "device descriptor read/64, error %d\n", 4087 dev_err(&udev->dev, "device descriptor read/64, error %d\n",
4095 r); 4088 r);
4096 retval = -EMSGSIZE; 4089 retval = -EMSGSIZE;
4097 continue; 4090 continue;
4098 } 4091 }
@@ -4112,9 +4105,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4112 msleep(200); 4105 msleep(200);
4113 } 4106 }
4114 if (retval < 0) { 4107 if (retval < 0) {
4115 dev_err(&udev->dev, 4108 if (retval != -ENODEV)
4116 "device not accepting address %d, error %d\n", 4109 dev_err(&udev->dev, "device not accepting address %d, error %d\n",
4117 devnum, retval); 4110 devnum, retval);
4118 goto fail; 4111 goto fail;
4119 } 4112 }
4120 if (udev->speed == USB_SPEED_SUPER) { 4113 if (udev->speed == USB_SPEED_SUPER) {
@@ -4136,7 +4129,8 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4136 4129
4137 retval = usb_get_device_descriptor(udev, 8); 4130 retval = usb_get_device_descriptor(udev, 8);
4138 if (retval < 8) { 4131 if (retval < 8) {
4139 dev_err(&udev->dev, 4132 if (retval != -ENODEV)
4133 dev_err(&udev->dev,
4140 "device descriptor read/8, error %d\n", 4134 "device descriptor read/8, error %d\n",
4141 retval); 4135 retval);
4142 if (retval >= 0) 4136 if (retval >= 0)
@@ -4190,8 +4184,9 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4190 4184
4191 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE); 4185 retval = usb_get_device_descriptor(udev, USB_DT_DEVICE_SIZE);
4192 if (retval < (signed)sizeof(udev->descriptor)) { 4186 if (retval < (signed)sizeof(udev->descriptor)) {
4193 dev_err(&udev->dev, "device descriptor read/all, error %d\n", 4187 if (retval != -ENODEV)
4194 retval); 4188 dev_err(&udev->dev, "device descriptor read/all, error %d\n",
4189 retval);
4195 if (retval >= 0) 4190 if (retval >= 0)
4196 retval = -ENOMSG; 4191 retval = -ENOMSG;
4197 goto fail; 4192 goto fail;
@@ -4333,7 +4328,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4333 if (portstatus & USB_PORT_STAT_ENABLE) { 4328 if (portstatus & USB_PORT_STAT_ENABLE) {
4334 status = 0; /* Nothing to do */ 4329 status = 0; /* Nothing to do */
4335 4330
4336#ifdef CONFIG_USB_SUSPEND 4331#ifdef CONFIG_PM_RUNTIME
4337 } else if (udev->state == USB_STATE_SUSPENDED && 4332 } else if (udev->state == USB_STATE_SUSPENDED &&
4338 udev->persist_enabled) { 4333 udev->persist_enabled) {
4339 /* For a suspended device, treat this as a 4334 /* For a suspended device, treat this as a
@@ -4373,7 +4368,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4373 USB_PORT_STAT_C_ENABLE)) { 4368 USB_PORT_STAT_C_ENABLE)) {
4374 status = hub_port_debounce_be_stable(hub, port1); 4369 status = hub_port_debounce_be_stable(hub, port1);
4375 if (status < 0) { 4370 if (status < 0) {
4376 if (printk_ratelimit()) 4371 if (status != -ENODEV && printk_ratelimit())
4377 dev_err(hub_dev, "connect-debounce failed, " 4372 dev_err(hub_dev, "connect-debounce failed, "
4378 "port %d disabled\n", port1); 4373 "port %d disabled\n", port1);
4379 portstatus &= ~USB_PORT_STAT_CONNECTION; 4374 portstatus &= ~USB_PORT_STAT_CONNECTION;
@@ -4402,6 +4397,7 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
4402 else 4397 else
4403 unit_load = 100; 4398 unit_load = 100;
4404 4399
4400 status = 0;
4405 for (i = 0; i < SET_CONFIG_TRIES; i++) { 4401 for (i = 0; i < SET_CONFIG_TRIES; i++) {
4406 4402
4407 /* reallocate for each attempt, since references 4403 /* reallocate for each attempt, since references
@@ -4526,9 +4522,11 @@ loop:
4526 } 4522 }
4527 if (hub->hdev->parent || 4523 if (hub->hdev->parent ||
4528 !hcd->driver->port_handed_over || 4524 !hcd->driver->port_handed_over ||
4529 !(hcd->driver->port_handed_over)(hcd, port1)) 4525 !(hcd->driver->port_handed_over)(hcd, port1)) {
4530 dev_err(hub_dev, "unable to enumerate USB device on port %d\n", 4526 if (status != -ENOTCONN && status != -ENODEV)
4531 port1); 4527 dev_err(hub_dev, "unable to enumerate USB device on port %d\n",
4528 port1);
4529 }
4532 4530
4533done: 4531done:
4534 hub_port_disable(hub, port1, 1); 4532 hub_port_disable(hub, port1, 1);
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 65d4e55552c6..b8bad294eeb8 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -70,7 +70,7 @@ static void usb_port_device_release(struct device *dev)
70 kfree(port_dev); 70 kfree(port_dev);
71} 71}
72 72
73#ifdef CONFIG_USB_SUSPEND 73#ifdef CONFIG_PM_RUNTIME
74static int usb_port_runtime_resume(struct device *dev) 74static int usb_port_runtime_resume(struct device *dev)
75{ 75{
76 struct usb_port *port_dev = to_usb_port(dev); 76 struct usb_port *port_dev = to_usb_port(dev);
@@ -138,7 +138,7 @@ static int usb_port_runtime_suspend(struct device *dev)
138#endif 138#endif
139 139
140static const struct dev_pm_ops usb_port_pm_ops = { 140static const struct dev_pm_ops usb_port_pm_ops = {
141#ifdef CONFIG_USB_SUSPEND 141#ifdef CONFIG_PM_RUNTIME
142 .runtime_suspend = usb_port_runtime_suspend, 142 .runtime_suspend = usb_port_runtime_suspend,
143 .runtime_resume = usb_port_runtime_resume, 143 .runtime_resume = usb_port_runtime_resume,
144 .runtime_idle = pm_generic_runtime_idle, 144 .runtime_idle = pm_generic_runtime_idle,
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 3113c1d71442..ab5638d9c707 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -201,20 +201,14 @@ void usb_detect_quirks(struct usb_device *udev)
201 dev_dbg(&udev->dev, "USB quirks for this device: %x\n", 201 dev_dbg(&udev->dev, "USB quirks for this device: %x\n",
202 udev->quirks); 202 udev->quirks);
203 203
204 /* For the present, all devices default to USB-PERSIST enabled */ 204#ifdef CONFIG_USB_DEFAULT_PERSIST
205#if 0 /* was: #ifdef CONFIG_PM */ 205 if (!(udev->quirks & USB_QUIRK_RESET))
206 /* Hubs are automatically enabled for USB-PERSIST */
207 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
208 udev->persist_enabled = 1; 206 udev->persist_enabled = 1;
209
210#else 207#else
211 /* In the absence of PM, we can safely enable USB-PERSIST 208 /* Hubs are automatically enabled for USB-PERSIST */
212 * for all devices. It will affect things like hub resets 209 if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
213 * and EMF-related port disables.
214 */
215 if (!(udev->quirks & USB_QUIRK_RESET))
216 udev->persist_enabled = 1; 210 udev->persist_enabled = 1;
217#endif /* CONFIG_PM */ 211#endif /* CONFIG_USB_DEFAULT_PERSIST */
218} 212}
219 213
220void usb_detect_interface_quirks(struct usb_device *udev) 214void usb_detect_interface_quirks(struct usb_device *udev)
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 3f81a3dc6867..aa38db44818a 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -338,7 +338,7 @@ static void remove_persist_attributes(struct device *dev)
338 338
339#endif /* CONFIG_PM */ 339#endif /* CONFIG_PM */
340 340
341#ifdef CONFIG_USB_SUSPEND 341#ifdef CONFIG_PM_RUNTIME
342 342
343static ssize_t 343static ssize_t
344show_connected_duration(struct device *dev, struct device_attribute *attr, 344show_connected_duration(struct device *dev, struct device_attribute *attr,
@@ -544,7 +544,7 @@ static void remove_power_attributes(struct device *dev)
544#define add_power_attributes(dev) 0 544#define add_power_attributes(dev) 0
545#define remove_power_attributes(dev) do {} while (0) 545#define remove_power_attributes(dev) do {} while (0)
546 546
547#endif /* CONFIG_USB_SUSPEND */ 547#endif /* CONFIG_PM_RUNTIME */
548 548
549 549
550/* Descriptor fields */ 550/* Descriptor fields */
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index e0d9d948218c..16927fa88fbd 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -683,10 +683,13 @@ EXPORT_SYMBOL_GPL(usb_kill_urb);
683void usb_poison_urb(struct urb *urb) 683void usb_poison_urb(struct urb *urb)
684{ 684{
685 might_sleep(); 685 might_sleep();
686 if (!(urb && urb->dev && urb->ep)) 686 if (!urb)
687 return; 687 return;
688 atomic_inc(&urb->reject); 688 atomic_inc(&urb->reject);
689 689
690 if (!urb->dev || !urb->ep)
691 return;
692
690 usb_hcd_unlink_urb(urb, -ENOENT); 693 usb_hcd_unlink_urb(urb, -ENOENT);
691 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0); 694 wait_event(usb_kill_urb_queue, atomic_read(&urb->use_count) == 0);
692} 695}
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index e092b414dc50..b10da720f2b4 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -49,7 +49,7 @@ const char *usbcore_name = "usbcore";
49 49
50static bool nousb; /* Disable USB when built into kernel image */ 50static bool nousb; /* Disable USB when built into kernel image */
51 51
52#ifdef CONFIG_USB_SUSPEND 52#ifdef CONFIG_PM_RUNTIME
53static int usb_autosuspend_delay = 2; /* Default delay value, 53static int usb_autosuspend_delay = 2; /* Default delay value,
54 * in seconds */ 54 * in seconds */
55module_param_named(autosuspend, usb_autosuspend_delay, int, 0644); 55module_param_named(autosuspend, usb_autosuspend_delay, int, 0644);
@@ -307,7 +307,7 @@ static const struct dev_pm_ops usb_device_pm_ops = {
307 .thaw = usb_dev_thaw, 307 .thaw = usb_dev_thaw,
308 .poweroff = usb_dev_poweroff, 308 .poweroff = usb_dev_poweroff,
309 .restore = usb_dev_restore, 309 .restore = usb_dev_restore,
310#ifdef CONFIG_USB_SUSPEND 310#ifdef CONFIG_PM_RUNTIME
311 .runtime_suspend = usb_runtime_suspend, 311 .runtime_suspend = usb_runtime_suspend,
312 .runtime_resume = usb_runtime_resume, 312 .runtime_resume = usb_runtime_resume,
313 .runtime_idle = usb_runtime_idle, 313 .runtime_idle = usb_runtime_idle,
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index a7f20bde0e5e..823857767a16 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -93,7 +93,7 @@ static inline int usb_port_resume(struct usb_device *udev, pm_message_t msg)
93 93
94#endif 94#endif
95 95
96#ifdef CONFIG_USB_SUSPEND 96#ifdef CONFIG_PM_RUNTIME
97 97
98extern void usb_autosuspend_device(struct usb_device *udev); 98extern void usb_autosuspend_device(struct usb_device *udev);
99extern int usb_autoresume_device(struct usb_device *udev); 99extern int usb_autoresume_device(struct usb_device *udev);
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 68e9a2c5a01a..ea5ee9c21c35 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -1,7 +1,6 @@
1config USB_DWC3 1config USB_DWC3
2 tristate "DesignWare USB3 DRD Core Support" 2 tristate "DesignWare USB3 DRD Core Support"
3 depends on (USB || USB_GADGET) && GENERIC_HARDIRQS 3 depends on (USB || USB_GADGET) && GENERIC_HARDIRQS
4 select USB_OTG_UTILS
5 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD 4 select USB_XHCI_PLATFORM if USB_SUPPORT && USB_XHCI_HCD
6 help 5 help
7 Say Y or M here if your system has a Dual Role SuperSpeed 6 Say Y or M here if your system has a Dual Role SuperSpeed
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ffa6b004a84b..c35d49d39b76 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -140,7 +140,8 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
140 * Returns a pointer to the allocated event buffer structure on success 140 * Returns a pointer to the allocated event buffer structure on success
141 * otherwise ERR_PTR(errno). 141 * otherwise ERR_PTR(errno).
142 */ 142 */
143static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) 143static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
144 unsigned length)
144{ 145{
145 struct dwc3_event_buffer *evt; 146 struct dwc3_event_buffer *evt;
146 147
@@ -259,6 +260,17 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
259 } 260 }
260} 261}
261 262
263static void dwc3_core_num_eps(struct dwc3 *dwc)
264{
265 struct dwc3_hwparams *parms = &dwc->hwparams;
266
267 dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
268 dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
269
270 dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
271 dwc->num_in_eps, dwc->num_out_eps);
272}
273
262static void dwc3_cache_hwparams(struct dwc3 *dwc) 274static void dwc3_cache_hwparams(struct dwc3 *dwc)
263{ 275{
264 struct dwc3_hwparams *parms = &dwc->hwparams; 276 struct dwc3_hwparams *parms = &dwc->hwparams;
@@ -335,13 +347,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
335 if (dwc->revision < DWC3_REVISION_190A) 347 if (dwc->revision < DWC3_REVISION_190A)
336 reg |= DWC3_GCTL_U2RSTECN; 348 reg |= DWC3_GCTL_U2RSTECN;
337 349
338 dwc3_writel(dwc->regs, DWC3_GCTL, reg); 350 dwc3_core_num_eps(dwc);
339 351
340 ret = dwc3_event_buffers_setup(dwc); 352 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
341 if (ret) {
342 dev_err(dwc->dev, "failed to setup event buffers\n");
343 goto err0;
344 }
345 353
346 return 0; 354 return 0;
347 355
@@ -351,8 +359,6 @@ err0:
351 359
352static void dwc3_core_exit(struct dwc3 *dwc) 360static void dwc3_core_exit(struct dwc3 *dwc)
353{ 361{
354 dwc3_event_buffers_cleanup(dwc);
355
356 usb_phy_shutdown(dwc->usb2_phy); 362 usb_phy_shutdown(dwc->usb2_phy);
357 usb_phy_shutdown(dwc->usb3_phy); 363 usb_phy_shutdown(dwc->usb3_phy);
358} 364}
@@ -428,12 +434,32 @@ static int dwc3_probe(struct platform_device *pdev)
428 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3); 434 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
429 } 435 }
430 436
431 if (IS_ERR_OR_NULL(dwc->usb2_phy)) { 437 if (IS_ERR(dwc->usb2_phy)) {
438 ret = PTR_ERR(dwc->usb2_phy);
439
440 /*
441 * if -ENXIO is returned, it means PHY layer wasn't
442 * enabled, so it makes no sense to return -EPROBE_DEFER
443 * in that case, since no PHY driver will ever probe.
444 */
445 if (ret == -ENXIO)
446 return ret;
447
432 dev_err(dev, "no usb2 phy configured\n"); 448 dev_err(dev, "no usb2 phy configured\n");
433 return -EPROBE_DEFER; 449 return -EPROBE_DEFER;
434 } 450 }
435 451
436 if (IS_ERR_OR_NULL(dwc->usb3_phy)) { 452 if (IS_ERR(dwc->usb3_phy)) {
453 ret = PTR_ERR(dwc->usb2_phy);
454
455 /*
456 * if -ENXIO is returned, it means PHY layer wasn't
457 * enabled, so it makes no sense to return -EPROBE_DEFER
458 * in that case, since no PHY driver will ever probe.
459 */
460 if (ret == -ENXIO)
461 return ret;
462
437 dev_err(dev, "no usb3 phy configured\n"); 463 dev_err(dev, "no usb3 phy configured\n");
438 return -EPROBE_DEFER; 464 return -EPROBE_DEFER;
439 } 465 }
@@ -448,6 +474,10 @@ static int dwc3_probe(struct platform_device *pdev)
448 dwc->regs_size = resource_size(res); 474 dwc->regs_size = resource_size(res);
449 dwc->dev = dev; 475 dwc->dev = dev;
450 476
477 dev->dma_mask = dev->parent->dma_mask;
478 dev->dma_parms = dev->parent->dma_parms;
479 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
480
451 if (!strncmp("super", maximum_speed, 5)) 481 if (!strncmp("super", maximum_speed, 5))
452 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; 482 dwc->maximum_speed = DWC3_DCFG_SUPERSPEED;
453 else if (!strncmp("high", maximum_speed, 4)) 483 else if (!strncmp("high", maximum_speed, 4))
@@ -480,7 +510,18 @@ static int dwc3_probe(struct platform_device *pdev)
480 goto err0; 510 goto err0;
481 } 511 }
482 512
483 mode = DWC3_MODE(dwc->hwparams.hwparams0); 513 ret = dwc3_event_buffers_setup(dwc);
514 if (ret) {
515 dev_err(dwc->dev, "failed to setup event buffers\n");
516 goto err1;
517 }
518
519 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
520 mode = DWC3_MODE_HOST;
521 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
522 mode = DWC3_MODE_DEVICE;
523 else
524 mode = DWC3_MODE_DRD;
484 525
485 switch (mode) { 526 switch (mode) {
486 case DWC3_MODE_DEVICE: 527 case DWC3_MODE_DEVICE:
@@ -488,7 +529,7 @@ static int dwc3_probe(struct platform_device *pdev)
488 ret = dwc3_gadget_init(dwc); 529 ret = dwc3_gadget_init(dwc);
489 if (ret) { 530 if (ret) {
490 dev_err(dev, "failed to initialize gadget\n"); 531 dev_err(dev, "failed to initialize gadget\n");
491 goto err1; 532 goto err2;
492 } 533 }
493 break; 534 break;
494 case DWC3_MODE_HOST: 535 case DWC3_MODE_HOST:
@@ -496,7 +537,7 @@ static int dwc3_probe(struct platform_device *pdev)
496 ret = dwc3_host_init(dwc); 537 ret = dwc3_host_init(dwc);
497 if (ret) { 538 if (ret) {
498 dev_err(dev, "failed to initialize host\n"); 539 dev_err(dev, "failed to initialize host\n");
499 goto err1; 540 goto err2;
500 } 541 }
501 break; 542 break;
502 case DWC3_MODE_DRD: 543 case DWC3_MODE_DRD:
@@ -504,32 +545,32 @@ static int dwc3_probe(struct platform_device *pdev)
504 ret = dwc3_host_init(dwc); 545 ret = dwc3_host_init(dwc);
505 if (ret) { 546 if (ret) {
506 dev_err(dev, "failed to initialize host\n"); 547 dev_err(dev, "failed to initialize host\n");
507 goto err1; 548 goto err2;
508 } 549 }
509 550
510 ret = dwc3_gadget_init(dwc); 551 ret = dwc3_gadget_init(dwc);
511 if (ret) { 552 if (ret) {
512 dev_err(dev, "failed to initialize gadget\n"); 553 dev_err(dev, "failed to initialize gadget\n");
513 goto err1; 554 goto err2;
514 } 555 }
515 break; 556 break;
516 default: 557 default:
517 dev_err(dev, "Unsupported mode of operation %d\n", mode); 558 dev_err(dev, "Unsupported mode of operation %d\n", mode);
518 goto err1; 559 goto err2;
519 } 560 }
520 dwc->mode = mode; 561 dwc->mode = mode;
521 562
522 ret = dwc3_debugfs_init(dwc); 563 ret = dwc3_debugfs_init(dwc);
523 if (ret) { 564 if (ret) {
524 dev_err(dev, "failed to initialize debugfs\n"); 565 dev_err(dev, "failed to initialize debugfs\n");
525 goto err2; 566 goto err3;
526 } 567 }
527 568
528 pm_runtime_allow(dev); 569 pm_runtime_allow(dev);
529 570
530 return 0; 571 return 0;
531 572
532err2: 573err3:
533 switch (mode) { 574 switch (mode) {
534 case DWC3_MODE_DEVICE: 575 case DWC3_MODE_DEVICE:
535 dwc3_gadget_exit(dwc); 576 dwc3_gadget_exit(dwc);
@@ -546,6 +587,9 @@ err2:
546 break; 587 break;
547 } 588 }
548 589
590err2:
591 dwc3_event_buffers_cleanup(dwc);
592
549err1: 593err1:
550 dwc3_core_exit(dwc); 594 dwc3_core_exit(dwc);
551 595
@@ -583,12 +627,130 @@ static int dwc3_remove(struct platform_device *pdev)
583 break; 627 break;
584 } 628 }
585 629
630 dwc3_event_buffers_cleanup(dwc);
586 dwc3_free_event_buffers(dwc); 631 dwc3_free_event_buffers(dwc);
587 dwc3_core_exit(dwc); 632 dwc3_core_exit(dwc);
588 633
589 return 0; 634 return 0;
590} 635}
591 636
637#ifdef CONFIG_PM_SLEEP
638static int dwc3_prepare(struct device *dev)
639{
640 struct dwc3 *dwc = dev_get_drvdata(dev);
641 unsigned long flags;
642
643 spin_lock_irqsave(&dwc->lock, flags);
644
645 switch (dwc->mode) {
646 case DWC3_MODE_DEVICE:
647 case DWC3_MODE_DRD:
648 dwc3_gadget_prepare(dwc);
649 /* FALLTHROUGH */
650 case DWC3_MODE_HOST:
651 default:
652 dwc3_event_buffers_cleanup(dwc);
653 break;
654 }
655
656 spin_unlock_irqrestore(&dwc->lock, flags);
657
658 return 0;
659}
660
661static void dwc3_complete(struct device *dev)
662{
663 struct dwc3 *dwc = dev_get_drvdata(dev);
664 unsigned long flags;
665
666 spin_lock_irqsave(&dwc->lock, flags);
667
668 switch (dwc->mode) {
669 case DWC3_MODE_DEVICE:
670 case DWC3_MODE_DRD:
671 dwc3_gadget_complete(dwc);
672 /* FALLTHROUGH */
673 case DWC3_MODE_HOST:
674 default:
675 dwc3_event_buffers_setup(dwc);
676 break;
677 }
678
679 spin_unlock_irqrestore(&dwc->lock, flags);
680}
681
682static int dwc3_suspend(struct device *dev)
683{
684 struct dwc3 *dwc = dev_get_drvdata(dev);
685 unsigned long flags;
686
687 spin_lock_irqsave(&dwc->lock, flags);
688
689 switch (dwc->mode) {
690 case DWC3_MODE_DEVICE:
691 case DWC3_MODE_DRD:
692 dwc3_gadget_suspend(dwc);
693 /* FALLTHROUGH */
694 case DWC3_MODE_HOST:
695 default:
696 /* do nothing */
697 break;
698 }
699
700 dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
701 spin_unlock_irqrestore(&dwc->lock, flags);
702
703 usb_phy_shutdown(dwc->usb3_phy);
704 usb_phy_shutdown(dwc->usb2_phy);
705
706 return 0;
707}
708
709static int dwc3_resume(struct device *dev)
710{
711 struct dwc3 *dwc = dev_get_drvdata(dev);
712 unsigned long flags;
713
714 usb_phy_init(dwc->usb3_phy);
715 usb_phy_init(dwc->usb2_phy);
716 msleep(100);
717
718 spin_lock_irqsave(&dwc->lock, flags);
719
720 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
721
722 switch (dwc->mode) {
723 case DWC3_MODE_DEVICE:
724 case DWC3_MODE_DRD:
725 dwc3_gadget_resume(dwc);
726 /* FALLTHROUGH */
727 case DWC3_MODE_HOST:
728 default:
729 /* do nothing */
730 break;
731 }
732
733 spin_unlock_irqrestore(&dwc->lock, flags);
734
735 pm_runtime_disable(dev);
736 pm_runtime_set_active(dev);
737 pm_runtime_enable(dev);
738
739 return 0;
740}
741
742static const struct dev_pm_ops dwc3_dev_pm_ops = {
743 .prepare = dwc3_prepare,
744 .complete = dwc3_complete,
745
746 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
747};
748
749#define DWC3_PM_OPS &(dwc3_dev_pm_ops)
750#else
751#define DWC3_PM_OPS NULL
752#endif
753
592#ifdef CONFIG_OF 754#ifdef CONFIG_OF
593static const struct of_device_id of_dwc3_match[] = { 755static const struct of_device_id of_dwc3_match[] = {
594 { 756 {
@@ -605,6 +767,7 @@ static struct platform_driver dwc3_driver = {
605 .driver = { 767 .driver = {
606 .name = "dwc3", 768 .name = "dwc3",
607 .of_match_table = of_match_ptr(of_dwc3_match), 769 .of_match_table = of_match_ptr(of_dwc3_match),
770 .pm = DWC3_PM_OPS,
608 }, 771 },
609}; 772};
610 773
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index b41750660235..b69d322e3cab 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -154,8 +154,9 @@
154/* OTG Registers */ 154/* OTG Registers */
155#define DWC3_OCFG 0xcc00 155#define DWC3_OCFG 0xcc00
156#define DWC3_OCTL 0xcc04 156#define DWC3_OCTL 0xcc04
157#define DWC3_OEVTEN 0xcc08 157#define DWC3_OEVT 0xcc08
158#define DWC3_OSTS 0xcc0C 158#define DWC3_OEVTEN 0xcc0C
159#define DWC3_OSTS 0xcc10
159 160
160/* Bit fields */ 161/* Bit fields */
161 162
@@ -369,6 +370,9 @@ struct dwc3_trb;
369 * @list: a list of event buffers 370 * @list: a list of event buffers
370 * @buf: _THE_ buffer 371 * @buf: _THE_ buffer
371 * @length: size of this buffer 372 * @length: size of this buffer
373 * @lpos: event offset
374 * @count: cache of last read event count register
375 * @flags: flags related to this event buffer
372 * @dma: dma_addr_t 376 * @dma: dma_addr_t
373 * @dwc: pointer to DWC controller 377 * @dwc: pointer to DWC controller
374 */ 378 */
@@ -376,6 +380,10 @@ struct dwc3_event_buffer {
376 void *buf; 380 void *buf;
377 unsigned length; 381 unsigned length;
378 unsigned int lpos; 382 unsigned int lpos;
383 unsigned int count;
384 unsigned int flags;
385
386#define DWC3_EVENT_PENDING BIT(0)
379 387
380 dma_addr_t dma; 388 dma_addr_t dma;
381 389
@@ -487,12 +495,6 @@ enum dwc3_link_state {
487 DWC3_LINK_STATE_MASK = 0x0f, 495 DWC3_LINK_STATE_MASK = 0x0f,
488}; 496};
489 497
490enum dwc3_device_state {
491 DWC3_DEFAULT_STATE,
492 DWC3_ADDRESS_STATE,
493 DWC3_CONFIGURED_STATE,
494};
495
496/* TRB Length, PCM and Status */ 498/* TRB Length, PCM and Status */
497#define DWC3_TRB_SIZE_MASK (0x00ffffff) 499#define DWC3_TRB_SIZE_MASK (0x00ffffff)
498#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK) 500#define DWC3_TRB_SIZE_LENGTH(n) ((n) & DWC3_TRB_SIZE_MASK)
@@ -574,6 +576,14 @@ struct dwc3_hwparams {
574/* HWPARAMS1 */ 576/* HWPARAMS1 */
575#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15) 577#define DWC3_NUM_INT(n) (((n) & (0x3f << 15)) >> 15)
576 578
579/* HWPARAMS3 */
580#define DWC3_NUM_IN_EPS_MASK (0x1f << 18)
581#define DWC3_NUM_EPS_MASK (0x3f << 12)
582#define DWC3_NUM_EPS(p) (((p)->hwparams3 & \
583 (DWC3_NUM_EPS_MASK)) >> 12)
584#define DWC3_NUM_IN_EPS(p) (((p)->hwparams3 & \
585 (DWC3_NUM_IN_EPS_MASK)) >> 18)
586
577/* HWPARAMS7 */ 587/* HWPARAMS7 */
578#define DWC3_RAM1_DEPTH(n) ((n) & 0xffff) 588#define DWC3_RAM1_DEPTH(n) ((n) & 0xffff)
579 589
@@ -618,7 +628,6 @@ struct dwc3_scratchpad_array {
618 * @gadget_driver: pointer to the gadget driver 628 * @gadget_driver: pointer to the gadget driver
619 * @regs: base address for our registers 629 * @regs: base address for our registers
620 * @regs_size: address space size 630 * @regs_size: address space size
621 * @irq: IRQ number
622 * @num_event_buffers: calculated number of event buffers 631 * @num_event_buffers: calculated number of event buffers
623 * @u1u2: only used on revisions <1.83a for workaround 632 * @u1u2: only used on revisions <1.83a for workaround
624 * @maximum_speed: maximum speed requested (mainly for testing purposes) 633 * @maximum_speed: maximum speed requested (mainly for testing purposes)
@@ -626,6 +635,8 @@ struct dwc3_scratchpad_array {
626 * @mode: mode of operation 635 * @mode: mode of operation
627 * @usb2_phy: pointer to USB2 PHY 636 * @usb2_phy: pointer to USB2 PHY
628 * @usb3_phy: pointer to USB3 PHY 637 * @usb3_phy: pointer to USB3 PHY
638 * @dcfg: saved contents of DCFG register
639 * @gctl: saved contents of GCTL register
629 * @is_selfpowered: true when we are selfpowered 640 * @is_selfpowered: true when we are selfpowered
630 * @three_stage_setup: set if we perform a three phase setup 641 * @three_stage_setup: set if we perform a three phase setup
631 * @ep0_bounced: true when we used bounce buffer 642 * @ep0_bounced: true when we used bounce buffer
@@ -639,6 +650,8 @@ struct dwc3_scratchpad_array {
639 * @u2pel: parameter from Set SEL request. 650 * @u2pel: parameter from Set SEL request.
640 * @u1sel: parameter from Set SEL request. 651 * @u1sel: parameter from Set SEL request.
641 * @u1pel: parameter from Set SEL request. 652 * @u1pel: parameter from Set SEL request.
653 * @num_out_eps: number of out endpoints
654 * @num_in_eps: number of in endpoints
642 * @ep0_next_event: hold the next expected event 655 * @ep0_next_event: hold the next expected event
643 * @ep0state: state of endpoint zero 656 * @ep0state: state of endpoint zero
644 * @link_state: link state 657 * @link_state: link state
@@ -656,8 +669,10 @@ struct dwc3 {
656 dma_addr_t ep0_trb_addr; 669 dma_addr_t ep0_trb_addr;
657 dma_addr_t ep0_bounce_addr; 670 dma_addr_t ep0_bounce_addr;
658 struct dwc3_request ep0_usb_req; 671 struct dwc3_request ep0_usb_req;
672
659 /* device lock */ 673 /* device lock */
660 spinlock_t lock; 674 spinlock_t lock;
675
661 struct device *dev; 676 struct device *dev;
662 677
663 struct platform_device *xhci; 678 struct platform_device *xhci;
@@ -675,6 +690,10 @@ struct dwc3 {
675 void __iomem *regs; 690 void __iomem *regs;
676 size_t regs_size; 691 size_t regs_size;
677 692
693 /* used for suspend/resume */
694 u32 dcfg;
695 u32 gctl;
696
678 u32 num_event_buffers; 697 u32 num_event_buffers;
679 u32 u1u2; 698 u32 u1u2;
680 u32 maximum_speed; 699 u32 maximum_speed;
@@ -694,6 +713,9 @@ struct dwc3 {
694#define DWC3_REVISION_202A 0x5533202a 713#define DWC3_REVISION_202A 0x5533202a
695#define DWC3_REVISION_210A 0x5533210a 714#define DWC3_REVISION_210A 0x5533210a
696#define DWC3_REVISION_220A 0x5533220a 715#define DWC3_REVISION_220A 0x5533220a
716#define DWC3_REVISION_230A 0x5533230a
717#define DWC3_REVISION_240A 0x5533240a
718#define DWC3_REVISION_250A 0x5533250a
697 719
698 unsigned is_selfpowered:1; 720 unsigned is_selfpowered:1;
699 unsigned three_stage_setup:1; 721 unsigned three_stage_setup:1;
@@ -704,11 +726,11 @@ struct dwc3 {
704 unsigned delayed_status:1; 726 unsigned delayed_status:1;
705 unsigned needs_fifo_resize:1; 727 unsigned needs_fifo_resize:1;
706 unsigned resize_fifos:1; 728 unsigned resize_fifos:1;
729 unsigned pullups_connected:1;
707 730
708 enum dwc3_ep0_next ep0_next_event; 731 enum dwc3_ep0_next ep0_next_event;
709 enum dwc3_ep0_state ep0state; 732 enum dwc3_ep0_state ep0state;
710 enum dwc3_link_state link_state; 733 enum dwc3_link_state link_state;
711 enum dwc3_device_state dev_state;
712 734
713 u16 isoch_delay; 735 u16 isoch_delay;
714 u16 u2sel; 736 u16 u2sel;
@@ -718,6 +740,9 @@ struct dwc3 {
718 740
719 u8 speed; 741 u8 speed;
720 742
743 u8 num_out_eps;
744 u8 num_in_eps;
745
721 void *mem; 746 void *mem;
722 747
723 struct dwc3_hwparams hwparams; 748 struct dwc3_hwparams hwparams;
@@ -884,4 +909,31 @@ static inline void dwc3_gadget_exit(struct dwc3 *dwc)
884{ } 909{ }
885#endif 910#endif
886 911
912/* power management interface */
913#if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
914int dwc3_gadget_prepare(struct dwc3 *dwc);
915void dwc3_gadget_complete(struct dwc3 *dwc);
916int dwc3_gadget_suspend(struct dwc3 *dwc);
917int dwc3_gadget_resume(struct dwc3 *dwc);
918#else
919static inline int dwc3_gadget_prepare(struct dwc3 *dwc)
920{
921 return 0;
922}
923
924static inline void dwc3_gadget_complete(struct dwc3 *dwc)
925{
926}
927
928static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
929{
930 return 0;
931}
932
933static inline int dwc3_gadget_resume(struct dwc3 *dwc)
934{
935 return 0;
936}
937#endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
938
887#endif /* __DRIVERS_USB_DWC3_CORE_H */ 939#endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 4a752e730c5f..9e9f122162f2 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -59,7 +59,7 @@
59 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \ 59 .offset = DWC3_ ##nm - DWC3_GLOBALS_REGS_START, \
60} 60}
61 61
62static struct debugfs_reg32 dwc3_regs[] = { 62static const struct debugfs_reg32 dwc3_regs[] = {
63 dump_register(GSBUSCFG0), 63 dump_register(GSBUSCFG0),
64 dump_register(GSBUSCFG1), 64 dump_register(GSBUSCFG1),
65 dump_register(GTXTHRCFG), 65 dump_register(GTXTHRCFG),
@@ -372,6 +372,7 @@ static struct debugfs_reg32 dwc3_regs[] = {
372 372
373 dump_register(OCFG), 373 dump_register(OCFG),
374 dump_register(OCTL), 374 dump_register(OCTL),
375 dump_register(OEVT),
375 dump_register(OEVTEN), 376 dump_register(OEVTEN),
376 dump_register(OSTS), 377 dump_register(OSTS),
377}; 378};
@@ -577,8 +578,14 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused)
577 case DWC3_LINK_STATE_LPBK: 578 case DWC3_LINK_STATE_LPBK:
578 seq_printf(s, "Loopback\n"); 579 seq_printf(s, "Loopback\n");
579 break; 580 break;
581 case DWC3_LINK_STATE_RESET:
582 seq_printf(s, "Reset\n");
583 break;
584 case DWC3_LINK_STATE_RESUME:
585 seq_printf(s, "Resume\n");
586 break;
580 default: 587 default:
581 seq_printf(s, "UNKNOWN %d\n", reg); 588 seq_printf(s, "UNKNOWN %d\n", state);
582 } 589 }
583 590
584 return 0; 591 return 0;
@@ -661,28 +668,31 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
661 goto err1; 668 goto err1;
662 } 669 }
663 670
664#if IS_ENABLED(CONFIG_USB_DWC3_GADGET) 671 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
665 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root, 672 file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,
666 dwc, &dwc3_mode_fops); 673 dwc, &dwc3_mode_fops);
667 if (!file) { 674 if (!file) {
668 ret = -ENOMEM; 675 ret = -ENOMEM;
669 goto err1; 676 goto err1;
670 } 677 }
671
672 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
673 dwc, &dwc3_testmode_fops);
674 if (!file) {
675 ret = -ENOMEM;
676 goto err1;
677 } 678 }
678 679
679 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, 680 if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) ||
680 dwc, &dwc3_link_state_fops); 681 IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
681 if (!file) { 682 file = debugfs_create_file("testmode", S_IRUGO | S_IWUSR, root,
682 ret = -ENOMEM; 683 dwc, &dwc3_testmode_fops);
683 goto err1; 684 if (!file) {
685 ret = -ENOMEM;
686 goto err1;
687 }
688
689 file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
690 dwc, &dwc3_link_state_fops);
691 if (!file) {
692 ret = -ENOMEM;
693 goto err1;
694 }
684 } 695 }
685#endif
686 696
687 return 0; 697 return 0;
688 698
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index b082bec7343e..a8afe6e26621 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -22,9 +22,9 @@
22#include <linux/usb/otg.h> 22#include <linux/usb/otg.h>
23#include <linux/usb/nop-usb-xceiv.h> 23#include <linux/usb/nop-usb-xceiv.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/of_platform.h>
25 26
26struct dwc3_exynos { 27struct dwc3_exynos {
27 struct platform_device *dwc3;
28 struct platform_device *usb2_phy; 28 struct platform_device *usb2_phy;
29 struct platform_device *usb3_phy; 29 struct platform_device *usb3_phy;
30 struct device *dev; 30 struct device *dev;
@@ -86,21 +86,30 @@ err1:
86 return ret; 86 return ret;
87} 87}
88 88
89static int dwc3_exynos_remove_child(struct device *dev, void *unused)
90{
91 struct platform_device *pdev = to_platform_device(dev);
92
93 platform_device_unregister(pdev);
94
95 return 0;
96}
97
89static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); 98static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32);
90 99
91static int dwc3_exynos_probe(struct platform_device *pdev) 100static int dwc3_exynos_probe(struct platform_device *pdev)
92{ 101{
93 struct platform_device *dwc3;
94 struct dwc3_exynos *exynos; 102 struct dwc3_exynos *exynos;
95 struct clk *clk; 103 struct clk *clk;
96 struct device *dev = &pdev->dev; 104 struct device *dev = &pdev->dev;
105 struct device_node *node = dev->of_node;
97 106
98 int ret = -ENOMEM; 107 int ret = -ENOMEM;
99 108
100 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); 109 exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL);
101 if (!exynos) { 110 if (!exynos) {
102 dev_err(dev, "not enough memory\n"); 111 dev_err(dev, "not enough memory\n");
103 return -ENOMEM; 112 goto err1;
104 } 113 }
105 114
106 /* 115 /*
@@ -108,21 +117,15 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
108 * Since shared usb code relies on it, set it here for now. 117 * Since shared usb code relies on it, set it here for now.
109 * Once we move to full device tree support this will vanish off. 118 * Once we move to full device tree support this will vanish off.
110 */ 119 */
111 if (!pdev->dev.dma_mask) 120 if (!dev->dma_mask)
112 pdev->dev.dma_mask = &dwc3_exynos_dma_mask; 121 dev->dma_mask = &dwc3_exynos_dma_mask;
113 122
114 platform_set_drvdata(pdev, exynos); 123 platform_set_drvdata(pdev, exynos);
115 124
116 ret = dwc3_exynos_register_phys(exynos); 125 ret = dwc3_exynos_register_phys(exynos);
117 if (ret) { 126 if (ret) {
118 dev_err(dev, "couldn't register PHYs\n"); 127 dev_err(dev, "couldn't register PHYs\n");
119 return ret; 128 goto err1;
120 }
121
122 dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
123 if (!dwc3) {
124 dev_err(dev, "couldn't allocate dwc3 device\n");
125 return -ENOMEM;
126 } 129 }
127 130
128 clk = devm_clk_get(dev, "usbdrd30"); 131 clk = devm_clk_get(dev, "usbdrd30");
@@ -132,37 +135,28 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
132 goto err1; 135 goto err1;
133 } 136 }
134 137
135 dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
136
137 dwc3->dev.parent = dev;
138 dwc3->dev.dma_mask = dev->dma_mask;
139 dwc3->dev.dma_parms = dev->dma_parms;
140 exynos->dwc3 = dwc3;
141 exynos->dev = dev; 138 exynos->dev = dev;
142 exynos->clk = clk; 139 exynos->clk = clk;
143 140
144 clk_enable(exynos->clk); 141 clk_prepare_enable(exynos->clk);
145 142
146 ret = platform_device_add_resources(dwc3, pdev->resource, 143 if (node) {
147 pdev->num_resources); 144 ret = of_platform_populate(node, NULL, NULL, dev);
148 if (ret) { 145 if (ret) {
149 dev_err(dev, "couldn't add resources to dwc3 device\n"); 146 dev_err(dev, "failed to add dwc3 core\n");
150 goto err2; 147 goto err2;
151 } 148 }
152 149 } else {
153 ret = platform_device_add(dwc3); 150 dev_err(dev, "no device node, failed to add dwc3 core\n");
154 if (ret) { 151 ret = -ENODEV;
155 dev_err(dev, "failed to register dwc3 device\n");
156 goto err2; 152 goto err2;
157 } 153 }
158 154
159 return 0; 155 return 0;
160 156
161err2: 157err2:
162 clk_disable(clk); 158 clk_disable_unprepare(clk);
163err1: 159err1:
164 platform_device_put(dwc3);
165
166 return ret; 160 return ret;
167} 161}
168 162
@@ -170,11 +164,11 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
170{ 164{
171 struct dwc3_exynos *exynos = platform_get_drvdata(pdev); 165 struct dwc3_exynos *exynos = platform_get_drvdata(pdev);
172 166
173 platform_device_unregister(exynos->dwc3);
174 platform_device_unregister(exynos->usb2_phy); 167 platform_device_unregister(exynos->usb2_phy);
175 platform_device_unregister(exynos->usb3_phy); 168 platform_device_unregister(exynos->usb3_phy);
169 device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child);
176 170
177 clk_disable(exynos->clk); 171 clk_disable_unprepare(exynos->clk);
178 172
179 return 0; 173 return 0;
180} 174}
@@ -187,12 +181,46 @@ static const struct of_device_id exynos_dwc3_match[] = {
187MODULE_DEVICE_TABLE(of, exynos_dwc3_match); 181MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
188#endif 182#endif
189 183
184#ifdef CONFIG_PM_SLEEP
185static int dwc3_exynos_suspend(struct device *dev)
186{
187 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
188
189 clk_disable(exynos->clk);
190
191 return 0;
192}
193
194static int dwc3_exynos_resume(struct device *dev)
195{
196 struct dwc3_exynos *exynos = dev_get_drvdata(dev);
197
198 clk_enable(exynos->clk);
199
200 /* runtime set active to reflect active state. */
201 pm_runtime_disable(dev);
202 pm_runtime_set_active(dev);
203 pm_runtime_enable(dev);
204
205 return 0;
206}
207
208static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
209 SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
210};
211
212#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops)
213#else
214#define DEV_PM_OPS NULL
215#endif /* CONFIG_PM_SLEEP */
216
190static struct platform_driver dwc3_exynos_driver = { 217static struct platform_driver dwc3_exynos_driver = {
191 .probe = dwc3_exynos_probe, 218 .probe = dwc3_exynos_probe,
192 .remove = dwc3_exynos_remove, 219 .remove = dwc3_exynos_remove,
193 .driver = { 220 .driver = {
194 .name = "exynos-dwc3", 221 .name = "exynos-dwc3",
195 .of_match_table = of_match_ptr(exynos_dwc3_match), 222 .of_match_table = of_match_ptr(exynos_dwc3_match),
223 .pm = DEV_PM_OPS,
196 }, 224 },
197}; 225};
198 226
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index afa05e3c9cf4..34638b92500d 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -52,7 +52,6 @@
52#include <linux/of_platform.h> 52#include <linux/of_platform.h>
53 53
54#include <linux/usb/otg.h> 54#include <linux/usb/otg.h>
55#include <linux/usb/nop-usb-xceiv.h>
56 55
57/* 56/*
58 * All these registers belong to OMAP's Wrapper around the 57 * All these registers belong to OMAP's Wrapper around the
@@ -117,20 +116,17 @@ struct dwc3_omap {
117 /* device lock */ 116 /* device lock */
118 spinlock_t lock; 117 spinlock_t lock;
119 118
120 struct platform_device *usb2_phy;
121 struct platform_device *usb3_phy;
122 struct device *dev; 119 struct device *dev;
123 120
124 int irq; 121 int irq;
125 void __iomem *base; 122 void __iomem *base;
126 123
127 void *context; 124 u32 utmi_otg_status;
128 u32 resource_size;
129 125
130 u32 dma_status:1; 126 u32 dma_status:1;
131}; 127};
132 128
133struct dwc3_omap *_omap; 129static struct dwc3_omap *_omap;
134 130
135static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset) 131static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
136{ 132{
@@ -142,11 +138,14 @@ static inline void dwc3_omap_writel(void __iomem *base, u32 offset, u32 value)
142 writel(value, base + offset); 138 writel(value, base + offset);
143} 139}
144 140
145void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 141int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
146{ 142{
147 u32 val; 143 u32 val;
148 struct dwc3_omap *omap = _omap; 144 struct dwc3_omap *omap = _omap;
149 145
146 if (!omap)
147 return -EPROBE_DEFER;
148
150 switch (status) { 149 switch (status) {
151 case OMAP_DWC3_ID_GROUND: 150 case OMAP_DWC3_ID_GROUND:
152 dev_dbg(omap->dev, "ID GND\n"); 151 dev_dbg(omap->dev, "ID GND\n");
@@ -189,63 +188,9 @@ void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
189 dev_dbg(omap->dev, "ID float\n"); 188 dev_dbg(omap->dev, "ID float\n");
190 } 189 }
191 190
192 return;
193}
194EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
195
196static int dwc3_omap_register_phys(struct dwc3_omap *omap)
197{
198 struct nop_usb_xceiv_platform_data pdata;
199 struct platform_device *pdev;
200 int ret;
201
202 memset(&pdata, 0x00, sizeof(pdata));
203
204 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
205 if (!pdev)
206 return -ENOMEM;
207
208 omap->usb2_phy = pdev;
209 pdata.type = USB_PHY_TYPE_USB2;
210
211 ret = platform_device_add_data(omap->usb2_phy, &pdata, sizeof(pdata));
212 if (ret)
213 goto err1;
214
215 pdev = platform_device_alloc("nop_usb_xceiv", PLATFORM_DEVID_AUTO);
216 if (!pdev) {
217 ret = -ENOMEM;
218 goto err1;
219 }
220
221 omap->usb3_phy = pdev;
222 pdata.type = USB_PHY_TYPE_USB3;
223
224 ret = platform_device_add_data(omap->usb3_phy, &pdata, sizeof(pdata));
225 if (ret)
226 goto err2;
227
228 ret = platform_device_add(omap->usb2_phy);
229 if (ret)
230 goto err2;
231
232 ret = platform_device_add(omap->usb3_phy);
233 if (ret)
234 goto err3;
235
236 return 0; 191 return 0;
237
238err3:
239 platform_device_del(omap->usb2_phy);
240
241err2:
242 platform_device_put(omap->usb3_phy);
243
244err1:
245 platform_device_put(omap->usb2_phy);
246
247 return ret;
248} 192}
193EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
249 194
250static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap) 195static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
251{ 196{
@@ -307,24 +252,57 @@ static int dwc3_omap_remove_core(struct device *dev, void *c)
307 return 0; 252 return 0;
308} 253}
309 254
255static void dwc3_omap_enable_irqs(struct dwc3_omap *omap)
256{
257 u32 reg;
258
259 /* enable all IRQs */
260 reg = USBOTGSS_IRQO_COREIRQ_ST;
261 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
262
263 reg = (USBOTGSS_IRQ1_OEVT |
264 USBOTGSS_IRQ1_DRVVBUS_RISE |
265 USBOTGSS_IRQ1_CHRGVBUS_RISE |
266 USBOTGSS_IRQ1_DISCHRGVBUS_RISE |
267 USBOTGSS_IRQ1_IDPULLUP_RISE |
268 USBOTGSS_IRQ1_DRVVBUS_FALL |
269 USBOTGSS_IRQ1_CHRGVBUS_FALL |
270 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
271 USBOTGSS_IRQ1_IDPULLUP_FALL);
272
273 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
274}
275
276static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
277{
278 /* disable all IRQs */
279 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, 0x00);
280 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, 0x00);
281}
282
283static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
284
310static int dwc3_omap_probe(struct platform_device *pdev) 285static int dwc3_omap_probe(struct platform_device *pdev)
311{ 286{
312 struct dwc3_omap_data *pdata = pdev->dev.platform_data;
313 struct device_node *node = pdev->dev.of_node; 287 struct device_node *node = pdev->dev.of_node;
314 288
315 struct dwc3_omap *omap; 289 struct dwc3_omap *omap;
316 struct resource *res; 290 struct resource *res;
317 struct device *dev = &pdev->dev; 291 struct device *dev = &pdev->dev;
318 292
319 int size;
320 int ret = -ENOMEM; 293 int ret = -ENOMEM;
321 int irq; 294 int irq;
322 295
323 const u32 *utmi_mode; 296 int utmi_mode = 0;
297
324 u32 reg; 298 u32 reg;
325 299
326 void __iomem *base; 300 void __iomem *base;
327 void *context; 301
302 if (!node) {
303 dev_err(dev, "device node not found\n");
304 return -EINVAL;
305 }
328 306
329 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); 307 omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL);
330 if (!omap) { 308 if (!omap) {
@@ -334,13 +312,13 @@ static int dwc3_omap_probe(struct platform_device *pdev)
334 312
335 platform_set_drvdata(pdev, omap); 313 platform_set_drvdata(pdev, omap);
336 314
337 irq = platform_get_irq(pdev, 1); 315 irq = platform_get_irq(pdev, 0);
338 if (irq < 0) { 316 if (irq < 0) {
339 dev_err(dev, "missing IRQ resource\n"); 317 dev_err(dev, "missing IRQ resource\n");
340 return -EINVAL; 318 return -EINVAL;
341 } 319 }
342 320
343 res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 321 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
344 if (!res) { 322 if (!res) {
345 dev_err(dev, "missing memory base resource\n"); 323 dev_err(dev, "missing memory base resource\n");
346 return -EINVAL; 324 return -EINVAL;
@@ -352,25 +330,12 @@ static int dwc3_omap_probe(struct platform_device *pdev)
352 return -ENOMEM; 330 return -ENOMEM;
353 } 331 }
354 332
355 ret = dwc3_omap_register_phys(omap);
356 if (ret) {
357 dev_err(dev, "couldn't register PHYs\n");
358 return ret;
359 }
360
361 context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL);
362 if (!context) {
363 dev_err(dev, "couldn't allocate dwc3 context memory\n");
364 return -ENOMEM;
365 }
366
367 spin_lock_init(&omap->lock); 333 spin_lock_init(&omap->lock);
368 334
369 omap->resource_size = resource_size(res);
370 omap->context = context;
371 omap->dev = dev; 335 omap->dev = dev;
372 omap->irq = irq; 336 omap->irq = irq;
373 omap->base = base; 337 omap->base = base;
338 dev->dma_mask = &dwc3_omap_dma_mask;
374 339
375 /* 340 /*
376 * REVISIT if we ever have two instances of the wrapper, we will be 341 * REVISIT if we ever have two instances of the wrapper, we will be
@@ -387,25 +352,17 @@ static int dwc3_omap_probe(struct platform_device *pdev)
387 352
388 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS); 353 reg = dwc3_omap_readl(omap->base, USBOTGSS_UTMI_OTG_STATUS);
389 354
390 utmi_mode = of_get_property(node, "utmi-mode", &size); 355 of_property_read_u32(node, "utmi-mode", &utmi_mode);
391 if (utmi_mode && size == sizeof(*utmi_mode)) { 356
392 reg |= *utmi_mode; 357 switch (utmi_mode) {
393 } else { 358 case DWC3_OMAP_UTMI_MODE_SW:
394 if (!pdata) { 359 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
395 dev_dbg(dev, "missing platform data\n"); 360 break;
396 } else { 361 case DWC3_OMAP_UTMI_MODE_HW:
397 switch (pdata->utmi_mode) { 362 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
398 case DWC3_OMAP_UTMI_MODE_SW: 363 break;
399 reg |= USBOTGSS_UTMI_OTG_STATUS_SW_MODE; 364 default:
400 break; 365 dev_dbg(dev, "UNKNOWN utmi mode %d\n", utmi_mode);
401 case DWC3_OMAP_UTMI_MODE_HW:
402 reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE;
403 break;
404 default:
405 dev_dbg(dev, "UNKNOWN utmi mode %d\n",
406 pdata->utmi_mode);
407 }
408 }
409 } 366 }
410 367
411 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg); 368 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS, reg);
@@ -422,29 +379,12 @@ static int dwc3_omap_probe(struct platform_device *pdev)
422 return ret; 379 return ret;
423 } 380 }
424 381
425 /* enable all IRQs */ 382 dwc3_omap_enable_irqs(omap);
426 reg = USBOTGSS_IRQO_COREIRQ_ST;
427 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_0, reg);
428 383
429 reg = (USBOTGSS_IRQ1_OEVT | 384 ret = of_platform_populate(node, NULL, NULL, dev);
430 USBOTGSS_IRQ1_DRVVBUS_RISE | 385 if (ret) {
431 USBOTGSS_IRQ1_CHRGVBUS_RISE | 386 dev_err(&pdev->dev, "failed to create dwc3 core\n");
432 USBOTGSS_IRQ1_DISCHRGVBUS_RISE | 387 return ret;
433 USBOTGSS_IRQ1_IDPULLUP_RISE |
434 USBOTGSS_IRQ1_DRVVBUS_FALL |
435 USBOTGSS_IRQ1_CHRGVBUS_FALL |
436 USBOTGSS_IRQ1_DISCHRGVBUS_FALL |
437 USBOTGSS_IRQ1_IDPULLUP_FALL);
438
439 dwc3_omap_writel(omap->base, USBOTGSS_IRQENABLE_SET_1, reg);
440
441 if (node) {
442 ret = of_platform_populate(node, NULL, NULL, dev);
443 if (ret) {
444 dev_err(&pdev->dev,
445 "failed to add create dwc3 core\n");
446 return ret;
447 }
448 } 388 }
449 389
450 return 0; 390 return 0;
@@ -454,8 +394,7 @@ static int dwc3_omap_remove(struct platform_device *pdev)
454{ 394{
455 struct dwc3_omap *omap = platform_get_drvdata(pdev); 395 struct dwc3_omap *omap = platform_get_drvdata(pdev);
456 396
457 platform_device_unregister(omap->usb2_phy); 397 dwc3_omap_disable_irqs(omap);
458 platform_device_unregister(omap->usb3_phy);
459 pm_runtime_put_sync(&pdev->dev); 398 pm_runtime_put_sync(&pdev->dev);
460 pm_runtime_disable(&pdev->dev); 399 pm_runtime_disable(&pdev->dev);
461 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core); 400 device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
@@ -465,18 +404,72 @@ static int dwc3_omap_remove(struct platform_device *pdev)
465 404
466static const struct of_device_id of_dwc3_match[] = { 405static const struct of_device_id of_dwc3_match[] = {
467 { 406 {
468 "ti,dwc3", 407 .compatible = "ti,dwc3"
469 }, 408 },
470 { }, 409 { },
471}; 410};
472MODULE_DEVICE_TABLE(of, of_dwc3_match); 411MODULE_DEVICE_TABLE(of, of_dwc3_match);
473 412
413#ifdef CONFIG_PM_SLEEP
414static int dwc3_omap_prepare(struct device *dev)
415{
416 struct dwc3_omap *omap = dev_get_drvdata(dev);
417
418 dwc3_omap_disable_irqs(omap);
419
420 return 0;
421}
422
423static void dwc3_omap_complete(struct device *dev)
424{
425 struct dwc3_omap *omap = dev_get_drvdata(dev);
426
427 dwc3_omap_enable_irqs(omap);
428}
429
430static int dwc3_omap_suspend(struct device *dev)
431{
432 struct dwc3_omap *omap = dev_get_drvdata(dev);
433
434 omap->utmi_otg_status = dwc3_omap_readl(omap->base,
435 USBOTGSS_UTMI_OTG_STATUS);
436
437 return 0;
438}
439
440static int dwc3_omap_resume(struct device *dev)
441{
442 struct dwc3_omap *omap = dev_get_drvdata(dev);
443
444 dwc3_omap_writel(omap->base, USBOTGSS_UTMI_OTG_STATUS,
445 omap->utmi_otg_status);
446
447 pm_runtime_disable(dev);
448 pm_runtime_set_active(dev);
449 pm_runtime_enable(dev);
450
451 return 0;
452}
453
454static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
455 .prepare = dwc3_omap_prepare,
456 .complete = dwc3_omap_complete,
457
458 SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
459};
460
461#define DEV_PM_OPS (&dwc3_omap_dev_pm_ops)
462#else
463#define DEV_PM_OPS NULL
464#endif /* CONFIG_PM_SLEEP */
465
474static struct platform_driver dwc3_omap_driver = { 466static struct platform_driver dwc3_omap_driver = {
475 .probe = dwc3_omap_probe, 467 .probe = dwc3_omap_probe,
476 .remove = dwc3_omap_remove, 468 .remove = dwc3_omap_remove,
477 .driver = { 469 .driver = {
478 .name = "omap-dwc3", 470 .name = "omap-dwc3",
479 .of_match_table = of_dwc3_match, 471 .of_match_table = of_dwc3_match,
472 .pm = DEV_PM_OPS,
480 }, 473 },
481}; 474};
482 475
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index e8d77689a322..227d4a7acad7 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -212,11 +212,49 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
212}; 212};
213MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); 213MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
214 214
215#ifdef CONFIG_PM
216static int dwc3_pci_suspend(struct device *dev)
217{
218 struct pci_dev *pci = to_pci_dev(dev);
219
220 pci_disable_device(pci);
221
222 return 0;
223}
224
225static int dwc3_pci_resume(struct device *dev)
226{
227 struct pci_dev *pci = to_pci_dev(dev);
228 int ret;
229
230 ret = pci_enable_device(pci);
231 if (ret) {
232 dev_err(dev, "can't re-enable device --> %d\n", ret);
233 return ret;
234 }
235
236 pci_set_master(pci);
237
238 return 0;
239}
240
241static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
242 SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
243};
244
245#define DEV_PM_OPS (&dwc3_pci_dev_pm_ops)
246#else
247#define DEV_PM_OPS NULL
248#endif /* CONFIG_PM */
249
215static struct pci_driver dwc3_pci_driver = { 250static struct pci_driver dwc3_pci_driver = {
216 .name = "dwc3-pci", 251 .name = "dwc3-pci",
217 .id_table = dwc3_pci_id_table, 252 .id_table = dwc3_pci_id_table,
218 .probe = dwc3_pci_probe, 253 .probe = dwc3_pci_probe,
219 .remove = dwc3_pci_remove, 254 .remove = dwc3_pci_remove,
255 .driver = {
256 .pm = DEV_PM_OPS,
257 },
220}; 258};
221 259
222MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); 260MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1d139ca05ef1..5acbb948b704 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -394,10 +394,13 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
394 u32 wIndex; 394 u32 wIndex;
395 u32 reg; 395 u32 reg;
396 int ret; 396 int ret;
397 enum usb_device_state state;
397 398
398 wValue = le16_to_cpu(ctrl->wValue); 399 wValue = le16_to_cpu(ctrl->wValue);
399 wIndex = le16_to_cpu(ctrl->wIndex); 400 wIndex = le16_to_cpu(ctrl->wIndex);
400 recip = ctrl->bRequestType & USB_RECIP_MASK; 401 recip = ctrl->bRequestType & USB_RECIP_MASK;
402 state = dwc->gadget.state;
403
401 switch (recip) { 404 switch (recip) {
402 case USB_RECIP_DEVICE: 405 case USB_RECIP_DEVICE:
403 406
@@ -409,7 +412,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
409 * default control pipe 412 * default control pipe
410 */ 413 */
411 case USB_DEVICE_U1_ENABLE: 414 case USB_DEVICE_U1_ENABLE:
412 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 415 if (state != USB_STATE_CONFIGURED)
413 return -EINVAL; 416 return -EINVAL;
414 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 417 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
415 return -EINVAL; 418 return -EINVAL;
@@ -423,7 +426,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
423 break; 426 break;
424 427
425 case USB_DEVICE_U2_ENABLE: 428 case USB_DEVICE_U2_ENABLE:
426 if (dwc->dev_state != DWC3_CONFIGURED_STATE) 429 if (state != USB_STATE_CONFIGURED)
427 return -EINVAL; 430 return -EINVAL;
428 if (dwc->speed != DWC3_DSTS_SUPERSPEED) 431 if (dwc->speed != DWC3_DSTS_SUPERSPEED)
429 return -EINVAL; 432 return -EINVAL;
@@ -493,6 +496,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
493 496
494static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 497static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
495{ 498{
499 enum usb_device_state state = dwc->gadget.state;
496 u32 addr; 500 u32 addr;
497 u32 reg; 501 u32 reg;
498 502
@@ -502,7 +506,7 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
502 return -EINVAL; 506 return -EINVAL;
503 } 507 }
504 508
505 if (dwc->dev_state == DWC3_CONFIGURED_STATE) { 509 if (state == USB_STATE_CONFIGURED) {
506 dev_dbg(dwc->dev, "trying to set address when configured\n"); 510 dev_dbg(dwc->dev, "trying to set address when configured\n");
507 return -EINVAL; 511 return -EINVAL;
508 } 512 }
@@ -513,9 +517,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
513 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 517 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
514 518
515 if (addr) 519 if (addr)
516 dwc->dev_state = DWC3_ADDRESS_STATE; 520 usb_gadget_set_state(&dwc->gadget, USB_STATE_ADDRESS);
517 else 521 else
518 dwc->dev_state = DWC3_DEFAULT_STATE; 522 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
519 523
520 return 0; 524 return 0;
521} 525}
@@ -532,6 +536,7 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
532 536
533static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 537static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
534{ 538{
539 enum usb_device_state state = dwc->gadget.state;
535 u32 cfg; 540 u32 cfg;
536 int ret; 541 int ret;
537 u32 reg; 542 u32 reg;
@@ -539,16 +544,18 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
539 dwc->start_config_issued = false; 544 dwc->start_config_issued = false;
540 cfg = le16_to_cpu(ctrl->wValue); 545 cfg = le16_to_cpu(ctrl->wValue);
541 546
542 switch (dwc->dev_state) { 547 switch (state) {
543 case DWC3_DEFAULT_STATE: 548 case USB_STATE_DEFAULT:
544 return -EINVAL; 549 return -EINVAL;
545 break; 550 break;
546 551
547 case DWC3_ADDRESS_STATE: 552 case USB_STATE_ADDRESS:
548 ret = dwc3_ep0_delegate_req(dwc, ctrl); 553 ret = dwc3_ep0_delegate_req(dwc, ctrl);
549 /* if the cfg matches and the cfg is non zero */ 554 /* if the cfg matches and the cfg is non zero */
550 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) { 555 if (cfg && (!ret || (ret == USB_GADGET_DELAYED_STATUS))) {
551 dwc->dev_state = DWC3_CONFIGURED_STATE; 556 usb_gadget_set_state(&dwc->gadget,
557 USB_STATE_CONFIGURED);
558
552 /* 559 /*
553 * Enable transition to U1/U2 state when 560 * Enable transition to U1/U2 state when
554 * nothing is pending from application. 561 * nothing is pending from application.
@@ -562,10 +569,11 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
562 } 569 }
563 break; 570 break;
564 571
565 case DWC3_CONFIGURED_STATE: 572 case USB_STATE_CONFIGURED:
566 ret = dwc3_ep0_delegate_req(dwc, ctrl); 573 ret = dwc3_ep0_delegate_req(dwc, ctrl);
567 if (!cfg) 574 if (!cfg)
568 dwc->dev_state = DWC3_ADDRESS_STATE; 575 usb_gadget_set_state(&dwc->gadget,
576 USB_STATE_ADDRESS);
569 break; 577 break;
570 default: 578 default:
571 ret = -EINVAL; 579 ret = -EINVAL;
@@ -620,10 +628,11 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)
620static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl) 628static int dwc3_ep0_set_sel(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)
621{ 629{
622 struct dwc3_ep *dep; 630 struct dwc3_ep *dep;
631 enum usb_device_state state = dwc->gadget.state;
623 u16 wLength; 632 u16 wLength;
624 u16 wValue; 633 u16 wValue;
625 634
626 if (dwc->dev_state == DWC3_DEFAULT_STATE) 635 if (state == USB_STATE_DEFAULT)
627 return -EINVAL; 636 return -EINVAL;
628 637
629 wValue = le16_to_cpu(ctrl->wValue); 638 wValue = le16_to_cpu(ctrl->wValue);
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 82e160e96fca..2b6e7e001207 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1425,8 +1425,10 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on)
1425 if (dwc->revision >= DWC3_REVISION_194A) 1425 if (dwc->revision >= DWC3_REVISION_194A)
1426 reg &= ~DWC3_DCTL_KEEP_CONNECT; 1426 reg &= ~DWC3_DCTL_KEEP_CONNECT;
1427 reg |= DWC3_DCTL_RUN_STOP; 1427 reg |= DWC3_DCTL_RUN_STOP;
1428 dwc->pullups_connected = true;
1428 } else { 1429 } else {
1429 reg &= ~DWC3_DCTL_RUN_STOP; 1430 reg &= ~DWC3_DCTL_RUN_STOP;
1431 dwc->pullups_connected = false;
1430 } 1432 }
1431 1433
1432 dwc3_writel(dwc->regs, DWC3_DCTL, reg); 1434 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
@@ -1469,6 +1471,33 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
1469 return ret; 1471 return ret;
1470} 1472}
1471 1473
1474static void dwc3_gadget_enable_irq(struct dwc3 *dwc)
1475{
1476 u32 reg;
1477
1478 /* Enable all but Start and End of Frame IRQs */
1479 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
1480 DWC3_DEVTEN_EVNTOVERFLOWEN |
1481 DWC3_DEVTEN_CMDCMPLTEN |
1482 DWC3_DEVTEN_ERRTICERREN |
1483 DWC3_DEVTEN_WKUPEVTEN |
1484 DWC3_DEVTEN_ULSTCNGEN |
1485 DWC3_DEVTEN_CONNECTDONEEN |
1486 DWC3_DEVTEN_USBRSTEN |
1487 DWC3_DEVTEN_DISCONNEVTEN);
1488
1489 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
1490}
1491
1492static void dwc3_gadget_disable_irq(struct dwc3 *dwc)
1493{
1494 /* mask all interrupts */
1495 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
1496}
1497
1498static irqreturn_t dwc3_interrupt(int irq, void *_dwc);
1499static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc);
1500
1472static int dwc3_gadget_start(struct usb_gadget *g, 1501static int dwc3_gadget_start(struct usb_gadget *g,
1473 struct usb_gadget_driver *driver) 1502 struct usb_gadget_driver *driver)
1474{ 1503{
@@ -1476,6 +1505,7 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1476 struct dwc3_ep *dep; 1505 struct dwc3_ep *dep;
1477 unsigned long flags; 1506 unsigned long flags;
1478 int ret = 0; 1507 int ret = 0;
1508 int irq;
1479 u32 reg; 1509 u32 reg;
1480 1510
1481 spin_lock_irqsave(&dwc->lock, flags); 1511 spin_lock_irqsave(&dwc->lock, flags);
@@ -1489,7 +1519,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1489 } 1519 }
1490 1520
1491 dwc->gadget_driver = driver; 1521 dwc->gadget_driver = driver;
1492 dwc->gadget.dev.driver = &driver->driver;
1493 1522
1494 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 1523 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
1495 reg &= ~(DWC3_DCFG_SPEED_MASK); 1524 reg &= ~(DWC3_DCFG_SPEED_MASK);
@@ -1536,6 +1565,17 @@ static int dwc3_gadget_start(struct usb_gadget *g,
1536 dwc->ep0state = EP0_SETUP_PHASE; 1565 dwc->ep0state = EP0_SETUP_PHASE;
1537 dwc3_ep0_out_start(dwc); 1566 dwc3_ep0_out_start(dwc);
1538 1567
1568 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1569 ret = request_threaded_irq(irq, dwc3_interrupt, dwc3_thread_interrupt,
1570 IRQF_SHARED | IRQF_ONESHOT, "dwc3", dwc);
1571 if (ret) {
1572 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
1573 irq, ret);
1574 goto err1;
1575 }
1576
1577 dwc3_gadget_enable_irq(dwc);
1578
1539 spin_unlock_irqrestore(&dwc->lock, flags); 1579 spin_unlock_irqrestore(&dwc->lock, flags);
1540 1580
1541 return 0; 1581 return 0;
@@ -1554,14 +1594,18 @@ static int dwc3_gadget_stop(struct usb_gadget *g,
1554{ 1594{
1555 struct dwc3 *dwc = gadget_to_dwc(g); 1595 struct dwc3 *dwc = gadget_to_dwc(g);
1556 unsigned long flags; 1596 unsigned long flags;
1597 int irq;
1557 1598
1558 spin_lock_irqsave(&dwc->lock, flags); 1599 spin_lock_irqsave(&dwc->lock, flags);
1559 1600
1601 dwc3_gadget_disable_irq(dwc);
1602 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
1603 free_irq(irq, dwc);
1604
1560 __dwc3_gadget_ep_disable(dwc->eps[0]); 1605 __dwc3_gadget_ep_disable(dwc->eps[0]);
1561 __dwc3_gadget_ep_disable(dwc->eps[1]); 1606 __dwc3_gadget_ep_disable(dwc->eps[1]);
1562 1607
1563 dwc->gadget_driver = NULL; 1608 dwc->gadget_driver = NULL;
1564 dwc->gadget.dev.driver = NULL;
1565 1609
1566 spin_unlock_irqrestore(&dwc->lock, flags); 1610 spin_unlock_irqrestore(&dwc->lock, flags);
1567 1611
@@ -1579,14 +1623,15 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
1579 1623
1580/* -------------------------------------------------------------------------- */ 1624/* -------------------------------------------------------------------------- */
1581 1625
1582static int dwc3_gadget_init_endpoints(struct dwc3 *dwc) 1626static int dwc3_gadget_init_hw_endpoints(struct dwc3 *dwc,
1627 u8 num, u32 direction)
1583{ 1628{
1584 struct dwc3_ep *dep; 1629 struct dwc3_ep *dep;
1585 u8 epnum; 1630 u8 i;
1586 1631
1587 INIT_LIST_HEAD(&dwc->gadget.ep_list); 1632 for (i = 0; i < num; i++) {
1633 u8 epnum = (i << 1) | (!!direction);
1588 1634
1589 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
1590 dep = kzalloc(sizeof(*dep), GFP_KERNEL); 1635 dep = kzalloc(sizeof(*dep), GFP_KERNEL);
1591 if (!dep) { 1636 if (!dep) {
1592 dev_err(dwc->dev, "can't allocate endpoint %d\n", 1637 dev_err(dwc->dev, "can't allocate endpoint %d\n",
@@ -1600,6 +1645,7 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1600 1645
1601 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1, 1646 snprintf(dep->name, sizeof(dep->name), "ep%d%s", epnum >> 1,
1602 (epnum & 1) ? "in" : "out"); 1647 (epnum & 1) ? "in" : "out");
1648
1603 dep->endpoint.name = dep->name; 1649 dep->endpoint.name = dep->name;
1604 dep->direction = (epnum & 1); 1650 dep->direction = (epnum & 1);
1605 1651
@@ -1630,6 +1676,27 @@ static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1630 return 0; 1676 return 0;
1631} 1677}
1632 1678
1679static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
1680{
1681 int ret;
1682
1683 INIT_LIST_HEAD(&dwc->gadget.ep_list);
1684
1685 ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_out_eps, 0);
1686 if (ret < 0) {
1687 dev_vdbg(dwc->dev, "failed to allocate OUT endpoints\n");
1688 return ret;
1689 }
1690
1691 ret = dwc3_gadget_init_hw_endpoints(dwc, dwc->num_in_eps, 1);
1692 if (ret < 0) {
1693 dev_vdbg(dwc->dev, "failed to allocate IN endpoints\n");
1694 return ret;
1695 }
1696
1697 return 0;
1698}
1699
1633static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) 1700static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1634{ 1701{
1635 struct dwc3_ep *dep; 1702 struct dwc3_ep *dep;
@@ -1637,6 +1704,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1637 1704
1638 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) { 1705 for (epnum = 0; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
1639 dep = dwc->eps[epnum]; 1706 dep = dwc->eps[epnum];
1707 if (!dep)
1708 continue;
1709
1640 dwc3_free_trb_pool(dep); 1710 dwc3_free_trb_pool(dep);
1641 1711
1642 if (epnum != 0 && epnum != 1) 1712 if (epnum != 0 && epnum != 1)
@@ -1646,12 +1716,8 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
1646 } 1716 }
1647} 1717}
1648 1718
1649static void dwc3_gadget_release(struct device *dev)
1650{
1651 dev_dbg(dev, "%s\n", __func__);
1652}
1653
1654/* -------------------------------------------------------------------------- */ 1719/* -------------------------------------------------------------------------- */
1720
1655static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep, 1721static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
1656 struct dwc3_request *req, struct dwc3_trb *trb, 1722 struct dwc3_request *req, struct dwc3_trb *trb,
1657 const struct dwc3_event_depevt *event, int status) 1723 const struct dwc3_event_depevt *event, int status)
@@ -1975,6 +2041,9 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc)
1975 struct dwc3_ep *dep; 2041 struct dwc3_ep *dep;
1976 2042
1977 dep = dwc->eps[epnum]; 2043 dep = dwc->eps[epnum];
2044 if (!dep)
2045 continue;
2046
1978 if (!(dep->flags & DWC3_EP_ENABLED)) 2047 if (!(dep->flags & DWC3_EP_ENABLED))
1979 continue; 2048 continue;
1980 2049
@@ -1992,6 +2061,8 @@ static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
1992 int ret; 2061 int ret;
1993 2062
1994 dep = dwc->eps[epnum]; 2063 dep = dwc->eps[epnum];
2064 if (!dep)
2065 continue;
1995 2066
1996 if (!(dep->flags & DWC3_EP_STALL)) 2067 if (!(dep->flags & DWC3_EP_STALL))
1997 continue; 2068 continue;
@@ -2091,7 +2162,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
2091 } 2162 }
2092 2163
2093 /* after reset -> Default State */ 2164 /* after reset -> Default State */
2094 dwc->dev_state = DWC3_DEFAULT_STATE; 2165 usb_gadget_set_state(&dwc->gadget, USB_STATE_DEFAULT);
2095 2166
2096 /* Recent versions support automatic phy suspend and don't need this */ 2167 /* Recent versions support automatic phy suspend and don't need this */
2097 if (dwc->revision < DWC3_REVISION_194A) { 2168 if (dwc->revision < DWC3_REVISION_194A) {
@@ -2277,6 +2348,34 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc,
2277 unsigned int evtinfo) 2348 unsigned int evtinfo)
2278{ 2349{
2279 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK; 2350 enum dwc3_link_state next = evtinfo & DWC3_LINK_STATE_MASK;
2351 unsigned int pwropt;
2352
2353 /*
2354 * WORKAROUND: DWC3 < 2.50a have an issue when configured without
2355 * Hibernation mode enabled which would show up when device detects
2356 * host-initiated U3 exit.
2357 *
2358 * In that case, device will generate a Link State Change Interrupt
2359 * from U3 to RESUME which is only necessary if Hibernation is
2360 * configured in.
2361 *
2362 * There are no functional changes due to such spurious event and we
2363 * just need to ignore it.
2364 *
2365 * Refers to:
2366 *
2367 * STAR#9000570034 RTL: SS Resume event generated in non-Hibernation
2368 * operational mode
2369 */
2370 pwropt = DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1);
2371 if ((dwc->revision < DWC3_REVISION_250A) &&
2372 (pwropt != DWC3_GHWPARAMS1_EN_PWROPT_HIB)) {
2373 if ((dwc->link_state == DWC3_LINK_STATE_U3) &&
2374 (next == DWC3_LINK_STATE_RESUME)) {
2375 dev_vdbg(dwc->dev, "ignoring transition U3 -> Resume\n");
2376 return;
2377 }
2378 }
2280 2379
2281 /* 2380 /*
2282 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending 2381 * WORKAROUND: DWC3 Revisions <1.83a have an issue which, depending
@@ -2387,40 +2486,73 @@ static void dwc3_process_event_entry(struct dwc3 *dwc,
2387 } 2486 }
2388} 2487}
2389 2488
2489static irqreturn_t dwc3_thread_interrupt(int irq, void *_dwc)
2490{
2491 struct dwc3 *dwc = _dwc;
2492 unsigned long flags;
2493 irqreturn_t ret = IRQ_NONE;
2494 int i;
2495
2496 spin_lock_irqsave(&dwc->lock, flags);
2497
2498 for (i = 0; i < dwc->num_event_buffers; i++) {
2499 struct dwc3_event_buffer *evt;
2500 int left;
2501
2502 evt = dwc->ev_buffs[i];
2503 left = evt->count;
2504
2505 if (!(evt->flags & DWC3_EVENT_PENDING))
2506 continue;
2507
2508 while (left > 0) {
2509 union dwc3_event event;
2510
2511 event.raw = *(u32 *) (evt->buf + evt->lpos);
2512
2513 dwc3_process_event_entry(dwc, &event);
2514
2515 /*
2516 * FIXME we wrap around correctly to the next entry as
2517 * almost all entries are 4 bytes in size. There is one
2518 * entry which has 12 bytes which is a regular entry
2519 * followed by 8 bytes data. ATM I don't know how
2520 * things are organized if we get next to the a
2521 * boundary so I worry about that once we try to handle
2522 * that.
2523 */
2524 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2525 left -= 4;
2526
2527 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(i), 4);
2528 }
2529
2530 evt->count = 0;
2531 evt->flags &= ~DWC3_EVENT_PENDING;
2532 ret = IRQ_HANDLED;
2533 }
2534
2535 spin_unlock_irqrestore(&dwc->lock, flags);
2536
2537 return ret;
2538}
2539
2390static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf) 2540static irqreturn_t dwc3_process_event_buf(struct dwc3 *dwc, u32 buf)
2391{ 2541{
2392 struct dwc3_event_buffer *evt; 2542 struct dwc3_event_buffer *evt;
2393 int left;
2394 u32 count; 2543 u32 count;
2395 2544
2545 evt = dwc->ev_buffs[buf];
2546
2396 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf)); 2547 count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(buf));
2397 count &= DWC3_GEVNTCOUNT_MASK; 2548 count &= DWC3_GEVNTCOUNT_MASK;
2398 if (!count) 2549 if (!count)
2399 return IRQ_NONE; 2550 return IRQ_NONE;
2400 2551
2401 evt = dwc->ev_buffs[buf]; 2552 evt->count = count;
2402 left = count; 2553 evt->flags |= DWC3_EVENT_PENDING;
2403
2404 while (left > 0) {
2405 union dwc3_event event;
2406
2407 event.raw = *(u32 *) (evt->buf + evt->lpos);
2408 2554
2409 dwc3_process_event_entry(dwc, &event); 2555 return IRQ_WAKE_THREAD;
2410 /*
2411 * XXX we wrap around correctly to the next entry as almost all
2412 * entries are 4 bytes in size. There is one entry which has 12
2413 * bytes which is a regular entry followed by 8 bytes data. ATM
2414 * I don't know how things are organized if were get next to the
2415 * a boundary so I worry about that once we try to handle that.
2416 */
2417 evt->lpos = (evt->lpos + 4) % DWC3_EVENT_BUFFERS_SIZE;
2418 left -= 4;
2419
2420 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(buf), 4);
2421 }
2422
2423 return IRQ_HANDLED;
2424} 2556}
2425 2557
2426static irqreturn_t dwc3_interrupt(int irq, void *_dwc) 2558static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
@@ -2435,7 +2567,7 @@ static irqreturn_t dwc3_interrupt(int irq, void *_dwc)
2435 irqreturn_t status; 2567 irqreturn_t status;
2436 2568
2437 status = dwc3_process_event_buf(dwc, i); 2569 status = dwc3_process_event_buf(dwc, i);
2438 if (status == IRQ_HANDLED) 2570 if (status == IRQ_WAKE_THREAD)
2439 ret = status; 2571 ret = status;
2440 } 2572 }
2441 2573
@@ -2454,7 +2586,6 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2454{ 2586{
2455 u32 reg; 2587 u32 reg;
2456 int ret; 2588 int ret;
2457 int irq;
2458 2589
2459 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2590 dwc->ctrl_req = dma_alloc_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
2460 &dwc->ctrl_req_addr, GFP_KERNEL); 2591 &dwc->ctrl_req_addr, GFP_KERNEL);
@@ -2488,19 +2619,10 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2488 goto err3; 2619 goto err3;
2489 } 2620 }
2490 2621
2491 dev_set_name(&dwc->gadget.dev, "gadget");
2492
2493 dwc->gadget.ops = &dwc3_gadget_ops; 2622 dwc->gadget.ops = &dwc3_gadget_ops;
2494 dwc->gadget.max_speed = USB_SPEED_SUPER; 2623 dwc->gadget.max_speed = USB_SPEED_SUPER;
2495 dwc->gadget.speed = USB_SPEED_UNKNOWN; 2624 dwc->gadget.speed = USB_SPEED_UNKNOWN;
2496 dwc->gadget.dev.parent = dwc->dev;
2497 dwc->gadget.sg_supported = true; 2625 dwc->gadget.sg_supported = true;
2498
2499 dma_set_coherent_mask(&dwc->gadget.dev, dwc->dev->coherent_dma_mask);
2500
2501 dwc->gadget.dev.dma_parms = dwc->dev->dma_parms;
2502 dwc->gadget.dev.dma_mask = dwc->dev->dma_mask;
2503 dwc->gadget.dev.release = dwc3_gadget_release;
2504 dwc->gadget.name = "dwc3-gadget"; 2626 dwc->gadget.name = "dwc3-gadget";
2505 2627
2506 /* 2628 /*
@@ -2512,60 +2634,24 @@ int dwc3_gadget_init(struct dwc3 *dwc)
2512 if (ret) 2634 if (ret)
2513 goto err4; 2635 goto err4;
2514 2636
2515 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2516
2517 ret = request_irq(irq, dwc3_interrupt, IRQF_SHARED,
2518 "dwc3", dwc);
2519 if (ret) {
2520 dev_err(dwc->dev, "failed to request irq #%d --> %d\n",
2521 irq, ret);
2522 goto err5;
2523 }
2524
2525 reg = dwc3_readl(dwc->regs, DWC3_DCFG); 2637 reg = dwc3_readl(dwc->regs, DWC3_DCFG);
2526 reg |= DWC3_DCFG_LPM_CAP; 2638 reg |= DWC3_DCFG_LPM_CAP;
2527 dwc3_writel(dwc->regs, DWC3_DCFG, reg); 2639 dwc3_writel(dwc->regs, DWC3_DCFG, reg);
2528 2640
2529 /* Enable all but Start and End of Frame IRQs */ 2641 /* Enable USB2 LPM and automatic phy suspend only on recent versions */
2530 reg = (DWC3_DEVTEN_VNDRDEVTSTRCVEDEN |
2531 DWC3_DEVTEN_EVNTOVERFLOWEN |
2532 DWC3_DEVTEN_CMDCMPLTEN |
2533 DWC3_DEVTEN_ERRTICERREN |
2534 DWC3_DEVTEN_WKUPEVTEN |
2535 DWC3_DEVTEN_ULSTCNGEN |
2536 DWC3_DEVTEN_CONNECTDONEEN |
2537 DWC3_DEVTEN_USBRSTEN |
2538 DWC3_DEVTEN_DISCONNEVTEN);
2539 dwc3_writel(dwc->regs, DWC3_DEVTEN, reg);
2540
2541 /* automatic phy suspend only on recent versions */
2542 if (dwc->revision >= DWC3_REVISION_194A) { 2642 if (dwc->revision >= DWC3_REVISION_194A) {
2543 dwc3_gadget_usb2_phy_suspend(dwc, false); 2643 dwc3_gadget_usb2_phy_suspend(dwc, false);
2544 dwc3_gadget_usb3_phy_suspend(dwc, false); 2644 dwc3_gadget_usb3_phy_suspend(dwc, false);
2545 } 2645 }
2546 2646
2547 ret = device_register(&dwc->gadget.dev);
2548 if (ret) {
2549 dev_err(dwc->dev, "failed to register gadget device\n");
2550 put_device(&dwc->gadget.dev);
2551 goto err6;
2552 }
2553
2554 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget); 2647 ret = usb_add_gadget_udc(dwc->dev, &dwc->gadget);
2555 if (ret) { 2648 if (ret) {
2556 dev_err(dwc->dev, "failed to register udc\n"); 2649 dev_err(dwc->dev, "failed to register udc\n");
2557 goto err7; 2650 goto err5;
2558 } 2651 }
2559 2652
2560 return 0; 2653 return 0;
2561 2654
2562err7:
2563 device_unregister(&dwc->gadget.dev);
2564
2565err6:
2566 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
2567 free_irq(irq, dwc);
2568
2569err5: 2655err5:
2570 dwc3_gadget_free_endpoints(dwc); 2656 dwc3_gadget_free_endpoints(dwc);
2571 2657
@@ -2588,15 +2674,11 @@ err0:
2588 return ret; 2674 return ret;
2589} 2675}
2590 2676
2677/* -------------------------------------------------------------------------- */
2678
2591void dwc3_gadget_exit(struct dwc3 *dwc) 2679void dwc3_gadget_exit(struct dwc3 *dwc)
2592{ 2680{
2593 int irq;
2594
2595 usb_del_gadget_udc(&dwc->gadget); 2681 usb_del_gadget_udc(&dwc->gadget);
2596 irq = platform_get_irq(to_platform_device(dwc->dev), 0);
2597
2598 dwc3_writel(dwc->regs, DWC3_DEVTEN, 0x00);
2599 free_irq(irq, dwc);
2600 2682
2601 dwc3_gadget_free_endpoints(dwc); 2683 dwc3_gadget_free_endpoints(dwc);
2602 2684
@@ -2610,6 +2692,63 @@ void dwc3_gadget_exit(struct dwc3 *dwc)
2610 2692
2611 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req), 2693 dma_free_coherent(dwc->dev, sizeof(*dwc->ctrl_req),
2612 dwc->ctrl_req, dwc->ctrl_req_addr); 2694 dwc->ctrl_req, dwc->ctrl_req_addr);
2695}
2613 2696
2614 device_unregister(&dwc->gadget.dev); 2697int dwc3_gadget_prepare(struct dwc3 *dwc)
2698{
2699 if (dwc->pullups_connected)
2700 dwc3_gadget_disable_irq(dwc);
2701
2702 return 0;
2703}
2704
2705void dwc3_gadget_complete(struct dwc3 *dwc)
2706{
2707 if (dwc->pullups_connected) {
2708 dwc3_gadget_enable_irq(dwc);
2709 dwc3_gadget_run_stop(dwc, true);
2710 }
2711}
2712
2713int dwc3_gadget_suspend(struct dwc3 *dwc)
2714{
2715 __dwc3_gadget_ep_disable(dwc->eps[0]);
2716 __dwc3_gadget_ep_disable(dwc->eps[1]);
2717
2718 dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
2719
2720 return 0;
2721}
2722
2723int dwc3_gadget_resume(struct dwc3 *dwc)
2724{
2725 struct dwc3_ep *dep;
2726 int ret;
2727
2728 /* Start with SuperSpeed Default */
2729 dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
2730
2731 dep = dwc->eps[0];
2732 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2733 if (ret)
2734 goto err0;
2735
2736 dep = dwc->eps[1];
2737 ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false);
2738 if (ret)
2739 goto err1;
2740
2741 /* begin to receive SETUP packets */
2742 dwc->ep0state = EP0_SETUP_PHASE;
2743 dwc3_ep0_out_start(dwc);
2744
2745 dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
2746
2747 return 0;
2748
2749err1:
2750 __dwc3_gadget_ep_disable(dwc->eps[0]);
2751
2752err0:
2753 return ret;
2615} 2754}
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index c7525b1cad74..83300d94a893 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -144,6 +144,7 @@ config USB_AT91
144config USB_LPC32XX 144config USB_LPC32XX
145 tristate "LPC32XX USB Peripheral Controller" 145 tristate "LPC32XX USB Peripheral Controller"
146 depends on ARCH_LPC32XX 146 depends on ARCH_LPC32XX
147 depends on USB_PHY
147 select USB_ISP1301 148 select USB_ISP1301
148 select USB_OTG_UTILS 149 select USB_OTG_UTILS
149 help 150 help
@@ -195,8 +196,8 @@ config USB_FUSB300
195config USB_OMAP 196config USB_OMAP
196 tristate "OMAP USB Device Controller" 197 tristate "OMAP USB Device Controller"
197 depends on ARCH_OMAP1 198 depends on ARCH_OMAP1
199 depends on USB_PHY
198 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG 200 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_H4_OTG
199 select USB_OTG_UTILS if ARCH_OMAP
200 help 201 help
201 Many Texas Instruments OMAP processors have flexible full 202 Many Texas Instruments OMAP processors have flexible full
202 speed USB device controllers, with support for up to 30 203 speed USB device controllers, with support for up to 30
@@ -211,7 +212,6 @@ config USB_OMAP
211config USB_PXA25X 212config USB_PXA25X
212 tristate "PXA 25x or IXP 4xx" 213 tristate "PXA 25x or IXP 4xx"
213 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX 214 depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
214 select USB_OTG_UTILS
215 help 215 help
216 Intel's PXA 25x series XScale ARM-5TE processors include 216 Intel's PXA 25x series XScale ARM-5TE processors include
217 an integrated full speed USB 1.1 device controller. The 217 an integrated full speed USB 1.1 device controller. The
@@ -259,8 +259,6 @@ config USB_RENESAS_USBHS_UDC
259 259
260config USB_PXA27X 260config USB_PXA27X
261 tristate "PXA 27x" 261 tristate "PXA 27x"
262 depends on ARCH_PXA && (PXA27x || PXA3xx)
263 select USB_OTG_UTILS
264 help 262 help
265 Intel's PXA 27x series XScale ARM v5TE processors include 263 Intel's PXA 27x series XScale ARM v5TE processors include
266 an integrated full speed USB 1.1 device controller. 264 an integrated full speed USB 1.1 device controller.
@@ -329,9 +327,6 @@ config USB_MV_UDC
329 327
330config USB_MV_U3D 328config USB_MV_U3D
331 tristate "MARVELL PXA2128 USB 3.0 controller" 329 tristate "MARVELL PXA2128 USB 3.0 controller"
332 depends on CPU_MMP3
333 select USB_GADGET_DUALSPEED
334 select USB_GADGET_SUPERSPEED
335 help 330 help
336 MARVELL PXA2128 Processor series include a super speed USB3.0 device 331 MARVELL PXA2128 Processor series include a super speed USB3.0 device
337 controller, which support super speed USB peripheral. 332 controller, which support super speed USB peripheral.
@@ -501,6 +496,7 @@ endmenu
501# composite based drivers 496# composite based drivers
502config USB_LIBCOMPOSITE 497config USB_LIBCOMPOSITE
503 tristate 498 tristate
499 select CONFIGFS_FS
504 depends on USB_GADGET 500 depends on USB_GADGET
505 501
506config USB_F_ACM 502config USB_F_ACM
@@ -512,6 +508,12 @@ config USB_F_SS_LB
512config USB_U_SERIAL 508config USB_U_SERIAL
513 tristate 509 tristate
514 510
511config USB_F_SERIAL
512 tristate
513
514config USB_F_OBEX
515 tristate
516
515choice 517choice
516 tristate "USB Gadget Drivers" 518 tristate "USB Gadget Drivers"
517 default USB_ETH 519 default USB_ETH
@@ -766,6 +768,8 @@ config USB_G_SERIAL
766 depends on TTY 768 depends on TTY
767 select USB_U_SERIAL 769 select USB_U_SERIAL
768 select USB_F_ACM 770 select USB_F_ACM
771 select USB_F_SERIAL
772 select USB_F_OBEX
769 select USB_LIBCOMPOSITE 773 select USB_LIBCOMPOSITE
770 help 774 help
771 The Serial Gadget talks to the Linux-USB generic serial driver. 775 The Serial Gadget talks to the Linux-USB generic serial driver.
@@ -839,6 +843,7 @@ config USB_G_NOKIA
839 depends on PHONET 843 depends on PHONET
840 select USB_LIBCOMPOSITE 844 select USB_LIBCOMPOSITE
841 select USB_U_SERIAL 845 select USB_U_SERIAL
846 select USB_F_ACM
842 help 847 help
843 The Nokia composite gadget provides support for acm, obex 848 The Nokia composite gadget provides support for acm, obex
844 and phonet in only one composite gadget driver. 849 and phonet in only one composite gadget driver.
@@ -957,6 +962,7 @@ config USB_G_WEBCAM
957 tristate "USB Webcam Gadget" 962 tristate "USB Webcam Gadget"
958 depends on VIDEO_DEV 963 depends on VIDEO_DEV
959 select USB_LIBCOMPOSITE 964 select USB_LIBCOMPOSITE
965 select VIDEOBUF2_VMALLOC
960 help 966 help
961 The Webcam Gadget acts as a composite USB Audio and Video Class 967 The Webcam Gadget acts as a composite USB Audio and Video Class
962 device. It provides a userspace API to process UVC control requests 968 device. It provides a userspace API to process UVC control requests
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 82fb22511356..6afd16659e78 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -6,7 +6,7 @@ ccflags-$(CONFIG_USB_GADGET_DEBUG) := -DDEBUG
6obj-$(CONFIG_USB_GADGET) += udc-core.o 6obj-$(CONFIG_USB_GADGET) += udc-core.o
7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o 7obj-$(CONFIG_USB_LIBCOMPOSITE) += libcomposite.o
8libcomposite-y := usbstring.o config.o epautoconf.o 8libcomposite-y := usbstring.o config.o epautoconf.o
9libcomposite-y += composite.o functions.o 9libcomposite-y += composite.o functions.o configfs.o
10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 10obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
11obj-$(CONFIG_USB_NET2272) += net2272.o 11obj-$(CONFIG_USB_NET2272) += net2272.o
12obj-$(CONFIG_USB_NET2280) += net2280.o 12obj-$(CONFIG_USB_NET2280) += net2280.o
@@ -36,10 +36,15 @@ obj-$(CONFIG_USB_FUSB300) += fusb300_udc.o
36obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o 36obj-$(CONFIG_USB_MV_U3D) += mv_u3d_core.o
37 37
38# USB Functions 38# USB Functions
39obj-$(CONFIG_USB_F_ACM) += f_acm.o 39usb_f_acm-y := f_acm.o
40f_ss_lb-y := f_loopback.o f_sourcesink.o 40obj-$(CONFIG_USB_F_ACM) += usb_f_acm.o
41obj-$(CONFIG_USB_F_SS_LB) += f_ss_lb.o 41usb_f_ss_lb-y := f_loopback.o f_sourcesink.o
42obj-$(CONFIG_USB_F_SS_LB) += usb_f_ss_lb.o
42obj-$(CONFIG_USB_U_SERIAL) += u_serial.o 43obj-$(CONFIG_USB_U_SERIAL) += u_serial.o
44usb_f_serial-y := f_serial.o
45obj-$(CONFIG_USB_F_SERIAL) += usb_f_serial.o
46usb_f_obex-y := f_obex.o
47obj-$(CONFIG_USB_F_OBEX) += usb_f_obex.o
43 48
44# 49#
45# USB gadget drivers 50# USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 8f2b0e391534..4b947bb50f62 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -109,7 +109,6 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
109static struct fsg_common fsg_common; 109static struct fsg_common fsg_common;
110 110
111/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
112static unsigned char tty_line;
113static struct usb_function *f_acm; 112static struct usb_function *f_acm;
114static struct usb_function_instance *f_acm_inst; 113static struct usb_function_instance *f_acm_inst;
115/* 114/*
@@ -117,7 +116,6 @@ static struct usb_function_instance *f_acm_inst;
117 */ 116 */
118static int __init acm_ms_do_config(struct usb_configuration *c) 117static int __init acm_ms_do_config(struct usb_configuration *c)
119{ 118{
120 struct f_serial_opts *opts;
121 int status; 119 int status;
122 120
123 if (gadget_is_otg(c->cdev->gadget)) { 121 if (gadget_is_otg(c->cdev->gadget)) {
@@ -129,9 +127,6 @@ static int __init acm_ms_do_config(struct usb_configuration *c)
129 if (IS_ERR(f_acm_inst)) 127 if (IS_ERR(f_acm_inst))
130 return PTR_ERR(f_acm_inst); 128 return PTR_ERR(f_acm_inst);
131 129
132 opts = container_of(f_acm_inst, struct f_serial_opts, func_inst);
133 opts->port_num = tty_line;
134
135 f_acm = usb_get_function(f_acm_inst); 130 f_acm = usb_get_function(f_acm_inst);
136 if (IS_ERR(f_acm)) { 131 if (IS_ERR(f_acm)) {
137 status = PTR_ERR(f_acm); 132 status = PTR_ERR(f_acm);
@@ -171,16 +166,11 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
171 int status; 166 int status;
172 void *retp; 167 void *retp;
173 168
174 /* set up serial link layer */
175 status = gserial_alloc_line(&tty_line);
176 if (status < 0)
177 return status;
178
179 /* set up mass storage function */ 169 /* set up mass storage function */
180 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data); 170 retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
181 if (IS_ERR(retp)) { 171 if (IS_ERR(retp)) {
182 status = PTR_ERR(retp); 172 status = PTR_ERR(retp);
183 goto fail0; 173 return PTR_ERR(retp);
184 } 174 }
185 175
186 /* 176 /*
@@ -207,8 +197,6 @@ static int __init acm_ms_bind(struct usb_composite_dev *cdev)
207 /* error recovery */ 197 /* error recovery */
208fail1: 198fail1:
209 fsg_common_put(&fsg_common); 199 fsg_common_put(&fsg_common);
210fail0:
211 gserial_free_line(tty_line);
212 return status; 200 return status;
213} 201}
214 202
@@ -216,7 +204,6 @@ static int __exit acm_ms_unbind(struct usb_composite_dev *cdev)
216{ 204{
217 usb_put_function(f_acm); 205 usb_put_function(f_acm);
218 usb_put_function_instance(f_acm_inst); 206 usb_put_function_instance(f_acm_inst);
219 gserial_free_line(tty_line);
220 return 0; 207 return 0;
221} 208}
222 209
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index 75973f33a4c8..f52dcfe8f545 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -1922,7 +1922,6 @@ static int amd5536_udc_start(struct usb_gadget *g,
1922 1922
1923 driver->driver.bus = NULL; 1923 driver->driver.bus = NULL;
1924 dev->driver = driver; 1924 dev->driver = driver;
1925 dev->gadget.dev.driver = &driver->driver;
1926 1925
1927 /* Some gadget drivers use both ep0 directions. 1926 /* Some gadget drivers use both ep0 directions.
1928 * NOTE: to gadget driver, ep0 is just one endpoint... 1927 * NOTE: to gadget driver, ep0 is just one endpoint...
@@ -1973,7 +1972,6 @@ static int amd5536_udc_stop(struct usb_gadget *g,
1973 shutdown(dev, driver); 1972 shutdown(dev, driver);
1974 spin_unlock_irqrestore(&dev->lock, flags); 1973 spin_unlock_irqrestore(&dev->lock, flags);
1975 1974
1976 dev->gadget.dev.driver = NULL;
1977 dev->driver = NULL; 1975 dev->driver = NULL;
1978 1976
1979 /* set SD */ 1977 /* set SD */
@@ -3080,7 +3078,6 @@ static void udc_pci_remove(struct pci_dev *pdev)
3080 if (dev->active) 3078 if (dev->active)
3081 pci_disable_device(pdev); 3079 pci_disable_device(pdev);
3082 3080
3083 device_unregister(&dev->gadget.dev);
3084 pci_set_drvdata(pdev, NULL); 3081 pci_set_drvdata(pdev, NULL);
3085 3082
3086 udc_remove(dev); 3083 udc_remove(dev);
@@ -3245,8 +3242,6 @@ static int udc_pci_probe(
3245 dev->phys_addr = resource; 3242 dev->phys_addr = resource;
3246 dev->irq = pdev->irq; 3243 dev->irq = pdev->irq;
3247 dev->pdev = pdev; 3244 dev->pdev = pdev;
3248 dev->gadget.dev.parent = &pdev->dev;
3249 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
3250 3245
3251 /* general probing */ 3246 /* general probing */
3252 if (udc_probe(dev) == 0) 3247 if (udc_probe(dev) == 0)
@@ -3273,7 +3268,6 @@ static int udc_probe(struct udc *dev)
3273 dev->gadget.ops = &udc_ops; 3268 dev->gadget.ops = &udc_ops;
3274 3269
3275 dev_set_name(&dev->gadget.dev, "gadget"); 3270 dev_set_name(&dev->gadget.dev, "gadget");
3276 dev->gadget.dev.release = gadget_release;
3277 dev->gadget.name = name; 3271 dev->gadget.name = name;
3278 dev->gadget.max_speed = USB_SPEED_HIGH; 3272 dev->gadget.max_speed = USB_SPEED_HIGH;
3279 3273
@@ -3297,17 +3291,11 @@ static int udc_probe(struct udc *dev)
3297 "driver version: %s(for Geode5536 B1)\n", tmp); 3291 "driver version: %s(for Geode5536 B1)\n", tmp);
3298 udc = dev; 3292 udc = dev;
3299 3293
3300 retval = usb_add_gadget_udc(&udc->pdev->dev, &dev->gadget); 3294 retval = usb_add_gadget_udc_release(&udc->pdev->dev, &dev->gadget,
3295 gadget_release);
3301 if (retval) 3296 if (retval)
3302 goto finished; 3297 goto finished;
3303 3298
3304 retval = device_register(&dev->gadget.dev);
3305 if (retval) {
3306 usb_del_gadget_udc(&dev->gadget);
3307 put_device(&dev->gadget.dev);
3308 goto finished;
3309 }
3310
3311 /* timer init */ 3299 /* timer init */
3312 init_timer(&udc_timer); 3300 init_timer(&udc_timer);
3313 udc_timer.function = udc_timer_function; 3301 udc_timer.function = udc_timer_function;
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h
index f1bf32e6b8d8..6744d3b83109 100644
--- a/drivers/usb/gadget/amd5536udc.h
+++ b/drivers/usb/gadget/amd5536udc.h
@@ -472,7 +472,6 @@ struct udc_request {
472 472
473 /* flags */ 473 /* flags */
474 unsigned dma_going : 1, 474 unsigned dma_going : 1,
475 dma_mapping : 1,
476 dma_done : 1; 475 dma_done : 1;
477 /* phys. address */ 476 /* phys. address */
478 dma_addr_t td_phys; 477 dma_addr_t td_phys;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 45dd2929a671..a690d64217f4 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1631,7 +1631,6 @@ static int at91_start(struct usb_gadget *gadget,
1631 1631
1632 udc = container_of(gadget, struct at91_udc, gadget); 1632 udc = container_of(gadget, struct at91_udc, gadget);
1633 udc->driver = driver; 1633 udc->driver = driver;
1634 udc->gadget.dev.driver = &driver->driver;
1635 udc->gadget.dev.of_node = udc->pdev->dev.of_node; 1634 udc->gadget.dev.of_node = udc->pdev->dev.of_node;
1636 udc->enabled = 1; 1635 udc->enabled = 1;
1637 udc->selfpowered = 1; 1636 udc->selfpowered = 1;
@@ -1652,7 +1651,6 @@ static int at91_stop(struct usb_gadget *gadget,
1652 at91_udp_write(udc, AT91_UDP_IDR, ~0); 1651 at91_udp_write(udc, AT91_UDP_IDR, ~0);
1653 spin_unlock_irqrestore(&udc->lock, flags); 1652 spin_unlock_irqrestore(&udc->lock, flags);
1654 1653
1655 udc->gadget.dev.driver = NULL;
1656 udc->driver = NULL; 1654 udc->driver = NULL;
1657 1655
1658 DBG("unbound from %s\n", driver->driver.name); 1656 DBG("unbound from %s\n", driver->driver.name);
@@ -1780,13 +1778,7 @@ static int at91udc_probe(struct platform_device *pdev)
1780 DBG("clocks missing\n"); 1778 DBG("clocks missing\n");
1781 retval = -ENODEV; 1779 retval = -ENODEV;
1782 /* NOTE: we "know" here that refcounts on these are NOPs */ 1780 /* NOTE: we "know" here that refcounts on these are NOPs */
1783 goto fail0b; 1781 goto fail1;
1784 }
1785
1786 retval = device_register(&udc->gadget.dev);
1787 if (retval < 0) {
1788 put_device(&udc->gadget.dev);
1789 goto fail0b;
1790 } 1782 }
1791 1783
1792 /* don't do anything until we have both gadget driver and VBUS */ 1784 /* don't do anything until we have both gadget driver and VBUS */
@@ -1857,8 +1849,6 @@ fail3:
1857fail2: 1849fail2:
1858 free_irq(udc->udp_irq, udc); 1850 free_irq(udc->udp_irq, udc);
1859fail1: 1851fail1:
1860 device_unregister(&udc->gadget.dev);
1861fail0b:
1862 iounmap(udc->udp_baseaddr); 1852 iounmap(udc->udp_baseaddr);
1863fail0a: 1853fail0a:
1864 if (cpu_is_at91rm9200()) 1854 if (cpu_is_at91rm9200())
@@ -1892,8 +1882,6 @@ static int __exit at91udc_remove(struct platform_device *pdev)
1892 gpio_free(udc->board.vbus_pin); 1882 gpio_free(udc->board.vbus_pin);
1893 } 1883 }
1894 free_irq(udc->udp_irq, udc); 1884 free_irq(udc->udp_irq, udc);
1895 device_unregister(&udc->gadget.dev);
1896
1897 iounmap(udc->udp_baseaddr); 1885 iounmap(udc->udp_baseaddr);
1898 1886
1899 if (cpu_is_at91rm9200()) 1887 if (cpu_is_at91rm9200())
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index b66130c97269..f2a970f75bfa 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -489,13 +489,8 @@ request_complete(struct usba_ep *ep, struct usba_request *req, int status)
489 if (req->req.status == -EINPROGRESS) 489 if (req->req.status == -EINPROGRESS)
490 req->req.status = status; 490 req->req.status = status;
491 491
492 if (req->mapped) { 492 if (req->using_dma)
493 dma_unmap_single( 493 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in);
494 &udc->pdev->dev, req->req.dma, req->req.length,
495 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
496 req->req.dma = DMA_ADDR_INVALID;
497 req->mapped = 0;
498 }
499 494
500 DBG(DBG_GADGET | DBG_REQ, 495 DBG(DBG_GADGET | DBG_REQ,
501 "%s: req %p complete: status %d, actual %u\n", 496 "%s: req %p complete: status %d, actual %u\n",
@@ -684,7 +679,6 @@ usba_ep_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
684 return NULL; 679 return NULL;
685 680
686 INIT_LIST_HEAD(&req->queue); 681 INIT_LIST_HEAD(&req->queue);
687 req->req.dma = DMA_ADDR_INVALID;
688 682
689 return &req->req; 683 return &req->req;
690} 684}
@@ -717,20 +711,11 @@ static int queue_dma(struct usba_udc *udc, struct usba_ep *ep,
717 return -EINVAL; 711 return -EINVAL;
718 } 712 }
719 713
720 req->using_dma = 1; 714 ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in);
721 715 if (ret)
722 if (req->req.dma == DMA_ADDR_INVALID) { 716 return ret;
723 req->req.dma = dma_map_single(
724 &udc->pdev->dev, req->req.buf, req->req.length,
725 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
726 req->mapped = 1;
727 } else {
728 dma_sync_single_for_device(
729 &udc->pdev->dev, req->req.dma, req->req.length,
730 ep->is_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
731 req->mapped = 0;
732 }
733 717
718 req->using_dma = 1;
734 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length) 719 req->ctrl = USBA_BF(DMA_BUF_LEN, req->req.length)
735 | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE 720 | USBA_DMA_CH_EN | USBA_DMA_END_BUF_IE
736 | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE; 721 | USBA_DMA_END_TR_EN | USBA_DMA_END_TR_IE;
@@ -1799,7 +1784,6 @@ static int atmel_usba_start(struct usb_gadget *gadget,
1799 1784
1800 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; 1785 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
1801 udc->driver = driver; 1786 udc->driver = driver;
1802 udc->gadget.dev.driver = &driver->driver;
1803 spin_unlock_irqrestore(&udc->lock, flags); 1787 spin_unlock_irqrestore(&udc->lock, flags);
1804 1788
1805 clk_enable(udc->pclk); 1789 clk_enable(udc->pclk);
@@ -1841,7 +1825,6 @@ static int atmel_usba_stop(struct usb_gadget *gadget,
1841 toggle_bias(0); 1825 toggle_bias(0);
1842 usba_writel(udc, CTRL, USBA_DISABLE_MASK); 1826 usba_writel(udc, CTRL, USBA_DISABLE_MASK);
1843 1827
1844 udc->gadget.dev.driver = NULL;
1845 udc->driver = NULL; 1828 udc->driver = NULL;
1846 1829
1847 clk_disable(udc->hclk); 1830 clk_disable(udc->hclk);
@@ -1900,10 +1883,6 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1900 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n", 1883 dev_info(&pdev->dev, "FIFO at 0x%08lx mapped at %p\n",
1901 (unsigned long)fifo->start, udc->fifo); 1884 (unsigned long)fifo->start, udc->fifo);
1902 1885
1903 device_initialize(&udc->gadget.dev);
1904 udc->gadget.dev.parent = &pdev->dev;
1905 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
1906
1907 platform_set_drvdata(pdev, udc); 1886 platform_set_drvdata(pdev, udc);
1908 1887
1909 /* Make sure we start from a clean slate */ 1888 /* Make sure we start from a clean slate */
@@ -1962,12 +1941,6 @@ static int __init usba_udc_probe(struct platform_device *pdev)
1962 } 1941 }
1963 udc->irq = irq; 1942 udc->irq = irq;
1964 1943
1965 ret = device_add(&udc->gadget.dev);
1966 if (ret) {
1967 dev_dbg(&pdev->dev, "Could not add gadget: %d\n", ret);
1968 goto err_device_add;
1969 }
1970
1971 if (gpio_is_valid(pdata->vbus_pin)) { 1944 if (gpio_is_valid(pdata->vbus_pin)) {
1972 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) { 1945 if (!gpio_request(pdata->vbus_pin, "atmel_usba_udc")) {
1973 udc->vbus_pin = pdata->vbus_pin; 1946 udc->vbus_pin = pdata->vbus_pin;
@@ -2007,9 +1980,6 @@ err_add_udc:
2007 gpio_free(udc->vbus_pin); 1980 gpio_free(udc->vbus_pin);
2008 } 1981 }
2009 1982
2010 device_unregister(&udc->gadget.dev);
2011
2012err_device_add:
2013 free_irq(irq, udc); 1983 free_irq(irq, udc);
2014err_request_irq: 1984err_request_irq:
2015 kfree(usba_ep); 1985 kfree(usba_ep);
@@ -2053,8 +2023,6 @@ static int __exit usba_udc_remove(struct platform_device *pdev)
2053 clk_put(udc->hclk); 2023 clk_put(udc->hclk);
2054 clk_put(udc->pclk); 2024 clk_put(udc->pclk);
2055 2025
2056 device_unregister(&udc->gadget.dev);
2057
2058 return 0; 2026 return 0;
2059} 2027}
2060 2028
diff --git a/drivers/usb/gadget/atmel_usba_udc.h b/drivers/usb/gadget/atmel_usba_udc.h
index 9791259cbda7..d65a61851d3d 100644
--- a/drivers/usb/gadget/atmel_usba_udc.h
+++ b/drivers/usb/gadget/atmel_usba_udc.h
@@ -216,12 +216,6 @@
216#define EP0_EPT_SIZE USBA_EPT_SIZE_64 216#define EP0_EPT_SIZE USBA_EPT_SIZE_64
217#define EP0_NR_BANKS 1 217#define EP0_NR_BANKS 1
218 218
219/*
220 * REVISIT: Try to eliminate this value. Can we rely on req->mapped to
221 * provide this information?
222 */
223#define DMA_ADDR_INVALID (~(dma_addr_t)0)
224
225#define FIFO_IOMEM_ID 0 219#define FIFO_IOMEM_ID 0
226#define CTRL_IOMEM_ID 1 220#define CTRL_IOMEM_ID 1
227 221
diff --git a/drivers/usb/gadget/bcm63xx_udc.c b/drivers/usb/gadget/bcm63xx_udc.c
index 8cc8253f1100..6e6518264c42 100644
--- a/drivers/usb/gadget/bcm63xx_udc.c
+++ b/drivers/usb/gadget/bcm63xx_udc.c
@@ -1819,7 +1819,6 @@ static int bcm63xx_udc_start(struct usb_gadget *gadget,
1819 1819
1820 udc->driver = driver; 1820 udc->driver = driver;
1821 driver->driver.bus = NULL; 1821 driver->driver.bus = NULL;
1822 udc->gadget.dev.driver = &driver->driver;
1823 udc->gadget.dev.of_node = udc->dev->of_node; 1822 udc->gadget.dev.of_node = udc->dev->of_node;
1824 1823
1825 spin_unlock_irqrestore(&udc->lock, flags); 1824 spin_unlock_irqrestore(&udc->lock, flags);
@@ -1841,7 +1840,6 @@ static int bcm63xx_udc_stop(struct usb_gadget *gadget,
1841 spin_lock_irqsave(&udc->lock, flags); 1840 spin_lock_irqsave(&udc->lock, flags);
1842 1841
1843 udc->driver = NULL; 1842 udc->driver = NULL;
1844 udc->gadget.dev.driver = NULL;
1845 1843
1846 /* 1844 /*
1847 * If we switch the PHY too abruptly after dropping D+, the host 1845 * If we switch the PHY too abruptly after dropping D+, the host
@@ -2306,17 +2304,6 @@ static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc)
2306 ***********************************************************************/ 2304 ***********************************************************************/
2307 2305
2308/** 2306/**
2309 * bcm63xx_udc_gadget_release - Called from device_release().
2310 * @dev: Unused.
2311 *
2312 * We get a warning if this function doesn't exist, but it's empty because
2313 * we don't have to free any of the memory allocated with the devm_* APIs.
2314 */
2315static void bcm63xx_udc_gadget_release(struct device *dev)
2316{
2317}
2318
2319/**
2320 * bcm63xx_udc_probe - Initialize a new instance of the UDC. 2307 * bcm63xx_udc_probe - Initialize a new instance of the UDC.
2321 * @pdev: Platform device struct from the bcm63xx BSP code. 2308 * @pdev: Platform device struct from the bcm63xx BSP code.
2322 * 2309 *
@@ -2368,13 +2355,9 @@ static int bcm63xx_udc_probe(struct platform_device *pdev)
2368 2355
2369 spin_lock_init(&udc->lock); 2356 spin_lock_init(&udc->lock);
2370 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); 2357 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process);
2371 dev_set_name(&udc->gadget.dev, "gadget");
2372 2358
2373 udc->gadget.ops = &bcm63xx_udc_ops; 2359 udc->gadget.ops = &bcm63xx_udc_ops;
2374 udc->gadget.name = dev_name(dev); 2360 udc->gadget.name = dev_name(dev);
2375 udc->gadget.dev.parent = dev;
2376 udc->gadget.dev.release = bcm63xx_udc_gadget_release;
2377 udc->gadget.dev.dma_mask = dev->dma_mask;
2378 2361
2379 if (!pd->use_fullspeed && !use_fullspeed) 2362 if (!pd->use_fullspeed && !use_fullspeed)
2380 udc->gadget.max_speed = USB_SPEED_HIGH; 2363 udc->gadget.max_speed = USB_SPEED_HIGH;
@@ -2414,17 +2397,12 @@ static int bcm63xx_udc_probe(struct platform_device *pdev)
2414 } 2397 }
2415 } 2398 }
2416 2399
2417 rc = device_register(&udc->gadget.dev);
2418 if (rc)
2419 goto out_uninit;
2420
2421 bcm63xx_udc_init_debugfs(udc); 2400 bcm63xx_udc_init_debugfs(udc);
2422 rc = usb_add_gadget_udc(dev, &udc->gadget); 2401 rc = usb_add_gadget_udc(dev, &udc->gadget);
2423 if (!rc) 2402 if (!rc)
2424 return 0; 2403 return 0;
2425 2404
2426 bcm63xx_udc_cleanup_debugfs(udc); 2405 bcm63xx_udc_cleanup_debugfs(udc);
2427 device_unregister(&udc->gadget.dev);
2428out_uninit: 2406out_uninit:
2429 bcm63xx_uninit_udc_hw(udc); 2407 bcm63xx_uninit_udc_hw(udc);
2430 return rc; 2408 return rc;
@@ -2440,7 +2418,6 @@ static int bcm63xx_udc_remove(struct platform_device *pdev)
2440 2418
2441 bcm63xx_udc_cleanup_debugfs(udc); 2419 bcm63xx_udc_cleanup_debugfs(udc);
2442 usb_del_gadget_udc(&udc->gadget); 2420 usb_del_gadget_udc(&udc->gadget);
2443 device_unregister(&udc->gadget.dev);
2444 BUG_ON(udc->driver); 2421 BUG_ON(udc->driver);
2445 2422
2446 platform_set_drvdata(pdev, NULL); 2423 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index a7d6f7026757..2c5255182769 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -103,18 +103,16 @@ static struct usb_gadget_strings *dev_strings[] = {
103}; 103};
104 104
105static u8 hostaddr[ETH_ALEN]; 105static u8 hostaddr[ETH_ALEN];
106 106static struct eth_dev *the_dev;
107/*-------------------------------------------------------------------------*/ 107/*-------------------------------------------------------------------------*/
108static struct usb_function *f_acm; 108static struct usb_function *f_acm;
109static struct usb_function_instance *fi_serial; 109static struct usb_function_instance *fi_serial;
110 110
111static unsigned char tty_line;
112/* 111/*
113 * We _always_ have both CDC ECM and CDC ACM functions. 112 * We _always_ have both CDC ECM and CDC ACM functions.
114 */ 113 */
115static int __init cdc_do_config(struct usb_configuration *c) 114static int __init cdc_do_config(struct usb_configuration *c)
116{ 115{
117 struct f_serial_opts *opts;
118 int status; 116 int status;
119 117
120 if (gadget_is_otg(c->cdev->gadget)) { 118 if (gadget_is_otg(c->cdev->gadget)) {
@@ -122,7 +120,7 @@ static int __init cdc_do_config(struct usb_configuration *c)
122 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 120 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
123 } 121 }
124 122
125 status = ecm_bind_config(c, hostaddr); 123 status = ecm_bind_config(c, hostaddr, the_dev);
126 if (status < 0) 124 if (status < 0)
127 return status; 125 return status;
128 126
@@ -130,12 +128,11 @@ static int __init cdc_do_config(struct usb_configuration *c)
130 if (IS_ERR(fi_serial)) 128 if (IS_ERR(fi_serial))
131 return PTR_ERR(fi_serial); 129 return PTR_ERR(fi_serial);
132 130
133 opts = container_of(fi_serial, struct f_serial_opts, func_inst);
134 opts->port_num = tty_line;
135
136 f_acm = usb_get_function(fi_serial); 131 f_acm = usb_get_function(fi_serial);
137 if (IS_ERR(f_acm)) 132 if (IS_ERR(f_acm)) {
133 status = PTR_ERR(f_acm);
138 goto err_func_acm; 134 goto err_func_acm;
135 }
139 136
140 status = usb_add_function(c, f_acm); 137 status = usb_add_function(c, f_acm);
141 if (status) 138 if (status)
@@ -169,14 +166,9 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
169 } 166 }
170 167
171 /* set up network link layer */ 168 /* set up network link layer */
172 status = gether_setup(cdev->gadget, hostaddr); 169 the_dev = gether_setup(cdev->gadget, hostaddr);
173 if (status < 0) 170 if (IS_ERR(the_dev))
174 return status; 171 return PTR_ERR(the_dev);
175
176 /* set up serial link layer */
177 status = gserial_alloc_line(&tty_line);
178 if (status < 0)
179 goto fail0;
180 172
181 /* Allocate string descriptor numbers ... note that string 173 /* Allocate string descriptor numbers ... note that string
182 * contents can be overridden by the composite_dev glue. 174 * contents can be overridden by the composite_dev glue.
@@ -200,9 +192,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
200 return 0; 192 return 0;
201 193
202fail1: 194fail1:
203 gserial_free_line(tty_line); 195 gether_cleanup(the_dev);
204fail0:
205 gether_cleanup();
206 return status; 196 return status;
207} 197}
208 198
@@ -210,8 +200,7 @@ static int __exit cdc_unbind(struct usb_composite_dev *cdev)
210{ 200{
211 usb_put_function(f_acm); 201 usb_put_function(f_acm);
212 usb_put_function_instance(fi_serial); 202 usb_put_function_instance(fi_serial);
213 gserial_free_line(tty_line); 203 gether_cleanup(the_dev);
214 gether_cleanup();
215 return 0; 204 return 0;
216} 205}
217 206
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index c0d62b278610..55f4df60f327 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1637,6 +1637,7 @@ void composite_dev_cleanup(struct usb_composite_dev *cdev)
1637 kfree(cdev->req->buf); 1637 kfree(cdev->req->buf);
1638 usb_ep_free_request(cdev->gadget->ep0, cdev->req); 1638 usb_ep_free_request(cdev->gadget->ep0, cdev->req);
1639 } 1639 }
1640 cdev->next_string_id = 0;
1640 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended); 1641 device_remove_file(&cdev->gadget->dev, &dev_attr_suspended);
1641} 1642}
1642 1643
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
new file mode 100644
index 000000000000..3d5cfc9c2c78
--- /dev/null
+++ b/drivers/usb/gadget/configfs.c
@@ -0,0 +1,1003 @@
1#include <linux/configfs.h>
2#include <linux/module.h>
3#include <linux/slab.h>
4#include <linux/device.h>
5#include <linux/usb/composite.h>
6#include <linux/usb/gadget_configfs.h>
7
8int check_user_usb_string(const char *name,
9 struct usb_gadget_strings *stringtab_dev)
10{
11 unsigned primary_lang;
12 unsigned sub_lang;
13 u16 num;
14 int ret;
15
16 ret = kstrtou16(name, 0, &num);
17 if (ret)
18 return ret;
19
20 primary_lang = num & 0x3ff;
21 sub_lang = num >> 10;
22
23 /* simple sanity check for valid langid */
24 switch (primary_lang) {
25 case 0:
26 case 0x62 ... 0xfe:
27 case 0x100 ... 0x3ff:
28 return -EINVAL;
29 }
30 if (!sub_lang)
31 return -EINVAL;
32
33 stringtab_dev->language = num;
34 return 0;
35}
36
37#define MAX_NAME_LEN 40
38#define MAX_USB_STRING_LANGS 2
39
40struct gadget_info {
41 struct config_group group;
42 struct config_group functions_group;
43 struct config_group configs_group;
44 struct config_group strings_group;
45 struct config_group *default_groups[4];
46
47 struct mutex lock;
48 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
49 struct list_head string_list;
50 struct list_head available_func;
51
52 const char *udc_name;
53#ifdef CONFIG_USB_OTG
54 struct usb_otg_descriptor otg;
55#endif
56 struct usb_composite_driver composite;
57 struct usb_composite_dev cdev;
58};
59
60struct config_usb_cfg {
61 struct config_group group;
62 struct config_group strings_group;
63 struct config_group *default_groups[2];
64 struct list_head string_list;
65 struct usb_configuration c;
66 struct list_head func_list;
67 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
68};
69
70struct gadget_strings {
71 struct usb_gadget_strings stringtab_dev;
72 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX];
73 char *manufacturer;
74 char *product;
75 char *serialnumber;
76
77 struct config_group group;
78 struct list_head list;
79};
80
81struct gadget_config_name {
82 struct usb_gadget_strings stringtab_dev;
83 struct usb_string strings;
84 char *configuration;
85
86 struct config_group group;
87 struct list_head list;
88};
89
90static int usb_string_copy(const char *s, char **s_copy)
91{
92 int ret;
93 char *str;
94 char *copy = *s_copy;
95 ret = strlen(s);
96 if (ret > 126)
97 return -EOVERFLOW;
98
99 str = kstrdup(s, GFP_KERNEL);
100 if (!str)
101 return -ENOMEM;
102 if (str[ret - 1] == '\n')
103 str[ret - 1] = '\0';
104 kfree(copy);
105 *s_copy = str;
106 return 0;
107}
108
109CONFIGFS_ATTR_STRUCT(gadget_info);
110CONFIGFS_ATTR_STRUCT(config_usb_cfg);
111
112#define GI_DEVICE_DESC_ITEM_ATTR(name) \
113 static struct gadget_info_attribute gadget_cdev_desc_##name = \
114 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
115 gadget_dev_desc_##name##_show, \
116 gadget_dev_desc_##name##_store)
117
118#define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \
119 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \
120 char *page) \
121{ \
122 return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \
123}
124
125#define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \
126 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \
127 char *page) \
128{ \
129 return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \
130}
131
132
133#define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \
134 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \
135 const char *page, size_t len) \
136{ \
137 u8 val; \
138 int ret; \
139 ret = kstrtou8(page, 0, &val); \
140 if (ret) \
141 return ret; \
142 gi->cdev.desc._name = val; \
143 return len; \
144}
145
146#define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \
147 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \
148 const char *page, size_t len) \
149{ \
150 u16 val; \
151 int ret; \
152 ret = kstrtou16(page, 0, &val); \
153 if (ret) \
154 return ret; \
155 gi->cdev.desc._name = cpu_to_le16p(&val); \
156 return len; \
157}
158
159#define GI_DEVICE_DESC_SIMPLE_RW(_name, _type) \
160 GI_DEVICE_DESC_SIMPLE_R_##_type(_name) \
161 GI_DEVICE_DESC_SIMPLE_W_##_type(_name)
162
163GI_DEVICE_DESC_SIMPLE_R_u16(bcdUSB);
164GI_DEVICE_DESC_SIMPLE_RW(bDeviceClass, u8);
165GI_DEVICE_DESC_SIMPLE_RW(bDeviceSubClass, u8);
166GI_DEVICE_DESC_SIMPLE_RW(bDeviceProtocol, u8);
167GI_DEVICE_DESC_SIMPLE_RW(bMaxPacketSize0, u8);
168GI_DEVICE_DESC_SIMPLE_RW(idVendor, u16);
169GI_DEVICE_DESC_SIMPLE_RW(idProduct, u16);
170GI_DEVICE_DESC_SIMPLE_R_u16(bcdDevice);
171
172static ssize_t is_valid_bcd(u16 bcd_val)
173{
174 if ((bcd_val & 0xf) > 9)
175 return -EINVAL;
176 if (((bcd_val >> 4) & 0xf) > 9)
177 return -EINVAL;
178 if (((bcd_val >> 8) & 0xf) > 9)
179 return -EINVAL;
180 if (((bcd_val >> 12) & 0xf) > 9)
181 return -EINVAL;
182 return 0;
183}
184
185static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi,
186 const char *page, size_t len)
187{
188 u16 bcdDevice;
189 int ret;
190
191 ret = kstrtou16(page, 0, &bcdDevice);
192 if (ret)
193 return ret;
194 ret = is_valid_bcd(bcdDevice);
195 if (ret)
196 return ret;
197
198 gi->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice);
199 return len;
200}
201
202static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi,
203 const char *page, size_t len)
204{
205 u16 bcdUSB;
206 int ret;
207
208 ret = kstrtou16(page, 0, &bcdUSB);
209 if (ret)
210 return ret;
211 ret = is_valid_bcd(bcdUSB);
212 if (ret)
213 return ret;
214
215 gi->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB);
216 return len;
217}
218
219static ssize_t gadget_dev_desc_UDC_show(struct gadget_info *gi, char *page)
220{
221 return sprintf(page, "%s\n", gi->udc_name ?: "");
222}
223
224static int unregister_gadget(struct gadget_info *gi)
225{
226 int ret;
227
228 if (!gi->udc_name)
229 return -ENODEV;
230
231 ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
232 if (ret)
233 return ret;
234 kfree(gi->udc_name);
235 gi->udc_name = NULL;
236 return 0;
237}
238
239static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi,
240 const char *page, size_t len)
241{
242 char *name;
243 int ret;
244
245 name = kstrdup(page, GFP_KERNEL);
246 if (!name)
247 return -ENOMEM;
248 if (name[len - 1] == '\n')
249 name[len - 1] = '\0';
250
251 mutex_lock(&gi->lock);
252
253 if (!strlen(name)) {
254 ret = unregister_gadget(gi);
255 if (ret)
256 goto err;
257 } else {
258 if (gi->udc_name) {
259 ret = -EBUSY;
260 goto err;
261 }
262 ret = udc_attach_driver(name, &gi->composite.gadget_driver);
263 if (ret)
264 goto err;
265 gi->udc_name = name;
266 }
267 mutex_unlock(&gi->lock);
268 return len;
269err:
270 kfree(name);
271 mutex_unlock(&gi->lock);
272 return ret;
273}
274
275GI_DEVICE_DESC_ITEM_ATTR(bDeviceClass);
276GI_DEVICE_DESC_ITEM_ATTR(bDeviceSubClass);
277GI_DEVICE_DESC_ITEM_ATTR(bDeviceProtocol);
278GI_DEVICE_DESC_ITEM_ATTR(bMaxPacketSize0);
279GI_DEVICE_DESC_ITEM_ATTR(idVendor);
280GI_DEVICE_DESC_ITEM_ATTR(idProduct);
281GI_DEVICE_DESC_ITEM_ATTR(bcdDevice);
282GI_DEVICE_DESC_ITEM_ATTR(bcdUSB);
283GI_DEVICE_DESC_ITEM_ATTR(UDC);
284
285static struct configfs_attribute *gadget_root_attrs[] = {
286 &gadget_cdev_desc_bDeviceClass.attr,
287 &gadget_cdev_desc_bDeviceSubClass.attr,
288 &gadget_cdev_desc_bDeviceProtocol.attr,
289 &gadget_cdev_desc_bMaxPacketSize0.attr,
290 &gadget_cdev_desc_idVendor.attr,
291 &gadget_cdev_desc_idProduct.attr,
292 &gadget_cdev_desc_bcdDevice.attr,
293 &gadget_cdev_desc_bcdUSB.attr,
294 &gadget_cdev_desc_UDC.attr,
295 NULL,
296};
297
298static inline struct gadget_info *to_gadget_info(struct config_item *item)
299{
300 return container_of(to_config_group(item), struct gadget_info, group);
301}
302
303static inline struct gadget_strings *to_gadget_strings(struct config_item *item)
304{
305 return container_of(to_config_group(item), struct gadget_strings,
306 group);
307}
308
309static inline struct gadget_config_name *to_gadget_config_name(
310 struct config_item *item)
311{
312 return container_of(to_config_group(item), struct gadget_config_name,
313 group);
314}
315
316static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
317{
318 return container_of(to_config_group(item), struct config_usb_cfg,
319 group);
320}
321
322static inline struct usb_function_instance *to_usb_function_instance(
323 struct config_item *item)
324{
325 return container_of(to_config_group(item),
326 struct usb_function_instance, group);
327}
328
329static void gadget_info_attr_release(struct config_item *item)
330{
331 struct gadget_info *gi = to_gadget_info(item);
332
333 WARN_ON(!list_empty(&gi->cdev.configs));
334 WARN_ON(!list_empty(&gi->string_list));
335 WARN_ON(!list_empty(&gi->available_func));
336 kfree(gi->composite.gadget_driver.function);
337 kfree(gi);
338}
339
340CONFIGFS_ATTR_OPS(gadget_info);
341
342static struct configfs_item_operations gadget_root_item_ops = {
343 .release = gadget_info_attr_release,
344 .show_attribute = gadget_info_attr_show,
345 .store_attribute = gadget_info_attr_store,
346};
347
348static void gadget_config_attr_release(struct config_item *item)
349{
350 struct config_usb_cfg *cfg = to_config_usb_cfg(item);
351
352 WARN_ON(!list_empty(&cfg->c.functions));
353 list_del(&cfg->c.list);
354 kfree(cfg->c.label);
355 kfree(cfg);
356}
357
358static int config_usb_cfg_link(
359 struct config_item *usb_cfg_ci,
360 struct config_item *usb_func_ci)
361{
362 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
363 struct usb_composite_dev *cdev = cfg->c.cdev;
364 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
365
366 struct config_group *group = to_config_group(usb_func_ci);
367 struct usb_function_instance *fi = container_of(group,
368 struct usb_function_instance, group);
369 struct usb_function_instance *a_fi;
370 struct usb_function *f;
371 int ret;
372
373 mutex_lock(&gi->lock);
374 /*
375 * Make sure this function is from within our _this_ gadget and not
376 * from another gadget or a random directory.
377 * Also a function instance can only be linked once.
378 */
379 list_for_each_entry(a_fi, &gi->available_func, cfs_list) {
380 if (a_fi == fi)
381 break;
382 }
383 if (a_fi != fi) {
384 ret = -EINVAL;
385 goto out;
386 }
387
388 list_for_each_entry(f, &cfg->func_list, list) {
389 if (f->fi == fi) {
390 ret = -EEXIST;
391 goto out;
392 }
393 }
394
395 f = usb_get_function(fi);
396 if (IS_ERR(f)) {
397 ret = PTR_ERR(f);
398 goto out;
399 }
400
401 /* stash the function until we bind it to the gadget */
402 list_add_tail(&f->list, &cfg->func_list);
403 ret = 0;
404out:
405 mutex_unlock(&gi->lock);
406 return ret;
407}
408
409static int config_usb_cfg_unlink(
410 struct config_item *usb_cfg_ci,
411 struct config_item *usb_func_ci)
412{
413 struct config_usb_cfg *cfg = to_config_usb_cfg(usb_cfg_ci);
414 struct usb_composite_dev *cdev = cfg->c.cdev;
415 struct gadget_info *gi = container_of(cdev, struct gadget_info, cdev);
416
417 struct config_group *group = to_config_group(usb_func_ci);
418 struct usb_function_instance *fi = container_of(group,
419 struct usb_function_instance, group);
420 struct usb_function *f;
421
422 /*
423 * ideally I would like to forbid to unlink functions while a gadget is
424 * bound to an UDC. Since this isn't possible at the moment, we simply
425 * force an unbind, the function is available here and then we can
426 * remove the function.
427 */
428 mutex_lock(&gi->lock);
429 if (gi->udc_name)
430 unregister_gadget(gi);
431 WARN_ON(gi->udc_name);
432
433 list_for_each_entry(f, &cfg->func_list, list) {
434 if (f->fi == fi) {
435 list_del(&f->list);
436 usb_put_function(f);
437 mutex_unlock(&gi->lock);
438 return 0;
439 }
440 }
441 mutex_unlock(&gi->lock);
442 WARN(1, "Unable to locate function to unbind\n");
443 return 0;
444}
445
446CONFIGFS_ATTR_OPS(config_usb_cfg);
447
448static struct configfs_item_operations gadget_config_item_ops = {
449 .release = gadget_config_attr_release,
450 .show_attribute = config_usb_cfg_attr_show,
451 .store_attribute = config_usb_cfg_attr_store,
452 .allow_link = config_usb_cfg_link,
453 .drop_link = config_usb_cfg_unlink,
454};
455
456
457static ssize_t gadget_config_desc_MaxPower_show(struct config_usb_cfg *cfg,
458 char *page)
459{
460 return sprintf(page, "%u\n", cfg->c.MaxPower);
461}
462
463static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg,
464 const char *page, size_t len)
465{
466 u16 val;
467 int ret;
468 ret = kstrtou16(page, 0, &val);
469 if (ret)
470 return ret;
471 if (DIV_ROUND_UP(val, 8) > 0xff)
472 return -ERANGE;
473 cfg->c.MaxPower = val;
474 return len;
475}
476
477static ssize_t gadget_config_desc_bmAttributes_show(struct config_usb_cfg *cfg,
478 char *page)
479{
480 return sprintf(page, "0x%02x\n", cfg->c.bmAttributes);
481}
482
483static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg,
484 const char *page, size_t len)
485{
486 u8 val;
487 int ret;
488 ret = kstrtou8(page, 0, &val);
489 if (ret)
490 return ret;
491 if (!(val & USB_CONFIG_ATT_ONE))
492 return -EINVAL;
493 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER |
494 USB_CONFIG_ATT_WAKEUP))
495 return -EINVAL;
496 cfg->c.bmAttributes = val;
497 return len;
498}
499
500#define CFG_CONFIG_DESC_ITEM_ATTR(name) \
501 static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \
502 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
503 gadget_config_desc_##name##_show, \
504 gadget_config_desc_##name##_store)
505
506CFG_CONFIG_DESC_ITEM_ATTR(MaxPower);
507CFG_CONFIG_DESC_ITEM_ATTR(bmAttributes);
508
509static struct configfs_attribute *gadget_config_attrs[] = {
510 &gadget_usb_cfg_MaxPower.attr,
511 &gadget_usb_cfg_bmAttributes.attr,
512 NULL,
513};
514
515static struct config_item_type gadget_config_type = {
516 .ct_item_ops = &gadget_config_item_ops,
517 .ct_attrs = gadget_config_attrs,
518 .ct_owner = THIS_MODULE,
519};
520
521static struct config_item_type gadget_root_type = {
522 .ct_item_ops = &gadget_root_item_ops,
523 .ct_attrs = gadget_root_attrs,
524 .ct_owner = THIS_MODULE,
525};
526
527static void composite_init_dev(struct usb_composite_dev *cdev)
528{
529 spin_lock_init(&cdev->lock);
530 INIT_LIST_HEAD(&cdev->configs);
531 INIT_LIST_HEAD(&cdev->gstrings);
532}
533
534static struct config_group *function_make(
535 struct config_group *group,
536 const char *name)
537{
538 struct gadget_info *gi;
539 struct usb_function_instance *fi;
540 char buf[MAX_NAME_LEN];
541 char *func_name;
542 char *instance_name;
543 int ret;
544
545 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
546 if (ret >= MAX_NAME_LEN)
547 return ERR_PTR(-ENAMETOOLONG);
548
549 func_name = buf;
550 instance_name = strchr(func_name, '.');
551 if (!instance_name) {
552 pr_err("Unable to locate . in FUNC.INSTANCE\n");
553 return ERR_PTR(-EINVAL);
554 }
555 *instance_name = '\0';
556 instance_name++;
557
558 fi = usb_get_function_instance(func_name);
559 if (IS_ERR(fi))
560 return ERR_PTR(PTR_ERR(fi));
561
562 ret = config_item_set_name(&fi->group.cg_item, name);
563 if (ret) {
564 usb_put_function_instance(fi);
565 return ERR_PTR(ret);
566 }
567
568 gi = container_of(group, struct gadget_info, functions_group);
569
570 mutex_lock(&gi->lock);
571 list_add_tail(&fi->cfs_list, &gi->available_func);
572 mutex_unlock(&gi->lock);
573 return &fi->group;
574}
575
576static void function_drop(
577 struct config_group *group,
578 struct config_item *item)
579{
580 struct usb_function_instance *fi = to_usb_function_instance(item);
581 struct gadget_info *gi;
582
583 gi = container_of(group, struct gadget_info, functions_group);
584
585 mutex_lock(&gi->lock);
586 list_del(&fi->cfs_list);
587 mutex_unlock(&gi->lock);
588 config_item_put(item);
589}
590
591static struct configfs_group_operations functions_ops = {
592 .make_group = &function_make,
593 .drop_item = &function_drop,
594};
595
596static struct config_item_type functions_type = {
597 .ct_group_ops = &functions_ops,
598 .ct_owner = THIS_MODULE,
599};
600
601CONFIGFS_ATTR_STRUCT(gadget_config_name);
602GS_STRINGS_RW(gadget_config_name, configuration);
603
604static struct configfs_attribute *gadget_config_name_langid_attrs[] = {
605 &gadget_config_name_configuration.attr,
606 NULL,
607};
608
609static void gadget_config_name_attr_release(struct config_item *item)
610{
611 struct gadget_config_name *cn = to_gadget_config_name(item);
612
613 kfree(cn->configuration);
614
615 list_del(&cn->list);
616 kfree(cn);
617}
618
619USB_CONFIG_STRING_RW_OPS(gadget_config_name);
620USB_CONFIG_STRINGS_LANG(gadget_config_name, config_usb_cfg);
621
622static struct config_group *config_desc_make(
623 struct config_group *group,
624 const char *name)
625{
626 struct gadget_info *gi;
627 struct config_usb_cfg *cfg;
628 char buf[MAX_NAME_LEN];
629 char *num_str;
630 u8 num;
631 int ret;
632
633 gi = container_of(group, struct gadget_info, configs_group);
634 ret = snprintf(buf, MAX_NAME_LEN, "%s", name);
635 if (ret >= MAX_NAME_LEN)
636 return ERR_PTR(-ENAMETOOLONG);
637
638 num_str = strchr(buf, '.');
639 if (!num_str) {
640 pr_err("Unable to locate . in name.bConfigurationValue\n");
641 return ERR_PTR(-EINVAL);
642 }
643
644 *num_str = '\0';
645 num_str++;
646
647 if (!strlen(buf))
648 return ERR_PTR(-EINVAL);
649
650 ret = kstrtou8(num_str, 0, &num);
651 if (ret)
652 return ERR_PTR(ret);
653
654 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
655 if (!cfg)
656 return ERR_PTR(-ENOMEM);
657 cfg->c.label = kstrdup(buf, GFP_KERNEL);
658 if (!cfg->c.label) {
659 ret = -ENOMEM;
660 goto err;
661 }
662 cfg->c.bConfigurationValue = num;
663 cfg->c.MaxPower = CONFIG_USB_GADGET_VBUS_DRAW;
664 cfg->c.bmAttributes = USB_CONFIG_ATT_ONE;
665 INIT_LIST_HEAD(&cfg->string_list);
666 INIT_LIST_HEAD(&cfg->func_list);
667
668 cfg->group.default_groups = cfg->default_groups;
669 cfg->default_groups[0] = &cfg->strings_group;
670
671 config_group_init_type_name(&cfg->group, name,
672 &gadget_config_type);
673 config_group_init_type_name(&cfg->strings_group, "strings",
674 &gadget_config_name_strings_type);
675
676 ret = usb_add_config_only(&gi->cdev, &cfg->c);
677 if (ret)
678 goto err;
679
680 return &cfg->group;
681err:
682 kfree(cfg->c.label);
683 kfree(cfg);
684 return ERR_PTR(ret);
685}
686
687static void config_desc_drop(
688 struct config_group *group,
689 struct config_item *item)
690{
691 config_item_put(item);
692}
693
694static struct configfs_group_operations config_desc_ops = {
695 .make_group = &config_desc_make,
696 .drop_item = &config_desc_drop,
697};
698
699static struct config_item_type config_desc_type = {
700 .ct_group_ops = &config_desc_ops,
701 .ct_owner = THIS_MODULE,
702};
703
704CONFIGFS_ATTR_STRUCT(gadget_strings);
705GS_STRINGS_RW(gadget_strings, manufacturer);
706GS_STRINGS_RW(gadget_strings, product);
707GS_STRINGS_RW(gadget_strings, serialnumber);
708
709static struct configfs_attribute *gadget_strings_langid_attrs[] = {
710 &gadget_strings_manufacturer.attr,
711 &gadget_strings_product.attr,
712 &gadget_strings_serialnumber.attr,
713 NULL,
714};
715
716static void gadget_strings_attr_release(struct config_item *item)
717{
718 struct gadget_strings *gs = to_gadget_strings(item);
719
720 kfree(gs->manufacturer);
721 kfree(gs->product);
722 kfree(gs->serialnumber);
723
724 list_del(&gs->list);
725 kfree(gs);
726}
727
728USB_CONFIG_STRING_RW_OPS(gadget_strings);
729USB_CONFIG_STRINGS_LANG(gadget_strings, gadget_info);
730
731static int configfs_do_nothing(struct usb_composite_dev *cdev)
732{
733 WARN_ON(1);
734 return -EINVAL;
735}
736
737int composite_dev_prepare(struct usb_composite_driver *composite,
738 struct usb_composite_dev *dev);
739
740static void purge_configs_funcs(struct gadget_info *gi)
741{
742 struct usb_configuration *c;
743
744 list_for_each_entry(c, &gi->cdev.configs, list) {
745 struct usb_function *f, *tmp;
746 struct config_usb_cfg *cfg;
747
748 cfg = container_of(c, struct config_usb_cfg, c);
749
750 list_for_each_entry_safe(f, tmp, &c->functions, list) {
751
752 list_move_tail(&f->list, &cfg->func_list);
753 if (f->unbind) {
754 dev_err(&gi->cdev.gadget->dev, "unbind function"
755 " '%s'/%p\n", f->name, f);
756 f->unbind(c, f);
757 }
758 }
759 c->next_interface_id = 0;
760 c->superspeed = 0;
761 c->highspeed = 0;
762 c->fullspeed = 0;
763 }
764}
765
766static int configfs_composite_bind(struct usb_gadget *gadget,
767 struct usb_gadget_driver *gdriver)
768{
769 struct usb_composite_driver *composite = to_cdriver(gdriver);
770 struct gadget_info *gi = container_of(composite,
771 struct gadget_info, composite);
772 struct usb_composite_dev *cdev = &gi->cdev;
773 struct usb_configuration *c;
774 struct usb_string *s;
775 unsigned i;
776 int ret;
777
778 /* the gi->lock is hold by the caller */
779 cdev->gadget = gadget;
780 set_gadget_data(gadget, cdev);
781 ret = composite_dev_prepare(composite, cdev);
782 if (ret)
783 return ret;
784 /* and now the gadget bind */
785 ret = -EINVAL;
786
787 if (list_empty(&gi->cdev.configs)) {
788 pr_err("Need atleast one configuration in %s.\n",
789 gi->composite.name);
790 goto err_comp_cleanup;
791 }
792
793
794 list_for_each_entry(c, &gi->cdev.configs, list) {
795 struct config_usb_cfg *cfg;
796
797 cfg = container_of(c, struct config_usb_cfg, c);
798 if (list_empty(&cfg->func_list)) {
799 pr_err("Config %s/%d of %s needs atleast one function.\n",
800 c->label, c->bConfigurationValue,
801 gi->composite.name);
802 goto err_comp_cleanup;
803 }
804 }
805
806 /* init all strings */
807 if (!list_empty(&gi->string_list)) {
808 struct gadget_strings *gs;
809
810 i = 0;
811 list_for_each_entry(gs, &gi->string_list, list) {
812
813 gi->gstrings[i] = &gs->stringtab_dev;
814 gs->stringtab_dev.strings = gs->strings;
815 gs->strings[USB_GADGET_MANUFACTURER_IDX].s =
816 gs->manufacturer;
817 gs->strings[USB_GADGET_PRODUCT_IDX].s = gs->product;
818 gs->strings[USB_GADGET_SERIAL_IDX].s = gs->serialnumber;
819 i++;
820 }
821 gi->gstrings[i] = NULL;
822 s = usb_gstrings_attach(&gi->cdev, gi->gstrings,
823 USB_GADGET_FIRST_AVAIL_IDX);
824 if (IS_ERR(s))
825 goto err_comp_cleanup;
826
827 gi->cdev.desc.iManufacturer = s[USB_GADGET_MANUFACTURER_IDX].id;
828 gi->cdev.desc.iProduct = s[USB_GADGET_PRODUCT_IDX].id;
829 gi->cdev.desc.iSerialNumber = s[USB_GADGET_SERIAL_IDX].id;
830 }
831
832 /* Go through all configs, attach all functions */
833 list_for_each_entry(c, &gi->cdev.configs, list) {
834 struct config_usb_cfg *cfg;
835 struct usb_function *f;
836 struct usb_function *tmp;
837 struct gadget_config_name *cn;
838
839 cfg = container_of(c, struct config_usb_cfg, c);
840 if (!list_empty(&cfg->string_list)) {
841 i = 0;
842 list_for_each_entry(cn, &cfg->string_list, list) {
843 cfg->gstrings[i] = &cn->stringtab_dev;
844 cn->stringtab_dev.strings = &cn->strings;
845 cn->strings.s = cn->configuration;
846 i++;
847 }
848 cfg->gstrings[i] = NULL;
849 s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1);
850 if (IS_ERR(s))
851 goto err_comp_cleanup;
852 c->iConfiguration = s[0].id;
853 }
854
855 list_for_each_entry_safe(f, tmp, &cfg->func_list, list) {
856 list_del(&f->list);
857 ret = usb_add_function(c, f);
858 if (ret)
859 goto err_purge_funcs;
860 }
861 usb_ep_autoconfig_reset(cdev->gadget);
862 }
863 usb_ep_autoconfig_reset(cdev->gadget);
864 return 0;
865
866err_purge_funcs:
867 purge_configs_funcs(gi);
868err_comp_cleanup:
869 composite_dev_cleanup(cdev);
870 return ret;
871}
872
873static void configfs_composite_unbind(struct usb_gadget *gadget)
874{
875 struct usb_composite_dev *cdev;
876 struct gadget_info *gi;
877
878 /* the gi->lock is hold by the caller */
879
880 cdev = get_gadget_data(gadget);
881 gi = container_of(cdev, struct gadget_info, cdev);
882
883 purge_configs_funcs(gi);
884 composite_dev_cleanup(cdev);
885 usb_ep_autoconfig_reset(cdev->gadget);
886 cdev->gadget = NULL;
887 set_gadget_data(gadget, NULL);
888}
889
890static const struct usb_gadget_driver configfs_driver_template = {
891 .bind = configfs_composite_bind,
892 .unbind = configfs_composite_unbind,
893
894 .setup = composite_setup,
895 .disconnect = composite_disconnect,
896
897 .max_speed = USB_SPEED_SUPER,
898 .driver = {
899 .owner = THIS_MODULE,
900 .name = "configfs-gadget",
901 },
902};
903
904static struct config_group *gadgets_make(
905 struct config_group *group,
906 const char *name)
907{
908 struct gadget_info *gi;
909
910 gi = kzalloc(sizeof(*gi), GFP_KERNEL);
911 if (!gi)
912 return ERR_PTR(-ENOMEM);
913
914 gi->group.default_groups = gi->default_groups;
915 gi->group.default_groups[0] = &gi->functions_group;
916 gi->group.default_groups[1] = &gi->configs_group;
917 gi->group.default_groups[2] = &gi->strings_group;
918
919 config_group_init_type_name(&gi->functions_group, "functions",
920 &functions_type);
921 config_group_init_type_name(&gi->configs_group, "configs",
922 &config_desc_type);
923 config_group_init_type_name(&gi->strings_group, "strings",
924 &gadget_strings_strings_type);
925
926 gi->composite.bind = configfs_do_nothing;
927 gi->composite.unbind = configfs_do_nothing;
928 gi->composite.suspend = NULL;
929 gi->composite.resume = NULL;
930 gi->composite.max_speed = USB_SPEED_SUPER;
931
932 mutex_init(&gi->lock);
933 INIT_LIST_HEAD(&gi->string_list);
934 INIT_LIST_HEAD(&gi->available_func);
935
936 composite_init_dev(&gi->cdev);
937 gi->cdev.desc.bLength = USB_DT_DEVICE_SIZE;
938 gi->cdev.desc.bDescriptorType = USB_DT_DEVICE;
939 gi->cdev.desc.bcdDevice = cpu_to_le16(get_default_bcdDevice());
940
941 gi->composite.gadget_driver = configfs_driver_template;
942
943 gi->composite.gadget_driver.function = kstrdup(name, GFP_KERNEL);
944 gi->composite.name = gi->composite.gadget_driver.function;
945
946 if (!gi->composite.gadget_driver.function)
947 goto err;
948
949#ifdef CONFIG_USB_OTG
950 gi->otg.bLength = sizeof(struct usb_otg_descriptor);
951 gi->otg.bDescriptorType = USB_DT_OTG;
952 gi->otg.bmAttributes = USB_OTG_SRP | USB_OTG_HNP;
953#endif
954
955 config_group_init_type_name(&gi->group, name,
956 &gadget_root_type);
957 return &gi->group;
958err:
959 kfree(gi);
960 return ERR_PTR(-ENOMEM);
961}
962
963static void gadgets_drop(struct config_group *group, struct config_item *item)
964{
965 config_item_put(item);
966}
967
968static struct configfs_group_operations gadgets_ops = {
969 .make_group = &gadgets_make,
970 .drop_item = &gadgets_drop,
971};
972
973static struct config_item_type gadgets_type = {
974 .ct_group_ops = &gadgets_ops,
975 .ct_owner = THIS_MODULE,
976};
977
978static struct configfs_subsystem gadget_subsys = {
979 .su_group = {
980 .cg_item = {
981 .ci_namebuf = "usb_gadget",
982 .ci_type = &gadgets_type,
983 },
984 },
985 .su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
986};
987
988static int __init gadget_cfs_init(void)
989{
990 int ret;
991
992 config_group_init(&gadget_subsys.su_group);
993
994 ret = configfs_register_subsystem(&gadget_subsys);
995 return ret;
996}
997module_init(gadget_cfs_init);
998
999static void __exit gadget_cfs_exit(void)
1000{
1001 configfs_unregister_subsystem(&gadget_subsys);
1002}
1003module_exit(gadget_cfs_exit);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 8cf0c0f6fa1f..a792e322f4f1 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -912,7 +912,6 @@ static int dummy_udc_start(struct usb_gadget *g,
912 dum->devstatus = 0; 912 dum->devstatus = 0;
913 913
914 dum->driver = driver; 914 dum->driver = driver;
915 dum->gadget.dev.driver = &driver->driver;
916 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n", 915 dev_dbg(udc_dev(dum), "binding gadget driver '%s'\n",
917 driver->driver.name); 916 driver->driver.name);
918 return 0; 917 return 0;
@@ -927,7 +926,6 @@ static int dummy_udc_stop(struct usb_gadget *g,
927 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n", 926 dev_dbg(udc_dev(dum), "unregister gadget driver '%s'\n",
928 driver->driver.name); 927 driver->driver.name);
929 928
930 dum->gadget.dev.driver = NULL;
931 dum->driver = NULL; 929 dum->driver = NULL;
932 930
933 return 0; 931 return 0;
@@ -937,11 +935,6 @@ static int dummy_udc_stop(struct usb_gadget *g,
937 935
938/* The gadget structure is stored inside the hcd structure and will be 936/* The gadget structure is stored inside the hcd structure and will be
939 * released along with it. */ 937 * released along with it. */
940static void dummy_gadget_release(struct device *dev)
941{
942 return;
943}
944
945static void init_dummy_udc_hw(struct dummy *dum) 938static void init_dummy_udc_hw(struct dummy *dum)
946{ 939{
947 int i; 940 int i;
@@ -984,15 +977,7 @@ static int dummy_udc_probe(struct platform_device *pdev)
984 dum->gadget.ops = &dummy_ops; 977 dum->gadget.ops = &dummy_ops;
985 dum->gadget.max_speed = USB_SPEED_SUPER; 978 dum->gadget.max_speed = USB_SPEED_SUPER;
986 979
987 dev_set_name(&dum->gadget.dev, "gadget");
988 dum->gadget.dev.parent = &pdev->dev; 980 dum->gadget.dev.parent = &pdev->dev;
989 dum->gadget.dev.release = dummy_gadget_release;
990 rc = device_register(&dum->gadget.dev);
991 if (rc < 0) {
992 put_device(&dum->gadget.dev);
993 return rc;
994 }
995
996 init_dummy_udc_hw(dum); 981 init_dummy_udc_hw(dum);
997 982
998 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget); 983 rc = usb_add_gadget_udc(&pdev->dev, &dum->gadget);
@@ -1008,7 +993,6 @@ static int dummy_udc_probe(struct platform_device *pdev)
1008err_dev: 993err_dev:
1009 usb_del_gadget_udc(&dum->gadget); 994 usb_del_gadget_udc(&dum->gadget);
1010err_udc: 995err_udc:
1011 device_unregister(&dum->gadget.dev);
1012 return rc; 996 return rc;
1013} 997}
1014 998
@@ -1019,7 +1003,6 @@ static int dummy_udc_remove(struct platform_device *pdev)
1019 usb_del_gadget_udc(&dum->gadget); 1003 usb_del_gadget_udc(&dum->gadget);
1020 platform_set_drvdata(pdev, NULL); 1004 platform_set_drvdata(pdev, NULL);
1021 device_remove_file(&dum->gadget.dev, &dev_attr_function); 1005 device_remove_file(&dum->gadget.dev, &dev_attr_function);
1022 device_unregister(&dum->gadget.dev);
1023 return 0; 1006 return 0;
1024} 1007}
1025 1008
@@ -1923,7 +1906,7 @@ done:
1923} 1906}
1924 1907
1925/* usb 3.0 root hub device descriptor */ 1908/* usb 3.0 root hub device descriptor */
1926struct { 1909static struct {
1927 struct usb_bos_descriptor bos; 1910 struct usb_bos_descriptor bos;
1928 struct usb_ss_cap_descriptor ss_cap; 1911 struct usb_ss_cap_descriptor ss_cap;
1929} __packed usb3_bos_desc = { 1912} __packed usb3_bos_desc = {
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 18c3f423706e..56c8ecae9bc3 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -207,7 +207,7 @@ static struct usb_gadget_strings *dev_strings[] = {
207}; 207};
208 208
209static u8 hostaddr[ETH_ALEN]; 209static u8 hostaddr[ETH_ALEN];
210 210static struct eth_dev *the_dev;
211/*-------------------------------------------------------------------------*/ 211/*-------------------------------------------------------------------------*/
212 212
213/* 213/*
@@ -224,7 +224,7 @@ static int __init rndis_do_config(struct usb_configuration *c)
224 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 224 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
225 } 225 }
226 226
227 return rndis_bind_config(c, hostaddr); 227 return rndis_bind_config(c, hostaddr, the_dev);
228} 228}
229 229
230static struct usb_configuration rndis_config_driver = { 230static struct usb_configuration rndis_config_driver = {
@@ -257,11 +257,11 @@ static int __init eth_do_config(struct usb_configuration *c)
257 } 257 }
258 258
259 if (use_eem) 259 if (use_eem)
260 return eem_bind_config(c); 260 return eem_bind_config(c, the_dev);
261 else if (can_support_ecm(c->cdev->gadget)) 261 else if (can_support_ecm(c->cdev->gadget))
262 return ecm_bind_config(c, hostaddr); 262 return ecm_bind_config(c, hostaddr, the_dev);
263 else 263 else
264 return geth_bind_config(c, hostaddr); 264 return geth_bind_config(c, hostaddr, the_dev);
265} 265}
266 266
267static struct usb_configuration eth_config_driver = { 267static struct usb_configuration eth_config_driver = {
@@ -279,9 +279,9 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
279 int status; 279 int status;
280 280
281 /* set up network link layer */ 281 /* set up network link layer */
282 status = gether_setup(cdev->gadget, hostaddr); 282 the_dev = gether_setup(cdev->gadget, hostaddr);
283 if (status < 0) 283 if (IS_ERR(the_dev))
284 return status; 284 return PTR_ERR(the_dev);
285 285
286 /* set up main config label and device descriptor */ 286 /* set up main config label and device descriptor */
287 if (use_eem) { 287 if (use_eem) {
@@ -338,13 +338,13 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
338 return 0; 338 return 0;
339 339
340fail: 340fail:
341 gether_cleanup(); 341 gether_cleanup(the_dev);
342 return status; 342 return status;
343} 343}
344 344
345static int __exit eth_unbind(struct usb_composite_dev *cdev) 345static int __exit eth_unbind(struct usb_composite_dev *cdev)
346{ 346{
347 gether_cleanup(); 347 gether_cleanup(the_dev);
348 return 0; 348 return 0;
349} 349}
350 350
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index 1ae180baa597..4b7e33e5d9c6 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -715,13 +715,31 @@ fail:
715 return status; 715 return status;
716} 716}
717 717
718static struct f_acm *acm_alloc_basic_func(void) 718static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
719{
720 struct f_acm *acm = func_to_acm(f);
721
722 acm_string_defs[0].id = 0;
723 usb_free_all_descriptors(f);
724 if (acm->notify_req)
725 gs_free_req(acm->notify, acm->notify_req);
726}
727
728static void acm_free_func(struct usb_function *f)
729{
730 struct f_acm *acm = func_to_acm(f);
731
732 kfree(acm);
733}
734
735static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
719{ 736{
720 struct f_acm *acm; 737 struct f_serial_opts *opts;
738 struct f_acm *acm;
721 739
722 acm = kzalloc(sizeof(*acm), GFP_KERNEL); 740 acm = kzalloc(sizeof(*acm), GFP_KERNEL);
723 if (!acm) 741 if (!acm)
724 return NULL; 742 return ERR_PTR(-ENOMEM);
725 743
726 spin_lock_init(&acm->lock); 744 spin_lock_init(&acm->lock);
727 745
@@ -730,109 +748,100 @@ static struct f_acm *acm_alloc_basic_func(void)
730 acm->port.send_break = acm_send_break; 748 acm->port.send_break = acm_send_break;
731 749
732 acm->port.func.name = "acm"; 750 acm->port.func.name = "acm";
751 acm->port.func.strings = acm_strings;
733 /* descriptors are per-instance copies */ 752 /* descriptors are per-instance copies */
734 acm->port.func.bind = acm_bind; 753 acm->port.func.bind = acm_bind;
735 acm->port.func.set_alt = acm_set_alt; 754 acm->port.func.set_alt = acm_set_alt;
736 acm->port.func.setup = acm_setup; 755 acm->port.func.setup = acm_setup;
737 acm->port.func.disable = acm_disable; 756 acm->port.func.disable = acm_disable;
738 757
739 return acm; 758 opts = container_of(fi, struct f_serial_opts, func_inst);
759 acm->port_num = opts->port_num;
760 acm->port.func.unbind = acm_unbind;
761 acm->port.func.free_func = acm_free_func;
762
763 return &acm->port.func;
740} 764}
741 765
742#ifdef USB_FACM_INCLUDED 766static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
743static void
744acm_old_unbind(struct usb_configuration *c, struct usb_function *f)
745{ 767{
746 struct f_acm *acm = func_to_acm(f); 768 return container_of(to_config_group(item), struct f_serial_opts,
747 769 func_inst.group);
748 usb_free_all_descriptors(f);
749 if (acm->notify_req)
750 gs_free_req(acm->notify, acm->notify_req);
751 kfree(acm);
752} 770}
753 771
754/** 772CONFIGFS_ATTR_STRUCT(f_serial_opts);
755 * acm_bind_config - add a CDC ACM function to a configuration 773static ssize_t f_acm_attr_show(struct config_item *item,
756 * @c: the configuration to support the CDC ACM instance 774 struct configfs_attribute *attr,
757 * @port_num: /dev/ttyGS* port this interface will use 775 char *page)
758 * Context: single threaded during gadget setup
759 *
760 * Returns zero on success, else negative errno.
761 *
762 */
763int acm_bind_config(struct usb_configuration *c, u8 port_num)
764{ 776{
765 struct f_acm *acm; 777 struct f_serial_opts *opts = to_f_serial_opts(item);
766 int status; 778 struct f_serial_opts_attribute *f_serial_opts_attr =
767 779 container_of(attr, struct f_serial_opts_attribute, attr);
768 /* allocate and initialize one new instance */ 780 ssize_t ret = 0;
769 acm = acm_alloc_basic_func(); 781
770 if (!acm) 782 if (f_serial_opts_attr->show)
771 return -ENOMEM; 783 ret = f_serial_opts_attr->show(opts, page);
772 784 return ret;
773 acm->port_num = port_num;
774 acm->port.func.unbind = acm_old_unbind;
775
776 status = usb_add_function(c, &acm->port.func);
777 if (status)
778 kfree(acm);
779 return status;
780} 785}
781 786
782#else 787static void acm_attr_release(struct config_item *item)
783
784static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
785{ 788{
786 struct f_acm *acm = func_to_acm(f); 789 struct f_serial_opts *opts = to_f_serial_opts(item);
787 790
788 acm_string_defs[0].id = 0; 791 usb_put_function_instance(&opts->func_inst);
789 usb_free_all_descriptors(f);
790 if (acm->notify_req)
791 gs_free_req(acm->notify, acm->notify_req);
792} 792}
793 793
794static void acm_free_func(struct usb_function *f) 794static struct configfs_item_operations acm_item_ops = {
795{ 795 .release = acm_attr_release,
796 struct f_acm *acm = func_to_acm(f); 796 .show_attribute = f_acm_attr_show,
797};
797 798
798 kfree(acm); 799static ssize_t f_acm_port_num_show(struct f_serial_opts *opts, char *page)
800{
801 return sprintf(page, "%u\n", opts->port_num);
799} 802}
800 803
801static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) 804static struct f_serial_opts_attribute f_acm_port_num =
802{ 805 __CONFIGFS_ATTR_RO(port_num, f_acm_port_num_show);
803 struct f_serial_opts *opts;
804 struct f_acm *acm;
805 806
806 acm = acm_alloc_basic_func();
807 if (!acm)
808 return ERR_PTR(-ENOMEM);
809 807
810 opts = container_of(fi, struct f_serial_opts, func_inst); 808static struct configfs_attribute *acm_attrs[] = {
811 acm->port_num = opts->port_num; 809 &f_acm_port_num.attr,
812 acm->port.func.unbind = acm_unbind; 810 NULL,
813 acm->port.func.free_func = acm_free_func; 811};
814 812
815 return &acm->port.func; 813static struct config_item_type acm_func_type = {
816} 814 .ct_item_ops = &acm_item_ops,
815 .ct_attrs = acm_attrs,
816 .ct_owner = THIS_MODULE,
817};
817 818
818static void acm_free_instance(struct usb_function_instance *fi) 819static void acm_free_instance(struct usb_function_instance *fi)
819{ 820{
820 struct f_serial_opts *opts; 821 struct f_serial_opts *opts;
821 822
822 opts = container_of(fi, struct f_serial_opts, func_inst); 823 opts = container_of(fi, struct f_serial_opts, func_inst);
824 gserial_free_line(opts->port_num);
823 kfree(opts); 825 kfree(opts);
824} 826}
825 827
826static struct usb_function_instance *acm_alloc_instance(void) 828static struct usb_function_instance *acm_alloc_instance(void)
827{ 829{
828 struct f_serial_opts *opts; 830 struct f_serial_opts *opts;
831 int ret;
829 832
830 opts = kzalloc(sizeof(*opts), GFP_KERNEL); 833 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
831 if (!opts) 834 if (!opts)
832 return ERR_PTR(-ENOMEM); 835 return ERR_PTR(-ENOMEM);
833 opts->func_inst.free_func_inst = acm_free_instance; 836 opts->func_inst.free_func_inst = acm_free_instance;
837 ret = gserial_alloc_line(&opts->port_num);
838 if (ret) {
839 kfree(opts);
840 return ERR_PTR(ret);
841 }
842 config_group_init_type_name(&opts->func_inst.group, "",
843 &acm_func_type);
834 return &opts->func_inst; 844 return &opts->func_inst;
835} 845}
836DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func); 846DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
837MODULE_LICENSE("GPL"); 847MODULE_LICENSE("GPL");
838#endif
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 83420a310fb7..d893d6929079 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -824,7 +824,8 @@ ecm_unbind(struct usb_configuration *c, struct usb_function *f)
824 * for calling @gether_cleanup() before module unload. 824 * for calling @gether_cleanup() before module unload.
825 */ 825 */
826int 826int
827ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 827ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
828 struct eth_dev *dev)
828{ 829{
829 struct f_ecm *ecm; 830 struct f_ecm *ecm;
830 int status; 831 int status;
@@ -852,6 +853,7 @@ ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
852 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr); 853 snprintf(ecm->ethaddr, sizeof ecm->ethaddr, "%pm", ethaddr);
853 ecm_string_defs[1].s = ecm->ethaddr; 854 ecm_string_defs[1].s = ecm->ethaddr;
854 855
856 ecm->port.ioport = dev;
855 ecm->port.cdc_filter = DEFAULT_FILTER; 857 ecm->port.cdc_filter = DEFAULT_FILTER;
856 858
857 ecm->port.func.name = "cdc_ethernet"; 859 ecm->port.func.name = "cdc_ethernet";
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index cf0ebee85563..f4e0bbef602a 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -528,7 +528,7 @@ error:
528 * Caller must have called @gether_setup(). Caller is also responsible 528 * Caller must have called @gether_setup(). Caller is also responsible
529 * for calling @gether_cleanup() before module unload. 529 * for calling @gether_cleanup() before module unload.
530 */ 530 */
531int __init eem_bind_config(struct usb_configuration *c) 531int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
532{ 532{
533 struct f_eem *eem; 533 struct f_eem *eem;
534 int status; 534 int status;
@@ -549,6 +549,7 @@ int __init eem_bind_config(struct usb_configuration *c)
549 if (!eem) 549 if (!eem)
550 return -ENOMEM; 550 return -ENOMEM;
551 551
552 eem->port.ioport = dev;
552 eem->port.cdc_filter = DEFAULT_FILTER; 553 eem->port.cdc_filter = DEFAULT_FILTER;
553 554
554 eem->port.func.name = "cdc_eem"; 555 eem->port.func.name = "cdc_eem";
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index 5e7557e23ecc..ee19bc8d0040 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -1287,7 +1287,8 @@ ncm_unbind(struct usb_configuration *c, struct usb_function *f)
1287 * Caller must have called @gether_setup(). Caller is also responsible 1287 * Caller must have called @gether_setup(). Caller is also responsible
1288 * for calling @gether_cleanup() before module unload. 1288 * for calling @gether_cleanup() before module unload.
1289 */ 1289 */
1290int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 1290int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
1291 struct eth_dev *dev)
1291{ 1292{
1292 struct f_ncm *ncm; 1293 struct f_ncm *ncm;
1293 int status; 1294 int status;
@@ -1321,6 +1322,7 @@ int __init ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
1321 1322
1322 spin_lock_init(&ncm->lock); 1323 spin_lock_init(&ncm->lock);
1323 ncm_reset_values(ncm); 1324 ncm_reset_values(ncm);
1325 ncm->port.ioport = dev;
1324 ncm->port.is_fixed = true; 1326 ncm->port.is_fixed = true;
1325 1327
1326 ncm->port.func.name = "cdc_network"; 1328 ncm->port.func.name = "cdc_network";
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 36a004563b82..8aa2be5329bc 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -72,7 +72,7 @@ static struct usb_gadget_strings *obex_strings[] = {
72 72
73/*-------------------------------------------------------------------------*/ 73/*-------------------------------------------------------------------------*/
74 74
75static struct usb_interface_descriptor obex_control_intf __initdata = { 75static struct usb_interface_descriptor obex_control_intf = {
76 .bLength = sizeof(obex_control_intf), 76 .bLength = sizeof(obex_control_intf),
77 .bDescriptorType = USB_DT_INTERFACE, 77 .bDescriptorType = USB_DT_INTERFACE,
78 .bInterfaceNumber = 0, 78 .bInterfaceNumber = 0,
@@ -83,7 +83,7 @@ static struct usb_interface_descriptor obex_control_intf __initdata = {
83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX, 83 .bInterfaceSubClass = USB_CDC_SUBCLASS_OBEX,
84}; 84};
85 85
86static struct usb_interface_descriptor obex_data_nop_intf __initdata = { 86static struct usb_interface_descriptor obex_data_nop_intf = {
87 .bLength = sizeof(obex_data_nop_intf), 87 .bLength = sizeof(obex_data_nop_intf),
88 .bDescriptorType = USB_DT_INTERFACE, 88 .bDescriptorType = USB_DT_INTERFACE,
89 .bInterfaceNumber = 1, 89 .bInterfaceNumber = 1,
@@ -93,7 +93,7 @@ static struct usb_interface_descriptor obex_data_nop_intf __initdata = {
93 .bInterfaceClass = USB_CLASS_CDC_DATA, 93 .bInterfaceClass = USB_CLASS_CDC_DATA,
94}; 94};
95 95
96static struct usb_interface_descriptor obex_data_intf __initdata = { 96static struct usb_interface_descriptor obex_data_intf = {
97 .bLength = sizeof(obex_data_intf), 97 .bLength = sizeof(obex_data_intf),
98 .bDescriptorType = USB_DT_INTERFACE, 98 .bDescriptorType = USB_DT_INTERFACE,
99 .bInterfaceNumber = 2, 99 .bInterfaceNumber = 2,
@@ -103,14 +103,14 @@ static struct usb_interface_descriptor obex_data_intf __initdata = {
103 .bInterfaceClass = USB_CLASS_CDC_DATA, 103 .bInterfaceClass = USB_CLASS_CDC_DATA,
104}; 104};
105 105
106static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = { 106static struct usb_cdc_header_desc obex_cdc_header_desc = {
107 .bLength = sizeof(obex_cdc_header_desc), 107 .bLength = sizeof(obex_cdc_header_desc),
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 .bcdCDC = cpu_to_le16(0x0120), 110 .bcdCDC = cpu_to_le16(0x0120),
111}; 111};
112 112
113static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { 113static struct usb_cdc_union_desc obex_cdc_union_desc = {
114 .bLength = sizeof(obex_cdc_union_desc), 114 .bLength = sizeof(obex_cdc_union_desc),
115 .bDescriptorType = USB_DT_CS_INTERFACE, 115 .bDescriptorType = USB_DT_CS_INTERFACE,
116 .bDescriptorSubType = USB_CDC_UNION_TYPE, 116 .bDescriptorSubType = USB_CDC_UNION_TYPE,
@@ -118,7 +118,7 @@ static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = {
118 .bSlaveInterface0 = 2, 118 .bSlaveInterface0 = 2,
119}; 119};
120 120
121static struct usb_cdc_obex_desc obex_desc __initdata = { 121static struct usb_cdc_obex_desc obex_desc = {
122 .bLength = sizeof(obex_desc), 122 .bLength = sizeof(obex_desc),
123 .bDescriptorType = USB_DT_CS_INTERFACE, 123 .bDescriptorType = USB_DT_CS_INTERFACE,
124 .bDescriptorSubType = USB_CDC_OBEX_TYPE, 124 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
@@ -127,7 +127,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = {
127 127
128/* High-Speed Support */ 128/* High-Speed Support */
129 129
130static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = { 130static struct usb_endpoint_descriptor obex_hs_ep_out_desc = {
131 .bLength = USB_DT_ENDPOINT_SIZE, 131 .bLength = USB_DT_ENDPOINT_SIZE,
132 .bDescriptorType = USB_DT_ENDPOINT, 132 .bDescriptorType = USB_DT_ENDPOINT,
133 133
@@ -136,7 +136,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = {
136 .wMaxPacketSize = cpu_to_le16(512), 136 .wMaxPacketSize = cpu_to_le16(512),
137}; 137};
138 138
139static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { 139static struct usb_endpoint_descriptor obex_hs_ep_in_desc = {
140 .bLength = USB_DT_ENDPOINT_SIZE, 140 .bLength = USB_DT_ENDPOINT_SIZE,
141 .bDescriptorType = USB_DT_ENDPOINT, 141 .bDescriptorType = USB_DT_ENDPOINT,
142 142
@@ -145,7 +145,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
145 .wMaxPacketSize = cpu_to_le16(512), 145 .wMaxPacketSize = cpu_to_le16(512),
146}; 146};
147 147
148static struct usb_descriptor_header *hs_function[] __initdata = { 148static struct usb_descriptor_header *hs_function[] = {
149 (struct usb_descriptor_header *) &obex_control_intf, 149 (struct usb_descriptor_header *) &obex_control_intf,
150 (struct usb_descriptor_header *) &obex_cdc_header_desc, 150 (struct usb_descriptor_header *) &obex_cdc_header_desc,
151 (struct usb_descriptor_header *) &obex_desc, 151 (struct usb_descriptor_header *) &obex_desc,
@@ -160,7 +160,7 @@ static struct usb_descriptor_header *hs_function[] __initdata = {
160 160
161/* Full-Speed Support */ 161/* Full-Speed Support */
162 162
163static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = { 163static struct usb_endpoint_descriptor obex_fs_ep_in_desc = {
164 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
166 166
@@ -168,7 +168,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_in_desc __initdata = {
168 .bmAttributes = USB_ENDPOINT_XFER_BULK, 168 .bmAttributes = USB_ENDPOINT_XFER_BULK,
169}; 169};
170 170
171static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = { 171static struct usb_endpoint_descriptor obex_fs_ep_out_desc = {
172 .bLength = USB_DT_ENDPOINT_SIZE, 172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT, 173 .bDescriptorType = USB_DT_ENDPOINT,
174 174
@@ -176,7 +176,7 @@ static struct usb_endpoint_descriptor obex_fs_ep_out_desc __initdata = {
176 .bmAttributes = USB_ENDPOINT_XFER_BULK, 176 .bmAttributes = USB_ENDPOINT_XFER_BULK,
177}; 177};
178 178
179static struct usb_descriptor_header *fs_function[] __initdata = { 179static struct usb_descriptor_header *fs_function[] = {
180 (struct usb_descriptor_header *) &obex_control_intf, 180 (struct usb_descriptor_header *) &obex_control_intf,
181 (struct usb_descriptor_header *) &obex_cdc_header_desc, 181 (struct usb_descriptor_header *) &obex_cdc_header_desc,
182 (struct usb_descriptor_header *) &obex_desc, 182 (struct usb_descriptor_header *) &obex_desc,
@@ -290,14 +290,43 @@ static void obex_disconnect(struct gserial *g)
290 290
291/*-------------------------------------------------------------------------*/ 291/*-------------------------------------------------------------------------*/
292 292
293static int __init 293/* Some controllers can't support CDC OBEX ... */
294obex_bind(struct usb_configuration *c, struct usb_function *f) 294static inline bool can_support_obex(struct usb_configuration *c)
295{
296 /* Since the first interface is a NOP, we can ignore the
297 * issue of multi-interface support on most controllers.
298 *
299 * Altsettings are mandatory, however...
300 */
301 if (!gadget_supports_altsettings(c->cdev->gadget))
302 return false;
303
304 /* everything else is *probably* fine ... */
305 return true;
306}
307
308static int obex_bind(struct usb_configuration *c, struct usb_function *f)
295{ 309{
296 struct usb_composite_dev *cdev = c->cdev; 310 struct usb_composite_dev *cdev = c->cdev;
297 struct f_obex *obex = func_to_obex(f); 311 struct f_obex *obex = func_to_obex(f);
298 int status; 312 int status;
299 struct usb_ep *ep; 313 struct usb_ep *ep;
300 314
315 if (!can_support_obex(c))
316 return -EINVAL;
317
318 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
319 status = usb_string_ids_tab(c->cdev, obex_string_defs);
320 if (status < 0)
321 return status;
322 obex_control_intf.iInterface =
323 obex_string_defs[OBEX_CTRL_IDX].id;
324
325 status = obex_string_defs[OBEX_DATA_IDX].id;
326 obex_data_nop_intf.iInterface = status;
327 obex_data_intf.iInterface = status;
328 }
329
301 /* allocate instance-specific interface IDs, and patch descriptors */ 330 /* allocate instance-specific interface IDs, and patch descriptors */
302 331
303 status = usb_interface_id(c, f); 332 status = usb_interface_id(c, f);
@@ -319,6 +348,7 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)
319 348
320 /* allocate instance-specific endpoints */ 349 /* allocate instance-specific endpoints */
321 350
351 status = -ENODEV;
322 ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_in_desc); 352 ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_in_desc);
323 if (!ep) 353 if (!ep)
324 goto fail; 354 goto fail;
@@ -376,29 +406,16 @@ fail:
376 return status; 406 return status;
377} 407}
378 408
409#ifdef USBF_OBEX_INCLUDED
410
379static void 411static void
380obex_unbind(struct usb_configuration *c, struct usb_function *f) 412obex_old_unbind(struct usb_configuration *c, struct usb_function *f)
381{ 413{
382 obex_string_defs[OBEX_CTRL_IDX].id = 0; 414 obex_string_defs[OBEX_CTRL_IDX].id = 0;
383 usb_free_all_descriptors(f); 415 usb_free_all_descriptors(f);
384 kfree(func_to_obex(f)); 416 kfree(func_to_obex(f));
385} 417}
386 418
387/* Some controllers can't support CDC OBEX ... */
388static inline bool can_support_obex(struct usb_configuration *c)
389{
390 /* Since the first interface is a NOP, we can ignore the
391 * issue of multi-interface support on most controllers.
392 *
393 * Altsettings are mandatory, however...
394 */
395 if (!gadget_supports_altsettings(c->cdev->gadget))
396 return false;
397
398 /* everything else is *probably* fine ... */
399 return true;
400}
401
402/** 419/**
403 * obex_bind_config - add a CDC OBEX function to a configuration 420 * obex_bind_config - add a CDC OBEX function to a configuration
404 * @c: the configuration to support the CDC OBEX instance 421 * @c: the configuration to support the CDC OBEX instance
@@ -412,21 +429,6 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
412 struct f_obex *obex; 429 struct f_obex *obex;
413 int status; 430 int status;
414 431
415 if (!can_support_obex(c))
416 return -EINVAL;
417
418 if (obex_string_defs[OBEX_CTRL_IDX].id == 0) {
419 status = usb_string_ids_tab(c->cdev, obex_string_defs);
420 if (status < 0)
421 return status;
422 obex_control_intf.iInterface =
423 obex_string_defs[OBEX_CTRL_IDX].id;
424
425 status = obex_string_defs[OBEX_DATA_IDX].id;
426 obex_data_nop_intf.iInterface = status;
427 obex_data_intf.iInterface = status;
428 }
429
430 /* allocate and initialize one new instance */ 432 /* allocate and initialize one new instance */
431 obex = kzalloc(sizeof *obex, GFP_KERNEL); 433 obex = kzalloc(sizeof *obex, GFP_KERNEL);
432 if (!obex) 434 if (!obex)
@@ -441,7 +443,7 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
441 obex->port.func.strings = obex_strings; 443 obex->port.func.strings = obex_strings;
442 /* descriptors are per-instance copies */ 444 /* descriptors are per-instance copies */
443 obex->port.func.bind = obex_bind; 445 obex->port.func.bind = obex_bind;
444 obex->port.func.unbind = obex_unbind; 446 obex->port.func.unbind = obex_old_unbind;
445 obex->port.func.set_alt = obex_set_alt; 447 obex->port.func.set_alt = obex_set_alt;
446 obex->port.func.get_alt = obex_get_alt; 448 obex->port.func.get_alt = obex_get_alt;
447 obex->port.func.disable = obex_disable; 449 obex->port.func.disable = obex_disable;
@@ -453,5 +455,138 @@ int __init obex_bind_config(struct usb_configuration *c, u8 port_num)
453 return status; 455 return status;
454} 456}
455 457
458#else
459
460static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
461{
462 return container_of(to_config_group(item), struct f_serial_opts,
463 func_inst.group);
464}
465
466CONFIGFS_ATTR_STRUCT(f_serial_opts);
467static ssize_t f_obex_attr_show(struct config_item *item,
468 struct configfs_attribute *attr,
469 char *page)
470{
471 struct f_serial_opts *opts = to_f_serial_opts(item);
472 struct f_serial_opts_attribute *f_serial_opts_attr =
473 container_of(attr, struct f_serial_opts_attribute, attr);
474 ssize_t ret = 0;
475
476 if (f_serial_opts_attr->show)
477 ret = f_serial_opts_attr->show(opts, page);
478
479 return ret;
480}
481
482static void obex_attr_release(struct config_item *item)
483{
484 struct f_serial_opts *opts = to_f_serial_opts(item);
485
486 usb_put_function_instance(&opts->func_inst);
487}
488
489static struct configfs_item_operations obex_item_ops = {
490 .release = obex_attr_release,
491 .show_attribute = f_obex_attr_show,
492};
493
494static ssize_t f_obex_port_num_show(struct f_serial_opts *opts, char *page)
495{
496 return sprintf(page, "%u\n", opts->port_num);
497}
498
499static struct f_serial_opts_attribute f_obex_port_num =
500 __CONFIGFS_ATTR_RO(port_num, f_obex_port_num_show);
501
502static struct configfs_attribute *acm_attrs[] = {
503 &f_obex_port_num.attr,
504 NULL,
505};
506
507static struct config_item_type obex_func_type = {
508 .ct_item_ops = &obex_item_ops,
509 .ct_attrs = acm_attrs,
510 .ct_owner = THIS_MODULE,
511};
512
513static void obex_free_inst(struct usb_function_instance *f)
514{
515 struct f_serial_opts *opts;
516
517 opts = container_of(f, struct f_serial_opts, func_inst);
518 gserial_free_line(opts->port_num);
519 kfree(opts);
520}
521
522static struct usb_function_instance *obex_alloc_inst(void)
523{
524 struct f_serial_opts *opts;
525 int ret;
526
527 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
528 if (!opts)
529 return ERR_PTR(-ENOMEM);
530
531 opts->func_inst.free_func_inst = obex_free_inst;
532 ret = gserial_alloc_line(&opts->port_num);
533 if (ret) {
534 kfree(opts);
535 return ERR_PTR(ret);
536 }
537 config_group_init_type_name(&opts->func_inst.group, "",
538 &obex_func_type);
539
540 return &opts->func_inst;
541}
542
543static void obex_free(struct usb_function *f)
544{
545 struct f_obex *obex;
546
547 obex = func_to_obex(f);
548 kfree(obex);
549}
550
551static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
552{
553 obex_string_defs[OBEX_CTRL_IDX].id = 0;
554 usb_free_all_descriptors(f);
555}
556
557struct usb_function *obex_alloc(struct usb_function_instance *fi)
558{
559 struct f_obex *obex;
560 struct f_serial_opts *opts;
561
562 /* allocate and initialize one new instance */
563 obex = kzalloc(sizeof(*obex), GFP_KERNEL);
564 if (!obex)
565 return ERR_PTR(-ENOMEM);
566
567 opts = container_of(fi, struct f_serial_opts, func_inst);
568
569 obex->port_num = opts->port_num;
570
571 obex->port.connect = obex_connect;
572 obex->port.disconnect = obex_disconnect;
573
574 obex->port.func.name = "obex";
575 obex->port.func.strings = obex_strings;
576 /* descriptors are per-instance copies */
577 obex->port.func.bind = obex_bind;
578 obex->port.func.unbind = obex_unbind;
579 obex->port.func.set_alt = obex_set_alt;
580 obex->port.func.get_alt = obex_get_alt;
581 obex->port.func.disable = obex_disable;
582 obex->port.func.free_func = obex_free;
583
584 return &obex->port.func;
585}
586
587DECLARE_USB_FUNCTION_INIT(obex, obex_alloc_inst, obex_alloc);
588
589#endif
590
456MODULE_AUTHOR("Felipe Balbi"); 591MODULE_AUTHOR("Felipe Balbi");
457MODULE_LICENSE("GPL"); 592MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index cc9c49c57c80..36e8c44d8e5e 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -813,7 +813,7 @@ static inline bool can_support_rndis(struct usb_configuration *c)
813 813
814int 814int
815rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 815rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
816 u32 vendorID, const char *manufacturer) 816 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
817{ 817{
818 struct f_rndis *rndis; 818 struct f_rndis *rndis;
819 int status; 819 int status;
@@ -846,6 +846,7 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
846 rndis->vendorID = vendorID; 846 rndis->vendorID = vendorID;
847 rndis->manufacturer = manufacturer; 847 rndis->manufacturer = manufacturer;
848 848
849 rndis->port.ioport = dev;
849 /* RNDIS activates when the host changes this filter */ 850 /* RNDIS activates when the host changes this filter */
850 rndis->port.cdc_filter = 0; 851 rndis->port.cdc_filter = 0;
851 852
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index da33cfb3031d..981113c9924d 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h>
15#include <linux/device.h> 16#include <linux/device.h>
16 17
17#include "u_serial.h" 18#include "u_serial.h"
@@ -42,7 +43,7 @@ static inline struct f_gser *func_to_gser(struct usb_function *f)
42 43
43/* interface descriptor: */ 44/* interface descriptor: */
44 45
45static struct usb_interface_descriptor gser_interface_desc __initdata = { 46static struct usb_interface_descriptor gser_interface_desc = {
46 .bLength = USB_DT_INTERFACE_SIZE, 47 .bLength = USB_DT_INTERFACE_SIZE,
47 .bDescriptorType = USB_DT_INTERFACE, 48 .bDescriptorType = USB_DT_INTERFACE,
48 /* .bInterfaceNumber = DYNAMIC */ 49 /* .bInterfaceNumber = DYNAMIC */
@@ -55,21 +56,21 @@ static struct usb_interface_descriptor gser_interface_desc __initdata = {
55 56
56/* full speed support: */ 57/* full speed support: */
57 58
58static struct usb_endpoint_descriptor gser_fs_in_desc __initdata = { 59static struct usb_endpoint_descriptor gser_fs_in_desc = {
59 .bLength = USB_DT_ENDPOINT_SIZE, 60 .bLength = USB_DT_ENDPOINT_SIZE,
60 .bDescriptorType = USB_DT_ENDPOINT, 61 .bDescriptorType = USB_DT_ENDPOINT,
61 .bEndpointAddress = USB_DIR_IN, 62 .bEndpointAddress = USB_DIR_IN,
62 .bmAttributes = USB_ENDPOINT_XFER_BULK, 63 .bmAttributes = USB_ENDPOINT_XFER_BULK,
63}; 64};
64 65
65static struct usb_endpoint_descriptor gser_fs_out_desc __initdata = { 66static struct usb_endpoint_descriptor gser_fs_out_desc = {
66 .bLength = USB_DT_ENDPOINT_SIZE, 67 .bLength = USB_DT_ENDPOINT_SIZE,
67 .bDescriptorType = USB_DT_ENDPOINT, 68 .bDescriptorType = USB_DT_ENDPOINT,
68 .bEndpointAddress = USB_DIR_OUT, 69 .bEndpointAddress = USB_DIR_OUT,
69 .bmAttributes = USB_ENDPOINT_XFER_BULK, 70 .bmAttributes = USB_ENDPOINT_XFER_BULK,
70}; 71};
71 72
72static struct usb_descriptor_header *gser_fs_function[] __initdata = { 73static struct usb_descriptor_header *gser_fs_function[] = {
73 (struct usb_descriptor_header *) &gser_interface_desc, 74 (struct usb_descriptor_header *) &gser_interface_desc,
74 (struct usb_descriptor_header *) &gser_fs_in_desc, 75 (struct usb_descriptor_header *) &gser_fs_in_desc,
75 (struct usb_descriptor_header *) &gser_fs_out_desc, 76 (struct usb_descriptor_header *) &gser_fs_out_desc,
@@ -78,47 +79,47 @@ static struct usb_descriptor_header *gser_fs_function[] __initdata = {
78 79
79/* high speed support: */ 80/* high speed support: */
80 81
81static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = { 82static struct usb_endpoint_descriptor gser_hs_in_desc = {
82 .bLength = USB_DT_ENDPOINT_SIZE, 83 .bLength = USB_DT_ENDPOINT_SIZE,
83 .bDescriptorType = USB_DT_ENDPOINT, 84 .bDescriptorType = USB_DT_ENDPOINT,
84 .bmAttributes = USB_ENDPOINT_XFER_BULK, 85 .bmAttributes = USB_ENDPOINT_XFER_BULK,
85 .wMaxPacketSize = cpu_to_le16(512), 86 .wMaxPacketSize = cpu_to_le16(512),
86}; 87};
87 88
88static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { 89static struct usb_endpoint_descriptor gser_hs_out_desc = {
89 .bLength = USB_DT_ENDPOINT_SIZE, 90 .bLength = USB_DT_ENDPOINT_SIZE,
90 .bDescriptorType = USB_DT_ENDPOINT, 91 .bDescriptorType = USB_DT_ENDPOINT,
91 .bmAttributes = USB_ENDPOINT_XFER_BULK, 92 .bmAttributes = USB_ENDPOINT_XFER_BULK,
92 .wMaxPacketSize = cpu_to_le16(512), 93 .wMaxPacketSize = cpu_to_le16(512),
93}; 94};
94 95
95static struct usb_descriptor_header *gser_hs_function[] __initdata = { 96static struct usb_descriptor_header *gser_hs_function[] = {
96 (struct usb_descriptor_header *) &gser_interface_desc, 97 (struct usb_descriptor_header *) &gser_interface_desc,
97 (struct usb_descriptor_header *) &gser_hs_in_desc, 98 (struct usb_descriptor_header *) &gser_hs_in_desc,
98 (struct usb_descriptor_header *) &gser_hs_out_desc, 99 (struct usb_descriptor_header *) &gser_hs_out_desc,
99 NULL, 100 NULL,
100}; 101};
101 102
102static struct usb_endpoint_descriptor gser_ss_in_desc __initdata = { 103static struct usb_endpoint_descriptor gser_ss_in_desc = {
103 .bLength = USB_DT_ENDPOINT_SIZE, 104 .bLength = USB_DT_ENDPOINT_SIZE,
104 .bDescriptorType = USB_DT_ENDPOINT, 105 .bDescriptorType = USB_DT_ENDPOINT,
105 .bmAttributes = USB_ENDPOINT_XFER_BULK, 106 .bmAttributes = USB_ENDPOINT_XFER_BULK,
106 .wMaxPacketSize = cpu_to_le16(1024), 107 .wMaxPacketSize = cpu_to_le16(1024),
107}; 108};
108 109
109static struct usb_endpoint_descriptor gser_ss_out_desc __initdata = { 110static struct usb_endpoint_descriptor gser_ss_out_desc = {
110 .bLength = USB_DT_ENDPOINT_SIZE, 111 .bLength = USB_DT_ENDPOINT_SIZE,
111 .bDescriptorType = USB_DT_ENDPOINT, 112 .bDescriptorType = USB_DT_ENDPOINT,
112 .bmAttributes = USB_ENDPOINT_XFER_BULK, 113 .bmAttributes = USB_ENDPOINT_XFER_BULK,
113 .wMaxPacketSize = cpu_to_le16(1024), 114 .wMaxPacketSize = cpu_to_le16(1024),
114}; 115};
115 116
116static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc __initdata = { 117static struct usb_ss_ep_comp_descriptor gser_ss_bulk_comp_desc = {
117 .bLength = sizeof gser_ss_bulk_comp_desc, 118 .bLength = sizeof gser_ss_bulk_comp_desc,
118 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 119 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
119}; 120};
120 121
121static struct usb_descriptor_header *gser_ss_function[] __initdata = { 122static struct usb_descriptor_header *gser_ss_function[] = {
122 (struct usb_descriptor_header *) &gser_interface_desc, 123 (struct usb_descriptor_header *) &gser_interface_desc,
123 (struct usb_descriptor_header *) &gser_ss_in_desc, 124 (struct usb_descriptor_header *) &gser_ss_in_desc,
124 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc, 125 (struct usb_descriptor_header *) &gser_ss_bulk_comp_desc,
@@ -183,14 +184,25 @@ static void gser_disable(struct usb_function *f)
183 184
184/* serial function driver setup/binding */ 185/* serial function driver setup/binding */
185 186
186static int __init 187static int gser_bind(struct usb_configuration *c, struct usb_function *f)
187gser_bind(struct usb_configuration *c, struct usb_function *f)
188{ 188{
189 struct usb_composite_dev *cdev = c->cdev; 189 struct usb_composite_dev *cdev = c->cdev;
190 struct f_gser *gser = func_to_gser(f); 190 struct f_gser *gser = func_to_gser(f);
191 int status; 191 int status;
192 struct usb_ep *ep; 192 struct usb_ep *ep;
193 193
194 /* REVISIT might want instance-specific strings to help
195 * distinguish instances ...
196 */
197
198 /* maybe allocate device-global string ID */
199 if (gser_string_defs[0].id == 0) {
200 status = usb_string_id(c->cdev);
201 if (status < 0)
202 return status;
203 gser_string_defs[0].id = status;
204 }
205
194 /* allocate instance-specific interface IDs */ 206 /* allocate instance-specific interface IDs */
195 status = usb_interface_id(c, f); 207 status = usb_interface_id(c, f);
196 if (status < 0) 208 if (status < 0)
@@ -246,44 +258,115 @@ fail:
246 return status; 258 return status;
247} 259}
248 260
249static void 261static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
250gser_unbind(struct usb_configuration *c, struct usb_function *f)
251{ 262{
252 usb_free_all_descriptors(f); 263 return container_of(to_config_group(item), struct f_serial_opts,
253 kfree(func_to_gser(f)); 264 func_inst.group);
254} 265}
255 266
256/** 267CONFIGFS_ATTR_STRUCT(f_serial_opts);
257 * gser_bind_config - add a generic serial function to a configuration 268static ssize_t f_serial_attr_show(struct config_item *item,
258 * @c: the configuration to support the serial instance 269 struct configfs_attribute *attr,
259 * @port_num: /dev/ttyGS* port this interface will use 270 char *page)
260 * Context: single threaded during gadget setup
261 *
262 * Returns zero on success, else negative errno.
263 */
264int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
265{ 271{
266 struct f_gser *gser; 272 struct f_serial_opts *opts = to_f_serial_opts(item);
267 int status; 273 struct f_serial_opts_attribute *f_serial_opts_attr =
274 container_of(attr, struct f_serial_opts_attribute, attr);
275 ssize_t ret = 0;
268 276
269 /* REVISIT might want instance-specific strings to help 277 if (f_serial_opts_attr->show)
270 * distinguish instances ... 278 ret = f_serial_opts_attr->show(opts, page);
271 */
272 279
273 /* maybe allocate device-global string ID */ 280 return ret;
274 if (gser_string_defs[0].id == 0) { 281}
275 status = usb_string_id(c->cdev); 282
276 if (status < 0) 283static void serial_attr_release(struct config_item *item)
277 return status; 284{
278 gser_string_defs[0].id = status; 285 struct f_serial_opts *opts = to_f_serial_opts(item);
286
287 usb_put_function_instance(&opts->func_inst);
288}
289
290static struct configfs_item_operations serial_item_ops = {
291 .release = serial_attr_release,
292 .show_attribute = f_serial_attr_show,
293};
294
295static ssize_t f_serial_port_num_show(struct f_serial_opts *opts, char *page)
296{
297 return sprintf(page, "%u\n", opts->port_num);
298}
299
300static struct f_serial_opts_attribute f_serial_port_num =
301 __CONFIGFS_ATTR_RO(port_num, f_serial_port_num_show);
302
303static struct configfs_attribute *acm_attrs[] = {
304 &f_serial_port_num.attr,
305 NULL,
306};
307
308static struct config_item_type serial_func_type = {
309 .ct_item_ops = &serial_item_ops,
310 .ct_attrs = acm_attrs,
311 .ct_owner = THIS_MODULE,
312};
313
314static void gser_free_inst(struct usb_function_instance *f)
315{
316 struct f_serial_opts *opts;
317
318 opts = container_of(f, struct f_serial_opts, func_inst);
319 gserial_free_line(opts->port_num);
320 kfree(opts);
321}
322
323static struct usb_function_instance *gser_alloc_inst(void)
324{
325 struct f_serial_opts *opts;
326 int ret;
327
328 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
329 if (!opts)
330 return ERR_PTR(-ENOMEM);
331
332 opts->func_inst.free_func_inst = gser_free_inst;
333 ret = gserial_alloc_line(&opts->port_num);
334 if (ret) {
335 kfree(opts);
336 return ERR_PTR(ret);
279 } 337 }
338 config_group_init_type_name(&opts->func_inst.group, "",
339 &serial_func_type);
340
341 return &opts->func_inst;
342}
343
344static void gser_free(struct usb_function *f)
345{
346 struct f_gser *serial;
347
348 serial = func_to_gser(f);
349 kfree(serial);
350}
351
352static void gser_unbind(struct usb_configuration *c, struct usb_function *f)
353{
354 usb_free_all_descriptors(f);
355}
356
357struct usb_function *gser_alloc(struct usb_function_instance *fi)
358{
359 struct f_gser *gser;
360 struct f_serial_opts *opts;
280 361
281 /* allocate and initialize one new instance */ 362 /* allocate and initialize one new instance */
282 gser = kzalloc(sizeof *gser, GFP_KERNEL); 363 gser = kzalloc(sizeof(*gser), GFP_KERNEL);
283 if (!gser) 364 if (!gser)
284 return -ENOMEM; 365 return ERR_PTR(-ENOMEM);
285 366
286 gser->port_num = port_num; 367 opts = container_of(fi, struct f_serial_opts, func_inst);
368
369 gser->port_num = opts->port_num;
287 370
288 gser->port.func.name = "gser"; 371 gser->port.func.name = "gser";
289 gser->port.func.strings = gser_strings; 372 gser->port.func.strings = gser_strings;
@@ -291,9 +374,12 @@ int __init gser_bind_config(struct usb_configuration *c, u8 port_num)
291 gser->port.func.unbind = gser_unbind; 374 gser->port.func.unbind = gser_unbind;
292 gser->port.func.set_alt = gser_set_alt; 375 gser->port.func.set_alt = gser_set_alt;
293 gser->port.func.disable = gser_disable; 376 gser->port.func.disable = gser_disable;
377 gser->port.func.free_func = gser_free;
294 378
295 status = usb_add_function(c, &gser->port.func); 379 return &gser->port.func;
296 if (status)
297 kfree(gser);
298 return status;
299} 380}
381
382DECLARE_USB_FUNCTION_INIT(gser, gser_alloc_inst, gser_alloc);
383MODULE_LICENSE("GPL");
384MODULE_AUTHOR("Al Borchers");
385MODULE_AUTHOR("David Brownell");
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 41adf3ef96c2..a8895859a221 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -898,7 +898,7 @@ static struct usb_function *source_sink_alloc_func(
898 return &ss->function; 898 return &ss->function;
899} 899}
900 900
901static void acm_free_instance(struct usb_function_instance *fi) 901static void source_sink_free_instance(struct usb_function_instance *fi)
902{ 902{
903 struct f_ss_opts *ss_opts; 903 struct f_ss_opts *ss_opts;
904 904
@@ -913,7 +913,7 @@ static struct usb_function_instance *source_sink_alloc_inst(void)
913 ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); 913 ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL);
914 if (!ss_opts) 914 if (!ss_opts)
915 return ERR_PTR(-ENOMEM); 915 return ERR_PTR(-ENOMEM);
916 ss_opts->func_inst.free_func_inst = acm_free_instance; 916 ss_opts->func_inst.free_func_inst = source_sink_free_instance;
917 return &ss_opts->func_inst; 917 return &ss_opts->func_inst;
918} 918}
919DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst, 919DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst,
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index f172bd152fbb..185d6f5e4e4d 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -380,7 +380,8 @@ geth_unbind(struct usb_configuration *c, struct usb_function *f)
380 * Caller must have called @gether_setup(). Caller is also responsible 380 * Caller must have called @gether_setup(). Caller is also responsible
381 * for calling @gether_cleanup() before module unload. 381 * for calling @gether_cleanup() before module unload.
382 */ 382 */
383int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 383int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
384 struct eth_dev *dev)
384{ 385{
385 struct f_gether *geth; 386 struct f_gether *geth;
386 int status; 387 int status;
@@ -406,6 +407,7 @@ int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
406 snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr); 407 snprintf(geth->ethaddr, sizeof geth->ethaddr, "%pm", ethaddr);
407 geth_string_defs[1].s = geth->ethaddr; 408 geth_string_defs[1].s = geth->ethaddr;
408 409
410 geth->port.ioport = dev;
409 geth->port.cdc_filter = DEFAULT_FILTER; 411 geth->port.cdc_filter = DEFAULT_FILTER;
410 412
411 geth->port.func.name = "cdc_subset"; 413 geth->port.func.name = "cdc_subset";
diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index 92efd6ec48af..38dcedddc52c 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -33,19 +33,15 @@ unsigned int uvc_gadget_trace_param;
33/*-------------------------------------------------------------------------*/ 33/*-------------------------------------------------------------------------*/
34 34
35/* module parameters specific to the Video streaming endpoint */ 35/* module parameters specific to the Video streaming endpoint */
36static unsigned streaming_interval = 1; 36static unsigned int streaming_interval = 1;
37module_param(streaming_interval, uint, S_IRUGO|S_IWUSR); 37module_param(streaming_interval, uint, S_IRUGO|S_IWUSR);
38MODULE_PARM_DESC(streaming_interval, "1 - 16"); 38MODULE_PARM_DESC(streaming_interval, "1 - 16");
39 39
40static unsigned streaming_maxpacket = 1024; 40static unsigned int streaming_maxpacket = 1024;
41module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR); 41module_param(streaming_maxpacket, uint, S_IRUGO|S_IWUSR);
42MODULE_PARM_DESC(streaming_maxpacket, "0 - 1023 (fs), 0 - 1024 (hs/ss)"); 42MODULE_PARM_DESC(streaming_maxpacket, "1 - 1023 (FS), 1 - 3072 (hs/ss)");
43 43
44static unsigned streaming_mult; 44static unsigned int streaming_maxburst;
45module_param(streaming_mult, uint, S_IRUGO|S_IWUSR);
46MODULE_PARM_DESC(streaming_mult, "0 - 2 (hs/ss only)");
47
48static unsigned streaming_maxburst;
49module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR); 45module_param(streaming_maxburst, uint, S_IRUGO|S_IWUSR);
50MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)"); 46MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)");
51 47
@@ -55,13 +51,11 @@ MODULE_PARM_DESC(streaming_maxburst, "0 - 15 (ss only)");
55 51
56/* string IDs are assigned dynamically */ 52/* string IDs are assigned dynamically */
57 53
58#define UVC_STRING_ASSOCIATION_IDX 0 54#define UVC_STRING_CONTROL_IDX 0
59#define UVC_STRING_CONTROL_IDX 1 55#define UVC_STRING_STREAMING_IDX 1
60#define UVC_STRING_STREAMING_IDX 2
61 56
62static struct usb_string uvc_en_us_strings[] = { 57static struct usb_string uvc_en_us_strings[] = {
63 [UVC_STRING_ASSOCIATION_IDX].s = "UVC Camera", 58 [UVC_STRING_CONTROL_IDX].s = "UVC Camera",
64 [UVC_STRING_CONTROL_IDX].s = "Video Control",
65 [UVC_STRING_STREAMING_IDX].s = "Video Streaming", 59 [UVC_STRING_STREAMING_IDX].s = "Video Streaming",
66 { } 60 { }
67}; 61};
@@ -79,7 +73,7 @@ static struct usb_gadget_strings *uvc_function_strings[] = {
79#define UVC_INTF_VIDEO_CONTROL 0 73#define UVC_INTF_VIDEO_CONTROL 0
80#define UVC_INTF_VIDEO_STREAMING 1 74#define UVC_INTF_VIDEO_STREAMING 1
81 75
82#define STATUS_BYTECOUNT 16 /* 16 bytes status */ 76#define UVC_STATUS_MAX_PACKET_SIZE 16 /* 16 bytes status */
83 77
84static struct usb_interface_assoc_descriptor uvc_iad __initdata = { 78static struct usb_interface_assoc_descriptor uvc_iad __initdata = {
85 .bLength = sizeof(uvc_iad), 79 .bLength = sizeof(uvc_iad),
@@ -104,20 +98,29 @@ static struct usb_interface_descriptor uvc_control_intf __initdata = {
104 .iInterface = 0, 98 .iInterface = 0,
105}; 99};
106 100
107static struct usb_endpoint_descriptor uvc_fs_control_ep __initdata = { 101static struct usb_endpoint_descriptor uvc_control_ep __initdata = {
108 .bLength = USB_DT_ENDPOINT_SIZE, 102 .bLength = USB_DT_ENDPOINT_SIZE,
109 .bDescriptorType = USB_DT_ENDPOINT, 103 .bDescriptorType = USB_DT_ENDPOINT,
110 .bEndpointAddress = USB_DIR_IN, 104 .bEndpointAddress = USB_DIR_IN,
111 .bmAttributes = USB_ENDPOINT_XFER_INT, 105 .bmAttributes = USB_ENDPOINT_XFER_INT,
112 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT), 106 .wMaxPacketSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
113 .bInterval = 8, 107 .bInterval = 8,
114}; 108};
115 109
110static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = {
111 .bLength = sizeof(uvc_ss_control_comp),
112 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
113 /* The following 3 values can be tweaked if necessary. */
114 .bMaxBurst = 0,
115 .bmAttributes = 0,
116 .wBytesPerInterval = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
117};
118
116static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = { 119static struct uvc_control_endpoint_descriptor uvc_control_cs_ep __initdata = {
117 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE, 120 .bLength = UVC_DT_CONTROL_ENDPOINT_SIZE,
118 .bDescriptorType = USB_DT_CS_ENDPOINT, 121 .bDescriptorType = USB_DT_CS_ENDPOINT,
119 .bDescriptorSubType = UVC_EP_INTERRUPT, 122 .bDescriptorSubType = UVC_EP_INTERRUPT,
120 .wMaxTransferSize = cpu_to_le16(STATUS_BYTECOUNT), 123 .wMaxTransferSize = cpu_to_le16(UVC_STATUS_MAX_PACKET_SIZE),
121}; 124};
122 125
123static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = { 126static struct usb_interface_descriptor uvc_streaming_intf_alt0 __initdata = {
@@ -144,63 +147,53 @@ static struct usb_interface_descriptor uvc_streaming_intf_alt1 __initdata = {
144 .iInterface = 0, 147 .iInterface = 0,
145}; 148};
146 149
147static struct usb_endpoint_descriptor uvc_fs_streaming_ep = { 150static struct usb_endpoint_descriptor uvc_fs_streaming_ep __initdata = {
148 .bLength = USB_DT_ENDPOINT_SIZE, 151 .bLength = USB_DT_ENDPOINT_SIZE,
149 .bDescriptorType = USB_DT_ENDPOINT, 152 .bDescriptorType = USB_DT_ENDPOINT,
150 .bEndpointAddress = USB_DIR_IN, 153 .bEndpointAddress = USB_DIR_IN,
151 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 154 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
152 .wMaxPacketSize = cpu_to_le16(512), 155 | USB_ENDPOINT_XFER_ISOC,
153 .bInterval = 1, 156 /* The wMaxPacketSize and bInterval values will be initialized from
157 * module parameters.
158 */
159 .wMaxPacketSize = 0,
160 .bInterval = 0,
154}; 161};
155 162
156static struct usb_endpoint_descriptor uvc_hs_streaming_ep = { 163static struct usb_endpoint_descriptor uvc_hs_streaming_ep __initdata = {
157 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
158 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
159 .bEndpointAddress = USB_DIR_IN, 166 .bEndpointAddress = USB_DIR_IN,
160 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 167 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
161 .wMaxPacketSize = cpu_to_le16(1024), 168 | USB_ENDPOINT_XFER_ISOC,
162 .bInterval = 1, 169 /* The wMaxPacketSize and bInterval values will be initialized from
163}; 170 * module parameters.
164 171 */
165/* super speed support */ 172 .wMaxPacketSize = 0,
166static struct usb_endpoint_descriptor uvc_ss_control_ep __initdata = { 173 .bInterval = 0,
167 .bLength = USB_DT_ENDPOINT_SIZE,
168 .bDescriptorType = USB_DT_ENDPOINT,
169
170 .bEndpointAddress = USB_DIR_IN,
171 .bmAttributes = USB_ENDPOINT_XFER_INT,
172 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
173 .bInterval = 8,
174};
175
176static struct usb_ss_ep_comp_descriptor uvc_ss_control_comp __initdata = {
177 .bLength = sizeof uvc_ss_control_comp,
178 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
179
180 /* the following 3 values can be tweaked if necessary */
181 /* .bMaxBurst = 0, */
182 /* .bmAttributes = 0, */
183 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
184}; 174};
185 175
186static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = { 176static struct usb_endpoint_descriptor uvc_ss_streaming_ep __initdata = {
187 .bLength = USB_DT_ENDPOINT_SIZE, 177 .bLength = USB_DT_ENDPOINT_SIZE,
188 .bDescriptorType = USB_DT_ENDPOINT, 178 .bDescriptorType = USB_DT_ENDPOINT,
189 179
190 .bEndpointAddress = USB_DIR_IN, 180 .bEndpointAddress = USB_DIR_IN,
191 .bmAttributes = USB_ENDPOINT_XFER_ISOC, 181 .bmAttributes = USB_ENDPOINT_SYNC_ASYNC
192 .wMaxPacketSize = cpu_to_le16(1024), 182 | USB_ENDPOINT_XFER_ISOC,
193 .bInterval = 4, 183 /* The wMaxPacketSize and bInterval values will be initialized from
184 * module parameters.
185 */
186 .wMaxPacketSize = 0,
187 .bInterval = 0,
194}; 188};
195 189
196static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp = { 190static struct usb_ss_ep_comp_descriptor uvc_ss_streaming_comp __initdata = {
197 .bLength = sizeof uvc_ss_streaming_comp, 191 .bLength = sizeof(uvc_ss_streaming_comp),
198 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, 192 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
199 193 /* The following 3 values can be tweaked if necessary. */
200 /* the following 3 values can be tweaked if necessary */ 194 .bMaxBurst = 0,
201 .bMaxBurst = 0, 195 .bmAttributes = 0,
202 .bmAttributes = 0, 196 .wBytesPerInterval = cpu_to_le16(1024),
203 .wBytesPerInterval = cpu_to_le16(1024),
204}; 197};
205 198
206static const struct usb_descriptor_header * const uvc_fs_streaming[] = { 199static const struct usb_descriptor_header * const uvc_fs_streaming[] = {
@@ -273,6 +266,13 @@ uvc_function_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
273 return 0; 266 return 0;
274} 267}
275 268
269void uvc_function_setup_continue(struct uvc_device *uvc)
270{
271 struct usb_composite_dev *cdev = uvc->func.config->cdev;
272
273 usb_composite_setup_continue(cdev);
274}
275
276static int 276static int
277uvc_function_get_alt(struct usb_function *f, unsigned interface) 277uvc_function_get_alt(struct usb_function *f, unsigned interface)
278{ 278{
@@ -335,7 +335,7 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
335 v4l2_event_queue(uvc->vdev, &v4l2_event); 335 v4l2_event_queue(uvc->vdev, &v4l2_event);
336 336
337 uvc->state = UVC_STATE_CONNECTED; 337 uvc->state = UVC_STATE_CONNECTED;
338 break; 338 return 0;
339 339
340 case 1: 340 case 1:
341 if (uvc->state != UVC_STATE_CONNECTED) 341 if (uvc->state != UVC_STATE_CONNECTED)
@@ -352,15 +352,11 @@ uvc_function_set_alt(struct usb_function *f, unsigned interface, unsigned alt)
352 memset(&v4l2_event, 0, sizeof(v4l2_event)); 352 memset(&v4l2_event, 0, sizeof(v4l2_event));
353 v4l2_event.type = UVC_EVENT_STREAMON; 353 v4l2_event.type = UVC_EVENT_STREAMON;
354 v4l2_event_queue(uvc->vdev, &v4l2_event); 354 v4l2_event_queue(uvc->vdev, &v4l2_event);
355 355 return USB_GADGET_DELAYED_STATUS;
356 uvc->state = UVC_STATE_STREAMING;
357 break;
358 356
359 default: 357 default:
360 return -EINVAL; 358 return -EINVAL;
361 } 359 }
362
363 return 0;
364} 360}
365 361
366static void 362static void
@@ -454,7 +450,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
454 const struct uvc_descriptor_header * const *uvc_streaming_cls; 450 const struct uvc_descriptor_header * const *uvc_streaming_cls;
455 const struct usb_descriptor_header * const *uvc_streaming_std; 451 const struct usb_descriptor_header * const *uvc_streaming_std;
456 const struct usb_descriptor_header * const *src; 452 const struct usb_descriptor_header * const *src;
457 static struct usb_endpoint_descriptor *uvc_control_ep;
458 struct usb_descriptor_header **dst; 453 struct usb_descriptor_header **dst;
459 struct usb_descriptor_header **hdr; 454 struct usb_descriptor_header **hdr;
460 unsigned int control_size; 455 unsigned int control_size;
@@ -468,14 +463,12 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
468 uvc_control_desc = uvc->desc.ss_control; 463 uvc_control_desc = uvc->desc.ss_control;
469 uvc_streaming_cls = uvc->desc.ss_streaming; 464 uvc_streaming_cls = uvc->desc.ss_streaming;
470 uvc_streaming_std = uvc_ss_streaming; 465 uvc_streaming_std = uvc_ss_streaming;
471 uvc_control_ep = &uvc_ss_control_ep;
472 break; 466 break;
473 467
474 case USB_SPEED_HIGH: 468 case USB_SPEED_HIGH:
475 uvc_control_desc = uvc->desc.fs_control; 469 uvc_control_desc = uvc->desc.fs_control;
476 uvc_streaming_cls = uvc->desc.hs_streaming; 470 uvc_streaming_cls = uvc->desc.hs_streaming;
477 uvc_streaming_std = uvc_hs_streaming; 471 uvc_streaming_std = uvc_hs_streaming;
478 uvc_control_ep = &uvc_fs_control_ep;
479 break; 472 break;
480 473
481 case USB_SPEED_FULL: 474 case USB_SPEED_FULL:
@@ -483,7 +476,6 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
483 uvc_control_desc = uvc->desc.fs_control; 476 uvc_control_desc = uvc->desc.fs_control;
484 uvc_streaming_cls = uvc->desc.fs_streaming; 477 uvc_streaming_cls = uvc->desc.fs_streaming;
485 uvc_streaming_std = uvc_fs_streaming; 478 uvc_streaming_std = uvc_fs_streaming;
486 uvc_control_ep = &uvc_fs_control_ep;
487 break; 479 break;
488 } 480 }
489 481
@@ -494,6 +486,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
494 * Class-specific UVC control descriptors 486 * Class-specific UVC control descriptors
495 * uvc_control_ep 487 * uvc_control_ep
496 * uvc_control_cs_ep 488 * uvc_control_cs_ep
489 * uvc_ss_control_comp (for SS only)
497 * uvc_streaming_intf_alt0 490 * uvc_streaming_intf_alt0
498 * Class-specific UVC streaming descriptors 491 * Class-specific UVC streaming descriptors
499 * uvc_{fs|hs}_streaming 492 * uvc_{fs|hs}_streaming
@@ -503,7 +496,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
503 control_size = 0; 496 control_size = 0;
504 streaming_size = 0; 497 streaming_size = 0;
505 bytes = uvc_iad.bLength + uvc_control_intf.bLength 498 bytes = uvc_iad.bLength + uvc_control_intf.bLength
506 + uvc_control_ep->bLength + uvc_control_cs_ep.bLength 499 + uvc_control_ep.bLength + uvc_control_cs_ep.bLength
507 + uvc_streaming_intf_alt0.bLength; 500 + uvc_streaming_intf_alt0.bLength;
508 501
509 if (speed == USB_SPEED_SUPER) { 502 if (speed == USB_SPEED_SUPER) {
@@ -514,13 +507,13 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
514 } 507 }
515 508
516 for (src = (const struct usb_descriptor_header **)uvc_control_desc; 509 for (src = (const struct usb_descriptor_header **)uvc_control_desc;
517 *src; ++src) { 510 *src; ++src) {
518 control_size += (*src)->bLength; 511 control_size += (*src)->bLength;
519 bytes += (*src)->bLength; 512 bytes += (*src)->bLength;
520 n_desc++; 513 n_desc++;
521 } 514 }
522 for (src = (const struct usb_descriptor_header **)uvc_streaming_cls; 515 for (src = (const struct usb_descriptor_header **)uvc_streaming_cls;
523 *src; ++src) { 516 *src; ++src) {
524 streaming_size += (*src)->bLength; 517 streaming_size += (*src)->bLength;
525 bytes += (*src)->bLength; 518 bytes += (*src)->bLength;
526 n_desc++; 519 n_desc++;
@@ -549,7 +542,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
549 uvc_control_header->bInCollection = 1; 542 uvc_control_header->bInCollection = 1;
550 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf; 543 uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
551 544
552 UVC_COPY_DESCRIPTOR(mem, dst, uvc_control_ep); 545 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_control_ep);
553 if (speed == USB_SPEED_SUPER) 546 if (speed == USB_SPEED_SUPER)
554 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp); 547 UVC_COPY_DESCRIPTOR(mem, dst, &uvc_ss_control_comp);
555 548
@@ -560,8 +553,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
560 UVC_COPY_DESCRIPTORS(mem, dst, 553 UVC_COPY_DESCRIPTORS(mem, dst,
561 (const struct usb_descriptor_header**)uvc_streaming_cls); 554 (const struct usb_descriptor_header**)uvc_streaming_cls);
562 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size); 555 uvc_streaming_header->wTotalLength = cpu_to_le16(streaming_size);
563 uvc_streaming_header->bEndpointAddress = 556 uvc_streaming_header->bEndpointAddress = uvc->video.ep->address;
564 uvc_fs_streaming_ep.bEndpointAddress;
565 557
566 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std); 558 UVC_COPY_DESCRIPTORS(mem, dst, uvc_streaming_std);
567 559
@@ -581,7 +573,7 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
581 uvc->control_ep->driver_data = NULL; 573 uvc->control_ep->driver_data = NULL;
582 uvc->video.ep->driver_data = NULL; 574 uvc->video.ep->driver_data = NULL;
583 575
584 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id = 0; 576 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id = 0;
585 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req); 577 usb_ep_free_request(cdev->gadget->ep0, uvc->control_req);
586 kfree(uvc->control_buf); 578 kfree(uvc->control_buf);
587 579
@@ -595,31 +587,52 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
595{ 587{
596 struct usb_composite_dev *cdev = c->cdev; 588 struct usb_composite_dev *cdev = c->cdev;
597 struct uvc_device *uvc = to_uvc(f); 589 struct uvc_device *uvc = to_uvc(f);
590 unsigned int max_packet_mult;
591 unsigned int max_packet_size;
598 struct usb_ep *ep; 592 struct usb_ep *ep;
599 int ret = -EINVAL; 593 int ret = -EINVAL;
600 594
601 INFO(cdev, "uvc_function_bind\n"); 595 INFO(cdev, "uvc_function_bind\n");
602 596
603 /* sanity check the streaming endpoint module parameters */ 597 /* Sanity check the streaming endpoint module parameters.
604 if (streaming_interval < 1)
605 streaming_interval = 1;
606 if (streaming_interval > 16)
607 streaming_interval = 16;
608 if (streaming_mult > 2)
609 streaming_mult = 2;
610 if (streaming_maxburst > 15)
611 streaming_maxburst = 15;
612
613 /*
614 * fill in the FS video streaming specific descriptors from the
615 * module parameters
616 */ 598 */
617 uvc_fs_streaming_ep.wMaxPacketSize = streaming_maxpacket > 1023 ? 599 streaming_interval = clamp(streaming_interval, 1U, 16U);
618 1023 : streaming_maxpacket; 600 streaming_maxpacket = clamp(streaming_maxpacket, 1U, 3072U);
601 streaming_maxburst = min(streaming_maxburst, 15U);
602
603 /* Fill in the FS/HS/SS Video Streaming specific descriptors from the
604 * module parameters.
605 *
606 * NOTE: We assume that the user knows what they are doing and won't
607 * give parameters that their UDC doesn't support.
608 */
609 if (streaming_maxpacket <= 1024) {
610 max_packet_mult = 1;
611 max_packet_size = streaming_maxpacket;
612 } else if (streaming_maxpacket <= 2048) {
613 max_packet_mult = 2;
614 max_packet_size = streaming_maxpacket / 2;
615 } else {
616 max_packet_mult = 3;
617 max_packet_size = streaming_maxpacket / 3;
618 }
619
620 uvc_fs_streaming_ep.wMaxPacketSize = min(streaming_maxpacket, 1023U);
619 uvc_fs_streaming_ep.bInterval = streaming_interval; 621 uvc_fs_streaming_ep.bInterval = streaming_interval;
620 622
623 uvc_hs_streaming_ep.wMaxPacketSize = max_packet_size;
624 uvc_hs_streaming_ep.wMaxPacketSize |= ((max_packet_mult - 1) << 11);
625 uvc_hs_streaming_ep.bInterval = streaming_interval;
626
627 uvc_ss_streaming_ep.wMaxPacketSize = max_packet_size;
628 uvc_ss_streaming_ep.bInterval = streaming_interval;
629 uvc_ss_streaming_comp.bmAttributes = max_packet_mult - 1;
630 uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst;
631 uvc_ss_streaming_comp.wBytesPerInterval =
632 max_packet_size * max_packet_mult * streaming_maxburst;
633
621 /* Allocate endpoints. */ 634 /* Allocate endpoints. */
622 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_control_ep); 635 ep = usb_ep_autoconfig(cdev->gadget, &uvc_control_ep);
623 if (!ep) { 636 if (!ep) {
624 INFO(cdev, "Unable to allocate control EP\n"); 637 INFO(cdev, "Unable to allocate control EP\n");
625 goto error; 638 goto error;
@@ -627,7 +640,14 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
627 uvc->control_ep = ep; 640 uvc->control_ep = ep;
628 ep->driver_data = uvc; 641 ep->driver_data = uvc;
629 642
630 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); 643 if (gadget_is_superspeed(c->cdev->gadget))
644 ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep,
645 &uvc_ss_streaming_comp);
646 else if (gadget_is_dualspeed(cdev->gadget))
647 ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep);
648 else
649 ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep);
650
631 if (!ep) { 651 if (!ep) {
632 INFO(cdev, "Unable to allocate streaming EP\n"); 652 INFO(cdev, "Unable to allocate streaming EP\n");
633 goto error; 653 goto error;
@@ -635,6 +655,10 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
635 uvc->video.ep = ep; 655 uvc->video.ep = ep;
636 ep->driver_data = uvc; 656 ep->driver_data = uvc;
637 657
658 uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
659 uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address;
660 uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;
661
638 /* Allocate interface IDs. */ 662 /* Allocate interface IDs. */
639 if ((ret = usb_interface_id(c, f)) < 0) 663 if ((ret = usb_interface_id(c, f)) < 0)
640 goto error; 664 goto error;
@@ -648,37 +672,6 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f)
648 uvc_streaming_intf_alt1.bInterfaceNumber = ret; 672 uvc_streaming_intf_alt1.bInterfaceNumber = ret;
649 uvc->streaming_intf = ret; 673 uvc->streaming_intf = ret;
650 674
651 /* sanity check the streaming endpoint module parameters */
652 if (streaming_maxpacket > 1024)
653 streaming_maxpacket = 1024;
654 /*
655 * Fill in the HS descriptors from the module parameters for the Video
656 * Streaming endpoint.
657 * NOTE: We assume that the user knows what they are doing and won't
658 * give parameters that their UDC doesn't support.
659 */
660 uvc_hs_streaming_ep.wMaxPacketSize = streaming_maxpacket;
661 uvc_hs_streaming_ep.wMaxPacketSize |= streaming_mult << 11;
662 uvc_hs_streaming_ep.bInterval = streaming_interval;
663 uvc_hs_streaming_ep.bEndpointAddress =
664 uvc_fs_streaming_ep.bEndpointAddress;
665
666 /*
667 * Fill in the SS descriptors from the module parameters for the Video
668 * Streaming endpoint.
669 * NOTE: We assume that the user knows what they are doing and won't
670 * give parameters that their UDC doesn't support.
671 */
672 uvc_ss_streaming_ep.wMaxPacketSize = streaming_maxpacket;
673 uvc_ss_streaming_ep.bInterval = streaming_interval;
674 uvc_ss_streaming_comp.bmAttributes = streaming_mult;
675 uvc_ss_streaming_comp.bMaxBurst = streaming_maxburst;
676 uvc_ss_streaming_comp.wBytesPerInterval =
677 streaming_maxpacket * (streaming_mult + 1) *
678 (streaming_maxburst + 1);
679 uvc_ss_streaming_ep.bEndpointAddress =
680 uvc_fs_streaming_ep.bEndpointAddress;
681
682 /* Copy descriptors */ 675 /* Copy descriptors */
683 f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL); 676 f->fs_descriptors = uvc_copy_descriptors(uvc, USB_SPEED_FULL);
684 if (gadget_is_dualspeed(cdev->gadget)) 677 if (gadget_is_dualspeed(cdev->gadget))
@@ -775,23 +768,23 @@ uvc_bind_config(struct usb_configuration *c,
775 768
776 /* Validate the descriptors. */ 769 /* Validate the descriptors. */
777 if (fs_control == NULL || fs_control[0] == NULL || 770 if (fs_control == NULL || fs_control[0] == NULL ||
778 fs_control[0]->bDescriptorSubType != UVC_VC_HEADER) 771 fs_control[0]->bDescriptorSubType != UVC_VC_HEADER)
779 goto error; 772 goto error;
780 773
781 if (ss_control == NULL || ss_control[0] == NULL || 774 if (ss_control == NULL || ss_control[0] == NULL ||
782 ss_control[0]->bDescriptorSubType != UVC_VC_HEADER) 775 ss_control[0]->bDescriptorSubType != UVC_VC_HEADER)
783 goto error; 776 goto error;
784 777
785 if (fs_streaming == NULL || fs_streaming[0] == NULL || 778 if (fs_streaming == NULL || fs_streaming[0] == NULL ||
786 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 779 fs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
787 goto error; 780 goto error;
788 781
789 if (hs_streaming == NULL || hs_streaming[0] == NULL || 782 if (hs_streaming == NULL || hs_streaming[0] == NULL ||
790 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 783 hs_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
791 goto error; 784 goto error;
792 785
793 if (ss_streaming == NULL || ss_streaming[0] == NULL || 786 if (ss_streaming == NULL || ss_streaming[0] == NULL ||
794 ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER) 787 ss_streaming[0]->bDescriptorSubType != UVC_VS_INPUT_HEADER)
795 goto error; 788 goto error;
796 789
797 uvc->desc.fs_control = fs_control; 790 uvc->desc.fs_control = fs_control;
@@ -800,13 +793,16 @@ uvc_bind_config(struct usb_configuration *c,
800 uvc->desc.hs_streaming = hs_streaming; 793 uvc->desc.hs_streaming = hs_streaming;
801 uvc->desc.ss_streaming = ss_streaming; 794 uvc->desc.ss_streaming = ss_streaming;
802 795
803 /* Allocate string descriptor numbers. */ 796 /* String descriptors are global, we only need to allocate string IDs
804 if (uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id == 0) { 797 * for the first UVC function. UVC functions beyond the first (if any)
798 * will reuse the same IDs.
799 */
800 if (uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id == 0) {
805 ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings); 801 ret = usb_string_ids_tab(c->cdev, uvc_en_us_strings);
806 if (ret) 802 if (ret)
807 goto error; 803 goto error;
808 uvc_iad.iFunction = 804 uvc_iad.iFunction =
809 uvc_en_us_strings[UVC_STRING_ASSOCIATION_IDX].id; 805 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id;
810 uvc_control_intf.iInterface = 806 uvc_control_intf.iInterface =
811 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id; 807 uvc_en_us_strings[UVC_STRING_CONTROL_IDX].id;
812 ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id; 808 ret = uvc_en_us_strings[UVC_STRING_STREAMING_IDX].id;
diff --git a/drivers/usb/gadget/f_uvc.h b/drivers/usb/gadget/f_uvc.h
index c3d258d30188..ec52752f7326 100644
--- a/drivers/usb/gadget/f_uvc.h
+++ b/drivers/usb/gadget/f_uvc.h
@@ -16,12 +16,12 @@
16#include <linux/usb/composite.h> 16#include <linux/usb/composite.h>
17#include <linux/usb/video.h> 17#include <linux/usb/video.h>
18 18
19extern int uvc_bind_config(struct usb_configuration *c, 19int uvc_bind_config(struct usb_configuration *c,
20 const struct uvc_descriptor_header * const *fs_control, 20 const struct uvc_descriptor_header * const *fs_control,
21 const struct uvc_descriptor_header * const *hs_control, 21 const struct uvc_descriptor_header * const *hs_control,
22 const struct uvc_descriptor_header * const *fs_streaming, 22 const struct uvc_descriptor_header * const *fs_streaming,
23 const struct uvc_descriptor_header * const *hs_streaming, 23 const struct uvc_descriptor_header * const *hs_streaming,
24 const struct uvc_descriptor_header * const *ss_streaming); 24 const struct uvc_descriptor_header * const *ss_streaming);
25 25
26#endif /* _F_UVC_H_ */ 26#endif /* _F_UVC_H_ */
27 27
diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 034477ce77c6..9a7ee3347e4d 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2296,7 +2296,6 @@ static int fsl_qe_start(struct usb_gadget *gadget,
2296 driver->driver.bus = NULL; 2296 driver->driver.bus = NULL;
2297 /* hook up the driver */ 2297 /* hook up the driver */
2298 udc->driver = driver; 2298 udc->driver = driver;
2299 udc->gadget.dev.driver = &driver->driver;
2300 udc->gadget.speed = driver->max_speed; 2299 udc->gadget.speed = driver->max_speed;
2301 2300
2302 /* Enable IRQ reg and Set usbcmd reg EN bit */ 2301 /* Enable IRQ reg and Set usbcmd reg EN bit */
@@ -2338,7 +2337,6 @@ static int fsl_qe_stop(struct usb_gadget *gadget,
2338 nuke(loop_ep, -ESHUTDOWN); 2337 nuke(loop_ep, -ESHUTDOWN);
2339 spin_unlock_irqrestore(&udc->lock, flags); 2338 spin_unlock_irqrestore(&udc->lock, flags);
2340 2339
2341 udc->gadget.dev.driver = NULL;
2342 udc->driver = NULL; 2340 udc->driver = NULL;
2343 2341
2344 dev_info(udc->dev, "unregistered gadget driver '%s'\r\n", 2342 dev_info(udc->dev, "unregistered gadget driver '%s'\r\n",
@@ -2523,12 +2521,6 @@ static int qe_udc_probe(struct platform_device *ofdev)
2523 2521
2524 /* name: Identifies the controller hardware type. */ 2522 /* name: Identifies the controller hardware type. */
2525 udc->gadget.name = driver_name; 2523 udc->gadget.name = driver_name;
2526
2527 device_initialize(&udc->gadget.dev);
2528
2529 dev_set_name(&udc->gadget.dev, "gadget");
2530
2531 udc->gadget.dev.release = qe_udc_release;
2532 udc->gadget.dev.parent = &ofdev->dev; 2524 udc->gadget.dev.parent = &ofdev->dev;
2533 2525
2534 /* initialize qe_ep struct */ 2526 /* initialize qe_ep struct */
@@ -2592,22 +2584,17 @@ static int qe_udc_probe(struct platform_device *ofdev)
2592 goto err5; 2584 goto err5;
2593 } 2585 }
2594 2586
2595 ret = device_add(&udc->gadget.dev); 2587 ret = usb_add_gadget_udc_release(&ofdev->dev, &udc->gadget,
2588 qe_udc_release);
2596 if (ret) 2589 if (ret)
2597 goto err6; 2590 goto err6;
2598 2591
2599 ret = usb_add_gadget_udc(&ofdev->dev, &udc->gadget);
2600 if (ret)
2601 goto err7;
2602
2603 dev_set_drvdata(&ofdev->dev, udc); 2592 dev_set_drvdata(&ofdev->dev, udc);
2604 dev_info(udc->dev, 2593 dev_info(udc->dev,
2605 "%s USB controller initialized as device\n", 2594 "%s USB controller initialized as device\n",
2606 (udc->soc_type == PORT_QE) ? "QE" : "CPM"); 2595 (udc->soc_type == PORT_QE) ? "QE" : "CPM");
2607 return 0; 2596 return 0;
2608 2597
2609err7:
2610 device_unregister(&udc->gadget.dev);
2611err6: 2598err6:
2612 free_irq(udc->usb_irq, udc); 2599 free_irq(udc->usb_irq, udc);
2613err5: 2600err5:
@@ -2702,7 +2689,6 @@ static int qe_udc_remove(struct platform_device *ofdev)
2702 2689
2703 iounmap(udc->usb_regs); 2690 iounmap(udc->usb_regs);
2704 2691
2705 device_unregister(&udc->gadget.dev);
2706 /* wait for release() of gadget.dev to free udc */ 2692 /* wait for release() of gadget.dev to free udc */
2707 wait_for_completion(&done); 2693 wait_for_completion(&done);
2708 2694
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 04d5fef1440c..7c2a101d19ac 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -185,20 +185,7 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
185 dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma); 185 dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
186 } 186 }
187 187
188 if (req->mapped) { 188 usb_gadget_unmap_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
189 dma_unmap_single(ep->udc->gadget.dev.parent,
190 req->req.dma, req->req.length,
191 ep_is_in(ep)
192 ? DMA_TO_DEVICE
193 : DMA_FROM_DEVICE);
194 req->req.dma = DMA_ADDR_INVALID;
195 req->mapped = 0;
196 } else
197 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
198 req->req.dma, req->req.length,
199 ep_is_in(ep)
200 ? DMA_TO_DEVICE
201 : DMA_FROM_DEVICE);
202 189
203 if (status && (status != -ESHUTDOWN)) 190 if (status && (status != -ESHUTDOWN))
204 VDBG("complete %s req %p stat %d len %u/%u", 191 VDBG("complete %s req %p stat %d len %u/%u",
@@ -888,6 +875,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
888 struct fsl_req *req = container_of(_req, struct fsl_req, req); 875 struct fsl_req *req = container_of(_req, struct fsl_req, req);
889 struct fsl_udc *udc; 876 struct fsl_udc *udc;
890 unsigned long flags; 877 unsigned long flags;
878 int ret;
891 879
892 /* catch various bogus parameters */ 880 /* catch various bogus parameters */
893 if (!_req || !req->req.complete || !req->req.buf 881 if (!_req || !req->req.complete || !req->req.buf
@@ -910,22 +898,9 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
910 898
911 req->ep = ep; 899 req->ep = ep;
912 900
913 /* map virtual address to hardware */ 901 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
914 if (req->req.dma == DMA_ADDR_INVALID) { 902 if (ret)
915 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 903 return ret;
916 req->req.buf,
917 req->req.length, ep_is_in(ep)
918 ? DMA_TO_DEVICE
919 : DMA_FROM_DEVICE);
920 req->mapped = 1;
921 } else {
922 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
923 req->req.dma, req->req.length,
924 ep_is_in(ep)
925 ? DMA_TO_DEVICE
926 : DMA_FROM_DEVICE);
927 req->mapped = 0;
928 }
929 904
930 req->req.status = -EINPROGRESS; 905 req->req.status = -EINPROGRESS;
931 req->req.actual = 0; 906 req->req.actual = 0;
@@ -1290,6 +1265,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1290{ 1265{
1291 struct fsl_req *req = udc->status_req; 1266 struct fsl_req *req = udc->status_req;
1292 struct fsl_ep *ep; 1267 struct fsl_ep *ep;
1268 int ret;
1293 1269
1294 if (direction == EP_DIR_IN) 1270 if (direction == EP_DIR_IN)
1295 udc->ep0_dir = USB_DIR_IN; 1271 udc->ep0_dir = USB_DIR_IN;
@@ -1307,10 +1283,9 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
1307 req->req.complete = NULL; 1283 req->req.complete = NULL;
1308 req->dtd_count = 0; 1284 req->dtd_count = 0;
1309 1285
1310 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 1286 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
1311 req->req.buf, req->req.length, 1287 if (ret)
1312 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1288 return ret;
1313 req->mapped = 1;
1314 1289
1315 if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0) 1290 if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
1316 fsl_queue_td(ep, req); 1291 fsl_queue_td(ep, req);
@@ -1353,6 +1328,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1353 u16 tmp = 0; /* Status, cpu endian */ 1328 u16 tmp = 0; /* Status, cpu endian */
1354 struct fsl_req *req; 1329 struct fsl_req *req;
1355 struct fsl_ep *ep; 1330 struct fsl_ep *ep;
1331 int ret;
1356 1332
1357 ep = &udc->eps[0]; 1333 ep = &udc->eps[0];
1358 1334
@@ -1390,10 +1366,9 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
1390 req->req.complete = NULL; 1366 req->req.complete = NULL;
1391 req->dtd_count = 0; 1367 req->dtd_count = 0;
1392 1368
1393 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 1369 ret = usb_gadget_map_request(&ep->udc->gadget, &req->req, ep_is_in(ep));
1394 req->req.buf, req->req.length, 1370 if (ret)
1395 ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE); 1371 goto stall;
1396 req->mapped = 1;
1397 1372
1398 /* prime the data phase */ 1373 /* prime the data phase */
1399 if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0)) 1374 if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
@@ -1964,7 +1939,6 @@ static int fsl_udc_start(struct usb_gadget *g,
1964 driver->driver.bus = NULL; 1939 driver->driver.bus = NULL;
1965 /* hook up the driver */ 1940 /* hook up the driver */
1966 udc_controller->driver = driver; 1941 udc_controller->driver = driver;
1967 udc_controller->gadget.dev.driver = &driver->driver;
1968 spin_unlock_irqrestore(&udc_controller->lock, flags); 1942 spin_unlock_irqrestore(&udc_controller->lock, flags);
1969 1943
1970 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) { 1944 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
@@ -1980,7 +1954,6 @@ static int fsl_udc_start(struct usb_gadget *g,
1980 if (retval < 0) { 1954 if (retval < 0) {
1981 ERR("can't bind to transceiver\n"); 1955 ERR("can't bind to transceiver\n");
1982 driver->unbind(&udc_controller->gadget); 1956 driver->unbind(&udc_controller->gadget);
1983 udc_controller->gadget.dev.driver = 0;
1984 udc_controller->driver = 0; 1957 udc_controller->driver = 0;
1985 return retval; 1958 return retval;
1986 } 1959 }
@@ -2023,7 +1996,6 @@ static int fsl_udc_stop(struct usb_gadget *g,
2023 nuke(loop_ep, -ESHUTDOWN); 1996 nuke(loop_ep, -ESHUTDOWN);
2024 spin_unlock_irqrestore(&udc_controller->lock, flags); 1997 spin_unlock_irqrestore(&udc_controller->lock, flags);
2025 1998
2026 udc_controller->gadget.dev.driver = NULL;
2027 udc_controller->driver = NULL; 1999 udc_controller->driver = NULL;
2028 2000
2029 return 0; 2001 return 0;
@@ -2521,12 +2493,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2521 2493
2522 /* Setup gadget.dev and register with kernel */ 2494 /* Setup gadget.dev and register with kernel */
2523 dev_set_name(&udc_controller->gadget.dev, "gadget"); 2495 dev_set_name(&udc_controller->gadget.dev, "gadget");
2524 udc_controller->gadget.dev.release = fsl_udc_release;
2525 udc_controller->gadget.dev.parent = &pdev->dev;
2526 udc_controller->gadget.dev.of_node = pdev->dev.of_node; 2496 udc_controller->gadget.dev.of_node = pdev->dev.of_node;
2527 ret = device_register(&udc_controller->gadget.dev);
2528 if (ret < 0)
2529 goto err_free_irq;
2530 2497
2531 if (!IS_ERR_OR_NULL(udc_controller->transceiver)) 2498 if (!IS_ERR_OR_NULL(udc_controller->transceiver))
2532 udc_controller->gadget.is_otg = 1; 2499 udc_controller->gadget.is_otg = 1;
@@ -2559,10 +2526,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2559 DTD_ALIGNMENT, UDC_DMA_BOUNDARY); 2526 DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
2560 if (udc_controller->td_pool == NULL) { 2527 if (udc_controller->td_pool == NULL) {
2561 ret = -ENOMEM; 2528 ret = -ENOMEM;
2562 goto err_unregister; 2529 goto err_free_irq;
2563 } 2530 }
2564 2531
2565 ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget); 2532 ret = usb_add_gadget_udc_release(&pdev->dev, &udc_controller->gadget,
2533 fsl_udc_release);
2566 if (ret) 2534 if (ret)
2567 goto err_del_udc; 2535 goto err_del_udc;
2568 2536
@@ -2571,8 +2539,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
2571 2539
2572err_del_udc: 2540err_del_udc:
2573 dma_pool_destroy(udc_controller->td_pool); 2541 dma_pool_destroy(udc_controller->td_pool);
2574err_unregister:
2575 device_unregister(&udc_controller->gadget.dev);
2576err_free_irq: 2542err_free_irq:
2577 free_irq(udc_controller->irq, udc_controller); 2543 free_irq(udc_controller->irq, udc_controller);
2578err_iounmap: 2544err_iounmap:
@@ -2622,7 +2588,6 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
2622 if (pdata->operating_mode == FSL_USB2_DR_DEVICE) 2588 if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
2623 release_mem_region(res->start, resource_size(res)); 2589 release_mem_region(res->start, resource_size(res));
2624 2590
2625 device_unregister(&udc_controller->gadget.dev);
2626 /* free udc --wait for the release() finished */ 2591 /* free udc --wait for the release() finished */
2627 wait_for_completion(&done); 2592 wait_for_completion(&done);
2628 2593
@@ -2747,21 +2712,7 @@ static struct platform_driver udc_driver = {
2747 }, 2712 },
2748}; 2713};
2749 2714
2750static int __init udc_init(void) 2715module_platform_driver_probe(udc_driver, fsl_udc_probe);
2751{
2752 printk(KERN_INFO "%s (%s)\n", driver_desc, DRIVER_VERSION);
2753 return platform_driver_probe(&udc_driver, fsl_udc_probe);
2754}
2755
2756module_init(udc_init);
2757
2758static void __exit udc_exit(void)
2759{
2760 platform_driver_unregister(&udc_driver);
2761 printk(KERN_WARNING "%s unregistered\n", driver_desc);
2762}
2763
2764module_exit(udc_exit);
2765 2716
2766MODULE_DESCRIPTION(DRIVER_DESC); 2717MODULE_DESCRIPTION(DRIVER_DESC);
2767MODULE_AUTHOR(DRIVER_AUTHOR); 2718MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index 066cb89376de..cec8871b77f9 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -394,7 +394,7 @@ static void fusb300_clear_epnstall(struct fusb300 *fusb300, u8 ep)
394 394
395 if (reg & FUSB300_EPSET0_STL) { 395 if (reg & FUSB300_EPSET0_STL) {
396 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep); 396 printk(KERN_DEBUG "EP%d stall... Clear!!\n", ep);
397 reg &= ~FUSB300_EPSET0_STL; 397 reg |= FUSB300_EPSET0_STL_CLR;
398 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep)); 398 iowrite32(reg, fusb300->reg + FUSB300_OFFSET_EPSET0(ep));
399 } 399 }
400} 400}
@@ -930,33 +930,33 @@ static void fusb300_wait_idma_finished(struct fusb300_ep *ep)
930 930
931 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0, 931 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGR0,
932 FUSB300_IGR0_EPn_PRD_INT(ep->epnum)); 932 FUSB300_IGR0_EPn_PRD_INT(ep->epnum));
933 return;
934
933IDMA_RESET: 935IDMA_RESET:
934 fusb300_clear_int(ep->fusb300, FUSB300_OFFSET_IGER0, 936 reg = ioread32(ep->fusb300->reg + FUSB300_OFFSET_IGER0);
935 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); 937 reg &= ~FUSB300_IGER0_EEPn_PRD_INT(ep->epnum);
938 iowrite32(reg, ep->fusb300->reg + FUSB300_OFFSET_IGER0);
936} 939}
937 940
938static void fusb300_set_idma(struct fusb300_ep *ep, 941static void fusb300_set_idma(struct fusb300_ep *ep,
939 struct fusb300_request *req) 942 struct fusb300_request *req)
940{ 943{
941 dma_addr_t d; 944 int ret;
942
943 d = dma_map_single(NULL, req->req.buf, req->req.length, DMA_TO_DEVICE);
944 945
945 if (dma_mapping_error(NULL, d)) { 946 ret = usb_gadget_map_request(&ep->fusb300->gadget,
946 printk(KERN_DEBUG "dma_mapping_error\n"); 947 &req->req, DMA_TO_DEVICE);
948 if (ret)
947 return; 949 return;
948 }
949
950 dma_sync_single_for_device(NULL, d, req->req.length, DMA_TO_DEVICE);
951 950
952 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0, 951 fusb300_enable_bit(ep->fusb300, FUSB300_OFFSET_IGER0,
953 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum)); 952 FUSB300_IGER0_EEPn_PRD_INT(ep->epnum));
954 953
955 fusb300_fill_idma_prdtbl(ep, d, req->req.length); 954 fusb300_fill_idma_prdtbl(ep, req->req.dma, req->req.length);
956 /* check idma is done */ 955 /* check idma is done */
957 fusb300_wait_idma_finished(ep); 956 fusb300_wait_idma_finished(ep);
958 957
959 dma_unmap_single(NULL, d, req->req.length, DMA_TO_DEVICE); 958 usb_gadget_unmap_request(&ep->fusb300->gadget,
959 &req->req, DMA_TO_DEVICE);
960} 960}
961 961
962static void in_ep_fifo_handler(struct fusb300_ep *ep) 962static void in_ep_fifo_handler(struct fusb300_ep *ep)
@@ -1316,7 +1316,6 @@ static int fusb300_udc_start(struct usb_gadget *g,
1316 /* hook up the driver */ 1316 /* hook up the driver */
1317 driver->driver.bus = NULL; 1317 driver->driver.bus = NULL;
1318 fusb300->driver = driver; 1318 fusb300->driver = driver;
1319 fusb300->gadget.dev.driver = &driver->driver;
1320 1319
1321 return 0; 1320 return 0;
1322} 1321}
@@ -1327,7 +1326,6 @@ static int fusb300_udc_stop(struct usb_gadget *g,
1327 struct fusb300 *fusb300 = to_fusb300(g); 1326 struct fusb300 *fusb300 = to_fusb300(g);
1328 1327
1329 driver->unbind(&fusb300->gadget); 1328 driver->unbind(&fusb300->gadget);
1330 fusb300->gadget.dev.driver = NULL;
1331 1329
1332 init_controller(fusb300); 1330 init_controller(fusb300);
1333 fusb300->driver = NULL; 1331 fusb300->driver = NULL;
@@ -1422,14 +1420,7 @@ static int __init fusb300_probe(struct platform_device *pdev)
1422 1420
1423 fusb300->gadget.ops = &fusb300_gadget_ops; 1421 fusb300->gadget.ops = &fusb300_gadget_ops;
1424 1422
1425 device_initialize(&fusb300->gadget.dev);
1426
1427 dev_set_name(&fusb300->gadget.dev, "gadget");
1428
1429 fusb300->gadget.max_speed = USB_SPEED_HIGH; 1423 fusb300->gadget.max_speed = USB_SPEED_HIGH;
1430 fusb300->gadget.dev.parent = &pdev->dev;
1431 fusb300->gadget.dev.dma_mask = pdev->dev.dma_mask;
1432 fusb300->gadget.dev.release = pdev->dev.release;
1433 fusb300->gadget.name = udc_name; 1424 fusb300->gadget.name = udc_name;
1434 fusb300->reg = reg; 1425 fusb300->reg = reg;
1435 1426
@@ -1478,19 +1469,10 @@ static int __init fusb300_probe(struct platform_device *pdev)
1478 if (ret) 1469 if (ret)
1479 goto err_add_udc; 1470 goto err_add_udc;
1480 1471
1481 ret = device_add(&fusb300->gadget.dev);
1482 if (ret) {
1483 pr_err("device_add error (%d)\n", ret);
1484 goto err_add_device;
1485 }
1486
1487 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION); 1472 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1488 1473
1489 return 0; 1474 return 0;
1490 1475
1491err_add_device:
1492 usb_del_gadget_udc(&fusb300->gadget);
1493
1494err_add_udc: 1476err_add_udc:
1495 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); 1477 fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req);
1496 1478
diff --git a/drivers/usb/gadget/fusb300_udc.h b/drivers/usb/gadget/fusb300_udc.h
index 6ba444ae8dd5..ae811d8d38b4 100644
--- a/drivers/usb/gadget/fusb300_udc.h
+++ b/drivers/usb/gadget/fusb300_udc.h
@@ -111,8 +111,8 @@
111/* 111/*
112 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 ) 112 * * EPn Setting 0 (EPn_SET0, offset = 020H+(n-1)*30H, n=1~15 )
113 * */ 113 * */
114#define FUSB300_EPSET0_STL_CLR (1 << 3)
114#define FUSB300_EPSET0_CLRSEQNUM (1 << 2) 115#define FUSB300_EPSET0_CLRSEQNUM (1 << 2)
115#define FUSB300_EPSET0_EPn_TX0BYTE (1 << 1)
116#define FUSB300_EPSET0_STL (1 << 0) 116#define FUSB300_EPSET0_STL (1 << 0)
117 117
118/* 118/*
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 3b343b23e4b0..787a78e92aa2 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -13,7 +13,6 @@
13#define pr_fmt(fmt) "g_ffs: " fmt 13#define pr_fmt(fmt) "g_ffs: " fmt
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16
17/* 16/*
18 * kbuild is not very cooperative with respect to linking separately 17 * kbuild is not very cooperative with respect to linking separately
19 * compiled library objects into one module. So for now we won't use 18 * compiled library objects into one module. So for now we won't use
@@ -38,13 +37,16 @@
38# include "u_ether.c" 37# include "u_ether.c"
39 38
40static u8 gfs_hostaddr[ETH_ALEN]; 39static u8 gfs_hostaddr[ETH_ALEN];
40static struct eth_dev *the_dev;
41# ifdef CONFIG_USB_FUNCTIONFS_ETH 41# ifdef CONFIG_USB_FUNCTIONFS_ETH
42static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 42static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
43 struct eth_dev *dev);
43# endif 44# endif
44#else 45#else
45# define gether_cleanup() do { } while (0) 46# define the_dev NULL
46# define gether_setup(gadget, hostaddr) ((int)0) 47# define gether_cleanup(dev) do { } while (0)
47# define gfs_hostaddr NULL 48# define gfs_hostaddr NULL
49struct eth_dev;
48#endif 50#endif
49 51
50#include "f_fs.c" 52#include "f_fs.c"
@@ -137,7 +139,8 @@ static struct usb_gadget_strings *gfs_dev_strings[] = {
137 139
138struct gfs_configuration { 140struct gfs_configuration {
139 struct usb_configuration c; 141 struct usb_configuration c;
140 int (*eth)(struct usb_configuration *c, u8 *ethaddr); 142 int (*eth)(struct usb_configuration *c, u8 *ethaddr,
143 struct eth_dev *dev);
141} gfs_configurations[] = { 144} gfs_configurations[] = {
142#ifdef CONFIG_USB_FUNCTIONFS_RNDIS 145#ifdef CONFIG_USB_FUNCTIONFS_RNDIS
143 { 146 {
@@ -346,10 +349,13 @@ static int gfs_bind(struct usb_composite_dev *cdev)
346 349
347 if (missing_funcs) 350 if (missing_funcs)
348 return -ENODEV; 351 return -ENODEV;
349 352#if defined CONFIG_USB_FUNCTIONFS_ETH || defined CONFIG_USB_FUNCTIONFS_RNDIS
350 ret = gether_setup(cdev->gadget, gfs_hostaddr); 353 the_dev = gether_setup(cdev->gadget, gfs_hostaddr);
351 if (unlikely(ret < 0)) 354#endif
355 if (IS_ERR(the_dev)) {
356 ret = PTR_ERR(the_dev);
352 goto error_quick; 357 goto error_quick;
358 }
353 gfs_ether_setup = true; 359 gfs_ether_setup = true;
354 360
355 ret = usb_string_ids_tab(cdev, gfs_strings); 361 ret = usb_string_ids_tab(cdev, gfs_strings);
@@ -386,7 +392,7 @@ error_unbind:
386 for (i = 0; i < func_num; i++) 392 for (i = 0; i < func_num; i++)
387 functionfs_unbind(ffs_tab[i].ffs_data); 393 functionfs_unbind(ffs_tab[i].ffs_data);
388error: 394error:
389 gether_cleanup(); 395 gether_cleanup(the_dev);
390error_quick: 396error_quick:
391 gfs_ether_setup = false; 397 gfs_ether_setup = false;
392 return ret; 398 return ret;
@@ -410,7 +416,7 @@ static int gfs_unbind(struct usb_composite_dev *cdev)
410 * do...? 416 * do...?
411 */ 417 */
412 if (gfs_ether_setup) 418 if (gfs_ether_setup)
413 gether_cleanup(); 419 gether_cleanup(the_dev);
414 gfs_ether_setup = false; 420 gfs_ether_setup = false;
415 421
416 for (i = func_num; i--; ) 422 for (i = func_num; i--; )
@@ -440,7 +446,7 @@ static int gfs_do_config(struct usb_configuration *c)
440 } 446 }
441 447
442 if (gc->eth) { 448 if (gc->eth) {
443 ret = gc->eth(c, gfs_hostaddr); 449 ret = gc->eth(c, gfs_hostaddr, the_dev);
444 if (unlikely(ret < 0)) 450 if (unlikely(ret < 0))
445 return ret; 451 return ret;
446 } 452 }
@@ -469,11 +475,12 @@ static int gfs_do_config(struct usb_configuration *c)
469 475
470#ifdef CONFIG_USB_FUNCTIONFS_ETH 476#ifdef CONFIG_USB_FUNCTIONFS_ETH
471 477
472static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]) 478static int eth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
479 struct eth_dev *dev)
473{ 480{
474 return can_support_ecm(c->cdev->gadget) 481 return can_support_ecm(c->cdev->gadget)
475 ? ecm_bind_config(c, ethaddr) 482 ? ecm_bind_config(c, ethaddr, dev)
476 : geth_bind_config(c, ethaddr); 483 : geth_bind_config(c, ethaddr, dev);
477} 484}
478 485
479#endif 486#endif
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 85742d4c67df..991aba390d9d 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -51,8 +51,6 @@
51#define DRIVER_DESC "TC86C001 USB Device Controller" 51#define DRIVER_DESC "TC86C001 USB Device Controller"
52#define DRIVER_VERSION "30-Oct 2003" 52#define DRIVER_VERSION "30-Oct 2003"
53 53
54#define DMA_ADDR_INVALID (~(dma_addr_t)0)
55
56static const char driver_name [] = "goku_udc"; 54static const char driver_name [] = "goku_udc";
57static const char driver_desc [] = DRIVER_DESC; 55static const char driver_desc [] = DRIVER_DESC;
58 56
@@ -275,7 +273,6 @@ goku_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
275 if (!req) 273 if (!req)
276 return NULL; 274 return NULL;
277 275
278 req->req.dma = DMA_ADDR_INVALID;
279 INIT_LIST_HEAD(&req->queue); 276 INIT_LIST_HEAD(&req->queue);
280 return &req->req; 277 return &req->req;
281} 278}
@@ -1354,7 +1351,6 @@ static int goku_udc_start(struct usb_gadget *g,
1354 /* hook up the driver */ 1351 /* hook up the driver */
1355 driver->driver.bus = NULL; 1352 driver->driver.bus = NULL;
1356 dev->driver = driver; 1353 dev->driver = driver;
1357 dev->gadget.dev.driver = &driver->driver;
1358 1354
1359 /* 1355 /*
1360 * then enable host detection and ep0; and we're ready 1356 * then enable host detection and ep0; and we're ready
@@ -1394,7 +1390,6 @@ static int goku_udc_stop(struct usb_gadget *g,
1394 dev->driver = NULL; 1390 dev->driver = NULL;
1395 stop_activity(dev, driver); 1391 stop_activity(dev, driver);
1396 spin_unlock_irqrestore(&dev->lock, flags); 1392 spin_unlock_irqrestore(&dev->lock, flags);
1397 dev->gadget.dev.driver = NULL;
1398 1393
1399 return 0; 1394 return 0;
1400} 1395}
@@ -1716,8 +1711,6 @@ static void goku_remove(struct pci_dev *pdev)
1716 pci_resource_len (pdev, 0)); 1711 pci_resource_len (pdev, 0));
1717 if (dev->enabled) 1712 if (dev->enabled)
1718 pci_disable_device(pdev); 1713 pci_disable_device(pdev);
1719 if (dev->registered)
1720 device_unregister(&dev->gadget.dev);
1721 1714
1722 pci_set_drvdata(pdev, NULL); 1715 pci_set_drvdata(pdev, NULL);
1723 dev->regs = NULL; 1716 dev->regs = NULL;
@@ -1756,10 +1749,6 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1756 dev->gadget.max_speed = USB_SPEED_FULL; 1749 dev->gadget.max_speed = USB_SPEED_FULL;
1757 1750
1758 /* the "gadget" abstracts/virtualizes the controller */ 1751 /* the "gadget" abstracts/virtualizes the controller */
1759 dev_set_name(&dev->gadget.dev, "gadget");
1760 dev->gadget.dev.parent = &pdev->dev;
1761 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
1762 dev->gadget.dev.release = gadget_release;
1763 dev->gadget.name = driver_name; 1752 dev->gadget.name = driver_name;
1764 1753
1765 /* now all the pci goodies ... */ 1754 /* now all the pci goodies ... */
@@ -1810,13 +1799,8 @@ static int goku_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1810 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev); 1799 create_proc_read_entry(proc_node_name, 0, NULL, udc_proc_read, dev);
1811#endif 1800#endif
1812 1801
1813 retval = device_register(&dev->gadget.dev); 1802 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
1814 if (retval) { 1803 gadget_release);
1815 put_device(&dev->gadget.dev);
1816 goto err;
1817 }
1818 dev->registered = 1;
1819 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget);
1820 if (retval) 1804 if (retval)
1821 goto err; 1805 goto err;
1822 1806
diff --git a/drivers/usb/gadget/goku_udc.h b/drivers/usb/gadget/goku_udc.h
index b4470d2b1d86..86d2adafe149 100644
--- a/drivers/usb/gadget/goku_udc.h
+++ b/drivers/usb/gadget/goku_udc.h
@@ -250,8 +250,7 @@ struct goku_udc {
250 got_region:1, 250 got_region:1,
251 req_config:1, 251 req_config:1,
252 configured:1, 252 configured:1,
253 enabled:1, 253 enabled:1;
254 registered:1;
255 254
256 /* pci state used to access those endpoints */ 255 /* pci state used to access those endpoints */
257 struct pci_dev *pdev; 256 struct pci_dev *pdev;
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 5bd930d779b9..b5cebd6b0d7a 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1338,7 +1338,6 @@ static int imx_udc_start(struct usb_gadget *gadget,
1338 imx_usb = container_of(gadget, struct imx_udc_struct, gadget); 1338 imx_usb = container_of(gadget, struct imx_udc_struct, gadget);
1339 /* first hook up the driver ... */ 1339 /* first hook up the driver ... */
1340 imx_usb->driver = driver; 1340 imx_usb->driver = driver;
1341 imx_usb->gadget.dev.driver = &driver->driver;
1342 1341
1343 D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n", 1342 D_INI(imx_usb->dev, "<%s> registered gadget driver '%s'\n",
1344 __func__, driver->driver.name); 1343 __func__, driver->driver.name);
@@ -1358,7 +1357,6 @@ static int imx_udc_stop(struct usb_gadget *gadget,
1358 imx_udc_disable(imx_usb); 1357 imx_udc_disable(imx_usb);
1359 del_timer(&imx_usb->timer); 1358 del_timer(&imx_usb->timer);
1360 1359
1361 imx_usb->gadget.dev.driver = NULL;
1362 imx_usb->driver = NULL; 1360 imx_usb->driver = NULL;
1363 1361
1364 D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n", 1362 D_INI(imx_usb->dev, "<%s> unregistered gadget driver '%s'\n",
@@ -1461,15 +1459,6 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1461 imx_usb->clk = clk; 1459 imx_usb->clk = clk;
1462 imx_usb->dev = &pdev->dev; 1460 imx_usb->dev = &pdev->dev;
1463 1461
1464 device_initialize(&imx_usb->gadget.dev);
1465
1466 imx_usb->gadget.dev.parent = &pdev->dev;
1467 imx_usb->gadget.dev.dma_mask = pdev->dev.dma_mask;
1468
1469 ret = device_add(&imx_usb->gadget.dev);
1470 if (retval)
1471 goto fail4;
1472
1473 platform_set_drvdata(pdev, imx_usb); 1462 platform_set_drvdata(pdev, imx_usb);
1474 1463
1475 usb_init_data(imx_usb); 1464 usb_init_data(imx_usb);
@@ -1481,11 +1470,9 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1481 1470
1482 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget); 1471 ret = usb_add_gadget_udc(&pdev->dev, &imx_usb->gadget);
1483 if (ret) 1472 if (ret)
1484 goto fail5; 1473 goto fail4;
1485 1474
1486 return 0; 1475 return 0;
1487fail5:
1488 device_unregister(&imx_usb->gadget.dev);
1489fail4: 1476fail4:
1490 for (i = 0; i < IMX_USB_NB_EP + 1; i++) 1477 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1491 free_irq(imx_usb->usbd_int[i], imx_usb); 1478 free_irq(imx_usb->usbd_int[i], imx_usb);
@@ -1509,7 +1496,6 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1509 int i; 1496 int i;
1510 1497
1511 usb_del_gadget_udc(&imx_usb->gadget); 1498 usb_del_gadget_udc(&imx_usb->gadget);
1512 device_unregister(&imx_usb->gadget.dev);
1513 imx_udc_disable(imx_usb); 1499 imx_udc_disable(imx_usb);
1514 del_timer(&imx_usb->timer); 1500 del_timer(&imx_usb->timer);
1515 1501
diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index aa04089d6899..b943d8cdfbf7 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -1469,23 +1469,7 @@ static void done(struct lpc32xx_ep *ep, struct lpc32xx_request *req, int status)
1469 status = req->req.status; 1469 status = req->req.status;
1470 1470
1471 if (ep->lep) { 1471 if (ep->lep) {
1472 enum dma_data_direction direction; 1472 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in);
1473
1474 if (ep->is_in)
1475 direction = DMA_TO_DEVICE;
1476 else
1477 direction = DMA_FROM_DEVICE;
1478
1479 if (req->mapped) {
1480 dma_unmap_single(ep->udc->gadget.dev.parent,
1481 req->req.dma, req->req.length,
1482 direction);
1483 req->req.dma = 0;
1484 req->mapped = 0;
1485 } else
1486 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
1487 req->req.dma, req->req.length,
1488 direction);
1489 1473
1490 /* Free DDs */ 1474 /* Free DDs */
1491 udc_dd_free(udc, req->dd_desc_ptr); 1475 udc_dd_free(udc, req->dd_desc_ptr);
@@ -1841,26 +1825,11 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep,
1841 } 1825 }
1842 1826
1843 if (ep->lep) { 1827 if (ep->lep) {
1844 enum dma_data_direction direction;
1845 struct lpc32xx_usbd_dd_gad *dd; 1828 struct lpc32xx_usbd_dd_gad *dd;
1846 1829
1847 /* Map DMA pointer */ 1830 status = usb_gadget_map_request(&udc->gadget, _req, ep->is_in);
1848 if (ep->is_in) 1831 if (status)
1849 direction = DMA_TO_DEVICE; 1832 return status;
1850 else
1851 direction = DMA_FROM_DEVICE;
1852
1853 if (req->req.dma == 0) {
1854 req->req.dma = dma_map_single(
1855 ep->udc->gadget.dev.parent,
1856 req->req.buf, req->req.length, direction);
1857 req->mapped = 1;
1858 } else {
1859 dma_sync_single_for_device(
1860 ep->udc->gadget.dev.parent, req->req.dma,
1861 req->req.length, direction);
1862 req->mapped = 0;
1863 }
1864 1833
1865 /* For the request, build a list of DDs */ 1834 /* For the request, build a list of DDs */
1866 dd = udc_dd_alloc(udc); 1835 dd = udc_dd_alloc(udc);
@@ -2977,7 +2946,6 @@ static int lpc32xx_start(struct usb_gadget *gadget,
2977 } 2946 }
2978 2947
2979 udc->driver = driver; 2948 udc->driver = driver;
2980 udc->gadget.dev.driver = &driver->driver;
2981 udc->gadget.dev.of_node = udc->dev->of_node; 2949 udc->gadget.dev.of_node = udc->dev->of_node;
2982 udc->enabled = 1; 2950 udc->enabled = 1;
2983 udc->selfpowered = 1; 2951 udc->selfpowered = 1;
@@ -3026,7 +2994,6 @@ static int lpc32xx_stop(struct usb_gadget *gadget,
3026 } 2994 }
3027 2995
3028 udc->enabled = 0; 2996 udc->enabled = 0;
3029 udc->gadget.dev.driver = NULL;
3030 udc->driver = NULL; 2997 udc->driver = NULL;
3031 2998
3032 return 0; 2999 return 0;
@@ -3248,12 +3215,6 @@ static int __init lpc32xx_udc_probe(struct platform_device *pdev)
3248 udc_disable(udc); 3215 udc_disable(udc);
3249 udc_reinit(udc); 3216 udc_reinit(udc);
3250 3217
3251 retval = device_register(&udc->gadget.dev);
3252 if (retval < 0) {
3253 dev_err(udc->dev, "Device registration failure\n");
3254 goto dev_register_fail;
3255 }
3256
3257 /* Request IRQs - low and high priority USB device IRQs are routed to 3218 /* Request IRQs - low and high priority USB device IRQs are routed to
3258 * the same handler, while the DMA interrupt is routed elsewhere */ 3219 * the same handler, while the DMA interrupt is routed elsewhere */
3259 retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq, 3220 retval = request_irq(udc->udp_irq[IRQ_USB_LP], lpc32xx_usb_lp_irq,
@@ -3320,8 +3281,6 @@ irq_dev_fail:
3320irq_hp_fail: 3281irq_hp_fail:
3321 free_irq(udc->udp_irq[IRQ_USB_LP], udc); 3282 free_irq(udc->udp_irq[IRQ_USB_LP], udc);
3322irq_lp_fail: 3283irq_lp_fail:
3323 device_unregister(&udc->gadget.dev);
3324dev_register_fail:
3325 dma_pool_destroy(udc->dd_cache); 3284 dma_pool_destroy(udc->dd_cache);
3326dma_alloc_fail: 3285dma_alloc_fail:
3327 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, 3286 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE,
@@ -3376,8 +3335,6 @@ static int lpc32xx_udc_remove(struct platform_device *pdev)
3376 free_irq(udc->udp_irq[IRQ_USB_HP], udc); 3335 free_irq(udc->udp_irq[IRQ_USB_HP], udc);
3377 free_irq(udc->udp_irq[IRQ_USB_LP], udc); 3336 free_irq(udc->udp_irq[IRQ_USB_LP], udc);
3378 3337
3379 device_unregister(&udc->gadget.dev);
3380
3381 clk_disable(udc->usb_otg_clk); 3338 clk_disable(udc->usb_otg_clk);
3382 clk_put(udc->usb_otg_clk); 3339 clk_put(udc->usb_otg_clk);
3383 clk_disable(udc->usb_slv_clk); 3340 clk_disable(udc->usb_slv_clk);
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index c1b8c2dd808d..866ef0999247 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -1471,7 +1471,6 @@ static int m66592_udc_start(struct usb_gadget *g,
1471 /* hook up the driver */ 1471 /* hook up the driver */
1472 driver->driver.bus = NULL; 1472 driver->driver.bus = NULL;
1473 m66592->driver = driver; 1473 m66592->driver = driver;
1474 m66592->gadget.dev.driver = &driver->driver;
1475 1474
1476 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1475 m66592_bset(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1477 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) { 1476 if (m66592_read(m66592, M66592_INTSTS0) & M66592_VBSTS) {
@@ -1494,7 +1493,6 @@ static int m66592_udc_stop(struct usb_gadget *g,
1494 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0); 1493 m66592_bclr(m66592, M66592_VBSE | M66592_URST, M66592_INTENB0);
1495 1494
1496 driver->unbind(&m66592->gadget); 1495 driver->unbind(&m66592->gadget);
1497 m66592->gadget.dev.driver = NULL;
1498 1496
1499 init_controller(m66592); 1497 init_controller(m66592);
1500 disable_controller(m66592); 1498 disable_controller(m66592);
@@ -1538,7 +1536,6 @@ static int __exit m66592_remove(struct platform_device *pdev)
1538 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1536 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1539 1537
1540 usb_del_gadget_udc(&m66592->gadget); 1538 usb_del_gadget_udc(&m66592->gadget);
1541 device_del(&m66592->gadget.dev);
1542 1539
1543 del_timer_sync(&m66592->timer); 1540 del_timer_sync(&m66592->timer);
1544 iounmap(m66592->reg); 1541 iounmap(m66592->reg);
@@ -1608,12 +1605,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1608 dev_set_drvdata(&pdev->dev, m66592); 1605 dev_set_drvdata(&pdev->dev, m66592);
1609 1606
1610 m66592->gadget.ops = &m66592_gadget_ops; 1607 m66592->gadget.ops = &m66592_gadget_ops;
1611 device_initialize(&m66592->gadget.dev);
1612 dev_set_name(&m66592->gadget.dev, "gadget");
1613 m66592->gadget.max_speed = USB_SPEED_HIGH; 1608 m66592->gadget.max_speed = USB_SPEED_HIGH;
1614 m66592->gadget.dev.parent = &pdev->dev;
1615 m66592->gadget.dev.dma_mask = pdev->dev.dma_mask;
1616 m66592->gadget.dev.release = pdev->dev.release;
1617 m66592->gadget.name = udc_name; 1609 m66592->gadget.name = udc_name;
1618 1610
1619 init_timer(&m66592->timer); 1611 init_timer(&m66592->timer);
@@ -1674,12 +1666,6 @@ static int __init m66592_probe(struct platform_device *pdev)
1674 1666
1675 init_controller(m66592); 1667 init_controller(m66592);
1676 1668
1677 ret = device_add(&m66592->gadget.dev);
1678 if (ret) {
1679 pr_err("device_add error (%d)\n", ret);
1680 goto err_device_add;
1681 }
1682
1683 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget); 1669 ret = usb_add_gadget_udc(&pdev->dev, &m66592->gadget);
1684 if (ret) 1670 if (ret)
1685 goto err_add_udc; 1671 goto err_add_udc;
@@ -1688,9 +1674,6 @@ static int __init m66592_probe(struct platform_device *pdev)
1688 return 0; 1674 return 0;
1689 1675
1690err_add_udc: 1676err_add_udc:
1691 device_del(&m66592->gadget.dev);
1692
1693err_device_add:
1694 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req); 1677 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1695 1678
1696clean_up3: 1679clean_up3:
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 20bbbf917fc2..4a45e80c6e38 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -135,8 +135,8 @@ static struct fsg_common fsg_common;
135 135
136static u8 hostaddr[ETH_ALEN]; 136static u8 hostaddr[ETH_ALEN];
137 137
138static unsigned char tty_line;
139static struct usb_function_instance *fi_acm; 138static struct usb_function_instance *fi_acm;
139static struct eth_dev *the_dev;
140 140
141/********** RNDIS **********/ 141/********** RNDIS **********/
142 142
@@ -152,13 +152,15 @@ static __init int rndis_do_config(struct usb_configuration *c)
152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 152 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
153 } 153 }
154 154
155 ret = rndis_bind_config(c, hostaddr); 155 ret = rndis_bind_config(c, hostaddr, the_dev);
156 if (ret < 0) 156 if (ret < 0)
157 return ret; 157 return ret;
158 158
159 f_acm_rndis = usb_get_function(fi_acm); 159 f_acm_rndis = usb_get_function(fi_acm);
160 if (IS_ERR(f_acm_rndis)) 160 if (IS_ERR(f_acm_rndis)) {
161 ret = PTR_ERR(f_acm_rndis);
161 goto err_func_acm; 162 goto err_func_acm;
163 }
162 164
163 ret = usb_add_function(c, f_acm_rndis); 165 ret = usb_add_function(c, f_acm_rndis);
164 if (ret) 166 if (ret)
@@ -214,7 +216,7 @@ static __init int cdc_do_config(struct usb_configuration *c)
214 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 216 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
215 } 217 }
216 218
217 ret = ecm_bind_config(c, hostaddr); 219 ret = ecm_bind_config(c, hostaddr, the_dev);
218 if (ret < 0) 220 if (ret < 0)
219 return ret; 221 return ret;
220 222
@@ -269,7 +271,6 @@ static int cdc_config_register(struct usb_composite_dev *cdev)
269static int __ref multi_bind(struct usb_composite_dev *cdev) 271static int __ref multi_bind(struct usb_composite_dev *cdev)
270{ 272{
271 struct usb_gadget *gadget = cdev->gadget; 273 struct usb_gadget *gadget = cdev->gadget;
272 struct f_serial_opts *opts;
273 int status; 274 int status;
274 275
275 if (!can_support_ecm(cdev->gadget)) { 276 if (!can_support_ecm(cdev->gadget)) {
@@ -279,24 +280,17 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
279 } 280 }
280 281
281 /* set up network link layer */ 282 /* set up network link layer */
282 status = gether_setup(cdev->gadget, hostaddr); 283 the_dev = gether_setup(cdev->gadget, hostaddr);
283 if (status < 0) 284 if (IS_ERR(the_dev))
284 return status; 285 return PTR_ERR(the_dev);
285 286
286 /* set up serial link layer */ 287 /* set up serial link layer */
287 status = gserial_alloc_line(&tty_line);
288 if (status < 0)
289 goto fail0;
290
291 fi_acm = usb_get_function_instance("acm"); 288 fi_acm = usb_get_function_instance("acm");
292 if (IS_ERR(fi_acm)) { 289 if (IS_ERR(fi_acm)) {
293 status = PTR_ERR(fi_acm); 290 status = PTR_ERR(fi_acm);
294 goto fail0dot5; 291 goto fail0;
295 } 292 }
296 293
297 opts = container_of(fi_acm, struct f_serial_opts, func_inst);
298 opts->port_num = tty_line;
299
300 /* set up mass storage function */ 294 /* set up mass storage function */
301 { 295 {
302 void *retp; 296 void *retp;
@@ -334,10 +328,8 @@ fail2:
334 fsg_common_put(&fsg_common); 328 fsg_common_put(&fsg_common);
335fail1: 329fail1:
336 usb_put_function_instance(fi_acm); 330 usb_put_function_instance(fi_acm);
337fail0dot5:
338 gserial_free_line(tty_line);
339fail0: 331fail0:
340 gether_cleanup(); 332 gether_cleanup(the_dev);
341 return status; 333 return status;
342} 334}
343 335
@@ -350,8 +342,7 @@ static int __exit multi_unbind(struct usb_composite_dev *cdev)
350 usb_put_function(f_acm_rndis); 342 usb_put_function(f_acm_rndis);
351#endif 343#endif
352 usb_put_function_instance(fi_acm); 344 usb_put_function_instance(fi_acm);
353 gserial_free_line(tty_line); 345 gether_cleanup(the_dev);
354 gether_cleanup();
355 return 0; 346 return 0;
356} 347}
357 348
diff --git a/drivers/usb/gadget/mv_u3d_core.c b/drivers/usb/gadget/mv_u3d_core.c
index b5cea273c957..58288e9cf728 100644
--- a/drivers/usb/gadget/mv_u3d_core.c
+++ b/drivers/usb/gadget/mv_u3d_core.c
@@ -30,9 +30,6 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/platform_data/mv_usb.h> 31#include <linux/platform_data/mv_usb.h>
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <asm/system.h>
34#include <asm/unaligned.h>
35#include <asm/byteorder.h>
36 33
37#include "mv_u3d.h" 34#include "mv_u3d.h"
38 35
@@ -125,7 +122,7 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index,
125 struct mv_u3d_trb *curr_trb; 122 struct mv_u3d_trb *curr_trb;
126 dma_addr_t cur_deq_lo; 123 dma_addr_t cur_deq_lo;
127 struct mv_u3d_ep_context *curr_ep_context; 124 struct mv_u3d_ep_context *curr_ep_context;
128 int trb_complete, actual, remaining_length; 125 int trb_complete, actual, remaining_length = 0;
129 int direction, ep_num; 126 int direction, ep_num;
130 int retval = 0; 127 int retval = 0;
131 u32 tmp, status, length; 128 u32 tmp, status, length;
@@ -189,6 +186,8 @@ static int mv_u3d_process_ep_req(struct mv_u3d *u3d, int index,
189 */ 186 */
190static 187static
191void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status) 188void mv_u3d_done(struct mv_u3d_ep *ep, struct mv_u3d_req *req, int status)
189 __releases(&ep->udc->lock)
190 __acquires(&ep->udc->lock)
192{ 191{
193 struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d; 192 struct mv_u3d *u3d = (struct mv_u3d *)ep->u3d;
194 193
@@ -812,19 +811,19 @@ mv_u3d_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
812 return 0; 811 return 0;
813 } 812 }
814 813
815 dev_dbg(u3d->dev, "%s: %s, req: 0x%x\n", 814 dev_dbg(u3d->dev, "%s: %s, req: 0x%p\n",
816 __func__, _ep->name, (u32)req); 815 __func__, _ep->name, req);
817 816
818 /* catch various bogus parameters */ 817 /* catch various bogus parameters */
819 if (!req->req.complete || !req->req.buf 818 if (!req->req.complete || !req->req.buf
820 || !list_empty(&req->queue)) { 819 || !list_empty(&req->queue)) {
821 dev_err(u3d->dev, 820 dev_err(u3d->dev,
822 "%s, bad params, _req: 0x%x," 821 "%s, bad params, _req: 0x%p,"
823 "req->req.complete: 0x%x, req->req.buf: 0x%x," 822 "req->req.complete: 0x%p, req->req.buf: 0x%p,"
824 "list_empty: 0x%x\n", 823 "list_empty: 0x%x\n",
825 __func__, (u32)_req, 824 __func__, _req,
826 (u32)req->req.complete, (u32)req->req.buf, 825 req->req.complete, req->req.buf,
827 (u32)list_empty(&req->queue)); 826 list_empty(&req->queue));
828 return -EINVAL; 827 return -EINVAL;
829 } 828 }
830 if (unlikely(!ep->ep.desc)) { 829 if (unlikely(!ep->ep.desc)) {
@@ -905,7 +904,7 @@ static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
905 struct mv_u3d_req, queue); 904 struct mv_u3d_req, queue);
906 905
907 /* Point first TRB of next request to the EP context. */ 906 /* Point first TRB of next request to the EP context. */
908 iowrite32((u32) next_req->trb_head, 907 iowrite32((unsigned long) next_req->trb_head,
909 &ep_context->trb_addr_lo); 908 &ep_context->trb_addr_lo);
910 } else { 909 } else {
911 struct mv_u3d_ep_context *ep_context; 910 struct mv_u3d_ep_context *ep_context;
@@ -1264,7 +1263,6 @@ static int mv_u3d_start(struct usb_gadget *g,
1264 /* hook up the driver ... */ 1263 /* hook up the driver ... */
1265 driver->driver.bus = NULL; 1264 driver->driver.bus = NULL;
1266 u3d->driver = driver; 1265 u3d->driver = driver;
1267 u3d->gadget.dev.driver = &driver->driver;
1268 1266
1269 u3d->ep0_dir = USB_DIR_OUT; 1267 u3d->ep0_dir = USB_DIR_OUT;
1270 1268
@@ -1302,7 +1300,6 @@ static int mv_u3d_stop(struct usb_gadget *g,
1302 1300
1303 spin_unlock_irqrestore(&u3d->lock, flags); 1301 spin_unlock_irqrestore(&u3d->lock, flags);
1304 1302
1305 u3d->gadget.dev.driver = NULL;
1306 u3d->driver = NULL; 1303 u3d->driver = NULL;
1307 1304
1308 return 0; 1305 return 0;
@@ -1525,6 +1522,8 @@ static int mv_u3d_is_set_configuration(struct usb_ctrlrequest *setup)
1525 1522
1526static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num, 1523static void mv_u3d_handle_setup_packet(struct mv_u3d *u3d, u8 ep_num,
1527 struct usb_ctrlrequest *setup) 1524 struct usb_ctrlrequest *setup)
1525 __releases(&u3c->lock)
1526 __acquires(&u3c->lock)
1528{ 1527{
1529 bool delegate = false; 1528 bool delegate = false;
1530 1529
@@ -1758,11 +1757,6 @@ static irqreturn_t mv_u3d_irq(int irq, void *dev)
1758 return IRQ_HANDLED; 1757 return IRQ_HANDLED;
1759} 1758}
1760 1759
1761static void mv_u3d_gadget_release(struct device *dev)
1762{
1763 dev_dbg(dev, "%s\n", __func__);
1764}
1765
1766static int mv_u3d_remove(struct platform_device *dev) 1760static int mv_u3d_remove(struct platform_device *dev)
1767{ 1761{
1768 struct mv_u3d *u3d = platform_get_drvdata(dev); 1762 struct mv_u3d *u3d = platform_get_drvdata(dev);
@@ -1792,8 +1786,6 @@ static int mv_u3d_remove(struct platform_device *dev)
1792 1786
1793 clk_put(u3d->clk); 1787 clk_put(u3d->clk);
1794 1788
1795 device_unregister(&u3d->gadget.dev);
1796
1797 platform_set_drvdata(dev, NULL); 1789 platform_set_drvdata(dev, NULL);
1798 1790
1799 kfree(u3d); 1791 kfree(u3d);
@@ -1829,7 +1821,7 @@ static int mv_u3d_probe(struct platform_device *dev)
1829 u3d->dev = &dev->dev; 1821 u3d->dev = &dev->dev;
1830 u3d->vbus = pdata->vbus; 1822 u3d->vbus = pdata->vbus;
1831 1823
1832 u3d->clk = clk_get(&dev->dev, pdata->clkname[0]); 1824 u3d->clk = clk_get(&dev->dev, NULL);
1833 if (IS_ERR(u3d->clk)) { 1825 if (IS_ERR(u3d->clk)) {
1834 retval = PTR_ERR(u3d->clk); 1826 retval = PTR_ERR(u3d->clk);
1835 goto err_get_clk; 1827 goto err_get_clk;
@@ -1849,8 +1841,9 @@ static int mv_u3d_probe(struct platform_device *dev)
1849 retval = -EBUSY; 1841 retval = -EBUSY;
1850 goto err_map_cap_regs; 1842 goto err_map_cap_regs;
1851 } else { 1843 } else {
1852 dev_dbg(&dev->dev, "cap_regs address: 0x%x/0x%x\n", 1844 dev_dbg(&dev->dev, "cap_regs address: 0x%lx/0x%lx\n",
1853 (unsigned int)r->start, (unsigned int)u3d->cap_regs); 1845 (unsigned long) r->start,
1846 (unsigned long) u3d->cap_regs);
1854 } 1847 }
1855 1848
1856 /* we will access controller register, so enable the u3d controller */ 1849 /* we will access controller register, so enable the u3d controller */
@@ -1864,10 +1857,10 @@ static int mv_u3d_probe(struct platform_device *dev)
1864 } 1857 }
1865 } 1858 }
1866 1859
1867 u3d->op_regs = (struct mv_u3d_op_regs __iomem *)((u32)u3d->cap_regs 1860 u3d->op_regs = (struct mv_u3d_op_regs __iomem *)(u3d->cap_regs
1868 + MV_U3D_USB3_OP_REGS_OFFSET); 1861 + MV_U3D_USB3_OP_REGS_OFFSET);
1869 1862
1870 u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)((u32)u3d->cap_regs 1863 u3d->vuc_regs = (struct mv_u3d_vuc_regs __iomem *)(u3d->cap_regs
1871 + ioread32(&u3d->cap_regs->vuoff)); 1864 + ioread32(&u3d->cap_regs->vuoff));
1872 1865
1873 u3d->max_eps = 16; 1866 u3d->max_eps = 16;
@@ -1957,16 +1950,8 @@ static int mv_u3d_probe(struct platform_device *dev)
1957 u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */ 1950 u3d->gadget.speed = USB_SPEED_UNKNOWN; /* speed */
1958 1951
1959 /* the "gadget" abstracts/virtualizes the controller */ 1952 /* the "gadget" abstracts/virtualizes the controller */
1960 dev_set_name(&u3d->gadget.dev, "gadget");
1961 u3d->gadget.dev.parent = &dev->dev;
1962 u3d->gadget.dev.dma_mask = dev->dev.dma_mask;
1963 u3d->gadget.dev.release = mv_u3d_gadget_release;
1964 u3d->gadget.name = driver_name; /* gadget name */ 1953 u3d->gadget.name = driver_name; /* gadget name */
1965 1954
1966 retval = device_register(&u3d->gadget.dev);
1967 if (retval)
1968 goto err_register_gadget_device;
1969
1970 mv_u3d_eps_init(u3d); 1955 mv_u3d_eps_init(u3d);
1971 1956
1972 /* external vbus detection */ 1957 /* external vbus detection */
@@ -1991,8 +1976,6 @@ static int mv_u3d_probe(struct platform_device *dev)
1991 return 0; 1976 return 0;
1992 1977
1993err_unregister: 1978err_unregister:
1994 device_unregister(&u3d->gadget.dev);
1995err_register_gadget_device:
1996 free_irq(u3d->irq, &dev->dev); 1979 free_irq(u3d->irq, &dev->dev);
1997err_request_irq: 1980err_request_irq:
1998err_get_irq: 1981err_get_irq:
@@ -2021,7 +2004,7 @@ err_pdata:
2021 return retval; 2004 return retval;
2022} 2005}
2023 2006
2024#ifdef CONFIG_PM 2007#ifdef CONFIG_PM_SLEEP
2025static int mv_u3d_suspend(struct device *dev) 2008static int mv_u3d_suspend(struct device *dev)
2026{ 2009{
2027 struct mv_u3d *u3d = dev_get_drvdata(dev); 2010 struct mv_u3d *u3d = dev_get_drvdata(dev);
@@ -2064,10 +2047,10 @@ static int mv_u3d_resume(struct device *dev)
2064 2047
2065 return 0; 2048 return 0;
2066} 2049}
2067
2068SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume);
2069#endif 2050#endif
2070 2051
2052static SIMPLE_DEV_PM_OPS(mv_u3d_pm_ops, mv_u3d_suspend, mv_u3d_resume);
2053
2071static void mv_u3d_shutdown(struct platform_device *dev) 2054static void mv_u3d_shutdown(struct platform_device *dev)
2072{ 2055{
2073 struct mv_u3d *u3d = dev_get_drvdata(&dev->dev); 2056 struct mv_u3d *u3d = dev_get_drvdata(&dev->dev);
@@ -2080,14 +2063,12 @@ static void mv_u3d_shutdown(struct platform_device *dev)
2080 2063
2081static struct platform_driver mv_u3d_driver = { 2064static struct platform_driver mv_u3d_driver = {
2082 .probe = mv_u3d_probe, 2065 .probe = mv_u3d_probe,
2083 .remove = __exit_p(mv_u3d_remove), 2066 .remove = mv_u3d_remove,
2084 .shutdown = mv_u3d_shutdown, 2067 .shutdown = mv_u3d_shutdown,
2085 .driver = { 2068 .driver = {
2086 .owner = THIS_MODULE, 2069 .owner = THIS_MODULE,
2087 .name = "mv-u3d", 2070 .name = "mv-u3d",
2088#ifdef CONFIG_PM
2089 .pm = &mv_u3d_pm_ops, 2071 .pm = &mv_u3d_pm_ops,
2090#endif
2091 }, 2072 },
2092}; 2073};
2093 2074
diff --git a/drivers/usb/gadget/mv_udc.h b/drivers/usb/gadget/mv_udc.h
index 9073436d8b24..be77f207dbaf 100644
--- a/drivers/usb/gadget/mv_udc.h
+++ b/drivers/usb/gadget/mv_udc.h
@@ -222,8 +222,7 @@ struct mv_udc {
222 struct mv_usb_platform_data *pdata; 222 struct mv_usb_platform_data *pdata;
223 223
224 /* some SOC has mutiple clock sources for USB*/ 224 /* some SOC has mutiple clock sources for USB*/
225 unsigned int clknum; 225 struct clk *clk;
226 struct clk *clk[0];
227}; 226};
228 227
229/* endpoint data structure */ 228/* endpoint data structure */
diff --git a/drivers/usb/gadget/mv_udc_core.c b/drivers/usb/gadget/mv_udc_core.c
index c8cf959057fe..c2a57023e467 100644
--- a/drivers/usb/gadget/mv_udc_core.c
+++ b/drivers/usb/gadget/mv_udc_core.c
@@ -212,6 +212,8 @@ static int process_ep_req(struct mv_udc *udc, int index,
212 * request is still in progress. 212 * request is still in progress.
213 */ 213 */
214static void done(struct mv_ep *ep, struct mv_req *req, int status) 214static void done(struct mv_ep *ep, struct mv_req *req, int status)
215 __releases(&ep->udc->lock)
216 __acquires(&ep->udc->lock)
215{ 217{
216 struct mv_udc *udc = NULL; 218 struct mv_udc *udc = NULL;
217 unsigned char stopped = ep->stopped; 219 unsigned char stopped = ep->stopped;
@@ -237,18 +239,7 @@ static void done(struct mv_ep *ep, struct mv_req *req, int status)
237 dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma); 239 dma_pool_free(udc->dtd_pool, curr_td, curr_td->td_dma);
238 } 240 }
239 241
240 if (req->mapped) { 242 usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep));
241 dma_unmap_single(ep->udc->gadget.dev.parent,
242 req->req.dma, req->req.length,
243 ((ep_dir(ep) == EP_DIR_IN) ?
244 DMA_TO_DEVICE : DMA_FROM_DEVICE));
245 req->req.dma = DMA_ADDR_INVALID;
246 req->mapped = 0;
247 } else
248 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
249 req->req.dma, req->req.length,
250 ((ep_dir(ep) == EP_DIR_IN) ?
251 DMA_TO_DEVICE : DMA_FROM_DEVICE));
252 243
253 if (status && (status != -ESHUTDOWN)) 244 if (status && (status != -ESHUTDOWN))
254 dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u", 245 dev_info(&udc->dev->dev, "complete %s req %p stat %d len %u/%u",
@@ -732,21 +723,9 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
732 req->ep = ep; 723 req->ep = ep;
733 724
734 /* map virtual address to hardware */ 725 /* map virtual address to hardware */
735 if (req->req.dma == DMA_ADDR_INVALID) { 726 retval = usb_gadget_map_request(&udc->gadget, _req, ep_dir(ep));
736 req->req.dma = dma_map_single(ep->udc->gadget.dev.parent, 727 if (retval)
737 req->req.buf, 728 return retval;
738 req->req.length, ep_dir(ep)
739 ? DMA_TO_DEVICE
740 : DMA_FROM_DEVICE);
741 req->mapped = 1;
742 } else {
743 dma_sync_single_for_device(ep->udc->gadget.dev.parent,
744 req->req.dma, req->req.length,
745 ep_dir(ep)
746 ? DMA_TO_DEVICE
747 : DMA_FROM_DEVICE);
748 req->mapped = 0;
749 }
750 729
751 req->req.status = -EINPROGRESS; 730 req->req.status = -EINPROGRESS;
752 req->req.actual = 0; 731 req->req.actual = 0;
@@ -780,18 +759,7 @@ mv_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
780 return 0; 759 return 0;
781 760
782err_unmap_dma: 761err_unmap_dma:
783 if (req->mapped) { 762 usb_gadget_unmap_request(&udc->gadget, _req, ep_dir(ep));
784 dma_unmap_single(ep->udc->gadget.dev.parent,
785 req->req.dma, req->req.length,
786 ((ep_dir(ep) == EP_DIR_IN) ?
787 DMA_TO_DEVICE : DMA_FROM_DEVICE));
788 req->req.dma = DMA_ADDR_INVALID;
789 req->mapped = 0;
790 } else
791 dma_sync_single_for_cpu(ep->udc->gadget.dev.parent,
792 req->req.dma, req->req.length,
793 ((ep_dir(ep) == EP_DIR_IN) ?
794 DMA_TO_DEVICE : DMA_FROM_DEVICE));
795 763
796 return retval; 764 return retval;
797} 765}
@@ -1006,18 +974,12 @@ static struct usb_ep_ops mv_ep_ops = {
1006 974
1007static void udc_clock_enable(struct mv_udc *udc) 975static void udc_clock_enable(struct mv_udc *udc)
1008{ 976{
1009 unsigned int i; 977 clk_prepare_enable(udc->clk);
1010
1011 for (i = 0; i < udc->clknum; i++)
1012 clk_prepare_enable(udc->clk[i]);
1013} 978}
1014 979
1015static void udc_clock_disable(struct mv_udc *udc) 980static void udc_clock_disable(struct mv_udc *udc)
1016{ 981{
1017 unsigned int i; 982 clk_disable_unprepare(udc->clk);
1018
1019 for (i = 0; i < udc->clknum; i++)
1020 clk_disable_unprepare(udc->clk[i]);
1021} 983}
1022 984
1023static void udc_stop(struct mv_udc *udc) 985static void udc_stop(struct mv_udc *udc)
@@ -1386,7 +1348,6 @@ static int mv_udc_start(struct usb_gadget *gadget,
1386 /* hook up the driver ... */ 1348 /* hook up the driver ... */
1387 driver->driver.bus = NULL; 1349 driver->driver.bus = NULL;
1388 udc->driver = driver; 1350 udc->driver = driver;
1389 udc->gadget.dev.driver = &driver->driver;
1390 1351
1391 udc->usb_state = USB_STATE_ATTACHED; 1352 udc->usb_state = USB_STATE_ATTACHED;
1392 udc->ep0_state = WAIT_FOR_SETUP; 1353 udc->ep0_state = WAIT_FOR_SETUP;
@@ -1401,7 +1362,6 @@ static int mv_udc_start(struct usb_gadget *gadget,
1401 dev_err(&udc->dev->dev, 1362 dev_err(&udc->dev->dev,
1402 "unable to register peripheral to otg\n"); 1363 "unable to register peripheral to otg\n");
1403 udc->driver = NULL; 1364 udc->driver = NULL;
1404 udc->gadget.dev.driver = NULL;
1405 return retval; 1365 return retval;
1406 } 1366 }
1407 } 1367 }
@@ -1437,7 +1397,6 @@ static int mv_udc_stop(struct usb_gadget *gadget,
1437 spin_unlock_irqrestore(&udc->lock, flags); 1397 spin_unlock_irqrestore(&udc->lock, flags);
1438 1398
1439 /* unbind gadget driver */ 1399 /* unbind gadget driver */
1440 udc->gadget.dev.driver = NULL;
1441 udc->driver = NULL; 1400 udc->driver = NULL;
1442 1401
1443 return 0; 1402 return 0;
@@ -1528,14 +1487,7 @@ udc_prime_status(struct mv_udc *udc, u8 direction, u16 status, bool empty)
1528 1487
1529 return 0; 1488 return 0;
1530out: 1489out:
1531 if (req->mapped) { 1490 usb_gadget_unmap_request(&udc->gadget, &req->req, ep_dir(ep));
1532 dma_unmap_single(ep->udc->gadget.dev.parent,
1533 req->req.dma, req->req.length,
1534 ((ep_dir(ep) == EP_DIR_IN) ?
1535 DMA_TO_DEVICE : DMA_FROM_DEVICE));
1536 req->req.dma = DMA_ADDR_INVALID;
1537 req->mapped = 0;
1538 }
1539 1491
1540 return retval; 1492 return retval;
1541} 1493}
@@ -1695,6 +1647,8 @@ out:
1695 1647
1696static void handle_setup_packet(struct mv_udc *udc, u8 ep_num, 1648static void handle_setup_packet(struct mv_udc *udc, u8 ep_num,
1697 struct usb_ctrlrequest *setup) 1649 struct usb_ctrlrequest *setup)
1650 __releases(&ep->udc->lock)
1651 __acquires(&ep->udc->lock)
1698{ 1652{
1699 bool delegate = false; 1653 bool delegate = false;
1700 1654
@@ -1891,7 +1845,7 @@ static void irq_process_tr_complete(struct mv_udc *udc)
1891 } 1845 }
1892} 1846}
1893 1847
1894void irq_process_reset(struct mv_udc *udc) 1848static void irq_process_reset(struct mv_udc *udc)
1895{ 1849{
1896 u32 tmp; 1850 u32 tmp;
1897 unsigned int loops; 1851 unsigned int loops;
@@ -2138,8 +2092,6 @@ static int mv_udc_remove(struct platform_device *pdev)
2138 2092
2139 mv_udc_disable(udc); 2093 mv_udc_disable(udc);
2140 2094
2141 device_unregister(&udc->gadget.dev);
2142
2143 /* free dev, wait for the release() finished */ 2095 /* free dev, wait for the release() finished */
2144 wait_for_completion(udc->done); 2096 wait_for_completion(udc->done);
2145 2097
@@ -2151,7 +2103,6 @@ static int mv_udc_probe(struct platform_device *pdev)
2151 struct mv_usb_platform_data *pdata = pdev->dev.platform_data; 2103 struct mv_usb_platform_data *pdata = pdev->dev.platform_data;
2152 struct mv_udc *udc; 2104 struct mv_udc *udc;
2153 int retval = 0; 2105 int retval = 0;
2154 int clk_i = 0;
2155 struct resource *r; 2106 struct resource *r;
2156 size_t size; 2107 size_t size;
2157 2108
@@ -2160,8 +2111,7 @@ static int mv_udc_probe(struct platform_device *pdev)
2160 return -ENODEV; 2111 return -ENODEV;
2161 } 2112 }
2162 2113
2163 size = sizeof(*udc) + sizeof(struct clk *) * pdata->clknum; 2114 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL);
2164 udc = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
2165 if (udc == NULL) { 2115 if (udc == NULL) {
2166 dev_err(&pdev->dev, "failed to allocate memory for udc\n"); 2116 dev_err(&pdev->dev, "failed to allocate memory for udc\n");
2167 return -ENOMEM; 2117 return -ENOMEM;
@@ -2173,26 +2123,24 @@ static int mv_udc_probe(struct platform_device *pdev)
2173 2123
2174 udc->dev = pdev; 2124 udc->dev = pdev;
2175 2125
2176#ifdef CONFIG_USB_OTG_UTILS
2177 if (pdata->mode == MV_USB_MODE_OTG) { 2126 if (pdata->mode == MV_USB_MODE_OTG) {
2178 udc->transceiver = devm_usb_get_phy(&pdev->dev, 2127 udc->transceiver = devm_usb_get_phy(&pdev->dev,
2179 USB_PHY_TYPE_USB2); 2128 USB_PHY_TYPE_USB2);
2180 if (IS_ERR_OR_NULL(udc->transceiver)) { 2129 if (IS_ERR(udc->transceiver)) {
2130 retval = PTR_ERR(udc->transceiver);
2131
2132 if (retval == -ENXIO)
2133 return retval;
2134
2181 udc->transceiver = NULL; 2135 udc->transceiver = NULL;
2182 return -ENODEV; 2136 return -EPROBE_DEFER;
2183 } 2137 }
2184 } 2138 }
2185#endif
2186 2139
2187 udc->clknum = pdata->clknum; 2140 /* udc only have one sysclk. */
2188 for (clk_i = 0; clk_i < udc->clknum; clk_i++) { 2141 udc->clk = devm_clk_get(&pdev->dev, NULL);
2189 udc->clk[clk_i] = devm_clk_get(&pdev->dev, 2142 if (IS_ERR(udc->clk))
2190 pdata->clkname[clk_i]); 2143 return PTR_ERR(udc->clk);
2191 if (IS_ERR(udc->clk[clk_i])) {
2192 retval = PTR_ERR(udc->clk[clk_i]);
2193 return retval;
2194 }
2195 }
2196 2144
2197 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs"); 2145 r = platform_get_resource_byname(udc->dev, IORESOURCE_MEM, "capregs");
2198 if (r == NULL) { 2146 if (r == NULL) {
@@ -2311,16 +2259,8 @@ static int mv_udc_probe(struct platform_device *pdev)
2311 udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */ 2259 udc->gadget.max_speed = USB_SPEED_HIGH; /* support dual speed */
2312 2260
2313 /* the "gadget" abstracts/virtualizes the controller */ 2261 /* the "gadget" abstracts/virtualizes the controller */
2314 dev_set_name(&udc->gadget.dev, "gadget");
2315 udc->gadget.dev.parent = &pdev->dev;
2316 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
2317 udc->gadget.dev.release = gadget_release;
2318 udc->gadget.name = driver_name; /* gadget name */ 2262 udc->gadget.name = driver_name; /* gadget name */
2319 2263
2320 retval = device_register(&udc->gadget.dev);
2321 if (retval)
2322 goto err_destroy_dma;
2323
2324 eps_init(udc); 2264 eps_init(udc);
2325 2265
2326 /* VBUS detect: we can disable/enable clock on demand.*/ 2266 /* VBUS detect: we can disable/enable clock on demand.*/
@@ -2342,7 +2282,7 @@ static int mv_udc_probe(struct platform_device *pdev)
2342 if (!udc->qwork) { 2282 if (!udc->qwork) {
2343 dev_err(&pdev->dev, "cannot create workqueue\n"); 2283 dev_err(&pdev->dev, "cannot create workqueue\n");
2344 retval = -ENOMEM; 2284 retval = -ENOMEM;
2345 goto err_unregister; 2285 goto err_destroy_dma;
2346 } 2286 }
2347 2287
2348 INIT_WORK(&udc->vbus_work, mv_udc_vbus_work); 2288 INIT_WORK(&udc->vbus_work, mv_udc_vbus_work);
@@ -2358,7 +2298,8 @@ static int mv_udc_probe(struct platform_device *pdev)
2358 else 2298 else
2359 udc->vbus_active = 1; 2299 udc->vbus_active = 1;
2360 2300
2361 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2301 retval = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
2302 gadget_release);
2362 if (retval) 2303 if (retval)
2363 goto err_create_workqueue; 2304 goto err_create_workqueue;
2364 2305
@@ -2370,8 +2311,6 @@ static int mv_udc_probe(struct platform_device *pdev)
2370 2311
2371err_create_workqueue: 2312err_create_workqueue:
2372 destroy_workqueue(udc->qwork); 2313 destroy_workqueue(udc->qwork);
2373err_unregister:
2374 device_unregister(&udc->gadget.dev);
2375err_destroy_dma: 2314err_destroy_dma:
2376 dma_pool_destroy(udc->dtd_pool); 2315 dma_pool_destroy(udc->dtd_pool);
2377err_free_dma: 2316err_free_dma:
diff --git a/drivers/usb/gadget/ncm.c b/drivers/usb/gadget/ncm.c
index a22ad9af0565..3b02fd4649ce 100644
--- a/drivers/usb/gadget/ncm.c
+++ b/drivers/usb/gadget/ncm.c
@@ -111,6 +111,7 @@ static struct usb_gadget_strings *dev_strings[] = {
111 NULL, 111 NULL,
112}; 112};
113 113
114struct eth_dev *the_dev;
114static u8 hostaddr[ETH_ALEN]; 115static u8 hostaddr[ETH_ALEN];
115 116
116/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
@@ -124,7 +125,7 @@ static int __init ncm_do_config(struct usb_configuration *c)
124 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; 125 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
125 } 126 }
126 127
127 return ncm_bind_config(c, hostaddr); 128 return ncm_bind_config(c, hostaddr, the_dev);
128} 129}
129 130
130static struct usb_configuration ncm_config_driver = { 131static struct usb_configuration ncm_config_driver = {
@@ -143,9 +144,9 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
143 int status; 144 int status;
144 145
145 /* set up network link layer */ 146 /* set up network link layer */
146 status = gether_setup(cdev->gadget, hostaddr); 147 the_dev = gether_setup(cdev->gadget, hostaddr);
147 if (status < 0) 148 if (IS_ERR(the_dev))
148 return status; 149 return PTR_ERR(the_dev);
149 150
150 /* Allocate string descriptor numbers ... note that string 151 /* Allocate string descriptor numbers ... note that string
151 * contents can be overridden by the composite_dev glue. 152 * contents can be overridden by the composite_dev glue.
@@ -168,13 +169,13 @@ static int __init gncm_bind(struct usb_composite_dev *cdev)
168 return 0; 169 return 0;
169 170
170fail: 171fail:
171 gether_cleanup(); 172 gether_cleanup(the_dev);
172 return status; 173 return status;
173} 174}
174 175
175static int __exit gncm_unbind(struct usb_composite_dev *cdev) 176static int __exit gncm_unbind(struct usb_composite_dev *cdev)
176{ 177{
177 gether_cleanup(); 178 gether_cleanup(the_dev);
178 return 0; 179 return 0;
179} 180}
180 181
diff --git a/drivers/usb/gadget/net2272.c b/drivers/usb/gadget/net2272.c
index 32524b631959..f1e50a3e322d 100644
--- a/drivers/usb/gadget/net2272.c
+++ b/drivers/usb/gadget/net2272.c
@@ -58,7 +58,6 @@ static const char * const ep_name[] = {
58 "ep-a", "ep-b", "ep-c", 58 "ep-a", "ep-b", "ep-c",
59}; 59};
60 60
61#define DMA_ADDR_INVALID (~(dma_addr_t)0)
62#ifdef CONFIG_USB_NET2272_DMA 61#ifdef CONFIG_USB_NET2272_DMA
63/* 62/*
64 * use_dma: the NET2272 can use an external DMA controller. 63 * use_dma: the NET2272 can use an external DMA controller.
@@ -341,7 +340,6 @@ net2272_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
341 if (!req) 340 if (!req)
342 return NULL; 341 return NULL;
343 342
344 req->req.dma = DMA_ADDR_INVALID;
345 INIT_LIST_HEAD(&req->queue); 343 INIT_LIST_HEAD(&req->queue);
346 344
347 return &req->req; 345 return &req->req;
@@ -913,7 +911,7 @@ net2272_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
913 } 911 }
914 } 912 }
915 } 913 }
916 if (likely(req != 0)) 914 if (likely(req))
917 list_add_tail(&req->queue, &ep->queue); 915 list_add_tail(&req->queue, &ep->queue);
918 916
919 if (likely(!list_empty(&ep->queue))) 917 if (likely(!list_empty(&ep->queue)))
@@ -1467,7 +1465,6 @@ static int net2272_start(struct usb_gadget *_gadget,
1467 dev->softconnect = 1; 1465 dev->softconnect = 1;
1468 driver->driver.bus = NULL; 1466 driver->driver.bus = NULL;
1469 dev->driver = driver; 1467 dev->driver = driver;
1470 dev->gadget.dev.driver = &driver->driver;
1471 1468
1472 /* ... then enable host detection and ep0; and we're ready 1469 /* ... then enable host detection and ep0; and we're ready
1473 * for set_configuration as well as eventual disconnect. 1470 * for set_configuration as well as eventual disconnect.
@@ -1517,7 +1514,6 @@ static int net2272_stop(struct usb_gadget *_gadget,
1517 stop_activity(dev, driver); 1514 stop_activity(dev, driver);
1518 spin_unlock_irqrestore(&dev->lock, flags); 1515 spin_unlock_irqrestore(&dev->lock, flags);
1519 1516
1520 dev->gadget.dev.driver = NULL;
1521 dev->driver = NULL; 1517 dev->driver = NULL;
1522 1518
1523 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name); 1519 dev_dbg(dev->dev, "unregistered driver '%s'\n", driver->driver.name);
@@ -1549,7 +1545,7 @@ net2272_handle_dma(struct net2272_ep *ep)
1549 | (ep->dev->dma_eot_polarity << EOT_POLARITY) 1545 | (ep->dev->dma_eot_polarity << EOT_POLARITY)
1550 | (ep->dev->dma_dack_polarity << DACK_POLARITY) 1546 | (ep->dev->dma_dack_polarity << DACK_POLARITY)
1551 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY) 1547 | (ep->dev->dma_dreq_polarity << DREQ_POLARITY)
1552 | ((ep->dma >> 1) << DMA_ENDPOINT_SELECT)); 1548 | (ep->dma << DMA_ENDPOINT_SELECT));
1553 1549
1554 ep->dev->dma_busy = 0; 1550 ep->dev->dma_busy = 0;
1555 1551
@@ -1622,7 +1618,7 @@ net2272_handle_ep(struct net2272_ep *ep)
1622 ep->irqs++; 1618 ep->irqs++;
1623 1619
1624 dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n", 1620 dev_vdbg(ep->dev->dev, "%s ack ep_stat0 %02x, ep_stat1 %02x, req %p\n",
1625 ep->ep.name, stat0, stat1, req ? &req->req : 0); 1621 ep->ep.name, stat0, stat1, req ? &req->req : NULL);
1626 1622
1627 net2272_ep_write(ep, EP_STAT0, stat0 & 1623 net2272_ep_write(ep, EP_STAT0, stat0 &
1628 ~((1 << NAK_OUT_PACKETS) 1624 ~((1 << NAK_OUT_PACKETS)
@@ -2216,7 +2212,6 @@ net2272_remove(struct net2272 *dev)
2216 free_irq(dev->irq, dev); 2212 free_irq(dev->irq, dev);
2217 iounmap(dev->base_addr); 2213 iounmap(dev->base_addr);
2218 2214
2219 device_unregister(&dev->gadget.dev);
2220 device_remove_file(dev->dev, &dev_attr_registers); 2215 device_remove_file(dev->dev, &dev_attr_registers);
2221 2216
2222 dev_info(dev->dev, "unbind\n"); 2217 dev_info(dev->dev, "unbind\n");
@@ -2243,10 +2238,6 @@ static struct net2272 *net2272_probe_init(struct device *dev, unsigned int irq)
2243 ret->gadget.max_speed = USB_SPEED_HIGH; 2238 ret->gadget.max_speed = USB_SPEED_HIGH;
2244 2239
2245 /* the "gadget" abstracts/virtualizes the controller */ 2240 /* the "gadget" abstracts/virtualizes the controller */
2246 dev_set_name(&ret->gadget.dev, "gadget");
2247 ret->gadget.dev.parent = dev;
2248 ret->gadget.dev.dma_mask = dev->dma_mask;
2249 ret->gadget.dev.release = net2272_gadget_release;
2250 ret->gadget.name = driver_name; 2241 ret->gadget.name = driver_name;
2251 2242
2252 return ret; 2243 return ret;
@@ -2282,14 +2273,12 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2282 dma_mode_string()); 2273 dma_mode_string());
2283 dev_info(dev->dev, "version: %s\n", driver_vers); 2274 dev_info(dev->dev, "version: %s\n", driver_vers);
2284 2275
2285 ret = device_register(&dev->gadget.dev);
2286 if (ret)
2287 goto err_irq;
2288 ret = device_create_file(dev->dev, &dev_attr_registers); 2276 ret = device_create_file(dev->dev, &dev_attr_registers);
2289 if (ret) 2277 if (ret)
2290 goto err_dev_reg; 2278 goto err_irq;
2291 2279
2292 ret = usb_add_gadget_udc(dev->dev, &dev->gadget); 2280 ret = usb_add_gadget_udc_release(dev->dev, &dev->gadget,
2281 net2272_gadget_release);
2293 if (ret) 2282 if (ret)
2294 goto err_add_udc; 2283 goto err_add_udc;
2295 2284
@@ -2297,8 +2286,6 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)
2297 2286
2298err_add_udc: 2287err_add_udc:
2299 device_remove_file(dev->dev, &dev_attr_registers); 2288 device_remove_file(dev->dev, &dev_attr_registers);
2300 err_dev_reg:
2301 device_unregister(&dev->gadget.dev);
2302 err_irq: 2289 err_irq:
2303 free_irq(dev->irq, dev); 2290 free_irq(dev->irq, dev);
2304 err: 2291 err:
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 3bd0f992fb49..fbd006ab31d3 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -65,7 +65,6 @@
65#define DRIVER_DESC "PLX NET228x USB Peripheral Controller" 65#define DRIVER_DESC "PLX NET228x USB Peripheral Controller"
66#define DRIVER_VERSION "2005 Sept 27" 66#define DRIVER_VERSION "2005 Sept 27"
67 67
68#define DMA_ADDR_INVALID (~(dma_addr_t)0)
69#define EP_DONTUSE 13 /* nonzero */ 68#define EP_DONTUSE 13 /* nonzero */
70 69
71#define USE_RDK_LEDS /* GPIO pins control three LEDs */ 70#define USE_RDK_LEDS /* GPIO pins control three LEDs */
@@ -406,7 +405,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
406 if (!req) 405 if (!req)
407 return NULL; 406 return NULL;
408 407
409 req->req.dma = DMA_ADDR_INVALID;
410 INIT_LIST_HEAD (&req->queue); 408 INIT_LIST_HEAD (&req->queue);
411 409
412 /* this dma descriptor may be swapped with the previous dummy */ 410 /* this dma descriptor may be swapped with the previous dummy */
@@ -420,7 +418,6 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
420 return NULL; 418 return NULL;
421 } 419 }
422 td->dmacount = 0; /* not VALID */ 420 td->dmacount = 0; /* not VALID */
423 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
424 td->dmadesc = td->dmaaddr; 421 td->dmadesc = td->dmaaddr;
425 req->td = td; 422 req->td = td;
426 } 423 }
@@ -1896,7 +1893,6 @@ static int net2280_start(struct usb_gadget *_gadget,
1896 dev->softconnect = 1; 1893 dev->softconnect = 1;
1897 driver->driver.bus = NULL; 1894 driver->driver.bus = NULL;
1898 dev->driver = driver; 1895 dev->driver = driver;
1899 dev->gadget.dev.driver = &driver->driver;
1900 1896
1901 retval = device_create_file (&dev->pdev->dev, &dev_attr_function); 1897 retval = device_create_file (&dev->pdev->dev, &dev_attr_function);
1902 if (retval) goto err_unbind; 1898 if (retval) goto err_unbind;
@@ -1924,7 +1920,6 @@ static int net2280_start(struct usb_gadget *_gadget,
1924err_func: 1920err_func:
1925 device_remove_file (&dev->pdev->dev, &dev_attr_function); 1921 device_remove_file (&dev->pdev->dev, &dev_attr_function);
1926err_unbind: 1922err_unbind:
1927 dev->gadget.dev.driver = NULL;
1928 dev->driver = NULL; 1923 dev->driver = NULL;
1929 return retval; 1924 return retval;
1930} 1925}
@@ -1967,7 +1962,6 @@ static int net2280_stop(struct usb_gadget *_gadget,
1967 stop_activity (dev, driver); 1962 stop_activity (dev, driver);
1968 spin_unlock_irqrestore (&dev->lock, flags); 1963 spin_unlock_irqrestore (&dev->lock, flags);
1969 1964
1970 dev->gadget.dev.driver = NULL;
1971 dev->driver = NULL; 1965 dev->driver = NULL;
1972 1966
1973 net2280_led_active (dev, 0); 1967 net2280_led_active (dev, 0);
@@ -2072,7 +2066,7 @@ static void handle_ep_small (struct net2280_ep *ep)
2072 return; 2066 return;
2073 2067
2074 /* manual DMA queue advance after short OUT */ 2068 /* manual DMA queue advance after short OUT */
2075 if (likely (ep->dma != 0)) { 2069 if (likely (ep->dma)) {
2076 if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) { 2070 if (t & (1 << SHORT_PACKET_TRANSFERRED_INTERRUPT)) {
2077 u32 count; 2071 u32 count;
2078 int stopped = ep->stopped; 2072 int stopped = ep->stopped;
@@ -2330,7 +2324,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2330 /* hw handles device and interface status */ 2324 /* hw handles device and interface status */
2331 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT)) 2325 if (u.r.bRequestType != (USB_DIR_IN|USB_RECIP_ENDPOINT))
2332 goto delegate; 2326 goto delegate;
2333 if ((e = get_ep_by_addr (dev, w_index)) == 0 2327 if ((e = get_ep_by_addr (dev, w_index)) == NULL
2334 || w_length > 2) 2328 || w_length > 2)
2335 goto do_stall; 2329 goto do_stall;
2336 2330
@@ -2358,7 +2352,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2358 if (w_value != USB_ENDPOINT_HALT 2352 if (w_value != USB_ENDPOINT_HALT
2359 || w_length != 0) 2353 || w_length != 0)
2360 goto do_stall; 2354 goto do_stall;
2361 if ((e = get_ep_by_addr (dev, w_index)) == 0) 2355 if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2362 goto do_stall; 2356 goto do_stall;
2363 if (e->wedged) { 2357 if (e->wedged) {
2364 VDEBUG(dev, "%s wedged, halt not cleared\n", 2358 VDEBUG(dev, "%s wedged, halt not cleared\n",
@@ -2380,7 +2374,7 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2380 if (w_value != USB_ENDPOINT_HALT 2374 if (w_value != USB_ENDPOINT_HALT
2381 || w_length != 0) 2375 || w_length != 0)
2382 goto do_stall; 2376 goto do_stall;
2383 if ((e = get_ep_by_addr (dev, w_index)) == 0) 2377 if ((e = get_ep_by_addr (dev, w_index)) == NULL)
2384 goto do_stall; 2378 goto do_stall;
2385 if (e->ep.name == ep0name) 2379 if (e->ep.name == ep0name)
2386 goto do_stall; 2380 goto do_stall;
@@ -2685,7 +2679,6 @@ static void net2280_remove (struct pci_dev *pdev)
2685 pci_resource_len (pdev, 0)); 2679 pci_resource_len (pdev, 0));
2686 if (dev->enabled) 2680 if (dev->enabled)
2687 pci_disable_device (pdev); 2681 pci_disable_device (pdev);
2688 device_unregister (&dev->gadget.dev);
2689 device_remove_file (&pdev->dev, &dev_attr_registers); 2682 device_remove_file (&pdev->dev, &dev_attr_registers);
2690 pci_set_drvdata (pdev, NULL); 2683 pci_set_drvdata (pdev, NULL);
2691 2684
@@ -2717,10 +2710,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2717 dev->gadget.max_speed = USB_SPEED_HIGH; 2710 dev->gadget.max_speed = USB_SPEED_HIGH;
2718 2711
2719 /* the "gadget" abstracts/virtualizes the controller */ 2712 /* the "gadget" abstracts/virtualizes the controller */
2720 dev_set_name(&dev->gadget.dev, "gadget");
2721 dev->gadget.dev.parent = &pdev->dev;
2722 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2723 dev->gadget.dev.release = gadget_release;
2724 dev->gadget.name = driver_name; 2713 dev->gadget.name = driver_name;
2725 2714
2726 /* now all the pci goodies ... */ 2715 /* now all the pci goodies ... */
@@ -2802,7 +2791,6 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2802 goto done; 2791 goto done;
2803 } 2792 }
2804 td->dmacount = 0; /* not VALID */ 2793 td->dmacount = 0; /* not VALID */
2805 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
2806 td->dmadesc = td->dmaaddr; 2794 td->dmadesc = td->dmaaddr;
2807 dev->ep [i].dummy = td; 2795 dev->ep [i].dummy = td;
2808 } 2796 }
@@ -2829,12 +2817,11 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2829 use_dma 2817 use_dma
2830 ? (use_dma_chaining ? "chaining" : "enabled") 2818 ? (use_dma_chaining ? "chaining" : "enabled")
2831 : "disabled"); 2819 : "disabled");
2832 retval = device_register (&dev->gadget.dev);
2833 if (retval) goto done;
2834 retval = device_create_file (&pdev->dev, &dev_attr_registers); 2820 retval = device_create_file (&pdev->dev, &dev_attr_registers);
2835 if (retval) goto done; 2821 if (retval) goto done;
2836 2822
2837 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); 2823 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
2824 gadget_release);
2838 if (retval) 2825 if (retval)
2839 goto done; 2826 goto done;
2840 return 0; 2827 return 0;
diff --git a/drivers/usb/gadget/nokia.c b/drivers/usb/gadget/nokia.c
index def37403989a..3b344b41a167 100644
--- a/drivers/usb/gadget/nokia.c
+++ b/drivers/usb/gadget/nokia.c
@@ -37,11 +37,9 @@
37 * the runtime footprint, and giving us at least some parts of what 37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */ 39 */
40#define USB_FACM_INCLUDED 40#define USBF_OBEX_INCLUDED
41#include "f_acm.c"
42#include "f_ecm.c" 41#include "f_ecm.c"
43#include "f_obex.c" 42#include "f_obex.c"
44#include "f_serial.c"
45#include "f_phonet.c" 43#include "f_phonet.c"
46#include "u_ether.c" 44#include "u_ether.c"
47 45
@@ -98,20 +96,40 @@ MODULE_AUTHOR("Felipe Balbi");
98MODULE_LICENSE("GPL"); 96MODULE_LICENSE("GPL");
99 97
100/*-------------------------------------------------------------------------*/ 98/*-------------------------------------------------------------------------*/
101 99static struct usb_function *f_acm_cfg1;
100static struct usb_function *f_acm_cfg2;
102static u8 hostaddr[ETH_ALEN]; 101static u8 hostaddr[ETH_ALEN];
102static struct eth_dev *the_dev;
103 103
104enum { 104enum {
105 TTY_PORT_OBEX0, 105 TTY_PORT_OBEX0,
106 TTY_PORT_OBEX1, 106 TTY_PORT_OBEX1,
107 TTY_PORT_ACM,
108 TTY_PORTS_MAX, 107 TTY_PORTS_MAX,
109}; 108};
110 109
111static unsigned char tty_lines[TTY_PORTS_MAX]; 110static unsigned char tty_lines[TTY_PORTS_MAX];
112 111
112static struct usb_configuration nokia_config_500ma_driver = {
113 .label = "Bus Powered",
114 .bConfigurationValue = 1,
115 /* .iConfiguration = DYNAMIC */
116 .bmAttributes = USB_CONFIG_ATT_ONE,
117 .MaxPower = 500,
118};
119
120static struct usb_configuration nokia_config_100ma_driver = {
121 .label = "Self Powered",
122 .bConfigurationValue = 2,
123 /* .iConfiguration = DYNAMIC */
124 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
125 .MaxPower = 100,
126};
127
128static struct usb_function_instance *fi_acm;
129
113static int __init nokia_bind_config(struct usb_configuration *c) 130static int __init nokia_bind_config(struct usb_configuration *c)
114{ 131{
132 struct usb_function *f_acm;
115 int status = 0; 133 int status = 0;
116 134
117 status = phonet_bind_config(c); 135 status = phonet_bind_config(c);
@@ -126,33 +144,32 @@ static int __init nokia_bind_config(struct usb_configuration *c)
126 if (status) 144 if (status)
127 printk(KERN_DEBUG "could not bind obex config %d\n", 0); 145 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
128 146
129 status = acm_bind_config(c, tty_lines[TTY_PORT_ACM]); 147 f_acm = usb_get_function(fi_acm);
130 if (status) 148 if (IS_ERR(f_acm))
131 printk(KERN_DEBUG "could not bind acm config\n"); 149 return PTR_ERR(f_acm);
132 150
133 status = ecm_bind_config(c, hostaddr); 151 status = usb_add_function(c, f_acm);
134 if (status) 152 if (status)
135 printk(KERN_DEBUG "could not bind ecm config\n"); 153 goto err_conf;
154
155 status = ecm_bind_config(c, hostaddr, the_dev);
156 if (status) {
157 pr_debug("could not bind ecm config %d\n", status);
158 goto err_ecm;
159 }
160 if (c == &nokia_config_500ma_driver)
161 f_acm_cfg1 = f_acm;
162 else
163 f_acm_cfg2 = f_acm;
136 164
137 return status; 165 return status;
166err_ecm:
167 usb_remove_function(c, f_acm);
168err_conf:
169 usb_put_function(f_acm);
170 return status;
138} 171}
139 172
140static struct usb_configuration nokia_config_500ma_driver = {
141 .label = "Bus Powered",
142 .bConfigurationValue = 1,
143 /* .iConfiguration = DYNAMIC */
144 .bmAttributes = USB_CONFIG_ATT_ONE,
145 .MaxPower = 500,
146};
147
148static struct usb_configuration nokia_config_100ma_driver = {
149 .label = "Self Powered",
150 .bConfigurationValue = 2,
151 /* .iConfiguration = DYNAMIC */
152 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
153 .MaxPower = 100,
154};
155
156static int __init nokia_bind(struct usb_composite_dev *cdev) 173static int __init nokia_bind(struct usb_composite_dev *cdev)
157{ 174{
158 struct usb_gadget *gadget = cdev->gadget; 175 struct usb_gadget *gadget = cdev->gadget;
@@ -169,9 +186,11 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
169 goto err_ether; 186 goto err_ether;
170 } 187 }
171 188
172 status = gether_setup(cdev->gadget, hostaddr); 189 the_dev = gether_setup(cdev->gadget, hostaddr);
173 if (status < 0) 190 if (IS_ERR(the_dev)) {
191 status = PTR_ERR(the_dev);
174 goto err_ether; 192 goto err_ether;
193 }
175 194
176 status = usb_string_ids_tab(cdev, strings_dev); 195 status = usb_string_ids_tab(cdev, strings_dev);
177 if (status < 0) 196 if (status < 0)
@@ -185,24 +204,32 @@ static int __init nokia_bind(struct usb_composite_dev *cdev)
185 if (!gadget_supports_altsettings(gadget)) 204 if (!gadget_supports_altsettings(gadget))
186 goto err_usb; 205 goto err_usb;
187 206
207 fi_acm = usb_get_function_instance("acm");
208 if (IS_ERR(fi_acm))
209 goto err_usb;
210
188 /* finally register the configuration */ 211 /* finally register the configuration */
189 status = usb_add_config(cdev, &nokia_config_500ma_driver, 212 status = usb_add_config(cdev, &nokia_config_500ma_driver,
190 nokia_bind_config); 213 nokia_bind_config);
191 if (status < 0) 214 if (status < 0)
192 goto err_usb; 215 goto err_acm_inst;
193 216
194 status = usb_add_config(cdev, &nokia_config_100ma_driver, 217 status = usb_add_config(cdev, &nokia_config_100ma_driver,
195 nokia_bind_config); 218 nokia_bind_config);
196 if (status < 0) 219 if (status < 0)
197 goto err_usb; 220 goto err_put_cfg1;
198 221
199 usb_composite_overwrite_options(cdev, &coverwrite); 222 usb_composite_overwrite_options(cdev, &coverwrite);
200 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME); 223 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
201 224
202 return 0; 225 return 0;
203 226
227err_put_cfg1:
228 usb_put_function(f_acm_cfg1);
229err_acm_inst:
230 usb_put_function_instance(fi_acm);
204err_usb: 231err_usb:
205 gether_cleanup(); 232 gether_cleanup(the_dev);
206err_ether: 233err_ether:
207 cur_line--; 234 cur_line--;
208 while (cur_line >= 0) 235 while (cur_line >= 0)
@@ -217,12 +244,15 @@ static int __exit nokia_unbind(struct usb_composite_dev *cdev)
217{ 244{
218 int i; 245 int i;
219 246
247 usb_put_function(f_acm_cfg1);
248 usb_put_function(f_acm_cfg2);
249 usb_put_function_instance(fi_acm);
220 gphonet_cleanup(); 250 gphonet_cleanup();
221 251
222 for (i = 0; i < TTY_PORTS_MAX; i++) 252 for (i = 0; i < TTY_PORTS_MAX; i++)
223 gserial_free_line(tty_lines[i]); 253 gserial_free_line(tty_lines[i]);
224 254
225 gether_cleanup(); 255 gether_cleanup(the_dev);
226 256
227 return 0; 257 return 0;
228} 258}
@@ -247,4 +277,3 @@ static void __exit nokia_cleanup(void)
247 usb_composite_unregister(&nokia_driver); 277 usb_composite_unregister(&nokia_driver);
248} 278}
249module_exit(nokia_cleanup); 279module_exit(nokia_cleanup);
250
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index f8445653577f..b8ed74a823cb 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2067,7 +2067,6 @@ static int omap_udc_start(struct usb_gadget *g,
2067 /* hook up the driver */ 2067 /* hook up the driver */
2068 driver->driver.bus = NULL; 2068 driver->driver.bus = NULL;
2069 udc->driver = driver; 2069 udc->driver = driver;
2070 udc->gadget.dev.driver = &driver->driver;
2071 spin_unlock_irqrestore(&udc->lock, flags); 2070 spin_unlock_irqrestore(&udc->lock, flags);
2072 2071
2073 if (udc->dc_clk != NULL) 2072 if (udc->dc_clk != NULL)
@@ -2083,7 +2082,6 @@ static int omap_udc_start(struct usb_gadget *g,
2083 ERR("can't bind to transceiver\n"); 2082 ERR("can't bind to transceiver\n");
2084 if (driver->unbind) { 2083 if (driver->unbind) {
2085 driver->unbind(&udc->gadget); 2084 driver->unbind(&udc->gadget);
2086 udc->gadget.dev.driver = NULL;
2087 udc->driver = NULL; 2085 udc->driver = NULL;
2088 } 2086 }
2089 goto done; 2087 goto done;
@@ -2129,7 +2127,6 @@ static int omap_udc_stop(struct usb_gadget *g,
2129 udc_quiesce(udc); 2127 udc_quiesce(udc);
2130 spin_unlock_irqrestore(&udc->lock, flags); 2128 spin_unlock_irqrestore(&udc->lock, flags);
2131 2129
2132 udc->gadget.dev.driver = NULL;
2133 udc->driver = NULL; 2130 udc->driver = NULL;
2134 2131
2135 if (udc->dc_clk != NULL) 2132 if (udc->dc_clk != NULL)
@@ -2631,14 +2628,6 @@ omap_udc_setup(struct platform_device *odev, struct usb_phy *xceiv)
2631 udc->gadget.speed = USB_SPEED_UNKNOWN; 2628 udc->gadget.speed = USB_SPEED_UNKNOWN;
2632 udc->gadget.max_speed = USB_SPEED_FULL; 2629 udc->gadget.max_speed = USB_SPEED_FULL;
2633 udc->gadget.name = driver_name; 2630 udc->gadget.name = driver_name;
2634
2635 device_initialize(&udc->gadget.dev);
2636 dev_set_name(&udc->gadget.dev, "gadget");
2637 udc->gadget.dev.release = omap_udc_release;
2638 udc->gadget.dev.parent = &odev->dev;
2639 if (use_dma)
2640 udc->gadget.dev.dma_mask = odev->dev.dma_mask;
2641
2642 udc->transceiver = xceiv; 2631 udc->transceiver = xceiv;
2643 2632
2644 /* ep0 is special; put it right after the SETUP buffer */ 2633 /* ep0 is special; put it right after the SETUP buffer */
@@ -2912,14 +2901,13 @@ bad_on_1710:
2912 } 2901 }
2913 2902
2914 create_proc_file(); 2903 create_proc_file();
2915 status = device_add(&udc->gadget.dev); 2904 status = usb_add_gadget_udc_release(&pdev->dev, &udc->gadget,
2905 omap_udc_release);
2916 if (status) 2906 if (status)
2917 goto cleanup4; 2907 goto cleanup4;
2918 2908
2919 status = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2909 return 0;
2920 if (!status) 2910
2921 return status;
2922 /* If fail, fall through */
2923cleanup4: 2911cleanup4:
2924 remove_proc_file(); 2912 remove_proc_file();
2925 2913
@@ -2990,7 +2978,6 @@ static int omap_udc_remove(struct platform_device *pdev)
2990 release_mem_region(pdev->resource[0].start, 2978 release_mem_region(pdev->resource[0].start,
2991 pdev->resource[0].end - pdev->resource[0].start + 1); 2979 pdev->resource[0].end - pdev->resource[0].start + 1);
2992 2980
2993 device_unregister(&udc->gadget.dev);
2994 wait_for_completion(&done); 2981 wait_for_completion(&done);
2995 2982
2996 return 0; 2983 return 0;
diff --git a/drivers/usb/gadget/pch_udc.c b/drivers/usb/gadget/pch_udc.c
index a787a8ef672b..24174e1d1564 100644
--- a/drivers/usb/gadget/pch_udc.c
+++ b/drivers/usb/gadget/pch_udc.c
@@ -358,7 +358,6 @@ struct pch_udc_dev {
358 prot_stall:1, 358 prot_stall:1,
359 irq_registered:1, 359 irq_registered:1,
360 mem_region:1, 360 mem_region:1,
361 registered:1,
362 suspended:1, 361 suspended:1,
363 connected:1, 362 connected:1,
364 vbus_session:1, 363 vbus_session:1,
@@ -1441,6 +1440,8 @@ static void pch_vbus_gpio_free(struct pch_udc_dev *dev)
1441 */ 1440 */
1442static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req, 1441static void complete_req(struct pch_udc_ep *ep, struct pch_udc_request *req,
1443 int status) 1442 int status)
1443 __releases(&dev->lock)
1444 __acquires(&dev->lock)
1444{ 1445{
1445 struct pch_udc_dev *dev; 1446 struct pch_udc_dev *dev;
1446 unsigned halted = ep->halted; 1447 unsigned halted = ep->halted;
@@ -2382,6 +2383,8 @@ static void pch_udc_svc_control_in(struct pch_udc_dev *dev)
2382 * @dev: Reference to the device structure 2383 * @dev: Reference to the device structure
2383 */ 2384 */
2384static void pch_udc_svc_control_out(struct pch_udc_dev *dev) 2385static void pch_udc_svc_control_out(struct pch_udc_dev *dev)
2386 __releases(&dev->lock)
2387 __acquires(&dev->lock)
2385{ 2388{
2386 u32 stat; 2389 u32 stat;
2387 int setup_supported; 2390 int setup_supported;
@@ -2989,7 +2992,6 @@ static int pch_udc_start(struct usb_gadget *g,
2989 2992
2990 driver->driver.bus = NULL; 2993 driver->driver.bus = NULL;
2991 dev->driver = driver; 2994 dev->driver = driver;
2992 dev->gadget.dev.driver = &driver->driver;
2993 2995
2994 /* get ready for ep0 traffic */ 2996 /* get ready for ep0 traffic */
2995 pch_udc_setup_ep0(dev); 2997 pch_udc_setup_ep0(dev);
@@ -3010,7 +3012,6 @@ static int pch_udc_stop(struct usb_gadget *g,
3010 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK); 3012 pch_udc_disable_interrupts(dev, UDC_DEVINT_MSK);
3011 3013
3012 /* Assures that there are no pending requests with this driver */ 3014 /* Assures that there are no pending requests with this driver */
3013 dev->gadget.dev.driver = NULL;
3014 dev->driver = NULL; 3015 dev->driver = NULL;
3015 dev->connected = 0; 3016 dev->connected = 0;
3016 3017
@@ -3078,8 +3079,6 @@ static void pch_udc_remove(struct pci_dev *pdev)
3078 pci_resource_len(pdev, PCH_UDC_PCI_BAR)); 3079 pci_resource_len(pdev, PCH_UDC_PCI_BAR));
3079 if (dev->active) 3080 if (dev->active)
3080 pci_disable_device(pdev); 3081 pci_disable_device(pdev);
3081 if (dev->registered)
3082 device_unregister(&dev->gadget.dev);
3083 kfree(dev); 3082 kfree(dev);
3084 pci_set_drvdata(pdev, NULL); 3083 pci_set_drvdata(pdev, NULL);
3085} 3084}
@@ -3196,21 +3195,13 @@ static int pch_udc_probe(struct pci_dev *pdev,
3196 if (retval) 3195 if (retval)
3197 goto finished; 3196 goto finished;
3198 3197
3199 dev_set_name(&dev->gadget.dev, "gadget");
3200 dev->gadget.dev.parent = &pdev->dev;
3201 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
3202 dev->gadget.dev.release = gadget_release;
3203 dev->gadget.name = KBUILD_MODNAME; 3198 dev->gadget.name = KBUILD_MODNAME;
3204 dev->gadget.max_speed = USB_SPEED_HIGH; 3199 dev->gadget.max_speed = USB_SPEED_HIGH;
3205 3200
3206 retval = device_register(&dev->gadget.dev);
3207 if (retval)
3208 goto finished;
3209 dev->registered = 1;
3210
3211 /* Put the device in disconnected state till a driver is bound */ 3201 /* Put the device in disconnected state till a driver is bound */
3212 pch_udc_set_disconnect(dev); 3202 pch_udc_set_disconnect(dev);
3213 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); 3203 retval = usb_add_gadget_udc_release(&pdev->dev, &dev->gadget,
3204 gadget_release);
3214 if (retval) 3205 if (retval)
3215 goto finished; 3206 goto finished;
3216 return 0; 3207 return 0;
diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c
index d0f37484b6b0..ef47495dec8f 100644
--- a/drivers/usb/gadget/pxa25x_udc.c
+++ b/drivers/usb/gadget/pxa25x_udc.c
@@ -1263,7 +1263,6 @@ static int pxa25x_udc_start(struct usb_gadget *g,
1263 1263
1264 /* first hook up the driver ... */ 1264 /* first hook up the driver ... */
1265 dev->driver = driver; 1265 dev->driver = driver;
1266 dev->gadget.dev.driver = &driver->driver;
1267 dev->pullup = 1; 1266 dev->pullup = 1;
1268 1267
1269 /* ... then enable host detection and ep0; and we're ready 1268 /* ... then enable host detection and ep0; and we're ready
@@ -1325,7 +1324,6 @@ static int pxa25x_udc_stop(struct usb_gadget*g,
1325 if (!IS_ERR_OR_NULL(dev->transceiver)) 1324 if (!IS_ERR_OR_NULL(dev->transceiver))
1326 (void) otg_set_peripheral(dev->transceiver->otg, NULL); 1325 (void) otg_set_peripheral(dev->transceiver->otg, NULL);
1327 1326
1328 dev->gadget.dev.driver = NULL;
1329 dev->driver = NULL; 1327 dev->driver = NULL;
1330 1328
1331 dump_state(dev); 1329 dump_state(dev);
@@ -2138,17 +2136,6 @@ static int __init pxa25x_udc_probe(struct platform_device *pdev)
2138 dev->timer.function = udc_watchdog; 2136 dev->timer.function = udc_watchdog;
2139 dev->timer.data = (unsigned long) dev; 2137 dev->timer.data = (unsigned long) dev;
2140 2138
2141 device_initialize(&dev->gadget.dev);
2142 dev->gadget.dev.parent = &pdev->dev;
2143 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
2144
2145 retval = device_add(&dev->gadget.dev);
2146 if (retval) {
2147 dev->driver = NULL;
2148 dev->gadget.dev.driver = NULL;
2149 goto err_device_add;
2150 }
2151
2152 the_controller = dev; 2139 the_controller = dev;
2153 platform_set_drvdata(pdev, dev); 2140 platform_set_drvdata(pdev, dev);
2154 2141
@@ -2199,8 +2186,6 @@ lubbock_fail0:
2199 free_irq(irq, dev); 2186 free_irq(irq, dev);
2200#endif 2187#endif
2201 err_irq1: 2188 err_irq1:
2202 device_unregister(&dev->gadget.dev);
2203 err_device_add:
2204 if (gpio_is_valid(dev->mach->gpio_pullup)) 2189 if (gpio_is_valid(dev->mach->gpio_pullup))
2205 gpio_free(dev->mach->gpio_pullup); 2190 gpio_free(dev->mach->gpio_pullup);
2206 err_gpio_pullup: 2191 err_gpio_pullup:
@@ -2226,7 +2211,6 @@ static int __exit pxa25x_udc_remove(struct platform_device *pdev)
2226 return -EBUSY; 2211 return -EBUSY;
2227 2212
2228 usb_del_gadget_udc(&dev->gadget); 2213 usb_del_gadget_udc(&dev->gadget);
2229 device_unregister(&dev->gadget.dev);
2230 dev->pullup = 0; 2214 dev->pullup = 0;
2231 pullup(dev); 2215 pullup(dev);
2232 2216
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 2fc867652ef5..6b4c7d95853f 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -24,14 +24,12 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/prefetch.h> 26#include <linux/prefetch.h>
27 27#include <linux/byteorder/generic.h>
28#include <asm/byteorder.h> 28#include <linux/platform_data/pxa2xx_udc.h>
29#include <mach/hardware.h>
30 29
31#include <linux/usb.h> 30#include <linux/usb.h>
32#include <linux/usb/ch9.h> 31#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h> 32#include <linux/usb/gadget.h>
34#include <mach/udc.h>
35 33
36#include "pxa27x_udc.h" 34#include "pxa27x_udc.h"
37 35
@@ -611,7 +609,7 @@ static void inc_ep_stats_bytes(struct pxa_ep *ep, int count, int is_in)
611 * 609 *
612 * Find the physical pxa27x ep, and setup its UDCCR 610 * Find the physical pxa27x ep, and setup its UDCCR
613 */ 611 */
614static __init void pxa_ep_setup(struct pxa_ep *ep) 612static void pxa_ep_setup(struct pxa_ep *ep)
615{ 613{
616 u32 new_udccr; 614 u32 new_udccr;
617 615
@@ -633,7 +631,7 @@ static __init void pxa_ep_setup(struct pxa_ep *ep)
633 * 631 *
634 * Setup all pxa physical endpoints, except ep0 632 * Setup all pxa physical endpoints, except ep0
635 */ 633 */
636static __init void pxa_eps_setup(struct pxa_udc *dev) 634static void pxa_eps_setup(struct pxa_udc *dev)
637{ 635{
638 unsigned int i; 636 unsigned int i;
639 637
@@ -1718,7 +1716,7 @@ static void udc_disable(struct pxa_udc *udc)
1718 * Initializes gadget endpoint list, endpoints locks. No action is taken 1716 * Initializes gadget endpoint list, endpoints locks. No action is taken
1719 * on the hardware. 1717 * on the hardware.
1720 */ 1718 */
1721static __init void udc_init_data(struct pxa_udc *dev) 1719static void udc_init_data(struct pxa_udc *dev)
1722{ 1720{
1723 int i; 1721 int i;
1724 struct pxa_ep *ep; 1722 struct pxa_ep *ep;
@@ -1811,7 +1809,6 @@ static int pxa27x_udc_start(struct usb_gadget *g,
1811 1809
1812 /* first hook up the driver ... */ 1810 /* first hook up the driver ... */
1813 udc->driver = driver; 1811 udc->driver = driver;
1814 udc->gadget.dev.driver = &driver->driver;
1815 dplus_pullup(udc, 1); 1812 dplus_pullup(udc, 1);
1816 1813
1817 if (!IS_ERR_OR_NULL(udc->transceiver)) { 1814 if (!IS_ERR_OR_NULL(udc->transceiver)) {
@@ -1829,7 +1826,6 @@ static int pxa27x_udc_start(struct usb_gadget *g,
1829 1826
1830fail: 1827fail:
1831 udc->driver = NULL; 1828 udc->driver = NULL;
1832 udc->gadget.dev.driver = NULL;
1833 return retval; 1829 return retval;
1834} 1830}
1835 1831
@@ -1871,7 +1867,6 @@ static int pxa27x_udc_stop(struct usb_gadget *g,
1871 1867
1872 udc->driver = NULL; 1868 udc->driver = NULL;
1873 1869
1874
1875 if (!IS_ERR_OR_NULL(udc->transceiver)) 1870 if (!IS_ERR_OR_NULL(udc->transceiver))
1876 return otg_set_peripheral(udc->transceiver->otg, NULL); 1871 return otg_set_peripheral(udc->transceiver->otg, NULL);
1877 return 0; 1872 return 0;
@@ -2413,7 +2408,7 @@ static struct pxa_udc memory = {
2413 * Perform basic init : allocates udc clock, creates sysfs files, requests 2408 * Perform basic init : allocates udc clock, creates sysfs files, requests
2414 * irq. 2409 * irq.
2415 */ 2410 */
2416static int __init pxa_udc_probe(struct platform_device *pdev) 2411static int pxa_udc_probe(struct platform_device *pdev)
2417{ 2412{
2418 struct resource *regs; 2413 struct resource *regs;
2419 struct pxa_udc *udc = &memory; 2414 struct pxa_udc *udc = &memory;
@@ -2456,9 +2451,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2456 goto err_map; 2451 goto err_map;
2457 } 2452 }
2458 2453
2459 device_initialize(&udc->gadget.dev);
2460 udc->gadget.dev.parent = &pdev->dev;
2461 udc->gadget.dev.dma_mask = NULL;
2462 udc->vbus_sensed = 0; 2454 udc->vbus_sensed = 0;
2463 2455
2464 the_controller = udc; 2456 the_controller = udc;
@@ -2475,12 +2467,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2475 goto err_irq; 2467 goto err_irq;
2476 } 2468 }
2477 2469
2478 retval = device_add(&udc->gadget.dev);
2479 if (retval) {
2480 dev_err(udc->dev, "device_add error %d\n", retval);
2481 goto err_dev_add;
2482 }
2483
2484 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); 2470 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
2485 if (retval) 2471 if (retval)
2486 goto err_add_udc; 2472 goto err_add_udc;
@@ -2490,8 +2476,6 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2490 return 0; 2476 return 0;
2491 2477
2492err_add_udc: 2478err_add_udc:
2493 device_unregister(&udc->gadget.dev);
2494err_dev_add:
2495 free_irq(udc->irq, udc); 2479 free_irq(udc->irq, udc);
2496err_irq: 2480err_irq:
2497 iounmap(udc->regs); 2481 iounmap(udc->regs);
@@ -2506,13 +2490,12 @@ err_clk:
2506 * pxa_udc_remove - removes the udc device driver 2490 * pxa_udc_remove - removes the udc device driver
2507 * @_dev: platform device 2491 * @_dev: platform device
2508 */ 2492 */
2509static int __exit pxa_udc_remove(struct platform_device *_dev) 2493static int pxa_udc_remove(struct platform_device *_dev)
2510{ 2494{
2511 struct pxa_udc *udc = platform_get_drvdata(_dev); 2495 struct pxa_udc *udc = platform_get_drvdata(_dev);
2512 int gpio = udc->mach->gpio_pullup; 2496 int gpio = udc->mach->gpio_pullup;
2513 2497
2514 usb_del_gadget_udc(&udc->gadget); 2498 usb_del_gadget_udc(&udc->gadget);
2515 device_del(&udc->gadget.dev);
2516 usb_gadget_unregister_driver(udc->driver); 2499 usb_gadget_unregister_driver(udc->driver);
2517 free_irq(udc->irq, udc); 2500 free_irq(udc->irq, udc);
2518 pxa_cleanup_debugfs(udc); 2501 pxa_cleanup_debugfs(udc);
@@ -2625,7 +2608,8 @@ static struct platform_driver udc_driver = {
2625 .name = "pxa27x-udc", 2608 .name = "pxa27x-udc",
2626 .owner = THIS_MODULE, 2609 .owner = THIS_MODULE,
2627 }, 2610 },
2628 .remove = __exit_p(pxa_udc_remove), 2611 .probe = pxa_udc_probe,
2612 .remove = pxa_udc_remove,
2629 .shutdown = pxa_udc_shutdown, 2613 .shutdown = pxa_udc_shutdown,
2630#ifdef CONFIG_PM 2614#ifdef CONFIG_PM
2631 .suspend = pxa_udc_suspend, 2615 .suspend = pxa_udc_suspend,
@@ -2633,22 +2617,7 @@ static struct platform_driver udc_driver = {
2633#endif 2617#endif
2634}; 2618};
2635 2619
2636static int __init udc_init(void) 2620module_platform_driver(udc_driver);
2637{
2638 if (!cpu_is_pxa27x() && !cpu_is_pxa3xx())
2639 return -ENODEV;
2640
2641 printk(KERN_INFO "%s: version %s\n", driver_name, DRIVER_VERSION);
2642 return platform_driver_probe(&udc_driver, pxa_udc_probe);
2643}
2644module_init(udc_init);
2645
2646
2647static void __exit udc_exit(void)
2648{
2649 platform_driver_unregister(&udc_driver);
2650}
2651module_exit(udc_exit);
2652 2621
2653MODULE_DESCRIPTION(DRIVER_DESC); 2622MODULE_DESCRIPTION(DRIVER_DESC);
2654MODULE_AUTHOR("Robert Jarzmik"); 2623MODULE_AUTHOR("Robert Jarzmik");
diff --git a/drivers/usb/gadget/r8a66597-udc.c b/drivers/usb/gadget/r8a66597-udc.c
index f46a1b77ce3e..0b742d171843 100644
--- a/drivers/usb/gadget/r8a66597-udc.c
+++ b/drivers/usb/gadget/r8a66597-udc.c
@@ -1837,7 +1837,6 @@ static int __exit r8a66597_remove(struct platform_device *pdev)
1837 clk_put(r8a66597->clk); 1837 clk_put(r8a66597->clk);
1838 } 1838 }
1839 1839
1840 device_unregister(&r8a66597->gadget.dev);
1841 kfree(r8a66597); 1840 kfree(r8a66597);
1842 return 0; 1841 return 0;
1843} 1842}
@@ -1915,17 +1914,8 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1915 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW; 1914 r8a66597->irq_sense_low = irq_trigger == IRQF_TRIGGER_LOW;
1916 1915
1917 r8a66597->gadget.ops = &r8a66597_gadget_ops; 1916 r8a66597->gadget.ops = &r8a66597_gadget_ops;
1918 dev_set_name(&r8a66597->gadget.dev, "gadget");
1919 r8a66597->gadget.max_speed = USB_SPEED_HIGH; 1917 r8a66597->gadget.max_speed = USB_SPEED_HIGH;
1920 r8a66597->gadget.dev.parent = &pdev->dev;
1921 r8a66597->gadget.dev.dma_mask = pdev->dev.dma_mask;
1922 r8a66597->gadget.dev.release = pdev->dev.release;
1923 r8a66597->gadget.name = udc_name; 1918 r8a66597->gadget.name = udc_name;
1924 ret = device_register(&r8a66597->gadget.dev);
1925 if (ret < 0) {
1926 dev_err(&pdev->dev, "device_register failed\n");
1927 goto clean_up;
1928 }
1929 1919
1930 init_timer(&r8a66597->timer); 1920 init_timer(&r8a66597->timer);
1931 r8a66597->timer.function = r8a66597_timer; 1921 r8a66597->timer.function = r8a66597_timer;
@@ -1939,7 +1929,7 @@ static int __init r8a66597_probe(struct platform_device *pdev)
1939 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", 1929 dev_err(&pdev->dev, "cannot get clock \"%s\"\n",
1940 clk_name); 1930 clk_name);
1941 ret = PTR_ERR(r8a66597->clk); 1931 ret = PTR_ERR(r8a66597->clk);
1942 goto clean_up_dev; 1932 goto clean_up;
1943 } 1933 }
1944 clk_enable(r8a66597->clk); 1934 clk_enable(r8a66597->clk);
1945 } 1935 }
@@ -2007,8 +1997,6 @@ clean_up2:
2007 clk_disable(r8a66597->clk); 1997 clk_disable(r8a66597->clk);
2008 clk_put(r8a66597->clk); 1998 clk_put(r8a66597->clk);
2009 } 1999 }
2010clean_up_dev:
2011 device_unregister(&r8a66597->gadget.dev);
2012clean_up: 2000clean_up:
2013 if (r8a66597) { 2001 if (r8a66597) {
2014 if (r8a66597->sudmac_reg) 2002 if (r8a66597->sudmac_reg)
diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/gadget/s3c-hsotg.c
index c26564f29a2c..a3cdc32115d5 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/gadget/s3c-hsotg.c
@@ -39,8 +39,6 @@
39 39
40#include "s3c-hsotg.h" 40#include "s3c-hsotg.h"
41 41
42#define DMA_ADDR_INVALID (~((dma_addr_t)0))
43
44static const char * const s3c_hsotg_supply_names[] = { 42static const char * const s3c_hsotg_supply_names[] = {
45 "vusb_d", /* digital USB supply, 1.2V */ 43 "vusb_d", /* digital USB supply, 1.2V */
46 "vusb_a", /* analog USB supply, 1.1V */ 44 "vusb_a", /* analog USB supply, 1.1V */
@@ -405,7 +403,6 @@ static struct usb_request *s3c_hsotg_ep_alloc_request(struct usb_ep *ep,
405 403
406 INIT_LIST_HEAD(&req->queue); 404 INIT_LIST_HEAD(&req->queue);
407 405
408 req->req.dma = DMA_ADDR_INVALID;
409 return &req->req; 406 return &req->req;
410} 407}
411 408
@@ -435,24 +432,12 @@ static void s3c_hsotg_unmap_dma(struct s3c_hsotg *hsotg,
435 struct s3c_hsotg_req *hs_req) 432 struct s3c_hsotg_req *hs_req)
436{ 433{
437 struct usb_request *req = &hs_req->req; 434 struct usb_request *req = &hs_req->req;
438 enum dma_data_direction dir;
439
440 dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
441 435
442 /* ignore this if we're not moving any data */ 436 /* ignore this if we're not moving any data */
443 if (hs_req->req.length == 0) 437 if (hs_req->req.length == 0)
444 return; 438 return;
445 439
446 if (hs_req->mapped) { 440 usb_gadget_unmap_request(&hsotg->gadget, hs_req, hs_ep->dir_in);
447 /* we mapped this, so unmap and remove the dma */
448
449 dma_unmap_single(hsotg->dev, req->dma, req->length, dir);
450
451 req->dma = DMA_ADDR_INVALID;
452 hs_req->mapped = 0;
453 } else {
454 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
455 }
456} 441}
457 442
458/** 443/**
@@ -852,37 +837,16 @@ static int s3c_hsotg_map_dma(struct s3c_hsotg *hsotg,
852 struct s3c_hsotg_ep *hs_ep, 837 struct s3c_hsotg_ep *hs_ep,
853 struct usb_request *req) 838 struct usb_request *req)
854{ 839{
855 enum dma_data_direction dir;
856 struct s3c_hsotg_req *hs_req = our_req(req); 840 struct s3c_hsotg_req *hs_req = our_req(req);
857 841 int ret;
858 dir = hs_ep->dir_in ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
859 842
860 /* if the length is zero, ignore the DMA data */ 843 /* if the length is zero, ignore the DMA data */
861 if (hs_req->req.length == 0) 844 if (hs_req->req.length == 0)
862 return 0; 845 return 0;
863 846
864 if (req->dma == DMA_ADDR_INVALID) { 847 ret = usb_gadget_map_request(&hsotg->gadget, req, hs_ep->dir_in);
865 dma_addr_t dma; 848 if (ret)
866 849 goto dma_error;
867 dma = dma_map_single(hsotg->dev, req->buf, req->length, dir);
868
869 if (unlikely(dma_mapping_error(hsotg->dev, dma)))
870 goto dma_error;
871
872 if (dma & 3) {
873 dev_err(hsotg->dev, "%s: unaligned dma buffer\n",
874 __func__);
875
876 dma_unmap_single(hsotg->dev, dma, req->length, dir);
877 return -EINVAL;
878 }
879
880 hs_req->mapped = 1;
881 req->dma = dma;
882 } else {
883 dma_sync_single_for_cpu(hsotg->dev, req->dma, req->length, dir);
884 hs_req->mapped = 0;
885 }
886 850
887 return 0; 851 return 0;
888 852
@@ -2961,9 +2925,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2961 2925
2962 driver->driver.bus = NULL; 2926 driver->driver.bus = NULL;
2963 hsotg->driver = driver; 2927 hsotg->driver = driver;
2964 hsotg->gadget.dev.driver = &driver->driver;
2965 hsotg->gadget.dev.of_node = hsotg->dev->of_node; 2928 hsotg->gadget.dev.of_node = hsotg->dev->of_node;
2966 hsotg->gadget.dev.dma_mask = hsotg->dev->dma_mask;
2967 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 2929 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
2968 2930
2969 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), 2931 ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies),
@@ -2979,7 +2941,6 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget,
2979 2941
2980err: 2942err:
2981 hsotg->driver = NULL; 2943 hsotg->driver = NULL;
2982 hsotg->gadget.dev.driver = NULL;
2983 return ret; 2944 return ret;
2984} 2945}
2985 2946
@@ -3014,7 +2975,6 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget,
3014 2975
3015 hsotg->driver = NULL; 2976 hsotg->driver = NULL;
3016 hsotg->gadget.speed = USB_SPEED_UNKNOWN; 2977 hsotg->gadget.speed = USB_SPEED_UNKNOWN;
3017 hsotg->gadget.dev.driver = NULL;
3018 2978
3019 spin_unlock_irqrestore(&hsotg->lock, flags); 2979 spin_unlock_irqrestore(&hsotg->lock, flags);
3020 2980
@@ -3484,16 +3444,6 @@ static void s3c_hsotg_delete_debug(struct s3c_hsotg *hsotg)
3484} 3444}
3485 3445
3486/** 3446/**
3487 * s3c_hsotg_release - release callback for hsotg device
3488 * @dev: Device to for which release is called
3489 *
3490 * Nothing to do as the resource is allocated using devm_ API.
3491 */
3492static void s3c_hsotg_release(struct device *dev)
3493{
3494}
3495
3496/**
3497 * s3c_hsotg_probe - probe function for hsotg driver 3447 * s3c_hsotg_probe - probe function for hsotg driver
3498 * @pdev: The platform information for the driver 3448 * @pdev: The platform information for the driver
3499 */ 3449 */
@@ -3517,7 +3467,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3517 } 3467 }
3518 3468
3519 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2); 3469 phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
3520 if (IS_ERR_OR_NULL(phy)) { 3470 if (IS_ERR(phy)) {
3521 /* Fallback for pdata */ 3471 /* Fallback for pdata */
3522 plat = pdev->dev.platform_data; 3472 plat = pdev->dev.platform_data;
3523 if (!plat) { 3473 if (!plat) {
@@ -3567,18 +3517,10 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3567 3517
3568 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq); 3518 dev_info(dev, "regs %p, irq %d\n", hsotg->regs, hsotg->irq);
3569 3519
3570 device_initialize(&hsotg->gadget.dev);
3571
3572 dev_set_name(&hsotg->gadget.dev, "gadget");
3573
3574 hsotg->gadget.max_speed = USB_SPEED_HIGH; 3520 hsotg->gadget.max_speed = USB_SPEED_HIGH;
3575 hsotg->gadget.ops = &s3c_hsotg_gadget_ops; 3521 hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
3576 hsotg->gadget.name = dev_name(dev); 3522 hsotg->gadget.name = dev_name(dev);
3577 3523
3578 hsotg->gadget.dev.parent = dev;
3579 hsotg->gadget.dev.dma_mask = dev->dma_mask;
3580 hsotg->gadget.dev.release = s3c_hsotg_release;
3581
3582 /* reset the system */ 3524 /* reset the system */
3583 3525
3584 clk_prepare_enable(hsotg->clk); 3526 clk_prepare_enable(hsotg->clk);
@@ -3658,12 +3600,6 @@ static int s3c_hsotg_probe(struct platform_device *pdev)
3658 3600
3659 s3c_hsotg_phy_disable(hsotg); 3601 s3c_hsotg_phy_disable(hsotg);
3660 3602
3661 ret = device_add(&hsotg->gadget.dev);
3662 if (ret) {
3663 put_device(&hsotg->gadget.dev);
3664 goto err_ep_mem;
3665 }
3666
3667 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget); 3603 ret = usb_add_gadget_udc(&pdev->dev, &hsotg->gadget);
3668 if (ret) 3604 if (ret)
3669 goto err_ep_mem; 3605 goto err_ep_mem;
@@ -3702,10 +3638,8 @@ static int s3c_hsotg_remove(struct platform_device *pdev)
3702 } 3638 }
3703 3639
3704 s3c_hsotg_phy_disable(hsotg); 3640 s3c_hsotg_phy_disable(hsotg);
3705
3706 clk_disable_unprepare(hsotg->clk); 3641 clk_disable_unprepare(hsotg->clk);
3707 3642
3708 device_unregister(&hsotg->gadget.dev);
3709 return 0; 3643 return 0;
3710} 3644}
3711 3645
diff --git a/drivers/usb/gadget/s3c-hsudc.c b/drivers/usb/gadget/s3c-hsudc.c
index 458965a1b138..b1f0771fbd3d 100644
--- a/drivers/usb/gadget/s3c-hsudc.c
+++ b/drivers/usb/gadget/s3c-hsudc.c
@@ -283,7 +283,6 @@ static void s3c_hsudc_nuke_ep(struct s3c_hsudc_ep *hsep, int status)
283/** 283/**
284 * s3c_hsudc_stop_activity - Stop activity on all endpoints. 284 * s3c_hsudc_stop_activity - Stop activity on all endpoints.
285 * @hsudc: Device controller for which EP activity is to be stopped. 285 * @hsudc: Device controller for which EP activity is to be stopped.
286 * @driver: Reference to the gadget driver which is currently active.
287 * 286 *
288 * All the endpoints are stopped and any pending transfer requests if any on 287 * All the endpoints are stopped and any pending transfer requests if any on
289 * the endpoint are terminated. 288 * the endpoint are terminated.
@@ -1154,7 +1153,6 @@ static int s3c_hsudc_start(struct usb_gadget *gadget,
1154 return -EBUSY; 1153 return -EBUSY;
1155 1154
1156 hsudc->driver = driver; 1155 hsudc->driver = driver;
1157 hsudc->gadget.dev.driver = &driver->driver;
1158 1156
1159 ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies), 1157 ret = regulator_bulk_enable(ARRAY_SIZE(hsudc->supplies),
1160 hsudc->supplies); 1158 hsudc->supplies);
@@ -1190,7 +1188,6 @@ err_otg:
1190 regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies); 1188 regulator_bulk_disable(ARRAY_SIZE(hsudc->supplies), hsudc->supplies);
1191err_supplies: 1189err_supplies:
1192 hsudc->driver = NULL; 1190 hsudc->driver = NULL;
1193 hsudc->gadget.dev.driver = NULL;
1194 return ret; 1191 return ret;
1195} 1192}
1196 1193
@@ -1208,7 +1205,6 @@ static int s3c_hsudc_stop(struct usb_gadget *gadget,
1208 1205
1209 spin_lock_irqsave(&hsudc->lock, flags); 1206 spin_lock_irqsave(&hsudc->lock, flags);
1210 hsudc->driver = NULL; 1207 hsudc->driver = NULL;
1211 hsudc->gadget.dev.driver = NULL;
1212 hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1208 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
1213 s3c_hsudc_uninit_phy(); 1209 s3c_hsudc_uninit_phy();
1214 1210
@@ -1303,15 +1299,10 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1303 1299
1304 spin_lock_init(&hsudc->lock); 1300 spin_lock_init(&hsudc->lock);
1305 1301
1306 dev_set_name(&hsudc->gadget.dev, "gadget");
1307
1308 hsudc->gadget.max_speed = USB_SPEED_HIGH; 1302 hsudc->gadget.max_speed = USB_SPEED_HIGH;
1309 hsudc->gadget.ops = &s3c_hsudc_gadget_ops; 1303 hsudc->gadget.ops = &s3c_hsudc_gadget_ops;
1310 hsudc->gadget.name = dev_name(dev); 1304 hsudc->gadget.name = dev_name(dev);
1311 hsudc->gadget.dev.parent = dev;
1312 hsudc->gadget.dev.dma_mask = dev->dma_mask;
1313 hsudc->gadget.ep0 = &hsudc->ep[0].ep; 1305 hsudc->gadget.ep0 = &hsudc->ep[0].ep;
1314
1315 hsudc->gadget.is_otg = 0; 1306 hsudc->gadget.is_otg = 0;
1316 hsudc->gadget.is_a_peripheral = 0; 1307 hsudc->gadget.is_a_peripheral = 0;
1317 hsudc->gadget.speed = USB_SPEED_UNKNOWN; 1308 hsudc->gadget.speed = USB_SPEED_UNKNOWN;
@@ -1345,12 +1336,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1345 disable_irq(hsudc->irq); 1336 disable_irq(hsudc->irq);
1346 local_irq_enable(); 1337 local_irq_enable();
1347 1338
1348 ret = device_register(&hsudc->gadget.dev);
1349 if (ret) {
1350 put_device(&hsudc->gadget.dev);
1351 goto err_add_device;
1352 }
1353
1354 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget); 1339 ret = usb_add_gadget_udc(&pdev->dev, &hsudc->gadget);
1355 if (ret) 1340 if (ret)
1356 goto err_add_udc; 1341 goto err_add_udc;
@@ -1359,7 +1344,6 @@ static int s3c_hsudc_probe(struct platform_device *pdev)
1359 1344
1360 return 0; 1345 return 0;
1361err_add_udc: 1346err_add_udc:
1362 device_unregister(&hsudc->gadget.dev);
1363err_add_device: 1347err_add_device:
1364 clk_disable(hsudc->uclk); 1348 clk_disable(hsudc->uclk);
1365err_res: 1349err_res:
diff --git a/drivers/usb/gadget/s3c2410_udc.c b/drivers/usb/gadget/s3c2410_udc.c
index 08f89652533b..d0e75e1b3ccb 100644
--- a/drivers/usb/gadget/s3c2410_udc.c
+++ b/drivers/usb/gadget/s3c2410_udc.c
@@ -1674,7 +1674,6 @@ static int s3c2410_udc_start(struct usb_gadget *g,
1674 1674
1675 /* Hook the driver */ 1675 /* Hook the driver */
1676 udc->driver = driver; 1676 udc->driver = driver;
1677 udc->gadget.dev.driver = &driver->driver;
1678 1677
1679 /* Enable udc */ 1678 /* Enable udc */
1680 s3c2410_udc_enable(udc); 1679 s3c2410_udc_enable(udc);
@@ -1824,17 +1823,6 @@ static int s3c2410_udc_probe(struct platform_device *pdev)
1824 goto err_mem; 1823 goto err_mem;
1825 } 1824 }
1826 1825
1827 device_initialize(&udc->gadget.dev);
1828 udc->gadget.dev.parent = &pdev->dev;
1829 udc->gadget.dev.dma_mask = pdev->dev.dma_mask;
1830
1831 /* Bind the driver */
1832 retval = device_add(&udc->gadget.dev);
1833 if (retval) {
1834 dev_err(&udc->gadget.dev, "Error in device_add() : %d\n", retval);
1835 goto err_device_add;
1836 }
1837
1838 the_controller = udc; 1826 the_controller = udc;
1839 platform_set_drvdata(pdev, udc); 1827 platform_set_drvdata(pdev, udc);
1840 1828
@@ -1923,8 +1911,6 @@ err_gpio_claim:
1923err_int: 1911err_int:
1924 free_irq(IRQ_USBD, udc); 1912 free_irq(IRQ_USBD, udc);
1925err_map: 1913err_map:
1926 device_unregister(&udc->gadget.dev);
1927err_device_add:
1928 iounmap(base_addr); 1914 iounmap(base_addr);
1929err_mem: 1915err_mem:
1930 release_mem_region(rsrc_start, rsrc_len); 1916 release_mem_region(rsrc_start, rsrc_len);
@@ -1946,7 +1932,6 @@ static int s3c2410_udc_remove(struct platform_device *pdev)
1946 return -EBUSY; 1932 return -EBUSY;
1947 1933
1948 usb_del_gadget_udc(&udc->gadget); 1934 usb_del_gadget_udc(&udc->gadget);
1949 device_unregister(&udc->gadget.dev);
1950 debugfs_remove(udc->regs_info); 1935 debugfs_remove(udc->regs_info);
1951 1936
1952 if (udc_info && !udc_info->udc_command && 1937 if (udc_info && !udc_info->udc_command &&
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 68d7bb06ebcb..1f5f978d35d5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/module.h>
15#include <linux/tty.h> 16#include <linux/tty.h>
16#include <linux/tty_flip.h> 17#include <linux/tty_flip.h>
17 18
@@ -28,18 +29,6 @@
28#define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR 29#define GS_VERSION_NAME GS_LONG_NAME " " GS_VERSION_STR
29 30
30/*-------------------------------------------------------------------------*/ 31/*-------------------------------------------------------------------------*/
31
32/*
33 * Kbuild is not very cooperative with respect to linking separately
34 * compiled library objects into one module. So for now we won't use
35 * separate compilation ... ensuring init/exit sections work to shrink
36 * the runtime footprint, and giving us at least some parts of what
37 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
38 */
39#include "f_obex.c"
40#include "f_serial.c"
41
42/*-------------------------------------------------------------------------*/
43USB_GADGET_COMPOSITE_OPTIONS(); 32USB_GADGET_COMPOSITE_OPTIONS();
44 33
45/* Thanks to NetChip Technologies for donating this product ID. 34/* Thanks to NetChip Technologies for donating this product ID.
@@ -126,27 +115,6 @@ module_param(n_ports, uint, 0);
126MODULE_PARM_DESC(n_ports, "number of ports to create, default=1"); 115MODULE_PARM_DESC(n_ports, "number of ports to create, default=1");
127 116
128/*-------------------------------------------------------------------------*/ 117/*-------------------------------------------------------------------------*/
129static unsigned char tty_lines[MAX_U_SERIAL_PORTS];
130
131static int __init serial_bind_obex_config(struct usb_configuration *c)
132{
133 unsigned i;
134 int status = 0;
135
136 for (i = 0; i < n_ports && status == 0; i++)
137 status = obex_bind_config(c, tty_lines[i]);
138 return status;
139}
140
141static int __init serial_bind_gser_config(struct usb_configuration *c)
142{
143 unsigned i;
144 int status = 0;
145
146 for (i = 0; i < n_ports && status == 0; i++)
147 status = gser_bind_config(c, tty_lines[i]);
148 return status;
149}
150 118
151static struct usb_configuration serial_config_driver = { 119static struct usb_configuration serial_config_driver = {
152 /* .label = f(use_acm) */ 120 /* .label = f(use_acm) */
@@ -169,15 +137,12 @@ static int serial_register_ports(struct usb_composite_dev *cdev,
169 goto out; 137 goto out;
170 138
171 for (i = 0; i < n_ports; i++) { 139 for (i = 0; i < n_ports; i++) {
172 struct f_serial_opts *opts;
173 140
174 fi_serial[i] = usb_get_function_instance(f_name); 141 fi_serial[i] = usb_get_function_instance(f_name);
175 if (IS_ERR(fi_serial[i])) { 142 if (IS_ERR(fi_serial[i])) {
176 ret = PTR_ERR(fi_serial[i]); 143 ret = PTR_ERR(fi_serial[i]);
177 goto fail; 144 goto fail;
178 } 145 }
179 opts = container_of(fi_serial[i], struct f_serial_opts, func_inst);
180 opts->port_num = tty_lines[i];
181 146
182 f_serial[i] = usb_get_function(fi_serial[i]); 147 f_serial[i] = usb_get_function(fi_serial[i]);
183 if (IS_ERR(f_serial[i])) { 148 if (IS_ERR(f_serial[i])) {
@@ -212,13 +177,6 @@ out:
212static int __init gs_bind(struct usb_composite_dev *cdev) 177static int __init gs_bind(struct usb_composite_dev *cdev)
213{ 178{
214 int status; 179 int status;
215 int cur_line;
216
217 for (cur_line = 0; cur_line < n_ports; cur_line++) {
218 status = gserial_alloc_line(&tty_lines[cur_line]);
219 if (status)
220 goto fail;
221 }
222 180
223 /* Allocate string descriptor numbers ... note that string 181 /* Allocate string descriptor numbers ... note that string
224 * contents can be overridden by the composite_dev glue. 182 * contents can be overridden by the composite_dev glue.
@@ -243,11 +201,12 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
243 "acm"); 201 "acm");
244 usb_ep_autoconfig_reset(cdev->gadget); 202 usb_ep_autoconfig_reset(cdev->gadget);
245 } else if (use_obex) 203 } else if (use_obex)
246 status = usb_add_config(cdev, &serial_config_driver, 204 status = serial_register_ports(cdev, &serial_config_driver,
247 serial_bind_obex_config); 205 "obex");
248 else 206 else {
249 status = usb_add_config(cdev, &serial_config_driver, 207 status = serial_register_ports(cdev, &serial_config_driver,
250 serial_bind_gser_config); 208 "gser");
209 }
251 if (status < 0) 210 if (status < 0)
252 goto fail; 211 goto fail;
253 212
@@ -257,9 +216,6 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
257 return 0; 216 return 0;
258 217
259fail: 218fail:
260 cur_line--;
261 while (cur_line >= 0)
262 gserial_free_line(tty_lines[cur_line--]);
263 return status; 219 return status;
264} 220}
265 221
@@ -270,7 +226,6 @@ static int gs_unbind(struct usb_composite_dev *cdev)
270 for (i = 0; i < n_ports; i++) { 226 for (i = 0; i < n_ports; i++) {
271 usb_put_function(f_serial[i]); 227 usb_put_function(f_serial[i]);
272 usb_put_function_instance(fi_serial[i]); 228 usb_put_function_instance(fi_serial[i]);
273 gserial_free_line(tty_lines[i]);
274 } 229 }
275 return 0; 230 return 0;
276} 231}
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index a0aa721d8b21..4b76124ce96b 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -50,7 +50,6 @@
50 50
51struct eth_dev { 51struct eth_dev {
52 /* lock is held while accessing port_usb 52 /* lock is held while accessing port_usb
53 * or updating its backlink port_usb->ioport
54 */ 53 */
55 spinlock_t lock; 54 spinlock_t lock;
56 struct gether *port_usb; 55 struct gether *port_usb;
@@ -729,8 +728,6 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
729 return 1; 728 return 1;
730} 729}
731 730
732static struct eth_dev *the_dev;
733
734static const struct net_device_ops eth_netdev_ops = { 731static const struct net_device_ops eth_netdev_ops = {
735 .ndo_open = eth_open, 732 .ndo_open = eth_open,
736 .ndo_stop = eth_stop, 733 .ndo_stop = eth_stop,
@@ -758,19 +755,16 @@ static struct device_type gadget_type = {
758 * 755 *
759 * Returns negative errno, or zero on success 756 * Returns negative errno, or zero on success
760 */ 757 */
761int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 758struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
762 const char *netname) 759 const char *netname)
763{ 760{
764 struct eth_dev *dev; 761 struct eth_dev *dev;
765 struct net_device *net; 762 struct net_device *net;
766 int status; 763 int status;
767 764
768 if (the_dev)
769 return -EBUSY;
770
771 net = alloc_etherdev(sizeof *dev); 765 net = alloc_etherdev(sizeof *dev);
772 if (!net) 766 if (!net)
773 return -ENOMEM; 767 return ERR_PTR(-ENOMEM);
774 768
775 dev = netdev_priv(net); 769 dev = netdev_priv(net);
776 spin_lock_init(&dev->lock); 770 spin_lock_init(&dev->lock);
@@ -807,12 +801,11 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
807 if (status < 0) { 801 if (status < 0) {
808 dev_dbg(&g->dev, "register_netdev failed, %d\n", status); 802 dev_dbg(&g->dev, "register_netdev failed, %d\n", status);
809 free_netdev(net); 803 free_netdev(net);
804 dev = ERR_PTR(status);
810 } else { 805 } else {
811 INFO(dev, "MAC %pM\n", net->dev_addr); 806 INFO(dev, "MAC %pM\n", net->dev_addr);
812 INFO(dev, "HOST MAC %pM\n", dev->host_mac); 807 INFO(dev, "HOST MAC %pM\n", dev->host_mac);
813 808
814 the_dev = dev;
815
816 /* two kinds of host-initiated state changes: 809 /* two kinds of host-initiated state changes:
817 * - iff DATA transfer is active, carrier is "on" 810 * - iff DATA transfer is active, carrier is "on"
818 * - tx queueing enabled if open *and* carrier is "on" 811 * - tx queueing enabled if open *and* carrier is "on"
@@ -820,7 +813,7 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
820 netif_carrier_off(net); 813 netif_carrier_off(net);
821 } 814 }
822 815
823 return status; 816 return dev;
824} 817}
825 818
826/** 819/**
@@ -829,19 +822,16 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
829 * 822 *
830 * This is called to free all resources allocated by @gether_setup(). 823 * This is called to free all resources allocated by @gether_setup().
831 */ 824 */
832void gether_cleanup(void) 825void gether_cleanup(struct eth_dev *dev)
833{ 826{
834 if (!the_dev) 827 if (!dev)
835 return; 828 return;
836 829
837 unregister_netdev(the_dev->net); 830 unregister_netdev(dev->net);
838 flush_work(&the_dev->work); 831 flush_work(&dev->work);
839 free_netdev(the_dev->net); 832 free_netdev(dev->net);
840
841 the_dev = NULL;
842} 833}
843 834
844
845/** 835/**
846 * gether_connect - notify network layer that USB link is active 836 * gether_connect - notify network layer that USB link is active
847 * @link: the USB link, set up with endpoints, descriptors matching 837 * @link: the USB link, set up with endpoints, descriptors matching
@@ -860,7 +850,7 @@ void gether_cleanup(void)
860 */ 850 */
861struct net_device *gether_connect(struct gether *link) 851struct net_device *gether_connect(struct gether *link)
862{ 852{
863 struct eth_dev *dev = the_dev; 853 struct eth_dev *dev = link->ioport;
864 int result = 0; 854 int result = 0;
865 855
866 if (!dev) 856 if (!dev)
@@ -895,7 +885,6 @@ struct net_device *gether_connect(struct gether *link)
895 885
896 spin_lock(&dev->lock); 886 spin_lock(&dev->lock);
897 dev->port_usb = link; 887 dev->port_usb = link;
898 link->ioport = dev;
899 if (netif_running(dev->net)) { 888 if (netif_running(dev->net)) {
900 if (link->open) 889 if (link->open)
901 link->open(link); 890 link->open(link);
@@ -989,6 +978,5 @@ void gether_disconnect(struct gether *link)
989 978
990 spin_lock(&dev->lock); 979 spin_lock(&dev->lock);
991 dev->port_usb = NULL; 980 dev->port_usb = NULL;
992 link->ioport = NULL;
993 spin_unlock(&dev->lock); 981 spin_unlock(&dev->lock);
994} 982}
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 6f4a1623d854..02522338a708 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -21,6 +21,7 @@
21 21
22#include "gadget_chips.h" 22#include "gadget_chips.h"
23 23
24struct eth_dev;
24 25
25/* 26/*
26 * This represents the USB side of an "ethernet" link, managed by a USB 27 * This represents the USB side of an "ethernet" link, managed by a USB
@@ -70,7 +71,7 @@ struct gether {
70 |USB_CDC_PACKET_TYPE_DIRECTED) 71 |USB_CDC_PACKET_TYPE_DIRECTED)
71 72
72/* variant of gether_setup that allows customizing network device name */ 73/* variant of gether_setup that allows customizing network device name */
73int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN], 74struct eth_dev *gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
74 const char *netname); 75 const char *netname);
75 76
76/* netdev setup/teardown as directed by the gadget driver */ 77/* netdev setup/teardown as directed by the gadget driver */
@@ -86,12 +87,13 @@ int gether_setup_name(struct usb_gadget *g, u8 ethaddr[ETH_ALEN],
86 * 87 *
87 * Returns negative errno, or zero on success 88 * Returns negative errno, or zero on success
88 */ 89 */
89static inline int gether_setup(struct usb_gadget *g, u8 ethaddr[ETH_ALEN]) 90static inline struct eth_dev *gether_setup(struct usb_gadget *g,
91 u8 ethaddr[ETH_ALEN])
90{ 92{
91 return gether_setup_name(g, ethaddr, "usb"); 93 return gether_setup_name(g, ethaddr, "usb");
92} 94}
93 95
94void gether_cleanup(void); 96void gether_cleanup(struct eth_dev *dev);
95 97
96/* connect/disconnect is handled by individual functions */ 98/* connect/disconnect is handled by individual functions */
97struct net_device *gether_connect(struct gether *); 99struct net_device *gether_connect(struct gether *);
@@ -111,21 +113,24 @@ static inline bool can_support_ecm(struct usb_gadget *gadget)
111} 113}
112 114
113/* each configuration may bind one instance of an ethernet link */ 115/* each configuration may bind one instance of an ethernet link */
114int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 116int geth_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
115int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 117 struct eth_dev *dev);
116int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN]); 118int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
117int eem_bind_config(struct usb_configuration *c); 119 struct eth_dev *dev);
120int ncm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
121 struct eth_dev *dev);
122int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev);
118 123
119#ifdef USB_ETH_RNDIS 124#ifdef USB_ETH_RNDIS
120 125
121int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 126int rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
122 u32 vendorID, const char *manufacturer); 127 u32 vendorID, const char *manufacturer, struct eth_dev *dev);
123 128
124#else 129#else
125 130
126static inline int 131static inline int
127rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN], 132rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
128 u32 vendorID, const char *manufacturer) 133 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
129{ 134{
130 return 0; 135 return 0;
131} 136}
@@ -145,9 +150,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
145 * for calling @gether_cleanup() before module unload. 150 * for calling @gether_cleanup() before module unload.
146 */ 151 */
147static inline int rndis_bind_config(struct usb_configuration *c, 152static inline int rndis_bind_config(struct usb_configuration *c,
148 u8 ethaddr[ETH_ALEN]) 153 u8 ethaddr[ETH_ALEN], struct eth_dev *dev)
149{ 154{
150 return rndis_bind_config_vendor(c, ethaddr, 0, NULL); 155 return rndis_bind_config_vendor(c, ethaddr, 0, NULL, dev);
151} 156}
152 157
153 158
diff --git a/drivers/usb/gadget/u_serial.h b/drivers/usb/gadget/u_serial.h
index 66ce73a00509..c20210c0babd 100644
--- a/drivers/usb/gadget/u_serial.h
+++ b/drivers/usb/gadget/u_serial.h
@@ -65,7 +65,6 @@ int gserial_connect(struct gserial *, u8 port_num);
65void gserial_disconnect(struct gserial *); 65void gserial_disconnect(struct gserial *);
66 66
67/* functions are bound to configurations by a config or gadget driver */ 67/* functions are bound to configurations by a config or gadget driver */
68int acm_bind_config(struct usb_configuration *c, u8 port_num);
69int gser_bind_config(struct usb_configuration *c, u8 port_num); 68int gser_bind_config(struct usb_configuration *c, u8 port_num);
70int obex_bind_config(struct usb_configuration *c, u8 port_num); 69int obex_bind_config(struct usb_configuration *c, u8 port_num);
71 70
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index f8f62c3ed65e..ffd8fa541101 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -101,6 +101,16 @@ EXPORT_SYMBOL_GPL(usb_gadget_unmap_request);
101 101
102/* ------------------------------------------------------------------------- */ 102/* ------------------------------------------------------------------------- */
103 103
104void usb_gadget_set_state(struct usb_gadget *gadget,
105 enum usb_device_state state)
106{
107 gadget->state = state;
108 sysfs_notify(&gadget->dev.kobj, NULL, "status");
109}
110EXPORT_SYMBOL_GPL(usb_gadget_set_state);
111
112/* ------------------------------------------------------------------------- */
113
104/** 114/**
105 * usb_gadget_udc_start - tells usb device controller to start up 115 * usb_gadget_udc_start - tells usb device controller to start up
106 * @gadget: The gadget we want to get started 116 * @gadget: The gadget we want to get started
@@ -156,15 +166,23 @@ static void usb_udc_release(struct device *dev)
156} 166}
157 167
158static const struct attribute_group *usb_udc_attr_groups[]; 168static const struct attribute_group *usb_udc_attr_groups[];
169
170static void usb_udc_nop_release(struct device *dev)
171{
172 dev_vdbg(dev, "%s\n", __func__);
173}
174
159/** 175/**
160 * usb_add_gadget_udc - adds a new gadget to the udc class driver list 176 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
161 * @parent: the parent device to this udc. Usually the controller 177 * @parent: the parent device to this udc. Usually the controller driver's
162 * driver's device. 178 * device.
163 * @gadget: the gadget to be added to the list 179 * @gadget: the gadget to be added to the list.
180 * @release: a gadget release function.
164 * 181 *
165 * Returns zero on success, negative errno otherwise. 182 * Returns zero on success, negative errno otherwise.
166 */ 183 */
167int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) 184int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget,
185 void (*release)(struct device *dev))
168{ 186{
169 struct usb_udc *udc; 187 struct usb_udc *udc;
170 int ret = -ENOMEM; 188 int ret = -ENOMEM;
@@ -173,6 +191,22 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
173 if (!udc) 191 if (!udc)
174 goto err1; 192 goto err1;
175 193
194 dev_set_name(&gadget->dev, "gadget");
195 gadget->dev.parent = parent;
196
197 dma_set_coherent_mask(&gadget->dev, parent->coherent_dma_mask);
198 gadget->dev.dma_parms = parent->dma_parms;
199 gadget->dev.dma_mask = parent->dma_mask;
200
201 if (release)
202 gadget->dev.release = release;
203 else
204 gadget->dev.release = usb_udc_nop_release;
205
206 ret = device_register(&gadget->dev);
207 if (ret)
208 goto err2;
209
176 device_initialize(&udc->dev); 210 device_initialize(&udc->dev);
177 udc->dev.release = usb_udc_release; 211 udc->dev.release = usb_udc_release;
178 udc->dev.class = udc_class; 212 udc->dev.class = udc_class;
@@ -180,7 +214,7 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
180 udc->dev.parent = parent; 214 udc->dev.parent = parent;
181 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); 215 ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
182 if (ret) 216 if (ret)
183 goto err2; 217 goto err3;
184 218
185 udc->gadget = gadget; 219 udc->gadget = gadget;
186 220
@@ -189,21 +223,42 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
189 223
190 ret = device_add(&udc->dev); 224 ret = device_add(&udc->dev);
191 if (ret) 225 if (ret)
192 goto err3; 226 goto err4;
227
228 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED);
193 229
194 mutex_unlock(&udc_lock); 230 mutex_unlock(&udc_lock);
195 231
196 return 0; 232 return 0;
197err3: 233
234err4:
198 list_del(&udc->list); 235 list_del(&udc->list);
199 mutex_unlock(&udc_lock); 236 mutex_unlock(&udc_lock);
200 237
201err2: 238err3:
202 put_device(&udc->dev); 239 put_device(&udc->dev);
203 240
241err2:
242 put_device(&gadget->dev);
243 kfree(udc);
244
204err1: 245err1:
205 return ret; 246 return ret;
206} 247}
248EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);
249
250/**
251 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
252 * @parent: the parent device to this udc. Usually the controller
253 * driver's device.
254 * @gadget: the gadget to be added to the list
255 *
256 * Returns zero on success, negative errno otherwise.
257 */
258int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
259{
260 return usb_add_gadget_udc_release(parent, gadget, NULL);
261}
207EXPORT_SYMBOL_GPL(usb_add_gadget_udc); 262EXPORT_SYMBOL_GPL(usb_add_gadget_udc);
208 263
209static void usb_gadget_remove_driver(struct usb_udc *udc) 264static void usb_gadget_remove_driver(struct usb_udc *udc)
@@ -220,6 +275,7 @@ static void usb_gadget_remove_driver(struct usb_udc *udc)
220 275
221 udc->driver = NULL; 276 udc->driver = NULL;
222 udc->dev.driver = NULL; 277 udc->dev.driver = NULL;
278 udc->gadget->dev.driver = NULL;
223} 279}
224 280
225/** 281/**
@@ -254,6 +310,7 @@ found:
254 310
255 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); 311 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
256 device_unregister(&udc->dev); 312 device_unregister(&udc->dev);
313 device_unregister(&gadget->dev);
257} 314}
258EXPORT_SYMBOL_GPL(usb_del_gadget_udc); 315EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
259 316
@@ -268,6 +325,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
268 325
269 udc->driver = driver; 326 udc->driver = driver;
270 udc->dev.driver = &driver->driver; 327 udc->dev.driver = &driver->driver;
328 udc->gadget->dev.driver = &driver->driver;
271 329
272 ret = driver->bind(udc->gadget, driver); 330 ret = driver->bind(udc->gadget, driver);
273 if (ret) 331 if (ret)
@@ -286,6 +344,7 @@ err1:
286 udc->driver->function, ret); 344 udc->driver->function, ret);
287 udc->driver = NULL; 345 udc->driver = NULL;
288 udc->dev.driver = NULL; 346 udc->dev.driver = NULL;
347 udc->gadget->dev.driver = NULL;
289 return ret; 348 return ret;
290} 349}
291 350
@@ -395,6 +454,16 @@ static ssize_t usb_udc_softconn_store(struct device *dev,
395} 454}
396static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store); 455static DEVICE_ATTR(soft_connect, S_IWUSR, NULL, usb_udc_softconn_store);
397 456
457static ssize_t usb_gadget_state_show(struct device *dev,
458 struct device_attribute *attr, char *buf)
459{
460 struct usb_udc *udc = container_of(dev, struct usb_udc, dev);
461 struct usb_gadget *gadget = udc->gadget;
462
463 return sprintf(buf, "%s\n", usb_state_string(gadget->state));
464}
465static DEVICE_ATTR(state, S_IRUGO, usb_gadget_state_show, NULL);
466
398#define USB_UDC_SPEED_ATTR(name, param) \ 467#define USB_UDC_SPEED_ATTR(name, param) \
399ssize_t usb_udc_##param##_show(struct device *dev, \ 468ssize_t usb_udc_##param##_show(struct device *dev, \
400 struct device_attribute *attr, char *buf) \ 469 struct device_attribute *attr, char *buf) \
@@ -403,7 +472,7 @@ ssize_t usb_udc_##param##_show(struct device *dev, \
403 return snprintf(buf, PAGE_SIZE, "%s\n", \ 472 return snprintf(buf, PAGE_SIZE, "%s\n", \
404 usb_speed_string(udc->gadget->param)); \ 473 usb_speed_string(udc->gadget->param)); \
405} \ 474} \
406static DEVICE_ATTR(name, S_IRUSR, usb_udc_##param##_show, NULL) 475static DEVICE_ATTR(name, S_IRUGO, usb_udc_##param##_show, NULL)
407 476
408static USB_UDC_SPEED_ATTR(current_speed, speed); 477static USB_UDC_SPEED_ATTR(current_speed, speed);
409static USB_UDC_SPEED_ATTR(maximum_speed, max_speed); 478static USB_UDC_SPEED_ATTR(maximum_speed, max_speed);
@@ -428,6 +497,7 @@ static USB_UDC_ATTR(a_alt_hnp_support);
428static struct attribute *usb_udc_attrs[] = { 497static struct attribute *usb_udc_attrs[] = {
429 &dev_attr_srp.attr, 498 &dev_attr_srp.attr,
430 &dev_attr_soft_connect.attr, 499 &dev_attr_soft_connect.attr,
500 &dev_attr_state.attr,
431 &dev_attr_current_speed.attr, 501 &dev_attr_current_speed.attr,
432 &dev_attr_maximum_speed.attr, 502 &dev_attr_maximum_speed.attr,
433 503
diff --git a/drivers/usb/gadget/uvc.h b/drivers/usb/gadget/uvc.h
index 93b0c1191115..817e9e19cecf 100644
--- a/drivers/usb/gadget/uvc.h
+++ b/drivers/usb/gadget/uvc.h
@@ -98,8 +98,6 @@ extern unsigned int uvc_gadget_trace_param;
98#define DRIVER_VERSION "0.1.0" 98#define DRIVER_VERSION "0.1.0"
99#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0) 99#define DRIVER_VERSION_NUMBER KERNEL_VERSION(0, 1, 0)
100 100
101#define DMA_ADDR_INVALID (~(dma_addr_t)0)
102
103#define UVC_NUM_REQUESTS 4 101#define UVC_NUM_REQUESTS 4
104#define UVC_MAX_REQUEST_SIZE 64 102#define UVC_MAX_REQUEST_SIZE 64
105#define UVC_MAX_EVENTS 4 103#define UVC_MAX_EVENTS 4
@@ -190,6 +188,7 @@ struct uvc_file_handle
190 * Functions 188 * Functions
191 */ 189 */
192 190
191extern void uvc_function_setup_continue(struct uvc_device *uvc);
193extern void uvc_endpoint_stream(struct uvc_device *dev); 192extern void uvc_endpoint_stream(struct uvc_device *dev);
194 193
195extern void uvc_function_connect(struct uvc_device *uvc); 194extern void uvc_function_connect(struct uvc_device *uvc);
diff --git a/drivers/usb/gadget/uvc_queue.c b/drivers/usb/gadget/uvc_queue.c
index 104ae9c81251..7ce27e35550b 100644
--- a/drivers/usb/gadget/uvc_queue.c
+++ b/drivers/usb/gadget/uvc_queue.c
@@ -10,6 +10,7 @@
10 * (at your option) any later version. 10 * (at your option) any later version.
11 */ 11 */
12 12
13#include <linux/atomic.h>
13#include <linux/kernel.h> 14#include <linux/kernel.h>
14#include <linux/mm.h> 15#include <linux/mm.h>
15#include <linux/list.h> 16#include <linux/list.h>
@@ -18,7 +19,8 @@
18#include <linux/videodev2.h> 19#include <linux/videodev2.h>
19#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
20#include <linux/wait.h> 21#include <linux/wait.h>
21#include <linux/atomic.h> 22
23#include <media/videobuf2-vmalloc.h>
22 24
23#include "uvc.h" 25#include "uvc.h"
24 26
@@ -28,330 +30,175 @@
28 * Video queues is initialized by uvc_queue_init(). The function performs 30 * Video queues is initialized by uvc_queue_init(). The function performs
29 * basic initialization of the uvc_video_queue struct and never fails. 31 * basic initialization of the uvc_video_queue struct and never fails.
30 * 32 *
31 * Video buffer allocation and freeing are performed by uvc_alloc_buffers and 33 * Video buffers are managed by videobuf2. The driver uses a mutex to protect
32 * uvc_free_buffers respectively. The former acquires the video queue lock, 34 * the videobuf2 queue operations by serializing calls to videobuf2 and a
33 * while the later must be called with the lock held (so that allocation can 35 * spinlock to protect the IRQ queue that holds the buffers to be processed by
34 * free previously allocated buffers). Trying to free buffers that are mapped 36 * the driver.
35 * to user space will return -EBUSY.
36 *
37 * Video buffers are managed using two queues. However, unlike most USB video
38 * drivers that use an in queue and an out queue, we use a main queue to hold
39 * all queued buffers (both 'empty' and 'done' buffers), and an irq queue to
40 * hold empty buffers. This design (copied from video-buf) minimizes locking
41 * in interrupt, as only one queue is shared between interrupt and user
42 * contexts.
43 *
44 * Use cases
45 * ---------
46 *
47 * Unless stated otherwise, all operations that modify the irq buffers queue
48 * are protected by the irq spinlock.
49 *
50 * 1. The user queues the buffers, starts streaming and dequeues a buffer.
51 *
52 * The buffers are added to the main and irq queues. Both operations are
53 * protected by the queue lock, and the later is protected by the irq
54 * spinlock as well.
55 *
56 * The completion handler fetches a buffer from the irq queue and fills it
57 * with video data. If no buffer is available (irq queue empty), the handler
58 * returns immediately.
59 *
60 * When the buffer is full, the completion handler removes it from the irq
61 * queue, marks it as ready (UVC_BUF_STATE_DONE) and wakes its wait queue.
62 * At that point, any process waiting on the buffer will be woken up. If a
63 * process tries to dequeue a buffer after it has been marked ready, the
64 * dequeing will succeed immediately.
65 *
66 * 2. Buffers are queued, user is waiting on a buffer and the device gets
67 * disconnected.
68 *
69 * When the device is disconnected, the kernel calls the completion handler
70 * with an appropriate status code. The handler marks all buffers in the
71 * irq queue as being erroneous (UVC_BUF_STATE_ERROR) and wakes them up so
72 * that any process waiting on a buffer gets woken up.
73 *
74 * Waking up up the first buffer on the irq list is not enough, as the
75 * process waiting on the buffer might restart the dequeue operation
76 * immediately.
77 *
78 */ 37 */
79 38
80static void 39/* -----------------------------------------------------------------------------
81uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) 40 * videobuf2 queue operations
82{
83 mutex_init(&queue->mutex);
84 spin_lock_init(&queue->irqlock);
85 INIT_LIST_HEAD(&queue->mainqueue);
86 INIT_LIST_HEAD(&queue->irqqueue);
87 queue->type = type;
88}
89
90/*
91 * Free the video buffers.
92 *
93 * This function must be called with the queue lock held.
94 */ 41 */
95static int uvc_free_buffers(struct uvc_video_queue *queue) 42
43static int uvc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
44 unsigned int *nbuffers, unsigned int *nplanes,
45 unsigned int sizes[], void *alloc_ctxs[])
96{ 46{
97 unsigned int i; 47 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
48 struct uvc_video *video = container_of(queue, struct uvc_video, queue);
98 49
99 for (i = 0; i < queue->count; ++i) { 50 if (*nbuffers > UVC_MAX_VIDEO_BUFFERS)
100 if (queue->buffer[i].vma_use_count != 0) 51 *nbuffers = UVC_MAX_VIDEO_BUFFERS;
101 return -EBUSY;
102 }
103 52
104 if (queue->count) { 53 *nplanes = 1;
105 vfree(queue->mem); 54
106 queue->count = 0; 55 sizes[0] = video->imagesize;
107 }
108 56
109 return 0; 57 return 0;
110} 58}
111 59
112/* 60static int uvc_buffer_prepare(struct vb2_buffer *vb)
113 * Allocate the video buffers.
114 *
115 * Pages are reserved to make sure they will not be swapped, as they will be
116 * filled in the URB completion handler.
117 *
118 * Buffers will be individually mapped, so they must all be page aligned.
119 */
120static int
121uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
122 unsigned int buflength)
123{ 61{
124 unsigned int bufsize = PAGE_ALIGN(buflength); 62 struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
125 unsigned int i; 63 struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
126 void *mem = NULL;
127 int ret;
128 64
129 if (nbuffers > UVC_MAX_VIDEO_BUFFERS) 65 if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
130 nbuffers = UVC_MAX_VIDEO_BUFFERS; 66 vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) {
67 uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
68 return -EINVAL;
69 }
131 70
132 mutex_lock(&queue->mutex); 71 if (unlikely(queue->flags & UVC_QUEUE_DISCONNECTED))
72 return -ENODEV;
133 73
134 if ((ret = uvc_free_buffers(queue)) < 0) 74 buf->state = UVC_BUF_STATE_QUEUED;
135 goto done; 75 buf->mem = vb2_plane_vaddr(vb, 0);
76 buf->length = vb2_plane_size(vb, 0);
77 if (vb->v4l2_buf.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
78 buf->bytesused = 0;
79 else
80 buf->bytesused = vb2_get_plane_payload(vb, 0);
136 81
137 /* Bail out if no buffers should be allocated. */ 82 return 0;
138 if (nbuffers == 0) 83}
139 goto done;
140 84
141 /* Decrement the number of buffers until allocation succeeds. */ 85static void uvc_buffer_queue(struct vb2_buffer *vb)
142 for (; nbuffers > 0; --nbuffers) { 86{
143 mem = vmalloc_32(nbuffers * bufsize); 87 struct uvc_video_queue *queue = vb2_get_drv_priv(vb->vb2_queue);
144 if (mem != NULL) 88 struct uvc_buffer *buf = container_of(vb, struct uvc_buffer, buf);
145 break; 89 unsigned long flags;
146 }
147 90
148 if (mem == NULL) { 91 spin_lock_irqsave(&queue->irqlock, flags);
149 ret = -ENOMEM;
150 goto done;
151 }
152 92
153 for (i = 0; i < nbuffers; ++i) { 93 if (likely(!(queue->flags & UVC_QUEUE_DISCONNECTED))) {
154 memset(&queue->buffer[i], 0, sizeof queue->buffer[i]); 94 list_add_tail(&buf->queue, &queue->irqqueue);
155 queue->buffer[i].buf.index = i; 95 } else {
156 queue->buffer[i].buf.m.offset = i * bufsize; 96 /* If the device is disconnected return the buffer to userspace
157 queue->buffer[i].buf.length = buflength; 97 * directly. The next QBUF call will fail with -ENODEV.
158 queue->buffer[i].buf.type = queue->type; 98 */
159 queue->buffer[i].buf.sequence = 0; 99 buf->state = UVC_BUF_STATE_ERROR;
160 queue->buffer[i].buf.field = V4L2_FIELD_NONE; 100 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
161 queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
162 queue->buffer[i].buf.flags = 0;
163 init_waitqueue_head(&queue->buffer[i].wait);
164 } 101 }
165 102
166 queue->mem = mem; 103 spin_unlock_irqrestore(&queue->irqlock, flags);
167 queue->count = nbuffers;
168 queue->buf_size = bufsize;
169 ret = nbuffers;
170
171done:
172 mutex_unlock(&queue->mutex);
173 return ret;
174} 104}
175 105
176static void __uvc_query_buffer(struct uvc_buffer *buf, 106static struct vb2_ops uvc_queue_qops = {
177 struct v4l2_buffer *v4l2_buf) 107 .queue_setup = uvc_queue_setup,
178{ 108 .buf_prepare = uvc_buffer_prepare,
179 memcpy(v4l2_buf, &buf->buf, sizeof *v4l2_buf); 109 .buf_queue = uvc_buffer_queue,
180 110};
181 if (buf->vma_use_count)
182 v4l2_buf->flags |= V4L2_BUF_FLAG_MAPPED;
183
184 switch (buf->state) {
185 case UVC_BUF_STATE_ERROR:
186 case UVC_BUF_STATE_DONE:
187 v4l2_buf->flags |= V4L2_BUF_FLAG_DONE;
188 break;
189 case UVC_BUF_STATE_QUEUED:
190 case UVC_BUF_STATE_ACTIVE:
191 v4l2_buf->flags |= V4L2_BUF_FLAG_QUEUED;
192 break;
193 case UVC_BUF_STATE_IDLE:
194 default:
195 break;
196 }
197}
198 111
199static int 112static int uvc_queue_init(struct uvc_video_queue *queue,
200uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) 113 enum v4l2_buf_type type)
201{ 114{
202 int ret = 0; 115 int ret;
203 116
204 mutex_lock(&queue->mutex); 117 queue->queue.type = type;
205 if (v4l2_buf->index >= queue->count) { 118 queue->queue.io_modes = VB2_MMAP | VB2_USERPTR;
206 ret = -EINVAL; 119 queue->queue.drv_priv = queue;
207 goto done; 120 queue->queue.buf_struct_size = sizeof(struct uvc_buffer);
208 } 121 queue->queue.ops = &uvc_queue_qops;
122 queue->queue.mem_ops = &vb2_vmalloc_memops;
123 ret = vb2_queue_init(&queue->queue);
124 if (ret)
125 return ret;
126
127 mutex_init(&queue->mutex);
128 spin_lock_init(&queue->irqlock);
129 INIT_LIST_HEAD(&queue->irqqueue);
130 queue->flags = 0;
209 131
210 __uvc_query_buffer(&queue->buffer[v4l2_buf->index], v4l2_buf); 132 return 0;
133}
211 134
212done: 135/*
136 * Free the video buffers.
137 */
138static void uvc_free_buffers(struct uvc_video_queue *queue)
139{
140 mutex_lock(&queue->mutex);
141 vb2_queue_release(&queue->queue);
213 mutex_unlock(&queue->mutex); 142 mutex_unlock(&queue->mutex);
214 return ret;
215} 143}
216 144
217/* 145/*
218 * Queue a video buffer. Attempting to queue a buffer that has already been 146 * Allocate the video buffers.
219 * queued will return -EINVAL.
220 */ 147 */
221static int 148static int uvc_alloc_buffers(struct uvc_video_queue *queue,
222uvc_queue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf) 149 struct v4l2_requestbuffers *rb)
223{ 150{
224 struct uvc_buffer *buf; 151 int ret;
225 unsigned long flags;
226 int ret = 0;
227 152
228 uvc_trace(UVC_TRACE_CAPTURE, "Queuing buffer %u.\n", v4l2_buf->index); 153 mutex_lock(&queue->mutex);
154 ret = vb2_reqbufs(&queue->queue, rb);
155 mutex_unlock(&queue->mutex);
229 156
230 if (v4l2_buf->type != queue->type || 157 return ret ? ret : rb->count;
231 v4l2_buf->memory != V4L2_MEMORY_MMAP) { 158}
232 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
233 "and/or memory (%u).\n", v4l2_buf->type,
234 v4l2_buf->memory);
235 return -EINVAL;
236 }
237 159
238 mutex_lock(&queue->mutex); 160static int uvc_query_buffer(struct uvc_video_queue *queue,
239 if (v4l2_buf->index >= queue->count) { 161 struct v4l2_buffer *buf)
240 uvc_trace(UVC_TRACE_CAPTURE, "[E] Out of range index.\n"); 162{
241 ret = -EINVAL; 163 int ret;
242 goto done;
243 }
244 164
245 buf = &queue->buffer[v4l2_buf->index]; 165 mutex_lock(&queue->mutex);
246 if (buf->state != UVC_BUF_STATE_IDLE) { 166 ret = vb2_querybuf(&queue->queue, buf);
247 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state " 167 mutex_unlock(&queue->mutex);
248 "(%u).\n", buf->state);
249 ret = -EINVAL;
250 goto done;
251 }
252 168
253 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 169 return ret;
254 v4l2_buf->bytesused > buf->buf.length) { 170}
255 uvc_trace(UVC_TRACE_CAPTURE, "[E] Bytes used out of bounds.\n");
256 ret = -EINVAL;
257 goto done;
258 }
259 171
260 if (v4l2_buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) 172static int uvc_queue_buffer(struct uvc_video_queue *queue,
261 buf->buf.bytesused = 0; 173 struct v4l2_buffer *buf)
262 else 174{
263 buf->buf.bytesused = v4l2_buf->bytesused; 175 unsigned long flags;
176 int ret;
264 177
178 mutex_lock(&queue->mutex);
179 ret = vb2_qbuf(&queue->queue, buf);
265 spin_lock_irqsave(&queue->irqlock, flags); 180 spin_lock_irqsave(&queue->irqlock, flags);
266 if (queue->flags & UVC_QUEUE_DISCONNECTED) {
267 spin_unlock_irqrestore(&queue->irqlock, flags);
268 ret = -ENODEV;
269 goto done;
270 }
271 buf->state = UVC_BUF_STATE_QUEUED;
272
273 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0; 181 ret = (queue->flags & UVC_QUEUE_PAUSED) != 0;
274 queue->flags &= ~UVC_QUEUE_PAUSED; 182 queue->flags &= ~UVC_QUEUE_PAUSED;
275
276 list_add_tail(&buf->stream, &queue->mainqueue);
277 list_add_tail(&buf->queue, &queue->irqqueue);
278 spin_unlock_irqrestore(&queue->irqlock, flags); 183 spin_unlock_irqrestore(&queue->irqlock, flags);
279
280done:
281 mutex_unlock(&queue->mutex); 184 mutex_unlock(&queue->mutex);
282 return ret;
283}
284 185
285static int uvc_queue_waiton(struct uvc_buffer *buf, int nonblocking) 186 return ret;
286{
287 if (nonblocking) {
288 return (buf->state != UVC_BUF_STATE_QUEUED &&
289 buf->state != UVC_BUF_STATE_ACTIVE)
290 ? 0 : -EAGAIN;
291 }
292
293 return wait_event_interruptible(buf->wait,
294 buf->state != UVC_BUF_STATE_QUEUED &&
295 buf->state != UVC_BUF_STATE_ACTIVE);
296} 187}
297 188
298/* 189/*
299 * Dequeue a video buffer. If nonblocking is false, block until a buffer is 190 * Dequeue a video buffer. If nonblocking is false, block until a buffer is
300 * available. 191 * available.
301 */ 192 */
302static int 193static int uvc_dequeue_buffer(struct uvc_video_queue *queue,
303uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *v4l2_buf, 194 struct v4l2_buffer *buf, int nonblocking)
304 int nonblocking)
305{ 195{
306 struct uvc_buffer *buf; 196 int ret;
307 int ret = 0;
308
309 if (v4l2_buf->type != queue->type ||
310 v4l2_buf->memory != V4L2_MEMORY_MMAP) {
311 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer type (%u) "
312 "and/or memory (%u).\n", v4l2_buf->type,
313 v4l2_buf->memory);
314 return -EINVAL;
315 }
316 197
317 mutex_lock(&queue->mutex); 198 mutex_lock(&queue->mutex);
318 if (list_empty(&queue->mainqueue)) { 199 ret = vb2_dqbuf(&queue->queue, buf, nonblocking);
319 uvc_trace(UVC_TRACE_CAPTURE, "[E] Empty buffer queue.\n");
320 ret = -EINVAL;
321 goto done;
322 }
323
324 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
325 if ((ret = uvc_queue_waiton(buf, nonblocking)) < 0)
326 goto done;
327
328 uvc_trace(UVC_TRACE_CAPTURE, "Dequeuing buffer %u (%u, %u bytes).\n",
329 buf->buf.index, buf->state, buf->buf.bytesused);
330
331 switch (buf->state) {
332 case UVC_BUF_STATE_ERROR:
333 uvc_trace(UVC_TRACE_CAPTURE, "[W] Corrupted data "
334 "(transmission error).\n");
335 ret = -EIO;
336 case UVC_BUF_STATE_DONE:
337 buf->state = UVC_BUF_STATE_IDLE;
338 break;
339
340 case UVC_BUF_STATE_IDLE:
341 case UVC_BUF_STATE_QUEUED:
342 case UVC_BUF_STATE_ACTIVE:
343 default:
344 uvc_trace(UVC_TRACE_CAPTURE, "[E] Invalid buffer state %u "
345 "(driver bug?).\n", buf->state);
346 ret = -EINVAL;
347 goto done;
348 }
349
350 list_del(&buf->stream);
351 __uvc_query_buffer(buf, v4l2_buf);
352
353done:
354 mutex_unlock(&queue->mutex); 200 mutex_unlock(&queue->mutex);
201
355 return ret; 202 return ret;
356} 203}
357 204
@@ -361,105 +208,47 @@ done:
361 * This function implements video queue polling and is intended to be used by 208 * This function implements video queue polling and is intended to be used by
362 * the device poll handler. 209 * the device poll handler.
363 */ 210 */
364static unsigned int 211static unsigned int uvc_queue_poll(struct uvc_video_queue *queue,
365uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, 212 struct file *file, poll_table *wait)
366 poll_table *wait)
367{ 213{
368 struct uvc_buffer *buf; 214 unsigned int ret;
369 unsigned int mask = 0;
370 215
371 mutex_lock(&queue->mutex); 216 mutex_lock(&queue->mutex);
372 if (list_empty(&queue->mainqueue)) 217 ret = vb2_poll(&queue->queue, file, wait);
373 goto done;
374
375 buf = list_first_entry(&queue->mainqueue, struct uvc_buffer, stream);
376
377 poll_wait(file, &buf->wait, wait);
378 if (buf->state == UVC_BUF_STATE_DONE ||
379 buf->state == UVC_BUF_STATE_ERROR)
380 mask |= POLLOUT | POLLWRNORM;
381
382done:
383 mutex_unlock(&queue->mutex); 218 mutex_unlock(&queue->mutex);
384 return mask;
385}
386 219
387/* 220 return ret;
388 * VMA operations.
389 */
390static void uvc_vm_open(struct vm_area_struct *vma)
391{
392 struct uvc_buffer *buffer = vma->vm_private_data;
393 buffer->vma_use_count++;
394} 221}
395 222
396static void uvc_vm_close(struct vm_area_struct *vma) 223static int uvc_queue_mmap(struct uvc_video_queue *queue,
224 struct vm_area_struct *vma)
397{ 225{
398 struct uvc_buffer *buffer = vma->vm_private_data; 226 int ret;
399 buffer->vma_use_count--;
400}
401 227
402static struct vm_operations_struct uvc_vm_ops = { 228 mutex_lock(&queue->mutex);
403 .open = uvc_vm_open, 229 ret = vb2_mmap(&queue->queue, vma);
404 .close = uvc_vm_close, 230 mutex_unlock(&queue->mutex);
405}; 231
232 return ret;
233}
406 234
235#ifndef CONFIG_MMU
407/* 236/*
408 * Memory-map a buffer. 237 * Get unmapped area.
409 * 238 *
410 * This function implements video buffer memory mapping and is intended to be 239 * NO-MMU arch need this function to make mmap() work correctly.
411 * used by the device mmap handler.
412 */ 240 */
413static int 241static unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
414uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) 242 unsigned long pgoff)
415{ 243{
416 struct uvc_buffer *uninitialized_var(buffer); 244 unsigned long ret;
417 struct page *page;
418 unsigned long addr, start, size;
419 unsigned int i;
420 int ret = 0;
421
422 start = vma->vm_start;
423 size = vma->vm_end - vma->vm_start;
424 245
425 mutex_lock(&queue->mutex); 246 mutex_lock(&queue->mutex);
426 247 ret = vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0);
427 for (i = 0; i < queue->count; ++i) {
428 buffer = &queue->buffer[i];
429 if ((buffer->buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
430 break;
431 }
432
433 if (i == queue->count || size != queue->buf_size) {
434 ret = -EINVAL;
435 goto done;
436 }
437
438 /*
439 * VM_IO marks the area as being an mmaped region for I/O to a
440 * device. It also prevents the region from being core dumped.
441 */
442 vma->vm_flags |= VM_IO;
443
444 addr = (unsigned long)queue->mem + buffer->buf.m.offset;
445 while (size > 0) {
446 page = vmalloc_to_page((void *)addr);
447 if ((ret = vm_insert_page(vma, start, page)) < 0)
448 goto done;
449
450 start += PAGE_SIZE;
451 addr += PAGE_SIZE;
452 size -= PAGE_SIZE;
453 }
454
455 vma->vm_ops = &uvc_vm_ops;
456 vma->vm_private_data = buffer;
457 uvc_vm_open(vma);
458
459done:
460 mutex_unlock(&queue->mutex); 248 mutex_unlock(&queue->mutex);
461 return ret; 249 return ret;
462} 250}
251#endif
463 252
464/* 253/*
465 * Cancel the video buffers queue. 254 * Cancel the video buffers queue.
@@ -484,7 +273,7 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
484 queue); 273 queue);
485 list_del(&buf->queue); 274 list_del(&buf->queue);
486 buf->state = UVC_BUF_STATE_ERROR; 275 buf->state = UVC_BUF_STATE_ERROR;
487 wake_up(&buf->wait); 276 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_ERROR);
488 } 277 }
489 /* This must be protected by the irqlock spinlock to avoid race 278 /* This must be protected by the irqlock spinlock to avoid race
490 * conditions between uvc_queue_buffer and the disconnection event that 279 * conditions between uvc_queue_buffer and the disconnection event that
@@ -516,26 +305,33 @@ static void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect)
516 */ 305 */
517static int uvc_queue_enable(struct uvc_video_queue *queue, int enable) 306static int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
518{ 307{
519 unsigned int i; 308 unsigned long flags;
520 int ret = 0; 309 int ret = 0;
521 310
522 mutex_lock(&queue->mutex); 311 mutex_lock(&queue->mutex);
523 if (enable) { 312 if (enable) {
524 if (uvc_queue_streaming(queue)) { 313 ret = vb2_streamon(&queue->queue, queue->queue.type);
525 ret = -EBUSY; 314 if (ret < 0)
526 goto done; 315 goto done;
527 } 316
528 queue->sequence = 0; 317 queue->sequence = 0;
529 queue->flags |= UVC_QUEUE_STREAMING;
530 queue->buf_used = 0; 318 queue->buf_used = 0;
531 } else { 319 } else {
532 uvc_queue_cancel(queue, 0); 320 ret = vb2_streamoff(&queue->queue, queue->queue.type);
533 INIT_LIST_HEAD(&queue->mainqueue); 321 if (ret < 0)
322 goto done;
534 323
535 for (i = 0; i < queue->count; ++i) 324 spin_lock_irqsave(&queue->irqlock, flags);
536 queue->buffer[i].state = UVC_BUF_STATE_IDLE; 325 INIT_LIST_HEAD(&queue->irqqueue);
537 326
538 queue->flags &= ~UVC_QUEUE_STREAMING; 327 /*
328 * FIXME: We need to clear the DISCONNECTED flag to ensure that
329 * applications will be able to queue buffers for the next
330 * streaming run. However, clearing it here doesn't guarantee
331 * that the device will be reconnected in the meantime.
332 */
333 queue->flags &= ~UVC_QUEUE_DISCONNECTED;
334 spin_unlock_irqrestore(&queue->irqlock, flags);
539 } 335 }
540 336
541done: 337done:
@@ -544,15 +340,15 @@ done:
544} 340}
545 341
546/* called with &queue_irqlock held.. */ 342/* called with &queue_irqlock held.. */
547static struct uvc_buffer * 343static struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
548uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf) 344 struct uvc_buffer *buf)
549{ 345{
550 struct uvc_buffer *nextbuf; 346 struct uvc_buffer *nextbuf;
551 347
552 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) && 348 if ((queue->flags & UVC_QUEUE_DROP_INCOMPLETE) &&
553 buf->buf.length != buf->buf.bytesused) { 349 buf->length != buf->bytesused) {
554 buf->state = UVC_BUF_STATE_QUEUED; 350 buf->state = UVC_BUF_STATE_QUEUED;
555 buf->buf.bytesused = 0; 351 vb2_set_plane_payload(&buf->buf, 0, 0);
556 return buf; 352 return buf;
557 } 353 }
558 354
@@ -563,10 +359,18 @@ uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf)
563 else 359 else
564 nextbuf = NULL; 360 nextbuf = NULL;
565 361
566 buf->buf.sequence = queue->sequence++; 362 /*
567 do_gettimeofday(&buf->buf.timestamp); 363 * FIXME: with videobuf2, the sequence number or timestamp fields
364 * are valid only for video capture devices and the UVC gadget usually
365 * is a video output device. Keeping these until the specs are clear on
366 * this aspect.
367 */
368 buf->buf.v4l2_buf.sequence = queue->sequence++;
369 do_gettimeofday(&buf->buf.v4l2_buf.timestamp);
370
371 vb2_set_plane_payload(&buf->buf, 0, buf->bytesused);
372 vb2_buffer_done(&buf->buf, VB2_BUF_STATE_DONE);
568 373
569 wake_up(&buf->wait);
570 return nextbuf; 374 return nextbuf;
571} 375}
572 376
diff --git a/drivers/usb/gadget/uvc_queue.h b/drivers/usb/gadget/uvc_queue.h
index 1812a8ecc5d0..8e76ce982f1e 100644
--- a/drivers/usb/gadget/uvc_queue.h
+++ b/drivers/usb/gadget/uvc_queue.h
@@ -6,6 +6,7 @@
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/poll.h> 7#include <linux/poll.h>
8#include <linux/videodev2.h> 8#include <linux/videodev2.h>
9#include <media/videobuf2-core.h>
9 10
10/* Maximum frame size in bytes, for sanity checking. */ 11/* Maximum frame size in bytes, for sanity checking. */
11#define UVC_MAX_FRAME_SIZE (16*1024*1024) 12#define UVC_MAX_FRAME_SIZE (16*1024*1024)
@@ -25,42 +26,35 @@ enum uvc_buffer_state {
25}; 26};
26 27
27struct uvc_buffer { 28struct uvc_buffer {
28 unsigned long vma_use_count; 29 struct vb2_buffer buf;
29 struct list_head stream;
30
31 /* Touched by interrupt handler. */
32 struct v4l2_buffer buf;
33 struct list_head queue; 30 struct list_head queue;
34 wait_queue_head_t wait; 31
35 enum uvc_buffer_state state; 32 enum uvc_buffer_state state;
33 void *mem;
34 unsigned int length;
35 unsigned int bytesused;
36}; 36};
37 37
38#define UVC_QUEUE_STREAMING (1 << 0) 38#define UVC_QUEUE_DISCONNECTED (1 << 0)
39#define UVC_QUEUE_DISCONNECTED (1 << 1) 39#define UVC_QUEUE_DROP_INCOMPLETE (1 << 1)
40#define UVC_QUEUE_DROP_INCOMPLETE (1 << 2) 40#define UVC_QUEUE_PAUSED (1 << 2)
41#define UVC_QUEUE_PAUSED (1 << 3)
42 41
43struct uvc_video_queue { 42struct uvc_video_queue {
44 enum v4l2_buf_type type; 43 struct vb2_queue queue;
44 struct mutex mutex; /* Protects queue */
45 45
46 void *mem;
47 unsigned int flags; 46 unsigned int flags;
48 __u32 sequence; 47 __u32 sequence;
49 48
50 unsigned int count;
51 unsigned int buf_size;
52 unsigned int buf_used; 49 unsigned int buf_used;
53 struct uvc_buffer buffer[UVC_MAX_VIDEO_BUFFERS];
54 struct mutex mutex; /* protects buffers and mainqueue */
55 spinlock_t irqlock; /* protects irqqueue */
56 50
57 struct list_head mainqueue; 51 spinlock_t irqlock; /* Protects flags and irqqueue */
58 struct list_head irqqueue; 52 struct list_head irqqueue;
59}; 53};
60 54
61static inline int uvc_queue_streaming(struct uvc_video_queue *queue) 55static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
62{ 56{
63 return queue->flags & UVC_QUEUE_STREAMING; 57 return vb2_is_streaming(&queue->queue);
64} 58}
65 59
66#endif /* __KERNEL__ */ 60#endif /* __KERNEL__ */
diff --git a/drivers/usb/gadget/uvc_v4l2.c b/drivers/usb/gadget/uvc_v4l2.c
index 2ca9386d655b..ad48e81155e2 100644
--- a/drivers/usb/gadget/uvc_v4l2.c
+++ b/drivers/usb/gadget/uvc_v4l2.c
@@ -41,9 +41,8 @@ uvc_send_response(struct uvc_device *uvc, struct uvc_request_data *data)
41 41
42 req->length = min_t(unsigned int, uvc->event_length, data->length); 42 req->length = min_t(unsigned int, uvc->event_length, data->length);
43 req->zero = data->length < uvc->event_length; 43 req->zero = data->length < uvc->event_length;
44 req->dma = DMA_ADDR_INVALID;
45 44
46 memcpy(req->buf, data->data, data->length); 45 memcpy(req->buf, data->data, req->length);
47 46
48 return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL); 47 return usb_ep_queue(cdev->gadget->ep0, req, GFP_KERNEL);
49} 48}
@@ -148,16 +147,13 @@ uvc_v4l2_release(struct file *file)
148 uvc_function_disconnect(uvc); 147 uvc_function_disconnect(uvc);
149 148
150 uvc_video_enable(video, 0); 149 uvc_video_enable(video, 0);
151 mutex_lock(&video->queue.mutex); 150 uvc_free_buffers(&video->queue);
152 if (uvc_free_buffers(&video->queue) < 0)
153 printk(KERN_ERR "uvc_v4l2_release: Unable to free "
154 "buffers.\n");
155 mutex_unlock(&video->queue.mutex);
156 151
157 file->private_data = NULL; 152 file->private_data = NULL;
158 v4l2_fh_del(&handle->vfh); 153 v4l2_fh_del(&handle->vfh);
159 v4l2_fh_exit(&handle->vfh); 154 v4l2_fh_exit(&handle->vfh);
160 kfree(handle); 155 kfree(handle);
156
161 return 0; 157 return 0;
162} 158}
163 159
@@ -178,9 +174,9 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
178 struct v4l2_capability *cap = arg; 174 struct v4l2_capability *cap = arg;
179 175
180 memset(cap, 0, sizeof *cap); 176 memset(cap, 0, sizeof *cap);
181 strncpy(cap->driver, "g_uvc", sizeof(cap->driver)); 177 strlcpy(cap->driver, "g_uvc", sizeof(cap->driver));
182 strncpy(cap->card, cdev->gadget->name, sizeof(cap->card)); 178 strlcpy(cap->card, cdev->gadget->name, sizeof(cap->card));
183 strncpy(cap->bus_info, dev_name(&cdev->gadget->dev), 179 strlcpy(cap->bus_info, dev_name(&cdev->gadget->dev),
184 sizeof cap->bus_info); 180 sizeof cap->bus_info);
185 cap->version = DRIVER_VERSION_NUMBER; 181 cap->version = DRIVER_VERSION_NUMBER;
186 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING; 182 cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
@@ -192,7 +188,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
192 { 188 {
193 struct v4l2_format *fmt = arg; 189 struct v4l2_format *fmt = arg;
194 190
195 if (fmt->type != video->queue.type) 191 if (fmt->type != video->queue.queue.type)
196 return -EINVAL; 192 return -EINVAL;
197 193
198 return uvc_v4l2_get_format(video, fmt); 194 return uvc_v4l2_get_format(video, fmt);
@@ -202,7 +198,7 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
202 { 198 {
203 struct v4l2_format *fmt = arg; 199 struct v4l2_format *fmt = arg;
204 200
205 if (fmt->type != video->queue.type) 201 if (fmt->type != video->queue.queue.type)
206 return -EINVAL; 202 return -EINVAL;
207 203
208 return uvc_v4l2_set_format(video, fmt); 204 return uvc_v4l2_set_format(video, fmt);
@@ -213,16 +209,13 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
213 { 209 {
214 struct v4l2_requestbuffers *rb = arg; 210 struct v4l2_requestbuffers *rb = arg;
215 211
216 if (rb->type != video->queue.type || 212 if (rb->type != video->queue.queue.type)
217 rb->memory != V4L2_MEMORY_MMAP)
218 return -EINVAL; 213 return -EINVAL;
219 214
220 ret = uvc_alloc_buffers(&video->queue, rb->count, 215 ret = uvc_alloc_buffers(&video->queue, rb);
221 video->imagesize);
222 if (ret < 0) 216 if (ret < 0)
223 return ret; 217 return ret;
224 218
225 rb->count = ret;
226 ret = 0; 219 ret = 0;
227 break; 220 break;
228 } 221 }
@@ -231,9 +224,6 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
231 { 224 {
232 struct v4l2_buffer *buf = arg; 225 struct v4l2_buffer *buf = arg;
233 226
234 if (buf->type != video->queue.type)
235 return -EINVAL;
236
237 return uvc_query_buffer(&video->queue, buf); 227 return uvc_query_buffer(&video->queue, buf);
238 } 228 }
239 229
@@ -251,24 +241,36 @@ uvc_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
251 { 241 {
252 int *type = arg; 242 int *type = arg;
253 243
254 if (*type != video->queue.type) 244 if (*type != video->queue.queue.type)
255 return -EINVAL; 245 return -EINVAL;
256 246
257 return uvc_video_enable(video, 1); 247 /* Enable UVC video. */
248 ret = uvc_video_enable(video, 1);
249 if (ret < 0)
250 return ret;
251
252 /*
253 * Complete the alternate setting selection setup phase now that
254 * userspace is ready to provide video frames.
255 */
256 uvc_function_setup_continue(uvc);
257 uvc->state = UVC_STATE_STREAMING;
258
259 return 0;
258 } 260 }
259 261
260 case VIDIOC_STREAMOFF: 262 case VIDIOC_STREAMOFF:
261 { 263 {
262 int *type = arg; 264 int *type = arg;
263 265
264 if (*type != video->queue.type) 266 if (*type != video->queue.queue.type)
265 return -EINVAL; 267 return -EINVAL;
266 268
267 return uvc_video_enable(video, 0); 269 return uvc_video_enable(video, 0);
268 } 270 }
269 271
270 /* Events */ 272 /* Events */
271 case VIDIOC_DQEVENT: 273 case VIDIOC_DQEVENT:
272 { 274 {
273 struct v4l2_event *event = arg; 275 struct v4l2_event *event = arg;
274 276
@@ -333,17 +335,21 @@ uvc_v4l2_poll(struct file *file, poll_table *wait)
333{ 335{
334 struct video_device *vdev = video_devdata(file); 336 struct video_device *vdev = video_devdata(file);
335 struct uvc_device *uvc = video_get_drvdata(vdev); 337 struct uvc_device *uvc = video_get_drvdata(vdev);
336 struct uvc_file_handle *handle = to_uvc_file_handle(file->private_data);
337 unsigned int mask = 0;
338 338
339 poll_wait(file, &handle->vfh.wait, wait); 339 return uvc_queue_poll(&uvc->video.queue, file, wait);
340 if (v4l2_event_pending(&handle->vfh)) 340}
341 mask |= POLLPRI;
342 341
343 mask |= uvc_queue_poll(&uvc->video.queue, file, wait); 342#ifndef CONFIG_MMU
343static unsigned long uvc_v4l2_get_unmapped_area(struct file *file,
344 unsigned long addr, unsigned long len, unsigned long pgoff,
345 unsigned long flags)
346{
347 struct video_device *vdev = video_devdata(file);
348 struct uvc_device *uvc = video_get_drvdata(vdev);
344 349
345 return mask; 350 return uvc_queue_get_unmapped_area(&uvc->video.queue, pgoff);
346} 351}
352#endif
347 353
348static struct v4l2_file_operations uvc_v4l2_fops = { 354static struct v4l2_file_operations uvc_v4l2_fops = {
349 .owner = THIS_MODULE, 355 .owner = THIS_MODULE,
@@ -352,5 +358,8 @@ static struct v4l2_file_operations uvc_v4l2_fops = {
352 .ioctl = uvc_v4l2_ioctl, 358 .ioctl = uvc_v4l2_ioctl,
353 .mmap = uvc_v4l2_mmap, 359 .mmap = uvc_v4l2_mmap,
354 .poll = uvc_v4l2_poll, 360 .poll = uvc_v4l2_poll,
361#ifndef CONFIG_MMU
362 .get_unmapped_area = uvc_v4l2_get_unmapped_area,
363#endif
355}; 364};
356 365
diff --git a/drivers/usb/gadget/uvc_video.c b/drivers/usb/gadget/uvc_video.c
index b0e53a8ea4f7..71e896d4c5ae 100644
--- a/drivers/usb/gadget/uvc_video.c
+++ b/drivers/usb/gadget/uvc_video.c
@@ -32,7 +32,7 @@ uvc_video_encode_header(struct uvc_video *video, struct uvc_buffer *buf,
32 data[0] = 2; 32 data[0] = 2;
33 data[1] = UVC_STREAM_EOH | video->fid; 33 data[1] = UVC_STREAM_EOH | video->fid;
34 34
35 if (buf->buf.bytesused - video->queue.buf_used <= len - 2) 35 if (buf->bytesused - video->queue.buf_used <= len - 2)
36 data[1] |= UVC_STREAM_EOF; 36 data[1] |= UVC_STREAM_EOF;
37 37
38 return 2; 38 return 2;
@@ -47,8 +47,8 @@ uvc_video_encode_data(struct uvc_video *video, struct uvc_buffer *buf,
47 void *mem; 47 void *mem;
48 48
49 /* Copy video data to the USB buffer. */ 49 /* Copy video data to the USB buffer. */
50 mem = queue->mem + buf->buf.m.offset + queue->buf_used; 50 mem = buf->mem + queue->buf_used;
51 nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); 51 nbytes = min((unsigned int)len, buf->bytesused - queue->buf_used);
52 52
53 memcpy(data, mem, nbytes); 53 memcpy(data, mem, nbytes);
54 queue->buf_used += nbytes; 54 queue->buf_used += nbytes;
@@ -82,7 +82,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
82 req->length = video->req_size - len; 82 req->length = video->req_size - len;
83 req->zero = video->payload_size == video->max_payload_size; 83 req->zero = video->payload_size == video->max_payload_size;
84 84
85 if (buf->buf.bytesused == video->queue.buf_used) { 85 if (buf->bytesused == video->queue.buf_used) {
86 video->queue.buf_used = 0; 86 video->queue.buf_used = 0;
87 buf->state = UVC_BUF_STATE_DONE; 87 buf->state = UVC_BUF_STATE_DONE;
88 uvc_queue_next_buffer(&video->queue, buf); 88 uvc_queue_next_buffer(&video->queue, buf);
@@ -92,7 +92,7 @@ uvc_video_encode_bulk(struct usb_request *req, struct uvc_video *video,
92 } 92 }
93 93
94 if (video->payload_size == video->max_payload_size || 94 if (video->payload_size == video->max_payload_size ||
95 buf->buf.bytesused == video->queue.buf_used) 95 buf->bytesused == video->queue.buf_used)
96 video->payload_size = 0; 96 video->payload_size = 0;
97} 97}
98 98
@@ -115,7 +115,7 @@ uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
115 115
116 req->length = video->req_size - len; 116 req->length = video->req_size - len;
117 117
118 if (buf->buf.bytesused == video->queue.buf_used) { 118 if (buf->bytesused == video->queue.buf_used) {
119 video->queue.buf_used = 0; 119 video->queue.buf_used = 0;
120 buf->state = UVC_BUF_STATE_DONE; 120 buf->state = UVC_BUF_STATE_DONE;
121 uvc_queue_next_buffer(&video->queue, buf); 121 uvc_queue_next_buffer(&video->queue, buf);
@@ -161,6 +161,7 @@ static void
161uvc_video_complete(struct usb_ep *ep, struct usb_request *req) 161uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
162{ 162{
163 struct uvc_video *video = req->context; 163 struct uvc_video *video = req->context;
164 struct uvc_video_queue *queue = &video->queue;
164 struct uvc_buffer *buf; 165 struct uvc_buffer *buf;
165 unsigned long flags; 166 unsigned long flags;
166 int ret; 167 int ret;
@@ -169,13 +170,15 @@ uvc_video_complete(struct usb_ep *ep, struct usb_request *req)
169 case 0: 170 case 0:
170 break; 171 break;
171 172
172 case -ESHUTDOWN: 173 case -ESHUTDOWN: /* disconnect from host. */
173 printk(KERN_INFO "VS request cancelled.\n"); 174 printk(KERN_INFO "VS request cancelled.\n");
175 uvc_queue_cancel(queue, 1);
174 goto requeue; 176 goto requeue;
175 177
176 default: 178 default:
177 printk(KERN_INFO "VS request completed with status %d.\n", 179 printk(KERN_INFO "VS request completed with status %d.\n",
178 req->status); 180 req->status);
181 uvc_queue_cancel(queue, 0);
179 goto requeue; 182 goto requeue;
180 } 183 }
181 184
@@ -229,13 +232,18 @@ uvc_video_free_requests(struct uvc_video *video)
229static int 232static int
230uvc_video_alloc_requests(struct uvc_video *video) 233uvc_video_alloc_requests(struct uvc_video *video)
231{ 234{
235 unsigned int req_size;
232 unsigned int i; 236 unsigned int i;
233 int ret = -ENOMEM; 237 int ret = -ENOMEM;
234 238
235 BUG_ON(video->req_size); 239 BUG_ON(video->req_size);
236 240
241 req_size = video->ep->maxpacket
242 * max_t(unsigned int, video->ep->maxburst, 1)
243 * (video->ep->mult + 1);
244
237 for (i = 0; i < UVC_NUM_REQUESTS; ++i) { 245 for (i = 0; i < UVC_NUM_REQUESTS; ++i) {
238 video->req_buffer[i] = kmalloc(video->ep->maxpacket, GFP_KERNEL); 246 video->req_buffer[i] = kmalloc(req_size, GFP_KERNEL);
239 if (video->req_buffer[i] == NULL) 247 if (video->req_buffer[i] == NULL)
240 goto error; 248 goto error;
241 249
@@ -245,14 +253,14 @@ uvc_video_alloc_requests(struct uvc_video *video)
245 253
246 video->req[i]->buf = video->req_buffer[i]; 254 video->req[i]->buf = video->req_buffer[i];
247 video->req[i]->length = 0; 255 video->req[i]->length = 0;
248 video->req[i]->dma = DMA_ADDR_INVALID;
249 video->req[i]->complete = uvc_video_complete; 256 video->req[i]->complete = uvc_video_complete;
250 video->req[i]->context = video; 257 video->req[i]->context = video;
251 258
252 list_add_tail(&video->req[i]->list, &video->req_free); 259 list_add_tail(&video->req[i]->list, &video->req_free);
253 } 260 }
254 261
255 video->req_size = video->ep->maxpacket; 262 video->req_size = req_size;
263
256 return 0; 264 return 0;
257 265
258error: 266error:
@@ -309,7 +317,8 @@ uvc_video_pump(struct uvc_video *video)
309 video->encode(req, video, buf); 317 video->encode(req, video, buf);
310 318
311 /* Queue the USB request */ 319 /* Queue the USB request */
312 if ((ret = usb_ep_queue(video->ep, req, GFP_KERNEL)) < 0) { 320 ret = usb_ep_queue(video->ep, req, GFP_ATOMIC);
321 if (ret < 0) {
313 printk(KERN_INFO "Failed to queue request (%d)\n", ret); 322 printk(KERN_INFO "Failed to queue request (%d)\n", ret);
314 usb_ep_set_halt(video->ep); 323 usb_ep_set_halt(video->ep);
315 spin_unlock_irqrestore(&video->queue.irqlock, flags); 324 spin_unlock_irqrestore(&video->queue.irqlock, flags);
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 685fa681cb65..2cd6262e8b71 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -368,8 +368,10 @@ static int zero_unbind(struct usb_composite_dev *cdev)
368 del_timer_sync(&autoresume_timer); 368 del_timer_sync(&autoresume_timer);
369 if (!IS_ERR_OR_NULL(func_ss)) 369 if (!IS_ERR_OR_NULL(func_ss))
370 usb_put_function(func_ss); 370 usb_put_function(func_ss);
371 usb_put_function_instance(func_inst_ss);
371 if (!IS_ERR_OR_NULL(func_lb)) 372 if (!IS_ERR_OR_NULL(func_lb))
372 usb_put_function(func_lb); 373 usb_put_function(func_lb);
374 usb_put_function_instance(func_inst_lb);
373 return 0; 375 return 0;
374} 376}
375 377
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index c59a1126926f..de94f2699063 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -2,11 +2,9 @@
2# USB Host Controller Drivers 2# USB Host Controller Drivers
3# 3#
4comment "USB Host Controller Drivers" 4comment "USB Host Controller Drivers"
5 depends on USB
6 5
7config USB_C67X00_HCD 6config USB_C67X00_HCD
8 tristate "Cypress C67x00 HCD support" 7 tristate "Cypress C67x00 HCD support"
9 depends on USB
10 help 8 help
11 The Cypress C67x00 (EZ-Host/EZ-OTG) chips are dual-role 9 The Cypress C67x00 (EZ-Host/EZ-OTG) chips are dual-role
12 host/peripheral/OTG USB controllers. 10 host/peripheral/OTG USB controllers.
@@ -19,7 +17,7 @@ config USB_C67X00_HCD
19 17
20config USB_XHCI_HCD 18config USB_XHCI_HCD
21 tristate "xHCI HCD (USB 3.0) support" 19 tristate "xHCI HCD (USB 3.0) support"
22 depends on USB && USB_ARCH_HAS_XHCI 20 depends on USB_ARCH_HAS_XHCI
23 ---help--- 21 ---help---
24 The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0 22 The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0
25 "SuperSpeed" host controller hardware. 23 "SuperSpeed" host controller hardware.
@@ -27,13 +25,13 @@ config USB_XHCI_HCD
27 To compile this driver as a module, choose M here: the 25 To compile this driver as a module, choose M here: the
28 module will be called xhci-hcd. 26 module will be called xhci-hcd.
29 27
28if USB_XHCI_HCD
29
30config USB_XHCI_PLATFORM 30config USB_XHCI_PLATFORM
31 tristate 31 tristate
32 depends on USB_XHCI_HCD
33 32
34config USB_XHCI_HCD_DEBUGGING 33config USB_XHCI_HCD_DEBUGGING
35 bool "Debugging for the xHCI host controller" 34 bool "Debugging for the xHCI host controller"
36 depends on USB_XHCI_HCD
37 ---help--- 35 ---help---
38 Say 'Y' to turn on debugging for the xHCI host controller driver. 36 Say 'Y' to turn on debugging for the xHCI host controller driver.
39 This will spew debugging output, even in interrupt context. 37 This will spew debugging output, even in interrupt context.
@@ -41,9 +39,11 @@ config USB_XHCI_HCD_DEBUGGING
41 39
42 If unsure, say N. 40 If unsure, say N.
43 41
42endif # USB_XHCI_HCD
43
44config USB_EHCI_HCD 44config USB_EHCI_HCD
45 tristate "EHCI HCD (USB 2.0) support" 45 tristate "EHCI HCD (USB 2.0) support"
46 depends on USB && USB_ARCH_HAS_EHCI 46 depends on USB_ARCH_HAS_EHCI
47 ---help--- 47 ---help---
48 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0 48 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0
49 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware. 49 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware.
@@ -95,14 +95,19 @@ config USB_EHCI_TT_NEWSCHED
95 95
96 If unsure, say Y. 96 If unsure, say Y.
97 97
98config USB_FSL_MPH_DR_OF
99 tristate
100
101if USB_EHCI_HCD
102
98config USB_EHCI_PCI 103config USB_EHCI_PCI
99 tristate 104 tristate
100 depends on USB_EHCI_HCD && PCI 105 depends on PCI
101 default y 106 default y
102 107
103config USB_EHCI_HCD_PMC_MSP 108config USB_EHCI_HCD_PMC_MSP
104 tristate "EHCI support for on-chip PMC MSP71xx USB controller" 109 tristate "EHCI support for on-chip PMC MSP71xx USB controller"
105 depends on USB_EHCI_HCD && MSP_HAS_USB 110 depends on MSP_HAS_USB
106 default n 111 default n
107 select USB_EHCI_BIG_ENDIAN_DESC 112 select USB_EHCI_BIG_ENDIAN_DESC
108 select USB_EHCI_BIG_ENDIAN_MMIO 113 select USB_EHCI_BIG_ENDIAN_MMIO
@@ -112,22 +117,13 @@ config USB_EHCI_HCD_PMC_MSP
112 117
113config USB_EHCI_BIG_ENDIAN_MMIO 118config USB_EHCI_BIG_ENDIAN_MMIO
114 bool 119 bool
115 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
116 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
117 PPC_MPC512x || CPU_CAVIUM_OCTEON || \
118 PMC_MSP || SPARC_LEON || MIPS_SEAD3)
119 default y
120 120
121config USB_EHCI_BIG_ENDIAN_DESC 121config USB_EHCI_BIG_ENDIAN_DESC
122 bool 122 bool
123 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
124 PPC_MPC512x || PMC_MSP || SPARC_LEON || \
125 MIPS_SEAD3)
126 default y
127 123
128config XPS_USB_HCD_XILINX 124config XPS_USB_HCD_XILINX
129 bool "Use Xilinx usb host EHCI controller core" 125 bool "Use Xilinx usb host EHCI controller core"
130 depends on USB_EHCI_HCD && (PPC32 || MICROBLAZE) 126 depends on (PPC32 || MICROBLAZE)
131 select USB_EHCI_BIG_ENDIAN_DESC 127 select USB_EHCI_BIG_ENDIAN_DESC
132 select USB_EHCI_BIG_ENDIAN_MMIO 128 select USB_EHCI_BIG_ENDIAN_MMIO
133 ---help--- 129 ---help---
@@ -136,12 +132,9 @@ config XPS_USB_HCD_XILINX
136 support both high speed and full speed devices, or high speed 132 support both high speed and full speed devices, or high speed
137 devices only. 133 devices only.
138 134
139config USB_FSL_MPH_DR_OF
140 tristate
141
142config USB_EHCI_FSL 135config USB_EHCI_FSL
143 bool "Support for Freescale PPC on-chip EHCI USB controller" 136 bool "Support for Freescale PPC on-chip EHCI USB controller"
144 depends on USB_EHCI_HCD && FSL_SOC 137 depends on FSL_SOC
145 select USB_EHCI_ROOT_HUB_TT 138 select USB_EHCI_ROOT_HUB_TT
146 select USB_FSL_MPH_DR_OF if OF 139 select USB_FSL_MPH_DR_OF if OF
147 ---help--- 140 ---help---
@@ -149,22 +142,53 @@ config USB_EHCI_FSL
149 142
150config USB_EHCI_MXC 143config USB_EHCI_MXC
151 tristate "Support for Freescale i.MX on-chip EHCI USB controller" 144 tristate "Support for Freescale i.MX on-chip EHCI USB controller"
152 depends on USB_EHCI_HCD && ARCH_MXC 145 depends on ARCH_MXC
153 select USB_EHCI_ROOT_HUB_TT 146 select USB_EHCI_ROOT_HUB_TT
154 ---help--- 147 ---help---
155 Variation of ARC USB block used in some Freescale chips. 148 Variation of ARC USB block used in some Freescale chips.
156 149
157config USB_EHCI_HCD_OMAP 150config USB_EHCI_HCD_OMAP
158 bool "EHCI support for OMAP3 and later chips" 151 tristate "EHCI support for OMAP3 and later chips"
159 depends on USB_EHCI_HCD && ARCH_OMAP 152 depends on ARCH_OMAP
160 default y 153 default y
161 ---help--- 154 ---help---
162 Enables support for the on-chip EHCI controller on 155 Enables support for the on-chip EHCI controller on
163 OMAP3 and later chips. 156 OMAP3 and later chips.
157 If your system uses a PHY on the USB port, you will need to
158 enable USB_PHY and the appropriate PHY driver as well. Most
159 boards need the NOP_USB_XCEIV PHY driver.
160
161config USB_EHCI_HCD_ORION
162 tristate "Support for Marvell EBU on-chip EHCI USB controller"
163 depends on USB_EHCI_HCD && PLAT_ORION
164 default y
165 ---help---
166 Enables support for the on-chip EHCI controller on Marvell's
167 embedded ARM SoCs, including Orion, Kirkwood, Dove, Armada XP,
168 Armada 370. This is different from the EHCI implementation
169 on Marvell's mobile PXA and MMP SoC, see "EHCI support for
170 Marvell PXA/MMP USB controller" for those.
171
172config USB_EHCI_HCD_SPEAR
173 tristate "Support for ST SPEAr on-chip EHCI USB controller"
174 depends on USB_EHCI_HCD && PLAT_SPEAR
175 default y
176 ---help---
177 Enables support for the on-chip EHCI controller on
178 ST SPEAr chips.
179
180config USB_EHCI_HCD_AT91
181 tristate "Support for Atmel on-chip EHCI USB controller"
182 depends on USB_EHCI_HCD && ARCH_AT91
183 default y
184 ---help---
185 Enables support for the on-chip EHCI controller on
186 Atmel chips.
164 187
165config USB_EHCI_MSM 188config USB_EHCI_MSM
166 bool "Support for MSM on-chip EHCI USB controller" 189 tristate "Support for Qualcomm QSD/MSM on-chip EHCI USB controller"
167 depends on USB_EHCI_HCD && ARCH_MSM 190 depends on ARCH_MSM
191 depends on USB_PHY
168 select USB_EHCI_ROOT_HUB_TT 192 select USB_EHCI_ROOT_HUB_TT
169 select USB_MSM_OTG 193 select USB_MSM_OTG
170 ---help--- 194 ---help---
@@ -177,15 +201,16 @@ config USB_EHCI_MSM
177 201
178config USB_EHCI_TEGRA 202config USB_EHCI_TEGRA
179 boolean "NVIDIA Tegra HCD support" 203 boolean "NVIDIA Tegra HCD support"
180 depends on USB_EHCI_HCD && ARCH_TEGRA 204 depends on ARCH_TEGRA
181 select USB_EHCI_ROOT_HUB_TT 205 select USB_EHCI_ROOT_HUB_TT
206 select USB_PHY
182 help 207 help
183 This driver enables support for the internal USB Host Controllers 208 This driver enables support for the internal USB Host Controllers
184 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant. 209 found in NVIDIA Tegra SoCs. The controllers are EHCI compliant.
185 210
186config USB_EHCI_HCD_PPC_OF 211config USB_EHCI_HCD_PPC_OF
187 bool "EHCI support for PPC USB controller on OF platform bus" 212 bool "EHCI support for PPC USB controller on OF platform bus"
188 depends on USB_EHCI_HCD && PPC_OF 213 depends on PPC_OF
189 default y 214 default y
190 ---help--- 215 ---help---
191 Enables support for the USB controller present on the PowerPC 216 Enables support for the USB controller present on the PowerPC
@@ -193,35 +218,40 @@ config USB_EHCI_HCD_PPC_OF
193 218
194config USB_EHCI_SH 219config USB_EHCI_SH
195 bool "EHCI support for SuperH USB controller" 220 bool "EHCI support for SuperH USB controller"
196 depends on USB_EHCI_HCD && SUPERH 221 depends on SUPERH
197 ---help--- 222 ---help---
198 Enables support for the on-chip EHCI controller on the SuperH. 223 Enables support for the on-chip EHCI controller on the SuperH.
199 If you use the PCI EHCI controller, this option is not necessary. 224 If you use the PCI EHCI controller, this option is not necessary.
200 225
201config USB_EHCI_S5P 226config USB_EHCI_S5P
202 boolean "S5P EHCI support" 227 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series"
203 depends on USB_EHCI_HCD && PLAT_S5P 228 depends on PLAT_S5P
204 help 229 help
205 Enable support for the S5P SOC's on-chip EHCI controller. 230 Enable support for the Samsung S5Pxxxx and Exynos3/4/5 SOC's
231 on-chip EHCI controller.
206 232
207config USB_EHCI_MV 233config USB_EHCI_MV
208 bool "EHCI support for Marvell on-chip controller" 234 bool "EHCI support for Marvell PXA/MMP USB controller"
209 depends on USB_EHCI_HCD && (ARCH_PXA || ARCH_MMP) 235 depends on (ARCH_PXA || ARCH_MMP)
210 select USB_EHCI_ROOT_HUB_TT 236 select USB_EHCI_ROOT_HUB_TT
211 ---help--- 237 ---help---
212 Enables support for Marvell (including PXA and MMP series) on-chip 238 Enables support for Marvell (including PXA and MMP series) on-chip
213 USB SPH and OTG controller. SPH is a single port host, and it can 239 USB SPH and OTG controller. SPH is a single port host, and it can
214 only be EHCI host. OTG is controller that can switch to host mode. 240 only be EHCI host. OTG is controller that can switch to host mode.
241 Note that this driver will not work on Marvell's other EHCI
242 controller used by the EBU-type SoCs including Orion, Kirkwood,
243 Dova, Armada 370 and Armada XP. See "Support for Marvell EBU
244 on-chip EHCI USB controller" for those.
215 245
216config USB_W90X900_EHCI 246config USB_W90X900_EHCI
217 bool "W90X900(W90P910) EHCI support" 247 bool "W90X900(W90P910) EHCI support"
218 depends on USB_EHCI_HCD && ARCH_W90X900 248 depends on ARCH_W90X900
219 ---help--- 249 ---help---
220 Enables support for the W90X900 USB controller 250 Enables support for the W90X900 USB controller
221 251
222config USB_CNS3XXX_EHCI 252config USB_CNS3XXX_EHCI
223 bool "Cavium CNS3XXX EHCI Module (DEPRECATED)" 253 bool "Cavium CNS3XXX EHCI Module (DEPRECATED)"
224 depends on USB_EHCI_HCD && ARCH_CNS3XXX 254 depends on ARCH_CNS3XXX
225 select USB_EHCI_HCD_PLATFORM 255 select USB_EHCI_HCD_PLATFORM
226 ---help--- 256 ---help---
227 This option is deprecated now and the driver was removed, use 257 This option is deprecated now and the driver was removed, use
@@ -233,7 +263,7 @@ config USB_CNS3XXX_EHCI
233 263
234config USB_EHCI_ATH79 264config USB_EHCI_ATH79
235 bool "EHCI support for AR7XXX/AR9XXX SoCs (DEPRECATED)" 265 bool "EHCI support for AR7XXX/AR9XXX SoCs (DEPRECATED)"
236 depends on USB_EHCI_HCD && (SOC_AR71XX || SOC_AR724X || SOC_AR913X || SOC_AR933X) 266 depends on (SOC_AR71XX || SOC_AR724X || SOC_AR913X || SOC_AR933X)
237 select USB_EHCI_ROOT_HUB_TT 267 select USB_EHCI_ROOT_HUB_TT
238 select USB_EHCI_HCD_PLATFORM 268 select USB_EHCI_HCD_PLATFORM
239 default y 269 default y
@@ -244,9 +274,31 @@ config USB_EHCI_ATH79
244 Enables support for the built-in EHCI controller present 274 Enables support for the built-in EHCI controller present
245 on the Atheros AR7XXX/AR9XXX SoCs. 275 on the Atheros AR7XXX/AR9XXX SoCs.
246 276
277config USB_EHCI_HCD_PLATFORM
278 tristate "Generic EHCI driver for a platform device"
279 default n
280 ---help---
281 Adds an EHCI host driver for a generic platform device, which
282 provides a memory space and an irq.
283
284 If unsure, say N.
285
286config USB_OCTEON_EHCI
287 bool "Octeon on-chip EHCI support"
288 depends on CPU_CAVIUM_OCTEON
289 default n
290 select USB_EHCI_BIG_ENDIAN_MMIO
291 help
292 Enable support for the Octeon II SOC's on-chip EHCI
293 controller. It is needed for high-speed (480Mbit/sec)
294 USB 2.0 device support. All CN6XXX based chips with USB are
295 supported.
296
297endif # USB_EHCI_HCD
298
247config USB_OXU210HP_HCD 299config USB_OXU210HP_HCD
248 tristate "OXU210HP HCD support" 300 tristate "OXU210HP HCD support"
249 depends on USB && GENERIC_HARDIRQS 301 depends on GENERIC_HARDIRQS
250 ---help--- 302 ---help---
251 The OXU210HP is an USB host/OTG/device controller. Enable this 303 The OXU210HP is an USB host/OTG/device controller. Enable this
252 option if your board has this chip. If unsure, say N. 304 option if your board has this chip. If unsure, say N.
@@ -259,7 +311,6 @@ config USB_OXU210HP_HCD
259 311
260config USB_ISP116X_HCD 312config USB_ISP116X_HCD
261 tristate "ISP116X HCD support" 313 tristate "ISP116X HCD support"
262 depends on USB
263 ---help--- 314 ---help---
264 The ISP1160 and ISP1161 chips are USB host controllers. Enable this 315 The ISP1160 and ISP1161 chips are USB host controllers. Enable this
265 option if your board has this chip. If unsure, say N. 316 option if your board has this chip. If unsure, say N.
@@ -271,7 +322,6 @@ config USB_ISP116X_HCD
271 322
272config USB_ISP1760_HCD 323config USB_ISP1760_HCD
273 tristate "ISP 1760 HCD support" 324 tristate "ISP 1760 HCD support"
274 depends on USB
275 ---help--- 325 ---help---
276 The ISP1760 chip is a USB 2.0 host controller. 326 The ISP1760 chip is a USB 2.0 host controller.
277 327
@@ -286,7 +336,6 @@ config USB_ISP1760_HCD
286 336
287config USB_ISP1362_HCD 337config USB_ISP1362_HCD
288 tristate "ISP1362 HCD support" 338 tristate "ISP1362 HCD support"
289 depends on USB
290 default N 339 default N
291 ---help--- 340 ---help---
292 Supports the Philips ISP1362 chip as a host controller 341 Supports the Philips ISP1362 chip as a host controller
@@ -298,9 +347,8 @@ config USB_ISP1362_HCD
298 347
299config USB_OHCI_HCD 348config USB_OHCI_HCD
300 tristate "OHCI HCD support" 349 tristate "OHCI HCD support"
301 depends on USB && USB_ARCH_HAS_OHCI 350 depends on USB_ARCH_HAS_OHCI
302 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 351 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
303 select USB_OTG_UTILS if ARCH_OMAP
304 depends on USB_ISP1301 || !ARCH_LPC32XX 352 depends on USB_ISP1301 || !ARCH_LPC32XX
305 ---help--- 353 ---help---
306 The Open Host Controller Interface (OHCI) is a standard for accessing 354 The Open Host Controller Interface (OHCI) is a standard for accessing
@@ -315,16 +363,18 @@ config USB_OHCI_HCD
315 To compile this driver as a module, choose M here: the 363 To compile this driver as a module, choose M here: the
316 module will be called ohci-hcd. 364 module will be called ohci-hcd.
317 365
366if USB_OHCI_HCD
367
318config USB_OHCI_HCD_OMAP1 368config USB_OHCI_HCD_OMAP1
319 bool "OHCI support for OMAP1/2 chips" 369 bool "OHCI support for OMAP1/2 chips"
320 depends on USB_OHCI_HCD && ARCH_OMAP1 370 depends on ARCH_OMAP1
321 default y 371 default y
322 ---help--- 372 ---help---
323 Enables support for the OHCI controller on OMAP1/2 chips. 373 Enables support for the OHCI controller on OMAP1/2 chips.
324 374
325config USB_OHCI_HCD_OMAP3 375config USB_OHCI_HCD_OMAP3
326 bool "OHCI support for OMAP3 and later chips" 376 bool "OHCI support for OMAP3 and later chips"
327 depends on USB_OHCI_HCD && (ARCH_OMAP3 || ARCH_OMAP4) 377 depends on (ARCH_OMAP3 || ARCH_OMAP4)
328 default y 378 default y
329 ---help--- 379 ---help---
330 Enables support for the on-chip OHCI controller on 380 Enables support for the on-chip OHCI controller on
@@ -332,7 +382,7 @@ config USB_OHCI_HCD_OMAP3
332 382
333config USB_OHCI_ATH79 383config USB_OHCI_ATH79
334 bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)" 384 bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)"
335 depends on USB_OHCI_HCD && (SOC_AR71XX || SOC_AR724X) 385 depends on (SOC_AR71XX || SOC_AR724X)
336 select USB_OHCI_HCD_PLATFORM 386 select USB_OHCI_HCD_PLATFORM
337 default y 387 default y
338 help 388 help
@@ -344,7 +394,7 @@ config USB_OHCI_ATH79
344 394
345config USB_OHCI_HCD_PPC_OF_BE 395config USB_OHCI_HCD_PPC_OF_BE
346 bool "OHCI support for OF platform bus (big endian)" 396 bool "OHCI support for OF platform bus (big endian)"
347 depends on USB_OHCI_HCD && PPC_OF 397 depends on PPC_OF
348 select USB_OHCI_BIG_ENDIAN_DESC 398 select USB_OHCI_BIG_ENDIAN_DESC
349 select USB_OHCI_BIG_ENDIAN_MMIO 399 select USB_OHCI_BIG_ENDIAN_MMIO
350 ---help--- 400 ---help---
@@ -353,7 +403,7 @@ config USB_OHCI_HCD_PPC_OF_BE
353 403
354config USB_OHCI_HCD_PPC_OF_LE 404config USB_OHCI_HCD_PPC_OF_LE
355 bool "OHCI support for OF platform bus (little endian)" 405 bool "OHCI support for OF platform bus (little endian)"
356 depends on USB_OHCI_HCD && PPC_OF 406 depends on PPC_OF
357 select USB_OHCI_LITTLE_ENDIAN 407 select USB_OHCI_LITTLE_ENDIAN
358 ---help--- 408 ---help---
359 Enables support for little-endian USB controllers present on the 409 Enables support for little-endian USB controllers present on the
@@ -361,12 +411,12 @@ config USB_OHCI_HCD_PPC_OF_LE
361 411
362config USB_OHCI_HCD_PPC_OF 412config USB_OHCI_HCD_PPC_OF
363 bool 413 bool
364 depends on USB_OHCI_HCD && PPC_OF 414 depends on PPC_OF
365 default USB_OHCI_HCD_PPC_OF_BE || USB_OHCI_HCD_PPC_OF_LE 415 default USB_OHCI_HCD_PPC_OF_BE || USB_OHCI_HCD_PPC_OF_LE
366 416
367config USB_OHCI_HCD_PCI 417config USB_OHCI_HCD_PCI
368 bool "OHCI support for PCI-bus USB controllers" 418 bool "OHCI support for PCI-bus USB controllers"
369 depends on USB_OHCI_HCD && PCI && (STB03xxx || PPC_MPC52xx || USB_OHCI_HCD_PPC_OF) 419 depends on PCI && (STB03xxx || PPC_MPC52xx || USB_OHCI_HCD_PPC_OF)
370 default y 420 default y
371 select USB_OHCI_LITTLE_ENDIAN 421 select USB_OHCI_LITTLE_ENDIAN
372 ---help--- 422 ---help---
@@ -375,7 +425,7 @@ config USB_OHCI_HCD_PCI
375 425
376config USB_OHCI_HCD_SSB 426config USB_OHCI_HCD_SSB
377 bool "OHCI support for Broadcom SSB OHCI core (DEPRECATED)" 427 bool "OHCI support for Broadcom SSB OHCI core (DEPRECATED)"
378 depends on USB_OHCI_HCD && (SSB = y || SSB = USB_OHCI_HCD) 428 depends on (SSB = y || SSB = USB_OHCI_HCD)
379 select USB_HCD_SSB 429 select USB_HCD_SSB
380 select USB_OHCI_HCD_PLATFORM 430 select USB_OHCI_HCD_PLATFORM
381 default n 431 default n
@@ -393,7 +443,7 @@ config USB_OHCI_HCD_SSB
393 443
394config USB_OHCI_SH 444config USB_OHCI_SH
395 bool "OHCI support for SuperH USB controller (DEPRECATED)" 445 bool "OHCI support for SuperH USB controller (DEPRECATED)"
396 depends on USB_OHCI_HCD && SUPERH 446 depends on SUPERH
397 select USB_OHCI_HCD_PLATFORM 447 select USB_OHCI_HCD_PLATFORM
398 ---help--- 448 ---help---
399 This option is deprecated now and the driver was removed, use 449 This option is deprecated now and the driver was removed, use
@@ -404,13 +454,13 @@ config USB_OHCI_SH
404 454
405config USB_OHCI_EXYNOS 455config USB_OHCI_EXYNOS
406 boolean "OHCI support for Samsung EXYNOS SoC Series" 456 boolean "OHCI support for Samsung EXYNOS SoC Series"
407 depends on USB_OHCI_HCD && ARCH_EXYNOS 457 depends on ARCH_EXYNOS
408 help 458 help
409 Enable support for the Samsung Exynos SOC's on-chip OHCI controller. 459 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
410 460
411config USB_CNS3XXX_OHCI 461config USB_CNS3XXX_OHCI
412 bool "Cavium CNS3XXX OHCI Module (DEPRECATED)" 462 bool "Cavium CNS3XXX OHCI Module (DEPRECATED)"
413 depends on USB_OHCI_HCD && ARCH_CNS3XXX 463 depends on ARCH_CNS3XXX
414 select USB_OHCI_HCD_PLATFORM 464 select USB_OHCI_HCD_PLATFORM
415 ---help--- 465 ---help---
416 This option is deprecated now and the driver was removed, use 466 This option is deprecated now and the driver was removed, use
@@ -421,7 +471,6 @@ config USB_CNS3XXX_OHCI
421 471
422config USB_OHCI_HCD_PLATFORM 472config USB_OHCI_HCD_PLATFORM
423 bool "Generic OHCI driver for a platform device" 473 bool "Generic OHCI driver for a platform device"
424 depends on USB_OHCI_HCD
425 default n 474 default n
426 ---help--- 475 ---help---
427 Adds an OHCI host driver for a generic platform device, which 476 Adds an OHCI host driver for a generic platform device, which
@@ -429,35 +478,36 @@ config USB_OHCI_HCD_PLATFORM
429 478
430 If unsure, say N. 479 If unsure, say N.
431 480
432config USB_EHCI_HCD_PLATFORM 481config USB_OCTEON_OHCI
433 tristate "Generic EHCI driver for a platform device" 482 bool "Octeon on-chip OHCI support"
434 depends on USB_EHCI_HCD 483 depends on CPU_CAVIUM_OCTEON
435 default n 484 default USB_OCTEON_EHCI
436 ---help--- 485 select USB_OHCI_BIG_ENDIAN_MMIO
437 Adds an EHCI host driver for a generic platform device, which 486 select USB_OHCI_LITTLE_ENDIAN
438 provides a memory space and an irq. 487 help
488 Enable support for the Octeon II SOC's on-chip OHCI
489 controller. It is needed for low-speed USB 1.0 device
490 support. All CN6XXX based chips with USB are supported.
439 491
440 If unsure, say N.
441 492
442config USB_OHCI_BIG_ENDIAN_DESC 493config USB_OHCI_BIG_ENDIAN_DESC
443 bool 494 bool
444 depends on USB_OHCI_HCD
445 default n 495 default n
446 496
447config USB_OHCI_BIG_ENDIAN_MMIO 497config USB_OHCI_BIG_ENDIAN_MMIO
448 bool 498 bool
449 depends on USB_OHCI_HCD
450 default n 499 default n
451 500
452config USB_OHCI_LITTLE_ENDIAN 501config USB_OHCI_LITTLE_ENDIAN
453 bool 502 bool
454 depends on USB_OHCI_HCD
455 default n if STB03xxx || PPC_MPC52xx 503 default n if STB03xxx || PPC_MPC52xx
456 default y 504 default y
457 505
506endif # USB_OHCI_HCD
507
458config USB_UHCI_HCD 508config USB_UHCI_HCD
459 tristate "UHCI HCD (most Intel and VIA) support" 509 tristate "UHCI HCD (most Intel and VIA) support"
460 depends on USB && (PCI || SPARC_LEON || ARCH_VT8500) 510 depends on PCI || SPARC_LEON || ARCH_VT8500
461 ---help--- 511 ---help---
462 The Universal Host Controller Interface is a standard by Intel for 512 The Universal Host Controller Interface is a standard by Intel for
463 accessing the USB hardware in the PC (which is also called the USB 513 accessing the USB hardware in the PC (which is also called the USB
@@ -497,7 +547,7 @@ config USB_UHCI_BIG_ENDIAN_DESC
497 547
498config USB_FHCI_HCD 548config USB_FHCI_HCD
499 tristate "Freescale QE USB Host Controller support" 549 tristate "Freescale QE USB Host Controller support"
500 depends on USB && OF_GPIO && QE_GPIO && QUICC_ENGINE 550 depends on OF_GPIO && QE_GPIO && QUICC_ENGINE
501 select FSL_GTM 551 select FSL_GTM
502 select QE_USB 552 select QE_USB
503 help 553 help
@@ -514,7 +564,7 @@ config FHCI_DEBUG
514 564
515config USB_U132_HCD 565config USB_U132_HCD
516 tristate "Elan U132 Adapter Host Controller" 566 tristate "Elan U132 Adapter Host Controller"
517 depends on USB && USB_FTDI_ELAN 567 depends on USB_FTDI_ELAN
518 default M 568 default M
519 help 569 help
520 The U132 adapter is a USB to CardBus adapter specifically designed 570 The U132 adapter is a USB to CardBus adapter specifically designed
@@ -542,7 +592,6 @@ config USB_U132_HCD
542 592
543config USB_SL811_HCD 593config USB_SL811_HCD
544 tristate "SL811HS HCD support" 594 tristate "SL811HS HCD support"
545 depends on USB
546 help 595 help
547 The SL811HS is a single-port USB controller that supports either 596 The SL811HS is a single-port USB controller that supports either
548 host side or peripheral side roles. Enable this option if your 597 host side or peripheral side roles. Enable this option if your
@@ -574,7 +623,6 @@ config USB_SL811_CS
574 623
575config USB_R8A66597_HCD 624config USB_R8A66597_HCD
576 tristate "R8A66597 HCD support" 625 tristate "R8A66597 HCD support"
577 depends on USB
578 help 626 help
579 The R8A66597 is a USB 2.0 host and peripheral controller. 627 The R8A66597 is a USB 2.0 host and peripheral controller.
580 628
@@ -586,7 +634,6 @@ config USB_R8A66597_HCD
586 634
587config USB_RENESAS_USBHS_HCD 635config USB_RENESAS_USBHS_HCD
588 tristate "Renesas USBHS HCD support" 636 tristate "Renesas USBHS HCD support"
589 depends on USB
590 depends on USB_RENESAS_USBHS 637 depends on USB_RENESAS_USBHS
591 help 638 help
592 The Renesas USBHS is a USB 2.0 host and peripheral controller. 639 The Renesas USBHS is a USB 2.0 host and peripheral controller.
@@ -611,7 +658,7 @@ config USB_WHCI_HCD
611 658
612config USB_HWA_HCD 659config USB_HWA_HCD
613 tristate "Host Wire Adapter (HWA) driver" 660 tristate "Host Wire Adapter (HWA) driver"
614 depends on USB && UWB 661 depends on UWB
615 select USB_WUSB 662 select USB_WUSB
616 select UWB_HWA 663 select UWB_HWA
617 help 664 help
@@ -625,7 +672,7 @@ config USB_HWA_HCD
625 672
626config USB_IMX21_HCD 673config USB_IMX21_HCD
627 tristate "i.MX21 HCD support" 674 tristate "i.MX21 HCD support"
628 depends on USB && ARM && ARCH_MXC 675 depends on ARM && ARCH_MXC
629 help 676 help
630 This driver enables support for the on-chip USB host in the 677 This driver enables support for the on-chip USB host in the
631 i.MX21 processor. 678 i.MX21 processor.
@@ -633,27 +680,7 @@ config USB_IMX21_HCD
633 To compile this driver as a module, choose M here: the 680 To compile this driver as a module, choose M here: the
634 module will be called "imx21-hcd". 681 module will be called "imx21-hcd".
635 682
636config USB_OCTEON_EHCI
637 bool "Octeon on-chip EHCI support"
638 depends on USB && USB_EHCI_HCD && CPU_CAVIUM_OCTEON
639 default n
640 select USB_EHCI_BIG_ENDIAN_MMIO
641 help
642 Enable support for the Octeon II SOC's on-chip EHCI
643 controller. It is needed for high-speed (480Mbit/sec)
644 USB 2.0 device support. All CN6XXX based chips with USB are
645 supported.
646 683
647config USB_OCTEON_OHCI
648 bool "Octeon on-chip OHCI support"
649 depends on USB && USB_OHCI_HCD && CPU_CAVIUM_OCTEON
650 default USB_OCTEON_EHCI
651 select USB_OHCI_BIG_ENDIAN_MMIO
652 select USB_OHCI_LITTLE_ENDIAN
653 help
654 Enable support for the Octeon II SOC's on-chip OHCI
655 controller. It is needed for low-speed USB 1.0 device
656 support. All CN6XXX based chips with USB are supported.
657 684
658config USB_OCTEON2_COMMON 685config USB_OCTEON2_COMMON
659 bool 686 bool
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 001fbff2fdef..4fb73c156d72 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -27,6 +27,12 @@ obj-$(CONFIG_USB_EHCI_HCD) += ehci-hcd.o
27obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o 27obj-$(CONFIG_USB_EHCI_PCI) += ehci-pci.o
28obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o 28obj-$(CONFIG_USB_EHCI_HCD_PLATFORM) += ehci-platform.o
29obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o 29obj-$(CONFIG_USB_EHCI_MXC) += ehci-mxc.o
30obj-$(CONFIG_USB_EHCI_HCD_OMAP) += ehci-omap.o
31obj-$(CONFIG_USB_EHCI_HCD_ORION) += ehci-orion.o
32obj-$(CONFIG_USB_EHCI_HCD_SPEAR) += ehci-spear.o
33obj-$(CONFIG_USB_EHCI_S5P) += ehci-s5p.o
34obj-$(CONFIG_USB_EHCI_HCD_AT91) += ehci-atmel.o
35obj-$(CONFIG_USB_EHCI_MSM) += ehci-msm.o
30 36
31obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o 37obj-$(CONFIG_USB_OXU210HP_HCD) += oxu210hp-hcd.o
32obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o 38obj-$(CONFIG_USB_ISP116X_HCD) += isp116x-hcd.o
diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index f3beac4d06b8..66420097c242 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -12,9 +12,22 @@
12 */ 12 */
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/platform_device.h> 15#include <linux/dma-mapping.h>
16#include <linux/io.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
16#include <linux/of.h> 19#include <linux/of.h>
17#include <linux/of_platform.h> 20#include <linux/of_platform.h>
21#include <linux/platform_device.h>
22#include <linux/usb.h>
23#include <linux/usb/hcd.h>
24
25#include "ehci.h"
26
27#define DRIVER_DESC "EHCI Atmel driver"
28
29static const char hcd_name[] = "ehci-atmel";
30static struct hc_driver __read_mostly ehci_atmel_hc_driver;
18 31
19/* interface and function clocks */ 32/* interface and function clocks */
20static struct clk *iclk, *fclk; 33static struct clk *iclk, *fclk;
@@ -50,51 +63,6 @@ static void atmel_stop_ehci(struct platform_device *pdev)
50 63
51/*-------------------------------------------------------------------------*/ 64/*-------------------------------------------------------------------------*/
52 65
53static int ehci_atmel_setup(struct usb_hcd *hcd)
54{
55 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
56
57 /* registers start at offset 0x0 */
58 ehci->caps = hcd->regs;
59
60 return ehci_setup(hcd);
61}
62
63static const struct hc_driver ehci_atmel_hc_driver = {
64 .description = hcd_name,
65 .product_desc = "Atmel EHCI UHP HS",
66 .hcd_priv_size = sizeof(struct ehci_hcd),
67
68 /* generic hardware linkage */
69 .irq = ehci_irq,
70 .flags = HCD_MEMORY | HCD_USB2,
71
72 /* basic lifecycle operations */
73 .reset = ehci_atmel_setup,
74 .start = ehci_run,
75 .stop = ehci_stop,
76 .shutdown = ehci_shutdown,
77
78 /* managing i/o requests and associated device resources */
79 .urb_enqueue = ehci_urb_enqueue,
80 .urb_dequeue = ehci_urb_dequeue,
81 .endpoint_disable = ehci_endpoint_disable,
82 .endpoint_reset = ehci_endpoint_reset,
83
84 /* scheduling support */
85 .get_frame_number = ehci_get_frame,
86
87 /* root hub support */
88 .hub_status_data = ehci_hub_status_data,
89 .hub_control = ehci_hub_control,
90 .bus_suspend = ehci_bus_suspend,
91 .bus_resume = ehci_bus_resume,
92 .relinquish_port = ehci_relinquish_port,
93 .port_handed_over = ehci_port_handed_over,
94
95 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
96};
97
98static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32); 66static u64 at91_ehci_dma_mask = DMA_BIT_MASK(32);
99 67
100static int ehci_atmel_drv_probe(struct platform_device *pdev) 68static int ehci_atmel_drv_probe(struct platform_device *pdev)
@@ -102,6 +70,7 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
102 struct usb_hcd *hcd; 70 struct usb_hcd *hcd;
103 const struct hc_driver *driver = &ehci_atmel_hc_driver; 71 const struct hc_driver *driver = &ehci_atmel_hc_driver;
104 struct resource *res; 72 struct resource *res;
73 struct ehci_hcd *ehci;
105 int irq; 74 int irq;
106 int retval; 75 int retval;
107 76
@@ -162,6 +131,10 @@ static int ehci_atmel_drv_probe(struct platform_device *pdev)
162 goto fail_request_resource; 131 goto fail_request_resource;
163 } 132 }
164 133
134 ehci = hcd_to_ehci(hcd);
135 /* registers start at offset 0x0 */
136 ehci->caps = hcd->regs;
137
165 atmel_start_ehci(pdev); 138 atmel_start_ehci(pdev);
166 139
167 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 140 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
@@ -185,7 +158,6 @@ static int ehci_atmel_drv_remove(struct platform_device *pdev)
185{ 158{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev); 159 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187 160
188 ehci_shutdown(hcd);
189 usb_remove_hcd(hcd); 161 usb_remove_hcd(hcd);
190 usb_put_hcd(hcd); 162 usb_put_hcd(hcd);
191 163
@@ -213,3 +185,25 @@ static struct platform_driver ehci_atmel_driver = {
213 .of_match_table = of_match_ptr(atmel_ehci_dt_ids), 185 .of_match_table = of_match_ptr(atmel_ehci_dt_ids),
214 }, 186 },
215}; 187};
188
189static int __init ehci_atmel_init(void)
190{
191 if (usb_disabled())
192 return -ENODEV;
193
194 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
195 ehci_init_driver(&ehci_atmel_hc_driver, NULL);
196 return platform_driver_register(&ehci_atmel_driver);
197}
198module_init(ehci_atmel_init);
199
200static void __exit ehci_atmel_cleanup(void)
201{
202 platform_driver_unregister(&ehci_atmel_driver);
203}
204module_exit(ehci_atmel_cleanup);
205
206MODULE_DESCRIPTION(DRIVER_DESC);
207MODULE_ALIAS("platform:atmel-ehci");
208MODULE_AUTHOR("Nicolas Ferre");
209MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 70b496dc18a0..5429d2645bbc 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -510,14 +510,16 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
510 spin_lock_irqsave (&ehci->lock, flags); 510 spin_lock_irqsave (&ehci->lock, flags);
511 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh) 511 for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
512 qh_lines (ehci, qh, &next, &size); 512 qh_lines (ehci, qh, &next, &size);
513 if (ehci->async_unlink && size > 0) { 513 if (!list_empty(&ehci->async_unlink) && size > 0) {
514 temp = scnprintf(next, size, "\nunlink =\n"); 514 temp = scnprintf(next, size, "\nunlink =\n");
515 size -= temp; 515 size -= temp;
516 next += temp; 516 next += temp;
517 517
518 for (qh = ehci->async_unlink; size > 0 && qh; 518 list_for_each_entry(qh, &ehci->async_unlink, unlink_node) {
519 qh = qh->unlink_next) 519 if (size <= 0)
520 qh_lines (ehci, qh, &next, &size); 520 break;
521 qh_lines(ehci, qh, &next, &size);
522 }
521 } 523 }
522 spin_unlock_irqrestore (&ehci->lock, flags); 524 spin_unlock_irqrestore (&ehci->lock, flags);
523 525
@@ -814,9 +816,10 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
814 } 816 }
815 } 817 }
816 818
817 if (ehci->async_unlink) { 819 if (!list_empty(&ehci->async_unlink)) {
818 temp = scnprintf(next, size, "async unlink qh %p\n", 820 temp = scnprintf(next, size, "async unlink qh %p\n",
819 ehci->async_unlink); 821 list_first_entry(&ehci->async_unlink,
822 struct ehci_qh, unlink_node));
820 size -= temp; 823 size -= temp;
821 next += temp; 824 next += temp;
822 } 825 }
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index d81d2fcbff18..3be3df233a0e 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -370,6 +370,15 @@ static int ehci_fsl_setup(struct usb_hcd *hcd)
370 /* EHCI registers start at offset 0x100 */ 370 /* EHCI registers start at offset 0x100 */
371 ehci->caps = hcd->regs + 0x100; 371 ehci->caps = hcd->regs + 0x100;
372 372
373#ifdef CONFIG_PPC_83xx
374 /*
375 * Deal with MPC834X that need port power to be cycled after the power
376 * fault condition is removed. Otherwise the state machine does not
377 * reflect PORTSC[CSC] correctly.
378 */
379 ehci->need_oc_pp_cycle = 1;
380#endif
381
373 hcd->has_tt = 1; 382 hcd->has_tt = 1;
374 383
375 retval = ehci_setup(hcd); 384 retval = ehci_setup(hcd);
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 416a6dce5e11..312fc10da3c7 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -482,6 +482,9 @@ static int ehci_init(struct usb_hcd *hcd)
482 * periodic_size can shrink by USBCMD update if hcc_params allows. 482 * periodic_size can shrink by USBCMD update if hcc_params allows.
483 */ 483 */
484 ehci->periodic_size = DEFAULT_I_TDPS; 484 ehci->periodic_size = DEFAULT_I_TDPS;
485 INIT_LIST_HEAD(&ehci->async_unlink);
486 INIT_LIST_HEAD(&ehci->async_idle);
487 INIT_LIST_HEAD(&ehci->intr_unlink);
485 INIT_LIST_HEAD(&ehci->intr_qh_list); 488 INIT_LIST_HEAD(&ehci->intr_qh_list);
486 INIT_LIST_HEAD(&ehci->cached_itd_list); 489 INIT_LIST_HEAD(&ehci->cached_itd_list);
487 INIT_LIST_HEAD(&ehci->cached_sitd_list); 490 INIT_LIST_HEAD(&ehci->cached_sitd_list);
@@ -670,9 +673,6 @@ int ehci_setup(struct usb_hcd *hcd)
670 if (retval) 673 if (retval)
671 return retval; 674 return retval;
672 675
673 if (ehci_is_TDI(ehci))
674 tdi_reset(ehci);
675
676 ehci_reset(ehci); 676 ehci_reset(ehci);
677 677
678 return 0; 678 return 0;
@@ -749,7 +749,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
749 /* guard against (alleged) silicon errata */ 749 /* guard against (alleged) silicon errata */
750 if (cmd & CMD_IAAD) 750 if (cmd & CMD_IAAD)
751 ehci_dbg(ehci, "IAA with IAAD still set?\n"); 751 ehci_dbg(ehci, "IAA with IAAD still set?\n");
752 if (ehci->async_iaa) 752 if (ehci->iaa_in_progress)
753 COUNT(ehci->stats.iaa); 753 COUNT(ehci->stats.iaa);
754 end_unlink_async(ehci); 754 end_unlink_async(ehci);
755 } 755 }
@@ -757,7 +757,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
757 /* remote wakeup [4.3.1] */ 757 /* remote wakeup [4.3.1] */
758 if (status & STS_PCD) { 758 if (status & STS_PCD) {
759 unsigned i = HCS_N_PORTS (ehci->hcs_params); 759 unsigned i = HCS_N_PORTS (ehci->hcs_params);
760 u32 ppcd = 0; 760 u32 ppcd = ~0;
761 761
762 /* kick root hub later */ 762 /* kick root hub later */
763 pcd_status = status; 763 pcd_status = status;
@@ -774,7 +774,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
774 int pstatus; 774 int pstatus;
775 775
776 /* leverage per-port change bits feature */ 776 /* leverage per-port change bits feature */
777 if (ehci->has_ppcd && !(ppcd & (1 << i))) 777 if (!(ppcd & (1 << i)))
778 continue; 778 continue;
779 pstatus = ehci_readl(ehci, 779 pstatus = ehci_readl(ehci,
780 &ehci->regs->port_status[i]); 780 &ehci->regs->port_status[i]);
@@ -896,17 +896,24 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
896 if (rc) 896 if (rc)
897 goto done; 897 goto done;
898 898
899 switch (usb_pipetype (urb->pipe)) { 899 if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
900 // case PIPE_CONTROL: 900 /*
901 // case PIPE_BULK: 901 * We don't expedite dequeue for isochronous URBs.
902 default: 902 * Just wait until they complete normally or their
903 * time slot expires.
904 */
905 } else {
903 qh = (struct ehci_qh *) urb->hcpriv; 906 qh = (struct ehci_qh *) urb->hcpriv;
904 if (!qh) 907 qh->exception = 1;
905 break;
906 switch (qh->qh_state) { 908 switch (qh->qh_state) {
907 case QH_STATE_LINKED: 909 case QH_STATE_LINKED:
910 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
911 start_unlink_intr(ehci, qh);
912 else
913 start_unlink_async(ehci, qh);
914 break;
908 case QH_STATE_COMPLETING: 915 case QH_STATE_COMPLETING:
909 start_unlink_async(ehci, qh); 916 qh->dequeue_during_giveback = 1;
910 break; 917 break;
911 case QH_STATE_UNLINK: 918 case QH_STATE_UNLINK:
912 case QH_STATE_UNLINK_WAIT: 919 case QH_STATE_UNLINK_WAIT:
@@ -917,33 +924,6 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
917 qh_completions(ehci, qh); 924 qh_completions(ehci, qh);
918 break; 925 break;
919 } 926 }
920 break;
921
922 case PIPE_INTERRUPT:
923 qh = (struct ehci_qh *) urb->hcpriv;
924 if (!qh)
925 break;
926 switch (qh->qh_state) {
927 case QH_STATE_LINKED:
928 case QH_STATE_COMPLETING:
929 start_unlink_intr(ehci, qh);
930 break;
931 case QH_STATE_IDLE:
932 qh_completions (ehci, qh);
933 break;
934 default:
935 ehci_dbg (ehci, "bogus qh %p state %d\n",
936 qh, qh->qh_state);
937 goto done;
938 }
939 break;
940
941 case PIPE_ISOCHRONOUS:
942 // itd or sitd ...
943
944 // wait till next completion, do it then.
945 // completion irqs can wait up to 1024 msec,
946 break;
947 } 927 }
948done: 928done:
949 spin_unlock_irqrestore (&ehci->lock, flags); 929 spin_unlock_irqrestore (&ehci->lock, flags);
@@ -984,6 +964,7 @@ rescan:
984 goto done; 964 goto done;
985 } 965 }
986 966
967 qh->exception = 1;
987 if (ehci->rh_state < EHCI_RH_RUNNING) 968 if (ehci->rh_state < EHCI_RH_RUNNING)
988 qh->qh_state = QH_STATE_IDLE; 969 qh->qh_state = QH_STATE_IDLE;
989 switch (qh->qh_state) { 970 switch (qh->qh_state) {
@@ -1052,13 +1033,12 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
1052 usb_settoggle(qh->dev, epnum, is_out, 0); 1033 usb_settoggle(qh->dev, epnum, is_out, 0);
1053 if (!list_empty(&qh->qtd_list)) { 1034 if (!list_empty(&qh->qtd_list)) {
1054 WARN_ONCE(1, "clear_halt for a busy endpoint\n"); 1035 WARN_ONCE(1, "clear_halt for a busy endpoint\n");
1055 } else if (qh->qh_state == QH_STATE_LINKED || 1036 } else {
1056 qh->qh_state == QH_STATE_COMPLETING) {
1057
1058 /* The toggle value in the QH can't be updated 1037 /* The toggle value in the QH can't be updated
1059 * while the QH is active. Unlink it now; 1038 * while the QH is active. Unlink it now;
1060 * re-linking will call qh_refresh(). 1039 * re-linking will call qh_refresh().
1061 */ 1040 */
1041 qh->exception = 1;
1062 if (eptype == USB_ENDPOINT_XFER_BULK) 1042 if (eptype == USB_ENDPOINT_XFER_BULK)
1063 start_unlink_async(ehci, qh); 1043 start_unlink_async(ehci, qh);
1064 else 1044 else
@@ -1251,11 +1231,6 @@ MODULE_LICENSE ("GPL");
1251#define PLATFORM_DRIVER ehci_hcd_sh_driver 1231#define PLATFORM_DRIVER ehci_hcd_sh_driver
1252#endif 1232#endif
1253 1233
1254#ifdef CONFIG_USB_EHCI_HCD_OMAP
1255#include "ehci-omap.c"
1256#define PLATFORM_DRIVER ehci_hcd_omap_driver
1257#endif
1258
1259#ifdef CONFIG_PPC_PS3 1234#ifdef CONFIG_PPC_PS3
1260#include "ehci-ps3.c" 1235#include "ehci-ps3.c"
1261#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver 1236#define PS3_SYSTEM_BUS_DRIVER ps3_ehci_driver
@@ -1271,41 +1246,16 @@ MODULE_LICENSE ("GPL");
1271#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver 1246#define XILINX_OF_PLATFORM_DRIVER ehci_hcd_xilinx_of_driver
1272#endif 1247#endif
1273 1248
1274#ifdef CONFIG_PLAT_ORION
1275#include "ehci-orion.c"
1276#define PLATFORM_DRIVER ehci_orion_driver
1277#endif
1278
1279#ifdef CONFIG_USB_W90X900_EHCI 1249#ifdef CONFIG_USB_W90X900_EHCI
1280#include "ehci-w90x900.c" 1250#include "ehci-w90x900.c"
1281#define PLATFORM_DRIVER ehci_hcd_w90x900_driver 1251#define PLATFORM_DRIVER ehci_hcd_w90x900_driver
1282#endif 1252#endif
1283 1253
1284#ifdef CONFIG_ARCH_AT91
1285#include "ehci-atmel.c"
1286#define PLATFORM_DRIVER ehci_atmel_driver
1287#endif
1288
1289#ifdef CONFIG_USB_OCTEON_EHCI 1254#ifdef CONFIG_USB_OCTEON_EHCI
1290#include "ehci-octeon.c" 1255#include "ehci-octeon.c"
1291#define PLATFORM_DRIVER ehci_octeon_driver 1256#define PLATFORM_DRIVER ehci_octeon_driver
1292#endif 1257#endif
1293 1258
1294#ifdef CONFIG_ARCH_VT8500
1295#include "ehci-vt8500.c"
1296#define PLATFORM_DRIVER vt8500_ehci_driver
1297#endif
1298
1299#ifdef CONFIG_PLAT_SPEAR
1300#include "ehci-spear.c"
1301#define PLATFORM_DRIVER spear_ehci_hcd_driver
1302#endif
1303
1304#ifdef CONFIG_USB_EHCI_MSM
1305#include "ehci-msm.c"
1306#define PLATFORM_DRIVER ehci_msm_driver
1307#endif
1308
1309#ifdef CONFIG_TILE_USB 1259#ifdef CONFIG_TILE_USB
1310#include "ehci-tilegx.c" 1260#include "ehci-tilegx.c"
1311#define PLATFORM_DRIVER ehci_hcd_tilegx_driver 1261#define PLATFORM_DRIVER ehci_hcd_tilegx_driver
@@ -1321,11 +1271,6 @@ MODULE_LICENSE ("GPL");
1321#define PLATFORM_DRIVER tegra_ehci_driver 1271#define PLATFORM_DRIVER tegra_ehci_driver
1322#endif 1272#endif
1323 1273
1324#ifdef CONFIG_USB_EHCI_S5P
1325#include "ehci-s5p.c"
1326#define PLATFORM_DRIVER s5p_ehci_driver
1327#endif
1328
1329#ifdef CONFIG_SPARC_LEON 1274#ifdef CONFIG_SPARC_LEON
1330#include "ehci-grlib.c" 1275#include "ehci-grlib.c"
1331#define PLATFORM_DRIVER ehci_grlib_driver 1276#define PLATFORM_DRIVER ehci_grlib_driver
@@ -1345,6 +1290,12 @@ MODULE_LICENSE ("GPL");
1345 !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \ 1290 !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \
1346 !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \ 1291 !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \
1347 !IS_ENABLED(CONFIG_USB_EHCI_MXC) && \ 1292 !IS_ENABLED(CONFIG_USB_EHCI_MXC) && \
1293 !IS_ENABLED(CONFIG_USB_EHCI_HCD_OMAP) && \
1294 !IS_ENABLED(CONFIG_USB_EHCI_HCD_ORION) && \
1295 !IS_ENABLED(CONFIG_USB_EHCI_HCD_SPEAR) && \
1296 !IS_ENABLED(CONFIG_USB_EHCI_S5P) && \
1297 !IS_ENABLED(CONFIG_USB_EHCI_HCD_AT91) && \
1298 !IS_ENABLED(CONFIG_USB_EHCI_MSM) && \
1348 !defined(PLATFORM_DRIVER) && \ 1299 !defined(PLATFORM_DRIVER) && \
1349 !defined(PS3_SYSTEM_BUS_DRIVER) && \ 1300 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1350 !defined(OF_PLATFORM_DRIVER) && \ 1301 !defined(OF_PLATFORM_DRIVER) && \
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 7d06e77f6c4f..9ab4a4d9768a 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -464,7 +464,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
464 while (i--) { 464 while (i--) {
465 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 465 temp = ehci_readl(ehci, &ehci->regs->port_status [i]);
466 if (test_bit(i, &resume_needed)) { 466 if (test_bit(i, &resume_needed)) {
467 temp &= ~(PORT_RWC_BITS | PORT_RESUME); 467 temp &= ~(PORT_RWC_BITS | PORT_SUSPEND | PORT_RESUME);
468 ehci_writel(ehci, temp, &ehci->regs->port_status [i]); 468 ehci_writel(ehci, temp, &ehci->regs->port_status [i]);
469 ehci_vdbg (ehci, "resumed port %d\n", i + 1); 469 ehci_vdbg (ehci, "resumed port %d\n", i + 1);
470 } 470 }
@@ -590,7 +590,7 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
590 u32 mask; 590 u32 mask;
591 int ports, i, retval = 1; 591 int ports, i, retval = 1;
592 unsigned long flags; 592 unsigned long flags;
593 u32 ppcd = 0; 593 u32 ppcd = ~0;
594 594
595 /* init status to no-changes */ 595 /* init status to no-changes */
596 buf [0] = 0; 596 buf [0] = 0;
@@ -628,9 +628,10 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)
628 628
629 for (i = 0; i < ports; i++) { 629 for (i = 0; i < ports; i++) {
630 /* leverage per-port change bits feature */ 630 /* leverage per-port change bits feature */
631 if (ehci->has_ppcd && !(ppcd & (1 << i))) 631 if (ppcd & (1 << i))
632 continue; 632 temp = ehci_readl(ehci, &ehci->regs->port_status[i]);
633 temp = ehci_readl(ehci, &ehci->regs->port_status [i]); 633 else
634 temp = 0;
634 635
635 /* 636 /*
636 * Return status information even for ports with OWNER set. 637 * Return status information even for ports with OWNER set.
@@ -839,7 +840,8 @@ static int ehci_hub_control (
839 * power switching; they're allowed to just limit the 840 * power switching; they're allowed to just limit the
840 * current. khubd will turn the power back on. 841 * current. khubd will turn the power back on.
841 */ 842 */
842 if ((temp & PORT_OC) && HCS_PPC(ehci->hcs_params)) { 843 if (((temp & PORT_OC) || (ehci->need_oc_pp_cycle))
844 && HCS_PPC(ehci->hcs_params)) {
843 ehci_writel(ehci, 845 ehci_writel(ehci,
844 temp & ~(PORT_RWC_BITS | PORT_POWER), 846 temp & ~(PORT_RWC_BITS | PORT_POWER),
845 status_reg); 847 status_reg);
@@ -870,10 +872,9 @@ static int ehci_hub_control (
870 usb_hcd_end_port_resume(&hcd->self, wIndex); 872 usb_hcd_end_port_resume(&hcd->self, wIndex);
871 873
872 /* stop resume signaling */ 874 /* stop resume signaling */
873 temp = ehci_readl(ehci, status_reg); 875 temp &= ~(PORT_RWC_BITS |
874 ehci_writel(ehci, 876 PORT_SUSPEND | PORT_RESUME);
875 temp & ~(PORT_RWC_BITS | PORT_RESUME), 877 ehci_writel(ehci, temp, status_reg);
876 status_reg);
877 clear_bit(wIndex, &ehci->resuming_ports); 878 clear_bit(wIndex, &ehci->resuming_ports);
878 retval = handshake(ehci, status_reg, 879 retval = handshake(ehci, status_reg,
879 PORT_RESUME, 0, 2000 /* 2msec */); 880 PORT_RESUME, 0, 2000 /* 2msec */);
@@ -883,7 +884,7 @@ static int ehci_hub_control (
883 wIndex + 1, retval); 884 wIndex + 1, retval);
884 goto error; 885 goto error;
885 } 886 }
886 temp &= ~(PORT_SUSPEND|PORT_RESUME|(3<<10)); 887 temp = ehci_readl(ehci, status_reg);
887 } 888 }
888 } 889 }
889 890
diff --git a/drivers/usb/host/ehci-msm.c b/drivers/usb/host/ehci-msm.c
index 88a49c87e748..0f717dc688b7 100644
--- a/drivers/usb/host/ehci-msm.c
+++ b/drivers/usb/host/ehci-msm.c
@@ -22,16 +22,26 @@
22 * along with this program; if not, you can find it at http://www.fsf.org 22 * along with this program; if not, you can find it at http://www.fsf.org
23 */ 23 */
24 24
25#include <linux/platform_device.h>
26#include <linux/clk.h> 25#include <linux/clk.h>
27#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/platform_device.h>
28#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
29
30#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
31#include <linux/usb/msm_hsusb_hw.h> 33#include <linux/usb/msm_hsusb_hw.h>
34#include <linux/usb.h>
35#include <linux/usb/hcd.h>
36
37#include "ehci.h"
32 38
33#define MSM_USB_BASE (hcd->regs) 39#define MSM_USB_BASE (hcd->regs)
34 40
41#define DRIVER_DESC "Qualcomm On-Chip EHCI Host Controller"
42
43static const char hcd_name[] = "ehci-msm";
44static struct hc_driver __read_mostly msm_hc_driver;
35static struct usb_phy *phy; 45static struct usb_phy *phy;
36 46
37static int ehci_msm_reset(struct usb_hcd *hcd) 47static int ehci_msm_reset(struct usb_hcd *hcd)
@@ -56,52 +66,6 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
56 return 0; 66 return 0;
57} 67}
58 68
59static struct hc_driver msm_hc_driver = {
60 .description = hcd_name,
61 .product_desc = "Qualcomm On-Chip EHCI Host Controller",
62 .hcd_priv_size = sizeof(struct ehci_hcd),
63
64 /*
65 * generic hardware linkage
66 */
67 .irq = ehci_irq,
68 .flags = HCD_USB2 | HCD_MEMORY,
69
70 .reset = ehci_msm_reset,
71 .start = ehci_run,
72
73 .stop = ehci_stop,
74 .shutdown = ehci_shutdown,
75
76 /*
77 * managing i/o requests and associated device resources
78 */
79 .urb_enqueue = ehci_urb_enqueue,
80 .urb_dequeue = ehci_urb_dequeue,
81 .endpoint_disable = ehci_endpoint_disable,
82 .endpoint_reset = ehci_endpoint_reset,
83 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
84
85 /*
86 * scheduling support
87 */
88 .get_frame_number = ehci_get_frame,
89
90 /*
91 * root hub support
92 */
93 .hub_status_data = ehci_hub_status_data,
94 .hub_control = ehci_hub_control,
95 .relinquish_port = ehci_relinquish_port,
96 .port_handed_over = ehci_port_handed_over,
97
98 /*
99 * PM support
100 */
101 .bus_suspend = ehci_bus_suspend,
102 .bus_resume = ehci_bus_resume,
103};
104
105static int ehci_msm_probe(struct platform_device *pdev) 69static int ehci_msm_probe(struct platform_device *pdev)
106{ 70{
107 struct usb_hcd *hcd; 71 struct usb_hcd *hcd;
@@ -145,7 +109,7 @@ static int ehci_msm_probe(struct platform_device *pdev)
145 * management. 109 * management.
146 */ 110 */
147 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 111 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
148 if (IS_ERR_OR_NULL(phy)) { 112 if (IS_ERR(phy)) {
149 dev_err(&pdev->dev, "unable to find transceiver\n"); 113 dev_err(&pdev->dev, "unable to find transceiver\n");
150 ret = -ENODEV; 114 ret = -ENODEV;
151 goto put_hcd; 115 goto put_hcd;
@@ -165,6 +129,8 @@ static int ehci_msm_probe(struct platform_device *pdev)
165 pm_runtime_no_callbacks(&pdev->dev); 129 pm_runtime_no_callbacks(&pdev->dev);
166 pm_runtime_enable(&pdev->dev); 130 pm_runtime_enable(&pdev->dev);
167 131
132 /* FIXME: need to call usb_add_hcd() here? */
133
168 return 0; 134 return 0;
169 135
170put_hcd: 136put_hcd:
@@ -183,6 +149,8 @@ static int ehci_msm_remove(struct platform_device *pdev)
183 149
184 otg_set_host(phy->otg, NULL); 150 otg_set_host(phy->otg, NULL);
185 151
152 /* FIXME: need to call usb_remove_hcd() here? */
153
186 usb_put_hcd(hcd); 154 usb_put_hcd(hcd);
187 155
188 return 0; 156 return 0;
@@ -226,3 +194,28 @@ static struct platform_driver ehci_msm_driver = {
226 .pm = &ehci_msm_dev_pm_ops, 194 .pm = &ehci_msm_dev_pm_ops,
227 }, 195 },
228}; 196};
197
198static const struct ehci_driver_overrides msm_overrides __initdata = {
199 .reset = ehci_msm_reset,
200};
201
202static int __init ehci_msm_init(void)
203{
204 if (usb_disabled())
205 return -ENODEV;
206
207 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
208 ehci_init_driver(&msm_hc_driver, &msm_overrides);
209 return platform_driver_register(&ehci_msm_driver);
210}
211module_init(ehci_msm_init);
212
213static void __exit ehci_msm_cleanup(void)
214{
215 platform_driver_unregister(&ehci_msm_driver);
216}
217module_exit(ehci_msm_cleanup);
218
219MODULE_DESCRIPTION(DRIVER_DESC);
220MODULE_ALIAS("platform:msm-ehci");
221MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-mv.c b/drivers/usb/host/ehci-mv.c
index 3065809546b1..402062973f03 100644
--- a/drivers/usb/host/ehci-mv.c
+++ b/drivers/usb/host/ehci-mv.c
@@ -33,25 +33,17 @@ struct ehci_hcd_mv {
33 33
34 struct mv_usb_platform_data *pdata; 34 struct mv_usb_platform_data *pdata;
35 35
36 /* clock source and total clock number */ 36 struct clk *clk;
37 unsigned int clknum;
38 struct clk *clk[0];
39}; 37};
40 38
41static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv) 39static void ehci_clock_enable(struct ehci_hcd_mv *ehci_mv)
42{ 40{
43 unsigned int i; 41 clk_prepare_enable(ehci_mv->clk);
44
45 for (i = 0; i < ehci_mv->clknum; i++)
46 clk_prepare_enable(ehci_mv->clk[i]);
47} 42}
48 43
49static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv) 44static void ehci_clock_disable(struct ehci_hcd_mv *ehci_mv)
50{ 45{
51 unsigned int i; 46 clk_disable_unprepare(ehci_mv->clk);
52
53 for (i = 0; i < ehci_mv->clknum; i++)
54 clk_disable_unprepare(ehci_mv->clk[i]);
55} 47}
56 48
57static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv) 49static int mv_ehci_enable(struct ehci_hcd_mv *ehci_mv)
@@ -144,9 +136,8 @@ static int mv_ehci_probe(struct platform_device *pdev)
144 struct ehci_hcd *ehci; 136 struct ehci_hcd *ehci;
145 struct ehci_hcd_mv *ehci_mv; 137 struct ehci_hcd_mv *ehci_mv;
146 struct resource *r; 138 struct resource *r;
147 int clk_i, retval = -ENODEV; 139 int retval = -ENODEV;
148 u32 offset; 140 u32 offset;
149 size_t size;
150 141
151 if (!pdata) { 142 if (!pdata) {
152 dev_err(&pdev->dev, "missing platform_data\n"); 143 dev_err(&pdev->dev, "missing platform_data\n");
@@ -160,8 +151,7 @@ static int mv_ehci_probe(struct platform_device *pdev)
160 if (!hcd) 151 if (!hcd)
161 return -ENOMEM; 152 return -ENOMEM;
162 153
163 size = sizeof(*ehci_mv) + sizeof(struct clk *) * pdata->clknum; 154 ehci_mv = devm_kzalloc(&pdev->dev, sizeof(*ehci_mv), GFP_KERNEL);
164 ehci_mv = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
165 if (ehci_mv == NULL) { 155 if (ehci_mv == NULL) {
166 dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n"); 156 dev_err(&pdev->dev, "cannot allocate ehci_hcd_mv\n");
167 retval = -ENOMEM; 157 retval = -ENOMEM;
@@ -172,16 +162,11 @@ static int mv_ehci_probe(struct platform_device *pdev)
172 ehci_mv->pdata = pdata; 162 ehci_mv->pdata = pdata;
173 ehci_mv->hcd = hcd; 163 ehci_mv->hcd = hcd;
174 164
175 ehci_mv->clknum = pdata->clknum; 165 ehci_mv->clk = devm_clk_get(&pdev->dev, NULL);
176 for (clk_i = 0; clk_i < ehci_mv->clknum; clk_i++) { 166 if (IS_ERR(ehci_mv->clk)) {
177 ehci_mv->clk[clk_i] = 167 dev_err(&pdev->dev, "error getting clock\n");
178 devm_clk_get(&pdev->dev, pdata->clkname[clk_i]); 168 retval = PTR_ERR(ehci_mv->clk);
179 if (IS_ERR(ehci_mv->clk[clk_i])) { 169 goto err_clear_drvdata;
180 dev_err(&pdev->dev, "error get clck \"%s\"\n",
181 pdata->clkname[clk_i]);
182 retval = PTR_ERR(ehci_mv->clk[clk_i]);
183 goto err_clear_drvdata;
184 }
185 } 170 }
186 171
187 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs"); 172 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phyregs");
@@ -225,7 +210,7 @@ static int mv_ehci_probe(struct platform_device *pdev)
225 (void __iomem *) ((unsigned long) ehci_mv->cap_regs + offset); 210 (void __iomem *) ((unsigned long) ehci_mv->cap_regs + offset);
226 211
227 hcd->rsrc_start = r->start; 212 hcd->rsrc_start = r->start;
228 hcd->rsrc_len = r->end - r->start + 1; 213 hcd->rsrc_len = resource_size(r);
229 hcd->regs = ehci_mv->op_regs; 214 hcd->regs = ehci_mv->op_regs;
230 215
231 hcd->irq = platform_get_irq(pdev, 0); 216 hcd->irq = platform_get_irq(pdev, 0);
@@ -240,12 +225,16 @@ static int mv_ehci_probe(struct platform_device *pdev)
240 225
241 ehci_mv->mode = pdata->mode; 226 ehci_mv->mode = pdata->mode;
242 if (ehci_mv->mode == MV_USB_MODE_OTG) { 227 if (ehci_mv->mode == MV_USB_MODE_OTG) {
243#ifdef CONFIG_USB_OTG_UTILS
244 ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 228 ehci_mv->otg = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
245 if (IS_ERR_OR_NULL(ehci_mv->otg)) { 229 if (IS_ERR(ehci_mv->otg)) {
246 dev_err(&pdev->dev, 230 retval = PTR_ERR(ehci_mv->otg);
247 "unable to find transceiver\n"); 231
248 retval = -ENODEV; 232 if (retval == -ENXIO)
233 dev_info(&pdev->dev, "MV_USB_MODE_OTG "
234 "must have CONFIG_USB_PHY enabled\n");
235 else
236 dev_err(&pdev->dev,
237 "unable to find transceiver\n");
249 goto err_disable_clk; 238 goto err_disable_clk;
250 } 239 }
251 240
@@ -258,11 +247,6 @@ static int mv_ehci_probe(struct platform_device *pdev)
258 } 247 }
259 /* otg will enable clock before use as host */ 248 /* otg will enable clock before use as host */
260 mv_ehci_disable(ehci_mv); 249 mv_ehci_disable(ehci_mv);
261#else
262 dev_info(&pdev->dev, "MV_USB_MODE_OTG "
263 "must have CONFIG_USB_OTG_UTILS enabled\n");
264 goto err_disable_clk;
265#endif
266 } else { 250 } else {
267 if (pdata->set_vbus) 251 if (pdata->set_vbus)
268 pdata->set_vbus(1); 252 pdata->set_vbus(1);
diff --git a/drivers/usb/host/ehci-mxc.c b/drivers/usb/host/ehci-mxc.c
index e9301fb97eaa..c369767b00e2 100644
--- a/drivers/usb/host/ehci-mxc.c
+++ b/drivers/usb/host/ehci-mxc.c
@@ -28,11 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include <linux/usb/hcd.h> 30#include <linux/usb/hcd.h>
31
32#include <linux/platform_data/usb-ehci-mxc.h> 31#include <linux/platform_data/usb-ehci-mxc.h>
33
34#include <asm/mach-types.h>
35
36#include "ehci.h" 32#include "ehci.h"
37 33
38#define DRIVER_DESC "Freescale On-Chip EHCI Host driver" 34#define DRIVER_DESC "Freescale On-Chip EHCI Host driver"
@@ -47,7 +43,7 @@ struct ehci_mxc_priv {
47 43
48static struct hc_driver __read_mostly ehci_mxc_hc_driver; 44static struct hc_driver __read_mostly ehci_mxc_hc_driver;
49 45
50static const struct ehci_driver_overrides ehci_mxc_overrides __initdata = { 46static const struct ehci_driver_overrides ehci_mxc_overrides __initconst = {
51 .extra_priv_size = sizeof(struct ehci_mxc_priv), 47 .extra_priv_size = sizeof(struct ehci_mxc_priv),
52}; 48};
53 49
@@ -61,8 +57,6 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
61 struct device *dev = &pdev->dev; 57 struct device *dev = &pdev->dev;
62 struct ehci_hcd *ehci; 58 struct ehci_hcd *ehci;
63 59
64 dev_info(&pdev->dev, "initializing i.MX USB Controller\n");
65
66 if (!pdata) { 60 if (!pdata) {
67 dev_err(dev, "No platform data given, bailing out.\n"); 61 dev_err(dev, "No platform data given, bailing out.\n");
68 return -EINVAL; 62 return -EINVAL;
@@ -178,7 +172,7 @@ err_alloc:
178 return ret; 172 return ret;
179} 173}
180 174
181static int __exit ehci_mxc_drv_remove(struct platform_device *pdev) 175static int ehci_mxc_drv_remove(struct platform_device *pdev)
182{ 176{
183 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data; 177 struct mxc_usbh_platform_data *pdata = pdev->dev.platform_data;
184 struct usb_hcd *hcd = platform_get_drvdata(pdev); 178 struct usb_hcd *hcd = platform_get_drvdata(pdev);
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index 0555ee42d7cb..3d1491b5f360 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -4,10 +4,11 @@
4 * Bus Glue for the EHCI controllers in OMAP3/4 4 * Bus Glue for the EHCI controllers in OMAP3/4
5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard 5 * Tested on several OMAP3 boards, and OMAP4 Pandaboard
6 * 6 *
7 * Copyright (C) 2007-2011 Texas Instruments, Inc. 7 * Copyright (C) 2007-2013 Texas Instruments, Inc.
8 * Author: Vikram Pandita <vikram.pandita@ti.com> 8 * Author: Vikram Pandita <vikram.pandita@ti.com>
9 * Author: Anand Gadiyar <gadiyar@ti.com> 9 * Author: Anand Gadiyar <gadiyar@ti.com>
10 * Author: Keshava Munegowda <keshava_mgowda@ti.com> 10 * Author: Keshava Munegowda <keshava_mgowda@ti.com>
11 * Author: Roger Quadros <rogerq@ti.com>
11 * 12 *
12 * Copyright (C) 2009 Nokia Corporation 13 * Copyright (C) 2009 Nokia Corporation
13 * Contact: Felipe Balbi <felipe.balbi@nokia.com> 14 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
@@ -28,21 +29,23 @@
28 * along with this program; if not, write to the Free Software 29 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * 31 *
31 * TODO (last updated Feb 27, 2010):
32 * - add kernel-doc
33 * - enable AUTOIDLE
34 * - add suspend/resume
35 * - add HSIC and TLL support
36 * - convert to use hwmod and runtime PM
37 */ 32 */
38 33
34#include <linux/kernel.h>
35#include <linux/module.h>
36#include <linux/io.h>
39#include <linux/platform_device.h> 37#include <linux/platform_device.h>
40#include <linux/slab.h> 38#include <linux/slab.h>
41#include <linux/usb/ulpi.h> 39#include <linux/usb/ulpi.h>
42#include <linux/regulator/consumer.h>
43#include <linux/pm_runtime.h> 40#include <linux/pm_runtime.h>
44#include <linux/gpio.h> 41#include <linux/gpio.h>
45#include <linux/clk.h> 42#include <linux/clk.h>
43#include <linux/usb.h>
44#include <linux/usb/hcd.h>
45#include <linux/of.h>
46#include <linux/dma-mapping.h>
47
48#include "ehci.h"
46 49
47#include <linux/platform_data/usb-omap.h> 50#include <linux/platform_data/usb-omap.h>
48 51
@@ -57,10 +60,16 @@
57#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 60#define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8
58#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 61#define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0
59 62
60/*-------------------------------------------------------------------------*/ 63#define DRIVER_DESC "OMAP-EHCI Host Controller driver"
64
65static const char hcd_name[] = "ehci-omap";
61 66
62static const struct hc_driver ehci_omap_hc_driver; 67/*-------------------------------------------------------------------------*/
63 68
69struct omap_hcd {
70 struct usb_phy *phy[OMAP3_HS_USB_PORTS]; /* one PHY for each port */
71 int nports;
72};
64 73
65static inline void ehci_write(void __iomem *base, u32 reg, u32 val) 74static inline void ehci_write(void __iomem *base, u32 reg, u32 val)
66{ 75{
@@ -72,99 +81,16 @@ static inline u32 ehci_read(void __iomem *base, u32 reg)
72 return __raw_readl(base + reg); 81 return __raw_readl(base + reg);
73} 82}
74 83
84/* configure so an HC device and id are always provided */
85/* always called with process context; sleeping is OK */
75 86
76static void omap_ehci_soft_phy_reset(struct usb_hcd *hcd, u8 port) 87static struct hc_driver __read_mostly ehci_omap_hc_driver;
77{
78 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
79 unsigned reg = 0;
80
81 reg = ULPI_FUNC_CTRL_RESET
82 /* FUNCTION_CTRL_SET register */
83 | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT)
84 /* Write */
85 | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT)
86 /* PORTn */
87 | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT)
88 /* start ULPI access*/
89 | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT);
90
91 ehci_write(hcd->regs, EHCI_INSNREG05_ULPI, reg);
92
93 /* Wait for ULPI access completion */
94 while ((ehci_read(hcd->regs, EHCI_INSNREG05_ULPI)
95 & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) {
96 cpu_relax();
97
98 if (time_after(jiffies, timeout)) {
99 dev_dbg(hcd->self.controller,
100 "phy reset operation timed out\n");
101 break;
102 }
103 }
104}
105
106static int omap_ehci_init(struct usb_hcd *hcd)
107{
108 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
109 int rc;
110 struct usbhs_omap_platform_data *pdata;
111
112 pdata = hcd->self.controller->platform_data;
113
114 /* Hold PHYs in reset while initializing EHCI controller */
115 if (pdata->phy_reset) {
116 if (gpio_is_valid(pdata->reset_gpio_port[0]))
117 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 0);
118
119 if (gpio_is_valid(pdata->reset_gpio_port[1]))
120 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 0);
121
122 /* Hold the PHY in RESET for enough time till DIR is high */
123 udelay(10);
124 }
125
126 /* Soft reset the PHY using PHY reset command over ULPI */
127 if (pdata->port_mode[0] == OMAP_EHCI_PORT_MODE_PHY)
128 omap_ehci_soft_phy_reset(hcd, 0);
129 if (pdata->port_mode[1] == OMAP_EHCI_PORT_MODE_PHY)
130 omap_ehci_soft_phy_reset(hcd, 1);
131
132 /* we know this is the memory we want, no need to ioremap again */
133 ehci->caps = hcd->regs;
134
135 rc = ehci_setup(hcd);
136
137 if (pdata->phy_reset) {
138 /* Hold the PHY in RESET for enough time till
139 * PHY is settled and ready
140 */
141 udelay(10);
142
143 if (gpio_is_valid(pdata->reset_gpio_port[0]))
144 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
145
146 if (gpio_is_valid(pdata->reset_gpio_port[1]))
147 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
148 }
149
150 return rc;
151}
152 88
153static void disable_put_regulator( 89static const struct ehci_driver_overrides ehci_omap_overrides __initdata = {
154 struct usbhs_omap_platform_data *pdata) 90 .extra_priv_size = sizeof(struct omap_hcd),
155{ 91};
156 int i;
157
158 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) {
159 if (pdata->regulator[i]) {
160 regulator_disable(pdata->regulator[i]);
161 regulator_put(pdata->regulator[i]);
162 }
163 }
164}
165 92
166/* configure so an HC device and id are always provided */ 93static u64 omap_ehci_dma_mask = DMA_BIT_MASK(32);
167/* always called with process context; sleeping is OK */
168 94
169/** 95/**
170 * ehci_hcd_omap_probe - initialize TI-based HCDs 96 * ehci_hcd_omap_probe - initialize TI-based HCDs
@@ -175,15 +101,15 @@ static void disable_put_regulator(
175 */ 101 */
176static int ehci_hcd_omap_probe(struct platform_device *pdev) 102static int ehci_hcd_omap_probe(struct platform_device *pdev)
177{ 103{
178 struct device *dev = &pdev->dev; 104 struct device *dev = &pdev->dev;
179 struct usbhs_omap_platform_data *pdata = dev->platform_data; 105 struct usbhs_omap_platform_data *pdata = dev->platform_data;
180 struct resource *res; 106 struct resource *res;
181 struct usb_hcd *hcd; 107 struct usb_hcd *hcd;
182 void __iomem *regs; 108 void __iomem *regs;
183 int ret = -ENODEV; 109 int ret = -ENODEV;
184 int irq; 110 int irq;
185 int i; 111 int i;
186 char supply[7]; 112 struct omap_hcd *omap;
187 113
188 if (usb_disabled()) 114 if (usb_disabled())
189 return -ENODEV; 115 return -ENODEV;
@@ -193,52 +119,74 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
193 return -ENODEV; 119 return -ENODEV;
194 } 120 }
195 121
196 irq = platform_get_irq_byname(pdev, "ehci-irq"); 122 /* For DT boot, get platform data from parent. i.e. usbhshost */
197 if (irq < 0) { 123 if (dev->of_node) {
198 dev_err(dev, "EHCI irq failed\n"); 124 pdata = dev->parent->platform_data;
199 return -ENODEV; 125 dev->platform_data = pdata;
200 } 126 }
201 127
202 res = platform_get_resource_byname(pdev, 128 if (!pdata) {
203 IORESOURCE_MEM, "ehci"); 129 dev_err(dev, "Missing platform data\n");
204 if (!res) {
205 dev_err(dev, "UHH EHCI get resource failed\n");
206 return -ENODEV; 130 return -ENODEV;
207 } 131 }
208 132
209 regs = ioremap(res->start, resource_size(res)); 133 irq = platform_get_irq(pdev, 0);
210 if (!regs) { 134 if (irq < 0) {
211 dev_err(dev, "UHH EHCI ioremap failed\n"); 135 dev_err(dev, "EHCI irq failed\n");
212 return -ENOMEM; 136 return -ENODEV;
213 } 137 }
214 138
139 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 regs = devm_ioremap_resource(dev, res);
141 if (IS_ERR(regs))
142 return PTR_ERR(regs);
143
144 /*
145 * Right now device-tree probed devices don't get dma_mask set.
146 * Since shared usb code relies on it, set it here for now.
147 * Once we have dma capability bindings this can go away.
148 */
149 if (!pdev->dev.dma_mask)
150 pdev->dev.dma_mask = &omap_ehci_dma_mask;
151
215 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev, 152 hcd = usb_create_hcd(&ehci_omap_hc_driver, dev,
216 dev_name(dev)); 153 dev_name(dev));
217 if (!hcd) { 154 if (!hcd) {
218 dev_err(dev, "failed to create hcd with err %d\n", ret); 155 dev_err(dev, "Failed to create HCD\n");
219 ret = -ENOMEM; 156 return -ENOMEM;
220 goto err_io;
221 } 157 }
222 158
223 hcd->rsrc_start = res->start; 159 hcd->rsrc_start = res->start;
224 hcd->rsrc_len = resource_size(res); 160 hcd->rsrc_len = resource_size(res);
225 hcd->regs = regs; 161 hcd->regs = regs;
226 162 hcd_to_ehci(hcd)->caps = regs;
227 /* get ehci regulator and enable */ 163
228 for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { 164 omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
229 if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY) { 165 omap->nports = pdata->nports;
230 pdata->regulator[i] = NULL; 166
231 continue; 167 platform_set_drvdata(pdev, hcd);
232 } 168
233 snprintf(supply, sizeof(supply), "hsusb%d", i); 169 /* get the PHY devices if needed */
234 pdata->regulator[i] = regulator_get(dev, supply); 170 for (i = 0 ; i < omap->nports ; i++) {
235 if (IS_ERR(pdata->regulator[i])) { 171 struct usb_phy *phy;
236 pdata->regulator[i] = NULL; 172
237 dev_dbg(dev, 173 /* get the PHY device */
238 "failed to get ehci port%d regulator\n", i); 174 if (dev->of_node)
239 } else { 175 phy = devm_usb_get_phy_by_phandle(dev, "phys", i);
240 regulator_enable(pdata->regulator[i]); 176 else
177 phy = devm_usb_get_phy_dev(dev, i);
178 if (IS_ERR(phy)) {
179 /* Don't bail out if PHY is not absolutely necessary */
180 if (pdata->port_mode[i] != OMAP_EHCI_PORT_MODE_PHY)
181 continue;
182
183 ret = PTR_ERR(phy);
184 dev_err(dev, "Can't get PHY device for port %d: %d\n",
185 i, ret);
186 goto err_phy;
241 } 187 }
188
189 omap->phy[i] = phy;
242 } 190 }
243 191
244 pm_runtime_enable(dev); 192 pm_runtime_enable(dev);
@@ -262,16 +210,34 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
262 goto err_pm_runtime; 210 goto err_pm_runtime;
263 } 211 }
264 212
213 /*
214 * Bring PHYs out of reset.
215 * Even though HSIC mode is a PHY-less mode, the reset
216 * line exists between the chips and can be modelled
217 * as a PHY device for reset control.
218 */
219 for (i = 0; i < omap->nports; i++) {
220 if (!omap->phy[i])
221 continue;
222
223 usb_phy_init(omap->phy[i]);
224 /* bring PHY out of suspend */
225 usb_phy_set_suspend(omap->phy[i], 0);
226 }
265 227
266 return 0; 228 return 0;
267 229
268err_pm_runtime: 230err_pm_runtime:
269 disable_put_regulator(pdata);
270 pm_runtime_put_sync(dev); 231 pm_runtime_put_sync(dev);
232
233err_phy:
234 for (i = 0; i < omap->nports; i++) {
235 if (omap->phy[i])
236 usb_phy_shutdown(omap->phy[i]);
237 }
238
271 usb_put_hcd(hcd); 239 usb_put_hcd(hcd);
272 240
273err_io:
274 iounmap(regs);
275 return ret; 241 return ret;
276} 242}
277 243
@@ -286,14 +252,19 @@ err_io:
286 */ 252 */
287static int ehci_hcd_omap_remove(struct platform_device *pdev) 253static int ehci_hcd_omap_remove(struct platform_device *pdev)
288{ 254{
289 struct device *dev = &pdev->dev; 255 struct device *dev = &pdev->dev;
290 struct usb_hcd *hcd = dev_get_drvdata(dev); 256 struct usb_hcd *hcd = dev_get_drvdata(dev);
257 struct omap_hcd *omap = (struct omap_hcd *)hcd_to_ehci(hcd)->priv;
258 int i;
291 259
292 usb_remove_hcd(hcd); 260 usb_remove_hcd(hcd);
293 disable_put_regulator(dev->platform_data);
294 iounmap(hcd->regs);
295 usb_put_hcd(hcd);
296 261
262 for (i = 0; i < omap->nports; i++) {
263 if (omap->phy[i])
264 usb_phy_shutdown(omap->phy[i]);
265 }
266
267 usb_put_hcd(hcd);
297 pm_runtime_put_sync(dev); 268 pm_runtime_put_sync(dev);
298 pm_runtime_disable(dev); 269 pm_runtime_disable(dev);
299 270
@@ -308,6 +279,13 @@ static void ehci_hcd_omap_shutdown(struct platform_device *pdev)
308 hcd->driver->shutdown(hcd); 279 hcd->driver->shutdown(hcd);
309} 280}
310 281
282static const struct of_device_id omap_ehci_dt_ids[] = {
283 { .compatible = "ti,ehci-omap" },
284 { }
285};
286
287MODULE_DEVICE_TABLE(of, omap_ehci_dt_ids);
288
311static struct platform_driver ehci_hcd_omap_driver = { 289static struct platform_driver ehci_hcd_omap_driver = {
312 .probe = ehci_hcd_omap_probe, 290 .probe = ehci_hcd_omap_probe,
313 .remove = ehci_hcd_omap_remove, 291 .remove = ehci_hcd_omap_remove,
@@ -315,56 +293,35 @@ static struct platform_driver ehci_hcd_omap_driver = {
315 /*.suspend = ehci_hcd_omap_suspend, */ 293 /*.suspend = ehci_hcd_omap_suspend, */
316 /*.resume = ehci_hcd_omap_resume, */ 294 /*.resume = ehci_hcd_omap_resume, */
317 .driver = { 295 .driver = {
318 .name = "ehci-omap", 296 .name = hcd_name,
297 .of_match_table = of_match_ptr(omap_ehci_dt_ids),
319 } 298 }
320}; 299};
321 300
322/*-------------------------------------------------------------------------*/ 301/*-------------------------------------------------------------------------*/
323 302
324static const struct hc_driver ehci_omap_hc_driver = { 303static int __init ehci_omap_init(void)
325 .description = hcd_name, 304{
326 .product_desc = "OMAP-EHCI Host Controller", 305 if (usb_disabled())
327 .hcd_priv_size = sizeof(struct ehci_hcd), 306 return -ENODEV;
328
329 /*
330 * generic hardware linkage
331 */
332 .irq = ehci_irq,
333 .flags = HCD_MEMORY | HCD_USB2,
334
335 /*
336 * basic lifecycle operations
337 */
338 .reset = omap_ehci_init,
339 .start = ehci_run,
340 .stop = ehci_stop,
341 .shutdown = ehci_shutdown,
342
343 /*
344 * managing i/o requests and associated device resources
345 */
346 .urb_enqueue = ehci_urb_enqueue,
347 .urb_dequeue = ehci_urb_dequeue,
348 .endpoint_disable = ehci_endpoint_disable,
349 .endpoint_reset = ehci_endpoint_reset,
350 307
351 /* 308 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
352 * scheduling support
353 */
354 .get_frame_number = ehci_get_frame,
355 309
356 /* 310 ehci_init_driver(&ehci_omap_hc_driver, &ehci_omap_overrides);
357 * root hub support 311 return platform_driver_register(&ehci_hcd_omap_driver);
358 */ 312}
359 .hub_status_data = ehci_hub_status_data, 313module_init(ehci_omap_init);
360 .hub_control = ehci_hub_control,
361 .bus_suspend = ehci_bus_suspend,
362 .bus_resume = ehci_bus_resume,
363 314
364 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 315static void __exit ehci_omap_cleanup(void)
365}; 316{
317 platform_driver_unregister(&ehci_hcd_omap_driver);
318}
319module_exit(ehci_omap_cleanup);
366 320
367MODULE_ALIAS("platform:ehci-omap"); 321MODULE_ALIAS("platform:ehci-omap");
368MODULE_AUTHOR("Texas Instruments, Inc."); 322MODULE_AUTHOR("Texas Instruments, Inc.");
369MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); 323MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
324MODULE_AUTHOR("Roger Quadros <rogerq@ti.com>");
370 325
326MODULE_DESCRIPTION(DRIVER_DESC);
327MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-orion.c b/drivers/usb/host/ehci-orion.c
index 914a3ecfb5d3..54c579485150 100644
--- a/drivers/usb/host/ehci-orion.c
+++ b/drivers/usb/host/ehci-orion.c
@@ -17,6 +17,12 @@
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_device.h> 18#include <linux/of_device.h>
19#include <linux/of_irq.h> 19#include <linux/of_irq.h>
20#include <linux/usb.h>
21#include <linux/usb/hcd.h>
22#include <linux/io.h>
23#include <linux/dma-mapping.h>
24
25#include "ehci.h"
20 26
21#define rdl(off) __raw_readl(hcd->regs + (off)) 27#define rdl(off) __raw_readl(hcd->regs + (off))
22#define wrl(off, val) __raw_writel((val), hcd->regs + (off)) 28#define wrl(off, val) __raw_writel((val), hcd->regs + (off))
@@ -34,6 +40,12 @@
34#define USB_PHY_IVREF_CTRL 0x440 40#define USB_PHY_IVREF_CTRL 0x440
35#define USB_PHY_TST_GRP_CTRL 0x450 41#define USB_PHY_TST_GRP_CTRL 0x450
36 42
43#define DRIVER_DESC "EHCI orion driver"
44
45static const char hcd_name[] = "ehci-orion";
46
47static struct hc_driver __read_mostly ehci_orion_hc_driver;
48
37/* 49/*
38 * Implement Orion USB controller specification guidelines 50 * Implement Orion USB controller specification guidelines
39 */ 51 */
@@ -104,51 +116,6 @@ static void orion_usb_phy_v1_setup(struct usb_hcd *hcd)
104 wrl(USB_MODE, 0x13); 116 wrl(USB_MODE, 0x13);
105} 117}
106 118
107static const struct hc_driver ehci_orion_hc_driver = {
108 .description = hcd_name,
109 .product_desc = "Marvell Orion EHCI",
110 .hcd_priv_size = sizeof(struct ehci_hcd),
111
112 /*
113 * generic hardware linkage
114 */
115 .irq = ehci_irq,
116 .flags = HCD_MEMORY | HCD_USB2,
117
118 /*
119 * basic lifecycle operations
120 */
121 .reset = ehci_setup,
122 .start = ehci_run,
123 .stop = ehci_stop,
124 .shutdown = ehci_shutdown,
125
126 /*
127 * managing i/o requests and associated device resources
128 */
129 .urb_enqueue = ehci_urb_enqueue,
130 .urb_dequeue = ehci_urb_dequeue,
131 .endpoint_disable = ehci_endpoint_disable,
132 .endpoint_reset = ehci_endpoint_reset,
133
134 /*
135 * scheduling support
136 */
137 .get_frame_number = ehci_get_frame,
138
139 /*
140 * root hub support
141 */
142 .hub_status_data = ehci_hub_status_data,
143 .hub_control = ehci_hub_control,
144 .bus_suspend = ehci_bus_suspend,
145 .bus_resume = ehci_bus_resume,
146 .relinquish_port = ehci_relinquish_port,
147 .port_handed_over = ehci_port_handed_over,
148
149 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
150};
151
152static void 119static void
153ehci_orion_conf_mbus_windows(struct usb_hcd *hcd, 120ehci_orion_conf_mbus_windows(struct usb_hcd *hcd,
154 const struct mbus_dram_target_info *dram) 121 const struct mbus_dram_target_info *dram)
@@ -305,7 +272,7 @@ err1:
305 return err; 272 return err;
306} 273}
307 274
308static int __exit ehci_orion_drv_remove(struct platform_device *pdev) 275static int ehci_orion_drv_remove(struct platform_device *pdev)
309{ 276{
310 struct usb_hcd *hcd = platform_get_drvdata(pdev); 277 struct usb_hcd *hcd = platform_get_drvdata(pdev);
311 struct clk *clk; 278 struct clk *clk;
@@ -323,8 +290,6 @@ static int __exit ehci_orion_drv_remove(struct platform_device *pdev)
323 return 0; 290 return 0;
324} 291}
325 292
326MODULE_ALIAS("platform:orion-ehci");
327
328static const struct of_device_id ehci_orion_dt_ids[] = { 293static const struct of_device_id ehci_orion_dt_ids[] = {
329 { .compatible = "marvell,orion-ehci", }, 294 { .compatible = "marvell,orion-ehci", },
330 {}, 295 {},
@@ -333,7 +298,7 @@ MODULE_DEVICE_TABLE(of, ehci_orion_dt_ids);
333 298
334static struct platform_driver ehci_orion_driver = { 299static struct platform_driver ehci_orion_driver = {
335 .probe = ehci_orion_drv_probe, 300 .probe = ehci_orion_drv_probe,
336 .remove = __exit_p(ehci_orion_drv_remove), 301 .remove = ehci_orion_drv_remove,
337 .shutdown = usb_hcd_platform_shutdown, 302 .shutdown = usb_hcd_platform_shutdown,
338 .driver = { 303 .driver = {
339 .name = "orion-ehci", 304 .name = "orion-ehci",
@@ -341,3 +306,26 @@ static struct platform_driver ehci_orion_driver = {
341 .of_match_table = of_match_ptr(ehci_orion_dt_ids), 306 .of_match_table = of_match_ptr(ehci_orion_dt_ids),
342 }, 307 },
343}; 308};
309
310static int __init ehci_orion_init(void)
311{
312 if (usb_disabled())
313 return -ENODEV;
314
315 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
316
317 ehci_init_driver(&ehci_orion_hc_driver, NULL);
318 return platform_driver_register(&ehci_orion_driver);
319}
320module_init(ehci_orion_init);
321
322static void __exit ehci_orion_cleanup(void)
323{
324 platform_driver_unregister(&ehci_orion_driver);
325}
326module_exit(ehci_orion_cleanup);
327
328MODULE_DESCRIPTION(DRIVER_DESC);
329MODULE_ALIAS("platform:orion-ehci");
330MODULE_AUTHOR("Tzachi Perelstein");
331MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 170b9399e09f..595d210655b6 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -292,17 +292,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
292 } 292 }
293 } 293 }
294 294
295#ifdef CONFIG_USB_SUSPEND 295#ifdef CONFIG_PM_RUNTIME
296 /* REVISIT: the controller works fine for wakeup iff the root hub
297 * itself is "globally" suspended, but usbcore currently doesn't
298 * understand such things.
299 *
300 * System suspend currently expects to be able to suspend the entire
301 * device tree, device-at-a-time. If we failed selective suspend
302 * reports, system suspend would fail; so the root hub code must claim
303 * success. That's lying to usbcore, and it matters for runtime
304 * PM scenarios with selective suspend and remote wakeup...
305 */
306 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev)) 296 if (ehci->no_selective_suspend && device_can_wakeup(&pdev->dev))
307 ehci_warn(ehci, "selective suspend/wakeup unavailable\n"); 297 ehci_warn(ehci, "selective suspend/wakeup unavailable\n");
308#endif 298#endif
@@ -385,7 +375,7 @@ static int ehci_pci_resume(struct usb_hcd *hcd, bool hibernated)
385 375
386static struct hc_driver __read_mostly ehci_pci_hc_driver; 376static struct hc_driver __read_mostly ehci_pci_hc_driver;
387 377
388static const struct ehci_driver_overrides pci_overrides __initdata = { 378static const struct ehci_driver_overrides pci_overrides __initconst = {
389 .reset = ehci_pci_setup, 379 .reset = ehci_pci_setup,
390}; 380};
391 381
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index ca7506390542..f47f2594c9d4 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -18,11 +18,13 @@
18 * 18 *
19 * Licensed under the GNU/GPL. See COPYING for details. 19 * Licensed under the GNU/GPL. See COPYING for details.
20 */ 20 */
21#include <linux/dma-mapping.h>
21#include <linux/err.h> 22#include <linux/err.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
23#include <linux/hrtimer.h> 24#include <linux/hrtimer.h>
24#include <linux/io.h> 25#include <linux/io.h>
25#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/of.h>
26#include <linux/platform_device.h> 28#include <linux/platform_device.h>
27#include <linux/usb.h> 29#include <linux/usb.h>
28#include <linux/usb/hcd.h> 30#include <linux/usb/hcd.h>
@@ -58,26 +60,36 @@ static int ehci_platform_reset(struct usb_hcd *hcd)
58 60
59static struct hc_driver __read_mostly ehci_platform_hc_driver; 61static struct hc_driver __read_mostly ehci_platform_hc_driver;
60 62
61static const struct ehci_driver_overrides platform_overrides __initdata = { 63static const struct ehci_driver_overrides platform_overrides __initconst = {
62 .reset = ehci_platform_reset, 64 .reset = ehci_platform_reset,
63}; 65};
64 66
67static struct usb_ehci_pdata ehci_platform_defaults;
68
65static int ehci_platform_probe(struct platform_device *dev) 69static int ehci_platform_probe(struct platform_device *dev)
66{ 70{
67 struct usb_hcd *hcd; 71 struct usb_hcd *hcd;
68 struct resource *res_mem; 72 struct resource *res_mem;
69 struct usb_ehci_pdata *pdata = dev->dev.platform_data; 73 struct usb_ehci_pdata *pdata;
70 int irq; 74 int irq;
71 int err = -ENOMEM; 75 int err = -ENOMEM;
72 76
73 if (!pdata) {
74 WARN_ON(1);
75 return -ENODEV;
76 }
77
78 if (usb_disabled()) 77 if (usb_disabled())
79 return -ENODEV; 78 return -ENODEV;
80 79
80 /*
81 * use reasonable defaults so platforms don't have to provide these.
82 * with DT probing on ARM, none of these are set.
83 */
84 if (!dev->dev.platform_data)
85 dev->dev.platform_data = &ehci_platform_defaults;
86 if (!dev->dev.dma_mask)
87 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
88 if (!dev->dev.coherent_dma_mask)
89 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
90
91 pdata = dev->dev.platform_data;
92
81 irq = platform_get_irq(dev, 0); 93 irq = platform_get_irq(dev, 0);
82 if (irq < 0) { 94 if (irq < 0) {
83 dev_err(&dev->dev, "no irq provided"); 95 dev_err(&dev->dev, "no irq provided");
@@ -139,6 +151,9 @@ static int ehci_platform_remove(struct platform_device *dev)
139 if (pdata->power_off) 151 if (pdata->power_off)
140 pdata->power_off(dev); 152 pdata->power_off(dev);
141 153
154 if (pdata == &ehci_platform_defaults)
155 dev->dev.platform_data = NULL;
156
142 return 0; 157 return 0;
143} 158}
144 159
@@ -183,6 +198,12 @@ static int ehci_platform_resume(struct device *dev)
183#define ehci_platform_resume NULL 198#define ehci_platform_resume NULL
184#endif /* CONFIG_PM */ 199#endif /* CONFIG_PM */
185 200
201static const struct of_device_id vt8500_ehci_ids[] = {
202 { .compatible = "via,vt8500-ehci", },
203 { .compatible = "wm,prizm-ehci", },
204 {}
205};
206
186static const struct platform_device_id ehci_platform_table[] = { 207static const struct platform_device_id ehci_platform_table[] = {
187 { "ehci-platform", 0 }, 208 { "ehci-platform", 0 },
188 { } 209 { }
@@ -203,6 +224,7 @@ static struct platform_driver ehci_platform_driver = {
203 .owner = THIS_MODULE, 224 .owner = THIS_MODULE,
204 .name = "ehci-platform", 225 .name = "ehci-platform",
205 .pm = &ehci_platform_pm_ops, 226 .pm = &ehci_platform_pm_ops,
227 .of_match_table = of_match_ptr(vt8500_ehci_ids),
206 } 228 }
207}; 229};
208 230
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index df5925a4f0db..fd983771b025 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -221,7 +221,6 @@ static int ps3_ehci_remove(struct ps3_system_bus_device *dev)
221 221
222 tmp = hcd->irq; 222 tmp = hcd->irq;
223 223
224 ehci_shutdown(hcd);
225 usb_remove_hcd(hcd); 224 usb_remove_hcd(hcd);
226 225
227 ps3_system_bus_set_drvdata(dev, NULL); 226 ps3_system_bus_set_drvdata(dev, NULL);
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 23d136904285..d34b399b78e2 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -90,7 +90,7 @@ qh_update (struct ehci_hcd *ehci, struct ehci_qh *qh, struct ehci_qtd *qtd)
90 struct ehci_qh_hw *hw = qh->hw; 90 struct ehci_qh_hw *hw = qh->hw;
91 91
92 /* writes to an active overlay are unsafe */ 92 /* writes to an active overlay are unsafe */
93 BUG_ON(qh->qh_state != QH_STATE_IDLE); 93 WARN_ON(qh->qh_state != QH_STATE_IDLE);
94 94
95 hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma); 95 hw->hw_qtd_next = QTD_NEXT(ehci, qtd->qtd_dma);
96 hw->hw_alt_next = EHCI_LIST_END(ehci); 96 hw->hw_alt_next = EHCI_LIST_END(ehci);
@@ -123,26 +123,19 @@ qh_refresh (struct ehci_hcd *ehci, struct ehci_qh *qh)
123{ 123{
124 struct ehci_qtd *qtd; 124 struct ehci_qtd *qtd;
125 125
126 if (list_empty (&qh->qtd_list)) 126 qtd = list_entry(qh->qtd_list.next, struct ehci_qtd, qtd_list);
127 qtd = qh->dummy;
128 else {
129 qtd = list_entry (qh->qtd_list.next,
130 struct ehci_qtd, qtd_list);
131 /*
132 * first qtd may already be partially processed.
133 * If we come here during unlink, the QH overlay region
134 * might have reference to the just unlinked qtd. The
135 * qtd is updated in qh_completions(). Update the QH
136 * overlay here.
137 */
138 if (qh->hw->hw_token & ACTIVE_BIT(ehci)) {
139 qh->hw->hw_qtd_next = qtd->hw_next;
140 qtd = NULL;
141 }
142 }
143 127
144 if (qtd) 128 /*
145 qh_update (ehci, qh, qtd); 129 * first qtd may already be partially processed.
130 * If we come here during unlink, the QH overlay region
131 * might have reference to the just unlinked qtd. The
132 * qtd is updated in qh_completions(). Update the QH
133 * overlay here.
134 */
135 if (qh->hw->hw_token & ACTIVE_BIT(ehci))
136 qh->hw->hw_qtd_next = qtd->hw_next;
137 else
138 qh_update(ehci, qh, qtd);
146} 139}
147 140
148/*-------------------------------------------------------------------------*/ 141/*-------------------------------------------------------------------------*/
@@ -299,8 +292,8 @@ static int qh_schedule (struct ehci_hcd *ehci, struct ehci_qh *qh);
299 292
300/* 293/*
301 * Process and free completed qtds for a qh, returning URBs to drivers. 294 * Process and free completed qtds for a qh, returning URBs to drivers.
302 * Chases up to qh->hw_current. Returns number of completions called, 295 * Chases up to qh->hw_current. Returns nonzero if the caller should
303 * indicating how much "real" work we did. 296 * unlink qh.
304 */ 297 */
305static unsigned 298static unsigned
306qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh) 299qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
@@ -309,13 +302,9 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
309 struct list_head *entry, *tmp; 302 struct list_head *entry, *tmp;
310 int last_status; 303 int last_status;
311 int stopped; 304 int stopped;
312 unsigned count = 0;
313 u8 state; 305 u8 state;
314 struct ehci_qh_hw *hw = qh->hw; 306 struct ehci_qh_hw *hw = qh->hw;
315 307
316 if (unlikely (list_empty (&qh->qtd_list)))
317 return count;
318
319 /* completions (or tasks on other cpus) must never clobber HALT 308 /* completions (or tasks on other cpus) must never clobber HALT
320 * till we've gone through and cleaned everything up, even when 309 * till we've gone through and cleaned everything up, even when
321 * they add urbs to this qh's queue or mark them for unlinking. 310 * they add urbs to this qh's queue or mark them for unlinking.
@@ -333,7 +322,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
333 rescan: 322 rescan:
334 last = NULL; 323 last = NULL;
335 last_status = -EINPROGRESS; 324 last_status = -EINPROGRESS;
336 qh->needs_rescan = 0; 325 qh->dequeue_during_giveback = 0;
337 326
338 /* remove de-activated QTDs from front of queue. 327 /* remove de-activated QTDs from front of queue.
339 * after faults (including short reads), cleanup this urb 328 * after faults (including short reads), cleanup this urb
@@ -352,7 +341,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
352 if (last) { 341 if (last) {
353 if (likely (last->urb != urb)) { 342 if (likely (last->urb != urb)) {
354 ehci_urb_done(ehci, last->urb, last_status); 343 ehci_urb_done(ehci, last->urb, last_status);
355 count++;
356 last_status = -EINPROGRESS; 344 last_status = -EINPROGRESS;
357 } 345 }
358 ehci_qtd_free (ehci, last); 346 ehci_qtd_free (ehci, last);
@@ -526,23 +514,16 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
526 /* last urb's completion might still need calling */ 514 /* last urb's completion might still need calling */
527 if (likely (last != NULL)) { 515 if (likely (last != NULL)) {
528 ehci_urb_done(ehci, last->urb, last_status); 516 ehci_urb_done(ehci, last->urb, last_status);
529 count++;
530 ehci_qtd_free (ehci, last); 517 ehci_qtd_free (ehci, last);
531 } 518 }
532 519
533 /* Do we need to rescan for URBs dequeued during a giveback? */ 520 /* Do we need to rescan for URBs dequeued during a giveback? */
534 if (unlikely(qh->needs_rescan)) { 521 if (unlikely(qh->dequeue_during_giveback)) {
535 /* If the QH is already unlinked, do the rescan now. */ 522 /* If the QH is already unlinked, do the rescan now. */
536 if (state == QH_STATE_IDLE) 523 if (state == QH_STATE_IDLE)
537 goto rescan; 524 goto rescan;
538 525
539 /* Otherwise we have to wait until the QH is fully unlinked. 526 /* Otherwise the caller must unlink the QH. */
540 * Our caller will start an unlink if qh->needs_rescan is
541 * set. But if an unlink has already started, nothing needs
542 * to be done.
543 */
544 if (state != QH_STATE_LINKED)
545 qh->needs_rescan = 0;
546 } 527 }
547 528
548 /* restore original state; caller must unlink or relink */ 529 /* restore original state; caller must unlink or relink */
@@ -551,33 +532,23 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
551 /* be sure the hardware's done with the qh before refreshing 532 /* be sure the hardware's done with the qh before refreshing
552 * it after fault cleanup, or recovering from silicon wrongly 533 * it after fault cleanup, or recovering from silicon wrongly
553 * overlaying the dummy qtd (which reduces DMA chatter). 534 * overlaying the dummy qtd (which reduces DMA chatter).
535 *
536 * We won't refresh a QH that's linked (after the HC
537 * stopped the queue). That avoids a race:
538 * - HC reads first part of QH;
539 * - CPU updates that first part and the token;
540 * - HC reads rest of that QH, including token
541 * Result: HC gets an inconsistent image, and then
542 * DMAs to/from the wrong memory (corrupting it).
543 *
544 * That should be rare for interrupt transfers,
545 * except maybe high bandwidth ...
554 */ 546 */
555 if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci)) { 547 if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci))
556 switch (state) { 548 qh->exception = 1;
557 case QH_STATE_IDLE:
558 qh_refresh(ehci, qh);
559 break;
560 case QH_STATE_LINKED:
561 /* We won't refresh a QH that's linked (after the HC
562 * stopped the queue). That avoids a race:
563 * - HC reads first part of QH;
564 * - CPU updates that first part and the token;
565 * - HC reads rest of that QH, including token
566 * Result: HC gets an inconsistent image, and then
567 * DMAs to/from the wrong memory (corrupting it).
568 *
569 * That should be rare for interrupt transfers,
570 * except maybe high bandwidth ...
571 */
572 549
573 /* Tell the caller to start an unlink */ 550 /* Let the caller know if the QH needs to be unlinked. */
574 qh->needs_rescan = 1; 551 return qh->exception;
575 break;
576 /* otherwise, unlink already started */
577 }
578 }
579
580 return count;
581} 552}
582 553
583/*-------------------------------------------------------------------------*/ 554/*-------------------------------------------------------------------------*/
@@ -957,14 +928,13 @@ done:
957 928
958 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */ 929 /* NOTE: if (PIPE_INTERRUPT) { scheduler sets s-mask } */
959 930
960 /* init as live, toggle clear, advance to dummy */ 931 /* init as live, toggle clear */
961 qh->qh_state = QH_STATE_IDLE; 932 qh->qh_state = QH_STATE_IDLE;
962 hw = qh->hw; 933 hw = qh->hw;
963 hw->hw_info1 = cpu_to_hc32(ehci, info1); 934 hw->hw_info1 = cpu_to_hc32(ehci, info1);
964 hw->hw_info2 = cpu_to_hc32(ehci, info2); 935 hw->hw_info2 = cpu_to_hc32(ehci, info2);
965 qh->is_out = !is_input; 936 qh->is_out = !is_input;
966 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1); 937 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), !is_input, 1);
967 qh_refresh (ehci, qh);
968 return qh; 938 return qh;
969} 939}
970 940
@@ -988,8 +958,9 @@ static void disable_async(struct ehci_hcd *ehci)
988 if (--ehci->async_count) 958 if (--ehci->async_count)
989 return; 959 return;
990 960
991 /* The async schedule and async_unlink list are supposed to be empty */ 961 /* The async schedule and unlink lists are supposed to be empty */
992 WARN_ON(ehci->async->qh_next.qh || ehci->async_unlink); 962 WARN_ON(ehci->async->qh_next.qh || !list_empty(&ehci->async_unlink) ||
963 !list_empty(&ehci->async_idle));
993 964
994 /* Don't turn off the schedule until ASS is 1 */ 965 /* Don't turn off the schedule until ASS is 1 */
995 ehci_poll_ASS(ehci); 966 ehci_poll_ASS(ehci);
@@ -1020,8 +991,9 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1020 head->qh_next.qh = qh; 991 head->qh_next.qh = qh;
1021 head->hw->hw_next = dma; 992 head->hw->hw_next = dma;
1022 993
1023 qh->xacterrs = 0;
1024 qh->qh_state = QH_STATE_LINKED; 994 qh->qh_state = QH_STATE_LINKED;
995 qh->xacterrs = 0;
996 qh->exception = 0;
1025 /* qtd completions reported later by interrupt */ 997 /* qtd completions reported later by interrupt */
1026 998
1027 enable_async(ehci); 999 enable_async(ehci);
@@ -1179,11 +1151,7 @@ static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1179 1151
1180 /* Add to the end of the list of QHs waiting for the next IAAD */ 1152 /* Add to the end of the list of QHs waiting for the next IAAD */
1181 qh->qh_state = QH_STATE_UNLINK_WAIT; 1153 qh->qh_state = QH_STATE_UNLINK_WAIT;
1182 if (ehci->async_unlink) 1154 list_add_tail(&qh->unlink_node, &ehci->async_unlink);
1183 ehci->async_unlink_last->unlink_next = qh;
1184 else
1185 ehci->async_unlink = qh;
1186 ehci->async_unlink_last = qh;
1187 1155
1188 /* Unlink it from the schedule */ 1156 /* Unlink it from the schedule */
1189 prev = ehci->async; 1157 prev = ehci->async;
@@ -1196,44 +1164,19 @@ static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1196 ehci->qh_scan_next = qh->qh_next.qh; 1164 ehci->qh_scan_next = qh->qh_next.qh;
1197} 1165}
1198 1166
1199static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested) 1167static void start_iaa_cycle(struct ehci_hcd *ehci)
1200{ 1168{
1201 /* 1169 /* Do nothing if an IAA cycle is already running */
1202 * Do nothing if an IAA cycle is already running or 1170 if (ehci->iaa_in_progress)
1203 * if one will be started shortly.
1204 */
1205 if (ehci->async_iaa || ehci->async_unlinking)
1206 return; 1171 return;
1172 ehci->iaa_in_progress = true;
1207 1173
1208 /* If the controller isn't running, we don't have to wait for it */ 1174 /* If the controller isn't running, we don't have to wait for it */
1209 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) { 1175 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
1210 1176 end_unlink_async(ehci);
1211 /* Do all the waiting QHs */
1212 ehci->async_iaa = ehci->async_unlink;
1213 ehci->async_unlink = NULL;
1214
1215 if (!nested) /* Avoid recursion */
1216 end_unlink_async(ehci);
1217 1177
1218 /* Otherwise start a new IAA cycle */ 1178 /* Otherwise start a new IAA cycle */
1219 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) { 1179 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
1220 struct ehci_qh *qh;
1221
1222 /* Do only the first waiting QH (nVidia bug?) */
1223 qh = ehci->async_unlink;
1224
1225 /*
1226 * Intel (?) bug: The HC can write back the overlay region
1227 * even after the IAA interrupt occurs. In self-defense,
1228 * always go through two IAA cycles for each QH.
1229 */
1230 if (qh->qh_state == QH_STATE_UNLINK_WAIT) {
1231 qh->qh_state = QH_STATE_UNLINK;
1232 } else {
1233 ehci->async_iaa = qh;
1234 ehci->async_unlink = qh->unlink_next;
1235 qh->unlink_next = NULL;
1236 }
1237 1180
1238 /* Make sure the unlinks are all visible to the hardware */ 1181 /* Make sure the unlinks are all visible to the hardware */
1239 wmb(); 1182 wmb();
@@ -1250,36 +1193,73 @@ static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested)
1250static void end_unlink_async(struct ehci_hcd *ehci) 1193static void end_unlink_async(struct ehci_hcd *ehci)
1251{ 1194{
1252 struct ehci_qh *qh; 1195 struct ehci_qh *qh;
1196 bool early_exit;
1253 1197
1254 if (ehci->has_synopsys_hc_bug) 1198 if (ehci->has_synopsys_hc_bug)
1255 ehci_writel(ehci, (u32) ehci->async->qh_dma, 1199 ehci_writel(ehci, (u32) ehci->async->qh_dma,
1256 &ehci->regs->async_next); 1200 &ehci->regs->async_next);
1257 1201
1202 /* The current IAA cycle has ended */
1203 ehci->iaa_in_progress = false;
1204
1205 if (list_empty(&ehci->async_unlink))
1206 return;
1207 qh = list_first_entry(&ehci->async_unlink, struct ehci_qh,
1208 unlink_node); /* QH whose IAA cycle just ended */
1209
1210 /*
1211 * If async_unlinking is set then this routine is already running,
1212 * either on the stack or on another CPU.
1213 */
1214 early_exit = ehci->async_unlinking;
1215
1216 /* If the controller isn't running, process all the waiting QHs */
1217 if (ehci->rh_state < EHCI_RH_RUNNING)
1218 list_splice_tail_init(&ehci->async_unlink, &ehci->async_idle);
1219
1220 /*
1221 * Intel (?) bug: The HC can write back the overlay region even
1222 * after the IAA interrupt occurs. In self-defense, always go
1223 * through two IAA cycles for each QH.
1224 */
1225 else if (qh->qh_state == QH_STATE_UNLINK_WAIT) {
1226 qh->qh_state = QH_STATE_UNLINK;
1227 early_exit = true;
1228 }
1229
1230 /* Otherwise process only the first waiting QH (NVIDIA bug?) */
1231 else
1232 list_move_tail(&qh->unlink_node, &ehci->async_idle);
1233
1234 /* Start a new IAA cycle if any QHs are waiting for it */
1235 if (!list_empty(&ehci->async_unlink))
1236 start_iaa_cycle(ehci);
1237
1238 /*
1239 * Don't allow nesting or concurrent calls,
1240 * or wait for the second IAA cycle for the next QH.
1241 */
1242 if (early_exit)
1243 return;
1244
1258 /* Process the idle QHs */ 1245 /* Process the idle QHs */
1259 restart:
1260 ehci->async_unlinking = true; 1246 ehci->async_unlinking = true;
1261 while (ehci->async_iaa) { 1247 while (!list_empty(&ehci->async_idle)) {
1262 qh = ehci->async_iaa; 1248 qh = list_first_entry(&ehci->async_idle, struct ehci_qh,
1263 ehci->async_iaa = qh->unlink_next; 1249 unlink_node);
1264 qh->unlink_next = NULL; 1250 list_del(&qh->unlink_node);
1265 1251
1266 qh->qh_state = QH_STATE_IDLE; 1252 qh->qh_state = QH_STATE_IDLE;
1267 qh->qh_next.qh = NULL; 1253 qh->qh_next.qh = NULL;
1268 1254
1269 qh_completions(ehci, qh); 1255 if (!list_empty(&qh->qtd_list))
1256 qh_completions(ehci, qh);
1270 if (!list_empty(&qh->qtd_list) && 1257 if (!list_empty(&qh->qtd_list) &&
1271 ehci->rh_state == EHCI_RH_RUNNING) 1258 ehci->rh_state == EHCI_RH_RUNNING)
1272 qh_link_async(ehci, qh); 1259 qh_link_async(ehci, qh);
1273 disable_async(ehci); 1260 disable_async(ehci);
1274 } 1261 }
1275 ehci->async_unlinking = false; 1262 ehci->async_unlinking = false;
1276
1277 /* Start a new IAA cycle if any QHs are waiting for it */
1278 if (ehci->async_unlink) {
1279 start_iaa_cycle(ehci, true);
1280 if (unlikely(ehci->rh_state < EHCI_RH_RUNNING))
1281 goto restart;
1282 }
1283} 1263}
1284 1264
1285static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh); 1265static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh);
@@ -1288,7 +1268,6 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1288{ 1268{
1289 struct ehci_qh *qh; 1269 struct ehci_qh *qh;
1290 struct ehci_qh *qh_to_unlink = NULL; 1270 struct ehci_qh *qh_to_unlink = NULL;
1291 bool check_unlinks_later = false;
1292 int count = 0; 1271 int count = 0;
1293 1272
1294 /* Find the last async QH which has been empty for a timer cycle */ 1273 /* Find the last async QH which has been empty for a timer cycle */
@@ -1296,15 +1275,13 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1296 if (list_empty(&qh->qtd_list) && 1275 if (list_empty(&qh->qtd_list) &&
1297 qh->qh_state == QH_STATE_LINKED) { 1276 qh->qh_state == QH_STATE_LINKED) {
1298 ++count; 1277 ++count;
1299 if (qh->unlink_cycle == ehci->async_unlink_cycle) 1278 if (qh->unlink_cycle != ehci->async_unlink_cycle)
1300 check_unlinks_later = true;
1301 else
1302 qh_to_unlink = qh; 1279 qh_to_unlink = qh;
1303 } 1280 }
1304 } 1281 }
1305 1282
1306 /* If nothing else is being unlinked, unlink the last empty QH */ 1283 /* If nothing else is being unlinked, unlink the last empty QH */
1307 if (!ehci->async_iaa && !ehci->async_unlink && qh_to_unlink) { 1284 if (list_empty(&ehci->async_unlink) && qh_to_unlink) {
1308 start_unlink_async(ehci, qh_to_unlink); 1285 start_unlink_async(ehci, qh_to_unlink);
1309 --count; 1286 --count;
1310 } 1287 }
@@ -1317,7 +1294,7 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
1317} 1294}
1318 1295
1319/* The root hub is suspended; unlink all the async QHs */ 1296/* The root hub is suspended; unlink all the async QHs */
1320static void unlink_empty_async_suspended(struct ehci_hcd *ehci) 1297static void __maybe_unused unlink_empty_async_suspended(struct ehci_hcd *ehci)
1321{ 1298{
1322 struct ehci_qh *qh; 1299 struct ehci_qh *qh;
1323 1300
@@ -1326,7 +1303,7 @@ static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
1326 WARN_ON(!list_empty(&qh->qtd_list)); 1303 WARN_ON(!list_empty(&qh->qtd_list));
1327 single_unlink_async(ehci, qh); 1304 single_unlink_async(ehci, qh);
1328 } 1305 }
1329 start_iaa_cycle(ehci, false); 1306 start_iaa_cycle(ehci);
1330} 1307}
1331 1308
1332/* makes sure the async qh will become idle */ 1309/* makes sure the async qh will become idle */
@@ -1334,19 +1311,12 @@ static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
1334 1311
1335static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh) 1312static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1336{ 1313{
1337 /* 1314 /* If the QH isn't linked then there's nothing we can do. */
1338 * If the QH isn't linked then there's nothing we can do 1315 if (qh->qh_state != QH_STATE_LINKED)
1339 * unless we were called during a giveback, in which case
1340 * qh_completions() has to deal with it.
1341 */
1342 if (qh->qh_state != QH_STATE_LINKED) {
1343 if (qh->qh_state == QH_STATE_COMPLETING)
1344 qh->needs_rescan = 1;
1345 return; 1316 return;
1346 }
1347 1317
1348 single_unlink_async(ehci, qh); 1318 single_unlink_async(ehci, qh);
1349 start_iaa_cycle(ehci, false); 1319 start_iaa_cycle(ehci);
1350} 1320}
1351 1321
1352/*-------------------------------------------------------------------------*/ 1322/*-------------------------------------------------------------------------*/
@@ -1360,7 +1330,7 @@ static void scan_async (struct ehci_hcd *ehci)
1360 while (ehci->qh_scan_next) { 1330 while (ehci->qh_scan_next) {
1361 qh = ehci->qh_scan_next; 1331 qh = ehci->qh_scan_next;
1362 ehci->qh_scan_next = qh->qh_next.qh; 1332 ehci->qh_scan_next = qh->qh_next.qh;
1363 rescan: 1333
1364 /* clean any finished work for this qh */ 1334 /* clean any finished work for this qh */
1365 if (!list_empty(&qh->qtd_list)) { 1335 if (!list_empty(&qh->qtd_list)) {
1366 int temp; 1336 int temp;
@@ -1373,14 +1343,13 @@ static void scan_async (struct ehci_hcd *ehci)
1373 * in single_unlink_async(). 1343 * in single_unlink_async().
1374 */ 1344 */
1375 temp = qh_completions(ehci, qh); 1345 temp = qh_completions(ehci, qh);
1376 if (qh->needs_rescan) { 1346 if (unlikely(temp)) {
1377 start_unlink_async(ehci, qh); 1347 start_unlink_async(ehci, qh);
1378 } else if (list_empty(&qh->qtd_list) 1348 } else if (list_empty(&qh->qtd_list)
1379 && qh->qh_state == QH_STATE_LINKED) { 1349 && qh->qh_state == QH_STATE_LINKED) {
1380 qh->unlink_cycle = ehci->async_unlink_cycle; 1350 qh->unlink_cycle = ehci->async_unlink_cycle;
1381 check_unlinks_later = true; 1351 check_unlinks_later = true;
1382 } else if (temp != 0) 1352 }
1383 goto rescan;
1384 } 1353 }
1385 } 1354 }
1386 1355
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index 20ebf6a8b7f4..635775278c7f 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -13,13 +13,23 @@
13 */ 13 */
14 14
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/dma-mapping.h>
17#include <linux/io.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
16#include <linux/of.h> 20#include <linux/of.h>
17#include <linux/platform_device.h>
18#include <linux/of_gpio.h> 21#include <linux/of_gpio.h>
22#include <linux/platform_device.h>
19#include <linux/platform_data/usb-ehci-s5p.h> 23#include <linux/platform_data/usb-ehci-s5p.h>
20#include <linux/usb/phy.h> 24#include <linux/usb/phy.h>
21#include <linux/usb/samsung_usb_phy.h> 25#include <linux/usb/samsung_usb_phy.h>
22#include <plat/usb-phy.h> 26#include <linux/usb.h>
27#include <linux/usb/hcd.h>
28#include <linux/usb/otg.h>
29
30#include "ehci.h"
31
32#define DRIVER_DESC "EHCI s5p driver"
23 33
24#define EHCI_INSNREG00(base) (base + 0x90) 34#define EHCI_INSNREG00(base) (base + 0x90)
25#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25) 35#define EHCI_INSNREG00_ENA_INCR16 (0x1 << 25)
@@ -30,82 +40,35 @@
30 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \ 40 (EHCI_INSNREG00_ENA_INCR16 | EHCI_INSNREG00_ENA_INCR8 | \
31 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN) 41 EHCI_INSNREG00_ENA_INCR4 | EHCI_INSNREG00_ENA_INCRX_ALIGN)
32 42
43static const char hcd_name[] = "ehci-s5p";
44static struct hc_driver __read_mostly s5p_ehci_hc_driver;
45
33struct s5p_ehci_hcd { 46struct s5p_ehci_hcd {
34 struct device *dev;
35 struct usb_hcd *hcd;
36 struct clk *clk; 47 struct clk *clk;
37 struct usb_phy *phy; 48 struct usb_phy *phy;
38 struct usb_otg *otg; 49 struct usb_otg *otg;
39 struct s5p_ehci_platdata *pdata; 50 struct s5p_ehci_platdata *pdata;
40}; 51};
41 52
42static const struct hc_driver s5p_ehci_hc_driver = { 53#define to_s5p_ehci(hcd) (struct s5p_ehci_hcd *)(hcd_to_ehci(hcd)->priv)
43 .description = hcd_name,
44 .product_desc = "S5P EHCI Host Controller",
45 .hcd_priv_size = sizeof(struct ehci_hcd),
46
47 .irq = ehci_irq,
48 .flags = HCD_MEMORY | HCD_USB2,
49
50 .reset = ehci_setup,
51 .start = ehci_run,
52 .stop = ehci_stop,
53 .shutdown = ehci_shutdown,
54
55 .get_frame_number = ehci_get_frame,
56
57 .urb_enqueue = ehci_urb_enqueue,
58 .urb_dequeue = ehci_urb_dequeue,
59 .endpoint_disable = ehci_endpoint_disable,
60 .endpoint_reset = ehci_endpoint_reset,
61
62 .hub_status_data = ehci_hub_status_data,
63 .hub_control = ehci_hub_control,
64 .bus_suspend = ehci_bus_suspend,
65 .bus_resume = ehci_bus_resume,
66
67 .relinquish_port = ehci_relinquish_port,
68 .port_handed_over = ehci_port_handed_over,
69
70 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
71};
72
73static void s5p_ehci_phy_enable(struct s5p_ehci_hcd *s5p_ehci)
74{
75 struct platform_device *pdev = to_platform_device(s5p_ehci->dev);
76
77 if (s5p_ehci->phy)
78 usb_phy_init(s5p_ehci->phy);
79 else if (s5p_ehci->pdata->phy_init)
80 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
81}
82
83static void s5p_ehci_phy_disable(struct s5p_ehci_hcd *s5p_ehci)
84{
85 struct platform_device *pdev = to_platform_device(s5p_ehci->dev);
86
87 if (s5p_ehci->phy)
88 usb_phy_shutdown(s5p_ehci->phy);
89 else if (s5p_ehci->pdata->phy_exit)
90 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
91}
92 54
93static void s5p_setup_vbus_gpio(struct platform_device *pdev) 55static void s5p_setup_vbus_gpio(struct platform_device *pdev)
94{ 56{
57 struct device *dev = &pdev->dev;
95 int err; 58 int err;
96 int gpio; 59 int gpio;
97 60
98 if (!pdev->dev.of_node) 61 if (!dev->of_node)
99 return; 62 return;
100 63
101 gpio = of_get_named_gpio(pdev->dev.of_node, 64 gpio = of_get_named_gpio(dev->of_node, "samsung,vbus-gpio", 0);
102 "samsung,vbus-gpio", 0);
103 if (!gpio_is_valid(gpio)) 65 if (!gpio_is_valid(gpio))
104 return; 66 return;
105 67
106 err = gpio_request_one(gpio, GPIOF_OUT_INIT_HIGH, "ehci_vbus_gpio"); 68 err = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_HIGH,
69 "ehci_vbus_gpio");
107 if (err) 70 if (err)
108 dev_err(&pdev->dev, "can't request ehci vbus gpio %d", gpio); 71 dev_err(dev, "can't request ehci vbus gpio %d", gpio);
109} 72}
110 73
111static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32); 74static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
@@ -133,13 +96,15 @@ static int s5p_ehci_probe(struct platform_device *pdev)
133 96
134 s5p_setup_vbus_gpio(pdev); 97 s5p_setup_vbus_gpio(pdev);
135 98
136 s5p_ehci = devm_kzalloc(&pdev->dev, sizeof(struct s5p_ehci_hcd), 99 hcd = usb_create_hcd(&s5p_ehci_hc_driver,
137 GFP_KERNEL); 100 &pdev->dev, dev_name(&pdev->dev));
138 if (!s5p_ehci) 101 if (!hcd) {
102 dev_err(&pdev->dev, "Unable to create HCD\n");
139 return -ENOMEM; 103 return -ENOMEM;
140 104 }
105 s5p_ehci = to_s5p_ehci(hcd);
141 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 106 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
142 if (IS_ERR_OR_NULL(phy)) { 107 if (IS_ERR(phy)) {
143 /* Fallback to pdata */ 108 /* Fallback to pdata */
144 if (!pdata) { 109 if (!pdata) {
145 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 110 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
@@ -152,16 +117,6 @@ static int s5p_ehci_probe(struct platform_device *pdev)
152 s5p_ehci->otg = phy->otg; 117 s5p_ehci->otg = phy->otg;
153 } 118 }
154 119
155 s5p_ehci->dev = &pdev->dev;
156
157 hcd = usb_create_hcd(&s5p_ehci_hc_driver, &pdev->dev,
158 dev_name(&pdev->dev));
159 if (!hcd) {
160 dev_err(&pdev->dev, "Unable to create HCD\n");
161 return -ENOMEM;
162 }
163
164 s5p_ehci->hcd = hcd;
165 s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost"); 120 s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
166 121
167 if (IS_ERR(s5p_ehci->clk)) { 122 if (IS_ERR(s5p_ehci->clk)) {
@@ -198,9 +153,12 @@ static int s5p_ehci_probe(struct platform_device *pdev)
198 } 153 }
199 154
200 if (s5p_ehci->otg) 155 if (s5p_ehci->otg)
201 s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 156 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self);
202 157
203 s5p_ehci_phy_enable(s5p_ehci); 158 if (s5p_ehci->phy)
159 usb_phy_init(s5p_ehci->phy);
160 else if (s5p_ehci->pdata->phy_init)
161 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
204 162
205 ehci = hcd_to_ehci(hcd); 163 ehci = hcd_to_ehci(hcd);
206 ehci->caps = hcd->regs; 164 ehci->caps = hcd->regs;
@@ -214,12 +172,15 @@ static int s5p_ehci_probe(struct platform_device *pdev)
214 goto fail_add_hcd; 172 goto fail_add_hcd;
215 } 173 }
216 174
217 platform_set_drvdata(pdev, s5p_ehci); 175 platform_set_drvdata(pdev, hcd);
218 176
219 return 0; 177 return 0;
220 178
221fail_add_hcd: 179fail_add_hcd:
222 s5p_ehci_phy_disable(s5p_ehci); 180 if (s5p_ehci->phy)
181 usb_phy_shutdown(s5p_ehci->phy);
182 else if (s5p_ehci->pdata->phy_exit)
183 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
223fail_io: 184fail_io:
224 clk_disable_unprepare(s5p_ehci->clk); 185 clk_disable_unprepare(s5p_ehci->clk);
225fail_clk: 186fail_clk:
@@ -229,15 +190,18 @@ fail_clk:
229 190
230static int s5p_ehci_remove(struct platform_device *pdev) 191static int s5p_ehci_remove(struct platform_device *pdev)
231{ 192{
232 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); 193 struct usb_hcd *hcd = platform_get_drvdata(pdev);
233 struct usb_hcd *hcd = s5p_ehci->hcd; 194 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd);
234 195
235 usb_remove_hcd(hcd); 196 usb_remove_hcd(hcd);
236 197
237 if (s5p_ehci->otg) 198 if (s5p_ehci->otg)
238 s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 199 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self);
239 200
240 s5p_ehci_phy_disable(s5p_ehci); 201 if (s5p_ehci->phy)
202 usb_phy_shutdown(s5p_ehci->phy);
203 else if (s5p_ehci->pdata->phy_exit)
204 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
241 205
242 clk_disable_unprepare(s5p_ehci->clk); 206 clk_disable_unprepare(s5p_ehci->clk);
243 207
@@ -248,8 +212,7 @@ static int s5p_ehci_remove(struct platform_device *pdev)
248 212
249static void s5p_ehci_shutdown(struct platform_device *pdev) 213static void s5p_ehci_shutdown(struct platform_device *pdev)
250{ 214{
251 struct s5p_ehci_hcd *s5p_ehci = platform_get_drvdata(pdev); 215 struct usb_hcd *hcd = platform_get_drvdata(pdev);
252 struct usb_hcd *hcd = s5p_ehci->hcd;
253 216
254 if (hcd->driver->shutdown) 217 if (hcd->driver->shutdown)
255 hcd->driver->shutdown(hcd); 218 hcd->driver->shutdown(hcd);
@@ -258,17 +221,22 @@ static void s5p_ehci_shutdown(struct platform_device *pdev)
258#ifdef CONFIG_PM 221#ifdef CONFIG_PM
259static int s5p_ehci_suspend(struct device *dev) 222static int s5p_ehci_suspend(struct device *dev)
260{ 223{
261 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 224 struct usb_hcd *hcd = dev_get_drvdata(dev);
262 struct usb_hcd *hcd = s5p_ehci->hcd; 225 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd);
226 struct platform_device *pdev = to_platform_device(dev);
227
263 bool do_wakeup = device_may_wakeup(dev); 228 bool do_wakeup = device_may_wakeup(dev);
264 int rc; 229 int rc;
265 230
266 rc = ehci_suspend(hcd, do_wakeup); 231 rc = ehci_suspend(hcd, do_wakeup);
267 232
268 if (s5p_ehci->otg) 233 if (s5p_ehci->otg)
269 s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 234 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self);
270 235
271 s5p_ehci_phy_disable(s5p_ehci); 236 if (s5p_ehci->phy)
237 usb_phy_shutdown(s5p_ehci->phy);
238 else if (s5p_ehci->pdata->phy_exit)
239 s5p_ehci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
272 240
273 clk_disable_unprepare(s5p_ehci->clk); 241 clk_disable_unprepare(s5p_ehci->clk);
274 242
@@ -277,15 +245,19 @@ static int s5p_ehci_suspend(struct device *dev)
277 245
278static int s5p_ehci_resume(struct device *dev) 246static int s5p_ehci_resume(struct device *dev)
279{ 247{
280 struct s5p_ehci_hcd *s5p_ehci = dev_get_drvdata(dev); 248 struct usb_hcd *hcd = dev_get_drvdata(dev);
281 struct usb_hcd *hcd = s5p_ehci->hcd; 249 struct s5p_ehci_hcd *s5p_ehci = to_s5p_ehci(hcd);
250 struct platform_device *pdev = to_platform_device(dev);
282 251
283 clk_prepare_enable(s5p_ehci->clk); 252 clk_prepare_enable(s5p_ehci->clk);
284 253
285 if (s5p_ehci->otg) 254 if (s5p_ehci->otg)
286 s5p_ehci->otg->set_host(s5p_ehci->otg, &s5p_ehci->hcd->self); 255 s5p_ehci->otg->set_host(s5p_ehci->otg, &hcd->self);
287 256
288 s5p_ehci_phy_enable(s5p_ehci); 257 if (s5p_ehci->phy)
258 usb_phy_init(s5p_ehci->phy);
259 else if (s5p_ehci->pdata->phy_init)
260 s5p_ehci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
289 261
290 /* DMA burst Enable */ 262 /* DMA burst Enable */
291 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs)); 263 writel(EHCI_INSNREG00_ENABLE_DMA_BURST, EHCI_INSNREG00(hcd->regs));
@@ -322,5 +294,29 @@ static struct platform_driver s5p_ehci_driver = {
322 .of_match_table = of_match_ptr(exynos_ehci_match), 294 .of_match_table = of_match_ptr(exynos_ehci_match),
323 } 295 }
324}; 296};
297static const struct ehci_driver_overrides s5p_overrides __initdata = {
298 .extra_priv_size = sizeof(struct s5p_ehci_hcd),
299};
300
301static int __init ehci_s5p_init(void)
302{
303 if (usb_disabled())
304 return -ENODEV;
305
306 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
307 ehci_init_driver(&s5p_ehci_hc_driver, &s5p_overrides);
308 return platform_driver_register(&s5p_ehci_driver);
309}
310module_init(ehci_s5p_init);
311
312static void __exit ehci_s5p_cleanup(void)
313{
314 platform_driver_unregister(&s5p_ehci_driver);
315}
316module_exit(ehci_s5p_cleanup);
325 317
318MODULE_DESCRIPTION(DRIVER_DESC);
326MODULE_ALIAS("platform:s5p-ehci"); 319MODULE_ALIAS("platform:s5p-ehci");
320MODULE_AUTHOR("Jingoo Han");
321MODULE_AUTHOR("Joonyoung Shim");
322MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 010f686d8881..acff5b8f6e89 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -539,6 +539,7 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
539 } 539 }
540 qh->qh_state = QH_STATE_LINKED; 540 qh->qh_state = QH_STATE_LINKED;
541 qh->xacterrs = 0; 541 qh->xacterrs = 0;
542 qh->exception = 0;
542 543
543 /* update per-qh bandwidth for usbfs */ 544 /* update per-qh bandwidth for usbfs */
544 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period 545 ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->period
@@ -602,15 +603,9 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
602 603
603static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh) 604static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
604{ 605{
605 /* If the QH isn't linked then there's nothing we can do 606 /* If the QH isn't linked then there's nothing we can do. */
606 * unless we were called during a giveback, in which case 607 if (qh->qh_state != QH_STATE_LINKED)
607 * qh_completions() has to deal with it.
608 */
609 if (qh->qh_state != QH_STATE_LINKED) {
610 if (qh->qh_state == QH_STATE_COMPLETING)
611 qh->needs_rescan = 1;
612 return; 608 return;
613 }
614 609
615 qh_unlink_periodic (ehci, qh); 610 qh_unlink_periodic (ehci, qh);
616 611
@@ -625,17 +620,13 @@ static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
625 qh->unlink_cycle = ehci->intr_unlink_cycle; 620 qh->unlink_cycle = ehci->intr_unlink_cycle;
626 621
627 /* New entries go at the end of the intr_unlink list */ 622 /* New entries go at the end of the intr_unlink list */
628 if (ehci->intr_unlink) 623 list_add_tail(&qh->unlink_node, &ehci->intr_unlink);
629 ehci->intr_unlink_last->unlink_next = qh;
630 else
631 ehci->intr_unlink = qh;
632 ehci->intr_unlink_last = qh;
633 624
634 if (ehci->intr_unlinking) 625 if (ehci->intr_unlinking)
635 ; /* Avoid recursive calls */ 626 ; /* Avoid recursive calls */
636 else if (ehci->rh_state < EHCI_RH_RUNNING) 627 else if (ehci->rh_state < EHCI_RH_RUNNING)
637 ehci_handle_intr_unlinks(ehci); 628 ehci_handle_intr_unlinks(ehci);
638 else if (ehci->intr_unlink == qh) { 629 else if (ehci->intr_unlink.next == &qh->unlink_node) {
639 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true); 630 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
640 ++ehci->intr_unlink_cycle; 631 ++ehci->intr_unlink_cycle;
641 } 632 }
@@ -649,7 +640,8 @@ static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
649 qh->qh_state = QH_STATE_IDLE; 640 qh->qh_state = QH_STATE_IDLE;
650 hw->hw_next = EHCI_LIST_END(ehci); 641 hw->hw_next = EHCI_LIST_END(ehci);
651 642
652 qh_completions(ehci, qh); 643 if (!list_empty(&qh->qtd_list))
644 qh_completions(ehci, qh);
653 645
654 /* reschedule QH iff another request is queued */ 646 /* reschedule QH iff another request is queued */
655 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) { 647 if (!list_empty(&qh->qtd_list) && ehci->rh_state == EHCI_RH_RUNNING) {
@@ -792,7 +784,6 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
792 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */ 784 unsigned frame; /* 0..(qh->period - 1), or NO_FRAME */
793 struct ehci_qh_hw *hw = qh->hw; 785 struct ehci_qh_hw *hw = qh->hw;
794 786
795 qh_refresh(ehci, qh);
796 hw->hw_next = EHCI_LIST_END(ehci); 787 hw->hw_next = EHCI_LIST_END(ehci);
797 frame = qh->start; 788 frame = qh->start;
798 789
@@ -844,8 +835,6 @@ static int qh_schedule(struct ehci_hcd *ehci, struct ehci_qh *qh)
844 } else 835 } else
845 ehci_dbg (ehci, "reused qh %p schedule\n", qh); 836 ehci_dbg (ehci, "reused qh %p schedule\n", qh);
846 837
847 /* stuff into the periodic schedule */
848 qh_link_periodic(ehci, qh);
849done: 838done:
850 return status; 839 return status;
851} 840}
@@ -891,6 +880,12 @@ static int intr_submit (
891 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv); 880 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
892 BUG_ON (qh == NULL); 881 BUG_ON (qh == NULL);
893 882
883 /* stuff into the periodic schedule */
884 if (qh->qh_state == QH_STATE_IDLE) {
885 qh_refresh(ehci, qh);
886 qh_link_periodic(ehci, qh);
887 }
888
894 /* ... update usbfs periodic stats */ 889 /* ... update usbfs periodic stats */
895 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++; 890 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++;
896 891
@@ -911,7 +906,7 @@ static void scan_intr(struct ehci_hcd *ehci)
911 906
912 list_for_each_entry_safe(qh, ehci->qh_scan_next, &ehci->intr_qh_list, 907 list_for_each_entry_safe(qh, ehci->qh_scan_next, &ehci->intr_qh_list,
913 intr_node) { 908 intr_node) {
914 rescan: 909
915 /* clean any finished work for this qh */ 910 /* clean any finished work for this qh */
916 if (!list_empty(&qh->qtd_list)) { 911 if (!list_empty(&qh->qtd_list)) {
917 int temp; 912 int temp;
@@ -924,12 +919,9 @@ static void scan_intr(struct ehci_hcd *ehci)
924 * in qh_unlink_periodic(). 919 * in qh_unlink_periodic().
925 */ 920 */
926 temp = qh_completions(ehci, qh); 921 temp = qh_completions(ehci, qh);
927 if (unlikely(qh->needs_rescan || 922 if (unlikely(temp || (list_empty(&qh->qtd_list) &&
928 (list_empty(&qh->qtd_list) && 923 qh->qh_state == QH_STATE_LINKED)))
929 qh->qh_state == QH_STATE_LINKED)))
930 start_unlink_intr(ehci, qh); 924 start_unlink_intr(ehci, qh);
931 else if (temp != 0)
932 goto rescan;
933 } 925 }
934 } 926 }
935} 927}
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index 3565a300f401..b44d716ddc82 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -77,7 +77,6 @@ static const struct hc_driver ehci_sh_hc_driver = {
77 77
78static int ehci_hcd_sh_probe(struct platform_device *pdev) 78static int ehci_hcd_sh_probe(struct platform_device *pdev)
79{ 79{
80 const struct hc_driver *driver = &ehci_sh_hc_driver;
81 struct resource *res; 80 struct resource *res;
82 struct ehci_sh_priv *priv; 81 struct ehci_sh_priv *priv;
83 struct ehci_sh_platdata *pdata; 82 struct ehci_sh_platdata *pdata;
@@ -170,7 +169,7 @@ fail_create_hcd:
170 return ret; 169 return ret;
171} 170}
172 171
173static int __exit ehci_hcd_sh_remove(struct platform_device *pdev) 172static int ehci_hcd_sh_remove(struct platform_device *pdev)
174{ 173{
175 struct ehci_sh_priv *priv = platform_get_drvdata(pdev); 174 struct ehci_sh_priv *priv = platform_get_drvdata(pdev);
176 struct usb_hcd *hcd = priv->hcd; 175 struct usb_hcd *hcd = priv->hcd;
@@ -196,7 +195,7 @@ static void ehci_hcd_sh_shutdown(struct platform_device *pdev)
196 195
197static struct platform_driver ehci_hcd_sh_driver = { 196static struct platform_driver ehci_hcd_sh_driver = {
198 .probe = ehci_hcd_sh_probe, 197 .probe = ehci_hcd_sh_probe,
199 .remove = __exit_p(ehci_hcd_sh_remove), 198 .remove = ehci_hcd_sh_remove,
200 .shutdown = ehci_hcd_sh_shutdown, 199 .shutdown = ehci_hcd_sh_shutdown,
201 .driver = { 200 .driver = {
202 .name = "sh_ehci", 201 .name = "sh_ehci",
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 466c1bb5b967..61ecfb3d52f5 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -1,5 +1,5 @@
1/* 1/*
2* Driver for EHCI HCD on SPEAR SOC 2* Driver for EHCI HCD on SPEAr SOC
3* 3*
4* Copyright (C) 2010 ST Micro Electronics, 4* Copyright (C) 2010 ST Micro Electronics,
5* Deepak Sikri <deepak.sikri@st.com> 5* Deepak Sikri <deepak.sikri@st.com>
@@ -12,73 +12,32 @@
12*/ 12*/
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/dma-mapping.h>
16#include <linux/io.h>
15#include <linux/jiffies.h> 17#include <linux/jiffies.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
16#include <linux/of.h> 20#include <linux/of.h>
17#include <linux/platform_device.h> 21#include <linux/platform_device.h>
18#include <linux/pm.h> 22#include <linux/pm.h>
23#include <linux/usb.h>
24#include <linux/usb/hcd.h>
19 25
20struct spear_ehci { 26#include "ehci.h"
21 struct ehci_hcd ehci;
22 struct clk *clk;
23};
24
25#define to_spear_ehci(hcd) (struct spear_ehci *)hcd_to_ehci(hcd)
26 27
27static void spear_start_ehci(struct spear_ehci *ehci) 28#define DRIVER_DESC "EHCI SPEAr driver"
28{
29 clk_prepare_enable(ehci->clk);
30}
31 29
32static void spear_stop_ehci(struct spear_ehci *ehci) 30static const char hcd_name[] = "SPEAr-ehci";
33{
34 clk_disable_unprepare(ehci->clk);
35}
36 31
37static int ehci_spear_setup(struct usb_hcd *hcd) 32struct spear_ehci {
38{ 33 struct clk *clk;
39 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 34};
40
41 /* registers start at offset 0x0 */
42 ehci->caps = hcd->regs;
43 35
44 return ehci_setup(hcd); 36#define to_spear_ehci(hcd) (struct spear_ehci *)(hcd_to_ehci(hcd)->priv)
45}
46 37
47static const struct hc_driver ehci_spear_hc_driver = { 38static struct hc_driver __read_mostly ehci_spear_hc_driver;
48 .description = hcd_name,
49 .product_desc = "SPEAr EHCI",
50 .hcd_priv_size = sizeof(struct spear_ehci),
51
52 /* generic hardware linkage */
53 .irq = ehci_irq,
54 .flags = HCD_MEMORY | HCD_USB2,
55
56 /* basic lifecycle operations */
57 .reset = ehci_spear_setup,
58 .start = ehci_run,
59 .stop = ehci_stop,
60 .shutdown = ehci_shutdown,
61
62 /* managing i/o requests and associated device resources */
63 .urb_enqueue = ehci_urb_enqueue,
64 .urb_dequeue = ehci_urb_dequeue,
65 .endpoint_disable = ehci_endpoint_disable,
66 .endpoint_reset = ehci_endpoint_reset,
67
68 /* scheduling support */
69 .get_frame_number = ehci_get_frame,
70
71 /* root hub support */
72 .hub_status_data = ehci_hub_status_data,
73 .hub_control = ehci_hub_control,
74 .bus_suspend = ehci_bus_suspend,
75 .bus_resume = ehci_bus_resume,
76 .relinquish_port = ehci_relinquish_port,
77 .port_handed_over = ehci_port_handed_over,
78 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
79};
80 39
81#ifdef CONFIG_PM 40#ifdef CONFIG_PM_SLEEP
82static int ehci_spear_drv_suspend(struct device *dev) 41static int ehci_spear_drv_suspend(struct device *dev)
83{ 42{
84 struct usb_hcd *hcd = dev_get_drvdata(dev); 43 struct usb_hcd *hcd = dev_get_drvdata(dev);
@@ -94,7 +53,7 @@ static int ehci_spear_drv_resume(struct device *dev)
94 ehci_resume(hcd, false); 53 ehci_resume(hcd, false);
95 return 0; 54 return 0;
96} 55}
97#endif /* CONFIG_PM */ 56#endif /* CONFIG_PM_SLEEP */
98 57
99static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend, 58static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
100 ehci_spear_drv_resume); 59 ehci_spear_drv_resume);
@@ -104,7 +63,7 @@ static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
104static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) 63static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
105{ 64{
106 struct usb_hcd *hcd ; 65 struct usb_hcd *hcd ;
107 struct spear_ehci *ehci; 66 struct spear_ehci *sehci;
108 struct resource *res; 67 struct resource *res;
109 struct clk *usbh_clk; 68 struct clk *usbh_clk;
110 const struct hc_driver *driver = &ehci_spear_hc_driver; 69 const struct hc_driver *driver = &ehci_spear_hc_driver;
@@ -161,10 +120,13 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
161 goto err_put_hcd; 120 goto err_put_hcd;
162 } 121 }
163 122
164 ehci = (struct spear_ehci *)hcd_to_ehci(hcd); 123 sehci = to_spear_ehci(hcd);
165 ehci->clk = usbh_clk; 124 sehci->clk = usbh_clk;
125
126 /* registers start at offset 0x0 */
127 hcd_to_ehci(hcd)->caps = hcd->regs;
166 128
167 spear_start_ehci(ehci); 129 clk_prepare_enable(sehci->clk);
168 retval = usb_add_hcd(hcd, irq, IRQF_SHARED); 130 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
169 if (retval) 131 if (retval)
170 goto err_stop_ehci; 132 goto err_stop_ehci;
@@ -172,7 +134,7 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
172 return retval; 134 return retval;
173 135
174err_stop_ehci: 136err_stop_ehci:
175 spear_stop_ehci(ehci); 137 clk_disable_unprepare(sehci->clk);
176err_put_hcd: 138err_put_hcd:
177 usb_put_hcd(hcd); 139 usb_put_hcd(hcd);
178fail: 140fail:
@@ -184,7 +146,7 @@ fail:
184static int spear_ehci_hcd_drv_remove(struct platform_device *pdev) 146static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
185{ 147{
186 struct usb_hcd *hcd = platform_get_drvdata(pdev); 148 struct usb_hcd *hcd = platform_get_drvdata(pdev);
187 struct spear_ehci *ehci_p = to_spear_ehci(hcd); 149 struct spear_ehci *sehci = to_spear_ehci(hcd);
188 150
189 if (!hcd) 151 if (!hcd)
190 return 0; 152 return 0;
@@ -192,8 +154,8 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
192 BUG(); 154 BUG();
193 usb_remove_hcd(hcd); 155 usb_remove_hcd(hcd);
194 156
195 if (ehci_p->clk) 157 if (sehci->clk)
196 spear_stop_ehci(ehci_p); 158 clk_disable_unprepare(sehci->clk);
197 usb_put_hcd(hcd); 159 usb_put_hcd(hcd);
198 160
199 return 0; 161 return 0;
@@ -216,4 +178,29 @@ static struct platform_driver spear_ehci_hcd_driver = {
216 } 178 }
217}; 179};
218 180
181static const struct ehci_driver_overrides spear_overrides __initdata = {
182 .extra_priv_size = sizeof(struct spear_ehci),
183};
184
185static int __init ehci_spear_init(void)
186{
187 if (usb_disabled())
188 return -ENODEV;
189
190 pr_info("%s: " DRIVER_DESC "\n", hcd_name);
191
192 ehci_init_driver(&ehci_spear_hc_driver, &spear_overrides);
193 return platform_driver_register(&spear_ehci_hcd_driver);
194}
195module_init(ehci_spear_init);
196
197static void __exit ehci_spear_cleanup(void)
198{
199 platform_driver_unregister(&spear_ehci_hcd_driver);
200}
201module_exit(ehci_spear_cleanup);
202
203MODULE_DESCRIPTION(DRIVER_DESC);
219MODULE_ALIAS("platform:spear-ehci"); 204MODULE_ALIAS("platform:spear-ehci");
205MODULE_AUTHOR("Deepak Sikri");
206MODULE_LICENSE("GPL");
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 568aecc7075b..e3eddc31ac83 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -28,6 +28,7 @@
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/usb/ehci_def.h> 29#include <linux/usb/ehci_def.h>
30#include <linux/usb/tegra_usb_phy.h> 30#include <linux/usb/tegra_usb_phy.h>
31#include <linux/clk/tegra.h>
31 32
32#define TEGRA_USB_BASE 0xC5000000 33#define TEGRA_USB_BASE 0xC5000000
33#define TEGRA_USB2_BASE 0xC5004000 34#define TEGRA_USB2_BASE 0xC5004000
@@ -610,7 +611,7 @@ static const struct dev_pm_ops tegra_ehci_pm_ops = {
610/* Bits of PORTSC1, which will get cleared by writing 1 into them */ 611/* Bits of PORTSC1, which will get cleared by writing 1 into them */
611#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC) 612#define TEGRA_PORTSC1_RWC_BITS (PORT_CSC | PORT_PEC | PORT_OCC)
612 613
613void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val) 614static void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val)
614{ 615{
615 unsigned long val; 616 unsigned long val;
616 struct usb_hcd *hcd = bus_to_hcd(x->otg->host); 617 struct usb_hcd *hcd = bus_to_hcd(x->otg->host);
@@ -621,9 +622,8 @@ void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val)
621 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3); 622 val |= TEGRA_USB_PORTSC1_PTS(pts_val & 3);
622 writel(val, base + TEGRA_USB_PORTSC1); 623 writel(val, base + TEGRA_USB_PORTSC1);
623} 624}
624EXPORT_SYMBOL_GPL(tegra_ehci_set_pts);
625 625
626void tegra_ehci_set_phcd(struct usb_phy *x, bool enable) 626static void tegra_ehci_set_phcd(struct usb_phy *x, bool enable)
627{ 627{
628 unsigned long val; 628 unsigned long val;
629 struct usb_hcd *hcd = bus_to_hcd(x->otg->host); 629 struct usb_hcd *hcd = bus_to_hcd(x->otg->host);
@@ -636,7 +636,6 @@ void tegra_ehci_set_phcd(struct usb_phy *x, bool enable)
636 val &= ~TEGRA_USB_PORTSC1_PHCD; 636 val &= ~TEGRA_USB_PORTSC1_PHCD;
637 writel(val, base + TEGRA_USB_PORTSC1); 637 writel(val, base + TEGRA_USB_PORTSC1);
638} 638}
639EXPORT_SYMBOL_GPL(tegra_ehci_set_phcd);
640 639
641static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32); 640static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32);
642 641
@@ -691,6 +690,10 @@ static int tegra_ehci_probe(struct platform_device *pdev)
691 if (err) 690 if (err)
692 goto fail_clk; 691 goto fail_clk;
693 692
693 tegra_periph_reset_assert(tegra->clk);
694 udelay(1);
695 tegra_periph_reset_deassert(tegra->clk);
696
694 tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node, 697 tegra->needs_double_reset = of_property_read_bool(pdev->dev.of_node,
695 "nvidia,needs-double-reset"); 698 "nvidia,needs-double-reset");
696 699
@@ -733,7 +736,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
733 736
734 tegra->phy = tegra_usb_phy_open(&pdev->dev, instance, hcd->regs, 737 tegra->phy = tegra_usb_phy_open(&pdev->dev, instance, hcd->regs,
735 pdata->phy_config, 738 pdata->phy_config,
736 TEGRA_USB_PHY_MODE_HOST); 739 TEGRA_USB_PHY_MODE_HOST,
740 tegra_ehci_set_pts,
741 tegra_ehci_set_phcd);
737 if (IS_ERR(tegra->phy)) { 742 if (IS_ERR(tegra->phy)) {
738 dev_err(&pdev->dev, "Failed to open USB phy\n"); 743 dev_err(&pdev->dev, "Failed to open USB phy\n");
739 err = -ENXIO; 744 err = -ENXIO;
@@ -755,7 +760,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
755 err = usb_phy_set_suspend(hcd->phy, 0); 760 err = usb_phy_set_suspend(hcd->phy, 0);
756 if (err) { 761 if (err) {
757 dev_err(&pdev->dev, "Failed to power on the phy\n"); 762 dev_err(&pdev->dev, "Failed to power on the phy\n");
758 goto fail; 763 goto fail_phy;
759 } 764 }
760 765
761 tegra->host_resumed = 1; 766 tegra->host_resumed = 1;
@@ -765,17 +770,17 @@ static int tegra_ehci_probe(struct platform_device *pdev)
765 if (!irq) { 770 if (!irq) {
766 dev_err(&pdev->dev, "Failed to get IRQ\n"); 771 dev_err(&pdev->dev, "Failed to get IRQ\n");
767 err = -ENODEV; 772 err = -ENODEV;
768 goto fail; 773 goto fail_phy;
769 } 774 }
770 775
771#ifdef CONFIG_USB_OTG_UTILS
772 if (pdata->operating_mode == TEGRA_USB_OTG) { 776 if (pdata->operating_mode == TEGRA_USB_OTG) {
773 tegra->transceiver = 777 tegra->transceiver =
774 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 778 devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
775 if (!IS_ERR_OR_NULL(tegra->transceiver)) 779 if (!IS_ERR(tegra->transceiver))
776 otg_set_host(tegra->transceiver->otg, &hcd->self); 780 otg_set_host(tegra->transceiver->otg, &hcd->self);
781 } else {
782 tegra->transceiver = ERR_PTR(-ENODEV);
777 } 783 }
778#endif
779 784
780 err = usb_add_hcd(hcd, irq, IRQF_SHARED); 785 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
781 if (err) { 786 if (err) {
@@ -794,10 +799,9 @@ static int tegra_ehci_probe(struct platform_device *pdev)
794 return err; 799 return err;
795 800
796fail: 801fail:
797#ifdef CONFIG_USB_OTG_UTILS 802 if (!IS_ERR(tegra->transceiver))
798 if (!IS_ERR_OR_NULL(tegra->transceiver))
799 otg_set_host(tegra->transceiver->otg, NULL); 803 otg_set_host(tegra->transceiver->otg, NULL);
800#endif 804fail_phy:
801 usb_phy_shutdown(hcd->phy); 805 usb_phy_shutdown(hcd->phy);
802fail_io: 806fail_io:
803 clk_disable_unprepare(tegra->clk); 807 clk_disable_unprepare(tegra->clk);
@@ -815,10 +819,8 @@ static int tegra_ehci_remove(struct platform_device *pdev)
815 pm_runtime_disable(&pdev->dev); 819 pm_runtime_disable(&pdev->dev);
816 pm_runtime_put_noidle(&pdev->dev); 820 pm_runtime_put_noidle(&pdev->dev);
817 821
818#ifdef CONFIG_USB_OTG_UTILS 822 if (!IS_ERR(tegra->transceiver))
819 if (!IS_ERR_OR_NULL(tegra->transceiver))
820 otg_set_host(tegra->transceiver->otg, NULL); 823 otg_set_host(tegra->transceiver->otg, NULL);
821#endif
822 824
823 usb_phy_shutdown(hcd->phy); 825 usb_phy_shutdown(hcd->phy);
824 usb_remove_hcd(hcd); 826 usb_remove_hcd(hcd);
diff --git a/drivers/usb/host/ehci-timer.c b/drivers/usb/host/ehci-timer.c
index c3fa1305f830..11e5b32f73e9 100644
--- a/drivers/usb/host/ehci-timer.c
+++ b/drivers/usb/host/ehci-timer.c
@@ -113,8 +113,8 @@ static void ehci_poll_ASS(struct ehci_hcd *ehci)
113 113
114 if (want != actual) { 114 if (want != actual) {
115 115
116 /* Poll again later, but give up after about 20 ms */ 116 /* Poll again later, but give up after about 2-4 ms */
117 if (ehci->ASS_poll_count++ < 20) { 117 if (ehci->ASS_poll_count++ < 2) {
118 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true); 118 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_ASS, true);
119 return; 119 return;
120 } 120 }
@@ -159,8 +159,8 @@ static void ehci_poll_PSS(struct ehci_hcd *ehci)
159 159
160 if (want != actual) { 160 if (want != actual) {
161 161
162 /* Poll again later, but give up after about 20 ms */ 162 /* Poll again later, but give up after about 2-4 ms */
163 if (ehci->PSS_poll_count++ < 20) { 163 if (ehci->PSS_poll_count++ < 2) {
164 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true); 164 ehci_enable_event(ehci, EHCI_HRTIMER_POLL_PSS, true);
165 return; 165 return;
166 } 166 }
@@ -229,18 +229,19 @@ static void ehci_handle_intr_unlinks(struct ehci_hcd *ehci)
229 * process all the QHs on the list. 229 * process all the QHs on the list.
230 */ 230 */
231 ehci->intr_unlinking = true; 231 ehci->intr_unlinking = true;
232 while (ehci->intr_unlink) { 232 while (!list_empty(&ehci->intr_unlink)) {
233 struct ehci_qh *qh = ehci->intr_unlink; 233 struct ehci_qh *qh;
234 234
235 qh = list_first_entry(&ehci->intr_unlink, struct ehci_qh,
236 unlink_node);
235 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle) 237 if (!stopped && qh->unlink_cycle == ehci->intr_unlink_cycle)
236 break; 238 break;
237 ehci->intr_unlink = qh->unlink_next; 239 list_del(&qh->unlink_node);
238 qh->unlink_next = NULL;
239 end_unlink_intr(ehci, qh); 240 end_unlink_intr(ehci, qh);
240 } 241 }
241 242
242 /* Handle remaining entries later */ 243 /* Handle remaining entries later */
243 if (ehci->intr_unlink) { 244 if (!list_empty(&ehci->intr_unlink)) {
244 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true); 245 ehci_enable_event(ehci, EHCI_HRTIMER_UNLINK_INTR, true);
245 ++ehci->intr_unlink_cycle; 246 ++ehci->intr_unlink_cycle;
246 } 247 }
@@ -295,8 +296,7 @@ static void end_free_itds(struct ehci_hcd *ehci)
295/* Handle lost (or very late) IAA interrupts */ 296/* Handle lost (or very late) IAA interrupts */
296static void ehci_iaa_watchdog(struct ehci_hcd *ehci) 297static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
297{ 298{
298 if (ehci->rh_state != EHCI_RH_RUNNING) 299 u32 cmd, status;
299 return;
300 300
301 /* 301 /*
302 * Lost IAA irqs wedge things badly; seen first with a vt8235. 302 * Lost IAA irqs wedge things badly; seen first with a vt8235.
@@ -304,34 +304,32 @@ static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
304 * (a) SMP races against real IAA firing and retriggering, and 304 * (a) SMP races against real IAA firing and retriggering, and
305 * (b) clean HC shutdown, when IAA watchdog was pending. 305 * (b) clean HC shutdown, when IAA watchdog was pending.
306 */ 306 */
307 if (1) { 307 if (!ehci->iaa_in_progress || ehci->rh_state != EHCI_RH_RUNNING)
308 u32 cmd, status; 308 return;
309 309
310 /* If we get here, IAA is *REALLY* late. It's barely 310 /* If we get here, IAA is *REALLY* late. It's barely
311 * conceivable that the system is so busy that CMD_IAAD 311 * conceivable that the system is so busy that CMD_IAAD
312 * is still legitimately set, so let's be sure it's 312 * is still legitimately set, so let's be sure it's
313 * clear before we read STS_IAA. (The HC should clear 313 * clear before we read STS_IAA. (The HC should clear
314 * CMD_IAAD when it sets STS_IAA.) 314 * CMD_IAAD when it sets STS_IAA.)
315 */ 315 */
316 cmd = ehci_readl(ehci, &ehci->regs->command); 316 cmd = ehci_readl(ehci, &ehci->regs->command);
317
318 /*
319 * If IAA is set here it either legitimately triggered
320 * after the watchdog timer expired (_way_ late, so we'll
321 * still count it as lost) ... or a silicon erratum:
322 * - VIA seems to set IAA without triggering the IRQ;
323 * - IAAD potentially cleared without setting IAA.
324 */
325 status = ehci_readl(ehci, &ehci->regs->status);
326 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
327 COUNT(ehci->stats.lost_iaa);
328 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
329 }
330 317
331 ehci_vdbg(ehci, "IAA watchdog: status %x cmd %x\n", 318 /*
332 status, cmd); 319 * If IAA is set here it either legitimately triggered
333 end_unlink_async(ehci); 320 * after the watchdog timer expired (_way_ late, so we'll
321 * still count it as lost) ... or a silicon erratum:
322 * - VIA seems to set IAA without triggering the IRQ;
323 * - IAAD potentially cleared without setting IAA.
324 */
325 status = ehci_readl(ehci, &ehci->regs->status);
326 if ((status & STS_IAA) || !(cmd & CMD_IAAD)) {
327 COUNT(ehci->stats.lost_iaa);
328 ehci_writel(ehci, STS_IAA, &ehci->regs->status);
334 } 329 }
330
331 ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd);
332 end_unlink_async(ehci);
335} 333}
336 334
337 335
diff --git a/drivers/usb/host/ehci-vt8500.c b/drivers/usb/host/ehci-vt8500.c
deleted file mode 100644
index 7ecf709610ba..000000000000
--- a/drivers/usb/host/ehci-vt8500.c
+++ /dev/null
@@ -1,150 +0,0 @@
1/*
2 * drivers/usb/host/ehci-vt8500.c
3 *
4 * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
5 *
6 * Based on ehci-au1xxx.c
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/err.h>
20#include <linux/of.h>
21#include <linux/platform_device.h>
22
23static const struct hc_driver vt8500_ehci_hc_driver = {
24 .description = hcd_name,
25 .product_desc = "VT8500 EHCI",
26 .hcd_priv_size = sizeof(struct ehci_hcd),
27
28 /*
29 * generic hardware linkage
30 */
31 .irq = ehci_irq,
32 .flags = HCD_MEMORY | HCD_USB2,
33
34 /*
35 * basic lifecycle operations
36 */
37 .reset = ehci_setup,
38 .start = ehci_run,
39 .stop = ehci_stop,
40 .shutdown = ehci_shutdown,
41
42 /*
43 * managing i/o requests and associated device resources
44 */
45 .urb_enqueue = ehci_urb_enqueue,
46 .urb_dequeue = ehci_urb_dequeue,
47 .endpoint_disable = ehci_endpoint_disable,
48 .endpoint_reset = ehci_endpoint_reset,
49
50 /*
51 * scheduling support
52 */
53 .get_frame_number = ehci_get_frame,
54
55 /*
56 * root hub support
57 */
58 .hub_status_data = ehci_hub_status_data,
59 .hub_control = ehci_hub_control,
60 .bus_suspend = ehci_bus_suspend,
61 .bus_resume = ehci_bus_resume,
62 .relinquish_port = ehci_relinquish_port,
63 .port_handed_over = ehci_port_handed_over,
64
65 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
66};
67
68static u64 vt8500_ehci_dma_mask = DMA_BIT_MASK(32);
69
70static int vt8500_ehci_drv_probe(struct platform_device *pdev)
71{
72 struct usb_hcd *hcd;
73 struct ehci_hcd *ehci;
74 struct resource *res;
75 int ret;
76
77 if (usb_disabled())
78 return -ENODEV;
79
80 /*
81 * Right now device-tree probed devices don't get dma_mask set.
82 * Since shared usb code relies on it, set it here for now.
83 * Once we have dma capability bindings this can go away.
84 */
85 if (!pdev->dev.dma_mask)
86 pdev->dev.dma_mask = &vt8500_ehci_dma_mask;
87
88 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
89 pr_debug("resource[1] is not IORESOURCE_IRQ");
90 return -ENOMEM;
91 }
92 hcd = usb_create_hcd(&vt8500_ehci_hc_driver, &pdev->dev, "VT8500");
93 if (!hcd)
94 return -ENOMEM;
95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 hcd->rsrc_start = res->start;
98 hcd->rsrc_len = resource_size(res);
99
100 hcd->regs = devm_ioremap_resource(&pdev->dev, res);
101 if (IS_ERR(hcd->regs)) {
102 ret = PTR_ERR(hcd->regs);
103 goto err1;
104 }
105
106 ehci = hcd_to_ehci(hcd);
107 ehci->caps = hcd->regs;
108
109 ret = usb_add_hcd(hcd, pdev->resource[1].start,
110 IRQF_SHARED);
111 if (ret == 0) {
112 platform_set_drvdata(pdev, hcd);
113 return ret;
114 }
115
116err1:
117 usb_put_hcd(hcd);
118 return ret;
119}
120
121static int vt8500_ehci_drv_remove(struct platform_device *pdev)
122{
123 struct usb_hcd *hcd = platform_get_drvdata(pdev);
124
125 usb_remove_hcd(hcd);
126 usb_put_hcd(hcd);
127 platform_set_drvdata(pdev, NULL);
128
129 return 0;
130}
131
132static const struct of_device_id vt8500_ehci_ids[] = {
133 { .compatible = "via,vt8500-ehci", },
134 { .compatible = "wm,prizm-ehci", },
135 {}
136};
137
138static struct platform_driver vt8500_ehci_driver = {
139 .probe = vt8500_ehci_drv_probe,
140 .remove = vt8500_ehci_drv_remove,
141 .shutdown = usb_hcd_platform_shutdown,
142 .driver = {
143 .name = "vt8500-ehci",
144 .owner = THIS_MODULE,
145 .of_match_table = of_match_ptr(vt8500_ehci_ids),
146 }
147};
148
149MODULE_ALIAS("platform:vt8500-ehci");
150MODULE_DEVICE_TABLE(of, vt8500_ehci_ids);
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 36c3a8210595..7c978b23520d 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -121,6 +121,7 @@ struct ehci_hcd { /* one per controller */
121 bool scanning:1; 121 bool scanning:1;
122 bool need_rescan:1; 122 bool need_rescan:1;
123 bool intr_unlinking:1; 123 bool intr_unlinking:1;
124 bool iaa_in_progress:1;
124 bool async_unlinking:1; 125 bool async_unlinking:1;
125 bool shutdown:1; 126 bool shutdown:1;
126 struct ehci_qh *qh_scan_next; 127 struct ehci_qh *qh_scan_next;
@@ -128,9 +129,8 @@ struct ehci_hcd { /* one per controller */
128 /* async schedule support */ 129 /* async schedule support */
129 struct ehci_qh *async; 130 struct ehci_qh *async;
130 struct ehci_qh *dummy; /* For AMD quirk use */ 131 struct ehci_qh *dummy; /* For AMD quirk use */
131 struct ehci_qh *async_unlink; 132 struct list_head async_unlink;
132 struct ehci_qh *async_unlink_last; 133 struct list_head async_idle;
133 struct ehci_qh *async_iaa;
134 unsigned async_unlink_cycle; 134 unsigned async_unlink_cycle;
135 unsigned async_count; /* async activity count */ 135 unsigned async_count; /* async activity count */
136 136
@@ -143,8 +143,7 @@ struct ehci_hcd { /* one per controller */
143 unsigned i_thresh; /* uframes HC might cache */ 143 unsigned i_thresh; /* uframes HC might cache */
144 144
145 union ehci_shadow *pshadow; /* mirror hw periodic table */ 145 union ehci_shadow *pshadow; /* mirror hw periodic table */
146 struct ehci_qh *intr_unlink; 146 struct list_head intr_unlink;
147 struct ehci_qh *intr_unlink_last;
148 unsigned intr_unlink_cycle; 147 unsigned intr_unlink_cycle;
149 unsigned now_frame; /* frame from HC hardware */ 148 unsigned now_frame; /* frame from HC hardware */
150 unsigned last_iso_frame; /* last frame scanned for iso */ 149 unsigned last_iso_frame; /* last frame scanned for iso */
@@ -200,6 +199,7 @@ struct ehci_hcd { /* one per controller */
200 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/ 199 unsigned use_dummy_qh:1; /* AMD Frame List table quirk*/
201 unsigned has_synopsys_hc_bug:1; /* Synopsys HC */ 200 unsigned has_synopsys_hc_bug:1; /* Synopsys HC */
202 unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */ 201 unsigned frame_index_bug:1; /* MosChip (AKA NetMos) */
202 unsigned need_oc_pp_cycle:1; /* MPC834X port power */
203 203
204 /* required for usb32 quirk */ 204 /* required for usb32 quirk */
205 #define OHCI_CTRL_HCFS (3 << 6) 205 #define OHCI_CTRL_HCFS (3 << 6)
@@ -380,11 +380,10 @@ struct ehci_qh {
380 struct list_head qtd_list; /* sw qtd list */ 380 struct list_head qtd_list; /* sw qtd list */
381 struct list_head intr_node; /* list of intr QHs */ 381 struct list_head intr_node; /* list of intr QHs */
382 struct ehci_qtd *dummy; 382 struct ehci_qtd *dummy;
383 struct ehci_qh *unlink_next; /* next on unlink list */ 383 struct list_head unlink_node;
384 384
385 unsigned unlink_cycle; 385 unsigned unlink_cycle;
386 386
387 u8 needs_rescan; /* Dequeue during giveback */
388 u8 qh_state; 387 u8 qh_state;
389#define QH_STATE_LINKED 1 /* HC sees this */ 388#define QH_STATE_LINKED 1 /* HC sees this */
390#define QH_STATE_UNLINK 2 /* HC may still see this */ 389#define QH_STATE_UNLINK 2 /* HC may still see this */
@@ -407,6 +406,9 @@ struct ehci_qh {
407 struct usb_device *dev; /* access to TT */ 406 struct usb_device *dev; /* access to TT */
408 unsigned is_out:1; /* bulk or intr OUT */ 407 unsigned is_out:1; /* bulk or intr OUT */
409 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */ 408 unsigned clearing_tt:1; /* Clear-TT-Buf in progress */
409 unsigned dequeue_during_giveback:1;
410 unsigned exception:1; /* got a fault, or an unlink
411 was requested */
410}; 412};
411 413
412/*-------------------------------------------------------------------------*/ 414/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index e3b7e85120e4..114583a8e92b 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -17,7 +17,6 @@
17#include <linux/platform_data/usb-exynos.h> 17#include <linux/platform_data/usb-exynos.h>
18#include <linux/usb/phy.h> 18#include <linux/usb/phy.h>
19#include <linux/usb/samsung_usb_phy.h> 19#include <linux/usb/samsung_usb_phy.h>
20#include <plat/usb-phy.h>
21 20
22struct exynos_ohci_hcd { 21struct exynos_ohci_hcd {
23 struct device *dev; 22 struct device *dev;
@@ -34,7 +33,7 @@ static void exynos_ohci_phy_enable(struct exynos_ohci_hcd *exynos_ohci)
34 33
35 if (exynos_ohci->phy) 34 if (exynos_ohci->phy)
36 usb_phy_init(exynos_ohci->phy); 35 usb_phy_init(exynos_ohci->phy);
37 else if (exynos_ohci->pdata->phy_init) 36 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_init)
38 exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST); 37 exynos_ohci->pdata->phy_init(pdev, USB_PHY_TYPE_HOST);
39} 38}
40 39
@@ -44,7 +43,7 @@ static void exynos_ohci_phy_disable(struct exynos_ohci_hcd *exynos_ohci)
44 43
45 if (exynos_ohci->phy) 44 if (exynos_ohci->phy)
46 usb_phy_shutdown(exynos_ohci->phy); 45 usb_phy_shutdown(exynos_ohci->phy);
47 else if (exynos_ohci->pdata->phy_exit) 46 else if (exynos_ohci->pdata && exynos_ohci->pdata->phy_exit)
48 exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST); 47 exynos_ohci->pdata->phy_exit(pdev, USB_PHY_TYPE_HOST);
49} 48}
50 49
@@ -127,8 +126,12 @@ static int exynos_ohci_probe(struct platform_device *pdev)
127 if (!exynos_ohci) 126 if (!exynos_ohci)
128 return -ENOMEM; 127 return -ENOMEM;
129 128
129 if (of_device_is_compatible(pdev->dev.of_node,
130 "samsung,exynos5440-ohci"))
131 goto skip_phy;
132
130 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); 133 phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
131 if (IS_ERR_OR_NULL(phy)) { 134 if (IS_ERR(phy)) {
132 /* Fallback to pdata */ 135 /* Fallback to pdata */
133 if (!pdata) { 136 if (!pdata) {
134 dev_warn(&pdev->dev, "no platform data or transceiver defined\n"); 137 dev_warn(&pdev->dev, "no platform data or transceiver defined\n");
@@ -141,6 +144,8 @@ static int exynos_ohci_probe(struct platform_device *pdev)
141 exynos_ohci->otg = phy->otg; 144 exynos_ohci->otg = phy->otg;
142 } 145 }
143 146
147skip_phy:
148
144 exynos_ohci->dev = &pdev->dev; 149 exynos_ohci->dev = &pdev->dev;
145 150
146 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev, 151 hcd = usb_create_hcd(&exynos_ohci_hc_driver, &pdev->dev,
@@ -311,6 +316,7 @@ static const struct dev_pm_ops exynos_ohci_pm_ops = {
311#ifdef CONFIG_OF 316#ifdef CONFIG_OF
312static const struct of_device_id exynos_ohci_match[] = { 317static const struct of_device_id exynos_ohci_match[] = {
313 { .compatible = "samsung,exynos4210-ohci" }, 318 { .compatible = "samsung,exynos4210-ohci" },
319 { .compatible = "samsung,exynos5440-ohci" },
314 {}, 320 {},
315}; 321};
316MODULE_DEVICE_TABLE(of, exynos_ohci_match); 322MODULE_DEVICE_TABLE(of, exynos_ohci_match);
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 180a2b01db56..9e6de9586ae4 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1102,12 +1102,12 @@ MODULE_LICENSE ("GPL");
1102 1102
1103#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX) 1103#if defined(CONFIG_ARCH_S3C24XX) || defined(CONFIG_ARCH_S3C64XX)
1104#include "ohci-s3c2410.c" 1104#include "ohci-s3c2410.c"
1105#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver 1105#define S3C2410_PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1106#endif 1106#endif
1107 1107
1108#ifdef CONFIG_USB_OHCI_EXYNOS 1108#ifdef CONFIG_USB_OHCI_EXYNOS
1109#include "ohci-exynos.c" 1109#include "ohci-exynos.c"
1110#define PLATFORM_DRIVER exynos_ohci_driver 1110#define EXYNOS_PLATFORM_DRIVER exynos_ohci_driver
1111#endif 1111#endif
1112 1112
1113#ifdef CONFIG_USB_OHCI_HCD_OMAP1 1113#ifdef CONFIG_USB_OHCI_HCD_OMAP1
@@ -1127,25 +1127,24 @@ MODULE_LICENSE ("GPL");
1127 1127
1128#ifdef CONFIG_ARCH_EP93XX 1128#ifdef CONFIG_ARCH_EP93XX
1129#include "ohci-ep93xx.c" 1129#include "ohci-ep93xx.c"
1130#define PLATFORM_DRIVER ohci_hcd_ep93xx_driver 1130#define EP93XX_PLATFORM_DRIVER ohci_hcd_ep93xx_driver
1131#endif 1131#endif
1132 1132
1133#ifdef CONFIG_ARCH_AT91 1133#ifdef CONFIG_ARCH_AT91
1134#include "ohci-at91.c" 1134#include "ohci-at91.c"
1135#define PLATFORM_DRIVER ohci_hcd_at91_driver 1135#define AT91_PLATFORM_DRIVER ohci_hcd_at91_driver
1136#endif 1136#endif
1137 1137
1138#ifdef CONFIG_ARCH_LPC32XX 1138#ifdef CONFIG_ARCH_LPC32XX
1139#include "ohci-nxp.c" 1139#include "ohci-nxp.c"
1140#define PLATFORM_DRIVER usb_hcd_nxp_driver 1140#define NXP_PLATFORM_DRIVER usb_hcd_nxp_driver
1141#endif 1141#endif
1142 1142
1143#ifdef CONFIG_ARCH_DAVINCI_DA8XX 1143#ifdef CONFIG_ARCH_DAVINCI_DA8XX
1144#include "ohci-da8xx.c" 1144#include "ohci-da8xx.c"
1145#define PLATFORM_DRIVER ohci_hcd_da8xx_driver 1145#define DAVINCI_PLATFORM_DRIVER ohci_hcd_da8xx_driver
1146#endif 1146#endif
1147 1147
1148
1149#ifdef CONFIG_USB_OHCI_HCD_PPC_OF 1148#ifdef CONFIG_USB_OHCI_HCD_PPC_OF
1150#include "ohci-ppc-of.c" 1149#include "ohci-ppc-of.c"
1151#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver 1150#define OF_PLATFORM_DRIVER ohci_hcd_ppc_of_driver
@@ -1153,7 +1152,7 @@ MODULE_LICENSE ("GPL");
1153 1152
1154#ifdef CONFIG_PLAT_SPEAR 1153#ifdef CONFIG_PLAT_SPEAR
1155#include "ohci-spear.c" 1154#include "ohci-spear.c"
1156#define PLATFORM_DRIVER spear_ohci_hcd_driver 1155#define SPEAR_PLATFORM_DRIVER spear_ohci_hcd_driver
1157#endif 1156#endif
1158 1157
1159#ifdef CONFIG_PPC_PS3 1158#ifdef CONFIG_PPC_PS3
@@ -1199,7 +1198,14 @@ MODULE_LICENSE ("GPL");
1199 !defined(SA1111_DRIVER) && \ 1198 !defined(SA1111_DRIVER) && \
1200 !defined(PS3_SYSTEM_BUS_DRIVER) && \ 1199 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1201 !defined(SM501_OHCI_DRIVER) && \ 1200 !defined(SM501_OHCI_DRIVER) && \
1202 !defined(TMIO_OHCI_DRIVER) 1201 !defined(TMIO_OHCI_DRIVER) && \
1202 !defined(S3C2410_PLATFORM_DRIVER) && \
1203 !defined(EXYNOS_PLATFORM_DRIVER) && \
1204 !defined(EP93XX_PLATFORM_DRIVER) && \
1205 !defined(AT91_PLATFORM_DRIVER) && \
1206 !defined(NXP_PLATFORM_DRIVER) && \
1207 !defined(DAVINCI_PLATFORM_DRIVER) && \
1208 !defined(SPEAR_PLATFORM_DRIVER)
1203#error "missing bus glue for ohci-hcd" 1209#error "missing bus glue for ohci-hcd"
1204#endif 1210#endif
1205 1211
@@ -1277,9 +1283,79 @@ static int __init ohci_hcd_mod_init(void)
1277 goto error_tmio; 1283 goto error_tmio;
1278#endif 1284#endif
1279 1285
1286#ifdef S3C2410_PLATFORM_DRIVER
1287 retval = platform_driver_register(&S3C2410_PLATFORM_DRIVER);
1288 if (retval < 0)
1289 goto error_s3c2410;
1290#endif
1291
1292#ifdef EXYNOS_PLATFORM_DRIVER
1293 retval = platform_driver_register(&EXYNOS_PLATFORM_DRIVER);
1294 if (retval < 0)
1295 goto error_exynos;
1296#endif
1297
1298#ifdef EP93XX_PLATFORM_DRIVER
1299 retval = platform_driver_register(&EP93XX_PLATFORM_DRIVER);
1300 if (retval < 0)
1301 goto error_ep93xx;
1302#endif
1303
1304#ifdef AT91_PLATFORM_DRIVER
1305 retval = platform_driver_register(&AT91_PLATFORM_DRIVER);
1306 if (retval < 0)
1307 goto error_at91;
1308#endif
1309
1310#ifdef NXP_PLATFORM_DRIVER
1311 retval = platform_driver_register(&NXP_PLATFORM_DRIVER);
1312 if (retval < 0)
1313 goto error_nxp;
1314#endif
1315
1316#ifdef DAVINCI_PLATFORM_DRIVER
1317 retval = platform_driver_register(&DAVINCI_PLATFORM_DRIVER);
1318 if (retval < 0)
1319 goto error_davinci;
1320#endif
1321
1322#ifdef SPEAR_PLATFORM_DRIVER
1323 retval = platform_driver_register(&SPEAR_PLATFORM_DRIVER);
1324 if (retval < 0)
1325 goto error_spear;
1326#endif
1327
1280 return retval; 1328 return retval;
1281 1329
1282 /* Error path */ 1330 /* Error path */
1331#ifdef SPEAR_PLATFORM_DRIVER
1332 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1333 error_spear:
1334#endif
1335#ifdef DAVINCI_PLATFORM_DRIVER
1336 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1337 error_davinci:
1338#endif
1339#ifdef NXP_PLATFORM_DRIVER
1340 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1341 error_nxp:
1342#endif
1343#ifdef AT91_PLATFORM_DRIVER
1344 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1345 error_at91:
1346#endif
1347#ifdef EP93XX_PLATFORM_DRIVER
1348 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1349 error_ep93xx:
1350#endif
1351#ifdef EXYNOS_PLATFORM_DRIVER
1352 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1353 error_exynos:
1354#endif
1355#ifdef S3C2410_PLATFORM_DRIVER
1356 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1357 error_s3c2410:
1358#endif
1283#ifdef TMIO_OHCI_DRIVER 1359#ifdef TMIO_OHCI_DRIVER
1284 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1360 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1285 error_tmio: 1361 error_tmio:
@@ -1300,17 +1376,17 @@ static int __init ohci_hcd_mod_init(void)
1300 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1376 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1301 error_of_platform: 1377 error_of_platform:
1302#endif 1378#endif
1303#ifdef PLATFORM_DRIVER 1379#ifdef OMAP3_PLATFORM_DRIVER
1304 platform_driver_unregister(&PLATFORM_DRIVER); 1380 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1305 error_platform: 1381 error_omap3_platform:
1306#endif 1382#endif
1307#ifdef OMAP1_PLATFORM_DRIVER 1383#ifdef OMAP1_PLATFORM_DRIVER
1308 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER); 1384 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1309 error_omap1_platform: 1385 error_omap1_platform:
1310#endif 1386#endif
1311#ifdef OMAP3_PLATFORM_DRIVER 1387#ifdef PLATFORM_DRIVER
1312 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER); 1388 platform_driver_unregister(&PLATFORM_DRIVER);
1313 error_omap3_platform: 1389 error_platform:
1314#endif 1390#endif
1315#ifdef PS3_SYSTEM_BUS_DRIVER 1391#ifdef PS3_SYSTEM_BUS_DRIVER
1316 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1392 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
@@ -1329,6 +1405,27 @@ module_init(ohci_hcd_mod_init);
1329 1405
1330static void __exit ohci_hcd_mod_exit(void) 1406static void __exit ohci_hcd_mod_exit(void)
1331{ 1407{
1408#ifdef SPEAR_PLATFORM_DRIVER
1409 platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
1410#endif
1411#ifdef DAVINCI_PLATFORM_DRIVER
1412 platform_driver_unregister(&DAVINCI_PLATFORM_DRIVER);
1413#endif
1414#ifdef NXP_PLATFORM_DRIVER
1415 platform_driver_unregister(&NXP_PLATFORM_DRIVER);
1416#endif
1417#ifdef AT91_PLATFORM_DRIVER
1418 platform_driver_unregister(&AT91_PLATFORM_DRIVER);
1419#endif
1420#ifdef EP93XX_PLATFORM_DRIVER
1421 platform_driver_unregister(&EP93XX_PLATFORM_DRIVER);
1422#endif
1423#ifdef EXYNOS_PLATFORM_DRIVER
1424 platform_driver_unregister(&EXYNOS_PLATFORM_DRIVER);
1425#endif
1426#ifdef S3C2410_PLATFORM_DRIVER
1427 platform_driver_unregister(&S3C2410_PLATFORM_DRIVER);
1428#endif
1332#ifdef TMIO_OHCI_DRIVER 1429#ifdef TMIO_OHCI_DRIVER
1333 platform_driver_unregister(&TMIO_OHCI_DRIVER); 1430 platform_driver_unregister(&TMIO_OHCI_DRIVER);
1334#endif 1431#endif
@@ -1344,12 +1441,15 @@ static void __exit ohci_hcd_mod_exit(void)
1344#ifdef OF_PLATFORM_DRIVER 1441#ifdef OF_PLATFORM_DRIVER
1345 platform_driver_unregister(&OF_PLATFORM_DRIVER); 1442 platform_driver_unregister(&OF_PLATFORM_DRIVER);
1346#endif 1443#endif
1347#ifdef PLATFORM_DRIVER
1348 platform_driver_unregister(&PLATFORM_DRIVER);
1349#endif
1350#ifdef OMAP3_PLATFORM_DRIVER 1444#ifdef OMAP3_PLATFORM_DRIVER
1351 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER); 1445 platform_driver_unregister(&OMAP3_PLATFORM_DRIVER);
1352#endif 1446#endif
1447#ifdef OMAP1_PLATFORM_DRIVER
1448 platform_driver_unregister(&OMAP1_PLATFORM_DRIVER);
1449#endif
1450#ifdef PLATFORM_DRIVER
1451 platform_driver_unregister(&PLATFORM_DRIVER);
1452#endif
1353#ifdef PS3_SYSTEM_BUS_DRIVER 1453#ifdef PS3_SYSTEM_BUS_DRIVER
1354 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER); 1454 ps3_ohci_driver_unregister(&PS3_SYSTEM_BUS_DRIVER);
1355#endif 1455#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index db09dae7b557..60ff4220e8b4 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -580,14 +580,8 @@ static int ohci_start_port_reset (struct usb_hcd *hcd, unsigned port)
580 580
581/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling, 581/* See usb 7.1.7.5: root hubs must issue at least 50 msec reset signaling,
582 * not necessarily continuous ... to guard against resume signaling. 582 * not necessarily continuous ... to guard against resume signaling.
583 * The short timeout is safe for non-root hubs, and is backward-compatible
584 * with earlier Linux hosts.
585 */ 583 */
586#ifdef CONFIG_USB_SUSPEND
587#define PORT_RESET_MSEC 50 584#define PORT_RESET_MSEC 50
588#else
589#define PORT_RESET_MSEC 10
590#endif
591 585
592/* this timer value might be vendor-specific ... */ 586/* this timer value might be vendor-specific ... */
593#define PORT_RESET_HW_MSEC 10 587#define PORT_RESET_HW_MSEC 10
diff --git a/drivers/usb/host/ohci-omap3.c b/drivers/usb/host/ohci-omap3.c
index eb35d9630237..ddfc31427bc0 100644
--- a/drivers/usb/host/ohci-omap3.c
+++ b/drivers/usb/host/ohci-omap3.c
@@ -31,6 +31,8 @@
31 31
32#include <linux/platform_device.h> 32#include <linux/platform_device.h>
33#include <linux/pm_runtime.h> 33#include <linux/pm_runtime.h>
34#include <linux/of.h>
35#include <linux/dma-mapping.h>
34 36
35/*-------------------------------------------------------------------------*/ 37/*-------------------------------------------------------------------------*/
36 38
@@ -112,6 +114,8 @@ static const struct hc_driver ohci_omap3_hc_driver = {
112 114
113/*-------------------------------------------------------------------------*/ 115/*-------------------------------------------------------------------------*/
114 116
117static u64 omap_ohci_dma_mask = DMA_BIT_MASK(32);
118
115/* 119/*
116 * configure so an HC device and id are always provided 120 * configure so an HC device and id are always provided
117 * always called with process context; sleeping is OK 121 * always called with process context; sleeping is OK
@@ -141,14 +145,13 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
141 return -ENODEV; 145 return -ENODEV;
142 } 146 }
143 147
144 irq = platform_get_irq_byname(pdev, "ohci-irq"); 148 irq = platform_get_irq(pdev, 0);
145 if (irq < 0) { 149 if (irq < 0) {
146 dev_err(dev, "OHCI irq failed\n"); 150 dev_err(dev, "OHCI irq failed\n");
147 return -ENODEV; 151 return -ENODEV;
148 } 152 }
149 153
150 res = platform_get_resource_byname(pdev, 154 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 IORESOURCE_MEM, "ohci");
152 if (!res) { 155 if (!res) {
153 dev_err(dev, "UHH OHCI get resource failed\n"); 156 dev_err(dev, "UHH OHCI get resource failed\n");
154 return -ENOMEM; 157 return -ENOMEM;
@@ -160,6 +163,13 @@ static int ohci_hcd_omap3_probe(struct platform_device *pdev)
160 return -ENOMEM; 163 return -ENOMEM;
161 } 164 }
162 165
166 /*
167 * Right now device-tree probed devices don't get dma_mask set.
168 * Since shared usb code relies on it, set it here for now.
169 * Once we have dma capability bindings this can go away.
170 */
171 if (!pdev->dev.dma_mask)
172 pdev->dev.dma_mask = &omap_ohci_dma_mask;
163 173
164 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev, 174 hcd = usb_create_hcd(&ohci_omap3_hc_driver, dev,
165 dev_name(dev)); 175 dev_name(dev));
@@ -229,12 +239,20 @@ static void ohci_hcd_omap3_shutdown(struct platform_device *pdev)
229 hcd->driver->shutdown(hcd); 239 hcd->driver->shutdown(hcd);
230} 240}
231 241
242static const struct of_device_id omap_ohci_dt_ids[] = {
243 { .compatible = "ti,ohci-omap3" },
244 { }
245};
246
247MODULE_DEVICE_TABLE(of, omap_ohci_dt_ids);
248
232static struct platform_driver ohci_hcd_omap3_driver = { 249static struct platform_driver ohci_hcd_omap3_driver = {
233 .probe = ohci_hcd_omap3_probe, 250 .probe = ohci_hcd_omap3_probe,
234 .remove = ohci_hcd_omap3_remove, 251 .remove = ohci_hcd_omap3_remove,
235 .shutdown = ohci_hcd_omap3_shutdown, 252 .shutdown = ohci_hcd_omap3_shutdown,
236 .driver = { 253 .driver = {
237 .name = "ohci-omap3", 254 .name = "ohci-omap3",
255 .of_match_table = of_match_ptr(omap_ohci_dt_ids),
238 }, 256 },
239}; 257};
240 258
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index d62f0404baaa..15ed7e8d887f 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -1755,7 +1755,7 @@ sl811h_probe(struct platform_device *dev)
1755 1755
1756/* for this device there's no useful distinction between the controller 1756/* for this device there's no useful distinction between the controller
1757 * and its root hub, except that the root hub only gets direct PM calls 1757 * and its root hub, except that the root hub only gets direct PM calls
1758 * when CONFIG_USB_SUSPEND is enabled. 1758 * when CONFIG_PM_RUNTIME is enabled.
1759 */ 1759 */
1760 1760
1761static int 1761static int
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 5efdffe32365..5c124bf5d018 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -3141,10 +3141,11 @@ static int u132_probe(struct platform_device *pdev)
3141 3141
3142 3142
3143#ifdef CONFIG_PM 3143#ifdef CONFIG_PM
3144/* for this device there's no useful distinction between the controller 3144/*
3145* and its root hub, except that the root hub only gets direct PM calls 3145 * for this device there's no useful distinction between the controller
3146* when CONFIG_USB_SUSPEND is enabled. 3146 * and its root hub, except that the root hub only gets direct PM calls
3147*/ 3147 * when CONFIG_PM_RUNTIME is enabled.
3148 */
3148static int u132_suspend(struct platform_device *pdev, pm_message_t state) 3149static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3149{ 3150{
3150 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3151 struct usb_hcd *hcd = platform_get_drvdata(pdev);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 68914429482f..187a3ec1069a 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1075,7 +1075,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1075 set_bit(port_index, &bus_state->bus_suspended); 1075 set_bit(port_index, &bus_state->bus_suspended);
1076 } 1076 }
1077 /* USB core sets remote wake mask for USB 3.0 hubs, 1077 /* USB core sets remote wake mask for USB 3.0 hubs,
1078 * including the USB 3.0 roothub, but only if CONFIG_USB_SUSPEND 1078 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME
1079 * is enabled, so also enable remote wake here. 1079 * is enabled, so also enable remote wake here.
1080 */ 1080 */
1081 if (hcd->self.root_hub->do_remote_wakeup) { 1081 if (hcd->self.root_hub->do_remote_wakeup) {
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6dc238c592bc..965b539bc474 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -51,7 +51,7 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
51 return NULL; 51 return NULL;
52 } 52 }
53 53
54 memset(seg->trbs, 0, SEGMENT_SIZE); 54 memset(seg->trbs, 0, TRB_SEGMENT_SIZE);
55 /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */ 55 /* If the cycle state is 0, set the cycle bit to 1 for all the TRBs */
56 if (cycle_state == 0) { 56 if (cycle_state == 0) {
57 for (i = 0; i < TRBS_PER_SEGMENT; i++) 57 for (i = 0; i < TRBS_PER_SEGMENT; i++)
@@ -467,7 +467,7 @@ struct xhci_ring *xhci_dma_to_transfer_ring(
467{ 467{
468 if (ep->ep_state & EP_HAS_STREAMS) 468 if (ep->ep_state & EP_HAS_STREAMS)
469 return radix_tree_lookup(&ep->stream_info->trb_address_map, 469 return radix_tree_lookup(&ep->stream_info->trb_address_map,
470 address >> SEGMENT_SHIFT); 470 address >> TRB_SEGMENT_SHIFT);
471 return ep->ring; 471 return ep->ring;
472} 472}
473 473
@@ -478,7 +478,7 @@ static struct xhci_ring *dma_to_stream_ring(
478 u64 address) 478 u64 address)
479{ 479{
480 return radix_tree_lookup(&stream_info->trb_address_map, 480 return radix_tree_lookup(&stream_info->trb_address_map,
481 address >> SEGMENT_SHIFT); 481 address >> TRB_SEGMENT_SHIFT);
482} 482}
483#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */ 483#endif /* CONFIG_USB_XHCI_HCD_DEBUGGING */
484 484
@@ -514,7 +514,7 @@ static int xhci_test_radix_tree(struct xhci_hcd *xhci,
514 514
515 cur_ring = stream_info->stream_rings[cur_stream]; 515 cur_ring = stream_info->stream_rings[cur_stream];
516 for (addr = cur_ring->first_seg->dma; 516 for (addr = cur_ring->first_seg->dma;
517 addr < cur_ring->first_seg->dma + SEGMENT_SIZE; 517 addr < cur_ring->first_seg->dma + TRB_SEGMENT_SIZE;
518 addr += trb_size) { 518 addr += trb_size) {
519 mapped_ring = dma_to_stream_ring(stream_info, addr); 519 mapped_ring = dma_to_stream_ring(stream_info, addr);
520 if (cur_ring != mapped_ring) { 520 if (cur_ring != mapped_ring) {
@@ -662,7 +662,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
662 cur_stream, (unsigned long long) addr); 662 cur_stream, (unsigned long long) addr);
663 663
664 key = (unsigned long) 664 key = (unsigned long)
665 (cur_ring->first_seg->dma >> SEGMENT_SHIFT); 665 (cur_ring->first_seg->dma >> TRB_SEGMENT_SHIFT);
666 ret = radix_tree_insert(&stream_info->trb_address_map, 666 ret = radix_tree_insert(&stream_info->trb_address_map,
667 key, cur_ring); 667 key, cur_ring);
668 if (ret) { 668 if (ret) {
@@ -693,7 +693,7 @@ cleanup_rings:
693 if (cur_ring) { 693 if (cur_ring) {
694 addr = cur_ring->first_seg->dma; 694 addr = cur_ring->first_seg->dma;
695 radix_tree_delete(&stream_info->trb_address_map, 695 radix_tree_delete(&stream_info->trb_address_map,
696 addr >> SEGMENT_SHIFT); 696 addr >> TRB_SEGMENT_SHIFT);
697 xhci_ring_free(xhci, cur_ring); 697 xhci_ring_free(xhci, cur_ring);
698 stream_info->stream_rings[cur_stream] = NULL; 698 stream_info->stream_rings[cur_stream] = NULL;
699 } 699 }
@@ -764,7 +764,7 @@ void xhci_free_stream_info(struct xhci_hcd *xhci,
764 if (cur_ring) { 764 if (cur_ring) {
765 addr = cur_ring->first_seg->dma; 765 addr = cur_ring->first_seg->dma;
766 radix_tree_delete(&stream_info->trb_address_map, 766 radix_tree_delete(&stream_info->trb_address_map,
767 addr >> SEGMENT_SHIFT); 767 addr >> TRB_SEGMENT_SHIFT);
768 xhci_ring_free(xhci, cur_ring); 768 xhci_ring_free(xhci, cur_ring);
769 stream_info->stream_rings[cur_stream] = NULL; 769 stream_info->stream_rings[cur_stream] = NULL;
770 } 770 }
@@ -2305,7 +2305,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2305 * so we pick the greater alignment need. 2305 * so we pick the greater alignment need.
2306 */ 2306 */
2307 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, 2307 xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
2308 SEGMENT_SIZE, 64, xhci->page_size); 2308 TRB_SEGMENT_SIZE, 64, xhci->page_size);
2309 2309
2310 /* See Table 46 and Note on Figure 55 */ 2310 /* See Table 46 and Note on Figure 55 */
2311 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, 2311 xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev,
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 53b8f89a0b1c..b4aa79d154b2 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -417,9 +417,9 @@ static void compliance_mode_recovery(unsigned long arg)
417 * Compliance Mode Detected. Letting USB Core 417 * Compliance Mode Detected. Letting USB Core
418 * handle the Warm Reset 418 * handle the Warm Reset
419 */ 419 */
420 xhci_dbg(xhci, "Compliance Mode Detected->Port %d!\n", 420 xhci_dbg(xhci, "Compliance mode detected->port %d\n",
421 i + 1); 421 i + 1);
422 xhci_dbg(xhci, "Attempting Recovery routine!\n"); 422 xhci_dbg(xhci, "Attempting compliance mode recovery\n");
423 hcd = xhci->shared_hcd; 423 hcd = xhci->shared_hcd;
424 424
425 if (hcd->state == HC_STATE_SUSPENDED) 425 if (hcd->state == HC_STATE_SUSPENDED)
@@ -457,7 +457,7 @@ static void compliance_mode_recovery_timer_init(struct xhci_hcd *xhci)
457 set_timer_slack(&xhci->comp_mode_recovery_timer, 457 set_timer_slack(&xhci->comp_mode_recovery_timer,
458 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS)); 458 msecs_to_jiffies(COMP_MODE_RCVRY_MSECS));
459 add_timer(&xhci->comp_mode_recovery_timer); 459 add_timer(&xhci->comp_mode_recovery_timer);
460 xhci_dbg(xhci, "Compliance Mode Recovery Timer Initialized.\n"); 460 xhci_dbg(xhci, "Compliance mode recovery timer initialized\n");
461} 461}
462 462
463/* 463/*
@@ -733,8 +733,11 @@ void xhci_stop(struct usb_hcd *hcd)
733 733
734 /* Deleting Compliance Mode Recovery Timer */ 734 /* Deleting Compliance Mode Recovery Timer */
735 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && 735 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
736 (!(xhci_all_ports_seen_u0(xhci)))) 736 (!(xhci_all_ports_seen_u0(xhci)))) {
737 del_timer_sync(&xhci->comp_mode_recovery_timer); 737 del_timer_sync(&xhci->comp_mode_recovery_timer);
738 xhci_dbg(xhci, "%s: compliance mode recovery timer deleted\n",
739 __func__);
740 }
738 741
739 if (xhci->quirks & XHCI_AMD_PLL_FIX) 742 if (xhci->quirks & XHCI_AMD_PLL_FIX)
740 usb_amd_dev_put(); 743 usb_amd_dev_put();
@@ -930,7 +933,8 @@ int xhci_suspend(struct xhci_hcd *xhci)
930 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && 933 if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
931 (!(xhci_all_ports_seen_u0(xhci)))) { 934 (!(xhci_all_ports_seen_u0(xhci)))) {
932 del_timer_sync(&xhci->comp_mode_recovery_timer); 935 del_timer_sync(&xhci->comp_mode_recovery_timer);
933 xhci_dbg(xhci, "Compliance Mode Recovery Timer Deleted!\n"); 936 xhci_dbg(xhci, "%s: compliance mode recovery timer deleted\n",
937 __func__);
934 } 938 }
935 939
936 /* step 5: remove core well power */ 940 /* step 5: remove core well power */
@@ -3801,7 +3805,7 @@ int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1)
3801 return raw_port; 3805 return raw_port;
3802} 3806}
3803 3807
3804#ifdef CONFIG_USB_SUSPEND 3808#ifdef CONFIG_PM_RUNTIME
3805 3809
3806/* BESL to HIRD Encoding array for USB2 LPM */ 3810/* BESL to HIRD Encoding array for USB2 LPM */
3807static int xhci_besl_encoding[16] = {125, 150, 200, 300, 400, 500, 1000, 2000, 3811static int xhci_besl_encoding[16] = {125, 150, 200, 300, 400, 500, 1000, 2000,
@@ -4051,7 +4055,7 @@ int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
4051 return 0; 4055 return 0;
4052} 4056}
4053 4057
4054#endif /* CONFIG_USB_SUSPEND */ 4058#endif /* CONFIG_PM_RUNTIME */
4055 4059
4056/*---------------------- USB 3.0 Link PM functions ------------------------*/ 4060/*---------------------- USB 3.0 Link PM functions ------------------------*/
4057 4061
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 63582719e0fb..29c978e37135 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1238,8 +1238,8 @@ union xhci_trb {
1238#define TRBS_PER_SEGMENT 64 1238#define TRBS_PER_SEGMENT 64
1239/* Allow two commands + a link TRB, along with any reserved command TRBs */ 1239/* Allow two commands + a link TRB, along with any reserved command TRBs */
1240#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3) 1240#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1241#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16) 1241#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
1242#define SEGMENT_SHIFT (__ffs(SEGMENT_SIZE)) 1242#define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE))
1243/* TRB buffer pointers can't cross 64KB boundaries */ 1243/* TRB buffer pointers can't cross 64KB boundaries */
1244#define TRB_MAX_BUFF_SHIFT 16 1244#define TRB_MAX_BUFF_SHIFT 16
1245#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT) 1245#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
diff --git a/drivers/usb/image/Kconfig b/drivers/usb/image/Kconfig
index 33350f9dd34f..320d368c8dac 100644
--- a/drivers/usb/image/Kconfig
+++ b/drivers/usb/image/Kconfig
@@ -2,11 +2,9 @@
2# USB Imaging devices configuration 2# USB Imaging devices configuration
3# 3#
4comment "USB Imaging devices" 4comment "USB Imaging devices"
5 depends on USB
6 5
7config USB_MDC800 6config USB_MDC800
8 tristate "USB Mustek MDC800 Digital Camera support" 7 tristate "USB Mustek MDC800 Digital Camera support"
9 depends on USB
10 ---help--- 8 ---help---
11 Say Y here if you want to connect this type of still camera to 9 Say Y here if you want to connect this type of still camera to
12 your computer's USB port. This driver can be used with gphoto 0.4.3 10 your computer's USB port. This driver can be used with gphoto 0.4.3
@@ -19,7 +17,7 @@ config USB_MDC800
19 17
20config USB_MICROTEK 18config USB_MICROTEK
21 tristate "Microtek X6USB scanner support" 19 tristate "Microtek X6USB scanner support"
22 depends on USB && SCSI 20 depends on SCSI
23 help 21 help
24 Say Y here if you want support for the Microtek X6USB and 22 Say Y here if you want support for the Microtek X6USB and
25 possibly the Phantom 336CX, Phantom C6 and ScanMaker V6U(S)L. 23 possibly the Phantom 336CX, Phantom C6 and ScanMaker V6U(S)L.
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 3b1a3f4ec5e9..a51e7d6afda9 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -2,11 +2,9 @@
2# USB Miscellaneous driver configuration 2# USB Miscellaneous driver configuration
3# 3#
4comment "USB Miscellaneous drivers" 4comment "USB Miscellaneous drivers"
5 depends on USB
6 5
7config USB_EMI62 6config USB_EMI62
8 tristate "EMI 6|2m USB Audio interface support" 7 tristate "EMI 6|2m USB Audio interface support"
9 depends on USB
10 ---help--- 8 ---help---
11 This driver loads firmware to Emagic EMI 6|2m low latency USB 9 This driver loads firmware to Emagic EMI 6|2m low latency USB
12 Audio and Midi interface. 10 Audio and Midi interface.
@@ -21,7 +19,6 @@ config USB_EMI62
21 19
22config USB_EMI26 20config USB_EMI26
23 tristate "EMI 2|6 USB Audio interface support" 21 tristate "EMI 2|6 USB Audio interface support"
24 depends on USB
25 ---help--- 22 ---help---
26 This driver loads firmware to Emagic EMI 2|6 low latency USB 23 This driver loads firmware to Emagic EMI 2|6 low latency USB
27 Audio interface. 24 Audio interface.
@@ -34,7 +31,6 @@ config USB_EMI26
34 31
35config USB_ADUTUX 32config USB_ADUTUX
36 tristate "ADU devices from Ontrak Control Systems" 33 tristate "ADU devices from Ontrak Control Systems"
37 depends on USB
38 help 34 help
39 Say Y if you want to use an ADU device from Ontrak Control 35 Say Y if you want to use an ADU device from Ontrak Control
40 Systems. 36 Systems.
@@ -44,7 +40,6 @@ config USB_ADUTUX
44 40
45config USB_SEVSEG 41config USB_SEVSEG
46 tristate "USB 7-Segment LED Display" 42 tristate "USB 7-Segment LED Display"
47 depends on USB
48 help 43 help
49 Say Y here if you have a USB 7-Segment Display by Delcom 44 Say Y here if you have a USB 7-Segment Display by Delcom
50 45
@@ -53,7 +48,6 @@ config USB_SEVSEG
53 48
54config USB_RIO500 49config USB_RIO500
55 tristate "USB Diamond Rio500 support" 50 tristate "USB Diamond Rio500 support"
56 depends on USB
57 help 51 help
58 Say Y here if you want to connect a USB Rio500 mp3 player to your 52 Say Y here if you want to connect a USB Rio500 mp3 player to your
59 computer's USB port. Please read <file:Documentation/usb/rio.txt> 53 computer's USB port. Please read <file:Documentation/usb/rio.txt>
@@ -64,7 +58,6 @@ config USB_RIO500
64 58
65config USB_LEGOTOWER 59config USB_LEGOTOWER
66 tristate "USB Lego Infrared Tower support" 60 tristate "USB Lego Infrared Tower support"
67 depends on USB
68 help 61 help
69 Say Y here if you want to connect a USB Lego Infrared Tower to your 62 Say Y here if you want to connect a USB Lego Infrared Tower to your
70 computer's USB port. 63 computer's USB port.
@@ -77,7 +70,6 @@ config USB_LEGOTOWER
77 70
78config USB_LCD 71config USB_LCD
79 tristate "USB LCD driver support" 72 tristate "USB LCD driver support"
80 depends on USB
81 help 73 help
82 Say Y here if you want to connect an USBLCD to your computer's 74 Say Y here if you want to connect an USBLCD to your computer's
83 USB port. The USBLCD is a small USB interface board for 75 USB port. The USBLCD is a small USB interface board for
@@ -89,7 +81,6 @@ config USB_LCD
89 81
90config USB_LED 82config USB_LED
91 tristate "USB LED driver support" 83 tristate "USB LED driver support"
92 depends on USB
93 help 84 help
94 Say Y here if you want to connect an USBLED device to your 85 Say Y here if you want to connect an USBLED device to your
95 computer's USB port. 86 computer's USB port.
@@ -99,7 +90,6 @@ config USB_LED
99 90
100config USB_CYPRESS_CY7C63 91config USB_CYPRESS_CY7C63
101 tristate "Cypress CY7C63xxx USB driver support" 92 tristate "Cypress CY7C63xxx USB driver support"
102 depends on USB
103 help 93 help
104 Say Y here if you want to connect a Cypress CY7C63xxx 94 Say Y here if you want to connect a Cypress CY7C63xxx
105 micro controller to your computer's USB port. Currently this 95 micro controller to your computer's USB port. Currently this
@@ -113,7 +103,6 @@ config USB_CYPRESS_CY7C63
113 103
114config USB_CYTHERM 104config USB_CYTHERM
115 tristate "Cypress USB thermometer driver support" 105 tristate "Cypress USB thermometer driver support"
116 depends on USB
117 help 106 help
118 Say Y here if you want to connect a Cypress USB thermometer 107 Say Y here if you want to connect a Cypress USB thermometer
119 device to your computer's USB port. This device is also known 108 device to your computer's USB port. This device is also known
@@ -126,7 +115,6 @@ config USB_CYTHERM
126 115
127config USB_IDMOUSE 116config USB_IDMOUSE
128 tristate "Siemens ID USB Mouse Fingerprint sensor support" 117 tristate "Siemens ID USB Mouse Fingerprint sensor support"
129 depends on USB
130 help 118 help
131 Say Y here if you want to use the fingerprint sensor on 119 Say Y here if you want to use the fingerprint sensor on
132 the Siemens ID Mouse. There is also a Siemens ID Mouse 120 the Siemens ID Mouse. There is also a Siemens ID Mouse
@@ -140,7 +128,6 @@ config USB_IDMOUSE
140 128
141config USB_FTDI_ELAN 129config USB_FTDI_ELAN
142 tristate "Elan PCMCIA CardBus Adapter USB Client" 130 tristate "Elan PCMCIA CardBus Adapter USB Client"
143 depends on USB
144 default M 131 default M
145 help 132 help
146 ELAN's Uxxx series of adapters are USB to PCMCIA CardBus adapters. 133 ELAN's Uxxx series of adapters are USB to PCMCIA CardBus adapters.
@@ -164,7 +151,6 @@ config USB_FTDI_ELAN
164 151
165config USB_APPLEDISPLAY 152config USB_APPLEDISPLAY
166 tristate "Apple Cinema Display support" 153 tristate "Apple Cinema Display support"
167 depends on USB
168 select BACKLIGHT_LCD_SUPPORT 154 select BACKLIGHT_LCD_SUPPORT
169 select BACKLIGHT_CLASS_DEVICE 155 select BACKLIGHT_CLASS_DEVICE
170 help 156 help
@@ -175,7 +161,6 @@ source "drivers/usb/misc/sisusbvga/Kconfig"
175 161
176config USB_LD 162config USB_LD
177 tristate "USB LD driver" 163 tristate "USB LD driver"
178 depends on USB
179 help 164 help
180 This driver is for generic USB devices that use interrupt transfers, 165 This driver is for generic USB devices that use interrupt transfers,
181 like LD Didactic's USB devices. 166 like LD Didactic's USB devices.
@@ -185,7 +170,6 @@ config USB_LD
185 170
186config USB_TRANCEVIBRATOR 171config USB_TRANCEVIBRATOR
187 tristate "PlayStation 2 Trance Vibrator driver support" 172 tristate "PlayStation 2 Trance Vibrator driver support"
188 depends on USB
189 help 173 help
190 Say Y here if you want to connect a PlayStation 2 Trance Vibrator 174 Say Y here if you want to connect a PlayStation 2 Trance Vibrator
191 device to your computer's USB port. 175 device to your computer's USB port.
@@ -195,7 +179,6 @@ config USB_TRANCEVIBRATOR
195 179
196config USB_IOWARRIOR 180config USB_IOWARRIOR
197 tristate "IO Warrior driver support" 181 tristate "IO Warrior driver support"
198 depends on USB
199 help 182 help
200 Say Y here if you want to support the IO Warrior devices from Code 183 Say Y here if you want to support the IO Warrior devices from Code
201 Mercenaries. This includes support for the following devices: 184 Mercenaries. This includes support for the following devices:
@@ -209,7 +192,6 @@ config USB_IOWARRIOR
209 192
210config USB_TEST 193config USB_TEST
211 tristate "USB testing driver" 194 tristate "USB testing driver"
212 depends on USB
213 help 195 help
214 This driver is for testing host controller software. It is used 196 This driver is for testing host controller software. It is used
215 with specialized device firmware for regression and stress testing, 197 with specialized device firmware for regression and stress testing,
@@ -220,7 +202,6 @@ config USB_TEST
220 202
221config USB_ISIGHTFW 203config USB_ISIGHTFW
222 tristate "iSight firmware loading support" 204 tristate "iSight firmware loading support"
223 depends on USB
224 select FW_LOADER 205 select FW_LOADER
225 help 206 help
226 This driver loads firmware for USB Apple iSight cameras, allowing 207 This driver loads firmware for USB Apple iSight cameras, allowing
@@ -233,7 +214,6 @@ config USB_ISIGHTFW
233 214
234config USB_YUREX 215config USB_YUREX
235 tristate "USB YUREX driver support" 216 tristate "USB YUREX driver support"
236 depends on USB
237 help 217 help
238 Say Y here if you want to connect a YUREX to your computer's 218 Say Y here if you want to connect a YUREX to your computer's
239 USB port. The YUREX is a leg-shakes sensor. See 219 USB port. The YUREX is a leg-shakes sensor. See
@@ -246,7 +226,6 @@ config USB_YUREX
246 226
247config USB_EZUSB_FX2 227config USB_EZUSB_FX2
248 tristate "Functions for loading firmware on EZUSB chips" 228 tristate "Functions for loading firmware on EZUSB chips"
249 depends on USB
250 help 229 help
251 Say Y here if you need EZUSB device support. 230 Say Y here if you need EZUSB device support.
252 (Cypress FX/FX2/FX2LP microcontrollers) 231 (Cypress FX/FX2/FX2LP microcontrollers)
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 0fc6e5fc745f..ba6a5d6e618e 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -63,6 +63,7 @@ static const struct usb_device_id appledisplay_table[] = {
63 { APPLEDISPLAY_DEVICE(0x9219) }, 63 { APPLEDISPLAY_DEVICE(0x9219) },
64 { APPLEDISPLAY_DEVICE(0x921c) }, 64 { APPLEDISPLAY_DEVICE(0x921c) },
65 { APPLEDISPLAY_DEVICE(0x921d) }, 65 { APPLEDISPLAY_DEVICE(0x921d) },
66 { APPLEDISPLAY_DEVICE(0x9236) },
66 67
67 /* Terminating entry */ 68 /* Terminating entry */
68 { } 69 { }
diff --git a/drivers/usb/misc/sisusbvga/Kconfig b/drivers/usb/misc/sisusbvga/Kconfig
index 30ea7ca6846e..0d03a5200482 100644
--- a/drivers/usb/misc/sisusbvga/Kconfig
+++ b/drivers/usb/misc/sisusbvga/Kconfig
@@ -1,7 +1,7 @@
1 1
2config USB_SISUSBVGA 2config USB_SISUSBVGA
3 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)" 3 tristate "USB 2.0 SVGA dongle support (Net2280/SiS315)"
4 depends on USB && (USB_MUSB_HDRC || USB_EHCI_HCD) 4 depends on (USB_MUSB_HDRC || USB_EHCI_HCD)
5 ---help--- 5 ---help---
6 Say Y here if you intend to attach a USB2VGA dongle based on a 6 Say Y here if you intend to attach a USB2VGA dongle based on a
7 Net2280 and a SiS315 chip. 7 Net2280 and a SiS315 chip.
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index dd573abd2d1e..c21386ec5d35 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3084,7 +3084,7 @@ static int sisusb_probe(struct usb_interface *intf,
3084 3084
3085 /* Allocate memory for our private */ 3085 /* Allocate memory for our private */
3086 if (!(sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL))) { 3086 if (!(sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL))) {
3087 dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for private data\n"); 3087 dev_err(&dev->dev, "Failed to allocate memory for private data\n");
3088 return -ENOMEM; 3088 return -ENOMEM;
3089 } 3089 }
3090 kref_init(&sisusb->kref); 3090 kref_init(&sisusb->kref);
diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c
index f713f6aeb6e5..d3a1cce1bf9c 100644
--- a/drivers/usb/misc/usb3503.c
+++ b/drivers/usb/misc/usb3503.c
@@ -307,18 +307,7 @@ static struct i2c_driver usb3503_driver = {
307 .id_table = usb3503_id, 307 .id_table = usb3503_id,
308}; 308};
309 309
310static int __init usb3503_init(void) 310module_i2c_driver(usb3503_driver);
311{
312 return i2c_add_driver(&usb3503_driver);
313}
314
315static void __exit usb3503_exit(void)
316{
317 i2c_del_driver(&usb3503_driver);
318}
319
320module_init(usb3503_init);
321module_exit(usb3503_exit);
322 311
323MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>"); 312MODULE_AUTHOR("Dongjin Kim <tobetter@gmail.com>");
324MODULE_DESCRIPTION("USB3503 USB HUB driver"); 313MODULE_DESCRIPTION("USB3503 USB HUB driver");
diff --git a/drivers/usb/mon/Kconfig b/drivers/usb/mon/Kconfig
index 635745f57fbd..5c6ffa2a612e 100644
--- a/drivers/usb/mon/Kconfig
+++ b/drivers/usb/mon/Kconfig
@@ -4,7 +4,6 @@
4 4
5config USB_MON 5config USB_MON
6 tristate "USB Monitor" 6 tristate "USB Monitor"
7 depends on USB
8 help 7 help
9 If you select this option, a component which captures the USB traffic 8 If you select this option, a component which captures the USB traffic
10 between peripheral-specific drivers and HC drivers will be built. 9 between peripheral-specific drivers and HC drivers will be built.
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 05e51432dd2f..06f8d29af1ef 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -6,8 +6,7 @@
6# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller 6# (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
7config USB_MUSB_HDRC 7config USB_MUSB_HDRC
8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' 8 tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
9 depends on USB && USB_GADGET 9 depends on USB_GADGET
10 select USB_OTG_UTILS
11 help 10 help
12 Say Y here if your system has a dual role high speed USB 11 Say Y here if your system has a dual role high speed USB
13 controller based on the Mentor Graphics silicon IP. Then 12 controller based on the Mentor Graphics silicon IP. Then
@@ -34,10 +33,12 @@ choice
34config USB_MUSB_DAVINCI 33config USB_MUSB_DAVINCI
35 tristate "DaVinci" 34 tristate "DaVinci"
36 depends on ARCH_DAVINCI_DMx 35 depends on ARCH_DAVINCI_DMx
36 depends on BROKEN
37 37
38config USB_MUSB_DA8XX 38config USB_MUSB_DA8XX
39 tristate "DA8xx/OMAP-L1x" 39 tristate "DA8xx/OMAP-L1x"
40 depends on ARCH_DAVINCI_DA8XX 40 depends on ARCH_DAVINCI_DA8XX
41 depends on BROKEN
41 42
42config USB_MUSB_TUSB6010 43config USB_MUSB_TUSB6010
43 tristate "TUSB6010" 44 tristate "TUSB6010"
@@ -53,7 +54,6 @@ config USB_MUSB_AM35X
53 54
54config USB_MUSB_DSPS 55config USB_MUSB_DSPS
55 tristate "TI DSPS platforms" 56 tristate "TI DSPS platforms"
56 depends on SOC_TI81XX || SOC_AM33XX
57 57
58config USB_MUSB_BLACKFIN 58config USB_MUSB_BLACKFIN
59 tristate "Blackfin" 59 tristate "Blackfin"
@@ -61,12 +61,12 @@ config USB_MUSB_BLACKFIN
61 61
62config USB_MUSB_UX500 62config USB_MUSB_UX500
63 tristate "U8500 and U5500" 63 tristate "U8500 and U5500"
64 depends on (ARCH_U8500 && AB8500_USB)
65 64
66endchoice 65endchoice
67 66
68choice 67choice
69 prompt 'MUSB DMA mode' 68 prompt 'MUSB DMA mode'
69 default MUSB_PIO_ONLY if ARCH_MULTIPLATFORM
70 default USB_UX500_DMA if USB_MUSB_UX500 70 default USB_UX500_DMA if USB_MUSB_UX500
71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN 71 default USB_INVENTRA_DMA if USB_MUSB_OMAP2PLUS || USB_MUSB_BLACKFIN
72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI 72 default USB_TI_CPPI_DMA if USB_MUSB_DAVINCI
diff --git a/drivers/usb/musb/am35x.c b/drivers/usb/musb/am35x.c
index 59eea219034a..2231850c0625 100644
--- a/drivers/usb/musb/am35x.c
+++ b/drivers/usb/musb/am35x.c
@@ -149,7 +149,7 @@ static void otg_timer(unsigned long _musb)
149 */ 149 */
150 devctl = musb_readb(mregs, MUSB_DEVCTL); 150 devctl = musb_readb(mregs, MUSB_DEVCTL);
151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 151 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
152 otg_state_string(musb->xceiv->state)); 152 usb_otg_state_string(musb->xceiv->state));
153 153
154 spin_lock_irqsave(&musb->lock, flags); 154 spin_lock_irqsave(&musb->lock, flags);
155 switch (musb->xceiv->state) { 155 switch (musb->xceiv->state) {
@@ -195,7 +195,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
195 if (musb->is_active || (musb->a_wait_bcon == 0 && 195 if (musb->is_active || (musb->a_wait_bcon == 0 &&
196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 196 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
197 dev_dbg(musb->controller, "%s active, deleting timer\n", 197 dev_dbg(musb->controller, "%s active, deleting timer\n",
198 otg_state_string(musb->xceiv->state)); 198 usb_otg_state_string(musb->xceiv->state));
199 del_timer(&otg_workaround); 199 del_timer(&otg_workaround);
200 last_timer = jiffies; 200 last_timer = jiffies;
201 return; 201 return;
@@ -208,7 +208,7 @@ static void am35x_musb_try_idle(struct musb *musb, unsigned long timeout)
208 last_timer = timeout; 208 last_timer = timeout;
209 209
210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 210 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
211 otg_state_string(musb->xceiv->state), 211 usb_otg_state_string(musb->xceiv->state),
212 jiffies_to_msecs(timeout - jiffies)); 212 jiffies_to_msecs(timeout - jiffies));
213 mod_timer(&otg_workaround, timeout); 213 mod_timer(&otg_workaround, timeout);
214} 214}
@@ -298,7 +298,7 @@ static irqreturn_t am35x_musb_interrupt(int irq, void *hci)
298 /* NOTE: this must complete power-on within 100 ms. */ 298 /* NOTE: this must complete power-on within 100 ms. */
299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 299 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
300 drvvbus ? "on" : "off", 300 drvvbus ? "on" : "off",
301 otg_state_string(musb->xceiv->state), 301 usb_otg_state_string(musb->xceiv->state),
302 err ? " ERROR" : "", 302 err ? " ERROR" : "",
303 devctl); 303 devctl);
304 ret = IRQ_HANDLED; 304 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/blackfin.c b/drivers/usb/musb/blackfin.c
index dbb31b30c7fa..5e63b160db0c 100644
--- a/drivers/usb/musb/blackfin.c
+++ b/drivers/usb/musb/blackfin.c
@@ -280,13 +280,13 @@ static void musb_conn_timer_handler(unsigned long _musb)
280 break; 280 break;
281 default: 281 default:
282 dev_dbg(musb->controller, "%s state not handled\n", 282 dev_dbg(musb->controller, "%s state not handled\n",
283 otg_state_string(musb->xceiv->state)); 283 usb_otg_state_string(musb->xceiv->state));
284 break; 284 break;
285 } 285 }
286 spin_unlock_irqrestore(&musb->lock, flags); 286 spin_unlock_irqrestore(&musb->lock, flags);
287 287
288 dev_dbg(musb->controller, "state is %s\n", 288 dev_dbg(musb->controller, "state is %s\n",
289 otg_state_string(musb->xceiv->state)); 289 usb_otg_state_string(musb->xceiv->state));
290} 290}
291 291
292static void bfin_musb_enable(struct musb *musb) 292static void bfin_musb_enable(struct musb *musb)
@@ -307,7 +307,7 @@ static void bfin_musb_set_vbus(struct musb *musb, int is_on)
307 307
308 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 308 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
309 /* otg %3x conf %08x prcm %08x */ "\n", 309 /* otg %3x conf %08x prcm %08x */ "\n",
310 otg_state_string(musb->xceiv->state), 310 usb_otg_state_string(musb->xceiv->state),
311 musb_readb(musb->mregs, MUSB_DEVCTL)); 311 musb_readb(musb->mregs, MUSB_DEVCTL));
312} 312}
313 313
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index f522000e8f06..9db211ee15b5 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -435,7 +435,6 @@ cppi_rndis_update(struct cppi_channel *c, int is_rx,
435 } 435 }
436} 436}
437 437
438#ifdef CONFIG_USB_MUSB_DEBUG
439static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd) 438static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
440{ 439{
441 pr_debug("RXBD/%s %08x: " 440 pr_debug("RXBD/%s %08x: "
@@ -444,21 +443,16 @@ static void cppi_dump_rxbd(const char *tag, struct cppi_descriptor *bd)
444 bd->hw_next, bd->hw_bufp, bd->hw_off_len, 443 bd->hw_next, bd->hw_bufp, bd->hw_off_len,
445 bd->hw_options); 444 bd->hw_options);
446} 445}
447#endif
448 446
449static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx) 447static void cppi_dump_rxq(int level, const char *tag, struct cppi_channel *rx)
450{ 448{
451#ifdef CONFIG_USB_MUSB_DEBUG
452 struct cppi_descriptor *bd; 449 struct cppi_descriptor *bd;
453 450
454 if (!_dbg_level(level))
455 return;
456 cppi_dump_rx(level, rx, tag); 451 cppi_dump_rx(level, rx, tag);
457 if (rx->last_processed) 452 if (rx->last_processed)
458 cppi_dump_rxbd("last", rx->last_processed); 453 cppi_dump_rxbd("last", rx->last_processed);
459 for (bd = rx->head; bd; bd = bd->next) 454 for (bd = rx->head; bd; bd = bd->next)
460 cppi_dump_rxbd("active", bd); 455 cppi_dump_rxbd("active", bd);
461#endif
462} 456}
463 457
464 458
@@ -784,6 +778,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
784 void __iomem *tibase = musb->ctrl_base; 778 void __iomem *tibase = musb->ctrl_base;
785 int is_rndis = 0; 779 int is_rndis = 0;
786 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram; 780 struct cppi_rx_stateram __iomem *rx_ram = rx->state_ram;
781 struct cppi_descriptor *d;
787 782
788 if (onepacket) { 783 if (onepacket) {
789 /* almost every USB driver, host or peripheral side */ 784 /* almost every USB driver, host or peripheral side */
@@ -897,14 +892,8 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket)
897 bd->hw_options |= CPPI_SOP_SET; 892 bd->hw_options |= CPPI_SOP_SET;
898 tail->hw_options |= CPPI_EOP_SET; 893 tail->hw_options |= CPPI_EOP_SET;
899 894
900#ifdef CONFIG_USB_MUSB_DEBUG 895 for (d = rx->head; d; d = d->next)
901 if (_dbg_level(5)) { 896 cppi_dump_rxbd("S", d);
902 struct cppi_descriptor *d;
903
904 for (d = rx->head; d; d = d->next)
905 cppi_dump_rxbd("S", d);
906 }
907#endif
908 897
909 /* in case the preceding transfer left some state... */ 898 /* in case the preceding transfer left some state... */
910 tail = rx->last_processed; 899 tail = rx->last_processed;
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 41613a2b35e8..b903b744a224 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -198,7 +198,7 @@ static void otg_timer(unsigned long _musb)
198 */ 198 */
199 devctl = musb_readb(mregs, MUSB_DEVCTL); 199 devctl = musb_readb(mregs, MUSB_DEVCTL);
200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 200 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
201 otg_state_string(musb->xceiv->state)); 201 usb_otg_state_string(musb->xceiv->state));
202 202
203 spin_lock_irqsave(&musb->lock, flags); 203 spin_lock_irqsave(&musb->lock, flags);
204 switch (musb->xceiv->state) { 204 switch (musb->xceiv->state) {
@@ -267,7 +267,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
267 if (musb->is_active || (musb->a_wait_bcon == 0 && 267 if (musb->is_active || (musb->a_wait_bcon == 0 &&
268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 268 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
269 dev_dbg(musb->controller, "%s active, deleting timer\n", 269 dev_dbg(musb->controller, "%s active, deleting timer\n",
270 otg_state_string(musb->xceiv->state)); 270 usb_otg_state_string(musb->xceiv->state));
271 del_timer(&otg_workaround); 271 del_timer(&otg_workaround);
272 last_timer = jiffies; 272 last_timer = jiffies;
273 return; 273 return;
@@ -280,7 +280,7 @@ static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout)
280 last_timer = timeout; 280 last_timer = timeout;
281 281
282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 282 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
283 otg_state_string(musb->xceiv->state), 283 usb_otg_state_string(musb->xceiv->state),
284 jiffies_to_msecs(timeout - jiffies)); 284 jiffies_to_msecs(timeout - jiffies));
285 mod_timer(&otg_workaround, timeout); 285 mod_timer(&otg_workaround, timeout);
286} 286}
@@ -360,7 +360,7 @@ static irqreturn_t da8xx_musb_interrupt(int irq, void *hci)
360 360
361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 361 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
362 drvvbus ? "on" : "off", 362 drvvbus ? "on" : "off",
363 otg_state_string(musb->xceiv->state), 363 usb_otg_state_string(musb->xceiv->state),
364 err ? " ERROR" : "", 364 err ? " ERROR" : "",
365 devctl); 365 devctl);
366 ret = IRQ_HANDLED; 366 ret = IRQ_HANDLED;
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index e040d9103735..bea6cc35471c 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -215,7 +215,7 @@ static void otg_timer(unsigned long _musb)
215 */ 215 */
216 devctl = musb_readb(mregs, MUSB_DEVCTL); 216 devctl = musb_readb(mregs, MUSB_DEVCTL);
217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl, 217 dev_dbg(musb->controller, "poll devctl %02x (%s)\n", devctl,
218 otg_state_string(musb->xceiv->state)); 218 usb_otg_state_string(musb->xceiv->state));
219 219
220 spin_lock_irqsave(&musb->lock, flags); 220 spin_lock_irqsave(&musb->lock, flags);
221 switch (musb->xceiv->state) { 221 switch (musb->xceiv->state) {
@@ -349,7 +349,7 @@ static irqreturn_t davinci_musb_interrupt(int irq, void *__hci)
349 davinci_musb_source_power(musb, drvvbus, 0); 349 davinci_musb_source_power(musb, drvvbus, 0);
350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 350 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
351 drvvbus ? "on" : "off", 351 drvvbus ? "on" : "off",
352 otg_state_string(musb->xceiv->state), 352 usb_otg_state_string(musb->xceiv->state),
353 err ? " ERROR" : "", 353 err ? " ERROR" : "",
354 devctl); 354 devctl);
355 retval = IRQ_HANDLED; 355 retval = IRQ_HANDLED;
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index daec6e0f7e38..37a261a6bb6a 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -372,13 +372,13 @@ static void musb_otg_timer_func(unsigned long data)
372 case OTG_STATE_A_SUSPEND: 372 case OTG_STATE_A_SUSPEND:
373 case OTG_STATE_A_WAIT_BCON: 373 case OTG_STATE_A_WAIT_BCON:
374 dev_dbg(musb->controller, "HNP: %s timeout\n", 374 dev_dbg(musb->controller, "HNP: %s timeout\n",
375 otg_state_string(musb->xceiv->state)); 375 usb_otg_state_string(musb->xceiv->state));
376 musb_platform_set_vbus(musb, 0); 376 musb_platform_set_vbus(musb, 0);
377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; 377 musb->xceiv->state = OTG_STATE_A_WAIT_VFALL;
378 break; 378 break;
379 default: 379 default:
380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n", 380 dev_dbg(musb->controller, "HNP: Unhandled mode %s\n",
381 otg_state_string(musb->xceiv->state)); 381 usb_otg_state_string(musb->xceiv->state));
382 } 382 }
383 musb->ignore_disconnect = 0; 383 musb->ignore_disconnect = 0;
384 spin_unlock_irqrestore(&musb->lock, flags); 384 spin_unlock_irqrestore(&musb->lock, flags);
@@ -393,13 +393,14 @@ void musb_hnp_stop(struct musb *musb)
393 void __iomem *mbase = musb->mregs; 393 void __iomem *mbase = musb->mregs;
394 u8 reg; 394 u8 reg;
395 395
396 dev_dbg(musb->controller, "HNP: stop from %s\n", otg_state_string(musb->xceiv->state)); 396 dev_dbg(musb->controller, "HNP: stop from %s\n",
397 usb_otg_state_string(musb->xceiv->state));
397 398
398 switch (musb->xceiv->state) { 399 switch (musb->xceiv->state) {
399 case OTG_STATE_A_PERIPHERAL: 400 case OTG_STATE_A_PERIPHERAL:
400 musb_g_disconnect(musb); 401 musb_g_disconnect(musb);
401 dev_dbg(musb->controller, "HNP: back to %s\n", 402 dev_dbg(musb->controller, "HNP: back to %s\n",
402 otg_state_string(musb->xceiv->state)); 403 usb_otg_state_string(musb->xceiv->state));
403 break; 404 break;
404 case OTG_STATE_B_HOST: 405 case OTG_STATE_B_HOST:
405 dev_dbg(musb->controller, "HNP: Disabling HR\n"); 406 dev_dbg(musb->controller, "HNP: Disabling HR\n");
@@ -413,7 +414,7 @@ void musb_hnp_stop(struct musb *musb)
413 break; 414 break;
414 default: 415 default:
415 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n", 416 dev_dbg(musb->controller, "HNP: Stopping in unknown state %s\n",
416 otg_state_string(musb->xceiv->state)); 417 usb_otg_state_string(musb->xceiv->state));
417 } 418 }
418 419
419 /* 420 /*
@@ -451,7 +452,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
451 */ 452 */
452 if (int_usb & MUSB_INTR_RESUME) { 453 if (int_usb & MUSB_INTR_RESUME) {
453 handled = IRQ_HANDLED; 454 handled = IRQ_HANDLED;
454 dev_dbg(musb->controller, "RESUME (%s)\n", otg_state_string(musb->xceiv->state)); 455 dev_dbg(musb->controller, "RESUME (%s)\n", usb_otg_state_string(musb->xceiv->state));
455 456
456 if (devctl & MUSB_DEVCTL_HM) { 457 if (devctl & MUSB_DEVCTL_HM) {
457 void __iomem *mbase = musb->mregs; 458 void __iomem *mbase = musb->mregs;
@@ -493,7 +494,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
493 default: 494 default:
494 WARNING("bogus %s RESUME (%s)\n", 495 WARNING("bogus %s RESUME (%s)\n",
495 "host", 496 "host",
496 otg_state_string(musb->xceiv->state)); 497 usb_otg_state_string(musb->xceiv->state));
497 } 498 }
498 } else { 499 } else {
499 switch (musb->xceiv->state) { 500 switch (musb->xceiv->state) {
@@ -522,7 +523,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
522 default: 523 default:
523 WARNING("bogus %s RESUME (%s)\n", 524 WARNING("bogus %s RESUME (%s)\n",
524 "peripheral", 525 "peripheral",
525 otg_state_string(musb->xceiv->state)); 526 usb_otg_state_string(musb->xceiv->state));
526 } 527 }
527 } 528 }
528 } 529 }
@@ -538,7 +539,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
538 } 539 }
539 540
540 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n", 541 dev_dbg(musb->controller, "SESSION_REQUEST (%s)\n",
541 otg_state_string(musb->xceiv->state)); 542 usb_otg_state_string(musb->xceiv->state));
542 543
543 /* IRQ arrives from ID pin sense or (later, if VBUS power 544 /* IRQ arrives from ID pin sense or (later, if VBUS power
544 * is removed) SRP. responses are time critical: 545 * is removed) SRP. responses are time critical:
@@ -602,8 +603,9 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
602 break; 603 break;
603 } 604 }
604 605
605 dev_dbg(musb->controller, "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n", 606 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller,
606 otg_state_string(musb->xceiv->state), 607 "VBUS_ERROR in %s (%02x, %s), retry #%d, port1 %08x\n",
608 usb_otg_state_string(musb->xceiv->state),
607 devctl, 609 devctl,
608 ({ char *s; 610 ({ char *s;
609 switch (devctl & MUSB_DEVCTL_VBUS) { 611 switch (devctl & MUSB_DEVCTL_VBUS) {
@@ -628,7 +630,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb,
628 630
629 if (int_usb & MUSB_INTR_SUSPEND) { 631 if (int_usb & MUSB_INTR_SUSPEND) {
630 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n", 632 dev_dbg(musb->controller, "SUSPEND (%s) devctl %02x\n",
631 otg_state_string(musb->xceiv->state), devctl); 633 usb_otg_state_string(musb->xceiv->state), devctl);
632 handled = IRQ_HANDLED; 634 handled = IRQ_HANDLED;
633 635
634 switch (musb->xceiv->state) { 636 switch (musb->xceiv->state) {
@@ -745,12 +747,12 @@ b_host:
745 usb_hcd_resume_root_hub(hcd); 747 usb_hcd_resume_root_hub(hcd);
746 748
747 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n", 749 dev_dbg(musb->controller, "CONNECT (%s) devctl %02x\n",
748 otg_state_string(musb->xceiv->state), devctl); 750 usb_otg_state_string(musb->xceiv->state), devctl);
749 } 751 }
750 752
751 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) { 753 if ((int_usb & MUSB_INTR_DISCONNECT) && !musb->ignore_disconnect) {
752 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n", 754 dev_dbg(musb->controller, "DISCONNECT (%s) as %s, devctl %02x\n",
753 otg_state_string(musb->xceiv->state), 755 usb_otg_state_string(musb->xceiv->state),
754 MUSB_MODE(musb), devctl); 756 MUSB_MODE(musb), devctl);
755 handled = IRQ_HANDLED; 757 handled = IRQ_HANDLED;
756 758
@@ -787,7 +789,7 @@ b_host:
787 break; 789 break;
788 default: 790 default:
789 WARNING("unhandled DISCONNECT transition (%s)\n", 791 WARNING("unhandled DISCONNECT transition (%s)\n",
790 otg_state_string(musb->xceiv->state)); 792 usb_otg_state_string(musb->xceiv->state));
791 break; 793 break;
792 } 794 }
793 } 795 }
@@ -813,7 +815,7 @@ b_host:
813 } 815 }
814 } else { 816 } else {
815 dev_dbg(musb->controller, "BUS RESET as %s\n", 817 dev_dbg(musb->controller, "BUS RESET as %s\n",
816 otg_state_string(musb->xceiv->state)); 818 usb_otg_state_string(musb->xceiv->state));
817 switch (musb->xceiv->state) { 819 switch (musb->xceiv->state) {
818 case OTG_STATE_A_SUSPEND: 820 case OTG_STATE_A_SUSPEND:
819 /* We need to ignore disconnect on suspend 821 /* We need to ignore disconnect on suspend
@@ -826,7 +828,7 @@ b_host:
826 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ 828 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */
827 /* never use invalid T(a_wait_bcon) */ 829 /* never use invalid T(a_wait_bcon) */
828 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n", 830 dev_dbg(musb->controller, "HNP: in %s, %d msec timeout\n",
829 otg_state_string(musb->xceiv->state), 831 usb_otg_state_string(musb->xceiv->state),
830 TA_WAIT_BCON(musb)); 832 TA_WAIT_BCON(musb));
831 mod_timer(&musb->otg_timer, jiffies 833 mod_timer(&musb->otg_timer, jiffies
832 + msecs_to_jiffies(TA_WAIT_BCON(musb))); 834 + msecs_to_jiffies(TA_WAIT_BCON(musb)));
@@ -838,7 +840,7 @@ b_host:
838 break; 840 break;
839 case OTG_STATE_B_WAIT_ACON: 841 case OTG_STATE_B_WAIT_ACON:
840 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n", 842 dev_dbg(musb->controller, "HNP: RESET (%s), to b_peripheral\n",
841 otg_state_string(musb->xceiv->state)); 843 usb_otg_state_string(musb->xceiv->state));
842 musb->xceiv->state = OTG_STATE_B_PERIPHERAL; 844 musb->xceiv->state = OTG_STATE_B_PERIPHERAL;
843 musb_g_reset(musb); 845 musb_g_reset(musb);
844 break; 846 break;
@@ -850,7 +852,7 @@ b_host:
850 break; 852 break;
851 default: 853 default:
852 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n", 854 dev_dbg(musb->controller, "Unhandled BUS RESET as %s\n",
853 otg_state_string(musb->xceiv->state)); 855 usb_otg_state_string(musb->xceiv->state));
854 } 856 }
855 } 857 }
856 } 858 }
@@ -1632,7 +1634,7 @@ musb_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1632 int ret = -EINVAL; 1634 int ret = -EINVAL;
1633 1635
1634 spin_lock_irqsave(&musb->lock, flags); 1636 spin_lock_irqsave(&musb->lock, flags);
1635 ret = sprintf(buf, "%s\n", otg_state_string(musb->xceiv->state)); 1637 ret = sprintf(buf, "%s\n", usb_otg_state_string(musb->xceiv->state));
1636 spin_unlock_irqrestore(&musb->lock, flags); 1638 spin_unlock_irqrestore(&musb->lock, flags);
1637 1639
1638 return ret; 1640 return ret;
@@ -1951,9 +1953,13 @@ musb_init_controller(struct device *dev, int nIrq, void __iomem *ctrl)
1951 musb_write_ulpi_buscontrol(musb->mregs, busctl); 1953 musb_write_ulpi_buscontrol(musb->mregs, busctl);
1952 } 1954 }
1953 1955
1954 MUSB_DEV_MODE(musb); 1956 if (musb->xceiv->otg->default_a) {
1955 musb->xceiv->otg->default_a = 0; 1957 MUSB_HST_MODE(musb);
1956 musb->xceiv->state = OTG_STATE_B_IDLE; 1958 musb->xceiv->state = OTG_STATE_A_IDLE;
1959 } else {
1960 MUSB_DEV_MODE(musb);
1961 musb->xceiv->state = OTG_STATE_B_IDLE;
1962 }
1957 1963
1958 status = musb_gadget_setup(musb); 1964 status = musb_gadget_setup(musb);
1959 1965
@@ -2008,7 +2014,6 @@ static int musb_probe(struct platform_device *pdev)
2008{ 2014{
2009 struct device *dev = &pdev->dev; 2015 struct device *dev = &pdev->dev;
2010 int irq = platform_get_irq_byname(pdev, "mc"); 2016 int irq = platform_get_irq_byname(pdev, "mc");
2011 int status;
2012 struct resource *iomem; 2017 struct resource *iomem;
2013 void __iomem *base; 2018 void __iomem *base;
2014 2019
@@ -2016,24 +2021,17 @@ static int musb_probe(struct platform_device *pdev)
2016 if (!iomem || irq <= 0) 2021 if (!iomem || irq <= 0)
2017 return -ENODEV; 2022 return -ENODEV;
2018 2023
2019 base = ioremap(iomem->start, resource_size(iomem)); 2024 base = devm_ioremap_resource(dev, iomem);
2020 if (!base) { 2025 if (IS_ERR(base))
2021 dev_err(dev, "ioremap failed\n"); 2026 return PTR_ERR(base);
2022 return -ENOMEM;
2023 }
2024 2027
2025 status = musb_init_controller(dev, irq, base); 2028 return musb_init_controller(dev, irq, base);
2026 if (status < 0)
2027 iounmap(base);
2028
2029 return status;
2030} 2029}
2031 2030
2032static int musb_remove(struct platform_device *pdev) 2031static int musb_remove(struct platform_device *pdev)
2033{ 2032{
2034 struct device *dev = &pdev->dev; 2033 struct device *dev = &pdev->dev;
2035 struct musb *musb = dev_to_musb(dev); 2034 struct musb *musb = dev_to_musb(dev);
2036 void __iomem *ctrl_base = musb->ctrl_base;
2037 2035
2038 /* this gets called on rmmod. 2036 /* this gets called on rmmod.
2039 * - Host mode: host may still be active 2037 * - Host mode: host may still be active
@@ -2044,7 +2042,6 @@ static int musb_remove(struct platform_device *pdev)
2044 musb_shutdown(pdev); 2042 musb_shutdown(pdev);
2045 2043
2046 musb_free(musb); 2044 musb_free(musb);
2047 iounmap(ctrl_base);
2048 device_init_wakeup(dev, 0); 2045 device_init_wakeup(dev, 0);
2049#ifndef CONFIG_MUSB_PIO_ONLY 2046#ifndef CONFIG_MUSB_PIO_ONLY
2050 dma_set_mask(dev, *dev->parent->dma_mask); 2047 dma_set_mask(dev, *dev->parent->dma_mask);
@@ -2293,8 +2290,6 @@ static int __init musb_init(void)
2293 if (usb_disabled()) 2290 if (usb_disabled())
2294 return 0; 2291 return 0;
2295 2292
2296 pr_info("%s: version " MUSB_VERSION ", ?dma?, otg (peripheral+host)\n",
2297 musb_driver_name);
2298 return platform_driver_register(&musb_driver); 2293 return platform_driver_register(&musb_driver);
2299} 2294}
2300module_init(musb_init); 2295module_init(musb_init);
diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 6bb89715b637..3a18e44e9391 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/usb/nop-usb-xceiv.h> 39#include <linux/usb/nop-usb-xceiv.h>
40#include <linux/platform_data/usb-omap.h> 40#include <linux/platform_data/usb-omap.h>
41#include <linux/sizes.h>
41 42
42#include <linux/of.h> 43#include <linux/of.h>
43#include <linux/of_device.h> 44#include <linux/of_device.h>
@@ -224,7 +225,7 @@ static void otg_timer(unsigned long _musb)
224 */ 225 */
225 devctl = dsps_readb(mregs, MUSB_DEVCTL); 226 devctl = dsps_readb(mregs, MUSB_DEVCTL);
226 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, 227 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl,
227 otg_state_string(musb->xceiv->state)); 228 usb_otg_state_string(musb->xceiv->state));
228 229
229 spin_lock_irqsave(&musb->lock, flags); 230 spin_lock_irqsave(&musb->lock, flags);
230 switch (musb->xceiv->state) { 231 switch (musb->xceiv->state) {
@@ -273,7 +274,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
273 if (musb->is_active || (musb->a_wait_bcon == 0 && 274 if (musb->is_active || (musb->a_wait_bcon == 0 &&
274 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { 275 musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) {
275 dev_dbg(musb->controller, "%s active, deleting timer\n", 276 dev_dbg(musb->controller, "%s active, deleting timer\n",
276 otg_state_string(musb->xceiv->state)); 277 usb_otg_state_string(musb->xceiv->state));
277 del_timer(&glue->timer[pdev->id]); 278 del_timer(&glue->timer[pdev->id]);
278 glue->last_timer[pdev->id] = jiffies; 279 glue->last_timer[pdev->id] = jiffies;
279 return; 280 return;
@@ -288,7 +289,7 @@ static void dsps_musb_try_idle(struct musb *musb, unsigned long timeout)
288 glue->last_timer[pdev->id] = timeout; 289 glue->last_timer[pdev->id] = timeout;
289 290
290 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", 291 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n",
291 otg_state_string(musb->xceiv->state), 292 usb_otg_state_string(musb->xceiv->state),
292 jiffies_to_msecs(timeout - jiffies)); 293 jiffies_to_msecs(timeout - jiffies));
293 mod_timer(&glue->timer[pdev->id], timeout); 294 mod_timer(&glue->timer[pdev->id], timeout);
294} 295}
@@ -334,7 +335,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
334 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set. 335 * value but DEVCTL.BDEVICE is invalid without DEVCTL.SESSION set.
335 * Also, DRVVBUS pulses for SRP (but not at 5V) ... 336 * Also, DRVVBUS pulses for SRP (but not at 5V) ...
336 */ 337 */
337 if (usbintr & MUSB_INTR_BABBLE) 338 if (is_host_active(musb) && usbintr & MUSB_INTR_BABBLE)
338 pr_info("CAUTION: musb: Babble Interrupt Occurred\n"); 339 pr_info("CAUTION: musb: Babble Interrupt Occurred\n");
339 340
340 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) { 341 if (usbintr & ((1 << wrp->drvvbus) << wrp->usb_shift)) {
@@ -377,7 +378,7 @@ static irqreturn_t dsps_interrupt(int irq, void *hci)
377 /* NOTE: this must complete power-on within 100 ms. */ 378 /* NOTE: this must complete power-on within 100 ms. */
378 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", 379 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n",
379 drvvbus ? "on" : "off", 380 drvvbus ? "on" : "off",
380 otg_state_string(musb->xceiv->state), 381 usb_otg_state_string(musb->xceiv->state),
381 err ? " ERROR" : "", 382 err ? " ERROR" : "",
382 devctl); 383 devctl);
383 ret = IRQ_HANDLED; 384 ret = IRQ_HANDLED;
@@ -596,14 +597,13 @@ err0:
596 597
597static int dsps_probe(struct platform_device *pdev) 598static int dsps_probe(struct platform_device *pdev)
598{ 599{
599 struct device_node *np = pdev->dev.of_node;
600 const struct of_device_id *match; 600 const struct of_device_id *match;
601 const struct dsps_musb_wrapper *wrp; 601 const struct dsps_musb_wrapper *wrp;
602 struct dsps_glue *glue; 602 struct dsps_glue *glue;
603 struct resource *iomem; 603 struct resource *iomem;
604 int ret, i; 604 int ret, i;
605 605
606 match = of_match_node(musb_dsps_of_match, np); 606 match = of_match_node(musb_dsps_of_match, pdev->dev.of_node);
607 if (!match) { 607 if (!match) {
608 dev_err(&pdev->dev, "fail to get matching of_match struct\n"); 608 dev_err(&pdev->dev, "fail to get matching of_match struct\n");
609 ret = -EINVAL; 609 ret = -EINVAL;
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 83eddedcd9be..ba7092349fa9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -46,48 +46,6 @@
46#include "musb_core.h" 46#include "musb_core.h"
47 47
48 48
49/* MUSB PERIPHERAL status 3-mar-2006:
50 *
51 * - EP0 seems solid. It passes both USBCV and usbtest control cases.
52 * Minor glitches:
53 *
54 * + remote wakeup to Linux hosts work, but saw USBCV failures;
55 * in one test run (operator error?)
56 * + endpoint halt tests -- in both usbtest and usbcv -- seem
57 * to break when dma is enabled ... is something wrongly
58 * clearing SENDSTALL?
59 *
60 * - Mass storage behaved ok when last tested. Network traffic patterns
61 * (with lots of short transfers etc) need retesting; they turn up the
62 * worst cases of the DMA, since short packets are typical but are not
63 * required.
64 *
65 * - TX/IN
66 * + both pio and dma behave in with network and g_zero tests
67 * + no cppi throughput issues other than no-hw-queueing
68 * + failed with FLAT_REG (DaVinci)
69 * + seems to behave with double buffering, PIO -and- CPPI
70 * + with gadgetfs + AIO, requests got lost?
71 *
72 * - RX/OUT
73 * + both pio and dma behave in with network and g_zero tests
74 * + dma is slow in typical case (short_not_ok is clear)
75 * + double buffering ok with PIO
76 * + double buffering *FAILS* with CPPI, wrong data bytes sometimes
77 * + request lossage observed with gadgetfs
78 *
79 * - ISO not tested ... might work, but only weakly isochronous
80 *
81 * - Gadget driver disabling of softconnect during bind() is ignored; so
82 * drivers can't hold off host requests until userspace is ready.
83 * (Workaround: they can turn it off later.)
84 *
85 * - PORTABILITY (assumes PIO works):
86 * + DaVinci, basically works with cppi dma
87 * + OMAP 2430, ditto with mentor dma
88 * + TUSB 6010, platform-specific dma in the works
89 */
90
91/* ----------------------------------------------------------------------- */ 49/* ----------------------------------------------------------------------- */
92 50
93#define is_buffer_mapped(req) (is_dma_capable() && \ 51#define is_buffer_mapped(req) (is_dma_capable() && \
@@ -280,41 +238,6 @@ static inline int max_ep_writesize(struct musb *musb, struct musb_ep *ep)
280 return ep->packet_sz; 238 return ep->packet_sz;
281} 239}
282 240
283
284#ifdef CONFIG_USB_INVENTRA_DMA
285
286/* Peripheral tx (IN) using Mentor DMA works as follows:
287 Only mode 0 is used for transfers <= wPktSize,
288 mode 1 is used for larger transfers,
289
290 One of the following happens:
291 - Host sends IN token which causes an endpoint interrupt
292 -> TxAvail
293 -> if DMA is currently busy, exit.
294 -> if queue is non-empty, txstate().
295
296 - Request is queued by the gadget driver.
297 -> if queue was previously empty, txstate()
298
299 txstate()
300 -> start
301 /\ -> setup DMA
302 | (data is transferred to the FIFO, then sent out when
303 | IN token(s) are recd from Host.
304 | -> DMA interrupt on completion
305 | calls TxAvail.
306 | -> stop DMA, ~DMAENAB,
307 | -> set TxPktRdy for last short pkt or zlp
308 | -> Complete Request
309 | -> Continue next request (call txstate)
310 |___________________________________|
311
312 * Non-Mentor DMA engines can of course work differently, such as by
313 * upleveling from irq-per-packet to irq-per-buffer.
314 */
315
316#endif
317
318/* 241/*
319 * An endpoint is transmitting data. This can be called either from 242 * An endpoint is transmitting data. This can be called either from
320 * the IRQ routine or from ep.queue() to kickstart a request on an 243 * the IRQ routine or from ep.queue() to kickstart a request on an
@@ -621,37 +544,6 @@ void musb_g_tx(struct musb *musb, u8 epnum)
621 544
622/* ------------------------------------------------------------ */ 545/* ------------------------------------------------------------ */
623 546
624#ifdef CONFIG_USB_INVENTRA_DMA
625
626/* Peripheral rx (OUT) using Mentor DMA works as follows:
627 - Only mode 0 is used.
628
629 - Request is queued by the gadget class driver.
630 -> if queue was previously empty, rxstate()
631
632 - Host sends OUT token which causes an endpoint interrupt
633 /\ -> RxReady
634 | -> if request queued, call rxstate
635 | /\ -> setup DMA
636 | | -> DMA interrupt on completion
637 | | -> RxReady
638 | | -> stop DMA
639 | | -> ack the read
640 | | -> if data recd = max expected
641 | | by the request, or host
642 | | sent a short packet,
643 | | complete the request,
644 | | and start the next one.
645 | |_____________________________________|
646 | else just wait for the host
647 | to send the next OUT token.
648 |__________________________________________________|
649
650 * Non-Mentor DMA engines can of course work differently.
651 */
652
653#endif
654
655/* 547/*
656 * Context: controller locked, IRQs blocked, endpoint selected 548 * Context: controller locked, IRQs blocked, endpoint selected
657 */ 549 */
@@ -740,7 +632,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
740 struct dma_controller *c; 632 struct dma_controller *c;
741 struct dma_channel *channel; 633 struct dma_channel *channel;
742 int use_dma = 0; 634 int use_dma = 0;
743 int transfer_size; 635 unsigned int transfer_size;
744 636
745 c = musb->dma_controller; 637 c = musb->dma_controller;
746 channel = musb_ep->dma; 638 channel = musb_ep->dma;
@@ -782,10 +674,11 @@ static void rxstate(struct musb *musb, struct musb_request *req)
782 csr | MUSB_RXCSR_DMAMODE); 674 csr | MUSB_RXCSR_DMAMODE);
783 musb_writew(epio, MUSB_RXCSR, csr); 675 musb_writew(epio, MUSB_RXCSR, csr);
784 676
785 transfer_size = min(request->length - request->actual, 677 transfer_size = min_t(unsigned int,
678 request->length -
679 request->actual,
786 channel->max_len); 680 channel->max_len);
787 musb_ep->dma->desired_mode = 1; 681 musb_ep->dma->desired_mode = 1;
788
789 } else { 682 } else {
790 if (!musb_ep->hb_mult && 683 if (!musb_ep->hb_mult &&
791 musb_ep->hw_ep->rx_double_buffered) 684 musb_ep->hw_ep->rx_double_buffered)
@@ -815,7 +708,7 @@ static void rxstate(struct musb *musb, struct musb_request *req)
815 708
816 struct dma_controller *c; 709 struct dma_controller *c;
817 struct dma_channel *channel; 710 struct dma_channel *channel;
818 int transfer_size = 0; 711 unsigned int transfer_size = 0;
819 712
820 c = musb->dma_controller; 713 c = musb->dma_controller;
821 channel = musb_ep->dma; 714 channel = musb_ep->dma;
@@ -824,11 +717,13 @@ static void rxstate(struct musb *musb, struct musb_request *req)
824 if (fifo_count < musb_ep->packet_sz) 717 if (fifo_count < musb_ep->packet_sz)
825 transfer_size = fifo_count; 718 transfer_size = fifo_count;
826 else if (request->short_not_ok) 719 else if (request->short_not_ok)
827 transfer_size = min(request->length - 720 transfer_size = min_t(unsigned int,
721 request->length -
828 request->actual, 722 request->actual,
829 channel->max_len); 723 channel->max_len);
830 else 724 else
831 transfer_size = min(request->length - 725 transfer_size = min_t(unsigned int,
726 request->length -
832 request->actual, 727 request->actual,
833 (unsigned)fifo_count); 728 (unsigned)fifo_count);
834 729
@@ -1681,7 +1576,7 @@ static int musb_gadget_wakeup(struct usb_gadget *gadget)
1681 goto done; 1576 goto done;
1682 default: 1577 default:
1683 dev_dbg(musb->controller, "Unhandled wake: %s\n", 1578 dev_dbg(musb->controller, "Unhandled wake: %s\n",
1684 otg_state_string(musb->xceiv->state)); 1579 usb_otg_state_string(musb->xceiv->state));
1685 goto done; 1580 goto done;
1686 } 1581 }
1687 1582
@@ -1801,13 +1696,6 @@ static const struct usb_gadget_ops musb_gadget_operations = {
1801 * all peripheral ports are external... 1696 * all peripheral ports are external...
1802 */ 1697 */
1803 1698
1804static void musb_gadget_release(struct device *dev)
1805{
1806 /* kref_put(WHAT) */
1807 dev_dbg(dev, "%s\n", __func__);
1808}
1809
1810
1811static void 1699static void
1812init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in) 1700init_peripheral_ep(struct musb *musb, struct musb_ep *ep, u8 epnum, int is_in)
1813{ 1701{
@@ -1892,12 +1780,7 @@ int musb_gadget_setup(struct musb *musb)
1892 musb->g.speed = USB_SPEED_UNKNOWN; 1780 musb->g.speed = USB_SPEED_UNKNOWN;
1893 1781
1894 /* this "gadget" abstracts/virtualizes the controller */ 1782 /* this "gadget" abstracts/virtualizes the controller */
1895 dev_set_name(&musb->g.dev, "gadget");
1896 musb->g.dev.parent = musb->controller;
1897 musb->g.dev.dma_mask = musb->controller->dma_mask;
1898 musb->g.dev.release = musb_gadget_release;
1899 musb->g.name = musb_driver_name; 1783 musb->g.name = musb_driver_name;
1900
1901 musb->g.is_otg = 1; 1784 musb->g.is_otg = 1;
1902 1785
1903 musb_g_init_endpoints(musb); 1786 musb_g_init_endpoints(musb);
@@ -1905,11 +1788,6 @@ int musb_gadget_setup(struct musb *musb)
1905 musb->is_active = 0; 1788 musb->is_active = 0;
1906 musb_platform_try_idle(musb, 0); 1789 musb_platform_try_idle(musb, 0);
1907 1790
1908 status = device_register(&musb->g.dev);
1909 if (status != 0) {
1910 put_device(&musb->g.dev);
1911 return status;
1912 }
1913 status = usb_add_gadget_udc(musb->controller, &musb->g); 1791 status = usb_add_gadget_udc(musb->controller, &musb->g);
1914 if (status) 1792 if (status)
1915 goto err; 1793 goto err;
@@ -1924,8 +1802,6 @@ err:
1924void musb_gadget_cleanup(struct musb *musb) 1802void musb_gadget_cleanup(struct musb *musb)
1925{ 1803{
1926 usb_del_gadget_udc(&musb->g); 1804 usb_del_gadget_udc(&musb->g);
1927 if (musb->g.dev.parent)
1928 device_unregister(&musb->g.dev);
1929} 1805}
1930 1806
1931/* 1807/*
@@ -1977,9 +1853,8 @@ static int musb_gadget_start(struct usb_gadget *g,
1977 goto err; 1853 goto err;
1978 } 1854 }
1979 1855
1980 if ((musb->xceiv->last_event == USB_EVENT_ID) 1856 if (musb->xceiv->last_event == USB_EVENT_ID)
1981 && otg->set_vbus) 1857 musb_platform_set_vbus(musb, 1);
1982 otg_set_vbus(otg, 1);
1983 1858
1984 hcd->self.uses_pio_for_control = 1; 1859 hcd->self.uses_pio_for_control = 1;
1985 1860
@@ -2063,6 +1938,7 @@ static int musb_gadget_stop(struct usb_gadget *g,
2063 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function); 1938 dev_dbg(musb->controller, "unregistering driver %s\n", driver->function);
2064 1939
2065 musb->is_active = 0; 1940 musb->is_active = 0;
1941 musb->gadget_driver = NULL;
2066 musb_platform_try_idle(musb, 0); 1942 musb_platform_try_idle(musb, 0);
2067 spin_unlock_irqrestore(&musb->lock, flags); 1943 spin_unlock_irqrestore(&musb->lock, flags);
2068 1944
@@ -2099,7 +1975,7 @@ void musb_g_resume(struct musb *musb)
2099 break; 1975 break;
2100 default: 1976 default:
2101 WARNING("unhandled RESUME transition (%s)\n", 1977 WARNING("unhandled RESUME transition (%s)\n",
2102 otg_state_string(musb->xceiv->state)); 1978 usb_otg_state_string(musb->xceiv->state));
2103 } 1979 }
2104} 1980}
2105 1981
@@ -2129,7 +2005,7 @@ void musb_g_suspend(struct musb *musb)
2129 * A_PERIPHERAL may need care too 2005 * A_PERIPHERAL may need care too
2130 */ 2006 */
2131 WARNING("unhandled SUSPEND transition (%s)\n", 2007 WARNING("unhandled SUSPEND transition (%s)\n",
2132 otg_state_string(musb->xceiv->state)); 2008 usb_otg_state_string(musb->xceiv->state));
2133 } 2009 }
2134} 2010}
2135 2011
@@ -2163,7 +2039,7 @@ void musb_g_disconnect(struct musb *musb)
2163 switch (musb->xceiv->state) { 2039 switch (musb->xceiv->state) {
2164 default: 2040 default:
2165 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n", 2041 dev_dbg(musb->controller, "Unhandled disconnect %s, setting a_idle\n",
2166 otg_state_string(musb->xceiv->state)); 2042 usb_otg_state_string(musb->xceiv->state));
2167 musb->xceiv->state = OTG_STATE_A_IDLE; 2043 musb->xceiv->state = OTG_STATE_A_IDLE;
2168 MUSB_HST_MODE(musb); 2044 MUSB_HST_MODE(musb);
2169 break; 2045 break;
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index c9c1ac4e075f..2af45a0c8930 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -505,8 +505,10 @@ static void ep0_rxstate(struct musb *musb)
505 req->status = -EOVERFLOW; 505 req->status = -EOVERFLOW;
506 count = len; 506 count = len;
507 } 507 }
508 musb_read_fifo(&musb->endpoints[0], count, buf); 508 if (count > 0) {
509 req->actual += count; 509 musb_read_fifo(&musb->endpoints[0], count, buf);
510 req->actual += count;
511 }
510 csr = MUSB_CSR0_P_SVDRXPKTRDY; 512 csr = MUSB_CSR0_P_SVDRXPKTRDY;
511 if (count < 64 || req->actual == req->length) { 513 if (count < 64 || req->actual == req->length) {
512 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN; 514 musb->ep0_state = MUSB_EP0_STAGE_STATUSIN;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 1ce1fcf3f3e7..8914dec49f01 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2453,7 +2453,7 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
2453 2453
2454 if (musb->is_active) { 2454 if (musb->is_active) {
2455 WARNING("trying to suspend as %s while active\n", 2455 WARNING("trying to suspend as %s while active\n",
2456 otg_state_string(musb->xceiv->state)); 2456 usb_otg_state_string(musb->xceiv->state));
2457 return -EBUSY; 2457 return -EBUSY;
2458 } else 2458 } else
2459 return 0; 2459 return 0;
@@ -2465,6 +2465,118 @@ static int musb_bus_resume(struct usb_hcd *hcd)
2465 return 0; 2465 return 0;
2466} 2466}
2467 2467
2468
2469#ifndef CONFIG_MUSB_PIO_ONLY
2470
2471#define MUSB_USB_DMA_ALIGN 4
2472
2473struct musb_temp_buffer {
2474 void *kmalloc_ptr;
2475 void *old_xfer_buffer;
2476 u8 data[0];
2477};
2478
2479static void musb_free_temp_buffer(struct urb *urb)
2480{
2481 enum dma_data_direction dir;
2482 struct musb_temp_buffer *temp;
2483
2484 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
2485 return;
2486
2487 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2488
2489 temp = container_of(urb->transfer_buffer, struct musb_temp_buffer,
2490 data);
2491
2492 if (dir == DMA_FROM_DEVICE) {
2493 memcpy(temp->old_xfer_buffer, temp->data,
2494 urb->transfer_buffer_length);
2495 }
2496 urb->transfer_buffer = temp->old_xfer_buffer;
2497 kfree(temp->kmalloc_ptr);
2498
2499 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
2500}
2501
2502static int musb_alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
2503{
2504 enum dma_data_direction dir;
2505 struct musb_temp_buffer *temp;
2506 void *kmalloc_ptr;
2507 size_t kmalloc_size;
2508
2509 if (urb->num_sgs || urb->sg ||
2510 urb->transfer_buffer_length == 0 ||
2511 !((uintptr_t)urb->transfer_buffer & (MUSB_USB_DMA_ALIGN - 1)))
2512 return 0;
2513
2514 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
2515
2516 /* Allocate a buffer with enough padding for alignment */
2517 kmalloc_size = urb->transfer_buffer_length +
2518 sizeof(struct musb_temp_buffer) + MUSB_USB_DMA_ALIGN - 1;
2519
2520 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
2521 if (!kmalloc_ptr)
2522 return -ENOMEM;
2523
2524 /* Position our struct temp_buffer such that data is aligned */
2525 temp = PTR_ALIGN(kmalloc_ptr, MUSB_USB_DMA_ALIGN);
2526
2527
2528 temp->kmalloc_ptr = kmalloc_ptr;
2529 temp->old_xfer_buffer = urb->transfer_buffer;
2530 if (dir == DMA_TO_DEVICE)
2531 memcpy(temp->data, urb->transfer_buffer,
2532 urb->transfer_buffer_length);
2533 urb->transfer_buffer = temp->data;
2534
2535 urb->transfer_flags |= URB_ALIGNED_TEMP_BUFFER;
2536
2537 return 0;
2538}
2539
2540static int musb_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
2541 gfp_t mem_flags)
2542{
2543 struct musb *musb = hcd_to_musb(hcd);
2544 int ret;
2545
2546 /*
2547 * The DMA engine in RTL1.8 and above cannot handle
2548 * DMA addresses that are not aligned to a 4 byte boundary.
2549 * For such engine implemented (un)map_urb_for_dma hooks.
2550 * Do not use these hooks for RTL<1.8
2551 */
2552 if (musb->hwvers < MUSB_HWVERS_1800)
2553 return usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2554
2555 ret = musb_alloc_temp_buffer(urb, mem_flags);
2556 if (ret)
2557 return ret;
2558
2559 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
2560 if (ret)
2561 musb_free_temp_buffer(urb);
2562
2563 return ret;
2564}
2565
2566static void musb_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
2567{
2568 struct musb *musb = hcd_to_musb(hcd);
2569
2570 usb_hcd_unmap_urb_for_dma(hcd, urb);
2571
2572 /* Do not use this hook for RTL<1.8 (see description above) */
2573 if (musb->hwvers < MUSB_HWVERS_1800)
2574 return;
2575
2576 musb_free_temp_buffer(urb);
2577}
2578#endif /* !CONFIG_MUSB_PIO_ONLY */
2579
2468const struct hc_driver musb_hc_driver = { 2580const struct hc_driver musb_hc_driver = {
2469 .description = "musb-hcd", 2581 .description = "musb-hcd",
2470 .product_desc = "MUSB HDRC host driver", 2582 .product_desc = "MUSB HDRC host driver",
@@ -2484,6 +2596,11 @@ const struct hc_driver musb_hc_driver = {
2484 .urb_dequeue = musb_urb_dequeue, 2596 .urb_dequeue = musb_urb_dequeue,
2485 .endpoint_disable = musb_h_disable, 2597 .endpoint_disable = musb_h_disable,
2486 2598
2599#ifndef CONFIG_MUSB_PIO_ONLY
2600 .map_urb_for_dma = musb_map_urb_for_dma,
2601 .unmap_urb_for_dma = musb_unmap_urb_for_dma,
2602#endif
2603
2487 .hub_status_data = musb_hub_status_data, 2604 .hub_status_data = musb_hub_status_data,
2488 .hub_control = musb_hub_control, 2605 .hub_control = musb_hub_control,
2489 .bus_suspend = musb_bus_suspend, 2606 .bus_suspend = musb_bus_suspend,
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index f70579154ded..ef7d11045f56 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -95,7 +95,7 @@ static void musb_port_suspend(struct musb *musb, bool do_suspend)
95 break; 95 break;
96 default: 96 default:
97 dev_dbg(musb->controller, "bogus rh suspend? %s\n", 97 dev_dbg(musb->controller, "bogus rh suspend? %s\n",
98 otg_state_string(musb->xceiv->state)); 98 usb_otg_state_string(musb->xceiv->state));
99 } 99 }
100 } else if (power & MUSB_POWER_SUSPENDM) { 100 } else if (power & MUSB_POWER_SUSPENDM) {
101 power &= ~MUSB_POWER_SUSPENDM; 101 power &= ~MUSB_POWER_SUSPENDM;
@@ -203,7 +203,7 @@ void musb_root_disconnect(struct musb *musb)
203 break; 203 break;
204 default: 204 default:
205 dev_dbg(musb->controller, "host disconnect (%s)\n", 205 dev_dbg(musb->controller, "host disconnect (%s)\n",
206 otg_state_string(musb->xceiv->state)); 206 usb_otg_state_string(musb->xceiv->state));
207 } 207 }
208} 208}
209 209
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 1a42a458f2c4..3551f1a30c65 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -117,7 +117,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
117 if (musb->is_active || ((musb->a_wait_bcon == 0) 117 if (musb->is_active || ((musb->a_wait_bcon == 0)
118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 118 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
119 dev_dbg(musb->controller, "%s active, deleting timer\n", 119 dev_dbg(musb->controller, "%s active, deleting timer\n",
120 otg_state_string(musb->xceiv->state)); 120 usb_otg_state_string(musb->xceiv->state));
121 del_timer(&musb_idle_timer); 121 del_timer(&musb_idle_timer);
122 last_timer = jiffies; 122 last_timer = jiffies;
123 return; 123 return;
@@ -134,7 +134,7 @@ static void omap2430_musb_try_idle(struct musb *musb, unsigned long timeout)
134 last_timer = timeout; 134 last_timer = timeout;
135 135
136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 136 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
137 otg_state_string(musb->xceiv->state), 137 usb_otg_state_string(musb->xceiv->state),
138 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 138 (unsigned long)jiffies_to_msecs(timeout - jiffies));
139 mod_timer(&musb_idle_timer, timeout); 139 mod_timer(&musb_idle_timer, timeout);
140} 140}
@@ -174,8 +174,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
174 } 174 }
175 } 175 }
176 176
177 if (otg->set_vbus) 177 otg_set_vbus(otg, 1);
178 otg_set_vbus(otg, 1);
179 } else { 178 } else {
180 musb->is_active = 1; 179 musb->is_active = 1;
181 otg->default_a = 1; 180 otg->default_a = 1;
@@ -200,7 +199,7 @@ static void omap2430_musb_set_vbus(struct musb *musb, int is_on)
200 199
201 dev_dbg(musb->controller, "VBUS %s, devctl %02x " 200 dev_dbg(musb->controller, "VBUS %s, devctl %02x "
202 /* otg %3x conf %08x prcm %08x */ "\n", 201 /* otg %3x conf %08x prcm %08x */ "\n",
203 otg_state_string(musb->xceiv->state), 202 usb_otg_state_string(musb->xceiv->state),
204 musb_readb(musb->mregs, MUSB_DEVCTL)); 203 musb_readb(musb->mregs, MUSB_DEVCTL));
205} 204}
206 205
@@ -292,14 +291,14 @@ static void omap_musb_set_mailbox(struct omap2430_glue *glue)
292 291
293 musb->xceiv->last_event = USB_EVENT_NONE; 292 musb->xceiv->last_event = USB_EVENT_NONE;
294 if (musb->gadget_driver) { 293 if (musb->gadget_driver) {
294 omap2430_musb_set_vbus(musb, 0);
295 pm_runtime_mark_last_busy(dev); 295 pm_runtime_mark_last_busy(dev);
296 pm_runtime_put_autosuspend(dev); 296 pm_runtime_put_autosuspend(dev);
297 } 297 }
298 298
299 if (data->interface_type == MUSB_INTERFACE_UTMI) { 299 if (data->interface_type == MUSB_INTERFACE_UTMI)
300 if (musb->xceiv->otg->set_vbus) 300 otg_set_vbus(musb->xceiv->otg, 0);
301 otg_set_vbus(musb->xceiv->otg, 0); 301
302 }
303 omap_control_usb_set_mode(glue->control_otghs, 302 omap_control_usb_set_mode(glue->control_otghs,
304 USB_MODE_DISCONNECT); 303 USB_MODE_DISCONNECT);
305 break; 304 break;
@@ -355,7 +354,12 @@ static int omap2430_musb_init(struct musb *musb)
355 else 354 else
356 musb->xceiv = devm_usb_get_phy_dev(dev, 0); 355 musb->xceiv = devm_usb_get_phy_dev(dev, 0);
357 356
358 if (IS_ERR_OR_NULL(musb->xceiv)) { 357 if (IS_ERR(musb->xceiv)) {
358 status = PTR_ERR(musb->xceiv);
359
360 if (status == -ENXIO)
361 return status;
362
359 pr_err("HS USB OTG: no transceiver configured\n"); 363 pr_err("HS USB OTG: no transceiver configured\n");
360 return -EPROBE_DEFER; 364 return -EPROBE_DEFER;
361 } 365 }
@@ -393,6 +397,8 @@ static int omap2430_musb_init(struct musb *musb)
393 if (glue->status != OMAP_MUSB_UNKNOWN) 397 if (glue->status != OMAP_MUSB_UNKNOWN)
394 omap_musb_set_mailbox(glue); 398 omap_musb_set_mailbox(glue);
395 399
400 usb_phy_init(musb->xceiv);
401
396 pm_runtime_put_noidle(musb->controller); 402 pm_runtime_put_noidle(musb->controller);
397 return 0; 403 return 0;
398 404
@@ -526,10 +532,10 @@ static int omap2430_probe(struct platform_device *pdev)
526 } 532 }
527 533
528 of_property_read_u32(np, "mode", (u32 *)&pdata->mode); 534 of_property_read_u32(np, "mode", (u32 *)&pdata->mode);
529 of_property_read_u32(np, "interface_type", 535 of_property_read_u32(np, "interface-type",
530 (u32 *)&data->interface_type); 536 (u32 *)&data->interface_type);
531 of_property_read_u32(np, "num_eps", (u32 *)&config->num_eps); 537 of_property_read_u32(np, "num-eps", (u32 *)&config->num_eps);
532 of_property_read_u32(np, "ram_bits", (u32 *)&config->ram_bits); 538 of_property_read_u32(np, "ram-bits", (u32 *)&config->ram_bits);
533 of_property_read_u32(np, "power", (u32 *)&pdata->power); 539 of_property_read_u32(np, "power", (u32 *)&pdata->power);
534 config->multipoint = of_property_read_bool(np, "multipoint"); 540 config->multipoint = of_property_read_bool(np, "multipoint");
535 pdata->has_mailbox = of_property_read_bool(np, 541 pdata->has_mailbox = of_property_read_bool(np,
diff --git a/drivers/usb/musb/tusb6010.c b/drivers/usb/musb/tusb6010.c
index 464bd23cccda..7369ba33c94f 100644
--- a/drivers/usb/musb/tusb6010.c
+++ b/drivers/usb/musb/tusb6010.c
@@ -423,7 +423,7 @@ static void musb_do_idle(unsigned long _musb)
423 && (musb->idle_timeout == 0 423 && (musb->idle_timeout == 0
424 || time_after(jiffies, musb->idle_timeout))) { 424 || time_after(jiffies, musb->idle_timeout))) {
425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", 425 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n",
426 otg_state_string(musb->xceiv->state)); 426 usb_otg_state_string(musb->xceiv->state));
427 } 427 }
428 /* FALLTHROUGH */ 428 /* FALLTHROUGH */
429 case OTG_STATE_A_IDLE: 429 case OTG_STATE_A_IDLE:
@@ -478,7 +478,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
478 if (musb->is_active || ((musb->a_wait_bcon == 0) 478 if (musb->is_active || ((musb->a_wait_bcon == 0)
479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) { 479 && (musb->xceiv->state == OTG_STATE_A_WAIT_BCON))) {
480 dev_dbg(musb->controller, "%s active, deleting timer\n", 480 dev_dbg(musb->controller, "%s active, deleting timer\n",
481 otg_state_string(musb->xceiv->state)); 481 usb_otg_state_string(musb->xceiv->state));
482 del_timer(&musb_idle_timer); 482 del_timer(&musb_idle_timer);
483 last_timer = jiffies; 483 last_timer = jiffies;
484 return; 484 return;
@@ -495,7 +495,7 @@ static void tusb_musb_try_idle(struct musb *musb, unsigned long timeout)
495 last_timer = timeout; 495 last_timer = timeout;
496 496
497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", 497 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n",
498 otg_state_string(musb->xceiv->state), 498 usb_otg_state_string(musb->xceiv->state),
499 (unsigned long)jiffies_to_msecs(timeout - jiffies)); 499 (unsigned long)jiffies_to_msecs(timeout - jiffies));
500 mod_timer(&musb_idle_timer, timeout); 500 mod_timer(&musb_idle_timer, timeout);
501} 501}
@@ -571,7 +571,7 @@ static void tusb_musb_set_vbus(struct musb *musb, int is_on)
571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); 571 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
572 572
573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", 573 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n",
574 otg_state_string(musb->xceiv->state), 574 usb_otg_state_string(musb->xceiv->state),
575 musb_readb(musb->mregs, MUSB_DEVCTL), 575 musb_readb(musb->mregs, MUSB_DEVCTL),
576 musb_readl(tbase, TUSB_DEV_OTG_STAT), 576 musb_readl(tbase, TUSB_DEV_OTG_STAT),
577 conf, prcm); 577 conf, prcm);
@@ -678,13 +678,13 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
678 musb->is_active = 0; 678 musb->is_active = 0;
679 } 679 }
680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 680 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
681 otg_state_string(musb->xceiv->state), otg_stat); 681 usb_otg_state_string(musb->xceiv->state), otg_stat);
682 idle_timeout = jiffies + (1 * HZ); 682 idle_timeout = jiffies + (1 * HZ);
683 schedule_work(&musb->irq_work); 683 schedule_work(&musb->irq_work);
684 684
685 } else /* A-dev state machine */ { 685 } else /* A-dev state machine */ {
686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", 686 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n",
687 otg_state_string(musb->xceiv->state), otg_stat); 687 usb_otg_state_string(musb->xceiv->state), otg_stat);
688 688
689 switch (musb->xceiv->state) { 689 switch (musb->xceiv->state) {
690 case OTG_STATE_A_IDLE: 690 case OTG_STATE_A_IDLE:
@@ -733,7 +733,7 @@ tusb_otg_ints(struct musb *musb, u32 int_src, void __iomem *tbase)
733 u8 devctl; 733 u8 devctl;
734 734
735 dev_dbg(musb->controller, "%s timer, %03x\n", 735 dev_dbg(musb->controller, "%s timer, %03x\n",
736 otg_state_string(musb->xceiv->state), otg_stat); 736 usb_otg_state_string(musb->xceiv->state), otg_stat);
737 737
738 switch (musb->xceiv->state) { 738 switch (musb->xceiv->state) {
739 case OTG_STATE_A_WAIT_VRISE: 739 case OTG_STATE_A_WAIT_VRISE:
diff --git a/drivers/usb/musb/ux500.c b/drivers/usb/musb/ux500.c
index 13a392913769..2c80004e0a83 100644
--- a/drivers/usb/musb/ux500.c
+++ b/drivers/usb/musb/ux500.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/usb/musb-ux500.h>
29 30
30#include "musb_core.h" 31#include "musb_core.h"
31 32
@@ -36,6 +37,98 @@ struct ux500_glue {
36}; 37};
37#define glue_to_musb(g) platform_get_drvdata(g->musb) 38#define glue_to_musb(g) platform_get_drvdata(g->musb)
38 39
40static void ux500_musb_set_vbus(struct musb *musb, int is_on)
41{
42 u8 devctl;
43 unsigned long timeout = jiffies + msecs_to_jiffies(1000);
44 /* HDRC controls CPEN, but beware current surges during device
45 * connect. They can trigger transient overcurrent conditions
46 * that must be ignored.
47 */
48
49 devctl = musb_readb(musb->mregs, MUSB_DEVCTL);
50
51 if (is_on) {
52 if (musb->xceiv->state == OTG_STATE_A_IDLE) {
53 /* start the session */
54 devctl |= MUSB_DEVCTL_SESSION;
55 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
56 /*
57 * Wait for the musb to set as A device to enable the
58 * VBUS
59 */
60 while (musb_readb(musb->mregs, MUSB_DEVCTL) & 0x80) {
61
62 if (time_after(jiffies, timeout)) {
63 dev_err(musb->controller,
64 "configured as A device timeout");
65 break;
66 }
67 }
68
69 } else {
70 musb->is_active = 1;
71 musb->xceiv->otg->default_a = 1;
72 musb->xceiv->state = OTG_STATE_A_WAIT_VRISE;
73 devctl |= MUSB_DEVCTL_SESSION;
74 MUSB_HST_MODE(musb);
75 }
76 } else {
77 musb->is_active = 0;
78
79 /* NOTE: we're skipping A_WAIT_VFALL -> A_IDLE and jumping
80 * right to B_IDLE...
81 */
82 musb->xceiv->otg->default_a = 0;
83 devctl &= ~MUSB_DEVCTL_SESSION;
84 MUSB_DEV_MODE(musb);
85 }
86 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl);
87
88 /*
89 * Devctl values will be updated after vbus goes below
90 * session_valid. The time taken depends on the capacitance
91 * on VBUS line. The max discharge time can be upto 1 sec
92 * as per the spec. Typically on our platform, it is 200ms
93 */
94 if (!is_on)
95 mdelay(200);
96
97 dev_dbg(musb->controller, "VBUS %s, devctl %02x\n",
98 usb_otg_state_string(musb->xceiv->state),
99 musb_readb(musb->mregs, MUSB_DEVCTL));
100}
101
102static int musb_otg_notifications(struct notifier_block *nb,
103 unsigned long event, void *unused)
104{
105 struct musb *musb = container_of(nb, struct musb, nb);
106
107 dev_dbg(musb->controller, "musb_otg_notifications %ld %s\n",
108 event, usb_otg_state_string(musb->xceiv->state));
109
110 switch (event) {
111 case UX500_MUSB_ID:
112 dev_dbg(musb->controller, "ID GND\n");
113 ux500_musb_set_vbus(musb, 1);
114 break;
115 case UX500_MUSB_VBUS:
116 dev_dbg(musb->controller, "VBUS Connect\n");
117 break;
118 case UX500_MUSB_NONE:
119 dev_dbg(musb->controller, "VBUS Disconnect\n");
120 if (is_host_active(musb))
121 ux500_musb_set_vbus(musb, 0);
122 else
123 musb->xceiv->state = OTG_STATE_B_IDLE;
124 break;
125 default:
126 dev_dbg(musb->controller, "ID float\n");
127 return NOTIFY_DONE;
128 }
129 return NOTIFY_OK;
130}
131
39static irqreturn_t ux500_musb_interrupt(int irq, void *__hci) 132static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
40{ 133{
41 unsigned long flags; 134 unsigned long flags;
@@ -58,12 +151,21 @@ static irqreturn_t ux500_musb_interrupt(int irq, void *__hci)
58 151
59static int ux500_musb_init(struct musb *musb) 152static int ux500_musb_init(struct musb *musb)
60{ 153{
154 int status;
155
61 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 156 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
62 if (IS_ERR_OR_NULL(musb->xceiv)) { 157 if (IS_ERR_OR_NULL(musb->xceiv)) {
63 pr_err("HS USB OTG: no transceiver configured\n"); 158 pr_err("HS USB OTG: no transceiver configured\n");
64 return -EPROBE_DEFER; 159 return -EPROBE_DEFER;
65 } 160 }
66 161
162 musb->nb.notifier_call = musb_otg_notifications;
163 status = usb_register_notifier(musb->xceiv, &musb->nb);
164 if (status < 0) {
165 dev_dbg(musb->controller, "notification register failed\n");
166 return status;
167 }
168
67 musb->isr = ux500_musb_interrupt; 169 musb->isr = ux500_musb_interrupt;
68 170
69 return 0; 171 return 0;
@@ -71,6 +173,8 @@ static int ux500_musb_init(struct musb *musb)
71 173
72static int ux500_musb_exit(struct musb *musb) 174static int ux500_musb_exit(struct musb *musb)
73{ 175{
176 usb_unregister_notifier(musb->xceiv, &musb->nb);
177
74 usb_put_phy(musb->xceiv); 178 usb_put_phy(musb->xceiv);
75 179
76 return 0; 180 return 0;
@@ -79,6 +183,8 @@ static int ux500_musb_exit(struct musb *musb)
79static const struct musb_platform_ops ux500_ops = { 183static const struct musb_platform_ops ux500_ops = {
80 .init = ux500_musb_init, 184 .init = ux500_musb_init,
81 .exit = ux500_musb_exit, 185 .exit = ux500_musb_exit,
186
187 .set_vbus = ux500_musb_set_vbus,
82}; 188};
83 189
84static int ux500_probe(struct platform_device *pdev) 190static int ux500_probe(struct platform_device *pdev)
diff --git a/drivers/usb/musb/ux500_dma.c b/drivers/usb/musb/ux500_dma.c
index 039e567dd3b6..338120641145 100644
--- a/drivers/usb/musb/ux500_dma.c
+++ b/drivers/usb/musb/ux500_dma.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * drivers/usb/musb/ux500_dma.c 2 * drivers/usb/musb/ux500_dma.c
3 * 3 *
4 * U8500 and U5500 DMA support code 4 * U8500 DMA support code
5 * 5 *
6 * Copyright (C) 2009 STMicroelectronics 6 * Copyright (C) 2009 STMicroelectronics
7 * Copyright (C) 2011 ST-Ericsson SA 7 * Copyright (C) 2011 ST-Ericsson SA
@@ -30,6 +30,7 @@
30#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
31#include <linux/dmaengine.h> 31#include <linux/dmaengine.h>
32#include <linux/pfn.h> 32#include <linux/pfn.h>
33#include <linux/sizes.h>
33#include <linux/platform_data/usb-musb-ux500.h> 34#include <linux/platform_data/usb-musb-ux500.h>
34#include "musb_core.h" 35#include "musb_core.h"
35 36
@@ -56,7 +57,7 @@ struct ux500_dma_controller {
56}; 57};
57 58
58/* Work function invoked from DMA callback to handle rx transfers. */ 59/* Work function invoked from DMA callback to handle rx transfers. */
59void ux500_dma_callback(void *private_data) 60static void ux500_dma_callback(void *private_data)
60{ 61{
61 struct dma_channel *channel = private_data; 62 struct dma_channel *channel = private_data;
62 struct ux500_dma_channel *ux500_channel = channel->private_data; 63 struct ux500_dma_channel *ux500_channel = channel->private_data;
@@ -93,8 +94,9 @@ static bool ux500_configure_channel(struct dma_channel *channel,
93 struct musb *musb = ux500_channel->controller->private_data; 94 struct musb *musb = ux500_channel->controller->private_data;
94 95
95 dev_dbg(musb->controller, 96 dev_dbg(musb->controller,
96 "packet_sz=%d, mode=%d, dma_addr=0x%x, len=%d is_tx=%d\n", 97 "packet_sz=%d, mode=%d, dma_addr=0x%llu, len=%d is_tx=%d\n",
97 packet_sz, mode, dma_addr, len, ux500_channel->is_tx); 98 packet_sz, mode, (unsigned long long) dma_addr,
99 len, ux500_channel->is_tx);
98 100
99 ux500_channel->cur_len = len; 101 ux500_channel->cur_len = len;
100 102
@@ -191,7 +193,7 @@ static int ux500_dma_is_compatible(struct dma_channel *channel,
191 u16 maxpacket, void *buf, u32 length) 193 u16 maxpacket, void *buf, u32 length)
192{ 194{
193 if ((maxpacket & 0x3) || 195 if ((maxpacket & 0x3) ||
194 ((int)buf & 0x3) || 196 ((unsigned long int) buf & 0x3) ||
195 (length < 512) || 197 (length < 512) ||
196 (length & 0x3)) 198 (length & 0x3))
197 return false; 199 return false;
@@ -372,12 +374,17 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
372 374
373 controller = kzalloc(sizeof(*controller), GFP_KERNEL); 375 controller = kzalloc(sizeof(*controller), GFP_KERNEL);
374 if (!controller) 376 if (!controller)
375 return NULL; 377 goto kzalloc_fail;
376 378
377 controller->private_data = musb; 379 controller->private_data = musb;
378 380
379 /* Save physical address for DMA controller. */ 381 /* Save physical address for DMA controller. */
380 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 382 iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383 if (!iomem) {
384 dev_err(musb->controller, "no memory resource defined\n");
385 goto plat_get_fail;
386 }
387
381 controller->phy_base = (dma_addr_t) iomem->start; 388 controller->phy_base = (dma_addr_t) iomem->start;
382 389
383 controller->controller.start = ux500_dma_controller_start; 390 controller->controller.start = ux500_dma_controller_start;
@@ -389,4 +396,9 @@ struct dma_controller *dma_controller_create(struct musb *musb, void __iomem *ba
389 controller->controller.is_compatible = ux500_dma_is_compatible; 396 controller->controller.is_compatible = ux500_dma_is_compatible;
390 397
391 return &controller->controller; 398 return &controller->controller;
399
400plat_get_fail:
401 kfree(controller);
402kzalloc_fail:
403 return NULL;
392} 404}
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
deleted file mode 100644
index 37962c99ff1e..000000000000
--- a/drivers/usb/otg/Kconfig
+++ /dev/null
@@ -1,141 +0,0 @@
1#
2# USB OTG infrastructure may be needed for peripheral-only, host-only,
3# or OTG-capable configurations when OTG transceivers or controllers
4# are used.
5#
6
7comment "OTG and related infrastructure"
8
9config USB_OTG_UTILS
10 bool
11 help
12 Select this to make sure the build includes objects from
13 the OTG infrastructure directory.
14
15if USB || USB_GADGET
16
17#
18# USB Transceiver Drivers
19#
20config USB_GPIO_VBUS
21 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
22 depends on GENERIC_GPIO
23 select USB_OTG_UTILS
24 help
25 Provides simple GPIO VBUS sensing for controllers with an
26 internal transceiver via the usb_phy interface, and
27 optionally control of a D+ pullup GPIO as well as a VBUS
28 current limit regulator.
29
30config ISP1301_OMAP
31 tristate "Philips ISP1301 with OMAP OTG"
32 depends on I2C && ARCH_OMAP_OTG
33 select USB_OTG_UTILS
34 help
35 If you say yes here you get support for the Philips ISP1301
36 USB-On-The-Go transceiver working with the OMAP OTG controller.
37 The ISP1301 is a full speed USB transceiver which is used in
38 products including H2, H3, and H4 development boards for Texas
39 Instruments OMAP processors.
40
41 This driver can also be built as a module. If so, the module
42 will be called isp1301_omap.
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
52config USB_ULPI_VIEWPORT
53 bool
54 depends on USB_ULPI
55 help
56 Provides read/write operations to the ULPI phy register set for
57 controllers with a viewport register (e.g. Chipidea/ARC controllers).
58
59config TWL4030_USB
60 tristate "TWL4030 USB Transceiver Driver"
61 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
62 select USB_OTG_UTILS
63 help
64 Enable this to support the USB OTG transceiver on TWL4030
65 family chips (including the TWL5030 and TPS659x0 devices).
66 This transceiver supports high and full speed devices plus,
67 in host mode, low speed.
68
69config TWL6030_USB
70 tristate "TWL6030 USB Transceiver Driver"
71 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
72 select USB_OTG_UTILS
73 help
74 Enable this to support the USB OTG transceiver on TWL6030
75 family chips. This TWL6030 transceiver has the VBUS and ID GND
76 and OTG SRP events capabilities. For all other transceiver functionality
77 UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs
78 are hooked to this driver through platform_data structure.
79 The definition of internal PHY APIs are in the mach-omap2 layer.
80
81config NOP_USB_XCEIV
82 tristate "NOP USB Transceiver Driver"
83 select USB_OTG_UTILS
84 help
85 This driver is to be used by all the usb transceiver which are either
86 built-in with usb ip or which are autonomous and doesn't require any
87 phy programming such as ISP1x04 etc.
88
89config USB_MSM_OTG
90 tristate "OTG support for Qualcomm on-chip USB controller"
91 depends on (USB || USB_GADGET) && ARCH_MSM
92 select USB_OTG_UTILS
93 help
94 Enable this to support the USB OTG transceiver on MSM chips. It
95 handles PHY initialization, clock management, and workarounds
96 required after resetting the hardware and power management.
97 This driver is required even for peripheral only or host only
98 mode configurations.
99 This driver is not supported on boards like trout which
100 has an external PHY.
101
102config AB8500_USB
103 tristate "AB8500 USB Transceiver Driver"
104 depends on AB8500_CORE
105 select USB_OTG_UTILS
106 help
107 Enable this to support the USB OTG transceiver in AB8500 chip.
108 This transceiver supports high and full speed devices plus,
109 in host mode, low speed.
110
111config FSL_USB2_OTG
112 bool "Freescale USB OTG Transceiver Driver"
113 depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND
114 select USB_OTG
115 select USB_OTG_UTILS
116 help
117 Enable this to support Freescale USB OTG transceiver.
118
119config USB_MXS_PHY
120 tristate "Freescale MXS USB PHY support"
121 depends on ARCH_MXC || ARCH_MXS
122 select STMP_DEVICE
123 select USB_OTG_UTILS
124 help
125 Enable this to support the Freescale MXS USB PHY.
126
127 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
128
129config USB_MV_OTG
130 tristate "Marvell USB OTG support"
131 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
132 select USB_OTG
133 select USB_OTG_UTILS
134 help
135 Say Y here if you want to build Marvell USB OTG transciever
136 driver in kernel (including PXA and MMP series). This driver
137 implements role switch between EHCI host driver and gadget driver.
138
139 To compile this driver as a module, choose M here.
140
141endif # USB || OTG
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
deleted file mode 100644
index a844b8d35d14..000000000000
--- a/drivers/usb/otg/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
1#
2# OTG infrastructure and transceiver drivers
3#
4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
7
8# infrastructure
9obj-$(CONFIG_USB_OTG_UTILS) += otg.o
10
11# transceiver drivers
12obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o
13obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
14obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o
15obj-$(CONFIG_TWL6030_USB) += twl6030-usb.o
16obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
17obj-$(CONFIG_USB_ULPI) += ulpi.o
18obj-$(CONFIG_USB_ULPI_VIEWPORT) += ulpi_viewport.o
19obj-$(CONFIG_USB_MSM_OTG) += msm_otg.o
20obj-$(CONFIG_AB8500_USB) += ab8500-usb.o
21fsl_usb2_otg-objs := fsl_otg.o otg_fsm.o
22obj-$(CONFIG_FSL_USB2_OTG) += fsl_usb2_otg.o
23obj-$(CONFIG_USB_MXS_PHY) += mxs-phy.o
24obj-$(CONFIG_USB_MV_OTG) += mv_otg.o
diff --git a/drivers/usb/otg/ab8500-usb.c b/drivers/usb/otg/ab8500-usb.c
deleted file mode 100644
index 2d86f26a0183..000000000000
--- a/drivers/usb/otg/ab8500-usb.c
+++ /dev/null
@@ -1,596 +0,0 @@
1/*
2 * drivers/usb/otg/ab8500_usb.c
3 *
4 * USB transceiver driver for AB8500 chip
5 *
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/usb/otg.h>
28#include <linux/slab.h>
29#include <linux/notifier.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/mfd/abx500.h>
33#include <linux/mfd/abx500/ab8500.h>
34
35#define AB8500_MAIN_WD_CTRL_REG 0x01
36#define AB8500_USB_LINE_STAT_REG 0x80
37#define AB8500_USB_PHY_CTRL_REG 0x8A
38
39#define AB8500_BIT_OTG_STAT_ID (1 << 0)
40#define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
41#define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
42#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
43#define AB8500_BIT_WD_CTRL_KICK (1 << 1)
44
45#define AB8500_V1x_LINK_STAT_WAIT (HZ/10)
46#define AB8500_WD_KICK_DELAY_US 100 /* usec */
47#define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
48#define AB8500_WD_V10_DISABLE_DELAY_MS 100 /* ms */
49
50/* Usb line status register */
51enum ab8500_usb_link_status {
52 USB_LINK_NOT_CONFIGURED = 0,
53 USB_LINK_STD_HOST_NC,
54 USB_LINK_STD_HOST_C_NS,
55 USB_LINK_STD_HOST_C_S,
56 USB_LINK_HOST_CHG_NM,
57 USB_LINK_HOST_CHG_HS,
58 USB_LINK_HOST_CHG_HS_CHIRP,
59 USB_LINK_DEDICATED_CHG,
60 USB_LINK_ACA_RID_A,
61 USB_LINK_ACA_RID_B,
62 USB_LINK_ACA_RID_C_NM,
63 USB_LINK_ACA_RID_C_HS,
64 USB_LINK_ACA_RID_C_HS_CHIRP,
65 USB_LINK_HM_IDGND,
66 USB_LINK_RESERVED,
67 USB_LINK_NOT_VALID_LINK
68};
69
70struct ab8500_usb {
71 struct usb_phy phy;
72 struct device *dev;
73 int irq_num_id_rise;
74 int irq_num_id_fall;
75 int irq_num_vbus_rise;
76 int irq_num_vbus_fall;
77 int irq_num_link_status;
78 unsigned vbus_draw;
79 struct delayed_work dwork;
80 struct work_struct phy_dis_work;
81 unsigned long link_status_wait;
82 int rev;
83};
84
85static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
86{
87 return container_of(x, struct ab8500_usb, phy);
88}
89
90static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
91{
92 abx500_set_register_interruptible(ab->dev,
93 AB8500_SYS_CTRL2_BLOCK,
94 AB8500_MAIN_WD_CTRL_REG,
95 AB8500_BIT_WD_CTRL_ENABLE);
96
97 udelay(AB8500_WD_KICK_DELAY_US);
98
99 abx500_set_register_interruptible(ab->dev,
100 AB8500_SYS_CTRL2_BLOCK,
101 AB8500_MAIN_WD_CTRL_REG,
102 (AB8500_BIT_WD_CTRL_ENABLE
103 | AB8500_BIT_WD_CTRL_KICK));
104
105 if (ab->rev > 0x10) /* v1.1 v2.0 */
106 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
107 else /* v1.0 */
108 msleep(AB8500_WD_V10_DISABLE_DELAY_MS);
109
110 abx500_set_register_interruptible(ab->dev,
111 AB8500_SYS_CTRL2_BLOCK,
112 AB8500_MAIN_WD_CTRL_REG,
113 0);
114}
115
116static void ab8500_usb_phy_ctrl(struct ab8500_usb *ab, bool sel_host,
117 bool enable)
118{
119 u8 ctrl_reg;
120 abx500_get_register_interruptible(ab->dev,
121 AB8500_USB,
122 AB8500_USB_PHY_CTRL_REG,
123 &ctrl_reg);
124 if (sel_host) {
125 if (enable)
126 ctrl_reg |= AB8500_BIT_PHY_CTRL_HOST_EN;
127 else
128 ctrl_reg &= ~AB8500_BIT_PHY_CTRL_HOST_EN;
129 } else {
130 if (enable)
131 ctrl_reg |= AB8500_BIT_PHY_CTRL_DEVICE_EN;
132 else
133 ctrl_reg &= ~AB8500_BIT_PHY_CTRL_DEVICE_EN;
134 }
135
136 abx500_set_register_interruptible(ab->dev,
137 AB8500_USB,
138 AB8500_USB_PHY_CTRL_REG,
139 ctrl_reg);
140
141 /* Needed to enable the phy.*/
142 if (enable)
143 ab8500_usb_wd_workaround(ab);
144}
145
146#define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_ctrl(ab, true, true)
147#define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_ctrl(ab, true, false)
148#define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_ctrl(ab, false, true)
149#define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_ctrl(ab, false, false)
150
151static int ab8500_usb_link_status_update(struct ab8500_usb *ab)
152{
153 u8 reg;
154 enum ab8500_usb_link_status lsts;
155 void *v = NULL;
156 enum usb_phy_events event;
157
158 abx500_get_register_interruptible(ab->dev,
159 AB8500_USB,
160 AB8500_USB_LINE_STAT_REG,
161 &reg);
162
163 lsts = (reg >> 3) & 0x0F;
164
165 switch (lsts) {
166 case USB_LINK_NOT_CONFIGURED:
167 case USB_LINK_RESERVED:
168 case USB_LINK_NOT_VALID_LINK:
169 /* TODO: Disable regulators. */
170 ab8500_usb_host_phy_dis(ab);
171 ab8500_usb_peri_phy_dis(ab);
172 ab->phy.state = OTG_STATE_B_IDLE;
173 ab->phy.otg->default_a = false;
174 ab->vbus_draw = 0;
175 event = USB_EVENT_NONE;
176 break;
177
178 case USB_LINK_STD_HOST_NC:
179 case USB_LINK_STD_HOST_C_NS:
180 case USB_LINK_STD_HOST_C_S:
181 case USB_LINK_HOST_CHG_NM:
182 case USB_LINK_HOST_CHG_HS:
183 case USB_LINK_HOST_CHG_HS_CHIRP:
184 if (ab->phy.otg->gadget) {
185 /* TODO: Enable regulators. */
186 ab8500_usb_peri_phy_en(ab);
187 v = ab->phy.otg->gadget;
188 }
189 event = USB_EVENT_VBUS;
190 break;
191
192 case USB_LINK_HM_IDGND:
193 if (ab->phy.otg->host) {
194 /* TODO: Enable regulators. */
195 ab8500_usb_host_phy_en(ab);
196 v = ab->phy.otg->host;
197 }
198 ab->phy.state = OTG_STATE_A_IDLE;
199 ab->phy.otg->default_a = true;
200 event = USB_EVENT_ID;
201 break;
202
203 case USB_LINK_ACA_RID_A:
204 case USB_LINK_ACA_RID_B:
205 /* TODO */
206 case USB_LINK_ACA_RID_C_NM:
207 case USB_LINK_ACA_RID_C_HS:
208 case USB_LINK_ACA_RID_C_HS_CHIRP:
209 case USB_LINK_DEDICATED_CHG:
210 /* TODO: vbus_draw */
211 event = USB_EVENT_CHARGER;
212 break;
213 }
214
215 atomic_notifier_call_chain(&ab->phy.notifier, event, v);
216
217 return 0;
218}
219
220static void ab8500_usb_delayed_work(struct work_struct *work)
221{
222 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
223 dwork.work);
224
225 ab8500_usb_link_status_update(ab);
226}
227
228static irqreturn_t ab8500_usb_v1x_common_irq(int irq, void *data)
229{
230 struct ab8500_usb *ab = (struct ab8500_usb *) data;
231
232 /* Wait for link status to become stable. */
233 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
234
235 return IRQ_HANDLED;
236}
237
238static irqreturn_t ab8500_usb_v1x_vbus_fall_irq(int irq, void *data)
239{
240 struct ab8500_usb *ab = (struct ab8500_usb *) data;
241
242 /* Link status will not be updated till phy is disabled. */
243 ab8500_usb_peri_phy_dis(ab);
244
245 /* Wait for link status to become stable. */
246 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
247
248 return IRQ_HANDLED;
249}
250
251static irqreturn_t ab8500_usb_v20_irq(int irq, void *data)
252{
253 struct ab8500_usb *ab = (struct ab8500_usb *) data;
254
255 ab8500_usb_link_status_update(ab);
256
257 return IRQ_HANDLED;
258}
259
260static void ab8500_usb_phy_disable_work(struct work_struct *work)
261{
262 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
263 phy_dis_work);
264
265 if (!ab->phy.otg->host)
266 ab8500_usb_host_phy_dis(ab);
267
268 if (!ab->phy.otg->gadget)
269 ab8500_usb_peri_phy_dis(ab);
270}
271
272static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
273{
274 struct ab8500_usb *ab;
275
276 if (!phy)
277 return -ENODEV;
278
279 ab = phy_to_ab(phy);
280
281 ab->vbus_draw = mA;
282
283 if (mA)
284 atomic_notifier_call_chain(&ab->phy.notifier,
285 USB_EVENT_ENUMERATED, ab->phy.otg->gadget);
286 return 0;
287}
288
289/* TODO: Implement some way for charging or other drivers to read
290 * ab->vbus_draw.
291 */
292
293static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
294{
295 /* TODO */
296 return 0;
297}
298
299static int ab8500_usb_set_peripheral(struct usb_otg *otg,
300 struct usb_gadget *gadget)
301{
302 struct ab8500_usb *ab;
303
304 if (!otg)
305 return -ENODEV;
306
307 ab = phy_to_ab(otg->phy);
308
309 /* Some drivers call this function in atomic context.
310 * Do not update ab8500 registers directly till this
311 * is fixed.
312 */
313
314 if (!gadget) {
315 /* TODO: Disable regulators. */
316 otg->gadget = NULL;
317 schedule_work(&ab->phy_dis_work);
318 } else {
319 otg->gadget = gadget;
320 otg->phy->state = OTG_STATE_B_IDLE;
321
322 /* Phy will not be enabled if cable is already
323 * plugged-in. Schedule to enable phy.
324 * Use same delay to avoid any race condition.
325 */
326 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
327 }
328
329 return 0;
330}
331
332static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
333{
334 struct ab8500_usb *ab;
335
336 if (!otg)
337 return -ENODEV;
338
339 ab = phy_to_ab(otg->phy);
340
341 /* Some drivers call this function in atomic context.
342 * Do not update ab8500 registers directly till this
343 * is fixed.
344 */
345
346 if (!host) {
347 /* TODO: Disable regulators. */
348 otg->host = NULL;
349 schedule_work(&ab->phy_dis_work);
350 } else {
351 otg->host = host;
352 /* Phy will not be enabled if cable is already
353 * plugged-in. Schedule to enable phy.
354 * Use same delay to avoid any race condition.
355 */
356 schedule_delayed_work(&ab->dwork, ab->link_status_wait);
357 }
358
359 return 0;
360}
361
362static void ab8500_usb_irq_free(struct ab8500_usb *ab)
363{
364 if (ab->rev < 0x20) {
365 free_irq(ab->irq_num_id_rise, ab);
366 free_irq(ab->irq_num_id_fall, ab);
367 free_irq(ab->irq_num_vbus_rise, ab);
368 free_irq(ab->irq_num_vbus_fall, ab);
369 } else {
370 free_irq(ab->irq_num_link_status, ab);
371 }
372}
373
374static int ab8500_usb_v1x_res_setup(struct platform_device *pdev,
375 struct ab8500_usb *ab)
376{
377 int err;
378
379 ab->irq_num_id_rise = platform_get_irq_byname(pdev, "ID_WAKEUP_R");
380 if (ab->irq_num_id_rise < 0) {
381 dev_err(&pdev->dev, "ID rise irq not found\n");
382 return ab->irq_num_id_rise;
383 }
384 err = request_threaded_irq(ab->irq_num_id_rise, NULL,
385 ab8500_usb_v1x_common_irq,
386 IRQF_NO_SUSPEND | IRQF_SHARED,
387 "usb-id-rise", ab);
388 if (err < 0) {
389 dev_err(ab->dev, "request_irq failed for ID rise irq\n");
390 goto fail0;
391 }
392
393 ab->irq_num_id_fall = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
394 if (ab->irq_num_id_fall < 0) {
395 dev_err(&pdev->dev, "ID fall irq not found\n");
396 return ab->irq_num_id_fall;
397 }
398 err = request_threaded_irq(ab->irq_num_id_fall, NULL,
399 ab8500_usb_v1x_common_irq,
400 IRQF_NO_SUSPEND | IRQF_SHARED,
401 "usb-id-fall", ab);
402 if (err < 0) {
403 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
404 goto fail1;
405 }
406
407 ab->irq_num_vbus_rise = platform_get_irq_byname(pdev, "VBUS_DET_R");
408 if (ab->irq_num_vbus_rise < 0) {
409 dev_err(&pdev->dev, "VBUS rise irq not found\n");
410 return ab->irq_num_vbus_rise;
411 }
412 err = request_threaded_irq(ab->irq_num_vbus_rise, NULL,
413 ab8500_usb_v1x_common_irq,
414 IRQF_NO_SUSPEND | IRQF_SHARED,
415 "usb-vbus-rise", ab);
416 if (err < 0) {
417 dev_err(ab->dev, "request_irq failed for Vbus rise irq\n");
418 goto fail2;
419 }
420
421 ab->irq_num_vbus_fall = platform_get_irq_byname(pdev, "VBUS_DET_F");
422 if (ab->irq_num_vbus_fall < 0) {
423 dev_err(&pdev->dev, "VBUS fall irq not found\n");
424 return ab->irq_num_vbus_fall;
425 }
426 err = request_threaded_irq(ab->irq_num_vbus_fall, NULL,
427 ab8500_usb_v1x_vbus_fall_irq,
428 IRQF_NO_SUSPEND | IRQF_SHARED,
429 "usb-vbus-fall", ab);
430 if (err < 0) {
431 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
432 goto fail3;
433 }
434
435 return 0;
436fail3:
437 free_irq(ab->irq_num_vbus_rise, ab);
438fail2:
439 free_irq(ab->irq_num_id_fall, ab);
440fail1:
441 free_irq(ab->irq_num_id_rise, ab);
442fail0:
443 return err;
444}
445
446static int ab8500_usb_v2_res_setup(struct platform_device *pdev,
447 struct ab8500_usb *ab)
448{
449 int err;
450
451 ab->irq_num_link_status = platform_get_irq_byname(pdev,
452 "USB_LINK_STATUS");
453 if (ab->irq_num_link_status < 0) {
454 dev_err(&pdev->dev, "Link status irq not found\n");
455 return ab->irq_num_link_status;
456 }
457
458 err = request_threaded_irq(ab->irq_num_link_status, NULL,
459 ab8500_usb_v20_irq,
460 IRQF_NO_SUSPEND | IRQF_SHARED,
461 "usb-link-status", ab);
462 if (err < 0) {
463 dev_err(ab->dev,
464 "request_irq failed for link status irq\n");
465 return err;
466 }
467
468 return 0;
469}
470
471static int ab8500_usb_probe(struct platform_device *pdev)
472{
473 struct ab8500_usb *ab;
474 struct usb_otg *otg;
475 int err;
476 int rev;
477
478 rev = abx500_get_chip_id(&pdev->dev);
479 if (rev < 0) {
480 dev_err(&pdev->dev, "Chip id read failed\n");
481 return rev;
482 } else if (rev < 0x10) {
483 dev_err(&pdev->dev, "Unsupported AB8500 chip\n");
484 return -ENODEV;
485 }
486
487 ab = kzalloc(sizeof *ab, GFP_KERNEL);
488 if (!ab)
489 return -ENOMEM;
490
491 otg = kzalloc(sizeof *otg, GFP_KERNEL);
492 if (!otg) {
493 kfree(ab);
494 return -ENOMEM;
495 }
496
497 ab->dev = &pdev->dev;
498 ab->rev = rev;
499 ab->phy.dev = ab->dev;
500 ab->phy.otg = otg;
501 ab->phy.label = "ab8500";
502 ab->phy.set_suspend = ab8500_usb_set_suspend;
503 ab->phy.set_power = ab8500_usb_set_power;
504 ab->phy.state = OTG_STATE_UNDEFINED;
505
506 otg->phy = &ab->phy;
507 otg->set_host = ab8500_usb_set_host;
508 otg->set_peripheral = ab8500_usb_set_peripheral;
509
510 platform_set_drvdata(pdev, ab);
511
512 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
513
514 /* v1: Wait for link status to become stable.
515 * all: Updates form set_host and set_peripheral as they are atomic.
516 */
517 INIT_DELAYED_WORK(&ab->dwork, ab8500_usb_delayed_work);
518
519 /* all: Disable phy when called from set_host and set_peripheral */
520 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
521
522 if (ab->rev < 0x20) {
523 err = ab8500_usb_v1x_res_setup(pdev, ab);
524 ab->link_status_wait = AB8500_V1x_LINK_STAT_WAIT;
525 } else {
526 err = ab8500_usb_v2_res_setup(pdev, ab);
527 }
528
529 if (err < 0)
530 goto fail0;
531
532 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
533 if (err) {
534 dev_err(&pdev->dev, "Can't register transceiver\n");
535 goto fail1;
536 }
537
538 dev_info(&pdev->dev, "AB8500 usb driver initialized\n");
539
540 return 0;
541fail1:
542 ab8500_usb_irq_free(ab);
543fail0:
544 kfree(otg);
545 kfree(ab);
546 return err;
547}
548
549static int ab8500_usb_remove(struct platform_device *pdev)
550{
551 struct ab8500_usb *ab = platform_get_drvdata(pdev);
552
553 ab8500_usb_irq_free(ab);
554
555 cancel_delayed_work_sync(&ab->dwork);
556
557 cancel_work_sync(&ab->phy_dis_work);
558
559 usb_remove_phy(&ab->phy);
560
561 ab8500_usb_host_phy_dis(ab);
562 ab8500_usb_peri_phy_dis(ab);
563
564 platform_set_drvdata(pdev, NULL);
565
566 kfree(ab->phy.otg);
567 kfree(ab);
568
569 return 0;
570}
571
572static struct platform_driver ab8500_usb_driver = {
573 .probe = ab8500_usb_probe,
574 .remove = ab8500_usb_remove,
575 .driver = {
576 .name = "ab8500-usb",
577 .owner = THIS_MODULE,
578 },
579};
580
581static int __init ab8500_usb_init(void)
582{
583 return platform_driver_register(&ab8500_usb_driver);
584}
585subsys_initcall(ab8500_usb_init);
586
587static void __exit ab8500_usb_exit(void)
588{
589 platform_driver_unregister(&ab8500_usb_driver);
590}
591module_exit(ab8500_usb_exit);
592
593MODULE_ALIAS("platform:ab8500_usb");
594MODULE_AUTHOR("ST-Ericsson AB");
595MODULE_DESCRIPTION("AB8500 usb transceiver driver");
596MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 90549382eba5..aab2ab2fbc90 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -1,13 +1,74 @@
1# 1#
2# Physical Layer USB driver configuration 2# Physical Layer USB driver configuration
3# 3#
4comment "USB Physical Layer drivers" 4menuconfig USB_PHY
5 depends on USB || USB_GADGET 5 bool "USB Physical Layer drivers"
6 help
7 USB controllers (those which are host, device or DRD) need a
8 device to handle the physical layer signalling, commonly called
9 a PHY.
10
11 The following drivers add support for such PHY devices.
12
13if USB_PHY
14
15#
16# USB Transceiver Drivers
17#
18config AB8500_USB
19 tristate "AB8500 USB Transceiver Driver"
20 depends on AB8500_CORE
21 help
22 Enable this to support the USB OTG transceiver in AB8500 chip.
23 This transceiver supports high and full speed devices plus,
24 in host mode, low speed.
25
26config FSL_USB2_OTG
27 bool "Freescale USB OTG Transceiver Driver"
28 depends on USB_EHCI_FSL && USB_FSL_USB2 && USB_SUSPEND
29 select USB_OTG
30 help
31 Enable this to support Freescale USB OTG transceiver.
32
33config ISP1301_OMAP
34 tristate "Philips ISP1301 with OMAP OTG"
35 depends on I2C && ARCH_OMAP_OTG
36 help
37 If you say yes here you get support for the Philips ISP1301
38 USB-On-The-Go transceiver working with the OMAP OTG controller.
39 The ISP1301 is a full speed USB transceiver which is used in
40 products including H2, H3, and H4 development boards for Texas
41 Instruments OMAP processors.
42
43 This driver can also be built as a module. If so, the module
44 will be called isp1301_omap.
45
46config MV_U3D_PHY
47 bool "Marvell USB 3.0 PHY controller Driver"
48 depends on CPU_MMP3
49 help
50 Enable this to support Marvell USB 3.0 phy controller for Marvell
51 SoC.
52
53config NOP_USB_XCEIV
54 tristate "NOP USB Transceiver Driver"
55 help
56 This driver is to be used by all the usb transceiver which are either
57 built-in with usb ip or which are autonomous and doesn't require any
58 phy programming such as ISP1x04 etc.
59
60config OMAP_CONTROL_USB
61 tristate "OMAP CONTROL USB Driver"
62 help
63 Enable this to add support for the USB part present in the control
64 module. This driver has API to power on the USB2 PHY and to write to
65 the mailbox. The mailbox is present only in omap4 and the register to
66 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an
67 additional register to power on USB3 PHY.
6 68
7config OMAP_USB2 69config OMAP_USB2
8 tristate "OMAP USB2 PHY Driver" 70 tristate "OMAP USB2 PHY Driver"
9 depends on ARCH_OMAP2PLUS 71 depends on ARCH_OMAP2PLUS
10 select USB_OTG_UTILS
11 select OMAP_CONTROL_USB 72 select OMAP_CONTROL_USB
12 help 73 help
13 Enable this to support the transceiver that is part of SOC. This 74 Enable this to support the transceiver that is part of SOC. This
@@ -17,7 +78,6 @@ config OMAP_USB2
17 78
18config OMAP_USB3 79config OMAP_USB3
19 tristate "OMAP USB3 PHY Driver" 80 tristate "OMAP USB3 PHY Driver"
20 select USB_OTG_UTILS
21 select OMAP_CONTROL_USB 81 select OMAP_CONTROL_USB
22 help 82 help
23 Enable this to support the USB3 PHY that is part of SOC. This 83 Enable this to support the USB3 PHY that is part of SOC. This
@@ -25,14 +85,55 @@ config OMAP_USB3
25 This driver interacts with the "OMAP Control USB Driver" to power 85 This driver interacts with the "OMAP Control USB Driver" to power
26 on/off the PHY. 86 on/off the PHY.
27 87
28config OMAP_CONTROL_USB 88config SAMSUNG_USBPHY
29 tristate "OMAP CONTROL USB Driver" 89 tristate "Samsung USB PHY Driver"
30 help 90 help
31 Enable this to add support for the USB part present in the control 91 Enable this to support Samsung USB phy helper driver for Samsung SoCs.
32 module. This driver has API to power on the USB2 PHY and to write to 92 This driver provides common interface to interact, for Samsung USB 2.0 PHY
33 the mailbox. The mailbox is present only in omap4 and the register to 93 driver and later for Samsung USB 3.0 PHY driver.
34 power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 has an 94
35 additional register to power on USB3 PHY. 95config SAMSUNG_USB2PHY
96 tristate "Samsung USB 2.0 PHY controller Driver"
97 select SAMSUNG_USBPHY
98 help
99 Enable this to support Samsung USB 2.0 (High Speed) PHY controller
100 driver for Samsung SoCs.
101
102config SAMSUNG_USB3PHY
103 tristate "Samsung USB 3.0 PHY controller Driver"
104 select SAMSUNG_USBPHY
105 help
106 Enable this to support Samsung USB 3.0 (Super Speed) phy controller
107 for samsung SoCs.
108
109config TWL4030_USB
110 tristate "TWL4030 USB Transceiver Driver"
111 depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
112 help
113 Enable this to support the USB OTG transceiver on TWL4030
114 family chips (including the TWL5030 and TPS659x0 devices).
115 This transceiver supports high and full speed devices plus,
116 in host mode, low speed.
117
118config TWL6030_USB
119 tristate "TWL6030 USB Transceiver Driver"
120 depends on TWL4030_CORE && OMAP_USB2 && USB_MUSB_OMAP2PLUS
121 help
122 Enable this to support the USB OTG transceiver on TWL6030
123 family chips. This TWL6030 transceiver has the VBUS and ID GND
124 and OTG SRP events capabilities. For all other transceiver functionality
125 UTMI PHY is embedded in OMAP4430. The internal PHY configurations APIs
126 are hooked to this driver through platform_data structure.
127 The definition of internal PHY APIs are in the mach-omap2 layer.
128
129config USB_GPIO_VBUS
130 tristate "GPIO based peripheral-only VBUS sensing 'transceiver'"
131 depends on GENERIC_GPIO
132 help
133 Provides simple GPIO VBUS sensing for controllers with an
134 internal transceiver via the usb_phy interface, and
135 optionally control of a D+ pullup GPIO as well as a VBUS
136 current limit regulator.
36 137
37config USB_ISP1301 138config USB_ISP1301
38 tristate "NXP ISP1301 USB transceiver support" 139 tristate "NXP ISP1301 USB transceiver support"
@@ -47,18 +148,41 @@ config USB_ISP1301
47 To compile this driver as a module, choose M here: the 148 To compile this driver as a module, choose M here: the
48 module will be called isp1301. 149 module will be called isp1301.
49 150
50config MV_U3D_PHY 151config USB_MSM_OTG
51 bool "Marvell USB 3.0 PHY controller Driver" 152 tristate "OTG support for Qualcomm on-chip USB controller"
52 depends on USB_MV_U3D 153 depends on (USB || USB_GADGET) && ARCH_MSM
53 select USB_OTG_UTILS
54 help 154 help
55 Enable this to support Marvell USB 3.0 phy controller for Marvell 155 Enable this to support the USB OTG transceiver on MSM chips. It
56 SoC. 156 handles PHY initialization, clock management, and workarounds
157 required after resetting the hardware and power management.
158 This driver is required even for peripheral only or host only
159 mode configurations.
160 This driver is not supported on boards like trout which
161 has an external PHY.
162
163config USB_MV_OTG
164 tristate "Marvell USB OTG support"
165 depends on USB_EHCI_MV && USB_MV_UDC && USB_SUSPEND
166 select USB_OTG
167 help
168 Say Y here if you want to build Marvell USB OTG transciever
169 driver in kernel (including PXA and MMP series). This driver
170 implements role switch between EHCI host driver and gadget driver.
171
172 To compile this driver as a module, choose M here.
173
174config USB_MXS_PHY
175 tristate "Freescale MXS USB PHY support"
176 depends on ARCH_MXC || ARCH_MXS
177 select STMP_DEVICE
178 help
179 Enable this to support the Freescale MXS USB PHY.
180
181 MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
57 182
58config USB_RCAR_PHY 183config USB_RCAR_PHY
59 tristate "Renesas R-Car USB phy support" 184 tristate "Renesas R-Car USB phy support"
60 depends on USB || USB_GADGET 185 depends on USB || USB_GADGET
61 select USB_OTG_UTILS
62 help 186 help
63 Say Y here to add support for the Renesas R-Car USB phy driver. 187 Say Y here to add support for the Renesas R-Car USB phy driver.
64 This chip is typically used as USB phy for USB host, gadget. 188 This chip is typically used as USB phy for USB host, gadget.
@@ -67,10 +191,18 @@ config USB_RCAR_PHY
67 To compile this driver as a module, choose M here: the 191 To compile this driver as a module, choose M here: the
68 module will be called rcar-phy. 192 module will be called rcar-phy.
69 193
70config SAMSUNG_USBPHY 194config USB_ULPI
71 bool "Samsung USB PHY controller Driver" 195 bool "Generic ULPI Transceiver Driver"
72 depends on USB_S3C_HSOTG || USB_EHCI_S5P || USB_OHCI_EXYNOS 196 depends on ARM
73 select USB_OTG_UTILS 197 help
198 Enable this to support ULPI connected USB OTG transceivers which
199 are likely found on embedded boards.
200
201config USB_ULPI_VIEWPORT
202 bool
203 depends on USB_ULPI
74 help 204 help
75 Enable this to support Samsung USB phy controller for samsung 205 Provides read/write operations to the ULPI phy register set for
76 SoCs. 206 controllers with a viewport register (e.g. Chipidea/ARC controllers).
207
208endif # USB_PHY
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index b13faa193e0c..a9169cb1e6fc 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -4,11 +4,30 @@
4 4
5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG 5ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
6 6
7obj-$(CONFIG_OMAP_USB2) += omap-usb2.o 7obj-$(CONFIG_USB_PHY) += phy.o
8obj-$(CONFIG_OMAP_USB3) += omap-usb3.o 8
9obj-$(CONFIG_OMAP_CONTROL_USB) += omap-control-usb.o 9# transceiver drivers, keep the list sorted
10obj-$(CONFIG_USB_ISP1301) += isp1301.o 10
11obj-$(CONFIG_MV_U3D_PHY) += mv_u3d_phy.o 11obj-$(CONFIG_AB8500_USB) += phy-ab8500-usb.o
12obj-$(CONFIG_USB_EHCI_TEGRA) += tegra_usb_phy.o 12phy-fsl-usb2-objs := phy-fsl-usb.o phy-fsm-usb.o
13obj-$(CONFIG_USB_RCAR_PHY) += rcar-phy.o 13obj-$(CONFIG_FSL_USB2_OTG) += phy-fsl-usb2.o
14obj-$(CONFIG_SAMSUNG_USBPHY) += samsung-usbphy.o 14obj-$(CONFIG_ISP1301_OMAP) += phy-isp1301-omap.o
15obj-$(CONFIG_MV_U3D_PHY) += phy-mv-u3d-usb.o
16obj-$(CONFIG_NOP_USB_XCEIV) += phy-nop.o
17obj-$(CONFIG_OMAP_CONTROL_USB) += phy-omap-control.o
18obj-$(CONFIG_OMAP_USB2) += phy-omap-usb2.o
19obj-$(CONFIG_OMAP_USB3) += phy-omap-usb3.o
20obj-$(CONFIG_SAMSUNG_USBPHY) += phy-samsung-usb.o
21obj-$(CONFIG_SAMSUNG_USB2PHY) += phy-samsung-usb2.o
22obj-$(CONFIG_SAMSUNG_USB3PHY) += phy-samsung-usb3.o
23obj-$(CONFIG_TWL4030_USB) += phy-twl4030-usb.o
24obj-$(CONFIG_TWL6030_USB) += phy-twl6030-usb.o
25obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
26obj-$(CONFIG_USB_GPIO_VBUS) += phy-gpio-vbus-usb.o
27obj-$(CONFIG_USB_ISP1301) += phy-isp1301.o
28obj-$(CONFIG_USB_MSM_OTG) += phy-msm-usb.o
29obj-$(CONFIG_USB_MV_OTG) += phy-mv-usb.o
30obj-$(CONFIG_USB_MXS_PHY) += phy-mxs-usb.o
31obj-$(CONFIG_USB_RCAR_PHY) += phy-rcar-usb.o
32obj-$(CONFIG_USB_ULPI) += phy-ulpi.o
33obj-$(CONFIG_USB_ULPI_VIEWPORT) += phy-ulpi-viewport.o
diff --git a/drivers/usb/phy/isp1301.c b/drivers/usb/phy/isp1301.c
deleted file mode 100644
index 18dbf7e37607..000000000000
--- a/drivers/usb/phy/isp1301.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * NXP ISP1301 USB transceiver driver
3 *
4 * Copyright (C) 2012 Roland Stigge
5 *
6 * Author: Roland Stigge <stigge@antcom.de>
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 version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/i2c.h>
15
16#define DRV_NAME "isp1301"
17
18static const struct i2c_device_id isp1301_id[] = {
19 { "isp1301", 0 },
20 { }
21};
22
23static struct i2c_client *isp1301_i2c_client;
24
25static int isp1301_probe(struct i2c_client *client,
26 const struct i2c_device_id *i2c_id)
27{
28 isp1301_i2c_client = client;
29 return 0;
30}
31
32static int isp1301_remove(struct i2c_client *client)
33{
34 return 0;
35}
36
37static struct i2c_driver isp1301_driver = {
38 .driver = {
39 .name = DRV_NAME,
40 },
41 .probe = isp1301_probe,
42 .remove = isp1301_remove,
43 .id_table = isp1301_id,
44};
45
46module_i2c_driver(isp1301_driver);
47
48static int match(struct device *dev, void *data)
49{
50 struct device_node *node = (struct device_node *)data;
51 return (dev->of_node == node) &&
52 (dev->driver == &isp1301_driver.driver);
53}
54
55struct i2c_client *isp1301_get_client(struct device_node *node)
56{
57 if (node) { /* reference of ISP1301 I2C node via DT */
58 struct device *dev = bus_find_device(&i2c_bus_type, NULL,
59 node, match);
60 if (!dev)
61 return NULL;
62 return to_i2c_client(dev);
63 } else { /* non-DT: only one ISP1301 chip supported */
64 return isp1301_i2c_client;
65 }
66}
67EXPORT_SYMBOL_GPL(isp1301_get_client);
68
69MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
70MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
71MODULE_LICENSE("GPL");
diff --git a/drivers/usb/phy/phy-ab8500-usb.c b/drivers/usb/phy/phy-ab8500-usb.c
new file mode 100644
index 000000000000..4acef26a2ef5
--- /dev/null
+++ b/drivers/usb/phy/phy-ab8500-usb.c
@@ -0,0 +1,924 @@
1/*
2 * drivers/usb/otg/ab8500_usb.c
3 *
4 * USB transceiver driver for AB8500 chip
5 *
6 * Copyright (C) 2010 ST-Ericsson AB
7 * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/usb/otg.h>
28#include <linux/slab.h>
29#include <linux/notifier.h>
30#include <linux/interrupt.h>
31#include <linux/delay.h>
32#include <linux/mfd/abx500.h>
33#include <linux/mfd/abx500/ab8500.h>
34#include <linux/usb/musb-ux500.h>
35#include <linux/regulator/consumer.h>
36#include <linux/pinctrl/consumer.h>
37
38/* Bank AB8500_SYS_CTRL2_BLOCK */
39#define AB8500_MAIN_WD_CTRL_REG 0x01
40
41/* Bank AB8500_USB */
42#define AB8500_USB_LINE_STAT_REG 0x80
43#define AB8505_USB_LINE_STAT_REG 0x94
44#define AB8500_USB_PHY_CTRL_REG 0x8A
45
46/* Bank AB8500_DEVELOPMENT */
47#define AB8500_BANK12_ACCESS 0x00
48
49/* Bank AB8500_DEBUG */
50#define AB8500_USB_PHY_TUNE1 0x05
51#define AB8500_USB_PHY_TUNE2 0x06
52#define AB8500_USB_PHY_TUNE3 0x07
53
54#define AB8500_BIT_OTG_STAT_ID (1 << 0)
55#define AB8500_BIT_PHY_CTRL_HOST_EN (1 << 0)
56#define AB8500_BIT_PHY_CTRL_DEVICE_EN (1 << 1)
57#define AB8500_BIT_WD_CTRL_ENABLE (1 << 0)
58#define AB8500_BIT_WD_CTRL_KICK (1 << 1)
59
60#define AB8500_WD_KICK_DELAY_US 100 /* usec */
61#define AB8500_WD_V11_DISABLE_DELAY_US 100 /* usec */
62#define AB8500_V20_31952_DISABLE_DELAY_US 100 /* usec */
63
64/* Usb line status register */
65enum ab8500_usb_link_status {
66 USB_LINK_NOT_CONFIGURED_8500 = 0,
67 USB_LINK_STD_HOST_NC_8500,
68 USB_LINK_STD_HOST_C_NS_8500,
69 USB_LINK_STD_HOST_C_S_8500,
70 USB_LINK_HOST_CHG_NM_8500,
71 USB_LINK_HOST_CHG_HS_8500,
72 USB_LINK_HOST_CHG_HS_CHIRP_8500,
73 USB_LINK_DEDICATED_CHG_8500,
74 USB_LINK_ACA_RID_A_8500,
75 USB_LINK_ACA_RID_B_8500,
76 USB_LINK_ACA_RID_C_NM_8500,
77 USB_LINK_ACA_RID_C_HS_8500,
78 USB_LINK_ACA_RID_C_HS_CHIRP_8500,
79 USB_LINK_HM_IDGND_8500,
80 USB_LINK_RESERVED_8500,
81 USB_LINK_NOT_VALID_LINK_8500,
82};
83
84enum ab8505_usb_link_status {
85 USB_LINK_NOT_CONFIGURED_8505 = 0,
86 USB_LINK_STD_HOST_NC_8505,
87 USB_LINK_STD_HOST_C_NS_8505,
88 USB_LINK_STD_HOST_C_S_8505,
89 USB_LINK_CDP_8505,
90 USB_LINK_RESERVED0_8505,
91 USB_LINK_RESERVED1_8505,
92 USB_LINK_DEDICATED_CHG_8505,
93 USB_LINK_ACA_RID_A_8505,
94 USB_LINK_ACA_RID_B_8505,
95 USB_LINK_ACA_RID_C_NM_8505,
96 USB_LINK_RESERVED2_8505,
97 USB_LINK_RESERVED3_8505,
98 USB_LINK_HM_IDGND_8505,
99 USB_LINK_CHARGERPORT_NOT_OK_8505,
100 USB_LINK_CHARGER_DM_HIGH_8505,
101 USB_LINK_PHYEN_NO_VBUS_NO_IDGND_8505,
102 USB_LINK_STD_UPSTREAM_NO_IDGNG_NO_VBUS_8505,
103 USB_LINK_STD_UPSTREAM_8505,
104 USB_LINK_CHARGER_SE1_8505,
105 USB_LINK_CARKIT_CHGR_1_8505,
106 USB_LINK_CARKIT_CHGR_2_8505,
107 USB_LINK_ACA_DOCK_CHGR_8505,
108 USB_LINK_SAMSUNG_BOOT_CBL_PHY_EN_8505,
109 USB_LINK_SAMSUNG_BOOT_CBL_PHY_DISB_8505,
110 USB_LINK_SAMSUNG_UART_CBL_PHY_EN_8505,
111 USB_LINK_SAMSUNG_UART_CBL_PHY_DISB_8505,
112 USB_LINK_MOTOROLA_FACTORY_CBL_PHY_EN_8505,
113};
114
115enum ab8500_usb_mode {
116 USB_IDLE = 0,
117 USB_PERIPHERAL,
118 USB_HOST,
119 USB_DEDICATED_CHG
120};
121
122struct ab8500_usb {
123 struct usb_phy phy;
124 struct device *dev;
125 struct ab8500 *ab8500;
126 unsigned vbus_draw;
127 struct work_struct phy_dis_work;
128 enum ab8500_usb_mode mode;
129 struct regulator *v_ape;
130 struct regulator *v_musb;
131 struct regulator *v_ulpi;
132 int saved_v_ulpi;
133 int previous_link_status_state;
134 struct pinctrl *pinctrl;
135 struct pinctrl_state *pins_sleep;
136};
137
138static inline struct ab8500_usb *phy_to_ab(struct usb_phy *x)
139{
140 return container_of(x, struct ab8500_usb, phy);
141}
142
143static void ab8500_usb_wd_workaround(struct ab8500_usb *ab)
144{
145 abx500_set_register_interruptible(ab->dev,
146 AB8500_SYS_CTRL2_BLOCK,
147 AB8500_MAIN_WD_CTRL_REG,
148 AB8500_BIT_WD_CTRL_ENABLE);
149
150 udelay(AB8500_WD_KICK_DELAY_US);
151
152 abx500_set_register_interruptible(ab->dev,
153 AB8500_SYS_CTRL2_BLOCK,
154 AB8500_MAIN_WD_CTRL_REG,
155 (AB8500_BIT_WD_CTRL_ENABLE
156 | AB8500_BIT_WD_CTRL_KICK));
157
158 udelay(AB8500_WD_V11_DISABLE_DELAY_US);
159
160 abx500_set_register_interruptible(ab->dev,
161 AB8500_SYS_CTRL2_BLOCK,
162 AB8500_MAIN_WD_CTRL_REG,
163 0);
164}
165
166static void ab8500_usb_regulator_enable(struct ab8500_usb *ab)
167{
168 int ret, volt;
169
170 ret = regulator_enable(ab->v_ape);
171 if (ret)
172 dev_err(ab->dev, "Failed to enable v-ape\n");
173
174 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
175 ab->saved_v_ulpi = regulator_get_voltage(ab->v_ulpi);
176 if (ab->saved_v_ulpi < 0)
177 dev_err(ab->dev, "Failed to get v_ulpi voltage\n");
178
179 ret = regulator_set_voltage(ab->v_ulpi, 1300000, 1350000);
180 if (ret < 0)
181 dev_err(ab->dev, "Failed to set the Vintcore to 1.3V, ret=%d\n",
182 ret);
183
184 ret = regulator_set_optimum_mode(ab->v_ulpi, 28000);
185 if (ret < 0)
186 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
187 ret);
188 }
189
190 ret = regulator_enable(ab->v_ulpi);
191 if (ret)
192 dev_err(ab->dev, "Failed to enable vddulpivio18\n");
193
194 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
195 volt = regulator_get_voltage(ab->v_ulpi);
196 if ((volt != 1300000) && (volt != 1350000))
197 dev_err(ab->dev, "Vintcore is not set to 1.3V volt=%d\n",
198 volt);
199 }
200
201 ret = regulator_enable(ab->v_musb);
202 if (ret)
203 dev_err(ab->dev, "Failed to enable musb_1v8\n");
204}
205
206static void ab8500_usb_regulator_disable(struct ab8500_usb *ab)
207{
208 int ret;
209
210 regulator_disable(ab->v_musb);
211
212 regulator_disable(ab->v_ulpi);
213
214 /* USB is not the only consumer of Vintcore, restore old settings */
215 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
216 if (ab->saved_v_ulpi > 0) {
217 ret = regulator_set_voltage(ab->v_ulpi,
218 ab->saved_v_ulpi, ab->saved_v_ulpi);
219 if (ret < 0)
220 dev_err(ab->dev, "Failed to set the Vintcore to %duV, ret=%d\n",
221 ab->saved_v_ulpi, ret);
222 }
223
224 ret = regulator_set_optimum_mode(ab->v_ulpi, 0);
225 if (ret < 0)
226 dev_err(ab->dev, "Failed to set optimum mode (ret=%d)\n",
227 ret);
228 }
229
230 regulator_disable(ab->v_ape);
231}
232
233static void ab8500_usb_wd_linkstatus(struct ab8500_usb *ab, u8 bit)
234{
235 /* Workaround for v2.0 bug # 31952 */
236 if (is_ab8500_2p0(ab->ab8500)) {
237 abx500_mask_and_set_register_interruptible(ab->dev,
238 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
239 bit, bit);
240 udelay(AB8500_V20_31952_DISABLE_DELAY_US);
241 }
242}
243
244static void ab8500_usb_phy_enable(struct ab8500_usb *ab, bool sel_host)
245{
246 u8 bit;
247 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
248 AB8500_BIT_PHY_CTRL_DEVICE_EN;
249
250 /* mux and configure USB pins to DEFAULT state */
251 ab->pinctrl = pinctrl_get_select(ab->dev, PINCTRL_STATE_DEFAULT);
252 if (IS_ERR(ab->pinctrl))
253 dev_err(ab->dev, "could not get/set default pinstate\n");
254
255 ab8500_usb_regulator_enable(ab);
256
257 abx500_mask_and_set_register_interruptible(ab->dev,
258 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
259 bit, bit);
260}
261
262static void ab8500_usb_phy_disable(struct ab8500_usb *ab, bool sel_host)
263{
264 u8 bit;
265 bit = sel_host ? AB8500_BIT_PHY_CTRL_HOST_EN :
266 AB8500_BIT_PHY_CTRL_DEVICE_EN;
267
268 ab8500_usb_wd_linkstatus(ab, bit);
269
270 abx500_mask_and_set_register_interruptible(ab->dev,
271 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
272 bit, 0);
273
274 /* Needed to disable the phy.*/
275 ab8500_usb_wd_workaround(ab);
276
277 ab8500_usb_regulator_disable(ab);
278
279 if (!IS_ERR(ab->pinctrl)) {
280 /* configure USB pins to SLEEP state */
281 ab->pins_sleep = pinctrl_lookup_state(ab->pinctrl,
282 PINCTRL_STATE_SLEEP);
283
284 if (IS_ERR(ab->pins_sleep))
285 dev_dbg(ab->dev, "could not get sleep pinstate\n");
286 else if (pinctrl_select_state(ab->pinctrl, ab->pins_sleep))
287 dev_err(ab->dev, "could not set pins to sleep state\n");
288
289 /* as USB pins are shared with idddet, release them to allow
290 * iddet to request them
291 */
292 pinctrl_put(ab->pinctrl);
293 }
294}
295
296#define ab8500_usb_host_phy_en(ab) ab8500_usb_phy_enable(ab, true)
297#define ab8500_usb_host_phy_dis(ab) ab8500_usb_phy_disable(ab, true)
298#define ab8500_usb_peri_phy_en(ab) ab8500_usb_phy_enable(ab, false)
299#define ab8500_usb_peri_phy_dis(ab) ab8500_usb_phy_disable(ab, false)
300
301static int ab8505_usb_link_status_update(struct ab8500_usb *ab,
302 enum ab8505_usb_link_status lsts)
303{
304 enum ux500_musb_vbus_id_status event = 0;
305
306 dev_dbg(ab->dev, "ab8505_usb_link_status_update %d\n", lsts);
307
308 /*
309 * Spurious link_status interrupts are seen at the time of
310 * disconnection of a device in RIDA state
311 */
312 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8505 &&
313 (lsts == USB_LINK_STD_HOST_NC_8505))
314 return 0;
315
316 ab->previous_link_status_state = lsts;
317
318 switch (lsts) {
319 case USB_LINK_ACA_RID_B_8505:
320 event = UX500_MUSB_RIDB;
321 case USB_LINK_NOT_CONFIGURED_8505:
322 case USB_LINK_RESERVED0_8505:
323 case USB_LINK_RESERVED1_8505:
324 case USB_LINK_RESERVED2_8505:
325 case USB_LINK_RESERVED3_8505:
326 ab->mode = USB_IDLE;
327 ab->phy.otg->default_a = false;
328 ab->vbus_draw = 0;
329 if (event != UX500_MUSB_RIDB)
330 event = UX500_MUSB_NONE;
331 /*
332 * Fallback to default B_IDLE as nothing
333 * is connected
334 */
335 ab->phy.state = OTG_STATE_B_IDLE;
336 break;
337
338 case USB_LINK_ACA_RID_C_NM_8505:
339 event = UX500_MUSB_RIDC;
340 case USB_LINK_STD_HOST_NC_8505:
341 case USB_LINK_STD_HOST_C_NS_8505:
342 case USB_LINK_STD_HOST_C_S_8505:
343 case USB_LINK_CDP_8505:
344 if (ab->mode == USB_IDLE) {
345 ab->mode = USB_PERIPHERAL;
346 ab8500_usb_peri_phy_en(ab);
347 atomic_notifier_call_chain(&ab->phy.notifier,
348 UX500_MUSB_PREPARE, &ab->vbus_draw);
349 }
350 if (event != UX500_MUSB_RIDC)
351 event = UX500_MUSB_VBUS;
352 break;
353
354 case USB_LINK_ACA_RID_A_8505:
355 case USB_LINK_ACA_DOCK_CHGR_8505:
356 event = UX500_MUSB_RIDA;
357 case USB_LINK_HM_IDGND_8505:
358 if (ab->mode == USB_IDLE) {
359 ab->mode = USB_HOST;
360 ab8500_usb_host_phy_en(ab);
361 atomic_notifier_call_chain(&ab->phy.notifier,
362 UX500_MUSB_PREPARE, &ab->vbus_draw);
363 }
364 ab->phy.otg->default_a = true;
365 if (event != UX500_MUSB_RIDA)
366 event = UX500_MUSB_ID;
367 atomic_notifier_call_chain(&ab->phy.notifier,
368 event, &ab->vbus_draw);
369 break;
370
371 case USB_LINK_DEDICATED_CHG_8505:
372 ab->mode = USB_DEDICATED_CHG;
373 event = UX500_MUSB_CHARGER;
374 atomic_notifier_call_chain(&ab->phy.notifier,
375 event, &ab->vbus_draw);
376 break;
377
378 default:
379 break;
380 }
381
382 return 0;
383}
384
385static int ab8500_usb_link_status_update(struct ab8500_usb *ab,
386 enum ab8500_usb_link_status lsts)
387{
388 enum ux500_musb_vbus_id_status event = 0;
389
390 dev_dbg(ab->dev, "ab8500_usb_link_status_update %d\n", lsts);
391
392 /*
393 * Spurious link_status interrupts are seen in case of a
394 * disconnection of a device in IDGND and RIDA stage
395 */
396 if (ab->previous_link_status_state == USB_LINK_HM_IDGND_8500 &&
397 (lsts == USB_LINK_STD_HOST_C_NS_8500 ||
398 lsts == USB_LINK_STD_HOST_NC_8500))
399 return 0;
400
401 if (ab->previous_link_status_state == USB_LINK_ACA_RID_A_8500 &&
402 lsts == USB_LINK_STD_HOST_NC_8500)
403 return 0;
404
405 ab->previous_link_status_state = lsts;
406
407 switch (lsts) {
408 case USB_LINK_ACA_RID_B_8500:
409 event = UX500_MUSB_RIDB;
410 case USB_LINK_NOT_CONFIGURED_8500:
411 case USB_LINK_NOT_VALID_LINK_8500:
412 ab->mode = USB_IDLE;
413 ab->phy.otg->default_a = false;
414 ab->vbus_draw = 0;
415 if (event != UX500_MUSB_RIDB)
416 event = UX500_MUSB_NONE;
417 /* Fallback to default B_IDLE as nothing is connected */
418 ab->phy.state = OTG_STATE_B_IDLE;
419 break;
420
421 case USB_LINK_ACA_RID_C_NM_8500:
422 case USB_LINK_ACA_RID_C_HS_8500:
423 case USB_LINK_ACA_RID_C_HS_CHIRP_8500:
424 event = UX500_MUSB_RIDC;
425 case USB_LINK_STD_HOST_NC_8500:
426 case USB_LINK_STD_HOST_C_NS_8500:
427 case USB_LINK_STD_HOST_C_S_8500:
428 case USB_LINK_HOST_CHG_NM_8500:
429 case USB_LINK_HOST_CHG_HS_8500:
430 case USB_LINK_HOST_CHG_HS_CHIRP_8500:
431 if (ab->mode == USB_IDLE) {
432 ab->mode = USB_PERIPHERAL;
433 ab8500_usb_peri_phy_en(ab);
434 atomic_notifier_call_chain(&ab->phy.notifier,
435 UX500_MUSB_PREPARE, &ab->vbus_draw);
436 }
437 if (event != UX500_MUSB_RIDC)
438 event = UX500_MUSB_VBUS;
439 break;
440
441 case USB_LINK_ACA_RID_A_8500:
442 event = UX500_MUSB_RIDA;
443 case USB_LINK_HM_IDGND_8500:
444 if (ab->mode == USB_IDLE) {
445 ab->mode = USB_HOST;
446 ab8500_usb_host_phy_en(ab);
447 atomic_notifier_call_chain(&ab->phy.notifier,
448 UX500_MUSB_PREPARE, &ab->vbus_draw);
449 }
450 ab->phy.otg->default_a = true;
451 if (event != UX500_MUSB_RIDA)
452 event = UX500_MUSB_ID;
453 atomic_notifier_call_chain(&ab->phy.notifier,
454 event, &ab->vbus_draw);
455 break;
456
457 case USB_LINK_DEDICATED_CHG_8500:
458 ab->mode = USB_DEDICATED_CHG;
459 event = UX500_MUSB_CHARGER;
460 atomic_notifier_call_chain(&ab->phy.notifier,
461 event, &ab->vbus_draw);
462 break;
463
464 case USB_LINK_RESERVED_8500:
465 break;
466 }
467
468 return 0;
469}
470
471/*
472 * Connection Sequence:
473 * 1. Link Status Interrupt
474 * 2. Enable AB clock
475 * 3. Enable AB regulators
476 * 4. Enable USB phy
477 * 5. Reset the musb controller
478 * 6. Switch the ULPI GPIO pins to fucntion mode
479 * 7. Enable the musb Peripheral5 clock
480 * 8. Restore MUSB context
481 */
482static int abx500_usb_link_status_update(struct ab8500_usb *ab)
483{
484 u8 reg;
485 int ret = 0;
486
487 if (is_ab8500(ab->ab8500)) {
488 enum ab8500_usb_link_status lsts;
489
490 abx500_get_register_interruptible(ab->dev,
491 AB8500_USB, AB8500_USB_LINE_STAT_REG, &reg);
492 lsts = (reg >> 3) & 0x0F;
493 ret = ab8500_usb_link_status_update(ab, lsts);
494 } else if (is_ab8505(ab->ab8500)) {
495 enum ab8505_usb_link_status lsts;
496
497 abx500_get_register_interruptible(ab->dev,
498 AB8500_USB, AB8505_USB_LINE_STAT_REG, &reg);
499 lsts = (reg >> 3) & 0x1F;
500 ret = ab8505_usb_link_status_update(ab, lsts);
501 }
502
503 return ret;
504}
505
506/*
507 * Disconnection Sequence:
508 * 1. Disconect Interrupt
509 * 2. Disable regulators
510 * 3. Disable AB clock
511 * 4. Disable the Phy
512 * 5. Link Status Interrupt
513 * 6. Disable Musb Clock
514 */
515static irqreturn_t ab8500_usb_disconnect_irq(int irq, void *data)
516{
517 struct ab8500_usb *ab = (struct ab8500_usb *) data;
518 enum usb_phy_events event = UX500_MUSB_NONE;
519
520 /* Link status will not be updated till phy is disabled. */
521 if (ab->mode == USB_HOST) {
522 ab->phy.otg->default_a = false;
523 ab->vbus_draw = 0;
524 atomic_notifier_call_chain(&ab->phy.notifier,
525 event, &ab->vbus_draw);
526 ab8500_usb_host_phy_dis(ab);
527 ab->mode = USB_IDLE;
528 }
529
530 if (ab->mode == USB_PERIPHERAL) {
531 atomic_notifier_call_chain(&ab->phy.notifier,
532 event, &ab->vbus_draw);
533 ab8500_usb_peri_phy_dis(ab);
534 atomic_notifier_call_chain(&ab->phy.notifier,
535 UX500_MUSB_CLEAN, &ab->vbus_draw);
536 ab->mode = USB_IDLE;
537 ab->phy.otg->default_a = false;
538 ab->vbus_draw = 0;
539 }
540
541 if (is_ab8500_2p0(ab->ab8500)) {
542 if (ab->mode == USB_DEDICATED_CHG) {
543 ab8500_usb_wd_linkstatus(ab,
544 AB8500_BIT_PHY_CTRL_DEVICE_EN);
545 abx500_mask_and_set_register_interruptible(ab->dev,
546 AB8500_USB, AB8500_USB_PHY_CTRL_REG,
547 AB8500_BIT_PHY_CTRL_DEVICE_EN, 0);
548 }
549 }
550
551 return IRQ_HANDLED;
552}
553
554static irqreturn_t ab8500_usb_link_status_irq(int irq, void *data)
555{
556 struct ab8500_usb *ab = (struct ab8500_usb *) data;
557
558 abx500_usb_link_status_update(ab);
559
560 return IRQ_HANDLED;
561}
562
563static void ab8500_usb_phy_disable_work(struct work_struct *work)
564{
565 struct ab8500_usb *ab = container_of(work, struct ab8500_usb,
566 phy_dis_work);
567
568 if (!ab->phy.otg->host)
569 ab8500_usb_host_phy_dis(ab);
570
571 if (!ab->phy.otg->gadget)
572 ab8500_usb_peri_phy_dis(ab);
573}
574
575static unsigned ab8500_eyediagram_workaroud(struct ab8500_usb *ab, unsigned mA)
576{
577 /*
578 * AB8500 V2 has eye diagram issues when drawing more than 100mA from
579 * VBUS. Set charging current to 100mA in case of standard host
580 */
581 if (is_ab8500_2p0_or_earlier(ab->ab8500))
582 if (mA > 100)
583 mA = 100;
584
585 return mA;
586}
587
588static int ab8500_usb_set_power(struct usb_phy *phy, unsigned mA)
589{
590 struct ab8500_usb *ab;
591
592 if (!phy)
593 return -ENODEV;
594
595 ab = phy_to_ab(phy);
596
597 mA = ab8500_eyediagram_workaroud(ab, mA);
598
599 ab->vbus_draw = mA;
600
601 atomic_notifier_call_chain(&ab->phy.notifier,
602 UX500_MUSB_VBUS, &ab->vbus_draw);
603
604 return 0;
605}
606
607static int ab8500_usb_set_suspend(struct usb_phy *x, int suspend)
608{
609 /* TODO */
610 return 0;
611}
612
613static int ab8500_usb_set_peripheral(struct usb_otg *otg,
614 struct usb_gadget *gadget)
615{
616 struct ab8500_usb *ab;
617
618 if (!otg)
619 return -ENODEV;
620
621 ab = phy_to_ab(otg->phy);
622
623 ab->phy.otg->gadget = gadget;
624
625 /* Some drivers call this function in atomic context.
626 * Do not update ab8500 registers directly till this
627 * is fixed.
628 */
629
630 if ((ab->mode != USB_IDLE) && (!gadget)) {
631 ab->mode = USB_IDLE;
632 schedule_work(&ab->phy_dis_work);
633 }
634
635 return 0;
636}
637
638static int ab8500_usb_set_host(struct usb_otg *otg, struct usb_bus *host)
639{
640 struct ab8500_usb *ab;
641
642 if (!otg)
643 return -ENODEV;
644
645 ab = phy_to_ab(otg->phy);
646
647 ab->phy.otg->host = host;
648
649 /* Some drivers call this function in atomic context.
650 * Do not update ab8500 registers directly till this
651 * is fixed.
652 */
653
654 if ((ab->mode != USB_IDLE) && (!host)) {
655 ab->mode = USB_IDLE;
656 schedule_work(&ab->phy_dis_work);
657 }
658
659 return 0;
660}
661
662static int ab8500_usb_regulator_get(struct ab8500_usb *ab)
663{
664 int err;
665
666 ab->v_ape = devm_regulator_get(ab->dev, "v-ape");
667 if (IS_ERR(ab->v_ape)) {
668 dev_err(ab->dev, "Could not get v-ape supply\n");
669 err = PTR_ERR(ab->v_ape);
670 return err;
671 }
672
673 ab->v_ulpi = devm_regulator_get(ab->dev, "vddulpivio18");
674 if (IS_ERR(ab->v_ulpi)) {
675 dev_err(ab->dev, "Could not get vddulpivio18 supply\n");
676 err = PTR_ERR(ab->v_ulpi);
677 return err;
678 }
679
680 ab->v_musb = devm_regulator_get(ab->dev, "musb_1v8");
681 if (IS_ERR(ab->v_musb)) {
682 dev_err(ab->dev, "Could not get musb_1v8 supply\n");
683 err = PTR_ERR(ab->v_musb);
684 return err;
685 }
686
687 return 0;
688}
689
690static int ab8500_usb_irq_setup(struct platform_device *pdev,
691 struct ab8500_usb *ab)
692{
693 int err;
694 int irq;
695
696 irq = platform_get_irq_byname(pdev, "USB_LINK_STATUS");
697 if (irq < 0) {
698 dev_err(&pdev->dev, "Link status irq not found\n");
699 return irq;
700 }
701 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
702 ab8500_usb_link_status_irq,
703 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-link-status", ab);
704 if (err < 0) {
705 dev_err(ab->dev, "request_irq failed for link status irq\n");
706 return err;
707 }
708
709 irq = platform_get_irq_byname(pdev, "ID_WAKEUP_F");
710 if (irq < 0) {
711 dev_err(&pdev->dev, "ID fall irq not found\n");
712 return irq;
713 }
714 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
715 ab8500_usb_disconnect_irq,
716 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-id-fall", ab);
717 if (err < 0) {
718 dev_err(ab->dev, "request_irq failed for ID fall irq\n");
719 return err;
720 }
721
722 irq = platform_get_irq_byname(pdev, "VBUS_DET_F");
723 if (irq < 0) {
724 dev_err(&pdev->dev, "VBUS fall irq not found\n");
725 return irq;
726 }
727 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
728 ab8500_usb_disconnect_irq,
729 IRQF_NO_SUSPEND | IRQF_SHARED, "usb-vbus-fall", ab);
730 if (err < 0) {
731 dev_err(ab->dev, "request_irq failed for Vbus fall irq\n");
732 return err;
733 }
734
735 return 0;
736}
737
738static int ab8500_usb_probe(struct platform_device *pdev)
739{
740 struct ab8500_usb *ab;
741 struct ab8500 *ab8500;
742 struct usb_otg *otg;
743 int err;
744 int rev;
745
746 ab8500 = dev_get_drvdata(pdev->dev.parent);
747 rev = abx500_get_chip_id(&pdev->dev);
748
749 if (is_ab8500_1p1_or_earlier(ab8500)) {
750 dev_err(&pdev->dev, "Unsupported AB8500 chip rev=%d\n", rev);
751 return -ENODEV;
752 }
753
754 ab = devm_kzalloc(&pdev->dev, sizeof(*ab), GFP_KERNEL);
755 if (!ab)
756 return -ENOMEM;
757
758 otg = devm_kzalloc(&pdev->dev, sizeof(*otg), GFP_KERNEL);
759 if (!otg)
760 return -ENOMEM;
761
762 ab->dev = &pdev->dev;
763 ab->ab8500 = ab8500;
764 ab->phy.dev = ab->dev;
765 ab->phy.otg = otg;
766 ab->phy.label = "ab8500";
767 ab->phy.set_suspend = ab8500_usb_set_suspend;
768 ab->phy.set_power = ab8500_usb_set_power;
769 ab->phy.state = OTG_STATE_UNDEFINED;
770
771 otg->phy = &ab->phy;
772 otg->set_host = ab8500_usb_set_host;
773 otg->set_peripheral = ab8500_usb_set_peripheral;
774
775 platform_set_drvdata(pdev, ab);
776
777 ATOMIC_INIT_NOTIFIER_HEAD(&ab->phy.notifier);
778
779 /* all: Disable phy when called from set_host and set_peripheral */
780 INIT_WORK(&ab->phy_dis_work, ab8500_usb_phy_disable_work);
781
782 err = ab8500_usb_regulator_get(ab);
783 if (err)
784 return err;
785
786 err = ab8500_usb_irq_setup(pdev, ab);
787 if (err < 0)
788 return err;
789
790 err = usb_add_phy(&ab->phy, USB_PHY_TYPE_USB2);
791 if (err) {
792 dev_err(&pdev->dev, "Can't register transceiver\n");
793 return err;
794 }
795
796 /* Phy tuning values for AB8500 */
797 if (!is_ab8500_2p0_or_earlier(ab->ab8500)) {
798 /* Enable the PBT/Bank 0x12 access */
799 err = abx500_set_register_interruptible(ab->dev,
800 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x01);
801 if (err < 0)
802 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
803 err);
804
805 err = abx500_set_register_interruptible(ab->dev,
806 AB8500_DEBUG, AB8500_USB_PHY_TUNE1, 0xC8);
807 if (err < 0)
808 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
809 err);
810
811 err = abx500_set_register_interruptible(ab->dev,
812 AB8500_DEBUG, AB8500_USB_PHY_TUNE2, 0x00);
813 if (err < 0)
814 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
815 err);
816
817 err = abx500_set_register_interruptible(ab->dev,
818 AB8500_DEBUG, AB8500_USB_PHY_TUNE3, 0x78);
819 if (err < 0)
820 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
821 err);
822
823 /* Switch to normal mode/disable Bank 0x12 access */
824 err = abx500_set_register_interruptible(ab->dev,
825 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS, 0x00);
826 if (err < 0)
827 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
828 err);
829 }
830
831 /* Phy tuning values for AB8505 */
832 if (is_ab8505(ab->ab8500)) {
833 /* Enable the PBT/Bank 0x12 access */
834 err = abx500_mask_and_set_register_interruptible(ab->dev,
835 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
836 0x01, 0x01);
837 if (err < 0)
838 dev_err(ab->dev, "Failed to enable bank12 access err=%d\n",
839 err);
840
841 err = abx500_mask_and_set_register_interruptible(ab->dev,
842 AB8500_DEBUG, AB8500_USB_PHY_TUNE1,
843 0xC8, 0xC8);
844 if (err < 0)
845 dev_err(ab->dev, "Failed to set PHY_TUNE1 register err=%d\n",
846 err);
847
848 err = abx500_mask_and_set_register_interruptible(ab->dev,
849 AB8500_DEBUG, AB8500_USB_PHY_TUNE2,
850 0x60, 0x60);
851 if (err < 0)
852 dev_err(ab->dev, "Failed to set PHY_TUNE2 register err=%d\n",
853 err);
854
855 err = abx500_mask_and_set_register_interruptible(ab->dev,
856 AB8500_DEBUG, AB8500_USB_PHY_TUNE3,
857 0xFC, 0x80);
858
859 if (err < 0)
860 dev_err(ab->dev, "Failed to set PHY_TUNE3 regester err=%d\n",
861 err);
862
863 /* Switch to normal mode/disable Bank 0x12 access */
864 err = abx500_mask_and_set_register_interruptible(ab->dev,
865 AB8500_DEVELOPMENT, AB8500_BANK12_ACCESS,
866 0x00, 0x00);
867 if (err < 0)
868 dev_err(ab->dev, "Failed to switch bank12 access err=%d\n",
869 err);
870 }
871
872 /* Needed to enable ID detection. */
873 ab8500_usb_wd_workaround(ab);
874
875 abx500_usb_link_status_update(ab);
876
877 dev_info(&pdev->dev, "revision 0x%2x driver initialized\n", rev);
878
879 return 0;
880}
881
882static int ab8500_usb_remove(struct platform_device *pdev)
883{
884 struct ab8500_usb *ab = platform_get_drvdata(pdev);
885
886 cancel_work_sync(&ab->phy_dis_work);
887
888 usb_remove_phy(&ab->phy);
889
890 if (ab->mode == USB_HOST)
891 ab8500_usb_host_phy_dis(ab);
892 else if (ab->mode == USB_PERIPHERAL)
893 ab8500_usb_peri_phy_dis(ab);
894
895 platform_set_drvdata(pdev, NULL);
896
897 return 0;
898}
899
900static struct platform_driver ab8500_usb_driver = {
901 .probe = ab8500_usb_probe,
902 .remove = ab8500_usb_remove,
903 .driver = {
904 .name = "ab8500-usb",
905 .owner = THIS_MODULE,
906 },
907};
908
909static int __init ab8500_usb_init(void)
910{
911 return platform_driver_register(&ab8500_usb_driver);
912}
913subsys_initcall(ab8500_usb_init);
914
915static void __exit ab8500_usb_exit(void)
916{
917 platform_driver_unregister(&ab8500_usb_driver);
918}
919module_exit(ab8500_usb_exit);
920
921MODULE_ALIAS("platform:ab8500_usb");
922MODULE_AUTHOR("ST-Ericsson AB");
923MODULE_DESCRIPTION("AB8500 usb transceiver driver");
924MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/phy/phy-fsl-usb.c
index d16adb41eb21..97b9308507c3 100644
--- a/drivers/usb/otg/fsl_otg.c
+++ b/drivers/usb/phy/phy-fsl-usb.c
@@ -43,7 +43,7 @@
43 43
44#include <asm/unaligned.h> 44#include <asm/unaligned.h>
45 45
46#include "fsl_otg.h" 46#include "phy-fsl-usb.h"
47 47
48#define DRIVER_VERSION "Rev. 1.55" 48#define DRIVER_VERSION "Rev. 1.55"
49#define DRIVER_AUTHOR "Jerry Huang/Li Yang" 49#define DRIVER_AUTHOR "Jerry Huang/Li Yang"
@@ -361,28 +361,18 @@ int fsl_otg_init_timers(struct otg_fsm *fsm)
361void fsl_otg_uninit_timers(void) 361void fsl_otg_uninit_timers(void)
362{ 362{
363 /* FSM used timers */ 363 /* FSM used timers */
364 if (a_wait_vrise_tmr != NULL) 364 kfree(a_wait_vrise_tmr);
365 kfree(a_wait_vrise_tmr); 365 kfree(a_wait_bcon_tmr);
366 if (a_wait_bcon_tmr != NULL) 366 kfree(a_aidl_bdis_tmr);
367 kfree(a_wait_bcon_tmr); 367 kfree(b_ase0_brst_tmr);
368 if (a_aidl_bdis_tmr != NULL) 368 kfree(b_se0_srp_tmr);
369 kfree(a_aidl_bdis_tmr); 369 kfree(b_srp_fail_tmr);
370 if (b_ase0_brst_tmr != NULL) 370 kfree(a_wait_enum_tmr);
371 kfree(b_ase0_brst_tmr);
372 if (b_se0_srp_tmr != NULL)
373 kfree(b_se0_srp_tmr);
374 if (b_srp_fail_tmr != NULL)
375 kfree(b_srp_fail_tmr);
376 if (a_wait_enum_tmr != NULL)
377 kfree(a_wait_enum_tmr);
378 371
379 /* device driver used timers */ 372 /* device driver used timers */
380 if (b_srp_wait_tmr != NULL) 373 kfree(b_srp_wait_tmr);
381 kfree(b_srp_wait_tmr); 374 kfree(b_data_pulse_tmr);
382 if (b_data_pulse_tmr != NULL) 375 kfree(b_vbus_pulse_tmr);
383 kfree(b_data_pulse_tmr);
384 if (b_vbus_pulse_tmr != NULL)
385 kfree(b_vbus_pulse_tmr);
386} 376}
387 377
388/* Add timer to timer list */ 378/* Add timer to timer list */
@@ -1002,7 +992,7 @@ static int show_fsl_usb2_otg_state(struct device *dev,
1002 /* State */ 992 /* State */
1003 t = scnprintf(next, size, 993 t = scnprintf(next, size,
1004 "OTG state: %s\n\n", 994 "OTG state: %s\n\n",
1005 otg_state_string(fsl_otg_dev->phy.state)); 995 usb_otg_state_string(fsl_otg_dev->phy.state));
1006 size -= t; 996 size -= t;
1007 next += t; 997 next += t;
1008 998
diff --git a/drivers/usb/otg/fsl_otg.h b/drivers/usb/phy/phy-fsl-usb.h
index ca266280895d..ca266280895d 100644
--- a/drivers/usb/otg/fsl_otg.h
+++ b/drivers/usb/phy/phy-fsl-usb.h
diff --git a/drivers/usb/otg/otg_fsm.c b/drivers/usb/phy/phy-fsm-usb.c
index ade131a8ae5e..c520b3548e7c 100644
--- a/drivers/usb/otg/otg_fsm.c
+++ b/drivers/usb/phy/phy-fsm-usb.c
@@ -29,7 +29,7 @@
29#include <linux/usb/gadget.h> 29#include <linux/usb/gadget.h>
30#include <linux/usb/otg.h> 30#include <linux/usb/otg.h>
31 31
32#include "otg_fsm.h" 32#include "phy-otg-fsm.h"
33 33
34/* Change USB protocol when there is a protocol change */ 34/* Change USB protocol when there is a protocol change */
35static int otg_set_protocol(struct otg_fsm *fsm, int protocol) 35static int otg_set_protocol(struct otg_fsm *fsm, int protocol)
@@ -119,7 +119,7 @@ int otg_set_state(struct otg_fsm *fsm, enum usb_otg_state new_state)
119 state_changed = 1; 119 state_changed = 1;
120 if (fsm->otg->phy->state == new_state) 120 if (fsm->otg->phy->state == new_state)
121 return 0; 121 return 0;
122 VDBG("Set state: %s\n", otg_state_string(new_state)); 122 VDBG("Set state: %s\n", usb_otg_state_string(new_state));
123 otg_leave_state(fsm, fsm->otg->phy->state); 123 otg_leave_state(fsm, fsm->otg->phy->state);
124 switch (new_state) { 124 switch (new_state) {
125 case OTG_STATE_B_IDLE: 125 case OTG_STATE_B_IDLE:
diff --git a/drivers/usb/otg/otg_fsm.h b/drivers/usb/phy/phy-fsm-usb.h
index c30a2e1d9e46..c30a2e1d9e46 100644
--- a/drivers/usb/otg/otg_fsm.h
+++ b/drivers/usb/phy/phy-fsm-usb.h
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/phy/phy-gpio-vbus-usb.c
index a7d4ac591982..4c76074e518d 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/phy/phy-gpio-vbus-usb.c
@@ -61,6 +61,7 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
61{ 61{
62 struct regulator *vbus_draw = gpio_vbus->vbus_draw; 62 struct regulator *vbus_draw = gpio_vbus->vbus_draw;
63 int enabled; 63 int enabled;
64 int ret;
64 65
65 if (!vbus_draw) 66 if (!vbus_draw)
66 return; 67 return;
@@ -69,12 +70,16 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
69 if (mA) { 70 if (mA) {
70 regulator_set_current_limit(vbus_draw, 0, 1000 * mA); 71 regulator_set_current_limit(vbus_draw, 0, 1000 * mA);
71 if (!enabled) { 72 if (!enabled) {
72 regulator_enable(vbus_draw); 73 ret = regulator_enable(vbus_draw);
74 if (ret < 0)
75 return;
73 gpio_vbus->vbus_draw_enabled = 1; 76 gpio_vbus->vbus_draw_enabled = 1;
74 } 77 }
75 } else { 78 } else {
76 if (enabled) { 79 if (enabled) {
77 regulator_disable(vbus_draw); 80 ret = regulator_disable(vbus_draw);
81 if (ret < 0)
82 return;
78 gpio_vbus->vbus_draw_enabled = 0; 83 gpio_vbus->vbus_draw_enabled = 0;
79 } 84 }
80 } 85 }
diff --git a/drivers/usb/otg/isp1301_omap.c b/drivers/usb/phy/phy-isp1301-omap.c
index af9cb11626b2..ae481afcb3ec 100644
--- a/drivers/usb/otg/isp1301_omap.c
+++ b/drivers/usb/phy/phy-isp1301-omap.c
@@ -236,7 +236,7 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
236 236
237static inline const char *state_name(struct isp1301 *isp) 237static inline const char *state_name(struct isp1301 *isp)
238{ 238{
239 return otg_state_string(isp->phy.state); 239 return usb_otg_state_string(isp->phy.state);
240} 240}
241 241
242/*-------------------------------------------------------------------------*/ 242/*-------------------------------------------------------------------------*/
@@ -481,7 +481,7 @@ static void check_state(struct isp1301 *isp, const char *tag)
481 if (isp->phy.state == state && !extra) 481 if (isp->phy.state == state && !extra)
482 return; 482 return;
483 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, 483 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
484 otg_state_string(state), fsm, state_name(isp), 484 usb_otg_state_string(state), fsm, state_name(isp),
485 omap_readl(OTG_CTRL)); 485 omap_readl(OTG_CTRL));
486} 486}
487 487
@@ -1077,7 +1077,7 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1077 1077
1078 if (state != isp->phy.state) 1078 if (state != isp->phy.state)
1079 pr_debug(" isp, %s -> %s\n", 1079 pr_debug(" isp, %s -> %s\n",
1080 otg_state_string(state), state_name(isp)); 1080 usb_otg_state_string(state), state_name(isp));
1081 1081
1082#ifdef CONFIG_USB_OTG 1082#ifdef CONFIG_USB_OTG
1083 /* update the OTG controller state to match the isp1301; may 1083 /* update the OTG controller state to match the isp1301; may
@@ -1212,7 +1212,7 @@ static void isp1301_release(struct device *dev)
1212 1212
1213static struct isp1301 *the_transceiver; 1213static struct isp1301 *the_transceiver;
1214 1214
1215static int __exit isp1301_remove(struct i2c_client *i2c) 1215static int isp1301_remove(struct i2c_client *i2c)
1216{ 1216{
1217 struct isp1301 *isp; 1217 struct isp1301 *isp;
1218 1218
@@ -1634,7 +1634,7 @@ static struct i2c_driver isp1301_driver = {
1634 .name = "isp1301_omap", 1634 .name = "isp1301_omap",
1635 }, 1635 },
1636 .probe = isp1301_probe, 1636 .probe = isp1301_probe,
1637 .remove = __exit_p(isp1301_remove), 1637 .remove = isp1301_remove,
1638 .id_table = isp1301_id, 1638 .id_table = isp1301_id,
1639}; 1639};
1640 1640
diff --git a/drivers/usb/phy/phy-isp1301.c b/drivers/usb/phy/phy-isp1301.c
new file mode 100644
index 000000000000..225ae6c97eeb
--- /dev/null
+++ b/drivers/usb/phy/phy-isp1301.c
@@ -0,0 +1,162 @@
1/*
2 * NXP ISP1301 USB transceiver driver
3 *
4 * Copyright (C) 2012 Roland Stigge
5 *
6 * Author: Roland Stigge <stigge@antcom.de>
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 version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/mutex.h>
15#include <linux/i2c.h>
16#include <linux/usb/phy.h>
17#include <linux/usb/isp1301.h>
18
19#define DRV_NAME "isp1301"
20
21struct isp1301 {
22 struct usb_phy phy;
23 struct mutex mutex;
24
25 struct i2c_client *client;
26};
27
28#define phy_to_isp(p) (container_of((p), struct isp1301, phy))
29
30static const struct i2c_device_id isp1301_id[] = {
31 { "isp1301", 0 },
32 { }
33};
34
35static struct i2c_client *isp1301_i2c_client;
36
37static int __isp1301_write(struct isp1301 *isp, u8 reg, u8 value, u8 clear)
38{
39 return i2c_smbus_write_byte_data(isp->client, reg | clear, value);
40}
41
42static int isp1301_write(struct isp1301 *isp, u8 reg, u8 value)
43{
44 return __isp1301_write(isp, reg, value, 0);
45}
46
47static int isp1301_clear(struct isp1301 *isp, u8 reg, u8 value)
48{
49 return __isp1301_write(isp, reg, value, ISP1301_I2C_REG_CLEAR_ADDR);
50}
51
52static int isp1301_phy_init(struct usb_phy *phy)
53{
54 struct isp1301 *isp = phy_to_isp(phy);
55
56 /* Disable transparent UART mode first */
57 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_UART_EN);
58 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_1, ~MC1_SPEED_REG);
59 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_SPEED_REG);
60 isp1301_clear(isp, ISP1301_I2C_MODE_CONTROL_2, ~0);
61 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_2, (MC2_BI_DI | MC2_PSW_EN
62 | MC2_SPD_SUSP_CTRL));
63
64 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, ~0);
65 isp1301_write(isp, ISP1301_I2C_MODE_CONTROL_1, MC1_DAT_SE0);
66 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLDOWN
67 | OTG1_DP_PULLDOWN));
68 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, (OTG1_DM_PULLUP
69 | OTG1_DP_PULLUP));
70
71 /* mask all interrupts */
72 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_LATCH, ~0);
73 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_FALLING, ~0);
74 isp1301_clear(isp, ISP1301_I2C_INTERRUPT_RISING, ~0);
75
76 return 0;
77}
78
79static int isp1301_phy_set_vbus(struct usb_phy *phy, int on)
80{
81 struct isp1301 *isp = phy_to_isp(phy);
82
83 if (on)
84 isp1301_write(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
85 else
86 isp1301_clear(isp, ISP1301_I2C_OTG_CONTROL_1, OTG1_VBUS_DRV);
87
88 return 0;
89}
90
91static int isp1301_probe(struct i2c_client *client,
92 const struct i2c_device_id *i2c_id)
93{
94 struct isp1301 *isp;
95 struct usb_phy *phy;
96
97 isp = devm_kzalloc(&client->dev, sizeof(*isp), GFP_KERNEL);
98 if (!isp)
99 return -ENOMEM;
100
101 isp->client = client;
102 mutex_init(&isp->mutex);
103
104 phy = &isp->phy;
105 phy->label = DRV_NAME;
106 phy->init = isp1301_phy_init;
107 phy->set_vbus = isp1301_phy_set_vbus;
108 phy->type = USB_PHY_TYPE_USB2;
109
110 i2c_set_clientdata(client, isp);
111 usb_add_phy_dev(phy);
112
113 isp1301_i2c_client = client;
114
115 return 0;
116}
117
118static int isp1301_remove(struct i2c_client *client)
119{
120 struct isp1301 *isp = i2c_get_clientdata(client);
121
122 usb_remove_phy(&isp->phy);
123 isp1301_i2c_client = NULL;
124
125 return 0;
126}
127
128static struct i2c_driver isp1301_driver = {
129 .driver = {
130 .name = DRV_NAME,
131 },
132 .probe = isp1301_probe,
133 .remove = isp1301_remove,
134 .id_table = isp1301_id,
135};
136
137module_i2c_driver(isp1301_driver);
138
139static int match(struct device *dev, void *data)
140{
141 struct device_node *node = (struct device_node *)data;
142 return (dev->of_node == node) &&
143 (dev->driver == &isp1301_driver.driver);
144}
145
146struct i2c_client *isp1301_get_client(struct device_node *node)
147{
148 if (node) { /* reference of ISP1301 I2C node via DT */
149 struct device *dev = bus_find_device(&i2c_bus_type, NULL,
150 node, match);
151 if (!dev)
152 return NULL;
153 return to_i2c_client(dev);
154 } else { /* non-DT: only one ISP1301 chip supported */
155 return isp1301_i2c_client;
156 }
157}
158EXPORT_SYMBOL_GPL(isp1301_get_client);
159
160MODULE_AUTHOR("Roland Stigge <stigge@antcom.de>");
161MODULE_DESCRIPTION("NXP ISP1301 USB transceiver driver");
162MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/msm_otg.c b/drivers/usb/phy/phy-msm-usb.c
index 749fbf41fb6f..749fbf41fb6f 100644
--- a/drivers/usb/otg/msm_otg.c
+++ b/drivers/usb/phy/phy-msm-usb.c
diff --git a/drivers/usb/phy/mv_u3d_phy.c b/drivers/usb/phy/phy-mv-u3d-usb.c
index 9d8599122aa9..f7838a43347c 100644
--- a/drivers/usb/phy/mv_u3d_phy.c
+++ b/drivers/usb/phy/phy-mv-u3d-usb.c
@@ -15,7 +15,7 @@
15#include <linux/usb/otg.h> 15#include <linux/usb/otg.h>
16#include <linux/platform_data/mv_usb.h> 16#include <linux/platform_data/mv_usb.h>
17 17
18#include "mv_u3d_phy.h" 18#include "phy-mv-u3d-usb.h"
19 19
20/* 20/*
21 * struct mv_u3d_phy - transceiver driver state 21 * struct mv_u3d_phy - transceiver driver state
@@ -313,7 +313,7 @@ err:
313 return ret; 313 return ret;
314} 314}
315 315
316static int __exit mv_u3d_phy_remove(struct platform_device *pdev) 316static int mv_u3d_phy_remove(struct platform_device *pdev)
317{ 317{
318 struct mv_u3d_phy *mv_u3d_phy = platform_get_drvdata(pdev); 318 struct mv_u3d_phy *mv_u3d_phy = platform_get_drvdata(pdev);
319 319
diff --git a/drivers/usb/phy/mv_u3d_phy.h b/drivers/usb/phy/phy-mv-u3d-usb.h
index 2a658cb9a527..2a658cb9a527 100644
--- a/drivers/usb/phy/mv_u3d_phy.h
+++ b/drivers/usb/phy/phy-mv-u3d-usb.h
diff --git a/drivers/usb/otg/mv_otg.c b/drivers/usb/phy/phy-mv-usb.c
index b6a9be31133b..c987bbe27851 100644
--- a/drivers/usb/otg/mv_otg.c
+++ b/drivers/usb/phy/phy-mv-usb.c
@@ -27,7 +27,7 @@
27#include <linux/usb/hcd.h> 27#include <linux/usb/hcd.h>
28#include <linux/platform_data/mv_usb.h> 28#include <linux/platform_data/mv_usb.h>
29 29
30#include "mv_otg.h" 30#include "phy-mv-usb.h"
31 31
32#define DRIVER_DESC "Marvell USB OTG transceiver driver" 32#define DRIVER_DESC "Marvell USB OTG transceiver driver"
33#define DRIVER_VERSION "Jan 20, 2010" 33#define DRIVER_VERSION "Jan 20, 2010"
@@ -237,18 +237,12 @@ static void mv_otg_start_periphrals(struct mv_otg *mvotg, int on)
237 237
238static void otg_clock_enable(struct mv_otg *mvotg) 238static void otg_clock_enable(struct mv_otg *mvotg)
239{ 239{
240 unsigned int i; 240 clk_prepare_enable(mvotg->clk);
241
242 for (i = 0; i < mvotg->clknum; i++)
243 clk_prepare_enable(mvotg->clk[i]);
244} 241}
245 242
246static void otg_clock_disable(struct mv_otg *mvotg) 243static void otg_clock_disable(struct mv_otg *mvotg)
247{ 244{
248 unsigned int i; 245 clk_disable_unprepare(mvotg->clk);
249
250 for (i = 0; i < mvotg->clknum; i++)
251 clk_disable_unprepare(mvotg->clk[i]);
252} 246}
253 247
254static int mv_otg_enable_internal(struct mv_otg *mvotg) 248static int mv_otg_enable_internal(struct mv_otg *mvotg)
@@ -684,16 +678,14 @@ static int mv_otg_probe(struct platform_device *pdev)
684 struct mv_otg *mvotg; 678 struct mv_otg *mvotg;
685 struct usb_otg *otg; 679 struct usb_otg *otg;
686 struct resource *r; 680 struct resource *r;
687 int retval = 0, clk_i, i; 681 int retval = 0, i;
688 size_t size;
689 682
690 if (pdata == NULL) { 683 if (pdata == NULL) {
691 dev_err(&pdev->dev, "failed to get platform data\n"); 684 dev_err(&pdev->dev, "failed to get platform data\n");
692 return -ENODEV; 685 return -ENODEV;
693 } 686 }
694 687
695 size = sizeof(*mvotg) + sizeof(struct clk *) * pdata->clknum; 688 mvotg = devm_kzalloc(&pdev->dev, sizeof(*mvotg), GFP_KERNEL);
696 mvotg = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
697 if (!mvotg) { 689 if (!mvotg) {
698 dev_err(&pdev->dev, "failed to allocate memory!\n"); 690 dev_err(&pdev->dev, "failed to allocate memory!\n");
699 return -ENOMEM; 691 return -ENOMEM;
@@ -708,15 +700,9 @@ static int mv_otg_probe(struct platform_device *pdev)
708 mvotg->pdev = pdev; 700 mvotg->pdev = pdev;
709 mvotg->pdata = pdata; 701 mvotg->pdata = pdata;
710 702
711 mvotg->clknum = pdata->clknum; 703 mvotg->clk = devm_clk_get(&pdev->dev, NULL);
712 for (clk_i = 0; clk_i < mvotg->clknum; clk_i++) { 704 if (IS_ERR(mvotg->clk))
713 mvotg->clk[clk_i] = devm_clk_get(&pdev->dev, 705 return PTR_ERR(mvotg->clk);
714 pdata->clkname[clk_i]);
715 if (IS_ERR(mvotg->clk[clk_i])) {
716 retval = PTR_ERR(mvotg->clk[clk_i]);
717 return retval;
718 }
719 }
720 706
721 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue"); 707 mvotg->qwork = create_singlethread_workqueue("mv_otg_queue");
722 if (!mvotg->qwork) { 708 if (!mvotg->qwork) {
diff --git a/drivers/usb/otg/mv_otg.h b/drivers/usb/phy/phy-mv-usb.h
index 8a9e351b36ba..551da6eb0ba8 100644
--- a/drivers/usb/otg/mv_otg.h
+++ b/drivers/usb/phy/phy-mv-usb.h
@@ -158,8 +158,7 @@ struct mv_otg {
158 158
159 unsigned int active; 159 unsigned int active;
160 unsigned int clock_gating; 160 unsigned int clock_gating;
161 unsigned int clknum; 161 struct clk *clk;
162 struct clk *clk[0];
163}; 162};
164 163
165#endif 164#endif
diff --git a/drivers/usb/otg/mxs-phy.c b/drivers/usb/phy/phy-mxs-usb.c
index b0d9f119c749..9d4381e64d51 100644
--- a/drivers/usb/otg/mxs-phy.c
+++ b/drivers/usb/phy/phy-mxs-usb.c
@@ -48,12 +48,12 @@ static void mxs_phy_hw_init(struct mxs_phy *mxs_phy)
48 stmp_reset_block(base + HW_USBPHY_CTRL); 48 stmp_reset_block(base + HW_USBPHY_CTRL);
49 49
50 /* Power up the PHY */ 50 /* Power up the PHY */
51 writel_relaxed(0, base + HW_USBPHY_PWD); 51 writel(0, base + HW_USBPHY_PWD);
52 52
53 /* enable FS/LS device */ 53 /* enable FS/LS device */
54 writel_relaxed(BM_USBPHY_CTRL_ENUTMILEVEL2 | 54 writel(BM_USBPHY_CTRL_ENUTMILEVEL2 |
55 BM_USBPHY_CTRL_ENUTMILEVEL3, 55 BM_USBPHY_CTRL_ENUTMILEVEL3,
56 base + HW_USBPHY_CTRL_SET); 56 base + HW_USBPHY_CTRL_SET);
57} 57}
58 58
59static int mxs_phy_init(struct usb_phy *phy) 59static int mxs_phy_init(struct usb_phy *phy)
@@ -70,8 +70,8 @@ static void mxs_phy_shutdown(struct usb_phy *phy)
70{ 70{
71 struct mxs_phy *mxs_phy = to_mxs_phy(phy); 71 struct mxs_phy *mxs_phy = to_mxs_phy(phy);
72 72
73 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 73 writel(BM_USBPHY_CTRL_CLKGATE,
74 phy->io_priv + HW_USBPHY_CTRL_SET); 74 phy->io_priv + HW_USBPHY_CTRL_SET);
75 75
76 clk_disable_unprepare(mxs_phy->clk); 76 clk_disable_unprepare(mxs_phy->clk);
77} 77}
@@ -81,15 +81,15 @@ static int mxs_phy_suspend(struct usb_phy *x, int suspend)
81 struct mxs_phy *mxs_phy = to_mxs_phy(x); 81 struct mxs_phy *mxs_phy = to_mxs_phy(x);
82 82
83 if (suspend) { 83 if (suspend) {
84 writel_relaxed(0xffffffff, x->io_priv + HW_USBPHY_PWD); 84 writel(0xffffffff, x->io_priv + HW_USBPHY_PWD);
85 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 85 writel(BM_USBPHY_CTRL_CLKGATE,
86 x->io_priv + HW_USBPHY_CTRL_SET); 86 x->io_priv + HW_USBPHY_CTRL_SET);
87 clk_disable_unprepare(mxs_phy->clk); 87 clk_disable_unprepare(mxs_phy->clk);
88 } else { 88 } else {
89 clk_prepare_enable(mxs_phy->clk); 89 clk_prepare_enable(mxs_phy->clk);
90 writel_relaxed(BM_USBPHY_CTRL_CLKGATE, 90 writel(BM_USBPHY_CTRL_CLKGATE,
91 x->io_priv + HW_USBPHY_CTRL_CLR); 91 x->io_priv + HW_USBPHY_CTRL_CLR);
92 writel_relaxed(0, x->io_priv + HW_USBPHY_PWD); 92 writel(0, x->io_priv + HW_USBPHY_PWD);
93 } 93 }
94 94
95 return 0; 95 return 0;
@@ -102,8 +102,8 @@ static int mxs_phy_on_connect(struct usb_phy *phy,
102 (speed == USB_SPEED_HIGH) ? "high" : "non-high"); 102 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
103 103
104 if (speed == USB_SPEED_HIGH) 104 if (speed == USB_SPEED_HIGH)
105 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, 105 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
106 phy->io_priv + HW_USBPHY_CTRL_SET); 106 phy->io_priv + HW_USBPHY_CTRL_SET);
107 107
108 return 0; 108 return 0;
109} 109}
@@ -115,8 +115,8 @@ static int mxs_phy_on_disconnect(struct usb_phy *phy,
115 (speed == USB_SPEED_HIGH) ? "high" : "non-high"); 115 (speed == USB_SPEED_HIGH) ? "high" : "non-high");
116 116
117 if (speed == USB_SPEED_HIGH) 117 if (speed == USB_SPEED_HIGH)
118 writel_relaxed(BM_USBPHY_CTRL_ENHOSTDISCONDETECT, 118 writel(BM_USBPHY_CTRL_ENHOSTDISCONDETECT,
119 phy->io_priv + HW_USBPHY_CTRL_CLR); 119 phy->io_priv + HW_USBPHY_CTRL_CLR);
120 120
121 return 0; 121 return 0;
122} 122}
@@ -127,6 +127,7 @@ static int mxs_phy_probe(struct platform_device *pdev)
127 void __iomem *base; 127 void __iomem *base;
128 struct clk *clk; 128 struct clk *clk;
129 struct mxs_phy *mxs_phy; 129 struct mxs_phy *mxs_phy;
130 int ret;
130 131
131 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 132 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
132 if (!res) { 133 if (!res) {
@@ -166,11 +167,19 @@ static int mxs_phy_probe(struct platform_device *pdev)
166 167
167 platform_set_drvdata(pdev, &mxs_phy->phy); 168 platform_set_drvdata(pdev, &mxs_phy->phy);
168 169
170 ret = usb_add_phy_dev(&mxs_phy->phy);
171 if (ret)
172 return ret;
173
169 return 0; 174 return 0;
170} 175}
171 176
172static int mxs_phy_remove(struct platform_device *pdev) 177static int mxs_phy_remove(struct platform_device *pdev)
173{ 178{
179 struct mxs_phy *mxs_phy = platform_get_drvdata(pdev);
180
181 usb_remove_phy(&mxs_phy->phy);
182
174 platform_set_drvdata(pdev, NULL); 183 platform_set_drvdata(pdev, NULL);
175 184
176 return 0; 185 return 0;
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/phy/phy-nop.c
index a3ce24b94a73..2b10cc969bbb 100644
--- a/drivers/usb/otg/nop-usb-xceiv.c
+++ b/drivers/usb/phy/phy-nop.c
@@ -32,10 +32,16 @@
32#include <linux/usb/otg.h> 32#include <linux/usb/otg.h>
33#include <linux/usb/nop-usb-xceiv.h> 33#include <linux/usb/nop-usb-xceiv.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/clk.h>
36#include <linux/regulator/consumer.h>
37#include <linux/of.h>
35 38
36struct nop_usb_xceiv { 39struct nop_usb_xceiv {
37 struct usb_phy phy; 40 struct usb_phy phy;
38 struct device *dev; 41 struct device *dev;
42 struct clk *clk;
43 struct regulator *vcc;
44 struct regulator *reset;
39}; 45};
40 46
41static struct platform_device *pd; 47static struct platform_device *pd;
@@ -64,6 +70,46 @@ static int nop_set_suspend(struct usb_phy *x, int suspend)
64 return 0; 70 return 0;
65} 71}
66 72
73static int nop_init(struct usb_phy *phy)
74{
75 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
76
77 if (!IS_ERR(nop->vcc)) {
78 if (regulator_enable(nop->vcc))
79 dev_err(phy->dev, "Failed to enable power\n");
80 }
81
82 if (!IS_ERR(nop->clk))
83 clk_enable(nop->clk);
84
85 if (!IS_ERR(nop->reset)) {
86 /* De-assert RESET */
87 if (regulator_enable(nop->reset))
88 dev_err(phy->dev, "Failed to de-assert reset\n");
89 }
90
91 return 0;
92}
93
94static void nop_shutdown(struct usb_phy *phy)
95{
96 struct nop_usb_xceiv *nop = dev_get_drvdata(phy->dev);
97
98 if (!IS_ERR(nop->reset)) {
99 /* Assert RESET */
100 if (regulator_disable(nop->reset))
101 dev_err(phy->dev, "Failed to assert reset\n");
102 }
103
104 if (!IS_ERR(nop->clk))
105 clk_disable(nop->clk);
106
107 if (!IS_ERR(nop->vcc)) {
108 if (regulator_disable(nop->vcc))
109 dev_err(phy->dev, "Failed to disable power\n");
110 }
111}
112
67static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) 113static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
68{ 114{
69 if (!otg) 115 if (!otg)
@@ -95,39 +141,96 @@ static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
95 141
96static int nop_usb_xceiv_probe(struct platform_device *pdev) 142static int nop_usb_xceiv_probe(struct platform_device *pdev)
97{ 143{
144 struct device *dev = &pdev->dev;
98 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data; 145 struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
99 struct nop_usb_xceiv *nop; 146 struct nop_usb_xceiv *nop;
100 enum usb_phy_type type = USB_PHY_TYPE_USB2; 147 enum usb_phy_type type = USB_PHY_TYPE_USB2;
101 int err; 148 int err;
149 u32 clk_rate = 0;
150 bool needs_vcc = false;
151 bool needs_reset = false;
102 152
103 nop = kzalloc(sizeof *nop, GFP_KERNEL); 153 nop = devm_kzalloc(&pdev->dev, sizeof(*nop), GFP_KERNEL);
104 if (!nop) 154 if (!nop)
105 return -ENOMEM; 155 return -ENOMEM;
106 156
107 nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL); 157 nop->phy.otg = devm_kzalloc(&pdev->dev, sizeof(*nop->phy.otg),
108 if (!nop->phy.otg) { 158 GFP_KERNEL);
109 kfree(nop); 159 if (!nop->phy.otg)
110 return -ENOMEM; 160 return -ENOMEM;
111 }
112 161
113 if (pdata) 162 if (dev->of_node) {
163 struct device_node *node = dev->of_node;
164
165 if (of_property_read_u32(node, "clock-frequency", &clk_rate))
166 clk_rate = 0;
167
168 needs_vcc = of_property_read_bool(node, "vcc-supply");
169 needs_reset = of_property_read_bool(node, "reset-supply");
170
171 } else if (pdata) {
114 type = pdata->type; 172 type = pdata->type;
173 clk_rate = pdata->clk_rate;
174 needs_vcc = pdata->needs_vcc;
175 needs_reset = pdata->needs_reset;
176 }
177
178 nop->clk = devm_clk_get(&pdev->dev, "main_clk");
179 if (IS_ERR(nop->clk)) {
180 dev_dbg(&pdev->dev, "Can't get phy clock: %ld\n",
181 PTR_ERR(nop->clk));
182 }
183
184 if (!IS_ERR(nop->clk) && clk_rate) {
185 err = clk_set_rate(nop->clk, clk_rate);
186 if (err) {
187 dev_err(&pdev->dev, "Error setting clock rate\n");
188 return err;
189 }
190 }
191
192 if (!IS_ERR(nop->clk)) {
193 err = clk_prepare(nop->clk);
194 if (err) {
195 dev_err(&pdev->dev, "Error preparing clock\n");
196 return err;
197 }
198 }
199
200 nop->vcc = devm_regulator_get(&pdev->dev, "vcc");
201 if (IS_ERR(nop->vcc)) {
202 dev_dbg(&pdev->dev, "Error getting vcc regulator: %ld\n",
203 PTR_ERR(nop->vcc));
204 if (needs_vcc)
205 return -EPROBE_DEFER;
206 }
207
208 nop->reset = devm_regulator_get(&pdev->dev, "reset");
209 if (IS_ERR(nop->reset)) {
210 dev_dbg(&pdev->dev, "Error getting reset regulator: %ld\n",
211 PTR_ERR(nop->reset));
212 if (needs_reset)
213 return -EPROBE_DEFER;
214 }
115 215
116 nop->dev = &pdev->dev; 216 nop->dev = &pdev->dev;
117 nop->phy.dev = nop->dev; 217 nop->phy.dev = nop->dev;
118 nop->phy.label = "nop-xceiv"; 218 nop->phy.label = "nop-xceiv";
119 nop->phy.set_suspend = nop_set_suspend; 219 nop->phy.set_suspend = nop_set_suspend;
220 nop->phy.init = nop_init;
221 nop->phy.shutdown = nop_shutdown;
120 nop->phy.state = OTG_STATE_UNDEFINED; 222 nop->phy.state = OTG_STATE_UNDEFINED;
223 nop->phy.type = type;
121 224
122 nop->phy.otg->phy = &nop->phy; 225 nop->phy.otg->phy = &nop->phy;
123 nop->phy.otg->set_host = nop_set_host; 226 nop->phy.otg->set_host = nop_set_host;
124 nop->phy.otg->set_peripheral = nop_set_peripheral; 227 nop->phy.otg->set_peripheral = nop_set_peripheral;
125 228
126 err = usb_add_phy(&nop->phy, type); 229 err = usb_add_phy_dev(&nop->phy);
127 if (err) { 230 if (err) {
128 dev_err(&pdev->dev, "can't register transceiver, err: %d\n", 231 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
129 err); 232 err);
130 goto exit; 233 goto err_add;
131 } 234 }
132 235
133 platform_set_drvdata(pdev, nop); 236 platform_set_drvdata(pdev, nop);
@@ -135,9 +238,10 @@ static int nop_usb_xceiv_probe(struct platform_device *pdev)
135 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier); 238 ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
136 239
137 return 0; 240 return 0;
138exit: 241
139 kfree(nop->phy.otg); 242err_add:
140 kfree(nop); 243 if (!IS_ERR(nop->clk))
244 clk_unprepare(nop->clk);
141 return err; 245 return err;
142} 246}
143 247
@@ -145,21 +249,30 @@ static int nop_usb_xceiv_remove(struct platform_device *pdev)
145{ 249{
146 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev); 250 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
147 251
252 if (!IS_ERR(nop->clk))
253 clk_unprepare(nop->clk);
254
148 usb_remove_phy(&nop->phy); 255 usb_remove_phy(&nop->phy);
149 256
150 platform_set_drvdata(pdev, NULL); 257 platform_set_drvdata(pdev, NULL);
151 kfree(nop->phy.otg);
152 kfree(nop);
153 258
154 return 0; 259 return 0;
155} 260}
156 261
262static const struct of_device_id nop_xceiv_dt_ids[] = {
263 { .compatible = "usb-nop-xceiv" },
264 { }
265};
266
267MODULE_DEVICE_TABLE(of, nop_xceiv_dt_ids);
268
157static struct platform_driver nop_usb_xceiv_driver = { 269static struct platform_driver nop_usb_xceiv_driver = {
158 .probe = nop_usb_xceiv_probe, 270 .probe = nop_usb_xceiv_probe,
159 .remove = nop_usb_xceiv_remove, 271 .remove = nop_usb_xceiv_remove,
160 .driver = { 272 .driver = {
161 .name = "nop_usb_xceiv", 273 .name = "nop_usb_xceiv",
162 .owner = THIS_MODULE, 274 .owner = THIS_MODULE,
275 .of_match_table = of_match_ptr(nop_xceiv_dt_ids),
163 }, 276 },
164}; 277};
165 278
diff --git a/drivers/usb/phy/omap-control-usb.c b/drivers/usb/phy/phy-omap-control.c
index 1419ceda9759..1419ceda9759 100644
--- a/drivers/usb/phy/omap-control-usb.c
+++ b/drivers/usb/phy/phy-omap-control.c
diff --git a/drivers/usb/phy/omap-usb2.c b/drivers/usb/phy/phy-omap-usb2.c
index 844ab68f08d0..844ab68f08d0 100644
--- a/drivers/usb/phy/omap-usb2.c
+++ b/drivers/usb/phy/phy-omap-usb2.c
diff --git a/drivers/usb/phy/omap-usb3.c b/drivers/usb/phy/phy-omap-usb3.c
index a6e60b1e102e..a6e60b1e102e 100644
--- a/drivers/usb/phy/omap-usb3.c
+++ b/drivers/usb/phy/phy-omap-usb3.c
diff --git a/drivers/usb/phy/rcar-phy.c b/drivers/usb/phy/phy-rcar-usb.c
index a35681b0c501..a35681b0c501 100644
--- a/drivers/usb/phy/rcar-phy.c
+++ b/drivers/usb/phy/phy-rcar-usb.c
diff --git a/drivers/usb/phy/phy-samsung-usb.c b/drivers/usb/phy/phy-samsung-usb.c
new file mode 100644
index 000000000000..7b118ee5f5e4
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb.c
@@ -0,0 +1,236 @@
1/* linux/drivers/usb/phy/phy-samsung-usb.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB-PHY helper driver with common function calls;
9 * interacts with Samsung USB 2.0 PHY controller driver and later
10 * with Samsung USB 3.0 PHY driver.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
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
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/clk.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/of_address.h>
30#include <linux/usb/samsung_usb_phy.h>
31
32#include "phy-samsung-usb.h"
33
34int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy)
35{
36 struct device_node *usbphy_sys;
37
38 /* Getting node for system controller interface for usb-phy */
39 usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys");
40 if (!usbphy_sys) {
41 dev_err(sphy->dev, "No sys-controller interface for usb-phy\n");
42 return -ENODEV;
43 }
44
45 sphy->pmuregs = of_iomap(usbphy_sys, 0);
46
47 if (sphy->pmuregs == NULL) {
48 dev_err(sphy->dev, "Can't get usb-phy pmu control register\n");
49 goto err0;
50 }
51
52 sphy->sysreg = of_iomap(usbphy_sys, 1);
53
54 /*
55 * Not returning error code here, since this situation is not fatal.
56 * Few SoCs may not have this switch available
57 */
58 if (sphy->sysreg == NULL)
59 dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n");
60
61 of_node_put(usbphy_sys);
62
63 return 0;
64
65err0:
66 of_node_put(usbphy_sys);
67 return -ENXIO;
68}
69EXPORT_SYMBOL_GPL(samsung_usbphy_parse_dt);
70
71/*
72 * Set isolation here for phy.
73 * Here 'on = true' would mean USB PHY block is isolated, hence
74 * de-activated and vice-versa.
75 */
76void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on)
77{
78 void __iomem *reg = NULL;
79 u32 reg_val;
80 u32 en_mask = 0;
81
82 if (!sphy->pmuregs) {
83 dev_warn(sphy->dev, "Can't set pmu isolation\n");
84 return;
85 }
86
87 switch (sphy->drv_data->cpu_type) {
88 case TYPE_S3C64XX:
89 /*
90 * Do nothing: We will add here once S3C64xx goes for DT support
91 */
92 break;
93 case TYPE_EXYNOS4210:
94 /*
95 * Fall through since exynos4210 and exynos5250 have similar
96 * register architecture: two separate registers for host and
97 * device phy control with enable bit at position 0.
98 */
99 case TYPE_EXYNOS5250:
100 if (sphy->phy_type == USB_PHY_TYPE_DEVICE) {
101 reg = sphy->pmuregs +
102 sphy->drv_data->devphy_reg_offset;
103 en_mask = sphy->drv_data->devphy_en_mask;
104 } else if (sphy->phy_type == USB_PHY_TYPE_HOST) {
105 reg = sphy->pmuregs +
106 sphy->drv_data->hostphy_reg_offset;
107 en_mask = sphy->drv_data->hostphy_en_mask;
108 }
109 break;
110 default:
111 dev_err(sphy->dev, "Invalid SoC type\n");
112 return;
113 }
114
115 reg_val = readl(reg);
116
117 if (on)
118 reg_val &= ~en_mask;
119 else
120 reg_val |= en_mask;
121
122 writel(reg_val, reg);
123}
124EXPORT_SYMBOL_GPL(samsung_usbphy_set_isolation);
125
126/*
127 * Configure the mode of working of usb-phy here: HOST/DEVICE.
128 */
129void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy)
130{
131 u32 reg;
132
133 if (!sphy->sysreg) {
134 dev_warn(sphy->dev, "Can't configure specified phy mode\n");
135 return;
136 }
137
138 reg = readl(sphy->sysreg);
139
140 if (sphy->phy_type == USB_PHY_TYPE_DEVICE)
141 reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK;
142 else if (sphy->phy_type == USB_PHY_TYPE_HOST)
143 reg |= EXYNOS_USB20PHY_CFG_HOST_LINK;
144
145 writel(reg, sphy->sysreg);
146}
147EXPORT_SYMBOL_GPL(samsung_usbphy_cfg_sel);
148
149/*
150 * PHYs are different for USB Device and USB Host.
151 * This make sure that correct PHY type is selected before
152 * any operation on PHY.
153 */
154int samsung_usbphy_set_type(struct usb_phy *phy,
155 enum samsung_usb_phy_type phy_type)
156{
157 struct samsung_usbphy *sphy = phy_to_sphy(phy);
158
159 sphy->phy_type = phy_type;
160
161 return 0;
162}
163EXPORT_SYMBOL_GPL(samsung_usbphy_set_type);
164
165/*
166 * Returns reference clock frequency selection value
167 */
168int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy)
169{
170 struct clk *ref_clk;
171 int refclk_freq = 0;
172
173 /*
174 * In exynos5250 USB host and device PHY use
175 * external crystal clock XXTI
176 */
177 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
178 ref_clk = devm_clk_get(sphy->dev, "ext_xtal");
179 else
180 ref_clk = devm_clk_get(sphy->dev, "xusbxti");
181 if (IS_ERR(ref_clk)) {
182 dev_err(sphy->dev, "Failed to get reference clock\n");
183 return PTR_ERR(ref_clk);
184 }
185
186 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) {
187 /* set clock frequency for PLL */
188 switch (clk_get_rate(ref_clk)) {
189 case 9600 * KHZ:
190 refclk_freq = FSEL_CLKSEL_9600K;
191 break;
192 case 10 * MHZ:
193 refclk_freq = FSEL_CLKSEL_10M;
194 break;
195 case 12 * MHZ:
196 refclk_freq = FSEL_CLKSEL_12M;
197 break;
198 case 19200 * KHZ:
199 refclk_freq = FSEL_CLKSEL_19200K;
200 break;
201 case 20 * MHZ:
202 refclk_freq = FSEL_CLKSEL_20M;
203 break;
204 case 50 * MHZ:
205 refclk_freq = FSEL_CLKSEL_50M;
206 break;
207 case 24 * MHZ:
208 default:
209 /* default reference clock */
210 refclk_freq = FSEL_CLKSEL_24M;
211 break;
212 }
213 } else {
214 switch (clk_get_rate(ref_clk)) {
215 case 12 * MHZ:
216 refclk_freq = PHYCLK_CLKSEL_12M;
217 break;
218 case 24 * MHZ:
219 refclk_freq = PHYCLK_CLKSEL_24M;
220 break;
221 case 48 * MHZ:
222 refclk_freq = PHYCLK_CLKSEL_48M;
223 break;
224 default:
225 if (sphy->drv_data->cpu_type == TYPE_S3C64XX)
226 refclk_freq = PHYCLK_CLKSEL_48M;
227 else
228 refclk_freq = PHYCLK_CLKSEL_24M;
229 break;
230 }
231 }
232 clk_put(ref_clk);
233
234 return refclk_freq;
235}
236EXPORT_SYMBOL_GPL(samsung_usbphy_get_refclk_freq);
diff --git a/drivers/usb/phy/phy-samsung-usb.h b/drivers/usb/phy/phy-samsung-usb.h
new file mode 100644
index 000000000000..70a9cae5e37f
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb.h
@@ -0,0 +1,327 @@
1/* linux/drivers/usb/phy/phy-samsung-usb.h
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Samsung USB-PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
7 * OHCI-EXYNOS controllers.
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 version 2 as
11 * published by the Free Software Foundation.
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
19#include <linux/usb/phy.h>
20
21/* Register definitions */
22
23#define SAMSUNG_PHYPWR (0x00)
24
25#define PHYPWR_NORMAL_MASK (0x19 << 0)
26#define PHYPWR_OTG_DISABLE (0x1 << 4)
27#define PHYPWR_ANALOG_POWERDOWN (0x1 << 3)
28#define PHYPWR_FORCE_SUSPEND (0x1 << 1)
29/* For Exynos4 */
30#define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0)
31#define PHYPWR_SLEEP_PHY0 (0x1 << 5)
32
33#define SAMSUNG_PHYCLK (0x04)
34
35#define PHYCLK_MODE_USB11 (0x1 << 6)
36#define PHYCLK_EXT_OSC (0x1 << 5)
37#define PHYCLK_COMMON_ON_N (0x1 << 4)
38#define PHYCLK_ID_PULL (0x1 << 2)
39#define PHYCLK_CLKSEL_MASK (0x3 << 0)
40#define PHYCLK_CLKSEL_48M (0x0 << 0)
41#define PHYCLK_CLKSEL_12M (0x2 << 0)
42#define PHYCLK_CLKSEL_24M (0x3 << 0)
43
44#define SAMSUNG_RSTCON (0x08)
45
46#define RSTCON_PHYLINK_SWRST (0x1 << 2)
47#define RSTCON_HLINK_SWRST (0x1 << 1)
48#define RSTCON_SWRST (0x1 << 0)
49
50/* EXYNOS5 */
51#define EXYNOS5_PHY_HOST_CTRL0 (0x00)
52
53#define HOST_CTRL0_PHYSWRSTALL (0x1 << 31)
54
55#define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19)
56#define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19)
57#define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19)
58#define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19)
59
60#define HOST_CTRL0_FSEL_MASK (0x7 << 16)
61#define HOST_CTRL0_FSEL(_x) ((_x) << 16)
62
63#define FSEL_CLKSEL_50M (0x7)
64#define FSEL_CLKSEL_24M (0x5)
65#define FSEL_CLKSEL_20M (0x4)
66#define FSEL_CLKSEL_19200K (0x3)
67#define FSEL_CLKSEL_12M (0x2)
68#define FSEL_CLKSEL_10M (0x1)
69#define FSEL_CLKSEL_9600K (0x0)
70
71#define HOST_CTRL0_TESTBURNIN (0x1 << 11)
72#define HOST_CTRL0_RETENABLE (0x1 << 10)
73#define HOST_CTRL0_COMMONON_N (0x1 << 9)
74#define HOST_CTRL0_SIDDQ (0x1 << 6)
75#define HOST_CTRL0_FORCESLEEP (0x1 << 5)
76#define HOST_CTRL0_FORCESUSPEND (0x1 << 4)
77#define HOST_CTRL0_WORDINTERFACE (0x1 << 3)
78#define HOST_CTRL0_UTMISWRST (0x1 << 2)
79#define HOST_CTRL0_LINKSWRST (0x1 << 1)
80#define HOST_CTRL0_PHYSWRST (0x1 << 0)
81
82#define EXYNOS5_PHY_HOST_TUNE0 (0x04)
83
84#define EXYNOS5_PHY_HSIC_CTRL1 (0x10)
85
86#define EXYNOS5_PHY_HSIC_TUNE1 (0x14)
87
88#define EXYNOS5_PHY_HSIC_CTRL2 (0x20)
89
90#define EXYNOS5_PHY_HSIC_TUNE2 (0x24)
91
92#define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23)
93#define HSIC_CTRL_REFCLKSEL (0x2 << 23)
94
95#define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16)
96#define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16)
97#define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16)
98#define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16)
99#define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16)
100#define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16)
101#define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16)
102
103#define HSIC_CTRL_SIDDQ (0x1 << 6)
104#define HSIC_CTRL_FORCESLEEP (0x1 << 5)
105#define HSIC_CTRL_FORCESUSPEND (0x1 << 4)
106#define HSIC_CTRL_WORDINTERFACE (0x1 << 3)
107#define HSIC_CTRL_UTMISWRST (0x1 << 2)
108#define HSIC_CTRL_PHYSWRST (0x1 << 0)
109
110#define EXYNOS5_PHY_HOST_EHCICTRL (0x30)
111
112#define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29)
113#define HOST_EHCICTRL_ENAINCR4 (0x1 << 28)
114#define HOST_EHCICTRL_ENAINCR8 (0x1 << 27)
115#define HOST_EHCICTRL_ENAINCR16 (0x1 << 26)
116
117#define EXYNOS5_PHY_HOST_OHCICTRL (0x34)
118
119#define HOST_OHCICTRL_SUSPLGCY (0x1 << 3)
120#define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2)
121#define HOST_OHCICTRL_CNTSEL (0x1 << 1)
122#define HOST_OHCICTRL_CLKCKTRST (0x1 << 0)
123
124#define EXYNOS5_PHY_OTG_SYS (0x38)
125
126#define OTG_SYS_PHYLINK_SWRESET (0x1 << 14)
127#define OTG_SYS_LINKSWRST_UOTG (0x1 << 13)
128#define OTG_SYS_PHY0_SWRST (0x1 << 12)
129
130#define OTG_SYS_REFCLKSEL_MASK (0x3 << 9)
131#define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9)
132#define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9)
133#define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9)
134
135#define OTG_SYS_IDPULLUP_UOTG (0x1 << 8)
136#define OTG_SYS_COMMON_ON (0x1 << 7)
137
138#define OTG_SYS_FSEL_MASK (0x7 << 4)
139#define OTG_SYS_FSEL(_x) ((_x) << 4)
140
141#define OTG_SYS_FORCESLEEP (0x1 << 3)
142#define OTG_SYS_OTGDISABLE (0x1 << 2)
143#define OTG_SYS_SIDDQ_UOTG (0x1 << 1)
144#define OTG_SYS_FORCESUSPEND (0x1 << 0)
145
146#define EXYNOS5_PHY_OTG_TUNE (0x40)
147
148/* EXYNOS5: USB 3.0 DRD */
149#define EXYNOS5_DRD_LINKSYSTEM (0x04)
150
151#define LINKSYSTEM_FLADJ_MASK (0x3f << 1)
152#define LINKSYSTEM_FLADJ(_x) ((_x) << 1)
153#define LINKSYSTEM_XHCI_VERSION_CONTROL (0x1 << 27)
154
155#define EXYNOS5_DRD_PHYUTMI (0x08)
156
157#define PHYUTMI_OTGDISABLE (0x1 << 6)
158#define PHYUTMI_FORCESUSPEND (0x1 << 1)
159#define PHYUTMI_FORCESLEEP (0x1 << 0)
160
161#define EXYNOS5_DRD_PHYPIPE (0x0c)
162
163#define EXYNOS5_DRD_PHYCLKRST (0x10)
164
165#define PHYCLKRST_SSC_REFCLKSEL_MASK (0xff << 23)
166#define PHYCLKRST_SSC_REFCLKSEL(_x) ((_x) << 23)
167
168#define PHYCLKRST_SSC_RANGE_MASK (0x03 << 21)
169#define PHYCLKRST_SSC_RANGE(_x) ((_x) << 21)
170
171#define PHYCLKRST_SSC_EN (0x1 << 20)
172#define PHYCLKRST_REF_SSP_EN (0x1 << 19)
173#define PHYCLKRST_REF_CLKDIV2 (0x1 << 18)
174
175#define PHYCLKRST_MPLL_MULTIPLIER_MASK (0x7f << 11)
176#define PHYCLKRST_MPLL_MULTIPLIER_100MHZ_REF (0x19 << 11)
177#define PHYCLKRST_MPLL_MULTIPLIER_50M_REF (0x02 << 11)
178#define PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF (0x68 << 11)
179#define PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF (0x7d << 11)
180#define PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF (0x02 << 11)
181
182#define PHYCLKRST_FSEL_MASK (0x3f << 5)
183#define PHYCLKRST_FSEL(_x) ((_x) << 5)
184#define PHYCLKRST_FSEL_PAD_100MHZ (0x27 << 5)
185#define PHYCLKRST_FSEL_PAD_24MHZ (0x2a << 5)
186#define PHYCLKRST_FSEL_PAD_20MHZ (0x31 << 5)
187#define PHYCLKRST_FSEL_PAD_19_2MHZ (0x38 << 5)
188
189#define PHYCLKRST_RETENABLEN (0x1 << 4)
190
191#define PHYCLKRST_REFCLKSEL_MASK (0x03 << 2)
192#define PHYCLKRST_REFCLKSEL_PAD_REFCLK (0x2 << 2)
193#define PHYCLKRST_REFCLKSEL_EXT_REFCLK (0x3 << 2)
194
195#define PHYCLKRST_PORTRESET (0x1 << 1)
196#define PHYCLKRST_COMMONONN (0x1 << 0)
197
198#define EXYNOS5_DRD_PHYREG0 (0x14)
199#define EXYNOS5_DRD_PHYREG1 (0x18)
200
201#define EXYNOS5_DRD_PHYPARAM0 (0x1c)
202
203#define PHYPARAM0_REF_USE_PAD (0x1 << 31)
204#define PHYPARAM0_REF_LOSLEVEL_MASK (0x1f << 26)
205#define PHYPARAM0_REF_LOSLEVEL (0x9 << 26)
206
207#define EXYNOS5_DRD_PHYPARAM1 (0x20)
208
209#define PHYPARAM1_PCS_TXDEEMPH_MASK (0x1f << 0)
210#define PHYPARAM1_PCS_TXDEEMPH (0x1c)
211
212#define EXYNOS5_DRD_PHYTERM (0x24)
213
214#define EXYNOS5_DRD_PHYTEST (0x28)
215
216#define PHYTEST_POWERDOWN_SSP (0x1 << 3)
217#define PHYTEST_POWERDOWN_HSP (0x1 << 2)
218
219#define EXYNOS5_DRD_PHYADP (0x2c)
220
221#define EXYNOS5_DRD_PHYBATCHG (0x30)
222
223#define PHYBATCHG_UTMI_CLKSEL (0x1 << 2)
224
225#define EXYNOS5_DRD_PHYRESUME (0x34)
226#define EXYNOS5_DRD_LINKPORT (0x44)
227
228#ifndef MHZ
229#define MHZ (1000*1000)
230#endif
231
232#ifndef KHZ
233#define KHZ (1000)
234#endif
235
236#define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4)
237#define S3C64XX_USBPHY_ENABLE (0x1 << 16)
238#define EXYNOS_USBPHY_ENABLE (0x1 << 0)
239#define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0)
240
241enum samsung_cpu_type {
242 TYPE_S3C64XX,
243 TYPE_EXYNOS4210,
244 TYPE_EXYNOS5250,
245};
246
247/*
248 * struct samsung_usbphy_drvdata - driver data for various SoC variants
249 * @cpu_type: machine identifier
250 * @devphy_en_mask: device phy enable mask for PHY CONTROL register
251 * @hostphy_en_mask: host phy enable mask for PHY CONTROL register
252 * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from
253 * mapped address of system controller.
254 * @hostphy_reg_offset: offset to HOST PHY CONTROL register from
255 * mapped address of system controller.
256 *
257 * Here we have a separate mask for device type phy.
258 * Having different masks for host and device type phy helps
259 * in setting independent masks in case of SoCs like S5PV210,
260 * in which PHY0 and PHY1 enable bits belong to same register
261 * placed at position 0 and 1 respectively.
262 * Although for newer SoCs like exynos these bits belong to
263 * different registers altogether placed at position 0.
264 */
265struct samsung_usbphy_drvdata {
266 int cpu_type;
267 int devphy_en_mask;
268 int hostphy_en_mask;
269 u32 devphy_reg_offset;
270 u32 hostphy_reg_offset;
271};
272
273/*
274 * struct samsung_usbphy - transceiver driver state
275 * @phy: transceiver structure
276 * @plat: platform data
277 * @dev: The parent device supplied to the probe function
278 * @clk: usb phy clock
279 * @regs: usb phy controller registers memory base
280 * @pmuregs: USB device PHY_CONTROL register memory base
281 * @sysreg: USB2.0 PHY_CFG register memory base
282 * @ref_clk_freq: reference clock frequency selection
283 * @drv_data: driver data available for different SoCs
284 * @phy_type: Samsung SoCs specific phy types: #HOST
285 * #DEVICE
286 * @phy_usage: usage count for phy
287 * @lock: lock for phy operations
288 */
289struct samsung_usbphy {
290 struct usb_phy phy;
291 struct samsung_usbphy_data *plat;
292 struct device *dev;
293 struct clk *clk;
294 void __iomem *regs;
295 void __iomem *pmuregs;
296 void __iomem *sysreg;
297 int ref_clk_freq;
298 const struct samsung_usbphy_drvdata *drv_data;
299 enum samsung_usb_phy_type phy_type;
300 atomic_t phy_usage;
301 spinlock_t lock;
302};
303
304#define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy)
305
306static const struct of_device_id samsung_usbphy_dt_match[];
307
308static inline const struct samsung_usbphy_drvdata
309*samsung_usbphy_get_driver_data(struct platform_device *pdev)
310{
311 if (pdev->dev.of_node) {
312 const struct of_device_id *match;
313 match = of_match_node(samsung_usbphy_dt_match,
314 pdev->dev.of_node);
315 return match->data;
316 }
317
318 return (struct samsung_usbphy_drvdata *)
319 platform_get_device_id(pdev)->driver_data;
320}
321
322extern int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy);
323extern void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on);
324extern void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy);
325extern int samsung_usbphy_set_type(struct usb_phy *phy,
326 enum samsung_usb_phy_type phy_type);
327extern int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy);
diff --git a/drivers/usb/phy/phy-samsung-usb2.c b/drivers/usb/phy/phy-samsung-usb2.c
new file mode 100644
index 000000000000..45ffe036dacc
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb2.c
@@ -0,0 +1,509 @@
1/* linux/drivers/usb/phy/phy-samsung-usb2.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
9 * OHCI-EXYNOS controllers.
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 version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/usb/otg.h>
30#include <linux/usb/samsung_usb_phy.h>
31#include <linux/platform_data/samsung-usbphy.h>
32
33#include "phy-samsung-usb.h"
34
35static int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host)
36{
37 if (!otg)
38 return -ENODEV;
39
40 if (!otg->host)
41 otg->host = host;
42
43 return 0;
44}
45
46static bool exynos5_phyhost_is_on(void __iomem *regs)
47{
48 u32 reg;
49
50 reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
51
52 return !(reg & HOST_CTRL0_SIDDQ);
53}
54
55static void samsung_exynos5_usb2phy_enable(struct samsung_usbphy *sphy)
56{
57 void __iomem *regs = sphy->regs;
58 u32 phyclk = sphy->ref_clk_freq;
59 u32 phyhost;
60 u32 phyotg;
61 u32 phyhsic;
62 u32 ehcictrl;
63 u32 ohcictrl;
64
65 /*
66 * phy_usage helps in keeping usage count for phy
67 * so that the first consumer enabling the phy is also
68 * the last consumer to disable it.
69 */
70
71 atomic_inc(&sphy->phy_usage);
72
73 if (exynos5_phyhost_is_on(regs)) {
74 dev_info(sphy->dev, "Already power on PHY\n");
75 return;
76 }
77
78 /* Host configuration */
79 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
80
81 /* phy reference clock configuration */
82 phyhost &= ~HOST_CTRL0_FSEL_MASK;
83 phyhost |= HOST_CTRL0_FSEL(phyclk);
84
85 /* host phy reset */
86 phyhost &= ~(HOST_CTRL0_PHYSWRST |
87 HOST_CTRL0_PHYSWRSTALL |
88 HOST_CTRL0_SIDDQ |
89 /* Enable normal mode of operation */
90 HOST_CTRL0_FORCESUSPEND |
91 HOST_CTRL0_FORCESLEEP);
92
93 /* Link reset */
94 phyhost |= (HOST_CTRL0_LINKSWRST |
95 HOST_CTRL0_UTMISWRST |
96 /* COMMON Block configuration during suspend */
97 HOST_CTRL0_COMMONON_N);
98 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
99 udelay(10);
100 phyhost &= ~(HOST_CTRL0_LINKSWRST |
101 HOST_CTRL0_UTMISWRST);
102 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
103
104 /* OTG configuration */
105 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
106
107 /* phy reference clock configuration */
108 phyotg &= ~OTG_SYS_FSEL_MASK;
109 phyotg |= OTG_SYS_FSEL(phyclk);
110
111 /* Enable normal mode of operation */
112 phyotg &= ~(OTG_SYS_FORCESUSPEND |
113 OTG_SYS_SIDDQ_UOTG |
114 OTG_SYS_FORCESLEEP |
115 OTG_SYS_REFCLKSEL_MASK |
116 /* COMMON Block configuration during suspend */
117 OTG_SYS_COMMON_ON);
118
119 /* OTG phy & link reset */
120 phyotg |= (OTG_SYS_PHY0_SWRST |
121 OTG_SYS_LINKSWRST_UOTG |
122 OTG_SYS_PHYLINK_SWRESET |
123 OTG_SYS_OTGDISABLE |
124 /* Set phy refclk */
125 OTG_SYS_REFCLKSEL_CLKCORE);
126
127 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
128 udelay(10);
129 phyotg &= ~(OTG_SYS_PHY0_SWRST |
130 OTG_SYS_LINKSWRST_UOTG |
131 OTG_SYS_PHYLINK_SWRESET);
132 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
133
134 /* HSIC phy configuration */
135 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
136 HSIC_CTRL_REFCLKSEL |
137 HSIC_CTRL_PHYSWRST);
138 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
139 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
140 udelay(10);
141 phyhsic &= ~HSIC_CTRL_PHYSWRST;
142 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
143 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
144
145 udelay(80);
146
147 /* enable EHCI DMA burst */
148 ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL);
149 ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN |
150 HOST_EHCICTRL_ENAINCR4 |
151 HOST_EHCICTRL_ENAINCR8 |
152 HOST_EHCICTRL_ENAINCR16);
153 writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL);
154
155 /* set ohci_suspend_on_n */
156 ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL);
157 ohcictrl |= HOST_OHCICTRL_SUSPLGCY;
158 writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL);
159}
160
161static void samsung_usb2phy_enable(struct samsung_usbphy *sphy)
162{
163 void __iomem *regs = sphy->regs;
164 u32 phypwr;
165 u32 phyclk;
166 u32 rstcon;
167
168 /* set clock frequency for PLL */
169 phyclk = sphy->ref_clk_freq;
170 phypwr = readl(regs + SAMSUNG_PHYPWR);
171 rstcon = readl(regs + SAMSUNG_RSTCON);
172
173 switch (sphy->drv_data->cpu_type) {
174 case TYPE_S3C64XX:
175 phyclk &= ~PHYCLK_COMMON_ON_N;
176 phypwr &= ~PHYPWR_NORMAL_MASK;
177 rstcon |= RSTCON_SWRST;
178 break;
179 case TYPE_EXYNOS4210:
180 phypwr &= ~PHYPWR_NORMAL_MASK_PHY0;
181 rstcon |= RSTCON_SWRST;
182 default:
183 break;
184 }
185
186 writel(phyclk, regs + SAMSUNG_PHYCLK);
187 /* Configure PHY0 for normal operation*/
188 writel(phypwr, regs + SAMSUNG_PHYPWR);
189 /* reset all ports of PHY and Link */
190 writel(rstcon, regs + SAMSUNG_RSTCON);
191 udelay(10);
192 rstcon &= ~RSTCON_SWRST;
193 writel(rstcon, regs + SAMSUNG_RSTCON);
194}
195
196static void samsung_exynos5_usb2phy_disable(struct samsung_usbphy *sphy)
197{
198 void __iomem *regs = sphy->regs;
199 u32 phyhost;
200 u32 phyotg;
201 u32 phyhsic;
202
203 if (atomic_dec_return(&sphy->phy_usage) > 0) {
204 dev_info(sphy->dev, "still being used\n");
205 return;
206 }
207
208 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
209 HSIC_CTRL_REFCLKSEL |
210 HSIC_CTRL_SIDDQ |
211 HSIC_CTRL_FORCESLEEP |
212 HSIC_CTRL_FORCESUSPEND);
213 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
214 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
215
216 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
217 phyhost |= (HOST_CTRL0_SIDDQ |
218 HOST_CTRL0_FORCESUSPEND |
219 HOST_CTRL0_FORCESLEEP |
220 HOST_CTRL0_PHYSWRST |
221 HOST_CTRL0_PHYSWRSTALL);
222 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
223
224 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
225 phyotg |= (OTG_SYS_FORCESUSPEND |
226 OTG_SYS_SIDDQ_UOTG |
227 OTG_SYS_FORCESLEEP);
228 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
229}
230
231static void samsung_usb2phy_disable(struct samsung_usbphy *sphy)
232{
233 void __iomem *regs = sphy->regs;
234 u32 phypwr;
235
236 phypwr = readl(regs + SAMSUNG_PHYPWR);
237
238 switch (sphy->drv_data->cpu_type) {
239 case TYPE_S3C64XX:
240 phypwr |= PHYPWR_NORMAL_MASK;
241 break;
242 case TYPE_EXYNOS4210:
243 phypwr |= PHYPWR_NORMAL_MASK_PHY0;
244 default:
245 break;
246 }
247
248 /* Disable analog and otg block power */
249 writel(phypwr, regs + SAMSUNG_PHYPWR);
250}
251
252/*
253 * The function passed to the usb driver for phy initialization
254 */
255static int samsung_usb2phy_init(struct usb_phy *phy)
256{
257 struct samsung_usbphy *sphy;
258 struct usb_bus *host = NULL;
259 unsigned long flags;
260 int ret = 0;
261
262 sphy = phy_to_sphy(phy);
263
264 host = phy->otg->host;
265
266 /* Enable the phy clock */
267 ret = clk_prepare_enable(sphy->clk);
268 if (ret) {
269 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
270 return ret;
271 }
272
273 spin_lock_irqsave(&sphy->lock, flags);
274
275 if (host) {
276 /* setting default phy-type for USB 2.0 */
277 if (!strstr(dev_name(host->controller), "ehci") ||
278 !strstr(dev_name(host->controller), "ohci"))
279 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
280 } else {
281 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
282 }
283
284 /* Disable phy isolation */
285 if (sphy->plat && sphy->plat->pmu_isolation)
286 sphy->plat->pmu_isolation(false);
287 else
288 samsung_usbphy_set_isolation(sphy, false);
289
290 /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */
291 samsung_usbphy_cfg_sel(sphy);
292
293 /* Initialize usb phy registers */
294 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
295 samsung_exynos5_usb2phy_enable(sphy);
296 else
297 samsung_usb2phy_enable(sphy);
298
299 spin_unlock_irqrestore(&sphy->lock, flags);
300
301 /* Disable the phy clock */
302 clk_disable_unprepare(sphy->clk);
303
304 return ret;
305}
306
307/*
308 * The function passed to the usb driver for phy shutdown
309 */
310static void samsung_usb2phy_shutdown(struct usb_phy *phy)
311{
312 struct samsung_usbphy *sphy;
313 struct usb_bus *host = NULL;
314 unsigned long flags;
315
316 sphy = phy_to_sphy(phy);
317
318 host = phy->otg->host;
319
320 if (clk_prepare_enable(sphy->clk)) {
321 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
322 return;
323 }
324
325 spin_lock_irqsave(&sphy->lock, flags);
326
327 if (host) {
328 /* setting default phy-type for USB 2.0 */
329 if (!strstr(dev_name(host->controller), "ehci") ||
330 !strstr(dev_name(host->controller), "ohci"))
331 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
332 } else {
333 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
334 }
335
336 /* De-initialize usb phy registers */
337 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
338 samsung_exynos5_usb2phy_disable(sphy);
339 else
340 samsung_usb2phy_disable(sphy);
341
342 /* Enable phy isolation */
343 if (sphy->plat && sphy->plat->pmu_isolation)
344 sphy->plat->pmu_isolation(true);
345 else
346 samsung_usbphy_set_isolation(sphy, true);
347
348 spin_unlock_irqrestore(&sphy->lock, flags);
349
350 clk_disable_unprepare(sphy->clk);
351}
352
353static int samsung_usb2phy_probe(struct platform_device *pdev)
354{
355 struct samsung_usbphy *sphy;
356 struct usb_otg *otg;
357 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
358 const struct samsung_usbphy_drvdata *drv_data;
359 struct device *dev = &pdev->dev;
360 struct resource *phy_mem;
361 void __iomem *phy_base;
362 struct clk *clk;
363 int ret;
364
365 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
366 if (!phy_mem) {
367 dev_err(dev, "%s: missing mem resource\n", __func__);
368 return -ENODEV;
369 }
370
371 phy_base = devm_ioremap_resource(dev, phy_mem);
372 if (IS_ERR(phy_base))
373 return PTR_ERR(phy_base);
374
375 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
376 if (!sphy)
377 return -ENOMEM;
378
379 otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
380 if (!otg)
381 return -ENOMEM;
382
383 drv_data = samsung_usbphy_get_driver_data(pdev);
384
385 if (drv_data->cpu_type == TYPE_EXYNOS5250)
386 clk = devm_clk_get(dev, "usbhost");
387 else
388 clk = devm_clk_get(dev, "otg");
389
390 if (IS_ERR(clk)) {
391 dev_err(dev, "Failed to get otg clock\n");
392 return PTR_ERR(clk);
393 }
394
395 sphy->dev = dev;
396
397 if (dev->of_node) {
398 ret = samsung_usbphy_parse_dt(sphy);
399 if (ret < 0)
400 return ret;
401 } else {
402 if (!pdata) {
403 dev_err(dev, "no platform data specified\n");
404 return -EINVAL;
405 }
406 }
407
408 sphy->plat = pdata;
409 sphy->regs = phy_base;
410 sphy->clk = clk;
411 sphy->drv_data = drv_data;
412 sphy->phy.dev = sphy->dev;
413 sphy->phy.label = "samsung-usb2phy";
414 sphy->phy.init = samsung_usb2phy_init;
415 sphy->phy.shutdown = samsung_usb2phy_shutdown;
416 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
417
418 sphy->phy.otg = otg;
419 sphy->phy.otg->phy = &sphy->phy;
420 sphy->phy.otg->set_host = samsung_usbphy_set_host;
421
422 spin_lock_init(&sphy->lock);
423
424 platform_set_drvdata(pdev, sphy);
425
426 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2);
427}
428
429static int samsung_usb2phy_remove(struct platform_device *pdev)
430{
431 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
432
433 usb_remove_phy(&sphy->phy);
434
435 if (sphy->pmuregs)
436 iounmap(sphy->pmuregs);
437 if (sphy->sysreg)
438 iounmap(sphy->sysreg);
439
440 return 0;
441}
442
443static const struct samsung_usbphy_drvdata usb2phy_s3c64xx = {
444 .cpu_type = TYPE_S3C64XX,
445 .devphy_en_mask = S3C64XX_USBPHY_ENABLE,
446};
447
448static const struct samsung_usbphy_drvdata usb2phy_exynos4 = {
449 .cpu_type = TYPE_EXYNOS4210,
450 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
451 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
452};
453
454static struct samsung_usbphy_drvdata usb2phy_exynos5 = {
455 .cpu_type = TYPE_EXYNOS5250,
456 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
457 .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET,
458};
459
460#ifdef CONFIG_OF
461static const struct of_device_id samsung_usbphy_dt_match[] = {
462 {
463 .compatible = "samsung,s3c64xx-usb2phy",
464 .data = &usb2phy_s3c64xx,
465 }, {
466 .compatible = "samsung,exynos4210-usb2phy",
467 .data = &usb2phy_exynos4,
468 }, {
469 .compatible = "samsung,exynos5250-usb2phy",
470 .data = &usb2phy_exynos5
471 },
472 {},
473};
474MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
475#endif
476
477static struct platform_device_id samsung_usbphy_driver_ids[] = {
478 {
479 .name = "s3c64xx-usb2phy",
480 .driver_data = (unsigned long)&usb2phy_s3c64xx,
481 }, {
482 .name = "exynos4210-usb2phy",
483 .driver_data = (unsigned long)&usb2phy_exynos4,
484 }, {
485 .name = "exynos5250-usb2phy",
486 .driver_data = (unsigned long)&usb2phy_exynos5,
487 },
488 {},
489};
490
491MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
492
493static struct platform_driver samsung_usb2phy_driver = {
494 .probe = samsung_usb2phy_probe,
495 .remove = samsung_usb2phy_remove,
496 .id_table = samsung_usbphy_driver_ids,
497 .driver = {
498 .name = "samsung-usb2phy",
499 .owner = THIS_MODULE,
500 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
501 },
502};
503
504module_platform_driver(samsung_usb2phy_driver);
505
506MODULE_DESCRIPTION("Samsung USB 2.0 phy controller");
507MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>");
508MODULE_LICENSE("GPL");
509MODULE_ALIAS("platform:samsung-usb2phy");
diff --git a/drivers/usb/phy/phy-samsung-usb3.c b/drivers/usb/phy/phy-samsung-usb3.c
new file mode 100644
index 000000000000..133f3d0c554f
--- /dev/null
+++ b/drivers/usb/phy/phy-samsung-usb3.c
@@ -0,0 +1,347 @@
1/* linux/drivers/usb/phy/phy-samsung-usb3.c
2 *
3 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Vivek Gautam <gautam.vivek@samsung.com>
7 *
8 * Samsung USB 3.0 PHY transceiver; talks to DWC3 controller.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
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
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/clk.h>
23#include <linux/delay.h>
24#include <linux/err.h>
25#include <linux/io.h>
26#include <linux/of.h>
27#include <linux/usb/samsung_usb_phy.h>
28#include <linux/platform_data/samsung-usbphy.h>
29
30#include "phy-samsung-usb.h"
31
32/*
33 * Sets the phy clk as EXTREFCLK (XXTI) which is internal clock from clock core.
34 */
35static u32 samsung_usb3phy_set_refclk(struct samsung_usbphy *sphy)
36{
37 u32 reg;
38 u32 refclk;
39
40 refclk = sphy->ref_clk_freq;
41
42 reg = PHYCLKRST_REFCLKSEL_EXT_REFCLK |
43 PHYCLKRST_FSEL(refclk);
44
45 switch (refclk) {
46 case FSEL_CLKSEL_50M:
47 reg |= (PHYCLKRST_MPLL_MULTIPLIER_50M_REF |
48 PHYCLKRST_SSC_REFCLKSEL(0x00));
49 break;
50 case FSEL_CLKSEL_20M:
51 reg |= (PHYCLKRST_MPLL_MULTIPLIER_20MHZ_REF |
52 PHYCLKRST_SSC_REFCLKSEL(0x00));
53 break;
54 case FSEL_CLKSEL_19200K:
55 reg |= (PHYCLKRST_MPLL_MULTIPLIER_19200KHZ_REF |
56 PHYCLKRST_SSC_REFCLKSEL(0x88));
57 break;
58 case FSEL_CLKSEL_24M:
59 default:
60 reg |= (PHYCLKRST_MPLL_MULTIPLIER_24MHZ_REF |
61 PHYCLKRST_SSC_REFCLKSEL(0x88));
62 break;
63 }
64
65 return reg;
66}
67
68static int samsung_exynos5_usb3phy_enable(struct samsung_usbphy *sphy)
69{
70 void __iomem *regs = sphy->regs;
71 u32 phyparam0;
72 u32 phyparam1;
73 u32 linksystem;
74 u32 phybatchg;
75 u32 phytest;
76 u32 phyclkrst;
77
78 /* Reset USB 3.0 PHY */
79 writel(0x0, regs + EXYNOS5_DRD_PHYREG0);
80
81 phyparam0 = readl(regs + EXYNOS5_DRD_PHYPARAM0);
82 /* Select PHY CLK source */
83 phyparam0 &= ~PHYPARAM0_REF_USE_PAD;
84 /* Set Loss-of-Signal Detector sensitivity */
85 phyparam0 &= ~PHYPARAM0_REF_LOSLEVEL_MASK;
86 phyparam0 |= PHYPARAM0_REF_LOSLEVEL;
87 writel(phyparam0, regs + EXYNOS5_DRD_PHYPARAM0);
88
89 writel(0x0, regs + EXYNOS5_DRD_PHYRESUME);
90
91 /*
92 * Setting the Frame length Adj value[6:1] to default 0x20
93 * See xHCI 1.0 spec, 5.2.4
94 */
95 linksystem = LINKSYSTEM_XHCI_VERSION_CONTROL |
96 LINKSYSTEM_FLADJ(0x20);
97 writel(linksystem, regs + EXYNOS5_DRD_LINKSYSTEM);
98
99 phyparam1 = readl(regs + EXYNOS5_DRD_PHYPARAM1);
100 /* Set Tx De-Emphasis level */
101 phyparam1 &= ~PHYPARAM1_PCS_TXDEEMPH_MASK;
102 phyparam1 |= PHYPARAM1_PCS_TXDEEMPH;
103 writel(phyparam1, regs + EXYNOS5_DRD_PHYPARAM1);
104
105 phybatchg = readl(regs + EXYNOS5_DRD_PHYBATCHG);
106 phybatchg |= PHYBATCHG_UTMI_CLKSEL;
107 writel(phybatchg, regs + EXYNOS5_DRD_PHYBATCHG);
108
109 /* PHYTEST POWERDOWN Control */
110 phytest = readl(regs + EXYNOS5_DRD_PHYTEST);
111 phytest &= ~(PHYTEST_POWERDOWN_SSP |
112 PHYTEST_POWERDOWN_HSP);
113 writel(phytest, regs + EXYNOS5_DRD_PHYTEST);
114
115 /* UTMI Power Control */
116 writel(PHYUTMI_OTGDISABLE, regs + EXYNOS5_DRD_PHYUTMI);
117
118 phyclkrst = samsung_usb3phy_set_refclk(sphy);
119
120 phyclkrst |= PHYCLKRST_PORTRESET |
121 /* Digital power supply in normal operating mode */
122 PHYCLKRST_RETENABLEN |
123 /* Enable ref clock for SS function */
124 PHYCLKRST_REF_SSP_EN |
125 /* Enable spread spectrum */
126 PHYCLKRST_SSC_EN |
127 /* Power down HS Bias and PLL blocks in suspend mode */
128 PHYCLKRST_COMMONONN;
129
130 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
131
132 udelay(10);
133
134 phyclkrst &= ~(PHYCLKRST_PORTRESET);
135 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
136
137 return 0;
138}
139
140static void samsung_exynos5_usb3phy_disable(struct samsung_usbphy *sphy)
141{
142 u32 phyutmi;
143 u32 phyclkrst;
144 u32 phytest;
145 void __iomem *regs = sphy->regs;
146
147 phyutmi = PHYUTMI_OTGDISABLE |
148 PHYUTMI_FORCESUSPEND |
149 PHYUTMI_FORCESLEEP;
150 writel(phyutmi, regs + EXYNOS5_DRD_PHYUTMI);
151
152 /* Resetting the PHYCLKRST enable bits to reduce leakage current */
153 phyclkrst = readl(regs + EXYNOS5_DRD_PHYCLKRST);
154 phyclkrst &= ~(PHYCLKRST_REF_SSP_EN |
155 PHYCLKRST_SSC_EN |
156 PHYCLKRST_COMMONONN);
157 writel(phyclkrst, regs + EXYNOS5_DRD_PHYCLKRST);
158
159 /* Control PHYTEST to remove leakage current */
160 phytest = readl(regs + EXYNOS5_DRD_PHYTEST);
161 phytest |= (PHYTEST_POWERDOWN_SSP |
162 PHYTEST_POWERDOWN_HSP);
163 writel(phytest, regs + EXYNOS5_DRD_PHYTEST);
164}
165
166static int samsung_usb3phy_init(struct usb_phy *phy)
167{
168 struct samsung_usbphy *sphy;
169 unsigned long flags;
170 int ret = 0;
171
172 sphy = phy_to_sphy(phy);
173
174 /* Enable the phy clock */
175 ret = clk_prepare_enable(sphy->clk);
176 if (ret) {
177 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
178 return ret;
179 }
180
181 spin_lock_irqsave(&sphy->lock, flags);
182
183 /* setting default phy-type for USB 3.0 */
184 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
185
186 /* Disable phy isolation */
187 samsung_usbphy_set_isolation(sphy, false);
188
189 /* Initialize usb phy registers */
190 samsung_exynos5_usb3phy_enable(sphy);
191
192 spin_unlock_irqrestore(&sphy->lock, flags);
193
194 /* Disable the phy clock */
195 clk_disable_unprepare(sphy->clk);
196
197 return ret;
198}
199
200/*
201 * The function passed to the usb driver for phy shutdown
202 */
203static void samsung_usb3phy_shutdown(struct usb_phy *phy)
204{
205 struct samsung_usbphy *sphy;
206 unsigned long flags;
207
208 sphy = phy_to_sphy(phy);
209
210 if (clk_prepare_enable(sphy->clk)) {
211 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
212 return;
213 }
214
215 spin_lock_irqsave(&sphy->lock, flags);
216
217 /* setting default phy-type for USB 3.0 */
218 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
219
220 /* De-initialize usb phy registers */
221 samsung_exynos5_usb3phy_disable(sphy);
222
223 /* Enable phy isolation */
224 samsung_usbphy_set_isolation(sphy, true);
225
226 spin_unlock_irqrestore(&sphy->lock, flags);
227
228 clk_disable_unprepare(sphy->clk);
229}
230
231static int samsung_usb3phy_probe(struct platform_device *pdev)
232{
233 struct samsung_usbphy *sphy;
234 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
235 struct device *dev = &pdev->dev;
236 struct resource *phy_mem;
237 void __iomem *phy_base;
238 struct clk *clk;
239 int ret;
240
241 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
242 if (!phy_mem) {
243 dev_err(dev, "%s: missing mem resource\n", __func__);
244 return -ENODEV;
245 }
246
247 phy_base = devm_ioremap_resource(dev, phy_mem);
248 if (IS_ERR(phy_base))
249 return PTR_ERR(phy_base);
250
251 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
252 if (!sphy)
253 return -ENOMEM;
254
255 clk = devm_clk_get(dev, "usbdrd30");
256 if (IS_ERR(clk)) {
257 dev_err(dev, "Failed to get device clock\n");
258 return PTR_ERR(clk);
259 }
260
261 sphy->dev = dev;
262
263 if (dev->of_node) {
264 ret = samsung_usbphy_parse_dt(sphy);
265 if (ret < 0)
266 return ret;
267 } else {
268 if (!pdata) {
269 dev_err(dev, "no platform data specified\n");
270 return -EINVAL;
271 }
272 }
273
274 sphy->plat = pdata;
275 sphy->regs = phy_base;
276 sphy->clk = clk;
277 sphy->phy.dev = sphy->dev;
278 sphy->phy.label = "samsung-usb3phy";
279 sphy->phy.init = samsung_usb3phy_init;
280 sphy->phy.shutdown = samsung_usb3phy_shutdown;
281 sphy->drv_data = samsung_usbphy_get_driver_data(pdev);
282 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
283
284 spin_lock_init(&sphy->lock);
285
286 platform_set_drvdata(pdev, sphy);
287
288 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB3);
289}
290
291static int samsung_usb3phy_remove(struct platform_device *pdev)
292{
293 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
294
295 usb_remove_phy(&sphy->phy);
296
297 if (sphy->pmuregs)
298 iounmap(sphy->pmuregs);
299 if (sphy->sysreg)
300 iounmap(sphy->sysreg);
301
302 return 0;
303}
304
305static struct samsung_usbphy_drvdata usb3phy_exynos5 = {
306 .cpu_type = TYPE_EXYNOS5250,
307 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
308};
309
310#ifdef CONFIG_OF
311static const struct of_device_id samsung_usbphy_dt_match[] = {
312 {
313 .compatible = "samsung,exynos5250-usb3phy",
314 .data = &usb3phy_exynos5
315 },
316 {},
317};
318MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
319#endif
320
321static struct platform_device_id samsung_usbphy_driver_ids[] = {
322 {
323 .name = "exynos5250-usb3phy",
324 .driver_data = (unsigned long)&usb3phy_exynos5,
325 },
326 {},
327};
328
329MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
330
331static struct platform_driver samsung_usb3phy_driver = {
332 .probe = samsung_usb3phy_probe,
333 .remove = samsung_usb3phy_remove,
334 .id_table = samsung_usbphy_driver_ids,
335 .driver = {
336 .name = "samsung-usb3phy",
337 .owner = THIS_MODULE,
338 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
339 },
340};
341
342module_platform_driver(samsung_usb3phy_driver);
343
344MODULE_DESCRIPTION("Samsung USB 3.0 phy controller");
345MODULE_AUTHOR("Vivek Gautam <gautam.vivek@samsung.com>");
346MODULE_LICENSE("GPL");
347MODULE_ALIAS("platform:samsung-usb3phy");
diff --git a/drivers/usb/phy/tegra_usb_phy.c b/drivers/usb/phy/phy-tegra-usb.c
index 5487d38481af..17d811292f3a 100644
--- a/drivers/usb/phy/tegra_usb_phy.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -299,7 +299,7 @@ static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
299 val &= ~USB_SUSP_SET; 299 val &= ~USB_SUSP_SET;
300 writel(val, base + USB_SUSP_CTRL); 300 writel(val, base + USB_SUSP_CTRL);
301 } else 301 } else
302 tegra_ehci_set_phcd(&phy->u_phy, true); 302 phy->set_phcd(&phy->u_phy, true);
303 303
304 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0) 304 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
305 pr_err("%s: timeout waiting for phy to stabilize\n", __func__); 305 pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
@@ -321,7 +321,7 @@ static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
321 val &= ~USB_SUSP_CLR; 321 val &= ~USB_SUSP_CLR;
322 writel(val, base + USB_SUSP_CTRL); 322 writel(val, base + USB_SUSP_CTRL);
323 } else 323 } else
324 tegra_ehci_set_phcd(&phy->u_phy, false); 324 phy->set_phcd(&phy->u_phy, false);
325 325
326 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 326 if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
327 USB_PHY_CLK_VALID)) 327 USB_PHY_CLK_VALID))
@@ -444,7 +444,7 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
444 utmi_phy_clk_enable(phy); 444 utmi_phy_clk_enable(phy);
445 445
446 if (!phy->is_legacy_phy) 446 if (!phy->is_legacy_phy)
447 tegra_ehci_set_pts(&phy->u_phy, 0); 447 phy->set_pts(&phy->u_phy, 0);
448 448
449 return 0; 449 return 0;
450} 450}
@@ -688,7 +688,10 @@ static int tegra_usb_phy_suspend(struct usb_phy *x, int suspend)
688} 688}
689 689
690struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance, 690struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
691 void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode) 691 void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode,
692 void (*set_pts)(struct usb_phy *x, u8 pts_val),
693 void (*set_phcd)(struct usb_phy *x, bool enable))
694
692{ 695{
693 struct tegra_usb_phy *phy; 696 struct tegra_usb_phy *phy;
694 unsigned long parent_rate; 697 unsigned long parent_rate;
@@ -707,6 +710,8 @@ struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
707 phy->dev = dev; 710 phy->dev = dev;
708 phy->is_legacy_phy = 711 phy->is_legacy_phy =
709 of_property_read_bool(np, "nvidia,has-legacy-mode"); 712 of_property_read_bool(np, "nvidia,has-legacy-mode");
713 phy->set_pts = set_pts;
714 phy->set_phcd = set_phcd;
710 err = of_property_match_string(np, "phy_type", "ulpi"); 715 err = of_property_match_string(np, "phy_type", "ulpi");
711 if (err < 0) 716 if (err < 0)
712 phy->is_ulpi_phy = false; 717 phy->is_ulpi_phy = false;
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/phy/phy-twl4030-usb.c
index a994715a3101..8f78d2d40722 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/phy/phy-twl4030-usb.c
@@ -163,6 +163,8 @@ struct twl4030_usb {
163 bool vbus_supplied; 163 bool vbus_supplied;
164 u8 asleep; 164 u8 asleep;
165 bool irq_enabled; 165 bool irq_enabled;
166
167 struct delayed_work id_workaround_work;
166}; 168};
167 169
168/* internal define on top of container_of */ 170/* internal define on top of container_of */
@@ -246,6 +248,25 @@ twl4030_usb_clear_bits(struct twl4030_usb *twl, u8 reg, u8 bits)
246 248
247/*-------------------------------------------------------------------------*/ 249/*-------------------------------------------------------------------------*/
248 250
251static bool twl4030_is_driving_vbus(struct twl4030_usb *twl)
252{
253 int ret;
254
255 ret = twl4030_usb_read(twl, PHY_CLK_CTRL_STS);
256 if (ret < 0 || !(ret & PHY_DPLL_CLK))
257 /*
258 * if clocks are off, registers are not updated,
259 * but we can assume we don't drive VBUS in this case
260 */
261 return false;
262
263 ret = twl4030_usb_read(twl, ULPI_OTG_CTRL);
264 if (ret < 0)
265 return false;
266
267 return (ret & (ULPI_OTG_DRVVBUS | ULPI_OTG_CHRGVBUS)) ? true : false;
268}
269
249static enum omap_musb_vbus_id_status 270static enum omap_musb_vbus_id_status
250 twl4030_usb_linkstat(struct twl4030_usb *twl) 271 twl4030_usb_linkstat(struct twl4030_usb *twl)
251{ 272{
@@ -268,13 +289,19 @@ static enum omap_musb_vbus_id_status
268 if (status < 0) 289 if (status < 0)
269 dev_err(twl->dev, "USB link status err %d\n", status); 290 dev_err(twl->dev, "USB link status err %d\n", status);
270 else if (status & (BIT(7) | BIT(2))) { 291 else if (status & (BIT(7) | BIT(2))) {
271 if (status & (BIT(7))) 292 if (status & BIT(7)) {
272 twl->vbus_supplied = true; 293 if (twl4030_is_driving_vbus(twl))
294 status &= ~BIT(7);
295 else
296 twl->vbus_supplied = true;
297 }
273 298
274 if (status & BIT(2)) 299 if (status & BIT(2))
275 linkstat = OMAP_MUSB_ID_GROUND; 300 linkstat = OMAP_MUSB_ID_GROUND;
276 else 301 else if (status & BIT(7))
277 linkstat = OMAP_MUSB_VBUS_VALID; 302 linkstat = OMAP_MUSB_VBUS_VALID;
303 else
304 linkstat = OMAP_MUSB_VBUS_OFF;
278 } else { 305 } else {
279 if (twl->linkstat != OMAP_MUSB_UNKNOWN) 306 if (twl->linkstat != OMAP_MUSB_UNKNOWN)
280 linkstat = OMAP_MUSB_VBUS_OFF; 307 linkstat = OMAP_MUSB_VBUS_OFF;
@@ -287,10 +314,6 @@ static enum omap_musb_vbus_id_status
287 * are registered, and that both are active... 314 * are registered, and that both are active...
288 */ 315 */
289 316
290 spin_lock_irq(&twl->lock);
291 twl->linkstat = linkstat;
292 spin_unlock_irq(&twl->lock);
293
294 return linkstat; 317 return linkstat;
295} 318}
296 319
@@ -361,9 +384,17 @@ static void __twl4030_phy_power(struct twl4030_usb *twl, int on)
361 384
362static void twl4030_phy_power(struct twl4030_usb *twl, int on) 385static void twl4030_phy_power(struct twl4030_usb *twl, int on)
363{ 386{
387 int ret;
388
364 if (on) { 389 if (on) {
365 regulator_enable(twl->usb3v1); 390 ret = regulator_enable(twl->usb3v1);
366 regulator_enable(twl->usb1v8); 391 if (ret)
392 dev_err(twl->dev, "Failed to enable usb3v1\n");
393
394 ret = regulator_enable(twl->usb1v8);
395 if (ret)
396 dev_err(twl->dev, "Failed to enable usb1v8\n");
397
367 /* 398 /*
368 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP 399 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP
369 * in twl4030) resets the VUSB_DEDICATED2 register. This reset 400 * in twl4030) resets the VUSB_DEDICATED2 register. This reset
@@ -372,7 +403,11 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
372 * is re-activated. This ensures that VUSB3V1 is really active. 403 * is re-activated. This ensures that VUSB3V1 is really active.
373 */ 404 */
374 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); 405 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);
375 regulator_enable(twl->usb1v5); 406
407 ret = regulator_enable(twl->usb1v5);
408 if (ret)
409 dev_err(twl->dev, "Failed to enable usb1v5\n");
410
376 __twl4030_phy_power(twl, 1); 411 __twl4030_phy_power(twl, 1);
377 twl4030_usb_write(twl, PHY_CLK_CTRL, 412 twl4030_usb_write(twl, PHY_CLK_CTRL,
378 twl4030_usb_read(twl, PHY_CLK_CTRL) | 413 twl4030_usb_read(twl, PHY_CLK_CTRL) |
@@ -412,6 +447,16 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
412 __twl4030_phy_resume(twl); 447 __twl4030_phy_resume(twl);
413 twl->asleep = 0; 448 twl->asleep = 0;
414 dev_dbg(twl->dev, "%s\n", __func__); 449 dev_dbg(twl->dev, "%s\n", __func__);
450
451 /*
452 * XXX When VBUS gets driven after musb goes to A mode,
453 * ID_PRES related interrupts no longer arrive, why?
454 * Register itself is updated fine though, so we must poll.
455 */
456 if (twl->linkstat == OMAP_MUSB_ID_GROUND) {
457 cancel_delayed_work(&twl->id_workaround_work);
458 schedule_delayed_work(&twl->id_workaround_work, HZ);
459 }
415} 460}
416 461
417static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 462static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
@@ -432,7 +477,7 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
432 /* Initialize 3.1V regulator */ 477 /* Initialize 3.1V regulator */
433 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP); 478 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP);
434 479
435 twl->usb3v1 = regulator_get(twl->dev, "usb3v1"); 480 twl->usb3v1 = devm_regulator_get(twl->dev, "usb3v1");
436 if (IS_ERR(twl->usb3v1)) 481 if (IS_ERR(twl->usb3v1))
437 return -ENODEV; 482 return -ENODEV;
438 483
@@ -441,18 +486,18 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
441 /* Initialize 1.5V regulator */ 486 /* Initialize 1.5V regulator */
442 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP); 487 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP);
443 488
444 twl->usb1v5 = regulator_get(twl->dev, "usb1v5"); 489 twl->usb1v5 = devm_regulator_get(twl->dev, "usb1v5");
445 if (IS_ERR(twl->usb1v5)) 490 if (IS_ERR(twl->usb1v5))
446 goto fail1; 491 return -ENODEV;
447 492
448 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); 493 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
449 494
450 /* Initialize 1.8V regulator */ 495 /* Initialize 1.8V regulator */
451 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP); 496 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP);
452 497
453 twl->usb1v8 = regulator_get(twl->dev, "usb1v8"); 498 twl->usb1v8 = devm_regulator_get(twl->dev, "usb1v8");
454 if (IS_ERR(twl->usb1v8)) 499 if (IS_ERR(twl->usb1v8))
455 goto fail2; 500 return -ENODEV;
456 501
457 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); 502 twl_i2c_write_u8(TWL_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
458 503
@@ -461,14 +506,6 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
461 TWL4030_PM_MASTER_PROTECT_KEY); 506 TWL4030_PM_MASTER_PROTECT_KEY);
462 507
463 return 0; 508 return 0;
464
465fail2:
466 regulator_put(twl->usb1v5);
467 twl->usb1v5 = NULL;
468fail1:
469 regulator_put(twl->usb3v1);
470 twl->usb3v1 = NULL;
471 return -ENODEV;
472} 509}
473 510
474static ssize_t twl4030_usb_vbus_show(struct device *dev, 511static ssize_t twl4030_usb_vbus_show(struct device *dev,
@@ -491,9 +528,18 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
491{ 528{
492 struct twl4030_usb *twl = _twl; 529 struct twl4030_usb *twl = _twl;
493 enum omap_musb_vbus_id_status status; 530 enum omap_musb_vbus_id_status status;
531 bool status_changed = false;
494 532
495 status = twl4030_usb_linkstat(twl); 533 status = twl4030_usb_linkstat(twl);
496 if (status > 0) { 534
535 spin_lock_irq(&twl->lock);
536 if (status >= 0 && status != twl->linkstat) {
537 twl->linkstat = status;
538 status_changed = true;
539 }
540 spin_unlock_irq(&twl->lock);
541
542 if (status_changed) {
497 /* FIXME add a set_power() method so that B-devices can 543 /* FIXME add a set_power() method so that B-devices can
498 * configure the charger appropriately. It's not always 544 * configure the charger appropriately. It's not always
499 * correct to consume VBUS power, and how much current to 545 * correct to consume VBUS power, and how much current to
@@ -505,37 +551,62 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
505 * USB_LINK_VBUS state. musb_hdrc won't care until it 551 * USB_LINK_VBUS state. musb_hdrc won't care until it
506 * starts to handle softconnect right. 552 * starts to handle softconnect right.
507 */ 553 */
508 if (status == OMAP_MUSB_VBUS_OFF || 554 omap_musb_mailbox(status);
509 status == OMAP_MUSB_ID_FLOAT)
510 twl4030_phy_suspend(twl, 0);
511 else
512 twl4030_phy_resume(twl);
513
514 omap_musb_mailbox(twl->linkstat);
515 } 555 }
516 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 556 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
517 557
518 return IRQ_HANDLED; 558 return IRQ_HANDLED;
519} 559}
520 560
521static void twl4030_usb_phy_init(struct twl4030_usb *twl) 561static void twl4030_id_workaround_work(struct work_struct *work)
522{ 562{
563 struct twl4030_usb *twl = container_of(work, struct twl4030_usb,
564 id_workaround_work.work);
523 enum omap_musb_vbus_id_status status; 565 enum omap_musb_vbus_id_status status;
566 bool status_changed = false;
524 567
525 status = twl4030_usb_linkstat(twl); 568 status = twl4030_usb_linkstat(twl);
526 if (status > 0) {
527 if (status == OMAP_MUSB_VBUS_OFF ||
528 status == OMAP_MUSB_ID_FLOAT) {
529 __twl4030_phy_power(twl, 0);
530 twl->asleep = 1;
531 } else {
532 __twl4030_phy_resume(twl);
533 twl->asleep = 0;
534 }
535 569
536 omap_musb_mailbox(twl->linkstat); 570 spin_lock_irq(&twl->lock);
571 if (status >= 0 && status != twl->linkstat) {
572 twl->linkstat = status;
573 status_changed = true;
574 }
575 spin_unlock_irq(&twl->lock);
576
577 if (status_changed) {
578 dev_dbg(twl->dev, "handle missing status change to %d\n",
579 status);
580 omap_musb_mailbox(status);
537 } 581 }
582
583 /* don't schedule during sleep - irq works right then */
584 if (status == OMAP_MUSB_ID_GROUND && !twl->asleep) {
585 cancel_delayed_work(&twl->id_workaround_work);
586 schedule_delayed_work(&twl->id_workaround_work, HZ);
587 }
588}
589
590static int twl4030_usb_phy_init(struct usb_phy *phy)
591{
592 struct twl4030_usb *twl = phy_to_twl(phy);
593 enum omap_musb_vbus_id_status status;
594
595 /*
596 * Start in sleep state, we'll get called through set_suspend()
597 * callback when musb is runtime resumed and it's time to start.
598 */
599 __twl4030_phy_power(twl, 0);
600 twl->asleep = 1;
601
602 status = twl4030_usb_linkstat(twl);
603 twl->linkstat = status;
604
605 if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
606 omap_musb_mailbox(twl->linkstat);
607
538 sysfs_notify(&twl->dev->kobj, NULL, "vbus"); 608 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
609 return 0;
539} 610}
540 611
541static int twl4030_set_suspend(struct usb_phy *x, int suspend) 612static int twl4030_set_suspend(struct usb_phy *x, int suspend)
@@ -612,6 +683,7 @@ static int twl4030_usb_probe(struct platform_device *pdev)
612 twl->phy.otg = otg; 683 twl->phy.otg = otg;
613 twl->phy.type = USB_PHY_TYPE_USB2; 684 twl->phy.type = USB_PHY_TYPE_USB2;
614 twl->phy.set_suspend = twl4030_set_suspend; 685 twl->phy.set_suspend = twl4030_set_suspend;
686 twl->phy.init = twl4030_usb_phy_init;
615 687
616 otg->phy = &twl->phy; 688 otg->phy = &twl->phy;
617 otg->set_host = twl4030_set_host; 689 otg->set_host = twl4030_set_host;
@@ -620,6 +692,8 @@ static int twl4030_usb_probe(struct platform_device *pdev)
620 /* init spinlock for workqueue */ 692 /* init spinlock for workqueue */
621 spin_lock_init(&twl->lock); 693 spin_lock_init(&twl->lock);
622 694
695 INIT_DELAYED_WORK(&twl->id_workaround_work, twl4030_id_workaround_work);
696
623 err = twl4030_usb_ldo_init(twl); 697 err = twl4030_usb_ldo_init(twl);
624 if (err) { 698 if (err) {
625 dev_err(&pdev->dev, "ldo init failed\n"); 699 dev_err(&pdev->dev, "ldo init failed\n");
@@ -640,30 +714,25 @@ static int twl4030_usb_probe(struct platform_device *pdev)
640 * need both handles, otherwise just one suffices. 714 * need both handles, otherwise just one suffices.
641 */ 715 */
642 twl->irq_enabled = true; 716 twl->irq_enabled = true;
643 status = request_threaded_irq(twl->irq, NULL, twl4030_usb_irq, 717 status = devm_request_threaded_irq(twl->dev, twl->irq, NULL,
644 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | 718 twl4030_usb_irq, IRQF_TRIGGER_FALLING |
645 IRQF_ONESHOT, "twl4030_usb", twl); 719 IRQF_TRIGGER_RISING | IRQF_ONESHOT, "twl4030_usb", twl);
646 if (status < 0) { 720 if (status < 0) {
647 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n", 721 dev_dbg(&pdev->dev, "can't get IRQ %d, err %d\n",
648 twl->irq, status); 722 twl->irq, status);
649 return status; 723 return status;
650 } 724 }
651 725
652 /* Power down phy or make it work according to
653 * current link state.
654 */
655 twl4030_usb_phy_init(twl);
656
657 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); 726 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
658 return 0; 727 return 0;
659} 728}
660 729
661static int __exit twl4030_usb_remove(struct platform_device *pdev) 730static int twl4030_usb_remove(struct platform_device *pdev)
662{ 731{
663 struct twl4030_usb *twl = platform_get_drvdata(pdev); 732 struct twl4030_usb *twl = platform_get_drvdata(pdev);
664 int val; 733 int val;
665 734
666 free_irq(twl->irq, twl); 735 cancel_delayed_work(&twl->id_workaround_work);
667 device_remove_file(twl->dev, &dev_attr_vbus); 736 device_remove_file(twl->dev, &dev_attr_vbus);
668 737
669 /* set transceiver mode to power on defaults */ 738 /* set transceiver mode to power on defaults */
@@ -685,9 +754,6 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
685 754
686 if (!twl->asleep) 755 if (!twl->asleep)
687 twl4030_phy_power(twl, 0); 756 twl4030_phy_power(twl, 0);
688 regulator_put(twl->usb1v5);
689 regulator_put(twl->usb1v8);
690 regulator_put(twl->usb3v1);
691 757
692 return 0; 758 return 0;
693} 759}
@@ -702,7 +768,7 @@ MODULE_DEVICE_TABLE(of, twl4030_usb_id_table);
702 768
703static struct platform_driver twl4030_usb_driver = { 769static struct platform_driver twl4030_usb_driver = {
704 .probe = twl4030_usb_probe, 770 .probe = twl4030_usb_probe,
705 .remove = __exit_p(twl4030_usb_remove), 771 .remove = twl4030_usb_remove,
706 .driver = { 772 .driver = {
707 .name = "twl4030_usb", 773 .name = "twl4030_usb",
708 .owner = THIS_MODULE, 774 .owner = THIS_MODULE,
diff --git a/drivers/usb/otg/twl6030-usb.c b/drivers/usb/phy/phy-twl6030-usb.c
index 8cd6cf49bdbd..9de7ada90a8b 100644
--- a/drivers/usb/otg/twl6030-usb.c
+++ b/drivers/usb/phy/phy-twl6030-usb.c
@@ -211,6 +211,7 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
211 struct twl6030_usb *twl = _twl; 211 struct twl6030_usb *twl = _twl;
212 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 212 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
213 u8 vbus_state, hw_state; 213 u8 vbus_state, hw_state;
214 int ret;
214 215
215 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 216 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
216 217
@@ -218,7 +219,10 @@ static irqreturn_t twl6030_usb_irq(int irq, void *_twl)
218 CONTROLLER_STAT1); 219 CONTROLLER_STAT1);
219 if (!(hw_state & STS_USB_ID)) { 220 if (!(hw_state & STS_USB_ID)) {
220 if (vbus_state & VBUS_DET) { 221 if (vbus_state & VBUS_DET) {
221 regulator_enable(twl->usb3v3); 222 ret = regulator_enable(twl->usb3v3);
223 if (ret)
224 dev_err(twl->dev, "Failed to enable usb3v3\n");
225
222 twl->asleep = 1; 226 twl->asleep = 1;
223 status = OMAP_MUSB_VBUS_VALID; 227 status = OMAP_MUSB_VBUS_VALID;
224 twl->linkstat = status; 228 twl->linkstat = status;
@@ -245,12 +249,15 @@ static irqreturn_t twl6030_usbotg_irq(int irq, void *_twl)
245 struct twl6030_usb *twl = _twl; 249 struct twl6030_usb *twl = _twl;
246 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN; 250 enum omap_musb_vbus_id_status status = OMAP_MUSB_UNKNOWN;
247 u8 hw_state; 251 u8 hw_state;
252 int ret;
248 253
249 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS); 254 hw_state = twl6030_readb(twl, TWL6030_MODULE_ID0, STS_HW_CONDITIONS);
250 255
251 if (hw_state & STS_USB_ID) { 256 if (hw_state & STS_USB_ID) {
257 ret = regulator_enable(twl->usb3v3);
258 if (ret)
259 dev_err(twl->dev, "Failed to enable usb3v3\n");
252 260
253 regulator_enable(twl->usb3v3);
254 twl->asleep = 1; 261 twl->asleep = 1;
255 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR); 262 twl6030_writeb(twl, TWL_MODULE_USB, 0x1, USB_ID_INT_EN_HI_CLR);
256 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET); 263 twl6030_writeb(twl, TWL_MODULE_USB, 0x10, USB_ID_INT_EN_HI_SET);
@@ -393,7 +400,7 @@ static int twl6030_usb_probe(struct platform_device *pdev)
393 return 0; 400 return 0;
394} 401}
395 402
396static int __exit twl6030_usb_remove(struct platform_device *pdev) 403static int twl6030_usb_remove(struct platform_device *pdev)
397{ 404{
398 struct twl6030_usb *twl = platform_get_drvdata(pdev); 405 struct twl6030_usb *twl = platform_get_drvdata(pdev);
399 406
@@ -420,7 +427,7 @@ MODULE_DEVICE_TABLE(of, twl6030_usb_id_table);
420 427
421static struct platform_driver twl6030_usb_driver = { 428static struct platform_driver twl6030_usb_driver = {
422 .probe = twl6030_usb_probe, 429 .probe = twl6030_usb_probe,
423 .remove = __exit_p(twl6030_usb_remove), 430 .remove = twl6030_usb_remove,
424 .driver = { 431 .driver = {
425 .name = "twl6030_usb", 432 .name = "twl6030_usb",
426 .owner = THIS_MODULE, 433 .owner = THIS_MODULE,
diff --git a/drivers/usb/otg/ulpi_viewport.c b/drivers/usb/phy/phy-ulpi-viewport.c
index c5ba7e5423fc..c5ba7e5423fc 100644
--- a/drivers/usb/otg/ulpi_viewport.c
+++ b/drivers/usb/phy/phy-ulpi-viewport.c
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/phy/phy-ulpi.c
index 217339dd7a90..217339dd7a90 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/phy/phy-ulpi.c
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/phy/phy.c
index 2bd03d261a50..a9984c700d2c 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/phy/phy.c
@@ -1,14 +1,13 @@
1/* 1/*
2 * otg.c -- USB OTG utility code 2 * phy.c -- USB phy handling
3 * 3 *
4 * Copyright (C) 2004 Texas Instruments 4 * Copyright (C) 2004-2013 Texas Instruments
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 */ 10 */
11
12#include <linux/kernel.h> 11#include <linux/kernel.h>
13#include <linux/export.h> 12#include <linux/export.h>
14#include <linux/err.h> 13#include <linux/err.h>
@@ -17,7 +16,7 @@
17#include <linux/slab.h> 16#include <linux/slab.h>
18#include <linux/of.h> 17#include <linux/of.h>
19 18
20#include <linux/usb/otg.h> 19#include <linux/usb/phy.h>
21 20
22static LIST_HEAD(phy_list); 21static LIST_HEAD(phy_list);
23static LIST_HEAD(phy_bind_list); 22static LIST_HEAD(phy_bind_list);
@@ -110,7 +109,7 @@ struct usb_phy *devm_usb_get_phy(struct device *dev, enum usb_phy_type type)
110 109
111 return phy; 110 return phy;
112} 111}
113EXPORT_SYMBOL(devm_usb_get_phy); 112EXPORT_SYMBOL_GPL(devm_usb_get_phy);
114 113
115/** 114/**
116 * usb_get_phy - find the USB PHY 115 * usb_get_phy - find the USB PHY
@@ -143,7 +142,7 @@ err0:
143 142
144 return phy; 143 return phy;
145} 144}
146EXPORT_SYMBOL(usb_get_phy); 145EXPORT_SYMBOL_GPL(usb_get_phy);
147 146
148 /** 147 /**
149 * devm_usb_get_phy_by_phandle - find the USB PHY by phandle 148 * devm_usb_get_phy_by_phandle - find the USB PHY by phandle
@@ -207,7 +206,7 @@ err0:
207 206
208 return phy; 207 return phy;
209} 208}
210EXPORT_SYMBOL(devm_usb_get_phy_by_phandle); 209EXPORT_SYMBOL_GPL(devm_usb_get_phy_by_phandle);
211 210
212/** 211/**
213 * usb_get_phy_dev - find the USB PHY 212 * usb_get_phy_dev - find the USB PHY
@@ -240,7 +239,7 @@ err0:
240 239
241 return phy; 240 return phy;
242} 241}
243EXPORT_SYMBOL(usb_get_phy_dev); 242EXPORT_SYMBOL_GPL(usb_get_phy_dev);
244 243
245/** 244/**
246 * devm_usb_get_phy_dev - find the USB PHY using device ptr and index 245 * devm_usb_get_phy_dev - find the USB PHY using device ptr and index
@@ -270,7 +269,7 @@ struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
270 269
271 return phy; 270 return phy;
272} 271}
273EXPORT_SYMBOL(devm_usb_get_phy_dev); 272EXPORT_SYMBOL_GPL(devm_usb_get_phy_dev);
274 273
275/** 274/**
276 * devm_usb_put_phy - release the USB PHY 275 * devm_usb_put_phy - release the USB PHY
@@ -289,7 +288,7 @@ void devm_usb_put_phy(struct device *dev, struct usb_phy *phy)
289 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy); 288 r = devres_destroy(dev, devm_usb_phy_release, devm_usb_phy_match, phy);
290 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n"); 289 dev_WARN_ONCE(dev, r, "couldn't find PHY resource\n");
291} 290}
292EXPORT_SYMBOL(devm_usb_put_phy); 291EXPORT_SYMBOL_GPL(devm_usb_put_phy);
293 292
294/** 293/**
295 * usb_put_phy - release the USB PHY 294 * usb_put_phy - release the USB PHY
@@ -308,7 +307,7 @@ void usb_put_phy(struct usb_phy *x)
308 module_put(owner); 307 module_put(owner);
309 } 308 }
310} 309}
311EXPORT_SYMBOL(usb_put_phy); 310EXPORT_SYMBOL_GPL(usb_put_phy);
312 311
313/** 312/**
314 * usb_add_phy - declare the USB PHY 313 * usb_add_phy - declare the USB PHY
@@ -348,7 +347,7 @@ out:
348 spin_unlock_irqrestore(&phy_lock, flags); 347 spin_unlock_irqrestore(&phy_lock, flags);
349 return ret; 348 return ret;
350} 349}
351EXPORT_SYMBOL(usb_add_phy); 350EXPORT_SYMBOL_GPL(usb_add_phy);
352 351
353/** 352/**
354 * usb_add_phy_dev - declare the USB PHY 353 * usb_add_phy_dev - declare the USB PHY
@@ -378,7 +377,7 @@ int usb_add_phy_dev(struct usb_phy *x)
378 spin_unlock_irqrestore(&phy_lock, flags); 377 spin_unlock_irqrestore(&phy_lock, flags);
379 return 0; 378 return 0;
380} 379}
381EXPORT_SYMBOL(usb_add_phy_dev); 380EXPORT_SYMBOL_GPL(usb_add_phy_dev);
382 381
383/** 382/**
384 * usb_remove_phy - remove the OTG PHY 383 * usb_remove_phy - remove the OTG PHY
@@ -400,7 +399,7 @@ void usb_remove_phy(struct usb_phy *x)
400 } 399 }
401 spin_unlock_irqrestore(&phy_lock, flags); 400 spin_unlock_irqrestore(&phy_lock, flags);
402} 401}
403EXPORT_SYMBOL(usb_remove_phy); 402EXPORT_SYMBOL_GPL(usb_remove_phy);
404 403
405/** 404/**
406 * usb_bind_phy - bind the phy and the controller that uses the phy 405 * usb_bind_phy - bind the phy and the controller that uses the phy
@@ -414,7 +413,7 @@ EXPORT_SYMBOL(usb_remove_phy);
414 * 413 *
415 * To be used by platform specific initialization code. 414 * To be used by platform specific initialization code.
416 */ 415 */
417int __init usb_bind_phy(const char *dev_name, u8 index, 416int usb_bind_phy(const char *dev_name, u8 index,
418 const char *phy_dev_name) 417 const char *phy_dev_name)
419{ 418{
420 struct usb_phy_bind *phy_bind; 419 struct usb_phy_bind *phy_bind;
@@ -437,38 +436,3 @@ int __init usb_bind_phy(const char *dev_name, u8 index,
437 return 0; 436 return 0;
438} 437}
439EXPORT_SYMBOL_GPL(usb_bind_phy); 438EXPORT_SYMBOL_GPL(usb_bind_phy);
440
441const char *otg_state_string(enum usb_otg_state state)
442{
443 switch (state) {
444 case OTG_STATE_A_IDLE:
445 return "a_idle";
446 case OTG_STATE_A_WAIT_VRISE:
447 return "a_wait_vrise";
448 case OTG_STATE_A_WAIT_BCON:
449 return "a_wait_bcon";
450 case OTG_STATE_A_HOST:
451 return "a_host";
452 case OTG_STATE_A_SUSPEND:
453 return "a_suspend";
454 case OTG_STATE_A_PERIPHERAL:
455 return "a_peripheral";
456 case OTG_STATE_A_WAIT_VFALL:
457 return "a_wait_vfall";
458 case OTG_STATE_A_VBUS_ERR:
459 return "a_vbus_err";
460 case OTG_STATE_B_IDLE:
461 return "b_idle";
462 case OTG_STATE_B_SRP_INIT:
463 return "b_srp_init";
464 case OTG_STATE_B_PERIPHERAL:
465 return "b_peripheral";
466 case OTG_STATE_B_WAIT_ACON:
467 return "b_wait_acon";
468 case OTG_STATE_B_HOST:
469 return "b_host";
470 default:
471 return "UNDEFINED";
472 }
473}
474EXPORT_SYMBOL(otg_state_string);
diff --git a/drivers/usb/phy/samsung-usbphy.c b/drivers/usb/phy/samsung-usbphy.c
deleted file mode 100644
index 967101ec15fd..000000000000
--- a/drivers/usb/phy/samsung-usbphy.c
+++ /dev/null
@@ -1,928 +0,0 @@
1/* linux/drivers/usb/phy/samsung-usbphy.c
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * http://www.samsung.com
5 *
6 * Author: Praveen Paneri <p.paneri@samsung.com>
7 *
8 * Samsung USB2.0 PHY transceiver; talks to S3C HS OTG controller, EHCI-S5P and
9 * OHCI-EXYNOS controllers.
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 version 2 as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/clk.h>
24#include <linux/delay.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/io.h>
28#include <linux/of.h>
29#include <linux/of_address.h>
30#include <linux/usb/otg.h>
31#include <linux/usb/samsung_usb_phy.h>
32#include <linux/platform_data/samsung-usbphy.h>
33
34/* Register definitions */
35
36#define SAMSUNG_PHYPWR (0x00)
37
38#define PHYPWR_NORMAL_MASK (0x19 << 0)
39#define PHYPWR_OTG_DISABLE (0x1 << 4)
40#define PHYPWR_ANALOG_POWERDOWN (0x1 << 3)
41#define PHYPWR_FORCE_SUSPEND (0x1 << 1)
42/* For Exynos4 */
43#define PHYPWR_NORMAL_MASK_PHY0 (0x39 << 0)
44#define PHYPWR_SLEEP_PHY0 (0x1 << 5)
45
46#define SAMSUNG_PHYCLK (0x04)
47
48#define PHYCLK_MODE_USB11 (0x1 << 6)
49#define PHYCLK_EXT_OSC (0x1 << 5)
50#define PHYCLK_COMMON_ON_N (0x1 << 4)
51#define PHYCLK_ID_PULL (0x1 << 2)
52#define PHYCLK_CLKSEL_MASK (0x3 << 0)
53#define PHYCLK_CLKSEL_48M (0x0 << 0)
54#define PHYCLK_CLKSEL_12M (0x2 << 0)
55#define PHYCLK_CLKSEL_24M (0x3 << 0)
56
57#define SAMSUNG_RSTCON (0x08)
58
59#define RSTCON_PHYLINK_SWRST (0x1 << 2)
60#define RSTCON_HLINK_SWRST (0x1 << 1)
61#define RSTCON_SWRST (0x1 << 0)
62
63/* EXYNOS5 */
64#define EXYNOS5_PHY_HOST_CTRL0 (0x00)
65
66#define HOST_CTRL0_PHYSWRSTALL (0x1 << 31)
67
68#define HOST_CTRL0_REFCLKSEL_MASK (0x3 << 19)
69#define HOST_CTRL0_REFCLKSEL_XTAL (0x0 << 19)
70#define HOST_CTRL0_REFCLKSEL_EXTL (0x1 << 19)
71#define HOST_CTRL0_REFCLKSEL_CLKCORE (0x2 << 19)
72
73#define HOST_CTRL0_FSEL_MASK (0x7 << 16)
74#define HOST_CTRL0_FSEL(_x) ((_x) << 16)
75
76#define FSEL_CLKSEL_50M (0x7)
77#define FSEL_CLKSEL_24M (0x5)
78#define FSEL_CLKSEL_20M (0x4)
79#define FSEL_CLKSEL_19200K (0x3)
80#define FSEL_CLKSEL_12M (0x2)
81#define FSEL_CLKSEL_10M (0x1)
82#define FSEL_CLKSEL_9600K (0x0)
83
84#define HOST_CTRL0_TESTBURNIN (0x1 << 11)
85#define HOST_CTRL0_RETENABLE (0x1 << 10)
86#define HOST_CTRL0_COMMONON_N (0x1 << 9)
87#define HOST_CTRL0_SIDDQ (0x1 << 6)
88#define HOST_CTRL0_FORCESLEEP (0x1 << 5)
89#define HOST_CTRL0_FORCESUSPEND (0x1 << 4)
90#define HOST_CTRL0_WORDINTERFACE (0x1 << 3)
91#define HOST_CTRL0_UTMISWRST (0x1 << 2)
92#define HOST_CTRL0_LINKSWRST (0x1 << 1)
93#define HOST_CTRL0_PHYSWRST (0x1 << 0)
94
95#define EXYNOS5_PHY_HOST_TUNE0 (0x04)
96
97#define EXYNOS5_PHY_HSIC_CTRL1 (0x10)
98
99#define EXYNOS5_PHY_HSIC_TUNE1 (0x14)
100
101#define EXYNOS5_PHY_HSIC_CTRL2 (0x20)
102
103#define EXYNOS5_PHY_HSIC_TUNE2 (0x24)
104
105#define HSIC_CTRL_REFCLKSEL_MASK (0x3 << 23)
106#define HSIC_CTRL_REFCLKSEL (0x2 << 23)
107
108#define HSIC_CTRL_REFCLKDIV_MASK (0x7f << 16)
109#define HSIC_CTRL_REFCLKDIV(_x) ((_x) << 16)
110#define HSIC_CTRL_REFCLKDIV_12 (0x24 << 16)
111#define HSIC_CTRL_REFCLKDIV_15 (0x1c << 16)
112#define HSIC_CTRL_REFCLKDIV_16 (0x1a << 16)
113#define HSIC_CTRL_REFCLKDIV_19_2 (0x15 << 16)
114#define HSIC_CTRL_REFCLKDIV_20 (0x14 << 16)
115
116#define HSIC_CTRL_SIDDQ (0x1 << 6)
117#define HSIC_CTRL_FORCESLEEP (0x1 << 5)
118#define HSIC_CTRL_FORCESUSPEND (0x1 << 4)
119#define HSIC_CTRL_WORDINTERFACE (0x1 << 3)
120#define HSIC_CTRL_UTMISWRST (0x1 << 2)
121#define HSIC_CTRL_PHYSWRST (0x1 << 0)
122
123#define EXYNOS5_PHY_HOST_EHCICTRL (0x30)
124
125#define HOST_EHCICTRL_ENAINCRXALIGN (0x1 << 29)
126#define HOST_EHCICTRL_ENAINCR4 (0x1 << 28)
127#define HOST_EHCICTRL_ENAINCR8 (0x1 << 27)
128#define HOST_EHCICTRL_ENAINCR16 (0x1 << 26)
129
130#define EXYNOS5_PHY_HOST_OHCICTRL (0x34)
131
132#define HOST_OHCICTRL_SUSPLGCY (0x1 << 3)
133#define HOST_OHCICTRL_APPSTARTCLK (0x1 << 2)
134#define HOST_OHCICTRL_CNTSEL (0x1 << 1)
135#define HOST_OHCICTRL_CLKCKTRST (0x1 << 0)
136
137#define EXYNOS5_PHY_OTG_SYS (0x38)
138
139#define OTG_SYS_PHYLINK_SWRESET (0x1 << 14)
140#define OTG_SYS_LINKSWRST_UOTG (0x1 << 13)
141#define OTG_SYS_PHY0_SWRST (0x1 << 12)
142
143#define OTG_SYS_REFCLKSEL_MASK (0x3 << 9)
144#define OTG_SYS_REFCLKSEL_XTAL (0x0 << 9)
145#define OTG_SYS_REFCLKSEL_EXTL (0x1 << 9)
146#define OTG_SYS_REFCLKSEL_CLKCORE (0x2 << 9)
147
148#define OTG_SYS_IDPULLUP_UOTG (0x1 << 8)
149#define OTG_SYS_COMMON_ON (0x1 << 7)
150
151#define OTG_SYS_FSEL_MASK (0x7 << 4)
152#define OTG_SYS_FSEL(_x) ((_x) << 4)
153
154#define OTG_SYS_FORCESLEEP (0x1 << 3)
155#define OTG_SYS_OTGDISABLE (0x1 << 2)
156#define OTG_SYS_SIDDQ_UOTG (0x1 << 1)
157#define OTG_SYS_FORCESUSPEND (0x1 << 0)
158
159#define EXYNOS5_PHY_OTG_TUNE (0x40)
160
161#ifndef MHZ
162#define MHZ (1000*1000)
163#endif
164
165#ifndef KHZ
166#define KHZ (1000)
167#endif
168
169#define EXYNOS_USBHOST_PHY_CTRL_OFFSET (0x4)
170#define S3C64XX_USBPHY_ENABLE (0x1 << 16)
171#define EXYNOS_USBPHY_ENABLE (0x1 << 0)
172#define EXYNOS_USB20PHY_CFG_HOST_LINK (0x1 << 0)
173
174enum samsung_cpu_type {
175 TYPE_S3C64XX,
176 TYPE_EXYNOS4210,
177 TYPE_EXYNOS5250,
178};
179
180/*
181 * struct samsung_usbphy_drvdata - driver data for various SoC variants
182 * @cpu_type: machine identifier
183 * @devphy_en_mask: device phy enable mask for PHY CONTROL register
184 * @hostphy_en_mask: host phy enable mask for PHY CONTROL register
185 * @devphy_reg_offset: offset to DEVICE PHY CONTROL register from
186 * mapped address of system controller.
187 * @hostphy_reg_offset: offset to HOST PHY CONTROL register from
188 * mapped address of system controller.
189 *
190 * Here we have a separate mask for device type phy.
191 * Having different masks for host and device type phy helps
192 * in setting independent masks in case of SoCs like S5PV210,
193 * in which PHY0 and PHY1 enable bits belong to same register
194 * placed at position 0 and 1 respectively.
195 * Although for newer SoCs like exynos these bits belong to
196 * different registers altogether placed at position 0.
197 */
198struct samsung_usbphy_drvdata {
199 int cpu_type;
200 int devphy_en_mask;
201 int hostphy_en_mask;
202 u32 devphy_reg_offset;
203 u32 hostphy_reg_offset;
204};
205
206/*
207 * struct samsung_usbphy - transceiver driver state
208 * @phy: transceiver structure
209 * @plat: platform data
210 * @dev: The parent device supplied to the probe function
211 * @clk: usb phy clock
212 * @regs: usb phy controller registers memory base
213 * @pmuregs: USB device PHY_CONTROL register memory base
214 * @sysreg: USB2.0 PHY_CFG register memory base
215 * @ref_clk_freq: reference clock frequency selection
216 * @drv_data: driver data available for different SoCs
217 * @phy_type: Samsung SoCs specific phy types: #HOST
218 * #DEVICE
219 * @phy_usage: usage count for phy
220 * @lock: lock for phy operations
221 */
222struct samsung_usbphy {
223 struct usb_phy phy;
224 struct samsung_usbphy_data *plat;
225 struct device *dev;
226 struct clk *clk;
227 void __iomem *regs;
228 void __iomem *pmuregs;
229 void __iomem *sysreg;
230 int ref_clk_freq;
231 const struct samsung_usbphy_drvdata *drv_data;
232 enum samsung_usb_phy_type phy_type;
233 atomic_t phy_usage;
234 spinlock_t lock;
235};
236
237#define phy_to_sphy(x) container_of((x), struct samsung_usbphy, phy)
238
239int samsung_usbphy_set_host(struct usb_otg *otg, struct usb_bus *host)
240{
241 if (!otg)
242 return -ENODEV;
243
244 if (!otg->host)
245 otg->host = host;
246
247 return 0;
248}
249
250static int samsung_usbphy_parse_dt(struct samsung_usbphy *sphy)
251{
252 struct device_node *usbphy_sys;
253
254 /* Getting node for system controller interface for usb-phy */
255 usbphy_sys = of_get_child_by_name(sphy->dev->of_node, "usbphy-sys");
256 if (!usbphy_sys) {
257 dev_err(sphy->dev, "No sys-controller interface for usb-phy\n");
258 return -ENODEV;
259 }
260
261 sphy->pmuregs = of_iomap(usbphy_sys, 0);
262
263 if (sphy->pmuregs == NULL) {
264 dev_err(sphy->dev, "Can't get usb-phy pmu control register\n");
265 goto err0;
266 }
267
268 sphy->sysreg = of_iomap(usbphy_sys, 1);
269
270 /*
271 * Not returning error code here, since this situation is not fatal.
272 * Few SoCs may not have this switch available
273 */
274 if (sphy->sysreg == NULL)
275 dev_warn(sphy->dev, "Can't get usb-phy sysreg cfg register\n");
276
277 of_node_put(usbphy_sys);
278
279 return 0;
280
281err0:
282 of_node_put(usbphy_sys);
283 return -ENXIO;
284}
285
286/*
287 * Set isolation here for phy.
288 * Here 'on = true' would mean USB PHY block is isolated, hence
289 * de-activated and vice-versa.
290 */
291static void samsung_usbphy_set_isolation(struct samsung_usbphy *sphy, bool on)
292{
293 void __iomem *reg = NULL;
294 u32 reg_val;
295 u32 en_mask = 0;
296
297 if (!sphy->pmuregs) {
298 dev_warn(sphy->dev, "Can't set pmu isolation\n");
299 return;
300 }
301
302 switch (sphy->drv_data->cpu_type) {
303 case TYPE_S3C64XX:
304 /*
305 * Do nothing: We will add here once S3C64xx goes for DT support
306 */
307 break;
308 case TYPE_EXYNOS4210:
309 /*
310 * Fall through since exynos4210 and exynos5250 have similar
311 * register architecture: two separate registers for host and
312 * device phy control with enable bit at position 0.
313 */
314 case TYPE_EXYNOS5250:
315 if (sphy->phy_type == USB_PHY_TYPE_DEVICE) {
316 reg = sphy->pmuregs +
317 sphy->drv_data->devphy_reg_offset;
318 en_mask = sphy->drv_data->devphy_en_mask;
319 } else if (sphy->phy_type == USB_PHY_TYPE_HOST) {
320 reg = sphy->pmuregs +
321 sphy->drv_data->hostphy_reg_offset;
322 en_mask = sphy->drv_data->hostphy_en_mask;
323 }
324 break;
325 default:
326 dev_err(sphy->dev, "Invalid SoC type\n");
327 return;
328 }
329
330 reg_val = readl(reg);
331
332 if (on)
333 reg_val &= ~en_mask;
334 else
335 reg_val |= en_mask;
336
337 writel(reg_val, reg);
338}
339
340/*
341 * Configure the mode of working of usb-phy here: HOST/DEVICE.
342 */
343static void samsung_usbphy_cfg_sel(struct samsung_usbphy *sphy)
344{
345 u32 reg;
346
347 if (!sphy->sysreg) {
348 dev_warn(sphy->dev, "Can't configure specified phy mode\n");
349 return;
350 }
351
352 reg = readl(sphy->sysreg);
353
354 if (sphy->phy_type == USB_PHY_TYPE_DEVICE)
355 reg &= ~EXYNOS_USB20PHY_CFG_HOST_LINK;
356 else if (sphy->phy_type == USB_PHY_TYPE_HOST)
357 reg |= EXYNOS_USB20PHY_CFG_HOST_LINK;
358
359 writel(reg, sphy->sysreg);
360}
361
362/*
363 * PHYs are different for USB Device and USB Host.
364 * This make sure that correct PHY type is selected before
365 * any operation on PHY.
366 */
367static int samsung_usbphy_set_type(struct usb_phy *phy,
368 enum samsung_usb_phy_type phy_type)
369{
370 struct samsung_usbphy *sphy = phy_to_sphy(phy);
371
372 sphy->phy_type = phy_type;
373
374 return 0;
375}
376
377/*
378 * Returns reference clock frequency selection value
379 */
380static int samsung_usbphy_get_refclk_freq(struct samsung_usbphy *sphy)
381{
382 struct clk *ref_clk;
383 int refclk_freq = 0;
384
385 /*
386 * In exynos5250 USB host and device PHY use
387 * external crystal clock XXTI
388 */
389 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
390 ref_clk = clk_get(sphy->dev, "ext_xtal");
391 else
392 ref_clk = clk_get(sphy->dev, "xusbxti");
393 if (IS_ERR(ref_clk)) {
394 dev_err(sphy->dev, "Failed to get reference clock\n");
395 return PTR_ERR(ref_clk);
396 }
397
398 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250) {
399 /* set clock frequency for PLL */
400 switch (clk_get_rate(ref_clk)) {
401 case 9600 * KHZ:
402 refclk_freq = FSEL_CLKSEL_9600K;
403 break;
404 case 10 * MHZ:
405 refclk_freq = FSEL_CLKSEL_10M;
406 break;
407 case 12 * MHZ:
408 refclk_freq = FSEL_CLKSEL_12M;
409 break;
410 case 19200 * KHZ:
411 refclk_freq = FSEL_CLKSEL_19200K;
412 break;
413 case 20 * MHZ:
414 refclk_freq = FSEL_CLKSEL_20M;
415 break;
416 case 50 * MHZ:
417 refclk_freq = FSEL_CLKSEL_50M;
418 break;
419 case 24 * MHZ:
420 default:
421 /* default reference clock */
422 refclk_freq = FSEL_CLKSEL_24M;
423 break;
424 }
425 } else {
426 switch (clk_get_rate(ref_clk)) {
427 case 12 * MHZ:
428 refclk_freq = PHYCLK_CLKSEL_12M;
429 break;
430 case 24 * MHZ:
431 refclk_freq = PHYCLK_CLKSEL_24M;
432 break;
433 case 48 * MHZ:
434 refclk_freq = PHYCLK_CLKSEL_48M;
435 break;
436 default:
437 if (sphy->drv_data->cpu_type == TYPE_S3C64XX)
438 refclk_freq = PHYCLK_CLKSEL_48M;
439 else
440 refclk_freq = PHYCLK_CLKSEL_24M;
441 break;
442 }
443 }
444 clk_put(ref_clk);
445
446 return refclk_freq;
447}
448
449static bool exynos5_phyhost_is_on(void *regs)
450{
451 u32 reg;
452
453 reg = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
454
455 return !(reg & HOST_CTRL0_SIDDQ);
456}
457
458static void samsung_exynos5_usbphy_enable(struct samsung_usbphy *sphy)
459{
460 void __iomem *regs = sphy->regs;
461 u32 phyclk = sphy->ref_clk_freq;
462 u32 phyhost;
463 u32 phyotg;
464 u32 phyhsic;
465 u32 ehcictrl;
466 u32 ohcictrl;
467
468 /*
469 * phy_usage helps in keeping usage count for phy
470 * so that the first consumer enabling the phy is also
471 * the last consumer to disable it.
472 */
473
474 atomic_inc(&sphy->phy_usage);
475
476 if (exynos5_phyhost_is_on(regs)) {
477 dev_info(sphy->dev, "Already power on PHY\n");
478 return;
479 }
480
481 /* Host configuration */
482 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
483
484 /* phy reference clock configuration */
485 phyhost &= ~HOST_CTRL0_FSEL_MASK;
486 phyhost |= HOST_CTRL0_FSEL(phyclk);
487
488 /* host phy reset */
489 phyhost &= ~(HOST_CTRL0_PHYSWRST |
490 HOST_CTRL0_PHYSWRSTALL |
491 HOST_CTRL0_SIDDQ |
492 /* Enable normal mode of operation */
493 HOST_CTRL0_FORCESUSPEND |
494 HOST_CTRL0_FORCESLEEP);
495
496 /* Link reset */
497 phyhost |= (HOST_CTRL0_LINKSWRST |
498 HOST_CTRL0_UTMISWRST |
499 /* COMMON Block configuration during suspend */
500 HOST_CTRL0_COMMONON_N);
501 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
502 udelay(10);
503 phyhost &= ~(HOST_CTRL0_LINKSWRST |
504 HOST_CTRL0_UTMISWRST);
505 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
506
507 /* OTG configuration */
508 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
509
510 /* phy reference clock configuration */
511 phyotg &= ~OTG_SYS_FSEL_MASK;
512 phyotg |= OTG_SYS_FSEL(phyclk);
513
514 /* Enable normal mode of operation */
515 phyotg &= ~(OTG_SYS_FORCESUSPEND |
516 OTG_SYS_SIDDQ_UOTG |
517 OTG_SYS_FORCESLEEP |
518 OTG_SYS_REFCLKSEL_MASK |
519 /* COMMON Block configuration during suspend */
520 OTG_SYS_COMMON_ON);
521
522 /* OTG phy & link reset */
523 phyotg |= (OTG_SYS_PHY0_SWRST |
524 OTG_SYS_LINKSWRST_UOTG |
525 OTG_SYS_PHYLINK_SWRESET |
526 OTG_SYS_OTGDISABLE |
527 /* Set phy refclk */
528 OTG_SYS_REFCLKSEL_CLKCORE);
529
530 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
531 udelay(10);
532 phyotg &= ~(OTG_SYS_PHY0_SWRST |
533 OTG_SYS_LINKSWRST_UOTG |
534 OTG_SYS_PHYLINK_SWRESET);
535 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
536
537 /* HSIC phy configuration */
538 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
539 HSIC_CTRL_REFCLKSEL |
540 HSIC_CTRL_PHYSWRST);
541 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
542 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
543 udelay(10);
544 phyhsic &= ~HSIC_CTRL_PHYSWRST;
545 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
546 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
547
548 udelay(80);
549
550 /* enable EHCI DMA burst */
551 ehcictrl = readl(regs + EXYNOS5_PHY_HOST_EHCICTRL);
552 ehcictrl |= (HOST_EHCICTRL_ENAINCRXALIGN |
553 HOST_EHCICTRL_ENAINCR4 |
554 HOST_EHCICTRL_ENAINCR8 |
555 HOST_EHCICTRL_ENAINCR16);
556 writel(ehcictrl, regs + EXYNOS5_PHY_HOST_EHCICTRL);
557
558 /* set ohci_suspend_on_n */
559 ohcictrl = readl(regs + EXYNOS5_PHY_HOST_OHCICTRL);
560 ohcictrl |= HOST_OHCICTRL_SUSPLGCY;
561 writel(ohcictrl, regs + EXYNOS5_PHY_HOST_OHCICTRL);
562}
563
564static void samsung_usbphy_enable(struct samsung_usbphy *sphy)
565{
566 void __iomem *regs = sphy->regs;
567 u32 phypwr;
568 u32 phyclk;
569 u32 rstcon;
570
571 /* set clock frequency for PLL */
572 phyclk = sphy->ref_clk_freq;
573 phypwr = readl(regs + SAMSUNG_PHYPWR);
574 rstcon = readl(regs + SAMSUNG_RSTCON);
575
576 switch (sphy->drv_data->cpu_type) {
577 case TYPE_S3C64XX:
578 phyclk &= ~PHYCLK_COMMON_ON_N;
579 phypwr &= ~PHYPWR_NORMAL_MASK;
580 rstcon |= RSTCON_SWRST;
581 break;
582 case TYPE_EXYNOS4210:
583 phypwr &= ~PHYPWR_NORMAL_MASK_PHY0;
584 rstcon |= RSTCON_SWRST;
585 default:
586 break;
587 }
588
589 writel(phyclk, regs + SAMSUNG_PHYCLK);
590 /* Configure PHY0 for normal operation*/
591 writel(phypwr, regs + SAMSUNG_PHYPWR);
592 /* reset all ports of PHY and Link */
593 writel(rstcon, regs + SAMSUNG_RSTCON);
594 udelay(10);
595 rstcon &= ~RSTCON_SWRST;
596 writel(rstcon, regs + SAMSUNG_RSTCON);
597}
598
599static void samsung_exynos5_usbphy_disable(struct samsung_usbphy *sphy)
600{
601 void __iomem *regs = sphy->regs;
602 u32 phyhost;
603 u32 phyotg;
604 u32 phyhsic;
605
606 if (atomic_dec_return(&sphy->phy_usage) > 0) {
607 dev_info(sphy->dev, "still being used\n");
608 return;
609 }
610
611 phyhsic = (HSIC_CTRL_REFCLKDIV_12 |
612 HSIC_CTRL_REFCLKSEL |
613 HSIC_CTRL_SIDDQ |
614 HSIC_CTRL_FORCESLEEP |
615 HSIC_CTRL_FORCESUSPEND);
616 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL1);
617 writel(phyhsic, regs + EXYNOS5_PHY_HSIC_CTRL2);
618
619 phyhost = readl(regs + EXYNOS5_PHY_HOST_CTRL0);
620 phyhost |= (HOST_CTRL0_SIDDQ |
621 HOST_CTRL0_FORCESUSPEND |
622 HOST_CTRL0_FORCESLEEP |
623 HOST_CTRL0_PHYSWRST |
624 HOST_CTRL0_PHYSWRSTALL);
625 writel(phyhost, regs + EXYNOS5_PHY_HOST_CTRL0);
626
627 phyotg = readl(regs + EXYNOS5_PHY_OTG_SYS);
628 phyotg |= (OTG_SYS_FORCESUSPEND |
629 OTG_SYS_SIDDQ_UOTG |
630 OTG_SYS_FORCESLEEP);
631 writel(phyotg, regs + EXYNOS5_PHY_OTG_SYS);
632}
633
634static void samsung_usbphy_disable(struct samsung_usbphy *sphy)
635{
636 void __iomem *regs = sphy->regs;
637 u32 phypwr;
638
639 phypwr = readl(regs + SAMSUNG_PHYPWR);
640
641 switch (sphy->drv_data->cpu_type) {
642 case TYPE_S3C64XX:
643 phypwr |= PHYPWR_NORMAL_MASK;
644 break;
645 case TYPE_EXYNOS4210:
646 phypwr |= PHYPWR_NORMAL_MASK_PHY0;
647 default:
648 break;
649 }
650
651 /* Disable analog and otg block power */
652 writel(phypwr, regs + SAMSUNG_PHYPWR);
653}
654
655/*
656 * The function passed to the usb driver for phy initialization
657 */
658static int samsung_usbphy_init(struct usb_phy *phy)
659{
660 struct samsung_usbphy *sphy;
661 struct usb_bus *host = NULL;
662 unsigned long flags;
663 int ret = 0;
664
665 sphy = phy_to_sphy(phy);
666
667 host = phy->otg->host;
668
669 /* Enable the phy clock */
670 ret = clk_prepare_enable(sphy->clk);
671 if (ret) {
672 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
673 return ret;
674 }
675
676 spin_lock_irqsave(&sphy->lock, flags);
677
678 if (host) {
679 /* setting default phy-type for USB 2.0 */
680 if (!strstr(dev_name(host->controller), "ehci") ||
681 !strstr(dev_name(host->controller), "ohci"))
682 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
683 } else {
684 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
685 }
686
687 /* Disable phy isolation */
688 if (sphy->plat && sphy->plat->pmu_isolation)
689 sphy->plat->pmu_isolation(false);
690 else
691 samsung_usbphy_set_isolation(sphy, false);
692
693 /* Selecting Host/OTG mode; After reset USB2.0PHY_CFG: HOST */
694 samsung_usbphy_cfg_sel(sphy);
695
696 /* Initialize usb phy registers */
697 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
698 samsung_exynos5_usbphy_enable(sphy);
699 else
700 samsung_usbphy_enable(sphy);
701
702 spin_unlock_irqrestore(&sphy->lock, flags);
703
704 /* Disable the phy clock */
705 clk_disable_unprepare(sphy->clk);
706
707 return ret;
708}
709
710/*
711 * The function passed to the usb driver for phy shutdown
712 */
713static void samsung_usbphy_shutdown(struct usb_phy *phy)
714{
715 struct samsung_usbphy *sphy;
716 struct usb_bus *host = NULL;
717 unsigned long flags;
718
719 sphy = phy_to_sphy(phy);
720
721 host = phy->otg->host;
722
723 if (clk_prepare_enable(sphy->clk)) {
724 dev_err(sphy->dev, "%s: clk_prepare_enable failed\n", __func__);
725 return;
726 }
727
728 spin_lock_irqsave(&sphy->lock, flags);
729
730 if (host) {
731 /* setting default phy-type for USB 2.0 */
732 if (!strstr(dev_name(host->controller), "ehci") ||
733 !strstr(dev_name(host->controller), "ohci"))
734 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_HOST);
735 } else {
736 samsung_usbphy_set_type(&sphy->phy, USB_PHY_TYPE_DEVICE);
737 }
738
739 /* De-initialize usb phy registers */
740 if (sphy->drv_data->cpu_type == TYPE_EXYNOS5250)
741 samsung_exynos5_usbphy_disable(sphy);
742 else
743 samsung_usbphy_disable(sphy);
744
745 /* Enable phy isolation */
746 if (sphy->plat && sphy->plat->pmu_isolation)
747 sphy->plat->pmu_isolation(true);
748 else
749 samsung_usbphy_set_isolation(sphy, true);
750
751 spin_unlock_irqrestore(&sphy->lock, flags);
752
753 clk_disable_unprepare(sphy->clk);
754}
755
756static const struct of_device_id samsung_usbphy_dt_match[];
757
758static inline const struct samsung_usbphy_drvdata
759*samsung_usbphy_get_driver_data(struct platform_device *pdev)
760{
761 if (pdev->dev.of_node) {
762 const struct of_device_id *match;
763 match = of_match_node(samsung_usbphy_dt_match,
764 pdev->dev.of_node);
765 return match->data;
766 }
767
768 return (struct samsung_usbphy_drvdata *)
769 platform_get_device_id(pdev)->driver_data;
770}
771
772static int samsung_usbphy_probe(struct platform_device *pdev)
773{
774 struct samsung_usbphy *sphy;
775 struct usb_otg *otg;
776 struct samsung_usbphy_data *pdata = pdev->dev.platform_data;
777 const struct samsung_usbphy_drvdata *drv_data;
778 struct device *dev = &pdev->dev;
779 struct resource *phy_mem;
780 void __iomem *phy_base;
781 struct clk *clk;
782 int ret;
783
784 phy_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
785 if (!phy_mem) {
786 dev_err(dev, "%s: missing mem resource\n", __func__);
787 return -ENODEV;
788 }
789
790 phy_base = devm_ioremap_resource(dev, phy_mem);
791 if (IS_ERR(phy_base))
792 return PTR_ERR(phy_base);
793
794 sphy = devm_kzalloc(dev, sizeof(*sphy), GFP_KERNEL);
795 if (!sphy)
796 return -ENOMEM;
797
798 otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
799 if (!otg)
800 return -ENOMEM;
801
802 drv_data = samsung_usbphy_get_driver_data(pdev);
803
804 if (drv_data->cpu_type == TYPE_EXYNOS5250)
805 clk = devm_clk_get(dev, "usbhost");
806 else
807 clk = devm_clk_get(dev, "otg");
808
809 if (IS_ERR(clk)) {
810 dev_err(dev, "Failed to get otg clock\n");
811 return PTR_ERR(clk);
812 }
813
814 sphy->dev = dev;
815
816 if (dev->of_node) {
817 ret = samsung_usbphy_parse_dt(sphy);
818 if (ret < 0)
819 return ret;
820 } else {
821 if (!pdata) {
822 dev_err(dev, "no platform data specified\n");
823 return -EINVAL;
824 }
825 }
826
827 sphy->plat = pdata;
828 sphy->regs = phy_base;
829 sphy->clk = clk;
830 sphy->drv_data = drv_data;
831 sphy->phy.dev = sphy->dev;
832 sphy->phy.label = "samsung-usbphy";
833 sphy->phy.init = samsung_usbphy_init;
834 sphy->phy.shutdown = samsung_usbphy_shutdown;
835 sphy->ref_clk_freq = samsung_usbphy_get_refclk_freq(sphy);
836
837 sphy->phy.otg = otg;
838 sphy->phy.otg->phy = &sphy->phy;
839 sphy->phy.otg->set_host = samsung_usbphy_set_host;
840
841 spin_lock_init(&sphy->lock);
842
843 platform_set_drvdata(pdev, sphy);
844
845 return usb_add_phy(&sphy->phy, USB_PHY_TYPE_USB2);
846}
847
848static int samsung_usbphy_remove(struct platform_device *pdev)
849{
850 struct samsung_usbphy *sphy = platform_get_drvdata(pdev);
851
852 usb_remove_phy(&sphy->phy);
853
854 if (sphy->pmuregs)
855 iounmap(sphy->pmuregs);
856 if (sphy->sysreg)
857 iounmap(sphy->sysreg);
858
859 return 0;
860}
861
862static const struct samsung_usbphy_drvdata usbphy_s3c64xx = {
863 .cpu_type = TYPE_S3C64XX,
864 .devphy_en_mask = S3C64XX_USBPHY_ENABLE,
865};
866
867static const struct samsung_usbphy_drvdata usbphy_exynos4 = {
868 .cpu_type = TYPE_EXYNOS4210,
869 .devphy_en_mask = EXYNOS_USBPHY_ENABLE,
870 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
871};
872
873static struct samsung_usbphy_drvdata usbphy_exynos5 = {
874 .cpu_type = TYPE_EXYNOS5250,
875 .hostphy_en_mask = EXYNOS_USBPHY_ENABLE,
876 .hostphy_reg_offset = EXYNOS_USBHOST_PHY_CTRL_OFFSET,
877};
878
879#ifdef CONFIG_OF
880static const struct of_device_id samsung_usbphy_dt_match[] = {
881 {
882 .compatible = "samsung,s3c64xx-usbphy",
883 .data = &usbphy_s3c64xx,
884 }, {
885 .compatible = "samsung,exynos4210-usbphy",
886 .data = &usbphy_exynos4,
887 }, {
888 .compatible = "samsung,exynos5250-usbphy",
889 .data = &usbphy_exynos5
890 },
891 {},
892};
893MODULE_DEVICE_TABLE(of, samsung_usbphy_dt_match);
894#endif
895
896static struct platform_device_id samsung_usbphy_driver_ids[] = {
897 {
898 .name = "s3c64xx-usbphy",
899 .driver_data = (unsigned long)&usbphy_s3c64xx,
900 }, {
901 .name = "exynos4210-usbphy",
902 .driver_data = (unsigned long)&usbphy_exynos4,
903 }, {
904 .name = "exynos5250-usbphy",
905 .driver_data = (unsigned long)&usbphy_exynos5,
906 },
907 {},
908};
909
910MODULE_DEVICE_TABLE(platform, samsung_usbphy_driver_ids);
911
912static struct platform_driver samsung_usbphy_driver = {
913 .probe = samsung_usbphy_probe,
914 .remove = samsung_usbphy_remove,
915 .id_table = samsung_usbphy_driver_ids,
916 .driver = {
917 .name = "samsung-usbphy",
918 .owner = THIS_MODULE,
919 .of_match_table = of_match_ptr(samsung_usbphy_dt_match),
920 },
921};
922
923module_platform_driver(samsung_usbphy_driver);
924
925MODULE_DESCRIPTION("Samsung USB phy controller");
926MODULE_AUTHOR("Praveen Paneri <p.paneri@samsung.com>");
927MODULE_LICENSE("GPL");
928MODULE_ALIAS("platform:samsung-usbphy");
diff --git a/drivers/usb/renesas_usbhs/Kconfig b/drivers/usb/renesas_usbhs/Kconfig
index 29feb00d7f39..019bf7e49ee6 100644
--- a/drivers/usb/renesas_usbhs/Kconfig
+++ b/drivers/usb/renesas_usbhs/Kconfig
@@ -4,7 +4,7 @@
4 4
5config USB_RENESAS_USBHS 5config USB_RENESAS_USBHS
6 tristate 'Renesas USBHS controller' 6 tristate 'Renesas USBHS controller'
7 depends on USB && USB_GADGET && GENERIC_HARDIRQS 7 depends on USB_GADGET && GENERIC_HARDIRQS
8 default n 8 default n
9 help 9 help
10 Renesas USBHS is a discrete USB host and peripheral controller chip 10 Renesas USBHS is a discrete USB host and peripheral controller chip
diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 9538f0feafe2..45b94019aec8 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -32,7 +32,6 @@
32 */ 32 */
33void usbhs_pkt_init(struct usbhs_pkt *pkt) 33void usbhs_pkt_init(struct usbhs_pkt *pkt)
34{ 34{
35 pkt->dma = DMA_ADDR_INVALID;
36 INIT_LIST_HEAD(&pkt->node); 35 INIT_LIST_HEAD(&pkt->node);
37} 36}
38 37
diff --git a/drivers/usb/renesas_usbhs/fifo.h b/drivers/usb/renesas_usbhs/fifo.h
index c31731a843d1..a168a1760fce 100644
--- a/drivers/usb/renesas_usbhs/fifo.h
+++ b/drivers/usb/renesas_usbhs/fifo.h
@@ -23,8 +23,6 @@
23#include <asm/dma.h> 23#include <asm/dma.h>
24#include "pipe.h" 24#include "pipe.h"
25 25
26#define DMA_ADDR_INVALID (~(dma_addr_t)0)
27
28struct usbhs_fifo { 26struct usbhs_fifo {
29 char *name; 27 char *name;
30 u32 port; /* xFIFO */ 28 u32 port; /* xFIFO */
diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c
index 78fca978b2d0..ed4949faa70d 100644
--- a/drivers/usb/renesas_usbhs/mod_gadget.c
+++ b/drivers/usb/renesas_usbhs/mod_gadget.c
@@ -230,7 +230,7 @@ static int usbhsg_recip_handler_std_clear_endpoint(struct usbhs_priv *priv,
230 return 0; 230 return 0;
231} 231}
232 232
233struct usbhsg_recip_handle req_clear_feature = { 233static struct usbhsg_recip_handle req_clear_feature = {
234 .name = "clear feature", 234 .name = "clear feature",
235 .device = usbhsg_recip_handler_std_control_done, 235 .device = usbhsg_recip_handler_std_control_done,
236 .interface = usbhsg_recip_handler_std_control_done, 236 .interface = usbhsg_recip_handler_std_control_done,
@@ -271,7 +271,7 @@ static int usbhsg_recip_handler_std_set_endpoint(struct usbhs_priv *priv,
271 return 0; 271 return 0;
272} 272}
273 273
274struct usbhsg_recip_handle req_set_feature = { 274static struct usbhsg_recip_handle req_set_feature = {
275 .name = "set feature", 275 .name = "set feature",
276 .device = usbhsg_recip_handler_std_set_device, 276 .device = usbhsg_recip_handler_std_set_device,
277 .interface = usbhsg_recip_handler_std_control_done, 277 .interface = usbhsg_recip_handler_std_control_done,
@@ -372,7 +372,7 @@ static int usbhsg_recip_handler_std_get_endpoint(struct usbhs_priv *priv,
372 return 0; 372 return 0;
373} 373}
374 374
375struct usbhsg_recip_handle req_get_status = { 375static struct usbhsg_recip_handle req_get_status = {
376 .name = "get status", 376 .name = "get status",
377 .device = usbhsg_recip_handler_std_get_device, 377 .device = usbhsg_recip_handler_std_get_device,
378 .interface = usbhsg_recip_handler_std_get_interface, 378 .interface = usbhsg_recip_handler_std_get_interface,
@@ -845,7 +845,6 @@ static int usbhsg_gadget_start(struct usb_gadget *gadget,
845 845
846 /* first hook up the driver ... */ 846 /* first hook up the driver ... */
847 gpriv->driver = driver; 847 gpriv->driver = driver;
848 gpriv->gadget.dev.driver = &driver->driver;
849 848
850 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD); 849 return usbhsg_try_start(priv, USBHSG_STATUS_REGISTERD);
851} 850}
@@ -861,7 +860,6 @@ static int usbhsg_gadget_stop(struct usb_gadget *gadget,
861 return -EINVAL; 860 return -EINVAL;
862 861
863 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD); 862 usbhsg_try_stop(priv, USBHSG_STATUS_REGISTERD);
864 gpriv->gadget.dev.driver = NULL;
865 gpriv->driver = NULL; 863 gpriv->driver = NULL;
866 864
867 return 0; 865 return 0;
@@ -925,11 +923,6 @@ static int usbhsg_stop(struct usbhs_priv *priv)
925 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED); 923 return usbhsg_try_stop(priv, USBHSG_STATUS_STARTED);
926} 924}
927 925
928static void usbhs_mod_gadget_release(struct device *pdev)
929{
930 /* do nothing */
931}
932
933int usbhs_mod_gadget_probe(struct usbhs_priv *priv) 926int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
934{ 927{
935 struct usbhsg_gpriv *gpriv; 928 struct usbhsg_gpriv *gpriv;
@@ -976,15 +969,10 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
976 /* 969 /*
977 * init gadget 970 * init gadget
978 */ 971 */
979 dev_set_name(&gpriv->gadget.dev, "gadget");
980 gpriv->gadget.dev.parent = dev; 972 gpriv->gadget.dev.parent = dev;
981 gpriv->gadget.dev.release = usbhs_mod_gadget_release;
982 gpriv->gadget.name = "renesas_usbhs_udc"; 973 gpriv->gadget.name = "renesas_usbhs_udc";
983 gpriv->gadget.ops = &usbhsg_gadget_ops; 974 gpriv->gadget.ops = &usbhsg_gadget_ops;
984 gpriv->gadget.max_speed = USB_SPEED_HIGH; 975 gpriv->gadget.max_speed = USB_SPEED_HIGH;
985 ret = device_register(&gpriv->gadget.dev);
986 if (ret < 0)
987 goto err_add_udc;
988 976
989 INIT_LIST_HEAD(&gpriv->gadget.ep_list); 977 INIT_LIST_HEAD(&gpriv->gadget.ep_list);
990 978
@@ -1014,15 +1002,13 @@ int usbhs_mod_gadget_probe(struct usbhs_priv *priv)
1014 1002
1015 ret = usb_add_gadget_udc(dev, &gpriv->gadget); 1003 ret = usb_add_gadget_udc(dev, &gpriv->gadget);
1016 if (ret) 1004 if (ret)
1017 goto err_register; 1005 goto err_add_udc;
1018 1006
1019 1007
1020 dev_info(dev, "gadget probed\n"); 1008 dev_info(dev, "gadget probed\n");
1021 1009
1022 return 0; 1010 return 0;
1023 1011
1024err_register:
1025 device_unregister(&gpriv->gadget.dev);
1026err_add_udc: 1012err_add_udc:
1027 kfree(gpriv->uep); 1013 kfree(gpriv->uep);
1028 1014
@@ -1038,8 +1024,6 @@ void usbhs_mod_gadget_remove(struct usbhs_priv *priv)
1038 1024
1039 usb_del_gadget_udc(&gpriv->gadget); 1025 usb_del_gadget_udc(&gpriv->gadget);
1040 1026
1041 device_unregister(&gpriv->gadget.dev);
1042
1043 kfree(gpriv->uep); 1027 kfree(gpriv->uep);
1044 kfree(gpriv); 1028 kfree(gpriv);
1045} 1029}
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 17b7f9ae36ad..1d55762afbb1 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -4,7 +4,7 @@
4 4
5menuconfig USB_SERIAL 5menuconfig USB_SERIAL
6 tristate "USB Serial Converter support" 6 tristate "USB Serial Converter support"
7 depends on USB && TTY 7 depends on TTY
8 ---help--- 8 ---help---
9 Say Y here if you have a USB device that provides normal serial 9 Say Y here if you have a USB device that provides normal serial
10 ports, or acts like a serial device, and you want to connect it to 10 ports, or acts like a serial device, and you want to connect it to
@@ -667,6 +667,23 @@ config USB_SERIAL_ZIO
667 To compile this driver as a module, choose M here: the 667 To compile this driver as a module, choose M here: the
668 module will be called zio. 668 module will be called zio.
669 669
670config USB_SERIAL_WISHBONE
671 tristate "USB-Wishbone adapter interface driver"
672 help
673 Say Y here if you want to use a USB attached Wishbone bus.
674
675 Wishbone is an open hardware SoC bus commonly used in FPGA
676 designs. Bus access can be serialized using the Etherbone
677 protocol <http://www.ohwr.org/projects/etherbone-core>.
678
679 This driver is intended to be used with devices which attach
680 their internal Wishbone bus to a USB serial interface using
681 the Etherbone protocol. A userspace library is required to
682 speak the protocol made available by this driver as ttyUSBx.
683
684 To compile this driver as a module, choose M here: the
685 module will be called wishbone-serial.
686
670config USB_SERIAL_ZTE 687config USB_SERIAL_ZTE
671 tristate "ZTE USB serial driver" 688 tristate "ZTE USB serial driver"
672 help 689 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index eaf5ca14dfeb..cec63fa19104 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o
58obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o 58obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o
59obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 59obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
60obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 60obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
61obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o
61obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 62obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
62obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o 63obj-$(CONFIG_USB_SERIAL_XIRCOM) += keyspan_pda.o
63obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o 64obj-$(CONFIG_USB_SERIAL_VIVOPAY_SERIAL) += vivopay-serial.o
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 4775f8209e55..3b16118cbf62 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -62,7 +62,6 @@ static int is_irda(struct usb_serial *serial)
62} 62}
63 63
64struct ark3116_private { 64struct ark3116_private {
65 struct async_icount icount;
66 int irda; /* 1 for irda device */ 65 int irda; /* 1 for irda device */
67 66
68 /* protects hw register updates */ 67 /* protects hw register updates */
@@ -341,18 +340,15 @@ static void ark3116_close(struct usb_serial_port *port)
341{ 340{
342 struct usb_serial *serial = port->serial; 341 struct usb_serial *serial = port->serial;
343 342
344 if (serial->dev) { 343 /* disable DMA */
345 /* disable DMA */ 344 ark3116_write_reg(serial, UART_FCR, 0);
346 ark3116_write_reg(serial, UART_FCR, 0);
347
348 /* deactivate interrupts */
349 ark3116_write_reg(serial, UART_IER, 0);
350 345
351 usb_serial_generic_close(port); 346 /* deactivate interrupts */
352 if (serial->num_interrupt_in) 347 ark3116_write_reg(serial, UART_IER, 0);
353 usb_kill_urb(port->interrupt_in_urb);
354 }
355 348
349 usb_serial_generic_close(port);
350 if (serial->num_interrupt_in)
351 usb_kill_urb(port->interrupt_in_urb);
356} 352}
357 353
358static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port) 354static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -405,31 +401,10 @@ err_out:
405 return result; 401 return result;
406} 402}
407 403
408static int ark3116_get_icount(struct tty_struct *tty,
409 struct serial_icounter_struct *icount)
410{
411 struct usb_serial_port *port = tty->driver_data;
412 struct ark3116_private *priv = usb_get_serial_port_data(port);
413 struct async_icount cnow = priv->icount;
414 icount->cts = cnow.cts;
415 icount->dsr = cnow.dsr;
416 icount->rng = cnow.rng;
417 icount->dcd = cnow.dcd;
418 icount->rx = cnow.rx;
419 icount->tx = cnow.tx;
420 icount->frame = cnow.frame;
421 icount->overrun = cnow.overrun;
422 icount->parity = cnow.parity;
423 icount->brk = cnow.brk;
424 icount->buf_overrun = cnow.buf_overrun;
425 return 0;
426}
427
428static int ark3116_ioctl(struct tty_struct *tty, 404static int ark3116_ioctl(struct tty_struct *tty,
429 unsigned int cmd, unsigned long arg) 405 unsigned int cmd, unsigned long arg)
430{ 406{
431 struct usb_serial_port *port = tty->driver_data; 407 struct usb_serial_port *port = tty->driver_data;
432 struct ark3116_private *priv = usb_get_serial_port_data(port);
433 struct serial_struct serstruct; 408 struct serial_struct serstruct;
434 void __user *user_arg = (void __user *)arg; 409 void __user *user_arg = (void __user *)arg;
435 410
@@ -451,33 +426,6 @@ static int ark3116_ioctl(struct tty_struct *tty,
451 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct))) 426 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
452 return -EFAULT; 427 return -EFAULT;
453 return 0; 428 return 0;
454 case TIOCMIWAIT:
455 for (;;) {
456 struct async_icount prev = priv->icount;
457 interruptible_sleep_on(&port->delta_msr_wait);
458 /* see if a signal did it */
459 if (signal_pending(current))
460 return -ERESTARTSYS;
461
462 if (port->serial->disconnected)
463 return -EIO;
464
465 if ((prev.rng == priv->icount.rng) &&
466 (prev.dsr == priv->icount.dsr) &&
467 (prev.dcd == priv->icount.dcd) &&
468 (prev.cts == priv->icount.cts))
469 return -EIO;
470 if ((arg & TIOCM_RNG &&
471 (prev.rng != priv->icount.rng)) ||
472 (arg & TIOCM_DSR &&
473 (prev.dsr != priv->icount.dsr)) ||
474 (arg & TIOCM_CD &&
475 (prev.dcd != priv->icount.dcd)) ||
476 (arg & TIOCM_CTS &&
477 (prev.cts != priv->icount.cts)))
478 return 0;
479 }
480 break;
481 } 429 }
482 430
483 return -ENOIOCTLCMD; 431 return -ENOIOCTLCMD;
@@ -575,14 +523,14 @@ static void ark3116_update_msr(struct usb_serial_port *port, __u8 msr)
575 if (msr & UART_MSR_ANY_DELTA) { 523 if (msr & UART_MSR_ANY_DELTA) {
576 /* update input line counters */ 524 /* update input line counters */
577 if (msr & UART_MSR_DCTS) 525 if (msr & UART_MSR_DCTS)
578 priv->icount.cts++; 526 port->icount.cts++;
579 if (msr & UART_MSR_DDSR) 527 if (msr & UART_MSR_DDSR)
580 priv->icount.dsr++; 528 port->icount.dsr++;
581 if (msr & UART_MSR_DDCD) 529 if (msr & UART_MSR_DDCD)
582 priv->icount.dcd++; 530 port->icount.dcd++;
583 if (msr & UART_MSR_TERI) 531 if (msr & UART_MSR_TERI)
584 priv->icount.rng++; 532 port->icount.rng++;
585 wake_up_interruptible(&port->delta_msr_wait); 533 wake_up_interruptible(&port->port.delta_msr_wait);
586 } 534 }
587} 535}
588 536
@@ -598,13 +546,13 @@ static void ark3116_update_lsr(struct usb_serial_port *port, __u8 lsr)
598 546
599 if (lsr&UART_LSR_BRK_ERROR_BITS) { 547 if (lsr&UART_LSR_BRK_ERROR_BITS) {
600 if (lsr & UART_LSR_BI) 548 if (lsr & UART_LSR_BI)
601 priv->icount.brk++; 549 port->icount.brk++;
602 if (lsr & UART_LSR_FE) 550 if (lsr & UART_LSR_FE)
603 priv->icount.frame++; 551 port->icount.frame++;
604 if (lsr & UART_LSR_PE) 552 if (lsr & UART_LSR_PE)
605 priv->icount.parity++; 553 port->icount.parity++;
606 if (lsr & UART_LSR_OE) 554 if (lsr & UART_LSR_OE)
607 priv->icount.overrun++; 555 port->icount.overrun++;
608 } 556 }
609} 557}
610 558
@@ -722,7 +670,8 @@ static struct usb_serial_driver ark3116_device = {
722 .ioctl = ark3116_ioctl, 670 .ioctl = ark3116_ioctl,
723 .tiocmget = ark3116_tiocmget, 671 .tiocmget = ark3116_tiocmget,
724 .tiocmset = ark3116_tiocmset, 672 .tiocmset = ark3116_tiocmset,
725 .get_icount = ark3116_get_icount, 673 .tiocmiwait = usb_serial_generic_tiocmiwait,
674 .get_icount = usb_serial_generic_get_icount,
726 .open = ark3116_open, 675 .open = ark3116_open,
727 .close = ark3116_close, 676 .close = ark3116_close,
728 .break_ctl = ark3116_break_ctl, 677 .break_ctl = ark3116_break_ctl,
diff --git a/drivers/usb/serial/bus.c b/drivers/usb/serial/bus.c
index 37decb13d7eb..3c4db6d196c6 100644
--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -106,14 +106,15 @@ static int usb_serial_device_remove(struct device *dev)
106 /* make sure suspend/resume doesn't race against port_remove */ 106 /* make sure suspend/resume doesn't race against port_remove */
107 usb_autopm_get_interface(port->serial->interface); 107 usb_autopm_get_interface(port->serial->interface);
108 108
109 minor = port->number;
110 tty_unregister_device(usb_serial_tty_driver, minor);
111
109 device_remove_file(&port->dev, &dev_attr_port_number); 112 device_remove_file(&port->dev, &dev_attr_port_number);
110 113
111 driver = port->serial->type; 114 driver = port->serial->type;
112 if (driver->port_remove) 115 if (driver->port_remove)
113 retval = driver->port_remove(port); 116 retval = driver->port_remove(port);
114 117
115 minor = port->number;
116 tty_unregister_device(usb_serial_tty_driver, minor);
117 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 118 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
118 driver->description, minor); 119 driver->description, minor);
119 120
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 07d4650a32ab..c2a4171ab9cb 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -296,7 +296,6 @@ static void ch341_dtr_rts(struct usb_serial_port *port, int on)
296 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR); 296 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
297 spin_unlock_irqrestore(&priv->lock, flags); 297 spin_unlock_irqrestore(&priv->lock, flags);
298 ch341_set_handshake(port->serial->dev, priv->line_control); 298 ch341_set_handshake(port->serial->dev, priv->line_control);
299 wake_up_interruptible(&port->delta_msr_wait);
300} 299}
301 300
302static void ch341_close(struct usb_serial_port *port) 301static void ch341_close(struct usb_serial_port *port)
@@ -489,7 +488,7 @@ static void ch341_read_int_callback(struct urb *urb)
489 tty_kref_put(tty); 488 tty_kref_put(tty);
490 } 489 }
491 490
492 wake_up_interruptible(&port->delta_msr_wait); 491 wake_up_interruptible(&port->port.delta_msr_wait);
493 } 492 }
494 493
495exit: 494exit:
@@ -500,8 +499,9 @@ exit:
500 __func__, status); 499 __func__, status);
501} 500}
502 501
503static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 502static int ch341_tiocmiwait(struct tty_struct *tty, unsigned long arg)
504{ 503{
504 struct usb_serial_port *port = tty->driver_data;
505 struct ch341_private *priv = usb_get_serial_port_data(port); 505 struct ch341_private *priv = usb_get_serial_port_data(port);
506 unsigned long flags; 506 unsigned long flags;
507 u8 prevstatus; 507 u8 prevstatus;
@@ -515,7 +515,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
515 spin_unlock_irqrestore(&priv->lock, flags); 515 spin_unlock_irqrestore(&priv->lock, flags);
516 516
517 while (!multi_change) { 517 while (!multi_change) {
518 interruptible_sleep_on(&port->delta_msr_wait); 518 interruptible_sleep_on(&port->port.delta_msr_wait);
519 /* see if a signal did it */ 519 /* see if a signal did it */
520 if (signal_pending(current)) 520 if (signal_pending(current))
521 return -ERESTARTSYS; 521 return -ERESTARTSYS;
@@ -542,26 +542,6 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
542 return 0; 542 return 0;
543} 543}
544 544
545static int ch341_ioctl(struct tty_struct *tty,
546 unsigned int cmd, unsigned long arg)
547{
548 struct usb_serial_port *port = tty->driver_data;
549
550 dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__, port->number, cmd);
551
552 switch (cmd) {
553 case TIOCMIWAIT:
554 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number);
555 return wait_modem_info(port, arg);
556
557 default:
558 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd);
559 break;
560 }
561
562 return -ENOIOCTLCMD;
563}
564
565static int ch341_tiocmget(struct tty_struct *tty) 545static int ch341_tiocmget(struct tty_struct *tty)
566{ 546{
567 struct usb_serial_port *port = tty->driver_data; 547 struct usb_serial_port *port = tty->driver_data;
@@ -611,11 +591,11 @@ static struct usb_serial_driver ch341_device = {
611 .dtr_rts = ch341_dtr_rts, 591 .dtr_rts = ch341_dtr_rts,
612 .carrier_raised = ch341_carrier_raised, 592 .carrier_raised = ch341_carrier_raised,
613 .close = ch341_close, 593 .close = ch341_close,
614 .ioctl = ch341_ioctl,
615 .set_termios = ch341_set_termios, 594 .set_termios = ch341_set_termios,
616 .break_ctl = ch341_break_ctl, 595 .break_ctl = ch341_break_ctl,
617 .tiocmget = ch341_tiocmget, 596 .tiocmget = ch341_tiocmget,
618 .tiocmset = ch341_tiocmset, 597 .tiocmset = ch341_tiocmset,
598 .tiocmiwait = ch341_tiocmiwait,
619 .read_int_callback = ch341_read_int_callback, 599 .read_int_callback = ch341_read_int_callback,
620 .port_probe = ch341_port_probe, 600 .port_probe = ch341_port_probe,
621 .port_remove = ch341_port_remove, 601 .port_remove = ch341_port_remove,
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 4747d1c328ff..2c659553c07c 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -462,11 +462,7 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
462static void cp210x_close(struct usb_serial_port *port) 462static void cp210x_close(struct usb_serial_port *port)
463{ 463{
464 usb_serial_generic_close(port); 464 usb_serial_generic_close(port);
465 465 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
466 mutex_lock(&port->serial->disc_mutex);
467 if (!port->serial->disconnected)
468 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
469 mutex_unlock(&port->serial->disc_mutex);
470} 466}
471 467
472/* 468/*
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 629bd2894506..781426230d69 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -51,7 +51,6 @@
51#define CYBERJACK_PRODUCT_ID 0x0100 51#define CYBERJACK_PRODUCT_ID 0x0100
52 52
53/* Function prototypes */ 53/* Function prototypes */
54static void cyberjack_disconnect(struct usb_serial *serial);
55static int cyberjack_port_probe(struct usb_serial_port *port); 54static int cyberjack_port_probe(struct usb_serial_port *port);
56static int cyberjack_port_remove(struct usb_serial_port *port); 55static int cyberjack_port_remove(struct usb_serial_port *port);
57static int cyberjack_open(struct tty_struct *tty, 56static int cyberjack_open(struct tty_struct *tty,
@@ -79,7 +78,6 @@ static struct usb_serial_driver cyberjack_device = {
79 .description = "Reiner SCT Cyberjack USB card reader", 78 .description = "Reiner SCT Cyberjack USB card reader",
80 .id_table = id_table, 79 .id_table = id_table,
81 .num_ports = 1, 80 .num_ports = 1,
82 .disconnect = cyberjack_disconnect,
83 .port_probe = cyberjack_port_probe, 81 .port_probe = cyberjack_port_probe,
84 .port_remove = cyberjack_port_remove, 82 .port_remove = cyberjack_port_remove,
85 .open = cyberjack_open, 83 .open = cyberjack_open,
@@ -130,20 +128,14 @@ static int cyberjack_port_remove(struct usb_serial_port *port)
130{ 128{
131 struct cyberjack_private *priv; 129 struct cyberjack_private *priv;
132 130
131 usb_kill_urb(port->interrupt_in_urb);
132
133 priv = usb_get_serial_port_data(port); 133 priv = usb_get_serial_port_data(port);
134 kfree(priv); 134 kfree(priv);
135 135
136 return 0; 136 return 0;
137} 137}
138 138
139static void cyberjack_disconnect(struct usb_serial *serial)
140{
141 int i;
142
143 for (i = 0; i < serial->num_ports; ++i)
144 usb_kill_urb(serial->port[i]->interrupt_in_urb);
145}
146
147static int cyberjack_open(struct tty_struct *tty, 139static int cyberjack_open(struct tty_struct *tty,
148 struct usb_serial_port *port) 140 struct usb_serial_port *port)
149{ 141{
@@ -166,11 +158,8 @@ static int cyberjack_open(struct tty_struct *tty,
166 158
167static void cyberjack_close(struct usb_serial_port *port) 159static void cyberjack_close(struct usb_serial_port *port)
168{ 160{
169 if (port->serial->dev) { 161 usb_kill_urb(port->write_urb);
170 /* shutdown any bulk reads that might be going on */ 162 usb_kill_urb(port->read_urb);
171 usb_kill_urb(port->write_urb);
172 usb_kill_urb(port->read_urb);
173 }
174} 163}
175 164
176static int cyberjack_write(struct tty_struct *tty, 165static int cyberjack_write(struct tty_struct *tty,
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index ba7352e4187e..d341555d37d8 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -129,13 +129,12 @@ static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
129 const unsigned char *buf, int count); 129 const unsigned char *buf, int count);
130static void cypress_send(struct usb_serial_port *port); 130static void cypress_send(struct usb_serial_port *port);
131static int cypress_write_room(struct tty_struct *tty); 131static int cypress_write_room(struct tty_struct *tty);
132static int cypress_ioctl(struct tty_struct *tty,
133 unsigned int cmd, unsigned long arg);
134static void cypress_set_termios(struct tty_struct *tty, 132static void cypress_set_termios(struct tty_struct *tty,
135 struct usb_serial_port *port, struct ktermios *old); 133 struct usb_serial_port *port, struct ktermios *old);
136static int cypress_tiocmget(struct tty_struct *tty); 134static int cypress_tiocmget(struct tty_struct *tty);
137static int cypress_tiocmset(struct tty_struct *tty, 135static int cypress_tiocmset(struct tty_struct *tty,
138 unsigned int set, unsigned int clear); 136 unsigned int set, unsigned int clear);
137static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg);
139static int cypress_chars_in_buffer(struct tty_struct *tty); 138static int cypress_chars_in_buffer(struct tty_struct *tty);
140static void cypress_throttle(struct tty_struct *tty); 139static void cypress_throttle(struct tty_struct *tty);
141static void cypress_unthrottle(struct tty_struct *tty); 140static void cypress_unthrottle(struct tty_struct *tty);
@@ -158,10 +157,10 @@ static struct usb_serial_driver cypress_earthmate_device = {
158 .dtr_rts = cypress_dtr_rts, 157 .dtr_rts = cypress_dtr_rts,
159 .write = cypress_write, 158 .write = cypress_write,
160 .write_room = cypress_write_room, 159 .write_room = cypress_write_room,
161 .ioctl = cypress_ioctl,
162 .set_termios = cypress_set_termios, 160 .set_termios = cypress_set_termios,
163 .tiocmget = cypress_tiocmget, 161 .tiocmget = cypress_tiocmget,
164 .tiocmset = cypress_tiocmset, 162 .tiocmset = cypress_tiocmset,
163 .tiocmiwait = cypress_tiocmiwait,
165 .chars_in_buffer = cypress_chars_in_buffer, 164 .chars_in_buffer = cypress_chars_in_buffer,
166 .throttle = cypress_throttle, 165 .throttle = cypress_throttle,
167 .unthrottle = cypress_unthrottle, 166 .unthrottle = cypress_unthrottle,
@@ -184,10 +183,10 @@ static struct usb_serial_driver cypress_hidcom_device = {
184 .dtr_rts = cypress_dtr_rts, 183 .dtr_rts = cypress_dtr_rts,
185 .write = cypress_write, 184 .write = cypress_write,
186 .write_room = cypress_write_room, 185 .write_room = cypress_write_room,
187 .ioctl = cypress_ioctl,
188 .set_termios = cypress_set_termios, 186 .set_termios = cypress_set_termios,
189 .tiocmget = cypress_tiocmget, 187 .tiocmget = cypress_tiocmget,
190 .tiocmset = cypress_tiocmset, 188 .tiocmset = cypress_tiocmset,
189 .tiocmiwait = cypress_tiocmiwait,
191 .chars_in_buffer = cypress_chars_in_buffer, 190 .chars_in_buffer = cypress_chars_in_buffer,
192 .throttle = cypress_throttle, 191 .throttle = cypress_throttle,
193 .unthrottle = cypress_unthrottle, 192 .unthrottle = cypress_unthrottle,
@@ -210,10 +209,10 @@ static struct usb_serial_driver cypress_ca42v2_device = {
210 .dtr_rts = cypress_dtr_rts, 209 .dtr_rts = cypress_dtr_rts,
211 .write = cypress_write, 210 .write = cypress_write,
212 .write_room = cypress_write_room, 211 .write_room = cypress_write_room,
213 .ioctl = cypress_ioctl,
214 .set_termios = cypress_set_termios, 212 .set_termios = cypress_set_termios,
215 .tiocmget = cypress_tiocmget, 213 .tiocmget = cypress_tiocmget,
216 .tiocmset = cypress_tiocmset, 214 .tiocmset = cypress_tiocmset,
215 .tiocmiwait = cypress_tiocmiwait,
217 .chars_in_buffer = cypress_chars_in_buffer, 216 .chars_in_buffer = cypress_chars_in_buffer,
218 .throttle = cypress_throttle, 217 .throttle = cypress_throttle,
219 .unthrottle = cypress_unthrottle, 218 .unthrottle = cypress_unthrottle,
@@ -633,12 +632,6 @@ static void cypress_close(struct usb_serial_port *port)
633 struct cypress_private *priv = usb_get_serial_port_data(port); 632 struct cypress_private *priv = usb_get_serial_port_data(port);
634 unsigned long flags; 633 unsigned long flags;
635 634
636 /* writing is potentially harmful, lock must be taken */
637 mutex_lock(&port->serial->disc_mutex);
638 if (port->serial->disconnected) {
639 mutex_unlock(&port->serial->disc_mutex);
640 return;
641 }
642 spin_lock_irqsave(&priv->lock, flags); 635 spin_lock_irqsave(&priv->lock, flags);
643 kfifo_reset_out(&priv->write_fifo); 636 kfifo_reset_out(&priv->write_fifo);
644 spin_unlock_irqrestore(&priv->lock, flags); 637 spin_unlock_irqrestore(&priv->lock, flags);
@@ -650,7 +643,6 @@ static void cypress_close(struct usb_serial_port *port)
650 if (stats) 643 if (stats)
651 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 644 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
652 priv->bytes_in, priv->bytes_out, priv->cmd_count); 645 priv->bytes_in, priv->bytes_out, priv->cmd_count);
653 mutex_unlock(&port->serial->disc_mutex);
654} /* cypress_close */ 646} /* cypress_close */
655 647
656 648
@@ -855,55 +847,43 @@ static int cypress_tiocmset(struct tty_struct *tty,
855} 847}
856 848
857 849
858static int cypress_ioctl(struct tty_struct *tty, 850static int cypress_tiocmiwait(struct tty_struct *tty, unsigned long arg)
859 unsigned int cmd, unsigned long arg)
860{ 851{
861 struct usb_serial_port *port = tty->driver_data; 852 struct usb_serial_port *port = tty->driver_data;
862 struct cypress_private *priv = usb_get_serial_port_data(port); 853 struct cypress_private *priv = usb_get_serial_port_data(port);
863 854 char diff;
864 dev_dbg(&port->dev, "%s - port %d, cmd 0x%.4x\n", __func__, port->number, cmd); 855
865 856 for (;;) {
866 switch (cmd) { 857 interruptible_sleep_on(&port->port.delta_msr_wait);
867 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 858 /* see if a signal did it */
868 case TIOCMIWAIT: 859 if (signal_pending(current))
869 for (;;) { 860 return -ERESTARTSYS;
870 interruptible_sleep_on(&port->delta_msr_wait); 861
871 /* see if a signal did it */ 862 if (port->serial->disconnected)
872 if (signal_pending(current)) 863 return -EIO;
873 return -ERESTARTSYS; 864
874 865 diff = priv->diff_status;
875 if (port->serial->disconnected) 866 if (diff == 0)
876 return -EIO; 867 return -EIO; /* no change => error */
877 868
878 { 869 /* consume all events */
879 char diff = priv->diff_status; 870 priv->diff_status = 0;
880 if (diff == 0) 871
881 return -EIO; /* no change => error */ 872 /* return 0 if caller wanted to know about
882 873 these bits */
883 /* consume all events */ 874 if (((arg & TIOCM_RNG) && (diff & UART_RI)) ||
884 priv->diff_status = 0; 875 ((arg & TIOCM_DSR) && (diff & UART_DSR)) ||
885 876 ((arg & TIOCM_CD) && (diff & UART_CD)) ||
886 /* return 0 if caller wanted to know about 877 ((arg & TIOCM_CTS) && (diff & UART_CTS)))
887 these bits */ 878 return 0;
888 if (((arg & TIOCM_RNG) && (diff & UART_RI)) || 879 /* otherwise caller can't care less about what
889 ((arg & TIOCM_DSR) && (diff & UART_DSR)) || 880 * happened, and so we continue to wait for
890 ((arg & TIOCM_CD) && (diff & UART_CD)) || 881 * more events.
891 ((arg & TIOCM_CTS) && (diff & UART_CTS))) 882 */
892 return 0;
893 /* otherwise caller can't care less about what
894 * happened, and so we continue to wait for
895 * more events.
896 */
897 }
898 }
899 return 0;
900 default:
901 break;
902 } 883 }
903 dev_dbg(&port->dev, "%s - arg not supported - it was 0x%04x - check include/asm/ioctls.h\n", __func__, cmd);
904 return -ENOIOCTLCMD;
905} /* cypress_ioctl */
906 884
885 return 0;
886}
907 887
908static void cypress_set_termios(struct tty_struct *tty, 888static void cypress_set_termios(struct tty_struct *tty,
909 struct usb_serial_port *port, struct ktermios *old_termios) 889 struct usb_serial_port *port, struct ktermios *old_termios)
@@ -1189,7 +1169,7 @@ static void cypress_read_int_callback(struct urb *urb)
1189 if (priv->current_status != priv->prev_status) { 1169 if (priv->current_status != priv->prev_status) {
1190 priv->diff_status |= priv->current_status ^ 1170 priv->diff_status |= priv->current_status ^
1191 priv->prev_status; 1171 priv->prev_status;
1192 wake_up_interruptible(&port->delta_msr_wait); 1172 wake_up_interruptible(&port->port.delta_msr_wait);
1193 priv->prev_status = priv->current_status; 1173 priv->prev_status = priv->current_status;
1194 } 1174 }
1195 spin_unlock_irqrestore(&priv->lock, flags); 1175 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 31191581060c..7b807d389527 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -196,7 +196,6 @@ struct digi_port {
196 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE]; 196 unsigned char dp_out_buf[DIGI_OUT_BUF_SIZE];
197 int dp_write_urb_in_use; 197 int dp_write_urb_in_use;
198 unsigned int dp_modem_signals; 198 unsigned int dp_modem_signals;
199 wait_queue_head_t dp_modem_change_wait;
200 int dp_transmit_idle; 199 int dp_transmit_idle;
201 wait_queue_head_t dp_transmit_idle_wait; 200 wait_queue_head_t dp_transmit_idle_wait;
202 int dp_throttled; 201 int dp_throttled;
@@ -1138,53 +1137,51 @@ static void digi_close(struct usb_serial_port *port)
1138 if (port->serial->disconnected) 1137 if (port->serial->disconnected)
1139 goto exit; 1138 goto exit;
1140 1139
1141 if (port->serial->dev) { 1140 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1142 /* FIXME: Transmit idle belongs in the wait_unti_sent path */ 1141 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1143 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT); 1142
1144 1143 /* disable input flow control */
1145 /* disable input flow control */ 1144 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
1146 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; 1145 buf[1] = priv->dp_port_num;
1147 buf[1] = priv->dp_port_num; 1146 buf[2] = DIGI_DISABLE;
1148 buf[2] = DIGI_DISABLE; 1147 buf[3] = 0;
1149 buf[3] = 0; 1148
1150 1149 /* disable output flow control */
1151 /* disable output flow control */ 1150 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL;
1152 buf[4] = DIGI_CMD_SET_OUTPUT_FLOW_CONTROL; 1151 buf[5] = priv->dp_port_num;
1153 buf[5] = priv->dp_port_num; 1152 buf[6] = DIGI_DISABLE;
1154 buf[6] = DIGI_DISABLE; 1153 buf[7] = 0;
1155 buf[7] = 0; 1154
1156 1155 /* disable reading modem signals automatically */
1157 /* disable reading modem signals automatically */ 1156 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS;
1158 buf[8] = DIGI_CMD_READ_INPUT_SIGNALS; 1157 buf[9] = priv->dp_port_num;
1159 buf[9] = priv->dp_port_num; 1158 buf[10] = DIGI_DISABLE;
1160 buf[10] = DIGI_DISABLE; 1159 buf[11] = 0;
1161 buf[11] = 0; 1160
1162 1161 /* disable receive */
1163 /* disable receive */ 1162 buf[12] = DIGI_CMD_RECEIVE_ENABLE;
1164 buf[12] = DIGI_CMD_RECEIVE_ENABLE; 1163 buf[13] = priv->dp_port_num;
1165 buf[13] = priv->dp_port_num; 1164 buf[14] = DIGI_DISABLE;
1166 buf[14] = DIGI_DISABLE; 1165 buf[15] = 0;
1167 buf[15] = 0; 1166
1168 1167 /* flush fifos */
1169 /* flush fifos */ 1168 buf[16] = DIGI_CMD_IFLUSH_FIFO;
1170 buf[16] = DIGI_CMD_IFLUSH_FIFO; 1169 buf[17] = priv->dp_port_num;
1171 buf[17] = priv->dp_port_num; 1170 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX;
1172 buf[18] = DIGI_FLUSH_TX | DIGI_FLUSH_RX; 1171 buf[19] = 0;
1173 buf[19] = 0; 1172
1174 1173 ret = digi_write_oob_command(port, buf, 20, 0);
1175 ret = digi_write_oob_command(port, buf, 20, 0); 1174 if (ret != 0)
1176 if (ret != 0) 1175 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n",
1177 dev_dbg(&port->dev, "digi_close: write oob failed, ret=%d\n", ret); 1176 ret);
1178 1177 /* wait for final commands on oob port to complete */
1179 /* wait for final commands on oob port to complete */ 1178 prepare_to_wait(&priv->dp_flush_wait, &wait,
1180 prepare_to_wait(&priv->dp_flush_wait, &wait, 1179 TASK_INTERRUPTIBLE);
1181 TASK_INTERRUPTIBLE); 1180 schedule_timeout(DIGI_CLOSE_TIMEOUT);
1182 schedule_timeout(DIGI_CLOSE_TIMEOUT); 1181 finish_wait(&priv->dp_flush_wait, &wait);
1183 finish_wait(&priv->dp_flush_wait, &wait); 1182
1184 1183 /* shutdown any outstanding bulk writes */
1185 /* shutdown any outstanding bulk writes */ 1184 usb_kill_urb(port->write_urb);
1186 usb_kill_urb(port->write_urb);
1187 }
1188exit: 1185exit:
1189 spin_lock_irq(&priv->dp_port_lock); 1186 spin_lock_irq(&priv->dp_port_lock);
1190 priv->dp_write_urb_in_use = 0; 1187 priv->dp_write_urb_in_use = 0;
@@ -1241,7 +1238,6 @@ static int digi_port_init(struct usb_serial_port *port, unsigned port_num)
1241 1238
1242 spin_lock_init(&priv->dp_port_lock); 1239 spin_lock_init(&priv->dp_port_lock);
1243 priv->dp_port_num = port_num; 1240 priv->dp_port_num = port_num;
1244 init_waitqueue_head(&priv->dp_modem_change_wait);
1245 init_waitqueue_head(&priv->dp_transmit_idle_wait); 1241 init_waitqueue_head(&priv->dp_transmit_idle_wait);
1246 init_waitqueue_head(&priv->dp_flush_wait); 1242 init_waitqueue_head(&priv->dp_flush_wait);
1247 init_waitqueue_head(&priv->dp_close_wait); 1243 init_waitqueue_head(&priv->dp_close_wait);
@@ -1532,7 +1528,6 @@ static int digi_read_oob_callback(struct urb *urb)
1532 else 1528 else
1533 priv->dp_modem_signals &= ~TIOCM_CD; 1529 priv->dp_modem_signals &= ~TIOCM_CD;
1534 1530
1535 wake_up_interruptible(&priv->dp_modem_change_wait);
1536 spin_unlock(&priv->dp_port_lock); 1531 spin_unlock(&priv->dp_port_lock);
1537 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) { 1532 } else if (opcode == DIGI_CMD_TRANSMIT_IDLE) {
1538 spin_lock(&priv->dp_port_lock); 1533 spin_lock(&priv->dp_port_lock);
diff --git a/drivers/usb/serial/f81232.c b/drivers/usb/serial/f81232.c
index a172ad5c5ce8..090b411d893f 100644
--- a/drivers/usb/serial/f81232.c
+++ b/drivers/usb/serial/f81232.c
@@ -110,7 +110,7 @@ static void f81232_process_read_urb(struct urb *urb)
110 line_status = priv->line_status; 110 line_status = priv->line_status;
111 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 111 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
112 spin_unlock_irqrestore(&priv->lock, flags); 112 spin_unlock_irqrestore(&priv->lock, flags);
113 wake_up_interruptible(&port->delta_msr_wait); 113 wake_up_interruptible(&port->port.delta_msr_wait);
114 114
115 if (!urb->actual_length) 115 if (!urb->actual_length)
116 return; 116 return;
@@ -242,8 +242,9 @@ static int f81232_carrier_raised(struct usb_serial_port *port)
242 return 0; 242 return 0;
243} 243}
244 244
245static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 245static int f81232_tiocmiwait(struct tty_struct *tty, unsigned long arg)
246{ 246{
247 struct usb_serial_port *port = tty->driver_data;
247 struct f81232_private *priv = usb_get_serial_port_data(port); 248 struct f81232_private *priv = usb_get_serial_port_data(port);
248 unsigned long flags; 249 unsigned long flags;
249 unsigned int prevstatus; 250 unsigned int prevstatus;
@@ -255,7 +256,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
255 spin_unlock_irqrestore(&priv->lock, flags); 256 spin_unlock_irqrestore(&priv->lock, flags);
256 257
257 while (1) { 258 while (1) {
258 interruptible_sleep_on(&port->delta_msr_wait); 259 interruptible_sleep_on(&port->port.delta_msr_wait);
259 /* see if a signal did it */ 260 /* see if a signal did it */
260 if (signal_pending(current)) 261 if (signal_pending(current))
261 return -ERESTARTSYS; 262 return -ERESTARTSYS;
@@ -302,11 +303,6 @@ static int f81232_ioctl(struct tty_struct *tty,
302 return -EFAULT; 303 return -EFAULT;
303 304
304 return 0; 305 return 0;
305
306 case TIOCMIWAIT:
307 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
308 port->number);
309 return wait_modem_info(port, arg);
310 default: 306 default:
311 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", 307 dev_dbg(&port->dev, "%s not supported = 0x%04x\n",
312 __func__, cmd); 308 __func__, cmd);
@@ -358,6 +354,7 @@ static struct usb_serial_driver f81232_device = {
358 .set_termios = f81232_set_termios, 354 .set_termios = f81232_set_termios,
359 .tiocmget = f81232_tiocmget, 355 .tiocmget = f81232_tiocmget,
360 .tiocmset = f81232_tiocmset, 356 .tiocmset = f81232_tiocmset,
357 .tiocmiwait = f81232_tiocmiwait,
361 .process_read_urb = f81232_process_read_urb, 358 .process_read_urb = f81232_process_read_urb,
362 .read_int_callback = f81232_read_int_callback, 359 .read_int_callback = f81232_read_int_callback,
363 .port_probe = f81232_port_probe, 360 .port_probe = f81232_port_probe,
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 9886180e45f1..242b5776648a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB FTDI SIO driver 2 * USB FTDI SIO driver
3 * 3 *
4 * Copyright (C) 2009 - 2010 4 * Copyright (C) 2009 - 2013
5 * Johan Hovold (jhovold@gmail.com) 5 * Johan Hovold (jhovold@gmail.com)
6 * Copyright (C) 1999 - 2001 6 * Copyright (C) 1999 - 2001
7 * Greg Kroah-Hartman (greg@kroah.com) 7 * Greg Kroah-Hartman (greg@kroah.com)
@@ -55,7 +55,6 @@ static __u16 vendor = FTDI_VID;
55static __u16 product; 55static __u16 product;
56 56
57struct ftdi_private { 57struct ftdi_private {
58 struct kref kref;
59 enum ftdi_chip_type chip_type; 58 enum ftdi_chip_type chip_type;
60 /* type of device, either SIO or FT8U232AM */ 59 /* type of device, either SIO or FT8U232AM */
61 int baud_base; /* baud base clock for divisor setting */ 60 int baud_base; /* baud base clock for divisor setting */
@@ -68,7 +67,6 @@ struct ftdi_private {
68 */ 67 */
69 int flags; /* some ASYNC_xxxx flags are supported */ 68 int flags; /* some ASYNC_xxxx flags are supported */
70 unsigned long last_dtr_rts; /* saved modem control outputs */ 69 unsigned long last_dtr_rts; /* saved modem control outputs */
71 struct async_icount icount;
72 char prev_status; /* Used for TIOCMIWAIT */ 70 char prev_status; /* Used for TIOCMIWAIT */
73 char transmit_empty; /* If transmitter is empty or not */ 71 char transmit_empty; /* If transmitter is empty or not */
74 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface 72 __u16 interface; /* FT2232C, FT2232H or FT4232H port interface
@@ -189,6 +187,7 @@ static struct usb_device_id id_table_combined [] = {
189 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) }, 187 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_THROTTLE_PID) },
190 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) }, 188 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GATEWAY_PID) },
191 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GBM_PID) }, 189 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GBM_PID) },
190 { USB_DEVICE(FTDI_VID, FTDI_OPENDCC_GBM_BOOST_PID) },
192 { USB_DEVICE(NEWPORT_VID, NEWPORT_AGILIS_PID) }, 191 { USB_DEVICE(NEWPORT_VID, NEWPORT_AGILIS_PID) },
193 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) }, 192 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_IOBOARD_PID) },
194 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) }, 193 { USB_DEVICE(INTERBIOMETRICS_VID, INTERBIOMETRICS_MINI_IOBOARD_PID) },
@@ -870,7 +869,9 @@ static struct usb_device_id id_table_combined [] = {
870 { USB_DEVICE(FTDI_VID, FTDI_DOTEC_PID) }, 869 { USB_DEVICE(FTDI_VID, FTDI_DOTEC_PID) },
871 { USB_DEVICE(QIHARDWARE_VID, MILKYMISTONE_JTAGSERIAL_PID), 870 { USB_DEVICE(QIHARDWARE_VID, MILKYMISTONE_JTAGSERIAL_PID),
872 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, 871 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
873 { USB_DEVICE(ST_VID, ST_STMCLT1030_PID), 872 { USB_DEVICE(ST_VID, ST_STMCLT_2232_PID),
873 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk },
874 { USB_DEVICE(ST_VID, ST_STMCLT_4232_PID),
874 .driver_info = (kernel_ulong_t)&ftdi_stmclite_quirk }, 875 .driver_info = (kernel_ulong_t)&ftdi_stmclite_quirk },
875 { USB_DEVICE(FTDI_VID, FTDI_RF_R106) }, 876 { USB_DEVICE(FTDI_VID, FTDI_RF_R106) },
876 { USB_DEVICE(FTDI_VID, FTDI_DISTORTEC_JTAG_LOCK_PICK_PID), 877 { USB_DEVICE(FTDI_VID, FTDI_DISTORTEC_JTAG_LOCK_PICK_PID),
@@ -911,7 +912,6 @@ static int ftdi_sio_probe(struct usb_serial *serial,
911static int ftdi_sio_port_probe(struct usb_serial_port *port); 912static int ftdi_sio_port_probe(struct usb_serial_port *port);
912static int ftdi_sio_port_remove(struct usb_serial_port *port); 913static int ftdi_sio_port_remove(struct usb_serial_port *port);
913static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); 914static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port);
914static void ftdi_close(struct usb_serial_port *port);
915static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 915static void ftdi_dtr_rts(struct usb_serial_port *port, int on);
916static void ftdi_process_read_urb(struct urb *urb); 916static void ftdi_process_read_urb(struct urb *urb);
917static int ftdi_prepare_write_buffer(struct usb_serial_port *port, 917static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
@@ -921,8 +921,6 @@ static void ftdi_set_termios(struct tty_struct *tty,
921static int ftdi_tiocmget(struct tty_struct *tty); 921static int ftdi_tiocmget(struct tty_struct *tty);
922static int ftdi_tiocmset(struct tty_struct *tty, 922static int ftdi_tiocmset(struct tty_struct *tty,
923 unsigned int set, unsigned int clear); 923 unsigned int set, unsigned int clear);
924static int ftdi_get_icount(struct tty_struct *tty,
925 struct serial_icounter_struct *icount);
926static int ftdi_ioctl(struct tty_struct *tty, 924static int ftdi_ioctl(struct tty_struct *tty,
927 unsigned int cmd, unsigned long arg); 925 unsigned int cmd, unsigned long arg);
928static void ftdi_break_ctl(struct tty_struct *tty, int break_state); 926static void ftdi_break_ctl(struct tty_struct *tty, int break_state);
@@ -951,7 +949,6 @@ static struct usb_serial_driver ftdi_sio_device = {
951 .port_probe = ftdi_sio_port_probe, 949 .port_probe = ftdi_sio_port_probe,
952 .port_remove = ftdi_sio_port_remove, 950 .port_remove = ftdi_sio_port_remove,
953 .open = ftdi_open, 951 .open = ftdi_open,
954 .close = ftdi_close,
955 .dtr_rts = ftdi_dtr_rts, 952 .dtr_rts = ftdi_dtr_rts,
956 .throttle = usb_serial_generic_throttle, 953 .throttle = usb_serial_generic_throttle,
957 .unthrottle = usb_serial_generic_unthrottle, 954 .unthrottle = usb_serial_generic_unthrottle,
@@ -959,7 +956,8 @@ static struct usb_serial_driver ftdi_sio_device = {
959 .prepare_write_buffer = ftdi_prepare_write_buffer, 956 .prepare_write_buffer = ftdi_prepare_write_buffer,
960 .tiocmget = ftdi_tiocmget, 957 .tiocmget = ftdi_tiocmget,
961 .tiocmset = ftdi_tiocmset, 958 .tiocmset = ftdi_tiocmset,
962 .get_icount = ftdi_get_icount, 959 .tiocmiwait = usb_serial_generic_tiocmiwait,
960 .get_icount = usb_serial_generic_get_icount,
963 .ioctl = ftdi_ioctl, 961 .ioctl = ftdi_ioctl,
964 .set_termios = ftdi_set_termios, 962 .set_termios = ftdi_set_termios,
965 .break_ctl = ftdi_break_ctl, 963 .break_ctl = ftdi_break_ctl,
@@ -1688,7 +1686,6 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1688 return -ENOMEM; 1686 return -ENOMEM;
1689 } 1687 }
1690 1688
1691 kref_init(&priv->kref);
1692 mutex_init(&priv->cfg_lock); 1689 mutex_init(&priv->cfg_lock);
1693 1690
1694 priv->flags = ASYNC_LOW_LATENCY; 1691 priv->flags = ASYNC_LOW_LATENCY;
@@ -1792,20 +1789,24 @@ static int ftdi_8u2232c_probe(struct usb_serial *serial)
1792} 1789}
1793 1790
1794/* 1791/*
1795 * First and second port on STMCLiteadaptors is reserved for JTAG interface 1792 * First two ports on JTAG adaptors using an FT4232 such as STMicroelectronics's
1796 * and the forth port for pio 1793 * ST Micro Connect Lite are reserved for JTAG or other non-UART interfaces and
1794 * can be accessed from userspace.
1795 * The next two ports are enabled as UARTs by default, where port 2 is
1796 * a conventional RS-232 UART.
1797 */ 1797 */
1798static int ftdi_stmclite_probe(struct usb_serial *serial) 1798static int ftdi_stmclite_probe(struct usb_serial *serial)
1799{ 1799{
1800 struct usb_device *udev = serial->dev; 1800 struct usb_device *udev = serial->dev;
1801 struct usb_interface *interface = serial->interface; 1801 struct usb_interface *interface = serial->interface;
1802 1802
1803 if (interface == udev->actconfig->interface[2]) 1803 if (interface == udev->actconfig->interface[0] ||
1804 return 0; 1804 interface == udev->actconfig->interface[1]) {
1805 1805 dev_info(&udev->dev, "Ignoring serial port reserved for JTAG\n");
1806 dev_info(&udev->dev, "Ignoring serial port reserved for JTAG\n"); 1806 return -ENODEV;
1807 }
1807 1808
1808 return -ENODEV; 1809 return 0;
1809} 1810}
1810 1811
1811/* 1812/*
@@ -1826,22 +1827,13 @@ static int ftdi_mtxorb_hack_setup(struct usb_serial *serial)
1826 return 0; 1827 return 0;
1827} 1828}
1828 1829
1829static void ftdi_sio_priv_release(struct kref *k)
1830{
1831 struct ftdi_private *priv = container_of(k, struct ftdi_private, kref);
1832
1833 kfree(priv);
1834}
1835
1836static int ftdi_sio_port_remove(struct usb_serial_port *port) 1830static int ftdi_sio_port_remove(struct usb_serial_port *port)
1837{ 1831{
1838 struct ftdi_private *priv = usb_get_serial_port_data(port); 1832 struct ftdi_private *priv = usb_get_serial_port_data(port);
1839 1833
1840 wake_up_interruptible(&port->delta_msr_wait);
1841
1842 remove_sysfs_attrs(port); 1834 remove_sysfs_attrs(port);
1843 1835
1844 kref_put(&priv->kref, ftdi_sio_priv_release); 1836 kfree(priv);
1845 1837
1846 return 0; 1838 return 0;
1847} 1839}
@@ -1851,7 +1843,6 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1851 struct ktermios dummy; 1843 struct ktermios dummy;
1852 struct usb_device *dev = port->serial->dev; 1844 struct usb_device *dev = port->serial->dev;
1853 struct ftdi_private *priv = usb_get_serial_port_data(port); 1845 struct ftdi_private *priv = usb_get_serial_port_data(port);
1854 int result;
1855 1846
1856 /* No error checking for this (will get errors later anyway) */ 1847 /* No error checking for this (will get errors later anyway) */
1857 /* See ftdi_sio.h for description of what is reset */ 1848 /* See ftdi_sio.h for description of what is reset */
@@ -1870,12 +1861,7 @@ static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
1870 ftdi_set_termios(tty, port, &dummy); 1861 ftdi_set_termios(tty, port, &dummy);
1871 } 1862 }
1872 1863
1873 /* Start reading from the device */ 1864 return usb_serial_generic_open(tty, port);
1874 result = usb_serial_generic_open(tty, port);
1875 if (!result)
1876 kref_get(&priv->kref);
1877
1878 return result;
1879} 1865}
1880 1866
1881static void ftdi_dtr_rts(struct usb_serial_port *port, int on) 1867static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
@@ -1900,19 +1886,6 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1900 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 1886 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1901} 1887}
1902 1888
1903/*
1904 * usbserial:__serial_close only calls ftdi_close if the point is open
1905 *
1906 * This only gets called when it is the last close
1907 */
1908static void ftdi_close(struct usb_serial_port *port)
1909{
1910 struct ftdi_private *priv = usb_get_serial_port_data(port);
1911
1912 usb_serial_generic_close(port);
1913 kref_put(&priv->kref, ftdi_sio_priv_release);
1914}
1915
1916/* The SIO requires the first byte to have: 1889/* The SIO requires the first byte to have:
1917 * B0 1 1890 * B0 1
1918 * B1 0 1891 * B1 0
@@ -1940,7 +1913,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
1940 c = kfifo_out(&port->write_fifo, &buffer[i + 1], len); 1913 c = kfifo_out(&port->write_fifo, &buffer[i + 1], len);
1941 if (!c) 1914 if (!c)
1942 break; 1915 break;
1943 priv->icount.tx += c; 1916 port->icount.tx += c;
1944 buffer[i] = (c << 2) + 1; 1917 buffer[i] = (c << 2) + 1;
1945 count += c + 1; 1918 count += c + 1;
1946 } 1919 }
@@ -1948,7 +1921,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
1948 } else { 1921 } else {
1949 count = kfifo_out_locked(&port->write_fifo, dest, size, 1922 count = kfifo_out_locked(&port->write_fifo, dest, size,
1950 &port->lock); 1923 &port->lock);
1951 priv->icount.tx += count; 1924 port->icount.tx += count;
1952 } 1925 }
1953 1926
1954 return count; 1927 return count;
@@ -1977,15 +1950,15 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1977 char diff_status = status ^ priv->prev_status; 1950 char diff_status = status ^ priv->prev_status;
1978 1951
1979 if (diff_status & FTDI_RS0_CTS) 1952 if (diff_status & FTDI_RS0_CTS)
1980 priv->icount.cts++; 1953 port->icount.cts++;
1981 if (diff_status & FTDI_RS0_DSR) 1954 if (diff_status & FTDI_RS0_DSR)
1982 priv->icount.dsr++; 1955 port->icount.dsr++;
1983 if (diff_status & FTDI_RS0_RI) 1956 if (diff_status & FTDI_RS0_RI)
1984 priv->icount.rng++; 1957 port->icount.rng++;
1985 if (diff_status & FTDI_RS0_RLSD) 1958 if (diff_status & FTDI_RS0_RLSD)
1986 priv->icount.dcd++; 1959 port->icount.dcd++;
1987 1960
1988 wake_up_interruptible(&port->delta_msr_wait); 1961 wake_up_interruptible(&port->port.delta_msr_wait);
1989 priv->prev_status = status; 1962 priv->prev_status = status;
1990 } 1963 }
1991 1964
@@ -1995,18 +1968,18 @@ static int ftdi_process_packet(struct usb_serial_port *port,
1995 * over framing errors */ 1968 * over framing errors */
1996 if (packet[1] & FTDI_RS_BI) { 1969 if (packet[1] & FTDI_RS_BI) {
1997 flag = TTY_BREAK; 1970 flag = TTY_BREAK;
1998 priv->icount.brk++; 1971 port->icount.brk++;
1999 usb_serial_handle_break(port); 1972 usb_serial_handle_break(port);
2000 } else if (packet[1] & FTDI_RS_PE) { 1973 } else if (packet[1] & FTDI_RS_PE) {
2001 flag = TTY_PARITY; 1974 flag = TTY_PARITY;
2002 priv->icount.parity++; 1975 port->icount.parity++;
2003 } else if (packet[1] & FTDI_RS_FE) { 1976 } else if (packet[1] & FTDI_RS_FE) {
2004 flag = TTY_FRAME; 1977 flag = TTY_FRAME;
2005 priv->icount.frame++; 1978 port->icount.frame++;
2006 } 1979 }
2007 /* Overrun is special, not associated with a char */ 1980 /* Overrun is special, not associated with a char */
2008 if (packet[1] & FTDI_RS_OE) { 1981 if (packet[1] & FTDI_RS_OE) {
2009 priv->icount.overrun++; 1982 port->icount.overrun++;
2010 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); 1983 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
2011 } 1984 }
2012 } 1985 }
@@ -2020,7 +1993,7 @@ static int ftdi_process_packet(struct usb_serial_port *port,
2020 len -= 2; 1993 len -= 2;
2021 if (!len) 1994 if (!len)
2022 return 0; /* status only */ 1995 return 0; /* status only */
2023 priv->icount.rx += len; 1996 port->icount.rx += len;
2024 ch = packet + 2; 1997 ch = packet + 2;
2025 1998
2026 if (port->port.console && port->sysrq) { 1999 if (port->port.console && port->sysrq) {
@@ -2384,34 +2357,10 @@ static int ftdi_tiocmset(struct tty_struct *tty,
2384 return update_mctrl(port, set, clear); 2357 return update_mctrl(port, set, clear);
2385} 2358}
2386 2359
2387static int ftdi_get_icount(struct tty_struct *tty,
2388 struct serial_icounter_struct *icount)
2389{
2390 struct usb_serial_port *port = tty->driver_data;
2391 struct ftdi_private *priv = usb_get_serial_port_data(port);
2392 struct async_icount *ic = &priv->icount;
2393
2394 icount->cts = ic->cts;
2395 icount->dsr = ic->dsr;
2396 icount->rng = ic->rng;
2397 icount->dcd = ic->dcd;
2398 icount->tx = ic->tx;
2399 icount->rx = ic->rx;
2400 icount->frame = ic->frame;
2401 icount->parity = ic->parity;
2402 icount->overrun = ic->overrun;
2403 icount->brk = ic->brk;
2404 icount->buf_overrun = ic->buf_overrun;
2405 return 0;
2406}
2407
2408static int ftdi_ioctl(struct tty_struct *tty, 2360static int ftdi_ioctl(struct tty_struct *tty,
2409 unsigned int cmd, unsigned long arg) 2361 unsigned int cmd, unsigned long arg)
2410{ 2362{
2411 struct usb_serial_port *port = tty->driver_data; 2363 struct usb_serial_port *port = tty->driver_data;
2412 struct ftdi_private *priv = usb_get_serial_port_data(port);
2413 struct async_icount cnow;
2414 struct async_icount cprev;
2415 2364
2416 dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd); 2365 dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);
2417 2366
@@ -2425,35 +2374,6 @@ static int ftdi_ioctl(struct tty_struct *tty,
2425 case TIOCSSERIAL: /* sets serial port data */ 2374 case TIOCSSERIAL: /* sets serial port data */
2426 return set_serial_info(tty, port, 2375 return set_serial_info(tty, port,
2427 (struct serial_struct __user *) arg); 2376 (struct serial_struct __user *) arg);
2428
2429 /*
2430 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2431 * - mask passed in arg for lines of interest
2432 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2433 * Caller should use TIOCGICOUNT to see which one it was.
2434 *
2435 * This code is borrowed from linux/drivers/char/serial.c
2436 */
2437 case TIOCMIWAIT:
2438 cprev = priv->icount;
2439 for (;;) {
2440 interruptible_sleep_on(&port->delta_msr_wait);
2441 /* see if a signal did it */
2442 if (signal_pending(current))
2443 return -ERESTARTSYS;
2444
2445 if (port->serial->disconnected)
2446 return -EIO;
2447
2448 cnow = priv->icount;
2449 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2450 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2451 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2452 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2453 return 0;
2454 }
2455 cprev = cnow;
2456 }
2457 case TIOCSERGETLSR: 2377 case TIOCSERGETLSR:
2458 return get_lsr_info(port, (struct serial_struct __user *)arg); 2378 return get_lsr_info(port, (struct serial_struct __user *)arg);
2459 break; 2379 break;
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index e79861eeed4c..98528270c43c 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -74,6 +74,7 @@
74#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA 74#define FTDI_OPENDCC_THROTTLE_PID 0xBFDA
75#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB 75#define FTDI_OPENDCC_GATEWAY_PID 0xBFDB
76#define FTDI_OPENDCC_GBM_PID 0xBFDC 76#define FTDI_OPENDCC_GBM_PID 0xBFDC
77#define FTDI_OPENDCC_GBM_BOOST_PID 0xBFDD
77 78
78/* NZR SEM 16+ USB (http://www.nzr.de) */ 79/* NZR SEM 16+ USB (http://www.nzr.de) */
79#define FTDI_NZR_SEM_USB_PID 0xC1E0 /* NZR SEM-LOG16+ */ 80#define FTDI_NZR_SEM_USB_PID 0xC1E0 /* NZR SEM-LOG16+ */
@@ -1150,7 +1151,8 @@
1150 * STMicroelectonics 1151 * STMicroelectonics
1151 */ 1152 */
1152#define ST_VID 0x0483 1153#define ST_VID 0x0483
1153#define ST_STMCLT1030_PID 0x3747 /* ST Micro Connect Lite STMCLT1030 */ 1154#define ST_STMCLT_2232_PID 0x3746
1155#define ST_STMCLT_4232_PID 0x3747
1154 1156
1155/* 1157/*
1156 * Papouch products (http://www.papouch.com/) 1158 * Papouch products (http://www.papouch.com/)
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 81caf5623ee2..b110c573ea85 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -946,16 +946,12 @@ static int garmin_open(struct tty_struct *tty, struct usb_serial_port *port)
946 946
947static void garmin_close(struct usb_serial_port *port) 947static void garmin_close(struct usb_serial_port *port)
948{ 948{
949 struct usb_serial *serial = port->serial;
950 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 949 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
951 950
952 dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n", 951 dev_dbg(&port->dev, "%s - port %d - mode=%d state=%d flags=0x%X\n",
953 __func__, port->number, garmin_data_p->mode, 952 __func__, port->number, garmin_data_p->mode,
954 garmin_data_p->state, garmin_data_p->flags); 953 garmin_data_p->state, garmin_data_p->flags);
955 954
956 if (!serial)
957 return;
958
959 garmin_clear(garmin_data_p); 955 garmin_clear(garmin_data_p);
960 956
961 /* shutdown our urbs */ 957 /* shutdown our urbs */
@@ -1185,17 +1181,11 @@ static void garmin_read_bulk_callback(struct urb *urb)
1185{ 1181{
1186 unsigned long flags; 1182 unsigned long flags;
1187 struct usb_serial_port *port = urb->context; 1183 struct usb_serial_port *port = urb->context;
1188 struct usb_serial *serial = port->serial;
1189 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 1184 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
1190 unsigned char *data = urb->transfer_buffer; 1185 unsigned char *data = urb->transfer_buffer;
1191 int status = urb->status; 1186 int status = urb->status;
1192 int retval; 1187 int retval;
1193 1188
1194 if (!serial) {
1195 dev_dbg(&urb->dev->dev, "%s - bad serial pointer, exiting\n", __func__);
1196 return;
1197 }
1198
1199 if (status) { 1189 if (status) {
1200 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n", 1190 dev_dbg(&urb->dev->dev, "%s - nonzero read bulk status received: %d\n",
1201 __func__, status); 1191 __func__, status);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 4c5c23f1cae5..297665fdd16d 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * USB Serial Converter Generic functions 2 * USB Serial Converter Generic functions
3 * 3 *
4 * Copyright (C) 2010 - 2011 Johan Hovold (jhovold@gmail.com) 4 * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
5 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -45,8 +45,6 @@ struct usb_serial_driver usb_serial_generic_device = {
45 }, 45 },
46 .id_table = generic_device_ids, 46 .id_table = generic_device_ids,
47 .num_ports = 1, 47 .num_ports = 1,
48 .disconnect = usb_serial_generic_disconnect,
49 .release = usb_serial_generic_release,
50 .throttle = usb_serial_generic_throttle, 48 .throttle = usb_serial_generic_throttle,
51 .unthrottle = usb_serial_generic_unthrottle, 49 .unthrottle = usb_serial_generic_unthrottle,
52 .resume = usb_serial_generic_resume, 50 .resume = usb_serial_generic_resume,
@@ -102,32 +100,23 @@ int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port
102} 100}
103EXPORT_SYMBOL_GPL(usb_serial_generic_open); 101EXPORT_SYMBOL_GPL(usb_serial_generic_open);
104 102
105static void generic_cleanup(struct usb_serial_port *port) 103void usb_serial_generic_close(struct usb_serial_port *port)
106{ 104{
107 struct usb_serial *serial = port->serial;
108 unsigned long flags; 105 unsigned long flags;
109 int i; 106 int i;
110 107
111 if (serial->dev) { 108 if (port->bulk_out_size) {
112 /* shutdown any bulk transfers that might be going on */ 109 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
113 if (port->bulk_out_size) { 110 usb_kill_urb(port->write_urbs[i]);
114 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
115 usb_kill_urb(port->write_urbs[i]);
116 111
117 spin_lock_irqsave(&port->lock, flags); 112 spin_lock_irqsave(&port->lock, flags);
118 kfifo_reset_out(&port->write_fifo); 113 kfifo_reset_out(&port->write_fifo);
119 spin_unlock_irqrestore(&port->lock, flags); 114 spin_unlock_irqrestore(&port->lock, flags);
120 } 115 }
121 if (port->bulk_in_size) { 116 if (port->bulk_in_size) {
122 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) 117 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
123 usb_kill_urb(port->read_urbs[i]); 118 usb_kill_urb(port->read_urbs[i]);
124 }
125 } 119 }
126}
127
128void usb_serial_generic_close(struct usb_serial_port *port)
129{
130 generic_cleanup(port);
131} 120}
132EXPORT_SYMBOL_GPL(usb_serial_generic_close); 121EXPORT_SYMBOL_GPL(usb_serial_generic_close);
133 122
@@ -272,8 +261,7 @@ static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
272 if (!test_and_clear_bit(index, &port->read_urbs_free)) 261 if (!test_and_clear_bit(index, &port->read_urbs_free))
273 return 0; 262 return 0;
274 263
275 dev_dbg(&port->dev, "%s - port %d, urb %d\n", __func__, 264 dev_dbg(&port->dev, "%s - urb %d\n", __func__, index);
276 port->number, index);
277 265
278 res = usb_submit_urb(port->read_urbs[index], mem_flags); 266 res = usb_submit_urb(port->read_urbs[index], mem_flags);
279 if (res) { 267 if (res) {
@@ -347,8 +335,8 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb)
347 } 335 }
348 set_bit(i, &port->read_urbs_free); 336 set_bit(i, &port->read_urbs_free);
349 337
350 dev_dbg(&port->dev, "%s - port %d, urb %d, len %d\n", 338 dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
351 __func__, port->number, i, urb->actual_length); 339 urb->actual_length);
352 340
353 if (urb->status) { 341 if (urb->status) {
354 dev_dbg(&port->dev, "%s - non-zero urb status: %d\n", 342 dev_dbg(&port->dev, "%s - non-zero urb status: %d\n",
@@ -430,6 +418,91 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)
430} 418}
431EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); 419EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
432 420
421static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
422 unsigned long arg, struct async_icount *cprev)
423{
424 struct usb_serial_port *port = tty->driver_data;
425 struct async_icount cnow;
426 unsigned long flags;
427 bool ret;
428
429 /*
430 * Use tty-port initialised flag to detect all hangups including the
431 * one generated at USB-device disconnect.
432 *
433 * FIXME: Remove hupping check once tty_port_hangup calls shutdown
434 * (which clears the initialised flag) before wake up.
435 */
436 if (test_bit(TTY_HUPPING, &tty->flags))
437 return true;
438 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
439 return true;
440
441 spin_lock_irqsave(&port->lock, flags);
442 cnow = port->icount; /* atomic copy*/
443 spin_unlock_irqrestore(&port->lock, flags);
444
445 ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
446 ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
447 ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
448 ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
449
450 *cprev = cnow;
451
452 return ret;
453}
454
455int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
456{
457 struct usb_serial_port *port = tty->driver_data;
458 struct async_icount cnow;
459 unsigned long flags;
460 int ret;
461
462 spin_lock_irqsave(&port->lock, flags);
463 cnow = port->icount; /* atomic copy */
464 spin_unlock_irqrestore(&port->lock, flags);
465
466 ret = wait_event_interruptible(port->port.delta_msr_wait,
467 usb_serial_generic_msr_changed(tty, arg, &cnow));
468 if (!ret) {
469 if (test_bit(TTY_HUPPING, &tty->flags))
470 ret = -EIO;
471 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags))
472 ret = -EIO;
473 }
474
475 return ret;
476}
477EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
478
479int usb_serial_generic_get_icount(struct tty_struct *tty,
480 struct serial_icounter_struct *icount)
481{
482 struct usb_serial_port *port = tty->driver_data;
483 struct async_icount cnow;
484 unsigned long flags;
485
486 spin_lock_irqsave(&port->lock, flags);
487 cnow = port->icount; /* atomic copy */
488 spin_unlock_irqrestore(&port->lock, flags);
489
490 icount->cts = cnow.cts;
491 icount->dsr = cnow.dsr;
492 icount->rng = cnow.rng;
493 icount->dcd = cnow.dcd;
494 icount->tx = cnow.tx;
495 icount->rx = cnow.rx;
496 icount->frame = cnow.frame;
497 icount->parity = cnow.parity;
498 icount->overrun = cnow.overrun;
499 icount->brk = cnow.brk;
500 icount->buf_overrun = cnow.buf_overrun;
501
502 return 0;
503}
504EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
505
433#ifdef CONFIG_MAGIC_SYSRQ 506#ifdef CONFIG_MAGIC_SYSRQ
434int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) 507int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
435{ 508{
@@ -473,8 +546,7 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
473{ 546{
474 struct tty_port *port = &usb_port->port; 547 struct tty_port *port = &usb_port->port;
475 548
476 dev_dbg(&usb_port->dev, "%s - port %d, status %d\n", __func__, 549 dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
477 usb_port->number, status);
478 550
479 if (status) 551 if (status)
480 wake_up_interruptible(&port->open_wait); 552 wake_up_interruptible(&port->open_wait);
@@ -510,17 +582,3 @@ int usb_serial_generic_resume(struct usb_serial *serial)
510 return c ? -EIO : 0; 582 return c ? -EIO : 0;
511} 583}
512EXPORT_SYMBOL_GPL(usb_serial_generic_resume); 584EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
513
514void usb_serial_generic_disconnect(struct usb_serial *serial)
515{
516 int i;
517
518 /* stop reads and writes on all ports */
519 for (i = 0; i < serial->num_ports; ++i)
520 generic_cleanup(serial->port[i]);
521}
522EXPORT_SYMBOL_GPL(usb_serial_generic_disconnect);
523
524void usb_serial_generic_release(struct usb_serial *serial)
525{
526}
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index cf0b0a2f7b56..1477e8593476 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -111,7 +111,6 @@ struct edgeport_port {
111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */ 111 wait_queue_head_t wait_open; /* for handling sleeping while waiting for open to finish */
112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */ 112 wait_queue_head_t wait_command; /* for handling sleeping while waiting for command to finish */
113 113
114 struct async_icount icount;
115 struct usb_serial_port *port; /* loop back to the owner of this object */ 114 struct usb_serial_port *port; /* loop back to the owner of this object */
116}; 115};
117 116
@@ -215,8 +214,6 @@ static void edge_break(struct tty_struct *tty, int break_state);
215static int edge_tiocmget(struct tty_struct *tty); 214static int edge_tiocmget(struct tty_struct *tty);
216static int edge_tiocmset(struct tty_struct *tty, 215static int edge_tiocmset(struct tty_struct *tty,
217 unsigned int set, unsigned int clear); 216 unsigned int set, unsigned int clear);
218static int edge_get_icount(struct tty_struct *tty,
219 struct serial_icounter_struct *icount);
220static int edge_startup(struct usb_serial *serial); 217static int edge_startup(struct usb_serial *serial);
221static void edge_disconnect(struct usb_serial *serial); 218static void edge_disconnect(struct usb_serial *serial);
222static void edge_release(struct usb_serial *serial); 219static void edge_release(struct usb_serial *serial);
@@ -867,9 +864,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
867 init_waitqueue_head(&edge_port->wait_chase); 864 init_waitqueue_head(&edge_port->wait_chase);
868 init_waitqueue_head(&edge_port->wait_command); 865 init_waitqueue_head(&edge_port->wait_command);
869 866
870 /* initialize our icount structure */
871 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
872
873 /* initialize our port settings */ 867 /* initialize our port settings */
874 edge_port->txCredits = 0; /* Can't send any data yet */ 868 edge_port->txCredits = 0; /* Can't send any data yet */
875 /* Must always set this bit to enable ints! */ 869 /* Must always set this bit to enable ints! */
@@ -1296,7 +1290,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
1296 1290
1297 /* decrement the number of credits we have by the number we just sent */ 1291 /* decrement the number of credits we have by the number we just sent */
1298 edge_port->txCredits -= count; 1292 edge_port->txCredits -= count;
1299 edge_port->icount.tx += count; 1293 edge_port->port->icount.tx += count;
1300 1294
1301 status = usb_submit_urb(urb, GFP_ATOMIC); 1295 status = usb_submit_urb(urb, GFP_ATOMIC);
1302 if (status) { 1296 if (status) {
@@ -1308,7 +1302,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
1308 1302
1309 /* revert the credits as something bad happened. */ 1303 /* revert the credits as something bad happened. */
1310 edge_port->txCredits += count; 1304 edge_port->txCredits += count;
1311 edge_port->icount.tx -= count; 1305 edge_port->port->icount.tx -= count;
1312 } 1306 }
1313 dev_dbg(dev, "%s wrote %d byte(s) TxCredit %d, Fifo %d\n", 1307 dev_dbg(dev, "%s wrote %d byte(s) TxCredit %d, Fifo %d\n",
1314 __func__, count, edge_port->txCredits, fifo->count); 1308 __func__, count, edge_port->txCredits, fifo->count);
@@ -1570,31 +1564,6 @@ static int edge_tiocmget(struct tty_struct *tty)
1570 return result; 1564 return result;
1571} 1565}
1572 1566
1573static int edge_get_icount(struct tty_struct *tty,
1574 struct serial_icounter_struct *icount)
1575{
1576 struct usb_serial_port *port = tty->driver_data;
1577 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1578 struct async_icount cnow;
1579 cnow = edge_port->icount;
1580
1581 icount->cts = cnow.cts;
1582 icount->dsr = cnow.dsr;
1583 icount->rng = cnow.rng;
1584 icount->dcd = cnow.dcd;
1585 icount->rx = cnow.rx;
1586 icount->tx = cnow.tx;
1587 icount->frame = cnow.frame;
1588 icount->overrun = cnow.overrun;
1589 icount->parity = cnow.parity;
1590 icount->brk = cnow.brk;
1591 icount->buf_overrun = cnow.buf_overrun;
1592
1593 dev_dbg(&port->dev, "%s (%d) TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1594 port->number, icount->rx, icount->tx);
1595 return 0;
1596}
1597
1598static int get_serial_info(struct edgeport_port *edge_port, 1567static int get_serial_info(struct edgeport_port *edge_port,
1599 struct serial_struct __user *retinfo) 1568 struct serial_struct __user *retinfo)
1600{ 1569{
@@ -1631,8 +1600,6 @@ static int edge_ioctl(struct tty_struct *tty,
1631 struct usb_serial_port *port = tty->driver_data; 1600 struct usb_serial_port *port = tty->driver_data;
1632 DEFINE_WAIT(wait); 1601 DEFINE_WAIT(wait);
1633 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1602 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1634 struct async_icount cnow;
1635 struct async_icount cprev;
1636 1603
1637 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd); 1604 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
1638 1605
@@ -1644,37 +1611,6 @@ static int edge_ioctl(struct tty_struct *tty,
1644 case TIOCGSERIAL: 1611 case TIOCGSERIAL:
1645 dev_dbg(&port->dev, "%s (%d) TIOCGSERIAL\n", __func__, port->number); 1612 dev_dbg(&port->dev, "%s (%d) TIOCGSERIAL\n", __func__, port->number);
1646 return get_serial_info(edge_port, (struct serial_struct __user *) arg); 1613 return get_serial_info(edge_port, (struct serial_struct __user *) arg);
1647
1648 case TIOCMIWAIT:
1649 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__, port->number);
1650 cprev = edge_port->icount;
1651 while (1) {
1652 prepare_to_wait(&port->delta_msr_wait,
1653 &wait, TASK_INTERRUPTIBLE);
1654 schedule();
1655 finish_wait(&port->delta_msr_wait, &wait);
1656 /* see if a signal did it */
1657 if (signal_pending(current))
1658 return -ERESTARTSYS;
1659
1660 if (port->serial->disconnected)
1661 return -EIO;
1662
1663 cnow = edge_port->icount;
1664 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1665 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1666 return -EIO; /* no change => error */
1667 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1668 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1669 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1670 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1671 return 0;
1672 }
1673 cprev = cnow;
1674 }
1675 /* NOTREACHED */
1676 break;
1677
1678 } 1614 }
1679 return -ENOIOCTLCMD; 1615 return -ENOIOCTLCMD;
1680} 1616}
@@ -1848,7 +1784,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
1848 edge_serial->rxPort); 1784 edge_serial->rxPort);
1849 edge_tty_recv(edge_port->port, buffer, 1785 edge_tty_recv(edge_port->port, buffer,
1850 rxLen); 1786 rxLen);
1851 edge_port->icount.rx += rxLen; 1787 edge_port->port->icount.rx += rxLen;
1852 } 1788 }
1853 buffer += rxLen; 1789 buffer += rxLen;
1854 } 1790 }
@@ -2024,7 +1960,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2024 1960
2025 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | 1961 if (newMsr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
2026 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1962 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
2027 icount = &edge_port->icount; 1963 icount = &edge_port->port->icount;
2028 1964
2029 /* update input line counters */ 1965 /* update input line counters */
2030 if (newMsr & EDGEPORT_MSR_DELTA_CTS) 1966 if (newMsr & EDGEPORT_MSR_DELTA_CTS)
@@ -2035,7 +1971,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 newMsr)
2035 icount->dcd++; 1971 icount->dcd++;
2036 if (newMsr & EDGEPORT_MSR_DELTA_RI) 1972 if (newMsr & EDGEPORT_MSR_DELTA_RI)
2037 icount->rng++; 1973 icount->rng++;
2038 wake_up_interruptible(&edge_port->port->delta_msr_wait); 1974 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
2039 } 1975 }
2040 1976
2041 /* Save the new modem status */ 1977 /* Save the new modem status */
@@ -2070,7 +2006,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2070 edge_tty_recv(edge_port->port, &data, 1); 2006 edge_tty_recv(edge_port->port, &data, 1);
2071 2007
2072 /* update input line counters */ 2008 /* update input line counters */
2073 icount = &edge_port->icount; 2009 icount = &edge_port->port->icount;
2074 if (newLsr & LSR_BREAK) 2010 if (newLsr & LSR_BREAK)
2075 icount->brk++; 2011 icount->brk++;
2076 if (newLsr & LSR_OVER_ERR) 2012 if (newLsr & LSR_OVER_ERR)
diff --git a/drivers/usb/serial/io_tables.h b/drivers/usb/serial/io_tables.h
index 1511dd0ad324..ae5fac5656c9 100644
--- a/drivers/usb/serial/io_tables.h
+++ b/drivers/usb/serial/io_tables.h
@@ -116,7 +116,8 @@ static struct usb_serial_driver edgeport_2port_device = {
116 .set_termios = edge_set_termios, 116 .set_termios = edge_set_termios,
117 .tiocmget = edge_tiocmget, 117 .tiocmget = edge_tiocmget,
118 .tiocmset = edge_tiocmset, 118 .tiocmset = edge_tiocmset,
119 .get_icount = edge_get_icount, 119 .tiocmiwait = usb_serial_generic_tiocmiwait,
120 .get_icount = usb_serial_generic_get_icount,
120 .write = edge_write, 121 .write = edge_write,
121 .write_room = edge_write_room, 122 .write_room = edge_write_room,
122 .chars_in_buffer = edge_chars_in_buffer, 123 .chars_in_buffer = edge_chars_in_buffer,
@@ -147,7 +148,8 @@ static struct usb_serial_driver edgeport_4port_device = {
147 .set_termios = edge_set_termios, 148 .set_termios = edge_set_termios,
148 .tiocmget = edge_tiocmget, 149 .tiocmget = edge_tiocmget,
149 .tiocmset = edge_tiocmset, 150 .tiocmset = edge_tiocmset,
150 .get_icount = edge_get_icount, 151 .tiocmiwait = usb_serial_generic_tiocmiwait,
152 .get_icount = usb_serial_generic_get_icount,
151 .write = edge_write, 153 .write = edge_write,
152 .write_room = edge_write_room, 154 .write_room = edge_write_room,
153 .chars_in_buffer = edge_chars_in_buffer, 155 .chars_in_buffer = edge_chars_in_buffer,
@@ -178,7 +180,8 @@ static struct usb_serial_driver edgeport_8port_device = {
178 .set_termios = edge_set_termios, 180 .set_termios = edge_set_termios,
179 .tiocmget = edge_tiocmget, 181 .tiocmget = edge_tiocmget,
180 .tiocmset = edge_tiocmset, 182 .tiocmset = edge_tiocmset,
181 .get_icount = edge_get_icount, 183 .tiocmiwait = usb_serial_generic_tiocmiwait,
184 .get_icount = usb_serial_generic_get_icount,
182 .write = edge_write, 185 .write = edge_write,
183 .write_room = edge_write_room, 186 .write_room = edge_write_room,
184 .chars_in_buffer = edge_chars_in_buffer, 187 .chars_in_buffer = edge_chars_in_buffer,
@@ -209,7 +212,8 @@ static struct usb_serial_driver epic_device = {
209 .set_termios = edge_set_termios, 212 .set_termios = edge_set_termios,
210 .tiocmget = edge_tiocmget, 213 .tiocmget = edge_tiocmget,
211 .tiocmset = edge_tiocmset, 214 .tiocmset = edge_tiocmset,
212 .get_icount = edge_get_icount, 215 .tiocmiwait = usb_serial_generic_tiocmiwait,
216 .get_icount = usb_serial_generic_get_icount,
213 .write = edge_write, 217 .write = edge_write,
214 .write_room = edge_write_room, 218 .write_room = edge_write_room,
215 .chars_in_buffer = edge_chars_in_buffer, 219 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 7777172206de..158bf4bc29cc 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -86,7 +86,7 @@ struct edgeport_port {
86 int baud_rate; 86 int baud_rate;
87 int close_pending; 87 int close_pending;
88 int lsr_event; 88 int lsr_event;
89 struct async_icount icount; 89
90 struct edgeport_serial *edge_serial; 90 struct edgeport_serial *edge_serial;
91 struct usb_serial_port *port; 91 struct usb_serial_port *port;
92 __u8 bUartMode; /* Port type, 0: RS232, etc. */ 92 __u8 bUartMode; /* Port type, 0: RS232, etc. */
@@ -206,7 +206,7 @@ static int restart_read(struct edgeport_port *edge_port);
206 206
207static void edge_set_termios(struct tty_struct *tty, 207static void edge_set_termios(struct tty_struct *tty,
208 struct usb_serial_port *port, struct ktermios *old_termios); 208 struct usb_serial_port *port, struct ktermios *old_termios);
209static void edge_send(struct tty_struct *tty); 209static void edge_send(struct usb_serial_port *port, struct tty_struct *tty);
210 210
211/* sysfs attributes */ 211/* sysfs attributes */
212static int edge_create_sysfs_attrs(struct usb_serial_port *port); 212static int edge_create_sysfs_attrs(struct usb_serial_port *port);
@@ -1445,7 +1445,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1445 1445
1446 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR | 1446 if (msr & (EDGEPORT_MSR_DELTA_CTS | EDGEPORT_MSR_DELTA_DSR |
1447 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) { 1447 EDGEPORT_MSR_DELTA_RI | EDGEPORT_MSR_DELTA_CD)) {
1448 icount = &edge_port->icount; 1448 icount = &edge_port->port->icount;
1449 1449
1450 /* update input line counters */ 1450 /* update input line counters */
1451 if (msr & EDGEPORT_MSR_DELTA_CTS) 1451 if (msr & EDGEPORT_MSR_DELTA_CTS)
@@ -1456,7 +1456,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1456 icount->dcd++; 1456 icount->dcd++;
1457 if (msr & EDGEPORT_MSR_DELTA_RI) 1457 if (msr & EDGEPORT_MSR_DELTA_RI)
1458 icount->rng++; 1458 icount->rng++;
1459 wake_up_interruptible(&edge_port->port->delta_msr_wait); 1459 wake_up_interruptible(&edge_port->port->port.delta_msr_wait);
1460 } 1460 }
1461 1461
1462 /* Save the new modem status */ 1462 /* Save the new modem status */
@@ -1498,7 +1498,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1498 edge_tty_recv(edge_port->port, &data, 1); 1498 edge_tty_recv(edge_port->port, &data, 1);
1499 1499
1500 /* update input line counters */ 1500 /* update input line counters */
1501 icount = &edge_port->icount; 1501 icount = &edge_port->port->icount;
1502 if (new_lsr & LSR_BREAK) 1502 if (new_lsr & LSR_BREAK)
1503 icount->brk++; 1503 icount->brk++;
1504 if (new_lsr & LSR_OVER_ERR) 1504 if (new_lsr & LSR_OVER_ERR)
@@ -1657,7 +1657,7 @@ static void edge_bulk_in_callback(struct urb *urb)
1657 else 1657 else
1658 edge_tty_recv(edge_port->port, data, 1658 edge_tty_recv(edge_port->port, data,
1659 urb->actual_length); 1659 urb->actual_length);
1660 edge_port->icount.rx += urb->actual_length; 1660 edge_port->port->icount.rx += urb->actual_length;
1661 } 1661 }
1662 1662
1663exit: 1663exit:
@@ -1712,7 +1712,7 @@ static void edge_bulk_out_callback(struct urb *urb)
1712 1712
1713 /* send any buffered data */ 1713 /* send any buffered data */
1714 tty = tty_port_tty_get(&port->port); 1714 tty = tty_port_tty_get(&port->port);
1715 edge_send(tty); 1715 edge_send(port, tty);
1716 tty_kref_put(tty); 1716 tty_kref_put(tty);
1717} 1717}
1718 1718
@@ -1750,8 +1750,6 @@ static int edge_open(struct tty_struct *tty, struct usb_serial_port *port)
1750 1750
1751 dev = port->serial->dev; 1751 dev = port->serial->dev;
1752 1752
1753 memset(&(edge_port->icount), 0x00, sizeof(edge_port->icount));
1754
1755 /* turn off loopback */ 1753 /* turn off loopback */
1756 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0); 1754 status = ti_do_config(edge_port, UMPC_SET_CLR_LOOPBACK, 0);
1757 if (status) { 1755 if (status) {
@@ -1909,21 +1907,10 @@ static void edge_close(struct usb_serial_port *port)
1909 kfifo_reset_out(&edge_port->write_fifo); 1907 kfifo_reset_out(&edge_port->write_fifo);
1910 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1908 spin_unlock_irqrestore(&edge_port->ep_lock, flags);
1911 1909
1912 /* assuming we can still talk to the device,
1913 * send a close port command to it */
1914 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__); 1910 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__);
1915 port_number = port->number - port->serial->minor; 1911 port_number = port->number - port->serial->minor;
1916 1912 send_cmd(serial->dev, UMPC_CLOSE_PORT,
1917 mutex_lock(&serial->disc_mutex); 1913 (__u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0);
1918 if (!serial->disconnected) {
1919 send_cmd(serial->dev,
1920 UMPC_CLOSE_PORT,
1921 (__u8)(UMPM_UART1_PORT + port_number),
1922 0,
1923 NULL,
1924 0);
1925 }
1926 mutex_unlock(&serial->disc_mutex);
1927 1914
1928 mutex_lock(&edge_serial->es_lock); 1915 mutex_lock(&edge_serial->es_lock);
1929 --edge_port->edge_serial->num_ports_open; 1916 --edge_port->edge_serial->num_ports_open;
@@ -1953,14 +1940,13 @@ static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
1953 1940
1954 count = kfifo_in_locked(&edge_port->write_fifo, data, count, 1941 count = kfifo_in_locked(&edge_port->write_fifo, data, count,
1955 &edge_port->ep_lock); 1942 &edge_port->ep_lock);
1956 edge_send(tty); 1943 edge_send(port, tty);
1957 1944
1958 return count; 1945 return count;
1959} 1946}
1960 1947
1961static void edge_send(struct tty_struct *tty) 1948static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
1962{ 1949{
1963 struct usb_serial_port *port = tty->driver_data;
1964 int count, result; 1950 int count, result;
1965 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1951 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1966 unsigned long flags; 1952 unsigned long flags;
@@ -1999,7 +1985,7 @@ static void edge_send(struct tty_struct *tty)
1999 edge_port->ep_write_urb_in_use = 0; 1985 edge_port->ep_write_urb_in_use = 0;
2000 /* TODO: reschedule edge_send */ 1986 /* TODO: reschedule edge_send */
2001 } else 1987 } else
2002 edge_port->icount.tx += count; 1988 edge_port->port->icount.tx += count;
2003 1989
2004 /* wakeup any process waiting for writes to complete */ 1990 /* wakeup any process waiting for writes to complete */
2005 /* there is now more room in the buffer for new writes */ 1991 /* there is now more room in the buffer for new writes */
@@ -2360,27 +2346,6 @@ static int edge_tiocmget(struct tty_struct *tty)
2360 return result; 2346 return result;
2361} 2347}
2362 2348
2363static int edge_get_icount(struct tty_struct *tty,
2364 struct serial_icounter_struct *icount)
2365{
2366 struct usb_serial_port *port = tty->driver_data;
2367 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2368 struct async_icount *ic = &edge_port->icount;
2369
2370 icount->cts = ic->cts;
2371 icount->dsr = ic->dsr;
2372 icount->rng = ic->rng;
2373 icount->dcd = ic->dcd;
2374 icount->tx = ic->tx;
2375 icount->rx = ic->rx;
2376 icount->frame = ic->frame;
2377 icount->parity = ic->parity;
2378 icount->overrun = ic->overrun;
2379 icount->brk = ic->brk;
2380 icount->buf_overrun = ic->buf_overrun;
2381 return 0;
2382}
2383
2384static int get_serial_info(struct edgeport_port *edge_port, 2349static int get_serial_info(struct edgeport_port *edge_port,
2385 struct serial_struct __user *retinfo) 2350 struct serial_struct __user *retinfo)
2386{ 2351{
@@ -2392,7 +2357,7 @@ static int get_serial_info(struct edgeport_port *edge_port,
2392 2357
2393 cwait = edge_port->port->port.closing_wait; 2358 cwait = edge_port->port->port.closing_wait;
2394 if (cwait != ASYNC_CLOSING_WAIT_NONE) 2359 if (cwait != ASYNC_CLOSING_WAIT_NONE)
2395 cwait = jiffies_to_msecs(closing_wait) / 10; 2360 cwait = jiffies_to_msecs(cwait) / 10;
2396 2361
2397 memset(&tmp, 0, sizeof(tmp)); 2362 memset(&tmp, 0, sizeof(tmp));
2398 2363
@@ -2416,8 +2381,6 @@ static int edge_ioctl(struct tty_struct *tty,
2416{ 2381{
2417 struct usb_serial_port *port = tty->driver_data; 2382 struct usb_serial_port *port = tty->driver_data;
2418 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2383 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2419 struct async_icount cnow;
2420 struct async_icount cprev;
2421 2384
2422 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd); 2385 dev_dbg(&port->dev, "%s - port %d, cmd = 0x%x\n", __func__, port->number, cmd);
2423 2386
@@ -2426,32 +2389,6 @@ static int edge_ioctl(struct tty_struct *tty,
2426 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); 2389 dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__);
2427 return get_serial_info(edge_port, 2390 return get_serial_info(edge_port,
2428 (struct serial_struct __user *) arg); 2391 (struct serial_struct __user *) arg);
2429 case TIOCMIWAIT:
2430 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
2431 cprev = edge_port->icount;
2432 while (1) {
2433 interruptible_sleep_on(&port->delta_msr_wait);
2434 /* see if a signal did it */
2435 if (signal_pending(current))
2436 return -ERESTARTSYS;
2437
2438 if (port->serial->disconnected)
2439 return -EIO;
2440
2441 cnow = edge_port->icount;
2442 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2443 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2444 return -EIO; /* no change => error */
2445 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2446 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2447 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2448 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2449 return 0;
2450 }
2451 cprev = cnow;
2452 }
2453 /* not reached */
2454 break;
2455 } 2392 }
2456 return -ENOIOCTLCMD; 2393 return -ENOIOCTLCMD;
2457} 2394}
@@ -2463,8 +2400,6 @@ static void edge_break(struct tty_struct *tty, int break_state)
2463 int status; 2400 int status;
2464 int bv = 0; /* Off */ 2401 int bv = 0; /* Off */
2465 2402
2466 tty_wait_until_sent(tty, 0);
2467
2468 if (break_state == -1) 2403 if (break_state == -1)
2469 bv = 1; /* On */ 2404 bv = 1; /* On */
2470 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv); 2405 status = ti_do_config(edge_port, UMPC_SET_CLR_BREAK, bv);
@@ -2546,7 +2481,6 @@ static int edge_port_remove(struct usb_serial_port *port)
2546 struct edgeport_port *edge_port; 2481 struct edgeport_port *edge_port;
2547 2482
2548 edge_port = usb_get_serial_port_data(port); 2483 edge_port = usb_get_serial_port_data(port);
2549
2550 edge_remove_sysfs_attrs(port); 2484 edge_remove_sysfs_attrs(port);
2551 kfifo_free(&edge_port->write_fifo); 2485 kfifo_free(&edge_port->write_fifo);
2552 kfree(edge_port); 2486 kfree(edge_port);
@@ -2618,7 +2552,8 @@ static struct usb_serial_driver edgeport_1port_device = {
2618 .set_termios = edge_set_termios, 2552 .set_termios = edge_set_termios,
2619 .tiocmget = edge_tiocmget, 2553 .tiocmget = edge_tiocmget,
2620 .tiocmset = edge_tiocmset, 2554 .tiocmset = edge_tiocmset,
2621 .get_icount = edge_get_icount, 2555 .tiocmiwait = usb_serial_generic_tiocmiwait,
2556 .get_icount = usb_serial_generic_get_icount,
2622 .write = edge_write, 2557 .write = edge_write,
2623 .write_room = edge_write_room, 2558 .write_room = edge_write_room,
2624 .chars_in_buffer = edge_chars_in_buffer, 2559 .chars_in_buffer = edge_chars_in_buffer,
@@ -2649,7 +2584,8 @@ static struct usb_serial_driver edgeport_2port_device = {
2649 .set_termios = edge_set_termios, 2584 .set_termios = edge_set_termios,
2650 .tiocmget = edge_tiocmget, 2585 .tiocmget = edge_tiocmget,
2651 .tiocmset = edge_tiocmset, 2586 .tiocmset = edge_tiocmset,
2652 .get_icount = edge_get_icount, 2587 .tiocmiwait = usb_serial_generic_tiocmiwait,
2588 .get_icount = usb_serial_generic_get_icount,
2653 .write = edge_write, 2589 .write = edge_write,
2654 .write_room = edge_write_room, 2590 .write_room = edge_write_room,
2655 .chars_in_buffer = edge_chars_in_buffer, 2591 .chars_in_buffer = edge_chars_in_buffer,
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index ff77027160aa..9d74c278b7b5 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -55,7 +55,6 @@ static void read_rxcmd_callback(struct urb *urb);
55 55
56struct iuu_private { 56struct iuu_private {
57 spinlock_t lock; /* store irq state */ 57 spinlock_t lock; /* store irq state */
58 wait_queue_head_t delta_msr_wait;
59 u8 line_status; 58 u8 line_status;
60 int tiostatus; /* store IUART SIGNAL for tiocmget call */ 59 int tiostatus; /* store IUART SIGNAL for tiocmget call */
61 u8 reset; /* if 1 reset is needed */ 60 u8 reset; /* if 1 reset is needed */
@@ -94,7 +93,6 @@ static int iuu_port_probe(struct usb_serial_port *port)
94 93
95 priv->vcc = vcc_default; 94 priv->vcc = vcc_default;
96 spin_lock_init(&priv->lock); 95 spin_lock_init(&priv->lock);
97 init_waitqueue_head(&priv->delta_msr_wait);
98 96
99 usb_set_serial_port_data(port, priv); 97 usb_set_serial_port_data(port, priv);
100 98
@@ -944,22 +942,13 @@ static void iuu_set_termios(struct tty_struct *tty,
944static void iuu_close(struct usb_serial_port *port) 942static void iuu_close(struct usb_serial_port *port)
945{ 943{
946 /* iuu_led (port,255,0,0,0); */ 944 /* iuu_led (port,255,0,0,0); */
947 struct usb_serial *serial;
948
949 serial = port->serial;
950 if (!serial)
951 return;
952 945
953 iuu_uart_off(port); 946 iuu_uart_off(port);
954 if (serial->dev) { 947
955 /* free writebuf */ 948 usb_kill_urb(port->write_urb);
956 /* shutdown our urbs */ 949 usb_kill_urb(port->read_urb);
957 dev_dbg(&port->dev, "%s - shutting down urbs\n", __func__); 950
958 usb_kill_urb(port->write_urb); 951 iuu_led(port, 0, 0, 0xF000, 0xFF);
959 usb_kill_urb(port->read_urb);
960 usb_kill_urb(port->interrupt_in_urb);
961 iuu_led(port, 0, 0, 0xF000, 0xFF);
962 }
963} 952}
964 953
965static void iuu_init_termios(struct tty_struct *tty) 954static void iuu_init_termios(struct tty_struct *tty)
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index b011478d2e5f..eb30d7b01f36 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -712,45 +712,45 @@ static void usa49wg_indat_callback(struct urb *urb)
712 i = 0; 712 i = 0;
713 len = 0; 713 len = 0;
714 714
715 if (urb->actual_length) { 715 while (i < urb->actual_length) {
716 while (i < urb->actual_length) {
717 716
718 /* Check port number from message*/ 717 /* Check port number from message */
719 if (data[i] >= serial->num_ports) { 718 if (data[i] >= serial->num_ports) {
720 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", 719 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
721 __func__, data[i]); 720 __func__, data[i]);
722 return; 721 return;
723 } 722 }
724 port = serial->port[data[i++]]; 723 port = serial->port[data[i++]];
725 len = data[i++]; 724 len = data[i++];
726 725
727 /* 0x80 bit is error flag */ 726 /* 0x80 bit is error flag */
728 if ((data[i] & 0x80) == 0) { 727 if ((data[i] & 0x80) == 0) {
729 /* no error on any byte */ 728 /* no error on any byte */
730 i++; 729 i++;
731 for (x = 1; x < len ; ++x) 730 for (x = 1; x < len && i < urb->actual_length; ++x)
732 tty_insert_flip_char(&port->port, 731 tty_insert_flip_char(&port->port,
733 data[i++], 0); 732 data[i++], 0);
734 } else { 733 } else {
735 /* 734 /*
736 * some bytes had errors, every byte has status 735 * some bytes had errors, every byte has status
737 */ 736 */
738 for (x = 0; x + 1 < len; x += 2) { 737 for (x = 0; x + 1 < len &&
739 int stat = data[i], flag = 0; 738 i + 1 < urb->actual_length; x += 2) {
740 if (stat & RXERROR_OVERRUN) 739 int stat = data[i], flag = 0;
741 flag |= TTY_OVERRUN; 740
742 if (stat & RXERROR_FRAMING) 741 if (stat & RXERROR_OVERRUN)
743 flag |= TTY_FRAME; 742 flag |= TTY_OVERRUN;
744 if (stat & RXERROR_PARITY) 743 if (stat & RXERROR_FRAMING)
745 flag |= TTY_PARITY; 744 flag |= TTY_FRAME;
746 /* XXX should handle break (0x10) */ 745 if (stat & RXERROR_PARITY)
747 tty_insert_flip_char(&port->port, 746 flag |= TTY_PARITY;
748 data[i+1], flag); 747 /* XXX should handle break (0x10) */
749 i += 2; 748 tty_insert_flip_char(&port->port, data[i+1],
750 } 749 flag);
750 i += 2;
751 } 751 }
752 tty_flip_buffer_push(&port->port);
753 } 752 }
753 tty_flip_buffer_push(&port->port);
754 } 754 }
755 755
756 /* Resubmit urb so we continue receiving */ 756 /* Resubmit urb so we continue receiving */
@@ -1092,7 +1092,6 @@ static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1092static void keyspan_close(struct usb_serial_port *port) 1092static void keyspan_close(struct usb_serial_port *port)
1093{ 1093{
1094 int i; 1094 int i;
1095 struct usb_serial *serial = port->serial;
1096 struct keyspan_port_private *p_priv; 1095 struct keyspan_port_private *p_priv;
1097 1096
1098 p_priv = usb_get_serial_port_data(port); 1097 p_priv = usb_get_serial_port_data(port);
@@ -1100,28 +1099,17 @@ static void keyspan_close(struct usb_serial_port *port)
1100 p_priv->rts_state = 0; 1099 p_priv->rts_state = 0;
1101 p_priv->dtr_state = 0; 1100 p_priv->dtr_state = 0;
1102 1101
1103 if (serial->dev) { 1102 keyspan_send_setup(port, 2);
1104 keyspan_send_setup(port, 2); 1103 /* pilot-xfer seems to work best with this delay */
1105 /* pilot-xfer seems to work best with this delay */ 1104 mdelay(100);
1106 mdelay(100);
1107 /* keyspan_set_termios(port, NULL); */
1108 }
1109
1110 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1111 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1112 }*/
1113 1105
1114 p_priv->out_flip = 0; 1106 p_priv->out_flip = 0;
1115 p_priv->in_flip = 0; 1107 p_priv->in_flip = 0;
1116 1108
1117 if (serial->dev) { 1109 stop_urb(p_priv->inack_urb);
1118 /* Stop reading/writing urbs */ 1110 for (i = 0; i < 2; i++) {
1119 stop_urb(p_priv->inack_urb); 1111 stop_urb(p_priv->in_urbs[i]);
1120 /* stop_urb(p_priv->outcont_urb); */ 1112 stop_urb(p_priv->out_urbs[i]);
1121 for (i = 0; i < 2; i++) {
1122 stop_urb(p_priv->in_urbs[i]);
1123 stop_urb(p_priv->out_urbs[i]);
1124 }
1125 } 1113 }
1126} 1114}
1127 1115
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 2230223978ca..5f1d382e55cf 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -593,12 +593,10 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
593{ 593{
594 struct usb_serial *serial = port->serial; 594 struct usb_serial *serial = port->serial;
595 595
596 if (serial->dev) { 596 if (on)
597 if (on) 597 keyspan_pda_set_modem_info(serial, (1 << 7) | (1 << 2));
598 keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2)); 598 else
599 else 599 keyspan_pda_set_modem_info(serial, 0);
600 keyspan_pda_set_modem_info(serial, 0);
601 }
602} 600}
603 601
604 602
@@ -649,13 +647,8 @@ error:
649} 647}
650static void keyspan_pda_close(struct usb_serial_port *port) 648static void keyspan_pda_close(struct usb_serial_port *port)
651{ 649{
652 struct usb_serial *serial = port->serial; 650 usb_kill_urb(port->write_urb);
653 651 usb_kill_urb(port->interrupt_in_urb);
654 if (serial->dev) {
655 /* shutdown our bulk reads and writes */
656 usb_kill_urb(port->write_urb);
657 usb_kill_urb(port->interrupt_in_urb);
658 }
659} 652}
660 653
661 654
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 769d910ae0a5..1b4054fe52a5 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -341,28 +341,20 @@ static void klsi_105_close(struct usb_serial_port *port)
341{ 341{
342 int rc; 342 int rc;
343 343
344 mutex_lock(&port->serial->disc_mutex); 344 /* send READ_OFF */
345 if (!port->serial->disconnected) { 345 rc = usb_control_msg(port->serial->dev,
346 /* send READ_OFF */ 346 usb_sndctrlpipe(port->serial->dev, 0),
347 rc = usb_control_msg(port->serial->dev, 347 KL5KUSB105A_SIO_CONFIGURE,
348 usb_sndctrlpipe(port->serial->dev, 0), 348 USB_TYPE_VENDOR | USB_DIR_OUT,
349 KL5KUSB105A_SIO_CONFIGURE, 349 KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
350 USB_TYPE_VENDOR | USB_DIR_OUT, 350 0, /* index */
351 KL5KUSB105A_SIO_CONFIGURE_READ_OFF, 351 NULL, 0,
352 0, /* index */ 352 KLSI_TIMEOUT);
353 NULL, 0, 353 if (rc < 0)
354 KLSI_TIMEOUT); 354 dev_err(&port->dev, "failed to disable read: %d\n", rc);
355 if (rc < 0)
356 dev_err(&port->dev,
357 "Disabling read failed (error = %d)\n", rc);
358 }
359 mutex_unlock(&port->serial->disc_mutex);
360 355
361 /* shutdown our bulk reads and writes */ 356 /* shutdown our bulk reads and writes */
362 usb_serial_generic_close(port); 357 usb_serial_generic_close(port);
363
364 /* wgg - do I need this? I think so. */
365 usb_kill_urb(port->interrupt_in_urb);
366} 358}
367 359
368/* We need to write a complete 64-byte data block and encode the 360/* We need to write a complete 64-byte data block and encode the
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 903d938e174b..78b48c31abf5 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -65,7 +65,7 @@ static int kobil_tiocmget(struct tty_struct *tty);
65static int kobil_tiocmset(struct tty_struct *tty, 65static int kobil_tiocmset(struct tty_struct *tty,
66 unsigned int set, unsigned int clear); 66 unsigned int set, unsigned int clear);
67static void kobil_read_int_callback(struct urb *urb); 67static void kobil_read_int_callback(struct urb *urb);
68static void kobil_write_callback(struct urb *purb); 68static void kobil_write_int_callback(struct urb *urb);
69static void kobil_set_termios(struct tty_struct *tty, 69static void kobil_set_termios(struct tty_struct *tty,
70 struct usb_serial_port *port, struct ktermios *old); 70 struct usb_serial_port *port, struct ktermios *old);
71static void kobil_init_termios(struct tty_struct *tty); 71static void kobil_init_termios(struct tty_struct *tty);
@@ -99,6 +99,7 @@ static struct usb_serial_driver kobil_device = {
99 .write = kobil_write, 99 .write = kobil_write,
100 .write_room = kobil_write_room, 100 .write_room = kobil_write_room,
101 .read_int_callback = kobil_read_int_callback, 101 .read_int_callback = kobil_read_int_callback,
102 .write_int_callback = kobil_write_int_callback,
102}; 103};
103 104
104static struct usb_serial_driver * const serial_drivers[] = { 105static struct usb_serial_driver * const serial_drivers[] = {
@@ -106,8 +107,6 @@ static struct usb_serial_driver * const serial_drivers[] = {
106}; 107};
107 108
108struct kobil_private { 109struct kobil_private {
109 int write_int_endpoint_address;
110 int read_int_endpoint_address;
111 unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */ 110 unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */
112 int filled; /* index of the last char in buf */ 111 int filled; /* index of the last char in buf */
113 int cur_pos; /* index of the next char to send in buf */ 112 int cur_pos; /* index of the next char to send in buf */
@@ -117,14 +116,8 @@ struct kobil_private {
117 116
118static int kobil_port_probe(struct usb_serial_port *port) 117static int kobil_port_probe(struct usb_serial_port *port)
119{ 118{
120 int i;
121 struct usb_serial *serial = port->serial; 119 struct usb_serial *serial = port->serial;
122 struct kobil_private *priv; 120 struct kobil_private *priv;
123 struct usb_device *pdev;
124 struct usb_host_config *actconfig;
125 struct usb_interface *interface;
126 struct usb_host_interface *altsetting;
127 struct usb_host_endpoint *endpoint;
128 121
129 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); 122 priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL);
130 if (!priv) 123 if (!priv)
@@ -150,30 +143,6 @@ static int kobil_port_probe(struct usb_serial_port *port)
150 } 143 }
151 usb_set_serial_port_data(port, priv); 144 usb_set_serial_port_data(port, priv);
152 145
153 /* search for the necessary endpoints */
154 pdev = serial->dev;
155 actconfig = pdev->actconfig;
156 interface = actconfig->interface[0];
157 altsetting = interface->cur_altsetting;
158 endpoint = altsetting->endpoint;
159
160 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
161 endpoint = &altsetting->endpoint[i];
162 if (usb_endpoint_is_int_out(&endpoint->desc)) {
163 dev_dbg(&serial->dev->dev,
164 "%s Found interrupt out endpoint. Address: %d\n",
165 __func__, endpoint->desc.bEndpointAddress);
166 priv->write_int_endpoint_address =
167 endpoint->desc.bEndpointAddress;
168 }
169 if (usb_endpoint_is_int_in(&endpoint->desc)) {
170 dev_dbg(&serial->dev->dev,
171 "%s Found interrupt in endpoint. Address: %d\n",
172 __func__, endpoint->desc.bEndpointAddress);
173 priv->read_int_endpoint_address =
174 endpoint->desc.bEndpointAddress;
175 }
176 }
177 return 0; 146 return 0;
178} 147}
179 148
@@ -205,7 +174,6 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port)
205 struct kobil_private *priv; 174 struct kobil_private *priv;
206 unsigned char *transfer_buffer; 175 unsigned char *transfer_buffer;
207 int transfer_buffer_length = 8; 176 int transfer_buffer_length = 8;
208 int write_urb_transfer_buffer_length = 8;
209 177
210 priv = usb_get_serial_port_data(port); 178 priv = usb_get_serial_port_data(port);
211 179
@@ -214,27 +182,6 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port)
214 if (!transfer_buffer) 182 if (!transfer_buffer)
215 return -ENOMEM; 183 return -ENOMEM;
216 184
217 /* allocate write_urb */
218 if (!port->write_urb) {
219 dev_dbg(dev, "%s - Allocating port->write_urb\n", __func__);
220 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
221 if (!port->write_urb) {
222 dev_dbg(dev, "%s - usb_alloc_urb failed\n", __func__);
223 kfree(transfer_buffer);
224 return -ENOMEM;
225 }
226 }
227
228 /* allocate memory for write_urb transfer buffer */
229 port->write_urb->transfer_buffer =
230 kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL);
231 if (!port->write_urb->transfer_buffer) {
232 kfree(transfer_buffer);
233 usb_free_urb(port->write_urb);
234 port->write_urb = NULL;
235 return -ENOMEM;
236 }
237
238 /* get hardware version */ 185 /* get hardware version */
239 result = usb_control_msg(port->serial->dev, 186 result = usb_control_msg(port->serial->dev,
240 usb_rcvctrlpipe(port->serial->dev, 0), 187 usb_rcvctrlpipe(port->serial->dev, 0),
@@ -310,12 +257,7 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port)
310static void kobil_close(struct usb_serial_port *port) 257static void kobil_close(struct usb_serial_port *port)
311{ 258{
312 /* FIXME: Add rts/dtr methods */ 259 /* FIXME: Add rts/dtr methods */
313 if (port->write_urb) { 260 usb_kill_urb(port->interrupt_out_urb);
314 usb_poison_urb(port->write_urb);
315 kfree(port->write_urb->transfer_buffer);
316 usb_free_urb(port->write_urb);
317 port->write_urb = NULL;
318 }
319 usb_kill_urb(port->interrupt_in_urb); 261 usb_kill_urb(port->interrupt_in_urb);
320} 262}
321 263
@@ -333,24 +275,8 @@ static void kobil_read_int_callback(struct urb *urb)
333 } 275 }
334 276
335 if (urb->actual_length) { 277 if (urb->actual_length) {
336 278 usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
337 /* BEGIN DEBUG */ 279 data);
338 /*
339 char *dbg_data;
340
341 dbg_data = kzalloc((3 * purb->actual_length + 10)
342 * sizeof(char), GFP_KERNEL);
343 if (! dbg_data) {
344 return;
345 }
346 for (i = 0; i < purb->actual_length; i++) {
347 sprintf(dbg_data +3*i, "%02X ", data[i]);
348 }
349 dev_dbg(&port->dev, " <-- %s\n", dbg_data);
350 kfree(dbg_data);
351 */
352 /* END DEBUG */
353
354 tty_insert_flip_string(&port->port, data, urb->actual_length); 280 tty_insert_flip_string(&port->port, data, urb->actual_length);
355 tty_flip_buffer_push(&port->port); 281 tty_flip_buffer_push(&port->port);
356 } 282 }
@@ -360,7 +286,7 @@ static void kobil_read_int_callback(struct urb *urb)
360} 286}
361 287
362 288
363static void kobil_write_callback(struct urb *purb) 289static void kobil_write_int_callback(struct urb *urb)
364{ 290{
365} 291}
366 292
@@ -403,23 +329,14 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
403 329
404 while (todo > 0) { 330 while (todo > 0) {
405 /* max 8 byte in one urb (endpoint size) */ 331 /* max 8 byte in one urb (endpoint size) */
406 length = (todo < 8) ? todo : 8; 332 length = min(todo, port->interrupt_out_size);
407 /* copy data to transfer buffer */ 333 /* copy data to transfer buffer */
408 memcpy(port->write_urb->transfer_buffer, 334 memcpy(port->interrupt_out_buffer,
409 priv->buf + priv->cur_pos, length); 335 priv->buf + priv->cur_pos, length);
410 usb_fill_int_urb(port->write_urb, 336 port->interrupt_out_urb->transfer_buffer_length = length;
411 port->serial->dev,
412 usb_sndintpipe(port->serial->dev,
413 priv->write_int_endpoint_address),
414 port->write_urb->transfer_buffer,
415 length,
416 kobil_write_callback,
417 port,
418 8
419 );
420 337
421 priv->cur_pos = priv->cur_pos + length; 338 priv->cur_pos = priv->cur_pos + length;
422 result = usb_submit_urb(port->write_urb, GFP_NOIO); 339 result = usb_submit_urb(port->interrupt_out_urb, GFP_NOIO);
423 dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result); 340 dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result);
424 todo = priv->filled - priv->cur_pos; 341 todo = priv->filled - priv->cur_pos;
425 342
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 06d5a60be2c4..6a15adf53360 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -35,7 +35,6 @@
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include <linux/usb/serial.h> 36#include <linux/usb/serial.h>
37#include <linux/serial.h> 37#include <linux/serial.h>
38#include <linux/ioctl.h>
39#include "mct_u232.h" 38#include "mct_u232.h"
40 39
41#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>" 40#define DRIVER_AUTHOR "Wolfgang Grandegger <wolfgang@ces.ch>"
@@ -44,7 +43,6 @@
44/* 43/*
45 * Function prototypes 44 * Function prototypes
46 */ 45 */
47static int mct_u232_startup(struct usb_serial *serial);
48static int mct_u232_port_probe(struct usb_serial_port *port); 46static int mct_u232_port_probe(struct usb_serial_port *port);
49static int mct_u232_port_remove(struct usb_serial_port *remove); 47static int mct_u232_port_remove(struct usb_serial_port *remove);
50static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); 48static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port);
@@ -57,10 +55,6 @@ static void mct_u232_break_ctl(struct tty_struct *tty, int break_state);
57static int mct_u232_tiocmget(struct tty_struct *tty); 55static int mct_u232_tiocmget(struct tty_struct *tty);
58static int mct_u232_tiocmset(struct tty_struct *tty, 56static int mct_u232_tiocmset(struct tty_struct *tty,
59 unsigned int set, unsigned int clear); 57 unsigned int set, unsigned int clear);
60static int mct_u232_ioctl(struct tty_struct *tty,
61 unsigned int cmd, unsigned long arg);
62static int mct_u232_get_icount(struct tty_struct *tty,
63 struct serial_icounter_struct *icount);
64static void mct_u232_throttle(struct tty_struct *tty); 58static void mct_u232_throttle(struct tty_struct *tty);
65static void mct_u232_unthrottle(struct tty_struct *tty); 59static void mct_u232_unthrottle(struct tty_struct *tty);
66 60
@@ -95,11 +89,10 @@ static struct usb_serial_driver mct_u232_device = {
95 .break_ctl = mct_u232_break_ctl, 89 .break_ctl = mct_u232_break_ctl,
96 .tiocmget = mct_u232_tiocmget, 90 .tiocmget = mct_u232_tiocmget,
97 .tiocmset = mct_u232_tiocmset, 91 .tiocmset = mct_u232_tiocmset,
98 .attach = mct_u232_startup, 92 .tiocmiwait = usb_serial_generic_tiocmiwait,
99 .port_probe = mct_u232_port_probe, 93 .port_probe = mct_u232_port_probe,
100 .port_remove = mct_u232_port_remove, 94 .port_remove = mct_u232_port_remove,
101 .ioctl = mct_u232_ioctl, 95 .get_icount = usb_serial_generic_get_icount,
102 .get_icount = mct_u232_get_icount,
103}; 96};
104 97
105static struct usb_serial_driver * const serial_drivers[] = { 98static struct usb_serial_driver * const serial_drivers[] = {
@@ -107,13 +100,13 @@ static struct usb_serial_driver * const serial_drivers[] = {
107}; 100};
108 101
109struct mct_u232_private { 102struct mct_u232_private {
103 struct urb *read_urb;
110 spinlock_t lock; 104 spinlock_t lock;
111 unsigned int control_state; /* Modem Line Setting (TIOCM) */ 105 unsigned int control_state; /* Modem Line Setting (TIOCM) */
112 unsigned char last_lcr; /* Line Control Register */ 106 unsigned char last_lcr; /* Line Control Register */
113 unsigned char last_lsr; /* Line Status Register */ 107 unsigned char last_lsr; /* Line Status Register */
114 unsigned char last_msr; /* Modem Status Register */ 108 unsigned char last_msr; /* Modem Status Register */
115 unsigned int rx_flags; /* Throttling flags */ 109 unsigned int rx_flags; /* Throttling flags */
116 struct async_icount icount;
117}; 110};
118 111
119#define THROTTLED 0x01 112#define THROTTLED 0x01
@@ -382,22 +375,6 @@ static void mct_u232_msr_to_state(struct usb_serial_port *port,
382 * Driver's tty interface functions 375 * Driver's tty interface functions
383 */ 376 */
384 377
385static int mct_u232_startup(struct usb_serial *serial)
386{
387 struct usb_serial_port *port, *rport;
388
389 /* Puh, that's dirty */
390 port = serial->port[0];
391 rport = serial->port[1];
392 /* No unlinking, it wasn't submitted yet. */
393 usb_free_urb(port->read_urb);
394 port->read_urb = rport->interrupt_in_urb;
395 rport->interrupt_in_urb = NULL;
396 port->read_urb->context = port;
397
398 return 0;
399} /* mct_u232_startup */
400
401static int mct_u232_port_probe(struct usb_serial_port *port) 378static int mct_u232_port_probe(struct usb_serial_port *port)
402{ 379{
403 struct mct_u232_private *priv; 380 struct mct_u232_private *priv;
@@ -406,6 +383,10 @@ static int mct_u232_port_probe(struct usb_serial_port *port)
406 if (!priv) 383 if (!priv)
407 return -ENOMEM; 384 return -ENOMEM;
408 385
386 /* Use second interrupt-in endpoint for reading. */
387 priv->read_urb = port->serial->port[1]->interrupt_in_urb;
388 priv->read_urb->context = port;
389
409 spin_lock_init(&priv->lock); 390 spin_lock_init(&priv->lock);
410 391
411 usb_set_serial_port_data(port, priv); 392 usb_set_serial_port_data(port, priv);
@@ -469,17 +450,17 @@ static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
469 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr); 450 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr);
470 spin_unlock_irqrestore(&priv->lock, flags); 451 spin_unlock_irqrestore(&priv->lock, flags);
471 452
472 retval = usb_submit_urb(port->read_urb, GFP_KERNEL); 453 retval = usb_submit_urb(priv->read_urb, GFP_KERNEL);
473 if (retval) { 454 if (retval) {
474 dev_err(&port->dev, 455 dev_err(&port->dev,
475 "usb_submit_urb(read bulk) failed pipe 0x%x err %d\n", 456 "usb_submit_urb(read) failed pipe 0x%x err %d\n",
476 port->read_urb->pipe, retval); 457 port->read_urb->pipe, retval);
477 goto error; 458 goto error;
478 } 459 }
479 460
480 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 461 retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
481 if (retval) { 462 if (retval) {
482 usb_kill_urb(port->read_urb); 463 usb_kill_urb(priv->read_urb);
483 dev_err(&port->dev, 464 dev_err(&port->dev,
484 "usb_submit_urb(read int) failed pipe 0x%x err %d", 465 "usb_submit_urb(read int) failed pipe 0x%x err %d",
485 port->interrupt_in_urb->pipe, retval); 466 port->interrupt_in_urb->pipe, retval);
@@ -509,11 +490,9 @@ static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
509 490
510static void mct_u232_close(struct usb_serial_port *port) 491static void mct_u232_close(struct usb_serial_port *port)
511{ 492{
512 /* 493 struct mct_u232_private *priv = usb_get_serial_port_data(port);
513 * Must kill the read urb as it is actually an interrupt urb, which 494
514 * generic close thus fails to kill. 495 usb_kill_urb(priv->read_urb);
515 */
516 usb_kill_urb(port->read_urb);
517 usb_kill_urb(port->interrupt_in_urb); 496 usb_kill_urb(port->interrupt_in_urb);
518 497
519 usb_serial_generic_close(port); 498 usb_serial_generic_close(port);
@@ -570,7 +549,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
570 /* Record Control Line states */ 549 /* Record Control Line states */
571 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr); 550 mct_u232_msr_to_state(port, &priv->control_state, priv->last_msr);
572 551
573 mct_u232_msr_to_icount(&priv->icount, priv->last_msr); 552 mct_u232_msr_to_icount(&port->icount, priv->last_msr);
574 553
575#if 0 554#if 0
576 /* Not yet handled. See belkin_sa.c for further information */ 555 /* Not yet handled. See belkin_sa.c for further information */
@@ -598,7 +577,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
598 tty_kref_put(tty); 577 tty_kref_put(tty);
599 } 578 }
600#endif 579#endif
601 wake_up_interruptible(&port->delta_msr_wait); 580 wake_up_interruptible(&port->port.delta_msr_wait);
602 spin_unlock_irqrestore(&priv->lock, flags); 581 spin_unlock_irqrestore(&priv->lock, flags);
603exit: 582exit:
604 retval = usb_submit_urb(urb, GFP_ATOMIC); 583 retval = usb_submit_urb(urb, GFP_ATOMIC);
@@ -786,86 +765,6 @@ static void mct_u232_unthrottle(struct tty_struct *tty)
786 } 765 }
787} 766}
788 767
789static int mct_u232_ioctl(struct tty_struct *tty,
790 unsigned int cmd, unsigned long arg)
791{
792 DEFINE_WAIT(wait);
793 struct usb_serial_port *port = tty->driver_data;
794 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
795 struct async_icount cnow, cprev;
796 unsigned long flags;
797
798 dev_dbg(&port->dev, "%s - cmd = 0x%x\n", __func__, cmd);
799
800 switch (cmd) {
801
802 case TIOCMIWAIT:
803
804 dev_dbg(&port->dev, "%s TIOCMIWAIT", __func__);
805
806 spin_lock_irqsave(&mct_u232_port->lock, flags);
807 cprev = mct_u232_port->icount;
808 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
809 for ( ; ; ) {
810 prepare_to_wait(&port->delta_msr_wait,
811 &wait, TASK_INTERRUPTIBLE);
812 schedule();
813 finish_wait(&port->delta_msr_wait, &wait);
814 /* see if a signal did it */
815 if (signal_pending(current))
816 return -ERESTARTSYS;
817
818 if (port->serial->disconnected)
819 return -EIO;
820
821 spin_lock_irqsave(&mct_u232_port->lock, flags);
822 cnow = mct_u232_port->icount;
823 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
824 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
825 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
826 return -EIO; /* no change => error */
827 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
828 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
829 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
830 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
831 return 0;
832 }
833 cprev = cnow;
834 }
835
836 }
837 return -ENOIOCTLCMD;
838}
839
840static int mct_u232_get_icount(struct tty_struct *tty,
841 struct serial_icounter_struct *icount)
842{
843 struct usb_serial_port *port = tty->driver_data;
844 struct mct_u232_private *mct_u232_port = usb_get_serial_port_data(port);
845 struct async_icount *ic = &mct_u232_port->icount;
846 unsigned long flags;
847
848 spin_lock_irqsave(&mct_u232_port->lock, flags);
849
850 icount->cts = ic->cts;
851 icount->dsr = ic->dsr;
852 icount->rng = ic->rng;
853 icount->dcd = ic->dcd;
854 icount->rx = ic->rx;
855 icount->tx = ic->tx;
856 icount->frame = ic->frame;
857 icount->overrun = ic->overrun;
858 icount->parity = ic->parity;
859 icount->brk = ic->brk;
860 icount->buf_overrun = ic->buf_overrun;
861
862 spin_unlock_irqrestore(&mct_u232_port->lock, flags);
863
864 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n",
865 __func__, icount->rx, icount->tx);
866 return 0;
867}
868
869module_usb_serial_driver(serial_drivers, id_table); 768module_usb_serial_driver(serial_drivers, id_table);
870 769
871MODULE_AUTHOR(DRIVER_AUTHOR); 770MODULE_AUTHOR(DRIVER_AUTHOR);
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index bf3c7a23553e..47e247759eb0 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -177,10 +177,7 @@ static void metrousb_cleanup(struct usb_serial_port *port)
177 usb_unlink_urb(port->interrupt_in_urb); 177 usb_unlink_urb(port->interrupt_in_urb);
178 usb_kill_urb(port->interrupt_in_urb); 178 usb_kill_urb(port->interrupt_in_urb);
179 179
180 mutex_lock(&port->serial->disc_mutex); 180 metrousb_send_unidirectional_cmd(UNI_CMD_CLOSE, port);
181 if (!port->serial->disconnected)
182 metrousb_send_unidirectional_cmd(UNI_CMD_CLOSE, port);
183 mutex_unlock(&port->serial->disc_mutex);
184} 181}
185 182
186static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port) 183static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port)
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index e956eae198fd..cc0e54345df9 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -62,7 +62,6 @@ struct moschip_port {
62 __u8 shadowMCR; /* last MCR value received */ 62 __u8 shadowMCR; /* last MCR value received */
63 __u8 shadowMSR; /* last MSR value received */ 63 __u8 shadowMSR; /* last MSR value received */
64 char open; 64 char open;
65 struct async_icount icount;
66 struct usb_serial_port *port; /* loop back to the owner */ 65 struct usb_serial_port *port; /* loop back to the owner */
67 struct urb *write_urb_pool[NUM_URBS]; 66 struct urb *write_urb_pool[NUM_URBS];
68}; 67};
@@ -1071,9 +1070,6 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
1071 dev_err(&port->dev, "%s - Error %d submitting read urb\n", 1070 dev_err(&port->dev, "%s - Error %d submitting read urb\n",
1072 __func__, response); 1071 __func__, response);
1073 1072
1074 /* initialize our icount structure */
1075 memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
1076
1077 /* initialize our port settings */ 1073 /* initialize our port settings */
1078 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */ 1074 mos7720_port->shadowMCR = UART_MCR_OUT2; /* Must set to enable ints! */
1079 1075
@@ -1140,16 +1136,9 @@ static void mos7720_close(struct usb_serial_port *port)
1140 usb_kill_urb(port->write_urb); 1136 usb_kill_urb(port->write_urb);
1141 usb_kill_urb(port->read_urb); 1137 usb_kill_urb(port->read_urb);
1142 1138
1143 mutex_lock(&serial->disc_mutex); 1139 write_mos_reg(serial, port->number - port->serial->minor, MCR, 0x00);
1144 /* these commands must not be issued if the device has 1140 write_mos_reg(serial, port->number - port->serial->minor, IER, 0x00);
1145 * been disconnected */ 1141
1146 if (!serial->disconnected) {
1147 write_mos_reg(serial, port->number - port->serial->minor,
1148 MCR, 0x00);
1149 write_mos_reg(serial, port->number - port->serial->minor,
1150 IER, 0x00);
1151 }
1152 mutex_unlock(&serial->disc_mutex);
1153 mos7720_port->open = 0; 1142 mos7720_port->open = 0;
1154} 1143}
1155 1144
@@ -1799,33 +1788,6 @@ static int mos7720_tiocmset(struct tty_struct *tty,
1799 return 0; 1788 return 0;
1800} 1789}
1801 1790
1802static int mos7720_get_icount(struct tty_struct *tty,
1803 struct serial_icounter_struct *icount)
1804{
1805 struct usb_serial_port *port = tty->driver_data;
1806 struct moschip_port *mos7720_port;
1807 struct async_icount cnow;
1808
1809 mos7720_port = usb_get_serial_port_data(port);
1810 cnow = mos7720_port->icount;
1811
1812 icount->cts = cnow.cts;
1813 icount->dsr = cnow.dsr;
1814 icount->rng = cnow.rng;
1815 icount->dcd = cnow.dcd;
1816 icount->rx = cnow.rx;
1817 icount->tx = cnow.tx;
1818 icount->frame = cnow.frame;
1819 icount->overrun = cnow.overrun;
1820 icount->parity = cnow.parity;
1821 icount->brk = cnow.brk;
1822 icount->buf_overrun = cnow.buf_overrun;
1823
1824 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
1825 icount->rx, icount->tx);
1826 return 0;
1827}
1828
1829static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, 1791static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1830 unsigned int __user *value) 1792 unsigned int __user *value)
1831{ 1793{
@@ -1901,8 +1863,6 @@ static int mos7720_ioctl(struct tty_struct *tty,
1901{ 1863{
1902 struct usb_serial_port *port = tty->driver_data; 1864 struct usb_serial_port *port = tty->driver_data;
1903 struct moschip_port *mos7720_port; 1865 struct moschip_port *mos7720_port;
1904 struct async_icount cnow;
1905 struct async_icount cprev;
1906 1866
1907 mos7720_port = usb_get_serial_port_data(port); 1867 mos7720_port = usb_get_serial_port_data(port);
1908 if (mos7720_port == NULL) 1868 if (mos7720_port == NULL)
@@ -1927,27 +1887,6 @@ static int mos7720_ioctl(struct tty_struct *tty,
1927 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__); 1887 dev_dbg(&port->dev, "%s TIOCGSERIAL\n", __func__);
1928 return get_serial_info(mos7720_port, 1888 return get_serial_info(mos7720_port,
1929 (struct serial_struct __user *)arg); 1889 (struct serial_struct __user *)arg);
1930
1931 case TIOCMIWAIT:
1932 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
1933 cprev = mos7720_port->icount;
1934 while (1) {
1935 if (signal_pending(current))
1936 return -ERESTARTSYS;
1937 cnow = mos7720_port->icount;
1938 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
1939 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
1940 return -EIO; /* no change => error */
1941 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1942 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1943 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1944 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1945 return 0;
1946 }
1947 cprev = cnow;
1948 }
1949 /* NOTREACHED */
1950 break;
1951 } 1890 }
1952 1891
1953 return -ENOIOCTLCMD; 1892 return -ENOIOCTLCMD;
@@ -2103,7 +2042,6 @@ static struct usb_serial_driver moschip7720_2port_driver = {
2103 .ioctl = mos7720_ioctl, 2042 .ioctl = mos7720_ioctl,
2104 .tiocmget = mos7720_tiocmget, 2043 .tiocmget = mos7720_tiocmget,
2105 .tiocmset = mos7720_tiocmset, 2044 .tiocmset = mos7720_tiocmset,
2106 .get_icount = mos7720_get_icount,
2107 .set_termios = mos7720_set_termios, 2045 .set_termios = mos7720_set_termios,
2108 .write = mos7720_write, 2046 .write = mos7720_write,
2109 .write_room = mos7720_write_room, 2047 .write_room = mos7720_write_room,
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 2be376a2e0e3..a0d5ea545982 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -219,8 +219,6 @@ struct moschip_port {
219 char open; 219 char open;
220 char open_ports; 220 char open_ports;
221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */ 221 wait_queue_head_t wait_chase; /* for handling sleeping while waiting for chase to finish */
222 int delta_msr_cond;
223 struct async_icount icount;
224 struct usb_serial_port *port; /* loop back to the owner of this object */ 222 struct usb_serial_port *port; /* loop back to the owner of this object */
225 223
226 /* Offsets */ 224 /* Offsets */
@@ -399,32 +397,22 @@ static void mos7840_handle_new_msr(struct moschip_port *port, __u8 new_msr)
399 struct moschip_port *mos7840_port; 397 struct moschip_port *mos7840_port;
400 struct async_icount *icount; 398 struct async_icount *icount;
401 mos7840_port = port; 399 mos7840_port = port;
402 icount = &mos7840_port->icount;
403 if (new_msr & 400 if (new_msr &
404 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI | 401 (MOS_MSR_DELTA_CTS | MOS_MSR_DELTA_DSR | MOS_MSR_DELTA_RI |
405 MOS_MSR_DELTA_CD)) { 402 MOS_MSR_DELTA_CD)) {
406 icount = &mos7840_port->icount; 403 icount = &mos7840_port->port->icount;
407 404
408 /* update input line counters */ 405 /* update input line counters */
409 if (new_msr & MOS_MSR_DELTA_CTS) { 406 if (new_msr & MOS_MSR_DELTA_CTS)
410 icount->cts++; 407 icount->cts++;
411 smp_wmb(); 408 if (new_msr & MOS_MSR_DELTA_DSR)
412 }
413 if (new_msr & MOS_MSR_DELTA_DSR) {
414 icount->dsr++; 409 icount->dsr++;
415 smp_wmb(); 410 if (new_msr & MOS_MSR_DELTA_CD)
416 }
417 if (new_msr & MOS_MSR_DELTA_CD) {
418 icount->dcd++; 411 icount->dcd++;
419 smp_wmb(); 412 if (new_msr & MOS_MSR_DELTA_RI)
420 }
421 if (new_msr & MOS_MSR_DELTA_RI) {
422 icount->rng++; 413 icount->rng++;
423 smp_wmb();
424 }
425 414
426 mos7840_port->delta_msr_cond = 1; 415 wake_up_interruptible(&port->port->port.delta_msr_wait);
427 wake_up_interruptible(&port->port->delta_msr_wait);
428 } 416 }
429} 417}
430 418
@@ -442,23 +430,15 @@ static void mos7840_handle_new_lsr(struct moschip_port *port, __u8 new_lsr)
442 } 430 }
443 431
444 /* update input line counters */ 432 /* update input line counters */
445 icount = &port->icount; 433 icount = &port->port->icount;
446 if (new_lsr & SERIAL_LSR_BI) { 434 if (new_lsr & SERIAL_LSR_BI)
447 icount->brk++; 435 icount->brk++;
448 smp_wmb(); 436 if (new_lsr & SERIAL_LSR_OE)
449 }
450 if (new_lsr & SERIAL_LSR_OE) {
451 icount->overrun++; 437 icount->overrun++;
452 smp_wmb(); 438 if (new_lsr & SERIAL_LSR_PE)
453 }
454 if (new_lsr & SERIAL_LSR_PE) {
455 icount->parity++; 439 icount->parity++;
456 smp_wmb(); 440 if (new_lsr & SERIAL_LSR_FE)
457 }
458 if (new_lsr & SERIAL_LSR_FE) {
459 icount->frame++; 441 icount->frame++;
460 smp_wmb();
461 }
462} 442}
463 443
464/************************************************************************/ 444/************************************************************************/
@@ -777,9 +757,8 @@ static void mos7840_bulk_in_callback(struct urb *urb)
777 struct tty_port *tport = &mos7840_port->port->port; 757 struct tty_port *tport = &mos7840_port->port->port;
778 tty_insert_flip_string(tport, data, urb->actual_length); 758 tty_insert_flip_string(tport, data, urb->actual_length);
779 tty_flip_buffer_push(tport); 759 tty_flip_buffer_push(tport);
780 mos7840_port->icount.rx += urb->actual_length; 760 port->icount.rx += urb->actual_length;
781 smp_wmb(); 761 dev_dbg(&port->dev, "icount.rx is %d:\n", port->icount.rx);
782 dev_dbg(&port->dev, "mos7840_port->icount.rx is %d:\n", mos7840_port->icount.rx);
783 } 762 }
784 763
785 if (!mos7840_port->read_urb) { 764 if (!mos7840_port->read_urb) {
@@ -1127,17 +1106,12 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
1127 /* initialize our wait queues */ 1106 /* initialize our wait queues */
1128 init_waitqueue_head(&mos7840_port->wait_chase); 1107 init_waitqueue_head(&mos7840_port->wait_chase);
1129 1108
1130 /* initialize our icount structure */
1131 memset(&(mos7840_port->icount), 0x00, sizeof(mos7840_port->icount));
1132
1133 /* initialize our port settings */ 1109 /* initialize our port settings */
1134 /* Must set to enable ints! */ 1110 /* Must set to enable ints! */
1135 mos7840_port->shadowMCR = MCR_MASTER_IE; 1111 mos7840_port->shadowMCR = MCR_MASTER_IE;
1136 /* send a open port command */ 1112 /* send a open port command */
1137 mos7840_port->open = 1; 1113 mos7840_port->open = 1;
1138 /* mos7840_change_port_settings(mos7840_port,old_termios); */ 1114 /* mos7840_change_port_settings(mos7840_port,old_termios); */
1139 mos7840_port->icount.tx = 0;
1140 mos7840_port->icount.rx = 0;
1141 1115
1142 return 0; 1116 return 0;
1143} 1117}
@@ -1220,25 +1194,10 @@ static void mos7840_close(struct usb_serial_port *port)
1220 } 1194 }
1221 } 1195 }
1222 1196
1223 /* While closing port, shutdown all bulk read, write * 1197 usb_kill_urb(mos7840_port->write_urb);
1224 * and interrupt read if they exists */ 1198 usb_kill_urb(mos7840_port->read_urb);
1225 if (serial->dev) { 1199 mos7840_port->read_urb_busy = false;
1226 if (mos7840_port->write_urb) { 1200
1227 dev_dbg(&port->dev, "%s", "Shutdown bulk write\n");
1228 usb_kill_urb(mos7840_port->write_urb);
1229 }
1230 if (mos7840_port->read_urb) {
1231 dev_dbg(&port->dev, "%s", "Shutdown bulk read\n");
1232 usb_kill_urb(mos7840_port->read_urb);
1233 mos7840_port->read_urb_busy = false;
1234 }
1235 if ((&mos7840_port->control_urb)) {
1236 dev_dbg(&port->dev, "%s", "Shutdown control read\n");
1237 /*/ usb_kill_urb (mos7840_port->control_urb); */
1238 }
1239 }
1240/* if(mos7840_port->ctrl_buf != NULL) */
1241/* kfree(mos7840_port->ctrl_buf); */
1242 port0->open_ports--; 1201 port0->open_ports--;
1243 dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number); 1202 dev_dbg(&port->dev, "%s in close%d:in port%d\n", __func__, port0->open_ports, port->number);
1244 if (port0->open_ports == 0) { 1203 if (port0->open_ports == 0) {
@@ -1250,8 +1209,7 @@ static void mos7840_close(struct usb_serial_port *port)
1250 1209
1251 if (mos7840_port->write_urb) { 1210 if (mos7840_port->write_urb) {
1252 /* if this urb had a transfer buffer already (old tx) free it */ 1211 /* if this urb had a transfer buffer already (old tx) free it */
1253 if (mos7840_port->write_urb->transfer_buffer != NULL) 1212 kfree(mos7840_port->write_urb->transfer_buffer);
1254 kfree(mos7840_port->write_urb->transfer_buffer);
1255 usb_free_urb(mos7840_port->write_urb); 1213 usb_free_urb(mos7840_port->write_urb);
1256 } 1214 }
1257 1215
@@ -1328,9 +1286,8 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
1328 if (mos7840_port == NULL) 1286 if (mos7840_port == NULL)
1329 return; 1287 return;
1330 1288
1331 if (serial->dev) 1289 /* flush and block until tx is empty */
1332 /* flush and block until tx is empty */ 1290 mos7840_block_until_chase_response(tty, mos7840_port);
1333 mos7840_block_until_chase_response(tty, mos7840_port);
1334 1291
1335 if (break_state == -1) 1292 if (break_state == -1)
1336 data = mos7840_port->shadowLCR | LCR_SET_BREAK; 1293 data = mos7840_port->shadowLCR | LCR_SET_BREAK;
@@ -1520,9 +1477,8 @@ static int mos7840_write(struct tty_struct *tty, struct usb_serial_port *port,
1520 goto exit; 1477 goto exit;
1521 } 1478 }
1522 bytes_sent = transfer_size; 1479 bytes_sent = transfer_size;
1523 mos7840_port->icount.tx += transfer_size; 1480 port->icount.tx += transfer_size;
1524 smp_wmb(); 1481 dev_dbg(&port->dev, "icount.tx is %d:\n", port->icount.tx);
1525 dev_dbg(&port->dev, "mos7840_port->icount.tx is %d:\n", mos7840_port->icount.tx);
1526exit: 1482exit:
1527 return bytes_sent; 1483 return bytes_sent;
1528 1484
@@ -2141,34 +2097,6 @@ static int mos7840_get_serial_info(struct moschip_port *mos7840_port,
2141 return 0; 2097 return 0;
2142} 2098}
2143 2099
2144static int mos7840_get_icount(struct tty_struct *tty,
2145 struct serial_icounter_struct *icount)
2146{
2147 struct usb_serial_port *port = tty->driver_data;
2148 struct moschip_port *mos7840_port;
2149 struct async_icount cnow;
2150
2151 mos7840_port = mos7840_get_port_private(port);
2152 cnow = mos7840_port->icount;
2153
2154 smp_rmb();
2155 icount->cts = cnow.cts;
2156 icount->dsr = cnow.dsr;
2157 icount->rng = cnow.rng;
2158 icount->dcd = cnow.dcd;
2159 icount->rx = cnow.rx;
2160 icount->tx = cnow.tx;
2161 icount->frame = cnow.frame;
2162 icount->overrun = cnow.overrun;
2163 icount->parity = cnow.parity;
2164 icount->brk = cnow.brk;
2165 icount->buf_overrun = cnow.buf_overrun;
2166
2167 dev_dbg(&port->dev, "%s TIOCGICOUNT RX=%d, TX=%d\n", __func__,
2168 icount->rx, icount->tx);
2169 return 0;
2170}
2171
2172/***************************************************************************** 2100/*****************************************************************************
2173 * SerialIoctl 2101 * SerialIoctl
2174 * this function handles any ioctl calls to the driver 2102 * this function handles any ioctl calls to the driver
@@ -2181,9 +2109,6 @@ static int mos7840_ioctl(struct tty_struct *tty,
2181 void __user *argp = (void __user *)arg; 2109 void __user *argp = (void __user *)arg;
2182 struct moschip_port *mos7840_port; 2110 struct moschip_port *mos7840_port;
2183 2111
2184 struct async_icount cnow;
2185 struct async_icount cprev;
2186
2187 if (mos7840_port_paranoia_check(port, __func__)) 2112 if (mos7840_port_paranoia_check(port, __func__))
2188 return -1; 2113 return -1;
2189 2114
@@ -2208,41 +2133,6 @@ static int mos7840_ioctl(struct tty_struct *tty,
2208 case TIOCSSERIAL: 2133 case TIOCSSERIAL:
2209 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__); 2134 dev_dbg(&port->dev, "%s TIOCSSERIAL\n", __func__);
2210 break; 2135 break;
2211
2212 case TIOCMIWAIT:
2213 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
2214 cprev = mos7840_port->icount;
2215 while (1) {
2216 /* interruptible_sleep_on(&mos7840_port->delta_msr_wait); */
2217 mos7840_port->delta_msr_cond = 0;
2218 wait_event_interruptible(port->delta_msr_wait,
2219 (port->serial->disconnected ||
2220 mos7840_port->
2221 delta_msr_cond == 1));
2222
2223 /* see if a signal did it */
2224 if (signal_pending(current))
2225 return -ERESTARTSYS;
2226
2227 if (port->serial->disconnected)
2228 return -EIO;
2229
2230 cnow = mos7840_port->icount;
2231 smp_rmb();
2232 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2233 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2234 return -EIO; /* no change => error */
2235 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2236 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2237 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2238 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
2239 return 0;
2240 }
2241 cprev = cnow;
2242 }
2243 /* NOTREACHED */
2244 break;
2245
2246 default: 2136 default:
2247 break; 2137 break;
2248 } 2138 }
@@ -2589,7 +2479,8 @@ static struct usb_serial_driver moschip7840_4port_device = {
2589 .break_ctl = mos7840_break, 2479 .break_ctl = mos7840_break,
2590 .tiocmget = mos7840_tiocmget, 2480 .tiocmget = mos7840_tiocmget,
2591 .tiocmset = mos7840_tiocmset, 2481 .tiocmset = mos7840_tiocmset,
2592 .get_icount = mos7840_get_icount, 2482 .tiocmiwait = usb_serial_generic_tiocmiwait,
2483 .get_icount = usb_serial_generic_get_icount,
2593 .port_probe = mos7840_port_probe, 2484 .port_probe = mos7840_port_probe,
2594 .port_remove = mos7840_port_remove, 2485 .port_remove = mos7840_port_remove,
2595 .read_bulk_callback = mos7840_bulk_in_callback, 2486 .read_bulk_callback = mos7840_bulk_in_callback,
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 1e1cafe287e4..5739bf6f7200 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -33,8 +33,7 @@
33 33
34/* function prototypes */ 34/* function prototypes */
35static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port); 35static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port);
36static void omninet_close(struct usb_serial_port *port); 36static void omninet_process_read_urb(struct urb *urb);
37static void omninet_read_bulk_callback(struct urb *urb);
38static void omninet_write_bulk_callback(struct urb *urb); 37static void omninet_write_bulk_callback(struct urb *urb);
39static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 38static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
40 const unsigned char *buf, int count); 39 const unsigned char *buf, int count);
@@ -61,11 +60,10 @@ static struct usb_serial_driver zyxel_omninet_device = {
61 .port_probe = omninet_port_probe, 60 .port_probe = omninet_port_probe,
62 .port_remove = omninet_port_remove, 61 .port_remove = omninet_port_remove,
63 .open = omninet_open, 62 .open = omninet_open,
64 .close = omninet_close,
65 .write = omninet_write, 63 .write = omninet_write,
66 .write_room = omninet_write_room, 64 .write_room = omninet_write_room,
67 .read_bulk_callback = omninet_read_bulk_callback,
68 .write_bulk_callback = omninet_write_bulk_callback, 65 .write_bulk_callback = omninet_write_bulk_callback,
66 .process_read_urb = omninet_process_read_urb,
69 .disconnect = omninet_disconnect, 67 .disconnect = omninet_disconnect,
70}; 68};
71 69
@@ -74,29 +72,28 @@ static struct usb_serial_driver * const serial_drivers[] = {
74}; 72};
75 73
76 74
77/* The protocol. 75/*
76 * The protocol.
78 * 77 *
79 * The omni.net always exchange 64 bytes of data with the host. The first 78 * The omni.net always exchange 64 bytes of data with the host. The first
80 * four bytes are the control header, you can see it in the above structure. 79 * four bytes are the control header.
81 * 80 *
82 * oh_seq is a sequence number. Don't know if/how it's used. 81 * oh_seq is a sequence number. Don't know if/how it's used.
83 * oh_len is the length of the data bytes in the packet. 82 * oh_len is the length of the data bytes in the packet.
84 * oh_xxx Bit-mapped, related to handshaking and status info. 83 * oh_xxx Bit-mapped, related to handshaking and status info.
85 * I normally set it to 0x03 in trasmitted frames. 84 * I normally set it to 0x03 in transmitted frames.
86 * 7: Active when the TA is in a CONNECTed state. 85 * 7: Active when the TA is in a CONNECTed state.
87 * 6: unknown 86 * 6: unknown
88 * 5: handshaking, unknown 87 * 5: handshaking, unknown
89 * 4: handshaking, unknown 88 * 4: handshaking, unknown
90 * 3: unknown, usually 0 89 * 3: unknown, usually 0
91 * 2: unknown, usually 0 90 * 2: unknown, usually 0
92 * 1: handshaking, unknown, usually set to 1 in trasmitted frames 91 * 1: handshaking, unknown, usually set to 1 in transmitted frames
93 * 0: handshaking, unknown, usually set to 1 in trasmitted frames 92 * 0: handshaking, unknown, usually set to 1 in transmitted frames
94 * oh_pad Probably a pad byte. 93 * oh_pad Probably a pad byte.
95 * 94 *
96 * After the header you will find data bytes if oh_len was greater than zero. 95 * After the header you will find data bytes if oh_len was greater than zero.
97 *
98 */ 96 */
99
100struct omninet_header { 97struct omninet_header {
101 __u8 oh_seq; 98 __u8 oh_seq;
102 __u8 oh_len; 99 __u8 oh_len;
@@ -112,7 +109,7 @@ static int omninet_port_probe(struct usb_serial_port *port)
112{ 109{
113 struct omninet_data *od; 110 struct omninet_data *od;
114 111
115 od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL); 112 od = kzalloc(sizeof(*od), GFP_KERNEL);
116 if (!od) 113 if (!od)
117 return -ENOMEM; 114 return -ENOMEM;
118 115
@@ -135,56 +132,32 @@ static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port)
135{ 132{
136 struct usb_serial *serial = port->serial; 133 struct usb_serial *serial = port->serial;
137 struct usb_serial_port *wport; 134 struct usb_serial_port *wport;
138 int result = 0;
139 135
140 wport = serial->port[1]; 136 wport = serial->port[1];
141 tty_port_tty_set(&wport->port, tty); 137 tty_port_tty_set(&wport->port, tty);
142 138
143 /* Start reading from the device */ 139 return usb_serial_generic_open(tty, port);
144 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
145 if (result)
146 dev_err(&port->dev,
147 "%s - failed submitting read urb, error %d\n",
148 __func__, result);
149 return result;
150}
151
152static void omninet_close(struct usb_serial_port *port)
153{
154 usb_kill_urb(port->read_urb);
155} 140}
156 141
142#define OMNINET_HEADERLEN 4
143#define OMNINET_BULKOUTSIZE 64
144#define OMNINET_PAYLOADSIZE (OMNINET_BULKOUTSIZE - OMNINET_HEADERLEN)
157 145
158#define OMNINET_DATAOFFSET 0x04 146static void omninet_process_read_urb(struct urb *urb)
159#define OMNINET_HEADERLEN sizeof(struct omninet_header)
160#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN)
161
162static void omninet_read_bulk_callback(struct urb *urb)
163{ 147{
164 struct usb_serial_port *port = urb->context; 148 struct usb_serial_port *port = urb->context;
165 unsigned char *data = urb->transfer_buffer; 149 const struct omninet_header *hdr = urb->transfer_buffer;
166 struct omninet_header *header = (struct omninet_header *) &data[0]; 150 const unsigned char *data;
167 int status = urb->status; 151 size_t data_len;
168 int result;
169 152
170 if (status) { 153 if (urb->actual_length <= OMNINET_HEADERLEN || !hdr->oh_len)
171 dev_dbg(&port->dev, "%s - nonzero read bulk status received: %d\n",
172 __func__, status);
173 return; 154 return;
174 }
175
176 if (urb->actual_length && header->oh_len) {
177 tty_insert_flip_string(&port->port, data + OMNINET_DATAOFFSET,
178 header->oh_len);
179 tty_flip_buffer_push(&port->port);
180 }
181 155
182 /* Continue trying to always read */ 156 data = (char *)urb->transfer_buffer + OMNINET_HEADERLEN;
183 result = usb_submit_urb(urb, GFP_ATOMIC); 157 data_len = min_t(size_t, urb->actual_length - OMNINET_HEADERLEN,
184 if (result) 158 hdr->oh_len);
185 dev_err(&port->dev, 159 tty_insert_flip_string(&port->port, data, data_len);
186 "%s - failed resubmitting read urb, error %d\n", 160 tty_flip_buffer_push(&port->port);
187 __func__, result);
188} 161}
189 162
190static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 163static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -209,9 +182,9 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
209 return 0; 182 return 0;
210 } 183 }
211 184
212 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 185 count = (count > OMNINET_PAYLOADSIZE) ? OMNINET_PAYLOADSIZE : count;
213 186
214 memcpy(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, 187 memcpy(wport->write_urb->transfer_buffer + OMNINET_HEADERLEN,
215 buf, count); 188 buf, count);
216 189
217 usb_serial_debug_data(&port->dev, __func__, count, 190 usb_serial_debug_data(&port->dev, __func__, count,
@@ -223,7 +196,7 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
223 header->oh_pad = 0x00; 196 header->oh_pad = 0x00;
224 197
225 /* send the data out the bulk port, always 64 bytes */ 198 /* send the data out the bulk port, always 64 bytes */
226 wport->write_urb->transfer_buffer_length = 64; 199 wport->write_urb->transfer_buffer_length = OMNINET_BULKOUTSIZE;
227 200
228 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 201 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
229 if (result) { 202 if (result) {
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index e13e1a4d3e1e..5f4b0cd0f6e9 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -120,7 +120,10 @@ static int send_control_msg(struct usb_serial_port *port, u8 requesttype,
120 0, 0, buffer, 1, 0); 120 0, 0, buffer, 1, 0);
121 kfree(buffer); 121 kfree(buffer);
122 122
123 return retval; 123 if (retval < 0)
124 return retval;
125
126 return 0;
124} 127}
125 128
126static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port) 129static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port)
@@ -306,7 +309,6 @@ static int opticon_tiocmset(struct tty_struct *tty,
306 unsigned int set, unsigned int clear) 309 unsigned int set, unsigned int clear)
307{ 310{
308 struct usb_serial_port *port = tty->driver_data; 311 struct usb_serial_port *port = tty->driver_data;
309 struct usb_serial *serial = port->serial;
310 struct opticon_private *priv = usb_get_serial_port_data(port); 312 struct opticon_private *priv = usb_get_serial_port_data(port);
311 unsigned long flags; 313 unsigned long flags;
312 bool rts; 314 bool rts;
@@ -327,15 +329,11 @@ static int opticon_tiocmset(struct tty_struct *tty,
327 if (!changed) 329 if (!changed)
328 return 0; 330 return 0;
329 331
330 /* Send the new RTS state to the connected device */ 332 ret = send_control_msg(port, CONTROL_RTS, !rts);
331 mutex_lock(&serial->disc_mutex); 333 if (ret)
332 if (!serial->disconnected) 334 return usb_translate_errors(ret);
333 ret = send_control_msg(port, CONTROL_RTS, !rts);
334 else
335 ret = -ENODEV;
336 mutex_unlock(&serial->disc_mutex);
337 335
338 return ret; 336 return 0;
339} 337}
340 338
341static int get_serial_info(struct usb_serial_port *port, 339static int get_serial_info(struct usb_serial_port *port,
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 09cd3967b8df..734372846abb 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -347,6 +347,7 @@ static void option_instat_callback(struct urb *urb);
347/* Olivetti products */ 347/* Olivetti products */
348#define OLIVETTI_VENDOR_ID 0x0b3c 348#define OLIVETTI_VENDOR_ID 0x0b3c
349#define OLIVETTI_PRODUCT_OLICARD100 0xc000 349#define OLIVETTI_PRODUCT_OLICARD100 0xc000
350#define OLIVETTI_PRODUCT_OLICARD145 0xc003
350 351
351/* Celot products */ 352/* Celot products */
352#define CELOT_VENDOR_ID 0x211f 353#define CELOT_VENDOR_ID 0x211f
@@ -1273,6 +1274,7 @@ static const struct usb_device_id option_ids[] = {
1273 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) }, 1274 { USB_DEVICE(SIEMENS_VENDOR_ID, CINTERION_PRODUCT_HC28_MDMNET) },
1274 1275
1275 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) }, 1276 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) },
1277 { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD145) },
1276 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */ 1278 { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */
1277 { USB_DEVICE(ONDA_VENDOR_ID, ONDA_MT825UP) }, /* ONDA MT825UP modem */ 1279 { USB_DEVICE(ONDA_VENDOR_ID, ONDA_MT825UP) }, /* ONDA MT825UP modem */
1278 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/ 1280 { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730 LTE USB modem.*/
@@ -1350,6 +1352,12 @@ static const struct usb_device_id option_ids[] = {
1350 { USB_DEVICE(TPLINK_VENDOR_ID, TPLINK_PRODUCT_MA180), 1352 { USB_DEVICE(TPLINK_VENDOR_ID, TPLINK_PRODUCT_MA180),
1351 .driver_info = (kernel_ulong_t)&net_intf4_blacklist }, 1353 .driver_info = (kernel_ulong_t)&net_intf4_blacklist },
1352 { USB_DEVICE(CHANGHONG_VENDOR_ID, CHANGHONG_PRODUCT_CH690) }, 1354 { USB_DEVICE(CHANGHONG_VENDOR_ID, CHANGHONG_PRODUCT_CH690) },
1355 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d01, 0xff, 0x02, 0x01) }, /* D-Link DWM-156 (variant) */
1356 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d01, 0xff, 0x00, 0x00) }, /* D-Link DWM-156 (variant) */
1357 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d02, 0xff, 0x02, 0x01) },
1358 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d02, 0xff, 0x00, 0x00) },
1359 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x02, 0x01) },
1360 { USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x7d03, 0xff, 0x00, 0x00) },
1353 { } /* Terminating entry */ 1361 { } /* Terminating entry */
1354}; 1362};
1355MODULE_DEVICE_TABLE(usb, option_ids); 1363MODULE_DEVICE_TABLE(usb, option_ids);
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 87c71ccfee87..7e3e0782e51f 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -124,8 +124,6 @@ static void oti6858_close(struct usb_serial_port *port);
124static void oti6858_set_termios(struct tty_struct *tty, 124static void oti6858_set_termios(struct tty_struct *tty,
125 struct usb_serial_port *port, struct ktermios *old); 125 struct usb_serial_port *port, struct ktermios *old);
126static void oti6858_init_termios(struct tty_struct *tty); 126static void oti6858_init_termios(struct tty_struct *tty);
127static int oti6858_ioctl(struct tty_struct *tty,
128 unsigned int cmd, unsigned long arg);
129static void oti6858_read_int_callback(struct urb *urb); 127static void oti6858_read_int_callback(struct urb *urb);
130static void oti6858_read_bulk_callback(struct urb *urb); 128static void oti6858_read_bulk_callback(struct urb *urb);
131static void oti6858_write_bulk_callback(struct urb *urb); 129static void oti6858_write_bulk_callback(struct urb *urb);
@@ -136,6 +134,7 @@ static int oti6858_chars_in_buffer(struct tty_struct *tty);
136static int oti6858_tiocmget(struct tty_struct *tty); 134static int oti6858_tiocmget(struct tty_struct *tty);
137static int oti6858_tiocmset(struct tty_struct *tty, 135static int oti6858_tiocmset(struct tty_struct *tty,
138 unsigned int set, unsigned int clear); 136 unsigned int set, unsigned int clear);
137static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg);
139static int oti6858_port_probe(struct usb_serial_port *port); 138static int oti6858_port_probe(struct usb_serial_port *port);
140static int oti6858_port_remove(struct usb_serial_port *port); 139static int oti6858_port_remove(struct usb_serial_port *port);
141 140
@@ -150,11 +149,11 @@ static struct usb_serial_driver oti6858_device = {
150 .open = oti6858_open, 149 .open = oti6858_open,
151 .close = oti6858_close, 150 .close = oti6858_close,
152 .write = oti6858_write, 151 .write = oti6858_write,
153 .ioctl = oti6858_ioctl,
154 .set_termios = oti6858_set_termios, 152 .set_termios = oti6858_set_termios,
155 .init_termios = oti6858_init_termios, 153 .init_termios = oti6858_init_termios,
156 .tiocmget = oti6858_tiocmget, 154 .tiocmget = oti6858_tiocmget,
157 .tiocmset = oti6858_tiocmset, 155 .tiocmset = oti6858_tiocmset,
156 .tiocmiwait = oti6858_tiocmiwait,
158 .read_bulk_callback = oti6858_read_bulk_callback, 157 .read_bulk_callback = oti6858_read_bulk_callback,
159 .read_int_callback = oti6858_read_int_callback, 158 .read_int_callback = oti6858_read_int_callback,
160 .write_bulk_callback = oti6858_write_bulk_callback, 159 .write_bulk_callback = oti6858_write_bulk_callback,
@@ -650,8 +649,9 @@ static int oti6858_tiocmget(struct tty_struct *tty)
650 return result; 649 return result;
651} 650}
652 651
653static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 652static int oti6858_tiocmiwait(struct tty_struct *tty, unsigned long arg)
654{ 653{
654 struct usb_serial_port *port = tty->driver_data;
655 struct oti6858_private *priv = usb_get_serial_port_data(port); 655 struct oti6858_private *priv = usb_get_serial_port_data(port);
656 unsigned long flags; 656 unsigned long flags;
657 unsigned int prev, status; 657 unsigned int prev, status;
@@ -662,7 +662,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
662 spin_unlock_irqrestore(&priv->lock, flags); 662 spin_unlock_irqrestore(&priv->lock, flags);
663 663
664 while (1) { 664 while (1) {
665 wait_event_interruptible(port->delta_msr_wait, 665 wait_event_interruptible(port->port.delta_msr_wait,
666 port->serial->disconnected || 666 port->serial->disconnected ||
667 priv->status.pin_state != prev); 667 priv->status.pin_state != prev);
668 if (signal_pending(current)) 668 if (signal_pending(current))
@@ -689,24 +689,6 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
689 return 0; 689 return 0;
690} 690}
691 691
692static int oti6858_ioctl(struct tty_struct *tty,
693 unsigned int cmd, unsigned long arg)
694{
695 struct usb_serial_port *port = tty->driver_data;
696
697 dev_dbg(&port->dev, "%s(cmd = 0x%04x, arg = 0x%08lx)\n", __func__, cmd, arg);
698
699 switch (cmd) {
700 case TIOCMIWAIT:
701 dev_dbg(&port->dev, "%s(): TIOCMIWAIT\n", __func__);
702 return wait_modem_info(port, arg);
703 default:
704 dev_dbg(&port->dev, "%s(): 0x%04x not supported\n", __func__, cmd);
705 break;
706 }
707 return -ENOIOCTLCMD;
708}
709
710static void oti6858_read_int_callback(struct urb *urb) 692static void oti6858_read_int_callback(struct urb *urb)
711{ 693{
712 struct usb_serial_port *port = urb->context; 694 struct usb_serial_port *port = urb->context;
@@ -765,7 +747,7 @@ static void oti6858_read_int_callback(struct urb *urb)
765 747
766 if (!priv->transient) { 748 if (!priv->transient) {
767 if (xs->pin_state != priv->status.pin_state) 749 if (xs->pin_state != priv->status.pin_state)
768 wake_up_interruptible(&port->delta_msr_wait); 750 wake_up_interruptible(&port->port.delta_msr_wait);
769 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE); 751 memcpy(&priv->status, xs, OTI6858_CTRL_PKT_SIZE);
770 } 752 }
771 753
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 3b10018d89a3..7151659367a0 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -149,7 +149,7 @@ static int pl2303_vendor_read(__u16 value, __u16 index,
149 int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 149 int res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
150 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, 150 VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE,
151 value, index, buf, 1, 100); 151 value, index, buf, 1, 100);
152 dev_dbg(&serial->dev->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n", 152 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d - %x\n",
153 VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index, 153 VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, value, index,
154 res, buf[0]); 154 res, buf[0]);
155 return res; 155 return res;
@@ -161,7 +161,7 @@ static int pl2303_vendor_write(__u16 value, __u16 index,
161 int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 161 int res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
162 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, 162 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
163 value, index, NULL, 0, 100); 163 value, index, NULL, 0, 100);
164 dev_dbg(&serial->dev->dev, "0x%x:0x%x:0x%x:0x%x %d\n", 164 dev_dbg(&serial->interface->dev, "0x%x:0x%x:0x%x:0x%x %d\n",
165 VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index, 165 VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, value, index,
166 res); 166 res);
167 return res; 167 return res;
@@ -248,14 +248,15 @@ static int pl2303_port_remove(struct usb_serial_port *port)
248 return 0; 248 return 0;
249} 249}
250 250
251static int set_control_lines(struct usb_device *dev, u8 value) 251static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
252{ 252{
253 struct usb_device *dev = port->serial->dev;
253 int retval; 254 int retval;
254 255
255 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 256 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
256 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE, 257 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
257 value, 0, NULL, 0, 100); 258 value, 0, NULL, 0, 100);
258 dev_dbg(&dev->dev, "%s - value = %d, retval = %d\n", __func__, 259 dev_dbg(&port->dev, "%s - value = %d, retval = %d\n", __func__,
259 value, retval); 260 value, retval);
260 return retval; 261 return retval;
261} 262}
@@ -437,7 +438,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
437 if (control != priv->line_control) { 438 if (control != priv->line_control) {
438 control = priv->line_control; 439 control = priv->line_control;
439 spin_unlock_irqrestore(&priv->lock, flags); 440 spin_unlock_irqrestore(&priv->lock, flags);
440 set_control_lines(serial->dev, control); 441 pl2303_set_control_lines(port, control);
441 } else { 442 } else {
442 spin_unlock_irqrestore(&priv->lock, flags); 443 spin_unlock_irqrestore(&priv->lock, flags);
443 } 444 }
@@ -480,7 +481,7 @@ static void pl2303_dtr_rts(struct usb_serial_port *port, int on)
480 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS); 481 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
481 control = priv->line_control; 482 control = priv->line_control;
482 spin_unlock_irqrestore(&priv->lock, flags); 483 spin_unlock_irqrestore(&priv->lock, flags);
483 set_control_lines(port->serial->dev, control); 484 pl2303_set_control_lines(port, control);
484} 485}
485 486
486static void pl2303_close(struct usb_serial_port *port) 487static void pl2303_close(struct usb_serial_port *port)
@@ -530,7 +531,6 @@ static int pl2303_tiocmset(struct tty_struct *tty,
530 unsigned int set, unsigned int clear) 531 unsigned int set, unsigned int clear)
531{ 532{
532 struct usb_serial_port *port = tty->driver_data; 533 struct usb_serial_port *port = tty->driver_data;
533 struct usb_serial *serial = port->serial;
534 struct pl2303_private *priv = usb_get_serial_port_data(port); 534 struct pl2303_private *priv = usb_get_serial_port_data(port);
535 unsigned long flags; 535 unsigned long flags;
536 u8 control; 536 u8 control;
@@ -548,14 +548,11 @@ static int pl2303_tiocmset(struct tty_struct *tty,
548 control = priv->line_control; 548 control = priv->line_control;
549 spin_unlock_irqrestore(&priv->lock, flags); 549 spin_unlock_irqrestore(&priv->lock, flags);
550 550
551 mutex_lock(&serial->disc_mutex); 551 ret = pl2303_set_control_lines(port, control);
552 if (!serial->disconnected) 552 if (ret)
553 ret = set_control_lines(serial->dev, control); 553 return usb_translate_errors(ret);
554 else
555 ret = -ENODEV;
556 mutex_unlock(&serial->disc_mutex);
557 554
558 return ret; 555 return 0;
559} 556}
560 557
561static int pl2303_tiocmget(struct tty_struct *tty) 558static int pl2303_tiocmget(struct tty_struct *tty)
@@ -592,8 +589,9 @@ static int pl2303_carrier_raised(struct usb_serial_port *port)
592 return 0; 589 return 0;
593} 590}
594 591
595static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 592static int pl2303_tiocmiwait(struct tty_struct *tty, unsigned long arg)
596{ 593{
594 struct usb_serial_port *port = tty->driver_data;
597 struct pl2303_private *priv = usb_get_serial_port_data(port); 595 struct pl2303_private *priv = usb_get_serial_port_data(port);
598 unsigned long flags; 596 unsigned long flags;
599 unsigned int prevstatus; 597 unsigned int prevstatus;
@@ -605,7 +603,7 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
605 spin_unlock_irqrestore(&priv->lock, flags); 603 spin_unlock_irqrestore(&priv->lock, flags);
606 604
607 while (1) { 605 while (1) {
608 interruptible_sleep_on(&port->delta_msr_wait); 606 interruptible_sleep_on(&port->port.delta_msr_wait);
609 /* see if a signal did it */ 607 /* see if a signal did it */
610 if (signal_pending(current)) 608 if (signal_pending(current))
611 return -ERESTARTSYS; 609 return -ERESTARTSYS;
@@ -651,10 +649,6 @@ static int pl2303_ioctl(struct tty_struct *tty,
651 return -EFAULT; 649 return -EFAULT;
652 650
653 return 0; 651 return 0;
654
655 case TIOCMIWAIT:
656 dev_dbg(&port->dev, "%s TIOCMIWAIT\n", __func__);
657 return wait_modem_info(port, arg);
658 default: 652 default:
659 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd); 653 dev_dbg(&port->dev, "%s not supported = 0x%04x\n", __func__, cmd);
660 break; 654 break;
@@ -720,7 +714,7 @@ static void pl2303_update_line_status(struct usb_serial_port *port,
720 spin_unlock_irqrestore(&priv->lock, flags); 714 spin_unlock_irqrestore(&priv->lock, flags);
721 if (priv->line_status & UART_BREAK_ERROR) 715 if (priv->line_status & UART_BREAK_ERROR)
722 usb_serial_handle_break(port); 716 usb_serial_handle_break(port);
723 wake_up_interruptible(&port->delta_msr_wait); 717 wake_up_interruptible(&port->port.delta_msr_wait);
724 718
725 tty = tty_port_tty_get(&port->port); 719 tty = tty_port_tty_get(&port->port);
726 if (!tty) 720 if (!tty)
@@ -784,7 +778,7 @@ static void pl2303_process_read_urb(struct urb *urb)
784 line_status = priv->line_status; 778 line_status = priv->line_status;
785 priv->line_status &= ~UART_STATE_TRANSIENT_MASK; 779 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
786 spin_unlock_irqrestore(&priv->lock, flags); 780 spin_unlock_irqrestore(&priv->lock, flags);
787 wake_up_interruptible(&port->delta_msr_wait); 781 wake_up_interruptible(&port->port.delta_msr_wait);
788 782
789 if (!urb->actual_length) 783 if (!urb->actual_length)
790 return; 784 return;
@@ -835,6 +829,7 @@ static struct usb_serial_driver pl2303_device = {
835 .set_termios = pl2303_set_termios, 829 .set_termios = pl2303_set_termios,
836 .tiocmget = pl2303_tiocmget, 830 .tiocmget = pl2303_tiocmget,
837 .tiocmset = pl2303_tiocmset, 831 .tiocmset = pl2303_tiocmset,
832 .tiocmiwait = pl2303_tiocmiwait,
838 .process_read_urb = pl2303_process_read_urb, 833 .process_read_urb = pl2303_process_read_urb,
839 .read_int_callback = pl2303_read_int_callback, 834 .read_int_callback = pl2303_read_int_callback,
840 .attach = pl2303_startup, 835 .attach = pl2303_startup,
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index ef3a7d5eaab4..02b0803425c5 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -127,8 +127,6 @@ struct qt2_port_private {
127 u8 shadowLSR; 127 u8 shadowLSR;
128 u8 shadowMSR; 128 u8 shadowMSR;
129 129
130 struct async_icount icount;
131
132 struct usb_serial_port *port; 130 struct usb_serial_port *port;
133}; 131};
134 132
@@ -420,12 +418,6 @@ static void qt2_close(struct usb_serial_port *port)
420 port_priv->urb_in_use = false; 418 port_priv->urb_in_use = false;
421 spin_unlock_irqrestore(&port_priv->urb_lock, flags); 419 spin_unlock_irqrestore(&port_priv->urb_lock, flags);
422 420
423 mutex_lock(&port->serial->disc_mutex);
424 if (port->serial->disconnected) {
425 mutex_unlock(&port->serial->disc_mutex);
426 return;
427 }
428
429 /* flush the port transmit buffer */ 421 /* flush the port transmit buffer */
430 i = usb_control_msg(serial->dev, 422 i = usb_control_msg(serial->dev,
431 usb_rcvctrlpipe(serial->dev, 0), 423 usb_rcvctrlpipe(serial->dev, 0),
@@ -456,8 +448,6 @@ static void qt2_close(struct usb_serial_port *port)
456 if (i < 0) 448 if (i < 0)
457 dev_err(&port->dev, "%s - close port failed %i\n", 449 dev_err(&port->dev, "%s - close port failed %i\n",
458 __func__, i); 450 __func__, i);
459
460 mutex_unlock(&port->serial->disc_mutex);
461} 451}
462 452
463static void qt2_disconnect(struct usb_serial *serial) 453static void qt2_disconnect(struct usb_serial *serial)
@@ -490,71 +480,6 @@ static int get_serial_info(struct usb_serial_port *port,
490 return 0; 480 return 0;
491} 481}
492 482
493static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
494{
495 struct qt2_port_private *priv = usb_get_serial_port_data(port);
496 struct async_icount prev, cur;
497 unsigned long flags;
498
499 spin_lock_irqsave(&priv->lock, flags);
500 prev = priv->icount;
501 spin_unlock_irqrestore(&priv->lock, flags);
502
503 while (1) {
504 wait_event_interruptible(port->delta_msr_wait,
505 (port->serial->disconnected ||
506 (priv->icount.rng != prev.rng) ||
507 (priv->icount.dsr != prev.dsr) ||
508 (priv->icount.dcd != prev.dcd) ||
509 (priv->icount.cts != prev.cts)));
510
511 if (signal_pending(current))
512 return -ERESTARTSYS;
513
514 if (port->serial->disconnected)
515 return -EIO;
516
517 spin_lock_irqsave(&priv->lock, flags);
518 cur = priv->icount;
519 spin_unlock_irqrestore(&priv->lock, flags);
520
521 if ((prev.rng == cur.rng) &&
522 (prev.dsr == cur.dsr) &&
523 (prev.dcd == cur.dcd) &&
524 (prev.cts == cur.cts))
525 return -EIO;
526
527 if ((arg & TIOCM_RNG && (prev.rng != cur.rng)) ||
528 (arg & TIOCM_DSR && (prev.dsr != cur.dsr)) ||
529 (arg & TIOCM_CD && (prev.dcd != cur.dcd)) ||
530 (arg & TIOCM_CTS && (prev.cts != cur.cts)))
531 return 0;
532 }
533 return 0;
534}
535
536static int qt2_get_icount(struct tty_struct *tty,
537 struct serial_icounter_struct *icount)
538{
539 struct usb_serial_port *port = tty->driver_data;
540 struct qt2_port_private *priv = usb_get_serial_port_data(port);
541 struct async_icount cnow = priv->icount;
542
543 icount->cts = cnow.cts;
544 icount->dsr = cnow.dsr;
545 icount->rng = cnow.rng;
546 icount->dcd = cnow.dcd;
547 icount->rx = cnow.rx;
548 icount->tx = cnow.tx;
549 icount->frame = cnow.frame;
550 icount->overrun = cnow.overrun;
551 icount->parity = cnow.parity;
552 icount->brk = cnow.brk;
553 icount->buf_overrun = cnow.buf_overrun;
554
555 return 0;
556}
557
558static int qt2_ioctl(struct tty_struct *tty, 483static int qt2_ioctl(struct tty_struct *tty,
559 unsigned int cmd, unsigned long arg) 484 unsigned int cmd, unsigned long arg)
560{ 485{
@@ -564,10 +489,6 @@ static int qt2_ioctl(struct tty_struct *tty,
564 case TIOCGSERIAL: 489 case TIOCGSERIAL:
565 return get_serial_info(port, 490 return get_serial_info(port,
566 (struct serial_struct __user *)arg); 491 (struct serial_struct __user *)arg);
567
568 case TIOCMIWAIT:
569 return wait_modem_info(port, arg);
570
571 default: 492 default:
572 break; 493 break;
573 } 494 }
@@ -948,18 +869,15 @@ static void qt2_update_msr(struct usb_serial_port *port, unsigned char *ch)
948 if (newMSR & UART_MSR_ANY_DELTA) { 869 if (newMSR & UART_MSR_ANY_DELTA) {
949 /* update input line counters */ 870 /* update input line counters */
950 if (newMSR & UART_MSR_DCTS) 871 if (newMSR & UART_MSR_DCTS)
951 port_priv->icount.cts++; 872 port->icount.cts++;
952
953 if (newMSR & UART_MSR_DDSR) 873 if (newMSR & UART_MSR_DDSR)
954 port_priv->icount.dsr++; 874 port->icount.dsr++;
955
956 if (newMSR & UART_MSR_DDCD) 875 if (newMSR & UART_MSR_DDCD)
957 port_priv->icount.dcd++; 876 port->icount.dcd++;
958
959 if (newMSR & UART_MSR_TERI) 877 if (newMSR & UART_MSR_TERI)
960 port_priv->icount.rng++; 878 port->icount.rng++;
961 879
962 wake_up_interruptible(&port->delta_msr_wait); 880 wake_up_interruptible(&port->port.delta_msr_wait);
963 } 881 }
964} 882}
965 883
@@ -979,7 +897,7 @@ static void qt2_update_lsr(struct usb_serial_port *port, unsigned char *ch)
979 port_priv->shadowLSR = newLSR; 897 port_priv->shadowLSR = newLSR;
980 spin_unlock_irqrestore(&port_priv->lock, flags); 898 spin_unlock_irqrestore(&port_priv->lock, flags);
981 899
982 icount = &port_priv->icount; 900 icount = &port->icount;
983 901
984 if (newLSR & UART_LSR_BRK_ERROR_BITS) { 902 if (newLSR & UART_LSR_BRK_ERROR_BITS) {
985 903
@@ -1089,7 +1007,8 @@ static struct usb_serial_driver qt2_device = {
1089 .break_ctl = qt2_break_ctl, 1007 .break_ctl = qt2_break_ctl,
1090 .tiocmget = qt2_tiocmget, 1008 .tiocmget = qt2_tiocmget,
1091 .tiocmset = qt2_tiocmset, 1009 .tiocmset = qt2_tiocmset,
1092 .get_icount = qt2_get_icount, 1010 .tiocmiwait = usb_serial_generic_tiocmiwait,
1011 .get_icount = usb_serial_generic_get_icount,
1093 .ioctl = qt2_ioctl, 1012 .ioctl = qt2_ioctl,
1094 .set_termios = qt2_set_termios, 1013 .set_termios = qt2_set_termios,
1095}; 1014};
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index d66148a17fe3..8894665cd610 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -774,30 +774,25 @@ static void sierra_close(struct usb_serial_port *port)
774 portdata->rts_state = 0; 774 portdata->rts_state = 0;
775 portdata->dtr_state = 0; 775 portdata->dtr_state = 0;
776 776
777 if (serial->dev) { 777 mutex_lock(&serial->disc_mutex);
778 mutex_lock(&serial->disc_mutex); 778 if (!serial->disconnected) {
779 if (!serial->disconnected) { 779 serial->interface->needs_remote_wakeup = 0;
780 serial->interface->needs_remote_wakeup = 0; 780 /* odd error handling due to pm counters */
781 /* odd error handling due to pm counters */ 781 if (!usb_autopm_get_interface(serial->interface))
782 if (!usb_autopm_get_interface(serial->interface)) 782 sierra_send_setup(port);
783 sierra_send_setup(port); 783 else
784 else 784 usb_autopm_get_interface_no_resume(serial->interface);
785 usb_autopm_get_interface_no_resume(serial->interface);
786
787 }
788 mutex_unlock(&serial->disc_mutex);
789 spin_lock_irq(&intfdata->susp_lock);
790 portdata->opened = 0;
791 spin_unlock_irq(&intfdata->susp_lock);
792 785
786 }
787 mutex_unlock(&serial->disc_mutex);
788 spin_lock_irq(&intfdata->susp_lock);
789 portdata->opened = 0;
790 spin_unlock_irq(&intfdata->susp_lock);
793 791
794 /* Stop reading urbs */ 792 sierra_stop_rx_urbs(port);
795 sierra_stop_rx_urbs(port); 793 for (i = 0; i < portdata->num_in_urbs; i++) {
796 /* .. and release them */ 794 sierra_release_urb(portdata->in_urbs[i]);
797 for (i = 0; i < portdata->num_in_urbs; i++) { 795 portdata->in_urbs[i] = NULL;
798 sierra_release_urb(portdata->in_urbs[i]);
799 portdata->in_urbs[i] = NULL;
800 }
801 } 796 }
802} 797}
803 798
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 549ef68ff5fa..cf3df793c2b7 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * spcp8x5 USB to serial adaptor driver 2 * spcp8x5 USB to serial adaptor driver
3 * 3 *
4 * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com) 4 * Copyright (C) 2010-2013 Johan Hovold (jhovold@gmail.com)
5 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn) 5 * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn)
6 * Copyright (C) 2006 S1 Corp. 6 * Copyright (C) 2006 S1 Corp.
7 * 7 *
@@ -13,8 +13,6 @@
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. 15 * (at your option) any later version.
16 *
17 *
18 */ 16 */
19#include <linux/kernel.h> 17#include <linux/kernel.h>
20#include <linux/errno.h> 18#include <linux/errno.h>
@@ -28,7 +26,10 @@
28#include <linux/usb.h> 26#include <linux/usb.h>
29#include <linux/usb/serial.h> 27#include <linux/usb/serial.h>
30 28
31#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver" 29#define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
30
31#define SPCP825_QUIRK_NO_UART_STATUS 0x01
32#define SPCP825_QUIRK_NO_WORK_MODE 0x02
32 33
33#define SPCP8x5_007_VID 0x04FC 34#define SPCP8x5_007_VID 0x04FC
34#define SPCP8x5_007_PID 0x0201 35#define SPCP8x5_007_PID 0x0201
@@ -46,13 +47,15 @@ static const struct usb_device_id id_table[] = {
46 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)}, 47 { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)},
47 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)}, 48 { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)},
48 { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)}, 49 { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)},
49 { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID)}, 50 { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID),
51 .driver_info = SPCP825_QUIRK_NO_UART_STATUS |
52 SPCP825_QUIRK_NO_WORK_MODE },
50 { } /* Terminating entry */ 53 { } /* Terminating entry */
51}; 54};
52MODULE_DEVICE_TABLE(usb, id_table); 55MODULE_DEVICE_TABLE(usb, id_table);
53 56
54struct spcp8x5_usb_ctrl_arg { 57struct spcp8x5_usb_ctrl_arg {
55 u8 type; 58 u8 type;
56 u8 cmd; 59 u8 cmd;
57 u8 cmd_type; 60 u8 cmd_type;
58 u16 value; 61 u16 value;
@@ -138,49 +141,33 @@ struct spcp8x5_usb_ctrl_arg {
138#define UART_OVERRUN_ERROR 0x40 141#define UART_OVERRUN_ERROR 0x40
139#define UART_CTS 0x80 142#define UART_CTS 0x80
140 143
141enum spcp8x5_type {
142 SPCP825_007_TYPE,
143 SPCP825_008_TYPE,
144 SPCP825_PHILIP_TYPE,
145 SPCP825_INTERMATIC_TYPE,
146 SPCP835_TYPE,
147};
148
149struct spcp8x5_private { 144struct spcp8x5_private {
150 spinlock_t lock; 145 unsigned quirks;
151 enum spcp8x5_type type; 146 spinlock_t lock;
152 u8 line_control; 147 u8 line_control;
153 u8 line_status;
154}; 148};
155 149
150static int spcp8x5_probe(struct usb_serial *serial,
151 const struct usb_device_id *id)
152{
153 usb_set_serial_data(serial, (void *)id);
154
155 return 0;
156}
157
156static int spcp8x5_port_probe(struct usb_serial_port *port) 158static int spcp8x5_port_probe(struct usb_serial_port *port)
157{ 159{
158 struct usb_serial *serial = port->serial; 160 const struct usb_device_id *id = usb_get_serial_data(port->serial);
159 struct spcp8x5_private *priv; 161 struct spcp8x5_private *priv;
160 enum spcp8x5_type type = SPCP825_007_TYPE;
161 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
162
163 if (product == 0x0201)
164 type = SPCP825_007_TYPE;
165 else if (product == 0x0231)
166 type = SPCP835_TYPE;
167 else if (product == 0x0235)
168 type = SPCP825_008_TYPE;
169 else if (product == 0x0204)
170 type = SPCP825_INTERMATIC_TYPE;
171 else if (product == 0x0471 &&
172 serial->dev->descriptor.idVendor == cpu_to_le16(0x081e))
173 type = SPCP825_PHILIP_TYPE;
174 dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
175 162
176 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 163 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
177 if (!priv) 164 if (!priv)
178 return -ENOMEM; 165 return -ENOMEM;
179 166
180 spin_lock_init(&priv->lock); 167 spin_lock_init(&priv->lock);
181 priv->type = type; 168 priv->quirks = id->driver_info;
182 169
183 usb_set_serial_port_data(port , priv); 170 usb_set_serial_port_data(port, priv);
184 171
185 return 0; 172 return 0;
186} 173}
@@ -195,86 +182,79 @@ static int spcp8x5_port_remove(struct usb_serial_port *port)
195 return 0; 182 return 0;
196} 183}
197 184
198/* set the modem control line of the device. 185static int spcp8x5_set_ctrl_line(struct usb_serial_port *port, u8 mcr)
199 * NOTE spcp825-007 not supported this */
200static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
201 enum spcp8x5_type type)
202{ 186{
187 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
188 struct usb_device *dev = port->serial->dev;
203 int retval; 189 int retval;
204 u8 mcr = 0 ;
205 190
206 if (type == SPCP825_007_TYPE) 191 if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
207 return -EPERM; 192 return -EPERM;
208 193
209 mcr = (unsigned short)value;
210 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 194 retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
211 SET_UART_STATUS_TYPE, SET_UART_STATUS, 195 SET_UART_STATUS_TYPE, SET_UART_STATUS,
212 mcr, 0x04, NULL, 0, 100); 196 mcr, 0x04, NULL, 0, 100);
213 if (retval != 0) 197 if (retval != 0) {
214 dev_dbg(&dev->dev, "usb_control_msg return %#x\n", retval); 198 dev_err(&port->dev, "failed to set control lines: %d\n",
199 retval);
200 }
215 return retval; 201 return retval;
216} 202}
217 203
218/* get the modem status register of the device 204static int spcp8x5_get_msr(struct usb_serial_port *port, u8 *status)
219 * NOTE spcp825-007 not supported this */
220static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
221 enum spcp8x5_type type)
222{ 205{
223 u8 *status_buffer; 206 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
207 struct usb_device *dev = port->serial->dev;
208 u8 *buf;
224 int ret; 209 int ret;
225 210
226 /* I return Permited not support here but seem inval device 211 if (priv->quirks & SPCP825_QUIRK_NO_UART_STATUS)
227 * is more fix */
228 if (type == SPCP825_007_TYPE)
229 return -EPERM; 212 return -EPERM;
230 if (status == NULL)
231 return -EINVAL;
232 213
233 status_buffer = kmalloc(1, GFP_KERNEL); 214 buf = kzalloc(1, GFP_KERNEL);
234 if (!status_buffer) 215 if (!buf)
235 return -ENOMEM; 216 return -ENOMEM;
236 status_buffer[0] = status[0];
237 217
238 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 218 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
239 GET_UART_STATUS, GET_UART_STATUS_TYPE, 219 GET_UART_STATUS, GET_UART_STATUS_TYPE,
240 0, GET_UART_STATUS_MSR, status_buffer, 1, 100); 220 0, GET_UART_STATUS_MSR, buf, 1, 100);
241 if (ret < 0) 221 if (ret < 0)
242 dev_dbg(&dev->dev, "Get MSR = 0x%p failed (error = %d)", 222 dev_err(&port->dev, "failed to get modem status: %d", ret);
243 status_buffer, ret);
244 223
245 dev_dbg(&dev->dev, "0xc0:0x22:0:6 %d - 0x%p ", ret, status_buffer); 224 dev_dbg(&port->dev, "0xc0:0x22:0:6 %d - 0x02%x", ret, *buf);
246 status[0] = status_buffer[0]; 225 *status = *buf;
247 kfree(status_buffer); 226 kfree(buf);
248 227
249 return ret; 228 return ret;
250} 229}
251 230
252/* select the work mode. 231static void spcp8x5_set_work_mode(struct usb_serial_port *port, u16 value,
253 * NOTE this function not supported by spcp825-007 */ 232 u16 index)
254static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
255 u16 index, enum spcp8x5_type type)
256{ 233{
234 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
235 struct usb_device *dev = port->serial->dev;
257 int ret; 236 int ret;
258 237
259 /* I return Permited not support here but seem inval device 238 if (priv->quirks & SPCP825_QUIRK_NO_WORK_MODE)
260 * is more fix */
261 if (type == SPCP825_007_TYPE)
262 return; 239 return;
263 240
264 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 241 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
265 SET_WORKING_MODE_TYPE, SET_WORKING_MODE, 242 SET_WORKING_MODE_TYPE, SET_WORKING_MODE,
266 value, index, NULL, 0, 100); 243 value, index, NULL, 0, 100);
267 dev_dbg(&dev->dev, "value = %#x , index = %#x\n", value, index); 244 dev_dbg(&port->dev, "value = %#x , index = %#x\n", value, index);
268 if (ret < 0) 245 if (ret < 0)
269 dev_dbg(&dev->dev, 246 dev_err(&port->dev, "failed to set work mode: %d\n", ret);
270 "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
271} 247}
272 248
273static int spcp8x5_carrier_raised(struct usb_serial_port *port) 249static int spcp8x5_carrier_raised(struct usb_serial_port *port)
274{ 250{
275 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 251 u8 msr;
276 if (priv->line_status & MSR_STATUS_LINE_DCD) 252 int ret;
253
254 ret = spcp8x5_get_msr(port, &msr);
255 if (ret || msr & MSR_STATUS_LINE_DCD)
277 return 1; 256 return 1;
257
278 return 0; 258 return 0;
279} 259}
280 260
@@ -293,20 +273,17 @@ static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
293 | MCR_CONTROL_LINE_RTS); 273 | MCR_CONTROL_LINE_RTS);
294 control = priv->line_control; 274 control = priv->line_control;
295 spin_unlock_irqrestore(&priv->lock, flags); 275 spin_unlock_irqrestore(&priv->lock, flags);
296 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 276 spcp8x5_set_ctrl_line(port, control);
297} 277}
298 278
299static void spcp8x5_init_termios(struct tty_struct *tty) 279static void spcp8x5_init_termios(struct tty_struct *tty)
300{ 280{
301 /* for the 1st time call this function */
302 tty->termios = tty_std_termios; 281 tty->termios = tty_std_termios;
303 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL; 282 tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
304 tty->termios.c_ispeed = 115200; 283 tty->termios.c_ispeed = 115200;
305 tty->termios.c_ospeed = 115200; 284 tty->termios.c_ospeed = 115200;
306} 285}
307 286
308/* set the serial param for transfer. we should check if we really need to
309 * transfer. if we set flow control we should do this too. */
310static void spcp8x5_set_termios(struct tty_struct *tty, 287static void spcp8x5_set_termios(struct tty_struct *tty,
311 struct usb_serial_port *port, struct ktermios *old_termios) 288 struct usb_serial_port *port, struct ktermios *old_termios)
312{ 289{
@@ -321,7 +298,6 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
321 int i; 298 int i;
322 u8 control; 299 u8 control;
323 300
324
325 /* check that they really want us to change something */ 301 /* check that they really want us to change something */
326 if (!tty_termios_hw_change(&tty->termios, old_termios)) 302 if (!tty_termios_hw_change(&tty->termios, old_termios))
327 return; 303 return;
@@ -337,7 +313,7 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
337 if (control != priv->line_control) { 313 if (control != priv->line_control) {
338 control = priv->line_control; 314 control = priv->line_control;
339 spin_unlock_irqrestore(&priv->lock, flags); 315 spin_unlock_irqrestore(&priv->lock, flags);
340 spcp8x5_set_ctrlLine(serial->dev, control , priv->type); 316 spcp8x5_set_ctrl_line(port, control);
341 } else { 317 } else {
342 spin_unlock_irqrestore(&priv->lock, flags); 318 spin_unlock_irqrestore(&priv->lock, flags);
343 } 319 }
@@ -397,9 +373,9 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
397 if (cflag & PARENB) { 373 if (cflag & PARENB) {
398 buf[1] |= (cflag & PARODD) ? 374 buf[1] |= (cflag & PARODD) ?
399 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ; 375 SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
400 } else 376 } else {
401 buf[1] |= SET_UART_FORMAT_PAR_NONE; 377 buf[1] |= SET_UART_FORMAT_PAR_NONE;
402 378 }
403 uartdata = buf[0] | buf[1]<<8; 379 uartdata = buf[0] | buf[1]<<8;
404 380
405 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 381 i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
@@ -412,22 +388,16 @@ static void spcp8x5_set_termios(struct tty_struct *tty,
412 388
413 if (cflag & CRTSCTS) { 389 if (cflag & CRTSCTS) {
414 /* enable hardware flow control */ 390 /* enable hardware flow control */
415 spcp8x5_set_workMode(serial->dev, 0x000a, 391 spcp8x5_set_work_mode(port, 0x000a, SET_WORKING_MODE_U2C);
416 SET_WORKING_MODE_U2C, priv->type);
417 } 392 }
418} 393}
419 394
420/* open the serial port. do some usb system call. set termios and get the line
421 * status of the device. */
422static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port) 395static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
423{ 396{
424 struct ktermios tmp_termios; 397 struct ktermios tmp_termios;
425 struct usb_serial *serial = port->serial; 398 struct usb_serial *serial = port->serial;
426 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 399 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
427 int ret; 400 int ret;
428 unsigned long flags;
429 u8 status = 0x30;
430 /* status 0x30 means DSR and CTS = 1 other CDC RI and delta = 0 */
431 401
432 usb_clear_halt(serial->dev, port->write_urb->pipe); 402 usb_clear_halt(serial->dev, port->write_urb->pipe);
433 usb_clear_halt(serial->dev, port->read_urb->pipe); 403 usb_clear_halt(serial->dev, port->read_urb->pipe);
@@ -438,142 +408,16 @@ static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
438 if (ret) 408 if (ret)
439 return ret; 409 return ret;
440 410
441 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 411 spcp8x5_set_ctrl_line(port, priv->line_control);
442 412
443 /* Setup termios */
444 if (tty) 413 if (tty)
445 spcp8x5_set_termios(tty, port, &tmp_termios); 414 spcp8x5_set_termios(tty, port, &tmp_termios);
446 415
447 spcp8x5_get_msr(serial->dev, &status, priv->type);
448
449 /* may be we should update uart status here but now we did not do */
450 spin_lock_irqsave(&priv->lock, flags);
451 priv->line_status = status & 0xf0 ;
452 spin_unlock_irqrestore(&priv->lock, flags);
453
454 port->port.drain_delay = 256; 416 port->port.drain_delay = 256;
455 417
456 return usb_serial_generic_open(tty, port); 418 return usb_serial_generic_open(tty, port);
457} 419}
458 420
459static void spcp8x5_process_read_urb(struct urb *urb)
460{
461 struct usb_serial_port *port = urb->context;
462 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
463 unsigned char *data = urb->transfer_buffer;
464 unsigned long flags;
465 u8 status;
466 char tty_flag;
467
468 /* get tty_flag from status */
469 tty_flag = TTY_NORMAL;
470
471 spin_lock_irqsave(&priv->lock, flags);
472 status = priv->line_status;
473 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
474 spin_unlock_irqrestore(&priv->lock, flags);
475 /* wake up the wait for termios */
476 wake_up_interruptible(&port->delta_msr_wait);
477
478 if (!urb->actual_length)
479 return;
480
481
482 if (status & UART_STATE_TRANSIENT_MASK) {
483 /* break takes precedence over parity, which takes precedence
484 * over framing errors */
485 if (status & UART_BREAK_ERROR)
486 tty_flag = TTY_BREAK;
487 else if (status & UART_PARITY_ERROR)
488 tty_flag = TTY_PARITY;
489 else if (status & UART_FRAME_ERROR)
490 tty_flag = TTY_FRAME;
491 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
492
493 /* overrun is special, not associated with a char */
494 if (status & UART_OVERRUN_ERROR)
495 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
496
497 if (status & UART_DCD) {
498 struct tty_struct *tty = tty_port_tty_get(&port->port);
499 if (tty) {
500 usb_serial_handle_dcd_change(port, tty,
501 priv->line_status & MSR_STATUS_LINE_DCD);
502 tty_kref_put(tty);
503 }
504 }
505 }
506
507 tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag,
508 urb->actual_length);
509 tty_flip_buffer_push(&port->port);
510}
511
512static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
513 unsigned int arg)
514{
515 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
516 unsigned long flags;
517 unsigned int prevstatus;
518 unsigned int status;
519 unsigned int changed;
520
521 spin_lock_irqsave(&priv->lock, flags);
522 prevstatus = priv->line_status;
523 spin_unlock_irqrestore(&priv->lock, flags);
524
525 while (1) {
526 /* wake up in bulk read */
527 interruptible_sleep_on(&port->delta_msr_wait);
528
529 /* see if a signal did it */
530 if (signal_pending(current))
531 return -ERESTARTSYS;
532
533 if (port->serial->disconnected)
534 return -EIO;
535
536 spin_lock_irqsave(&priv->lock, flags);
537 status = priv->line_status;
538 spin_unlock_irqrestore(&priv->lock, flags);
539
540 changed = prevstatus^status;
541
542 if (((arg & TIOCM_RNG) && (changed & MSR_STATUS_LINE_RI)) ||
543 ((arg & TIOCM_DSR) && (changed & MSR_STATUS_LINE_DSR)) ||
544 ((arg & TIOCM_CD) && (changed & MSR_STATUS_LINE_DCD)) ||
545 ((arg & TIOCM_CTS) && (changed & MSR_STATUS_LINE_CTS)))
546 return 0;
547
548 prevstatus = status;
549 }
550 /* NOTREACHED */
551 return 0;
552}
553
554static int spcp8x5_ioctl(struct tty_struct *tty,
555 unsigned int cmd, unsigned long arg)
556{
557 struct usb_serial_port *port = tty->driver_data;
558
559 dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__,
560 port->number, cmd);
561
562 switch (cmd) {
563 case TIOCMIWAIT:
564 dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
565 port->number);
566 return spcp8x5_wait_modem_info(port, arg);
567
568 default:
569 dev_dbg(&port->dev, "%s not supported = 0x%04x", __func__,
570 cmd);
571 break;
572 }
573
574 return -ENOIOCTLCMD;
575}
576
577static int spcp8x5_tiocmset(struct tty_struct *tty, 421static int spcp8x5_tiocmset(struct tty_struct *tty,
578 unsigned int set, unsigned int clear) 422 unsigned int set, unsigned int clear)
579{ 423{
@@ -594,7 +438,7 @@ static int spcp8x5_tiocmset(struct tty_struct *tty,
594 control = priv->line_control; 438 control = priv->line_control;
595 spin_unlock_irqrestore(&priv->lock, flags); 439 spin_unlock_irqrestore(&priv->lock, flags);
596 440
597 return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type); 441 return spcp8x5_set_ctrl_line(port, control);
598} 442}
599 443
600static int spcp8x5_tiocmget(struct tty_struct *tty) 444static int spcp8x5_tiocmget(struct tty_struct *tty)
@@ -603,12 +447,15 @@ static int spcp8x5_tiocmget(struct tty_struct *tty)
603 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 447 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
604 unsigned long flags; 448 unsigned long flags;
605 unsigned int mcr; 449 unsigned int mcr;
606 unsigned int status; 450 u8 status;
607 unsigned int result; 451 unsigned int result;
608 452
453 result = spcp8x5_get_msr(port, &status);
454 if (result)
455 return result;
456
609 spin_lock_irqsave(&priv->lock, flags); 457 spin_lock_irqsave(&priv->lock, flags);
610 mcr = priv->line_control; 458 mcr = priv->line_control;
611 status = priv->line_status;
612 spin_unlock_irqrestore(&priv->lock, flags); 459 spin_unlock_irqrestore(&priv->lock, flags);
613 460
614 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) 461 result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
@@ -621,7 +468,6 @@ static int spcp8x5_tiocmget(struct tty_struct *tty)
621 return result; 468 return result;
622} 469}
623 470
624/* All of the device info needed for the spcp8x5 SIO serial converter */
625static struct usb_serial_driver spcp8x5_device = { 471static struct usb_serial_driver spcp8x5_device = {
626 .driver = { 472 .driver = {
627 .owner = THIS_MODULE, 473 .owner = THIS_MODULE,
@@ -629,17 +475,16 @@ static struct usb_serial_driver spcp8x5_device = {
629 }, 475 },
630 .id_table = id_table, 476 .id_table = id_table,
631 .num_ports = 1, 477 .num_ports = 1,
632 .open = spcp8x5_open, 478 .open = spcp8x5_open,
633 .dtr_rts = spcp8x5_dtr_rts, 479 .dtr_rts = spcp8x5_dtr_rts,
634 .carrier_raised = spcp8x5_carrier_raised, 480 .carrier_raised = spcp8x5_carrier_raised,
635 .set_termios = spcp8x5_set_termios, 481 .set_termios = spcp8x5_set_termios,
636 .init_termios = spcp8x5_init_termios, 482 .init_termios = spcp8x5_init_termios,
637 .ioctl = spcp8x5_ioctl, 483 .tiocmget = spcp8x5_tiocmget,
638 .tiocmget = spcp8x5_tiocmget, 484 .tiocmset = spcp8x5_tiocmset,
639 .tiocmset = spcp8x5_tiocmset, 485 .probe = spcp8x5_probe,
640 .port_probe = spcp8x5_port_probe, 486 .port_probe = spcp8x5_port_probe,
641 .port_remove = spcp8x5_port_remove, 487 .port_remove = spcp8x5_port_remove,
642 .process_read_urb = spcp8x5_process_read_urb,
643}; 488};
644 489
645static struct usb_serial_driver * const serial_drivers[] = { 490static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index 4b2a19757b4d..5b62dbbdf996 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -61,7 +61,6 @@ struct ssu100_port_private {
61 spinlock_t status_lock; 61 spinlock_t status_lock;
62 u8 shadowLSR; 62 u8 shadowLSR;
63 u8 shadowMSR; 63 u8 shadowMSR;
64 struct async_icount icount;
65}; 64};
66 65
67static inline int ssu100_control_msg(struct usb_device *dev, 66static inline int ssu100_control_msg(struct usb_device *dev,
@@ -315,11 +314,6 @@ static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
315 return usb_serial_generic_open(tty, port); 314 return usb_serial_generic_open(tty, port);
316} 315}
317 316
318static void ssu100_close(struct usb_serial_port *port)
319{
320 usb_serial_generic_close(port);
321}
322
323static int get_serial_info(struct usb_serial_port *port, 317static int get_serial_info(struct usb_serial_port *port,
324 struct serial_struct __user *retinfo) 318 struct serial_struct __user *retinfo)
325{ 319{
@@ -343,73 +337,6 @@ static int get_serial_info(struct usb_serial_port *port,
343 return 0; 337 return 0;
344} 338}
345 339
346static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
347{
348 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
349 struct async_icount prev, cur;
350 unsigned long flags;
351
352 spin_lock_irqsave(&priv->status_lock, flags);
353 prev = priv->icount;
354 spin_unlock_irqrestore(&priv->status_lock, flags);
355
356 while (1) {
357 wait_event_interruptible(port->delta_msr_wait,
358 (port->serial->disconnected ||
359 (priv->icount.rng != prev.rng) ||
360 (priv->icount.dsr != prev.dsr) ||
361 (priv->icount.dcd != prev.dcd) ||
362 (priv->icount.cts != prev.cts)));
363
364 if (signal_pending(current))
365 return -ERESTARTSYS;
366
367 if (port->serial->disconnected)
368 return -EIO;
369
370 spin_lock_irqsave(&priv->status_lock, flags);
371 cur = priv->icount;
372 spin_unlock_irqrestore(&priv->status_lock, flags);
373
374 if ((prev.rng == cur.rng) &&
375 (prev.dsr == cur.dsr) &&
376 (prev.dcd == cur.dcd) &&
377 (prev.cts == cur.cts))
378 return -EIO;
379
380 if ((arg & TIOCM_RNG && (prev.rng != cur.rng)) ||
381 (arg & TIOCM_DSR && (prev.dsr != cur.dsr)) ||
382 (arg & TIOCM_CD && (prev.dcd != cur.dcd)) ||
383 (arg & TIOCM_CTS && (prev.cts != cur.cts)))
384 return 0;
385 }
386 return 0;
387}
388
389static int ssu100_get_icount(struct tty_struct *tty,
390 struct serial_icounter_struct *icount)
391{
392 struct usb_serial_port *port = tty->driver_data;
393 struct ssu100_port_private *priv = usb_get_serial_port_data(port);
394 struct async_icount cnow = priv->icount;
395
396 icount->cts = cnow.cts;
397 icount->dsr = cnow.dsr;
398 icount->rng = cnow.rng;
399 icount->dcd = cnow.dcd;
400 icount->rx = cnow.rx;
401 icount->tx = cnow.tx;
402 icount->frame = cnow.frame;
403 icount->overrun = cnow.overrun;
404 icount->parity = cnow.parity;
405 icount->brk = cnow.brk;
406 icount->buf_overrun = cnow.buf_overrun;
407
408 return 0;
409}
410
411
412
413static int ssu100_ioctl(struct tty_struct *tty, 340static int ssu100_ioctl(struct tty_struct *tty,
414 unsigned int cmd, unsigned long arg) 341 unsigned int cmd, unsigned long arg)
415{ 342{
@@ -421,10 +348,6 @@ static int ssu100_ioctl(struct tty_struct *tty,
421 case TIOCGSERIAL: 348 case TIOCGSERIAL:
422 return get_serial_info(port, 349 return get_serial_info(port,
423 (struct serial_struct __user *) arg); 350 (struct serial_struct __user *) arg);
424
425 case TIOCMIWAIT:
426 return wait_modem_info(port, arg);
427
428 default: 351 default:
429 break; 352 break;
430 } 353 }
@@ -532,14 +455,14 @@ static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
532 if (msr & UART_MSR_ANY_DELTA) { 455 if (msr & UART_MSR_ANY_DELTA) {
533 /* update input line counters */ 456 /* update input line counters */
534 if (msr & UART_MSR_DCTS) 457 if (msr & UART_MSR_DCTS)
535 priv->icount.cts++; 458 port->icount.cts++;
536 if (msr & UART_MSR_DDSR) 459 if (msr & UART_MSR_DDSR)
537 priv->icount.dsr++; 460 port->icount.dsr++;
538 if (msr & UART_MSR_DDCD) 461 if (msr & UART_MSR_DDCD)
539 priv->icount.dcd++; 462 port->icount.dcd++;
540 if (msr & UART_MSR_TERI) 463 if (msr & UART_MSR_TERI)
541 priv->icount.rng++; 464 port->icount.rng++;
542 wake_up_interruptible(&port->delta_msr_wait); 465 wake_up_interruptible(&port->port.delta_msr_wait);
543 } 466 }
544} 467}
545 468
@@ -558,22 +481,22 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
558 /* we always want to update icount, but we only want to 481 /* we always want to update icount, but we only want to
559 * update tty_flag for one case */ 482 * update tty_flag for one case */
560 if (lsr & UART_LSR_BI) { 483 if (lsr & UART_LSR_BI) {
561 priv->icount.brk++; 484 port->icount.brk++;
562 *tty_flag = TTY_BREAK; 485 *tty_flag = TTY_BREAK;
563 usb_serial_handle_break(port); 486 usb_serial_handle_break(port);
564 } 487 }
565 if (lsr & UART_LSR_PE) { 488 if (lsr & UART_LSR_PE) {
566 priv->icount.parity++; 489 port->icount.parity++;
567 if (*tty_flag == TTY_NORMAL) 490 if (*tty_flag == TTY_NORMAL)
568 *tty_flag = TTY_PARITY; 491 *tty_flag = TTY_PARITY;
569 } 492 }
570 if (lsr & UART_LSR_FE) { 493 if (lsr & UART_LSR_FE) {
571 priv->icount.frame++; 494 port->icount.frame++;
572 if (*tty_flag == TTY_NORMAL) 495 if (*tty_flag == TTY_NORMAL)
573 *tty_flag = TTY_FRAME; 496 *tty_flag = TTY_FRAME;
574 } 497 }
575 if (lsr & UART_LSR_OE){ 498 if (lsr & UART_LSR_OE){
576 priv->icount.overrun++; 499 port->icount.overrun++;
577 if (*tty_flag == TTY_NORMAL) 500 if (*tty_flag == TTY_NORMAL)
578 *tty_flag = TTY_OVERRUN; 501 *tty_flag = TTY_OVERRUN;
579 } 502 }
@@ -630,7 +553,6 @@ static struct usb_serial_driver ssu100_device = {
630 .id_table = id_table, 553 .id_table = id_table,
631 .num_ports = 1, 554 .num_ports = 1,
632 .open = ssu100_open, 555 .open = ssu100_open,
633 .close = ssu100_close,
634 .attach = ssu100_attach, 556 .attach = ssu100_attach,
635 .port_probe = ssu100_port_probe, 557 .port_probe = ssu100_port_probe,
636 .port_remove = ssu100_port_remove, 558 .port_remove = ssu100_port_remove,
@@ -638,10 +560,10 @@ static struct usb_serial_driver ssu100_device = {
638 .process_read_urb = ssu100_process_read_urb, 560 .process_read_urb = ssu100_process_read_urb,
639 .tiocmget = ssu100_tiocmget, 561 .tiocmget = ssu100_tiocmget,
640 .tiocmset = ssu100_tiocmset, 562 .tiocmset = ssu100_tiocmset,
641 .get_icount = ssu100_get_icount, 563 .tiocmiwait = usb_serial_generic_tiocmiwait,
564 .get_icount = usb_serial_generic_get_icount,
642 .ioctl = ssu100_ioctl, 565 .ioctl = ssu100_ioctl,
643 .set_termios = ssu100_set_termios, 566 .set_termios = ssu100_set_termios,
644 .disconnect = usb_serial_generic_disconnect,
645}; 567};
646 568
647static struct usb_serial_driver * const serial_drivers[] = { 569static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c
index be05e6caf9a3..9b1648945e7a 100644
--- a/drivers/usb/serial/symbolserial.c
+++ b/drivers/usb/serial/symbolserial.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Symbol USB barcode to serial driver 2 * Symbol USB barcode to serial driver
3 * 3 *
4 * Copyright (C) 2013 Johan Hovold <jhovold@gmail.com>
4 * Copyright (C) 2009 Greg Kroah-Hartman <gregkh@suse.de> 5 * Copyright (C) 2009 Greg Kroah-Hartman <gregkh@suse.de>
5 * Copyright (C) 2009 Novell Inc. 6 * Copyright (C) 2009 Novell Inc.
6 * 7 *
@@ -26,27 +27,17 @@ static const struct usb_device_id id_table[] = {
26}; 27};
27MODULE_DEVICE_TABLE(usb, id_table); 28MODULE_DEVICE_TABLE(usb, id_table);
28 29
29/* This structure holds all of the individual device information */
30struct symbol_private { 30struct symbol_private {
31 struct usb_device *udev;
32 struct usb_serial *serial;
33 struct usb_serial_port *port;
34 unsigned char *int_buffer;
35 struct urb *int_urb;
36 int buffer_size;
37 u8 bInterval;
38 u8 int_address;
39 spinlock_t lock; /* protects the following flags */ 31 spinlock_t lock; /* protects the following flags */
40 bool throttled; 32 bool throttled;
41 bool actually_throttled; 33 bool actually_throttled;
42 bool rts;
43}; 34};
44 35
45static void symbol_int_callback(struct urb *urb) 36static void symbol_int_callback(struct urb *urb)
46{ 37{
47 struct symbol_private *priv = urb->context; 38 struct usb_serial_port *port = urb->context;
39 struct symbol_private *priv = usb_get_serial_port_data(port);
48 unsigned char *data = urb->transfer_buffer; 40 unsigned char *data = urb->transfer_buffer;
49 struct usb_serial_port *port = priv->port;
50 int status = urb->status; 41 int status = urb->status;
51 int result; 42 int result;
52 int data_length; 43 int data_length;
@@ -84,7 +75,7 @@ static void symbol_int_callback(struct urb *urb)
84 tty_insert_flip_string(&port->port, &data[1], data_length); 75 tty_insert_flip_string(&port->port, &data[1], data_length);
85 tty_flip_buffer_push(&port->port); 76 tty_flip_buffer_push(&port->port);
86 } else { 77 } else {
87 dev_dbg(&priv->udev->dev, 78 dev_dbg(&port->dev,
88 "Improper amount of data received from the device, " 79 "Improper amount of data received from the device, "
89 "%d bytes", urb->actual_length); 80 "%d bytes", urb->actual_length);
90 } 81 }
@@ -94,12 +85,7 @@ exit:
94 85
95 /* Continue trying to always read if we should */ 86 /* Continue trying to always read if we should */
96 if (!priv->throttled) { 87 if (!priv->throttled) {
97 usb_fill_int_urb(priv->int_urb, priv->udev, 88 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
98 usb_rcvintpipe(priv->udev,
99 priv->int_address),
100 priv->int_buffer, priv->buffer_size,
101 symbol_int_callback, priv, priv->bInterval);
102 result = usb_submit_urb(priv->int_urb, GFP_ATOMIC);
103 if (result) 89 if (result)
104 dev_err(&port->dev, 90 dev_err(&port->dev,
105 "%s - failed resubmitting read urb, error %d\n", 91 "%s - failed resubmitting read urb, error %d\n",
@@ -118,15 +104,10 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
118 spin_lock_irqsave(&priv->lock, flags); 104 spin_lock_irqsave(&priv->lock, flags);
119 priv->throttled = false; 105 priv->throttled = false;
120 priv->actually_throttled = false; 106 priv->actually_throttled = false;
121 priv->port = port;
122 spin_unlock_irqrestore(&priv->lock, flags); 107 spin_unlock_irqrestore(&priv->lock, flags);
123 108
124 /* Start reading from the device */ 109 /* Start reading from the device */
125 usb_fill_int_urb(priv->int_urb, priv->udev, 110 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
126 usb_rcvintpipe(priv->udev, priv->int_address),
127 priv->int_buffer, priv->buffer_size,
128 symbol_int_callback, priv, priv->bInterval);
129 result = usb_submit_urb(priv->int_urb, GFP_KERNEL);
130 if (result) 111 if (result)
131 dev_err(&port->dev, 112 dev_err(&port->dev,
132 "%s - failed resubmitting read urb, error %d\n", 113 "%s - failed resubmitting read urb, error %d\n",
@@ -136,10 +117,7 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
136 117
137static void symbol_close(struct usb_serial_port *port) 118static void symbol_close(struct usb_serial_port *port)
138{ 119{
139 struct symbol_private *priv = usb_get_serial_data(port->serial); 120 usb_kill_urb(port->interrupt_in_urb);
140
141 /* shutdown our urbs */
142 usb_kill_urb(priv->int_urb);
143} 121}
144 122
145static void symbol_throttle(struct tty_struct *tty) 123static void symbol_throttle(struct tty_struct *tty)
@@ -166,7 +144,7 @@ static void symbol_unthrottle(struct tty_struct *tty)
166 spin_unlock_irq(&priv->lock); 144 spin_unlock_irq(&priv->lock);
167 145
168 if (was_throttled) { 146 if (was_throttled) {
169 result = usb_submit_urb(priv->int_urb, GFP_KERNEL); 147 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
170 if (result) 148 if (result)
171 dev_err(&port->dev, 149 dev_err(&port->dev,
172 "%s - failed submitting read urb, error %d\n", 150 "%s - failed submitting read urb, error %d\n",
@@ -176,89 +154,36 @@ static void symbol_unthrottle(struct tty_struct *tty)
176 154
177static int symbol_startup(struct usb_serial *serial) 155static int symbol_startup(struct usb_serial *serial)
178{ 156{
157 if (!serial->num_interrupt_in) {
158 dev_err(&serial->dev->dev, "no interrupt-in endpoint\n");
159 return -ENODEV;
160 }
161
162 return 0;
163}
164
165static int symbol_port_probe(struct usb_serial_port *port)
166{
179 struct symbol_private *priv; 167 struct symbol_private *priv;
180 struct usb_host_interface *intf;
181 int i;
182 int retval = -ENOMEM;
183 bool int_in_found = false;
184 168
185 /* create our private serial structure */
186 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 169 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
187 if (priv == NULL) { 170 if (!priv)
188 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
189 return -ENOMEM; 171 return -ENOMEM;
190 } 172
191 spin_lock_init(&priv->lock); 173 spin_lock_init(&priv->lock);
192 priv->serial = serial;
193 priv->port = serial->port[0];
194 priv->udev = serial->dev;
195
196 /* find our interrupt endpoint */
197 intf = serial->interface->altsetting;
198 for (i = 0; i < intf->desc.bNumEndpoints; ++i) {
199 struct usb_endpoint_descriptor *endpoint;
200
201 endpoint = &intf->endpoint[i].desc;
202 if (!usb_endpoint_is_int_in(endpoint))
203 continue;
204
205 priv->int_urb = usb_alloc_urb(0, GFP_KERNEL);
206 if (!priv->int_urb) {
207 dev_err(&priv->udev->dev, "out of memory\n");
208 goto error;
209 }
210
211 priv->buffer_size = usb_endpoint_maxp(endpoint) * 2;
212 priv->int_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
213 if (!priv->int_buffer) {
214 dev_err(&priv->udev->dev, "out of memory\n");
215 goto error;
216 }
217
218 priv->int_address = endpoint->bEndpointAddress;
219 priv->bInterval = endpoint->bInterval;
220
221 /* set up our int urb */
222 usb_fill_int_urb(priv->int_urb, priv->udev,
223 usb_rcvintpipe(priv->udev,
224 endpoint->bEndpointAddress),
225 priv->int_buffer, priv->buffer_size,
226 symbol_int_callback, priv, priv->bInterval);
227
228 int_in_found = true;
229 break;
230 }
231 174
232 if (!int_in_found) { 175 usb_set_serial_port_data(port, priv);
233 dev_err(&priv->udev->dev,
234 "Error - the proper endpoints were not found!\n");
235 goto error;
236 }
237 176
238 usb_set_serial_data(serial, priv);
239 return 0; 177 return 0;
240
241error:
242 usb_free_urb(priv->int_urb);
243 kfree(priv->int_buffer);
244 kfree(priv);
245 return retval;
246}
247
248static void symbol_disconnect(struct usb_serial *serial)
249{
250 struct symbol_private *priv = usb_get_serial_data(serial);
251
252 usb_kill_urb(priv->int_urb);
253 usb_free_urb(priv->int_urb);
254} 178}
255 179
256static void symbol_release(struct usb_serial *serial) 180static int symbol_port_remove(struct usb_serial_port *port)
257{ 181{
258 struct symbol_private *priv = usb_get_serial_data(serial); 182 struct symbol_private *priv = usb_get_serial_port_data(port);
259 183
260 kfree(priv->int_buffer);
261 kfree(priv); 184 kfree(priv);
185
186 return 0;
262} 187}
263 188
264static struct usb_serial_driver symbol_device = { 189static struct usb_serial_driver symbol_device = {
@@ -269,12 +194,13 @@ static struct usb_serial_driver symbol_device = {
269 .id_table = id_table, 194 .id_table = id_table,
270 .num_ports = 1, 195 .num_ports = 1,
271 .attach = symbol_startup, 196 .attach = symbol_startup,
197 .port_probe = symbol_port_probe,
198 .port_remove = symbol_port_remove,
272 .open = symbol_open, 199 .open = symbol_open,
273 .close = symbol_close, 200 .close = symbol_close,
274 .disconnect = symbol_disconnect,
275 .release = symbol_release,
276 .throttle = symbol_throttle, 201 .throttle = symbol_throttle,
277 .unthrottle = symbol_unthrottle, 202 .unthrottle = symbol_unthrottle,
203 .read_int_callback = symbol_int_callback,
278}; 204};
279 205
280static struct usb_serial_driver * const serial_drivers[] = { 206static struct usb_serial_driver * const serial_drivers[] = {
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 19a71a9eecf0..cac47aef2918 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -67,13 +67,10 @@
67struct ti_port { 67struct ti_port {
68 int tp_is_open; 68 int tp_is_open;
69 __u8 tp_msr; 69 __u8 tp_msr;
70 __u8 tp_lsr;
71 __u8 tp_shadow_mcr; 70 __u8 tp_shadow_mcr;
72 __u8 tp_uart_mode; /* 232 or 485 modes */ 71 __u8 tp_uart_mode; /* 232 or 485 modes */
73 unsigned int tp_uart_base_addr; 72 unsigned int tp_uart_base_addr;
74 int tp_flags; 73 int tp_flags;
75 int tp_closing_wait;/* in .01 secs */
76 struct async_icount tp_icount;
77 wait_queue_head_t tp_write_wait; 74 wait_queue_head_t tp_write_wait;
78 struct ti_device *tp_tdev; 75 struct ti_device *tp_tdev;
79 struct usb_serial_port *tp_port; 76 struct usb_serial_port *tp_port;
@@ -108,8 +105,6 @@ static void ti_throttle(struct tty_struct *tty);
108static void ti_unthrottle(struct tty_struct *tty); 105static void ti_unthrottle(struct tty_struct *tty);
109static int ti_ioctl(struct tty_struct *tty, 106static int ti_ioctl(struct tty_struct *tty,
110 unsigned int cmd, unsigned long arg); 107 unsigned int cmd, unsigned long arg);
111static int ti_get_icount(struct tty_struct *tty,
112 struct serial_icounter_struct *icount);
113static void ti_set_termios(struct tty_struct *tty, 108static void ti_set_termios(struct tty_struct *tty,
114 struct usb_serial_port *port, struct ktermios *old_termios); 109 struct usb_serial_port *port, struct ktermios *old_termios);
115static int ti_tiocmget(struct tty_struct *tty); 110static int ti_tiocmget(struct tty_struct *tty);
@@ -124,15 +119,13 @@ static void ti_recv(struct usb_serial_port *port, unsigned char *data,
124 int length); 119 int length);
125static void ti_send(struct ti_port *tport); 120static void ti_send(struct ti_port *tport);
126static int ti_set_mcr(struct ti_port *tport, unsigned int mcr); 121static int ti_set_mcr(struct ti_port *tport, unsigned int mcr);
127static int ti_get_lsr(struct ti_port *tport); 122static int ti_get_lsr(struct ti_port *tport, u8 *lsr);
128static int ti_get_serial_info(struct ti_port *tport, 123static int ti_get_serial_info(struct ti_port *tport,
129 struct serial_struct __user *ret_arg); 124 struct serial_struct __user *ret_arg);
130static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, 125static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
131 struct serial_struct __user *new_arg); 126 struct serial_struct __user *new_arg);
132static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); 127static void ti_handle_new_msr(struct ti_port *tport, __u8 msr);
133 128
134static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush);
135
136static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); 129static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty);
137static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); 130static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty);
138 131
@@ -235,7 +228,8 @@ static struct usb_serial_driver ti_1port_device = {
235 .set_termios = ti_set_termios, 228 .set_termios = ti_set_termios,
236 .tiocmget = ti_tiocmget, 229 .tiocmget = ti_tiocmget,
237 .tiocmset = ti_tiocmset, 230 .tiocmset = ti_tiocmset,
238 .get_icount = ti_get_icount, 231 .tiocmiwait = usb_serial_generic_tiocmiwait,
232 .get_icount = usb_serial_generic_get_icount,
239 .break_ctl = ti_break, 233 .break_ctl = ti_break,
240 .read_int_callback = ti_interrupt_callback, 234 .read_int_callback = ti_interrupt_callback,
241 .read_bulk_callback = ti_bulk_in_callback, 235 .read_bulk_callback = ti_bulk_in_callback,
@@ -265,7 +259,8 @@ static struct usb_serial_driver ti_2port_device = {
265 .set_termios = ti_set_termios, 259 .set_termios = ti_set_termios,
266 .tiocmget = ti_tiocmget, 260 .tiocmget = ti_tiocmget,
267 .tiocmset = ti_tiocmset, 261 .tiocmset = ti_tiocmset,
268 .get_icount = ti_get_icount, 262 .tiocmiwait = usb_serial_generic_tiocmiwait,
263 .get_icount = usb_serial_generic_get_icount,
269 .break_ctl = ti_break, 264 .break_ctl = ti_break,
270 .read_int_callback = ti_interrupt_callback, 265 .read_int_callback = ti_interrupt_callback,
271 .read_bulk_callback = ti_bulk_in_callback, 266 .read_bulk_callback = ti_bulk_in_callback,
@@ -430,7 +425,7 @@ static int ti_port_probe(struct usb_serial_port *port)
430 tport->tp_uart_base_addr = TI_UART1_BASE_ADDR; 425 tport->tp_uart_base_addr = TI_UART1_BASE_ADDR;
431 else 426 else
432 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR; 427 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR;
433 tport->tp_closing_wait = closing_wait; 428 port->port.closing_wait = msecs_to_jiffies(10 * closing_wait);
434 init_waitqueue_head(&tport->tp_write_wait); 429 init_waitqueue_head(&tport->tp_write_wait);
435 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) { 430 if (kfifo_alloc(&tport->write_fifo, TI_WRITE_BUF_SIZE, GFP_KERNEL)) {
436 kfree(tport); 431 kfree(tport);
@@ -480,8 +475,6 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
480 475
481 port_number = port->number - port->serial->minor; 476 port_number = port->number - port->serial->minor;
482 477
483 memset(&(tport->tp_icount), 0x00, sizeof(tport->tp_icount));
484
485 tport->tp_msr = 0; 478 tport->tp_msr = 0;
486 tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR); 479 tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR);
487 480
@@ -585,6 +578,8 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
585 tport->tp_is_open = 1; 578 tport->tp_is_open = 1;
586 ++tdev->td_open_port_count; 579 ++tdev->td_open_port_count;
587 580
581 port->port.drain_delay = 3;
582
588 goto release_lock; 583 goto release_lock;
589 584
590unlink_int_urb: 585unlink_int_urb:
@@ -604,6 +599,7 @@ static void ti_close(struct usb_serial_port *port)
604 int port_number; 599 int port_number;
605 int status; 600 int status;
606 int do_unlock; 601 int do_unlock;
602 unsigned long flags;
607 603
608 tdev = usb_get_serial_data(port->serial); 604 tdev = usb_get_serial_data(port->serial);
609 tport = usb_get_serial_port_data(port); 605 tport = usb_get_serial_port_data(port);
@@ -612,11 +608,12 @@ static void ti_close(struct usb_serial_port *port)
612 608
613 tport->tp_is_open = 0; 609 tport->tp_is_open = 0;
614 610
615 ti_drain(tport, (tport->tp_closing_wait*HZ)/100, 1);
616
617 usb_kill_urb(port->read_urb); 611 usb_kill_urb(port->read_urb);
618 usb_kill_urb(port->write_urb); 612 usb_kill_urb(port->write_urb);
619 tport->tp_write_urb_in_use = 0; 613 tport->tp_write_urb_in_use = 0;
614 spin_lock_irqsave(&tport->tp_lock, flags);
615 kfifo_reset_out(&tport->write_fifo);
616 spin_unlock_irqrestore(&tport->tp_lock, flags);
620 617
621 port_number = port->number - port->serial->minor; 618 port_number = port->number - port->serial->minor;
622 619
@@ -687,6 +684,8 @@ static int ti_chars_in_buffer(struct tty_struct *tty)
687 struct ti_port *tport = usb_get_serial_port_data(port); 684 struct ti_port *tport = usb_get_serial_port_data(port);
688 int chars = 0; 685 int chars = 0;
689 unsigned long flags; 686 unsigned long flags;
687 int ret;
688 u8 lsr;
690 689
691 if (tport == NULL) 690 if (tport == NULL)
692 return 0; 691 return 0;
@@ -695,6 +694,12 @@ static int ti_chars_in_buffer(struct tty_struct *tty)
695 chars = kfifo_len(&tport->write_fifo); 694 chars = kfifo_len(&tport->write_fifo);
696 spin_unlock_irqrestore(&tport->tp_lock, flags); 695 spin_unlock_irqrestore(&tport->tp_lock, flags);
697 696
697 if (!chars) {
698 ret = ti_get_lsr(tport, &lsr);
699 if (!ret && !(lsr & TI_LSR_TX_EMPTY))
700 chars = 1;
701 }
702
698 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); 703 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
699 return chars; 704 return chars;
700} 705}
@@ -731,38 +736,11 @@ static void ti_unthrottle(struct tty_struct *tty)
731 } 736 }
732} 737}
733 738
734static int ti_get_icount(struct tty_struct *tty,
735 struct serial_icounter_struct *icount)
736{
737 struct usb_serial_port *port = tty->driver_data;
738 struct ti_port *tport = usb_get_serial_port_data(port);
739 struct async_icount cnow = tport->tp_icount;
740
741 dev_dbg(&port->dev, "%s - TIOCGICOUNT RX=%d, TX=%d\n", __func__,
742 cnow.rx, cnow.tx);
743
744 icount->cts = cnow.cts;
745 icount->dsr = cnow.dsr;
746 icount->rng = cnow.rng;
747 icount->dcd = cnow.dcd;
748 icount->rx = cnow.rx;
749 icount->tx = cnow.tx;
750 icount->frame = cnow.frame;
751 icount->overrun = cnow.overrun;
752 icount->parity = cnow.parity;
753 icount->brk = cnow.brk;
754 icount->buf_overrun = cnow.buf_overrun;
755
756 return 0;
757}
758
759static int ti_ioctl(struct tty_struct *tty, 739static int ti_ioctl(struct tty_struct *tty,
760 unsigned int cmd, unsigned long arg) 740 unsigned int cmd, unsigned long arg)
761{ 741{
762 struct usb_serial_port *port = tty->driver_data; 742 struct usb_serial_port *port = tty->driver_data;
763 struct ti_port *tport = usb_get_serial_port_data(port); 743 struct ti_port *tport = usb_get_serial_port_data(port);
764 struct async_icount cnow;
765 struct async_icount cprev;
766 744
767 dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd); 745 dev_dbg(&port->dev, "%s - cmd = 0x%04X\n", __func__, cmd);
768 746
@@ -778,29 +756,6 @@ static int ti_ioctl(struct tty_struct *tty,
778 dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__); 756 dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__);
779 return ti_set_serial_info(tty, tport, 757 return ti_set_serial_info(tty, tport,
780 (struct serial_struct __user *)arg); 758 (struct serial_struct __user *)arg);
781 case TIOCMIWAIT:
782 dev_dbg(&port->dev, "%s - TIOCMIWAIT\n", __func__);
783 cprev = tport->tp_icount;
784 while (1) {
785 interruptible_sleep_on(&port->delta_msr_wait);
786 if (signal_pending(current))
787 return -ERESTARTSYS;
788
789 if (port->serial->disconnected)
790 return -EIO;
791
792 cnow = tport->tp_icount;
793 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
794 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
795 return -EIO; /* no change => error */
796 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
797 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
798 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
799 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)))
800 return 0;
801 cprev = cnow;
802 }
803 break;
804 } 759 }
805 return -ENOIOCTLCMD; 760 return -ENOIOCTLCMD;
806} 761}
@@ -1018,8 +973,6 @@ static void ti_break(struct tty_struct *tty, int break_state)
1018 if (tport == NULL) 973 if (tport == NULL)
1019 return; 974 return;
1020 975
1021 ti_drain(tport, (tport->tp_closing_wait*HZ)/100, 0);
1022
1023 status = ti_write_byte(port, tport->tp_tdev, 976 status = ti_write_byte(port, tport->tp_tdev,
1024 tport->tp_uart_base_addr + TI_UART_OFFSET_LCR, 977 tport->tp_uart_base_addr + TI_UART_OFFSET_LCR,
1025 TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0); 978 TI_LCR_BREAK, break_state == -1 ? TI_LCR_BREAK : 0);
@@ -1156,7 +1109,7 @@ static void ti_bulk_in_callback(struct urb *urb)
1156 else 1109 else
1157 ti_recv(port, urb->transfer_buffer, urb->actual_length); 1110 ti_recv(port, urb->transfer_buffer, urb->actual_length);
1158 spin_lock(&tport->tp_lock); 1111 spin_lock(&tport->tp_lock);
1159 tport->tp_icount.rx += urb->actual_length; 1112 port->icount.rx += urb->actual_length;
1160 spin_unlock(&tport->tp_lock); 1113 spin_unlock(&tport->tp_lock);
1161 } 1114 }
1162 1115
@@ -1264,7 +1217,7 @@ static void ti_send(struct ti_port *tport)
1264 /* TODO: reschedule ti_send */ 1217 /* TODO: reschedule ti_send */
1265 } else { 1218 } else {
1266 spin_lock_irqsave(&tport->tp_lock, flags); 1219 spin_lock_irqsave(&tport->tp_lock, flags);
1267 tport->tp_icount.tx += count; 1220 port->icount.tx += count;
1268 spin_unlock_irqrestore(&tport->tp_lock, flags); 1221 spin_unlock_irqrestore(&tport->tp_lock, flags);
1269 } 1222 }
1270 1223
@@ -1297,7 +1250,7 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr)
1297} 1250}
1298 1251
1299 1252
1300static int ti_get_lsr(struct ti_port *tport) 1253static int ti_get_lsr(struct ti_port *tport, u8 *lsr)
1301{ 1254{
1302 int size, status; 1255 int size, status;
1303 struct ti_device *tdev = tport->tp_tdev; 1256 struct ti_device *tdev = tport->tp_tdev;
@@ -1323,7 +1276,7 @@ static int ti_get_lsr(struct ti_port *tport)
1323 1276
1324 dev_dbg(&port->dev, "%s - lsr 0x%02X\n", __func__, data->bLSR); 1277 dev_dbg(&port->dev, "%s - lsr 0x%02X\n", __func__, data->bLSR);
1325 1278
1326 tport->tp_lsr = data->bLSR; 1279 *lsr = data->bLSR;
1327 1280
1328free_data: 1281free_data:
1329 kfree(data); 1282 kfree(data);
@@ -1336,10 +1289,15 @@ static int ti_get_serial_info(struct ti_port *tport,
1336{ 1289{
1337 struct usb_serial_port *port = tport->tp_port; 1290 struct usb_serial_port *port = tport->tp_port;
1338 struct serial_struct ret_serial; 1291 struct serial_struct ret_serial;
1292 unsigned cwait;
1339 1293
1340 if (!ret_arg) 1294 if (!ret_arg)
1341 return -EFAULT; 1295 return -EFAULT;
1342 1296
1297 cwait = port->port.closing_wait;
1298 if (cwait != ASYNC_CLOSING_WAIT_NONE)
1299 cwait = jiffies_to_msecs(cwait) / 10;
1300
1343 memset(&ret_serial, 0, sizeof(ret_serial)); 1301 memset(&ret_serial, 0, sizeof(ret_serial));
1344 1302
1345 ret_serial.type = PORT_16550A; 1303 ret_serial.type = PORT_16550A;
@@ -1348,7 +1306,7 @@ static int ti_get_serial_info(struct ti_port *tport,
1348 ret_serial.flags = tport->tp_flags; 1306 ret_serial.flags = tport->tp_flags;
1349 ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE; 1307 ret_serial.xmit_fifo_size = TI_WRITE_BUF_SIZE;
1350 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1308 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800;
1351 ret_serial.closing_wait = tport->tp_closing_wait; 1309 ret_serial.closing_wait = cwait;
1352 1310
1353 if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg))) 1311 if (copy_to_user(ret_arg, &ret_serial, sizeof(*ret_arg)))
1354 return -EFAULT; 1312 return -EFAULT;
@@ -1361,12 +1319,17 @@ static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
1361 struct serial_struct __user *new_arg) 1319 struct serial_struct __user *new_arg)
1362{ 1320{
1363 struct serial_struct new_serial; 1321 struct serial_struct new_serial;
1322 unsigned cwait;
1364 1323
1365 if (copy_from_user(&new_serial, new_arg, sizeof(new_serial))) 1324 if (copy_from_user(&new_serial, new_arg, sizeof(new_serial)))
1366 return -EFAULT; 1325 return -EFAULT;
1367 1326
1327 cwait = new_serial.closing_wait;
1328 if (cwait != ASYNC_CLOSING_WAIT_NONE)
1329 cwait = msecs_to_jiffies(10 * new_serial.closing_wait);
1330
1368 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1331 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS;
1369 tport->tp_closing_wait = new_serial.closing_wait; 1332 tport->tp_port->port.closing_wait = cwait;
1370 1333
1371 return 0; 1334 return 0;
1372} 1335}
@@ -1382,7 +1345,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1382 1345
1383 if (msr & TI_MSR_DELTA_MASK) { 1346 if (msr & TI_MSR_DELTA_MASK) {
1384 spin_lock_irqsave(&tport->tp_lock, flags); 1347 spin_lock_irqsave(&tport->tp_lock, flags);
1385 icount = &tport->tp_icount; 1348 icount = &tport->tp_port->icount;
1386 if (msr & TI_MSR_DELTA_CTS) 1349 if (msr & TI_MSR_DELTA_CTS)
1387 icount->cts++; 1350 icount->cts++;
1388 if (msr & TI_MSR_DELTA_DSR) 1351 if (msr & TI_MSR_DELTA_DSR)
@@ -1391,7 +1354,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1391 icount->dcd++; 1354 icount->dcd++;
1392 if (msr & TI_MSR_DELTA_RI) 1355 if (msr & TI_MSR_DELTA_RI)
1393 icount->rng++; 1356 icount->rng++;
1394 wake_up_interruptible(&tport->tp_port->delta_msr_wait); 1357 wake_up_interruptible(&tport->tp_port->port.delta_msr_wait);
1395 spin_unlock_irqrestore(&tport->tp_lock, flags); 1358 spin_unlock_irqrestore(&tport->tp_lock, flags);
1396 } 1359 }
1397 1360
@@ -1411,56 +1374,6 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1411} 1374}
1412 1375
1413 1376
1414static void ti_drain(struct ti_port *tport, unsigned long timeout, int flush)
1415{
1416 struct ti_device *tdev = tport->tp_tdev;
1417 struct usb_serial_port *port = tport->tp_port;
1418 wait_queue_t wait;
1419
1420 spin_lock_irq(&tport->tp_lock);
1421
1422 /* wait for data to drain from the buffer */
1423 tdev->td_urb_error = 0;
1424 init_waitqueue_entry(&wait, current);
1425 add_wait_queue(&tport->tp_write_wait, &wait);
1426 for (;;) {
1427 set_current_state(TASK_INTERRUPTIBLE);
1428 if (kfifo_len(&tport->write_fifo) == 0
1429 || timeout == 0 || signal_pending(current)
1430 || tdev->td_urb_error
1431 || port->serial->disconnected) /* disconnect */
1432 break;
1433 spin_unlock_irq(&tport->tp_lock);
1434 timeout = schedule_timeout(timeout);
1435 spin_lock_irq(&tport->tp_lock);
1436 }
1437 set_current_state(TASK_RUNNING);
1438 remove_wait_queue(&tport->tp_write_wait, &wait);
1439
1440 /* flush any remaining data in the buffer */
1441 if (flush)
1442 kfifo_reset_out(&tport->write_fifo);
1443
1444 spin_unlock_irq(&tport->tp_lock);
1445
1446 mutex_lock(&port->serial->disc_mutex);
1447 /* wait for data to drain from the device */
1448 /* wait for empty tx register, plus 20 ms */
1449 timeout += jiffies;
1450 tport->tp_lsr &= ~TI_LSR_TX_EMPTY;
1451 while ((long)(jiffies - timeout) < 0 && !signal_pending(current)
1452 && !(tport->tp_lsr&TI_LSR_TX_EMPTY) && !tdev->td_urb_error
1453 && !port->serial->disconnected) {
1454 if (ti_get_lsr(tport))
1455 break;
1456 mutex_unlock(&port->serial->disc_mutex);
1457 msleep_interruptible(20);
1458 mutex_lock(&port->serial->disc_mutex);
1459 }
1460 mutex_unlock(&port->serial->disc_mutex);
1461}
1462
1463
1464static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty) 1377static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty)
1465{ 1378{
1466 unsigned long flags; 1379 unsigned long flags;
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 650be17a68f2..cf75beb1251b 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * USB Serial Converter driver 2 * USB Serial Converter driver
3 * 3 *
4 * Copyright (C) 2009 - 2013 Johan Hovold (jhovold@gmail.com)
4 * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com) 5 * Copyright (C) 1999 - 2012 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2000 Peter Berger (pberger@brimson.com) 6 * Copyright (C) 2000 Peter Berger (pberger@brimson.com)
6 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com) 7 * Copyright (C) 2000 Al Borchers (borchers@steinerpoint.com)
@@ -14,7 +15,6 @@
14 * 15 *
15 * See Documentation/usb/usb-serial.txt for more information on using this 16 * See Documentation/usb/usb-serial.txt for more information on using this
16 * driver 17 * driver
17 *
18 */ 18 */
19 19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -49,7 +49,6 @@
49 drivers depend on it. 49 drivers depend on it.
50*/ 50*/
51 51
52/* initially all NULL */
53static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; 52static struct usb_serial *serial_table[SERIAL_TTY_MINORS];
54static DEFINE_MUTEX(table_lock); 53static DEFINE_MUTEX(table_lock);
55static LIST_HEAD(usb_serial_driver_list); 54static LIST_HEAD(usb_serial_driver_list);
@@ -139,7 +138,7 @@ static void destroy_serial(struct kref *kref)
139 if (serial->minor != SERIAL_TTY_NO_MINOR) 138 if (serial->minor != SERIAL_TTY_NO_MINOR)
140 return_serial(serial); 139 return_serial(serial);
141 140
142 if (serial->attached) 141 if (serial->attached && serial->type->release)
143 serial->type->release(serial); 142 serial->type->release(serial);
144 143
145 /* Now that nothing is using the ports, they can be freed */ 144 /* Now that nothing is using the ports, they can be freed */
@@ -225,7 +224,7 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty)
225 return retval; 224 return retval;
226} 225}
227 226
228static int serial_activate(struct tty_port *tport, struct tty_struct *tty) 227static int serial_port_activate(struct tty_port *tport, struct tty_struct *tty)
229{ 228{
230 struct usb_serial_port *port = 229 struct usb_serial_port *port =
231 container_of(tport, struct usb_serial_port, port); 230 container_of(tport, struct usb_serial_port, port);
@@ -249,30 +248,27 @@ static int serial_open(struct tty_struct *tty, struct file *filp)
249{ 248{
250 struct usb_serial_port *port = tty->driver_data; 249 struct usb_serial_port *port = tty->driver_data;
251 250
252 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 251 dev_dbg(tty->dev, "%s\n", __func__);
252
253 return tty_port_open(&port->port, tty, filp); 253 return tty_port_open(&port->port, tty, filp);
254} 254}
255 255
256/** 256/**
257 * serial_down - shut down hardware 257 * serial_port_shutdown - shut down hardware
258 * @tport: tty port to shut down 258 * @tport: tty port to shut down
259 * 259 *
260 * Shut down a USB serial port unless it is the console. We never 260 * Shut down a USB serial port. Serialized against activate by the
261 * shut down the console hardware as it will always be in use. Serialized 261 * tport mutex and kept to matching open/close pairs
262 * against activate by the tport mutex and kept to matching open/close pairs
263 * of calls by the ASYNCB_INITIALIZED flag. 262 * of calls by the ASYNCB_INITIALIZED flag.
263 *
264 * Not called if tty is console.
264 */ 265 */
265static void serial_down(struct tty_port *tport) 266static void serial_port_shutdown(struct tty_port *tport)
266{ 267{
267 struct usb_serial_port *port = 268 struct usb_serial_port *port =
268 container_of(tport, struct usb_serial_port, port); 269 container_of(tport, struct usb_serial_port, port);
269 struct usb_serial_driver *drv = port->serial->type; 270 struct usb_serial_driver *drv = port->serial->type;
270 /* 271
271 * The console is magical. Do not hang up the console hardware
272 * or there will be tears.
273 */
274 if (port->port.console)
275 return;
276 if (drv->close) 272 if (drv->close)
277 drv->close(port); 273 drv->close(port);
278} 274}
@@ -281,7 +277,8 @@ static void serial_hangup(struct tty_struct *tty)
281{ 277{
282 struct usb_serial_port *port = tty->driver_data; 278 struct usb_serial_port *port = tty->driver_data;
283 279
284 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 280 dev_dbg(tty->dev, "%s\n", __func__);
281
285 tty_port_hangup(&port->port); 282 tty_port_hangup(&port->port);
286} 283}
287 284
@@ -289,7 +286,8 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
289{ 286{
290 struct usb_serial_port *port = tty->driver_data; 287 struct usb_serial_port *port = tty->driver_data;
291 288
292 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 289 dev_dbg(tty->dev, "%s\n", __func__);
290
293 tty_port_close(&port->port, tty, filp); 291 tty_port_close(&port->port, tty, filp);
294} 292}
295 293
@@ -308,14 +306,14 @@ static void serial_cleanup(struct tty_struct *tty)
308 struct usb_serial *serial; 306 struct usb_serial *serial;
309 struct module *owner; 307 struct module *owner;
310 308
309 dev_dbg(tty->dev, "%s\n", __func__);
310
311 /* The console is magical. Do not hang up the console hardware 311 /* The console is magical. Do not hang up the console hardware
312 * or there will be tears. 312 * or there will be tears.
313 */ 313 */
314 if (port->port.console) 314 if (port->port.console)
315 return; 315 return;
316 316
317 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number);
318
319 tty->driver_data = NULL; 317 tty->driver_data = NULL;
320 318
321 serial = port->serial; 319 serial = port->serial;
@@ -339,10 +337,8 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
339 if (port->serial->dev->state == USB_STATE_NOTATTACHED) 337 if (port->serial->dev->state == USB_STATE_NOTATTACHED)
340 goto exit; 338 goto exit;
341 339
342 dev_dbg(tty->dev, "%s - port %d, %d byte(s)\n", __func__, 340 dev_dbg(tty->dev, "%s - %d byte(s)\n", __func__, count);
343 port->number, count);
344 341
345 /* pass on to the driver specific version of this function */
346 retval = port->serial->type->write(tty, port, buf, count); 342 retval = port->serial->type->write(tty, port, buf, count);
347 if (retval < 0) 343 if (retval < 0)
348 retval = usb_translate_errors(retval); 344 retval = usb_translate_errors(retval);
@@ -354,8 +350,8 @@ static int serial_write_room(struct tty_struct *tty)
354{ 350{
355 struct usb_serial_port *port = tty->driver_data; 351 struct usb_serial_port *port = tty->driver_data;
356 352
357 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 353 dev_dbg(tty->dev, "%s\n", __func__);
358 /* pass on to the driver specific version of this function */ 354
359 return port->serial->type->write_room(tty); 355 return port->serial->type->write_room(tty);
360} 356}
361 357
@@ -365,7 +361,7 @@ static int serial_chars_in_buffer(struct tty_struct *tty)
365 struct usb_serial *serial = port->serial; 361 struct usb_serial *serial = port->serial;
366 int count = 0; 362 int count = 0;
367 363
368 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 364 dev_dbg(tty->dev, "%s\n", __func__);
369 365
370 mutex_lock(&serial->disc_mutex); 366 mutex_lock(&serial->disc_mutex);
371 /* if the device was unplugged then any remaining characters 367 /* if the device was unplugged then any remaining characters
@@ -383,9 +379,8 @@ static void serial_throttle(struct tty_struct *tty)
383{ 379{
384 struct usb_serial_port *port = tty->driver_data; 380 struct usb_serial_port *port = tty->driver_data;
385 381
386 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 382 dev_dbg(tty->dev, "%s\n", __func__);
387 383
388 /* pass on to the driver specific version of this function */
389 if (port->serial->type->throttle) 384 if (port->serial->type->throttle)
390 port->serial->type->throttle(tty); 385 port->serial->type->throttle(tty);
391} 386}
@@ -394,9 +389,8 @@ static void serial_unthrottle(struct tty_struct *tty)
394{ 389{
395 struct usb_serial_port *port = tty->driver_data; 390 struct usb_serial_port *port = tty->driver_data;
396 391
397 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 392 dev_dbg(tty->dev, "%s\n", __func__);
398 393
399 /* pass on to the driver specific version of this function */
400 if (port->serial->type->unthrottle) 394 if (port->serial->type->unthrottle)
401 port->serial->type->unthrottle(tty); 395 port->serial->type->unthrottle(tty);
402} 396}
@@ -407,15 +401,20 @@ static int serial_ioctl(struct tty_struct *tty,
407 struct usb_serial_port *port = tty->driver_data; 401 struct usb_serial_port *port = tty->driver_data;
408 int retval = -ENODEV; 402 int retval = -ENODEV;
409 403
410 dev_dbg(tty->dev, "%s - port %d, cmd 0x%.4x\n", __func__, 404 dev_dbg(tty->dev, "%s - cmd 0x%.4x\n", __func__, cmd);
411 port->number, cmd); 405
406 switch (cmd) {
407 case TIOCMIWAIT:
408 if (port->serial->type->tiocmiwait)
409 retval = port->serial->type->tiocmiwait(tty, arg);
410 break;
411 default:
412 if (port->serial->type->ioctl)
413 retval = port->serial->type->ioctl(tty, cmd, arg);
414 else
415 retval = -ENOIOCTLCMD;
416 }
412 417
413 /* pass on to the driver specific version of this function
414 if it is available */
415 if (port->serial->type->ioctl) {
416 retval = port->serial->type->ioctl(tty, cmd, arg);
417 } else
418 retval = -ENOIOCTLCMD;
419 return retval; 418 return retval;
420} 419}
421 420
@@ -423,10 +422,8 @@ static void serial_set_termios(struct tty_struct *tty, struct ktermios *old)
423{ 422{
424 struct usb_serial_port *port = tty->driver_data; 423 struct usb_serial_port *port = tty->driver_data;
425 424
426 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 425 dev_dbg(tty->dev, "%s\n", __func__);
427 426
428 /* pass on to the driver specific version of this function
429 if it is available */
430 if (port->serial->type->set_termios) 427 if (port->serial->type->set_termios)
431 port->serial->type->set_termios(tty, port, old); 428 port->serial->type->set_termios(tty, port, old);
432 else 429 else
@@ -437,12 +434,11 @@ static int serial_break(struct tty_struct *tty, int break_state)
437{ 434{
438 struct usb_serial_port *port = tty->driver_data; 435 struct usb_serial_port *port = tty->driver_data;
439 436
440 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 437 dev_dbg(tty->dev, "%s\n", __func__);
441 438
442 /* pass on to the driver specific version of this function
443 if it is available */
444 if (port->serial->type->break_ctl) 439 if (port->serial->type->break_ctl)
445 port->serial->type->break_ctl(tty, break_state); 440 port->serial->type->break_ctl(tty, break_state);
441
446 return 0; 442 return 0;
447} 443}
448 444
@@ -496,7 +492,7 @@ static int serial_tiocmget(struct tty_struct *tty)
496{ 492{
497 struct usb_serial_port *port = tty->driver_data; 493 struct usb_serial_port *port = tty->driver_data;
498 494
499 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 495 dev_dbg(tty->dev, "%s\n", __func__);
500 496
501 if (port->serial->type->tiocmget) 497 if (port->serial->type->tiocmget)
502 return port->serial->type->tiocmget(tty); 498 return port->serial->type->tiocmget(tty);
@@ -508,7 +504,7 @@ static int serial_tiocmset(struct tty_struct *tty,
508{ 504{
509 struct usb_serial_port *port = tty->driver_data; 505 struct usb_serial_port *port = tty->driver_data;
510 506
511 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 507 dev_dbg(tty->dev, "%s\n", __func__);
512 508
513 if (port->serial->type->tiocmset) 509 if (port->serial->type->tiocmset)
514 return port->serial->type->tiocmset(tty, set, clear); 510 return port->serial->type->tiocmset(tty, set, clear);
@@ -520,7 +516,7 @@ static int serial_get_icount(struct tty_struct *tty,
520{ 516{
521 struct usb_serial_port *port = tty->driver_data; 517 struct usb_serial_port *port = tty->driver_data;
522 518
523 dev_dbg(tty->dev, "%s - port %d\n", __func__, port->number); 519 dev_dbg(tty->dev, "%s\n", __func__);
524 520
525 if (port->serial->type->get_icount) 521 if (port->serial->type->get_icount)
526 return port->serial->type->get_icount(tty, icount); 522 return port->serial->type->get_icount(tty, icount);
@@ -546,43 +542,39 @@ static void usb_serial_port_work(struct work_struct *work)
546 tty_port_tty_wakeup(&port->port); 542 tty_port_tty_wakeup(&port->port);
547} 543}
548 544
549static void kill_traffic(struct usb_serial_port *port) 545static void usb_serial_port_poison_urbs(struct usb_serial_port *port)
550{ 546{
551 int i; 547 int i;
552 548
553 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) 549 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
554 usb_kill_urb(port->read_urbs[i]); 550 usb_poison_urb(port->read_urbs[i]);
555 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) 551 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
556 usb_kill_urb(port->write_urbs[i]); 552 usb_poison_urb(port->write_urbs[i]);
557 /* 553
558 * This is tricky. 554 usb_poison_urb(port->interrupt_in_urb);
559 * Some drivers submit the read_urb in the 555 usb_poison_urb(port->interrupt_out_urb);
560 * handler for the write_urb or vice versa 556}
561 * this order determines the order in which 557
562 * usb_kill_urb() must be used to reliably 558static void usb_serial_port_unpoison_urbs(struct usb_serial_port *port)
563 * kill the URBs. As it is unknown here, 559{
564 * both orders must be used in turn. 560 int i;
565 * The call below is not redundant. 561
566 */ 562 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
567 usb_kill_urb(port->read_urb); 563 usb_unpoison_urb(port->read_urbs[i]);
568 usb_kill_urb(port->interrupt_in_urb); 564 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
569 usb_kill_urb(port->interrupt_out_urb); 565 usb_unpoison_urb(port->write_urbs[i]);
566
567 usb_unpoison_urb(port->interrupt_in_urb);
568 usb_unpoison_urb(port->interrupt_out_urb);
570} 569}
571 570
572static void port_release(struct device *dev) 571static void usb_serial_port_release(struct device *dev)
573{ 572{
574 struct usb_serial_port *port = to_usb_serial_port(dev); 573 struct usb_serial_port *port = to_usb_serial_port(dev);
575 int i; 574 int i;
576 575
577 dev_dbg(dev, "%s\n", __func__); 576 dev_dbg(dev, "%s\n", __func__);
578 577
579 /*
580 * Stop all the traffic before cancelling the work, so that
581 * nobody will restart it by calling usb_serial_port_softint.
582 */
583 kill_traffic(port);
584 cancel_work_sync(&port->work);
585
586 usb_free_urb(port->interrupt_in_urb); 578 usb_free_urb(port->interrupt_in_urb);
587 usb_free_urb(port->interrupt_out_urb); 579 usb_free_urb(port->interrupt_out_urb);
588 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { 580 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
@@ -607,10 +599,8 @@ static struct usb_serial *create_serial(struct usb_device *dev,
607 struct usb_serial *serial; 599 struct usb_serial *serial;
608 600
609 serial = kzalloc(sizeof(*serial), GFP_KERNEL); 601 serial = kzalloc(sizeof(*serial), GFP_KERNEL);
610 if (!serial) { 602 if (!serial)
611 dev_err(&dev->dev, "%s - out of memory\n", __func__);
612 return NULL; 603 return NULL;
613 }
614 serial->dev = usb_get_dev(dev); 604 serial->dev = usb_get_dev(dev);
615 serial->type = driver; 605 serial->type = driver;
616 serial->interface = usb_get_intf(interface); 606 serial->interface = usb_get_intf(interface);
@@ -673,7 +663,7 @@ static struct usb_serial_driver *search_serial_device(
673 return NULL; 663 return NULL;
674} 664}
675 665
676static int serial_carrier_raised(struct tty_port *port) 666static int serial_port_carrier_raised(struct tty_port *port)
677{ 667{
678 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 668 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
679 struct usb_serial_driver *drv = p->serial->type; 669 struct usb_serial_driver *drv = p->serial->type;
@@ -684,7 +674,7 @@ static int serial_carrier_raised(struct tty_port *port)
684 return 1; 674 return 1;
685} 675}
686 676
687static void serial_dtr_rts(struct tty_port *port, int on) 677static void serial_port_dtr_rts(struct tty_port *port, int on)
688{ 678{
689 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 679 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
690 struct usb_serial *serial = p->serial; 680 struct usb_serial *serial = p->serial;
@@ -704,10 +694,10 @@ static void serial_dtr_rts(struct tty_port *port, int on)
704} 694}
705 695
706static const struct tty_port_operations serial_port_ops = { 696static const struct tty_port_operations serial_port_ops = {
707 .carrier_raised = serial_carrier_raised, 697 .carrier_raised = serial_port_carrier_raised,
708 .dtr_rts = serial_dtr_rts, 698 .dtr_rts = serial_port_dtr_rts,
709 .activate = serial_activate, 699 .activate = serial_port_activate,
710 .shutdown = serial_down, 700 .shutdown = serial_port_shutdown,
711}; 701};
712 702
713static int usb_serial_probe(struct usb_interface *interface, 703static int usb_serial_probe(struct usb_interface *interface,
@@ -754,7 +744,6 @@ static int usb_serial_probe(struct usb_interface *interface,
754 serial = create_serial(dev, interface, type); 744 serial = create_serial(dev, interface, type);
755 if (!serial) { 745 if (!serial) {
756 module_put(type->driver.owner); 746 module_put(type->driver.owner);
757 dev_err(ddev, "%s - out of memory\n", __func__);
758 return -ENOMEM; 747 return -ENOMEM;
759 } 748 }
760 749
@@ -895,7 +884,6 @@ static int usb_serial_probe(struct usb_interface *interface,
895 port->port.ops = &serial_port_ops; 884 port->port.ops = &serial_port_ops;
896 port->serial = serial; 885 port->serial = serial;
897 spin_lock_init(&port->lock); 886 spin_lock_init(&port->lock);
898 init_waitqueue_head(&port->delta_msr_wait);
899 /* Keep this for private driver use for the moment but 887 /* Keep this for private driver use for the moment but
900 should probably go away */ 888 should probably go away */
901 INIT_WORK(&port->work, usb_serial_port_work); 889 INIT_WORK(&port->work, usb_serial_port_work);
@@ -903,7 +891,7 @@ static int usb_serial_probe(struct usb_interface *interface,
903 port->dev.parent = &interface->dev; 891 port->dev.parent = &interface->dev;
904 port->dev.driver = NULL; 892 port->dev.driver = NULL;
905 port->dev.bus = &usb_serial_bus_type; 893 port->dev.bus = &usb_serial_bus_type;
906 port->dev.release = &port_release; 894 port->dev.release = &usb_serial_port_release;
907 device_initialize(&port->dev); 895 device_initialize(&port->dev);
908 } 896 }
909 897
@@ -919,16 +907,12 @@ static int usb_serial_probe(struct usb_interface *interface,
919 for (j = 0; j < ARRAY_SIZE(port->read_urbs); ++j) { 907 for (j = 0; j < ARRAY_SIZE(port->read_urbs); ++j) {
920 set_bit(j, &port->read_urbs_free); 908 set_bit(j, &port->read_urbs_free);
921 port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); 909 port->read_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
922 if (!port->read_urbs[j]) { 910 if (!port->read_urbs[j])
923 dev_err(ddev, "No free urbs available\n");
924 goto probe_error; 911 goto probe_error;
925 }
926 port->bulk_in_buffers[j] = kmalloc(buffer_size, 912 port->bulk_in_buffers[j] = kmalloc(buffer_size,
927 GFP_KERNEL); 913 GFP_KERNEL);
928 if (!port->bulk_in_buffers[j]) { 914 if (!port->bulk_in_buffers[j])
929 dev_err(ddev, "Couldn't allocate bulk_in_buffer\n");
930 goto probe_error; 915 goto probe_error;
931 }
932 usb_fill_bulk_urb(port->read_urbs[j], dev, 916 usb_fill_bulk_urb(port->read_urbs[j], dev,
933 usb_rcvbulkpipe(dev, 917 usb_rcvbulkpipe(dev,
934 endpoint->bEndpointAddress), 918 endpoint->bEndpointAddress),
@@ -955,16 +939,12 @@ static int usb_serial_probe(struct usb_interface *interface,
955 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { 939 for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) {
956 set_bit(j, &port->write_urbs_free); 940 set_bit(j, &port->write_urbs_free);
957 port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); 941 port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL);
958 if (!port->write_urbs[j]) { 942 if (!port->write_urbs[j])
959 dev_err(ddev, "No free urbs available\n");
960 goto probe_error; 943 goto probe_error;
961 }
962 port->bulk_out_buffers[j] = kmalloc(buffer_size, 944 port->bulk_out_buffers[j] = kmalloc(buffer_size,
963 GFP_KERNEL); 945 GFP_KERNEL);
964 if (!port->bulk_out_buffers[j]) { 946 if (!port->bulk_out_buffers[j])
965 dev_err(ddev, "Couldn't allocate bulk_out_buffer\n");
966 goto probe_error; 947 goto probe_error;
967 }
968 usb_fill_bulk_urb(port->write_urbs[j], dev, 948 usb_fill_bulk_urb(port->write_urbs[j], dev,
969 usb_sndbulkpipe(dev, 949 usb_sndbulkpipe(dev,
970 endpoint->bEndpointAddress), 950 endpoint->bEndpointAddress),
@@ -982,19 +962,15 @@ static int usb_serial_probe(struct usb_interface *interface,
982 endpoint = interrupt_in_endpoint[i]; 962 endpoint = interrupt_in_endpoint[i];
983 port = serial->port[i]; 963 port = serial->port[i];
984 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 964 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
985 if (!port->interrupt_in_urb) { 965 if (!port->interrupt_in_urb)
986 dev_err(ddev, "No free urbs available\n");
987 goto probe_error; 966 goto probe_error;
988 }
989 buffer_size = usb_endpoint_maxp(endpoint); 967 buffer_size = usb_endpoint_maxp(endpoint);
990 port->interrupt_in_endpointAddress = 968 port->interrupt_in_endpointAddress =
991 endpoint->bEndpointAddress; 969 endpoint->bEndpointAddress;
992 port->interrupt_in_buffer = kmalloc(buffer_size, 970 port->interrupt_in_buffer = kmalloc(buffer_size,
993 GFP_KERNEL); 971 GFP_KERNEL);
994 if (!port->interrupt_in_buffer) { 972 if (!port->interrupt_in_buffer)
995 dev_err(ddev, "Couldn't allocate interrupt_in_buffer\n");
996 goto probe_error; 973 goto probe_error;
997 }
998 usb_fill_int_urb(port->interrupt_in_urb, dev, 974 usb_fill_int_urb(port->interrupt_in_urb, dev,
999 usb_rcvintpipe(dev, 975 usb_rcvintpipe(dev,
1000 endpoint->bEndpointAddress), 976 endpoint->bEndpointAddress),
@@ -1011,20 +987,16 @@ static int usb_serial_probe(struct usb_interface *interface,
1011 endpoint = interrupt_out_endpoint[i]; 987 endpoint = interrupt_out_endpoint[i];
1012 port = serial->port[i]; 988 port = serial->port[i];
1013 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 989 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
1014 if (!port->interrupt_out_urb) { 990 if (!port->interrupt_out_urb)
1015 dev_err(ddev, "No free urbs available\n");
1016 goto probe_error; 991 goto probe_error;
1017 }
1018 buffer_size = usb_endpoint_maxp(endpoint); 992 buffer_size = usb_endpoint_maxp(endpoint);
1019 port->interrupt_out_size = buffer_size; 993 port->interrupt_out_size = buffer_size;
1020 port->interrupt_out_endpointAddress = 994 port->interrupt_out_endpointAddress =
1021 endpoint->bEndpointAddress; 995 endpoint->bEndpointAddress;
1022 port->interrupt_out_buffer = kmalloc(buffer_size, 996 port->interrupt_out_buffer = kmalloc(buffer_size,
1023 GFP_KERNEL); 997 GFP_KERNEL);
1024 if (!port->interrupt_out_buffer) { 998 if (!port->interrupt_out_buffer)
1025 dev_err(ddev, "Couldn't allocate interrupt_out_buffer\n");
1026 goto probe_error; 999 goto probe_error;
1027 }
1028 usb_fill_int_urb(port->interrupt_out_urb, dev, 1000 usb_fill_int_urb(port->interrupt_out_urb, dev,
1029 usb_sndintpipe(dev, 1001 usb_sndintpipe(dev,
1030 endpoint->bEndpointAddress), 1002 endpoint->bEndpointAddress),
@@ -1113,13 +1085,15 @@ static void usb_serial_disconnect(struct usb_interface *interface)
1113 tty_vhangup(tty); 1085 tty_vhangup(tty);
1114 tty_kref_put(tty); 1086 tty_kref_put(tty);
1115 } 1087 }
1116 kill_traffic(port); 1088 usb_serial_port_poison_urbs(port);
1089 wake_up_interruptible(&port->port.delta_msr_wait);
1117 cancel_work_sync(&port->work); 1090 cancel_work_sync(&port->work);
1118 if (device_is_registered(&port->dev)) 1091 if (device_is_registered(&port->dev))
1119 device_del(&port->dev); 1092 device_del(&port->dev);
1120 } 1093 }
1121 } 1094 }
1122 serial->type->disconnect(serial); 1095 if (serial->type->disconnect)
1096 serial->type->disconnect(serial);
1123 1097
1124 /* let the last holder of this object cause it to be cleaned up */ 1098 /* let the last holder of this object cause it to be cleaned up */
1125 usb_serial_put(serial); 1099 usb_serial_put(serial);
@@ -1134,6 +1108,11 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1134 1108
1135 serial->suspending = 1; 1109 serial->suspending = 1;
1136 1110
1111 /*
1112 * serial->type->suspend() MUST return 0 in system sleep context,
1113 * otherwise, the resume callback has to recover device from
1114 * previous suspend failure.
1115 */
1137 if (serial->type->suspend) { 1116 if (serial->type->suspend) {
1138 r = serial->type->suspend(serial, message); 1117 r = serial->type->suspend(serial, message);
1139 if (r < 0) { 1118 if (r < 0) {
@@ -1145,7 +1124,7 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1145 for (i = 0; i < serial->num_ports; ++i) { 1124 for (i = 0; i < serial->num_ports; ++i) {
1146 port = serial->port[i]; 1125 port = serial->port[i];
1147 if (port) 1126 if (port)
1148 kill_traffic(port); 1127 usb_serial_port_poison_urbs(port);
1149 } 1128 }
1150 1129
1151err_out: 1130err_out:
@@ -1153,11 +1132,25 @@ err_out:
1153} 1132}
1154EXPORT_SYMBOL(usb_serial_suspend); 1133EXPORT_SYMBOL(usb_serial_suspend);
1155 1134
1135static void usb_serial_unpoison_port_urbs(struct usb_serial *serial)
1136{
1137 struct usb_serial_port *port;
1138 int i;
1139
1140 for (i = 0; i < serial->num_ports; ++i) {
1141 port = serial->port[i];
1142 if (port)
1143 usb_serial_port_unpoison_urbs(port);
1144 }
1145}
1146
1156int usb_serial_resume(struct usb_interface *intf) 1147int usb_serial_resume(struct usb_interface *intf)
1157{ 1148{
1158 struct usb_serial *serial = usb_get_intfdata(intf); 1149 struct usb_serial *serial = usb_get_intfdata(intf);
1159 int rv; 1150 int rv;
1160 1151
1152 usb_serial_unpoison_port_urbs(serial);
1153
1161 serial->suspending = 0; 1154 serial->suspending = 0;
1162 if (serial->type->resume) 1155 if (serial->type->resume)
1163 rv = serial->type->resume(serial); 1156 rv = serial->type->resume(serial);
@@ -1173,6 +1166,8 @@ static int usb_serial_reset_resume(struct usb_interface *intf)
1173 struct usb_serial *serial = usb_get_intfdata(intf); 1166 struct usb_serial *serial = usb_get_intfdata(intf);
1174 int rv; 1167 int rv;
1175 1168
1169 usb_serial_unpoison_port_urbs(serial);
1170
1176 serial->suspending = 0; 1171 serial->suspending = 0;
1177 if (serial->type->reset_resume) 1172 if (serial->type->reset_resume)
1178 rv = serial->type->reset_resume(serial); 1173 rv = serial->type->reset_resume(serial);
@@ -1309,12 +1304,12 @@ module_exit(usb_serial_exit);
1309 do { \ 1304 do { \
1310 if (!type->function) { \ 1305 if (!type->function) { \
1311 type->function = usb_serial_generic_##function; \ 1306 type->function = usb_serial_generic_##function; \
1312 pr_debug("Had to override the " #function \ 1307 pr_debug("%s: using generic " #function "\n", \
1313 " usb serial operation with the generic one.");\ 1308 type->driver.name); \
1314 } \ 1309 } \
1315 } while (0) 1310 } while (0)
1316 1311
1317static void fixup_generic(struct usb_serial_driver *device) 1312static void usb_serial_operations_init(struct usb_serial_driver *device)
1318{ 1313{
1319 set_to_generic_if_null(device, open); 1314 set_to_generic_if_null(device, open);
1320 set_to_generic_if_null(device, write); 1315 set_to_generic_if_null(device, write);
@@ -1323,8 +1318,6 @@ static void fixup_generic(struct usb_serial_driver *device)
1323 set_to_generic_if_null(device, chars_in_buffer); 1318 set_to_generic_if_null(device, chars_in_buffer);
1324 set_to_generic_if_null(device, read_bulk_callback); 1319 set_to_generic_if_null(device, read_bulk_callback);
1325 set_to_generic_if_null(device, write_bulk_callback); 1320 set_to_generic_if_null(device, write_bulk_callback);
1326 set_to_generic_if_null(device, disconnect);
1327 set_to_generic_if_null(device, release);
1328 set_to_generic_if_null(device, process_read_urb); 1321 set_to_generic_if_null(device, process_read_urb);
1329 set_to_generic_if_null(device, prepare_write_buffer); 1322 set_to_generic_if_null(device, prepare_write_buffer);
1330} 1323}
@@ -1336,8 +1329,6 @@ static int usb_serial_register(struct usb_serial_driver *driver)
1336 if (usb_disabled()) 1329 if (usb_disabled())
1337 return -ENODEV; 1330 return -ENODEV;
1338 1331
1339 fixup_generic(driver);
1340
1341 if (!driver->description) 1332 if (!driver->description)
1342 driver->description = driver->driver.name; 1333 driver->description = driver->driver.name;
1343 if (!driver->usb_driver) { 1334 if (!driver->usb_driver) {
@@ -1346,6 +1337,8 @@ static int usb_serial_register(struct usb_serial_driver *driver)
1346 return -EINVAL; 1337 return -EINVAL;
1347 } 1338 }
1348 1339
1340 usb_serial_operations_init(driver);
1341
1349 /* Add this device to our list of devices */ 1342 /* Add this device to our list of devices */
1350 mutex_lock(&table_lock); 1343 mutex_lock(&table_lock);
1351 list_add(&driver->driver_list, &usb_serial_driver_list); 1344 list_add(&driver->driver_list, &usb_serial_driver_list);
@@ -1463,7 +1456,6 @@ void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_driver
1463} 1456}
1464EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers); 1457EXPORT_SYMBOL_GPL(usb_serial_deregister_drivers);
1465 1458
1466/* Module information */
1467MODULE_AUTHOR(DRIVER_AUTHOR); 1459MODULE_AUTHOR(DRIVER_AUTHOR);
1468MODULE_DESCRIPTION(DRIVER_DESC); 1460MODULE_DESCRIPTION(DRIVER_DESC);
1469MODULE_LICENSE("GPL"); 1461MODULE_LICENSE("GPL");
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 571965aa1cc0..ece326ef63a0 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -421,20 +421,19 @@ void usb_wwan_close(struct usb_serial_port *port)
421 421
422 portdata = usb_get_serial_port_data(port); 422 portdata = usb_get_serial_port_data(port);
423 423
424 if (serial->dev) { 424 /* Stop reading/writing urbs */
425 /* Stop reading/writing urbs */ 425 spin_lock_irq(&intfdata->susp_lock);
426 spin_lock_irq(&intfdata->susp_lock); 426 portdata->opened = 0;
427 portdata->opened = 0; 427 spin_unlock_irq(&intfdata->susp_lock);
428 spin_unlock_irq(&intfdata->susp_lock);
429 428
430 for (i = 0; i < N_IN_URB; i++) 429 for (i = 0; i < N_IN_URB; i++)
431 usb_kill_urb(portdata->in_urbs[i]); 430 usb_kill_urb(portdata->in_urbs[i]);
432 for (i = 0; i < N_OUT_URB; i++) 431 for (i = 0; i < N_OUT_URB; i++)
433 usb_kill_urb(portdata->out_urbs[i]); 432 usb_kill_urb(portdata->out_urbs[i]);
434 /* balancing - important as an error cannot be handled*/ 433
435 usb_autopm_get_interface_no_resume(serial->interface); 434 /* balancing - important as an error cannot be handled*/
436 serial->interface->needs_remote_wakeup = 0; 435 usb_autopm_get_interface_no_resume(serial->interface);
437 } 436 serial->interface->needs_remote_wakeup = 0;
438} 437}
439EXPORT_SYMBOL(usb_wwan_close); 438EXPORT_SYMBOL(usb_wwan_close);
440 439
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 1129aa73c23e..7573ec8a084f 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -257,24 +257,18 @@ static void visor_close(struct usb_serial_port *port)
257{ 257{
258 unsigned char *transfer_buffer; 258 unsigned char *transfer_buffer;
259 259
260 /* shutdown our urbs */
261 usb_serial_generic_close(port); 260 usb_serial_generic_close(port);
262 usb_kill_urb(port->interrupt_in_urb); 261 usb_kill_urb(port->interrupt_in_urb);
263 262
264 mutex_lock(&port->serial->disc_mutex); 263 transfer_buffer = kmalloc(0x12, GFP_KERNEL);
265 if (!port->serial->disconnected) { 264 if (!transfer_buffer)
266 /* Try to send shutdown message, unless the device is gone */ 265 return;
267 transfer_buffer = kmalloc(0x12, GFP_KERNEL); 266 usb_control_msg(port->serial->dev,
268 if (transfer_buffer) {
269 usb_control_msg(port->serial->dev,
270 usb_rcvctrlpipe(port->serial->dev, 0), 267 usb_rcvctrlpipe(port->serial->dev, 0),
271 VISOR_CLOSE_NOTIFICATION, 0xc2, 268 VISOR_CLOSE_NOTIFICATION, 0xc2,
272 0x0000, 0x0000, 269 0x0000, 0x0000,
273 transfer_buffer, 0x12, 300); 270 transfer_buffer, 0x12, 300);
274 kfree(transfer_buffer); 271 kfree(transfer_buffer);
275 }
276 }
277 mutex_unlock(&port->serial->disc_mutex);
278} 272}
279 273
280static void visor_read_int_callback(struct urb *urb) 274static void visor_read_int_callback(struct urb *urb)
diff --git a/drivers/usb/serial/wishbone-serial.c b/drivers/usb/serial/wishbone-serial.c
new file mode 100644
index 000000000000..100573c6f19e
--- /dev/null
+++ b/drivers/usb/serial/wishbone-serial.c
@@ -0,0 +1,95 @@
1/*
2 * USB Wishbone-Serial adapter driver
3 *
4 * Copyright (C) 2013 Wesley W. Terpstra <w.terpstra@gsi.de>
5 * Copyright (C) 2013 GSI Helmholtz Centre for Heavy Ion Research GmbH
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 */
12
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/tty.h>
16#include <linux/module.h>
17#include <linux/usb.h>
18#include <linux/usb/serial.h>
19#include <linux/uaccess.h>
20
21#define GSI_VENDOR_OPENCLOSE 0xB0
22
23static const struct usb_device_id id_table[] = {
24 { USB_DEVICE_AND_INTERFACE_INFO(0x1D50, 0x6062, 0xFF, 0xFF, 0xFF) },
25 { },
26};
27MODULE_DEVICE_TABLE(usb, id_table);
28
29/*
30 * Etherbone must be told that a new stream has begun before data arrives.
31 * This is necessary to restart the negotiation of Wishbone bus parameters.
32 * Similarly, when the stream ends, Etherbone must be told so that the cycle
33 * line can be driven low in the case that userspace failed to do so.
34 */
35static int usb_gsi_openclose(struct usb_serial_port *port, int value)
36{
37 struct usb_device *dev = port->serial->dev;
38
39 return usb_control_msg(
40 dev,
41 usb_sndctrlpipe(dev, 0), /* Send to EP0OUT */
42 GSI_VENDOR_OPENCLOSE,
43 USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE,
44 value, /* wValue = device is open(1) or closed(0) */
45 port->serial->interface->cur_altsetting->desc.bInterfaceNumber,
46 NULL, 0, /* There is no data stage */
47 5000); /* Timeout till operation fails */
48}
49
50static int wishbone_serial_open(struct tty_struct *tty,
51 struct usb_serial_port *port)
52{
53 int retval;
54
55 retval = usb_gsi_openclose(port, 1);
56 if (retval) {
57 dev_err(&port->serial->dev->dev,
58 "Could not mark device as open (%d)\n",
59 retval);
60 return retval;
61 }
62
63 retval = usb_serial_generic_open(tty, port);
64 if (retval)
65 usb_gsi_openclose(port, 0);
66
67 return retval;
68}
69
70static void wishbone_serial_close(struct usb_serial_port *port)
71{
72 usb_serial_generic_close(port);
73 usb_gsi_openclose(port, 0);
74}
75
76static struct usb_serial_driver wishbone_serial_device = {
77 .driver = {
78 .owner = THIS_MODULE,
79 .name = "wishbone_serial",
80 },
81 .id_table = id_table,
82 .num_ports = 1,
83 .open = &wishbone_serial_open,
84 .close = &wishbone_serial_close,
85};
86
87static struct usb_serial_driver * const serial_drivers[] = {
88 &wishbone_serial_device, NULL
89};
90
91module_usb_serial_driver(serial_drivers, id_table);
92
93MODULE_AUTHOR("Wesley W. Terpstra <w.terpstra@gsi.de>");
94MODULE_DESCRIPTION("USB Wishbone-Serial adapter");
95MODULE_LICENSE("GPL");
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index eab04a6b5fbc..8470e1b114f2 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -4,11 +4,10 @@
4 4
5comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may" 5comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may"
6comment "also be needed; see USB_STORAGE Help for more info" 6comment "also be needed; see USB_STORAGE Help for more info"
7 depends on USB
8 7
9config USB_STORAGE 8config USB_STORAGE
10 tristate "USB Mass Storage support" 9 tristate "USB Mass Storage support"
11 depends on USB && SCSI 10 depends on SCSI
12 ---help--- 11 ---help---
13 Say Y here if you want to connect USB mass storage devices to your 12 Say Y here if you want to connect USB mass storage devices to your
14 computer's USB port. This is the driver you need for USB 13 computer's USB port. This is the driver you need for USB
@@ -188,7 +187,7 @@ config USB_STORAGE_CYPRESS_ATACB
188 187
189config USB_STORAGE_ENE_UB6250 188config USB_STORAGE_ENE_UB6250
190 tristate "USB ENE card reader support" 189 tristate "USB ENE card reader support"
191 depends on USB && SCSI 190 depends on SCSI
192 depends on USB_STORAGE 191 depends on USB_STORAGE
193 ---help--- 192 ---help---
194 Say Y here if you wish to control a ENE SD/MS Card reader. 193 Say Y here if you wish to control a ENE SD/MS Card reader.
@@ -203,7 +202,7 @@ config USB_STORAGE_ENE_UB6250
203 202
204config USB_UAS 203config USB_UAS
205 tristate "USB Attached SCSI" 204 tristate "USB Attached SCSI"
206 depends on USB && SCSI && BROKEN 205 depends on SCSI && BROKEN
207 help 206 help
208 The USB Attached SCSI protocol is supported by some USB 207 The USB Attached SCSI protocol is supported by some USB
209 storage devices. It permits higher performance by supporting 208 storage devices. It permits higher performance by supporting
diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index be5564cc8e01..77a2ddfe6487 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -326,8 +326,7 @@ static int alauda_get_media_status(struct us_data *us, unsigned char *data)
326 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe, 326 rc = usb_stor_ctrl_transfer(us, us->recv_ctrl_pipe,
327 command, 0xc0, 0, 1, data, 2); 327 command, 0xc0, 0, 1, data, 2);
328 328
329 US_DEBUGP("alauda_get_media_status: Media status %02X %02X\n", 329 usb_stor_dbg(us, "Media status %02X %02X\n", data[0], data[1]);
330 data[0], data[1]);
331 330
332 return rc; 331 return rc;
333} 332}
@@ -402,7 +401,7 @@ static int alauda_init_media(struct us_data *us)
402 ready = 1; 401 ready = 1;
403 } 402 }
404 403
405 US_DEBUGP("alauda_init_media: We are ready for action!\n"); 404 usb_stor_dbg(us, "We are ready for action!\n");
406 405
407 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD) 406 if (alauda_ack_media(us) != USB_STOR_XFER_GOOD)
408 return USB_STOR_TRANSPORT_ERROR; 407 return USB_STOR_TRANSPORT_ERROR;
@@ -413,15 +412,15 @@ static int alauda_init_media(struct us_data *us)
413 return USB_STOR_TRANSPORT_ERROR; 412 return USB_STOR_TRANSPORT_ERROR;
414 413
415 if (data[0] != 0x14) { 414 if (data[0] != 0x14) {
416 US_DEBUGP("alauda_init_media: Media not ready after ack\n"); 415 usb_stor_dbg(us, "Media not ready after ack\n");
417 return USB_STOR_TRANSPORT_ERROR; 416 return USB_STOR_TRANSPORT_ERROR;
418 } 417 }
419 418
420 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD) 419 if (alauda_get_media_signature(us, data) != USB_STOR_XFER_GOOD)
421 return USB_STOR_TRANSPORT_ERROR; 420 return USB_STOR_TRANSPORT_ERROR;
422 421
423 US_DEBUGP("alauda_init_media: Media signature: %02X %02X %02X %02X\n", 422 usb_stor_dbg(us, "Media signature: %02X %02X %02X %02X\n",
424 data[0], data[1], data[2], data[3]); 423 data[0], data[1], data[2], data[3]);
425 media_info = alauda_card_find_id(data[1]); 424 media_info = alauda_card_find_id(data[1]);
426 if (media_info == NULL) { 425 if (media_info == NULL) {
427 printk(KERN_WARNING 426 printk(KERN_WARNING
@@ -432,8 +431,8 @@ static int alauda_init_media(struct us_data *us)
432 } 431 }
433 432
434 MEDIA_INFO(us).capacity = 1 << media_info->chipshift; 433 MEDIA_INFO(us).capacity = 1 << media_info->chipshift;
435 US_DEBUGP("Found media with capacity: %ldMB\n", 434 usb_stor_dbg(us, "Found media with capacity: %ldMB\n",
436 MEDIA_INFO(us).capacity >> 20); 435 MEDIA_INFO(us).capacity >> 20);
437 436
438 MEDIA_INFO(us).pageshift = media_info->pageshift; 437 MEDIA_INFO(us).pageshift = media_info->pageshift;
439 MEDIA_INFO(us).blockshift = media_info->blockshift; 438 MEDIA_INFO(us).blockshift = media_info->blockshift;
@@ -472,7 +471,7 @@ static int alauda_check_media(struct us_data *us)
472 /* Check for no media or door open */ 471 /* Check for no media or door open */
473 if ((status[0] & 0x80) || ((status[0] & 0x1F) == 0x10) 472 if ((status[0] & 0x80) || ((status[0] & 0x1F) == 0x10)
474 || ((status[1] & 0x01) == 0)) { 473 || ((status[1] & 0x01) == 0)) {
475 US_DEBUGP("alauda_check_media: No media, or door open\n"); 474 usb_stor_dbg(us, "No media, or door open\n");
476 alauda_free_maps(&MEDIA_INFO(us)); 475 alauda_free_maps(&MEDIA_INFO(us));
477 info->sense_key = 0x02; 476 info->sense_key = 0x02;
478 info->sense_asc = 0x3A; 477 info->sense_asc = 0x3A;
@@ -482,7 +481,7 @@ static int alauda_check_media(struct us_data *us)
482 481
483 /* Check for media change */ 482 /* Check for media change */
484 if (status[0] & 0x08) { 483 if (status[0] & 0x08) {
485 US_DEBUGP("alauda_check_media: Media change detected\n"); 484 usb_stor_dbg(us, "Media change detected\n");
486 alauda_free_maps(&MEDIA_INFO(us)); 485 alauda_free_maps(&MEDIA_INFO(us));
487 alauda_init_media(us); 486 alauda_init_media(us);
488 487
@@ -518,7 +517,7 @@ static int alauda_check_status2(struct us_data *us)
518 if (rc != USB_STOR_XFER_GOOD) 517 if (rc != USB_STOR_XFER_GOOD)
519 return rc; 518 return rc;
520 519
521 US_DEBUGP("alauda_check_status2: %02X %02X %02X\n", data[0], data[1], data[2]); 520 usb_stor_dbg(us, "%02X %02X %02X\n", data[0], data[1], data[2]);
522 if (data[0] & ALAUDA_STATUS_ERROR) 521 if (data[0] & ALAUDA_STATUS_ERROR)
523 return USB_STOR_XFER_ERROR; 522 return USB_STOR_XFER_ERROR;
524 523
@@ -584,7 +583,7 @@ static int alauda_read_map(struct us_data *us, unsigned int zone)
584 goto error; 583 goto error;
585 } 584 }
586 585
587 US_DEBUGP("alauda_read_map: Mapping blocks for zone %d\n", zone); 586 usb_stor_dbg(us, "Mapping blocks for zone %d\n", zone);
588 587
589 /* 1024 PBA's per zone */ 588 /* 1024 PBA's per zone */
590 for (i = 0; i < zonesize; i++) 589 for (i = 0; i < zonesize; i++)
@@ -604,7 +603,7 @@ static int alauda_read_map(struct us_data *us, unsigned int zone)
604 if (data[j] != 0) 603 if (data[j] != 0)
605 goto nonz; 604 goto nonz;
606 pba_to_lba[i] = UNUSABLE; 605 pba_to_lba[i] = UNUSABLE;
607 US_DEBUGP("alauda_read_map: PBA %d has no logical mapping\n", blocknum); 606 usb_stor_dbg(us, "PBA %d has no logical mapping\n", blocknum);
608 continue; 607 continue;
609 608
610 nonz: 609 nonz:
@@ -617,19 +616,18 @@ static int alauda_read_map(struct us_data *us, unsigned int zone)
617 nonff: 616 nonff:
618 /* normal PBAs start with six FFs */ 617 /* normal PBAs start with six FFs */
619 if (j < 6) { 618 if (j < 6) {
620 US_DEBUGP("alauda_read_map: PBA %d has no logical mapping: " 619 usb_stor_dbg(us, "PBA %d has no logical mapping: reserved area = %02X%02X%02X%02X data status %02X block status %02X\n",
621 "reserved area = %02X%02X%02X%02X " 620 blocknum,
622 "data status %02X block status %02X\n", 621 data[0], data[1], data[2], data[3],
623 blocknum, data[0], data[1], data[2], data[3], 622 data[4], data[5]);
624 data[4], data[5]);
625 pba_to_lba[i] = UNUSABLE; 623 pba_to_lba[i] = UNUSABLE;
626 continue; 624 continue;
627 } 625 }
628 626
629 if ((data[6] >> 4) != 0x01) { 627 if ((data[6] >> 4) != 0x01) {
630 US_DEBUGP("alauda_read_map: PBA %d has invalid address " 628 usb_stor_dbg(us, "PBA %d has invalid address field %02X%02X/%02X%02X\n",
631 "field %02X%02X/%02X%02X\n", 629 blocknum, data[6], data[7],
632 blocknum, data[6], data[7], data[11], data[12]); 630 data[11], data[12]);
633 pba_to_lba[i] = UNUSABLE; 631 pba_to_lba[i] = UNUSABLE;
634 continue; 632 continue;
635 } 633 }
@@ -711,7 +709,7 @@ static int alauda_erase_block(struct us_data *us, u16 pba)
711 }; 709 };
712 unsigned char buf[2]; 710 unsigned char buf[2];
713 711
714 US_DEBUGP("alauda_erase_block: Erasing PBA %d\n", pba); 712 usb_stor_dbg(us, "Erasing PBA %d\n", pba);
715 713
716 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 714 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
717 command, 9, NULL); 715 command, 9, NULL);
@@ -723,8 +721,7 @@ static int alauda_erase_block(struct us_data *us, u16 pba)
723 if (rc != USB_STOR_XFER_GOOD) 721 if (rc != USB_STOR_XFER_GOOD)
724 return rc; 722 return rc;
725 723
726 US_DEBUGP("alauda_erase_block: Erase result: %02X %02X\n", 724 usb_stor_dbg(us, "Erase result: %02X %02X\n", buf[0], buf[1]);
727 buf[0], buf[1]);
728 return rc; 725 return rc;
729} 726}
730 727
@@ -741,8 +738,7 @@ static int alauda_read_block_raw(struct us_data *us, u16 pba,
741 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us) 738 PBA_ZONE(pba), 0, PBA_LO(pba) + page, pages, 0, MEDIA_PORT(us)
742 }; 739 };
743 740
744 US_DEBUGP("alauda_read_block: pba %d page %d count %d\n", 741 usb_stor_dbg(us, "pba %d page %d count %d\n", pba, page, pages);
745 pba, page, pages);
746 742
747 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 743 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
748 command, 9, NULL); 744 command, 9, NULL);
@@ -793,7 +789,7 @@ static int alauda_write_block(struct us_data *us, u16 pba, unsigned char *data)
793 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us) 789 PBA_ZONE(pba), 0, PBA_LO(pba), 32, 0, MEDIA_PORT(us)
794 }; 790 };
795 791
796 US_DEBUGP("alauda_write_block: pba %d\n", pba); 792 usb_stor_dbg(us, "pba %d\n", pba);
797 793
798 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 794 rc = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
799 command, 9, NULL); 795 command, 9, NULL);
@@ -866,14 +862,14 @@ static int alauda_write_lba(struct us_data *us, u16 lba,
866 cptr = bptr + pagesize; 862 cptr = bptr + pagesize;
867 nand_compute_ecc(bptr, ecc); 863 nand_compute_ecc(bptr, ecc);
868 if (!nand_compare_ecc(cptr+13, ecc)) { 864 if (!nand_compare_ecc(cptr+13, ecc)) {
869 US_DEBUGP("Warning: bad ecc in page %d- of pba %d\n", 865 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n",
870 i, pba); 866 i, pba);
871 nand_store_ecc(cptr+13, ecc); 867 nand_store_ecc(cptr+13, ecc);
872 } 868 }
873 nand_compute_ecc(bptr + (pagesize / 2), ecc); 869 nand_compute_ecc(bptr + (pagesize / 2), ecc);
874 if (!nand_compare_ecc(cptr+8, ecc)) { 870 if (!nand_compare_ecc(cptr+8, ecc)) {
875 US_DEBUGP("Warning: bad ecc in page %d+ of pba %d\n", 871 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n",
876 i, pba); 872 i, pba);
877 nand_store_ecc(cptr+8, ecc); 873 nand_store_ecc(cptr+8, ecc);
878 } 874 }
879 cptr[6] = cptr[11] = MSB_of(lbap); 875 cptr[6] = cptr[11] = MSB_of(lbap);
@@ -900,8 +896,7 @@ static int alauda_write_lba(struct us_data *us, u16 lba,
900 new_pba_offset = new_pba - (zone * zonesize); 896 new_pba_offset = new_pba - (zone * zonesize);
901 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba; 897 MEDIA_INFO(us).pba_to_lba[zone][new_pba_offset] = lba;
902 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba; 898 MEDIA_INFO(us).lba_to_pba[zone][lba_offset] = new_pba;
903 US_DEBUGP("alauda_write_lba: Remapped LBA %d to PBA %d\n", 899 usb_stor_dbg(us, "Remapped LBA %d to PBA %d\n", lba, new_pba);
904 lba, new_pba);
905 900
906 if (pba != UNDEF) { 901 if (pba != UNDEF) {
907 unsigned int pba_offset = pba - (zone * zonesize); 902 unsigned int pba_offset = pba - (zone * zonesize);
@@ -964,8 +959,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
964 959
965 /* Not overflowing capacity? */ 960 /* Not overflowing capacity? */
966 if (lba >= max_lba) { 961 if (lba >= max_lba) {
967 US_DEBUGP("Error: Requested lba %u exceeds " 962 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
968 "maximum %u\n", lba, max_lba); 963 lba, max_lba);
969 result = USB_STOR_TRANSPORT_ERROR; 964 result = USB_STOR_TRANSPORT_ERROR;
970 break; 965 break;
971 } 966 }
@@ -978,8 +973,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
978 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset]; 973 pba = MEDIA_INFO(us).lba_to_pba[zone][lba_offset];
979 974
980 if (pba == UNDEF) { /* this lba was never written */ 975 if (pba == UNDEF) { /* this lba was never written */
981 US_DEBUGP("Read %d zero pages (LBA %d) page %d\n", 976 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n",
982 pages, lba, page); 977 pages, lba, page);
983 978
984 /* This is not really an error. It just means 979 /* This is not really an error. It just means
985 that the block has never been written. 980 that the block has never been written.
@@ -988,9 +983,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
988 983
989 memset(buffer, 0, len); 984 memset(buffer, 0, len);
990 } else { 985 } else {
991 US_DEBUGP("Read %d pages, from PBA %d" 986 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n",
992 " (LBA %d) page %d\n", 987 pages, pba, lba, page);
993 pages, pba, lba, page);
994 988
995 result = alauda_read_block(us, pba, page, pages, buffer); 989 result = alauda_read_block(us, pba, page, pages, buffer);
996 if (result != USB_STOR_TRANSPORT_GOOD) 990 if (result != USB_STOR_TRANSPORT_GOOD)
@@ -1066,8 +1060,8 @@ static int alauda_write_data(struct us_data *us, unsigned long address,
1066 1060
1067 /* Not overflowing capacity? */ 1061 /* Not overflowing capacity? */
1068 if (lba >= max_lba) { 1062 if (lba >= max_lba) {
1069 US_DEBUGP("alauda_write_data: Requested lba %u exceeds " 1063 usb_stor_dbg(us, "Requested lba %u exceeds maximum %u\n",
1070 "maximum %u\n", lba, max_lba); 1064 lba, max_lba);
1071 result = USB_STOR_TRANSPORT_ERROR; 1065 result = USB_STOR_TRANSPORT_ERROR;
1072 break; 1066 break;
1073 } 1067 }
@@ -1122,11 +1116,9 @@ static int init_alauda(struct us_data *us)
1122 nand_init_ecc(); 1116 nand_init_ecc();
1123 1117
1124 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO); 1118 us->extra = kzalloc(sizeof(struct alauda_info), GFP_NOIO);
1125 if (!us->extra) { 1119 if (!us->extra)
1126 US_DEBUGP("init_alauda: Gah! Can't allocate storage for"
1127 "alauda info struct!\n");
1128 return USB_STOR_TRANSPORT_ERROR; 1120 return USB_STOR_TRANSPORT_ERROR;
1129 } 1121
1130 info = (struct alauda_info *) us->extra; 1122 info = (struct alauda_info *) us->extra;
1131 us->extra_destructor = alauda_info_destructor; 1123 us->extra_destructor = alauda_info_destructor;
1132 1124
@@ -1147,15 +1139,14 @@ static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1147 }; 1139 };
1148 1140
1149 if (srb->cmnd[0] == INQUIRY) { 1141 if (srb->cmnd[0] == INQUIRY) {
1150 US_DEBUGP("alauda_transport: INQUIRY. " 1142 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
1151 "Returning bogus response.\n");
1152 memcpy(ptr, inquiry_response, sizeof(inquiry_response)); 1143 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
1153 fill_inquiry_response(us, ptr, 36); 1144 fill_inquiry_response(us, ptr, 36);
1154 return USB_STOR_TRANSPORT_GOOD; 1145 return USB_STOR_TRANSPORT_GOOD;
1155 } 1146 }
1156 1147
1157 if (srb->cmnd[0] == TEST_UNIT_READY) { 1148 if (srb->cmnd[0] == TEST_UNIT_READY) {
1158 US_DEBUGP("alauda_transport: TEST_UNIT_READY.\n"); 1149 usb_stor_dbg(us, "TEST_UNIT_READY\n");
1159 return alauda_check_media(us); 1150 return alauda_check_media(us);
1160 } 1151 }
1161 1152
@@ -1193,8 +1184,7 @@ static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1193 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); 1184 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1194 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); 1185 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1195 1186
1196 US_DEBUGP("alauda_transport: READ_10: page %d pagect %d\n", 1187 usb_stor_dbg(us, "READ_10: page %d pagect %d\n", page, pages);
1197 page, pages);
1198 1188
1199 return alauda_read_data(us, page, pages); 1189 return alauda_read_data(us, page, pages);
1200 } 1190 }
@@ -1211,14 +1201,13 @@ static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1211 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); 1201 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1212 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); 1202 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1213 1203
1214 US_DEBUGP("alauda_transport: WRITE_10: page %d pagect %d\n", 1204 usb_stor_dbg(us, "WRITE_10: page %d pagect %d\n", page, pages);
1215 page, pages);
1216 1205
1217 return alauda_write_data(us, page, pages); 1206 return alauda_write_data(us, page, pages);
1218 } 1207 }
1219 1208
1220 if (srb->cmnd[0] == REQUEST_SENSE) { 1209 if (srb->cmnd[0] == REQUEST_SENSE) {
1221 US_DEBUGP("alauda_transport: REQUEST_SENSE.\n"); 1210 usb_stor_dbg(us, "REQUEST_SENSE\n");
1222 1211
1223 memset(ptr, 0, 18); 1212 memset(ptr, 0, 18);
1224 ptr[0] = 0xF0; 1213 ptr[0] = 0xF0;
@@ -1237,8 +1226,8 @@ static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1237 return USB_STOR_TRANSPORT_GOOD; 1226 return USB_STOR_TRANSPORT_GOOD;
1238 } 1227 }
1239 1228
1240 US_DEBUGP("alauda_transport: Gah! Unknown command: %d (0x%x)\n", 1229 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
1241 srb->cmnd[0], srb->cmnd[0]); 1230 srb->cmnd[0], srb->cmnd[0]);
1242 info->sense_key = 0x05; 1231 info->sense_key = 0x05;
1243 info->sense_asc = 0x20; 1232 info->sense_asc = 0x20;
1244 info->sense_ascq = 0x00; 1233 info->sense_ascq = 0x00;
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index 070b5c0ebbf9..8514a2d82b72 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -159,7 +159,7 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
159 if (srb->result == SAM_STAT_CHECK_CONDITION && 159 if (srb->result == SAM_STAT_CHECK_CONDITION &&
160 memcmp(srb->sense_buffer, usb_stor_sense_invalidCDB, 160 memcmp(srb->sense_buffer, usb_stor_sense_invalidCDB,
161 sizeof(usb_stor_sense_invalidCDB)) == 0) { 161 sizeof(usb_stor_sense_invalidCDB)) == 0) {
162 US_DEBUGP("cypress atacb not supported ???\n"); 162 usb_stor_dbg(us, "cypress atacb not supported ???\n");
163 goto end; 163 goto end;
164 } 164 }
165 165
@@ -248,14 +248,26 @@ static int cypress_probe(struct usb_interface *intf,
248{ 248{
249 struct us_data *us; 249 struct us_data *us;
250 int result; 250 int result;
251 struct usb_device *device;
251 252
252 result = usb_stor_probe1(&us, intf, id, 253 result = usb_stor_probe1(&us, intf, id,
253 (id - cypress_usb_ids) + cypress_unusual_dev_list); 254 (id - cypress_usb_ids) + cypress_unusual_dev_list);
254 if (result) 255 if (result)
255 return result; 256 return result;
256 257
257 us->protocol_name = "Transparent SCSI with Cypress ATACB"; 258 /* Among CY7C68300 chips, the A revision does not support Cypress ATACB
258 us->proto_handler = cypress_atacb_passthrough; 259 * Filter out this revision from EEPROM default descriptor values
260 */
261 device = interface_to_usbdev(intf);
262 if (device->descriptor.iManufacturer != 0x38 ||
263 device->descriptor.iProduct != 0x4e ||
264 device->descriptor.iSerialNumber != 0x64) {
265 us->protocol_name = "Transparent SCSI with Cypress ATACB";
266 us->proto_handler = cypress_atacb_passthrough;
267 } else {
268 us->protocol_name = "Transparent SCSI";
269 us->proto_handler = usb_stor_transparent_scsi_command;
270 }
259 271
260 result = usb_stor_probe2(us); 272 result = usb_stor_probe2(us);
261 return result; 273 return result;
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 494fee5af41d..7b17c2169812 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -123,7 +123,7 @@ datafab_bulk_read(struct us_data *us, unsigned char *data, unsigned int len) {
123 if (len == 0) 123 if (len == 0)
124 return USB_STOR_XFER_GOOD; 124 return USB_STOR_XFER_GOOD;
125 125
126 US_DEBUGP("datafab_bulk_read: len = %d\n", len); 126 usb_stor_dbg(us, "len = %d\n", len);
127 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 127 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
128 data, len, NULL); 128 data, len, NULL);
129} 129}
@@ -134,7 +134,7 @@ datafab_bulk_write(struct us_data *us, unsigned char *data, unsigned int len) {
134 if (len == 0) 134 if (len == 0)
135 return USB_STOR_XFER_GOOD; 135 return USB_STOR_XFER_GOOD;
136 136
137 US_DEBUGP("datafab_bulk_write: len = %d\n", len); 137 usb_stor_dbg(us, "len = %d\n", len);
138 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 138 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
139 data, len, NULL); 139 data, len, NULL);
140} 140}
@@ -300,9 +300,8 @@ static int datafab_write_data(struct us_data *us,
300 goto leave; 300 goto leave;
301 301
302 if (reply[0] != 0x50 && reply[1] != 0) { 302 if (reply[0] != 0x50 && reply[1] != 0) {
303 US_DEBUGP("datafab_write_data: Gah! " 303 usb_stor_dbg(us, "Gah! write return code: %02x %02x\n",
304 "write return code: %02x %02x\n", 304 reply[0], reply[1]);
305 reply[0], reply[1]);
306 result = USB_STOR_TRANSPORT_ERROR; 305 result = USB_STOR_TRANSPORT_ERROR;
307 goto leave; 306 goto leave;
308 } 307 }
@@ -342,7 +341,7 @@ static int datafab_determine_lun(struct us_data *us,
342 if (!buf) 341 if (!buf)
343 return USB_STOR_TRANSPORT_ERROR; 342 return USB_STOR_TRANSPORT_ERROR;
344 343
345 US_DEBUGP("datafab_determine_lun: locating...\n"); 344 usb_stor_dbg(us, "locating...\n");
346 345
347 // we'll try 3 times before giving up... 346 // we'll try 3 times before giving up...
348 // 347 //
@@ -474,16 +473,16 @@ static int datafab_handle_mode_sense(struct us_data *us,
474 473
475 switch (pc) { 474 switch (pc) {
476 case 0x0: 475 case 0x0:
477 US_DEBUGP("datafab_handle_mode_sense: Current values\n"); 476 usb_stor_dbg(us, "Current values\n");
478 break; 477 break;
479 case 0x1: 478 case 0x1:
480 US_DEBUGP("datafab_handle_mode_sense: Changeable values\n"); 479 usb_stor_dbg(us, "Changeable values\n");
481 break; 480 break;
482 case 0x2: 481 case 0x2:
483 US_DEBUGP("datafab_handle_mode_sense: Default values\n"); 482 usb_stor_dbg(us, "Default values\n");
484 break; 483 break;
485 case 0x3: 484 case 0x3:
486 US_DEBUGP("datafab_handle_mode_sense: Saves values\n"); 485 usb_stor_dbg(us, "Saves values\n");
487 break; 486 break;
488 } 487 }
489 488
@@ -566,11 +565,9 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
566 565
567 if (!us->extra) { 566 if (!us->extra) {
568 us->extra = kzalloc(sizeof(struct datafab_info), GFP_NOIO); 567 us->extra = kzalloc(sizeof(struct datafab_info), GFP_NOIO);
569 if (!us->extra) { 568 if (!us->extra)
570 US_DEBUGP("datafab_transport: Gah! "
571 "Can't allocate storage for Datafab info struct!\n");
572 return USB_STOR_TRANSPORT_ERROR; 569 return USB_STOR_TRANSPORT_ERROR;
573 } 570
574 us->extra_destructor = datafab_info_destructor; 571 us->extra_destructor = datafab_info_destructor;
575 ((struct datafab_info *)us->extra)->lun = -1; 572 ((struct datafab_info *)us->extra)->lun = -1;
576 } 573 }
@@ -578,7 +575,7 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
578 info = (struct datafab_info *) (us->extra); 575 info = (struct datafab_info *) (us->extra);
579 576
580 if (srb->cmnd[0] == INQUIRY) { 577 if (srb->cmnd[0] == INQUIRY) {
581 US_DEBUGP("datafab_transport: INQUIRY. Returning bogus response"); 578 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
582 memcpy(ptr, inquiry_reply, sizeof(inquiry_reply)); 579 memcpy(ptr, inquiry_reply, sizeof(inquiry_reply));
583 fill_inquiry_response(us, ptr, 36); 580 fill_inquiry_response(us, ptr, 36);
584 return USB_STOR_TRANSPORT_GOOD; 581 return USB_STOR_TRANSPORT_GOOD;
@@ -590,8 +587,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
590 if (rc != USB_STOR_TRANSPORT_GOOD) 587 if (rc != USB_STOR_TRANSPORT_GOOD)
591 return rc; 588 return rc;
592 589
593 US_DEBUGP("datafab_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n", 590 usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
594 info->sectors, info->ssize); 591 info->sectors, info->ssize);
595 592
596 // build the reply 593 // build the reply
597 // we need the last sector, not the number of sectors 594 // we need the last sector, not the number of sectors
@@ -603,7 +600,7 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
603 } 600 }
604 601
605 if (srb->cmnd[0] == MODE_SELECT_10) { 602 if (srb->cmnd[0] == MODE_SELECT_10) {
606 US_DEBUGP("datafab_transport: Gah! MODE_SELECT_10.\n"); 603 usb_stor_dbg(us, "Gah! MODE_SELECT_10\n");
607 return USB_STOR_TRANSPORT_ERROR; 604 return USB_STOR_TRANSPORT_ERROR;
608 } 605 }
609 606
@@ -615,7 +612,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
615 612
616 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 613 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
617 614
618 US_DEBUGP("datafab_transport: READ_10: read block 0x%04lx count %ld\n", block, blocks); 615 usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n",
616 block, blocks);
619 return datafab_read_data(us, info, block, blocks); 617 return datafab_read_data(us, info, block, blocks);
620 } 618 }
621 619
@@ -628,7 +626,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
628 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 626 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
629 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 627 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
630 628
631 US_DEBUGP("datafab_transport: READ_12: read block 0x%04lx count %ld\n", block, blocks); 629 usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n",
630 block, blocks);
632 return datafab_read_data(us, info, block, blocks); 631 return datafab_read_data(us, info, block, blocks);
633 } 632 }
634 633
@@ -638,7 +637,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
638 637
639 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 638 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
640 639
641 US_DEBUGP("datafab_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks); 640 usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n",
641 block, blocks);
642 return datafab_write_data(us, info, block, blocks); 642 return datafab_write_data(us, info, block, blocks);
643 } 643 }
644 644
@@ -651,17 +651,18 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
651 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 651 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
652 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 652 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
653 653
654 US_DEBUGP("datafab_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks); 654 usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n",
655 block, blocks);
655 return datafab_write_data(us, info, block, blocks); 656 return datafab_write_data(us, info, block, blocks);
656 } 657 }
657 658
658 if (srb->cmnd[0] == TEST_UNIT_READY) { 659 if (srb->cmnd[0] == TEST_UNIT_READY) {
659 US_DEBUGP("datafab_transport: TEST_UNIT_READY.\n"); 660 usb_stor_dbg(us, "TEST_UNIT_READY\n");
660 return datafab_id_device(us, info); 661 return datafab_id_device(us, info);
661 } 662 }
662 663
663 if (srb->cmnd[0] == REQUEST_SENSE) { 664 if (srb->cmnd[0] == REQUEST_SENSE) {
664 US_DEBUGP("datafab_transport: REQUEST_SENSE. Returning faked response\n"); 665 usb_stor_dbg(us, "REQUEST_SENSE - Returning faked response\n");
665 666
666 // this response is pretty bogus right now. eventually if necessary 667 // this response is pretty bogus right now. eventually if necessary
667 // we can set the correct sense data. so far though it hasn't been 668 // we can set the correct sense data. so far though it hasn't been
@@ -679,12 +680,12 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
679 } 680 }
680 681
681 if (srb->cmnd[0] == MODE_SENSE) { 682 if (srb->cmnd[0] == MODE_SENSE) {
682 US_DEBUGP("datafab_transport: MODE_SENSE_6 detected\n"); 683 usb_stor_dbg(us, "MODE_SENSE_6 detected\n");
683 return datafab_handle_mode_sense(us, srb, 1); 684 return datafab_handle_mode_sense(us, srb, 1);
684 } 685 }
685 686
686 if (srb->cmnd[0] == MODE_SENSE_10) { 687 if (srb->cmnd[0] == MODE_SENSE_10) {
687 US_DEBUGP("datafab_transport: MODE_SENSE_10 detected\n"); 688 usb_stor_dbg(us, "MODE_SENSE_10 detected\n");
688 return datafab_handle_mode_sense(us, srb, 0); 689 return datafab_handle_mode_sense(us, srb, 0);
689 } 690 }
690 691
@@ -698,7 +699,7 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
698 if (srb->cmnd[0] == START_STOP) { 699 if (srb->cmnd[0] == START_STOP) {
699 /* this is used by sd.c'check_scsidisk_media_change to detect 700 /* this is used by sd.c'check_scsidisk_media_change to detect
700 media change */ 701 media change */
701 US_DEBUGP("datafab_transport: START_STOP.\n"); 702 usb_stor_dbg(us, "START_STOP\n");
702 /* the first datafab_id_device after a media change returns 703 /* the first datafab_id_device after a media change returns
703 an error (determined experimentally) */ 704 an error (determined experimentally) */
704 rc = datafab_id_device(us, info); 705 rc = datafab_id_device(us, info);
@@ -712,8 +713,8 @@ static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
712 return rc; 713 return rc;
713 } 714 }
714 715
715 US_DEBUGP("datafab_transport: Gah! Unknown command: %d (0x%x)\n", 716 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
716 srb->cmnd[0], srb->cmnd[0]); 717 srb->cmnd[0], srb->cmnd[0]);
717 info->sense_key = 0x05; 718 info->sense_key = 0x05;
718 info->sense_asc = 0x20; 719 info->sense_asc = 0x20;
719 info->sense_ascq = 0x00; 720 info->sense_ascq = 0x00;
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index a2b5526c9fa0..e08f64780e30 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -42,16 +42,19 @@
42 * 675 Mass Ave, Cambridge, MA 02139, USA. 42 * 675 Mass Ave, Cambridge, MA 02139, USA.
43 */ 43 */
44 44
45#include <linux/device.h>
45#include <linux/cdrom.h> 46#include <linux/cdrom.h>
47#include <linux/export.h>
46#include <scsi/scsi.h> 48#include <scsi/scsi.h>
47#include <scsi/scsi_cmnd.h> 49#include <scsi/scsi_cmnd.h>
48#include <scsi/scsi_dbg.h> 50#include <scsi/scsi_dbg.h>
49 51
52#include "usb.h"
50#include "debug.h" 53#include "debug.h"
51#include "scsi.h" 54#include "scsi.h"
52 55
53 56
54void usb_stor_show_command(struct scsi_cmnd *srb) 57void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
55{ 58{
56 char *what = NULL; 59 char *what = NULL;
57 int i; 60 int i;
@@ -149,18 +152,18 @@ void usb_stor_show_command(struct scsi_cmnd *srb)
149 case WRITE_LONG_2: what = "WRITE_LONG_2"; break; 152 case WRITE_LONG_2: what = "WRITE_LONG_2"; break;
150 default: what = "(unknown command)"; break; 153 default: what = "(unknown command)"; break;
151 } 154 }
152 US_DEBUGP("Command %s (%d bytes)\n", what, srb->cmd_len); 155 usb_stor_dbg(us, "Command %s (%d bytes)\n", what, srb->cmd_len);
153 US_DEBUGP(""); 156 usb_stor_dbg(us, "bytes: ");
154 for (i = 0; i < srb->cmd_len && i < 16; i++) 157 for (i = 0; i < srb->cmd_len && i < 16; i++)
155 US_DEBUGPX(" %02x", srb->cmnd[i]); 158 US_DEBUGPX(" %02x", srb->cmnd[i]);
156 US_DEBUGPX("\n"); 159 US_DEBUGPX("\n");
157} 160}
158 161
159void usb_stor_show_sense( 162void usb_stor_show_sense(const struct us_data *us,
160 unsigned char key, 163 unsigned char key,
161 unsigned char asc, 164 unsigned char asc,
162 unsigned char ascq) { 165 unsigned char ascq)
163 166{
164 const char *what, *keystr; 167 const char *what, *keystr;
165 168
166 keystr = scsi_sense_key_string(key); 169 keystr = scsi_sense_key_string(key);
@@ -171,7 +174,22 @@ void usb_stor_show_sense(
171 if (what == NULL) 174 if (what == NULL)
172 what = "(unknown ASC/ASCQ)"; 175 what = "(unknown ASC/ASCQ)";
173 176
174 US_DEBUGP("%s: ", keystr); 177 usb_stor_dbg(us, "%s: ", keystr);
175 US_DEBUGPX(what, ascq); 178 US_DEBUGPX(what, ascq);
176 US_DEBUGPX("\n"); 179 US_DEBUGPX("\n");
177} 180}
181
182int usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
183{
184 va_list args;
185 int r;
186
187 va_start(args, fmt);
188
189 r = dev_vprintk_emit(7, &us->pusb_dev->dev, fmt, args);
190
191 va_end(args);
192
193 return r;
194}
195EXPORT_SYMBOL_GPL(usb_stor_dbg);
diff --git a/drivers/usb/storage/debug.h b/drivers/usb/storage/debug.h
index dbb985d52423..b1273f03e223 100644
--- a/drivers/usb/storage/debug.h
+++ b/drivers/usb/storage/debug.h
@@ -47,15 +47,22 @@
47#define USB_STORAGE "usb-storage: " 47#define USB_STORAGE "usb-storage: "
48 48
49#ifdef CONFIG_USB_STORAGE_DEBUG 49#ifdef CONFIG_USB_STORAGE_DEBUG
50void usb_stor_show_command(struct scsi_cmnd *srb); 50void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb);
51void usb_stor_show_sense( unsigned char key, 51void usb_stor_show_sense(const struct us_data *us, unsigned char key,
52 unsigned char asc, unsigned char ascq ); 52 unsigned char asc, unsigned char ascq);
53#define US_DEBUGP(x...) printk( KERN_DEBUG USB_STORAGE x ) 53__printf(2, 3) int usb_stor_dbg(const struct us_data *us,
54#define US_DEBUGPX(x...) printk( x ) 54 const char *fmt, ...);
55#define US_DEBUG(x) x 55
56#define US_DEBUGPX(fmt, ...) printk(fmt, ##__VA_ARGS__)
57#define US_DEBUG(x) x
56#else 58#else
57#define US_DEBUGP(x...) 59__printf(2, 3)
58#define US_DEBUGPX(x...) 60static inline int _usb_stor_dbg(const struct us_data *us,
61 const char *fmt, ...) {return 1;}
62#define usb_stor_dbg(us, fmt, ...) \
63 do { if (0) _usb_stor_dbg(us, fmt, ##__VA_ARGS__); } while (0)
64#define US_DEBUGPX(fmt, ...) \
65 do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
59#define US_DEBUG(x) 66#define US_DEBUG(x)
60#endif 67#endif
61 68
diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c
index 118b134a1dad..1bfc9a6cab5f 100644
--- a/drivers/usb/storage/ene_ub6250.c
+++ b/drivers/usb/storage/ene_ub6250.c
@@ -504,12 +504,12 @@ static int ene_send_scsi_cmd(struct us_data *us, u8 fDir, void *buf, int use_sg)
504 unsigned int cswlen = 0, partial = 0; 504 unsigned int cswlen = 0, partial = 0;
505 unsigned int transfer_length = bcb->DataTransferLength; 505 unsigned int transfer_length = bcb->DataTransferLength;
506 506
507 /* US_DEBUGP("transport --- ene_send_scsi_cmd\n"); */ 507 /* usb_stor_dbg(us, "transport --- ene_send_scsi_cmd\n"); */
508 /* send cmd to out endpoint */ 508 /* send cmd to out endpoint */
509 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 509 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
510 bcb, US_BULK_CB_WRAP_LEN, NULL); 510 bcb, US_BULK_CB_WRAP_LEN, NULL);
511 if (result != USB_STOR_XFER_GOOD) { 511 if (result != USB_STOR_XFER_GOOD) {
512 US_DEBUGP("send cmd to out endpoint fail ---\n"); 512 usb_stor_dbg(us, "send cmd to out endpoint fail ---\n");
513 return USB_STOR_TRANSPORT_ERROR; 513 return USB_STOR_TRANSPORT_ERROR;
514 } 514 }
515 515
@@ -529,7 +529,7 @@ static int ene_send_scsi_cmd(struct us_data *us, u8 fDir, void *buf, int use_sg)
529 transfer_length, 0, &partial); 529 transfer_length, 0, &partial);
530 } 530 }
531 if (result != USB_STOR_XFER_GOOD) { 531 if (result != USB_STOR_XFER_GOOD) {
532 US_DEBUGP("data transfer fail ---\n"); 532 usb_stor_dbg(us, "data transfer fail ---\n");
533 return USB_STOR_TRANSPORT_ERROR; 533 return USB_STOR_TRANSPORT_ERROR;
534 } 534 }
535 } 535 }
@@ -539,14 +539,14 @@ static int ene_send_scsi_cmd(struct us_data *us, u8 fDir, void *buf, int use_sg)
539 US_BULK_CS_WRAP_LEN, &cswlen); 539 US_BULK_CS_WRAP_LEN, &cswlen);
540 540
541 if (result == USB_STOR_XFER_SHORT && cswlen == 0) { 541 if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
542 US_DEBUGP("Received 0-length CSW; retrying...\n"); 542 usb_stor_dbg(us, "Received 0-length CSW; retrying...\n");
543 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 543 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
544 bcs, US_BULK_CS_WRAP_LEN, &cswlen); 544 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
545 } 545 }
546 546
547 if (result == USB_STOR_XFER_STALLED) { 547 if (result == USB_STOR_XFER_STALLED) {
548 /* get the status again */ 548 /* get the status again */
549 US_DEBUGP("Attempting to get CSW (2nd try)...\n"); 549 usb_stor_dbg(us, "Attempting to get CSW (2nd try)...\n");
550 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 550 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
551 bcs, US_BULK_CS_WRAP_LEN, NULL); 551 bcs, US_BULK_CS_WRAP_LEN, NULL);
552 } 552 }
@@ -626,7 +626,7 @@ static int sd_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb)
626 struct scatterlist *sg = NULL; 626 struct scatterlist *sg = NULL;
627 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 627 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
628 628
629 US_DEBUGP("sd_scsi_read_capacity\n"); 629 usb_stor_dbg(us, "sd_scsi_read_capacity\n");
630 if (info->SD_Status.HiCapacity) { 630 if (info->SD_Status.HiCapacity) {
631 bl_len = 0x200; 631 bl_len = 0x200;
632 if (info->SD_Status.IsMMC) 632 if (info->SD_Status.IsMMC)
@@ -639,8 +639,8 @@ static int sd_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb)
639 * (1 << (info->SD_C_SIZE_MULT + 2)) - 1; 639 * (1 << (info->SD_C_SIZE_MULT + 2)) - 1;
640 } 640 }
641 info->bl_num = bl_num; 641 info->bl_num = bl_num;
642 US_DEBUGP("bl_len = %x\n", bl_len); 642 usb_stor_dbg(us, "bl_len = %x\n", bl_len);
643 US_DEBUGP("bl_num = %x\n", bl_num); 643 usb_stor_dbg(us, "bl_num = %x\n", bl_num);
644 644
645 /*srb->request_bufflen = 8; */ 645 /*srb->request_bufflen = 8; */
646 buf[0] = (bl_num >> 24) & 0xff; 646 buf[0] = (bl_num >> 24) & 0xff;
@@ -675,7 +675,7 @@ static int sd_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
675 675
676 result = ene_load_bincode(us, SD_RW_PATTERN); 676 result = ene_load_bincode(us, SD_RW_PATTERN);
677 if (result != USB_STOR_XFER_GOOD) { 677 if (result != USB_STOR_XFER_GOOD) {
678 US_DEBUGP("Load SD RW pattern Fail !!\n"); 678 usb_stor_dbg(us, "Load SD RW pattern Fail !!\n");
679 return USB_STOR_TRANSPORT_ERROR; 679 return USB_STOR_TRANSPORT_ERROR;
680 } 680 }
681 681
@@ -715,7 +715,7 @@ static int sd_scsi_write(struct us_data *us, struct scsi_cmnd *srb)
715 715
716 result = ene_load_bincode(us, SD_RW_PATTERN); 716 result = ene_load_bincode(us, SD_RW_PATTERN);
717 if (result != USB_STOR_XFER_GOOD) { 717 if (result != USB_STOR_XFER_GOOD) {
718 US_DEBUGP("Load SD RW pattern Fail !!\n"); 718 usb_stor_dbg(us, "Load SD RW pattern Fail !!\n");
719 return USB_STOR_TRANSPORT_ERROR; 719 return USB_STOR_TRANSPORT_ERROR;
720 } 720 }
721 721
@@ -1493,7 +1493,7 @@ static int ms_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb)
1493 struct scatterlist *sg = NULL; 1493 struct scatterlist *sg = NULL;
1494 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 1494 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
1495 1495
1496 US_DEBUGP("ms_scsi_read_capacity\n"); 1496 usb_stor_dbg(us, "ms_scsi_read_capacity\n");
1497 bl_len = 0x200; 1497 bl_len = 0x200;
1498 if (info->MS_Status.IsMSPro) 1498 if (info->MS_Status.IsMSPro)
1499 bl_num = info->MSP_TotalBlock - 1; 1499 bl_num = info->MSP_TotalBlock - 1;
@@ -1501,8 +1501,8 @@ static int ms_scsi_read_capacity(struct us_data *us, struct scsi_cmnd *srb)
1501 bl_num = info->MS_Lib.NumberOfLogBlock * info->MS_Lib.blockSize * 2 - 1; 1501 bl_num = info->MS_Lib.NumberOfLogBlock * info->MS_Lib.blockSize * 2 - 1;
1502 1502
1503 info->bl_num = bl_num; 1503 info->bl_num = bl_num;
1504 US_DEBUGP("bl_len = %x\n", bl_len); 1504 usb_stor_dbg(us, "bl_len = %x\n", bl_len);
1505 US_DEBUGP("bl_num = %x\n", bl_num); 1505 usb_stor_dbg(us, "bl_num = %x\n", bl_num);
1506 1506
1507 /*srb->request_bufflen = 8; */ 1507 /*srb->request_bufflen = 8; */
1508 buf[0] = (bl_num >> 24) & 0xff; 1508 buf[0] = (bl_num >> 24) & 0xff;
@@ -1654,7 +1654,7 @@ static int ms_scsi_read(struct us_data *us, struct scsi_cmnd *srb)
1654 if (info->MS_Status.IsMSPro) { 1654 if (info->MS_Status.IsMSPro) {
1655 result = ene_load_bincode(us, MSP_RW_PATTERN); 1655 result = ene_load_bincode(us, MSP_RW_PATTERN);
1656 if (result != USB_STOR_XFER_GOOD) { 1656 if (result != USB_STOR_XFER_GOOD) {
1657 US_DEBUGP("Load MPS RW pattern Fail !!\n"); 1657 usb_stor_dbg(us, "Load MPS RW pattern Fail !!\n");
1658 return USB_STOR_TRANSPORT_ERROR; 1658 return USB_STOR_TRANSPORT_ERROR;
1659 } 1659 }
1660 1660
@@ -1854,7 +1854,7 @@ static int ene_get_card_status(struct us_data *us, u8 *buf)
1854 u32 reg4b; 1854 u32 reg4b;
1855 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 1855 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
1856 1856
1857 /*US_DEBUGP("transport --- ENE_ReadSDReg\n");*/ 1857 /*usb_stor_dbg(us, "transport --- ENE_ReadSDReg\n");*/
1858 reg4b = *(u32 *)&buf[0x18]; 1858 reg4b = *(u32 *)&buf[0x18];
1859 info->SD_READ_BL_LEN = (u8)((reg4b >> 8) & 0x0f); 1859 info->SD_READ_BL_LEN = (u8)((reg4b >> 8) & 0x0f);
1860 1860
@@ -1894,45 +1894,44 @@ static int ene_load_bincode(struct us_data *us, unsigned char flag)
1894 switch (flag) { 1894 switch (flag) {
1895 /* For SD */ 1895 /* For SD */
1896 case SD_INIT1_PATTERN: 1896 case SD_INIT1_PATTERN:
1897 US_DEBUGP("SD_INIT1_PATTERN\n"); 1897 usb_stor_dbg(us, "SD_INIT1_PATTERN\n");
1898 fw_name = SD_INIT1_FIRMWARE; 1898 fw_name = SD_INIT1_FIRMWARE;
1899 break; 1899 break;
1900 case SD_INIT2_PATTERN: 1900 case SD_INIT2_PATTERN:
1901 US_DEBUGP("SD_INIT2_PATTERN\n"); 1901 usb_stor_dbg(us, "SD_INIT2_PATTERN\n");
1902 fw_name = SD_INIT2_FIRMWARE; 1902 fw_name = SD_INIT2_FIRMWARE;
1903 break; 1903 break;
1904 case SD_RW_PATTERN: 1904 case SD_RW_PATTERN:
1905 US_DEBUGP("SD_RW_PATTERN\n"); 1905 usb_stor_dbg(us, "SD_RW_PATTERN\n");
1906 fw_name = SD_RW_FIRMWARE; 1906 fw_name = SD_RW_FIRMWARE;
1907 break; 1907 break;
1908 /* For MS */ 1908 /* For MS */
1909 case MS_INIT_PATTERN: 1909 case MS_INIT_PATTERN:
1910 US_DEBUGP("MS_INIT_PATTERN\n"); 1910 usb_stor_dbg(us, "MS_INIT_PATTERN\n");
1911 fw_name = MS_INIT_FIRMWARE; 1911 fw_name = MS_INIT_FIRMWARE;
1912 break; 1912 break;
1913 case MSP_RW_PATTERN: 1913 case MSP_RW_PATTERN:
1914 US_DEBUGP("MSP_RW_PATTERN\n"); 1914 usb_stor_dbg(us, "MSP_RW_PATTERN\n");
1915 fw_name = MSP_RW_FIRMWARE; 1915 fw_name = MSP_RW_FIRMWARE;
1916 break; 1916 break;
1917 case MS_RW_PATTERN: 1917 case MS_RW_PATTERN:
1918 US_DEBUGP("MS_RW_PATTERN\n"); 1918 usb_stor_dbg(us, "MS_RW_PATTERN\n");
1919 fw_name = MS_RW_FIRMWARE; 1919 fw_name = MS_RW_FIRMWARE;
1920 break; 1920 break;
1921 default: 1921 default:
1922 US_DEBUGP("----------- Unknown PATTERN ----------\n"); 1922 usb_stor_dbg(us, "----------- Unknown PATTERN ----------\n");
1923 goto nofw; 1923 goto nofw;
1924 } 1924 }
1925 1925
1926 err = request_firmware(&sd_fw, fw_name, &us->pusb_dev->dev); 1926 err = request_firmware(&sd_fw, fw_name, &us->pusb_dev->dev);
1927 if (err) { 1927 if (err) {
1928 US_DEBUGP("load firmware %s failed\n", fw_name); 1928 usb_stor_dbg(us, "load firmware %s failed\n", fw_name);
1929 goto nofw; 1929 goto nofw;
1930 } 1930 }
1931 buf = kmalloc(sd_fw->size, GFP_KERNEL); 1931 buf = kmalloc(sd_fw->size, GFP_KERNEL);
1932 if (buf == NULL) { 1932 if (buf == NULL)
1933 US_DEBUGP("Malloc memory for fireware failed!\n");
1934 goto nofw; 1933 goto nofw;
1935 } 1934
1936 memcpy(buf, sd_fw->data, sd_fw->size); 1935 memcpy(buf, sd_fw->data, sd_fw->size);
1937 memset(bcb, 0, sizeof(struct bulk_cb_wrap)); 1936 memset(bcb, 0, sizeof(struct bulk_cb_wrap));
1938 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 1937 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
@@ -2116,9 +2115,9 @@ static int ene_ms_init(struct us_data *us)
2116 } else { 2115 } else {
2117 ms_card_init(us); /* Card is MS (to ms.c)*/ 2116 ms_card_init(us); /* Card is MS (to ms.c)*/
2118 } 2117 }
2119 US_DEBUGP("MS Init Code OK !!\n"); 2118 usb_stor_dbg(us, "MS Init Code OK !!\n");
2120 } else { 2119 } else {
2121 US_DEBUGP("MS Card Not Ready --- %x\n", buf[0]); 2120 usb_stor_dbg(us, "MS Card Not Ready --- %x\n", buf[0]);
2122 return USB_STOR_TRANSPORT_ERROR; 2121 return USB_STOR_TRANSPORT_ERROR;
2123 } 2122 }
2124 2123
@@ -2132,11 +2131,11 @@ static int ene_sd_init(struct us_data *us)
2132 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf; 2131 struct bulk_cb_wrap *bcb = (struct bulk_cb_wrap *) us->iobuf;
2133 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra; 2132 struct ene_ub6250_info *info = (struct ene_ub6250_info *) us->extra;
2134 2133
2135 US_DEBUGP("transport --- ENE_SDInit\n"); 2134 usb_stor_dbg(us, "transport --- ENE_SDInit\n");
2136 /* SD Init Part-1 */ 2135 /* SD Init Part-1 */
2137 result = ene_load_bincode(us, SD_INIT1_PATTERN); 2136 result = ene_load_bincode(us, SD_INIT1_PATTERN);
2138 if (result != USB_STOR_XFER_GOOD) { 2137 if (result != USB_STOR_XFER_GOOD) {
2139 US_DEBUGP("Load SD Init Code Part-1 Fail !!\n"); 2138 usb_stor_dbg(us, "Load SD Init Code Part-1 Fail !!\n");
2140 return USB_STOR_TRANSPORT_ERROR; 2139 return USB_STOR_TRANSPORT_ERROR;
2141 } 2140 }
2142 2141
@@ -2147,14 +2146,14 @@ static int ene_sd_init(struct us_data *us)
2147 2146
2148 result = ene_send_scsi_cmd(us, FDIR_READ, NULL, 0); 2147 result = ene_send_scsi_cmd(us, FDIR_READ, NULL, 0);
2149 if (result != USB_STOR_XFER_GOOD) { 2148 if (result != USB_STOR_XFER_GOOD) {
2150 US_DEBUGP("Execution SD Init Code Fail !!\n"); 2149 usb_stor_dbg(us, "Execution SD Init Code Fail !!\n");
2151 return USB_STOR_TRANSPORT_ERROR; 2150 return USB_STOR_TRANSPORT_ERROR;
2152 } 2151 }
2153 2152
2154 /* SD Init Part-2 */ 2153 /* SD Init Part-2 */
2155 result = ene_load_bincode(us, SD_INIT2_PATTERN); 2154 result = ene_load_bincode(us, SD_INIT2_PATTERN);
2156 if (result != USB_STOR_XFER_GOOD) { 2155 if (result != USB_STOR_XFER_GOOD) {
2157 US_DEBUGP("Load SD Init Code Part-2 Fail !!\n"); 2156 usb_stor_dbg(us, "Load SD Init Code Part-2 Fail !!\n");
2158 return USB_STOR_TRANSPORT_ERROR; 2157 return USB_STOR_TRANSPORT_ERROR;
2159 } 2158 }
2160 2159
@@ -2166,21 +2165,23 @@ static int ene_sd_init(struct us_data *us)
2166 2165
2167 result = ene_send_scsi_cmd(us, FDIR_READ, &buf, 0); 2166 result = ene_send_scsi_cmd(us, FDIR_READ, &buf, 0);
2168 if (result != USB_STOR_XFER_GOOD) { 2167 if (result != USB_STOR_XFER_GOOD) {
2169 US_DEBUGP("Execution SD Init Code Fail !!\n"); 2168 usb_stor_dbg(us, "Execution SD Init Code Fail !!\n");
2170 return USB_STOR_TRANSPORT_ERROR; 2169 return USB_STOR_TRANSPORT_ERROR;
2171 } 2170 }
2172 2171
2173 info->SD_Status = *(struct SD_STATUS *)&buf[0]; 2172 info->SD_Status = *(struct SD_STATUS *)&buf[0];
2174 if (info->SD_Status.Insert && info->SD_Status.Ready) { 2173 if (info->SD_Status.Insert && info->SD_Status.Ready) {
2174 struct SD_STATUS *s = &info->SD_Status;
2175
2175 ene_get_card_status(us, (unsigned char *)&buf); 2176 ene_get_card_status(us, (unsigned char *)&buf);
2176 US_DEBUGP("Insert = %x\n", info->SD_Status.Insert); 2177 usb_stor_dbg(us, "Insert = %x\n", s->Insert);
2177 US_DEBUGP("Ready = %x\n", info->SD_Status.Ready); 2178 usb_stor_dbg(us, "Ready = %x\n", s->Ready);
2178 US_DEBUGP("IsMMC = %x\n", info->SD_Status.IsMMC); 2179 usb_stor_dbg(us, "IsMMC = %x\n", s->IsMMC);
2179 US_DEBUGP("HiCapacity = %x\n", info->SD_Status.HiCapacity); 2180 usb_stor_dbg(us, "HiCapacity = %x\n", s->HiCapacity);
2180 US_DEBUGP("HiSpeed = %x\n", info->SD_Status.HiSpeed); 2181 usb_stor_dbg(us, "HiSpeed = %x\n", s->HiSpeed);
2181 US_DEBUGP("WtP = %x\n", info->SD_Status.WtP); 2182 usb_stor_dbg(us, "WtP = %x\n", s->WtP);
2182 } else { 2183 } else {
2183 US_DEBUGP("SD Card Not Ready --- %x\n", buf[0]); 2184 usb_stor_dbg(us, "SD Card Not Ready --- %x\n", buf[0]);
2184 return USB_STOR_TRANSPORT_ERROR; 2185 return USB_STOR_TRANSPORT_ERROR;
2185 } 2186 }
2186 return USB_STOR_TRANSPORT_GOOD; 2187 return USB_STOR_TRANSPORT_GOOD;
@@ -2293,7 +2294,7 @@ static int ene_transport(struct scsi_cmnd *srb, struct us_data *us)
2293 int result = 0; 2294 int result = 0;
2294 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); 2295 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
2295 2296
2296 /*US_DEBUG(usb_stor_show_command(srb)); */ 2297 /*US_DEBUG(usb_stor_show_command(us, srb)); */
2297 scsi_set_resid(srb, 0); 2298 scsi_set_resid(srb, 0);
2298 if (unlikely(!(info->SD_Status.Ready || info->MS_Status.Ready))) { 2299 if (unlikely(!(info->SD_Status.Ready || info->MS_Status.Ready))) {
2299 result = ene_init(us); 2300 result = ene_init(us);
@@ -2362,7 +2363,6 @@ static int ene_ub6250_resume(struct usb_interface *iface)
2362 2363
2363 mutex_lock(&us->dev_mutex); 2364 mutex_lock(&us->dev_mutex);
2364 2365
2365 US_DEBUGP("%s\n", __func__);
2366 if (us->suspend_resume_hook) 2366 if (us->suspend_resume_hook)
2367 (us->suspend_resume_hook)(us, US_RESUME); 2367 (us->suspend_resume_hook)(us, US_RESUME);
2368 2368
@@ -2382,7 +2382,7 @@ static int ene_ub6250_reset_resume(struct usb_interface *iface)
2382 u8 tmp = 0; 2382 u8 tmp = 0;
2383 struct us_data *us = usb_get_intfdata(iface); 2383 struct us_data *us = usb_get_intfdata(iface);
2384 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra); 2384 struct ene_ub6250_info *info = (struct ene_ub6250_info *)(us->extra);
2385 US_DEBUGP("%s\n", __func__); 2385
2386 /* Report the reset to the SCSI core */ 2386 /* Report the reset to the SCSI core */
2387 usb_stor_reset_resume(iface); 2387 usb_stor_reset_resume(iface);
2388 2388
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index e6df087dca9d..ef16068b7087 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -40,7 +40,7 @@ MODULE_AUTHOR("David Brown <usb-storage@davidb.org>");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42#ifdef CONFIG_USB_STORAGE_DEBUG 42#ifdef CONFIG_USB_STORAGE_DEBUG
43static void pdump (void *, int); 43static void pdump(struct us_data *us, void *ibuffer, int length);
44#endif 44#endif
45 45
46/* Bits of HD_STATUS */ 46/* Bits of HD_STATUS */
@@ -161,20 +161,20 @@ freecom_readdata (struct scsi_cmnd *srb, struct us_data *us,
161 fxfr->Count = cpu_to_le32 (count); 161 fxfr->Count = cpu_to_le32 (count);
162 memset (fxfr->Pad, 0, sizeof (fxfr->Pad)); 162 memset (fxfr->Pad, 0, sizeof (fxfr->Pad));
163 163
164 US_DEBUGP("Read data Freecom! (c=%d)\n", count); 164 usb_stor_dbg(us, "Read data Freecom! (c=%d)\n", count);
165 165
166 /* Issue the transfer command. */ 166 /* Issue the transfer command. */
167 result = usb_stor_bulk_transfer_buf (us, opipe, fxfr, 167 result = usb_stor_bulk_transfer_buf (us, opipe, fxfr,
168 FCM_PACKET_LENGTH, NULL); 168 FCM_PACKET_LENGTH, NULL);
169 if (result != USB_STOR_XFER_GOOD) { 169 if (result != USB_STOR_XFER_GOOD) {
170 US_DEBUGP ("Freecom readdata transport error\n"); 170 usb_stor_dbg(us, "Freecom readdata transport error\n");
171 return USB_STOR_TRANSPORT_ERROR; 171 return USB_STOR_TRANSPORT_ERROR;
172 } 172 }
173 173
174 /* Now transfer all of our blocks. */ 174 /* Now transfer all of our blocks. */
175 US_DEBUGP("Start of read\n"); 175 usb_stor_dbg(us, "Start of read\n");
176 result = usb_stor_bulk_srb(us, ipipe, srb); 176 result = usb_stor_bulk_srb(us, ipipe, srb);
177 US_DEBUGP("freecom_readdata done!\n"); 177 usb_stor_dbg(us, "freecom_readdata done!\n");
178 178
179 if (result > USB_STOR_XFER_SHORT) 179 if (result > USB_STOR_XFER_SHORT)
180 return USB_STOR_TRANSPORT_ERROR; 180 return USB_STOR_TRANSPORT_ERROR;
@@ -194,21 +194,21 @@ freecom_writedata (struct scsi_cmnd *srb, struct us_data *us,
194 fxfr->Count = cpu_to_le32 (count); 194 fxfr->Count = cpu_to_le32 (count);
195 memset (fxfr->Pad, 0, sizeof (fxfr->Pad)); 195 memset (fxfr->Pad, 0, sizeof (fxfr->Pad));
196 196
197 US_DEBUGP("Write data Freecom! (c=%d)\n", count); 197 usb_stor_dbg(us, "Write data Freecom! (c=%d)\n", count);
198 198
199 /* Issue the transfer command. */ 199 /* Issue the transfer command. */
200 result = usb_stor_bulk_transfer_buf (us, opipe, fxfr, 200 result = usb_stor_bulk_transfer_buf (us, opipe, fxfr,
201 FCM_PACKET_LENGTH, NULL); 201 FCM_PACKET_LENGTH, NULL);
202 if (result != USB_STOR_XFER_GOOD) { 202 if (result != USB_STOR_XFER_GOOD) {
203 US_DEBUGP ("Freecom writedata transport error\n"); 203 usb_stor_dbg(us, "Freecom writedata transport error\n");
204 return USB_STOR_TRANSPORT_ERROR; 204 return USB_STOR_TRANSPORT_ERROR;
205 } 205 }
206 206
207 /* Now transfer all of our blocks. */ 207 /* Now transfer all of our blocks. */
208 US_DEBUGP("Start of write\n"); 208 usb_stor_dbg(us, "Start of write\n");
209 result = usb_stor_bulk_srb(us, opipe, srb); 209 result = usb_stor_bulk_srb(us, opipe, srb);
210 210
211 US_DEBUGP("freecom_writedata done!\n"); 211 usb_stor_dbg(us, "freecom_writedata done!\n");
212 if (result > USB_STOR_XFER_SHORT) 212 if (result > USB_STOR_XFER_SHORT)
213 return USB_STOR_TRANSPORT_ERROR; 213 return USB_STOR_TRANSPORT_ERROR;
214 return USB_STOR_TRANSPORT_GOOD; 214 return USB_STOR_TRANSPORT_GOOD;
@@ -230,7 +230,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
230 fcb = (struct freecom_cb_wrap *) us->iobuf; 230 fcb = (struct freecom_cb_wrap *) us->iobuf;
231 fst = (struct freecom_status *) us->iobuf; 231 fst = (struct freecom_status *) us->iobuf;
232 232
233 US_DEBUGP("Freecom TRANSPORT STARTED\n"); 233 usb_stor_dbg(us, "Freecom TRANSPORT STARTED\n");
234 234
235 /* Get handles for both transports. */ 235 /* Get handles for both transports. */
236 opipe = us->send_bulk_pipe; 236 opipe = us->send_bulk_pipe;
@@ -242,7 +242,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
242 memcpy (fcb->Atapi, srb->cmnd, 12); 242 memcpy (fcb->Atapi, srb->cmnd, 12);
243 memset (fcb->Filler, 0, sizeof (fcb->Filler)); 243 memset (fcb->Filler, 0, sizeof (fcb->Filler));
244 244
245 US_DEBUG(pdump (srb->cmnd, 12)); 245 US_DEBUG(pdump(us, srb->cmnd, 12));
246 246
247 /* Send it out. */ 247 /* Send it out. */
248 result = usb_stor_bulk_transfer_buf (us, opipe, fcb, 248 result = usb_stor_bulk_transfer_buf (us, opipe, fcb,
@@ -252,7 +252,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
252 * USB land. It returns the status in its own registers, which 252 * USB land. It returns the status in its own registers, which
253 * come back in the bulk pipe. */ 253 * come back in the bulk pipe. */
254 if (result != USB_STOR_XFER_GOOD) { 254 if (result != USB_STOR_XFER_GOOD) {
255 US_DEBUGP ("freecom transport error\n"); 255 usb_stor_dbg(us, "freecom transport error\n");
256 return USB_STOR_TRANSPORT_ERROR; 256 return USB_STOR_TRANSPORT_ERROR;
257 } 257 }
258 258
@@ -260,11 +260,11 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
260 * doesn't hurt us to always do it now. */ 260 * doesn't hurt us to always do it now. */
261 result = usb_stor_bulk_transfer_buf (us, ipipe, fst, 261 result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
262 FCM_STATUS_PACKET_LENGTH, &partial); 262 FCM_STATUS_PACKET_LENGTH, &partial);
263 US_DEBUGP("foo Status result %d %u\n", result, partial); 263 usb_stor_dbg(us, "foo Status result %d %u\n", result, partial);
264 if (result != USB_STOR_XFER_GOOD) 264 if (result != USB_STOR_XFER_GOOD)
265 return USB_STOR_TRANSPORT_ERROR; 265 return USB_STOR_TRANSPORT_ERROR;
266 266
267 US_DEBUG(pdump ((void *) fst, partial)); 267 US_DEBUG(pdump(us, (void *)fst, partial));
268 268
269 /* The firmware will time-out commands after 20 seconds. Some commands 269 /* The firmware will time-out commands after 20 seconds. Some commands
270 * can legitimately take longer than this, so we use a different 270 * can legitimately take longer than this, so we use a different
@@ -275,8 +275,8 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
275 * may not work, but that is a condition that should never happen. 275 * may not work, but that is a condition that should never happen.
276 */ 276 */
277 while (fst->Status & FCM_STATUS_BUSY) { 277 while (fst->Status & FCM_STATUS_BUSY) {
278 US_DEBUGP("20 second USB/ATAPI bridge TIMEOUT occurred!\n"); 278 usb_stor_dbg(us, "20 second USB/ATAPI bridge TIMEOUT occurred!\n");
279 US_DEBUGP("fst->Status is %x\n", fst->Status); 279 usb_stor_dbg(us, "fst->Status is %x\n", fst->Status);
280 280
281 /* Get the status again */ 281 /* Get the status again */
282 fcb->Type = FCM_PACKET_STATUS; 282 fcb->Type = FCM_PACKET_STATUS;
@@ -293,7 +293,7 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
293 * registers, which come back in the bulk pipe. 293 * registers, which come back in the bulk pipe.
294 */ 294 */
295 if (result != USB_STOR_XFER_GOOD) { 295 if (result != USB_STOR_XFER_GOOD) {
296 US_DEBUGP ("freecom transport error\n"); 296 usb_stor_dbg(us, "freecom transport error\n");
297 return USB_STOR_TRANSPORT_ERROR; 297 return USB_STOR_TRANSPORT_ERROR;
298 } 298 }
299 299
@@ -301,26 +301,26 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
301 result = usb_stor_bulk_transfer_buf (us, ipipe, fst, 301 result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
302 FCM_STATUS_PACKET_LENGTH, &partial); 302 FCM_STATUS_PACKET_LENGTH, &partial);
303 303
304 US_DEBUGP("bar Status result %d %u\n", result, partial); 304 usb_stor_dbg(us, "bar Status result %d %u\n", result, partial);
305 if (result != USB_STOR_XFER_GOOD) 305 if (result != USB_STOR_XFER_GOOD)
306 return USB_STOR_TRANSPORT_ERROR; 306 return USB_STOR_TRANSPORT_ERROR;
307 307
308 US_DEBUG(pdump ((void *) fst, partial)); 308 US_DEBUG(pdump(us, (void *)fst, partial));
309 } 309 }
310 310
311 if (partial != 4) 311 if (partial != 4)
312 return USB_STOR_TRANSPORT_ERROR; 312 return USB_STOR_TRANSPORT_ERROR;
313 if ((fst->Status & 1) != 0) { 313 if ((fst->Status & 1) != 0) {
314 US_DEBUGP("operation failed\n"); 314 usb_stor_dbg(us, "operation failed\n");
315 return USB_STOR_TRANSPORT_FAILED; 315 return USB_STOR_TRANSPORT_FAILED;
316 } 316 }
317 317
318 /* The device might not have as much data available as we 318 /* The device might not have as much data available as we
319 * requested. If you ask for more than the device has, this reads 319 * requested. If you ask for more than the device has, this reads
320 * and such will hang. */ 320 * and such will hang. */
321 US_DEBUGP("Device indicates that it has %d bytes available\n", 321 usb_stor_dbg(us, "Device indicates that it has %d bytes available\n",
322 le16_to_cpu (fst->Count)); 322 le16_to_cpu(fst->Count));
323 US_DEBUGP("SCSI requested %d\n", scsi_bufflen(srb)); 323 usb_stor_dbg(us, "SCSI requested %d\n", scsi_bufflen(srb));
324 324
325 /* Find the length we desire to read. */ 325 /* Find the length we desire to read. */
326 switch (srb->cmnd[0]) { 326 switch (srb->cmnd[0]) {
@@ -337,7 +337,8 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
337 /* verify that this amount is legal */ 337 /* verify that this amount is legal */
338 if (length > scsi_bufflen(srb)) { 338 if (length > scsi_bufflen(srb)) {
339 length = scsi_bufflen(srb); 339 length = scsi_bufflen(srb);
340 US_DEBUGP("Truncating request to match buffer length: %d\n", length); 340 usb_stor_dbg(us, "Truncating request to match buffer length: %d\n",
341 length);
341 } 342 }
342 343
343 /* What we do now depends on what direction the data is supposed to 344 /* What we do now depends on what direction the data is supposed to
@@ -351,29 +352,29 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
351 /* Make sure that the status indicates that the device 352 /* Make sure that the status indicates that the device
352 * wants data as well. */ 353 * wants data as well. */
353 if ((fst->Status & DRQ_STAT) == 0 || (fst->Reason & 3) != 2) { 354 if ((fst->Status & DRQ_STAT) == 0 || (fst->Reason & 3) != 2) {
354 US_DEBUGP("SCSI wants data, drive doesn't have any\n"); 355 usb_stor_dbg(us, "SCSI wants data, drive doesn't have any\n");
355 return USB_STOR_TRANSPORT_FAILED; 356 return USB_STOR_TRANSPORT_FAILED;
356 } 357 }
357 result = freecom_readdata (srb, us, ipipe, opipe, length); 358 result = freecom_readdata (srb, us, ipipe, opipe, length);
358 if (result != USB_STOR_TRANSPORT_GOOD) 359 if (result != USB_STOR_TRANSPORT_GOOD)
359 return result; 360 return result;
360 361
361 US_DEBUGP("FCM: Waiting for status\n"); 362 usb_stor_dbg(us, "Waiting for status\n");
362 result = usb_stor_bulk_transfer_buf (us, ipipe, fst, 363 result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
363 FCM_PACKET_LENGTH, &partial); 364 FCM_PACKET_LENGTH, &partial);
364 US_DEBUG(pdump ((void *) fst, partial)); 365 US_DEBUG(pdump(us, (void *)fst, partial));
365 366
366 if (partial != 4 || result > USB_STOR_XFER_SHORT) 367 if (partial != 4 || result > USB_STOR_XFER_SHORT)
367 return USB_STOR_TRANSPORT_ERROR; 368 return USB_STOR_TRANSPORT_ERROR;
368 if ((fst->Status & ERR_STAT) != 0) { 369 if ((fst->Status & ERR_STAT) != 0) {
369 US_DEBUGP("operation failed\n"); 370 usb_stor_dbg(us, "operation failed\n");
370 return USB_STOR_TRANSPORT_FAILED; 371 return USB_STOR_TRANSPORT_FAILED;
371 } 372 }
372 if ((fst->Reason & 3) != 3) { 373 if ((fst->Reason & 3) != 3) {
373 US_DEBUGP("Drive seems still hungry\n"); 374 usb_stor_dbg(us, "Drive seems still hungry\n");
374 return USB_STOR_TRANSPORT_FAILED; 375 return USB_STOR_TRANSPORT_FAILED;
375 } 376 }
376 US_DEBUGP("Transfer happy\n"); 377 usb_stor_dbg(us, "Transfer happy\n");
377 break; 378 break;
378 379
379 case DMA_TO_DEVICE: 380 case DMA_TO_DEVICE:
@@ -387,22 +388,22 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
387 if (result != USB_STOR_TRANSPORT_GOOD) 388 if (result != USB_STOR_TRANSPORT_GOOD)
388 return result; 389 return result;
389 390
390 US_DEBUGP("FCM: Waiting for status\n"); 391 usb_stor_dbg(us, "Waiting for status\n");
391 result = usb_stor_bulk_transfer_buf (us, ipipe, fst, 392 result = usb_stor_bulk_transfer_buf (us, ipipe, fst,
392 FCM_PACKET_LENGTH, &partial); 393 FCM_PACKET_LENGTH, &partial);
393 394
394 if (partial != 4 || result > USB_STOR_XFER_SHORT) 395 if (partial != 4 || result > USB_STOR_XFER_SHORT)
395 return USB_STOR_TRANSPORT_ERROR; 396 return USB_STOR_TRANSPORT_ERROR;
396 if ((fst->Status & ERR_STAT) != 0) { 397 if ((fst->Status & ERR_STAT) != 0) {
397 US_DEBUGP("operation failed\n"); 398 usb_stor_dbg(us, "operation failed\n");
398 return USB_STOR_TRANSPORT_FAILED; 399 return USB_STOR_TRANSPORT_FAILED;
399 } 400 }
400 if ((fst->Reason & 3) != 3) { 401 if ((fst->Reason & 3) != 3) {
401 US_DEBUGP("Drive seems still hungry\n"); 402 usb_stor_dbg(us, "Drive seems still hungry\n");
402 return USB_STOR_TRANSPORT_FAILED; 403 return USB_STOR_TRANSPORT_FAILED;
403 } 404 }
404 405
405 US_DEBUGP("Transfer happy\n"); 406 usb_stor_dbg(us, "Transfer happy\n");
406 break; 407 break;
407 408
408 409
@@ -412,8 +413,8 @@ static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
412 413
413 default: 414 default:
414 /* should never hit here -- filtered in usb.c */ 415 /* should never hit here -- filtered in usb.c */
415 US_DEBUGP ("freecom unimplemented direction: %d\n", 416 usb_stor_dbg(us, "freecom unimplemented direction: %d\n",
416 us->srb->sc_data_direction); 417 us->srb->sc_data_direction);
417 /* Return fail, SCSI seems to handle this better. */ 418 /* Return fail, SCSI seems to handle this better. */
418 return USB_STOR_TRANSPORT_FAILED; 419 return USB_STOR_TRANSPORT_FAILED;
419 break; 420 break;
@@ -434,7 +435,7 @@ static int init_freecom(struct us_data *us)
434 result = usb_stor_control_msg(us, us->recv_ctrl_pipe, 435 result = usb_stor_control_msg(us, us->recv_ctrl_pipe,
435 0x4c, 0xc0, 0x4346, 0x0, buffer, 0x20, 3*HZ); 436 0x4c, 0xc0, 0x4346, 0x0, buffer, 0x20, 3*HZ);
436 buffer[32] = '\0'; 437 buffer[32] = '\0';
437 US_DEBUGP("String returned from FC init is: %s\n", buffer); 438 usb_stor_dbg(us, "String returned from FC init is: %s\n", buffer);
438 439
439 /* Special thanks to the people at Freecom for providing me with 440 /* Special thanks to the people at Freecom for providing me with
440 * this "magic sequence", which they use in their Windows and MacOS 441 * this "magic sequence", which they use in their Windows and MacOS
@@ -445,7 +446,7 @@ static int init_freecom(struct us_data *us)
445 /* send reset */ 446 /* send reset */
446 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 447 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
447 0x4d, 0x40, 0x24d8, 0x0, NULL, 0x0, 3*HZ); 448 0x4d, 0x40, 0x24d8, 0x0, NULL, 0x0, 3*HZ);
448 US_DEBUGP("result from activate reset is %d\n", result); 449 usb_stor_dbg(us, "result from activate reset is %d\n", result);
449 450
450 /* wait 250ms */ 451 /* wait 250ms */
451 mdelay(250); 452 mdelay(250);
@@ -453,7 +454,7 @@ static int init_freecom(struct us_data *us)
453 /* clear reset */ 454 /* clear reset */
454 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 455 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
455 0x4d, 0x40, 0x24f8, 0x0, NULL, 0x0, 3*HZ); 456 0x4d, 0x40, 0x24f8, 0x0, NULL, 0x0, 3*HZ);
456 US_DEBUGP("result from clear reset is %d\n", result); 457 usb_stor_dbg(us, "result from clear reset is %d\n", result);
457 458
458 /* wait 3 seconds */ 459 /* wait 3 seconds */
459 mdelay(3 * 1000); 460 mdelay(3 * 1000);
@@ -470,7 +471,7 @@ static int usb_stor_freecom_reset(struct us_data *us)
470} 471}
471 472
472#ifdef CONFIG_USB_STORAGE_DEBUG 473#ifdef CONFIG_USB_STORAGE_DEBUG
473static void pdump (void *ibuffer, int length) 474static void pdump(struct us_data *us, void *ibuffer, int length)
474{ 475{
475 static char line[80]; 476 static char line[80];
476 int offset = 0; 477 int offset = 0;
@@ -490,7 +491,7 @@ static void pdump (void *ibuffer, int length)
490 line[offset++] = '.'; 491 line[offset++] = '.';
491 } 492 }
492 line[offset] = 0; 493 line[offset] = 0;
493 US_DEBUGP("%s\n", line); 494 usb_stor_dbg(us, "%s\n", line);
494 offset = 0; 495 offset = 0;
495 } 496 }
496 offset += sprintf (line+offset, "%08x:", i); 497 offset += sprintf (line+offset, "%08x:", i);
@@ -517,7 +518,7 @@ static void pdump (void *ibuffer, int length)
517 line[offset++] = '.'; 518 line[offset++] = '.';
518 } 519 }
519 line[offset] = 0; 520 line[offset] = 0;
520 US_DEBUGP("%s\n", line); 521 usb_stor_dbg(us, "%s\n", line);
521 offset = 0; 522 offset = 0;
522} 523}
523#endif 524#endif
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index 105d900150c1..5a8b5ff1e45b 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -48,12 +48,12 @@ int usb_stor_euscsi_init(struct us_data *us)
48{ 48{
49 int result; 49 int result;
50 50
51 US_DEBUGP("Attempting to init eUSCSI bridge...\n"); 51 usb_stor_dbg(us, "Attempting to init eUSCSI bridge...\n");
52 us->iobuf[0] = 0x1; 52 us->iobuf[0] = 0x1;
53 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 53 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
54 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, 54 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
55 0x01, 0x0, us->iobuf, 0x1, 5000); 55 0x01, 0x0, us->iobuf, 0x1, 5000);
56 US_DEBUGP("-- result is %d\n", result); 56 usb_stor_dbg(us, "-- result is %d\n", result);
57 57
58 return 0; 58 return 0;
59} 59}
@@ -68,7 +68,7 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
68 unsigned int partial; 68 unsigned int partial;
69 static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS"; 69 static char init_string[] = "\xec\x0a\x06\x00$PCCHIPS";
70 70
71 US_DEBUGP("Sending UCR-61S2B initialization packet...\n"); 71 usb_stor_dbg(us, "Sending UCR-61S2B initialization packet...\n");
72 72
73 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN); 73 bcb->Signature = cpu_to_le32(US_BULK_CB_SIGN);
74 bcb->Tag = 0; 74 bcb->Tag = 0;
@@ -83,7 +83,7 @@ int usb_stor_ucr61s2b_init(struct us_data *us)
83 if (res) 83 if (res)
84 return -EIO; 84 return -EIO;
85 85
86 US_DEBUGP("Getting status packet...\n"); 86 usb_stor_dbg(us, "Getting status packet...\n");
87 res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, 87 res = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs,
88 US_BULK_CS_WRAP_LEN, &partial); 88 US_BULK_CS_WRAP_LEN, &partial);
89 if (res) 89 if (res)
@@ -101,6 +101,6 @@ int usb_stor_huawei_e220_init(struct us_data *us)
101 USB_REQ_SET_FEATURE, 101 USB_REQ_SET_FEATURE,
102 USB_TYPE_STANDARD | USB_RECIP_DEVICE, 102 USB_TYPE_STANDARD | USB_RECIP_DEVICE,
103 0x01, 0x0, NULL, 0x0, 1000); 103 0x01, 0x0, NULL, 0x0, 1000);
104 US_DEBUGP("Huawei mode set result is %d\n", result); 104 usb_stor_dbg(us, "Huawei mode set result is %d\n", result);
105 return 0; 105 return 0;
106} 106}
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index ecea47877364..599d8bff26c3 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -503,7 +503,7 @@ static int isd200_action( struct us_data *us, int action,
503 503
504 switch ( action ) { 504 switch ( action ) {
505 case ACTION_READ_STATUS: 505 case ACTION_READ_STATUS:
506 US_DEBUGP(" isd200_action(READ_STATUS)\n"); 506 usb_stor_dbg(us, " isd200_action(READ_STATUS)\n");
507 ata.generic.ActionSelect = ACTION_SELECT_0|ACTION_SELECT_2; 507 ata.generic.ActionSelect = ACTION_SELECT_0|ACTION_SELECT_2;
508 ata.generic.RegisterSelect = 508 ata.generic.RegisterSelect =
509 REG_CYLINDER_LOW | REG_CYLINDER_HIGH | 509 REG_CYLINDER_LOW | REG_CYLINDER_HIGH |
@@ -512,7 +512,7 @@ static int isd200_action( struct us_data *us, int action,
512 break; 512 break;
513 513
514 case ACTION_ENUM: 514 case ACTION_ENUM:
515 US_DEBUGP(" isd200_action(ENUM,0x%02x)\n",value); 515 usb_stor_dbg(us, " isd200_action(ENUM,0x%02x)\n", value);
516 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| 516 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
517 ACTION_SELECT_3|ACTION_SELECT_4| 517 ACTION_SELECT_3|ACTION_SELECT_4|
518 ACTION_SELECT_5; 518 ACTION_SELECT_5;
@@ -522,7 +522,7 @@ static int isd200_action( struct us_data *us, int action,
522 break; 522 break;
523 523
524 case ACTION_RESET: 524 case ACTION_RESET:
525 US_DEBUGP(" isd200_action(RESET)\n"); 525 usb_stor_dbg(us, " isd200_action(RESET)\n");
526 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| 526 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
527 ACTION_SELECT_3|ACTION_SELECT_4; 527 ACTION_SELECT_3|ACTION_SELECT_4;
528 ata.generic.RegisterSelect = REG_DEVICE_CONTROL; 528 ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
@@ -531,7 +531,7 @@ static int isd200_action( struct us_data *us, int action,
531 break; 531 break;
532 532
533 case ACTION_REENABLE: 533 case ACTION_REENABLE:
534 US_DEBUGP(" isd200_action(REENABLE)\n"); 534 usb_stor_dbg(us, " isd200_action(REENABLE)\n");
535 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2| 535 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_2|
536 ACTION_SELECT_3|ACTION_SELECT_4; 536 ACTION_SELECT_3|ACTION_SELECT_4;
537 ata.generic.RegisterSelect = REG_DEVICE_CONTROL; 537 ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
@@ -540,7 +540,7 @@ static int isd200_action( struct us_data *us, int action,
540 break; 540 break;
541 541
542 case ACTION_SOFT_RESET: 542 case ACTION_SOFT_RESET:
543 US_DEBUGP(" isd200_action(SOFT_RESET)\n"); 543 usb_stor_dbg(us, " isd200_action(SOFT_RESET)\n");
544 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_5; 544 ata.generic.ActionSelect = ACTION_SELECT_1|ACTION_SELECT_5;
545 ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND; 545 ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND;
546 ata.write.DeviceHeadByte = info->DeviceHead; 546 ata.write.DeviceHeadByte = info->DeviceHead;
@@ -549,7 +549,7 @@ static int isd200_action( struct us_data *us, int action,
549 break; 549 break;
550 550
551 case ACTION_IDENTIFY: 551 case ACTION_IDENTIFY:
552 US_DEBUGP(" isd200_action(IDENTIFY)\n"); 552 usb_stor_dbg(us, " isd200_action(IDENTIFY)\n");
553 ata.generic.RegisterSelect = REG_COMMAND; 553 ata.generic.RegisterSelect = REG_COMMAND;
554 ata.write.CommandByte = ATA_CMD_ID_ATA; 554 ata.write.CommandByte = ATA_CMD_ID_ATA;
555 isd200_set_srb(info, DMA_FROM_DEVICE, info->id, 555 isd200_set_srb(info, DMA_FROM_DEVICE, info->id,
@@ -557,7 +557,7 @@ static int isd200_action( struct us_data *us, int action,
557 break; 557 break;
558 558
559 default: 559 default:
560 US_DEBUGP("Error: Undefined action %d\n",action); 560 usb_stor_dbg(us, "Error: Undefined action %d\n", action);
561 return ISD200_ERROR; 561 return ISD200_ERROR;
562 } 562 }
563 563
@@ -567,7 +567,8 @@ static int isd200_action( struct us_data *us, int action,
567 if (status == USB_STOR_TRANSPORT_GOOD) 567 if (status == USB_STOR_TRANSPORT_GOOD)
568 status = ISD200_GOOD; 568 status = ISD200_GOOD;
569 else { 569 else {
570 US_DEBUGP(" isd200_action(0x%02x) error: %d\n",action,status); 570 usb_stor_dbg(us, " isd200_action(0x%02x) error: %d\n",
571 action, status);
571 status = ISD200_ERROR; 572 status = ISD200_ERROR;
572 /* need to reset device here */ 573 /* need to reset device here */
573 } 574 }
@@ -589,17 +590,17 @@ static int isd200_read_regs( struct us_data *us )
589 int retStatus = ISD200_GOOD; 590 int retStatus = ISD200_GOOD;
590 int transferStatus; 591 int transferStatus;
591 592
592 US_DEBUGP("Entering isd200_IssueATAReadRegs\n"); 593 usb_stor_dbg(us, "Entering isd200_IssueATAReadRegs\n");
593 594
594 transferStatus = isd200_action( us, ACTION_READ_STATUS, 595 transferStatus = isd200_action( us, ACTION_READ_STATUS,
595 info->RegsBuf, sizeof(info->ATARegs) ); 596 info->RegsBuf, sizeof(info->ATARegs) );
596 if (transferStatus != ISD200_TRANSPORT_GOOD) { 597 if (transferStatus != ISD200_TRANSPORT_GOOD) {
597 US_DEBUGP(" Error reading ATA registers\n"); 598 usb_stor_dbg(us, " Error reading ATA registers\n");
598 retStatus = ISD200_ERROR; 599 retStatus = ISD200_ERROR;
599 } else { 600 } else {
600 memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs)); 601 memcpy(info->ATARegs, info->RegsBuf, sizeof(info->ATARegs));
601 US_DEBUGP(" Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n", 602 usb_stor_dbg(us, " Got ATA Register[ATA_REG_ERROR_OFFSET] = 0x%x\n",
602 info->ATARegs[ATA_REG_ERROR_OFFSET]); 603 info->ATARegs[ATA_REG_ERROR_OFFSET]);
603 } 604 }
604 605
605 return retStatus; 606 return retStatus;
@@ -629,7 +630,7 @@ static void isd200_invoke_transport( struct us_data *us,
629 * short-circuit all other processing 630 * short-circuit all other processing
630 */ 631 */
631 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { 632 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
632 US_DEBUGP("-- command was aborted\n"); 633 usb_stor_dbg(us, "-- command was aborted\n");
633 goto Handle_Abort; 634 goto Handle_Abort;
634 } 635 }
635 636
@@ -641,23 +642,23 @@ static void isd200_invoke_transport( struct us_data *us,
641 break; 642 break;
642 643
643 case USB_STOR_TRANSPORT_NO_SENSE: 644 case USB_STOR_TRANSPORT_NO_SENSE:
644 US_DEBUGP("-- transport indicates protocol failure\n"); 645 usb_stor_dbg(us, "-- transport indicates protocol failure\n");
645 srb->result = SAM_STAT_CHECK_CONDITION; 646 srb->result = SAM_STAT_CHECK_CONDITION;
646 return; 647 return;
647 648
648 case USB_STOR_TRANSPORT_FAILED: 649 case USB_STOR_TRANSPORT_FAILED:
649 US_DEBUGP("-- transport indicates command failure\n"); 650 usb_stor_dbg(us, "-- transport indicates command failure\n");
650 need_auto_sense = 1; 651 need_auto_sense = 1;
651 break; 652 break;
652 653
653 case USB_STOR_TRANSPORT_ERROR: 654 case USB_STOR_TRANSPORT_ERROR:
654 US_DEBUGP("-- transport indicates transport error\n"); 655 usb_stor_dbg(us, "-- transport indicates transport error\n");
655 srb->result = DID_ERROR << 16; 656 srb->result = DID_ERROR << 16;
656 /* Need reset here */ 657 /* Need reset here */
657 return; 658 return;
658 659
659 default: 660 default:
660 US_DEBUGP("-- transport indicates unknown error\n"); 661 usb_stor_dbg(us, "-- transport indicates unknown error\n");
661 srb->result = DID_ERROR << 16; 662 srb->result = DID_ERROR << 16;
662 /* Need reset here */ 663 /* Need reset here */
663 return; 664 return;
@@ -669,14 +670,14 @@ static void isd200_invoke_transport( struct us_data *us,
669 (srb->cmnd[0] == MODE_SENSE) || 670 (srb->cmnd[0] == MODE_SENSE) ||
670 (srb->cmnd[0] == LOG_SENSE) || 671 (srb->cmnd[0] == LOG_SENSE) ||
671 (srb->cmnd[0] == MODE_SENSE_10))) { 672 (srb->cmnd[0] == MODE_SENSE_10))) {
672 US_DEBUGP("-- unexpectedly short transfer\n"); 673 usb_stor_dbg(us, "-- unexpectedly short transfer\n");
673 need_auto_sense = 1; 674 need_auto_sense = 1;
674 } 675 }
675 676
676 if (need_auto_sense) { 677 if (need_auto_sense) {
677 result = isd200_read_regs(us); 678 result = isd200_read_regs(us);
678 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { 679 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
679 US_DEBUGP("-- auto-sense aborted\n"); 680 usb_stor_dbg(us, "-- auto-sense aborted\n");
680 goto Handle_Abort; 681 goto Handle_Abort;
681 } 682 }
682 if (result == ISD200_GOOD) { 683 if (result == ISD200_GOOD) {
@@ -710,40 +711,40 @@ static void isd200_invoke_transport( struct us_data *us,
710} 711}
711 712
712#ifdef CONFIG_USB_STORAGE_DEBUG 713#ifdef CONFIG_USB_STORAGE_DEBUG
713static void isd200_log_config( struct isd200_info* info ) 714static void isd200_log_config(struct us_data *us, struct isd200_info *info)
714{ 715{
715 US_DEBUGP(" Event Notification: 0x%x\n", 716 usb_stor_dbg(us, " Event Notification: 0x%x\n",
716 info->ConfigData.EventNotification); 717 info->ConfigData.EventNotification);
717 US_DEBUGP(" External Clock: 0x%x\n", 718 usb_stor_dbg(us, " External Clock: 0x%x\n",
718 info->ConfigData.ExternalClock); 719 info->ConfigData.ExternalClock);
719 US_DEBUGP(" ATA Init Timeout: 0x%x\n", 720 usb_stor_dbg(us, " ATA Init Timeout: 0x%x\n",
720 info->ConfigData.ATAInitTimeout); 721 info->ConfigData.ATAInitTimeout);
721 US_DEBUGP(" ATAPI Command Block Size: 0x%x\n", 722 usb_stor_dbg(us, " ATAPI Command Block Size: 0x%x\n",
722 (info->ConfigData.ATAConfig & ATACFG_BLOCKSIZE) >> 6); 723 (info->ConfigData.ATAConfig & ATACFG_BLOCKSIZE) >> 6);
723 US_DEBUGP(" Master/Slave Selection: 0x%x\n", 724 usb_stor_dbg(us, " Master/Slave Selection: 0x%x\n",
724 info->ConfigData.ATAConfig & ATACFG_MASTER); 725 info->ConfigData.ATAConfig & ATACFG_MASTER);
725 US_DEBUGP(" ATAPI Reset: 0x%x\n", 726 usb_stor_dbg(us, " ATAPI Reset: 0x%x\n",
726 info->ConfigData.ATAConfig & ATACFG_ATAPI_RESET); 727 info->ConfigData.ATAConfig & ATACFG_ATAPI_RESET);
727 US_DEBUGP(" ATA Timing: 0x%x\n", 728 usb_stor_dbg(us, " ATA Timing: 0x%x\n",
728 info->ConfigData.ATAConfig & ATACFG_TIMING); 729 info->ConfigData.ATAConfig & ATACFG_TIMING);
729 US_DEBUGP(" ATA Major Command: 0x%x\n", 730 usb_stor_dbg(us, " ATA Major Command: 0x%x\n",
730 info->ConfigData.ATAMajorCommand); 731 info->ConfigData.ATAMajorCommand);
731 US_DEBUGP(" ATA Minor Command: 0x%x\n", 732 usb_stor_dbg(us, " ATA Minor Command: 0x%x\n",
732 info->ConfigData.ATAMinorCommand); 733 info->ConfigData.ATAMinorCommand);
733 US_DEBUGP(" Init Status: 0x%x\n", 734 usb_stor_dbg(us, " Init Status: 0x%x\n",
734 info->ConfigData.ATAExtraConfig & ATACFGE_INIT_STATUS); 735 info->ConfigData.ATAExtraConfig & ATACFGE_INIT_STATUS);
735 US_DEBUGP(" Config Descriptor 2: 0x%x\n", 736 usb_stor_dbg(us, " Config Descriptor 2: 0x%x\n",
736 info->ConfigData.ATAExtraConfig & ATACFGE_CONF_DESC2); 737 info->ConfigData.ATAExtraConfig & ATACFGE_CONF_DESC2);
737 US_DEBUGP(" Skip Device Boot: 0x%x\n", 738 usb_stor_dbg(us, " Skip Device Boot: 0x%x\n",
738 info->ConfigData.ATAExtraConfig & ATACFGE_SKIP_BOOT); 739 info->ConfigData.ATAExtraConfig & ATACFGE_SKIP_BOOT);
739 US_DEBUGP(" ATA 3 State Supsend: 0x%x\n", 740 usb_stor_dbg(us, " ATA 3 State Supsend: 0x%x\n",
740 info->ConfigData.ATAExtraConfig & ATACFGE_STATE_SUSPEND); 741 info->ConfigData.ATAExtraConfig & ATACFGE_STATE_SUSPEND);
741 US_DEBUGP(" Descriptor Override: 0x%x\n", 742 usb_stor_dbg(us, " Descriptor Override: 0x%x\n",
742 info->ConfigData.ATAExtraConfig & ATACFGE_DESC_OVERRIDE); 743 info->ConfigData.ATAExtraConfig & ATACFGE_DESC_OVERRIDE);
743 US_DEBUGP(" Last LUN Identifier: 0x%x\n", 744 usb_stor_dbg(us, " Last LUN Identifier: 0x%x\n",
744 info->ConfigData.ATAExtraConfig & ATACFGE_LAST_LUN); 745 info->ConfigData.ATAExtraConfig & ATACFGE_LAST_LUN);
745 US_DEBUGP(" SRST Enable: 0x%x\n", 746 usb_stor_dbg(us, " SRST Enable: 0x%x\n",
746 info->ConfigData.ATAExtraConfig & CFG_CAPABILITY_SRST); 747 info->ConfigData.ATAExtraConfig & CFG_CAPABILITY_SRST);
747} 748}
748#endif 749#endif
749 750
@@ -762,9 +763,9 @@ static int isd200_write_config( struct us_data *us )
762 int result; 763 int result;
763 764
764#ifdef CONFIG_USB_STORAGE_DEBUG 765#ifdef CONFIG_USB_STORAGE_DEBUG
765 US_DEBUGP("Entering isd200_write_config\n"); 766 usb_stor_dbg(us, "Entering isd200_write_config\n");
766 US_DEBUGP(" Writing the following ISD200 Config Data:\n"); 767 usb_stor_dbg(us, " Writing the following ISD200 Config Data:\n");
767 isd200_log_config(info); 768 isd200_log_config(us, info);
768#endif 769#endif
769 770
770 /* let's send the command via the control pipe */ 771 /* let's send the command via the control pipe */
@@ -779,13 +780,13 @@ static int isd200_write_config( struct us_data *us )
779 sizeof(info->ConfigData)); 780 sizeof(info->ConfigData));
780 781
781 if (result >= 0) { 782 if (result >= 0) {
782 US_DEBUGP(" ISD200 Config Data was written successfully\n"); 783 usb_stor_dbg(us, " ISD200 Config Data was written successfully\n");
783 } else { 784 } else {
784 US_DEBUGP(" Request to write ISD200 Config Data failed!\n"); 785 usb_stor_dbg(us, " Request to write ISD200 Config Data failed!\n");
785 retStatus = ISD200_ERROR; 786 retStatus = ISD200_ERROR;
786 } 787 }
787 788
788 US_DEBUGP("Leaving isd200_write_config %08X\n", retStatus); 789 usb_stor_dbg(us, "Leaving isd200_write_config %08X\n", retStatus);
789 return retStatus; 790 return retStatus;
790} 791}
791 792
@@ -804,7 +805,7 @@ static int isd200_read_config( struct us_data *us )
804 int retStatus = ISD200_GOOD; 805 int retStatus = ISD200_GOOD;
805 int result; 806 int result;
806 807
807 US_DEBUGP("Entering isd200_read_config\n"); 808 usb_stor_dbg(us, "Entering isd200_read_config\n");
808 809
809 /* read the configuration information from ISD200. Use this to */ 810 /* read the configuration information from ISD200. Use this to */
810 /* determine what the special ATA CDB bytes are. */ 811 /* determine what the special ATA CDB bytes are. */
@@ -821,16 +822,16 @@ static int isd200_read_config( struct us_data *us )
821 822
822 823
823 if (result >= 0) { 824 if (result >= 0) {
824 US_DEBUGP(" Retrieved the following ISD200 Config Data:\n"); 825 usb_stor_dbg(us, " Retrieved the following ISD200 Config Data:\n");
825#ifdef CONFIG_USB_STORAGE_DEBUG 826#ifdef CONFIG_USB_STORAGE_DEBUG
826 isd200_log_config(info); 827 isd200_log_config(us, info);
827#endif 828#endif
828 } else { 829 } else {
829 US_DEBUGP(" Request to get ISD200 Config Data failed!\n"); 830 usb_stor_dbg(us, " Request to get ISD200 Config Data failed!\n");
830 retStatus = ISD200_ERROR; 831 retStatus = ISD200_ERROR;
831 } 832 }
832 833
833 US_DEBUGP("Leaving isd200_read_config %08X\n", retStatus); 834 usb_stor_dbg(us, "Leaving isd200_read_config %08X\n", retStatus);
834 return retStatus; 835 return retStatus;
835} 836}
836 837
@@ -848,15 +849,15 @@ static int isd200_atapi_soft_reset( struct us_data *us )
848 int retStatus = ISD200_GOOD; 849 int retStatus = ISD200_GOOD;
849 int transferStatus; 850 int transferStatus;
850 851
851 US_DEBUGP("Entering isd200_atapi_soft_reset\n"); 852 usb_stor_dbg(us, "Entering isd200_atapi_soft_reset\n");
852 853
853 transferStatus = isd200_action( us, ACTION_SOFT_RESET, NULL, 0 ); 854 transferStatus = isd200_action( us, ACTION_SOFT_RESET, NULL, 0 );
854 if (transferStatus != ISD200_TRANSPORT_GOOD) { 855 if (transferStatus != ISD200_TRANSPORT_GOOD) {
855 US_DEBUGP(" Error issuing Atapi Soft Reset\n"); 856 usb_stor_dbg(us, " Error issuing Atapi Soft Reset\n");
856 retStatus = ISD200_ERROR; 857 retStatus = ISD200_ERROR;
857 } 858 }
858 859
859 US_DEBUGP("Leaving isd200_atapi_soft_reset %08X\n", retStatus); 860 usb_stor_dbg(us, "Leaving isd200_atapi_soft_reset %08X\n", retStatus);
860 return retStatus; 861 return retStatus;
861} 862}
862 863
@@ -874,13 +875,13 @@ static int isd200_srst( struct us_data *us )
874 int retStatus = ISD200_GOOD; 875 int retStatus = ISD200_GOOD;
875 int transferStatus; 876 int transferStatus;
876 877
877 US_DEBUGP("Entering isd200_SRST\n"); 878 usb_stor_dbg(us, "Entering isd200_SRST\n");
878 879
879 transferStatus = isd200_action( us, ACTION_RESET, NULL, 0 ); 880 transferStatus = isd200_action( us, ACTION_RESET, NULL, 0 );
880 881
881 /* check to see if this request failed */ 882 /* check to see if this request failed */
882 if (transferStatus != ISD200_TRANSPORT_GOOD) { 883 if (transferStatus != ISD200_TRANSPORT_GOOD) {
883 US_DEBUGP(" Error issuing SRST\n"); 884 usb_stor_dbg(us, " Error issuing SRST\n");
884 retStatus = ISD200_ERROR; 885 retStatus = ISD200_ERROR;
885 } else { 886 } else {
886 /* delay 10ms to give the drive a chance to see it */ 887 /* delay 10ms to give the drive a chance to see it */
@@ -888,7 +889,7 @@ static int isd200_srst( struct us_data *us )
888 889
889 transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 ); 890 transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 );
890 if (transferStatus != ISD200_TRANSPORT_GOOD) { 891 if (transferStatus != ISD200_TRANSPORT_GOOD) {
891 US_DEBUGP(" Error taking drive out of reset\n"); 892 usb_stor_dbg(us, " Error taking drive out of reset\n");
892 retStatus = ISD200_ERROR; 893 retStatus = ISD200_ERROR;
893 } else { 894 } else {
894 /* delay 50ms to give the drive a chance to recover after SRST */ 895 /* delay 50ms to give the drive a chance to recover after SRST */
@@ -896,7 +897,7 @@ static int isd200_srst( struct us_data *us )
896 } 897 }
897 } 898 }
898 899
899 US_DEBUGP("Leaving isd200_srst %08X\n", retStatus); 900 usb_stor_dbg(us, "Leaving isd200_srst %08X\n", retStatus);
900 return retStatus; 901 return retStatus;
901} 902}
902 903
@@ -926,10 +927,6 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
926 927
927 /* loop until we detect !BSY or timeout */ 928 /* loop until we detect !BSY or timeout */
928 while(1) { 929 while(1) {
929#ifdef CONFIG_USB_STORAGE_DEBUG
930 char* mstr = master_slave == ATA_ADDRESS_DEVHEAD_STD ?
931 "Master" : "Slave";
932#endif
933 930
934 status = isd200_action( us, ACTION_ENUM, NULL, master_slave ); 931 status = isd200_action( us, ACTION_ENUM, NULL, master_slave );
935 if ( status != ISD200_GOOD ) 932 if ( status != ISD200_GOOD )
@@ -942,9 +939,13 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
942 939
943 if (!detect) { 940 if (!detect) {
944 if (regs[ATA_REG_STATUS_OFFSET] & ATA_BUSY) { 941 if (regs[ATA_REG_STATUS_OFFSET] & ATA_BUSY) {
945 US_DEBUGP(" %s status is still BSY, try again...\n",mstr); 942 usb_stor_dbg(us, " %s status is still BSY, try again...\n",
943 master_slave == ATA_ADDRESS_DEVHEAD_STD ?
944 "Master" : "Slave");
946 } else { 945 } else {
947 US_DEBUGP(" %s status !BSY, continue with next operation\n",mstr); 946 usb_stor_dbg(us, " %s status !BSY, continue with next operation\n",
947 master_slave == ATA_ADDRESS_DEVHEAD_STD ?
948 "Master" : "Slave");
948 break; 949 break;
949 } 950 }
950 } 951 }
@@ -953,11 +954,11 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
953 /* ATA_ERR (workaround for Archos CD-ROM) */ 954 /* ATA_ERR (workaround for Archos CD-ROM) */
954 else if (regs[ATA_REG_STATUS_OFFSET] & 955 else if (regs[ATA_REG_STATUS_OFFSET] &
955 (ATA_BUSY | ATA_DF | ATA_ERR)) { 956 (ATA_BUSY | ATA_DF | ATA_ERR)) {
956 US_DEBUGP(" Status indicates it is not ready, try again...\n"); 957 usb_stor_dbg(us, " Status indicates it is not ready, try again...\n");
957 } 958 }
958 /* check for DRDY, ATA devices set DRDY after SRST */ 959 /* check for DRDY, ATA devices set DRDY after SRST */
959 else if (regs[ATA_REG_STATUS_OFFSET] & ATA_DRDY) { 960 else if (regs[ATA_REG_STATUS_OFFSET] & ATA_DRDY) {
960 US_DEBUGP(" Identified ATA device\n"); 961 usb_stor_dbg(us, " Identified ATA device\n");
961 info->DeviceFlags |= DF_ATA_DEVICE; 962 info->DeviceFlags |= DF_ATA_DEVICE;
962 info->DeviceHead = master_slave; 963 info->DeviceHead = master_slave;
963 break; 964 break;
@@ -978,27 +979,27 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
978 */ 979 */
979 if ((master_slave & ATA_ADDRESS_DEVHEAD_SLAVE) && 980 if ((master_slave & ATA_ADDRESS_DEVHEAD_SLAVE) &&
980 !recheckAsMaster) { 981 !recheckAsMaster) {
981 US_DEBUGP(" Identified ATAPI device as slave. Rechecking again as master\n"); 982 usb_stor_dbg(us, " Identified ATAPI device as slave. Rechecking again as master\n");
982 recheckAsMaster = 1; 983 recheckAsMaster = 1;
983 master_slave = ATA_ADDRESS_DEVHEAD_STD; 984 master_slave = ATA_ADDRESS_DEVHEAD_STD;
984 } else { 985 } else {
985 US_DEBUGP(" Identified ATAPI device\n"); 986 usb_stor_dbg(us, " Identified ATAPI device\n");
986 info->DeviceHead = master_slave; 987 info->DeviceHead = master_slave;
987 988
988 status = isd200_atapi_soft_reset(us); 989 status = isd200_atapi_soft_reset(us);
989 break; 990 break;
990 } 991 }
991 } else { 992 } else {
992 US_DEBUGP(" Not ATA, not ATAPI. Weird.\n"); 993 usb_stor_dbg(us, " Not ATA, not ATAPI - Weird\n");
993 break; 994 break;
994 } 995 }
995 996
996 /* check for timeout on this request */ 997 /* check for timeout on this request */
997 if (time_after_eq(jiffies, endTime)) { 998 if (time_after_eq(jiffies, endTime)) {
998 if (!detect) 999 if (!detect)
999 US_DEBUGP(" BSY check timeout, just continue with next operation...\n"); 1000 usb_stor_dbg(us, " BSY check timeout, just continue with next operation...\n");
1000 else 1001 else
1001 US_DEBUGP(" Device detect timeout!\n"); 1002 usb_stor_dbg(us, " Device detect timeout!\n");
1002 break; 1003 break;
1003 } 1004 }
1004 } 1005 }
@@ -1020,7 +1021,7 @@ static int isd200_manual_enum(struct us_data *us)
1020 struct isd200_info *info = (struct isd200_info *)us->extra; 1021 struct isd200_info *info = (struct isd200_info *)us->extra;
1021 int retStatus = ISD200_GOOD; 1022 int retStatus = ISD200_GOOD;
1022 1023
1023 US_DEBUGP("Entering isd200_manual_enum\n"); 1024 usb_stor_dbg(us, "Entering isd200_manual_enum\n");
1024 1025
1025 retStatus = isd200_read_config(us); 1026 retStatus = isd200_read_config(us);
1026 if (retStatus == ISD200_GOOD) { 1027 if (retStatus == ISD200_GOOD) {
@@ -1039,14 +1040,15 @@ static int isd200_manual_enum(struct us_data *us)
1039 1040
1040 isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0; 1041 isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0;
1041 if (!(info->ConfigData.ATAConfig & ATACFG_MASTER)) { 1042 if (!(info->ConfigData.ATAConfig & ATACFG_MASTER)) {
1042 US_DEBUGP(" Setting Master/Slave selection to %d\n", isslave); 1043 usb_stor_dbg(us, " Setting Master/Slave selection to %d\n",
1044 isslave);
1043 info->ConfigData.ATAConfig &= 0x3f; 1045 info->ConfigData.ATAConfig &= 0x3f;
1044 info->ConfigData.ATAConfig |= (isslave<<6); 1046 info->ConfigData.ATAConfig |= (isslave<<6);
1045 retStatus = isd200_write_config(us); 1047 retStatus = isd200_write_config(us);
1046 } 1048 }
1047 } 1049 }
1048 1050
1049 US_DEBUGP("Leaving isd200_manual_enum %08X\n", retStatus); 1051 usb_stor_dbg(us, "Leaving isd200_manual_enum %08X\n", retStatus);
1050 return(retStatus); 1052 return(retStatus);
1051} 1053}
1052 1054
@@ -1064,35 +1066,35 @@ static void isd200_fix_driveid(u16 *id)
1064#endif 1066#endif
1065} 1067}
1066 1068
1067static void isd200_dump_driveid(u16 *id) 1069static void isd200_dump_driveid(struct us_data *us, u16 *id)
1068{ 1070{
1069 US_DEBUGP(" Identify Data Structure:\n"); 1071 usb_stor_dbg(us, " Identify Data Structure:\n");
1070 US_DEBUGP(" config = 0x%x\n", id[ATA_ID_CONFIG]); 1072 usb_stor_dbg(us, " config = 0x%x\n", id[ATA_ID_CONFIG]);
1071 US_DEBUGP(" cyls = 0x%x\n", id[ATA_ID_CYLS]); 1073 usb_stor_dbg(us, " cyls = 0x%x\n", id[ATA_ID_CYLS]);
1072 US_DEBUGP(" heads = 0x%x\n", id[ATA_ID_HEADS]); 1074 usb_stor_dbg(us, " heads = 0x%x\n", id[ATA_ID_HEADS]);
1073 US_DEBUGP(" track_bytes = 0x%x\n", id[4]); 1075 usb_stor_dbg(us, " track_bytes = 0x%x\n", id[4]);
1074 US_DEBUGP(" sector_bytes = 0x%x\n", id[5]); 1076 usb_stor_dbg(us, " sector_bytes = 0x%x\n", id[5]);
1075 US_DEBUGP(" sectors = 0x%x\n", id[ATA_ID_SECTORS]); 1077 usb_stor_dbg(us, " sectors = 0x%x\n", id[ATA_ID_SECTORS]);
1076 US_DEBUGP(" serial_no[0] = 0x%x\n", *(char *)&id[ATA_ID_SERNO]); 1078 usb_stor_dbg(us, " serial_no[0] = 0x%x\n", *(char *)&id[ATA_ID_SERNO]);
1077 US_DEBUGP(" buf_type = 0x%x\n", id[20]); 1079 usb_stor_dbg(us, " buf_type = 0x%x\n", id[20]);
1078 US_DEBUGP(" buf_size = 0x%x\n", id[ATA_ID_BUF_SIZE]); 1080 usb_stor_dbg(us, " buf_size = 0x%x\n", id[ATA_ID_BUF_SIZE]);
1079 US_DEBUGP(" ecc_bytes = 0x%x\n", id[22]); 1081 usb_stor_dbg(us, " ecc_bytes = 0x%x\n", id[22]);
1080 US_DEBUGP(" fw_rev[0] = 0x%x\n", *(char *)&id[ATA_ID_FW_REV]); 1082 usb_stor_dbg(us, " fw_rev[0] = 0x%x\n", *(char *)&id[ATA_ID_FW_REV]);
1081 US_DEBUGP(" model[0] = 0x%x\n", *(char *)&id[ATA_ID_PROD]); 1083 usb_stor_dbg(us, " model[0] = 0x%x\n", *(char *)&id[ATA_ID_PROD]);
1082 US_DEBUGP(" max_multsect = 0x%x\n", id[ATA_ID_MAX_MULTSECT] & 0xff); 1084 usb_stor_dbg(us, " max_multsect = 0x%x\n", id[ATA_ID_MAX_MULTSECT] & 0xff);
1083 US_DEBUGP(" dword_io = 0x%x\n", id[ATA_ID_DWORD_IO]); 1085 usb_stor_dbg(us, " dword_io = 0x%x\n", id[ATA_ID_DWORD_IO]);
1084 US_DEBUGP(" capability = 0x%x\n", id[ATA_ID_CAPABILITY] >> 8); 1086 usb_stor_dbg(us, " capability = 0x%x\n", id[ATA_ID_CAPABILITY] >> 8);
1085 US_DEBUGP(" tPIO = 0x%x\n", id[ATA_ID_OLD_PIO_MODES] >> 8); 1087 usb_stor_dbg(us, " tPIO = 0x%x\n", id[ATA_ID_OLD_PIO_MODES] >> 8);
1086 US_DEBUGP(" tDMA = 0x%x\n", id[ATA_ID_OLD_DMA_MODES] >> 8); 1088 usb_stor_dbg(us, " tDMA = 0x%x\n", id[ATA_ID_OLD_DMA_MODES] >> 8);
1087 US_DEBUGP(" field_valid = 0x%x\n", id[ATA_ID_FIELD_VALID]); 1089 usb_stor_dbg(us, " field_valid = 0x%x\n", id[ATA_ID_FIELD_VALID]);
1088 US_DEBUGP(" cur_cyls = 0x%x\n", id[ATA_ID_CUR_CYLS]); 1090 usb_stor_dbg(us, " cur_cyls = 0x%x\n", id[ATA_ID_CUR_CYLS]);
1089 US_DEBUGP(" cur_heads = 0x%x\n", id[ATA_ID_CUR_HEADS]); 1091 usb_stor_dbg(us, " cur_heads = 0x%x\n", id[ATA_ID_CUR_HEADS]);
1090 US_DEBUGP(" cur_sectors = 0x%x\n", id[ATA_ID_CUR_SECTORS]); 1092 usb_stor_dbg(us, " cur_sectors = 0x%x\n", id[ATA_ID_CUR_SECTORS]);
1091 US_DEBUGP(" cur_capacity = 0x%x\n", ata_id_u32(id, 57)); 1093 usb_stor_dbg(us, " cur_capacity = 0x%x\n", ata_id_u32(id, 57));
1092 US_DEBUGP(" multsect = 0x%x\n", id[ATA_ID_MULTSECT] & 0xff); 1094 usb_stor_dbg(us, " multsect = 0x%x\n", id[ATA_ID_MULTSECT] & 0xff);
1093 US_DEBUGP(" lba_capacity = 0x%x\n", ata_id_u32(id, ATA_ID_LBA_CAPACITY)); 1095 usb_stor_dbg(us, " lba_capacity = 0x%x\n", ata_id_u32(id, ATA_ID_LBA_CAPACITY));
1094 US_DEBUGP(" command_set_1 = 0x%x\n", id[ATA_ID_COMMAND_SET_1]); 1096 usb_stor_dbg(us, " command_set_1 = 0x%x\n", id[ATA_ID_COMMAND_SET_1]);
1095 US_DEBUGP(" command_set_2 = 0x%x\n", id[ATA_ID_COMMAND_SET_2]); 1097 usb_stor_dbg(us, " command_set_2 = 0x%x\n", id[ATA_ID_COMMAND_SET_2]);
1096} 1098}
1097 1099
1098/************************************************************************** 1100/**************************************************************************
@@ -1109,7 +1111,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
1109 int retStatus = ISD200_GOOD; 1111 int retStatus = ISD200_GOOD;
1110 u16 *id = info->id; 1112 u16 *id = info->id;
1111 1113
1112 US_DEBUGP("Entering isd200_get_inquiry_data\n"); 1114 usb_stor_dbg(us, "Entering isd200_get_inquiry_data\n");
1113 1115
1114 /* set default to Master */ 1116 /* set default to Master */
1115 info->DeviceHead = ATA_ADDRESS_DEVHEAD_STD; 1117 info->DeviceHead = ATA_ADDRESS_DEVHEAD_STD;
@@ -1127,7 +1129,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
1127 id, ATA_ID_WORDS * 2); 1129 id, ATA_ID_WORDS * 2);
1128 if (transferStatus != ISD200_TRANSPORT_GOOD) { 1130 if (transferStatus != ISD200_TRANSPORT_GOOD) {
1129 /* Error issuing ATA Command Identify */ 1131 /* Error issuing ATA Command Identify */
1130 US_DEBUGP(" Error issuing ATA Command Identify\n"); 1132 usb_stor_dbg(us, " Error issuing ATA Command Identify\n");
1131 retStatus = ISD200_ERROR; 1133 retStatus = ISD200_ERROR;
1132 } else { 1134 } else {
1133 /* ATA Command Identify successful */ 1135 /* ATA Command Identify successful */
@@ -1136,7 +1138,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
1136 __u16 *dest; 1138 __u16 *dest;
1137 1139
1138 isd200_fix_driveid(id); 1140 isd200_fix_driveid(id);
1139 isd200_dump_driveid(id); 1141 isd200_dump_driveid(us, id);
1140 1142
1141 memset(&info->InquiryData, 0, sizeof(info->InquiryData)); 1143 memset(&info->InquiryData, 0, sizeof(info->InquiryData));
1142 1144
@@ -1170,7 +1172,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
1170 1172
1171 /* determine if it supports Media Status Notification */ 1173 /* determine if it supports Media Status Notification */
1172 if (id[ATA_ID_COMMAND_SET_2] & COMMANDSET_MEDIA_STATUS) { 1174 if (id[ATA_ID_COMMAND_SET_2] & COMMANDSET_MEDIA_STATUS) {
1173 US_DEBUGP(" Device supports Media Status Notification\n"); 1175 usb_stor_dbg(us, " Device supports Media Status Notification\n");
1174 1176
1175 /* Indicate that it is enabled, even though it is not 1177 /* Indicate that it is enabled, even though it is not
1176 * This allows the lock/unlock of the media to work 1178 * This allows the lock/unlock of the media to work
@@ -1190,7 +1192,8 @@ static int isd200_get_inquiry_data( struct us_data *us )
1190 us->protocol_name = "Transparent SCSI"; 1192 us->protocol_name = "Transparent SCSI";
1191 us->proto_handler = usb_stor_transparent_scsi_command; 1193 us->proto_handler = usb_stor_transparent_scsi_command;
1192 1194
1193 US_DEBUGP("Protocol changed to: %s\n", us->protocol_name); 1195 usb_stor_dbg(us, "Protocol changed to: %s\n",
1196 us->protocol_name);
1194 1197
1195 /* Free driver structure */ 1198 /* Free driver structure */
1196 us->extra_destructor(info); 1199 us->extra_destructor(info);
@@ -1200,7 +1203,7 @@ static int isd200_get_inquiry_data( struct us_data *us )
1200 } 1203 }
1201 } 1204 }
1202 1205
1203 US_DEBUGP("Leaving isd200_get_inquiry_data %08X\n", retStatus); 1206 usb_stor_dbg(us, "Leaving isd200_get_inquiry_data %08X\n", retStatus);
1204 1207
1205 return(retStatus); 1208 return(retStatus);
1206} 1209}
@@ -1231,7 +1234,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1231 /* SCSI Command */ 1234 /* SCSI Command */
1232 switch (srb->cmnd[0]) { 1235 switch (srb->cmnd[0]) {
1233 case INQUIRY: 1236 case INQUIRY:
1234 US_DEBUGP(" ATA OUT - INQUIRY\n"); 1237 usb_stor_dbg(us, " ATA OUT - INQUIRY\n");
1235 1238
1236 /* copy InquiryData */ 1239 /* copy InquiryData */
1237 usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData, 1240 usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData,
@@ -1241,7 +1244,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1241 break; 1244 break;
1242 1245
1243 case MODE_SENSE: 1246 case MODE_SENSE:
1244 US_DEBUGP(" ATA OUT - SCSIOP_MODE_SENSE\n"); 1247 usb_stor_dbg(us, " ATA OUT - SCSIOP_MODE_SENSE\n");
1245 1248
1246 /* Initialize the return buffer */ 1249 /* Initialize the return buffer */
1247 usb_stor_set_xfer_buf(senseData, sizeof(senseData), srb); 1250 usb_stor_set_xfer_buf(senseData, sizeof(senseData), srb);
@@ -1255,14 +1258,14 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1255 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1258 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1256 isd200_srb_set_bufflen(srb, 0); 1259 isd200_srb_set_bufflen(srb, 0);
1257 } else { 1260 } else {
1258 US_DEBUGP(" Media Status not supported, just report okay\n"); 1261 usb_stor_dbg(us, " Media Status not supported, just report okay\n");
1259 srb->result = SAM_STAT_GOOD; 1262 srb->result = SAM_STAT_GOOD;
1260 sendToTransport = 0; 1263 sendToTransport = 0;
1261 } 1264 }
1262 break; 1265 break;
1263 1266
1264 case TEST_UNIT_READY: 1267 case TEST_UNIT_READY:
1265 US_DEBUGP(" ATA OUT - SCSIOP_TEST_UNIT_READY\n"); 1268 usb_stor_dbg(us, " ATA OUT - SCSIOP_TEST_UNIT_READY\n");
1266 1269
1267 if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED) 1270 if (info->DeviceFlags & DF_MEDIA_STATUS_ENABLED)
1268 { 1271 {
@@ -1273,7 +1276,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1273 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1276 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1274 isd200_srb_set_bufflen(srb, 0); 1277 isd200_srb_set_bufflen(srb, 0);
1275 } else { 1278 } else {
1276 US_DEBUGP(" Media Status not supported, just report okay\n"); 1279 usb_stor_dbg(us, " Media Status not supported, just report okay\n");
1277 srb->result = SAM_STAT_GOOD; 1280 srb->result = SAM_STAT_GOOD;
1278 sendToTransport = 0; 1281 sendToTransport = 0;
1279 } 1282 }
@@ -1284,7 +1287,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1284 unsigned long capacity; 1287 unsigned long capacity;
1285 struct read_capacity_data readCapacityData; 1288 struct read_capacity_data readCapacityData;
1286 1289
1287 US_DEBUGP(" ATA OUT - SCSIOP_READ_CAPACITY\n"); 1290 usb_stor_dbg(us, " ATA OUT - SCSIOP_READ_CAPACITY\n");
1288 1291
1289 if (ata_id_has_lba(id)) 1292 if (ata_id_has_lba(id))
1290 capacity = ata_id_u32(id, ATA_ID_LBA_CAPACITY) - 1; 1293 capacity = ata_id_u32(id, ATA_ID_LBA_CAPACITY) - 1;
@@ -1303,7 +1306,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1303 break; 1306 break;
1304 1307
1305 case READ_10: 1308 case READ_10:
1306 US_DEBUGP(" ATA OUT - SCSIOP_READ\n"); 1309 usb_stor_dbg(us, " ATA OUT - SCSIOP_READ\n");
1307 1310
1308 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); 1311 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]);
1309 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; 1312 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
@@ -1335,7 +1338,7 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1335 break; 1338 break;
1336 1339
1337 case WRITE_10: 1340 case WRITE_10:
1338 US_DEBUGP(" ATA OUT - SCSIOP_WRITE\n"); 1341 usb_stor_dbg(us, " ATA OUT - SCSIOP_WRITE\n");
1339 1342
1340 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]); 1343 lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]);
1341 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8]; 1344 blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
@@ -1367,10 +1370,11 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1367 break; 1370 break;
1368 1371
1369 case ALLOW_MEDIUM_REMOVAL: 1372 case ALLOW_MEDIUM_REMOVAL:
1370 US_DEBUGP(" ATA OUT - SCSIOP_MEDIUM_REMOVAL\n"); 1373 usb_stor_dbg(us, " ATA OUT - SCSIOP_MEDIUM_REMOVAL\n");
1371 1374
1372 if (info->DeviceFlags & DF_REMOVABLE_MEDIA) { 1375 if (info->DeviceFlags & DF_REMOVABLE_MEDIA) {
1373 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb->cmnd[4]); 1376 usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n",
1377 srb->cmnd[4]);
1374 1378
1375 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; 1379 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
1376 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; 1380 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
@@ -1380,25 +1384,25 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1380 ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK; 1384 ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
1381 isd200_srb_set_bufflen(srb, 0); 1385 isd200_srb_set_bufflen(srb, 0);
1382 } else { 1386 } else {
1383 US_DEBUGP(" Not removeable media, just report okay\n"); 1387 usb_stor_dbg(us, " Not removeable media, just report okay\n");
1384 srb->result = SAM_STAT_GOOD; 1388 srb->result = SAM_STAT_GOOD;
1385 sendToTransport = 0; 1389 sendToTransport = 0;
1386 } 1390 }
1387 break; 1391 break;
1388 1392
1389 case START_STOP: 1393 case START_STOP:
1390 US_DEBUGP(" ATA OUT - SCSIOP_START_STOP_UNIT\n"); 1394 usb_stor_dbg(us, " ATA OUT - SCSIOP_START_STOP_UNIT\n");
1391 US_DEBUGP(" srb->cmnd[4] = 0x%X\n", srb->cmnd[4]); 1395 usb_stor_dbg(us, " srb->cmnd[4] = 0x%X\n", srb->cmnd[4]);
1392 1396
1393 if ((srb->cmnd[4] & 0x3) == 0x2) { 1397 if ((srb->cmnd[4] & 0x3) == 0x2) {
1394 US_DEBUGP(" Media Eject\n"); 1398 usb_stor_dbg(us, " Media Eject\n");
1395 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; 1399 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
1396 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; 1400 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
1397 ataCdb->generic.TransferBlockSize = 0; 1401 ataCdb->generic.TransferBlockSize = 0;
1398 ataCdb->generic.RegisterSelect = REG_COMMAND; 1402 ataCdb->generic.RegisterSelect = REG_COMMAND;
1399 ataCdb->write.CommandByte = ATA_COMMAND_MEDIA_EJECT; 1403 ataCdb->write.CommandByte = ATA_COMMAND_MEDIA_EJECT;
1400 } else if ((srb->cmnd[4] & 0x3) == 0x1) { 1404 } else if ((srb->cmnd[4] & 0x3) == 0x1) {
1401 US_DEBUGP(" Get Media Status\n"); 1405 usb_stor_dbg(us, " Get Media Status\n");
1402 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand; 1406 ataCdb->generic.SignatureByte0 = info->ConfigData.ATAMajorCommand;
1403 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand; 1407 ataCdb->generic.SignatureByte1 = info->ConfigData.ATAMinorCommand;
1404 ataCdb->generic.TransferBlockSize = 1; 1408 ataCdb->generic.TransferBlockSize = 1;
@@ -1406,14 +1410,15 @@ static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
1406 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS; 1410 ataCdb->write.CommandByte = ATA_COMMAND_GET_MEDIA_STATUS;
1407 isd200_srb_set_bufflen(srb, 0); 1411 isd200_srb_set_bufflen(srb, 0);
1408 } else { 1412 } else {
1409 US_DEBUGP(" Nothing to do, just report okay\n"); 1413 usb_stor_dbg(us, " Nothing to do, just report okay\n");
1410 srb->result = SAM_STAT_GOOD; 1414 srb->result = SAM_STAT_GOOD;
1411 sendToTransport = 0; 1415 sendToTransport = 0;
1412 } 1416 }
1413 break; 1417 break;
1414 1418
1415 default: 1419 default:
1416 US_DEBUGP("Unsupported SCSI command - 0x%X\n", srb->cmnd[0]); 1420 usb_stor_dbg(us, "Unsupported SCSI command - 0x%X\n",
1421 srb->cmnd[0]);
1417 srb->result = DID_ERROR << 16; 1422 srb->result = DID_ERROR << 16;
1418 sendToTransport = 0; 1423 sendToTransport = 0;
1419 break; 1424 break;
@@ -1457,8 +1462,7 @@ static int isd200_init_info(struct us_data *us)
1457 retStatus = ISD200_ERROR; 1462 retStatus = ISD200_ERROR;
1458 else { 1463 else {
1459 info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL); 1464 info->id = kzalloc(ATA_ID_WORDS * 2, GFP_KERNEL);
1460 info->RegsBuf = (unsigned char *) 1465 info->RegsBuf = kmalloc(sizeof(info->ATARegs), GFP_KERNEL);
1461 kmalloc(sizeof(info->ATARegs), GFP_KERNEL);
1462 info->srb.sense_buffer = 1466 info->srb.sense_buffer =
1463 kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); 1467 kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
1464 if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) { 1468 if (!info->id || !info->RegsBuf || !info->srb.sense_buffer) {
@@ -1471,8 +1475,7 @@ static int isd200_init_info(struct us_data *us)
1471 if (retStatus == ISD200_GOOD) { 1475 if (retStatus == ISD200_GOOD) {
1472 us->extra = info; 1476 us->extra = info;
1473 us->extra_destructor = isd200_free_info_ptrs; 1477 us->extra_destructor = isd200_free_info_ptrs;
1474 } else 1478 }
1475 US_DEBUGP("ERROR - kmalloc failure\n");
1476 1479
1477 return retStatus; 1480 return retStatus;
1478} 1481}
@@ -1483,19 +1486,19 @@ static int isd200_init_info(struct us_data *us)
1483 1486
1484static int isd200_Initialization(struct us_data *us) 1487static int isd200_Initialization(struct us_data *us)
1485{ 1488{
1486 US_DEBUGP("ISD200 Initialization...\n"); 1489 usb_stor_dbg(us, "ISD200 Initialization...\n");
1487 1490
1488 /* Initialize ISD200 info struct */ 1491 /* Initialize ISD200 info struct */
1489 1492
1490 if (isd200_init_info(us) == ISD200_ERROR) { 1493 if (isd200_init_info(us) == ISD200_ERROR) {
1491 US_DEBUGP("ERROR Initializing ISD200 Info struct\n"); 1494 usb_stor_dbg(us, "ERROR Initializing ISD200 Info struct\n");
1492 } else { 1495 } else {
1493 /* Get device specific data */ 1496 /* Get device specific data */
1494 1497
1495 if (isd200_get_inquiry_data(us) != ISD200_GOOD) 1498 if (isd200_get_inquiry_data(us) != ISD200_GOOD)
1496 US_DEBUGP("ISD200 Initialization Failure\n"); 1499 usb_stor_dbg(us, "ISD200 Initialization Failure\n");
1497 else 1500 else
1498 US_DEBUGP("ISD200 Initialization complete\n"); 1501 usb_stor_dbg(us, "ISD200 Initialization complete\n");
1499 } 1502 }
1500 1503
1501 return 0; 1504 return 0;
@@ -1520,7 +1523,7 @@ static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
1520 /* Make sure driver was initialized */ 1523 /* Make sure driver was initialized */
1521 1524
1522 if (us->extra == NULL) 1525 if (us->extra == NULL)
1523 US_DEBUGP("ERROR Driver not initialized\n"); 1526 usb_stor_dbg(us, "ERROR Driver not initialized\n");
1524 1527
1525 scsi_set_resid(srb, 0); 1528 scsi_set_resid(srb, 0);
1526 /* scsi_bufflen might change in protocol translation to ata */ 1529 /* scsi_bufflen might change in protocol translation to ata */
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index ddc78780b1ad..563078be6547 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -118,7 +118,7 @@ static inline int jumpshot_bulk_read(struct us_data *us,
118 if (len == 0) 118 if (len == 0)
119 return USB_STOR_XFER_GOOD; 119 return USB_STOR_XFER_GOOD;
120 120
121 US_DEBUGP("jumpshot_bulk_read: len = %d\n", len); 121 usb_stor_dbg(us, "len = %d\n", len);
122 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 122 return usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
123 data, len, NULL); 123 data, len, NULL);
124} 124}
@@ -131,7 +131,7 @@ static inline int jumpshot_bulk_write(struct us_data *us,
131 if (len == 0) 131 if (len == 0)
132 return USB_STOR_XFER_GOOD; 132 return USB_STOR_XFER_GOOD;
133 133
134 US_DEBUGP("jumpshot_bulk_write: len = %d\n", len); 134 usb_stor_dbg(us, "len = %d\n", len);
135 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 135 return usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
136 data, len, NULL); 136 data, len, NULL);
137} 137}
@@ -152,8 +152,7 @@ static int jumpshot_get_status(struct us_data *us)
152 return USB_STOR_TRANSPORT_ERROR; 152 return USB_STOR_TRANSPORT_ERROR;
153 153
154 if (us->iobuf[0] != 0x50) { 154 if (us->iobuf[0] != 0x50) {
155 US_DEBUGP("jumpshot_get_status: 0x%2x\n", 155 usb_stor_dbg(us, "0x%2x\n", us->iobuf[0]);
156 us->iobuf[0]);
157 return USB_STOR_TRANSPORT_ERROR; 156 return USB_STOR_TRANSPORT_ERROR;
158 } 157 }
159 158
@@ -218,7 +217,7 @@ static int jumpshot_read_data(struct us_data *us,
218 if (result != USB_STOR_XFER_GOOD) 217 if (result != USB_STOR_XFER_GOOD)
219 goto leave; 218 goto leave;
220 219
221 US_DEBUGP("jumpshot_read_data: %d bytes\n", len); 220 usb_stor_dbg(us, "%d bytes\n", len);
222 221
223 // Store the data in the transfer buffer 222 // Store the data in the transfer buffer
224 usb_stor_access_xfer_buf(buffer, len, us->srb, 223 usb_stor_access_xfer_buf(buffer, len, us->srb,
@@ -314,7 +313,7 @@ static int jumpshot_write_data(struct us_data *us,
314 } while ((result != USB_STOR_TRANSPORT_GOOD) && (waitcount < 10)); 313 } while ((result != USB_STOR_TRANSPORT_GOOD) && (waitcount < 10));
315 314
316 if (result != USB_STOR_TRANSPORT_GOOD) 315 if (result != USB_STOR_TRANSPORT_GOOD)
317 US_DEBUGP("jumpshot_write_data: Gah! Waitcount = 10. Bad write!?\n"); 316 usb_stor_dbg(us, "Gah! Waitcount = 10. Bad write!?\n");
318 317
319 sector += thistime; 318 sector += thistime;
320 totallen -= len; 319 totallen -= len;
@@ -349,8 +348,7 @@ static int jumpshot_id_device(struct us_data *us,
349 0, 0x20, 0, 6, command, 2); 348 0, 0x20, 0, 6, command, 2);
350 349
351 if (rc != USB_STOR_XFER_GOOD) { 350 if (rc != USB_STOR_XFER_GOOD) {
352 US_DEBUGP("jumpshot_id_device: Gah! " 351 usb_stor_dbg(us, "Gah! send_control for read_capacity failed\n");
353 "send_control for read_capacity failed\n");
354 rc = USB_STOR_TRANSPORT_ERROR; 352 rc = USB_STOR_TRANSPORT_ERROR;
355 goto leave; 353 goto leave;
356 } 354 }
@@ -400,17 +398,17 @@ static int jumpshot_handle_mode_sense(struct us_data *us,
400 398
401 switch (pc) { 399 switch (pc) {
402 case 0x0: 400 case 0x0:
403 US_DEBUGP("jumpshot_handle_mode_sense: Current values\n"); 401 usb_stor_dbg(us, "Current values\n");
404 break; 402 break;
405 case 0x1: 403 case 0x1:
406 US_DEBUGP("jumpshot_handle_mode_sense: Changeable values\n"); 404 usb_stor_dbg(us, "Changeable values\n");
407 break; 405 break;
408 case 0x2: 406 case 0x2:
409 US_DEBUGP("jumpshot_handle_mode_sense: Default values\n"); 407 usb_stor_dbg(us, "Default values\n");
410 break; 408 break;
411 case 0x3: 409 case 0x3:
412 US_DEBUGP("jumpshot_handle_mode_sense: Saves values\n"); 410 usb_stor_dbg(us, "Saves values\n");
413 break; 411 break;
414 } 412 }
415 413
416 memset(ptr, 0, 8); 414 memset(ptr, 0, 8);
@@ -494,17 +492,16 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
494 492
495 if (!us->extra) { 493 if (!us->extra) {
496 us->extra = kzalloc(sizeof(struct jumpshot_info), GFP_NOIO); 494 us->extra = kzalloc(sizeof(struct jumpshot_info), GFP_NOIO);
497 if (!us->extra) { 495 if (!us->extra)
498 US_DEBUGP("jumpshot_transport: Gah! Can't allocate storage for jumpshot info struct!\n");
499 return USB_STOR_TRANSPORT_ERROR; 496 return USB_STOR_TRANSPORT_ERROR;
500 } 497
501 us->extra_destructor = jumpshot_info_destructor; 498 us->extra_destructor = jumpshot_info_destructor;
502 } 499 }
503 500
504 info = (struct jumpshot_info *) (us->extra); 501 info = (struct jumpshot_info *) (us->extra);
505 502
506 if (srb->cmnd[0] == INQUIRY) { 503 if (srb->cmnd[0] == INQUIRY) {
507 US_DEBUGP("jumpshot_transport: INQUIRY. Returning bogus response.\n"); 504 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
508 memcpy(ptr, inquiry_response, sizeof(inquiry_response)); 505 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
509 fill_inquiry_response(us, ptr, 36); 506 fill_inquiry_response(us, ptr, 36);
510 return USB_STOR_TRANSPORT_GOOD; 507 return USB_STOR_TRANSPORT_GOOD;
@@ -521,8 +518,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
521 if (rc != USB_STOR_TRANSPORT_GOOD) 518 if (rc != USB_STOR_TRANSPORT_GOOD)
522 return rc; 519 return rc;
523 520
524 US_DEBUGP("jumpshot_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n", 521 usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
525 info->sectors, info->ssize); 522 info->sectors, info->ssize);
526 523
527 // build the reply 524 // build the reply
528 // 525 //
@@ -534,7 +531,7 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
534 } 531 }
535 532
536 if (srb->cmnd[0] == MODE_SELECT_10) { 533 if (srb->cmnd[0] == MODE_SELECT_10) {
537 US_DEBUGP("jumpshot_transport: Gah! MODE_SELECT_10.\n"); 534 usb_stor_dbg(us, "Gah! MODE_SELECT_10\n");
538 return USB_STOR_TRANSPORT_ERROR; 535 return USB_STOR_TRANSPORT_ERROR;
539 } 536 }
540 537
@@ -544,7 +541,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
544 541
545 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 542 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
546 543
547 US_DEBUGP("jumpshot_transport: READ_10: read block 0x%04lx count %ld\n", block, blocks); 544 usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n",
545 block, blocks);
548 return jumpshot_read_data(us, info, block, blocks); 546 return jumpshot_read_data(us, info, block, blocks);
549 } 547 }
550 548
@@ -557,7 +555,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
557 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 555 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
558 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 556 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
559 557
560 US_DEBUGP("jumpshot_transport: READ_12: read block 0x%04lx count %ld\n", block, blocks); 558 usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n",
559 block, blocks);
561 return jumpshot_read_data(us, info, block, blocks); 560 return jumpshot_read_data(us, info, block, blocks);
562 } 561 }
563 562
@@ -567,7 +566,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
567 566
568 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 567 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
569 568
570 US_DEBUGP("jumpshot_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks); 569 usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n",
570 block, blocks);
571 return jumpshot_write_data(us, info, block, blocks); 571 return jumpshot_write_data(us, info, block, blocks);
572 } 572 }
573 573
@@ -580,18 +580,19 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
580 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 580 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
581 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 581 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
582 582
583 US_DEBUGP("jumpshot_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks); 583 usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n",
584 block, blocks);
584 return jumpshot_write_data(us, info, block, blocks); 585 return jumpshot_write_data(us, info, block, blocks);
585 } 586 }
586 587
587 588
588 if (srb->cmnd[0] == TEST_UNIT_READY) { 589 if (srb->cmnd[0] == TEST_UNIT_READY) {
589 US_DEBUGP("jumpshot_transport: TEST_UNIT_READY.\n"); 590 usb_stor_dbg(us, "TEST_UNIT_READY\n");
590 return jumpshot_get_status(us); 591 return jumpshot_get_status(us);
591 } 592 }
592 593
593 if (srb->cmnd[0] == REQUEST_SENSE) { 594 if (srb->cmnd[0] == REQUEST_SENSE) {
594 US_DEBUGP("jumpshot_transport: REQUEST_SENSE.\n"); 595 usb_stor_dbg(us, "REQUEST_SENSE\n");
595 596
596 memset(ptr, 0, 18); 597 memset(ptr, 0, 18);
597 ptr[0] = 0xF0; 598 ptr[0] = 0xF0;
@@ -605,12 +606,12 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
605 } 606 }
606 607
607 if (srb->cmnd[0] == MODE_SENSE) { 608 if (srb->cmnd[0] == MODE_SENSE) {
608 US_DEBUGP("jumpshot_transport: MODE_SENSE_6 detected\n"); 609 usb_stor_dbg(us, "MODE_SENSE_6 detected\n");
609 return jumpshot_handle_mode_sense(us, srb, 1); 610 return jumpshot_handle_mode_sense(us, srb, 1);
610 } 611 }
611 612
612 if (srb->cmnd[0] == MODE_SENSE_10) { 613 if (srb->cmnd[0] == MODE_SENSE_10) {
613 US_DEBUGP("jumpshot_transport: MODE_SENSE_10 detected\n"); 614 usb_stor_dbg(us, "MODE_SENSE_10 detected\n");
614 return jumpshot_handle_mode_sense(us, srb, 0); 615 return jumpshot_handle_mode_sense(us, srb, 0);
615 } 616 }
616 617
@@ -624,7 +625,7 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
624 if (srb->cmnd[0] == START_STOP) { 625 if (srb->cmnd[0] == START_STOP) {
625 /* this is used by sd.c'check_scsidisk_media_change to detect 626 /* this is used by sd.c'check_scsidisk_media_change to detect
626 media change */ 627 media change */
627 US_DEBUGP("jumpshot_transport: START_STOP.\n"); 628 usb_stor_dbg(us, "START_STOP\n");
628 /* the first jumpshot_id_device after a media change returns 629 /* the first jumpshot_id_device after a media change returns
629 an error (determined experimentally) */ 630 an error (determined experimentally) */
630 rc = jumpshot_id_device(us, info); 631 rc = jumpshot_id_device(us, info);
@@ -638,8 +639,8 @@ static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
638 return rc; 639 return rc;
639 } 640 }
640 641
641 US_DEBUGP("jumpshot_transport: Gah! Unknown command: %d (0x%x)\n", 642 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
642 srb->cmnd[0], srb->cmnd[0]); 643 srb->cmnd[0], srb->cmnd[0]);
643 info->sense_key = 0x05; 644 info->sense_key = 0x05;
644 info->sense_asc = 0x20; 645 info->sense_asc = 0x20;
645 info->sense_ascq = 0x00; 646 info->sense_ascq = 0x00;
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
index f085ffb606c8..94d16ee5e84b 100644
--- a/drivers/usb/storage/karma.c
+++ b/drivers/usb/storage/karma.c
@@ -106,7 +106,7 @@ static int rio_karma_send_command(char cmd, struct us_data *us)
106 static unsigned char seq = 1; 106 static unsigned char seq = 1;
107 struct karma_data *data = (struct karma_data *) us->extra; 107 struct karma_data *data = (struct karma_data *) us->extra;
108 108
109 US_DEBUGP("karma: sending command %04x\n", cmd); 109 usb_stor_dbg(us, "sending command %04x\n", cmd);
110 memset(us->iobuf, 0, RIO_SEND_LEN); 110 memset(us->iobuf, 0, RIO_SEND_LEN);
111 memcpy(us->iobuf, RIO_PREFIX, RIO_PREFIX_LEN); 111 memcpy(us->iobuf, RIO_PREFIX, RIO_PREFIX_LEN);
112 us->iobuf[5] = cmd; 112 us->iobuf[5] = cmd;
@@ -139,10 +139,10 @@ static int rio_karma_send_command(char cmd, struct us_data *us)
139 if (seq == 0) 139 if (seq == 0)
140 seq = 1; 140 seq = 1;
141 141
142 US_DEBUGP("karma: sent command %04x\n", cmd); 142 usb_stor_dbg(us, "sent command %04x\n", cmd);
143 return 0; 143 return 0;
144err: 144err:
145 US_DEBUGP("karma: command %04x failed\n", cmd); 145 usb_stor_dbg(us, "command %04x failed\n", cmd);
146 return USB_STOR_TRANSPORT_FAILED; 146 return USB_STOR_TRANSPORT_FAILED;
147} 147}
148 148
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index cb79de61f4c8..26964895c88b 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -195,6 +195,7 @@ static int onetouch_connect_input(struct us_data *ss)
195 195
196 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); 196 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
197 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); 197 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
198 maxp = min(maxp, ONETOUCH_PKT_LEN);
198 199
199 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL); 200 onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL);
200 input_dev = input_allocate_device(); 201 input_dev = input_allocate_device();
@@ -245,8 +246,7 @@ static int onetouch_connect_input(struct us_data *ss)
245 input_dev->open = usb_onetouch_open; 246 input_dev->open = usb_onetouch_open;
246 input_dev->close = usb_onetouch_close; 247 input_dev->close = usb_onetouch_close;
247 248
248 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, 249 usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, maxp,
249 (maxp > 8 ? 8 : maxp),
250 usb_onetouch_irq, onetouch, endpoint->bInterval); 250 usb_onetouch_irq, onetouch, endpoint->bInterval);
251 onetouch->irq->transfer_dma = onetouch->data_dma; 251 onetouch->irq->transfer_dma = onetouch->data_dma;
252 onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 252 onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
diff --git a/drivers/usb/storage/option_ms.c b/drivers/usb/storage/option_ms.c
index e0f76bb05915..b2b35b1d7de8 100644
--- a/drivers/usb/storage/option_ms.c
+++ b/drivers/usb/storage/option_ms.c
@@ -50,7 +50,7 @@ static int option_rezero(struct us_data *us)
50 char *buffer; 50 char *buffer;
51 int result; 51 int result;
52 52
53 US_DEBUGP("Option MS: %s", "DEVICE MODE SWITCH\n"); 53 usb_stor_dbg(us, "Option MS: %s\n", "DEVICE MODE SWITCH");
54 54
55 buffer = kzalloc(RESPONSE_LEN, GFP_KERNEL); 55 buffer = kzalloc(RESPONSE_LEN, GFP_KERNEL);
56 if (buffer == NULL) 56 if (buffer == NULL)
@@ -95,7 +95,7 @@ static int option_inquiry(struct us_data *us)
95 char *buffer; 95 char *buffer;
96 int result; 96 int result;
97 97
98 US_DEBUGP("Option MS: %s", "device inquiry for vendor name\n"); 98 usb_stor_dbg(us, "Option MS: %s\n", "device inquiry for vendor name");
99 99
100 buffer = kzalloc(0x24, GFP_KERNEL); 100 buffer = kzalloc(0x24, GFP_KERNEL);
101 if (buffer == NULL) 101 if (buffer == NULL)
@@ -138,31 +138,32 @@ int option_ms_init(struct us_data *us)
138{ 138{
139 int result; 139 int result;
140 140
141 US_DEBUGP("Option MS: option_ms_init called\n"); 141 usb_stor_dbg(us, "Option MS: %s\n", "option_ms_init called");
142 142
143 /* Additional test for vendor information via INQUIRY, 143 /* Additional test for vendor information via INQUIRY,
144 * because some vendor/product IDs are ambiguous 144 * because some vendor/product IDs are ambiguous
145 */ 145 */
146 result = option_inquiry(us); 146 result = option_inquiry(us);
147 if (result != 0) { 147 if (result != 0) {
148 US_DEBUGP("Option MS: vendor is not Option or not determinable," 148 usb_stor_dbg(us, "Option MS: %s\n",
149 " no action taken\n"); 149 "vendor is not Option or not determinable, no action taken");
150 return 0; 150 return 0;
151 } else 151 } else
152 US_DEBUGP("Option MS: this is a genuine Option device," 152 usb_stor_dbg(us, "Option MS: %s\n",
153 " proceeding\n"); 153 "this is a genuine Option device, proceeding");
154 154
155 /* Force Modem mode */ 155 /* Force Modem mode */
156 if (option_zero_cd == ZCD_FORCE_MODEM) { 156 if (option_zero_cd == ZCD_FORCE_MODEM) {
157 US_DEBUGP("Option MS: %s", "Forcing Modem Mode\n"); 157 usb_stor_dbg(us, "Option MS: %s\n", "Forcing Modem Mode");
158 result = option_rezero(us); 158 result = option_rezero(us);
159 if (result != USB_STOR_XFER_GOOD) 159 if (result != USB_STOR_XFER_GOOD)
160 US_DEBUGP("Option MS: Failed to switch to modem mode.\n"); 160 usb_stor_dbg(us, "Option MS: %s\n",
161 "Failed to switch to modem mode");
161 return -EIO; 162 return -EIO;
162 } else if (option_zero_cd == ZCD_ALLOW_MS) { 163 } else if (option_zero_cd == ZCD_ALLOW_MS) {
163 /* Allow Mass Storage mode (keep CD-Rom) */ 164 /* Allow Mass Storage mode (keep CD-Rom) */
164 US_DEBUGP("Option MS: %s", "Allowing Mass Storage Mode if device" 165 usb_stor_dbg(us, "Option MS: %s\n",
165 " requests it\n"); 166 "Allowing Mass Storage Mode if device requests it");
166 } 167 }
167 168
168 return 0; 169 return 0;
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index 6c3586a4c956..4797228747fb 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -254,8 +254,8 @@ static int rts51x_bulk_transport(struct us_data *us, u8 lun,
254 254
255 /* check bulk status */ 255 /* check bulk status */
256 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) { 256 if (bcs->Signature != cpu_to_le32(US_BULK_CS_SIGN)) {
257 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n", 257 usb_stor_dbg(us, "Signature mismatch: got %08X, expecting %08X\n",
258 le32_to_cpu(bcs->Signature), US_BULK_CS_SIGN); 258 le32_to_cpu(bcs->Signature), US_BULK_CS_SIGN);
259 return USB_STOR_TRANSPORT_ERROR; 259 return USB_STOR_TRANSPORT_ERROR;
260 } 260 }
261 261
@@ -351,8 +351,8 @@ static int rts51x_get_max_lun(struct us_data *us)
351 USB_RECIP_INTERFACE, 351 USB_RECIP_INTERFACE,
352 0, us->ifnum, us->iobuf, 1, 10 * HZ); 352 0, us->ifnum, us->iobuf, 1, 10 * HZ);
353 353
354 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", 354 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
355 result, us->iobuf[0]); 355 result, us->iobuf[0]);
356 356
357 /* if we have a successful request, return the result */ 357 /* if we have a successful request, return the result */
358 if (result > 0) 358 if (result > 0)
@@ -371,7 +371,7 @@ static int rts51x_read_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
371 if (buf == NULL) 371 if (buf == NULL)
372 return USB_STOR_TRANSPORT_ERROR; 372 return USB_STOR_TRANSPORT_ERROR;
373 373
374 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 374 usb_stor_dbg(us, "addr = 0x%x, len = %d\n", addr, len);
375 375
376 cmnd[0] = 0xF0; 376 cmnd[0] = 0xF0;
377 cmnd[1] = 0x0D; 377 cmnd[1] = 0x0D;
@@ -402,7 +402,7 @@ static int rts51x_write_mem(struct us_data *us, u16 addr, u8 *data, u16 len)
402 if (buf == NULL) 402 if (buf == NULL)
403 return USB_STOR_TRANSPORT_ERROR; 403 return USB_STOR_TRANSPORT_ERROR;
404 404
405 US_DEBUGP("%s, addr = 0x%x, len = %d\n", __func__, addr, len); 405 usb_stor_dbg(us, "addr = 0x%x, len = %d\n", addr, len);
406 406
407 cmnd[0] = 0xF0; 407 cmnd[0] = 0xF0;
408 cmnd[1] = 0x0E; 408 cmnd[1] = 0x0E;
@@ -431,7 +431,7 @@ static int rts51x_read_status(struct us_data *us,
431 if (buf == NULL) 431 if (buf == NULL)
432 return USB_STOR_TRANSPORT_ERROR; 432 return USB_STOR_TRANSPORT_ERROR;
433 433
434 US_DEBUGP("%s, lun = %d\n", __func__, lun); 434 usb_stor_dbg(us, "lun = %d\n", lun);
435 435
436 cmnd[0] = 0xF0; 436 cmnd[0] = 0xF0;
437 cmnd[1] = 0x09; 437 cmnd[1] = 0x09;
@@ -458,7 +458,7 @@ static int rts51x_check_status(struct us_data *us, u8 lun)
458 if (retval != STATUS_SUCCESS) 458 if (retval != STATUS_SUCCESS)
459 return -EIO; 459 return -EIO;
460 460
461 US_DEBUGP("chip->status_len = %d\n", chip->status_len); 461 usb_stor_dbg(us, "chip->status_len = %d\n", chip->status_len);
462 462
463 chip->status[lun].vid = ((u16) buf[0] << 8) | buf[1]; 463 chip->status[lun].vid = ((u16) buf[0] << 8) | buf[1];
464 chip->status[lun].pid = ((u16) buf[2] << 8) | buf[3]; 464 chip->status[lun].pid = ((u16) buf[2] << 8) | buf[3];
@@ -509,7 +509,7 @@ static int __do_config_autodelink(struct us_data *us, u8 *data, u16 len)
509 u8 cmnd[12] = {0}; 509 u8 cmnd[12] = {0};
510 u8 *buf; 510 u8 *buf;
511 511
512 US_DEBUGP("%s, addr = 0xfe47, len = %d\n", __FUNCTION__, len); 512 usb_stor_dbg(us, "addr = 0xfe47, len = %d\n", len);
513 513
514 buf = kmemdup(data, len, GFP_NOIO); 514 buf = kmemdup(data, len, GFP_NOIO);
515 if (!buf) 515 if (!buf)
@@ -549,7 +549,7 @@ static int do_config_autodelink(struct us_data *us, int enable, int force)
549 value &= ~0x03; 549 value &= ~0x03;
550 } 550 }
551 551
552 US_DEBUGP("In %s,set 0xfe47 to 0x%x\n", __func__, value); 552 usb_stor_dbg(us, "set 0xfe47 to 0x%x\n", value);
553 553
554 /* retval = rts51x_write_mem(us, 0xFE47, &value, 1); */ 554 /* retval = rts51x_write_mem(us, 0xFE47, &value, 1); */
555 retval = __do_config_autodelink(us, &value, 1); 555 retval = __do_config_autodelink(us, &value, 1);
@@ -565,8 +565,6 @@ static int config_autodelink_after_power_on(struct us_data *us)
565 int retval; 565 int retval;
566 u8 value; 566 u8 value;
567 567
568 US_DEBUGP("%s: <---\n", __func__);
569
570 if (!CHK_AUTO_DELINK(chip)) 568 if (!CHK_AUTO_DELINK(chip))
571 return 0; 569 return 0;
572 570
@@ -624,8 +622,6 @@ static int config_autodelink_after_power_on(struct us_data *us)
624 } 622 }
625 } 623 }
626 624
627 US_DEBUGP("%s: --->\n", __func__);
628
629 return 0; 625 return 0;
630} 626}
631 627
@@ -635,8 +631,6 @@ static int config_autodelink_before_power_down(struct us_data *us)
635 int retval; 631 int retval;
636 u8 value; 632 u8 value;
637 633
638 US_DEBUGP("%s: <---\n", __func__);
639
640 if (!CHK_AUTO_DELINK(chip)) 634 if (!CHK_AUTO_DELINK(chip))
641 return 0; 635 return 0;
642 636
@@ -698,8 +692,6 @@ static int config_autodelink_before_power_down(struct us_data *us)
698 } 692 }
699 } 693 }
700 694
701 US_DEBUGP("%s: --->\n", __func__);
702
703 return 0; 695 return 0;
704} 696}
705 697
@@ -709,23 +701,19 @@ static void fw5895_init(struct us_data *us)
709 int retval; 701 int retval;
710 u8 val; 702 u8 val;
711 703
712 US_DEBUGP("%s: <---\n", __func__);
713
714 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) { 704 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) {
715 US_DEBUGP("Not the specified device, return immediately!\n"); 705 usb_stor_dbg(us, "Not the specified device, return immediately!\n");
716 } else { 706 } else {
717 retval = rts51x_read_mem(us, 0xFD6F, &val, 1); 707 retval = rts51x_read_mem(us, 0xFD6F, &val, 1);
718 if (retval == STATUS_SUCCESS && (val & 0x1F) == 0) { 708 if (retval == STATUS_SUCCESS && (val & 0x1F) == 0) {
719 val = 0x1F; 709 val = 0x1F;
720 retval = rts51x_write_mem(us, 0xFD70, &val, 1); 710 retval = rts51x_write_mem(us, 0xFD70, &val, 1);
721 if (retval != STATUS_SUCCESS) 711 if (retval != STATUS_SUCCESS)
722 US_DEBUGP("Write memory fail\n"); 712 usb_stor_dbg(us, "Write memory fail\n");
723 } else { 713 } else {
724 US_DEBUGP("Read memory fail, OR (val & 0x1F) != 0\n"); 714 usb_stor_dbg(us, "Read memory fail, OR (val & 0x1F) != 0\n");
725 } 715 }
726 } 716 }
727
728 US_DEBUGP("%s: --->\n", __func__);
729} 717}
730 718
731#ifdef CONFIG_REALTEK_AUTOPM 719#ifdef CONFIG_REALTEK_AUTOPM
@@ -735,10 +723,8 @@ static void fw5895_set_mmc_wp(struct us_data *us)
735 int retval; 723 int retval;
736 u8 buf[13]; 724 u8 buf[13];
737 725
738 US_DEBUGP("%s: <---\n", __func__);
739
740 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) { 726 if ((PRODUCT_ID(chip) != 0x0158) || (FW_VERSION(chip) != 0x5895)) {
741 US_DEBUGP("Not the specified device, return immediately!\n"); 727 usb_stor_dbg(us, "Not the specified device, return immediately!\n");
742 } else { 728 } else {
743 retval = rts51x_read_mem(us, 0xFD6F, buf, 1); 729 retval = rts51x_read_mem(us, 0xFD6F, buf, 1);
744 if (retval == STATUS_SUCCESS && (buf[0] & 0x24) == 0x24) { 730 if (retval == STATUS_SUCCESS && (buf[0] & 0x24) == 0x24) {
@@ -748,26 +734,24 @@ static void fw5895_set_mmc_wp(struct us_data *us)
748 buf[0] |= 0x04; 734 buf[0] |= 0x04;
749 retval = rts51x_write_mem(us, 0xFD70, buf, 1); 735 retval = rts51x_write_mem(us, 0xFD70, buf, 1);
750 if (retval != STATUS_SUCCESS) 736 if (retval != STATUS_SUCCESS)
751 US_DEBUGP("Write memory fail\n"); 737 usb_stor_dbg(us, "Write memory fail\n");
752 } else { 738 } else {
753 US_DEBUGP("Read memory fail\n"); 739 usb_stor_dbg(us, "Read memory fail\n");
754 } 740 }
755 } else { 741 } else {
756 US_DEBUGP("Read memory fail, OR (buf[0]&0x24)!=0x24\n"); 742 usb_stor_dbg(us, "Read memory fail, OR (buf[0]&0x24)!=0x24\n");
757 } 743 }
758 } 744 }
759
760 US_DEBUGP("%s: --->\n", __func__);
761} 745}
762 746
763static void rts51x_modi_suspend_timer(struct rts51x_chip *chip) 747static void rts51x_modi_suspend_timer(struct rts51x_chip *chip)
764{ 748{
765 US_DEBUGP("%s: <---, state:%d\n", __func__, rts51x_get_stat(chip)); 749 struct us_data *us = chip->us;
750
751 usb_stor_dbg(us, "state:%d\n", rts51x_get_stat(chip));
766 752
767 chip->timer_expires = jiffies + msecs_to_jiffies(1000*ss_delay); 753 chip->timer_expires = jiffies + msecs_to_jiffies(1000*ss_delay);
768 mod_timer(&chip->rts51x_suspend_timer, chip->timer_expires); 754 mod_timer(&chip->rts51x_suspend_timer, chip->timer_expires);
769
770 US_DEBUGP("%s: --->\n", __func__);
771} 755}
772 756
773static void rts51x_suspend_timer_fn(unsigned long data) 757static void rts51x_suspend_timer_fn(unsigned long data)
@@ -775,8 +759,6 @@ static void rts51x_suspend_timer_fn(unsigned long data)
775 struct rts51x_chip *chip = (struct rts51x_chip *)data; 759 struct rts51x_chip *chip = (struct rts51x_chip *)data;
776 struct us_data *us = chip->us; 760 struct us_data *us = chip->us;
777 761
778 US_DEBUGP("%s: <---\n", __func__);
779
780 switch (rts51x_get_stat(chip)) { 762 switch (rts51x_get_stat(chip)) {
781 case RTS51X_STAT_INIT: 763 case RTS51X_STAT_INIT:
782 case RTS51X_STAT_RUN: 764 case RTS51X_STAT_RUN:
@@ -784,32 +766,25 @@ static void rts51x_suspend_timer_fn(unsigned long data)
784 break; 766 break;
785 case RTS51X_STAT_IDLE: 767 case RTS51X_STAT_IDLE:
786 case RTS51X_STAT_SS: 768 case RTS51X_STAT_SS:
787 US_DEBUGP("%s: RTS51X_STAT_SS, intf->pm_usage_cnt:%d," 769 usb_stor_dbg(us, "RTS51X_STAT_SS, intf->pm_usage_cnt:%d, power.usage:%d\n",
788 "power.usage:%d\n", __func__, 770 atomic_read(&us->pusb_intf->pm_usage_cnt),
789 atomic_read(&us->pusb_intf->pm_usage_cnt), 771 atomic_read(&us->pusb_intf->dev.power.usage_count));
790 atomic_read(&us->pusb_intf->dev.power.usage_count));
791 772
792 if (atomic_read(&us->pusb_intf->pm_usage_cnt) > 0) { 773 if (atomic_read(&us->pusb_intf->pm_usage_cnt) > 0) {
793 US_DEBUGP("%s: Ready to enter SS state.\n", 774 usb_stor_dbg(us, "Ready to enter SS state\n");
794 __func__);
795 rts51x_set_stat(chip, RTS51X_STAT_SS); 775 rts51x_set_stat(chip, RTS51X_STAT_SS);
796 /* ignore mass storage interface's children */ 776 /* ignore mass storage interface's children */
797 pm_suspend_ignore_children(&us->pusb_intf->dev, true); 777 pm_suspend_ignore_children(&us->pusb_intf->dev, true);
798 usb_autopm_put_interface_async(us->pusb_intf); 778 usb_autopm_put_interface_async(us->pusb_intf);
799 US_DEBUGP("%s: RTS51X_STAT_SS 01," 779 usb_stor_dbg(us, "RTS51X_STAT_SS 01, intf->pm_usage_cnt:%d, power.usage:%d\n",
800 "intf->pm_usage_cnt:%d, power.usage:%d\n", 780 atomic_read(&us->pusb_intf->pm_usage_cnt),
801 __func__, 781 atomic_read(&us->pusb_intf->dev.power.usage_count));
802 atomic_read(&us->pusb_intf->pm_usage_cnt),
803 atomic_read(
804 &us->pusb_intf->dev.power.usage_count));
805 } 782 }
806 break; 783 break;
807 default: 784 default:
808 US_DEBUGP("%s: Unknonwn state !!!\n", __func__); 785 usb_stor_dbg(us, "Unknown state !!!\n");
809 break; 786 break;
810 } 787 }
811
812 US_DEBUGP("%s: --->\n", __func__);
813} 788}
814 789
815static inline int working_scsi(struct scsi_cmnd *srb) 790static inline int working_scsi(struct scsi_cmnd *srb)
@@ -834,24 +809,21 @@ static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
834 }; 809 };
835 int ret; 810 int ret;
836 811
837 US_DEBUGP("%s: <---\n", __func__);
838
839 if (working_scsi(srb)) { 812 if (working_scsi(srb)) {
840 US_DEBUGP("%s: working scsi, intf->pm_usage_cnt:%d," 813 usb_stor_dbg(us, "working scsi, intf->pm_usage_cnt:%d, power.usage:%d\n",
841 "power.usage:%d\n", __func__, 814 atomic_read(&us->pusb_intf->pm_usage_cnt),
842 atomic_read(&us->pusb_intf->pm_usage_cnt), 815 atomic_read(&us->pusb_intf->dev.power.usage_count));
843 atomic_read(&us->pusb_intf->dev.power.usage_count));
844 816
845 if (atomic_read(&us->pusb_intf->pm_usage_cnt) <= 0) { 817 if (atomic_read(&us->pusb_intf->pm_usage_cnt) <= 0) {
846 ret = usb_autopm_get_interface(us->pusb_intf); 818 ret = usb_autopm_get_interface(us->pusb_intf);
847 US_DEBUGP("%s: working scsi, ret=%d\n", __func__, ret); 819 usb_stor_dbg(us, "working scsi, ret=%d\n", ret);
848 } 820 }
849 if (rts51x_get_stat(chip) != RTS51X_STAT_RUN) 821 if (rts51x_get_stat(chip) != RTS51X_STAT_RUN)
850 rts51x_set_stat(chip, RTS51X_STAT_RUN); 822 rts51x_set_stat(chip, RTS51X_STAT_RUN);
851 chip->proto_handler_backup(srb, us); 823 chip->proto_handler_backup(srb, us);
852 } else { 824 } else {
853 if (rts51x_get_stat(chip) == RTS51X_STAT_SS) { 825 if (rts51x_get_stat(chip) == RTS51X_STAT_SS) {
854 US_DEBUGP("%s: NOT working scsi\n", __func__); 826 usb_stor_dbg(us, "NOT working scsi\n");
855 if ((srb->cmnd[0] == TEST_UNIT_READY) && 827 if ((srb->cmnd[0] == TEST_UNIT_READY) &&
856 (chip->pwr_state == US_SUSPEND)) { 828 (chip->pwr_state == US_SUSPEND)) {
857 if (TST_LUN_READY(chip, srb->device->lun)) { 829 if (TST_LUN_READY(chip, srb->device->lun)) {
@@ -862,8 +834,7 @@ static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
862 media_not_present, 834 media_not_present,
863 US_SENSE_SIZE); 835 US_SENSE_SIZE);
864 } 836 }
865 US_DEBUGP("%s: TEST_UNIT_READY--->\n", 837 usb_stor_dbg(us, "TEST_UNIT_READY\n");
866 __func__);
867 goto out; 838 goto out;
868 } 839 }
869 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { 840 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
@@ -876,12 +847,11 @@ static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
876 } else { 847 } else {
877 srb->result = SAM_STAT_GOOD; 848 srb->result = SAM_STAT_GOOD;
878 } 849 }
879 US_DEBUGP("%s: ALLOW_MEDIUM_REMOVAL--->\n", 850 usb_stor_dbg(us, "ALLOW_MEDIUM_REMOVAL\n");
880 __func__);
881 goto out; 851 goto out;
882 } 852 }
883 } else { 853 } else {
884 US_DEBUGP("%s: NOT working scsi, not SS\n", __func__); 854 usb_stor_dbg(us, "NOT working scsi, not SS\n");
885 chip->proto_handler_backup(srb, us); 855 chip->proto_handler_backup(srb, us);
886 /* Check whether card is plugged in */ 856 /* Check whether card is plugged in */
887 if (srb->cmnd[0] == TEST_UNIT_READY) { 857 if (srb->cmnd[0] == TEST_UNIT_READY) {
@@ -901,11 +871,9 @@ static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
901 } 871 }
902 } 872 }
903out: 873out:
904 US_DEBUGP("%s: state:%d\n", __func__, rts51x_get_stat(chip)); 874 usb_stor_dbg(us, "state:%d\n", rts51x_get_stat(chip));
905 if (rts51x_get_stat(chip) == RTS51X_STAT_RUN) 875 if (rts51x_get_stat(chip) == RTS51X_STAT_RUN)
906 rts51x_modi_suspend_timer(chip); 876 rts51x_modi_suspend_timer(chip);
907
908 US_DEBUGP("%s: --->\n", __func__);
909} 877}
910 878
911static int realtek_cr_autosuspend_setup(struct us_data *us) 879static int realtek_cr_autosuspend_setup(struct us_data *us)
@@ -923,7 +891,7 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
923 891
924 retval = rts51x_read_status(us, 0, buf, 16, &(chip->status_len)); 892 retval = rts51x_read_status(us, 0, buf, 16, &(chip->status_len));
925 if (retval != STATUS_SUCCESS) { 893 if (retval != STATUS_SUCCESS) {
926 US_DEBUGP("Read status fail\n"); 894 usb_stor_dbg(us, "Read status fail\n");
927 return -EIO; 895 return -EIO;
928 } 896 }
929 status = chip->status; 897 status = chip->status;
@@ -966,11 +934,13 @@ static int realtek_cr_autosuspend_setup(struct us_data *us)
966static void realtek_cr_destructor(void *extra) 934static void realtek_cr_destructor(void *extra)
967{ 935{
968 struct rts51x_chip *chip = (struct rts51x_chip *)extra; 936 struct rts51x_chip *chip = (struct rts51x_chip *)extra;
969 937 struct us_data *us;
970 US_DEBUGP("%s: <---\n", __func__);
971 938
972 if (!chip) 939 if (!chip)
973 return; 940 return;
941
942 us = chip->us;
943
974#ifdef CONFIG_REALTEK_AUTOPM 944#ifdef CONFIG_REALTEK_AUTOPM
975 if (ss_en) { 945 if (ss_en) {
976 del_timer(&chip->rts51x_suspend_timer); 946 del_timer(&chip->rts51x_suspend_timer);
@@ -985,8 +955,6 @@ static int realtek_cr_suspend(struct usb_interface *iface, pm_message_t message)
985{ 955{
986 struct us_data *us = usb_get_intfdata(iface); 956 struct us_data *us = usb_get_intfdata(iface);
987 957
988 US_DEBUGP("%s: <---\n", __func__);
989
990 /* wait until no command is running */ 958 /* wait until no command is running */
991 mutex_lock(&us->dev_mutex); 959 mutex_lock(&us->dev_mutex);
992 960
@@ -994,8 +962,6 @@ static int realtek_cr_suspend(struct usb_interface *iface, pm_message_t message)
994 962
995 mutex_unlock(&us->dev_mutex); 963 mutex_unlock(&us->dev_mutex);
996 964
997 US_DEBUGP("%s: --->\n", __func__);
998
999 return 0; 965 return 0;
1000} 966}
1001 967
@@ -1003,13 +969,9 @@ static int realtek_cr_resume(struct usb_interface *iface)
1003{ 969{
1004 struct us_data *us = usb_get_intfdata(iface); 970 struct us_data *us = usb_get_intfdata(iface);
1005 971
1006 US_DEBUGP("%s: <---\n", __func__);
1007
1008 fw5895_init(us); 972 fw5895_init(us);
1009 config_autodelink_after_power_on(us); 973 config_autodelink_after_power_on(us);
1010 974
1011 US_DEBUGP("%s: --->\n", __func__);
1012
1013 return 0; 975 return 0;
1014} 976}
1015#else 977#else
@@ -1030,7 +992,7 @@ static int init_realtek_cr(struct us_data *us)
1030 us->extra_destructor = realtek_cr_destructor; 992 us->extra_destructor = realtek_cr_destructor;
1031 us->max_lun = chip->max_lun = rts51x_get_max_lun(us); 993 us->max_lun = chip->max_lun = rts51x_get_max_lun(us);
1032 994
1033 US_DEBUGP("chip->max_lun = %d\n", chip->max_lun); 995 usb_stor_dbg(us, "chip->max_lun = %d\n", chip->max_lun);
1034 996
1035 size = (chip->max_lun + 1) * sizeof(struct rts51x_status); 997 size = (chip->max_lun + 1) * sizeof(struct rts51x_status);
1036 chip->status = kzalloc(size, GFP_KERNEL); 998 chip->status = kzalloc(size, GFP_KERNEL);
@@ -1057,7 +1019,7 @@ static int init_realtek_cr(struct us_data *us)
1057 } 1019 }
1058#endif 1020#endif
1059 1021
1060 US_DEBUGP("chip->flag = 0x%x\n", chip->flag); 1022 usb_stor_dbg(us, "chip->flag = 0x%x\n", chip->flag);
1061 1023
1062 (void)config_autodelink_after_power_on(us); 1024 (void)config_autodelink_after_power_on(us);
1063 1025
@@ -1079,7 +1041,7 @@ static int realtek_cr_probe(struct usb_interface *intf,
1079 struct us_data *us; 1041 struct us_data *us;
1080 int result; 1042 int result;
1081 1043
1082 US_DEBUGP("Probe Realtek Card Reader!\n"); 1044 dev_dbg(&intf->dev, "Probe Realtek Card Reader!\n");
1083 1045
1084 result = usb_stor_probe1(&us, intf, id, 1046 result = usb_stor_probe1(&us, intf, id,
1085 (id - realtek_cr_ids) + 1047 (id - realtek_cr_ids) +
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 92f35abee92d..4faa982807f2 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -313,8 +313,6 @@ static int queuecommand_lck(struct scsi_cmnd *srb,
313{ 313{
314 struct us_data *us = host_to_us(srb->device->host); 314 struct us_data *us = host_to_us(srb->device->host);
315 315
316 US_DEBUGP("%s called\n", __func__);
317
318 /* check for state-transition errors */ 316 /* check for state-transition errors */
319 if (us->srb != NULL) { 317 if (us->srb != NULL) {
320 printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n", 318 printk(KERN_ERR USB_STORAGE "Error in %s: us->srb = %p\n",
@@ -324,7 +322,7 @@ static int queuecommand_lck(struct scsi_cmnd *srb,
324 322
325 /* fail the command if we are disconnecting */ 323 /* fail the command if we are disconnecting */
326 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { 324 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
327 US_DEBUGP("Fail command during disconnect\n"); 325 usb_stor_dbg(us, "Fail command during disconnect\n");
328 srb->result = DID_NO_CONNECT << 16; 326 srb->result = DID_NO_CONNECT << 16;
329 done(srb); 327 done(srb);
330 return 0; 328 return 0;
@@ -349,7 +347,7 @@ static int command_abort(struct scsi_cmnd *srb)
349{ 347{
350 struct us_data *us = host_to_us(srb->device->host); 348 struct us_data *us = host_to_us(srb->device->host);
351 349
352 US_DEBUGP("%s called\n", __func__); 350 usb_stor_dbg(us, "%s called\n", __func__);
353 351
354 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING 352 /* us->srb together with the TIMED_OUT, RESETTING, and ABORTING
355 * bits are protected by the host lock. */ 353 * bits are protected by the host lock. */
@@ -358,7 +356,7 @@ static int command_abort(struct scsi_cmnd *srb)
358 /* Is this command still active? */ 356 /* Is this command still active? */
359 if (us->srb != srb) { 357 if (us->srb != srb) {
360 scsi_unlock(us_to_host(us)); 358 scsi_unlock(us_to_host(us));
361 US_DEBUGP ("-- nothing to abort\n"); 359 usb_stor_dbg(us, "-- nothing to abort\n");
362 return FAILED; 360 return FAILED;
363 } 361 }
364 362
@@ -386,7 +384,7 @@ static int device_reset(struct scsi_cmnd *srb)
386 struct us_data *us = host_to_us(srb->device->host); 384 struct us_data *us = host_to_us(srb->device->host);
387 int result; 385 int result;
388 386
389 US_DEBUGP("%s called\n", __func__); 387 usb_stor_dbg(us, "%s called\n", __func__);
390 388
391 /* lock the device pointers and do the reset */ 389 /* lock the device pointers and do the reset */
392 mutex_lock(&(us->dev_mutex)); 390 mutex_lock(&(us->dev_mutex));
@@ -402,7 +400,8 @@ static int bus_reset(struct scsi_cmnd *srb)
402 struct us_data *us = host_to_us(srb->device->host); 400 struct us_data *us = host_to_us(srb->device->host);
403 int result; 401 int result;
404 402
405 US_DEBUGP("%s called\n", __func__); 403 usb_stor_dbg(us, "%s called\n", __func__);
404
406 result = usb_stor_port_reset(us); 405 result = usb_stor_port_reset(us);
407 return result < 0 ? FAILED : SUCCESS; 406 return result < 0 ? FAILED : SUCCESS;
408} 407}
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 7bd54e0d5120..732027f33200 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -105,8 +105,6 @@ static struct us_unusual_dev sddr09_unusual_dev_list[] = {
105#define LSB_of(s) ((s)&0xFF) 105#define LSB_of(s) ((s)&0xFF)
106#define MSB_of(s) ((s)>>8) 106#define MSB_of(s) ((s)>>8)
107 107
108/* #define US_DEBUGP printk */
109
110/* 108/*
111 * First some stuff that does not belong here: 109 * First some stuff that does not belong here:
112 * data on SmartMedia and other cards, completely 110 * data on SmartMedia and other cards, completely
@@ -347,7 +345,7 @@ sddr09_test_unit_ready(struct us_data *us) {
347 345
348 result = sddr09_send_scsi_command(us, command, 6); 346 result = sddr09_send_scsi_command(us, command, 6);
349 347
350 US_DEBUGP("sddr09_test_unit_ready returns %d\n", result); 348 usb_stor_dbg(us, "sddr09_test_unit_ready returns %d\n", result);
351 349
352 return result; 350 return result;
353} 351}
@@ -423,8 +421,8 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
423 result = sddr09_send_scsi_command(us, command, 12); 421 result = sddr09_send_scsi_command(us, command, 12);
424 422
425 if (result) { 423 if (result) {
426 US_DEBUGP("Result for send_control in sddr09_read2%d %d\n", 424 usb_stor_dbg(us, "Result for send_control in sddr09_read2%d %d\n",
427 x, result); 425 x, result);
428 return result; 426 return result;
429 } 427 }
430 428
@@ -432,8 +430,8 @@ sddr09_readX(struct us_data *us, int x, unsigned long fromaddress,
432 buf, bulklen, use_sg, NULL); 430 buf, bulklen, use_sg, NULL);
433 431
434 if (result != USB_STOR_XFER_GOOD) { 432 if (result != USB_STOR_XFER_GOOD) {
435 US_DEBUGP("Result for bulk_transfer in sddr09_read2%d %d\n", 433 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read2%d %d\n",
436 x, result); 434 x, result);
437 return -EIO; 435 return -EIO;
438 } 436 }
439 return 0; 437 return 0;
@@ -494,8 +492,7 @@ sddr09_read22(struct us_data *us, unsigned long fromaddress,
494 int nr_of_pages, int pageshift, unsigned char *buf, int use_sg) { 492 int nr_of_pages, int pageshift, unsigned char *buf, int use_sg) {
495 493
496 int bulklen = (nr_of_pages << pageshift) + (nr_of_pages << CONTROL_SHIFT); 494 int bulklen = (nr_of_pages << pageshift) + (nr_of_pages << CONTROL_SHIFT);
497 US_DEBUGP("sddr09_read22: reading %d pages, %d bytes\n", 495 usb_stor_dbg(us, "reading %d pages, %d bytes\n", nr_of_pages, bulklen);
498 nr_of_pages, bulklen);
499 return sddr09_readX(us, 2, fromaddress, nr_of_pages, bulklen, 496 return sddr09_readX(us, 2, fromaddress, nr_of_pages, bulklen,
500 buf, use_sg); 497 buf, use_sg);
501} 498}
@@ -538,7 +535,7 @@ sddr09_erase(struct us_data *us, unsigned long Eaddress) {
538 unsigned char *command = us->iobuf; 535 unsigned char *command = us->iobuf;
539 int result; 536 int result;
540 537
541 US_DEBUGP("sddr09_erase: erase address %lu\n", Eaddress); 538 usb_stor_dbg(us, "erase address %lu\n", Eaddress);
542 539
543 memset(command, 0, 12); 540 memset(command, 0, 12);
544 command[0] = 0xEA; 541 command[0] = 0xEA;
@@ -551,8 +548,8 @@ sddr09_erase(struct us_data *us, unsigned long Eaddress) {
551 result = sddr09_send_scsi_command(us, command, 12); 548 result = sddr09_send_scsi_command(us, command, 12);
552 549
553 if (result) 550 if (result)
554 US_DEBUGP("Result for send_control in sddr09_erase %d\n", 551 usb_stor_dbg(us, "Result for send_control in sddr09_erase %d\n",
555 result); 552 result);
556 553
557 return result; 554 return result;
558} 555}
@@ -609,8 +606,8 @@ sddr09_writeX(struct us_data *us,
609 result = sddr09_send_scsi_command(us, command, 12); 606 result = sddr09_send_scsi_command(us, command, 12);
610 607
611 if (result) { 608 if (result) {
612 US_DEBUGP("Result for send_control in sddr09_writeX %d\n", 609 usb_stor_dbg(us, "Result for send_control in sddr09_writeX %d\n",
613 result); 610 result);
614 return result; 611 return result;
615 } 612 }
616 613
@@ -618,8 +615,8 @@ sddr09_writeX(struct us_data *us,
618 buf, bulklen, use_sg, NULL); 615 buf, bulklen, use_sg, NULL);
619 616
620 if (result != USB_STOR_XFER_GOOD) { 617 if (result != USB_STOR_XFER_GOOD) {
621 US_DEBUGP("Result for bulk_transfer in sddr09_writeX %d\n", 618 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_writeX %d\n",
622 result); 619 result);
623 return -EIO; 620 return -EIO;
624 } 621 }
625 return 0; 622 return 0;
@@ -687,8 +684,8 @@ sddr09_read_sg_test_only(struct us_data *us) {
687 result = sddr09_send_scsi_command(us, command, 4*nsg+3); 684 result = sddr09_send_scsi_command(us, command, 4*nsg+3);
688 685
689 if (result) { 686 if (result) {
690 US_DEBUGP("Result for send_control in sddr09_read_sg %d\n", 687 usb_stor_dbg(us, "Result for send_control in sddr09_read_sg %d\n",
691 result); 688 result);
692 return result; 689 return result;
693 } 690 }
694 691
@@ -700,8 +697,8 @@ sddr09_read_sg_test_only(struct us_data *us) {
700 buf, bulklen, NULL); 697 buf, bulklen, NULL);
701 kfree(buf); 698 kfree(buf);
702 if (result != USB_STOR_XFER_GOOD) { 699 if (result != USB_STOR_XFER_GOOD) {
703 US_DEBUGP("Result for bulk_transfer in sddr09_read_sg %d\n", 700 usb_stor_dbg(us, "Result for bulk_transfer in sddr09_read_sg %d\n",
704 result); 701 result);
705 return -EIO; 702 return -EIO;
706 } 703 }
707 704
@@ -727,7 +724,7 @@ sddr09_read_status(struct us_data *us, unsigned char *status) {
727 unsigned char *data = us->iobuf; 724 unsigned char *data = us->iobuf;
728 int result; 725 int result;
729 726
730 US_DEBUGP("Reading status...\n"); 727 usb_stor_dbg(us, "Reading status...\n");
731 728
732 memset(command, 0, 12); 729 memset(command, 0, 12);
733 command[0] = 0xEC; 730 command[0] = 0xEC;
@@ -789,8 +786,8 @@ sddr09_read_data(struct us_data *us,
789 786
790 /* Not overflowing capacity? */ 787 /* Not overflowing capacity? */
791 if (lba >= maxlba) { 788 if (lba >= maxlba) {
792 US_DEBUGP("Error: Requested lba %u exceeds " 789 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
793 "maximum %u\n", lba, maxlba); 790 lba, maxlba);
794 result = -EIO; 791 result = -EIO;
795 break; 792 break;
796 } 793 }
@@ -800,8 +797,8 @@ sddr09_read_data(struct us_data *us,
800 797
801 if (pba == UNDEF) { /* this lba was never written */ 798 if (pba == UNDEF) { /* this lba was never written */
802 799
803 US_DEBUGP("Read %d zero pages (LBA %d) page %d\n", 800 usb_stor_dbg(us, "Read %d zero pages (LBA %d) page %d\n",
804 pages, lba, page); 801 pages, lba, page);
805 802
806 /* This is not really an error. It just means 803 /* This is not really an error. It just means
807 that the block has never been written. 804 that the block has never been written.
@@ -811,9 +808,8 @@ sddr09_read_data(struct us_data *us,
811 memset(buffer, 0, len); 808 memset(buffer, 0, len);
812 809
813 } else { 810 } else {
814 US_DEBUGP("Read %d pages, from PBA %d" 811 usb_stor_dbg(us, "Read %d pages, from PBA %d (LBA %d) page %d\n",
815 " (LBA %d) page %d\n", 812 pages, pba, lba, page);
816 pages, pba, lba, page);
817 813
818 address = ((pba << info->blockshift) + page) << 814 address = ((pba << info->blockshift) + page) <<
819 info->pageshift; 815 info->pageshift;
@@ -916,14 +912,14 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
916 cptr = bptr + info->pagesize; 912 cptr = bptr + info->pagesize;
917 nand_compute_ecc(bptr, ecc); 913 nand_compute_ecc(bptr, ecc);
918 if (!nand_compare_ecc(cptr+13, ecc)) { 914 if (!nand_compare_ecc(cptr+13, ecc)) {
919 US_DEBUGP("Warning: bad ecc in page %d- of pba %d\n", 915 usb_stor_dbg(us, "Warning: bad ecc in page %d- of pba %d\n",
920 i, pba); 916 i, pba);
921 nand_store_ecc(cptr+13, ecc); 917 nand_store_ecc(cptr+13, ecc);
922 } 918 }
923 nand_compute_ecc(bptr+(info->pagesize / 2), ecc); 919 nand_compute_ecc(bptr+(info->pagesize / 2), ecc);
924 if (!nand_compare_ecc(cptr+8, ecc)) { 920 if (!nand_compare_ecc(cptr+8, ecc)) {
925 US_DEBUGP("Warning: bad ecc in page %d+ of pba %d\n", 921 usb_stor_dbg(us, "Warning: bad ecc in page %d+ of pba %d\n",
926 i, pba); 922 i, pba);
927 nand_store_ecc(cptr+8, ecc); 923 nand_store_ecc(cptr+8, ecc);
928 } 924 }
929 cptr[6] = cptr[11] = MSB_of(lbap); 925 cptr[6] = cptr[11] = MSB_of(lbap);
@@ -943,22 +939,21 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
943 nand_store_ecc(cptr+8, ecc); 939 nand_store_ecc(cptr+8, ecc);
944 } 940 }
945 941
946 US_DEBUGP("Rewrite PBA %d (LBA %d)\n", pba, lba); 942 usb_stor_dbg(us, "Rewrite PBA %d (LBA %d)\n", pba, lba);
947 943
948 result = sddr09_write_inplace(us, address>>1, info->blocksize, 944 result = sddr09_write_inplace(us, address>>1, info->blocksize,
949 info->pageshift, blockbuffer, 0); 945 info->pageshift, blockbuffer, 0);
950 946
951 US_DEBUGP("sddr09_write_inplace returns %d\n", result); 947 usb_stor_dbg(us, "sddr09_write_inplace returns %d\n", result);
952 948
953#if 0 949#if 0
954 { 950 {
955 unsigned char status = 0; 951 unsigned char status = 0;
956 int result2 = sddr09_read_status(us, &status); 952 int result2 = sddr09_read_status(us, &status);
957 if (result2) 953 if (result2)
958 US_DEBUGP("sddr09_write_inplace: cannot read status\n"); 954 usb_stor_dbg(us, "cannot read status\n");
959 else if (status != 0xc0) 955 else if (status != 0xc0)
960 US_DEBUGP("sddr09_write_inplace: status after write: 0x%x\n", 956 usb_stor_dbg(us, "status after write: 0x%x\n", status);
961 status);
962 } 957 }
963#endif 958#endif
964 959
@@ -1031,8 +1026,8 @@ sddr09_write_data(struct us_data *us,
1031 1026
1032 /* Not overflowing capacity? */ 1027 /* Not overflowing capacity? */
1033 if (lba >= maxlba) { 1028 if (lba >= maxlba) {
1034 US_DEBUGP("Error: Requested lba %u exceeds " 1029 usb_stor_dbg(us, "Error: Requested lba %u exceeds maximum %u\n",
1035 "maximum %u\n", lba, maxlba); 1030 lba, maxlba);
1036 result = -EIO; 1031 result = -EIO;
1037 break; 1032 break;
1038 } 1033 }
@@ -1064,8 +1059,8 @@ sddr09_read_control(struct us_data *us,
1064 unsigned char *content, 1059 unsigned char *content,
1065 int use_sg) { 1060 int use_sg) {
1066 1061
1067 US_DEBUGP("Read control address %lu, blocks %d\n", 1062 usb_stor_dbg(us, "Read control address %lu, blocks %d\n",
1068 address, blocks); 1063 address, blocks);
1069 1064
1070 return sddr09_read21(us, address, blocks, 1065 return sddr09_read21(us, address, blocks,
1071 CONTROL_SHIFT, content, use_sg); 1066 CONTROL_SHIFT, content, use_sg);
@@ -1111,21 +1106,21 @@ sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
1111 1106
1112 result = sddr09_read_status(us, &status); 1107 result = sddr09_read_status(us, &status);
1113 if (result) { 1108 if (result) {
1114 US_DEBUGP("sddr09_get_wp: read_status fails\n"); 1109 usb_stor_dbg(us, "read_status fails\n");
1115 return result; 1110 return result;
1116 } 1111 }
1117 US_DEBUGP("sddr09_get_wp: status 0x%02X", status); 1112 usb_stor_dbg(us, "status 0x%02X", status);
1118 if ((status & 0x80) == 0) { 1113 if ((status & 0x80) == 0) {
1119 info->flags |= SDDR09_WP; /* write protected */ 1114 info->flags |= SDDR09_WP; /* write protected */
1120 US_DEBUGP(" WP"); 1115 US_DEBUGPX(" WP");
1121 } 1116 }
1122 if (status & 0x40) 1117 if (status & 0x40)
1123 US_DEBUGP(" Ready"); 1118 US_DEBUGPX(" Ready");
1124 if (status & LUNBITS) 1119 if (status & LUNBITS)
1125 US_DEBUGP(" Suspended"); 1120 US_DEBUGPX(" Suspended");
1126 if (status & 0x1) 1121 if (status & 0x1)
1127 US_DEBUGP(" Error"); 1122 US_DEBUGPX(" Error");
1128 US_DEBUGP("\n"); 1123 US_DEBUGPX("\n");
1129 return 0; 1124 return 0;
1130} 1125}
1131 1126
@@ -1154,12 +1149,12 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
1154 char blurbtxt[256]; 1149 char blurbtxt[256];
1155 int result; 1150 int result;
1156 1151
1157 US_DEBUGP("Reading capacity...\n"); 1152 usb_stor_dbg(us, "Reading capacity...\n");
1158 1153
1159 result = sddr09_read_deviceID(us, deviceID); 1154 result = sddr09_read_deviceID(us, deviceID);
1160 1155
1161 if (result) { 1156 if (result) {
1162 US_DEBUGP("Result of read_deviceID is %d\n", result); 1157 usb_stor_dbg(us, "Result of read_deviceID is %d\n", result);
1163 printk(KERN_WARNING "sddr09: could not read card info\n"); 1158 printk(KERN_WARNING "sddr09: could not read card info\n");
1164 return NULL; 1159 return NULL;
1165 } 1160 }
@@ -1392,7 +1387,7 @@ sddr09_read_map(struct us_data *us) {
1392 lbact += ct; 1387 lbact += ct;
1393 } 1388 }
1394 info->lbact = lbact; 1389 info->lbact = lbact;
1395 US_DEBUGP("Found %d LBA's\n", lbact); 1390 usb_stor_dbg(us, "Found %d LBA's\n", lbact);
1396 result = 0; 1391 result = 0;
1397 1392
1398 done: 1393 done:
@@ -1423,18 +1418,18 @@ sddr09_common_init(struct us_data *us) {
1423 1418
1424 /* set the configuration -- STALL is an acceptable response here */ 1419 /* set the configuration -- STALL is an acceptable response here */
1425 if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) { 1420 if (us->pusb_dev->actconfig->desc.bConfigurationValue != 1) {
1426 US_DEBUGP("active config #%d != 1 ??\n", us->pusb_dev 1421 usb_stor_dbg(us, "active config #%d != 1 ??\n",
1427 ->actconfig->desc.bConfigurationValue); 1422 us->pusb_dev->actconfig->desc.bConfigurationValue);
1428 return -EINVAL; 1423 return -EINVAL;
1429 } 1424 }
1430 1425
1431 result = usb_reset_configuration(us->pusb_dev); 1426 result = usb_reset_configuration(us->pusb_dev);
1432 US_DEBUGP("Result of usb_reset_configuration is %d\n", result); 1427 usb_stor_dbg(us, "Result of usb_reset_configuration is %d\n", result);
1433 if (result == -EPIPE) { 1428 if (result == -EPIPE) {
1434 US_DEBUGP("-- stall on control interface\n"); 1429 usb_stor_dbg(us, "-- stall on control interface\n");
1435 } else if (result != 0) { 1430 } else if (result != 0) {
1436 /* it's not a stall, but another error -- time to bail */ 1431 /* it's not a stall, but another error -- time to bail */
1437 US_DEBUGP("-- Unknown error. Rejecting device\n"); 1432 usb_stor_dbg(us, "-- Unknown error. Rejecting device\n");
1438 return -EINVAL; 1433 return -EINVAL;
1439 } 1434 }
1440 1435
@@ -1464,20 +1459,20 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
1464 1459
1465 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2); 1460 result = sddr09_send_command(us, 0x01, USB_DIR_IN, data, 2);
1466 if (result) { 1461 if (result) {
1467 US_DEBUGP("sddr09_init: send_command fails\n"); 1462 usb_stor_dbg(us, "send_command fails\n");
1468 return result; 1463 return result;
1469 } 1464 }
1470 1465
1471 US_DEBUGP("SDDR09init: %02X %02X\n", data[0], data[1]); 1466 usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]);
1472 // get 07 02 1467 // get 07 02
1473 1468
1474 result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2); 1469 result = sddr09_send_command(us, 0x08, USB_DIR_IN, data, 2);
1475 if (result) { 1470 if (result) {
1476 US_DEBUGP("sddr09_init: 2nd send_command fails\n"); 1471 usb_stor_dbg(us, "2nd send_command fails\n");
1477 return result; 1472 return result;
1478 } 1473 }
1479 1474
1480 US_DEBUGP("SDDR09init: %02X %02X\n", data[0], data[1]); 1475 usb_stor_dbg(us, "%02X %02X\n", data[0], data[1]);
1481 // get 07 00 1476 // get 07 00
1482 1477
1483 result = sddr09_request_sense(us, data, 18); 1478 result = sddr09_request_sense(us, data, 18);
@@ -1507,7 +1502,7 @@ static int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
1507{ 1502{
1508 int ret; 1503 int ret;
1509 1504
1510 US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); 1505 usb_stor_dbg(us, "LUN=%d\n", srb->device->lun);
1511 1506
1512 switch (srb->device->lun) { 1507 switch (srb->device->lun) {
1513 case 0: 1508 case 0:
@@ -1533,8 +1528,7 @@ static int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
1533 break; 1528 break;
1534 1529
1535 default: 1530 default:
1536 US_DEBUGP("dpcm_transport: Invalid LUN %d\n", 1531 usb_stor_dbg(us, "Invalid LUN %d\n", srb->device->lun);
1537 srb->device->lun);
1538 ret = USB_STOR_TRANSPORT_ERROR; 1532 ret = USB_STOR_TRANSPORT_ERROR;
1539 break; 1533 break;
1540 } 1534 }
@@ -1640,8 +1634,8 @@ static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1640 or for all pages. */ 1634 or for all pages. */
1641 /* %% We should check DBD %% */ 1635 /* %% We should check DBD %% */
1642 if (modepage == 0x01 || modepage == 0x3F) { 1636 if (modepage == 0x01 || modepage == 0x3F) {
1643 US_DEBUGP("SDDR09: Dummy up request for " 1637 usb_stor_dbg(us, "Dummy up request for mode page 0x%x\n",
1644 "mode page 0x%x\n", modepage); 1638 modepage);
1645 1639
1646 memcpy(ptr, mode_page_01, sizeof(mode_page_01)); 1640 memcpy(ptr, mode_page_01, sizeof(mode_page_01));
1647 ((__be16*)ptr)[0] = cpu_to_be16(sizeof(mode_page_01) - 2); 1641 ((__be16*)ptr)[0] = cpu_to_be16(sizeof(mode_page_01) - 2);
@@ -1667,8 +1661,8 @@ static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1667 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); 1661 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1668 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); 1662 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1669 1663
1670 US_DEBUGP("READ_10: read page %d pagect %d\n", 1664 usb_stor_dbg(us, "READ_10: read page %d pagect %d\n",
1671 page, pages); 1665 page, pages);
1672 1666
1673 result = sddr09_read_data(us, page, pages); 1667 result = sddr09_read_data(us, page, pages);
1674 return (result == 0 ? USB_STOR_TRANSPORT_GOOD : 1668 return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
@@ -1682,8 +1676,8 @@ static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1682 page |= short_pack(srb->cmnd[5], srb->cmnd[4]); 1676 page |= short_pack(srb->cmnd[5], srb->cmnd[4]);
1683 pages = short_pack(srb->cmnd[8], srb->cmnd[7]); 1677 pages = short_pack(srb->cmnd[8], srb->cmnd[7]);
1684 1678
1685 US_DEBUGP("WRITE_10: write page %d pagect %d\n", 1679 usb_stor_dbg(us, "WRITE_10: write page %d pagect %d\n",
1686 page, pages); 1680 page, pages);
1687 1681
1688 result = sddr09_write_data(us, page, pages); 1682 result = sddr09_write_data(us, page, pages);
1689 return (result == 0 ? USB_STOR_TRANSPORT_GOOD : 1683 return (result == 0 ? USB_STOR_TRANSPORT_GOOD :
@@ -1710,12 +1704,12 @@ static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1710 for (i=0; i<12; i++) 1704 for (i=0; i<12; i++)
1711 sprintf(ptr+strlen(ptr), "%02X ", srb->cmnd[i]); 1705 sprintf(ptr+strlen(ptr), "%02X ", srb->cmnd[i]);
1712 1706
1713 US_DEBUGP("SDDR09: Send control for command %s\n", ptr); 1707 usb_stor_dbg(us, "Send control for command %s\n", ptr);
1714 1708
1715 result = sddr09_send_scsi_command(us, srb->cmnd, 12); 1709 result = sddr09_send_scsi_command(us, srb->cmnd, 12);
1716 if (result) { 1710 if (result) {
1717 US_DEBUGP("sddr09_transport: sddr09_send_scsi_command " 1711 usb_stor_dbg(us, "sddr09_send_scsi_command returns %d\n",
1718 "returns %d\n", result); 1712 result);
1719 return USB_STOR_TRANSPORT_ERROR; 1713 return USB_STOR_TRANSPORT_ERROR;
1720 } 1714 }
1721 1715
@@ -1727,10 +1721,10 @@ static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1727 unsigned int pipe = (srb->sc_data_direction == DMA_TO_DEVICE) 1721 unsigned int pipe = (srb->sc_data_direction == DMA_TO_DEVICE)
1728 ? us->send_bulk_pipe : us->recv_bulk_pipe; 1722 ? us->send_bulk_pipe : us->recv_bulk_pipe;
1729 1723
1730 US_DEBUGP("SDDR09: %s %d bytes\n", 1724 usb_stor_dbg(us, "%s %d bytes\n",
1731 (srb->sc_data_direction == DMA_TO_DEVICE) ? 1725 (srb->sc_data_direction == DMA_TO_DEVICE) ?
1732 "sending" : "receiving", 1726 "sending" : "receiving",
1733 scsi_bufflen(srb)); 1727 scsi_bufflen(srb));
1734 1728
1735 result = usb_stor_bulk_srb(us, pipe, srb); 1729 result = usb_stor_bulk_srb(us, pipe, srb);
1736 1730
diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c
index d278c5a99b7a..aacedef9667c 100644
--- a/drivers/usb/storage/sddr55.c
+++ b/drivers/usb/storage/sddr55.c
@@ -145,8 +145,7 @@ static int sddr55_status(struct us_data *us)
145 result = sddr55_bulk_transport(us, 145 result = sddr55_bulk_transport(us,
146 DMA_TO_DEVICE, command, 8); 146 DMA_TO_DEVICE, command, 8);
147 147
148 US_DEBUGP("Result for send_command in status %d\n", 148 usb_stor_dbg(us, "Result for send_command in status %d\n", result);
149 result);
150 149
151 if (result != USB_STOR_XFER_GOOD) { 150 if (result != USB_STOR_XFER_GOOD) {
152 set_sense_info (4, 0, 0); /* hardware error */ 151 set_sense_info (4, 0, 0); /* hardware error */
@@ -236,9 +235,8 @@ static int sddr55_read_data(struct us_data *us,
236 info->blocksize - page); 235 info->blocksize - page);
237 len = pages << info->pageshift; 236 len = pages << info->pageshift;
238 237
239 US_DEBUGP("Read %02X pages, from PBA %04X" 238 usb_stor_dbg(us, "Read %02X pages, from PBA %04X (LBA %04X) page %02X\n",
240 " (LBA %04X) page %02X\n", 239 pages, pba, lba, page);
241 pages, pba, lba, page);
242 240
243 if (pba == NOT_ALLOCATED) { 241 if (pba == NOT_ALLOCATED) {
244 /* no pba for this lba, fill with zeroes */ 242 /* no pba for this lba, fill with zeroes */
@@ -261,8 +259,8 @@ static int sddr55_read_data(struct us_data *us,
261 result = sddr55_bulk_transport(us, 259 result = sddr55_bulk_transport(us,
262 DMA_TO_DEVICE, command, 8); 260 DMA_TO_DEVICE, command, 8);
263 261
264 US_DEBUGP("Result for send_command in read_data %d\n", 262 usb_stor_dbg(us, "Result for send_command in read_data %d\n",
265 result); 263 result);
266 264
267 if (result != USB_STOR_XFER_GOOD) { 265 if (result != USB_STOR_XFER_GOOD) {
268 result = USB_STOR_TRANSPORT_ERROR; 266 result = USB_STOR_TRANSPORT_ERROR;
@@ -368,9 +366,8 @@ static int sddr55_write_data(struct us_data *us,
368 usb_stor_access_xfer_buf(buffer, len, us->srb, 366 usb_stor_access_xfer_buf(buffer, len, us->srb,
369 &sg, &offset, FROM_XFER_BUF); 367 &sg, &offset, FROM_XFER_BUF);
370 368
371 US_DEBUGP("Write %02X pages, to PBA %04X" 369 usb_stor_dbg(us, "Write %02X pages, to PBA %04X (LBA %04X) page %02X\n",
372 " (LBA %04X) page %02X\n", 370 pages, pba, lba, page);
373 pages, pba, lba, page);
374 371
375 command[4] = 0; 372 command[4] = 0;
376 373
@@ -384,7 +381,7 @@ static int sddr55_write_data(struct us_data *us,
384 /* set pba to first block in zone lba is in */ 381 /* set pba to first block in zone lba is in */
385 pba = (lba / 1000) * 1024; 382 pba = (lba / 1000) * 1024;
386 383
387 US_DEBUGP("No PBA for LBA %04X\n",lba); 384 usb_stor_dbg(us, "No PBA for LBA %04X\n", lba);
388 385
389 if (max_pba > 1024) 386 if (max_pba > 1024)
390 max_pba = 1024; 387 max_pba = 1024;
@@ -407,14 +404,15 @@ static int sddr55_write_data(struct us_data *us,
407 404
408 if (pba == -1) { 405 if (pba == -1) {
409 /* oh dear */ 406 /* oh dear */
410 US_DEBUGP("Couldn't find unallocated block\n"); 407 usb_stor_dbg(us, "Couldn't find unallocated block\n");
411 408
412 set_sense_info (3, 0x31, 0); /* medium error */ 409 set_sense_info (3, 0x31, 0); /* medium error */
413 result = USB_STOR_TRANSPORT_FAILED; 410 result = USB_STOR_TRANSPORT_FAILED;
414 goto leave; 411 goto leave;
415 } 412 }
416 413
417 US_DEBUGP("Allocating PBA %04X for LBA %04X\n", pba, lba); 414 usb_stor_dbg(us, "Allocating PBA %04X for LBA %04X\n",
415 pba, lba);
418 416
419 /* set writing to unallocated block flag */ 417 /* set writing to unallocated block flag */
420 command[4] = 0x40; 418 command[4] = 0x40;
@@ -439,8 +437,8 @@ static int sddr55_write_data(struct us_data *us,
439 DMA_TO_DEVICE, command, 8); 437 DMA_TO_DEVICE, command, 8);
440 438
441 if (result != USB_STOR_XFER_GOOD) { 439 if (result != USB_STOR_XFER_GOOD) {
442 US_DEBUGP("Result for send_command in write_data %d\n", 440 usb_stor_dbg(us, "Result for send_command in write_data %d\n",
443 result); 441 result);
444 442
445 /* set_sense_info is superfluous here? */ 443 /* set_sense_info is superfluous here? */
446 set_sense_info (3, 0x3, 0);/* peripheral write error */ 444 set_sense_info (3, 0x3, 0);/* peripheral write error */
@@ -453,8 +451,8 @@ static int sddr55_write_data(struct us_data *us,
453 DMA_TO_DEVICE, buffer, len); 451 DMA_TO_DEVICE, buffer, len);
454 452
455 if (result != USB_STOR_XFER_GOOD) { 453 if (result != USB_STOR_XFER_GOOD) {
456 US_DEBUGP("Result for send_data in write_data %d\n", 454 usb_stor_dbg(us, "Result for send_data in write_data %d\n",
457 result); 455 result);
458 456
459 /* set_sense_info is superfluous here? */ 457 /* set_sense_info is superfluous here? */
460 set_sense_info (3, 0x3, 0);/* peripheral write error */ 458 set_sense_info (3, 0x3, 0);/* peripheral write error */
@@ -466,8 +464,8 @@ static int sddr55_write_data(struct us_data *us,
466 result = sddr55_bulk_transport(us, DMA_FROM_DEVICE, status, 6); 464 result = sddr55_bulk_transport(us, DMA_FROM_DEVICE, status, 6);
467 465
468 if (result != USB_STOR_XFER_GOOD) { 466 if (result != USB_STOR_XFER_GOOD) {
469 US_DEBUGP("Result for get_status in write_data %d\n", 467 usb_stor_dbg(us, "Result for get_status in write_data %d\n",
470 result); 468 result);
471 469
472 /* set_sense_info is superfluous here? */ 470 /* set_sense_info is superfluous here? */
473 set_sense_info (3, 0x3, 0);/* peripheral write error */ 471 set_sense_info (3, 0x3, 0);/* peripheral write error */
@@ -487,8 +485,8 @@ static int sddr55_write_data(struct us_data *us,
487 goto leave; 485 goto leave;
488 } 486 }
489 487
490 US_DEBUGP("Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n", 488 usb_stor_dbg(us, "Updating maps for LBA %04X: old PBA %04X, new PBA %04X\n",
491 lba, pba, new_pba); 489 lba, pba, new_pba);
492 490
493 /* update the lba<->pba maps, note new_pba might be the same as pba */ 491 /* update the lba<->pba maps, note new_pba might be the same as pba */
494 info->lba_to_pba[lba] = new_pba; 492 info->lba_to_pba[lba] = new_pba;
@@ -531,8 +529,8 @@ static int sddr55_read_deviceID(struct us_data *us,
531 command[7] = 0x84; 529 command[7] = 0x84;
532 result = sddr55_bulk_transport(us, DMA_TO_DEVICE, command, 8); 530 result = sddr55_bulk_transport(us, DMA_TO_DEVICE, command, 8);
533 531
534 US_DEBUGP("Result of send_control for device ID is %d\n", 532 usb_stor_dbg(us, "Result of send_control for device ID is %d\n",
535 result); 533 result);
536 534
537 if (result != USB_STOR_XFER_GOOD) 535 if (result != USB_STOR_XFER_GOOD)
538 return USB_STOR_TRANSPORT_ERROR; 536 return USB_STOR_TRANSPORT_ERROR;
@@ -568,20 +566,19 @@ static unsigned long sddr55_get_capacity(struct us_data *us) {
568 int result; 566 int result;
569 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra; 567 struct sddr55_card_info *info = (struct sddr55_card_info *)us->extra;
570 568
571 US_DEBUGP("Reading capacity...\n"); 569 usb_stor_dbg(us, "Reading capacity...\n");
572 570
573 result = sddr55_read_deviceID(us, 571 result = sddr55_read_deviceID(us,
574 &manufacturerID, 572 &manufacturerID,
575 &deviceID); 573 &deviceID);
576 574
577 US_DEBUGP("Result of read_deviceID is %d\n", 575 usb_stor_dbg(us, "Result of read_deviceID is %d\n", result);
578 result);
579 576
580 if (result != USB_STOR_XFER_GOOD) 577 if (result != USB_STOR_XFER_GOOD)
581 return 0; 578 return 0;
582 579
583 US_DEBUGP("Device ID = %02X\n", deviceID); 580 usb_stor_dbg(us, "Device ID = %02X\n", deviceID);
584 US_DEBUGP("Manuf ID = %02X\n", manufacturerID); 581 usb_stor_dbg(us, "Manuf ID = %02X\n", manufacturerID);
585 582
586 info->pageshift = 9; 583 info->pageshift = 9;
587 info->smallpageshift = 0; 584 info->smallpageshift = 0;
@@ -753,7 +750,7 @@ static int sddr55_read_map(struct us_data *us) {
753 } 750 }
754 751
755 if (lba<0x10 || (lba>=0x3E0 && lba<0x3EF)) 752 if (lba<0x10 || (lba>=0x3E0 && lba<0x3EF))
756 US_DEBUGP("LBA %04X <-> PBA %04X\n", lba, i); 753 usb_stor_dbg(us, "LBA %04X <-> PBA %04X\n", lba, i);
757 754
758 info->lba_to_pba[lba + zone * 1000] = i; 755 info->lba_to_pba[lba + zone * 1000] = i;
759 } 756 }
@@ -808,7 +805,10 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
808 info = (struct sddr55_card_info *)(us->extra); 805 info = (struct sddr55_card_info *)(us->extra);
809 806
810 if (srb->cmnd[0] == REQUEST_SENSE) { 807 if (srb->cmnd[0] == REQUEST_SENSE) {
811 US_DEBUGP("SDDR55: request sense %02x/%02x/%02x\n", info->sense_data[2], info->sense_data[12], info->sense_data[13]); 808 usb_stor_dbg(us, "request sense %02x/%02x/%02x\n",
809 info->sense_data[2],
810 info->sense_data[12],
811 info->sense_data[13]);
812 812
813 memcpy (ptr, info->sense_data, sizeof info->sense_data); 813 memcpy (ptr, info->sense_data, sizeof info->sense_data);
814 ptr[0] = 0x70; 814 ptr[0] = 0x70;
@@ -892,13 +892,11 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
892 usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb); 892 usb_stor_set_xfer_buf(ptr, sizeof(mode_page_01), srb);
893 893
894 if ( (srb->cmnd[2] & 0x3F) == 0x01 ) { 894 if ( (srb->cmnd[2] & 0x3F) == 0x01 ) {
895 US_DEBUGP( 895 usb_stor_dbg(us, "Dummy up request for mode page 1\n");
896 "SDDR55: Dummy up request for mode page 1\n");
897 return USB_STOR_TRANSPORT_GOOD; 896 return USB_STOR_TRANSPORT_GOOD;
898 897
899 } else if ( (srb->cmnd[2] & 0x3F) == 0x3F ) { 898 } else if ( (srb->cmnd[2] & 0x3F) == 0x3F ) {
900 US_DEBUGP( 899 usb_stor_dbg(us, "Dummy up request for all mode pages\n");
901 "SDDR55: Dummy up request for all mode pages\n");
902 return USB_STOR_TRANSPORT_GOOD; 900 return USB_STOR_TRANSPORT_GOOD;
903 } 901 }
904 902
@@ -908,10 +906,8 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
908 906
909 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) { 907 if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
910 908
911 US_DEBUGP( 909 usb_stor_dbg(us, "%s medium removal. Not that I can do anything about it...\n",
912 "SDDR55: %s medium removal. Not that I can do" 910 (srb->cmnd[4]&0x03) ? "Prevent" : "Allow");
913 " anything about it...\n",
914 (srb->cmnd[4]&0x03) ? "Prevent" : "Allow");
915 911
916 return USB_STOR_TRANSPORT_GOOD; 912 return USB_STOR_TRANSPORT_GOOD;
917 913
@@ -935,8 +931,8 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
935 931
936 if (lba >= info->max_log_blks) { 932 if (lba >= info->max_log_blks) {
937 933
938 US_DEBUGP("Error: Requested LBA %04X exceeds maximum " 934 usb_stor_dbg(us, "Error: Requested LBA %04X exceeds maximum block %04X\n",
939 "block %04X\n", lba, info->max_log_blks-1); 935 lba, info->max_log_blks - 1);
940 936
941 set_sense_info (5, 0x24, 0); /* invalid field in command */ 937 set_sense_info (5, 0x24, 0); /* invalid field in command */
942 938
@@ -946,15 +942,13 @@ static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
946 pba = info->lba_to_pba[lba]; 942 pba = info->lba_to_pba[lba];
947 943
948 if (srb->cmnd[0] == WRITE_10) { 944 if (srb->cmnd[0] == WRITE_10) {
949 US_DEBUGP("WRITE_10: write block %04X (LBA %04X) page %01X" 945 usb_stor_dbg(us, "WRITE_10: write block %04X (LBA %04X) page %01X pages %d\n",
950 " pages %d\n", 946 pba, lba, page, pages);
951 pba, lba, page, pages);
952 947
953 return sddr55_write_data(us, lba, page, pages); 948 return sddr55_write_data(us, lba, page, pages);
954 } else { 949 } else {
955 US_DEBUGP("READ_10: read block %04X (LBA %04X) page %01X" 950 usb_stor_dbg(us, "READ_10: read block %04X (LBA %04X) page %01X pages %d\n",
956 " pages %d\n", 951 pba, lba, page, pages);
957 pba, lba, page, pages);
958 952
959 return sddr55_read_data(us, lba, page, pages); 953 return sddr55_read_data(us, lba, page, pages);
960 } 954 }
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index daf2fc58ae02..4ef2a80728f7 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -271,7 +271,7 @@ static int usbat_bulk_read(struct us_data *us,
271 if (len == 0) 271 if (len == 0)
272 return USB_STOR_XFER_GOOD; 272 return USB_STOR_XFER_GOOD;
273 273
274 US_DEBUGP("usbat_bulk_read: len = %d\n", len); 274 usb_stor_dbg(us, "len = %d\n", len);
275 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL); 275 return usb_stor_bulk_transfer_sg(us, us->recv_bulk_pipe, buf, len, use_sg, NULL);
276} 276}
277 277
@@ -286,7 +286,7 @@ static int usbat_bulk_write(struct us_data *us,
286 if (len == 0) 286 if (len == 0)
287 return USB_STOR_XFER_GOOD; 287 return USB_STOR_XFER_GOOD;
288 288
289 US_DEBUGP("usbat_bulk_write: len = %d\n", len); 289 usb_stor_dbg(us, "len = %d\n", len);
290 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL); 290 return usb_stor_bulk_transfer_sg(us, us->send_bulk_pipe, buf, len, use_sg, NULL);
291} 291}
292 292
@@ -312,7 +312,7 @@ static int usbat_get_status(struct us_data *us, unsigned char *status)
312 int rc; 312 int rc;
313 rc = usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status); 313 rc = usbat_read(us, USBAT_ATA, USBAT_ATA_STATUS, status);
314 314
315 US_DEBUGP("usbat_get_status: 0x%02X\n", (unsigned short) (*status)); 315 usb_stor_dbg(us, "0x%02X\n", *status);
316 return rc; 316 return rc;
317} 317}
318 318
@@ -425,7 +425,7 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
425 return USB_STOR_TRANSPORT_FAILED; 425 return USB_STOR_TRANSPORT_FAILED;
426 426
427 if ((*status & 0x80)==0x00) { /* not busy */ 427 if ((*status & 0x80)==0x00) { /* not busy */
428 US_DEBUGP("Waited not busy for %d steps\n", i); 428 usb_stor_dbg(us, "Waited not busy for %d steps\n", i);
429 return USB_STOR_TRANSPORT_GOOD; 429 return USB_STOR_TRANSPORT_GOOD;
430 } 430 }
431 431
@@ -439,8 +439,8 @@ static int usbat_wait_not_busy(struct us_data *us, int minutes)
439 msleep(1000); /* X minutes */ 439 msleep(1000); /* X minutes */
440 } 440 }
441 441
442 US_DEBUGP("Waited not busy for %d minutes, timing out.\n", 442 usb_stor_dbg(us, "Waited not busy for %d minutes, timing out\n",
443 minutes); 443 minutes);
444 return USB_STOR_TRANSPORT_FAILED; 444 return USB_STOR_TRANSPORT_FAILED;
445} 445}
446 446
@@ -657,8 +657,9 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
657 if (*status & 0x20) /* device fault */ 657 if (*status & 0x20) /* device fault */
658 return USB_STOR_TRANSPORT_FAILED; 658 return USB_STOR_TRANSPORT_FAILED;
659 659
660 US_DEBUGP("Redoing %s\n", 660 usb_stor_dbg(us, "Redoing %s\n",
661 direction==DMA_TO_DEVICE ? "write" : "read"); 661 direction == DMA_TO_DEVICE
662 ? "write" : "read");
662 663
663 } else if (result != USB_STOR_XFER_GOOD) 664 } else if (result != USB_STOR_XFER_GOOD)
664 return USB_STOR_TRANSPORT_ERROR; 665 return USB_STOR_TRANSPORT_ERROR;
@@ -667,8 +668,8 @@ static int usbat_hp8200e_rw_block_test(struct us_data *us,
667 668
668 } 669 }
669 670
670 US_DEBUGP("Bummer! %s bulk data 20 times failed.\n", 671 usb_stor_dbg(us, "Bummer! %s bulk data 20 times failed\n",
671 direction==DMA_TO_DEVICE ? "Writing" : "Reading"); 672 direction == DMA_TO_DEVICE ? "Writing" : "Reading");
672 673
673 return USB_STOR_TRANSPORT_FAILED; 674 return USB_STOR_TRANSPORT_FAILED;
674} 675}
@@ -827,7 +828,7 @@ static int usbat_read_user_io(struct us_data *us, unsigned char *data_flags)
827 data_flags, 828 data_flags,
828 USBAT_UIO_READ); 829 USBAT_UIO_READ);
829 830
830 US_DEBUGP("usbat_read_user_io: UIO register reads %02X\n", (unsigned short) (*data_flags)); 831 usb_stor_dbg(us, "UIO register reads %02X\n", *data_flags);
831 832
832 return result; 833 return result;
833} 834}
@@ -900,10 +901,11 @@ static int usbat_device_enable_cdt(struct us_data *us)
900/* 901/*
901 * Determine if media is present. 902 * Determine if media is present.
902 */ 903 */
903static int usbat_flash_check_media_present(unsigned char *uio) 904static int usbat_flash_check_media_present(struct us_data *us,
905 unsigned char *uio)
904{ 906{
905 if (*uio & USBAT_UIO_UI0) { 907 if (*uio & USBAT_UIO_UI0) {
906 US_DEBUGP("usbat_flash_check_media_present: no media detected\n"); 908 usb_stor_dbg(us, "no media detected\n");
907 return USBAT_FLASH_MEDIA_NONE; 909 return USBAT_FLASH_MEDIA_NONE;
908 } 910 }
909 911
@@ -913,10 +915,11 @@ static int usbat_flash_check_media_present(unsigned char *uio)
913/* 915/*
914 * Determine if media has changed since last operation 916 * Determine if media has changed since last operation
915 */ 917 */
916static int usbat_flash_check_media_changed(unsigned char *uio) 918static int usbat_flash_check_media_changed(struct us_data *us,
919 unsigned char *uio)
917{ 920{
918 if (*uio & USBAT_UIO_0) { 921 if (*uio & USBAT_UIO_0) {
919 US_DEBUGP("usbat_flash_check_media_changed: media change detected\n"); 922 usb_stor_dbg(us, "media change detected\n");
920 return USBAT_FLASH_MEDIA_CHANGED; 923 return USBAT_FLASH_MEDIA_CHANGED;
921 } 924 }
922 925
@@ -937,7 +940,7 @@ static int usbat_flash_check_media(struct us_data *us,
937 return USB_STOR_TRANSPORT_ERROR; 940 return USB_STOR_TRANSPORT_ERROR;
938 941
939 /* Check for media existence */ 942 /* Check for media existence */
940 rc = usbat_flash_check_media_present(uio); 943 rc = usbat_flash_check_media_present(us, uio);
941 if (rc == USBAT_FLASH_MEDIA_NONE) { 944 if (rc == USBAT_FLASH_MEDIA_NONE) {
942 info->sense_key = 0x02; 945 info->sense_key = 0x02;
943 info->sense_asc = 0x3A; 946 info->sense_asc = 0x3A;
@@ -946,7 +949,7 @@ static int usbat_flash_check_media(struct us_data *us,
946 } 949 }
947 950
948 /* Check for media change */ 951 /* Check for media change */
949 rc = usbat_flash_check_media_changed(uio); 952 rc = usbat_flash_check_media_changed(us, uio);
950 if (rc == USBAT_FLASH_MEDIA_CHANGED) { 953 if (rc == USBAT_FLASH_MEDIA_CHANGED) {
951 954
952 /* Reset and re-enable card detect */ 955 /* Reset and re-enable card detect */
@@ -1008,11 +1011,11 @@ static int usbat_identify_device(struct us_data *us,
1008 /* Check for error bit, or if the command 'fell through' */ 1011 /* Check for error bit, or if the command 'fell through' */
1009 if (status == 0xA1 || !(status & 0x01)) { 1012 if (status == 0xA1 || !(status & 0x01)) {
1010 /* Device is HP 8200 */ 1013 /* Device is HP 8200 */
1011 US_DEBUGP("usbat_identify_device: Detected HP8200 CDRW\n"); 1014 usb_stor_dbg(us, "Detected HP8200 CDRW\n");
1012 info->devicetype = USBAT_DEV_HP8200; 1015 info->devicetype = USBAT_DEV_HP8200;
1013 } else { 1016 } else {
1014 /* Device is a CompactFlash reader/writer */ 1017 /* Device is a CompactFlash reader/writer */
1015 US_DEBUGP("usbat_identify_device: Detected Flash reader/writer\n"); 1018 usb_stor_dbg(us, "Detected Flash reader/writer\n");
1016 info->devicetype = USBAT_DEV_FLASH; 1019 info->devicetype = USBAT_DEV_FLASH;
1017 } 1020 }
1018 1021
@@ -1075,7 +1078,7 @@ static int usbat_flash_get_sector_count(struct us_data *us,
1075 /* ATA command : IDENTIFY DEVICE */ 1078 /* ATA command : IDENTIFY DEVICE */
1076 rc = usbat_multiple_write(us, registers, command, 3); 1079 rc = usbat_multiple_write(us, registers, command, 3);
1077 if (rc != USB_STOR_XFER_GOOD) { 1080 if (rc != USB_STOR_XFER_GOOD) {
1078 US_DEBUGP("usbat_flash_get_sector_count: Gah! identify_device failed\n"); 1081 usb_stor_dbg(us, "Gah! identify_device failed\n");
1079 rc = USB_STOR_TRANSPORT_ERROR; 1082 rc = USB_STOR_TRANSPORT_ERROR;
1080 goto leave; 1083 goto leave;
1081 } 1084 }
@@ -1178,7 +1181,7 @@ static int usbat_flash_read_data(struct us_data *us,
1178 if (result != USB_STOR_TRANSPORT_GOOD) 1181 if (result != USB_STOR_TRANSPORT_GOOD)
1179 goto leave; 1182 goto leave;
1180 1183
1181 US_DEBUGP("usbat_flash_read_data: %d bytes\n", len); 1184 usb_stor_dbg(us, "%d bytes\n", len);
1182 1185
1183 /* Store the data in the transfer buffer */ 1186 /* Store the data in the transfer buffer */
1184 usb_stor_access_xfer_buf(buffer, len, us->srb, 1187 usb_stor_access_xfer_buf(buffer, len, us->srb,
@@ -1301,8 +1304,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1301 unsigned int sg_offset = 0; 1304 unsigned int sg_offset = 0;
1302 struct scatterlist *sg = NULL; 1305 struct scatterlist *sg = NULL;
1303 1306
1304 US_DEBUGP("handle_read10: transfersize %d\n", 1307 usb_stor_dbg(us, "transfersize %d\n", srb->transfersize);
1305 srb->transfersize);
1306 1308
1307 if (scsi_bufflen(srb) < 0x10000) { 1309 if (scsi_bufflen(srb) < 0x10000) {
1308 1310
@@ -1329,14 +1331,14 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1329 len = short_pack(data[7+9], data[7+8]); 1331 len = short_pack(data[7+9], data[7+8]);
1330 len <<= 16; 1332 len <<= 16;
1331 len |= data[7+7]; 1333 len |= data[7+7];
1332 US_DEBUGP("handle_read10: GPCMD_READ_CD: len %d\n", len); 1334 usb_stor_dbg(us, "GPCMD_READ_CD: len %d\n", len);
1333 srb->transfersize = scsi_bufflen(srb)/len; 1335 srb->transfersize = scsi_bufflen(srb)/len;
1334 } 1336 }
1335 1337
1336 if (!srb->transfersize) { 1338 if (!srb->transfersize) {
1337 srb->transfersize = 2048; /* A guess */ 1339 srb->transfersize = 2048; /* A guess */
1338 US_DEBUGP("handle_read10: transfersize 0, forcing %d\n", 1340 usb_stor_dbg(us, "transfersize 0, forcing %d\n",
1339 srb->transfersize); 1341 srb->transfersize);
1340 } 1342 }
1341 1343
1342 /* 1344 /*
@@ -1346,7 +1348,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
1346 */ 1348 */
1347 1349
1348 len = (65535/srb->transfersize) * srb->transfersize; 1350 len = (65535/srb->transfersize) * srb->transfersize;
1349 US_DEBUGP("Max read is %d bytes\n", len); 1351 usb_stor_dbg(us, "Max read is %d bytes\n", len);
1350 len = min(len, scsi_bufflen(srb)); 1352 len = min(len, scsi_bufflen(srb));
1351 buffer = kmalloc(len, GFP_NOIO); 1353 buffer = kmalloc(len, GFP_NOIO);
1352 if (buffer == NULL) /* bloody hell! */ 1354 if (buffer == NULL) /* bloody hell! */
@@ -1460,10 +1462,9 @@ static int init_usbat(struct us_data *us, int devicetype)
1460 unsigned char *status = us->iobuf; 1462 unsigned char *status = us->iobuf;
1461 1463
1462 us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO); 1464 us->extra = kzalloc(sizeof(struct usbat_info), GFP_NOIO);
1463 if (!us->extra) { 1465 if (!us->extra)
1464 US_DEBUGP("init_usbat: Gah! Can't allocate storage for usbat info struct!\n");
1465 return 1; 1466 return 1;
1466 } 1467
1467 info = (struct usbat_info *) (us->extra); 1468 info = (struct usbat_info *) (us->extra);
1468 1469
1469 /* Enable peripheral control signals */ 1470 /* Enable peripheral control signals */
@@ -1473,7 +1474,7 @@ static int init_usbat(struct us_data *us, int devicetype)
1473 if (rc != USB_STOR_XFER_GOOD) 1474 if (rc != USB_STOR_XFER_GOOD)
1474 return USB_STOR_TRANSPORT_ERROR; 1475 return USB_STOR_TRANSPORT_ERROR;
1475 1476
1476 US_DEBUGP("INIT 1\n"); 1477 usb_stor_dbg(us, "INIT 1\n");
1477 1478
1478 msleep(2000); 1479 msleep(2000);
1479 1480
@@ -1481,7 +1482,7 @@ static int init_usbat(struct us_data *us, int devicetype)
1481 if (rc != USB_STOR_TRANSPORT_GOOD) 1482 if (rc != USB_STOR_TRANSPORT_GOOD)
1482 return rc; 1483 return rc;
1483 1484
1484 US_DEBUGP("INIT 2\n"); 1485 usb_stor_dbg(us, "INIT 2\n");
1485 1486
1486 rc = usbat_read_user_io(us, status); 1487 rc = usbat_read_user_io(us, status);
1487 if (rc != USB_STOR_XFER_GOOD) 1488 if (rc != USB_STOR_XFER_GOOD)
@@ -1491,32 +1492,32 @@ static int init_usbat(struct us_data *us, int devicetype)
1491 if (rc != USB_STOR_XFER_GOOD) 1492 if (rc != USB_STOR_XFER_GOOD)
1492 return USB_STOR_TRANSPORT_ERROR; 1493 return USB_STOR_TRANSPORT_ERROR;
1493 1494
1494 US_DEBUGP("INIT 3\n"); 1495 usb_stor_dbg(us, "INIT 3\n");
1495 1496
1496 rc = usbat_select_and_test_registers(us); 1497 rc = usbat_select_and_test_registers(us);
1497 if (rc != USB_STOR_TRANSPORT_GOOD) 1498 if (rc != USB_STOR_TRANSPORT_GOOD)
1498 return rc; 1499 return rc;
1499 1500
1500 US_DEBUGP("INIT 4\n"); 1501 usb_stor_dbg(us, "INIT 4\n");
1501 1502
1502 rc = usbat_read_user_io(us, status); 1503 rc = usbat_read_user_io(us, status);
1503 if (rc != USB_STOR_XFER_GOOD) 1504 if (rc != USB_STOR_XFER_GOOD)
1504 return USB_STOR_TRANSPORT_ERROR; 1505 return USB_STOR_TRANSPORT_ERROR;
1505 1506
1506 US_DEBUGP("INIT 5\n"); 1507 usb_stor_dbg(us, "INIT 5\n");
1507 1508
1508 /* Enable peripheral control signals and card detect */ 1509 /* Enable peripheral control signals and card detect */
1509 rc = usbat_device_enable_cdt(us); 1510 rc = usbat_device_enable_cdt(us);
1510 if (rc != USB_STOR_TRANSPORT_GOOD) 1511 if (rc != USB_STOR_TRANSPORT_GOOD)
1511 return rc; 1512 return rc;
1512 1513
1513 US_DEBUGP("INIT 6\n"); 1514 usb_stor_dbg(us, "INIT 6\n");
1514 1515
1515 rc = usbat_read_user_io(us, status); 1516 rc = usbat_read_user_io(us, status);
1516 if (rc != USB_STOR_XFER_GOOD) 1517 if (rc != USB_STOR_XFER_GOOD)
1517 return USB_STOR_TRANSPORT_ERROR; 1518 return USB_STOR_TRANSPORT_ERROR;
1518 1519
1519 US_DEBUGP("INIT 7\n"); 1520 usb_stor_dbg(us, "INIT 7\n");
1520 1521
1521 msleep(1400); 1522 msleep(1400);
1522 1523
@@ -1524,19 +1525,19 @@ static int init_usbat(struct us_data *us, int devicetype)
1524 if (rc != USB_STOR_XFER_GOOD) 1525 if (rc != USB_STOR_XFER_GOOD)
1525 return USB_STOR_TRANSPORT_ERROR; 1526 return USB_STOR_TRANSPORT_ERROR;
1526 1527
1527 US_DEBUGP("INIT 8\n"); 1528 usb_stor_dbg(us, "INIT 8\n");
1528 1529
1529 rc = usbat_select_and_test_registers(us); 1530 rc = usbat_select_and_test_registers(us);
1530 if (rc != USB_STOR_TRANSPORT_GOOD) 1531 if (rc != USB_STOR_TRANSPORT_GOOD)
1531 return rc; 1532 return rc;
1532 1533
1533 US_DEBUGP("INIT 9\n"); 1534 usb_stor_dbg(us, "INIT 9\n");
1534 1535
1535 /* At this point, we need to detect which device we are using */ 1536 /* At this point, we need to detect which device we are using */
1536 if (usbat_set_transport(us, info, devicetype)) 1537 if (usbat_set_transport(us, info, devicetype))
1537 return USB_STOR_TRANSPORT_ERROR; 1538 return USB_STOR_TRANSPORT_ERROR;
1538 1539
1539 US_DEBUGP("INIT 10\n"); 1540 usb_stor_dbg(us, "INIT 10\n");
1540 1541
1541 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) { 1542 if (usbat_get_device_type(us) == USBAT_DEV_FLASH) {
1542 subcountH = 0x02; 1543 subcountH = 0x02;
@@ -1547,7 +1548,7 @@ static int init_usbat(struct us_data *us, int devicetype)
1547 if (rc != USB_STOR_XFER_GOOD) 1548 if (rc != USB_STOR_XFER_GOOD)
1548 return USB_STOR_TRANSPORT_ERROR; 1549 return USB_STOR_TRANSPORT_ERROR;
1549 1550
1550 US_DEBUGP("INIT 11\n"); 1551 usb_stor_dbg(us, "INIT 11\n");
1551 1552
1552 return USB_STOR_TRANSPORT_GOOD; 1553 return USB_STOR_TRANSPORT_GOOD;
1553} 1554}
@@ -1592,7 +1593,7 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1592 } 1593 }
1593 1594
1594 result = usbat_get_status(us, status); 1595 result = usbat_get_status(us, status);
1595 US_DEBUGP("Status = %02X\n", *status); 1596 usb_stor_dbg(us, "Status = %02X\n", *status);
1596 if (result != USB_STOR_XFER_GOOD) 1597 if (result != USB_STOR_XFER_GOOD)
1597 return USB_STOR_TRANSPORT_ERROR; 1598 return USB_STOR_TRANSPORT_ERROR;
1598 if (srb->cmnd[0] == TEST_UNIT_READY) 1599 if (srb->cmnd[0] == TEST_UNIT_READY)
@@ -1610,7 +1611,7 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1610 1611
1611 if (result == USB_STOR_TRANSPORT_GOOD) { 1612 if (result == USB_STOR_TRANSPORT_GOOD) {
1612 transferred += len; 1613 transferred += len;
1613 US_DEBUGP("Wrote %08X bytes\n", transferred); 1614 usb_stor_dbg(us, "Wrote %08X bytes\n", transferred);
1614 } 1615 }
1615 1616
1616 return result; 1617 return result;
@@ -1623,8 +1624,8 @@ static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us)
1623 } 1624 }
1624 1625
1625 if (len > 0xFFFF) { 1626 if (len > 0xFFFF) {
1626 US_DEBUGP("Error: len = %08X... what do I do now?\n", 1627 usb_stor_dbg(us, "Error: len = %08X... what do I do now?\n",
1627 len); 1628 len);
1628 return USB_STOR_TRANSPORT_ERROR; 1629 return USB_STOR_TRANSPORT_ERROR;
1629 } 1630 }
1630 1631
@@ -1693,7 +1694,7 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1693 }; 1694 };
1694 1695
1695 if (srb->cmnd[0] == INQUIRY) { 1696 if (srb->cmnd[0] == INQUIRY) {
1696 US_DEBUGP("usbat_flash_transport: INQUIRY. Returning bogus response.\n"); 1697 usb_stor_dbg(us, "INQUIRY - Returning bogus response\n");
1697 memcpy(ptr, inquiry_response, sizeof(inquiry_response)); 1698 memcpy(ptr, inquiry_response, sizeof(inquiry_response));
1698 fill_inquiry_response(us, ptr, 36); 1699 fill_inquiry_response(us, ptr, 36);
1699 return USB_STOR_TRANSPORT_GOOD; 1700 return USB_STOR_TRANSPORT_GOOD;
@@ -1710,8 +1711,8 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1710 1711
1711 /* hard coded 512 byte sectors as per ATA spec */ 1712 /* hard coded 512 byte sectors as per ATA spec */
1712 info->ssize = 0x200; 1713 info->ssize = 0x200;
1713 US_DEBUGP("usbat_flash_transport: READ_CAPACITY: %ld sectors, %ld bytes per sector\n", 1714 usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
1714 info->sectors, info->ssize); 1715 info->sectors, info->ssize);
1715 1716
1716 /* 1717 /*
1717 * build the reply 1718 * build the reply
@@ -1726,7 +1727,7 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1726 } 1727 }
1727 1728
1728 if (srb->cmnd[0] == MODE_SELECT_10) { 1729 if (srb->cmnd[0] == MODE_SELECT_10) {
1729 US_DEBUGP("usbat_flash_transport: Gah! MODE_SELECT_10.\n"); 1730 usb_stor_dbg(us, "Gah! MODE_SELECT_10\n");
1730 return USB_STOR_TRANSPORT_ERROR; 1731 return USB_STOR_TRANSPORT_ERROR;
1731 } 1732 }
1732 1733
@@ -1736,7 +1737,8 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1736 1737
1737 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 1738 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
1738 1739
1739 US_DEBUGP("usbat_flash_transport: READ_10: read block 0x%04lx count %ld\n", block, blocks); 1740 usb_stor_dbg(us, "READ_10: read block 0x%04lx count %ld\n",
1741 block, blocks);
1740 return usbat_flash_read_data(us, info, block, blocks); 1742 return usbat_flash_read_data(us, info, block, blocks);
1741 } 1743 }
1742 1744
@@ -1750,7 +1752,8 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1750 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 1752 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
1751 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 1753 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
1752 1754
1753 US_DEBUGP("usbat_flash_transport: READ_12: read block 0x%04lx count %ld\n", block, blocks); 1755 usb_stor_dbg(us, "READ_12: read block 0x%04lx count %ld\n",
1756 block, blocks);
1754 return usbat_flash_read_data(us, info, block, blocks); 1757 return usbat_flash_read_data(us, info, block, blocks);
1755 } 1758 }
1756 1759
@@ -1760,7 +1763,8 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1760 1763
1761 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8])); 1764 blocks = ((u32)(srb->cmnd[7]) << 8) | ((u32)(srb->cmnd[8]));
1762 1765
1763 US_DEBUGP("usbat_flash_transport: WRITE_10: write block 0x%04lx count %ld\n", block, blocks); 1766 usb_stor_dbg(us, "WRITE_10: write block 0x%04lx count %ld\n",
1767 block, blocks);
1764 return usbat_flash_write_data(us, info, block, blocks); 1768 return usbat_flash_write_data(us, info, block, blocks);
1765 } 1769 }
1766 1770
@@ -1774,13 +1778,14 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1774 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) | 1778 blocks = ((u32)(srb->cmnd[6]) << 24) | ((u32)(srb->cmnd[7]) << 16) |
1775 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9])); 1779 ((u32)(srb->cmnd[8]) << 8) | ((u32)(srb->cmnd[9]));
1776 1780
1777 US_DEBUGP("usbat_flash_transport: WRITE_12: write block 0x%04lx count %ld\n", block, blocks); 1781 usb_stor_dbg(us, "WRITE_12: write block 0x%04lx count %ld\n",
1782 block, blocks);
1778 return usbat_flash_write_data(us, info, block, blocks); 1783 return usbat_flash_write_data(us, info, block, blocks);
1779 } 1784 }
1780 1785
1781 1786
1782 if (srb->cmnd[0] == TEST_UNIT_READY) { 1787 if (srb->cmnd[0] == TEST_UNIT_READY) {
1783 US_DEBUGP("usbat_flash_transport: TEST_UNIT_READY.\n"); 1788 usb_stor_dbg(us, "TEST_UNIT_READY\n");
1784 1789
1785 rc = usbat_flash_check_media(us, info); 1790 rc = usbat_flash_check_media(us, info);
1786 if (rc != USB_STOR_TRANSPORT_GOOD) 1791 if (rc != USB_STOR_TRANSPORT_GOOD)
@@ -1790,7 +1795,7 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1790 } 1795 }
1791 1796
1792 if (srb->cmnd[0] == REQUEST_SENSE) { 1797 if (srb->cmnd[0] == REQUEST_SENSE) {
1793 US_DEBUGP("usbat_flash_transport: REQUEST_SENSE.\n"); 1798 usb_stor_dbg(us, "REQUEST_SENSE\n");
1794 1799
1795 memset(ptr, 0, 18); 1800 memset(ptr, 0, 18);
1796 ptr[0] = 0xF0; 1801 ptr[0] = 0xF0;
@@ -1811,8 +1816,8 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1811 return USB_STOR_TRANSPORT_GOOD; 1816 return USB_STOR_TRANSPORT_GOOD;
1812 } 1817 }
1813 1818
1814 US_DEBUGP("usbat_flash_transport: Gah! Unknown command: %d (0x%x)\n", 1819 usb_stor_dbg(us, "Gah! Unknown command: %d (0x%x)\n",
1815 srb->cmnd[0], srb->cmnd[0]); 1820 srb->cmnd[0], srb->cmnd[0]);
1816 info->sense_key = 0x05; 1821 info->sense_key = 0x05;
1817 info->sense_asc = 0x20; 1822 info->sense_asc = 0x20;
1818 info->sense_ascq = 0x00; 1823 info->sense_ascq = 0x00;
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 17e36952bced..2ea657be14c8 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -47,7 +47,7 @@ static bool containsFullLinuxPackage(struct swoc_info *swocInfo)
47static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode) 47static int sierra_set_ms_mode(struct usb_device *udev, __u16 eSWocMode)
48{ 48{
49 int result; 49 int result;
50 US_DEBUGP("SWIMS: %s", "DEVICE MODE SWITCH\n"); 50 dev_dbg(&udev->dev, "SWIMS: %s", "DEVICE MODE SWITCH\n");
51 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 51 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
52 SWIMS_USB_REQUEST_SetSwocMode, /* __u8 request */ 52 SWIMS_USB_REQUEST_SetSwocMode, /* __u8 request */
53 USB_TYPE_VENDOR | USB_DIR_OUT, /* __u8 request type */ 53 USB_TYPE_VENDOR | USB_DIR_OUT, /* __u8 request type */
@@ -65,7 +65,7 @@ static int sierra_get_swoc_info(struct usb_device *udev,
65{ 65{
66 int result; 66 int result;
67 67
68 US_DEBUGP("SWIMS: Attempting to get TRU-Install info.\n"); 68 dev_dbg(&udev->dev, "SWIMS: Attempting to get TRU-Install info\n");
69 69
70 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 70 result = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
71 SWIMS_USB_REQUEST_GetSwocInfo, /* __u8 request */ 71 SWIMS_USB_REQUEST_GetSwocInfo, /* __u8 request */
@@ -81,11 +81,11 @@ static int sierra_get_swoc_info(struct usb_device *udev,
81 return result; 81 return result;
82} 82}
83 83
84static void debug_swoc(struct swoc_info *swocInfo) 84static void debug_swoc(const struct device *dev, struct swoc_info *swocInfo)
85{ 85{
86 US_DEBUGP("SWIMS: SWoC Rev: %02d \n", swocInfo->rev); 86 dev_dbg(dev, "SWIMS: SWoC Rev: %02d\n", swocInfo->rev);
87 US_DEBUGP("SWIMS: Linux SKU: %04X \n", swocInfo->LinuxSKU); 87 dev_dbg(dev, "SWIMS: Linux SKU: %04X\n", swocInfo->LinuxSKU);
88 US_DEBUGP("SWIMS: Linux Version: %04X \n", swocInfo->LinuxVer); 88 dev_dbg(dev, "SWIMS: Linux Version: %04X\n", swocInfo->LinuxVer);
89} 89}
90 90
91 91
@@ -101,18 +101,17 @@ static ssize_t show_truinst(struct device *dev, struct device_attribute *attr,
101 } else { 101 } else {
102 swocInfo = kmalloc(sizeof(struct swoc_info), GFP_KERNEL); 102 swocInfo = kmalloc(sizeof(struct swoc_info), GFP_KERNEL);
103 if (!swocInfo) { 103 if (!swocInfo) {
104 US_DEBUGP("SWIMS: Allocation failure\n");
105 snprintf(buf, PAGE_SIZE, "Error\n"); 104 snprintf(buf, PAGE_SIZE, "Error\n");
106 return -ENOMEM; 105 return -ENOMEM;
107 } 106 }
108 result = sierra_get_swoc_info(udev, swocInfo); 107 result = sierra_get_swoc_info(udev, swocInfo);
109 if (result < 0) { 108 if (result < 0) {
110 US_DEBUGP("SWIMS: failed SWoC query\n"); 109 dev_dbg(dev, "SWIMS: failed SWoC query\n");
111 kfree(swocInfo); 110 kfree(swocInfo);
112 snprintf(buf, PAGE_SIZE, "Error\n"); 111 snprintf(buf, PAGE_SIZE, "Error\n");
113 return -EIO; 112 return -EIO;
114 } 113 }
115 debug_swoc(swocInfo); 114 debug_swoc(dev, swocInfo);
116 result = snprintf(buf, PAGE_SIZE, 115 result = snprintf(buf, PAGE_SIZE,
117 "REV=%02d SKU=%04X VER=%04X\n", 116 "REV=%02d SKU=%04X VER=%04X\n",
118 swocInfo->rev, 117 swocInfo->rev,
@@ -138,61 +137,55 @@ int sierra_ms_init(struct us_data *us)
138 sh = us_to_host(us); 137 sh = us_to_host(us);
139 scsi_get_host_dev(sh); 138 scsi_get_host_dev(sh);
140 139
141 US_DEBUGP("SWIMS: sierra_ms_init called\n");
142
143 /* Force Modem mode */ 140 /* Force Modem mode */
144 if (swi_tru_install == TRU_FORCE_MODEM) { 141 if (swi_tru_install == TRU_FORCE_MODEM) {
145 US_DEBUGP("SWIMS: %s", "Forcing Modem Mode\n"); 142 usb_stor_dbg(us, "SWIMS: Forcing Modem Mode\n");
146 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem); 143 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
147 if (result < 0) 144 if (result < 0)
148 US_DEBUGP("SWIMS: Failed to switch to modem mode.\n"); 145 usb_stor_dbg(us, "SWIMS: Failed to switch to modem mode\n");
149 return -EIO; 146 return -EIO;
150 } 147 }
151 /* Force Mass Storage mode (keep CD-Rom) */ 148 /* Force Mass Storage mode (keep CD-Rom) */
152 else if (swi_tru_install == TRU_FORCE_MS) { 149 else if (swi_tru_install == TRU_FORCE_MS) {
153 US_DEBUGP("SWIMS: %s", "Forcing Mass Storage Mode\n"); 150 usb_stor_dbg(us, "SWIMS: Forcing Mass Storage Mode\n");
154 goto complete; 151 goto complete;
155 } 152 }
156 /* Normal TRU-Install Logic */ 153 /* Normal TRU-Install Logic */
157 else { 154 else {
158 US_DEBUGP("SWIMS: %s", "Normal SWoC Logic\n"); 155 usb_stor_dbg(us, "SWIMS: Normal SWoC Logic\n");
159 156
160 swocInfo = kmalloc(sizeof(struct swoc_info), 157 swocInfo = kmalloc(sizeof(struct swoc_info),
161 GFP_KERNEL); 158 GFP_KERNEL);
162 if (!swocInfo) { 159 if (!swocInfo)
163 US_DEBUGP("SWIMS: %s", "Allocation failure\n");
164 return -ENOMEM; 160 return -ENOMEM;
165 }
166 161
167 retries = 3; 162 retries = 3;
168 do { 163 do {
169 retries--; 164 retries--;
170 result = sierra_get_swoc_info(udev, swocInfo); 165 result = sierra_get_swoc_info(udev, swocInfo);
171 if (result < 0) { 166 if (result < 0) {
172 US_DEBUGP("SWIMS: %s", "Failed SWoC query\n"); 167 usb_stor_dbg(us, "SWIMS: Failed SWoC query\n");
173 schedule_timeout_uninterruptible(2*HZ); 168 schedule_timeout_uninterruptible(2*HZ);
174 } 169 }
175 } while (retries && result < 0); 170 } while (retries && result < 0);
176 171
177 if (result < 0) { 172 if (result < 0) {
178 US_DEBUGP("SWIMS: %s", 173 usb_stor_dbg(us, "SWIMS: Completely failed SWoC query\n");
179 "Completely failed SWoC query\n");
180 kfree(swocInfo); 174 kfree(swocInfo);
181 return -EIO; 175 return -EIO;
182 } 176 }
183 177
184 debug_swoc(swocInfo); 178 debug_swoc(&us->pusb_dev->dev, swocInfo);
185 179
186 /* If there is not Linux software on the TRU-Install device 180 /* If there is not Linux software on the TRU-Install device
187 * then switch to modem mode 181 * then switch to modem mode
188 */ 182 */
189 if (!containsFullLinuxPackage(swocInfo)) { 183 if (!containsFullLinuxPackage(swocInfo)) {
190 US_DEBUGP("SWIMS: %s", 184 usb_stor_dbg(us, "SWIMS: Switching to Modem Mode\n");
191 "Switching to Modem Mode\n");
192 result = sierra_set_ms_mode(udev, 185 result = sierra_set_ms_mode(udev,
193 SWIMS_SET_MODE_Modem); 186 SWIMS_SET_MODE_Modem);
194 if (result < 0) 187 if (result < 0)
195 US_DEBUGP("SWIMS: Failed to switch modem\n"); 188 usb_stor_dbg(us, "SWIMS: Failed to switch modem\n");
196 kfree(swocInfo); 189 kfree(swocInfo);
197 return -EIO; 190 return -EIO;
198 } 191 }
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index c0543c83923e..22c7d4360fa2 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -166,7 +166,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
166 166
167 /* cancel the URB, if it hasn't been cancelled already */ 167 /* cancel the URB, if it hasn't been cancelled already */
168 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) { 168 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
169 US_DEBUGP("-- cancelling URB\n"); 169 usb_stor_dbg(us, "-- cancelling URB\n");
170 usb_unlink_urb(us->current_urb); 170 usb_unlink_urb(us->current_urb);
171 } 171 }
172 } 172 }
@@ -178,8 +178,8 @@ static int usb_stor_msg_common(struct us_data *us, int timeout)
178 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags); 178 clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags);
179 179
180 if (timeleft <= 0) { 180 if (timeleft <= 0) {
181 US_DEBUGP("%s -- cancelling URB\n", 181 usb_stor_dbg(us, "%s -- cancelling URB\n",
182 timeleft == 0 ? "Timeout" : "Signal"); 182 timeleft == 0 ? "Timeout" : "Signal");
183 usb_kill_urb(us->current_urb); 183 usb_kill_urb(us->current_urb);
184 } 184 }
185 185
@@ -197,9 +197,8 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
197{ 197{
198 int status; 198 int status;
199 199
200 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n", 200 usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
201 __func__, request, requesttype, 201 request, requesttype, value, index, size);
202 value, index, size);
203 202
204 /* fill in the devrequest structure */ 203 /* fill in the devrequest structure */
205 us->cr->bRequestType = requesttype; 204 us->cr->bRequestType = requesttype;
@@ -249,7 +248,7 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
249 if (result >= 0) 248 if (result >= 0)
250 usb_reset_endpoint(us->pusb_dev, endp); 249 usb_reset_endpoint(us->pusb_dev, endp);
251 250
252 US_DEBUGP("%s: result = %d\n", __func__, result); 251 usb_stor_dbg(us, "result = %d\n", result);
253 return result; 252 return result;
254} 253}
255EXPORT_SYMBOL_GPL(usb_stor_clear_halt); 254EXPORT_SYMBOL_GPL(usb_stor_clear_halt);
@@ -265,18 +264,18 @@ EXPORT_SYMBOL_GPL(usb_stor_clear_halt);
265static int interpret_urb_result(struct us_data *us, unsigned int pipe, 264static int interpret_urb_result(struct us_data *us, unsigned int pipe,
266 unsigned int length, int result, unsigned int partial) 265 unsigned int length, int result, unsigned int partial)
267{ 266{
268 US_DEBUGP("Status code %d; transferred %u/%u\n", 267 usb_stor_dbg(us, "Status code %d; transferred %u/%u\n",
269 result, partial, length); 268 result, partial, length);
270 switch (result) { 269 switch (result) {
271 270
272 /* no error code; did we send all the data? */ 271 /* no error code; did we send all the data? */
273 case 0: 272 case 0:
274 if (partial != length) { 273 if (partial != length) {
275 US_DEBUGP("-- short transfer\n"); 274 usb_stor_dbg(us, "-- short transfer\n");
276 return USB_STOR_XFER_SHORT; 275 return USB_STOR_XFER_SHORT;
277 } 276 }
278 277
279 US_DEBUGP("-- transfer complete\n"); 278 usb_stor_dbg(us, "-- transfer complete\n");
280 return USB_STOR_XFER_GOOD; 279 return USB_STOR_XFER_GOOD;
281 280
282 /* stalled */ 281 /* stalled */
@@ -284,39 +283,40 @@ static int interpret_urb_result(struct us_data *us, unsigned int pipe,
284 /* for control endpoints, (used by CB[I]) a stall indicates 283 /* for control endpoints, (used by CB[I]) a stall indicates
285 * a failed command */ 284 * a failed command */
286 if (usb_pipecontrol(pipe)) { 285 if (usb_pipecontrol(pipe)) {
287 US_DEBUGP("-- stall on control pipe\n"); 286 usb_stor_dbg(us, "-- stall on control pipe\n");
288 return USB_STOR_XFER_STALLED; 287 return USB_STOR_XFER_STALLED;
289 } 288 }
290 289
291 /* for other sorts of endpoint, clear the stall */ 290 /* for other sorts of endpoint, clear the stall */
292 US_DEBUGP("clearing endpoint halt for pipe 0x%x\n", pipe); 291 usb_stor_dbg(us, "clearing endpoint halt for pipe 0x%x\n",
292 pipe);
293 if (usb_stor_clear_halt(us, pipe) < 0) 293 if (usb_stor_clear_halt(us, pipe) < 0)
294 return USB_STOR_XFER_ERROR; 294 return USB_STOR_XFER_ERROR;
295 return USB_STOR_XFER_STALLED; 295 return USB_STOR_XFER_STALLED;
296 296
297 /* babble - the device tried to send more than we wanted to read */ 297 /* babble - the device tried to send more than we wanted to read */
298 case -EOVERFLOW: 298 case -EOVERFLOW:
299 US_DEBUGP("-- babble\n"); 299 usb_stor_dbg(us, "-- babble\n");
300 return USB_STOR_XFER_LONG; 300 return USB_STOR_XFER_LONG;
301 301
302 /* the transfer was cancelled by abort, disconnect, or timeout */ 302 /* the transfer was cancelled by abort, disconnect, or timeout */
303 case -ECONNRESET: 303 case -ECONNRESET:
304 US_DEBUGP("-- transfer cancelled\n"); 304 usb_stor_dbg(us, "-- transfer cancelled\n");
305 return USB_STOR_XFER_ERROR; 305 return USB_STOR_XFER_ERROR;
306 306
307 /* short scatter-gather read transfer */ 307 /* short scatter-gather read transfer */
308 case -EREMOTEIO: 308 case -EREMOTEIO:
309 US_DEBUGP("-- short read transfer\n"); 309 usb_stor_dbg(us, "-- short read transfer\n");
310 return USB_STOR_XFER_SHORT; 310 return USB_STOR_XFER_SHORT;
311 311
312 /* abort or disconnect in progress */ 312 /* abort or disconnect in progress */
313 case -EIO: 313 case -EIO:
314 US_DEBUGP("-- abort or disconnect in progress\n"); 314 usb_stor_dbg(us, "-- abort or disconnect in progress\n");
315 return USB_STOR_XFER_ERROR; 315 return USB_STOR_XFER_ERROR;
316 316
317 /* the catch-all error case */ 317 /* the catch-all error case */
318 default: 318 default:
319 US_DEBUGP("-- unknown error\n"); 319 usb_stor_dbg(us, "-- unknown error\n");
320 return USB_STOR_XFER_ERROR; 320 return USB_STOR_XFER_ERROR;
321 } 321 }
322} 322}
@@ -331,9 +331,8 @@ int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
331{ 331{
332 int result; 332 int result;
333 333
334 US_DEBUGP("%s: rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n", 334 usb_stor_dbg(us, "rq=%02x rqtype=%02x value=%04x index=%02x len=%u\n",
335 __func__, request, requesttype, 335 request, requesttype, value, index, size);
336 value, index, size);
337 336
338 /* fill in the devrequest structure */ 337 /* fill in the devrequest structure */
339 us->cr->bRequestType = requesttype; 338 us->cr->bRequestType = requesttype;
@@ -367,7 +366,7 @@ static int usb_stor_intr_transfer(struct us_data *us, void *buf,
367 unsigned int pipe = us->recv_intr_pipe; 366 unsigned int pipe = us->recv_intr_pipe;
368 unsigned int maxp; 367 unsigned int maxp;
369 368
370 US_DEBUGP("%s: xfer %u bytes\n", __func__, length); 369 usb_stor_dbg(us, "xfer %u bytes\n", length);
371 370
372 /* calculate the max packet size */ 371 /* calculate the max packet size */
373 maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe)); 372 maxp = usb_maxpacket(us->pusb_dev, pipe, usb_pipeout(pipe));
@@ -394,7 +393,7 @@ int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
394{ 393{
395 int result; 394 int result;
396 395
397 US_DEBUGP("%s: xfer %u bytes\n", __func__, length); 396 usb_stor_dbg(us, "xfer %u bytes\n", length);
398 397
399 /* fill and submit the URB */ 398 /* fill and submit the URB */
400 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length, 399 usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length,
@@ -426,12 +425,11 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
426 return USB_STOR_XFER_ERROR; 425 return USB_STOR_XFER_ERROR;
427 426
428 /* initialize the scatter-gather request block */ 427 /* initialize the scatter-gather request block */
429 US_DEBUGP("%s: xfer %u bytes, %d entries\n", __func__, 428 usb_stor_dbg(us, "xfer %u bytes, %d entries\n", length, num_sg);
430 length, num_sg);
431 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0, 429 result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0,
432 sg, num_sg, length, GFP_NOIO); 430 sg, num_sg, length, GFP_NOIO);
433 if (result) { 431 if (result) {
434 US_DEBUGP("usb_sg_init returned %d\n", result); 432 usb_stor_dbg(us, "usb_sg_init returned %d\n", result);
435 return USB_STOR_XFER_ERROR; 433 return USB_STOR_XFER_ERROR;
436 } 434 }
437 435
@@ -444,7 +442,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe,
444 442
445 /* cancel the request, if it hasn't been cancelled already */ 443 /* cancel the request, if it hasn't been cancelled already */
446 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) { 444 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
447 US_DEBUGP("-- cancelling sg request\n"); 445 usb_stor_dbg(us, "-- cancelling sg request\n");
448 usb_sg_cancel(&us->current_sg); 446 usb_sg_cancel(&us->current_sg);
449 } 447 }
450 } 448 }
@@ -609,14 +607,14 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
609 * short-circuit all other processing 607 * short-circuit all other processing
610 */ 608 */
611 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { 609 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
612 US_DEBUGP("-- command was aborted\n"); 610 usb_stor_dbg(us, "-- command was aborted\n");
613 srb->result = DID_ABORT << 16; 611 srb->result = DID_ABORT << 16;
614 goto Handle_Errors; 612 goto Handle_Errors;
615 } 613 }
616 614
617 /* if there is a transport error, reset and don't auto-sense */ 615 /* if there is a transport error, reset and don't auto-sense */
618 if (result == USB_STOR_TRANSPORT_ERROR) { 616 if (result == USB_STOR_TRANSPORT_ERROR) {
619 US_DEBUGP("-- transport indicates error, resetting\n"); 617 usb_stor_dbg(us, "-- transport indicates error, resetting\n");
620 srb->result = DID_ERROR << 16; 618 srb->result = DID_ERROR << 16;
621 goto Handle_Errors; 619 goto Handle_Errors;
622 } 620 }
@@ -645,7 +643,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
645 */ 643 */
646 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) && 644 if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) &&
647 srb->sc_data_direction != DMA_FROM_DEVICE) { 645 srb->sc_data_direction != DMA_FROM_DEVICE) {
648 US_DEBUGP("-- CB transport device requiring auto-sense\n"); 646 usb_stor_dbg(us, "-- CB transport device requiring auto-sense\n");
649 need_auto_sense = 1; 647 need_auto_sense = 1;
650 } 648 }
651 649
@@ -655,7 +653,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
655 * "failure" and an "error" in the transport mechanism. 653 * "failure" and an "error" in the transport mechanism.
656 */ 654 */
657 if (result == USB_STOR_TRANSPORT_FAILED) { 655 if (result == USB_STOR_TRANSPORT_FAILED) {
658 US_DEBUGP("-- transport indicates command failure\n"); 656 usb_stor_dbg(us, "-- transport indicates command failure\n");
659 need_auto_sense = 1; 657 need_auto_sense = 1;
660 } 658 }
661 659
@@ -670,7 +668,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
670 !(us->fflags & US_FL_SANE_SENSE) && 668 !(us->fflags & US_FL_SANE_SENSE) &&
671 !(us->fflags & US_FL_BAD_SENSE) && 669 !(us->fflags & US_FL_BAD_SENSE) &&
672 !(srb->cmnd[2] & 0x20))) { 670 !(srb->cmnd[2] & 0x20))) {
673 US_DEBUGP("-- SAT supported, increasing auto-sense\n"); 671 usb_stor_dbg(us, "-- SAT supported, increasing auto-sense\n");
674 us->fflags |= US_FL_SANE_SENSE; 672 us->fflags |= US_FL_SANE_SENSE;
675 } 673 }
676 674
@@ -684,7 +682,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
684 (srb->cmnd[0] == MODE_SENSE) || 682 (srb->cmnd[0] == MODE_SENSE) ||
685 (srb->cmnd[0] == LOG_SENSE) || 683 (srb->cmnd[0] == LOG_SENSE) ||
686 (srb->cmnd[0] == MODE_SENSE_10))) { 684 (srb->cmnd[0] == MODE_SENSE_10))) {
687 US_DEBUGP("-- unexpectedly short transfer\n"); 685 usb_stor_dbg(us, "-- unexpectedly short transfer\n");
688 } 686 }
689 687
690 /* Now, if we need to do the auto-sense, let's do it */ 688 /* Now, if we need to do the auto-sense, let's do it */
@@ -700,7 +698,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
700 if (us->fflags & US_FL_SANE_SENSE) 698 if (us->fflags & US_FL_SANE_SENSE)
701 sense_size = ~0; 699 sense_size = ~0;
702Retry_Sense: 700Retry_Sense:
703 US_DEBUGP("Issuing auto-REQUEST_SENSE\n"); 701 usb_stor_dbg(us, "Issuing auto-REQUEST_SENSE\n");
704 702
705 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size); 703 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sense_size);
706 704
@@ -719,7 +717,7 @@ Retry_Sense:
719 scsi_eh_restore_cmnd(srb, &ses); 717 scsi_eh_restore_cmnd(srb, &ses);
720 718
721 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { 719 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
722 US_DEBUGP("-- auto-sense aborted\n"); 720 usb_stor_dbg(us, "-- auto-sense aborted\n");
723 srb->result = DID_ABORT << 16; 721 srb->result = DID_ABORT << 16;
724 722
725 /* If SANE_SENSE caused this problem, disable it */ 723 /* If SANE_SENSE caused this problem, disable it */
@@ -737,7 +735,7 @@ Retry_Sense:
737 */ 735 */
738 if (temp_result == USB_STOR_TRANSPORT_FAILED && 736 if (temp_result == USB_STOR_TRANSPORT_FAILED &&
739 sense_size != US_SENSE_SIZE) { 737 sense_size != US_SENSE_SIZE) {
740 US_DEBUGP("-- auto-sense failure, retry small sense\n"); 738 usb_stor_dbg(us, "-- auto-sense failure, retry small sense\n");
741 sense_size = US_SENSE_SIZE; 739 sense_size = US_SENSE_SIZE;
742 us->fflags &= ~US_FL_SANE_SENSE; 740 us->fflags &= ~US_FL_SANE_SENSE;
743 us->fflags |= US_FL_BAD_SENSE; 741 us->fflags |= US_FL_BAD_SENSE;
@@ -746,7 +744,7 @@ Retry_Sense:
746 744
747 /* Other failures */ 745 /* Other failures */
748 if (temp_result != USB_STOR_TRANSPORT_GOOD) { 746 if (temp_result != USB_STOR_TRANSPORT_GOOD) {
749 US_DEBUGP("-- auto-sense failure\n"); 747 usb_stor_dbg(us, "-- auto-sense failure\n");
750 748
751 /* we skip the reset if this happens to be a 749 /* we skip the reset if this happens to be a
752 * multi-target device, since failure of an 750 * multi-target device, since failure of an
@@ -766,27 +764,28 @@ Retry_Sense:
766 !(us->fflags & US_FL_SANE_SENSE) && 764 !(us->fflags & US_FL_SANE_SENSE) &&
767 !(us->fflags & US_FL_BAD_SENSE) && 765 !(us->fflags & US_FL_BAD_SENSE) &&
768 (srb->sense_buffer[0] & 0x7C) == 0x70) { 766 (srb->sense_buffer[0] & 0x7C) == 0x70) {
769 US_DEBUGP("-- SANE_SENSE support enabled\n"); 767 usb_stor_dbg(us, "-- SANE_SENSE support enabled\n");
770 us->fflags |= US_FL_SANE_SENSE; 768 us->fflags |= US_FL_SANE_SENSE;
771 769
772 /* Indicate to the user that we truncated their sense 770 /* Indicate to the user that we truncated their sense
773 * because we didn't know it supported larger sense. 771 * because we didn't know it supported larger sense.
774 */ 772 */
775 US_DEBUGP("-- Sense data truncated to %i from %i\n", 773 usb_stor_dbg(us, "-- Sense data truncated to %i from %i\n",
776 US_SENSE_SIZE, 774 US_SENSE_SIZE,
777 srb->sense_buffer[7] + 8); 775 srb->sense_buffer[7] + 8);
778 srb->sense_buffer[7] = (US_SENSE_SIZE - 8); 776 srb->sense_buffer[7] = (US_SENSE_SIZE - 8);
779 } 777 }
780 778
781 scsi_normalize_sense(srb->sense_buffer, SCSI_SENSE_BUFFERSIZE, 779 scsi_normalize_sense(srb->sense_buffer, SCSI_SENSE_BUFFERSIZE,
782 &sshdr); 780 &sshdr);
783 781
784 US_DEBUGP("-- Result from auto-sense is %d\n", temp_result); 782 usb_stor_dbg(us, "-- Result from auto-sense is %d\n",
785 US_DEBUGP("-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n", 783 temp_result);
786 sshdr.response_code, sshdr.sense_key, 784 usb_stor_dbg(us, "-- code: 0x%x, key: 0x%x, ASC: 0x%x, ASCQ: 0x%x\n",
787 sshdr.asc, sshdr.ascq); 785 sshdr.response_code, sshdr.sense_key,
786 sshdr.asc, sshdr.ascq);
788#ifdef CONFIG_USB_STORAGE_DEBUG 787#ifdef CONFIG_USB_STORAGE_DEBUG
789 usb_stor_show_sense(sshdr.sense_key, sshdr.asc, sshdr.ascq); 788 usb_stor_show_sense(us, sshdr.sense_key, sshdr.asc, sshdr.ascq);
790#endif 789#endif
791 790
792 /* set the result so the higher layers expect this data */ 791 /* set the result so the higher layers expect this data */
@@ -892,20 +891,18 @@ Retry_Sense:
892/* Stop the current URB transfer */ 891/* Stop the current URB transfer */
893void usb_stor_stop_transport(struct us_data *us) 892void usb_stor_stop_transport(struct us_data *us)
894{ 893{
895 US_DEBUGP("%s called\n", __func__);
896
897 /* If the state machine is blocked waiting for an URB, 894 /* If the state machine is blocked waiting for an URB,
898 * let's wake it up. The test_and_clear_bit() call 895 * let's wake it up. The test_and_clear_bit() call
899 * guarantees that if a URB has just been submitted, 896 * guarantees that if a URB has just been submitted,
900 * it won't be cancelled more than once. */ 897 * it won't be cancelled more than once. */
901 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) { 898 if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) {
902 US_DEBUGP("-- cancelling URB\n"); 899 usb_stor_dbg(us, "-- cancelling URB\n");
903 usb_unlink_urb(us->current_urb); 900 usb_unlink_urb(us->current_urb);
904 } 901 }
905 902
906 /* If we are waiting for a scatter-gather operation, cancel it. */ 903 /* If we are waiting for a scatter-gather operation, cancel it. */
907 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) { 904 if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) {
908 US_DEBUGP("-- cancelling sg request\n"); 905 usb_stor_dbg(us, "-- cancelling sg request\n");
909 usb_sg_cancel(&us->current_sg); 906 usb_sg_cancel(&us->current_sg);
910 } 907 }
911} 908}
@@ -928,7 +925,8 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
928 us->ifnum, srb->cmnd, srb->cmd_len); 925 us->ifnum, srb->cmnd, srb->cmd_len);
929 926
930 /* check the return code for the command */ 927 /* check the return code for the command */
931 US_DEBUGP("Call to usb_stor_ctrl_transfer() returned %d\n", result); 928 usb_stor_dbg(us, "Call to usb_stor_ctrl_transfer() returned %d\n",
929 result);
932 930
933 /* if we stalled the command, it means command failed */ 931 /* if we stalled the command, it means command failed */
934 if (result == USB_STOR_XFER_STALLED) { 932 if (result == USB_STOR_XFER_STALLED) {
@@ -946,7 +944,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
946 pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 944 pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
947 us->recv_bulk_pipe : us->send_bulk_pipe; 945 us->recv_bulk_pipe : us->send_bulk_pipe;
948 result = usb_stor_bulk_srb(us, pipe, srb); 946 result = usb_stor_bulk_srb(us, pipe, srb);
949 US_DEBUGP("CBI data stage result is 0x%x\n", result); 947 usb_stor_dbg(us, "CBI data stage result is 0x%x\n", result);
950 948
951 /* if we stalled the data transfer it means command failed */ 949 /* if we stalled the data transfer it means command failed */
952 if (result == USB_STOR_XFER_STALLED) 950 if (result == USB_STOR_XFER_STALLED)
@@ -964,8 +962,8 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
964 return USB_STOR_TRANSPORT_GOOD; 962 return USB_STOR_TRANSPORT_GOOD;
965 963
966 result = usb_stor_intr_transfer(us, us->iobuf, 2); 964 result = usb_stor_intr_transfer(us, us->iobuf, 2);
967 US_DEBUGP("Got interrupt data (0x%x, 0x%x)\n", 965 usb_stor_dbg(us, "Got interrupt data (0x%x, 0x%x)\n",
968 us->iobuf[0], us->iobuf[1]); 966 us->iobuf[0], us->iobuf[1]);
969 if (result != USB_STOR_XFER_GOOD) 967 if (result != USB_STOR_XFER_GOOD)
970 return USB_STOR_TRANSPORT_ERROR; 968 return USB_STOR_TRANSPORT_ERROR;
971 969
@@ -992,8 +990,8 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
992 * into the first byte -- so if it's non-zero, call it a failure. 990 * into the first byte -- so if it's non-zero, call it a failure.
993 */ 991 */
994 if (us->iobuf[0]) { 992 if (us->iobuf[0]) {
995 US_DEBUGP("CBI IRQ data showed reserved bType 0x%x\n", 993 usb_stor_dbg(us, "CBI IRQ data showed reserved bType 0x%x\n",
996 us->iobuf[0]); 994 us->iobuf[0]);
997 goto Failed; 995 goto Failed;
998 996
999 } 997 }
@@ -1034,8 +1032,8 @@ int usb_stor_Bulk_max_lun(struct us_data *us)
1034 USB_RECIP_INTERFACE, 1032 USB_RECIP_INTERFACE,
1035 0, us->ifnum, us->iobuf, 1, 10*HZ); 1033 0, us->ifnum, us->iobuf, 1, 10*HZ);
1036 1034
1037 US_DEBUGP("GetMaxLUN command result is %d, data is %d\n", 1035 usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
1038 result, us->iobuf[0]); 1036 result, us->iobuf[0]);
1039 1037
1040 /* if we have a successful request, return the result */ 1038 /* if we have a successful request, return the result */
1041 if (result > 0) 1039 if (result > 0)
@@ -1084,14 +1082,14 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1084 memcpy(bcb->CDB, srb->cmnd, bcb->Length); 1082 memcpy(bcb->CDB, srb->cmnd, bcb->Length);
1085 1083
1086 /* send it to out endpoint */ 1084 /* send it to out endpoint */
1087 US_DEBUGP("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n", 1085 usb_stor_dbg(us, "Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n",
1088 le32_to_cpu(bcb->Signature), bcb->Tag, 1086 le32_to_cpu(bcb->Signature), bcb->Tag,
1089 le32_to_cpu(bcb->DataTransferLength), bcb->Flags, 1087 le32_to_cpu(bcb->DataTransferLength), bcb->Flags,
1090 (bcb->Lun >> 4), (bcb->Lun & 0x0F), 1088 (bcb->Lun >> 4), (bcb->Lun & 0x0F),
1091 bcb->Length); 1089 bcb->Length);
1092 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, 1090 result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe,
1093 bcb, cbwlen, NULL); 1091 bcb, cbwlen, NULL);
1094 US_DEBUGP("Bulk command transfer result=%d\n", result); 1092 usb_stor_dbg(us, "Bulk command transfer result=%d\n", result);
1095 if (result != USB_STOR_XFER_GOOD) 1093 if (result != USB_STOR_XFER_GOOD)
1096 return USB_STOR_TRANSPORT_ERROR; 1094 return USB_STOR_TRANSPORT_ERROR;
1097 1095
@@ -1108,7 +1106,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1108 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? 1106 unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ?
1109 us->recv_bulk_pipe : us->send_bulk_pipe; 1107 us->recv_bulk_pipe : us->send_bulk_pipe;
1110 result = usb_stor_bulk_srb(us, pipe, srb); 1108 result = usb_stor_bulk_srb(us, pipe, srb);
1111 US_DEBUGP("Bulk data transfer result 0x%x\n", result); 1109 usb_stor_dbg(us, "Bulk data transfer result 0x%x\n", result);
1112 if (result == USB_STOR_XFER_ERROR) 1110 if (result == USB_STOR_XFER_ERROR)
1113 return USB_STOR_TRANSPORT_ERROR; 1111 return USB_STOR_TRANSPORT_ERROR;
1114 1112
@@ -1127,7 +1125,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1127 */ 1125 */
1128 1126
1129 /* get CSW for device status */ 1127 /* get CSW for device status */
1130 US_DEBUGP("Attempting to get CSW...\n"); 1128 usb_stor_dbg(us, "Attempting to get CSW...\n");
1131 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 1129 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1132 bcs, US_BULK_CS_WRAP_LEN, &cswlen); 1130 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
1133 1131
@@ -1136,7 +1134,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1136 * CSWs. If we encounter such a thing, try to read the CSW again. 1134 * CSWs. If we encounter such a thing, try to read the CSW again.
1137 */ 1135 */
1138 if (result == USB_STOR_XFER_SHORT && cswlen == 0) { 1136 if (result == USB_STOR_XFER_SHORT && cswlen == 0) {
1139 US_DEBUGP("Received 0-length CSW; retrying...\n"); 1137 usb_stor_dbg(us, "Received 0-length CSW; retrying...\n");
1140 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 1138 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1141 bcs, US_BULK_CS_WRAP_LEN, &cswlen); 1139 bcs, US_BULK_CS_WRAP_LEN, &cswlen);
1142 } 1140 }
@@ -1145,24 +1143,24 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1145 if (result == USB_STOR_XFER_STALLED) { 1143 if (result == USB_STOR_XFER_STALLED) {
1146 1144
1147 /* get the status again */ 1145 /* get the status again */
1148 US_DEBUGP("Attempting to get CSW (2nd try)...\n"); 1146 usb_stor_dbg(us, "Attempting to get CSW (2nd try)...\n");
1149 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, 1147 result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe,
1150 bcs, US_BULK_CS_WRAP_LEN, NULL); 1148 bcs, US_BULK_CS_WRAP_LEN, NULL);
1151 } 1149 }
1152 1150
1153 /* if we still have a failure at this point, we're in trouble */ 1151 /* if we still have a failure at this point, we're in trouble */
1154 US_DEBUGP("Bulk status result = %d\n", result); 1152 usb_stor_dbg(us, "Bulk status result = %d\n", result);
1155 if (result != USB_STOR_XFER_GOOD) 1153 if (result != USB_STOR_XFER_GOOD)
1156 return USB_STOR_TRANSPORT_ERROR; 1154 return USB_STOR_TRANSPORT_ERROR;
1157 1155
1158 /* check bulk status */ 1156 /* check bulk status */
1159 residue = le32_to_cpu(bcs->Residue); 1157 residue = le32_to_cpu(bcs->Residue);
1160 US_DEBUGP("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", 1158 usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
1161 le32_to_cpu(bcs->Signature), bcs->Tag, 1159 le32_to_cpu(bcs->Signature), bcs->Tag,
1162 residue, bcs->Status); 1160 residue, bcs->Status);
1163 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) || 1161 if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) ||
1164 bcs->Status > US_BULK_STAT_PHASE) { 1162 bcs->Status > US_BULK_STAT_PHASE) {
1165 US_DEBUGP("Bulk logical error\n"); 1163 usb_stor_dbg(us, "Bulk logical error\n");
1166 return USB_STOR_TRANSPORT_ERROR; 1164 return USB_STOR_TRANSPORT_ERROR;
1167 } 1165 }
1168 1166
@@ -1173,12 +1171,12 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1173 if (!us->bcs_signature) { 1171 if (!us->bcs_signature) {
1174 us->bcs_signature = bcs->Signature; 1172 us->bcs_signature = bcs->Signature;
1175 if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN)) 1173 if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN))
1176 US_DEBUGP("Learnt BCS signature 0x%08X\n", 1174 usb_stor_dbg(us, "Learnt BCS signature 0x%08X\n",
1177 le32_to_cpu(us->bcs_signature)); 1175 le32_to_cpu(us->bcs_signature));
1178 } else if (bcs->Signature != us->bcs_signature) { 1176 } else if (bcs->Signature != us->bcs_signature) {
1179 US_DEBUGP("Signature mismatch: got %08X, expecting %08X\n", 1177 usb_stor_dbg(us, "Signature mismatch: got %08X, expecting %08X\n",
1180 le32_to_cpu(bcs->Signature), 1178 le32_to_cpu(bcs->Signature),
1181 le32_to_cpu(us->bcs_signature)); 1179 le32_to_cpu(us->bcs_signature));
1182 return USB_STOR_TRANSPORT_ERROR; 1180 return USB_STOR_TRANSPORT_ERROR;
1183 } 1181 }
1184 1182
@@ -1255,7 +1253,7 @@ static int usb_stor_reset_common(struct us_data *us,
1255 int result2; 1253 int result2;
1256 1254
1257 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { 1255 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1258 US_DEBUGP("No reset during disconnect\n"); 1256 usb_stor_dbg(us, "No reset during disconnect\n");
1259 return -EIO; 1257 return -EIO;
1260 } 1258 }
1261 1259
@@ -1263,7 +1261,7 @@ static int usb_stor_reset_common(struct us_data *us,
1263 request, requesttype, value, index, data, size, 1261 request, requesttype, value, index, data, size,
1264 5*HZ); 1262 5*HZ);
1265 if (result < 0) { 1263 if (result < 0) {
1266 US_DEBUGP("Soft reset failed: %d\n", result); 1264 usb_stor_dbg(us, "Soft reset failed: %d\n", result);
1267 return result; 1265 return result;
1268 } 1266 }
1269 1267
@@ -1273,23 +1271,23 @@ static int usb_stor_reset_common(struct us_data *us,
1273 test_bit(US_FLIDX_DISCONNECTING, &us->dflags), 1271 test_bit(US_FLIDX_DISCONNECTING, &us->dflags),
1274 HZ*6); 1272 HZ*6);
1275 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { 1273 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1276 US_DEBUGP("Reset interrupted by disconnect\n"); 1274 usb_stor_dbg(us, "Reset interrupted by disconnect\n");
1277 return -EIO; 1275 return -EIO;
1278 } 1276 }
1279 1277
1280 US_DEBUGP("Soft reset: clearing bulk-in endpoint halt\n"); 1278 usb_stor_dbg(us, "Soft reset: clearing bulk-in endpoint halt\n");
1281 result = usb_stor_clear_halt(us, us->recv_bulk_pipe); 1279 result = usb_stor_clear_halt(us, us->recv_bulk_pipe);
1282 1280
1283 US_DEBUGP("Soft reset: clearing bulk-out endpoint halt\n"); 1281 usb_stor_dbg(us, "Soft reset: clearing bulk-out endpoint halt\n");
1284 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); 1282 result2 = usb_stor_clear_halt(us, us->send_bulk_pipe);
1285 1283
1286 /* return a result code based on the result of the clear-halts */ 1284 /* return a result code based on the result of the clear-halts */
1287 if (result >= 0) 1285 if (result >= 0)
1288 result = result2; 1286 result = result2;
1289 if (result < 0) 1287 if (result < 0)
1290 US_DEBUGP("Soft reset failed\n"); 1288 usb_stor_dbg(us, "Soft reset failed\n");
1291 else 1289 else
1292 US_DEBUGP("Soft reset done\n"); 1290 usb_stor_dbg(us, "Soft reset done\n");
1293 return result; 1291 return result;
1294} 1292}
1295 1293
@@ -1299,8 +1297,6 @@ static int usb_stor_reset_common(struct us_data *us,
1299 1297
1300int usb_stor_CB_reset(struct us_data *us) 1298int usb_stor_CB_reset(struct us_data *us)
1301{ 1299{
1302 US_DEBUGP("%s called\n", __func__);
1303
1304 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE); 1300 memset(us->iobuf, 0xFF, CB_RESET_CMD_SIZE);
1305 us->iobuf[0] = SEND_DIAGNOSTIC; 1301 us->iobuf[0] = SEND_DIAGNOSTIC;
1306 us->iobuf[1] = 4; 1302 us->iobuf[1] = 4;
@@ -1315,8 +1311,6 @@ EXPORT_SYMBOL_GPL(usb_stor_CB_reset);
1315 */ 1311 */
1316int usb_stor_Bulk_reset(struct us_data *us) 1312int usb_stor_Bulk_reset(struct us_data *us)
1317{ 1313{
1318 US_DEBUGP("%s called\n", __func__);
1319
1320 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST, 1314 return usb_stor_reset_common(us, US_BULK_RESET_REQUEST,
1321 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1315 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1322 0, us->ifnum, NULL, 0); 1316 0, us->ifnum, NULL, 0);
@@ -1336,16 +1330,17 @@ int usb_stor_port_reset(struct us_data *us)
1336 1330
1337 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); 1331 result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf);
1338 if (result < 0) 1332 if (result < 0)
1339 US_DEBUGP("unable to lock device for reset: %d\n", result); 1333 usb_stor_dbg(us, "unable to lock device for reset: %d\n",
1334 result);
1340 else { 1335 else {
1341 /* Were we disconnected while waiting for the lock? */ 1336 /* Were we disconnected while waiting for the lock? */
1342 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { 1337 if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) {
1343 result = -EIO; 1338 result = -EIO;
1344 US_DEBUGP("No reset during disconnect\n"); 1339 usb_stor_dbg(us, "No reset during disconnect\n");
1345 } else { 1340 } else {
1346 result = usb_reset_device(us->pusb_dev); 1341 result = usb_reset_device(us->pusb_dev);
1347 US_DEBUGP("usb_reset_device returns %d\n", 1342 usb_stor_dbg(us, "usb_reset_device returns %d\n",
1348 result); 1343 result);
1349 } 1344 }
1350 usb_unlock_device(us->pusb_dev); 1345 usb_unlock_device(us->pusb_dev);
1351 } 1346 }
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index d6bee407af02..5c4fe0749af1 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -183,7 +183,6 @@ int usb_stor_suspend(struct usb_interface *iface, pm_message_t message)
183 /* Wait until no command is running */ 183 /* Wait until no command is running */
184 mutex_lock(&us->dev_mutex); 184 mutex_lock(&us->dev_mutex);
185 185
186 US_DEBUGP("%s\n", __func__);
187 if (us->suspend_resume_hook) 186 if (us->suspend_resume_hook)
188 (us->suspend_resume_hook)(us, US_SUSPEND); 187 (us->suspend_resume_hook)(us, US_SUSPEND);
189 188
@@ -201,7 +200,6 @@ int usb_stor_resume(struct usb_interface *iface)
201 200
202 mutex_lock(&us->dev_mutex); 201 mutex_lock(&us->dev_mutex);
203 202
204 US_DEBUGP("%s\n", __func__);
205 if (us->suspend_resume_hook) 203 if (us->suspend_resume_hook)
206 (us->suspend_resume_hook)(us, US_RESUME); 204 (us->suspend_resume_hook)(us, US_RESUME);
207 205
@@ -214,8 +212,6 @@ int usb_stor_reset_resume(struct usb_interface *iface)
214{ 212{
215 struct us_data *us = usb_get_intfdata(iface); 213 struct us_data *us = usb_get_intfdata(iface);
216 214
217 US_DEBUGP("%s\n", __func__);
218
219 /* Report the reset to the SCSI core */ 215 /* Report the reset to the SCSI core */
220 usb_stor_report_bus_reset(us); 216 usb_stor_report_bus_reset(us);
221 217
@@ -236,8 +232,6 @@ int usb_stor_pre_reset(struct usb_interface *iface)
236{ 232{
237 struct us_data *us = usb_get_intfdata(iface); 233 struct us_data *us = usb_get_intfdata(iface);
238 234
239 US_DEBUGP("%s\n", __func__);
240
241 /* Make sure no command runs during the reset */ 235 /* Make sure no command runs during the reset */
242 mutex_lock(&us->dev_mutex); 236 mutex_lock(&us->dev_mutex);
243 return 0; 237 return 0;
@@ -248,8 +242,6 @@ int usb_stor_post_reset(struct usb_interface *iface)
248{ 242{
249 struct us_data *us = usb_get_intfdata(iface); 243 struct us_data *us = usb_get_intfdata(iface);
250 244
251 US_DEBUGP("%s\n", __func__);
252
253 /* Report the reset to the SCSI core */ 245 /* Report the reset to the SCSI core */
254 usb_stor_report_bus_reset(us); 246 usb_stor_report_bus_reset(us);
255 247
@@ -311,11 +303,11 @@ static int usb_stor_control_thread(void * __us)
311 struct Scsi_Host *host = us_to_host(us); 303 struct Scsi_Host *host = us_to_host(us);
312 304
313 for (;;) { 305 for (;;) {
314 US_DEBUGP("*** thread sleeping.\n"); 306 usb_stor_dbg(us, "*** thread sleeping\n");
315 if (wait_for_completion_interruptible(&us->cmnd_ready)) 307 if (wait_for_completion_interruptible(&us->cmnd_ready))
316 break; 308 break;
317 309
318 US_DEBUGP("*** thread awakened.\n"); 310 usb_stor_dbg(us, "*** thread awakened\n");
319 311
320 /* lock the device pointers */ 312 /* lock the device pointers */
321 mutex_lock(&(us->dev_mutex)); 313 mutex_lock(&(us->dev_mutex));
@@ -327,7 +319,7 @@ static int usb_stor_control_thread(void * __us)
327 if (us->srb == NULL) { 319 if (us->srb == NULL) {
328 scsi_unlock(host); 320 scsi_unlock(host);
329 mutex_unlock(&us->dev_mutex); 321 mutex_unlock(&us->dev_mutex);
330 US_DEBUGP("-- exiting\n"); 322 usb_stor_dbg(us, "-- exiting\n");
331 break; 323 break;
332 } 324 }
333 325
@@ -343,7 +335,7 @@ static int usb_stor_control_thread(void * __us)
343 * is UNKNOWN 335 * is UNKNOWN
344 */ 336 */
345 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) { 337 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) {
346 US_DEBUGP("UNKNOWN data direction\n"); 338 usb_stor_dbg(us, "UNKNOWN data direction\n");
347 us->srb->result = DID_ERROR << 16; 339 us->srb->result = DID_ERROR << 16;
348 } 340 }
349 341
@@ -352,14 +344,14 @@ static int usb_stor_control_thread(void * __us)
352 */ 344 */
353 else if (us->srb->device->id && 345 else if (us->srb->device->id &&
354 !(us->fflags & US_FL_SCM_MULT_TARG)) { 346 !(us->fflags & US_FL_SCM_MULT_TARG)) {
355 US_DEBUGP("Bad target number (%d:%d)\n", 347 usb_stor_dbg(us, "Bad target number (%d:%d)\n",
356 us->srb->device->id, us->srb->device->lun); 348 us->srb->device->id, us->srb->device->lun);
357 us->srb->result = DID_BAD_TARGET << 16; 349 us->srb->result = DID_BAD_TARGET << 16;
358 } 350 }
359 351
360 else if (us->srb->device->lun > us->max_lun) { 352 else if (us->srb->device->lun > us->max_lun) {
361 US_DEBUGP("Bad LUN (%d:%d)\n", 353 usb_stor_dbg(us, "Bad LUN (%d:%d)\n",
362 us->srb->device->id, us->srb->device->lun); 354 us->srb->device->id, us->srb->device->lun);
363 us->srb->result = DID_BAD_TARGET << 16; 355 us->srb->result = DID_BAD_TARGET << 16;
364 } 356 }
365 357
@@ -371,14 +363,14 @@ static int usb_stor_control_thread(void * __us)
371 0x00, 0x80, 0x02, 0x02, 363 0x00, 0x80, 0x02, 0x02,
372 0x1F, 0x00, 0x00, 0x00}; 364 0x1F, 0x00, 0x00, 0x00};
373 365
374 US_DEBUGP("Faking INQUIRY command\n"); 366 usb_stor_dbg(us, "Faking INQUIRY command\n");
375 fill_inquiry_response(us, data_ptr, 36); 367 fill_inquiry_response(us, data_ptr, 36);
376 us->srb->result = SAM_STAT_GOOD; 368 us->srb->result = SAM_STAT_GOOD;
377 } 369 }
378 370
379 /* we've got a command, let's do it! */ 371 /* we've got a command, let's do it! */
380 else { 372 else {
381 US_DEBUG(usb_stor_show_command(us->srb)); 373 US_DEBUG(usb_stor_show_command(us, us->srb));
382 us->proto_handler(us->srb, us); 374 us->proto_handler(us->srb, us);
383 usb_mark_last_busy(us->pusb_dev); 375 usb_mark_last_busy(us->pusb_dev);
384 } 376 }
@@ -388,12 +380,12 @@ static int usb_stor_control_thread(void * __us)
388 380
389 /* indicate that the command is done */ 381 /* indicate that the command is done */
390 if (us->srb->result != DID_ABORT << 16) { 382 if (us->srb->result != DID_ABORT << 16) {
391 US_DEBUGP("scsi cmd done, result=0x%x\n", 383 usb_stor_dbg(us, "scsi cmd done, result=0x%x\n",
392 us->srb->result); 384 us->srb->result);
393 us->srb->scsi_done(us->srb); 385 us->srb->scsi_done(us->srb);
394 } else { 386 } else {
395SkipForAbort: 387SkipForAbort:
396 US_DEBUGP("scsi command aborted\n"); 388 usb_stor_dbg(us, "scsi command aborted\n");
397 } 389 }
398 390
399 /* If an abort request was received we need to signal that 391 /* If an abort request was received we need to signal that
@@ -435,34 +427,30 @@ SkipForAbort:
435/* Associate our private data with the USB device */ 427/* Associate our private data with the USB device */
436static int associate_dev(struct us_data *us, struct usb_interface *intf) 428static int associate_dev(struct us_data *us, struct usb_interface *intf)
437{ 429{
438 US_DEBUGP("-- %s\n", __func__);
439
440 /* Fill in the device-related fields */ 430 /* Fill in the device-related fields */
441 us->pusb_dev = interface_to_usbdev(intf); 431 us->pusb_dev = interface_to_usbdev(intf);
442 us->pusb_intf = intf; 432 us->pusb_intf = intf;
443 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 433 us->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
444 US_DEBUGP("Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n", 434 usb_stor_dbg(us, "Vendor: 0x%04x, Product: 0x%04x, Revision: 0x%04x\n",
445 le16_to_cpu(us->pusb_dev->descriptor.idVendor), 435 le16_to_cpu(us->pusb_dev->descriptor.idVendor),
446 le16_to_cpu(us->pusb_dev->descriptor.idProduct), 436 le16_to_cpu(us->pusb_dev->descriptor.idProduct),
447 le16_to_cpu(us->pusb_dev->descriptor.bcdDevice)); 437 le16_to_cpu(us->pusb_dev->descriptor.bcdDevice));
448 US_DEBUGP("Interface Subclass: 0x%02x, Protocol: 0x%02x\n", 438 usb_stor_dbg(us, "Interface Subclass: 0x%02x, Protocol: 0x%02x\n",
449 intf->cur_altsetting->desc.bInterfaceSubClass, 439 intf->cur_altsetting->desc.bInterfaceSubClass,
450 intf->cur_altsetting->desc.bInterfaceProtocol); 440 intf->cur_altsetting->desc.bInterfaceProtocol);
451 441
452 /* Store our private data in the interface */ 442 /* Store our private data in the interface */
453 usb_set_intfdata(intf, us); 443 usb_set_intfdata(intf, us);
454 444
455 /* Allocate the control/setup and DMA-mapped buffers */ 445 /* Allocate the control/setup and DMA-mapped buffers */
456 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL); 446 us->cr = kmalloc(sizeof(*us->cr), GFP_KERNEL);
457 if (!us->cr) { 447 if (!us->cr)
458 US_DEBUGP("usb_ctrlrequest allocation failed\n");
459 return -ENOMEM; 448 return -ENOMEM;
460 }
461 449
462 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, 450 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE,
463 GFP_KERNEL, &us->iobuf_dma); 451 GFP_KERNEL, &us->iobuf_dma);
464 if (!us->iobuf) { 452 if (!us->iobuf) {
465 US_DEBUGP("I/O buffer allocation failed\n"); 453 usb_stor_dbg(us, "I/O buffer allocation failed\n");
466 return -ENOMEM; 454 return -ENOMEM;
467 } 455 }
468 return 0; 456 return 0;
@@ -738,7 +726,7 @@ static int get_pipes(struct us_data *us)
738 } 726 }
739 727
740 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { 728 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) {
741 US_DEBUGP("Endpoint sanity check failed! Rejecting dev.\n"); 729 usb_stor_dbg(us, "Endpoint sanity check failed! Rejecting dev.\n");
742 return -EIO; 730 return -EIO;
743 } 731 }
744 732
@@ -765,7 +753,7 @@ static int usb_stor_acquire_resources(struct us_data *us)
765 753
766 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 754 us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
767 if (!us->current_urb) { 755 if (!us->current_urb) {
768 US_DEBUGP("URB allocation failed\n"); 756 usb_stor_dbg(us, "URB allocation failed\n");
769 return -ENOMEM; 757 return -ENOMEM;
770 } 758 }
771 759
@@ -792,20 +780,18 @@ static int usb_stor_acquire_resources(struct us_data *us)
792/* Release all our dynamic resources */ 780/* Release all our dynamic resources */
793static void usb_stor_release_resources(struct us_data *us) 781static void usb_stor_release_resources(struct us_data *us)
794{ 782{
795 US_DEBUGP("-- %s\n", __func__);
796
797 /* Tell the control thread to exit. The SCSI host must 783 /* Tell the control thread to exit. The SCSI host must
798 * already have been removed and the DISCONNECTING flag set 784 * already have been removed and the DISCONNECTING flag set
799 * so that we won't accept any more commands. 785 * so that we won't accept any more commands.
800 */ 786 */
801 US_DEBUGP("-- sending exit command to thread\n"); 787 usb_stor_dbg(us, "-- sending exit command to thread\n");
802 complete(&us->cmnd_ready); 788 complete(&us->cmnd_ready);
803 if (us->ctl_thread) 789 if (us->ctl_thread)
804 kthread_stop(us->ctl_thread); 790 kthread_stop(us->ctl_thread);
805 791
806 /* Call the destructor routine, if it exists */ 792 /* Call the destructor routine, if it exists */
807 if (us->extra_destructor) { 793 if (us->extra_destructor) {
808 US_DEBUGP("-- calling extra_destructor()\n"); 794 usb_stor_dbg(us, "-- calling extra_destructor()\n");
809 us->extra_destructor(us->extra); 795 us->extra_destructor(us->extra);
810 } 796 }
811 797
@@ -817,8 +803,6 @@ static void usb_stor_release_resources(struct us_data *us)
817/* Dissociate from the USB device */ 803/* Dissociate from the USB device */
818static void dissociate_dev(struct us_data *us) 804static void dissociate_dev(struct us_data *us)
819{ 805{
820 US_DEBUGP("-- %s\n", __func__);
821
822 /* Free the buffers */ 806 /* Free the buffers */
823 kfree(us->cr); 807 kfree(us->cr);
824 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma); 808 usb_free_coherent(us->pusb_dev, US_IOBUF_SIZE, us->iobuf, us->iobuf_dma);
@@ -918,7 +902,7 @@ int usb_stor_probe1(struct us_data **pus,
918 struct us_data *us; 902 struct us_data *us;
919 int result; 903 int result;
920 904
921 US_DEBUGP("USB Mass Storage device detected\n"); 905 dev_info(&intf->dev, "USB Mass Storage device detected\n");
922 906
923 /* 907 /*
924 * Ask the SCSI layer to allocate a host structure, with extra 908 * Ask the SCSI layer to allocate a host structure, with extra
@@ -926,8 +910,7 @@ int usb_stor_probe1(struct us_data **pus,
926 */ 910 */
927 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); 911 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
928 if (!host) { 912 if (!host) {
929 dev_warn(&intf->dev, 913 dev_warn(&intf->dev, "Unable to allocate the scsi host\n");
930 "Unable to allocate the scsi host\n");
931 return -ENOMEM; 914 return -ENOMEM;
932 } 915 }
933 916
@@ -964,7 +947,7 @@ int usb_stor_probe1(struct us_data **pus,
964 return 0; 947 return 0;
965 948
966BadDevice: 949BadDevice:
967 US_DEBUGP("storage_probe() failed\n"); 950 usb_stor_dbg(us, "storage_probe() failed\n");
968 release_everything(us); 951 release_everything(us);
969 return result; 952 return result;
970} 953}
@@ -981,8 +964,8 @@ int usb_stor_probe2(struct us_data *us)
981 result = -ENXIO; 964 result = -ENXIO;
982 goto BadDevice; 965 goto BadDevice;
983 } 966 }
984 US_DEBUGP("Transport: %s\n", us->transport_name); 967 usb_stor_dbg(us, "Transport: %s\n", us->transport_name);
985 US_DEBUGP("Protocol: %s\n", us->protocol_name); 968 usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name);
986 969
987 /* fix for single-lun devices */ 970 /* fix for single-lun devices */
988 if (us->fflags & US_FL_SINGLE_LUN) 971 if (us->fflags & US_FL_SINGLE_LUN)
@@ -1028,7 +1011,7 @@ int usb_stor_probe2(struct us_data *us)
1028 1011
1029 /* We come here if there are any problems */ 1012 /* We come here if there are any problems */
1030BadDevice: 1013BadDevice:
1031 US_DEBUGP("storage_probe() failed\n"); 1014 usb_stor_dbg(us, "storage_probe() failed\n");
1032 release_everything(us); 1015 release_everything(us);
1033 return result; 1016 return result;
1034} 1017}
@@ -1039,7 +1022,6 @@ void usb_stor_disconnect(struct usb_interface *intf)
1039{ 1022{
1040 struct us_data *us = usb_get_intfdata(intf); 1023 struct us_data *us = usb_get_intfdata(intf);
1041 1024
1042 US_DEBUGP("storage_disconnect() called\n");
1043 quiesce_and_remove_host(us); 1025 quiesce_and_remove_host(us);
1044 release_everything(us); 1026 release_everything(us);
1045} 1027}
@@ -1075,8 +1057,7 @@ static int storage_probe(struct usb_interface *intf,
1075 } else { 1057 } else {
1076 unusual_dev = &for_dynamic_ids; 1058 unusual_dev = &for_dynamic_ids;
1077 1059
1078 US_DEBUGP("%s %s 0x%04x 0x%04x\n", "Use Bulk-Only transport", 1060 dev_dbg(&intf->dev, "Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",
1079 "with the Transparent SCSI protocol for dynamic id:",
1080 id->idVendor, id->idProduct); 1061 id->idVendor, id->idProduct);
1081 } 1062 }
1082 1063
@@ -1090,10 +1071,6 @@ static int storage_probe(struct usb_interface *intf,
1090 return result; 1071 return result;
1091} 1072}
1092 1073
1093/***********************************************************************
1094 * Initialization and registration
1095 ***********************************************************************/
1096
1097static struct usb_driver usb_storage_driver = { 1074static struct usb_driver usb_storage_driver = {
1098 .name = "usb-storage", 1075 .name = "usb-storage",
1099 .probe = storage_probe, 1076 .probe = storage_probe,
@@ -1108,30 +1085,4 @@ static struct usb_driver usb_storage_driver = {
1108 .soft_unbind = 1, 1085 .soft_unbind = 1,
1109}; 1086};
1110 1087
1111static int __init usb_stor_init(void) 1088module_usb_driver(usb_storage_driver);
1112{
1113 int retval;
1114
1115 pr_info("Initializing USB Mass Storage driver...\n");
1116
1117 /* register the driver, return usb_register return code if error */
1118 retval = usb_register(&usb_storage_driver);
1119 if (retval == 0)
1120 pr_info("USB Mass Storage support registered.\n");
1121 return retval;
1122}
1123
1124static void __exit usb_stor_exit(void)
1125{
1126 US_DEBUGP("usb_stor_exit() called\n");
1127
1128 /* Deregister the driver
1129 * This will cause disconnect() to be called for each
1130 * attached unit
1131 */
1132 US_DEBUGP("-- calling usb_deregister()\n");
1133 usb_deregister(&usb_storage_driver) ;
1134}
1135
1136module_init(usb_stor_init);
1137module_exit(usb_stor_exit);
diff --git a/drivers/usb/usb-common.c b/drivers/usb/usb-common.c
index d29503e954ab..0db0a919d72b 100644
--- a/drivers/usb/usb-common.c
+++ b/drivers/usb/usb-common.c
@@ -14,6 +14,32 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/usb/ch9.h> 16#include <linux/usb/ch9.h>
17#include <linux/usb/otg.h>
18
19const char *usb_otg_state_string(enum usb_otg_state state)
20{
21 static const char *const names[] = {
22 [OTG_STATE_A_IDLE] = "a_idle",
23 [OTG_STATE_A_WAIT_VRISE] = "a_wait_vrise",
24 [OTG_STATE_A_WAIT_BCON] = "a_wait_bcon",
25 [OTG_STATE_A_HOST] = "a_host",
26 [OTG_STATE_A_SUSPEND] = "a_suspend",
27 [OTG_STATE_A_PERIPHERAL] = "a_peripheral",
28 [OTG_STATE_A_WAIT_VFALL] = "a_wait_vfall",
29 [OTG_STATE_A_VBUS_ERR] = "a_vbus_err",
30 [OTG_STATE_B_IDLE] = "b_idle",
31 [OTG_STATE_B_SRP_INIT] = "b_srp_init",
32 [OTG_STATE_B_PERIPHERAL] = "b_peripheral",
33 [OTG_STATE_B_WAIT_ACON] = "b_wait_acon",
34 [OTG_STATE_B_HOST] = "b_host",
35 };
36
37 if (state < 0 || state >= ARRAY_SIZE(names))
38 return "UNDEFINED";
39
40 return names[state];
41}
42EXPORT_SYMBOL_GPL(usb_otg_state_string);
17 43
18const char *usb_speed_string(enum usb_device_speed speed) 44const char *usb_speed_string(enum usb_device_speed speed)
19{ 45{
@@ -32,4 +58,25 @@ const char *usb_speed_string(enum usb_device_speed speed)
32} 58}
33EXPORT_SYMBOL_GPL(usb_speed_string); 59EXPORT_SYMBOL_GPL(usb_speed_string);
34 60
61const char *usb_state_string(enum usb_device_state state)
62{
63 static const char *const names[] = {
64 [USB_STATE_NOTATTACHED] = "not attached",
65 [USB_STATE_ATTACHED] = "attached",
66 [USB_STATE_POWERED] = "powered",
67 [USB_STATE_RECONNECTING] = "reconnecting",
68 [USB_STATE_UNAUTHENTICATED] = "unauthenticated",
69 [USB_STATE_DEFAULT] = "default",
70 [USB_STATE_ADDRESS] = "addresssed",
71 [USB_STATE_CONFIGURED] = "configured",
72 [USB_STATE_SUSPENDED] = "suspended",
73 };
74
75 if (state < 0 || state >= ARRAY_SIZE(names))
76 return "UNKNOWN";
77
78 return names[state];
79}
80EXPORT_SYMBOL_GPL(usb_state_string);
81
35MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index ce310170829f..7ed3b039dbe8 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -61,11 +61,10 @@ struct usb_skel {
61 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */ 61 __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
62 int errors; /* the last request tanked */ 62 int errors; /* the last request tanked */
63 bool ongoing_read; /* a read is going on */ 63 bool ongoing_read; /* a read is going on */
64 bool processed_urb; /* indicates we haven't processed the urb */
65 spinlock_t err_lock; /* lock for errors */ 64 spinlock_t err_lock; /* lock for errors */
66 struct kref kref; 65 struct kref kref;
67 struct mutex io_mutex; /* synchronize I/O with disconnect */ 66 struct mutex io_mutex; /* synchronize I/O with disconnect */
68 struct completion bulk_in_completion; /* to wait for an ongoing read */ 67 wait_queue_head_t bulk_in_wait; /* to wait for an ongoing read */
69}; 68};
70#define to_skel_dev(d) container_of(d, struct usb_skel, kref) 69#define to_skel_dev(d) container_of(d, struct usb_skel, kref)
71 70
@@ -185,7 +184,7 @@ static void skel_read_bulk_callback(struct urb *urb)
185 dev->ongoing_read = 0; 184 dev->ongoing_read = 0;
186 spin_unlock(&dev->err_lock); 185 spin_unlock(&dev->err_lock);
187 186
188 complete(&dev->bulk_in_completion); 187 wake_up_interruptible(&dev->bulk_in_wait);
189} 188}
190 189
191static int skel_do_read_io(struct usb_skel *dev, size_t count) 190static int skel_do_read_io(struct usb_skel *dev, size_t count)
@@ -206,13 +205,16 @@ static int skel_do_read_io(struct usb_skel *dev, size_t count)
206 dev->ongoing_read = 1; 205 dev->ongoing_read = 1;
207 spin_unlock_irq(&dev->err_lock); 206 spin_unlock_irq(&dev->err_lock);
208 207
208 /* submit bulk in urb, which means no data to deliver */
209 dev->bulk_in_filled = 0;
210 dev->bulk_in_copied = 0;
211
209 /* do it */ 212 /* do it */
210 rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL); 213 rv = usb_submit_urb(dev->bulk_in_urb, GFP_KERNEL);
211 if (rv < 0) { 214 if (rv < 0) {
212 dev_err(&dev->interface->dev, 215 dev_err(&dev->interface->dev,
213 "%s - failed submitting read urb, error %d\n", 216 "%s - failed submitting read urb, error %d\n",
214 __func__, rv); 217 __func__, rv);
215 dev->bulk_in_filled = 0;
216 rv = (rv == -ENOMEM) ? rv : -EIO; 218 rv = (rv == -ENOMEM) ? rv : -EIO;
217 spin_lock_irq(&dev->err_lock); 219 spin_lock_irq(&dev->err_lock);
218 dev->ongoing_read = 0; 220 dev->ongoing_read = 0;
@@ -261,25 +263,9 @@ retry:
261 * IO may take forever 263 * IO may take forever
262 * hence wait in an interruptible state 264 * hence wait in an interruptible state
263 */ 265 */
264 rv = wait_for_completion_interruptible(&dev->bulk_in_completion); 266 rv = wait_event_interruptible(dev->bulk_in_wait, (!dev->ongoing_read));
265 if (rv < 0) 267 if (rv < 0)
266 goto exit; 268 goto exit;
267 /*
268 * by waiting we also semiprocessed the urb
269 * we must finish now
270 */
271 dev->bulk_in_copied = 0;
272 dev->processed_urb = 1;
273 }
274
275 if (!dev->processed_urb) {
276 /*
277 * the URB hasn't been processed
278 * do it now
279 */
280 wait_for_completion(&dev->bulk_in_completion);
281 dev->bulk_in_copied = 0;
282 dev->processed_urb = 1;
283 } 269 }
284 270
285 /* errors must be reported */ 271 /* errors must be reported */
@@ -289,8 +275,6 @@ retry:
289 dev->errors = 0; 275 dev->errors = 0;
290 /* to preserve notifications about reset */ 276 /* to preserve notifications about reset */
291 rv = (rv == -EPIPE) ? rv : -EIO; 277 rv = (rv == -EPIPE) ? rv : -EIO;
292 /* no data to deliver */
293 dev->bulk_in_filled = 0;
294 /* report it */ 278 /* report it */
295 goto exit; 279 goto exit;
296 } 280 }
@@ -526,7 +510,7 @@ static int skel_probe(struct usb_interface *interface,
526 mutex_init(&dev->io_mutex); 510 mutex_init(&dev->io_mutex);
527 spin_lock_init(&dev->err_lock); 511 spin_lock_init(&dev->err_lock);
528 init_usb_anchor(&dev->submitted); 512 init_usb_anchor(&dev->submitted);
529 init_completion(&dev->bulk_in_completion); 513 init_waitqueue_head(&dev->bulk_in_wait);
530 514
531 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 515 dev->udev = usb_get_dev(interface_to_usbdev(interface));
532 dev->interface = interface; 516 dev->interface = interface;
diff --git a/drivers/usb/wusbcore/Kconfig b/drivers/usb/wusbcore/Kconfig
index 8bf19760d447..0e17b966e1b4 100644
--- a/drivers/usb/wusbcore/Kconfig
+++ b/drivers/usb/wusbcore/Kconfig
@@ -3,7 +3,6 @@
3# 3#
4config USB_WUSB 4config USB_WUSB
5 tristate "Enable Wireless USB extensions" 5 tristate "Enable Wireless USB extensions"
6 depends on USB
7 depends on PCI 6 depends on PCI
8 depends on UWB 7 depends on UWB
9 select CRYPTO 8 select CRYPTO
@@ -19,7 +18,6 @@ config USB_WUSB
19 18
20config USB_WUSB_CBAF 19config USB_WUSB_CBAF
21 tristate "Support WUSB Cable Based Association (CBA)" 20 tristate "Support WUSB Cable Based Association (CBA)"
22 depends on USB
23 help 21 help
24 Some WUSB devices support Cable Based Association. It's used to 22 Some WUSB devices support Cable Based Association. It's used to
25 enable the secure communication between the host and the 23 enable the secure communication between the host and the
diff --git a/include/linux/platform_data/dwc3-omap.h b/include/linux/platform_data/dwc3-omap.h
index ada401244e0b..1d36ca874cc8 100644
--- a/include/linux/platform_data/dwc3-omap.h
+++ b/include/linux/platform_data/dwc3-omap.h
@@ -41,7 +41,3 @@ enum dwc3_omap_utmi_mode {
41 DWC3_OMAP_UTMI_MODE_HW, 41 DWC3_OMAP_UTMI_MODE_HW,
42 DWC3_OMAP_UTMI_MODE_SW, 42 DWC3_OMAP_UTMI_MODE_SW,
43}; 43};
44
45struct dwc3_omap_data {
46 enum dwc3_omap_utmi_mode utmi_mode;
47};
diff --git a/include/linux/platform_data/mv_usb.h b/include/linux/platform_data/mv_usb.h
index 944b01dd103e..98b7925f1a2d 100644
--- a/include/linux/platform_data/mv_usb.h
+++ b/include/linux/platform_data/mv_usb.h
@@ -34,8 +34,6 @@ struct mv_usb_addon_irq {
34}; 34};
35 35
36struct mv_usb_platform_data { 36struct mv_usb_platform_data {
37 unsigned int clknum;
38 char **clkname;
39 struct mv_usb_addon_irq *id; /* Only valid for OTG. ID pin change*/ 37 struct mv_usb_addon_irq *id; /* Only valid for OTG. ID pin change*/
40 struct mv_usb_addon_irq *vbus; /* valid for OTG/UDC. VBUS change*/ 38 struct mv_usb_addon_irq *vbus; /* valid for OTG/UDC. VBUS change*/
41 39
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 4d22d0f6167a..a0bee5a28d1a 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -469,14 +469,12 @@ struct usb3_lpm_parameters {
469 * @lpm_capable: device supports LPM 469 * @lpm_capable: device supports LPM
470 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM 470 * @usb2_hw_lpm_capable: device can perform USB2 hardware LPM
471 * @usb2_hw_lpm_enabled: USB2 hardware LPM enabled 471 * @usb2_hw_lpm_enabled: USB2 hardware LPM enabled
472 * @usb3_lpm_enabled: USB3 hardware LPM enabled
472 * @string_langid: language ID for strings 473 * @string_langid: language ID for strings
473 * @product: iProduct string, if present (static) 474 * @product: iProduct string, if present (static)
474 * @manufacturer: iManufacturer string, if present (static) 475 * @manufacturer: iManufacturer string, if present (static)
475 * @serial: iSerialNumber string, if present (static) 476 * @serial: iSerialNumber string, if present (static)
476 * @filelist: usbfs files that are open to this device 477 * @filelist: usbfs files that are open to this device
477 * @usb_classdev: USB class device that was created for usbfs device
478 * access from userspace
479 * @usbfs_dentry: usbfs dentry entry for the device
480 * @maxchild: number of ports if hub 478 * @maxchild: number of ports if hub
481 * @quirks: quirks of the whole device 479 * @quirks: quirks of the whole device
482 * @urbnum: number of URBs submitted for the whole device 480 * @urbnum: number of URBs submitted for the whole device
@@ -619,7 +617,7 @@ static inline bool usb_acpi_power_manageable(struct usb_device *hdev, int index)
619#endif 617#endif
620 618
621/* USB autosuspend and autoresume */ 619/* USB autosuspend and autoresume */
622#ifdef CONFIG_USB_SUSPEND 620#ifdef CONFIG_PM_RUNTIME
623extern void usb_enable_autosuspend(struct usb_device *udev); 621extern void usb_enable_autosuspend(struct usb_device *udev);
624extern void usb_disable_autosuspend(struct usb_device *udev); 622extern void usb_disable_autosuspend(struct usb_device *udev);
625 623
@@ -978,7 +976,12 @@ struct usbdrv_wrap {
978 * the "usbfs" filesystem. This lets devices provide ways to 976 * the "usbfs" filesystem. This lets devices provide ways to
979 * expose information to user space regardless of where they 977 * expose information to user space regardless of where they
980 * do (or don't) show up otherwise in the filesystem. 978 * do (or don't) show up otherwise in the filesystem.
981 * @suspend: Called when the device is going to be suspended by the system. 979 * @suspend: Called when the device is going to be suspended by the
980 * system either from system sleep or runtime suspend context. The
981 * return value will be ignored in system sleep context, so do NOT
982 * try to continue using the device if suspend fails in this case.
983 * Instead, let the resume or reset-resume routine recover from
984 * the failure.
982 * @resume: Called when the device is being resumed by the system. 985 * @resume: Called when the device is being resumed by the system.
983 * @reset_resume: Called when the suspended device has been reset instead 986 * @reset_resume: Called when the suspended device has been reset instead
984 * of being resumed. 987 * of being resumed.
diff --git a/include/linux/usb/cdc-wdm.h b/include/linux/usb/cdc-wdm.h
index 719c332620fa..0b3f4295c025 100644
--- a/include/linux/usb/cdc-wdm.h
+++ b/include/linux/usb/cdc-wdm.h
@@ -11,6 +11,8 @@
11#ifndef __LINUX_USB_CDC_WDM_H 11#ifndef __LINUX_USB_CDC_WDM_H
12#define __LINUX_USB_CDC_WDM_H 12#define __LINUX_USB_CDC_WDM_H
13 13
14#include <uapi/linux/usb/cdc-wdm.h>
15
14extern struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf, 16extern struct usb_driver *usb_cdc_wdm_register(struct usb_interface *intf,
15 struct usb_endpoint_descriptor *ep, 17 struct usb_endpoint_descriptor *ep,
16 int bufsize, 18 int bufsize,
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 9c210f2283df..27603bcbb9b9 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -43,4 +43,13 @@
43 */ 43 */
44extern const char *usb_speed_string(enum usb_device_speed speed); 44extern const char *usb_speed_string(enum usb_device_speed speed);
45 45
46
47/**
48 * usb_state_string - Returns human readable name for the state.
49 * @state: The state to return a human-readable name for. If it's not
50 * any of the states devices in usb_device_state_string enum,
51 * the string UNKNOWN will be returned.
52 */
53extern const char *usb_state_string(enum usb_device_state state);
54
46#endif /* __LINUX_USB_CH9_H */ 55#endif /* __LINUX_USB_CH9_H */
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 8860594d6364..5e61589fc166 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -39,6 +39,7 @@
39#include <linux/usb/ch9.h> 39#include <linux/usb/ch9.h>
40#include <linux/usb/gadget.h> 40#include <linux/usb/gadget.h>
41#include <linux/log2.h> 41#include <linux/log2.h>
42#include <linux/configfs.h>
42 43
43/* 44/*
44 * USB function drivers should return USB_GADGET_DELAYED_STATUS if they 45 * USB function drivers should return USB_GADGET_DELAYED_STATUS if they
@@ -464,6 +465,8 @@ struct usb_function_driver {
464}; 465};
465 466
466struct usb_function_instance { 467struct usb_function_instance {
468 struct config_group group;
469 struct list_head cfs_list;
467 struct usb_function_driver *fd; 470 struct usb_function_driver *fd;
468 void (*free_func_inst)(struct usb_function_instance *inst); 471 void (*free_func_inst)(struct usb_function_instance *inst);
469}; 472};
diff --git a/include/linux/usb/dwc3-omap.h b/include/linux/usb/dwc3-omap.h
index 51eae14477f7..5615f4d82724 100644
--- a/include/linux/usb/dwc3-omap.h
+++ b/include/linux/usb/dwc3-omap.h
@@ -19,11 +19,11 @@ enum omap_dwc3_vbus_id_status {
19}; 19};
20 20
21#if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE)) 21#if (defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_DWC3_MODULE))
22extern void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status); 22extern int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status);
23#else 23#else
24static inline void dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status) 24static inline int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
25{ 25{
26 return; 26 return -ENODEV;
27} 27}
28#endif 28#endif
29 29
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 2e297e80d59a..c454a88abf2e 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -482,6 +482,7 @@ struct usb_gadget_ops {
482 * @speed: Speed of current connection to USB host. 482 * @speed: Speed of current connection to USB host.
483 * @max_speed: Maximal speed the UDC can handle. UDC must support this 483 * @max_speed: Maximal speed the UDC can handle. UDC must support this
484 * and all slower speeds. 484 * and all slower speeds.
485 * @state: the state we are now (attached, suspended, configured, etc)
485 * @sg_supported: true if we can handle scatter-gather 486 * @sg_supported: true if we can handle scatter-gather
486 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the 487 * @is_otg: True if the USB device port uses a Mini-AB jack, so that the
487 * gadget driver must provide a USB OTG descriptor. 488 * gadget driver must provide a USB OTG descriptor.
@@ -525,6 +526,7 @@ struct usb_gadget {
525 struct list_head ep_list; /* of usb_ep */ 526 struct list_head ep_list; /* of usb_ep */
526 enum usb_device_speed speed; 527 enum usb_device_speed speed;
527 enum usb_device_speed max_speed; 528 enum usb_device_speed max_speed;
529 enum usb_device_state state;
528 unsigned sg_supported:1; 530 unsigned sg_supported:1;
529 unsigned is_otg:1; 531 unsigned is_otg:1;
530 unsigned is_a_peripheral:1; 532 unsigned is_a_peripheral:1;
@@ -872,6 +874,8 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver);
872 */ 874 */
873int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); 875int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
874 876
877extern int usb_add_gadget_udc_release(struct device *parent,
878 struct usb_gadget *gadget, void (*release)(struct device *dev));
875extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget); 879extern int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget);
876extern void usb_del_gadget_udc(struct usb_gadget *gadget); 880extern void usb_del_gadget_udc(struct usb_gadget *gadget);
877extern int udc_attach_driver(const char *name, 881extern int udc_attach_driver(const char *name,
@@ -959,6 +963,13 @@ extern void usb_gadget_unmap_request(struct usb_gadget *gadget,
959 963
960/*-------------------------------------------------------------------------*/ 964/*-------------------------------------------------------------------------*/
961 965
966/* utility to set gadget state properly */
967
968extern void usb_gadget_set_state(struct usb_gadget *gadget,
969 enum usb_device_state state);
970
971/*-------------------------------------------------------------------------*/
972
962/* utility wrapping a simple endpoint selection policy */ 973/* utility wrapping a simple endpoint selection policy */
963 974
964extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, 975extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *,
diff --git a/include/linux/usb/gadget_configfs.h b/include/linux/usb/gadget_configfs.h
new file mode 100644
index 000000000000..d74c0ae989d5
--- /dev/null
+++ b/include/linux/usb/gadget_configfs.h
@@ -0,0 +1,110 @@
1#ifndef __GADGET_CONFIGFS__
2#define __GADGET_CONFIGFS__
3
4#include <linux/configfs.h>
5
6int check_user_usb_string(const char *name,
7 struct usb_gadget_strings *stringtab_dev);
8
9#define GS_STRINGS_W(__struct, __name) \
10 static ssize_t __struct##_##__name##_store(struct __struct *gs, \
11 const char *page, size_t len) \
12{ \
13 int ret; \
14 \
15 ret = usb_string_copy(page, &gs->__name); \
16 if (ret) \
17 return ret; \
18 return len; \
19}
20
21#define GS_STRINGS_R(__struct, __name) \
22 static ssize_t __struct##_##__name##_show(struct __struct *gs, \
23 char *page) \
24{ \
25 return sprintf(page, "%s\n", gs->__name ?: ""); \
26}
27
28#define GS_STRING_ITEM_ATTR(struct_name, name) \
29 static struct struct_name##_attribute struct_name##_##name = \
30 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
31 struct_name##_##name##_show, \
32 struct_name##_##name##_store)
33
34#define GS_STRINGS_RW(struct_name, _name) \
35 GS_STRINGS_R(struct_name, _name) \
36 GS_STRINGS_W(struct_name, _name) \
37 GS_STRING_ITEM_ATTR(struct_name, _name)
38
39#define USB_CONFIG_STRING_RW_OPS(struct_in) \
40 CONFIGFS_ATTR_OPS(struct_in); \
41 \
42static struct configfs_item_operations struct_in##_langid_item_ops = { \
43 .release = struct_in##_attr_release, \
44 .show_attribute = struct_in##_attr_show, \
45 .store_attribute = struct_in##_attr_store, \
46}; \
47 \
48static struct config_item_type struct_in##_langid_type = { \
49 .ct_item_ops = &struct_in##_langid_item_ops, \
50 .ct_attrs = struct_in##_langid_attrs, \
51 .ct_owner = THIS_MODULE, \
52}
53
54#define USB_CONFIG_STRINGS_LANG(struct_in, struct_member) \
55 static struct config_group *struct_in##_strings_make( \
56 struct config_group *group, \
57 const char *name) \
58 { \
59 struct struct_member *gi; \
60 struct struct_in *gs; \
61 struct struct_in *new; \
62 int langs = 0; \
63 int ret; \
64 \
65 new = kzalloc(sizeof(*new), GFP_KERNEL); \
66 if (!new) \
67 return ERR_PTR(-ENOMEM); \
68 \
69 ret = check_user_usb_string(name, &new->stringtab_dev); \
70 if (ret) \
71 goto err; \
72 config_group_init_type_name(&new->group, name, \
73 &struct_in##_langid_type); \
74 \
75 gi = container_of(group, struct struct_member, strings_group); \
76 ret = -EEXIST; \
77 list_for_each_entry(gs, &gi->string_list, list) { \
78 if (gs->stringtab_dev.language == new->stringtab_dev.language) \
79 goto err; \
80 langs++; \
81 } \
82 ret = -EOVERFLOW; \
83 if (langs >= MAX_USB_STRING_LANGS) \
84 goto err; \
85 \
86 list_add_tail(&new->list, &gi->string_list); \
87 return &new->group; \
88err: \
89 kfree(new); \
90 return ERR_PTR(ret); \
91} \
92 \
93static void struct_in##_strings_drop( \
94 struct config_group *group, \
95 struct config_item *item) \
96{ \
97 config_item_put(item); \
98} \
99 \
100static struct configfs_group_operations struct_in##_strings_ops = { \
101 .make_group = &struct_in##_strings_make, \
102 .drop_item = &struct_in##_strings_drop, \
103}; \
104 \
105static struct config_item_type struct_in##_strings_type = { \
106 .ct_group_ops = &struct_in##_strings_ops, \
107 .ct_owner = THIS_MODULE, \
108}
109
110#endif
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 59694b5e5e90..f5f5c7dfda90 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -84,7 +84,7 @@ struct usb_hcd {
84 84
85 struct timer_list rh_timer; /* drives root-hub polling */ 85 struct timer_list rh_timer; /* drives root-hub polling */
86 struct urb *status_urb; /* the current status urb */ 86 struct urb *status_urb; /* the current status urb */
87#ifdef CONFIG_USB_SUSPEND 87#ifdef CONFIG_PM_RUNTIME
88 struct work_struct wakeup_work; /* for remote wakeup */ 88 struct work_struct wakeup_work; /* for remote wakeup */
89#endif 89#endif
90 90
@@ -593,14 +593,14 @@ extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg);
593extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); 593extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg);
594#endif /* CONFIG_PM */ 594#endif /* CONFIG_PM */
595 595
596#ifdef CONFIG_USB_SUSPEND 596#ifdef CONFIG_PM_RUNTIME
597extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); 597extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd);
598#else 598#else
599static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) 599static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd)
600{ 600{
601 return; 601 return;
602} 602}
603#endif /* CONFIG_USB_SUSPEND */ 603#endif /* CONFIG_PM_RUNTIME */
604 604
605/*-------------------------------------------------------------------------*/ 605/*-------------------------------------------------------------------------*/
606 606
diff --git a/include/linux/usb/musb-ux500.h b/include/linux/usb/musb-ux500.h
new file mode 100644
index 000000000000..1e2c7130f6e1
--- /dev/null
+++ b/include/linux/usb/musb-ux500.h
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2013 ST-Ericsson AB
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef __MUSB_UX500_H__
16#define __MUSB_UX500_H__
17
18enum ux500_musb_vbus_id_status {
19 UX500_MUSB_NONE = 0,
20 UX500_MUSB_VBUS,
21 UX500_MUSB_ID,
22 UX500_MUSB_CHARGER,
23 UX500_MUSB_ENUMERATED,
24 UX500_MUSB_RIDA,
25 UX500_MUSB_RIDB,
26 UX500_MUSB_RIDC,
27 UX500_MUSB_PREPARE,
28 UX500_MUSB_CLEAN,
29};
30
31#endif /* __MUSB_UX500_H__ */
diff --git a/include/linux/usb/nop-usb-xceiv.h b/include/linux/usb/nop-usb-xceiv.h
index 28884c717411..148d35171aac 100644
--- a/include/linux/usb/nop-usb-xceiv.h
+++ b/include/linux/usb/nop-usb-xceiv.h
@@ -5,6 +5,11 @@
5 5
6struct nop_usb_xceiv_platform_data { 6struct nop_usb_xceiv_platform_data {
7 enum usb_phy_type type; 7 enum usb_phy_type type;
8 unsigned long clk_rate;
9
10 /* if set fails with -EPROBE_DEFER if can't get regulator */
11 unsigned int needs_vcc:1;
12 unsigned int needs_reset:1;
8}; 13};
9 14
10#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE)) 15#if defined(CONFIG_NOP_USB_XCEIV) || (defined(CONFIG_NOP_USB_XCEIV_MODULE) && defined(MODULE))
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index e8a5fe87c6bd..291e01ba32e5 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -36,14 +36,7 @@ struct usb_otg {
36 36
37}; 37};
38 38
39#ifdef CONFIG_USB_OTG_UTILS 39extern const char *usb_otg_state_string(enum usb_otg_state state);
40extern const char *otg_state_string(enum usb_otg_state state);
41#else
42static inline const char *otg_state_string(enum usb_otg_state state)
43{
44 return NULL;
45}
46#endif
47 40
48/* Context: can sleep */ 41/* Context: can sleep */
49static inline int 42static inline int
diff --git a/include/linux/usb/phy.h b/include/linux/usb/phy.h
index 15847cbdb512..6b5978f57633 100644
--- a/include/linux/usb/phy.h
+++ b/include/linux/usb/phy.h
@@ -91,6 +91,9 @@ struct usb_phy {
91 int (*init)(struct usb_phy *x); 91 int (*init)(struct usb_phy *x);
92 void (*shutdown)(struct usb_phy *x); 92 void (*shutdown)(struct usb_phy *x);
93 93
94 /* enable/disable VBUS */
95 int (*set_vbus)(struct usb_phy *x, int on);
96
94 /* effective for B devices, ignored for A-peripheral */ 97 /* effective for B devices, ignored for A-peripheral */
95 int (*set_power)(struct usb_phy *x, 98 int (*set_power)(struct usb_phy *x,
96 unsigned mA); 99 unsigned mA);
@@ -160,8 +163,26 @@ usb_phy_shutdown(struct usb_phy *x)
160 x->shutdown(x); 163 x->shutdown(x);
161} 164}
162 165
166static inline int
167usb_phy_vbus_on(struct usb_phy *x)
168{
169 if (!x->set_vbus)
170 return 0;
171
172 return x->set_vbus(x, true);
173}
174
175static inline int
176usb_phy_vbus_off(struct usb_phy *x)
177{
178 if (!x->set_vbus)
179 return 0;
180
181 return x->set_vbus(x, false);
182}
183
163/* for usb host and peripheral controller drivers */ 184/* for usb host and peripheral controller drivers */
164#ifdef CONFIG_USB_OTG_UTILS 185#if IS_ENABLED(CONFIG_USB_PHY)
165extern struct usb_phy *usb_get_phy(enum usb_phy_type type); 186extern struct usb_phy *usb_get_phy(enum usb_phy_type type);
166extern struct usb_phy *devm_usb_get_phy(struct device *dev, 187extern struct usb_phy *devm_usb_get_phy(struct device *dev,
167 enum usb_phy_type type); 188 enum usb_phy_type type);
@@ -176,29 +197,29 @@ extern int usb_bind_phy(const char *dev_name, u8 index,
176#else 197#else
177static inline struct usb_phy *usb_get_phy(enum usb_phy_type type) 198static inline struct usb_phy *usb_get_phy(enum usb_phy_type type)
178{ 199{
179 return NULL; 200 return ERR_PTR(-ENXIO);
180} 201}
181 202
182static inline struct usb_phy *devm_usb_get_phy(struct device *dev, 203static inline struct usb_phy *devm_usb_get_phy(struct device *dev,
183 enum usb_phy_type type) 204 enum usb_phy_type type)
184{ 205{
185 return NULL; 206 return ERR_PTR(-ENXIO);
186} 207}
187 208
188static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index) 209static inline struct usb_phy *usb_get_phy_dev(struct device *dev, u8 index)
189{ 210{
190 return NULL; 211 return ERR_PTR(-ENXIO);
191} 212}
192 213
193static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index) 214static inline struct usb_phy *devm_usb_get_phy_dev(struct device *dev, u8 index)
194{ 215{
195 return NULL; 216 return ERR_PTR(-ENXIO);
196} 217}
197 218
198static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev, 219static inline struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
199 const char *phandle, u8 index) 220 const char *phandle, u8 index)
200{ 221{
201 return NULL; 222 return ERR_PTR(-ENXIO);
202} 223}
203 224
204static inline void usb_put_phy(struct usb_phy *x) 225static inline void usb_put_phy(struct usb_phy *x)
diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
index c5d36c65c33b..e452ba6ec6bd 100644
--- a/include/linux/usb/renesas_usbhs.h
+++ b/include/linux/usb/renesas_usbhs.h
@@ -62,14 +62,14 @@ struct renesas_usbhs_platform_callback {
62 * Hardware exit function for platform. 62 * Hardware exit function for platform.
63 * it is called when driver was removed 63 * it is called when driver was removed
64 */ 64 */
65 void (*hardware_exit)(struct platform_device *pdev); 65 int (*hardware_exit)(struct platform_device *pdev);
66 66
67 /* 67 /*
68 * option: 68 * option:
69 * 69 *
70 * for board specific clock control 70 * for board specific clock control
71 */ 71 */
72 void (*power_ctrl)(struct platform_device *pdev, 72 int (*power_ctrl)(struct platform_device *pdev,
73 void __iomem *base, int enable); 73 void __iomem *base, int enable);
74 74
75 /* 75 /*
@@ -77,7 +77,7 @@ struct renesas_usbhs_platform_callback {
77 * 77 *
78 * Phy reset for platform 78 * Phy reset for platform
79 */ 79 */
80 void (*phy_reset)(struct platform_device *pdev); 80 int (*phy_reset)(struct platform_device *pdev);
81 81
82 /* 82 /*
83 * get USB ID function 83 * get USB ID function
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 1819b59aab2a..b9b0f7b4e43b 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -15,6 +15,7 @@
15 15
16#include <linux/kref.h> 16#include <linux/kref.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/serial.h>
18#include <linux/sysrq.h> 19#include <linux/sysrq.h>
19#include <linux/kfifo.h> 20#include <linux/kfifo.h>
20 21
@@ -61,12 +62,12 @@
61 * @bulk_out_buffers: pointers to the bulk out buffers for this port 62 * @bulk_out_buffers: pointers to the bulk out buffers for this port
62 * @write_urbs: pointers to the bulk out urbs for this port 63 * @write_urbs: pointers to the bulk out urbs for this port
63 * @write_urbs_free: status bitmap the for bulk out urbs 64 * @write_urbs_free: status bitmap the for bulk out urbs
65 * @icount: interrupt counters
64 * @tx_bytes: number of bytes currently in host stack queues 66 * @tx_bytes: number of bytes currently in host stack queues
65 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this 67 * @bulk_out_endpointAddress: endpoint address for the bulk out pipe for this
66 * port. 68 * port.
67 * @flags: usb serial port flags 69 * @flags: usb serial port flags
68 * @write_wait: a wait_queue_head_t used by the port. 70 * @write_wait: a wait_queue_head_t used by the port.
69 * @delta_msr_wait: modem-status-change wait queue
70 * @work: work queue entry for the line discipline waking up. 71 * @work: work queue entry for the line discipline waking up.
71 * @throttled: nonzero if the read urb is inactive to throttle the device 72 * @throttled: nonzero if the read urb is inactive to throttle the device
72 * @throttle_req: nonzero if the tty wants to throttle us 73 * @throttle_req: nonzero if the tty wants to throttle us
@@ -109,11 +110,11 @@ struct usb_serial_port {
109 unsigned long write_urbs_free; 110 unsigned long write_urbs_free;
110 __u8 bulk_out_endpointAddress; 111 __u8 bulk_out_endpointAddress;
111 112
113 struct async_icount icount;
112 int tx_bytes; 114 int tx_bytes;
113 115
114 unsigned long flags; 116 unsigned long flags;
115 wait_queue_head_t write_wait; 117 wait_queue_head_t write_wait;
116 wait_queue_head_t delta_msr_wait;
117 struct work_struct work; 118 struct work_struct work;
118 char throttled; 119 char throttled;
119 char throttle_req; 120 char throttle_req;
@@ -272,6 +273,7 @@ struct usb_serial_driver {
272 int (*tiocmget)(struct tty_struct *tty); 273 int (*tiocmget)(struct tty_struct *tty);
273 int (*tiocmset)(struct tty_struct *tty, 274 int (*tiocmset)(struct tty_struct *tty,
274 unsigned int set, unsigned int clear); 275 unsigned int set, unsigned int clear);
276 int (*tiocmiwait)(struct tty_struct *tty, unsigned long arg);
275 int (*get_icount)(struct tty_struct *tty, 277 int (*get_icount)(struct tty_struct *tty,
276 struct serial_icounter_struct *icount); 278 struct serial_icounter_struct *icount);
277 /* Called by the tty layer for port level work. There may or may not 279 /* Called by the tty layer for port level work. There may or may not
@@ -329,8 +331,10 @@ extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
329extern void usb_serial_generic_write_bulk_callback(struct urb *urb); 331extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
330extern void usb_serial_generic_throttle(struct tty_struct *tty); 332extern void usb_serial_generic_throttle(struct tty_struct *tty);
331extern void usb_serial_generic_unthrottle(struct tty_struct *tty); 333extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
332extern void usb_serial_generic_disconnect(struct usb_serial *serial); 334extern int usb_serial_generic_tiocmiwait(struct tty_struct *tty,
333extern void usb_serial_generic_release(struct usb_serial *serial); 335 unsigned long arg);
336extern int usb_serial_generic_get_icount(struct tty_struct *tty,
337 struct serial_icounter_struct *icount);
334extern int usb_serial_generic_register(void); 338extern int usb_serial_generic_register(void);
335extern void usb_serial_generic_deregister(void); 339extern void usb_serial_generic_deregister(void);
336extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port, 340extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
diff --git a/include/linux/usb/tegra_usb_phy.h b/include/linux/usb/tegra_usb_phy.h
index 9ebebe906925..1b7519a8c0bf 100644
--- a/include/linux/usb/tegra_usb_phy.h
+++ b/include/linux/usb/tegra_usb_phy.h
@@ -61,10 +61,14 @@ struct tegra_usb_phy {
61 struct device *dev; 61 struct device *dev;
62 bool is_legacy_phy; 62 bool is_legacy_phy;
63 bool is_ulpi_phy; 63 bool is_ulpi_phy;
64 void (*set_pts)(struct usb_phy *x, u8 pts_val);
65 void (*set_phcd)(struct usb_phy *x, bool enable);
64}; 66};
65 67
66struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance, 68struct tegra_usb_phy *tegra_usb_phy_open(struct device *dev, int instance,
67 void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode); 69 void __iomem *regs, void *config, enum tegra_usb_phy_mode phy_mode,
70 void (*set_pts)(struct usb_phy *x, u8 pts_val),
71 void (*set_phcd)(struct usb_phy *x, bool enable));
68 72
69void tegra_usb_phy_preresume(struct usb_phy *phy); 73void tegra_usb_phy_preresume(struct usb_phy *phy);
70 74
@@ -75,8 +79,4 @@ void tegra_ehci_phy_restore_start(struct usb_phy *phy,
75 79
76void tegra_ehci_phy_restore_end(struct usb_phy *phy); 80void tegra_ehci_phy_restore_end(struct usb_phy *phy);
77 81
78void tegra_ehci_set_pts(struct usb_phy *x, u8 pts_val);
79
80void tegra_ehci_set_phcd(struct usb_phy *x, bool enable);
81
82#endif /* __TEGRA_USB_PHY_H */ 82#endif /* __TEGRA_USB_PHY_H */
diff --git a/include/uapi/linux/usb/cdc-wdm.h b/include/uapi/linux/usb/cdc-wdm.h
new file mode 100644
index 000000000000..f03134feebd6
--- /dev/null
+++ b/include/uapi/linux/usb/cdc-wdm.h
@@ -0,0 +1,21 @@
1/*
2 * USB CDC Device Management userspace API definitions
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * version 2 as published by the Free Software Foundation.
7 */
8
9#ifndef _UAPI__LINUX_USB_CDC_WDM_H
10#define _UAPI__LINUX_USB_CDC_WDM_H
11
12/*
13 * This IOCTL is used to retrieve the wMaxCommand for the device,
14 * defining the message limit for both reading and writing.
15 *
16 * For CDC WDM functions this will be the wMaxCommand field of the
17 * Device Management Functional Descriptor.
18 */
19#define IOCTL_WDM_MAX_COMMAND _IOR('H', 0xA0, __u16)
20
21#endif /* _UAPI__LINUX_USB_CDC_WDM_H */
diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index f738e25377ff..aa33fd1b2d4f 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -138,7 +138,7 @@
138 138
139/* 139/*
140 * New Feature Selectors as added by USB 3.0 140 * New Feature Selectors as added by USB 3.0
141 * See USB 3.0 spec Table 9-6 141 * See USB 3.0 spec Table 9-7
142 */ 142 */
143#define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */ 143#define USB_DEVICE_U1_ENABLE 48 /* dev may initiate U1 transition */
144#define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */ 144#define USB_DEVICE_U2_ENABLE 49 /* dev may initiate U2 transition */
@@ -147,7 +147,7 @@
147 147
148#define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00 148#define USB_INTR_FUNC_SUSPEND_OPT_MASK 0xFF00
149/* 149/*
150 * Suspend Options, Table 9-7 USB 3.0 spec 150 * Suspend Options, Table 9-8 USB 3.0 spec
151 */ 151 */
152#define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0)) 152#define USB_INTRF_FUNC_SUSPEND_LP (1 << (8 + 0))
153#define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1)) 153#define USB_INTRF_FUNC_SUSPEND_RW (1 << (8 + 1))